1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-16 20:41:27 +02:00

Forum upgrade fixes. Forum-attachments now converted in batches.

This commit is contained in:
Cameron
2013-03-31 00:06:21 -07:00
parent 1b0760008a
commit eae211fc63
12 changed files with 1025 additions and 705 deletions

View File

@@ -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'))
{

View File

@@ -81,7 +81,6 @@
'news' => 'news',
'page' => 'page',
)]]></core>
<core name="email_notify">0</core>
<core name="email_text"></core>
<core name="emotepack">default</core>
<core name="enable_rdns">0</core>

View File

@@ -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.
@@ -2421,6 +2427,20 @@ class e_parser
}
/**
* 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.
* @param $html - raw html code

View File

@@ -73,6 +73,8 @@ class e_file
*/
public $fileFilter;
public $filesRejected = array();
/**
* Defines what array format should return get_files() method
* If one of 'fname', 'path', 'full' - numerical array.
@@ -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
}
}
@@ -574,10 +577,9 @@ class e_file
$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);
$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)

View File

@@ -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,6 +750,9 @@ class e_db_mysql
}
$fieldTypes = $this->_getTypes($arg);
$new_data = '';
foreach ($arg['data'] as $fn => $fv)
{
$new_data .= ($new_data ? ', ' : '');
@@ -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

View File

@@ -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 <b>".$path."_setup.php</b> ");
}
@@ -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 <b>".$class_name." :: ".$method_name."()</b>");
}
@@ -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.");
}

View File

@@ -224,17 +224,13 @@ class themeHandler
function getThemeInfo($file)
{
$STYLESHEET = FALSE;
$mes = e107::getMessage();
$reject = array('e_.*');
$handle2 = e107::getFile()->get_files(e_THEME.$file."/", ".php|.css|.xml|preview.jpg|preview.png", $reject, 1);
$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);
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);
}
}

View File

@@ -148,6 +148,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.
*/

View File

@@ -10,7 +10,6 @@
*
*/
define('e_ADMIN_AREA', true);
require_once ('../../class2.php');
@@ -20,7 +19,6 @@ if (!getperms('P'))
exit ;
}
error_reporting(E_ALL);
require_once (e_PLUGIN . 'forum/forum_class.php');
require_once (e_ADMIN . 'auth.php');
@@ -63,8 +61,6 @@ if(e_AJAX_REQUEST)
exit ;
}
$upgradeNeeded = $f -> checkUpdateNeeded();
$upgradeNeeded = true;
if (!$upgradeNeeded)
@@ -94,7 +90,6 @@ if(isset($_POST) && count($_POST))
}
}
$currentStep = (isset($f -> updateInfo['currentStep']) ? $f -> updateInfo['currentStep'] : 1);
$stepParms = (isset($stepParms) ? $stepParms : '');
@@ -107,7 +102,6 @@ if(function_exists('step'.$currentStep))
require (e_ADMIN . 'footer.php');
exit ;
function step1()
{
@@ -176,7 +170,13 @@ function step2()
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 = '';
@@ -211,8 +211,8 @@ function step2()
$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()
{
@@ -318,7 +318,9 @@ function step4()
}
}
$forumPrefList = array(
'reported_post_email', 'email_notify', 'email_notify_on'
'reported_post_email',
'email_notify',
'email_notify_on'
);
foreach ($forumPrefList as $_fp)
@@ -352,13 +354,11 @@ 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 . '<br />';
$debug .= 'viewed = ' . $viewed . '<br />';
$debug .= 'realm = ' . $realm . '<br />';
@@ -430,7 +430,12 @@ function step5()
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'))
{
@@ -463,7 +468,6 @@ function step5()
$mes -> addError("Insert failed on " . print_a($tmp, true));
}
}
$mes -> addSuccess("
@@ -481,7 +485,6 @@ function step5()
$result = $sql -> gen('RENAME TABLE `#forum_new` TO `#forum` ') ? e_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes -> add("Renaming forum_new to forum", $result);
$text = "
<form method='post' action='" . e_SELF . "?step=6'>
<input class='btn button' type='submit' name='nextStep[6]' value='Proceed to step 6' />
@@ -569,7 +572,6 @@ function step6x()
$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)
@@ -612,7 +614,6 @@ 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_count'] = 0;
$_SESSION['forumupdate_thread_last'] = 0;
@@ -621,7 +622,8 @@ function step6()
Depending on your forum size and speed of server, this could take some time.<br /><br /> ";
// $text .= "<form method='post'>
// There are {$count} forum threads to convert, we will be doing it in steps of: {$limitDropdown}
// There are {$count} forum threads to convert, we will be doing it in steps of:
// {$limitDropdown}
// <br /><br />";
$text .= '
@@ -640,13 +642,8 @@ function step6()
</form>";
$ns -> tablerender($stepCaption, $mes -> render() . $text);
}
function step6_ajax()
{
global $f;
@@ -688,10 +685,6 @@ function step6_ajax()
}
function step7()
{
$e107 = e107::getInstance();
@@ -721,7 +714,6 @@ function step7()
}
$forum -> forumUpdateCounts('all', true);
// var_dump($counts);
$text .= "
@@ -734,18 +726,11 @@ function step7()
$ns -> tablerender($stepCaption, $text);
}
function step7_ajax()//TODO
{
}
function step8()
{
$e107 = e107::getInstance();
@@ -767,10 +752,8 @@ function step8()
$forum -> forumUpdateLastpost('forum', 'all', true);
// $forum->forumUpdateLastpost('thread', 84867);
$text .= "
Successfully recalculated lastpost information for all forums and threads.
<br /><br />
@@ -781,21 +764,11 @@ function step8()
e107::getRender() -> tablerender($stepCaption, $text);
}
function step8_ajax()//TODO
{
}
function step9()
{
$e107 = e107::getInstance();
@@ -865,13 +838,10 @@ function step9()
function step9_ajax()//TODO
{
}
function step10()
/*
function step10x()
{
$e107 = e107::getInstance();
$sql = e107::getDb();
@@ -885,10 +855,13 @@ function step10()
{
$text = "
This step will migrate all forum attachment information.<br />
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.
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.
<br /><br />
<form method='post'>
<input class='btn button' type='submit' name='migrate_attachments' value='Proceed with attachment migration' />
<input class='btn button' type='submit' name='migrate_attachments'
value='Proceed with attachment migration' />
</form>
";
$ns->tablerender($stepCaption, $text);
@@ -910,7 +883,8 @@ function step10()
$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.?
//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'])."<br />";
@@ -923,7 +897,8 @@ function step10()
//[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)
{
@@ -939,7 +914,8 @@ 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)
{
@@ -955,10 +931,11 @@ function step10()
}
}
//<div class=&#039;spacer&#039;>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div>
//<div
// class=&#039;spacer&#039;>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div>
//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)
{
@@ -976,7 +953,8 @@ 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)
{
@@ -996,7 +974,8 @@ 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)
{
@@ -1010,7 +989,8 @@ 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)
{
@@ -1063,8 +1043,10 @@ function step10()
}
else
{
$errorText .= "Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}<br />";
$f->log("Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}");
$errorText .= "Failure processing post {$post['post_id']} - file
{$attachment['name']} - {$error}<br />";
$f->log("Failure processing post {$post['post_id']} - file {$attachment['name']}
- {$error}");
}
}
// echo $errorText."<br />";
@@ -1079,7 +1061,8 @@ function step10()
}
// echo $post['thread_thread']."<br />";
// print_a($newValues);
// echo $info['newpost']."<br />--------------------------------------<br />";
// echo $info['newpost']."<br />--------------------------------------<br
// />";
// Update db values now
}
}
@@ -1092,21 +1075,259 @@ function step10()
// $forum->forumUpdateLastpost('thread', 84867);
$text .= "
Successfully migrated forum attachment information for ".count($postList)." post(s).
Successfully migrated forum attachment information for ".count($postList)."
post(s).
<br /><br />
<form method='post' action='".e_SELF."?step=11'>
<input class='btn button' type='submit' name='nextStep[11]' value='Proceed to
step 11' />
</form>
";
$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';
$_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 .= "
No forum attachments found.
<br /><br />
<form method='post' action='" . e_SELF . "?step=11'>
<input class='btn button' type='submit' name='nextStep[11]' value='Proceed to step 11' />
</form>
";
$ns -> tablerender($stepCaption, $text);
return;
}
$text = "
This step will migrate the forum attachment information that was found in <b>" . $_SESSION['forumupdate_attachment_total'] . "</b> posts.<br />
All files will be moved from the e107_files/public directory into the <b>" . e_MEDIA . "plugins/forum/ </b> directory and related posts will be updated accordingly.
<br /><br />
";
$text .= '
<div class="row-fluid">
<div class="span9 well">
<div class="progress progress-success progress-striped active" id="progressouter">
<div class="bar" id="progress"></div>
</div>
<a id="step10" data-progress="' . e_SELF . '" data-progress-mode="10" data-progress-show="step11" data-progress-hide="step10" class="btn btn-primary e-progress" >Begin attachment migration</a>
</div>
</div>';
$text .= "<form method='post' action='" . e_SELF . "?step=11'>
<input id='step11' style='display:none' class='btn button' type='submit' name='nextStep[11]' value='Proceed to step 11' />
</form>";
$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_thread, post_entry, post_user FROM `#forum_post`
WHERE post_entry REGEXP '_[[:digit:]]+_FT'
AND post_id > {$lastPost} LIMIT 1
";
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'])."<br />";
$_SESSION['forumupdate_attachment_last'] = $post['post_id'];
$_SESSION['forumupdate_attachment_count']++;
$i++;
// if($pcount++ > 10) { die('here 10'); }
$attachments = array();
$foundFiles = array();
// echo $post['post_entry']."<br /><br />";
//[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['post_thread'];
$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['post_thread'];
$att['type'] = 'img';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = $match[2];
$attachments[] = $att;
$foundFiles[] = $match[1];
$foundFiles[] = $match[2];
}
}
//<div
// class=&#039;spacer&#039;>[img:width=604&height=453]{e_FILE}public/1229562306_1_FT0_julia.jpg[/img]</div>
//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['post_thread'];
$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['post_thread'];
$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['post_thread'];
$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['post_thread'];
$att['type'] = 'file';
$att['html'] = $match[0];
$att['name'] = $match[1];
$att['thumb'] = '';
$attachments[] = $att;
}
}
file_put_contents(e_LOG."forum_update_attachments.log",print_r($attachments,true),FILE_APPEND);
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, $error))
{
$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}<br />";
$f -> log("Failure processing post {$post['post_id']} - file {$attachment['name']} - {$error}");
}
}
// echo $errorText."<br />";
// Did we make any changes at all?
if (count($newValues))
{
$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 round(($_SESSION['forumupdate_attachment_count'] / $_SESSION['forumupdate_attachment_total']) * 100);
}
}
else
{
echo 100;
}
}
@@ -1149,7 +1370,8 @@ function step11()
{
$fileName = e_FILE . 'public/' . $file['fname'];
$r = unlink($fileName);
if($r) {
if ($r)
{
$success++;
}
else
@@ -1210,9 +1432,6 @@ function step11()
}
}
function step12()
{
$sql = e107::getDb();
@@ -1242,7 +1461,6 @@ function step12()
$qryArray = array(
"DROP TABLE `#forum_old`",
"DROP TABLE `#forum_t`",
);
// "DELETE FROM `#generic` WHERE gen_type = 'forumUpgrade' "
@@ -1260,11 +1478,6 @@ function step12()
return;
}
class forumUpgrade
{
var $newVersion = '2.0';
@@ -1301,15 +1514,17 @@ class forumUpgrade
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)
{
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";
}
@@ -1357,7 +1572,6 @@ class forumUpgrade
$_SESSION['forumUpgrade'] = $this -> updateInfo;
return;
$e107 = e107::getInstance();
$info = mysql_real_escape_string(serialize($this -> updateInfo));
$qry = "UPDATE `#generic` Set gen_chardata = '{$info}' WHERE gen_type = 'forumUpgrade'";
@@ -1460,7 +1674,8 @@ class forumUpgrade
$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 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);
@@ -1468,7 +1683,8 @@ class forumUpgrade
}
// $thread['_FIELD_TYPES'] = $forum->fieldTypes['forum_thread'];
// $thread['_FIELD_TYPES']['thread_name'] = 'escape'; //use escape to prevent double entities
// $thread['_FIELD_TYPES']['thread_name'] = 'escape'; //use escape to prevent
// double entities
$result = e107::getDb() -> insert('forum_thread', $thread);
return $result;
@@ -1496,7 +1712,8 @@ class forumUpgrade
$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
// $newPost['_FIELD_TYPES']['post_entry'] = 'escape'; //use escape to prevent
// double entities
// print_a($newPost);
// exit;
$result = e107::getDb() -> insert('forum_post', $newPost);
@@ -1546,15 +1763,30 @@ 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 (isset($this -> attachmentData[$hash]))
@@ -1567,10 +1799,11 @@ class forumUpgrade
}
return false;
}
if (!file_exists($new))
{
$this -> log("Copying [{$old}] -> [{$new}]");
$r = copy($old, $new);
$r = rename($old, $new);
$this -> attachmentData[$hash] = $post_id;
// $r = true;
}
@@ -1587,10 +1820,11 @@ class forumUpgrade
}
return false;
}
if (!$r)
{
//File copy failed!
$error = 'Copy of attachments failed';
$error = 'Moving of attachments failed';
return false;
}
@@ -1604,9 +1838,10 @@ class forumUpgrade
// $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))
{
$r = copy($oldThumb, $newThumb);
$r = rename($oldThumb, $newThumb);
// $r = true;
}
else
@@ -1625,33 +1860,32 @@ class forumUpgrade
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);
// $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)
{
// $r = true;
$r = unlink($oldThumb);
// $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,7 +1894,8 @@ function createThreadLimitDropdown($count)
<select class='tbox' name='threadLimit'>
";
$last = min($count, 10000);
if($count < 2000) {
if ($count < 2000)
{
$ret .= "<option value='{$count}'>{$count}</option>";
}
else
@@ -1678,7 +1913,6 @@ function createThreadLimitDropdown($count)
return $ret;
}
function forum_update_adminmenu()
{
$action = 1;
@@ -1719,7 +1953,6 @@ function forum_update_adminmenu()
$var[12]['text'] = '12 - Delete old forum data';
$var[12]['link'] = '#';
if (isset($_GET['step']))
{
// $action = key($_POST['nextStep']);
@@ -1728,5 +1961,4 @@ function forum_update_adminmenu()
show_admin_menu('Forum Upgrade', $action, $var);
}
?>

View File

@@ -36,6 +36,9 @@ if (!e_QUERY)
exit;
}
// include_lan(e_PLUGIN . 'forum/languages/'.e_LANGUAGE.'/lan_forum_viewtopic.php');
include_once (e_PLUGIN . 'forum/forum_class.php');
@@ -43,6 +46,15 @@ include_once (e_PLUGIN . 'forum/forum_class.php');
$forum = new e107forum();
$thread = new e107ForumThread();
if(vartrue($_GET['id']) && isset($_GET['dl']))
{
$forum->sendFile($_GET);
exit;
}
if(e_AJAX_REQUEST && varset($_POST['action']) == 'quickreply')
{
$forum->ajaxQuickReply();

View File

@@ -71,35 +71,60 @@ class plugin_forum_view_shortcodes extends e_shortcode
}
}
function sc_attachments()
{
$tp = e107::getParser();
if($this->postInfo['post_attachments'])
{
$baseDir = e_MEDIA_ABS.'files/plugins/forum/attachments/';
$attachments = explode(',', $this->postInfo['post_attachments']);
$txt = '';
foreach($attachments as $a)
$baseDir = $this->forum->getAttachmentPath($this->postInfo['post_user']);
$images = array();
$attachArray = e107::getArrayStorage()->read($this->postInfo['post_attachments']);
foreach($attachArray as $type=>$vals)
{
$info = explode('*', $a);
switch($info[0])
foreach($vals as $key=>$file)
{
list($date,$user,$tmp,$name) = explode("_",$file,4);
switch($type)
{
case 'file':
$txt .= IMAGE_attachment." <a href='{$baseDir}{$info[1]}'>{$info[2]}</a><br />";
$url = e_SELF."?id=".$this->postInfo['post_id']."&amp;dl=".$key;
$txt .= IMAGE_attachment." <a href='".$url."'>{$name}</a><br />";
break;
case 'img':
//if image has a thumb, show it and link to main
if(isset($info[2]))
case 'img': //Always use thumb to hide the hash.
$thumb = $tp->thumbUrl($baseDir.$file,'x=1',true);
$full = $tp->thumbUrl($baseDir.$file,'w=1000&x=1', true);
$inc = (vartrue($parm['modal'])) ? "data-toggle='modal' data-target='#".$parm['modal']."' " : "";
$images[] = "<a {$inc} rel='external' href='{$full}'><img class='thumbnail' src='{$thumb}' alt='' /></a>";
break;
}
}
}
if(count($images) )
{
$txt .= "<a href='{$baseDir}{$info[1]}'><img src='{$baseDir}thumb/{$info[2]}' alt='' /></a><br />";
}
else
{
$txt .= "<img src='{$baseDir}{$info[1]}' alt='' /><br />";
}
}
return (deftrue('e_BOOTSTRAP')) ? "<ul class='thumbnails'><li>".implode("</li><li>",$images)."</li></ul>" : implode("<br />",$images);
}
return $txt;
}
}

View File

@@ -339,14 +339,12 @@ $FORUM_VIEWTOPIC_TEMPLATE['thread'] = "
{CUSTOMTITLE}
{AVATAR}
{USERCOMBO}
<div>
</div>
</div>
<div class='span9 '>
{POLL}
{POST}
{ATTACHMENTS}
</div>
</div>
@@ -356,7 +354,7 @@ $FORUM_VIEWTOPIC_TEMPLATE['thread'] = "
&nbsp;
</div>
<div class='span9 finfobar' >
<small>{ATTACHMENTS} {SIGNATURE=clean}</small>
<small> {SIGNATURE=clean}</small>
</div>
<div class='span3'>