2006-12-02 04:36:16 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2009-11-17 13:48:46 +00:00
|
|
|
* e107 website system
|
|
|
|
*
|
2013-03-25 18:48:48 +01:00
|
|
|
* Copyright (C) 2008-2013 e107 Inc (e107.org)
|
2009-11-17 13:48:46 +00:00
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-01-10 14:40:09 +00:00
|
|
|
if (!defined('e107_INIT')) exit;
|
|
|
|
|
2015-02-02 15:19:13 -08:00
|
|
|
e107::lan('forum','menu',true); // English_menu.php or {LANGUAGE}_menu.php
|
2008-12-07 00:21:21 +00:00
|
|
|
include_once(e_PLUGIN.'forum/forum_class.php');
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
class forum_newforumposts_menu // plugin folder + menu name (without the .php)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2016-02-10 19:51:32 -08:00
|
|
|
|
|
|
|
private $plugPref = null;
|
|
|
|
private $menuPref = null;
|
|
|
|
private $forumObj = null;
|
|
|
|
|
|
|
|
function __construct()
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2016-02-10 19:51:32 -08:00
|
|
|
$this->forumObj = new e107forum;
|
|
|
|
$this->plugPref = e107::pref('forum'); // general forum preferences.
|
|
|
|
$this->menuPref = e107::getMenu()->pref();// ie. popup config details from within menu-manager.
|
|
|
|
|
|
|
|
$this->render();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getQuery()
|
|
|
|
{
|
|
|
|
$max_age = vartrue($this->menuPref['maxage'], 0);
|
2016-03-26 10:14:57 -07:00
|
|
|
$max_age = ($max_age == 0) ? '' : '(p.post_datestamp > '.(time()-(int)$max_age*86400).') AND ';
|
2016-02-10 19:51:32 -08:00
|
|
|
|
|
|
|
$forumList = implode(',', $this->forumObj->getForumPermList('view'));
|
|
|
|
|
|
|
|
$qry = "
|
|
|
|
SELECT
|
|
|
|
p.post_user, p.post_id, p.post_datestamp, p.post_user_anon, p.post_entry,
|
|
|
|
t.thread_id, t.thread_datestamp, t.thread_name, u.user_name, f.forum_sef
|
|
|
|
FROM `#forum_post` as p
|
|
|
|
|
|
|
|
LEFT JOIN `#forum_thread` AS t ON t.thread_id = p.post_thread
|
|
|
|
LEFT JOIN `#forum` as f ON f.forum_id = t.thread_forum_id
|
|
|
|
LEFT JOIN `#user` AS u ON u.user_id = p.post_user
|
|
|
|
WHERE {$max_age} p.post_forum IN ({$forumList})
|
|
|
|
ORDER BY p.post_datestamp DESC LIMIT 0, ".vartrue($this->menuPref['display'],10);
|
|
|
|
|
|
|
|
return $qry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: cache menu.
|
|
|
|
function render()
|
|
|
|
{
|
|
|
|
$tp = e107::getParser();
|
|
|
|
$sql = e107::getDb('nfp');
|
|
|
|
$pref = e107::getPref();
|
|
|
|
|
|
|
|
$qry = $this->getQuery();
|
|
|
|
|
|
|
|
|
|
|
|
if($results = $sql->gen($qry))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2016-03-23 19:34:17 -07:00
|
|
|
$text = "<ul class='newforumposts-menu'>";
|
2016-02-10 19:51:32 -08:00
|
|
|
|
|
|
|
while($row = $sql->fetch())
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2016-02-10 19:51:32 -08:00
|
|
|
$datestamp = $tp->toDate($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']));
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
$row['thread_sef'] = $this->forumObj->getThreadSef($row);
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
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]';
|
|
|
|
}
|
|
|
|
}
|
2015-12-18 11:09:33 +01:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
$post = strip_tags($tp->toHTML($row['post_entry'], true, 'emotes_off, no_make_clickable', '', $pref['menu_wordwrap']));
|
2016-03-23 19:34:17 -07:00
|
|
|
$post = $tp->text_truncate($post, varset($this->menuPref['characters'],120), varset($this->menuPref['postfix'],'...'));
|
2016-02-01 20:29:46 -08:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
// Count previous posts for calculating proper (topic) page number for the current post.
|
|
|
|
// $postNum = $sql2->count('forum_post', '(*)', "WHERE post_id <= " . $row['post_id'] . " AND post_thread = " . $row['thread_id'] . " ORDER BY post_id ASC");
|
|
|
|
// $postPage = ceil($postNum / vartrue($this->plugPref['postspage'], 10)); // Calculate (topic) page number for the current post.
|
|
|
|
// $thread = $sql->retrieve('forum_thread', '*', 'thread_id = ' . $row['thread_id']); // Load thread for passing it to e107::url().
|
2016-02-01 20:29:46 -08:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
// Create URL for post.
|
|
|
|
// like: e107_plugins/forum/forum_viewtopic.php?f=post&id=1
|
|
|
|
$url = e107::url('forum', 'topic', $row, array(
|
|
|
|
'query' => array(
|
|
|
|
'f' => 'post',
|
|
|
|
'id' => intval($row['post_id']) // proper page number
|
|
|
|
),
|
|
|
|
));
|
2016-02-01 20:29:46 -08:00
|
|
|
|
2016-02-10 19:51:32 -08:00
|
|
|
|
|
|
|
$text .= "<li>";
|
|
|
|
|
2016-12-17 10:15:10 -08:00
|
|
|
if (!empty($this->menuPref['title']))
|
2016-02-10 19:51:32 -08:00
|
|
|
{
|
|
|
|
$text .= "<a href='{$url}'>{$topic}</a><br />{$post}<br /><small class='text-muted muted'>".LAN_FORUM_MENU_001." {$poster} {$datestamp}</small>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$text .= "<a href='{$url}'>".LAN_FORUM_MENU_001."</a> {$poster} <small class='text-muted muted'>{$datestamp}</small><br />{$post}<br />";
|
|
|
|
}
|
|
|
|
|
|
|
|
$text .= "</li>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$text .= "</ul>";
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-10 19:51:32 -08:00
|
|
|
$text = LAN_FORUM_MENU_002;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2016-02-10 19:51:32 -08:00
|
|
|
|
2016-03-23 19:34:17 -07:00
|
|
|
|
2016-03-25 11:24:07 -07:00
|
|
|
if(!empty($this->menuPref['caption']))
|
2016-03-23 19:34:17 -07:00
|
|
|
{
|
2016-03-25 11:24:07 -07:00
|
|
|
$caption = !empty($this->menuPref['caption'][e_LANGUAGE]) ? $this->menuPref['caption'][e_LANGUAGE] : $this->menuPref['caption'];
|
2016-03-23 19:34:17 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$caption = LAN_PLUGIN_FORUM_LATESTPOSTS;
|
|
|
|
}
|
|
|
|
|
2016-03-26 10:14:57 -07:00
|
|
|
// e107::debug('menuPref', $this->menuPref);
|
|
|
|
|
2016-02-11 11:21:03 -08:00
|
|
|
e107::getRender()->tablerender($caption, $text, 'nfp_menu');
|
2016-02-10 19:51:32 -08:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2016-02-10 19:51:32 -08:00
|
|
|
|
2008-12-07 00:21:21 +00:00
|
|
|
}
|
2016-02-10 19:51:32 -08:00
|
|
|
|
|
|
|
new forum_newforumposts_menu;
|
|
|
|
|
|
|
|
|
|
|
|
|