/**
  * Get latest forum posts.
  *
  * @return array $posts
  *  Array contains latest forum posts. The first item is the newest post. Empty array if no post.
  */
 function getLatestForumPosts()
 {
     include_once e_PLUGIN . 'forum/forum_class.php';
     $posts = array();
     $db = e107::getDb();
     $forum = new e107forum();
     $forumList = implode(',', $forum->getForumPermList('view'));
     $limit = 10;
     $results = $db->select('forum_post', '*', 'post_forum IN (' . $forumList . ') ORDER BY post_datestamp DESC LIMIT 0, ' . $limit);
     if ($results) {
         while ($row = $db->fetch()) {
             $thread = new e_db_mysql();
             $user = new e_db_mysql();
             $posts[] = array('post' => $row, 'thread' => $thread->retrieve('forum_thread', '*', 'thread_id = ' . intval($row['post_thread'])), 'author' => $user->retrieve('user', '*', 'user_id = ' . intval($row['post_user'])));
             unset($thread);
             unset($user);
         }
     }
     return $posts;
 }
Пример #2
0
            $poster = $row['post_user_anon'];
        } else {
            if ($row['user_name']) {
                $poster = "<a href='" . e107::getUrl()->create('user/profile/view', array('name' => $row['user_name'], 'id' => $row['post_user'])) . "'>{$row['user_name']}</a>";
            } else {
                $poster = '[deleted]';
            }
        }
        $post = strip_tags($tp->toHTML($row['post_entry'], true, 'emotes_off, no_make_clickable', '', $pref['menu_wordwrap']));
        $post = $tp->text_truncate($post, $menu_pref['newforumposts_characters'], $menu_pref['newforumposts_postfix']);
        // Count previous posts for calculating proper (topic) page number for the current post.
        $postNum = $db->count('forum_post', '(*)', "WHERE post_id <= " . $row['post_id'] . " AND post_thread = " . $row['thread_id'] . " ORDER BY post_id ASC");
        // Calculate (topic) page number for the current post.
        $postPage = ceil($postNum / vartrue($plugForumPrefs['postspage'], 10));
        // Load thread for passing it to e107::url().
        $thread = $db->retrieve('forum_thread', '*', 'thread_id = ' . $row['thread_id']);
        // Create URL for post.
        // like: e107_plugins/forum/forum_viewtopic.php?id=1&p=2#post-55
        $url = e107::url('forum', 'topic', $thread, array('query' => array('p' => $postPage), 'fragment' => 'post-' . $row['post_id']));
        $text .= "<li>";
        if ($menu_pref['newforumposts_title']) {
            $text .= "<a href='{$url}'>{$topic}</a><br />{$post}<br /><small class='muted'>" . LAN_FORUM_MENU_001 . " {$poster} {$datestamp}</small>";
        } else {
            $text .= "<a href='{$url}'>" . LAN_FORUM_MENU_001 . "</a> {$poster} <small class='muted'>{$datestamp}</small><br />{$post}<br />";
        }
        $text .= "</li>";
    }
    $text .= "</ul>";
} else {
    $text = LAN_FORUM_MENU_002;
}