* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ define('INTERNAL', 1); define('MENUITEM', 'groups/findfriends'); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'pieforms/pieform.php'; define('TITLE', get_string('findfriends')); require_once 'searchlib.php'; safe_require('search', 'internal'); define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINNAME', 'user'); define('SECTION_PAGE', 'find'); if (param_variable('acceptfriend_submit', null)) { acceptfriend_form(param_integer('id')); } else { if (param_variable('addfriend_submit', null)) { addfriend_form(param_integer('id')); } } $query = param_variable('query', ''); $offset = param_integer('offset', 0); $filter = param_alpha('filter', $USER->get('admin') ? 'all' : 'myinstitutions'); $limit = 10; $options = array('exclude' => $USER->get('id')); if ($filter == 'myinstitutions' && $USER->get('institutions')) { $options['myinstitutions'] = true; } else { $filter = 'all'; }
/** * used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display * @param array $userids * @return array containing the users in the order from $userids */ function get_users_data($userids, $getviews = true) { global $USER; $userids = array_map('intval', $userids); $sql = 'SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted, u.profileicon, u.email, u.urlid, fp.requester AS pending, fp.ctime AS pending_time, ap.value AS hidenamepref, COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages, COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol, (SELECT 1 FROM {usr_friend} WHERE ((usr1 = ? AND usr2 = u.id) OR (usr2 = ? AND usr1 = u.id))) AS friend, (SELECT 1 FROM {usr_friend_request} fr WHERE fr.requester = ? AND fr.owner = u.id) AS requestedfriendship, (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction, fp.message FROM {usr} u LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\') LEFT JOIN {usr_friend_request} fp ON fp.owner = ? AND fp.requester = u.id WHERE u.id IN (' . join(',', array_fill(0, count($userids), '?')) . ')'; $userid = $USER->get('id'); $data = get_records_sql_assoc($sql, array_merge(array($userid, $userid, $userid, $userid), $userids)); $allowhidename = get_config('userscanhiderealnames'); $showusername = !get_config('nousernames'); $institutionstrings = get_institution_strings_for_users($userids); foreach ($data as &$record) { $record->pending_time = format_date(strtotime($record->pending_time), 'strftimedaydate'); $record->messages = $record->messages == 'allow' || $record->friend && $record->messages == 'friends' || $USER->get('admin') ? 1 : 0; if (isset($institutionstrings[$record->id])) { $record->institutions = $institutionstrings[$record->id]; } $record->display_name = display_name($record, null, false, !$allowhidename || !$record->hidenamepref, $showusername); } if (!$data || !$getviews || !($views = get_views(array_keys($data), null, null))) { $views = array(); } if ($getviews) { $viewcount = array_map('count', $views); // since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes. $cleanviews = array(); foreach ($views as $userindex => $viewarray) { $cleanviews[$userindex] = array_slice($viewarray, 0, 5); // Don't reveal any more about the view than necessary foreach ($cleanviews as $userviews) { foreach ($userviews as &$view) { foreach (array_keys(get_object_vars($view)) as $key) { if ($key != 'id' && $key != 'title' && $key != 'url' && $key != 'fullurl') { unset($view->{$key}); } } } } } } foreach ($data as $friend) { if ($getviews && isset($cleanviews[$friend->id])) { $friend->views = $cleanviews[$friend->id]; } if ($friend->pending) { $friend->accept = acceptfriend_form($friend->id); } if (!$friend->friend && !$friend->pending && !$friend->requestedfriendship && $friend->friendscontrol == 'auto') { $friend->makefriend = addfriend_form($friend->id); } } $ordereddata = array(); foreach ($userids as $id) { if (isset($data[$id])) { $ordereddata[] = $data[$id]; } } return $ordereddata; }
$smarty->assign('invitedlist', $groupinvitedlist); } if ($groupinvitedlistform) { $smarty->assign('inviteform', $groupinvitedlistform); } if ($grouprequestedlist) { $smarty->assign('requestedlist', $grouprequestedlist); } if ($grouprequestedlistform) { $smarty->assign('addform', $grouprequestedlistform); } if ($remoteusermessage) { $smarty->assign('message', $record->message); } if ($remoteuseracceptform) { $smarty->assign('acceptform', acceptfriend_form($userid)); } if ($remoteusernewfriendform) { $smarty->assign('newfriendform', addfriend_form($userid)); } if ($remoteuserfriendscontrol) { $smarty->assign('friendscontrol', $friendscontrol); } if ($remoteuserrelationship) { $smarty->assign('relationship', $relationship); } $smarty->assign('loginas', $loginas); $smarty->assign('INLINEJAVASCRIPT', $inlinejs); $smarty->assign('institutions', get_institution_string_for_user($userid)); $smarty->assign('canmessage', $loggedinid != $userid && can_send_message($loggedinid, $userid)); $smarty->assign('USERID', $userid);