public static function render_instance(BlockInstance $instance, $editing = false) { $userid = $instance->get_view()->get('owner'); if (!$userid) { return ''; } $smarty = smarty_core(); // Get viewable views $views = array(); if ($allviews = get_records_select_array('view', 'owner = ? AND type = ?', array($userid, 'portfolio'))) { foreach ($allviews as $view) { if (can_view_view($view->id)) { $views[$view->id] = $view; $view->artefacts = array(); $view->description = str_shorten_html($view->description, 100, true); } } } if ($views) { $viewidlist = implode(', ', array_map(create_function('$a', 'return $a->id;'), $views)); $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY 1, 2, 3, 4, 5 ORDER BY a.title, va.artefact', ''); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); // Perhaps I shouldn't have to construct the entire // artefact object to render the name properly. $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $views[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } } $smarty->assign('VIEWS', $views); return $smarty->fetch('blocktype:myviews:myviews.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $userid = $instance->get_view()->get('owner'); if (!$userid) { return ''; } $smarty = smarty_core(); require_once 'group.php'; // Group stuff $results = group_get_associated_groups($userid, 'member'); foreach ($results['groups'] as $group) { $group->description = str_shorten_html($group->description, 100, true); $group->roledisplay = get_string($group->role, 'grouptype.' . $group->grouptype); } $smarty->assign('USERGROUPS', $results['groups']); return $smarty->fetch('blocktype:mygroups:mygroups.tpl'); }
/** * Optional method. If specified, allows the blocktype class to munge the * artefactchooser element data before it's templated */ public static function artefactchooser_get_element_data($artefact) { static $blognames = array(); if (!isset($blognames[$artefact->parent])) { $blognames[$artefact->parent] = get_field('artefact', 'title', 'id', $artefact->parent); } $artefact->blog = $blognames[$artefact->parent]; $artefact->description = str_shorten_html($artefact->description, 50, true); return $artefact; }
/** * @param array $data Parameters: * - viewid (int) * - annotationid (int) */ public function __construct($data, $cron = false) { parent::__construct($data, $cron); $annotation = new ArtefactTypeAnnotation($this->annotationid); $annotationfeedback = new ArtefactTypeAnnotationfeedback($this->annotationfeedbackid); $this->overridemessagecontents = true; if ($onartefact = $annotation->get('artefact')) { // Feedback on artefact. $userid = null; require_once get_config('docroot') . 'artefact/lib.php'; $artefactinstance = artefact_instance_from_id($onartefact); if ($artefactinstance->feedback_notify_owner()) { $userid = $artefactinstance->get('owner'); $groupid = $artefactinstance->get('group'); $institutionid = $artefactinstance->get('institution'); } if (empty($this->url)) { $this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid; } } else { if ($onview = $annotation->get('view')) { // Feedback on view. if (!($viewrecord = get_record('view', 'id', $onview))) { throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview)); } $userid = $viewrecord->owner; $groupid = $viewrecord->group; $institutionid = $viewrecord->institution; if (empty($this->url)) { $this->url = 'view/view.php?id=' . $onview; } } else { // Something is wrong. throw new ViewNotFoundException(get_string('invalidannotationfeedbacklinkerror', 'artefact.annotation')); } } // Now fetch the users that will need to get notified about this event // depending on whether the page has an owner, group, or institution id set. if (!empty($userid)) { $this->users = activity_get_users($this->get_id(), array($userid)); } else { if (!empty($groupid)) { require_once get_config('docroot') . 'lib/group.php'; $sql = "SELECT u.*\n FROM {usr} u, {group_member} m, {group} g\n WHERE g.id = m.group\n AND m.member = u.id\n AND m.group = ?\n AND (g.feedbacknotify = " . GROUP_ROLES_ALL . "\n OR (g.feedbacknotify = " . GROUP_ROLES_NONMEMBER . " AND (m.role = 'tutor' OR m.role = 'admin'))\n OR (g.feedbacknotify = " . GROUP_ROLES_ADMIN . " AND m.role = 'admin')\n )"; $this->users = get_records_sql_array($sql, array($groupid)); } else { if (!empty($institutionid)) { require_once get_config('libroot') . 'institution.php'; $institution = new Institution($institutionid); $admins = $institution->institution_and_site_admins(); $this->users = get_records_sql_array("SELECT * FROM {usr} WHERE id IN (" . implode(',', $admins) . ")", array()); } } } if (empty($this->users)) { // no one to notify - possibe if group 'feedbacknotify' is set to 0 return; } $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title; $this->urltext = $title; $body = $annotationfeedback->get('description'); $posttime = strftime(get_string('strftimedaydatetime'), $annotationfeedback->get('ctime')); // Internal $this->message = strip_tags(str_shorten_html($body, 200, true)); // Seen as things like emaildigest base the message on $this->message // we need to set the language for the $removedbyline here based on first user. $user = $this->users[0]; $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang; // Comment deleted notification if ($deletedby = $annotationfeedback->get('deletedby')) { $this->strings = (object) array('subject' => (object) array('key' => 'annotationfeedbackdeletednotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title))); $deletedmessage = ArtefactTypeAnnotationfeedback::deleted_by_types_description(); $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation'); $this->message = $removedbyline . ":\n" . $this->message; foreach ($this->users as $key => $user) { if (empty($user->lang) || $user->lang == 'default') { // check to see if we need to show institution language $instlang = get_user_institution_language($user->id); $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang; } else { $lang = $user->lang; } // For email we can send the message in the user's preferred language $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation'); $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbackdeletedhtml', 'artefact.annotation', hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title)); $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbackdeletedtext', 'artefact.annotation', $title, $removedbyline, trim(html2text(htmlspecialchars($body))), $title, get_config('wwwroot') . $this->url); } return; } $this->strings = (object) array('subject' => (object) array('key' => 'newannotationfeedbacknotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title))); $this->url .= '&showcomment=' . $annotationfeedback->get('id'); // Email $author = $annotationfeedback->get('author'); foreach ($this->users as $key => $user) { $authorname = empty($author) ? $annotationfeedback->get('authorname') : display_name($author, $user); if (empty($user->lang) || $user->lang == 'default') { // check to see if we need to show institution language $instlang = get_user_institution_language($user->id); $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang; } else { $lang = $user->lang; } $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbacknotificationhtml', 'artefact.annotation', hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url); $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbacknotificationtext', 'artefact.annotation', $authorname, $title, $posttime, trim(html2text(htmlspecialchars($body))), get_config('wwwroot') . $this->url); } }
public static function get_extra_view_info(&$viewdata, $getartefacts = true) { if ($viewdata) { // Get view owner details for display $owners = array(); $groups = array(); $institutions = array(); foreach ($viewdata as $v) { if ($v->owner && !isset($owners[$v->owner])) { $owners[$v->owner] = (int) $v->owner; } else { if ($v->group && !isset($groups[$v->group])) { $groups[$v->group] = (int) $v->group; } else { if (strlen($v->institution) && !isset($institutions[$v->institution])) { $institutions[$v->institution] = $v->institution; } } } } $viewidlist = join(',', array_map('intval', array_keys($viewdata))); if ($getartefacts) { $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin ORDER BY a.title, va.artefact', ''); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $viewdata[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } } $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); if ($tags) { foreach ($tags as &$tag) { $viewdata[$tag->view]->tags[] = $tag->tag; } } if (!empty($owners)) { $owners = get_records_select_assoc('usr', 'id IN (' . join(',', $owners) . ')', null, '', 'id,username,firstname,lastname,preferredname,admin,staff,studentid,email,profileicon'); } if (!empty($groups)) { $groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name'); } if (!empty($institutions)) { $institutions = get_records_assoc('institution', '', '', '', 'name,displayname'); $institutions['mahara']->displayname = get_config('sitename'); } foreach ($viewdata as &$v) { $v->shortdescription = str_shorten_html(str_replace('<br />', ' ', $v->description), 100, true); if ($v->owner) { $v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]); $v->user = $owners[$v->owner]; } else { if ($v->group) { $v->sharedby = $groups[$v->group]->name; } else { if ($v->institution) { $v->sharedby = $institutions[$v->institution]->displayname; } } } $v = (array) $v; } } }
/** * @param array $data Parameters: * - viewid (int) * - commentid (int) */ public function __construct($data, $cron = false) { parent::__construct($data, $cron); $comment = new ArtefactTypeComment($this->commentid); $this->overridemessagecontents = true; if ($onartefact = $comment->get('onartefact')) { // feedback on artefact $userid = null; require_once get_config('docroot') . 'artefact/lib.php'; $artefactinstance = artefact_instance_from_id($onartefact); if ($artefactinstance->feedback_notify_owner()) { $userid = $artefactinstance->get('owner'); } if (empty($this->url)) { $this->url = get_config('wwwroot') . 'view/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid; } } else { // feedback on view. $onview = $comment->get('onview'); if (!($viewrecord = get_record('view', 'id', $onview))) { throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview)); } $userid = $viewrecord->owner; if (empty($this->url)) { $this->url = get_config('wwwroot') . 'view/view.php?id=' . $onview; } } if (empty($userid)) { return; } $this->users = activity_get_users($this->get_id(), array($userid)); $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title; $this->urltext = $title; $body = $comment->get('description'); $posttime = strftime(get_string('strftimedaydatetime'), $comment->get('ctime')); $user = $this->users[0]; $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang; // Internal $this->message = strip_tags(str_shorten_html($body, 200, true)); // Comment deleted notification if ($deletedby = $comment->get('deletedby')) { $this->strings = (object) array('subject' => (object) array('key' => 'commentdeletednotificationsubject', 'section' => 'artefact.comment', 'args' => array($title))); $deletedmessage = ArtefactTypeComment::deleted_messages(); $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment'); $this->message = $removedbyline . ":\n" . $this->message; // Email $this->users[0]->htmlmessage = get_string_from_language($lang, 'feedbackdeletedhtml', 'artefact.comment', $title, $removedbyline, $body, $this->url, $title); $this->users[0]->emailmessage = get_string_from_language($lang, 'feedbackdeletedtext', 'artefact.comment', $title, $removedbyline, trim(html2text($body)), $title, $this->url); return; } $this->strings = (object) array('subject' => (object) array('key' => 'newfeedbacknotificationsubject', 'section' => 'artefact.comment', 'args' => array($title))); $this->url .= '&showcomment=' . $comment->get('id'); // Email $author = $comment->get('author'); $authorname = empty($author) ? $comment->get('authorname') : display_name($author, $user); $this->users[0]->htmlmessage = get_string_from_language($lang, 'feedbacknotificationhtml', 'artefact.comment', $authorname, $title, $posttime, $body, $this->url); $this->users[0]->emailmessage = get_string_from_language($lang, 'feedbacknotificationtext', 'artefact.comment', $authorname, $title, $posttime, trim(html2text($body)), $this->url); }
public function __construct($data) { parent::__construct($data); $this->overridemessagecontents = true; $post = get_record_sql(' SELECT p.subject, p.body, p.poster, p.parent, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id AS topicid, fp.subject AS topicsubject, f.title AS forumtitle, g.name AS groupname, f.id AS forumid FROM {interaction_forum_post} p INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic AND t.deleted = 0) INNER JOIN {interaction_forum_post} fp ON (fp.parent IS NULL AND fp.topic = t.id) INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted = 0) INNER JOIN {group} g ON (f.group = g.id AND g.deleted = 0) WHERE p.id = ? AND p.deleted = 0', array($this->postid)); // The post may have been deleted during the activity delay if (!$post) { $this->users = array(); return; } $subscribers = get_records_sql_assoc(' SELECT "user" AS subscriber, \'topic\' AS type, "key" FROM {interaction_forum_subscription_topic} WHERE topic = ? UNION SELECT "user" AS subscriber, \'forum\' AS type, "key" FROM {interaction_forum_subscription_forum} WHERE forum = ? ORDER BY type', array($post->topicid, $post->forumid)); $this->users = $subscribers ? activity_get_users($this->get_id(), array_keys($subscribers)) : array(); $this->fromuser = $post->poster; // When emailing forum posts, create Message-Id headers for threaded display by email clients $urlinfo = parse_url(get_config('wwwroot')); $hostname = $urlinfo['host']; $cleanforumname = str_replace('"', "'", strip_tags($post->forumtitle)); $this->customheaders = array('List-Id: "' . $cleanforumname . '" <forum' . $post->forumid . '@' . $hostname . '>', 'List-Help: ' . get_config('wwwroot') . 'interaction/forum/view.php?id=' . $post->forumid, 'Message-ID: <forumpost' . $this->postid . '@' . $hostname . '>'); if ($post->parent) { $this->customheaders[] = 'In-Reply-To: <forumpost' . $post->parent . '@' . $hostname . '>'; $this->customheaders[] = 'References: <forumpost' . $post->parent . '@' . $hostname . '>'; } $posttime = strftime(get_string('strftimedaydatetime'), $post->ctime); $htmlbody = $post->body; $this->message = strip_tags(str_shorten_html($htmlbody, 200, true)); // For internal notifications. $textbody = trim(html2text($post->body)); $postlink = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topicid . '#post' . $this->postid; $this->url = $postlink; $this->add_urltext(array('key' => 'Topic', 'section' => 'interaction.forum')); foreach ($this->users as &$user) { $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang; if ($post->parent) { $user->subject = get_string_from_language($lang, 'replyforumpostnotificationsubject', 'interaction.forum', $post->groupname, $post->forumtitle, $post->topicsubject); } else { $user->subject = get_string_from_language($lang, 'newforumpostnotificationsubject', 'interaction.forum', $post->groupname, $post->forumtitle, $post->subject); } $type = $subscribers[$user->id]->type; $unsubscribeid = $post->{$type . 'id'}; $unsubscribelink = get_config('wwwroot') . 'interaction/forum/unsubscribe.php?' . $type . '=' . $unsubscribeid . '&key=' . $subscribers[$user->id]->key; $user->emailmessage = get_string_from_language($lang, 'forumposttemplate', 'interaction.forum', $post->subject ? $post->subject : get_string_from_language($lang, 're', 'interaction.forum', $post->topicsubject), display_name($post->poster, $user), $posttime, $textbody, $postlink, $type, $unsubscribelink); $user->htmlmessage = get_string_from_language($lang, 'forumposthtmltemplate', 'interaction.forum', $post->subject ? $post->subject : get_string_from_language($lang, 're', 'interaction.forum', $post->topicsubject), display_name($post->poster, $user), $posttime, $htmlbody, $postlink, $unsubscribelink, $type); } }
if ((is_string($tmp=(isset($this->scope["VIEWS"]) ? $this->scope["VIEWS"] : null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)) { ?> <div id="userviewstable" class="viewlist fullwidth listing"> <?php $_fh1_data = (is_string($tmp=(isset($this->scope["VIEWS"]) ? $this->scope["VIEWS"] : null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp); if ($this->isArray($_fh1_data) === true) { foreach ($_fh1_data as $this->scope['item']) { /* -- foreach start output */ ?> <div class="<?php echo $this->classCall('cycle', array('default', 'r0,r1', true, true, ',', null, false));?> listrow"> <h3 class="title"><a href="<?php echo (is_string($tmp=$this->scope["item"]["fullurl"]) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp);?>"><?php echo (is_string($tmp=$this->scope["item"]["title"]) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp);?></a></h3> <?php if ((is_string($tmp=(isset($this->scope["item"]["description"]) ? $this->scope["item"]["description"]:null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)) { ?> <div class="detail"><?php echo preg_replace('#<[^>]*>#', ' ', str_shorten_html((isset($this->scope["item"]["description"]) ? $this->scope["item"]["description"]:null), 100, true));?></div> <?php }?> <?php if ((is_string($tmp=(isset($this->scope["item"]["tags"]) ? $this->scope["item"]["tags"]:null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)) { ?> <div class="tags"><strong><?php echo Dwoo_Plugin_str($this, 'tags', 'mahara', null, null, null, null, null);?>:</strong> <?php echo Dwoo_Plugin_list_tags($this, (is_string($tmp=(isset($this->scope["item"]["tags"]) ? $this->scope["item"]["tags"]:null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp), (is_string($tmp=(isset($this->scope["item"]["owner"]) ? $this->scope["item"]["owner"]:null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp));?></div> <?php }?> </div> <?php /* -- foreach end output */ } }?>
/** * Sets up groups for display in mygroups.php and find.php * * @param array $groups Initial group data, including the current user's * membership type in each group. See mygroups.php for * the query to build this information. * @param string $returnto Where forms generated for display should be told to return to */ function group_prepare_usergroups_for_display($groups, $returnto = 'mygroups') { if (!$groups) { return; } // Retrieve a list of all the group admins, for placing in each $group object $groupadmins = array(); $groupids = array_map(create_function('$a', 'return $a->id;'), $groups); if ($groupids) { $groupadmins = get_records_sql_array('SELECT "group", member FROM {group_member} WHERE "group" IN (' . implode(',', db_array_to_ph($groupids)) . ")\n AND role = 'admin'", $groupids); if (!$groupadmins) { $groupadmins = array(); } } $i = 0; foreach ($groups as $group) { $group->admins = array(); foreach ($groupadmins as $admin) { if ($admin->group == $group->id) { $group->admins[] = $admin->member; } } $group->description = str_shorten_html($group->description, 100, true); if ($group->membershiptype == 'member') { $group->canleave = group_user_can_leave($group->id); } else { if ($group->jointype == 'open') { $group->groupjoin = group_get_join_form('joingroup' . $i++, $group->id); } else { if ($group->membershiptype == 'invite') { $group->invite = group_get_accept_form('invite' . $i++, $group->id, $returnto); } else { if ($group->membershiptype == 'admin' && $group->requests > 1) { $group->requests = array($group->requests); } } } } } }
<form class="pieform" name="progresssidebarselect" method="post" action="" id="progresssidebarselect"> <table cellspacing="0"><tbody> <tr id="progresssidebarselect_institution_container" class="select"> <th><label for="progresssidebarselect_institution"><?php echo Dwoo_Plugin_str($this, 'profilecompletionforwhichinstitution', 'mahara', null, null, null, null, null);?></label></th> <td><select class="select autofocus" id="progresssidebarselect_institution" name="institution" tabindex="1" style=""> <?php $_fh8_data = (is_string($tmp=(isset($this->scope["sbdata"]["institutions"]) ? $this->scope["sbdata"]["institutions"]:null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp); if ($this->isArray($_fh8_data) === true) { foreach ($_fh8_data as $this->scope['inst']=>$this->scope['displayname']) { /* -- foreach start output */ ?> <option value="<?php echo (is_string($tmp=$this->scope["inst"]) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp);?>"<?php if ((is_string($tmp=(isset($this->scope["inst"]) ? $this->scope["inst"] : null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp) == (is_string($tmp=(isset($this->scope["sbdata"]["institution"]) ? $this->scope["sbdata"]["institution"]:null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp)) { ?> selected="selected"<?php }?>><?php echo str_shorten_html((is_string($tmp=(isset($this->scope["displayname"]) ? $this->scope["displayname"] : null)) ? htmlspecialchars($tmp, ENT_QUOTES, $this->charset) : $tmp), 25, true);?></option> <?php /* -- foreach end output */ } }?> </select></td> </tr> </tbody></table> </form> <?php }?> </div> <?php }?>
/** * format body * format lastposttime */ function setup_topics(&$topics) { if ($topics) { foreach ($topics as $topic) { $topic->body = str_shorten_html($topic->body, 50, true, false); $topic->lastposttime = relative_date(get_string('strftimerecentrelative', 'interaction.forum'), get_string('strftimerecent'), $topic->lastposttime); } } }
/** * used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display * @param $userlist the ids separated by commas * @return array containing the users in the order from $userlist */ function get_users_data($userlist) { global $USER; $sql = 'SELECT u.id, 0 AS pending, 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, NULL AS message FROM {usr} u WHERE u.id IN (' . $userlist . ') UNION SELECT u.id, 1 AS pending, COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages, NULL AS friendscontrol, NULL AS friend, NULL AS requestedfriendship, (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction, message FROM {usr} u JOIN {usr_friend_request} fr ON fr.requester = u.id WHERE fr.owner = ? AND u.id IN (' . $userlist . ')'; $userid = $USER->get('id'); $data = get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid)); foreach ($data as &$record) { if (isset($record->introduction)) { $record->introduction = str_shorten_html($record->introduction, 100, true); } $record->messages = $record->messages == 'allow' || $record->friend && $record->messages == 'friends' || $USER->get('admin') ? 1 : 0; $record->institutions = get_institution_string_for_user($record->id); } if (!$data || !($views = get_views(array_keys($data), null, null))) { $views = array(); } $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') { unset($view->{$key}); } } } } } foreach ($data as $friend) { if (isset($cleanviews[$friend->id])) { $friend->views = $cleanviews[$friend->id]; } if ($friend->pending) { $friend->accept = pieform(array('name' => 'acceptfriend' . $friend->id, 'successcallback' => 'acceptfriend_submit', 'renderer' => 'div', 'autofocus' => 'false', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('approverequest', 'group')), 'id' => array('type' => 'hidden', 'value' => $friend->id)))); } if (!$friend->friend && !$friend->pending && !$friend->requestedfriendship && $friend->friendscontrol == 'auto') { $friend->makefriend = pieform(array('name' => 'addfriend' . $friend->id, 'successcallback' => 'addfriend_submit', 'renderer' => 'div', 'autofocus' => 'false', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('addtofriendslist', 'group')), 'id' => array('type' => 'hidden', 'value' => $friend->id), 'query' => array('type' => 'hidden', 'value' => param_variable('query', '')), 'offset' => array('type' => 'hidden', 'value' => param_integer('offset', 0))))); } } $order = explode(',', $userlist); $ordereddata = array(); foreach ($order as $id) { if (isset($data[$id])) { $ordereddata[] = $data[$id]; } } return $ordereddata; }