public function get_owner_object() { if (empty($this->owner)) { return false; } if (!isset($this->ownerobj)) { $this->ownerobj = get_user_for_display($this->get('owner')); } return $this->ownerobj; }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $configdata = $instance->get('configdata'); $view = $instance->get('view'); $full = isset($configdata['full']) ? $configdata['full'] : false; $results = array(); $smarty = smarty_core(); $smarty->assign('view', $view); $viewownerdisplay = null; // Display all posts, from all blogs, owned by this user $tagsin = $tagsout = array(); $results = self::get_blog_posts_in_block($instance, $tagsin, $tagsout); if ($tagsin || $tagsout) { $smarty->assign('blockid', $instance->get('id')); $smarty->assign('editing', $editing); if ($editing) { // Get list of blogs owned by this user to create the "Add new post" shortcut while editing $viewowner = $instance->get_view()->get('owner'); if (!$viewowner || !($blogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($viewowner), 'title ASC', 'id, title'))) { $blogs = array(); } $smarty->assign('tagselect', implode(', ', $tagsin)); $smarty->assign('blogs', $blogs); } // if posts are not found with the selected tag, notify the user if (!$results) { $smarty->assign('badtag', implode(', ', $tagsin)); $smarty->assign('badnotag', implode(', ', $tagsout)); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } // update the view_artefact table so journal entries are accessible when this is the only block on the page // referencing this journal $dataobject = array('view' => $view, 'block' => $instance->get('id')); require_once get_config('docroot') . 'lib/view.php'; $viewobj = new View($view); require_once get_config('docroot') . 'artefact/lib.php'; safe_require('artefact', 'blog'); safe_require('artefact', 'comment'); foreach ($results as $result) { $dataobject["artefact"] = $result->parent; $result->postedbyon = get_string('postedbyon', 'artefact.blog', display_default_name($result->owner), format_date(strtotime($result->ctime))); $result->displaydate = format_date(strtotime($result->ctime)); $artefact = new ArtefactTypeBlogpost($result->id); // get comments for this post $result->commentcount = count_records_select('artefact_comment_comment', "onartefact = {$result->id} AND private = 0 AND deletedby IS NULL"); $allowcomments = $artefact->get('allowcomments'); if (empty($result->commentcount) && empty($allowcomments)) { $result->commentcount = null; } list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $viewobj, null, false); $result->comments = $comments; // get all tags for this post $taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC"); foreach ($taglist as $t) { $result->taglist[] = $t->tag; } if ($full) { $rendered = $artefact->render_self(array('viewid' => $view, 'details' => true, 'blockid' => $instance->get('id'))); $result->html = $rendered['html']; if (!empty($rendered['javascript'])) { $result->html .= '<script type="application/javascript">' . $rendered['javascript'] . '</script>'; } } } // check if the user viewing the page is the owner of the selected tag $owner = $results[0]->owner; if ($USER->id != $owner) { $viewownerdisplay = get_user_for_display($owner); } $smarty->assign('tagsin', $tagsin); $smarty->assign('tagsout', $tagsout); } else { if (!self::get_chooseable_tags()) { // error if block configuration fails $smarty->assign('configerror', get_string('notagsavailableerror', 'blocktype.blog/taggedposts')); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } else { // error if block configuration fails $smarty->assign('configerror', get_string('configerror', 'blocktype.blog/taggedposts')); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } } // add any needed links to the tags $tagstr = $tagomitstr = ''; foreach ($tagsin as $key => $tag) { if ($key > 0) { $tagstr .= ', '; } $tagstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"'; } if (!empty($tagsout)) { foreach ($tagsout as $key => $tag) { if ($key > 0) { $tagomitstr .= ', '; } $tagomitstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"'; } } $blockheading = get_string('blockheadingtags', 'blocktype.blog/taggedposts', count($tagsin), $tagstr); $blockheading .= !empty($tagomitstr) ? get_string('blockheadingtagsomit', 'blocktype.blog/taggedposts', count($tagsout), $tagomitstr) : ''; $blockheading .= $viewownerdisplay ? ' ' . get_string('by', 'artefact.blog') . ' <a href="' . profile_url($viewownerdisplay) . '">' . display_name($viewownerdisplay) . '</a>' : ''; $smarty->assign('full', $full); $smarty->assign('results', $results); $smarty->assign('blockheading', $blockheading); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $configdata = $instance->get('configdata'); $view = $instance->get('view'); $limit = isset($configdata['count']) ? (int) $configdata['count'] : 10; $full = isset($configdata['full']) ? $configdata['full'] : false; $results = array(); $smarty = smarty_core(); $smarty->assign('view', $view); // Display all posts, from all blogs, owned by this user if (!empty($configdata['tagselect'])) { $tagselect = $configdata['tagselect']; $sql = 'SELECT a.title, p.title AS parenttitle, a.id, a.parent, a.owner, a.description, a.allowcomments, at.tag, a.ctime FROM {artefact} a JOIN {artefact} p ON a.parent = p.id JOIN {artefact_blog_blogpost} ab ON (ab.blogpost = a.id AND ab.published = 1) JOIN {artefact_tag} at ON (at.artefact = a.id) WHERE a.artefacttype = \'blogpost\' AND a.owner = (SELECT "owner" from {view} WHERE id = ?) AND at.tag = ? ORDER BY a.ctime DESC, a.id DESC LIMIT ?'; $results = get_records_sql_array($sql, array($view, $tagselect, $limit)); $smarty->assign('blockid', $instance->get('id')); $smarty->assign('editing', $editing); if ($editing) { // Get list of blogs owned by this user to create the "Add new post" shortcut while editing $viewowner = $instance->get_view()->get('owner'); if (!$viewowner || !($blogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($viewowner), 'title ASC', 'id, title'))) { $blogs = array(); } $smarty->assign('tagselect', $tagselect); $smarty->assign('blogs', $blogs); } // if posts are not found with the selected tag, notify the user if (!$results) { $smarty->assign('badtag', $tagselect); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } // update the view_artefact table so journal entries are accessible when this is the only block on the page // referencing this journal $dataobject = array('view' => $view, 'block' => $instance->get('id')); foreach ($results as $result) { $dataobject["artefact"] = $result->parent; ensure_record_exists('view_artefact', $dataobject, $dataobject); $result->postedbyon = get_string('postedbyon', 'artefact.blog', display_default_name($result->owner), format_date(strtotime($result->ctime))); $result->displaydate = format_date(strtotime($result->ctime)); // get comment count for this post $result->commentcount = count_records_select('artefact_comment_comment', "onartefact = {$result->id} AND private = 0 AND deletedby IS NULL"); // get all tags for this post $taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC"); foreach ($taglist as $t) { $result->taglist[] = $t->tag; } } // check if the user viewing the page is the owner of the selected tag $owner = $results[0]->owner; if ($USER->id != $owner) { $viewowner = get_user_for_display($owner); $smarty->assign('viewowner', $viewowner); } $smarty->assign('tag', $tagselect); } else { // error if block configuration fails $smarty->assign('configerror', true); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } $smarty->assign('full', $full); $smarty->assign('results', $results); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); }
/** * Return profile icon url for a user. Use this to quickly get a url * when you already have a bunch of user records with profileicon id & * email address. * * Avoids reloading the 'no user photo' image for each user separately * when we know they have no profile icon, and avoids the redirect to * gravatar. * * @param int|object|array $user A user ID, user object, or user data array. If an * object, should contain profileicon or email attributes, or a user ID. * @param int $maxwidth * @param int $maxheight * @return bool|string The URL of the image or FALSE if none was found */ function profile_icon_url($user, $maxwidth = 40, $maxheight = 40) { // Getting icon when feedback is done by anonymous user if (empty($user)) { return anonymous_icon_url($maxwidth, $maxheight); } $user = get_user_for_display($user); // If we were originally passed a $user that was lacking profileicon and email, // get_user_for_display() usually won't have found it for us. So we should try // to fill that in now, and then cache it for later calls. if (!isset($user->profileicon) && !isset($user->email)) { if (!isset($user->id) || !is_numeric($user->id)) { // No data. We'll just show the anonymous icon, but log a warning message for the devs. log_debug("profile_icon_url was passed a user object without a numeric id, a profileicon, or an email address. This is probably a coding error."); } else { $user = get_record('usr', 'id', $user->id, null, null, null, null, 'id, profileicon, email'); // Cache this for subsequent calls $user = get_user_for_display($user); } } // Available sizes of the 'no_userphoto' image: $allowedsizes = array(16, 20, 25, 40, 50, 60, 100); if ($maxwidth != $maxheight || !in_array($maxwidth, $allowedsizes)) { log_warn('profile_icon_url: maxwidth, maxheight should be equal and in (' . join(', ', $allowedsizes) . ')'); } $thumb = get_config('wwwroot') . 'thumb.php'; $sizeparams = 'maxwidth=' . $maxwidth . '&maxheight=' . $maxheight; if (!empty($user->profileicon)) { return $thumb . '?type=profileiconbyid&' . $sizeparams . '&id=' . $user->profileicon; } return anonymous_icon_url($maxwidth, $maxheight, !empty($user->email) ? $user->email : null); }
/** * creates a result-array with the number, limit, offset and notification-type(s) * of the returned htmlrepresentation of the notifications in the outbox, as well * as the html representation itself. The return array has the following format: * * array ( * 'count' => '17', * 'limit' => 10, * 'offset' => 0, * 'type' => 'all', * 'html' => '//html ... * 'pagination' => '// html * 'pagination_js' => '// javascript * ) * * @global User $USER * @param type $type * @param type $limit * @param type $offset * @return array */ function activitylistout_html($type = 'all', $limit = 10, $offset = 0) { global $USER; $userid = $USER->get('id'); $typesql = ''; if ($type != 'all') { // Treat as comma-separated list of activity type names $types = split(',', preg_replace('/[^a-z,]+/', '', $type)); if ($types) { $typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')'; if (in_array('adminmessages', $types)) { $typesql = '(' . $typesql . ' OR at.admin = 1)'; } $typesql = ' AND ' . $typesql; } } $notificationtargetcolumn = 'from'; $notificationtargetrole = 'sender'; $msgidquery = "\n (\n SELECT a.id, a.ctime, 'notification_internal_activity' AS msgtable\n FROM {notification_internal_activity} AS a\n INNER JOIN {activity_type} AS at ON a.type = at.id\n WHERE a." . $notificationtargetcolumn . " = ?\n " . $typesql . "\n AND at.name != 'newpost'\n )\n UNION\n (\n SELECT a.id, a.ctime, 'module_multirecipient_notification' AS msgtable\n FROM {module_multirecipient_notification} AS a\n INNER JOIN {module_multirecipient_userrelation} AS b\n ON a.id = b.notification\n INNER JOIN {activity_type} AS at ON a.type = at.id\n WHERE b.usr = ?\n AND b.deleted = '0'\n AND b.role = '" . $notificationtargetrole . "'\n " . $typesql . "\n )"; $countquery = 'SELECT COUNT(*) FROM (' . $msgidquery . ') AS dummytable'; $count = count_records_sql($countquery, array($userid, $userid)); $pagination = build_pagination(array('id' => 'activitylist_pagination', 'url' => get_config('wwwroot') . 'module/multirecipientnotification/outbox.php?type=' . hsc($type), 'jsonscript' => 'module/multirecipientnotification/indexout.json.php', 'datatable' => 'activitylist', 'count' => $count, 'limit' => $limit, 'offset' => $offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2, 'setlimit' => true)); $result = array('count' => $count, 'limit' => $limit, 'offset' => $offset, 'type' => $type, 'html' => '', 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript']); if ($count < 1) { return $result; } $records = array(); $msgidquery .= "\n ORDER BY ctime DESC"; $msgidrecords = get_records_sql_array($msgidquery, array($userid, $userid), $offset, $limit); if (!is_array($msgidrecords)) { $msgidrecords = array(); } foreach ($msgidrecords as $msgidrecord) { if ($msgidrecord->msgtable == 'notification_internal_activity') { $recordsarray = get_records_sql_array("SELECT a.*, at.name AS type, at.plugintype, at.pluginname\n FROM {notification_internal_activity} a\n INNER JOIN {activity_type} at ON a.type = at.id\n WHERE a.id = ?", array($msgidrecord->id)); if (1 !== count($recordsarray)) { log_warn('inconsistent message-id in notification_internal_activity, id: ' . $msgidrecord->id); continue; } $record = $recordsarray[0]; $record->self = false; $record->canreplyall = false; $record->canreply = false; $record->startnewthread = true; // read out receiver name if (isset($record->usr)) { $tousrarray = array('display' => display_name($record->usr), 'link' => null); if (!get_user($record->usr)->deleted) { $tousrarray['link'] = profile_url($record->usr); $record->canreply = true; } $record->tousr = array($tousrarray); $record->self = $record->from == $USER->get('id'); } else { $record->tousr = array(array('display' => get_string('system'), 'link' => null)); $record->self = true; } // read out sender name if (isset($record->from)) { $record->fromusr = $record->from; } else { // we're in the outbox, so basically, this should hold for all messages $record->fromusr = $USER->get('id'); } $record->date = format_date(strtotime($record->ctime), 'strfdaymonthyearshort'); $section = empty($record->plugintype) ? 'activity' : "{$record->plugintype}.{$record->pluginname}"; $record->strtype = get_string('type' . $record->type, $section); $record->message = format_notification_whitespace($record->message); // used to identify notification as internal for json-calls $record->table = 'notification_internal_activity'; $records[] = $record; } else { if ($msgidrecord->msgtable === 'module_multirecipient_notification') { $record = get_message_mr($userid, $msgidrecord->id); if (null === $record) { continue; } $record->strtype = $record->type; $record->date = format_date(strtotime($record->ctime), 'strfdaymonthyearshort'); // We fill $record->tousr with an array per userentry, that holds the // display name of the user and the link to the users profile, if // applicable - we don't link to deleted users. Those will be summed // up in a single entry at the end of the list $deletedcount = 0; $record->self = false; $record->canreply = false; $record->canreplyall = false; $record->startnewthread = false; for ($i = 0; $i < count($record->userids); $i++) { $tousr = get_user($record->userids[$i]); if ($tousr->deleted) { $deletedcount++; } else { $record->tousr[] = array('username' => display_username(get_user_for_display($record->userids[$i])), 'display' => display_name($record->userids[$i]), 'link' => profile_url($record->userids[$i])); } } if ($deletedcount > 0) { $record->tousr[] = array('username' => $deletedcount . ' ' . get_string('deleteduser', 'module.multirecipientnotification'), 'display' => $deletedcount . ' ' . get_string('deleteduser', 'module.multirecipientnotification'), 'link' => null); } if ($deletedcount < count($record->userids)) { if (count($record->userids) - $deletedcount == 1) { $record->canreply = true; $record->self = $record->fromid == $USER->get('id'); } else { $record->canreplyall = true; } } if (isset($record->fromid)) { $record->fromusr = $record->fromid; } else { $record->fromusr = 0; } $record->message = format_notification_whitespace($record->message); // used to identify notification as from this plugin for json-calls $record->table = 'module_multirecipient_notification'; $records[] = $record; } } } $smarty = smarty_core(); $smarty->assign('data', $records); $smarty->assign('USER', $USER); $smarty->assign('maxnamestrlength', PluginModuleMultirecipientnotification::MAX_USERNAME_IN_LIST_LENGTH); $result['html'] = $smarty->fetch('module:multirecipientnotification:activitylistout.tpl'); return $result; }