From 0f79de35b16e6f2d7f576dd963e0ea9aa2dbe611 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 6 Feb 2015 13:38:43 -0800 Subject: [PATCH] Quick cleanup of upload.php --- .../shortcodes/batch/download_shortcodes.php | 2 +- upload.php | 518 +++++++++++++----- 2 files changed, 384 insertions(+), 136 deletions(-) diff --git a/e107_core/shortcodes/batch/download_shortcodes.php b/e107_core/shortcodes/batch/download_shortcodes.php index 3f875496e..86c928afc 100644 --- a/e107_core/shortcodes/batch/download_shortcodes.php +++ b/e107_core/shortcodes/batch/download_shortcodes.php @@ -447,7 +447,7 @@ SC_BEGIN DOWNLOAD_CATEGORY_SELECT exit; } - $boxinfo .= " \n"; // Its a structured display option - need a 2-step process to create a tree diff --git a/upload.php b/upload.php index 55846ba25..4228eb5d0 100644 --- a/upload.php +++ b/upload.php @@ -17,9 +17,382 @@ if (!$pref['upload_enabled'] || $pref['upload_class'] == 255) exit; } +if (!defined("USER_WIDTH") && defset('BOOTSTRAP')==false){ define("USER_WIDTH","width:97%"); } + +require_once(e_HANDLER.'upload_handler.php'); + +class userUpload +{ + function __construct() + { + + + /* + e107::css('inline', " + input[type=file] { + + + } + "); + + e107::js('inline', " + + function frmVerify() + { + var message = ''; + var spacer = ''; + var testObjects = new Array(\"download_category\", \"user_email\", \"file_name\", \"file_realpath\", \"file_description\"); + var errorMessages = new Array('".LAN_UL_032."', '".LAN_UL_033."', '".LAN_UL_034."', '".LAN_UL_036."', '".LAN_UL_035."'); + var temp; + var i; + for (i = 0; i < 5; i++) + { + temp = document.getElementById(testObjects[i]); + if (temp && (temp.value == \"\")) + { + message = message + spacer + errorMessages[i]; + spacer = '\\n'; + } + } + if (message) + { + alert(message); + return false; + } + } + + "); + */ + + + + + } + + + public function init() + { + $ns = e107::getRender(); + + $uploadAccess = e107::pref('core','upload_class'); + + if(!check_class($uploadAccess)) + { + $text = "
".LAN_UL_002."
"; + $ns->tablerender(LAN_UL_020, $text); + return; + } + + + if (isset($_POST['upload'])) + { + $this->processUpload(); + return; + } + + $this->renderForm(); + + } + + + function processUpload() + { + $ns = e107::getRender(); + $sql = e107::getDb(); + $mes = e107::getMessage(); + $tp = e107::getParser(); + + $error = false; + $postemail =''; + + if (($_POST['file_email'] || USER == TRUE) && $_POST['file_name'] && $_POST['file_description'] && $_POST['download_category']) + { + + // $uploaded = file_upload(e_FILE."public/", "unique"); + $fl = e107::getFile(); + $uploaded = $fl->getUploaded(e_UPLOAD, "unique", array('max_file_count' => 2, 'extra_file_types' => TRUE)); + + // $uploaded = process_uploaded_files(e_UPLOAD, "unique", array('max_file_count' => 2, 'extra_file_types' => TRUE)); + + // First, see what errors the upload handler picked up + if ($uploaded === FALSE) + { + $error = true; + $mes->addError(LAN_UL_021); + } + + // Now see if we have a code file + if (count($uploaded) > 0) + { + if ($uploaded[0]['error'] == 0) + { + $file = $uploaded[0]['name']; + $filesize = $uploaded[0]['size']; + } + else + { + $error = true; + $mes->addError($uploaded[0]['message']); + } + } + + // Now see if we have an image file + if (count($uploaded) > 1) + { + if ($uploaded[1]['error'] == 0) + { + $image = $uploaded[1]['name']; + } + else + { + $error = true; + $mes->addError($uploaded[1]['message']); + } + } + + // The upload handler checks max file size + $downloadCategory = intval($_POST['download_category']); + if (!$downloadCategory) + { + $error = true; + $mes->addError(LAN_UL_037); + } + + // an error - delete the files to keep things tidy + if ($error) + { + @unlink($file); + @unlink($image); + } + else + { + if (USER) + { + $poster = USERID; + $row = e107::getUser()->toArray(); + if ($row['user_hideemail']) + { + $postemail = '-witheld-'; + } + else + { + $postemail = USEREMAIL; + } + } + else + { + $poster = "0";//.$tp -> toDB($_POST['file_poster']); + $postemail = $tp->toDB($_POST['file_email']); + } + if (($postemail != '-witheld-') && !check_email($postemail)) + { + $error = true; + $mes->addError(LAN_UL_001); + } + else + { + if ($postemail == '-witheld-') $postemail = ''; + + $_POST['file_description'] = $tp->toDB($_POST['file_description']); + + $file_time = time(); + + $sql->insert("upload", "0, '".$poster."', '".$postemail."', '".$tp -> toDB($_POST['file_website'])."', '".$file_time."', '".$tp -> toDB($_POST['file_name'])."', '".$tp -> toDB($_POST['file_version'])."', '".$file."', '".$image."', '".$tp -> toDB($_POST['file_description'])."', '".$tp -> toDB($_POST['file_demo'])."', '".$filesize."', 0, '".$downloadCategory."'"); + + $edata_fu = array("upload_user" => $poster, "upload_email" => $postemail, "upload_name" => $tp -> toDB($_POST['file_name']),"upload_file" => $file, "upload_version" => $_POST['file_version'], "upload_description" => $tp -> toDB($_POST['file_description']), "upload_size" => $filesize, "upload_category" => $downloadCategory, "upload_website" => $tp -> toDB($_POST['file_website']), "upload_image" => $image, "upload_demo" => $tp -> toDB($_POST['file_demo']), "upload_time" => $file_time); + + e107::getEvent()->trigger("fileupload", $edata_fu); + + $mes->addSuccess(LAN_404); + } + } + } + else + { // Error - missing data + $mes->addError(LAN_ERROR_29); + } + + echo e107::getMessage()->render(); + + } + + + + + + + function renderForm() + { + /* + $template = " +
+ +
+ +
+
"; + */ + + $ns = e107::getRender(); + $tp = e107::getParser(); + + $text = "
+
+ + + + + + + + + + + + + "; + + //TODO Replcae all form inputs with $frm methods. + + if (!USER) // Prompt for name, email + { + $text .= " + + + + + + + + "; + } + + $text .= " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
".DOWLAN_11.":"; + + require_once(e_CORE."shortcodes/batch/download_shortcodes.php"); + $dlparm = (isset($download_category)) ? $download_category : ""; + $text .= $tp->parseTemplate("{DOWNLOAD_CATEGORY_SELECT={$dlparm}}",true,$download_shortcodes); //FIXME - move to e_upload.php + + + $text .= "
".LAN_419.""; + + // $text .= "".LAN_406."
".LAN_419.":"; + + + + $a_filetypes = get_filetypes(); + + if (count($a_filetypes) == 0) + { + $ns->tablerender(LAN_417, LAN_UL_025); + return; + } + + $max_upload_size = calc_max_upload_size(-1); // Find overriding maximum upload size + $max_upload_size = set_max_size($a_filetypes, $max_upload_size); + + + if (ADMIN) + { + $upper_limit = calc_max_upload_size(); + $allowed_filetypes = ""; + + foreach ($a_filetypes as $type => $size) + { + $allowed_filetypes .= ""; + } + + $allowed_filetypes .= "
".LAN_UL_023."  ".LAN_UL_024."
{$type}".eHelper::parseMemorySize($size,0)."
"; + } + else + { + $a_filetypes = array_keys($a_filetypes); + $allowed_filetypes = implode(' | ', $a_filetypes); + } + + $text .= " ".$allowed_filetypes; + + $text .= "
".LAN_407."
".LAN_418.eHelper::parseMemorySize($max_upload_size,0)." (".LAN_UL_022.")
"; + + $text .= "".LAN_408." ".LAN_420; + + $text .= "
"; + + $text .= "
".LAN_61."
".LAN_112."
".LAN_409."
".LAN_410."
".LAN_411."
".LAN_412."
".LAN_413."
".LAN_144."
".LAN_414."
".LAN_415."
+
+
"; + + + $ns->tablerender(LAN_417, $text); + + } + + + //TODO Shortcodes for the form elements above. + function sc_author() + { + + return ""; + + } + +} + +$up = new userUpload(); + require_once(HEADERF); -if (!defined("USER_WIDTH")){ define("USER_WIDTH","width:97%"); } +$up->init(); + + + +require_once(FOOTERF); +exit; + + + + +/* if (!check_class($pref['upload_class'])) { @@ -28,123 +401,26 @@ if (!check_class($pref['upload_class'])) require_once(FOOTERF); exit; } +*/ -$postemail =''; -$msghandler = e107::getMessage(); -$error = false; -if (isset($_POST['upload'])) -{ - if (($_POST['file_email'] || USER == TRUE) && $_POST['file_name'] && $_POST['file_description'] && $_POST['download_category']) - { - require_once(e_HANDLER."upload_handler.php"); - // $uploaded = file_upload(e_FILE."public/", "unique"); - $uploaded = process_uploaded_files(e_UPLOAD, "unique", array('max_file_count' => 2, 'extra_file_types' => TRUE)); - // First, see what errors the upload handler picked up - if ($uploaded === FALSE) - { - $error = true; - $msghandler->addError(LAN_UL_021); - } - // Now see if we have a code file - if (count($uploaded) > 0) - { - if ($uploaded[0]['error'] == 0) - { - $file = $uploaded[0]['name']; - $filesize = $uploaded[0]['size']; - } - else - { - $error = true; - $msghandler->addError($uploaded[0]['message']); - } - } - // Now see if we have an image file - if (count($uploaded) > 1) - { - if ($uploaded[1]['error'] == 0) - { - $image = $uploaded[1]['name']; - } - else - { - $error = true; - $msghandler->addError($uploaded[1]['message']); - } - } - // The upload handler checks max file size - $downloadCategory = intval($_POST['download_category']); - if (!$downloadCategory) - { - $error = true; - $msghandler->addError(LAN_UL_037); - } - // an error - delete the files to keep things tidy - if ($error) - { - @unlink($file); - @unlink($image); - } - else - { - if (USER) - { - $poster = USERID; - $row = e107::getUser()->toArray(); - if ($row['user_hideemail']) - { - $postemail = '-witheld-'; - } - else - { - $postemail = USEREMAIL; - } - } - else - { - $poster = "0";//.$tp -> toDB($_POST['file_poster']); - $postemail = $tp->toDB($_POST['file_email']); - } - if (($postemail != '-witheld-') && !check_email($postemail)) - { - $error = true; - $msghandler->addError(LAN_UL_001); - } - else - { - if ($postemail == '-witheld-') $postemail = ''; - $_POST['file_description'] = $tp->toDB($_POST['file_description']); - $file_time = time(); - $sql->insert("upload", "0, '".$poster."', '".$postemail."', '".$tp -> toDB($_POST['file_website'])."', '".$file_time."', '".$tp -> toDB($_POST['file_name'])."', '".$tp -> toDB($_POST['file_version'])."', '".$file."', '".$image."', '".$tp -> toDB($_POST['file_description'])."', '".$tp -> toDB($_POST['file_demo'])."', '".$filesize."', 0, '".$downloadCategory."'"); - $edata_fu = array("upload_user" => $poster, "upload_email" => $postemail, "upload_name" => $tp -> toDB($_POST['file_name']),"upload_file" => $file, "upload_version" => $_POST['file_version'], "upload_description" => $tp -> toDB($_POST['file_description']), "upload_size" => $filesize, "upload_category" => $downloadCategory, "upload_website" => $tp -> toDB($_POST['file_website']), "upload_image" => $image, "upload_demo" => $tp -> toDB($_POST['file_demo']), "upload_time" => $file_time); - $e_event->trigger("fileupload", $edata_fu); - $msghandler->addInfo(LAN_404); - } - } - } - else - { // Error - missing data - message_handler("ALERT", 5); - } +/* + + + + + - if(!$error) - { - $ns->tablerender('Success', e107::getMessage()->render()); // TODO lan - require_once(FOOTERF); - exit; - } -} $text = "
- +
@@ -266,35 +542,7 @@ $ns->tablerender(LAN_417, $text); require_once(FOOTERF); -function headerjs() -{ - $script = ""; - return $script; -} +*/ ?>