示例#1
0
    $lastpost = get_record_select('interaction_forum_post', 'topic = ? ORDER by ctime DESC, id DESC LIMIT 1', array($topicid));
    $lastpostid = $lastpost->id;
}
// Get extra info of posts
$prevdeletedid = false;
foreach ($posts as $postid => $post) {
    // Get the number of posts
    $post->postcount = get_postcount($post->poster);
    $post->canedit = $post->parent && ($moderator || user_can_edit_post($post->poster, $post->ctime)) && $ineditwindow;
    $post->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $post->ctime);
    // Get post edit records
    $post->edit = get_postedits($post->id);
    // Get moderator info
    $post->moderator = is_moderator($post->poster) ? $post->poster : null;
    // Update the subject of posts
    $post->subject = !empty($post->subject) ? $post->subject : get_string('re', 'interaction.forum', get_ancestorpostsubject($post->id));
    // If this is the own post
    $post->ownpost = $USER->get('id') == $post->poster ? true : false;
    // Reported reason data
    $post->reports = get_records_select_array('objectionable', 'objecttype = ? AND objectid = ? AND resolvedby IS NULL AND resolvedtime IS NULL', array('forum', $post->id));
    // Consolidate deleted message posts by the same author into one "X posts by Spammer Joe were deleted"
    if ($post->deleted) {
        if ($prevdeletedid && $posts[$prevdeletedid]->poster == $post->poster) {
            $posts[$prevdeletedid]->deletedcount++;
            unset($posts[$postid]);
        } else {
            $prevdeletedid = $postid;
            $post->deletedcount = 1;
        }
    } else {
        $prevdeletedid = false;
示例#2
0
文件: lib.php 项目: vohung96/mahara
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $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;
     }
     // A user may be subscribed via the forum or the specific topic. If they're subscribed to both, we want
     // to focus on the topic subscription because it's more specific.
     $sql = '
         SELECT
             subq2.subscriber,
             (CASE WHEN subq2.topickey IS NOT NULL THEN subq2.topickey ELSE subq2.forumkey END) AS "key",
             (CASE WHEN subq2.topickey IS NOT NULL THEN \'topic\' ELSE \'forum\' END) AS "type"
         FROM (
             SELECT subq1.subscriber, max(topickey) AS topickey, max(forumkey) AS forumkey
             FROM (
                 SELECT "user" AS subscriber, "key" AS topickey, NULL AS forumkey FROM {interaction_forum_subscription_topic} WHERE topic = ?
                 UNION ALL
                 SELECT "user" AS subscriber, NULL AS topickey, "key" AS forumkey FROM {interaction_forum_subscription_forum} WHERE forum = ?
             ) subq1
             GROUP BY subq1.subscriber
         ) subq2
         INNER JOIN {usr} u ON subq2.subscriber = u.id
         WHERE u.deleted = 0
     ';
     $params = array($post->topicid, $post->forumid);
     if ($cron) {
         $sql .= ' AND subq2.subscriber > ? ';
         $params[] = (int) $data->last_processed_userid;
         $limitfrom = 0;
         $limitnum = self::USERCHUNK_SIZE;
     } else {
         $limitfrom = '';
         $limitnum = '';
     }
     $sql .= ' ORDER BY subq2.subscriber';
     $subscribers = get_records_sql_assoc($sql, $params, $limitfrom, $limitnum);
     $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 = clean_email_headers($post->forumtitle);
     $cleangroupname = clean_email_headers($post->groupname);
     $cleanforumname = str_replace('"', "'", strip_tags($cleanforumname));
     $cleangroupname = str_replace('"', "'", strip_tags($cleangroupname));
     $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 . '>', 'X-Mahara-Group: ' . $cleangroupname, 'X-Mahara-Forum: ' . $cleanforumname);
     if ($post->parent) {
         $this->customheaders[] = 'In-Reply-To: <forumpost' . $post->parent . '@' . $hostname . '>';
         $this->customheaders[] = 'References: <forumpost' . $post->parent . '@' . $hostname . '>';
     }
     $post->posttime = strftime(get_string('strftimedaydatetime'), $post->ctime);
     // Some messages are all html and when they're 'cleaned' with
     // strip_tags(str_shorten_html($post->body, 200, true)) for display,
     // they are left empty. Use html2text instead.
     $this->message = str_shorten_text(trim(html2text($post->body)), 200, true);
     // For internal notifications.
     $post->textbody = trim(html2text($post->body));
     $post->htmlbody = clean_html($post->body);
     $this->url = 'interaction/forum/topic.php?id=' . $post->topicid . '&post=' . $this->postid;
     $this->add_urltext(array('key' => 'Topic', 'section' => 'interaction.forum'));
     $this->strings->subject = (object) array('key' => 'newforumpostnotificationsubjectline', 'section' => 'interaction.forum', 'args' => array($post->subject ? $post->subject : get_string('Re:', 'interaction.forum') . ($post->parent ? get_ancestorpostsubject($post->parent, true) : $post->topicsubject)));
     foreach ($this->users as &$user) {
         $user->subscribetype = $subscribers[$user->id]->type;
         $user->unsubscribekey = $subscribers[$user->id]->key;
     }
     $this->temp = (object) array('post' => $post);
 }