1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 19:30:25 +02:00

Issue #1336 and Forum menu prefs upgrade and newforumpost_menu fix. e_menu.php pending.

This commit is contained in:
Cameron
2016-02-10 19:51:32 -08:00
parent a9eb2bd727
commit 550968d78a
7 changed files with 287 additions and 106 deletions

View File

@@ -41,6 +41,11 @@ class e_menu
*/
protected $_visibility_cache = array();
protected $_current_menu = null;
protected $_current_parms = array();
/**
* Constructor
*
@@ -126,10 +131,17 @@ class e_menu
}
return $data;
}
}
/**
* Return the preferences/parms for the current menu.
* @return array
*/
public function pref()
{
return $this->_current_parms;
}
/**
@@ -184,6 +196,21 @@ class e_menu
}
/**
* Set Parms for a specific menu.
* @param string $plugin ie. plugin folder name.
* @param string $menu menu name. including the _menu but not the .php
* @param array $parms
* @param string|int $location default 'all' or a menu area number..
* @return int|boolean number of records updated or false.
*/
public function setParms($plugin, $menu, $parms=array(), $location = 'all')
{
$qry = 'menu_parms="'.e107::serialize($parms).'" WHERE menu_parms="" AND menu_path="'.$plugin.'/" AND menu_name="'.$menu.'" ';
$qry .= ($location != 'all') ? 'menu_location='.intval($location) : '';
return e107::getDb()->update('menus', $qry);
}
/**
@@ -403,7 +430,7 @@ class e_menu
// global $sql; // required at the moment.
global $sc_style, $e107_debug;
$e107 = e107::getInstance();
$sql = e107::getDb();
$ns = e107::getRender();
$tp = e107::getParser();
@@ -414,6 +441,10 @@ class e_menu
unset($tmp);
}
$this->_current_parms = $parm;
$this->_current_menu = $mname;
if($return)
{
ob_start();

View File

@@ -877,6 +877,54 @@ final class e_core_pref extends e_pref
$prefid = trim($prefid);
return array_search($prefid, $this->aliases);
}
/**
* Export data from core pref and remove if needed. Useful for core pref -> menu table parm migration.
* @param array $prefList key/value pairs. key = oldpref value = new pref key
* @param bool|false $remove
* @return array|false if no match found.
*/
public function migrateData($prefList=array(), $remove=false)
{
$data = self::getData();
$array = array();
$save = false;
if(empty($prefList))
{
return false;
}
foreach($data as $k=>$v)
{
if(isset($prefList[$k]))
{
$key = $prefList[$k];
$array[$key] = $v;
if($remove == true)
{
self::remove($k);
$save = true;
}
}
}
if(empty($array))
{
return false;
}
if(!empty($save))
{
self::save(false,true,false);
}
return $array;
}
}
/**

View File

@@ -99,9 +99,11 @@ if(!deftrue('OLD_FORUMADMIN'))
{
$this->adminMenu['opt3'] = array('divider'=>true);
$this->adminMenu['main/update'] = array('caption'=>"Redo v1.x Forum Upgrade", 'perm'=>0, 'uri'=>'{e_PLUGIN}forum/forum_update.php');
}
}
}
}
@@ -258,6 +260,11 @@ if(!deftrue('OLD_FORUMADMIN'))
require_once(e_PLUGIN.'forum/forum_class.php');
$this->forumObj = new e107forum;
if(E107_DEBUG_LEVEL > 0) // check fpr legacy prefs in debug mode. Should normally be done during upgrade.
{
$this->forumObj->upgradeLegacyPrefs();
}
if (!empty($_POST['do_prune']) && !empty($_POST['prune_days']) && !empty($_POST['pruneForum']))
{

View File

@@ -745,7 +745,7 @@ class e107forum
$postInfo['post_thread'] = $newThreadId;
$newPostId = $this->postAdd($postInfo, false);
$this->threadMarkAsRead($newThreadId);
$threadInfo['thread_sef'] = eHelper::title2sef($threadInfo['thread_name'],'dashl');
$threadInfo['thread_sef'] = $this->getThreadsef($threadInfo);
return array('postid' => $newPostId, 'threadid' => $newThreadId, 'threadsef'=>$threadInfo['thread_sef']);
}
@@ -753,6 +753,12 @@ class e107forum
}
function getThreadSef($threadInfo)
{
return eHelper::title2sef($threadInfo['thread_name'],'dashl');
}
function threadMove($threadId, $newForumId, $threadTitle= '', $titleType=0)
{
@@ -2198,6 +2204,42 @@ class e107forum
return $deleted; // return boolean. $threadInfo['thread_total_replies'];
}
/**
* Check for legacy Prefernces and upgrade if neccessary.
*/
public function upgradeLegacyPrefs()
{
e107::getMessage()->addDebug("Legacy Forum Menu Pref Detected. Upgrading..");
$legacyMenuPrefs = array(
'newforumposts_caption' => 'caption',
'newforumposts_display' => 'display',
'newforumposts_maxage' => 'maxage',
'newforumposts_characters' => 'chars',
'newforumposts_postfix' => 'postfix',
'newforumposts_title' => 'title'
);
if($newPrefs = e107::getConfig('menu')->migrateData($legacyMenuPrefs, true)) // returns false if no match found.
{
if(e107::getMenu()->setParms('forum','newforumposts_menu', $newPrefs) !== false)
{
e107::getMessage()->addDebug("Sucessfully Migrated newforumposts prefs from core to menu table. ");
}
else
{
e107::getMessage()->addDebug("Legacy Forum Menu Pref Detected. Upgrading..");
}
}
}
}

View File

@@ -65,6 +65,12 @@ class forum_setup
e107::getDb()->gen("ALTER TABLE `#forum_thread` DROP `thread_sef` ");
}
$legacyMenuPref = e107::getConfig('menu')->getPref();
if(isset($legacyMenuPref['newforumposts_caption']))
{
}
return false;
}

View File

@@ -353,6 +353,15 @@ function step4()
$fconf -> setPref($old_prefs) -> save(false, true);
$coreConfig -> save(false, true);
// -----Upgrade old menu prefs ----------------
global $forum;
$forum->upgradeLegacyPrefs();
// --------------------
$result = array(
'usercount' => 0,
'viewcount' => 0,
@@ -1268,7 +1277,7 @@ function step12()
class forumUpgrade
{
var $newVersion = '2.0';
private $newVersion = '2.0';
var $error = array();
public $updateInfo;
private $attachmentData;
@@ -1365,10 +1374,12 @@ class forumUpgrade
function setNewVersion()
{
$sql = e107::getDb();
// $sql = e107::getDb();
$sql -> update('plugin', "plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum'");
e107::getConfig()->setPref('plug_installed/forum', $this->newVersion)->save(false,true,false);
// $sql -> update('plugin', "plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum' OR plugin_name = 'LAN_PLUGIN_FORUM_NAME'");
// e107::getConfig()->setPref('plug_installed/forum', $this->newVersion)->save(false,true,false);
e107::getPlugin()->refresh('forum');
return "Forum Version updated to version: {$this->newVersion} <br />";
}

View File

@@ -10,109 +10,145 @@
if (!defined('e107_INIT')) exit;
global $menu_pref;
$e107 = e107::getInstance();
$tp = e107::getParser();
$sql = e107::getDb();
$gen = new convert;
$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 = "
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
FROM `#forum_post` as p
LEFT JOIN `#forum_thread` AS t ON t.thread_id = p.post_thread
LEFT JOIN `#user` AS u ON u.user_id = p.post_user
WHERE {$maxage} p.post_forum IN ({$forumList})
ORDER 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))
class forum_newforumposts_menu // plugin folder + menu name (without the .php)
{
$text = "<ul>";
while($row = $sql->fetch(MYSQL_ASSOC))
private $plugPref = null;
private $menuPref = null;
private $forumObj = null;
function __construct()
{
$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]';
}
}
$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.
$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']);
$this->render();
// 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, // proper page number
),
'fragment' => 'post-' . $row['post_id'], // jump page to post
));
//FIXME Use f=post/id query.
$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>";
function getQuery()
{
$max_age = vartrue($this->menuPref['maxage'], 0);
$max_age = ($max_age == 0) ? '' : '(t.post_datestamp > '.(time()-(int)$max_age*86400).') AND ';
$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))
{
$text = "<ul>";
while($row = $sql->fetch())
{
$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']));
$row['thread_sef'] = $this->forumObj->getThreadSef($row);
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]';
}
}
$post = strip_tags($tp->toHTML($row['post_entry'], true, 'emotes_off, no_make_clickable', '', $pref['menu_wordwrap']));
$post = $tp->text_truncate($post, $this->menuPref['characters'], $this->menuPref['postfix']);
// 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().
// 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
),
));
$text .= "<li>";
if ($this->menuPref['title'])
{
$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>";
}
else
{
$text = LAN_FORUM_MENU_002;
}
e107::getRender()->tablerender($this->menuPref['caption'], $text, 'nfp_menu');
}
}
else
{
$text = LAN_FORUM_MENU_002;
}
e107::getRender()->tablerender($menu_pref['newforumposts_caption'], $text, 'nfp_menu');
new forum_newforumposts_menu;