From eae211fc63ebd5a170efe25041d80f8d4e7140de Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 31 Mar 2013 00:06:21 -0700 Subject: [PATCH] Forum upgrade fixes. Forum-attachments now converted in batches. --- e107_admin/update_routines.php | 8 +- e107_core/xml/default_install.xml | 1 - e107_handlers/e_parse_class.php | 20 + e107_handlers/file_class.php | 21 +- e107_handlers/mysql_class.php | 11 +- e107_handlers/plugin_class.php | 6 +- e107_handlers/theme_handler.php | 30 +- e107_plugins/forum/forum_class.php | 26 + e107_plugins/forum/forum_update.php | 1522 ++++++++++------- e107_plugins/forum/forum_viewtopic.php | 12 + .../shortcodes/batch/view_shortcodes.php | 67 +- .../templates/forum_viewtopic_template.php | 6 +- 12 files changed, 1025 insertions(+), 705 deletions(-) diff --git a/e107_admin/update_routines.php b/e107_admin/update_routines.php index 7a7c9e051..848d30471 100644 --- a/e107_admin/update_routines.php +++ b/e107_admin/update_routines.php @@ -1304,11 +1304,15 @@ function update_706_to_800($type='') } $dl_files = $fl->get_files(e_FILE.'downloads', "","standard",5); // don't use e_DOWNLOAD or a loop may occur. - $public_files = $fl->get_files(e_FILE.'public'); + + + $publicFilter = array('_FT', '^thumbs\.db$','^Thumbs\.db$','.*\._$','^\.htaccess$','^\.cvsignore$','^\.ftpquota$','^index\.html$','^null\.txt$','\.bak$','^.tmp'); // Default file filter (regex format) +// $publicFilter = array(1); + $public_files = $fl->get_files(e_FILE.'public','',$publicFilter); if((count($dl_files) || count($public_files)) && !$sql->gen("SELECT * FROM `#core_media` WHERE `media_category` = 'download_file' ")) { - if ($just_check) return update_needed('Import Download and Public Files into Media Manager'); + if ($just_check) return update_needed('Import '.count($dl_files).' Download File(s) and '.count($public_files).' Public File(s) into Media Manager'); // check for file-types; if (is_readable(e_ADMIN.'filetypes.php')) { diff --git a/e107_core/xml/default_install.xml b/e107_core/xml/default_install.xml index 2d7a11e03..a20065d3b 100644 --- a/e107_core/xml/default_install.xml +++ b/e107_core/xml/default_install.xml @@ -81,7 +81,6 @@ 'news' => 'news', 'page' => 'page', )]]> - 0 default 0 diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index eb817d7aa..654fb2ffe 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -1816,6 +1816,12 @@ class e_parse extends e_parser return $text; } + /** + * @param $url + * @param $options ?? + * @param $raw ?? + * @param $full + */ public function thumbUrl($url, $options = array(), $raw = false, $full = false) { if(substr($url,0,3)=="{e_") // Fix for broken links that use {e_MEDIA} etc. @@ -2419,7 +2425,21 @@ class e_parser { $this->allowedAttributes = $array; } + + + /** + * Add leading zeros to a number. eg. 3 might become 000003 + * @param $num integer + * @param $numDigits - total number of digits + * @return number with leading zeros. + */ + public function leadingZeros($num,$numDigits) + { + return sprintf("%0".$numDigits."d",$num); + } + + /** * Return an Array of all specific tags found in an HTML document and their attributes. diff --git a/e107_handlers/file_class.php b/e107_handlers/file_class.php index f25e95d1f..97fb1e116 100644 --- a/e107_handlers/file_class.php +++ b/e107_handlers/file_class.php @@ -72,6 +72,8 @@ class e_file * @var array */ public $fileFilter; + + public $filesRejected = array(); /** * Defines what array format should return get_files() method @@ -194,7 +196,7 @@ class e_file } if (($omit == 'standard') || ($omit == '')) { - $omit = array(); + $omit = $this->fileFilter; } else { @@ -223,11 +225,12 @@ class e_file $rejected = FALSE; // Check against the generic file reject filter - foreach($this->fileFilter as $rmask) + foreach($omit as $rmask) { if(preg_match("#".$rmask."#", $file)) { $rejected = TRUE; + $this->filesRejected[] = $file; break; // continue 2 may well work } } @@ -571,13 +574,12 @@ class e_file { global $e107; - $pref = e107::getPref(); - $tp = e107::getParser(); + $pref = e107::getPref(); + $tp = e107::getParser(); - - $DOWNLOADS_DIRECTORY = e_BASE.e107::getFolder('DOWNLOADS'); - $FILES_DIRECTORY = e_BASE.e107::getFolder('FILES'); - $MEDIA_DIRECTORY = realpath(e_MEDIA_FILE); + $DOWNLOADS_DIRECTORY = e_BASE.e107::getFolder('DOWNLOADS'); + $FILES_DIRECTORY = e_BASE.e107::getFolder('FILES'); + $MEDIA_DIRECTORY = realpath(e_MEDIA); // could be image, file or other type. $file = $tp->replaceConstants($file); @@ -594,6 +596,9 @@ class e_file $path = realpath($filename); $path_downloads = realpath($DOWNLOADS_DIRECTORY); $path_public = realpath($FILES_DIRECTORY."public/"); + + + if(!strstr($path, $path_downloads) && !strstr($path,$path_public) && !strstr($path, $MEDIA_DIRECTORY)) { if(E107_DEBUG_LEVEL > 0 && ADMIN) diff --git a/e107_handlers/mysql_class.php b/e107_handlers/mysql_class.php index 4023ae225..84f9d19a7 100644 --- a/e107_handlers/mysql_class.php +++ b/e107_handlers/mysql_class.php @@ -727,7 +727,7 @@ class e_db_mysql if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function. { - $new_data = ''; + if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data'])) { //Convert data if not using 'new' format @@ -750,10 +750,13 @@ class e_db_mysql } $fieldTypes = $this->_getTypes($arg); + + + $new_data = ''; foreach ($arg['data'] as $fn => $fv) { $new_data .= ($new_data ? ', ' : ''); - $new_data .= "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes); + $new_data .= "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes); } $arg = $new_data .(isset($arg['WHERE']) ? ' WHERE '. $arg['WHERE'] : ''); } @@ -868,7 +871,9 @@ class e_db_mysql } } - /* Similar to db_Update(), but splits the variables and the 'WHERE' clause. + /** + * @DEPRECATED + Similar to db_Update(), but splits the variables and the 'WHERE' clause. $vars may be an array (fieldname=>newvalue) of fields to be updated, or a simple list. $arg is usually a 'WHERE' clause The way the code is written at the moment, a call to db_Update() with just the first two parameters specified can be diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index 111e9b2c6..003ddc2e9 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -2142,7 +2142,7 @@ class e107plugin if (is_readable($setup_file)) { - if(e_PAGE == 'e107_update.php') + if(e_PAGE == 'e107_update.php' && E107_DBG_INCLUDES) { $mes->addDebug("Found setup file ".$path."_setup.php "); } @@ -2157,7 +2157,7 @@ class e107plugin if (method_exists($obj, $method_name)) { - if(e_PAGE == 'e107_update.php') + if(e_PAGE == 'e107_update.php' && E107_DBG_INCLUDES) { $mes->addDebug("Executing setup function ".$class_name." :: ".$method_name."()"); } @@ -2166,7 +2166,7 @@ class e107plugin } else { - if(e_PAGE == 'e107_update.php') + if(e_PAGE == 'e107_update.php' && E107_DBG_INCLUDES) { $mes->addDebug("Setup function ".$class_name." :: ".$method_name."() NOT found."); } diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index d5595f289..e103c3326 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -224,17 +224,13 @@ class themeHandler function getThemeInfo($file) { $STYLESHEET = FALSE; - - $reject = array('$.', - '$..', - '/', - 'CVS', - 'thumbs.db', - '*._$', - 'index', - 'null*', - 'e_*'); - $handle2 = $this->fl->get_files(e_THEME.$file."/", ".php|.css|.xml|preview.jpg|preview.png", $reject, 1); + $mes = e107::getMessage(); + + $reject = array('e_.*'); + + $handle2 = e107::getFile()->get_files(e_THEME.$file."/", ".php|.css|.xml|preview.jpg|preview.png", $reject, 1); + + foreach ($handle2 as $fln) { $file2 = str_replace(e_THEME.$file."/", "", $fln['path']).$fln['fname']; @@ -245,18 +241,12 @@ class themeHandler $themeArray[$file]['preview'] = e_THEME.$file."/".$file2; } - // ---------------- get information string for css file - if(strstr($file2, "css") && !strstr($file2, "menu.css") && strpos($file2, "e_") !== 0) { - - if($fp = fopen(e_THEME.$file."/".$file2, "r")) + if($cssContents = file_get_contents(e_THEME.$file."/".$file2)) { - // FIXME: use info from theme.xml alternateStyleSheet instead - $cssContents = fread($fp, filesize(e_THEME.$file."/".$file2)); - fclose($fp); $nonadmin = preg_match('/\* Non-Admin(.*?)\*\//', $cssContents) ? true : false; preg_match('/\* info:(.*?)\*\//', $cssContents, $match); $match[1] = varset($match[1], ''); @@ -272,6 +262,10 @@ class themeHandler $STYLESHEET = TRUE; } } + else + { + // $mes->addDebug("Couldn't read file: ".e_THEME.$file."/".$file2); + } } diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 7f2de101d..0cc9a223d 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -147,6 +147,32 @@ class e107forum */ } + + function getAttachmentPath($user=0) + { + $tp = e107::getParser(); + $baseDir = e_MEDIA.'plugins/forum/attachments/'; + $baseDir .= ($user) ? "user_". $tp->leadingZeros($user, 6) : "anon"; + $baseDir .= "/"; + + return $baseDir; + } + + + + + function sendFile($data) + { + $sql = e107::getDb(); + $fid = intval($data['dl']); + + $array = $sql->retrieve('forum_post','post_user,post_attachments','post_id='.intval($data['id'])); + $attach = e107::getArrayStorage()->read($array['post_attachments']); + $file = $this->getAttachmentPath($array['post_user']).varset($attach['file'][$fid]); + + e107::getFile()->send($file); + } + /** * Handle the Ajax quick-reply. diff --git a/e107_plugins/forum/forum_update.php b/e107_plugins/forum/forum_update.php index 752d833f4..10453799f 100644 --- a/e107_plugins/forum/forum_update.php +++ b/e107_plugins/forum/forum_update.php @@ -8,24 +8,22 @@ * * Forum upgrade routines * -*/ + */ - -define('e_ADMIN_AREA',true); -require_once('../../class2.php'); +define('e_ADMIN_AREA', true); +require_once ('../../class2.php'); if (!getperms('P')) { - header('location:'.e_BASE.'index.php'); - exit; + header('location:' . e_BASE . 'index.php'); + exit ; } - error_reporting(E_ALL); -require_once(e_PLUGIN.'forum/forum_class.php'); -require_once(e_ADMIN.'auth.php'); +require_once (e_PLUGIN . 'forum/forum_class.php'); +require_once (e_ADMIN . 'auth.php'); -if(e_QUERY == "reset") +if (e_QUERY == "reset") { unset($_SESSION['forumUpgrade']); unset($_SESSION['forumupdate_thread_last']); @@ -41,99 +39,95 @@ $f = new forumUpgrade; $e107 = e107::getInstance(); $sql = e107::getDb(); -if(e_AJAX_REQUEST) +if (e_AJAX_REQUEST) { - if(!vartrue($_GET['mode'])) + if (!vartrue($_GET['mode'])) { echo "data-progress-mode not set!"; - exit; + exit ; } - - $func = 'step'.intval($_GET['mode'])."_ajax"; - if(function_exists($func)) + $func = 'step' . intval($_GET['mode']) . "_ajax"; + + if (function_exists($func)) { call_user_func($func); } - else + else { - echo $func ."() doesn't exist!"; + echo $func . "() doesn't exist!"; } - exit; + exit ; } - - -$upgradeNeeded = $f->checkUpdateNeeded(); +$upgradeNeeded = $f -> checkUpdateNeeded(); $upgradeNeeded = true; -if(!$upgradeNeeded) +if (!$upgradeNeeded) { $mes = e107::getMessage(); - $mes->addInfo("The forum is already at the most recent version, no upgrade is required"); - $ns->tablerender('Forum Upgrade', $mes->render()); - require(e_ADMIN.'footer.php'); - exit; + $mes -> addInfo("The forum is already at the most recent version, no upgrade is required"); + $ns -> tablerender('Forum Upgrade', $mes -> render()); + require (e_ADMIN . 'footer.php'); + exit ; } -if(isset($_POST) && count($_POST)) +if (isset($_POST) && count($_POST)) { - if(isset($_POST['skip_attach'])) + if (isset($_POST['skip_attach'])) { - $f->updateInfo['skip_attach'] = 1; - $f->updateInfo['currentStep'] = 2; - $f->setUpdateInfo(); + $f -> updateInfo['skip_attach'] = 1; + $f -> updateInfo['currentStep'] = 2; + $f -> setUpdateInfo(); } - if(isset($_POST['nextStep'])) + if (isset($_POST['nextStep'])) { $tmp = array_keys($_POST['nextStep']); - $f->updateInfo['currentStep'] = $tmp[0]; - $f->setUpdateInfo(); + $f -> updateInfo['currentStep'] = $tmp[0]; + $f -> setUpdateInfo(); } } - -$currentStep = (isset($f->updateInfo['currentStep']) ? $f->updateInfo['currentStep'] : 1); +$currentStep = (isset($f -> updateInfo['currentStep']) ? $f -> updateInfo['currentStep'] : 1); $stepParms = (isset($stepParms) ? $stepParms : ''); //echo "currentStep = $currentStep
"; -if(function_exists('step'.$currentStep)) +if (function_exists('step' . $currentStep)) { - $result = call_user_func('step'.$currentStep, $stepParms); + $result = call_user_func('step' . $currentStep, $stepParms); } -require(e_ADMIN.'footer.php'); -exit; - +require (e_ADMIN . 'footer.php'); +exit ; function step1() { - + global $f; - $f->updateInfo['currentStep'] = 1; - $f->setUpdateInfo(); - + $f -> updateInfo['currentStep'] = 1; + $f -> setUpdateInfo(); + $e107 = e107::getInstance(); $mes = e107::getMessage(); //Check attachment dir permissions - if(!isset($f->updateInfo['skip_attach'])) + if (!isset($f -> updateInfo['skip_attach'])) { - $f->checkAttachmentDirs(); - if(isset($f->error['attach'])) + $f -> checkAttachmentDirs(); + if (isset($f -> error['attach'])) { $text = "

ERROR:

The following errors have occured. These issues must be resolved if you ever want to enable attachment or image uploading in your forums.
If you do not ever plan on enabling this setting in your forum, you may click the 'skip' button

"; - foreach($f->error['attach'] as $e) + foreach ($f->error['attach'] as $e) { - $text .= '** '.$e.'
'; + $text .= '** ' . $e . '
'; } $text .= "
-
+     @@ -142,14 +136,14 @@ function step1() } else { - $mes->addSuccess("Attachment and attachment/thumb directories are writable"); - - $text = " + $mes -> addSuccess("Attachment and attachment/thumb directories are writable"); + + $text = "
"; } - e107::getRender()->tablerender('Step 1: Attachment directory permissions', $mes->render(). $text); + e107::getRender() -> tablerender('Step 1: Attachment directory permissions', $mes -> render() . $text); } } @@ -158,8 +152,8 @@ function step2() $e107 = e107::getInstance(); $mes = e107::getMessage(); $ns = e107::getRender(); - - if(!isset($_POST['create_tables'])) + + if (!isset($_POST['create_tables'])) { $text = " This step will create the new forum_thread, forum_post, and forum_attach tables. It will also create a forum_new table that will become the 'real' forum table once the data from the current table is migrated. @@ -168,59 +162,65 @@ function step2() "; - $ns->tablerender('Step 2: Forum table creation', $text); + $ns -> tablerender('Step 2: Forum table creation', $text); return; } // FIXME - use db_verify. ?? - require_once(e_HANDLER.'db_table_admin_class.php'); + require_once (e_HANDLER . 'db_table_admin_class.php'); $db = new db_table_admin; - $tabList = array('forum' => 'forum_new' , 'forum_thread' => '', 'forum_post' => '', 'forum_track' => '' ); // + $tabList = array( + 'forum' => 'forum_new', + 'forum_thread' => '', + 'forum_post' => '', + 'forum_track' => '' + ); + // $ret = ''; $failed = false; $text = ''; - foreach($tabList as $name => $rename) + foreach ($tabList as $name => $rename) { - $message = 'Creating table '.($rename ? $rename : $name); - - $result = $db->createTable(e_PLUGIN.'forum/forum_sql.php', $name, true, $rename); - if($result === true) + $message = 'Creating table ' . ($rename ? $rename : $name); + + $result = $db -> createTable(e_PLUGIN . 'forum/forum_sql.php', $name, true, $rename); + if ($result === true) { - $mes->addSuccess($message); - // $text .= 'Success
'; + $mes -> addSuccess($message); + // $text .= 'Success
'; } - elseif($result !== true) + elseif ($result !== true) { - // $text .= 'Failed
'; - $mes->addError($message); + // $text .= 'Failed
'; + $mes -> addError($message); $failed = true; } } - if($failed) + if ($failed) { - $mes->addError("Creation of table(s) failed. You can not continue until these are created successfully!"); - + $mes -> addError("Creation of table(s) failed. You can not continue until these are created successfully!"); + } else { - $text = "
+ $text = "
"; } - $ns->tablerender('Step 2: Forum table creation', $mes->render(). $text); + $ns -> tablerender('Step 2: Forum table creation', $mes -> render() . $text); } - -// FIXME - use e107::getPlugin()->manage_extended_field('add', $name, $attrib, $source) +// FIXME - use e107::getPlugin()->manage_extended_field('add', $name, $attrib, +// $source) function step3() { $ns = e107::getRender(); $mes = e107::getMessage(); - + $stepCaption = 'Step 3: Extended user field creation'; - if(!isset($_POST['create_extended'])) + if (!isset($_POST['create_extended'])) { $text = " This step will create the new extended user fields required for the new forum code:
@@ -231,51 +231,51 @@ function step3() "; - - $ns->tablerender($stepCaption, $text); + + $ns -> tablerender($stepCaption, $text); return; } - - require_once(e_HANDLER.'user_extended_class.php'); + + require_once (e_HANDLER . 'user_extended_class.php'); $ue = new e107_user_extended; - + $fieldList = array( 'plugin_forum_posts' => EUF_INTEGER, 'plugin_forum_viewed' => EUF_TEXTAREA ); - - $failed = false; - foreach($fieldList as $fieldName => $fieldType) - { - - $result = $ue->user_extended_add_system($fieldName, $fieldType); - if($result === true) + $failed = false; + foreach ($fieldList as $fieldName => $fieldType) + { + + $result = $ue -> user_extended_add_system($fieldName, $fieldType); + + if ($result === true) { - $mes->addSuccess('Creating extended user field user_'.$fieldName); + $mes -> addSuccess('Creating extended user field user_' . $fieldName); } else { - $mes->addError('Creating extended user field user_'.$fieldName); + $mes -> addError('Creating extended user field user_' . $fieldName); $failed = true; } } - - if($failed) + + if ($failed) { - $mes->addError("Creation of extended field(s) failed. You can not continue until these are create successfully!"); - + $mes -> addError("Creation of extended field(s) failed. You can not continue until these are create successfully!"); + } else { - $text .= " -
+ $text .= " +
"; } - - $ns->tablerender($stepCaption, $mes->render(). $text); + + $ns -> tablerender($stepCaption, $mes -> render() . $text); } @@ -285,9 +285,9 @@ function step4() $e107 = e107::getInstance(); $mes = e107::getMessage(); $ns = e107::getRender(); - + $stepCaption = 'Step 4: Move user specific forum data and forum prefs'; - if(!isset($_POST['move_user_data'])) + if (!isset($_POST['move_user_data'])) { $text = " This step will move the main forum preferences into its own table row. It will also move all user_viewed data from user table into the user extended table.
@@ -299,7 +299,7 @@ function step4() "; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } @@ -307,42 +307,44 @@ function step4() $fconf = e107::getPlugConfig('forum', '', false); $coreConfig = e107::getConfig(); $old_prefs = array(); - foreach($pref as $k => $v) + foreach ($pref as $k => $v) { - if(substr($k, 0, 6) == 'forum_') + if (substr($k, 0, 6) == 'forum_') { $nk = substr($k, 6); - $mes->addDebug("Converting $k to $nk"); + $mes -> addDebug("Converting $k to $nk"); $old_prefs[$nk] = $v; - $coreConfig->remove($k); + $coreConfig -> remove($k); } } $forumPrefList = array( - 'reported_post_email', 'email_notify', 'email_notify_on' + 'reported_post_email', + 'email_notify', + 'email_notify_on' ); - foreach($forumPrefList as $_fp) + foreach ($forumPrefList as $_fp) { - $mes->addDebug( "converting $_fp to $_fp" ); - $old_prefs[$_fp] = $coreConfig->get($_fp); - $coreConfig->remove($_fp); + $mes -> addDebug("converting $_fp to $_fp"); + $old_prefs[$_fp] = $coreConfig -> get($_fp); + $coreConfig -> remove($_fp); } - $fconf->setPref($old_prefs)->save(false, true); - $coreConfig->save(false, true); + $fconf -> setPref($old_prefs) -> save(false, true); + $coreConfig -> save(false, true); $result = array( - 'usercount' => 0, - 'viewcount' => 0, - 'trackcount' => 0 + 'usercount' => 0, + 'viewcount' => 0, + 'trackcount' => 0 ); $db = new db; - if($db->select('user', 'user_id, user_viewed, user_realm',"user_viewed != '' OR user_realm != ''")) + if ($db -> select('user', 'user_id, user_viewed, user_realm', "user_viewed != '' OR user_realm != ''")) { - require_once(e_HANDLER.'user_extended_class.php'); + require_once (e_HANDLER . 'user_extended_class.php'); $ue = new e107_user_extended; - while($row = $db->fetch(MYSQL_ASSOC)) + while ($row = $db -> fetch(MYSQL_ASSOC)) { $result['usercount']++; $userId = (int)$row['user_id']; @@ -352,73 +354,71 @@ function step4() $tmp = preg_split('#\.+#', $viewed); $viewed = implode(',', $tmp); - $realm = $row['user_realm']; $realm = str_replace('USERREALM', '', $realm); $realm = trim($realm, '-.'); $trackList = preg_split('#\D+#', $realm); - - $debug = 'user_id = '.$userId.'
'; - $debug .= 'viewed = '.$viewed.'
'; - $debug .= 'realm = '.$realm.'
'; - $debug .= 'tracking = ' . implode(',', $trackList).'
'; - $debug .= print_a($trackList,true); - $mes->addDebug($debug); + $debug = 'user_id = ' . $userId . '
'; + $debug .= 'viewed = ' . $viewed . '
'; + $debug .= 'realm = ' . $realm . '
'; + $debug .= 'tracking = ' . implode(',', $trackList) . '
'; + $debug .= print_a($trackList, true); + $mes -> addDebug($debug); - if($viewed != '') + if ($viewed != '') { - $ue->user_extended_setvalue($userId, 'plugin_forum_viewed', mysql_real_escape_string($viewed)); + $ue -> user_extended_setvalue($userId, 'plugin_forum_viewed', mysql_real_escape_string($viewed)); $result['viewcount']++; } - if(is_array($trackList) && count($trackList)) + if (is_array($trackList) && count($trackList)) { - foreach($trackList as $threadId) + foreach ($trackList as $threadId) { $result['trackcount']++; $threadId = (int)$threadId; - if($threadId > 0) + if ($threadId > 0) { $tmp = array(); $tmp['track_userid'] = $userId; $tmp['track_thread'] = $threadId; - e107::getDb()->insert('forum_track', $tmp); + e107::getDb() -> insert('forum_track', $tmp); } } } } } - $mes->addSuccess( "User data move results: + $mes -> addSuccess("User data move results: "); - - $text = "
+ + $text = "
"; - $ns->tablerender($stepCaption, $mes->render().$text); + $ns -> tablerender($stepCaption, $mes -> render() . $text); } function step5() { $e107 = e107::getInstance(); - + $sql = e107::getDb(); $ns = e107::getRender(); $mes = e107::getMessage(); - + $stepCaption = 'Step 5: Migrate forum data'; - if(!isset($_POST['move_forum_data'])) + if (!isset($_POST['move_forum_data'])) { - $text ="This step will copy all of your forum configuration from the `forum` table into the `forum_new` table.
+ $text = "This step will copy all of your forum configuration from the `forum` table into the `forum_new` table.
Once the information is successfully copied, the existing 1.0 forum table will be renamed `forum_old` and the newly created `forum_new` table will be renamed `forum`.


"; $text .= " @@ -426,22 +426,27 @@ function step5() "; - $ns->tablerender($stepCaption, $mes->render().$text); + $ns -> tablerender($stepCaption, $mes -> render() . $text); return; } - $counts = array('parents' => 0, 'forums' => 0, 'subs' => 0); //XXX Typo on 'parents' ? + $counts = array( + 'parents' => 0, + 'forums' => 0, + 'subs' => 0 + ); + //XXX Typo on 'parents' ? - if($sql->select('forum')) + if ($sql -> select('forum')) { - $forumList = $sql->db_getList(); - foreach($forumList as $forum) + $forumList = $sql -> db_getList(); + foreach ($forumList as $forum) { - if($forum['forum_parent'] == 0) + if ($forum['forum_parent'] == 0) { $counts['parents']++; } - elseif($forum['forum_sub'] != 0) + elseif ($forum['forum_sub'] != 0) { $counts['subs']++; } @@ -453,20 +458,19 @@ function step5() $tmp = $forum; $tmp['forum_threadclass'] = $tmp['forum_postclass']; $tmp['forum_options'] = '_NULL_'; -// $tmp['_FIELD_TYPES'] = $ftypes['_FIELD_TYPES']; - if($sql->insert('forum_new', $tmp)) + // $tmp['_FIELD_TYPES'] = $ftypes['_FIELD_TYPES']; + if ($sql -> insert('forum_new', $tmp)) { - + } else { - $mes->addError("Insert failed on ".print_a($tmp,true)); + $mes -> addError("Insert failed on " . print_a($tmp, true)); } - - + } - $mes->addSuccess ( " + $mes -> addSuccess(" Forum data move results: "); - $result = $sql->gen('RENAME TABLE `#forum` TO `#forum_old` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR; - $mes->add("Renaming forum to forum_old", $result); + $result = $sql -> gen('RENAME TABLE `#forum` TO `#forum_old` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes -> add("Renaming forum to forum_old", $result); - $result = $sql->gen('RENAME TABLE `#forum_new` TO `#forum` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR; - $mes->add("Renaming forum_new to forum", $result); - + $result = $sql -> gen('RENAME TABLE `#forum_new` TO `#forum` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes -> add("Renaming forum_new to forum", $result); $text = " -
+
"; - $ns->tablerender($stepCaption, $mes->render(). $text); + $ns -> tablerender($stepCaption, $mes -> render() . $text); } } @@ -500,17 +503,17 @@ function step6x() $ns = e107::getRender(); $mes = e107::getMessage(); $sql = e107::getDb(); - + $stepCaption = 'Step 6: Thread and post data'; $threadLimit = varset($_POST['threadLimit'], 1000); - $lastThread = varset($f->updateInfo['lastThread'], 0); + $lastThread = varset($f -> updateInfo['lastThread'], 0); $maxTime = ini_get('max_execution_time'); - if(!isset($_POST['move_thread_data'])) + if (!isset($_POST['move_thread_data'])) { - $count = $sql->count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$lastThread}"); + $count = $sql -> count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$lastThread}"); $limitDropdown = createThreadLimitDropdown($count); - + $text = "This step will copy all of your existing forum threads and posts into the new `forum_thread` and `forum_post` tables.

Depending on your forum size and speed of server, this could take some time. This routine will attempt to do it in steps in order to reduce the possibility of data loss and server timeouts.
@@ -519,21 +522,21 @@ function step6x() success will depend on your server configuration. If you get a timeout while performing this function, return to this page and select fewer threads to process. "; - + $text .= "
There are {$count} forum threads to convert, we will be doing it in steps of: {$limitDropdown}

"; - $ns->tablerender($stepCaption, $mes->render(). $text); + $ns -> tablerender($stepCaption, $mes -> render() . $text); return; } - $count = $sql->count('forum_t', '(*)', "WHERE thread_parent=0 AND thread_id>{$lastThread}"); - if($count === false) + $count = $sql -> count('forum_t', '(*)', "WHERE thread_parent=0 AND thread_id>{$lastThread}"); + if ($count === false) { echo "error: Unable to determine last thread id"; - exit; + exit ; } $done = false; @@ -544,35 +547,34 @@ function step6x() ORDER BY thread_id ASC LIMIT 0, {$threadLimit} "; - if($sql->gen($qry)) + if ($sql -> gen($qry)) { $postCount = 0; - $threadList = $sql->db_getList(); - - foreach($threadList as $t) + $threadList = $sql -> db_getList(); + + foreach ($threadList as $t) { set_time_limit(30); $id = (int)$t['thread_id']; - $result = $f->migrateThread($id); - if($result === false) + $result = $f -> migrateThread($id); + if ($result === false) { - $mes->addError("ERROR! Failed to migrate thread id: {$id}"); + $mes -> addError("ERROR! Failed to migrate thread id: {$id}"); } else { - $postCount += ($result-1); - $f->updateInfo['lastThread'] = $id; - $f->setUpdateInfo(); + $postCount += ($result - 1); + $f -> updateInfo['lastThread'] = $id; + $f -> setUpdateInfo(); } } - - $mes->addSuccess('Successfully converted '.count($threadList)." threads and {$postCount} replies"); - $mes->addSuccess("Last thread id = {$t['thread_id']}"); + $mes -> addSuccess('Successfully converted ' . count($threadList) . " threads and {$postCount} replies"); + $mes -> addSuccess("Last thread id = {$t['thread_id']}"); - $count = $sql->count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$f->updateInfo['lastThread']}"); - - if($count) + $count = $sql -> count('forum_t', '(*)', "WHERE thread_parent = 0 AND thread_id > {$f->updateInfo['lastThread']}"); + + if ($count) { $limitDropdown = createThreadLimitDropdown($count); $text .= " @@ -582,7 +584,7 @@ function step6x() "; - $ns->tablerender($stepCaption, $mes->render(). $text); + $ns -> tablerender($stepCaption, $mes -> render() . $text); } else { @@ -593,14 +595,14 @@ function step6x() { $done = true; } - if($done) + if ($done) { - $mes->addSuccess("Thread migration is complete!!"); - $text = "
+ $mes -> addSuccess("Thread migration is complete!!"); + $text = "
"; - - $ns->tablerender($stepCaption, $mes->render(). $text); + + $ns -> tablerender($stepCaption, $mes -> render() . $text); } } @@ -612,48 +614,43 @@ function step6() $mes = e107::getMessage(); $stepCaption = 'Step 6: Thread and post data'; - - $_SESSION['forumupdate_thread_total'] = $sql->count('forum_t', '(*)', "WHERE thread_parent = 0"); + $_SESSION['forumupdate_thread_total'] = $sql -> count('forum_t', '(*)', "WHERE thread_parent = 0"); $_SESSION['forumupdate_thread_count'] = 0; $_SESSION['forumupdate_thread_last'] = 0; - + $text = "This step will copy all of your existing forum threads and posts into the new `forum_thread` and `forum_post` tables.
Depending on your forum size and speed of server, this could take some time.

"; - -// $text .= "
-// There are {$count} forum threads to convert, we will be doing it in steps of: {$limitDropdown} -//

"; - - $text .= ' + + // $text .= " + // There are {$count} forum threads to convert, we will be doing it in steps of: + // {$limitDropdown} + //

"; + + $text .= ' '; - - $text .= " + + $text .= "
"; - $ns->tablerender($stepCaption, $mes->render(). $text); - - + $ns -> tablerender($stepCaption, $mes -> render() . $text); + } - - - - function step6_ajax() { global $f; $sql = e107::getDb(); - - $lastThread = vartrue($_SESSION['forumupdate_thread_last'],0); - + + $lastThread = vartrue($_SESSION['forumupdate_thread_last'], 0); + $qry = " SELECT thread_id FROM `#forum_t` WHERE thread_parent = 0 @@ -661,17 +658,17 @@ function step6_ajax() ORDER BY thread_id ASC LIMIT 0, 300 "; - - if($sql->gen($qry)) + + if ($sql -> gen($qry)) { - $threadList = $sql->db_getList(); - - foreach($threadList as $t) + $threadList = $sql -> db_getList(); + + foreach ($threadList as $t) { $id = (int)$t['thread_id']; - $result = $f->migrateThread($id); - - if($result === false) + $result = $f -> migrateThread($id); + + if ($result === false) { echo "Error"; } @@ -680,24 +677,20 @@ function step6_ajax() $_SESSION['forumupdate_thread_last'] = $id; $_SESSION['forumupdate_thread_count']++; } - } - + } + } - - echo round(($_SESSION['forumupdate_thread_count'] / $_SESSION['forumupdate_thread_total'] ) * 100); + + echo round(($_SESSION['forumupdate_thread_count'] / $_SESSION['forumupdate_thread_total']) * 100); } - - - - function step7() { $e107 = e107::getInstance(); $ns = e107::getRender(); $stepCaption = 'Step 7: Calculate user post counts'; - if(!isset($_POST['calculate_usercounts'])) + if (!isset($_POST['calculate_usercounts'])) { $text = " This step will calculate post count information for all users, as well as recount all for thread and reply counts. @@ -706,51 +699,43 @@ function step7() "; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } global $forum; - require_once(e_HANDLER.'user_extended_class.php'); + require_once (e_HANDLER . 'user_extended_class.php'); $ue = new e107_user_extended; - $counts = $forum->getUserCounts(); - foreach($counts as $uid => $count) + $counts = $forum -> getUserCounts(); + foreach ($counts as $uid => $count) { - $ue->user_extended_setvalue($uid, 'user_plugin_forum_posts', $count, 'int'); + $ue -> user_extended_setvalue($uid, 'user_plugin_forum_posts', $count, 'int'); } - $forum->forumUpdateCounts('all', true); + $forum -> forumUpdateCounts('all', true); - -// var_dump($counts); + // var_dump($counts); $text .= " - Successfully recalculated forum posts for ".count($counts)." users. + Successfully recalculated forum posts for " . count($counts) . " users.

-
+
"; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); } - -function step7_ajax() //TODO +function step7_ajax()//TODO { - - - - - -} - +} function step8() { $e107 = e107::getInstance(); $stepCaption = 'Step 8: Calculate last post information'; - if(!isset($_POST['calculate_lastpost'])) + if (!isset($_POST['calculate_lastpost'])) { $text = " This step will recalculate all thread and forum lastpost information @@ -759,49 +744,37 @@ function step8() "; - e107::getRender()->tablerender($stepCaption, $text); + e107::getRender() -> tablerender($stepCaption, $text); return; } global $forum; - $forum->forumUpdateLastpost('forum', 'all', true); - - -// $forum->forumUpdateLastpost('thread', 84867); + $forum -> forumUpdateLastpost('forum', 'all', true); + // $forum->forumUpdateLastpost('thread', 84867); $text .= " Successfully recalculated lastpost information for all forums and threads.

-
+
"; - e107::getRender()->tablerender($stepCaption, $text); + e107::getRender() -> tablerender($stepCaption, $text); } - - -function step8_ajax() //TODO +function step8_ajax()//TODO { - - - - - + } - - - - function step9() { $e107 = e107::getInstance(); $sql = e107::getDb(); $stepCaption = 'Step 9: Migrate poll information'; - if(!isset($_POST['migrate_polls'])) + if (!isset($_POST['migrate_polls'])) { $text = " This step will recalculate all poll information that has been entered in the forums. @@ -810,7 +783,7 @@ function step9() "; - e107::getRender()->tablerender($stepCaption, $text); + e107::getRender() -> tablerender($stepCaption, $text); return; } @@ -819,18 +792,18 @@ function step9() LEFT JOIN `#forum_thread` AS t ON t.thread_id = p.poll_datestamp WHERE t.thread_id IS NOT NULL "; - if($sql->gen($qry)) + if ($sql -> gen($qry)) { - while($row = $sql->fetch(MYSQL_ASSOC)) + while ($row = $sql -> fetch(MYSQL_ASSOC)) { $threadList[] = $row['thread_id']; } - foreach($threadList as $threadId) + foreach ($threadList as $threadId) { - if($sql->select('forum_thread', 'thread_options', 'thread_id = '.$threadId, 'default')) + if ($sql -> select('forum_thread', 'thread_options', 'thread_id = ' . $threadId, 'default')) { - $row = $sql->fetch(MYSQL_ASSOC); - if($row['thread_options']) + $row = $sql -> fetch(MYSQL_ASSOC); + if ($row['thread_options']) { $opts = unserialize($row['thread_options']); $opts['poll'] = 1; @@ -841,9 +814,9 @@ function step9() } $tmp = array(); $tmp['thread_options'] = serialize($opts); - $tmp['WHERE'] = 'thread_id = '.$threadId; -// $tmp['_FIELD_TYPES']['thread_options'] = 'escape'; - $sql->update('forum_thread', $tmp); + $tmp['WHERE'] = 'thread_id = ' . $threadId; + // $tmp['_FIELD_TYPES']['thread_options'] = 'escape'; + $sql -> update('forum_thread', $tmp); } } } @@ -853,82 +826,366 @@ function step9() } $text .= " - Successfully migrated forum poll information for ".count($threadList)." thread poll(s). + Successfully migrated forum poll information for " . count($threadList) . " thread poll(s).

-
+
"; - e107::getRender()->tablerender($stepCaption, $text); + e107::getRender() -> tablerender($stepCaption, $text); } -function step9_ajax() //TODO +function step9_ajax()//TODO { - - - - - + } +/* + function step10x() + { + $e107 = e107::getInstance(); + $sql = e107::getDb(); + $ns = e107::getRender(); + + global $f; + $stepCaption = 'Step 10: Migrate forum attachments'; + + //FIXME - Files should be moved to e107_media/files/forum/ + if(!isset($_POST['migrate_attachments'])) + { + $text = " + This step will migrate all forum attachment information.
+ All files will be moved from the e107_files/public directory into the +".e_MEDIA."plugins/forum/attachment directory and related posts will be updated +accordingly. +

+
+ +
+ "; + $ns->tablerender($stepCaption, $text); + return; + } + + $qry = " + SELECT post_id, post_entry FROM `#forum_post` + WHERE post_entry REGEXP '_[[:digit:]]+_FT' + "; + + if($sql->gen($qry)) + { + while($row = $sql->fetch(MYSQL_ASSOC)) + { + $postList[] = $row; + } + $i = 0; + $pcount = 0; + $f->log("Found ".count($postList). " posts with attachments"); + + //XXX Run post through $tp->toHtml() and then use $tp->getTag() to find images +// or files.? + foreach($postList as $post) + { + // echo htmlentities($post['post_entry'])."
"; + $i++; + // if($pcount++ > 10) { die('here 10'); } + $attachments = array(); + $foundFiles = array(); + + // echo $post['post_entry']."

"; + + //[link={e_FILE}public/1230091080_1_FT0_julia.jpg][img:width=60&height=45]{e_FILE}public/1230091080_1_FT0_julia_.jpg[/img][/link][br] + //Check for images with thumbnails linking to full size + if(preg_match_all('#\[link=(.*?)\]\[img.*?\]({e_FILE}.*?)\[/img\]\[/link\]#ms', +$post['post_entry'], $matches, PREG_SET_ORDER)) + { + foreach($matches as $match) + { + $att = array(); + $att['thread_id'] = $post['thread_id']; + $att['type'] = 'img'; + $att['html'] = $match[0]; + $att['name'] = $match[1]; + $att['thumb'] = $match[2]; + $attachments[] = $att; + $foundFiles[] = $match[1]; + $foundFiles[] = $match[2]; + } + } + + if(preg_match_all('#\[link=(.*?)\]\[img.*?\](\.\./\.\./e107_files/public/.*?)\[/img\]\[/link\]#ms', +$post['post_entry'], $matches, PREG_SET_ORDER)) + { + foreach($matches as $match) + { + $att = array(); + $att['thread_id'] = $post['thread_id']; + $att['type'] = 'img'; + $att['html'] = $match[0]; + $att['name'] = $match[1]; + $att['thumb'] = $match[2]; + $attachments[] = $att; + $foundFiles[] = $match[1]; + $foundFiles[] = $match[2]; + } + } + + //
[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]
+ //Check for attached full-size images + if(preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', +$post['post_entry'], $matches, PREG_SET_ORDER)) + { + foreach($matches as $match) + { + //Ensure it hasn't already been handled above + if(!in_array($match[1], $foundFiles)) + { + $att = array(); + $att['thread_id'] = $post['thread_id']; + $att['type'] = 'img'; + $att['html'] = $match[0]; + $att['name'] = $match[1]; + $att['thumb'] = ''; + $attachments[] = $att; + } + } + } + + if(preg_match_all('#\[img.*?\](\.\./\.\./e107_files/public/.*?_FT\d+_.*?)\[/img\]#ms', +$post['post_entry'], $matches, PREG_SET_ORDER)) + { + foreach($matches as $match) + { + //Ensure it hasn't already been handled above + if(!in_array($match[1], $foundFiles)) + { + $att = array(); + $att['thread_id'] = $post['thread_id']; + $att['type'] = 'img'; + $att['html'] = $match[0]; + $att['name'] = $match[1]; + $att['thumb'] = ''; + $attachments[] = $att; + } + } + } + + //[file={e_FILE}public/1230090820_1_FT0_julia.zip]julia.zip[/file] + //Check for attached file (non-images) + if(preg_match_all('#\[file=({e_FILE}.*?)\](.*?)\[/file\]#ms', +$post['post_entry'], $matches, PREG_SET_ORDER)) + { + foreach($matches as $match) + { + $att = array(); + $att['thread_id'] = $post['thread_id']; + $att['type'] = 'file'; + $att['html'] = $match[0]; + $att['name'] = $match[1]; + $att['thumb'] = ''; + $attachments[] = $att; + } + } + + if(preg_match_all('#\[file=(\.\./\.\./e107_files/public/.*?)\](.*?)\[/file\]#ms', +$post['post_entry'], $matches, PREG_SET_ORDER)) + { + foreach($matches as $match) + { + $att = array(); + $att['thread_id'] = $post['thread_id']; + $att['type'] = 'file'; + $att['html'] = $match[0]; + $att['name'] = $match[1]; + $att['thumb'] = ''; + $attachments[] = $att; + } + } + + if(count($attachments)) + { + $f->log("found ".count($attachments)." attachments"); + $newValues = array(); + $info = array(); + $info['post_entry'] = $post['post_entry']; + foreach($attachments as $attachment) + { + $error = ''; + $f->log($attachment['name']); + if($f->moveAttachment($attachment, $post['post_id'], $error)) + { + $fInfo = pathinfo($attachment['name']); + // $_file = split('/', $attachment['name']); + $newval = $attachment['type'].'*'.$fInfo['basename']; + switch($attachment['type']) + { + //If file, add real name to entry + case 'file': + $tmp = explode('_', $fInfo['basename'], 4); + $newval .= '*'.$tmp[3]; + break; + + //If image and it has a thumb, add thumb filename to entry + case 'img': + if($attachment['thumb']) + { + $fInfo = pathinfo($attachment['thumb']); + $newval .= '*'.$fInfo['basename']; + } + break; + } + $newValues[] = $newval; + // echo "Newval = $newval
"; + // echo "Removing from post:".htmlentities($attachment['html'])."
"; + $info['post_entry'] = str_replace($attachment['html'], '', $info['post_entry']); + } + else + { + $errorText .= "Failure processing post {$post['post_id']} - file +{$attachment['name']} - {$error}
"; + $f->log("Failure processing post {$post['post_id']} - file {$attachment['name']} +- {$error}"); + } + } + // echo $errorText."
"; + + // Did we make any changes at all? + if(count($newValues)) + { + $info['WHERE'] = 'post_id = '.$post['post_id']; + $info['post_attachments'] = implode(',', $newValues); + // print_a($info); + $sql->db_Update('forum_post', $info); + } + // echo $post['thread_thread']."
"; + // print_a($newValues); + // echo $info['newpost']."
--------------------------------------
"; + // Update db values now + } + } + } + else + { + $text = 'No forum attachments found!
'; + } + + // $forum->forumUpdateLastpost('thread', 84867); + + $text .= " + Successfully migrated forum attachment information for ".count($postList)." +post(s). +

+
+ +
+ "; + $ns->tablerender($stepCaption, $text); + } + */ + function step10() { $e107 = e107::getInstance(); $sql = e107::getDb(); $ns = e107::getRender(); - + $mes = e107::getMessage(); + global $f; + $stepCaption = 'Step 10: Migrate forum attachments'; - - //FIXME - Files should be moved to e107_media/files/forum/ - if(!isset($_POST['migrate_attachments'])) + + $_SESSION['forumupdate_attachment_total'] = $sql -> count('forum_post', '(*)', "WHERE post_entry REGEXP '_[[:digit:]]+_FT' "); + $_SESSION['forumupdate_attachment_count'] = 0; + $_SESSION['forumupdate_attachment_last'] = 0; + + if ($_SESSION['forumupdate_attachment_total'] == 0) { - $text = " - This step will migrate all forum attachment information.
- All files will be moved from the e107_files/public directory into the ".e_MEDIA."plugins/forum/attachment directory and related posts will be updated accordingly. + $text .= " + No forum attachments found.

-
- + +
"; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } + $text = " + This step will migrate the forum attachment information that was found in " . $_SESSION['forumupdate_attachment_total'] . " posts.
+ All files will be moved from the e107_files/public directory into the " . e_MEDIA . "plugins/forum/ directory and related posts will be updated accordingly. +

+ "; + + $text .= ' +
+ +
'; + + $text .= "
+ +
"; + + $ns -> tablerender($stepCaption, $mes -> render() . $text); + +} + +function step10_ajax()//TODO +{ + $sql = e107::getDb(); + global $f; + + $lastPost = vartrue($_SESSION['forumupdate_attachment_last'], 0); + $qry = " - SELECT post_id, post_entry FROM `#forum_post` + SELECT post_id, post_thread, post_entry, post_user FROM `#forum_post` WHERE post_entry REGEXP '_[[:digit:]]+_FT' + AND post_id > {$lastPost} LIMIT 1 "; - - if($sql->gen($qry)) + + if ($sql->gen($qry)) { - while($row = $sql->fetch(MYSQL_ASSOC)) + while ($row = $sql->fetch(MYSQL_ASSOC)) { $postList[] = $row; } $i = 0; $pcount = 0; - $f->log("Found ".count($postList). " posts with attachments"); - - //XXX Run post through $tp->toHtml() and then use $tp->getTag() to find images or files.? - foreach($postList as $post) + $f -> log("Found " . count($postList) . " posts with attachments"); + + //XXX Run post through $tp->toHtml() and then use $tp->getTag() to find images or + // files.? + foreach ($postList as $post) { -// echo htmlentities($post['post_entry'])."
"; + // echo htmlentities($post['post_entry'])."
"; + $_SESSION['forumupdate_attachment_last'] = $post['post_id']; + $_SESSION['forumupdate_attachment_count']++; + $i++; -// if($pcount++ > 10) { die('here 10'); } + // if($pcount++ > 10) { die('here 10'); } $attachments = array(); $foundFiles = array(); -// echo $post['post_entry']."

"; + // echo $post['post_entry']."

"; //[link={e_FILE}public/1230091080_1_FT0_julia.jpg][img:width=60&height=45]{e_FILE}public/1230091080_1_FT0_julia_.jpg[/img][/link][br] //Check for images with thumbnails linking to full size - if(preg_match_all('#\[link=(.*?)\]\[img.*?\]({e_FILE}.*?)\[/img\]\[/link\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) + if (preg_match_all('#\[link=(.*?)\]\[img.*?\]({e_FILE}.*?)\[/img\]\[/link\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) { - foreach($matches as $match) + foreach ($matches as $match) { $att = array(); - $att['thread_id'] = $post['thread_id']; + $att['thread_id'] = $post['post_thread']; $att['type'] = 'img'; $att['html'] = $match[0]; $att['name'] = $match[1]; @@ -939,12 +1196,12 @@ function step10() } } - if(preg_match_all('#\[link=(.*?)\]\[img.*?\](\.\./\.\./e107_files/public/.*?)\[/img\]\[/link\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) + if (preg_match_all('#\[link=(.*?)\]\[img.*?\](\.\./\.\./e107_files/public/.*?)\[/img\]\[/link\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) { - foreach($matches as $match) + foreach ($matches as $match) { $att = array(); - $att['thread_id'] = $post['thread_id']; + $att['thread_id'] = $post['post_thread']; $att['type'] = 'img'; $att['html'] = $match[0]; $att['name'] = $match[1]; @@ -955,18 +1212,18 @@ function step10() } } - - //
[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]
+ //
[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]
//Check for attached full-size images - if(preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) + if (preg_match_all('#\[img.*?\]({e_FILE}.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) { - foreach($matches as $match) + foreach ($matches as $match) { //Ensure it hasn't already been handled above - if(!in_array($match[1], $foundFiles)) + if (!in_array($match[1], $foundFiles)) { $att = array(); - $att['thread_id'] = $post['thread_id']; + $att['thread_id'] = $post['post_thread']; $att['type'] = 'img'; $att['html'] = $match[0]; $att['name'] = $match[1]; @@ -976,15 +1233,15 @@ function step10() } } - if(preg_match_all('#\[img.*?\](\.\./\.\./e107_files/public/.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) + if (preg_match_all('#\[img.*?\](\.\./\.\./e107_files/public/.*?_FT\d+_.*?)\[/img\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) { - foreach($matches as $match) + foreach ($matches as $match) { //Ensure it hasn't already been handled above - if(!in_array($match[1], $foundFiles)) + if (!in_array($match[1], $foundFiles)) { $att = array(); - $att['thread_id'] = $post['thread_id']; + $att['thread_id'] = $post['post_thread']; $att['type'] = 'img'; $att['html'] = $match[0]; $att['name'] = $match[1]; @@ -996,12 +1253,12 @@ function step10() //[file={e_FILE}public/1230090820_1_FT0_julia.zip]julia.zip[/file] //Check for attached file (non-images) - if(preg_match_all('#\[file=({e_FILE}.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) + if (preg_match_all('#\[file=({e_FILE}.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) { - foreach($matches as $match) + foreach ($matches as $match) { $att = array(); - $att['thread_id'] = $post['thread_id']; + $att['thread_id'] = $post['post_thread']; $att['type'] = 'file'; $att['html'] = $match[0]; $att['name'] = $match[1]; @@ -1010,12 +1267,12 @@ function step10() } } - if(preg_match_all('#\[file=(\.\./\.\./e107_files/public/.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) + if (preg_match_all('#\[file=(\.\./\.\./e107_files/public/.*?)\](.*?)\[/file\]#ms', $post['post_entry'], $matches, PREG_SET_ORDER)) { - foreach($matches as $match) + foreach ($matches as $match) { $att = array(); - $att['thread_id'] = $post['thread_id']; + $att['thread_id'] = $post['post_thread']; $att['type'] = 'file'; $att['html'] = $match[0]; $att['name'] = $match[1]; @@ -1024,90 +1281,54 @@ function step10() } } - if(count($attachments)) + file_put_contents(e_LOG."forum_update_attachments.log",print_r($attachments,true),FILE_APPEND); + + + if (count($attachments)) { - $f->log("found ".count($attachments)." attachments"); + $f->log("found " . count($attachments) . " attachments"); $newValues = array(); $info = array(); $info['post_entry'] = $post['post_entry']; - foreach($attachments as $attachment) + + foreach ($attachments as $attachment) { $error = ''; $f->log($attachment['name']); - if($f->moveAttachment($attachment, $post['post_id'], $error)) + if ($f->moveAttachment($attachment, $post, $error)) { - $fInfo = pathinfo($attachment['name']); -// $_file = split('/', $attachment['name']); - $newval = $attachment['type'].'*'.$fInfo['basename']; - switch($attachment['type']) - { - //If file, add real name to entry - case 'file': - $tmp = explode('_', $fInfo['basename'], 4); - $newval .= '*'.$tmp[3]; - break; - - //If image and it has a thumb, add thumb filename to entry - case 'img': - if($attachment['thumb']) - { - $fInfo = pathinfo($attachment['thumb']); - $newval .= '*'.$fInfo['basename']; - } - break; - } - $newValues[] = $newval; -// echo "Newval = $newval
"; -// echo "Removing from post:".htmlentities($attachment['html'])."
"; + $type = $attachment['type']; + $newValues[$type][] = basename($attachment['name']); $info['post_entry'] = str_replace($attachment['html'], '', $info['post_entry']); } else { $errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}
"; - $f->log("Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}"); + $f -> log("Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}"); } } -// echo $errorText."
"; + // echo $errorText."
"; // Did we make any changes at all? - if(count($newValues)) + if (count($newValues)) { - $info['WHERE'] = 'post_id = '.$post['post_id']; - $info['post_attachments'] = implode(',', $newValues); -// print_a($info); - $sql->db_Update('forum_post', $info); + $info['WHERE'] = 'post_id = ' . $post['post_id']; + $info['post_attachments'] = e107::getArrayStorage()->write($newValues); + // $sql->update('forum_post', $info); // XXX screwed up due to Fields-defs. + + $sql->update('forum_post',"post_entry = \"".$info['post_entry']."\", post_attachments=\"".$info['post_attachments']."\" WHERE post_id = ".$post['post_id']." LIMIT 1"); } -// echo $post['thread_thread']."
"; -// print_a($newValues); -// echo $info['newpost']."
--------------------------------------
"; -// Update db values now + } + + echo round(($_SESSION['forumupdate_attachment_count'] / $_SESSION['forumupdate_attachment_total']) * 100); } } else { - $text = 'No forum attachments found!
'; + echo 100; } -// $forum->forumUpdateLastpost('thread', 84867); - - $text .= " - Successfully migrated forum attachment information for ".count($postList)." post(s). -

-
- -
- "; - $ns->tablerender($stepCaption, $text); -} - -function step10_ajax() //TODO -{ - - - - - } function step11() @@ -1115,7 +1336,7 @@ function step11() $e107 = e107::getInstance(); $ns = e107::getRender(); $stepCaption = 'Step 11: Delete old attachments'; - if(!isset($_POST['delete_orphans'])) + if (!isset($_POST['delete_orphans'])) { $text = " The previous versions of the forum had difficulty deleting attachment files when posts or threads were deleted. @@ -1127,29 +1348,30 @@ function step11() "; - e107::getRender()->tablerender($stepCaption, $text); + e107::getRender() -> tablerender($stepCaption, $text); return; } global $forum; - require_once(e_HANDLER.'file_class.php'); + require_once (e_HANDLER . 'file_class.php'); $f = new e_file; - $flist = $f->get_files(e_FILE.'public', '_\d+_FT\d+_'); + $flist = $f -> get_files(e_FILE . 'public', '_\d+_FT\d+_'); $numFiles = count($flist); - if($numFiles) + if ($numFiles) { - if($_POST['delete_orphans'] == 'Delete files') + if ($_POST['delete_orphans'] == 'Delete files') { //Do the deletion $success = 0; $failText = ''; - foreach($flist as $file) + foreach ($flist as $file) { - $fileName = e_FILE.'public/'.$file['fname']; + $fileName = e_FILE . 'public/' . $file['fname']; $r = unlink($fileName); - if($r) { + if ($r) + { $success++; } else @@ -1157,28 +1379,28 @@ function step11() $failText .= "Deletion failed: {$file['fname']}
"; } } - if($failText) + if ($failText) { - $failText = "

The following failures occured:
".$failText; + $failText = "

The following failures occured:
" . $failText; } $text .= " Successfully removed {$success} orphaned files
{$failText}

-
+
"; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } $text = "There were {$numFiles} orphaned files found

"; - if($_POST['delete_orphans'] == 'Show files' || $numFiles < 31) + if ($_POST['delete_orphans'] == 'Show files' || $numFiles < 31) { - $i=1; - foreach($flist as $file) + $i = 1; + foreach ($flist as $file) { - $text .= $i++.') '.$file['fname'].'
'; + $text .= $i++ . ') ' . $file['fname'] . '
'; } $extra = ''; } @@ -1193,7 +1415,7 @@ function step11() "; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } else @@ -1201,29 +1423,26 @@ function step11() $text .= " There were no orphaned files found


-
+
"; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } } - - - function step12() { - $sql = e107::getDb(); - $ns = e107::getRender(); - $mes = e107::getMessage(); - - $f = new forumUpgrade; - + $sql = e107::getDb(); + $ns = e107::getRender(); + $mes = e107::getMessage(); + + $f = new forumUpgrade; + $stepCaption = 'Step 12: Delete old forum data'; - - if(!isset($_POST['delete_old'])) + + if (!isset($_POST['delete_old'])) { $text = " The forum upgrade should now be complete.
During the upgrade process the old forum tables were @@ -1235,36 +1454,30 @@ function step12() "; - $ns->tablerender($stepCaption, $text); + $ns -> tablerender($stepCaption, $text); return; } $qryArray = array( "DROP TABLE `#forum_old`", "DROP TABLE `#forum_t`", - ); - + // "DELETE FROM `#generic` WHERE gen_type = 'forumUpgrade' " unset($_SESSION['forumUpgrade']); - - foreach($qryArray as $qry) - { - $sql->gen($qry); - } - - $ret = $f->setNewVersion(); - $mes->addSuccess("Congratulations, the forum upgrade is now completed!

{$ret}"); - $ns->tablerender($stepCaption,$mes->render(). $text); + foreach ($qryArray as $qry) + { + $sql -> gen($qry); + } + + $ret = $f -> setNewVersion(); + + $mes -> addSuccess("Congratulations, the forum upgrade is now completed!

{$ret}"); + $ns -> tablerender($stepCaption, $mes -> render() . $text); return; } - - - - - class forumUpgrade { var $newVersion = '2.0'; @@ -1275,50 +1488,52 @@ class forumUpgrade public function __construct() { - $this->updateInfo['lastThread'] = 0; - $this->attachmentData = array(); - $this->logf = e_LOG.'forum_upgrade.txt'; - $this->getUpdateInfo(); + $this -> updateInfo['lastThread'] = 0; + $this -> attachmentData = array(); + $this -> logf = e_LOG . 'forum_upgrade.txt'; + $this -> getUpdateInfo(); } - public function log($msg, $append=true) + public function log($msg, $append = true) { -// echo "logf = ".$this->logf."
"; + // echo "logf = ".$this->logf."
"; $txt = sprintf("%s - %s\n", date('m/d/Y H:i:s'), $msg); -// echo $txt."
"; + // echo $txt."
"; $flag = ($append ? FILE_APPEND : ''); - file_put_contents($this->logf, $txt, $flag); + file_put_contents($this -> logf, $txt, $flag); } public function checkUpdateNeeded() { - return true; - // include_once(e_PLUGIN.'forum/forum_update_check.php'); - // $needed = update_forum_08('check'); - // return !$needed; + return true; + // include_once(e_PLUGIN.'forum/forum_update_check.php'); + // $needed = update_forum_08('check'); + // return !$needed; } function checkAttachmentDirs() { $dirs = array( - e_MEDIA.'files/plugins/forum/attachments/', - e_MEDIA.'files/plugins/forum/attachments/thumb' + e_MEDIA . 'plugins/', + e_MEDIA . 'plugins/forum/', + e_MEDIA . 'plugins/forum/attachments/', + e_MEDIA . 'plugins/forum/attachments/thumb' ); - foreach($dirs as $dir) + foreach ($dirs as $dir) { - if(!file_exists($dir)) + if (!file_exists($dir)) { - if(!mkdir($dir, 0777, true)) + if (!mkdir($dir, 0755, true)) { - $this->error['attach'][] = "Directory '{$dir}' does not exist and I was unable to create it"; + $this -> error['attach'][] = "Directory '{$dir}' does not exist and I was unable to create it"; } } else { - if(!is_writable($dir)) + if (!is_writable($dir)) { - $this->error['attach'][] = "Directory '{$dir}' exits, but is not writeable"; + $this -> error['attach'][] = "Directory '{$dir}' exits, but is not writeable"; } } } @@ -1328,40 +1543,39 @@ class forumUpgrade { $sql = e107::getDb(); $e107 = e107::getInstance(); - - if($_SESSION['forumUpgrade']) + + if ($_SESSION['forumUpgrade']) { - $this->updateInfo = $_SESSION['forumUpgrade']; - } + $this -> updateInfo = $_SESSION['forumUpgrade']; + } else { - $this->updateInfo = array(); + $this -> updateInfo = array(); } - + return; - if($sql->select('generic', '*', "gen_type = 'forumUpgrade'")) + if ($sql -> select('generic', '*', "gen_type = 'forumUpgrade'")) { - $row = $sql->fetch(MYSQL_ASSOC); - $this->updateInfo = unserialize($row['gen_chardata']); + $row = $sql -> fetch(MYSQL_ASSOC); + $this -> updateInfo = unserialize($row['gen_chardata']); } else { $qry = "INSERT INTO `#generic` (gen_type) VALUES ('forumUpgrade')"; - $sql->gen($qry); - $this->updateInfo = array(); + $sql -> gen($qry); + $this -> updateInfo = array(); } } function setUpdateInfo() { - $_SESSION['forumUpgrade'] = $this->updateInfo; + $_SESSION['forumUpgrade'] = $this -> updateInfo; return; - - + $e107 = e107::getInstance(); - $info = mysql_real_escape_string(serialize($this->updateInfo)); + $info = mysql_real_escape_string(serialize($this -> updateInfo)); $qry = "UPDATE `#generic` Set gen_chardata = '{$info}' WHERE gen_type = 'forumUpgrade'"; - e107::getDb()->gen($qry); + e107::getDb() -> gen($qry); } function setNewVersion() @@ -1369,9 +1583,9 @@ class forumUpgrade $pref = e107::getPref(); $e107 = e107::getInstance(); $sql = e107::getDb(); - - $sql->update('plugin',"plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum'"); - $pref['plug_installed']['forum'] = $this->newVersion; + + $sql -> update('plugin', "plugin_version = '{$this->newVersion}' WHERE plugin_name='Forum'"); + $pref['plug_installed']['forum'] = $this -> newVersion; save_prefs(); return "Forum Version updated to version: {$this->newVersion}
"; } @@ -1381,22 +1595,22 @@ class forumUpgrade global $forum; $e107 = e107::getInstance(); $threadId = (int)$threadId; - if(e107::getDb()->select('forum_t', '*', "thread_parent = {$threadId} OR thread_id = {$threadId}", 'default')) + if (e107::getDb() -> select('forum_t', '*', "thread_parent = {$threadId} OR thread_id = {$threadId}", 'default')) { - $threadData = e107::getDb()->db_getList(); - foreach($threadData as $post) + $threadData = e107::getDb() -> db_getList(); + foreach ($threadData as $post) { - if($post['thread_parent'] == 0) + if ($post['thread_parent'] == 0) { - $result = $this->addThread($post); - if($result) + $result = $this -> addThread($post); + if ($result) { - $result = $this->addPost($post); + $result = $this -> addPost($post); } } else { - $result = $this->addPost($post); + $result = $this -> addPost($post); } } return ($result ? count($threadData) : false); @@ -1407,74 +1621,76 @@ class forumUpgrade function addThread(&$post) { global $forum; - + /* - * v1.x - * thread_id - * thread_name - * thread_thread - * thread_forum_id - * thread_datestamp - * thread_parent - * thread_user + * v1.x + * thread_id + * thread_name + * thread_thread + * thread_forum_id + * thread_datestamp + * thread_parent + * thread_user * thread_views - * thread_active - * thread_lastpost - * thread_s - * thread_edit_datestamp - * thread_lastuser + * thread_active + * thread_lastpost + * thread_s + * thread_edit_datestamp + * thread_lastuser * thread_total_replies */ - + /* * v2.x - * thread_id - * thread_name - * thread_forum_id - * thread_views - * thread_active - * thread_lastpost - * thread_sticky - * thread_datestamp - * thread_user - * thread_user_anon - * thread_lastuser - * thread_lastuser_anon - * thread_total_replies + * thread_id + * thread_name + * thread_forum_id + * thread_views + * thread_active + * thread_lastpost + * thread_sticky + * thread_datestamp + * thread_user + * thread_user_anon + * thread_lastuser + * thread_lastuser_anon + * thread_total_replies * thread_options */ - + $thread = array(); - $thread['thread_id'] = $post['thread_id']; - $thread['thread_name'] = $post['thread_name']; - $thread['thread_forum_id'] = $post['thread_forum_id']; - $thread['thread_datestamp'] = $post['thread_datestamp']; - $thread['thread_lastpost'] = $post['thread_lastpost']; - $thread['thread_views'] = $post['thread_views']; - $thread['thread_active'] = $post['thread_active']; - $thread['thread_sticky'] = $post['thread_s']; - // $thread['thread_lastuser'] = $post['thread_lastuser']; - $thread['thread_total_replies'] = $post['thread_total_replies']; - - $userInfo = $this->getUserInfo($post['thread_user']); - $thread['thread_user'] = $userInfo['user_id']; - $thread['thread_user_anon'] = $userInfo['anon_name']; - - // If thread marked as 'tracked by starter', we must convert to using forum_track table - if($thread['thread_active'] == 99 && $thread['thread_user'] > 0) + $thread['thread_id'] = $post['thread_id']; + $thread['thread_name'] = $post['thread_name']; + $thread['thread_forum_id'] = $post['thread_forum_id']; + $thread['thread_datestamp'] = $post['thread_datestamp']; + $thread['thread_lastpost'] = $post['thread_lastpost']; + $thread['thread_views'] = $post['thread_views']; + $thread['thread_active'] = $post['thread_active']; + $thread['thread_sticky'] = $post['thread_s']; + // $thread['thread_lastuser'] = $post['thread_lastuser']; + $thread['thread_total_replies'] = $post['thread_total_replies']; + + $userInfo = $this -> getUserInfo($post['thread_user']); + $thread['thread_user'] = $userInfo['user_id']; + $thread['thread_user_anon'] = $userInfo['anon_name']; + + // If thread marked as 'tracked by starter', we must convert to using + // forum_track table + if ($thread['thread_active'] == 99 && $thread['thread_user'] > 0) { - $forum->track('add', $thread['thread_user'], $thread['thread_id'], true); + $forum -> track('add', $thread['thread_user'], $thread['thread_id'], true); $thread['thread_active'] = 1; } -// $thread['_FIELD_TYPES'] = $forum->fieldTypes['forum_thread']; -// $thread['_FIELD_TYPES']['thread_name'] = 'escape'; //use escape to prevent double entities + // $thread['_FIELD_TYPES'] = $forum->fieldTypes['forum_thread']; + // $thread['_FIELD_TYPES']['thread_name'] = 'escape'; //use escape to prevent + // double entities - $result = e107::getDb()->insert('forum_thread', $thread); + $result = e107::getDb() -> insert('forum_thread', $thread); return $result; -// return $e107->sql->db_Insert('forum_thread', $thread); -// print_a($thread); + // return $e107->sql->db_Insert('forum_thread', $thread); + // print_a($thread); } function addPost(&$post) @@ -1482,25 +1698,26 @@ class forumUpgrade global $forum; $e107 = e107::getInstance(); $newPost = array(); - $newPost['post_id'] = $post['thread_id']; - $newPost['post_thread'] = ($post['thread_parent'] == 0 ? $post['thread_id'] : $post['thread_parent']); - $newPost['post_entry'] = $post['thread_thread']; - $newPost['post_forum'] = $post['thread_forum_id']; - $newPost['post_datestamp'] = $post['thread_datestamp']; + $newPost['post_id'] = $post['thread_id']; + $newPost['post_thread'] = ($post['thread_parent'] == 0 ? $post['thread_id'] : $post['thread_parent']); + $newPost['post_entry'] = $post['thread_thread']; + $newPost['post_forum'] = $post['thread_forum_id']; + $newPost['post_datestamp'] = $post['thread_datestamp']; $newPost['post_edit_datestamp'] = ($post['thread_edit_datestamp'] ? $post['thread_edit_datestamp'] : '_NULL_'); - $userInfo = $this->getUserInfo($post['thread_user']); - - $newPost['post_user'] = $userInfo['user_id']; - $newPost['post_user_anon'] = $userInfo['anon_name']; - $newPost['post_ip'] = $userInfo['user_ip']; + $userInfo = $this -> getUserInfo($post['thread_user']); -// $newPost['_FIELD_TYPES'] = $forum->fieldTypes['forum_post']; -// $newPost['_FIELD_TYPES']['post_entry'] = 'escape'; //use escape to prevent double entities -// print_a($newPost); -// exit; - $result = e107::getDb()->insert('forum_post', $newPost); -// exit; + $newPost['post_user'] = $userInfo['user_id']; + $newPost['post_user_anon'] = $userInfo['anon_name']; + $newPost['post_ip'] = $userInfo['user_ip']; + + // $newPost['_FIELD_TYPES'] = $forum->fieldTypes['forum_post']; + // $newPost['_FIELD_TYPES']['post_entry'] = 'escape'; //use escape to prevent + // double entities + // print_a($newPost); + // exit; + $result = e107::getDb() -> insert('forum_post', $newPost); + // exit; return $result; } @@ -1510,20 +1727,20 @@ class forumUpgrade $e107 = e107::getInstance(); $tmp = explode('.', $info); $ret = array( - 'user_id' => 0, - 'user_ip' => '_NULL_', - 'anon_name' => '_NULL_' + 'user_id' => 0, + 'user_ip' => '_NULL_', + 'anon_name' => '_NULL_' ); - if(count($tmp) == 2) + if (count($tmp) == 2) { $id = (int)$tmp[0]; - if($id == 0) //Anonymous post + if ($id == 0)//Anonymous post { $_tmp = explode(chr(0), $tmp[1]); - if(count($_tmp) == 2) //Ip address exists + if (count($_tmp) == 2)//Ip address exists { - $ret['user_ip'] = $e107->ipEncode($_tmp[1]); + $ret['user_ip'] = $e107 -> ipEncode($_tmp[1]); $ret['anon_name'] = $_tmp[0]; } } @@ -1534,7 +1751,7 @@ class forumUpgrade } else { - if(is_numeric($info) && $info > 0) + if (is_numeric($info) && $info > 0) { $ret['user_id'] = $info; } @@ -1546,20 +1763,35 @@ class forumUpgrade return $ret; } - function moveAttachment($attachment, $post_id, &$error) + function moveAttachment($attachment, $post, &$error) { + global $forum; set_time_limit(30); -// $tmp = explode('/', $attachment['name']); - $attachment['name'] = str_replace(array(' ', "\n", "\r"), '', $attachment['name']); + $tp = e107::getParser(); + + $post_id = $post['post_id']; + $newPath = $forum->getAttachmentPath($post['post_user']); + + if (!is_dir($newPath)) + { + mkdir($newPath, 0755); + } + + $attachment['name'] = str_replace(array( + ' ', + "\n", + "\r" + ), '', $attachment['name']); $old = str_replace('{e_FILE}', e_FILE, $attachment['name']); $fileInfo = pathinfo($attachment['name']); - $new = e_MEDIA.'files/plugins/forum/attachments/'.$fileInfo['basename']; + $new = $newPath . "/" . $fileInfo['basename']; $hash = md5($new); - if(!file_exists($old)) + + if (!file_exists($old)) { - if(isset($this->attachmentData[$hash])) + if (isset($this -> attachmentData[$hash])) { - $error = "Post {$post_id} - Attachment already migrated with post: ".$this->attachmentData[$hash]; + $error = "Post {$post_id} - Attachment already migrated with post: " . $this -> attachmentData[$hash]; } else { @@ -1567,19 +1799,20 @@ class forumUpgrade } return false; } - if(!file_exists($new)) + + if (!file_exists($new)) { - $this->log("Copying [{$old}] -> [{$new}]"); - $r = copy($old, $new); - $this->attachmentData[$hash] = $post_id; -// $r = true; + $this -> log("Copying [{$old}] -> [{$new}]"); + $r = rename($old, $new); + $this -> attachmentData[$hash] = $post_id; + // $r = true; } else { //File already exists, show some sort of error - if(isset($this->attachmentData[$hash])) + if (isset($this -> attachmentData[$hash])) { - $error = "Post {$post_id} - Attachment already migrated with post: ".$this->attachmentData[$hash]; + $error = "Post {$post_id} - Attachment already migrated with post: " . $this -> attachmentData[$hash]; } else { @@ -1587,71 +1820,72 @@ class forumUpgrade } return false; } - if(!$r) + + if (!$r) { //File copy failed! - $error = 'Copy of attachments failed'; + $error = 'Moving of attachments failed'; return false; } $oldThumb = ''; - if($attachment['thumb']) + if ($attachment['thumb']) { $tmp = explode('/', $attachment['thumb']); $fileInfo = pathinfo($attachment['thumb']); $oldThumb = str_replace('{e_FILE}', e_FILE, $attachment['thumb']); -// $newThumb = e_PLUGIN.'forum/attachments/thumb/'.$tmp[1]; - $newThumb = e_MEDIA.'files/plugins/forum/attachments/thumb/'.$fileInfo['basename']; + // $newThumb = e_PLUGIN.'forum/attachments/thumb/'.$tmp[1]; + $newThumb = e_MEDIA . 'files/plugins/forum/attachments/thumb/' . $fileInfo['basename']; $hash = md5($newThumb); - if(!file_exists($newThumb)) + + if (!file_exists($newThumb)) { - $r = copy($oldThumb, $newThumb); -// $r = true; + $r = rename($oldThumb, $newThumb); + // $r = true; } else { //File already exists, show some sort of error - if(isset($this->attachmentData[$hash])) + if (isset($this -> attachmentData[$hash])) { - $error = "Post {$post_id} - Thumb already migrated with post: ".$this->attachmentData[$hash]; + $error = "Post {$post_id} - Thumb already migrated with post: " . $this -> attachmentData[$hash]; } else { - $error = 'Thumb file already exists'; + $error = 'Thumb file already exists'; } return false; } - if(!$r) + if (!$r) { //File copy failed - $error = 'Copy of thumb failed'; + $error = 'Moving of thumb failed'; return false; } } //Copy was successful, let's delete the original files now. -// $r = true; - $r = unlink($old); - if(!$r) + // $r = true; + // $r = unlink($old); + if (!$r) { - $error = 'Was unable to delete old attachment: '.$old; - return false; + // $error = 'Was unable to delete old attachment: '.$old; + // return false; } - if($oldThumb) + if ($oldThumb) { -// $r = true; - $r = unlink($oldThumb); - if(!$r) + // $r = true; + // $r = unlink($oldThumb); + if (!$r) { - $error = 'Was unable to delete old thumb: '.$oldThumb; - return false; + // $error = 'Was unable to delete old thumb: '.$oldThumb; + // return false; } } return true; } - } function createThreadLimitDropdown($count) @@ -1660,16 +1894,17 @@ function createThreadLimitDropdown($count)