/** * @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 function __construct($data) { parent::__construct($data); $this->users = activity_get_users($this->get_id(), $this->users); $post = get_record_sql('SELECT p.subject, p.body, p.poster, p.parent, t.id AS topicid, p2.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 INNER JOIN {interaction_forum_post} p2 ON (p2.parent IS NULL AND p2.topic = t.id) INNER JOIN {interaction_instance} f ON t.forum = f.id INNER JOIN {group} g ON f.group = g.id WHERE p.id = ?', array($this->postid)); $this->url = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topicid . '#post' . $this->postid; // 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('Precedence: Bulk', '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 . '>'; } foreach ($this->users as &$user) { if ($post->parent) { $user->subject = get_string('replytotopicby', 'interaction.forum', $post->groupname, $post->forumtitle, $post->topicsubject, display_name($post->poster, $user)); } else { $user->subject = get_string('newforumpostby', 'interaction.forum', $post->groupname, $post->forumtitle, display_name($post->poster, $user)); } $user->message = ($post->subject ? $post->subject . "\n" . str_repeat('-', strlen($post->subject)) . "\n" : '') . trim(html2text($post->body)); } $this->unsubscribename = $post->forumtitle; $this->unsubscribeurl = get_config('wwwroot') . 'interaction/forum/view.php?id=' . $post->forumid; }
public function __construct($data, $cron = false) { parent::__construct($data, $cron); $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.id AS groupid, 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; } // Set notification to site admins. $siteadmins = activity_get_users($this->get_id(), null, null, true); // Get forum moderators and admins. $forumadminsandmoderators = activity_get_users($this->get_id(), array_merge(get_forum_moderators($post->forumid), group_get_admin_ids($post->groupid))); // Populate users to notify list and get rid of duplicates. foreach (array_merge($siteadmins, $forumadminsandmoderators) as $user) { if (!isset($this->users[$user->id])) { $this->users[$user->id] = $user; } } // Record who reported it. $this->fromuser = $this->reporter; $post->posttime = strftime(get_string('strftimedaydatetime'), $post->ctime); $post->textbody = trim(html2text($post->body)); $post->htmlbody = clean_html($post->body); $this->url = 'interaction/forum/topic.php?id=' . $post->topicid . '&post=' . $this->postid . '&objection=1'; $this->add_urltext(array('key' => 'Topic', 'section' => 'interaction.forum')); if ($this->event === REPORT_OBJECTIONABLE) { $this->overridemessagecontents = true; $this->strings->subject = (object) array('key' => 'objectionablecontentpost', 'section' => 'interaction.forum', 'args' => array($post->topicsubject, display_default_name($this->reporter))); } else { if ($this->event === MAKE_NOT_OBJECTIONABLE) { $this->strings = (object) array('subject' => (object) array('key' => 'postnotobjectionablesubject', 'section' => 'interaction.forum', 'args' => array($post->topicsubject, display_default_name($this->reporter))), 'message' => (object) array('key' => 'postnotobjectionablebody', 'section' => 'interaction.forum', 'args' => array(display_default_name($this->reporter), display_default_name($post->poster)))); } else { if ($this->event === DELETE_OBJECTIONABLE_POST) { $this->url = ''; $this->strings = (object) array('subject' => (object) array('key' => 'objectionablepostdeletedsubject', 'section' => 'interaction.forum', 'args' => array($post->topicsubject, display_default_name($this->reporter))), 'message' => (object) array('key' => 'objectionablepostdeletedbody', 'section' => 'interaction.forum', 'args' => array(display_default_name($this->reporter), display_default_name($post->poster), $post->textbody))); } else { if ($this->event === DELETE_OBJECTIONABLE_TOPIC) { $this->url = ''; $this->strings = (object) array('subject' => (object) array('key' => 'objectionabletopicdeletedsubject', 'section' => 'interaction.forum', 'args' => array($post->topicsubject, display_default_name($this->reporter))), 'message' => (object) array('key' => 'objectionabletopicdeletedbody', 'section' => 'interaction.forum', 'args' => array(display_default_name($this->reporter), display_default_name($post->poster), $post->textbody))); } else { throw new SystemException(); } } } } $this->temp = (object) array('post' => $post); }
/** * @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); } }
public function __construct($data, $cron = false) { parent::__construct($data, $cron); }