Passed
Pull Request — master (#81)
by Michael
02:31
created

index.php (5 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * Module: Yogurt
17
 *
18
 * @category        Module
19
 * @package         yogurt
20
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
21
 * @copyright       {@link https://xoops.org/ XOOPS Project}
22
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 */
24
25
use Xmf\Request;
26
use XoopsModules\Yogurt;
27
use XoopsModules\Yogurt\IndexController;
28
29
/**
30
 * Xoops header
31
 */
32
$GLOBALS['xoopsOption']['template_main'] = 'yogurt_index.tpl';
33
require __DIR__ . '/header.php';
34
35
$helper->loadLanguage('user');
36
37
$mainvideocode = '';
38
$mainvideodesc = '';
39
40
//require_once __DIR__ . '/class/yogurt_controller.php';
41
//if (!@ require_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/user.php') {
42
//    require_once XOOPS_ROOT_PATH . '/language/english/user.php';
43
//}
44
45
$controller = new IndexController($xoopsDB, $xoopsUser);
46
47
/**
48
 * Fetching numbers of groups friends videos pictures etc...
49
 */
50
$nbSections = $controller->getNumbersSections();
51
52
/**
53
 * This variable define the beginning of the navigation must be
54
 * set here so all calls to database will take this into account
55
 */
56
$start = Request::getInt(
57
    'start',
58
    0,
59
    'GET'
60
);
61
62
/**
63
 * Criteria for mainvideo
64
 */
65
$criteriaUidVideo  = new Criteria('uid_owner', $controller->uidOwner);
66
$criteria_mainvideo = new Criteria('main_video', '1');
67
$criteria_video     = new CriteriaCompo($criteria_mainvideo);
68
$criteria_video->add($criteriaUidVideo);
69
70
if ((isset($nbSections['nbVideos']) && $nbSections['nbVideos'] > 0) && ($videos = $controller->videosFactory->getObjects($criteria_video))) {
71
    $mainvideocode = $videos[0]->getVar('youtube_code');
72
    $mainvideodesc = $videos[0]->getVar('video_desc');
73
}
74
75
76
/**
77
 * Groups
78
 */
79
$criteria_groups = new Criteria('rel_user_uid', $controller->uidOwner);
80
$groups          = $controller->relgroupusersFactory->getGroups(8, $criteria_groups);
81
82
/**
83
 * Visitors
84
 */
85
 $controller->visitorsFactory->purgeVisits();
86
 
87
if (0 === $controller->isAnonym) {
88
    /**
89
     * Fectching last visitors
90
     */
91
    if ($controller->uidOwner !== $xoopsUser->getVar('uid')) {
92
        $visitor_now = $controller->visitorsFactory->create();
93
        $visitor_now->setVar('uid_owner', $controller->uidOwner);
94
        $visitor_now->setVar('uid_visitor', $xoopsUser->getVar('uid'));
95
        $visitor_now->setVar('uname_visitor', $xoopsUser->getVar('uname'));
96
        $controller->visitorsFactory->insert2($visitor_now);
97
    }
98
    $criteria_visitors = new Criteria('uid_owner', $controller->uidOwner);
99
    //$criteria_visitors->setLimit(5);
100
    $visitorsObjectArray = $controller->visitorsFactory->getObjects(
101
        $criteria_visitors
102
    );
103
104
    /**
105
     * Lets populate an array with the dati from visitors
106
     */
107
    $i              = 0;
108
    $visitorsArray = [];
109
    if (is_array($visitorsObjectArray) && count($visitorsObjectArray)>0) {
110
        foreach ($visitorsObjectArray as $visitor) {
111
            if (null !== $visitor) {
112
                $indice                 = $visitor->getVar('uid_visitor', 's');
113
                $visitorsArray[$indice] = $visitor->getVar('uname_visitor', 's');
114
115
                $i++;
116
            }
117
        }
118
    }
119
120
    $xoopsTpl->assign('visitors', $visitorsArray);
121
    $xoopsTpl->assign('lang_visitors', _MD_YOGURT_VISITORS);
122
    /*    $criteria_deletevisitors = new criteria('uid_owner',$uid);
123
        $criteria_deletevisitors->setStart(5);
124
125
        print_r($criteria_deletevisitors);
126
        $visitorsFactory->deleteAll($criteria_deletevisitors, true);
127
    */
128
}
129
130
$avatar = $controller->owner->getVar('user_avatar');
131
132
$memberHandler = xoops_getHandler('member');
133
$thisUser      = $memberHandler->getUser($controller->uidOwner);
0 ignored issues
show
The method getUser() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsAvatarHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

133
$thisUser      = $memberHandler->/** @scrutinizer ignore-call */ getUser($controller->uidOwner);
Loading history...
134
$myts          = MyTextSanitizer::getInstance();
135
136
//navbar
137
$xoopsTpl->assign('lang_mysection', _MD_YOGURT_MYPROFILE);
138
$xoopsTpl->assign('section_name', _MD_YOGURT_PROFILE);
139
140
//$xoopsTpl->assign('path_yogurt_uploads',$helper->getConfig('link_path_upload'));
141
142
//groups
143
$xoopsTpl->assign('groups', $groups);
144
if (isset($nbSections['nbGroups']) && $nbSections['nbGroups'] <= 0) {
145
    $xoopsTpl->assign('lang_nogroupsyet', _MD_YOGURT_NOGROUPSYET);
146
}
147
$xoopsTpl->assign('lang_viewallgroups', _MD_YOGURT_ALLGROUPS);
148
149
//Avatar and Main
150
$xoopsTpl->assign('avatar_url', $avatar);
151
$xoopsTpl->assign('lang_selectavatar', _MD_YOGURT_SELECTAVATAR);
152
$xoopsTpl->assign('lang_selectmainvideo', _MD_YOGURT_SELECTMAINVIDEO);
153
$xoopsTpl->assign('lang_noavatar', _MD_YOGURT_NOAVATARYET);
154
$xoopsTpl->assign('lang_nomainvideo', _MD_YOGURT_NOMAINVIDEOYET);
155
$xoopsTpl->assign('lang_featuredvideo', _MD_YOGURT_VIDEO_FEATURED);
156
$xoopsTpl->assign('lang_viewallvideos', _MD_YOGURT_ALLVIDEOS);
157
158
if (isset($nbSections['nbVideos']) && $nbSections['nbVideos'] > 0) {
159
    $xoopsTpl->assign('mainvideocode', $mainvideocode);
160
    $xoopsTpl->assign('mainvideodesc', $mainvideodesc);
161
    $xoopsTpl->assign(
162
        'width',
163
        $helper->getConfig('width_maintube')
164
    ); // Falta configurar o tamnho do main nas configs e alterar no template
165
    $xoopsTpl->assign(
166
        'height',
167
        $helper->getConfig('height_maintube')
168
    );
169
}
170
171
/**
172
 * Friends
173
 */
174
if ($xoopsUser){
175
176
$controller = new Yogurt\FriendsController($xoopsDB, $xoopsUser);
177
178
$friendrequest = 0;
179
if (1 === $controller->isOwner) {
180
    $criteria_uidfriendrequest = new Criteria('friendrequestto_uid', $controller->uidOwner);
181
    $newFriendrequest          = $controller->friendrequestFactory->getObjects($criteria_uidfriendrequest);
182
    if ($newFriendrequest) {
183
        $countFriendrequest      = count($newFriendrequest);
184
        $friendrequesterHandler = xoops_getHandler('member');
185
        $friendrequester        = $friendrequesterHandler->getUser($newFriendrequest[0]->getVar('friendrequester_uid'));
186
        $friendrequester_uid    = $friendrequester->getVar('uid');
187
        $friendrequester_uname  = $friendrequester->getVar('uname');
188
        $friendrequester_avatar = $friendrequester->getVar('user_avatar');
189
        $friendrequest_id       = $newFriendrequest[0]->getVar('friendreq_id');
190
        $friendrequest          = 1;
191
    }
192
}
193
 
194
//requests to become friend
195
if (1 === $friendrequest) {
196
	$xoopsTpl->assign('lang_youhavexfriendrequests', sprintf(_MD_YOGURT_YOUHAVEXFRIENDREQUESTS, $countFriendrequest));
197
    $xoopsTpl->assign('friendrequester_uid', $friendrequester_uid);
198
    $xoopsTpl->assign('friendrequester_uname', $friendrequester_uname);
199
    $xoopsTpl->assign('friendrequester_avatar', $friendrequester_avatar);
200
    $xoopsTpl->assign('friendrequest', $friendrequest);
201
    $xoopsTpl->assign('friendrequest_id', $friendrequest_id);
202
    $xoopsTpl->assign('lang_rejected', _MD_YOGURT_UNKNOWN_REJECTING);
203
    $xoopsTpl->assign('lang_accepted', _MD_YOGURT_UNKNOWN_ACCEPTING);
204
    $xoopsTpl->assign('lang_acquaintance', _MD_YOGURT_AQUAITANCE);
205
    $xoopsTpl->assign('lang_friend', _MD_YOGURT_FRIEND);
206
    $xoopsTpl->assign('lang_bestfriend', _MD_YOGURT_BESTFRIEND);
207
    $linkedpetioner = '<a href="index.php?uid=' . $friendrequester_uid . '">' . $friendrequester_uname . '</a>';
208
    $xoopsTpl->assign('lang_askingfriend', sprintf(_MD_YOGURT_ASKINGFRIEND, $linkedpetioner));
209
}
210
}
211
212
$xoopsTpl->assign('lang_askusertobefriend', _MD_YOGURT_ASKBEFRIEND);
213
$xoopsTpl->assign('lang_addfriend', _MD_YOGURT_ADDFRIEND);
214
$xoopsTpl->assign('lang_friendrequestpending', _MD_YOGURT_FRIENDREQUEST_PENDING);
215
$xoopsTpl->assign('lang_myfriend', _MD_YOGURT_MYFRIEND);
216
$xoopsTpl->assign('lang_friendrequestsent', _MD_YOGURT_FRIENDREQUEST_SENT);
217
$xoopsTpl->assign('lang_acceptfriend', _MD_YOGURT_FRIEND_ACCEPT);
218
$xoopsTpl->assign('lang_rejectfriend', _MD_YOGURT_FRIEND_REJECT);
219
220
$criteria_friends = new Criteria('friend1_uid', $controller->uidOwner);
221
$friends          = $controller->friendshipsFactory->getFriends(8, $criteria_friends);
222
$xoopsTpl->assign('friends', $friends);
223
$xoopsTpl->assign('lang_friendstitle', sprintf(_MD_YOGURT_FRIENDSTITLE, $controller->nameOwner));
0 ignored issues
show
It seems like $controller->nameOwner can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

223
$xoopsTpl->assign('lang_friendstitle', sprintf(_MD_YOGURT_FRIENDSTITLE, /** @scrutinizer ignore-type */ $controller->nameOwner));
Loading history...
224
$xoopsTpl->assign('lang_viewallfriends', _MD_YOGURT_ALLFRIENDS);
225
$xoopsTpl->assign('lang_nofriendsyet', _MD_YOGURT_NOFRIENDSYET);
226
227
228
//search
229
$xoopsTpl->assign('lang_usercontributions', _MD_YOGURT_USER_CONTRIBUTIONS);
230
231
//Profile
232
$xoopsTpl->assign('lang_detailsinfo', _MD_YOGURT_USER_DETAILS);
233
$xoopsTpl->assign('lang_contactinfo', _MD_YOGURT_CONTACTINFO);
234
//$xoopsTpl->assign('path_yogurt_uploads',$helper->getConfig('link_path_upload'));
235
$xoopsTpl->assign(
236
    'lang_max_countPicture',
237
    sprintf(_MD_YOGURT_YOUCANHAVE, $helper->getConfig('countPicture'))
238
);
239
$xoopsTpl->assign('lang_delete', _MD_YOGURT_DELETE);
240
$xoopsTpl->assign('lang_editdesc', _MD_YOGURT_EDIT_DESC);
241
$xoopsTpl->assign('lang_visitors', _MD_YOGURT_VISITORS);
242
$xoopsTpl->assign('lang_profilevisitors', _MD_YOGURT_PROFILEVISITORS);
243
$xoopsTpl->assign('lang_editprofile', _MD_YOGURT_EDITPROFILE);
244
245
$xoopsTpl->assign('user_uname', $thisUser->getVar('uname'));
246
$xoopsTpl->assign('user_realname', $thisUser->getVar('name'));
247
$xoopsTpl->assign('lang_uname', _US_NICKNAME);
248
$xoopsTpl->assign('lang_website', _US_WEBSITE);
249
$userwebsite = '' !== $thisUser->getVar('url', 'E') ? '<a href="' . $thisUser->getVar(
250
        'url',
251
        'E'
252
    ) . '" target="_blank">' . $thisUser->getVar(
253
        'url'
254
    ) . '</a>' : '';
255
$xoopsTpl->assign('user_websiteurl', $userwebsite);
256
$xoopsTpl->assign('lang_email', _US_EMAIL);
257
$xoopsTpl->assign('lang_privmsg', _US_PM);
258
$xoopsTpl->assign('lang_icq', _US_ICQ);
259
$xoopsTpl->assign('user_icq', $thisUser->getVar('user_icq'));
260
$xoopsTpl->assign('lang_aim', _US_AIM);
261
$xoopsTpl->assign('user_aim', $thisUser->getVar('user_aim'));
262
$xoopsTpl->assign('lang_yim', _US_YIM);
263
$xoopsTpl->assign('user_yim', $thisUser->getVar('user_yim'));
264
$xoopsTpl->assign('lang_msnm', _US_MSNM);
265
$xoopsTpl->assign('user_msnm', $thisUser->getVar('user_msnm'));
266
$xoopsTpl->assign('lang_location', _US_LOCATION);
267
$xoopsTpl->assign('user_location', $thisUser->getVar('user_from'));
268
$xoopsTpl->assign('lang_occupation', _US_OCCUPATION);
269
$xoopsTpl->assign('user_occupation', $thisUser->getVar('user_occ'));
270
$xoopsTpl->assign('lang_interest', _US_INTEREST);
271
$xoopsTpl->assign('user_interest', $thisUser->getVar('user_intrest'));
272
$xoopsTpl->assign('lang_extrainfo', _US_EXTRAINFO);
273
$var = $thisUser->getVar('bio', 'N');
274
$xoopsTpl->assign('user_extrainfo', $myts->displayTarea($var, 0, 1, 1));
275
$xoopsTpl->assign('lang_statistics', _US_STATISTICS);
276
$xoopsTpl->assign('lang_membersince', _US_MEMBERSINCE);
277
$var = $thisUser->getVar('user_regdate');
278
$xoopsTpl->assign('user_joindate', formatTimestamp($var, 's'));
279
$xoopsTpl->assign('lang_rank', _US_RANK);
280
$xoopsTpl->assign('lang_posts', _US_POSTS);
281
$xoopsTpl->assign('lang_basicInfo', _US_BASICINFO);
282
$xoopsTpl->assign('lang_more', _US_MOREABOUT);
283
$xoopsTpl->assign('lang_myinfo', _US_MYINFO);
284
$xoopsTpl->assign('user_posts', $thisUser->getVar('posts'));
285
$xoopsTpl->assign('lang_lastlogin', _US_LASTLOGIN);
286
$date = $thisUser->getVar('last_login');
287
if (!empty($date)) {
288
    $xoopsTpl->assign('user_lastlogin', formatTimestamp($date, 'm'));
289
}
290
$xoopsTpl->assign('lang_notregistered', _US_NOTREGISTERED);
291
292
$xoopsTpl->assign('lang_signature', _US_SIGNATURE);
293
$var = $thisUser->getVar('user_sig', 'N');
294
$xoopsTpl->assign('user_signature', $myts->displayTarea($var, 0, 1, 1));
295
296
$xoopsTpl->assign('user_viewemail', $thisUser->getVar('user_viewemail', 'E'));
297
if (1 === $thisUser->getVar('user_viewemail')) {
298
    $xoopsTpl->assign('user_email', $thisUser->getVar('email', 'E'));
299
} else {
300
    $xoopsTpl->assign('user_email', '&nbsp;');
301
}
302
303
$xoopsTpl->assign('user_onlinestatus', $thisUser->isOnline());
304
$xoopsTpl->assign('lang_onlinestatus', _MD_YOGURT_ONLINESTATUS);
305
$xoopsTpl->assign('uname', $thisUser->getVar('uname'));
306
$xoopsTpl->assign('lang_realname', _US_REALNAME);
307
$xoopsTpl->assign('name', $thisUser->getVar('name'));
308
309
$gpermHandler  = xoops_getHandler('groupperm');
310
$groups        = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
311
$moduleHandler = xoops_getHandler('module');
312
$criteria      = new CriteriaCompo(new Criteria('hassearch', 1));
313
$criteria->add(new Criteria('isactive', 1));
314
$mids = array_keys($moduleHandler->getList($criteria));
0 ignored issues
show
The method getList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsImageHandler or XoopsRankHandler or XoopsCommentHandler or XoopsTplsetHandler or XoopsAvatarHandler or XoopsBlockHandler or XoopsImagesetHandler or XoopsPersistableObjectHandler or XoopsImagecategoryHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

314
$mids = array_keys($moduleHandler->/** @scrutinizer ignore-call */ getList($criteria));
Loading history...
315
316
//user rank
317
$userrank = $thisUser->rank();
318
if ($userrank['image']) {
319
    $xoopsTpl->assign('user_rankimage', '<img src="' . XOOPS_UPLOAD_URL . '/' . $userrank['image'] . '" alt="">');
320
}
321
$xoopsTpl->assign('user_ranktitle', $userrank['title']);
322
323
foreach ($mids as $mid) {
324
    if ($gpermHandler->checkRight('module_read', $mid, $groups)) {
0 ignored issues
show
The method checkRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

324
    if ($gpermHandler->/** @scrutinizer ignore-call */ checkRight('module_read', $mid, $groups)) {
Loading history...
325
        $module   = $moduleHandler->get($mid);
326
        $user_uid = $thisUser->getVar('uid');
327
        $results  = $module->search('', '', 5, 0, $user_uid);
0 ignored issues
show
The method search() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModule. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

327
        /** @scrutinizer ignore-call */ 
328
        $results  = $module->search('', '', 5, 0, $user_uid);
Loading history...
328
        if (is_array($results)) {
329
            $count = count($results);
330
        }
331
        if (is_array($results) && $count > 0) {
332
            for ($i = 0; $i < $count; $i++) {
333
                if (isset($results[$i]['image']) && '' !== $results[$i]['image']) {
334
                    $results[$i]['image'] = 'modules/' . $module->getVar('dirname') . '/' . $results[$i]['image'];
335
                } else {
336
                    $results[$i]['image'] = 'images/icons/posticon2.gif';
337
                }
338
339
                if (!preg_match("#^http[s]*:\/\/#i", $results[$i]['link'])) {
340
                    $results[$i]['link'] = 'modules/' . $module->getVar('dirname') . '/' . $results[$i]['link'];
341
                }
342
343
                $results[$i]['title'] = $myts->htmlSpecialChars($results[$i]['title']);
344
                $results[$i]['time']  = $results[$i]['time'] ? formatTimestamp($results[$i]['time']) : '';
345
            }
346
            if (5 === $count) {
347
                $showall_link = '<a href="../../search.php?action=showallbyuser&amp;mid=' . $mid . '&amp;uid=' . $thisUser->getVar(
348
                        'uid'
349
                    ) . '">' . _US_SHOWALL . '</a>';
350
            } else {
351
                $showall_link = '';
352
            }
353
            $xoopsTpl->append(
354
                'modules',
355
                [
356
                    'name'         => $module->getVar('name'),
357
                    'results'      => $results,
358
                    'showall_link' => $showall_link,
359
                ]
360
            );
361
        }
362
        unset($module);
363
    }
364
}
365
366
// temporary solution for profile module integration
367
if (xoops_isActiveModule('profile')) {
368
$profileHandler=xoops_getModuleHandler('profile','profile');
369
$uid = $controller->uidOwner;
370
if ($uid <= 0) { 
371
 if (is_object($xoopsUser))  {
372
        $profile = $profileHandler->get($uid);
373
		} 
374
        else {
375
             header('location: ' . XOOPS_URL); 
376
             exit();
377
             }
378
 }
379
else 
380
{
381
$profile = $profileHandler->get($uid);
382
}
383
}
384
385
require __DIR__ . '/footer.php';
386
require dirname(__DIR__, 2) . '/footer.php';
387