/**
  * 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;
 }
Beispiel #2
0
 /**
  * Garbage collection
  * @param integer $session_maxlf ignored - see write()
  * @return boolean
  */
 public function gc($session_maxlf)
 {
     $this->_db->db_Delete($this->getTable(), '`session_expires`<' . time());
     return true;
 }
$pref = e107::getPref();
e107::lan('forum', 'menu', true);
// English_menu.php or {LANGUAGE}_menu.php
// include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_newforumposts_menu.php');
// include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/'.e_LANGUAGE.'_menu.php');
include_once e_PLUGIN . 'forum/forum_class.php';
$max_age = vartrue($menu_pref['newforumposts_maxage'], 0);
$max_age = $max_age == 0 ? '' : '(t.post_datestamp > ' . (time() - (int) $max_age * 86400) . ') AND ';
$forum = new e107forum();
$forumList = implode(',', $forum->getForumPermList('view'));
//TODO: Use query from forum class to get thread list
$qry = "\nSELECT\n\tp.post_user, p.post_id, p.post_datestamp, p.post_user_anon, p.post_entry,\n\tt.thread_id, t.thread_datestamp, t.thread_name, u.user_name\nFROM `#forum_post` as p\nLEFT JOIN `#forum_thread` AS t ON t.thread_id = p.post_thread\nLEFT JOIN `#user` AS u ON u.user_id = p.post_user\nWHERE {$maxage} p.post_forum IN ({$forumList})\nORDER BY p.post_datestamp DESC LIMIT 0, " . $menu_pref['newforumposts_display'];
// Get forum plugin preferences.
$plugForumPrefs = e107::getPlugConfig('forum')->getPref();
// New MySQL class instantiation to avoid overrides.
$db = new e_db_mysql();
// TODO: cache menu.
if ($results = $sql->gen($qry)) {
    $text = "<ul>";
    while ($row = $sql->fetch(MYSQL_ASSOC)) {
        $datestamp = $gen->convert_date($row['post_datestamp'], 'relative');
        $id = $row['thread_id'];
        $topic = $row['thread_datestamp'] == $row['post_datestamp'] ? '' : 'Re:';
        $topic .= strip_tags($tp->toHTML($row['thread_name'], true, 'emotes_off, no_make_clickable, parse_bb', '', $pref['menu_wordwrap']));
        if ($row['post_user_anon']) {
            $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]';