XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
userinfo.php
Go to the documentation of this file.
1 <?php
21 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'header.php';
22 include_once $GLOBALS['xoops']->path('modules/system/constants.php');
23 
24 $uid = intval($_GET['uid']);
25 if ($uid <= 0) {
26  if (is_object($GLOBALS['xoopsUser']) ) {
27  $uid = $GLOBALS['xoopsUser']->getVar('uid');
28  } else {
29  header('location: ' . XOOPS_URL);
30  exit();
31  }
32 }
33 
34 $gperm_handler = & xoops_gethandler( 'groupperm' );
35 $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
36 
37 if (is_object($GLOBALS['xoopsUser']) && $uid == $GLOBALS['xoopsUser']->getVar('uid')) {
38  //disable cache
39  $GLOBALS['xoopsConfig']['module_cache'][$GLOBALS['xoopsModule']->getVar('mid')] = 0;
40  $xoopsOption['template_main'] = 'profile_userinfo.html';
41  include $GLOBALS['xoops']->path('header.php');
42 
43  $config_handler =& xoops_gethandler('config');
44  $GLOBALS['xoopsConfigUser'] = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
45 
46  $GLOBALS['xoopsTpl']->assign('user_ownpage', true);
47  $GLOBALS['xoopsTpl']->assign('lang_editprofile', _US_EDITPROFILE);
48  $GLOBALS['xoopsTpl']->assign('lang_changepassword', _PROFILE_MA_CHANGEPASSWORD);
49  $GLOBALS['xoopsTpl']->assign('lang_avatar', _US_AVATAR);
50  $GLOBALS['xoopsTpl']->assign('lang_inbox', _US_INBOX);
51  $GLOBALS['xoopsTpl']->assign('lang_logout', _US_LOGOUT);
52  if ($GLOBALS['xoopsConfigUser']['self_delete'] == 1) {
53  $GLOBALS['xoopsTpl']->assign('user_candelete', true);
54  $GLOBALS['xoopsTpl']->assign('lang_deleteaccount', _US_DELACCOUNT);
55  } else {
56  $GLOBALS['xoopsTpl']->assign('user_candelete', false);
57  }
58  $GLOBALS['xoopsTpl']->assign('user_changeemail', $GLOBALS['xoopsConfigUser']['allow_chgmail']);
59  $thisUser =& $GLOBALS['xoopsUser'];
60 } else {
61  $member_handler =& xoops_gethandler('member');
63 
64  // Redirect if not a user or not active and the current user is not admin
65  if (!is_object($thisUser) || (!$thisUser->isActive() && (!$GLOBALS['xoopsUser'] || !$GLOBALS['xoopsUser']->isAdmin() ))) {
66  redirect_header(XOOPS_URL . "/modules/" . $GLOBALS['xoopsModule']->getVar('dirname', 'n'), 3, _US_SELECTNG);
67  exit();
68  }
69 
83  // Redirect if current user is not allowed to access the user's profile based on group permission
84  $groups_basic = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
85  $groups_thisUser = $thisUser->getGroups();
88  $gperm_handler =& xoops_gethandler('groupperm');
89  $groups_accessible = $gperm_handler->getItemIds('profile_access', $groups_xoopsUser, $GLOBALS['xoopsModule']->getVar('mid'));
90 
91  $rejected = false;
92  if ($thisUser->isAdmin()) {
93  $rejected = !in_array(XOOPS_GROUP_ADMIN, $groups_accessible);
94  } else if ($groups_thisUser_nonbasic) {
96  } else {
97  $rejected = !in_array(XOOPS_GROUP_USERS, $groups_accessible);
98  }
99 
100  if ($rejected) {
101  redirect_header(XOOPS_URL . "/modules/" . $GLOBALS['xoopsModule']->getVar('dirname', 'n'), 3, _NOPERM);
102  exit();
103  }
104 
105  if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin()) {
106  //disable cache
107  $GLOBALS['xoopsConfig']['module_cache'][$GLOBALS['xoopsModule']->getVar('mid')] = 0;
108  }
109  $xoopsOption['template_main'] = 'profile_userinfo.html';
110  include $GLOBALS['xoops']->path('header.php');
111  $GLOBALS['xoopsTpl']->assign('user_ownpage', false);
112 }
113 
114 $GLOBALS['xoopsTpl']->assign('user_uid', $thisUser->getVar('uid'));
115 if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin()) {
116  $GLOBALS['xoopsTpl']->assign('lang_editprofile', _US_EDITPROFILE);
117  $GLOBALS['xoopsTpl']->assign('lang_deleteaccount', _US_DELACCOUNT);
118  $GLOBALS['xoopsTpl']->assign('userlevel', $thisUser->isActive());
119 }
120 
121 $xoopsOption['xoops_pagetitle'] = sprintf(_US_ALLABOUT, $thisUser->getVar('uname'));
122 
123 // Dynamic User Profiles
124 $thisUsergroups = $thisUser->getGroups();
126 //search for visible Fields or null for none
128 
130 $fields = $profile_handler->loadFields();
133 $cat_crit->setSort("cat_weight");
134 $cats = $cat_handler->getObjects($cat_crit, true, false);
135 unset($cat_crit);
136 
137 $avatar = "";
138 if ($thisUser->getVar('user_avatar') && "blank.gif" != $thisUser->getVar('user_avatar')) {
139  $avatar = XOOPS_UPLOAD_URL . "/" . $thisUser->getVar('user_avatar');
140 }
141 
142 $email = "";
143 if ($thisUser->getVar('user_viewemail') == 1) {
144  $email = $thisUser->getVar('email', 'E');
145 } else if (is_object($GLOBALS['xoopsUser'])) {
146  // Module admins will be allowed to see emails
147  if ($GLOBALS['xoopsUser']->isAdmin() || ($GLOBALS['xoopsUser']->getVar("uid") == $thisUser->getVar("uid"))) {
148  $email = $thisUser->getVar('email', 'E');
149  }
150 }
151 foreach (array_keys($cats) as $i) {
152  $categories[$i] = $cats[$i];
153 }
154 
156 $profile = $profile_handler->get($thisUser->getVar('uid'));
157 // Add dynamic fields
158 foreach (array_keys($fields) as $i) {
159  //If field is not visible, skip
160  //if ( $field_ids_visible && !in_array($fields[$i]->getVar('field_id'), $field_ids_visible) ) continue;
161  if (!in_array($fields[$i]->getVar('field_id'), $field_ids_visible)) {
162  continue;
163  }
164  $cat_id = $fields[$i]->getVar('cat_id');
165  $value = $fields[$i]->getOutputValue($thisUser, $profile);
166  if (is_array($value)) {
167  $value = implode('<br />', array_values($value) );
168  }
169  if ($value) {
170  $categories[$cat_id]['fields'][] = array('title' => $fields[$i]->getVar('field_title'), 'value' => $value);
171  $weights[$cat_id][] = $fields[$i]->getVar('cat_id');
172  }
173 }
174 
175 $GLOBALS['xoopsTpl']->assign('categories', $categories);
176 // Dynamic user profiles end
177 
178 if ($GLOBALS['xoopsModuleConfig']['profile_search']) {
179  $module_handler =& xoops_gethandler('module');
180  $criteria = new CriteriaCompo(new Criteria('hassearch', 1));
181  $criteria->add(new Criteria('isactive', 1) );
182  $modules = $module_handler->getObjects($criteria, true);
183  $mids = array_keys($modules);
184 
186  $allowed_mids = $gperm_handler->getItemIds('module_read', $groups);
187  if (count($mids) > 0 && count($allowed_mids) > 0) {
188  foreach ($mids as $mid ) {
189  if ( in_array($mid, $allowed_mids) ) {
190  $results = $modules[$mid]->search('', '', 5, 0, $thisUser->getVar('uid') );
191  $count = count($results);
192  if (is_array($results) && $count > 0) {
193  for ($i = 0; $i < $count; $i++ ) {
194  if (isset($results[$i]['image']) && $results[$i]['image'] != '') {
195  $results[$i]['image'] = XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname', 'n') . '/' . $results[$i]['image'];
196  } else {
197  $results[$i]['image'] = XOOPS_URL . '/images/icons/posticon2.gif';
198  }
199  if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
200  $results[$i]['link'] = XOOPS_URL . "/modules/" . $modules[$mid]->getVar('dirname', 'n') . "/" . $results[$i]['link'];
201  }
202  $results[$i]['title'] = $myts->htmlspecialchars($results[$i]['title']);
203  $results[$i]['time'] = $results[$i]['time'] ? formatTimestamp($results[$i]['time']) : '';
204  }
205  if ($count == 5) {
206  $showall_link = '<a href="' . XOOPS_URL . '/search.php?action=showallbyuser&amp;mid=' . $mid . '&amp;uid=' . $thisUser->getVar('uid') . '">' . _US_SHOWALL . '</a>';
207  } else {
208  $showall_link = '';
209  }
210  $GLOBALS['xoopsTpl']->append('modules', array('name' => $modules[$mid]->getVar('name'), 'results' => $results, 'showall_link' => $showall_link));
211  }
212  unset($modules[$mid]);
213  }
214  }
215  }
216 }
217 
218 //User info
219 $GLOBALS['xoopsTpl']->assign('uname', $thisUser->getVar('uname'));
220 $GLOBALS['xoopsTpl']->assign('email', $email);
221 $GLOBALS['xoopsTpl']->assign('avatar', $avatar);
222 $GLOBALS['xoopsTpl']->assign('recent_activity', _PROFILE_MA_RECENTACTIVITY);
223 $xoBreadcrumbs[] = array('title' => _PROFILE_MA_USERINFO);
224 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footer.php';
225 ?>