diff --git a/e107_handlers/menu_class.php b/e107_handlers/menu_class.php index 222bb149c..fa309165c 100644 --- a/e107_handlers/menu_class.php +++ b/e107_handlers/menu_class.php @@ -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(); diff --git a/e107_handlers/pref_class.php b/e107_handlers/pref_class.php index b3dc6fa13..23cd69404 100644 --- a/e107_handlers/pref_class.php +++ b/e107_handlers/pref_class.php @@ -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; + + } } /** diff --git a/e107_plugins/forum/forum_admin.php b/e107_plugins/forum/forum_admin.php index 72b5ed01f..544fbdb9c 100644 --- a/e107_plugins/forum/forum_admin.php +++ b/e107_plugins/forum/forum_admin.php @@ -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'])) { diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index e830c2461..79643c209 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -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.."); + } + } + + } + + + + + } diff --git a/e107_plugins/forum/forum_setup.php b/e107_plugins/forum/forum_setup.php index eef2ece88..6c7296651 100644 --- a/e107_plugins/forum/forum_setup.php +++ b/e107_plugins/forum/forum_setup.php @@ -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; } diff --git a/e107_plugins/forum/forum_update.php b/e107_plugins/forum/forum_update.php index 707ad7839..6e37e99b8 100644 --- a/e107_plugins/forum/forum_update.php +++ b/e107_plugins/forum/forum_update.php @@ -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}
"; } diff --git a/e107_plugins/forum/newforumposts_menu.php b/e107_plugins/forum/newforumposts_menu.php index e1c76ca16..9ee24ecf8 100755 --- a/e107_plugins/forum/newforumposts_menu.php +++ b/e107_plugins/forum/newforumposts_menu.php @@ -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 = ""; + + + + + 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 = ""; + } + 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; + + +