From f1cc288878993bd20ebb9fd0cc1926c32ac9550d Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Fri, 20 Apr 2012 07:28:53 +0000 Subject: [PATCH] More work on admin->downloads. Now uses media-manager for images. --- .../shortcodes/batch/news_shortcodes.php | 2 +- .../shortcodes/batch/page_shortcodes.php | 13 +- e107_handlers/message_handler.php | 63 + e107_plugins/download/admin_download.php | 492 +++++- e107_plugins/download/download.php | 6 +- e107_plugins/download/download_setup.php | 57 +- e107_plugins/download/download_shortcodes.php | 44 +- e107_plugins/download/download_sql.php | 4 +- .../download/handlers/adminDownload_class.php | 1196 ++++++++------- .../download/handlers/download_class.php | 11 + e107_plugins/download/includes/admin.php | 1362 +++++++++++++++-- 11 files changed, 2513 insertions(+), 737 deletions(-) diff --git a/e107_core/shortcodes/batch/news_shortcodes.php b/e107_core/shortcodes/batch/news_shortcodes.php index e33578e7a..65b74aab5 100644 --- a/e107_core/shortcodes/batch/news_shortcodes.php +++ b/e107_core/shortcodes/batch/news_shortcodes.php @@ -209,7 +209,7 @@ class news_shortcodes extends e_shortcode if (ADMIN && getperms('H')) { $adop_icon = (file_exists(THEME."images/newsedit.png") ? THEME_ABS."images/newsedit.png" : e_IMAGE_ABS."admin_images/edit_16.png"); - return " ".LAN_NEWS_25."\n"; + return " ".LAN_NEWS_25."\n"; } else { diff --git a/e107_core/shortcodes/batch/page_shortcodes.php b/e107_core/shortcodes/batch/page_shortcodes.php index 54601a15c..30d9052b7 100644 --- a/e107_core/shortcodes/batch/page_shortcodes.php +++ b/e107_core/shortcodes/batch/page_shortcodes.php @@ -114,7 +114,7 @@ class page_shortcodes extends e_shortcode * @see eHelper::scDualParams() * @see eHelper::scParams() */ - function sc_cpagehumbnail($parm = '') + function sc_cpagethumbnail($parm = '') { $parms = eHelper::scDualParams($parm); if(empty($parms[1])) return ''; @@ -144,6 +144,17 @@ class page_shortcodes extends e_shortcode break; } } + + // For Future Use.. + function sc_cpageimage($parm = '') + { + list($num,$size) = explode("|",$parm); + if($this->page['page_images']) + { + $img = explode(",",$this->page['page_images']); + + } + } function sc_cpagelink($parm) { diff --git a/e107_handlers/message_handler.php b/e107_handlers/message_handler.php index 5c99d8c1a..4a36cdaae 100644 --- a/e107_handlers/message_handler.php +++ b/e107_handlers/message_handler.php @@ -799,6 +799,69 @@ class eMessage } throw new Exception('Method eMessage::'.$method.' does not exist!');//FIXME - e107Exception handler } + + + + /** + * Automate DB system messages + * NOTE: default value of $output parameter will be changed to false (no output by default) in the future + * + * @param integer|bool $update return result of db::db_Query + * @param string $type update|insert|update + * @param string $success forced success message + * @param string $failed forced error message + * @param bool $output false suppress any function output + * @return integer|bool db::db_Query result + */ + // TODO - This function often needs to be available BEFORE header.php is loaded. + // It has been copied from admin_update() in e107_admin/header.php + + public function autoMessage($update, $type = 'update', $success = false, $failed = false, $output = false) + { + + if (($type == 'update' && $update) || ($type == 'insert' && $update !== false)) + { + $this->add(($success ? $success : ($type == 'update' ? LAN_UPDATED : LAN_CREATED)), E_MESSAGE_SUCCESS); + } + elseif ($type == 'delete' && $update) + { + $this->add(($success ? $success : LAN_DELETED), E_MESSAGE_SUCCESS); + } + elseif (!mysql_errno()) + { + if ($type == 'update') + { + $this->add(LAN_NO_CHANGE.' '.LAN_TRY_AGAIN, E_MESSAGE_INFO); + } + elseif ($type == 'delete') + { + $this->add(LAN_DELETED_FAILED.' '.LAN_TRY_AGAIN, E_MESSAGE_INFO); + } + } + else + { + switch ($type) + { + case 'insert': + $msg = LAN_CREATED_FAILED; + break; + case 'delete': + $msg = LAN_DELETED_FAILED; + break; + default: + $msg = LAN_UPDATED_FAILED; + break; + } + + $text = ($failed ? $failed : $msg." - ".LAN_TRY_AGAIN)."
".LAN_ERROR." ".mysql_errno().": ".mysql_error(); + $this->add($text, E_MESSAGE_ERROR); + } + + if ($output) echo $this->render(); + return $update; + } + + } diff --git a/e107_plugins/download/admin_download.php b/e107_plugins/download/admin_download.php index 1521ce9de..25227eb92 100644 --- a/e107_plugins/download/admin_download.php +++ b/e107_plugins/download/admin_download.php @@ -26,7 +26,10 @@ if (!getperms("P") || !plugInstalled('download')) include_lan(e_PLUGIN.'download/languages/'.e_LANGUAGE.'/download.php'); include_lan(e_PLUGIN.'download/languages/'.e_LANGUAGE.'/admin_download.php'); -require_once(e_PLUGIN.'download/handlers/adminDownload_class.php'); +// require_once(e_PLUGIN.'download/handlers/adminDownload_class.php'); +require_once(e_PLUGIN.'download/handlers/download_class.php'); +require_once(e_HANDLER.'upload_handler.php'); +require_once(e_HANDLER.'xml_class.php'); require_once(e_HANDLER."form_handler.php"); require_once(e_HANDLER."ren_help.php"); require_once(e_HANDLER."calendar/calendar_class.php"); @@ -55,12 +58,14 @@ $pst->id = array("admin_downloads","admin_dl_cat"); // ------------------------------- $download = new download(); -$adminDownload = new adminDownload(); +// $adminDownload = new adminDownload(); +$pst->save_preset(); // unique name(s) for the presets - comma separated. new plugin_download_admin(); require_once(e_ADMIN."auth.php"); -$pst->save_preset(); // unique name(s) for the presets - comma separated. + + /* One form example (no arrays needed) @@ -68,6 +73,7 @@ $pst->form = "myform"; // form id of the form that will have it's values saved. $pst->page = "download.php?create"; // display preset options on which page. $pst->save_preset("admin_downloads"); // unique name for the preset */ +/* $rs = new form; $subAction = ''; @@ -82,7 +88,7 @@ if (e_QUERY) unset($tmp); } -$adminDownload->observer(); +// $adminDownload->observer(); require_once (e_HANDLER.'message_handler.php'); $emessage = &eMessage::getInstance(); @@ -95,17 +101,18 @@ $amount = varset($pref['download_view'], 50); if (isset($_POST)) { $e107cache->clear("download_cat"); -} +}*/ +/* if (isset($_POST['submit_download'])) { $adminDownload->submit_download($subAction, $id); $action = "main"; unset($subAction, $id); } - +*/ if (isset($_POST['update_catorder'])) { @@ -119,6 +126,7 @@ if (isset($_POST['update_catorder'])) $admin_log->log_event('DOWNL_08',implode(',',array_keys($_POST['catorder'])),E_LOG_INFORMATIVE,''); $ns->tablerender("", "
".LAN_UPDATED."
"); } +/* if (isset($_POST['updatedownlaodoptions'])) { @@ -149,6 +157,8 @@ if (isset($_POST['updatedownlaodoptions'])) } } +*/ + if (isset($_POST['updateuploadoptions'])) { unset($temp); @@ -239,10 +249,15 @@ if (isset($_POST['updatelimits'])) } -if (isset($_POST['submit_mirror'])) -{ - $adminDownload->submit_mirror($subAction, $id); -} +//download/includes/admin.php is auto-loaded. + e107::getAdminUI()->runPage(); +require_once(e_ADMIN."footer.php"); +exit; + + + + +/* if ($action == "mirror") @@ -272,9 +287,10 @@ if ($from === "maint" && isset($_POST['submit_download'])) $action = $from; $subAction = $maintPage; } +*/ - e107::getAdminUI()->runPage(); +/* if (!e_QUERY || $action == "main") { @@ -309,9 +325,9 @@ if ($action == "uopt") { $adminDownload->show_upload_options(); } +*/ + -require_once(e_ADMIN."footer.php"); -exit; function showLimits() @@ -825,6 +841,456 @@ function showMaint() // Deprecated. // $ns->tablerender(DOWLAN_165.$title, $text); } +// UNUSED + + + + + + function show_upload_list() { + global $ns, $sql, $gen, $e107, $tp; + + $frm = new e_form(true); //enable inner tabindex counter + $imgd = e_BASE.$IMAGES_DIRECTORY; + $columnInfo = array( + "checkboxes" => array("title" => "", "forced"=> TRUE, "width" => "3%", "thclass" => "center first", "toggle" => "dl_selected"), + "upload_id" => array("title"=>DOWLAN_67, "type"=>"", "width"=>"auto", "thclass"=>"", "forced"=>true), + "upload_date" => array("title"=>DOWLAN_78, "type"=>"", "width"=>"auto", "thclass"=>""), + "upload_uploader" => array("title"=>DOWLAN_79, "type"=>"", "width"=>"auto", "thclass"=>""), + "upload_name" => array("title"=>DOWLAN_12, "type"=>"", "width"=>"auto", "thclass"=>""), + "upload_file_name" => array("title"=>DOWLAN_59, "type"=>"", "width"=>"auto", "thclass"=>""), + "upload_size" => array("title"=>DOWLAN_66, "type"=>"", "width"=>"auto", "thclass"=>"right"), + "options" => array("title"=>LAN_OPTIONS,"width"=>"15%", "thclass"=>"center last", "forced"=>true) + ); + //TODO $filterColumns = ($user_pref['admin_download_disp'] ? $user_pref['admin_download_disp'] : array("download_name","download_class")); + $filterColumns = array("upload_id","upload_date","upload_uploader","upload_name","upload_file_name","upload_size"); + $text = " +
+
+ " + .$frm->colGroup($columnInfo,$filterColumns) + .$frm->thead($columnInfo,$filterColumns,"main.[FIELD].[ASC].[FROM]")." + + + "; + } + else + { + $activeUploads = $sql -> db_getList(); + + $text .= DOWLAN_80." ".($active_uploads == 1 ? DOWLAN_81 : DOWLAN_82)." ".$active_uploads." ".($active_uploads == 1 ? DOWLAN_83 : DOWLAN_84); + $text .= ""; + + foreach($activeUploads as $row) + { + $post_author_id = substr($row['upload_poster'], 0, strpos($row['upload_poster'], ".")); + $post_author_name = substr($row['upload_poster'], (strpos($row['upload_poster'], ".")+1)); + $poster = (!$post_author_id ? "".$post_author_name."" : "".$post_author_name.""); + $upload_datestamp = $gen->convert_date($row['upload_datestamp'], "short"); + $text .= " + + + + + + + + + + "; + } + } + $text .= "
"; + + if (!$active_uploads = $sql->db_Select("upload", "*", "upload_active=0 ORDER BY upload_id ASC")) + { + $text .= DOWLAN_19.".
".$frm->checkbox("dl_selected[".$row["upload_id"]."]", $row['upload_id'])."".$row['upload_id']."".$upload_datestamp."".$poster."".$row['upload_name']."".$row['upload_file']."".$e107->parseMemorySize($row['upload_filesize'])." +
+
+ ".DOWLAN_91." + ".DOWLAN_162." + toJS(" [ ".$row['upload_name']." ] ".DOWLAN_33)."') \"/> +
+
+
"; + + $ns->tablerender(DOWLAN_22, $text); + } + + + + + + + function show_filter_form($action, $subAction, $id, $from, $amount) + { + global $e107, $mySQLdefaultdb, $pref, $user_pref; + $frm = new e_form(); + + $filterColumns = ($user_pref['admin_download_disp'] ? $user_pref['admin_download_disp'] : array("download_name","download_class")); + // $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => 123)); + $url = "admin_download.php"; + + // Search field + $text .= " + +
+ +
+ "; + // Advanced search fields + $text .= " +
+ +
"; + + return $text; + } + + + + + + + function show_upload_filetypes() { + global $ns; + + //TODO is there an e107:: copy of this + if (!is_object($e_userclass)) + { + $e_userclass = new user_class; + } + + if(!getperms("0")) exit; //TODO still needed? + + $definition_source = DOWLAN_71; + $source_file = ''; + $edit_upload_list = varset($_POST['upload_do_edit'], false); + + if (isset($_POST['generate_filetypes_xml'])) + { // Write back edited data to filetypes_.xml + $file_text = "\n"; + foreach ($_POST['file_class_select'] as $k => $c) + { + if (!isset($_POST['file_line_delete_'.$c]) && varsettrue($_POST['file_type_list'][$k])) + { + $file_text .= " \n"; + } + } + $file_text .= ""; + if ((($handle = fopen(e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES,'wt')) == FALSE) + || (fwrite($handle,$file_text) == FALSE) + || (fclose($handle) == FALSE)) + { + $text = DOWLAN_88.e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES; + } + else + { + $text = DOWLAN_86.e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES.'
'.DOWLAN_87.e_ADMIN.e_READ_FILETYPES.'
'; + } + $ns->tablerender(DOWLAN_49, $text); + } + + $current_perms = array(); + if (($edit_upload_list && is_readable(e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES)) || (!$edit_upload_list && is_readable(e_ADMIN.e_READ_FILETYPES))) + { + require_once(e_HANDLER.'xml_class.php'); + $xml = new xmlClass; + $xml->setOptArrayTags('class'); + $source_file = $edit_upload_list ? e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES : e_ADMIN.e_READ_FILETYPES; + $temp_vars = $xml->loadXMLfile($source_file, true, false); + if ($temp_vars === FALSE) + { + echo "Error parsing XML file!"; + } + else + { + foreach ($temp_vars['class'] as $v1) + { + $v = $v1['@attributes']; + $current_perms[$v['name']] = array('type' => $v['type'],'maxupload' => $v['maxupload']); + } + } + } + elseif (is_readable(e_ADMIN.'filetypes.php')) + { + $source_file = 'filetypes.php'; + $current_perms[e_UC_MEMBER] = array('type' => implode(',',array_keys(get_allowed_filetypes('filetypes.php', ''))),'maxupload' => '2M'); + if (is_readable(e_ADMIN.'admin_filetypes.php')) + { + $current_perms[e_UC_ADMIN] = array('type' => implode(',',array_keys(get_allowed_filetypes('admin_filetypes.php', ''))),'maxupload' => '2M'); + $source_file .= ' + admin_filetypes.php'; + } + } + else + { // Set a default + $current_perms[e_UC_MEMBER] = array('type' => 'zip,tar,gz,jpg,png','maxupload' => '2M'); + } + + $frm = new e_form(true); //enable inner tabindex counter + $columnInfo = array( + "ftypes_userclass" => array("title"=>DOWLAN_73, "type"=>"", "width"=>"auto", "thclass"=>"", "forced"=>true), + "ftypes_extension" => array("title"=>DOWLAN_74, "type"=>"", "width"=>"auto", "thclass"=>""), + "ftypes_max_size" => array("title"=>DOWLAN_75, "type"=>"", "width"=>"auto", "thclass"=>""), + "ftypes_confirm_del" => array("title"=>DOWLAN_76, "type"=>"", "width"=>"auto", "thclass"=>"last"), + ); + $filterColumns = array("ftypes_userclass", "ftypes_extension", "ftypes_max_size", "ftypes_confirm_del"); + $text = " +
+
+
+
+

". + str_replace(array('--SOURCE--', '--DEST--'),array(e_UPLOAD_TEMP_DIR.e_SAVE_FILETYPES,e_ADMIN.e_READ_FILETYPES),DOWLAN_85) + ."

". + DOWLAN_72.$source_file." +

+ " + .$frm->colGroup($columnInfo) + .$frm->thead($columnInfo,$filterColumns)." + + "; + foreach ($current_perms as $uclass => $uinfo) + { + $text .= " + + + + + + + "; + } + // Now put up a box to add a new setting + $text .= " + + + + + + + + + +
+ +
".DOWLAN_90."
+
+
+
+ +
+
+ "; + + $ns->tablerender(DOWLAN_23, $text); + } + function show_upload_options() { + global $pref, $ns; + + require_once(e_HANDLER."form_handler.php"); + $frm = new e_form(true); //enable inner tabindex counter + + $text = " +
+
+
+ + + + + + + + + + + + + + + + + +
".DOWLAN_26."" + .$frm->radio_switch('upload_enabled', $pref['upload_enabled']) + ."
" + .$frm->label(DOWLAN_51, 'upload_enabled', '1') + ."
" + ."
".DOWLAN_35."" + .$frm->text('upload_maxfilesize', $pref['upload_maxfilesize'], '4', array('size'=>'10')) + ."
" + .$frm->label(str_replace(array("%1", "%2"), array(ini_get('upload_max_filesize'), ini_get('post_max_size')), DOWLAN_58), 'upload_maxfilesize', '1') + ."
" + ."
".DOWLAN_61."" + .r_userclass("upload_class", $pref['upload_class']) + ."
" + .$frm->label(DOWLAN_60, 'upload_class', '1') + ."
" + ."
+
+
+
+ +
+
+ "; + $ns->tablerender(LAN_DL_OPTIONS, $text); + } + + + + + /** + * + * @private + */ + function _getConditionList($name, $value) { + $text .= " + + "; + return $text; + } + /** + * + * @private + */ + function _getStatusList($name, $value) { + $download_status[99]= ' '; + $download_status[0] = DOWLAN_122; + $download_status[1] = DOWLAN_123; + $download_status[2] = DOWLAN_124; + $text = ""; + foreach($download_status as $key=>$val){ + $sel = ($value == $key && $value != null) ? " selected='selected'" : ""; + $text .= "\n"; + } + return $text; + } + + + + + + /* function admin_download_adminmenu($parms) { diff --git a/e107_plugins/download/download.php b/e107_plugins/download/download.php index 4b112d79a..12742ade5 100644 --- a/e107_plugins/download/download.php +++ b/e107_plugins/download/download.php @@ -149,9 +149,9 @@ else if (isset($order) && !in_array($order,$order_options)) unset($order); if (isset($sort) && !in_array($sort,$sort_options)) unset($sort); -if (!isset($order)) $order = varset($pref['download_order'],'download_datestamp'); -if (!isset($sort)) $sort = varset($pref['download_sort'], 'DESC'); -if (!isset($view)) $view = varset($pref['download_view'], '10'); +if (!isset($order)) $order = vartrue($pref['download_order'],'download_datestamp'); +if (!isset($sort)) $sort = vartrue($pref['download_sort'], 'DESC'); +if (!isset($view)) $view = vartrue($pref['download_view'], '10'); //-------------------------------------------------- // GENERATE DISPLAY TEXT diff --git a/e107_plugins/download/download_setup.php b/e107_plugins/download/download_setup.php index 4b8df0df3..05e5e31fb 100644 --- a/e107_plugins/download/download_setup.php +++ b/e107_plugins/download/download_setup.php @@ -2,7 +2,7 @@ /* * e107 website system * -* Copyright (C) 2008-2009 e107 Inc (e107.org) +* Copyright (C) 2008-2012 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * @@ -17,6 +17,7 @@ class download_setup { + function install_pre($var) { // print_a($var); @@ -38,12 +39,60 @@ class download_setup // $mes->add("custom uninstall 'pre' function.", E_MESSAGE_SUCCESS); } - function upgrade_post($var) + + // IMPORTANT : This function below is for modifying the CONTENT of the tables only, NOT the table-structure. + // To Modify the table-structure, simply modify your {plugin}_sql.php file and an update will be detected automatically. + /* + * @var $needed - true when only a check for a required update is being performed. + * Return: Reason the upgrade is required, otherwise set it to return FALSE. + */ + function upgrade_post($needed) { $sql = e107::getDb(); - $mes = eMessage::getInstance(); - // $mes->add("custom upgrade 'post' function.", E_MESSAGE_SUCCESS); + $mes = e107::getMessage(); + $qry = "SELECT * FROM #download WHERE download_image !='' AND SUBSTRING(download_image, 1, 3) != '{e_' LIMIT 2"; + if($sql->db_Select_gen($qry)) + { + if($needed == TRUE){ return "Incorrect download image paths"; } // Signal that an update is required. + + if($sql->db_Update("download","download_image = CONCAT('{e_FILE}downloadimages/',download_image) WHERE download_image !='' ")) + { + $mes->addSuccess("Updated Download-Image paths"); + } + else + { + $mes->addError("Failed to update Download-Image paths"); + } + + if($sql->db_Update("download"," download_thumb = CONCAT('{e_FILE}downloadthumbs/',download_thumb) WHERE download_thumb !='' ")) + { + $mes->addSuccess("Updated Download-Thumbnail paths"); + } + else + { + $mes->addError("Failed to update Download-Thumbnail paths"); + } + } + + $qry = "SELECT * FROM #download_category WHERE download_category_icon !='' AND SUBSTRING(download_category_icon, 1, 3) != '{e_' LIMIT 2"; + if($sql->db_Select_gen($qry)) + { + // Signal that an update is required. + if($needed == TRUE){ return "Downloads-Category icon paths need updating"; } // Must have a value if an update is needed. Text used for debug purposes. + + if($sql->db_Update("download_category","download_category_icon = CONCAT('{e_IMAGE}icons/',download_category_icon) WHERE download_category_icon !='' ")) + { + $mes->addSuccess("Updated Download-Image paths"); + } + else + { + $mes->addError("Failed to update Download-Image paths"); + } + } + + if($needed == TRUE){ return FALSE; } + //if(version_compare($var['current_plug']['plugin_version'], "1.2", "<")) //{ // $qry = "ALTER TABLE #download ADD download_postclass TINYINT( 3 ) UNSIGNED DEFAULT '0' NOT NULL ;"; diff --git a/e107_plugins/download/download_shortcodes.php b/e107_plugins/download/download_shortcodes.php index a36c9f8c1..348b2a4a1 100644 --- a/e107_plugins/download/download_shortcodes.php +++ b/e107_plugins/download/download_shortcodes.php @@ -171,7 +171,9 @@ class download_shortcodes function sc_download_list_thumb() { global $dlrow,$parm; - $img = ($dlrow['download_thumb']) ? "*" : ""; + $tp = e107::getParser(); + + $img = ($dlrow['download_thumb']) ? "*" : ""; if ($parm == "link" && $dlrow['download_thumb']){ return "".$img.""; } @@ -213,6 +215,8 @@ class download_shortcodes return ($pref['agree_flag'] ? "{$img}" : "{$img}"); } } + + function sc_download_list_icon() { global $dlrow,$parm; @@ -225,6 +229,25 @@ class download_shortcodes } return; } + + function sc_download_list_imagefull() + { + global $dlrow,$parm; + $tp = e107::getParser(); + + $img = ($dlrow['download_image']) ? "" : ""; + + if($parm == "link" && $dlrow['download_image']) + { + return "".$img.""; + } + else + { + return $img; + } + } + + function sc_download_list_nextprev() { global $nextprev_parms,$tp; @@ -238,6 +261,12 @@ class download_shortcodes global $dlft; return $dlft." ".LAN_dl_17; } + + + + + + // View **************************************************************************************** function sc_download_view_id() { @@ -330,8 +359,10 @@ class download_shortcodes function sc_download_view_image() { global $dlrow; + $tp = e107::getParser(); + if ($dlrow['download_thumb']) { - return ($dlrow['download_image'] ? "*" : "*"); + return ($dlrow['download_image'] ? "*" : "*"); } else if ($dlrow['download_image']) { return "".LAN_dl_40.""; @@ -344,7 +375,8 @@ class download_shortcodes function sc_download_view_imagefull() { global $dlrow; - return ($dlrow['download_image']) ? "*" : ""; + $tp = e107::getParser(); + return ($dlrow['download_image']) ? "*" : ""; } function sc_download_view_link() { @@ -430,7 +462,8 @@ class download_shortcodes } function sc_download_mirror_request_icon() { global $dlrow; - return ($dlrow['download_thumb'] ? "*" : ""); + $tp = e107::getParser(); + return ($dlrow['download_thumb'] ? "*" : ""); } function sc_download_mirror_name() { global $dlmirror; @@ -438,7 +471,8 @@ class download_shortcodes } function sc_download_mirror_image() { global $dlrow, $dlmirror; - return ($dlmirror['mirror_image'] ? "*" : ""); + $tp = e107::getParser(); + return ($dlmirror['mirror_image'] ? "*" : ""); } function sc_download_mirror_location() { global $dlmirror; diff --git a/e107_plugins/download/download_sql.php b/e107_plugins/download/download_sql.php index 23fece1ea..56f6323af 100644 --- a/e107_plugins/download/download_sql.php +++ b/e107_plugins/download/download_sql.php @@ -14,8 +14,8 @@ CREATE TABLE download ( download_category int(10) unsigned NOT NULL default '0', download_active tinyint(3) unsigned NOT NULL default '0', download_datestamp int(10) unsigned NOT NULL default '0', - download_thumb varchar(150) NOT NULL default '', - download_image varchar(150) NOT NULL default '', + download_thumb text NOT NULL, + download_image text NOT NULL, download_comment tinyint(3) unsigned NOT NULL default '0', download_class varchar(255) NOT NULL default '0', download_mirror text NOT NULL, diff --git a/e107_plugins/download/handlers/adminDownload_class.php b/e107_plugins/download/handlers/adminDownload_class.php index 096fea9bc..5d746999e 100644 --- a/e107_plugins/download/handlers/adminDownload_class.php +++ b/e107_plugins/download/handlers/adminDownload_class.php @@ -45,399 +45,406 @@ class adminDownload extends download } } + /* function show_filter_form($action, $subAction, $id, $from, $amount) - { - global $e107, $mySQLdefaultdb, $pref, $user_pref; - $frm = new e_form(); - - $filterColumns = ($user_pref['admin_download_disp'] ? $user_pref['admin_download_disp'] : array("download_name","download_class")); - // $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => 123)); - $url = "admin_download.php"; - - // Search field - $text .= " - -
- -
- "; - // Advanced search fields - $text .= " -
- -
"; - - return $text; - } - - function show_existing_items($action, $subAction, $id, $from, $amount) - { - global $sql, $rs, $ns, $tp, $mySQLdefaultdb, $pref, $user_pref; - $frm = new e_form(); - $sortorder = $subAction ? $subAction : $pref['download_order']; - $sortdirection = $id=="asc" ? "asc" : "desc"; - $amount = 10; - if(!$sortorder) - { - $sortorder = "download_id"; - } - - $sort_link = $sortdirection == 'asc' ? 'desc' : 'asc'; - - $columnInfo = array( - "checkboxes" => array("title" => "", "forced"=> TRUE, "width" => "3%", "thclass" => "center first", "toggle" => "dl_selected"), - "download_id" => array("title"=>DOWLAN_67, "type"=>"", "width"=>"auto", "thclass"=>"", "forced"=>true), - "download_name" => array("title"=>DOWLAN_12, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_url" => array("title"=>DOWLAN_13, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_author" => array("title"=>DOWLAN_15, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_author_email" => array("title"=>DOWLAN_16, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_author_website" => array("title"=>DOWLAN_17, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_description" => array("title"=>DOWLAN_18, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_filesize" => array("title"=>DOWLAN_66, "type"=>"", "width"=>"auto", "thclass"=>"right"), - "download_requested" => array("title"=>DOWLAN_29, "type"=>"", "width"=>"auto", "thclass"=>"center"), - "download_category" => array("title"=>DOWLAN_11, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_active" => array("title"=>DOWLAN_21, "type"=>"", "width"=>"auto", "thclass"=>"center"), - "download_datestamp" => array("title"=>DOWLAN_182, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_thumb" => array("title"=>DOWLAN_20, "type"=>"", "width"=>"auto", "thclass"=>"center"), - "download_image" => array("title"=>DOWLAN_19, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_comment" => array("title"=>DOWLAN_102, "type"=>"", "width"=>"auto", "thclass"=>"center"), - "download_class" => array("title"=>DOWLAN_113, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_mirror" => array("title"=>DOWLAN_128, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_mirror_type" => array("title"=>DOWLAN_195, "type"=>"", "width"=>"auto", "thclass"=>""), - "download_visible" => array("title"=>DOWLAN_43, "type"=>"", "width"=>"auto", "thclass"=>""), - "options" => array("title"=>LAN_OPTIONS, "width"=>"10%", "thclass"=>"center last", "forced"=>true) - ); - - $filterColumns = ($user_pref['admin_download_disp']) ? $user_pref['admin_download_disp'] : array("download_name","download_class"); - $query = "SELECT d.*, dc.* FROM `#download` AS d LEFT JOIN `#download_category` AS dc ON dc. download_category_id=d.download_category"; - - if ($this->searchField) { - $where = array(); - array_push($where, "download_name REGEXP('".$this->searchField."')"); - array_push($where, "download_description REGEXP('".$this->searchField."')"); - array_push($where, "download_author REGEXP('".$this->searchField."')"); - array_push($where, "download_author_email REGEXP('".$this->searchField."')"); - array_push($where, "download_author_website REGEXP('".$this->searchField."')"); - $where = " WHERE ".implode(" OR ", $where); - $query .= "$where ORDER BY {$sortorder} {$sortdirection}"; - } - else if ($this->advancedSearchFields) { - $where = array(); - if (strlen($this->advancedSearchFields['name']) > 0) { - array_push($where, "download_name REGEXP('".$this->advancedSearchFields['name']."')"); + { + global $e107, $mySQLdefaultdb, $pref, $user_pref; + $frm = new e_form(); + + $filterColumns = ($user_pref['admin_download_disp'] ? $user_pref['admin_download_disp'] : array("download_name","download_class")); + // $url = $e107->url->getUrl('forum', 'thread', array('func' => 'view', 'id' => 123)); + $url = "admin_download.php"; + + // Search field + $text .= " + +
+ +
+ "; + // Advanced search fields + $text .= " +
+ +
"; + + return $text; + } + */ + + + + /* + + + function show_existing_items($action, $subAction, $id, $from, $amount) + { + global $sql, $rs, $ns, $tp, $mySQLdefaultdb, $pref, $user_pref; + $frm = new e_form(); + $sortorder = $subAction ? $subAction : $pref['download_order']; + $sortdirection = $id=="asc" ? "asc" : "desc"; + $amount = 10; + if(!$sortorder) + { + $sortorder = "download_id"; + } + $sort_link = $sortdirection == 'asc' ? 'desc' : 'asc'; + $columnInfo = array( + "checkboxes" => array("title" => "", "forced"=> TRUE, "width" => "3%", "thclass" => "center first", "toggle" => "dl_selected"), + "download_id" => array("title"=>DOWLAN_67, "type"=>"", "width"=>"auto", "thclass"=>"", "forced"=>true), + "download_name" => array("title"=>DOWLAN_12, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_url" => array("title"=>DOWLAN_13, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_author" => array("title"=>DOWLAN_15, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_author_email" => array("title"=>DOWLAN_16, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_author_website" => array("title"=>DOWLAN_17, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_description" => array("title"=>DOWLAN_18, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_filesize" => array("title"=>DOWLAN_66, "type"=>"", "width"=>"auto", "thclass"=>"right"), + "download_requested" => array("title"=>DOWLAN_29, "type"=>"", "width"=>"auto", "thclass"=>"center"), + "download_category" => array("title"=>DOWLAN_11, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_active" => array("title"=>DOWLAN_21, "type"=>"", "width"=>"auto", "thclass"=>"center"), + "download_datestamp" => array("title"=>DOWLAN_182, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_thumb" => array("title"=>DOWLAN_20, "type"=>"", "width"=>"auto", "thclass"=>"center"), + "download_image" => array("title"=>DOWLAN_19, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_comment" => array("title"=>DOWLAN_102, "type"=>"", "width"=>"auto", "thclass"=>"center"), + "download_class" => array("title"=>DOWLAN_113, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_mirror" => array("title"=>DOWLAN_128, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_mirror_type" => array("title"=>DOWLAN_195, "type"=>"", "width"=>"auto", "thclass"=>""), + "download_visible" => array("title"=>DOWLAN_43, "type"=>"", "width"=>"auto", "thclass"=>""), + "options" => array("title"=>LAN_OPTIONS, "width"=>"10%", "thclass"=>"center last", "forced"=>true) + ); + + $filterColumns = ($user_pref['admin_download_disp']) ? $user_pref['admin_download_disp'] : array("download_name","download_class"); + $query = "SELECT d.*, dc.* FROM `#download` AS d LEFT JOIN `#download_category` AS dc ON dc. download_category_id=d.download_category"; + + if ($this->searchField) { + $where = array(); + array_push($where, "download_name REGEXP('".$this->searchField."')"); + array_push($where, "download_description REGEXP('".$this->searchField."')"); + array_push($where, "download_author REGEXP('".$this->searchField."')"); + array_push($where, "download_author_email REGEXP('".$this->searchField."')"); + array_push($where, "download_author_website REGEXP('".$this->searchField."')"); + $where = " WHERE ".implode(" OR ", $where); + $query .= "$where ORDER BY {$sortorder} {$sortdirection}"; } - if (strlen($this->advancedSearchFields['url']) > 0) { - array_push($where, "download_url REGEXP('".$this->advancedSearchFields['url']."')"); - } - if (strlen($this->advancedSearchFields['author']) > 0) { - array_push($where, "download_author REGEXP('".$this->advancedSearchFields['author']."')"); - } - if (strlen($this->advancedSearchFields['description']) > 0) { - array_push($where, "download_description REGEXP('".$this->advancedSearchFields['description']."')"); - } - if (strlen($this->advancedSearchFields['category']) != 0) { - array_push($where, "download_category=".$this->advancedSearchFields['category']); - } - if (strlen($this->advancedSearchFields['filesize']) > 0) { - array_push($where, "download_filesize".$this->advancedSearchFields['filesize_condition'].($this->advancedSearchFields['filesize']*$this->advancedSearchFields['filesize_units'])); - } - if ($this->advancedSearchFields['status'] != 99) { - array_push($where, "download_active=".$this->advancedSearchFields['status']); - } - if (strlen($this->advancedSearchFields['date']) > 0) { - switch ($this->advancedSearchFields['date_condition']) { - case "<=" : - { - array_push($where, "download_datestamp".$this->advancedSearchFields['date_condition'].($this->advancedSearchFields['date']+86400)); - break; - } - case "=" : - { - array_push($where, "(download_datestamp>=".$this->advancedSearchFields['date']." AND download_datestamp<=".($this->advancedSearchFields['date']+86399).")"); - break; - } - case ">=" : - { - array_push($where, "download_datestamp".$this->advancedSearchFields['date_condition'].$this->advancedSearchFields['date']); - break; + else if ($this->advancedSearchFields) { + $where = array(); + if (strlen($this->advancedSearchFields['name']) > 0) { + array_push($where, "download_name REGEXP('".$this->advancedSearchFields['name']."')"); + } + if (strlen($this->advancedSearchFields['url']) > 0) { + array_push($where, "download_url REGEXP('".$this->advancedSearchFields['url']."')"); + } + if (strlen($this->advancedSearchFields['author']) > 0) { + array_push($where, "download_author REGEXP('".$this->advancedSearchFields['author']."')"); + } + if (strlen($this->advancedSearchFields['description']) > 0) { + array_push($where, "download_description REGEXP('".$this->advancedSearchFields['description']."')"); + } + if (strlen($this->advancedSearchFields['category']) != 0) { + array_push($where, "download_category=".$this->advancedSearchFields['category']); + } + if (strlen($this->advancedSearchFields['filesize']) > 0) { + array_push($where, "download_filesize".$this->advancedSearchFields['filesize_condition'].($this->advancedSearchFields['filesize']*$this->advancedSearchFields['filesize_units'])); + } + if ($this->advancedSearchFields['status'] != 99) { + array_push($where, "download_active=".$this->advancedSearchFields['status']); + } + if (strlen($this->advancedSearchFields['date']) > 0) { + switch ($this->advancedSearchFields['date_condition']) { + case "<=" : + { + array_push($where, "download_datestamp".$this->advancedSearchFields['date_condition'].($this->advancedSearchFields['date']+86400)); + break; + } + case "=" : + { + array_push($where, "(download_datestamp>=".$this->advancedSearchFields['date']." AND download_datestamp<=".($this->advancedSearchFields['date']+86399).")"); + break; + } + case ">=" : + { + array_push($where, "download_datestamp".$this->advancedSearchFields['date_condition'].$this->advancedSearchFields['date']); + break; + } } } + if (strlen($this->advancedSearchFields['requested']) > 0) { + array_push($where, "download_requested".$this->advancedSearchFields['requested_condition'].$this->advancedSearchFields['requested']); + } + if ($this->advancedSearchFields['visible']) { + array_push($where, "download_visible=".$this->advancedSearchFields['visible']); + } + if ($this->advancedSearchFields['class']) { + array_push($where, "download_class=".$this->advancedSearchFields['class']); + } + $where = (count($where) > 0 ? " WHERE ".implode(" AND ", $where) : ""); + + $query .= "$where ORDER BY {$sortorder} {$sortdirection}"; } - if (strlen($this->advancedSearchFields['requested']) > 0) { - array_push($where, "download_requested".$this->advancedSearchFields['requested_condition'].$this->advancedSearchFields['requested']); - } - if ($this->advancedSearchFields['visible']) { - array_push($where, "download_visible=".$this->advancedSearchFields['visible']); - } - if ($this->advancedSearchFields['class']) { - array_push($where, "download_class=".$this->advancedSearchFields['class']); - } - $where = (count($where) > 0 ? " WHERE ".implode(" AND ", $where) : ""); - - $query .= "$where ORDER BY {$sortorder} {$sortdirection}"; - } - else - { - $query .= " ORDER BY ".($subAction ? $subAction : $sortorder)." ".($id ? $id : $sortdirection)." LIMIT $from, $amount"; - } - - $text .= "
".DOWLAN_7.""; - if ($dl_count = $sql->db_Select_gen($query)) - { - $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform")." - - ".$frm->colGroup($columnInfo,$filterColumns) - .$frm->thead($columnInfo,$filterColumns,"main.[FIELD].[ASC].[FROM]")." - - "; - - $rowStyle = "even"; - - while ($row = $sql->db_Fetch()) + else { - $mirror = strlen($row['download_mirror']) > 0; - $text .= "\n - - \n"; - - // Display Chosen options - - foreach($filterColumns as $disp) - { - - switch ($disp) - { - case "download_name" : - $text .= ""; - } - - $text .= " - - "; + $query .= " ORDER BY ".($subAction ? $subAction : $sortorder)." ".($id ? $id : $sortdirection)." LIMIT $from, $amount"; } - $text .= "
".$frm->checkbox("dl_selected[".$row["download_id"]."]", $row['download_id'])."".$row['download_id'].""; - $text .= "".$tp->toHTML($row['download_name']).""; - break; - case "download_category" : - $text .= ""; - $text .= $tp->toHTML($row['download_category_name']); - break; - case "download_datestamp" : - global $gen; - $text .= ""; - $text .= ($row[$disp]) ? $gen->convert_date($row[$disp],'short') : ""; - break; - case "download_class" : - case "download_visible" : - $text .= ""; - $text .= r_userclass_name($row[$disp])." "; - break; - case "download_filesize" : - $text .= ""; - //$text .= ($row[$disp]) ? $this->e107->parseMemorySize(($row[$disp])) : ""; - $text .= ($row[$disp]) ? (intval($row[$disp])) : ""; - break; - case "download_thumb" : - $text .= ""; - $text .= ($row[$disp]) ? "" : ""; - break; - case "download_image" : - $text .= ""; - $text .= "".$row[$disp].""; - break; - case "download_description" : - $text .= ""; - $text .= $tp->toHTML($row[$disp],TRUE); - break; - case "download_active" : - $text .= ""; - if ($row[$disp]== 1) - { - $text .= ""; - } - elseif ($row[$disp]== 2) - { - $text .= ""; - } - else - { - $text .= ""; - } - break; - case "download_comment" : - $text .= ""; - $text .= ($row[$disp]) ? ADMIN_TRUE_ICON : ""; - break; - case "download_mirror" : - $text .= ""; - $mirrorArray = $this->makeMirrorArray($row[$disp], TRUE); - foreach($mirrorArray as $mirror) { - $title = DOWLAN_66." ".$mirror['filesize']."; ".DOWLAN_29." ".$mirror['requests']; - $text .= "
"; - $text .= $tp->toHTML($mirror['url']).'
'; - } - break; - case "download_mirror_type" : - $text .= "
"; - if ($mirror) - { - switch ($row[$disp]) - { - case 1: - $text .= DOWLAN_196; - break; - default: - $text .= DOWLAN_197; - } - } - break; - case "download_requested" : - case "download_active" : - case "download_thumb" : - case "download_comment" : - $text .= ""; - $text .= $tp->toHTML($row[$disp]); - break; - default : - $text .= ""; - $text .= $tp->toHTML($row[$disp]); - } - $text .= " - ".ADMIN_EDIT_ICON." - toJS(DOWLAN_33." [ID: ".$row['download_id']." ]")."') \"/> -
"; - // $text .= ""; + + $text .= "
".DOWLAN_7.""; + if ($dl_count = $sql->db_Select_gen($query)) + { + $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform")." + + ".$frm->colGroup($columnInfo,$filterColumns) + .$frm->thead($columnInfo,$filterColumns,"main.[FIELD].[ASC].[FROM]")." + + "; + + $rowStyle = "even"; + + while ($row = $sql->db_Fetch()) + { + $mirror = strlen($row['download_mirror']) > 0; + $text .= "\n + + \n"; + + // Display Chosen options + + foreach($filterColumns as $disp) + { + + switch ($disp) + { + case "download_name" : + $text .= ""; + } + + $text .= " + + "; + } + $text .= "
".$frm->checkbox("dl_selected[".$row["download_id"]."]", $row['download_id'])."".$row['download_id'].""; + $text .= "".$tp->toHTML($row['download_name']).""; + break; + case "download_category" : + $text .= ""; + $text .= $tp->toHTML($row['download_category_name']); + break; + case "download_datestamp" : + global $gen; + $text .= ""; + $text .= ($row[$disp]) ? $gen->convert_date($row[$disp],'short') : ""; + break; + case "download_class" : + case "download_visible" : + $text .= ""; + $text .= r_userclass_name($row[$disp])." "; + break; + case "download_filesize" : + $text .= ""; + //$text .= ($row[$disp]) ? $this->e107->parseMemorySize(($row[$disp])) : ""; + $text .= ($row[$disp]) ? (intval($row[$disp])) : ""; + break; + case "download_thumb" : + $text .= ""; + $text .= ($row[$disp]) ? "" : ""; + break; + case "download_image" : + $text .= ""; + $text .= "".$row[$disp].""; + break; + case "download_description" : + $text .= ""; + $text .= $tp->toHTML($row[$disp],TRUE); + break; + case "download_active" : + $text .= ""; + if ($row[$disp]== 1) + { + $text .= ""; + } + elseif ($row[$disp]== 2) + { + $text .= ""; + } + else + { + $text .= ""; + } + break; + case "download_comment" : + $text .= ""; + $text .= ($row[$disp]) ? ADMIN_TRUE_ICON : ""; + break; + case "download_mirror" : + $text .= ""; + $mirrorArray = $this->makeMirrorArray($row[$disp], TRUE); + foreach($mirrorArray as $mirror) { + $title = DOWLAN_66." ".$mirror['filesize']."; ".DOWLAN_29." ".$mirror['requests']; + $text .= "
"; + $text .= $tp->toHTML($mirror['url']).'
'; + } + break; + case "download_mirror_type" : + $text .= "
"; + if ($mirror) + { + switch ($row[$disp]) + { + case 1: + $text .= DOWLAN_196; + break; + default: + $text .= DOWLAN_197; + } + } + break; + case "download_requested" : + case "download_active" : + case "download_thumb" : + case "download_comment" : + $text .= ""; + $text .= $tp->toHTML($row[$disp]); + break; + default : + $text .= ""; + $text .= $tp->toHTML($row[$disp]); + } + $text .= " + ".ADMIN_EDIT_ICON." + toJS(DOWLAN_33." [ID: ".$row['download_id']." ]")."') \"/> +
"; + // $text .= ""; + } + else + { // 'No downloads yet' + $text .= "
".DOWLAN_6."
"; + } + + // Next-Previous. + $downloads = $sql->db_Count("download"); + if ($downloads > $amount && !$this->searchFields && !$this->advancedSearchFields) + { + $parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$subAction.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]"; + $text .= "
".$this->batch_options(). + $tp->parseTemplate("{NEXTPREV={$parms}}")."
"; + } + + $text .= "
"; + + return $text; } - else - { // 'No downloads yet' - $text .= "
".DOWLAN_6."
"; - } - - // Next-Previous. - $downloads = $sql->db_Count("download"); - if ($downloads > $amount && !$this->searchFields && !$this->advancedSearchFields) - { - $parms = "{$downloads},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$subAction.$id." : "main.{$sortorder}.{$sortdirection}.")."[FROM]"; - $text .= "
".$this->batch_options(). - $tp->parseTemplate("{NEXTPREV={$parms}}")."
"; - } - - $text .= "
"; - - return $text; - } - + */ + // --------------------------------------------------------------------------- + + /* + function batch_options() { $frm = new e_form(); @@ -470,22 +477,24 @@ class adminDownload extends download } } + function batch_userclass($download_ids,$uclass,$mode='download_class') - { - $emessage = &eMessage::getInstance(); - - if(e107::getDb() -> db_Update("download", $mode." ='{$uclass}' WHERE download_id IN (".implode(",",$download_ids).") ")) { - $emessage->add("It Worked", E_MESSAGE_SUCCESS); - } - else - { - $emessage->add("It Failed", E_MESSAGE_ERROR); - } - } + $emessage = &eMessage::getInstance(); + if(e107::getDb() -> db_Update("download", $mode." ='{$uclass}' WHERE download_id IN (".implode(",",$download_ids).") ")) + { + $emessage->add("It Worked", E_MESSAGE_SUCCESS); + } + else + { + $emessage->add("It Failed", E_MESSAGE_ERROR); + } + }*/ + // Given the string which is stored in the DB, turns it into an array of mirror entries // If $byID is true, the array index is the mirror ID. Otherwise its a simple array + /* function makeMirrorArray($source, $byID = FALSE) { $ret = array(); @@ -506,8 +515,9 @@ class adminDownload extends download } return $ret; } + */ - +/* // Turn the array into a string which can be stored in the DB function compressMirrorArray($source) { @@ -518,10 +528,11 @@ class adminDownload extends download $inter[] = $s['id'].','.$s['url'].','.$s['requests'].','.$s['filesize']; } return implode(chr(1),$inter); - } + }*/ +/* function create_download($subAction='', $id='') { global $download, $e107, $cal, $tp, $sql, $fl, $rs, $ns, $file_array, $image_array, $thumb_array, $pst; @@ -539,6 +550,7 @@ class adminDownload extends download $file_array[] = str_replace(e_UPLOAD,"",$val); } } + */ /* if ($sql->db_Select("rbinary")) //TODO Remove me. { while ($row = $sql->db_Fetch()) @@ -548,6 +560,7 @@ class adminDownload extends download } } */ +/* if ($image_array = $fl->get_files(e_FILE.'downloadimages/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) { sort($image_array); @@ -944,19 +957,21 @@ class adminDownload extends download "; $ns->tablerender(ADLAN_24, $text); } - +*/ // ----------------------------------------------------------------------------- +/* function show_message($message) { global $ns; $ns->tablerender("", "
".$message."
"); } +*/ // ----------------------------------------------------------------------------- - // Actually save a new or edited download to the DB + /* // Actually save a new or edited download to the DB function submit_download($subAction, $id) { global $e107, $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event; @@ -1172,7 +1187,8 @@ class adminDownload extends download } } - +*/ +/* function downloadLog($aText, &$dlInfo, &$mirrorInfo=NULL) { global $admin_log; @@ -1190,8 +1206,9 @@ class adminDownload extends download } $admin_log->log_event($aText,$logString,E_LOG_INFORMATIVE,''); } - +*/ // ----------------------------------------------------------------------------- +/* function show_categories($subAction, $id) { @@ -1447,159 +1464,165 @@ class adminDownload extends download $ns->tablerender(DOWLAN_39, $text); } +*/ + /* function show_download_options() { - global $pref, $ns; - - require_once(e_HANDLER."form_handler.php"); - $frm = new e_form(true); //enable inner tabindex counter - - $agree_flag = $pref['agree_flag']; - $agree_text = $pref['agree_text']; - $c = $pref['download_php'] ? " checked = 'checked' " : ""; - $sacc = (varset($pref['download_incinfo'],0) == '1') ? " checked = 'checked' " : ""; - $order_options = array( - "download_id" => "Id No.", - "download_datestamp" => LAN_DATE, - "download_requested" => ADLAN_24, - "download_name" => DOWLAN_59, - "download_author" => DOWLAN_15 - ); - $sort_options = array( - "ASC" => DOWLAN_62, - "DESC" => DOWLAN_63 - ); - - $text = " -
- - -
\n -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
".LAN_DL_USE_PHP."" - .$frm->checkbox('download_php', '1', $pref['download_php']) - .$frm->label(LAN_DL_USE_PHP_INFO, 'download_php', '1') - ."
".LAN_DL_SUBSUB_CAT."" - .$frm->checkbox('download_subsub', '1', $pref['download_subsub']) - .$frm->label(LAN_DL_SUBSUB_CAT_INFO, 'download_subsub', '1') - ."
".LAN_DL_SUBSUB_COUNT."" - .$frm->checkbox('download_incinfo', '1', $pref['download_incinfo']) - .$frm->label(LAN_DL_SUBSUB_COUNT_INFO, 'download_incinfo', '1') - ."
".DOWLAN_55."".$frm->text('download_view', $pref['download_view'], '4', array('size'=>'4'))."
".DOWLAN_56."".$frm->selectbox('download_order', $order_options, $pref['download_order'])."
".LAN_ORDER."".$frm->selectbox('download_sort', $sort_options, $pref['download_sort'])."
".DOWLAN_160." - -
".DOWLAN_164." -
-
-
-
-
- - - - - - - - - - - - - -
".DOWLAN_151."". r_userclass("download_reportbroken", $pref['download_reportbroken'])."
".DOWLAN_150."". ($pref['download_email'] ? "" : "")."
-
-
-
-
- - - - - - - - - - - - - - - - - -
".DOWLAN_100."". ($agree_flag ? "" : "")."
".DOWLAN_101."".$frm->bbarea('agree_text',$agree_text)."
".DOWLAN_146."".$frm->bbarea('download_denied',$pref['download_denied'])."
-
-
-
-
- - - - - - - - - -
".DOWLAN_XXX."//TODO
-
-
-
- -
-
-
- "; - $ns->tablerender(LAN_DL_OPTIONS, $text); - } + global $pref, $ns; + require_once(e_HANDLER."form_handler.php"); + $frm = new e_form(true); //enable inner tabindex counter + $agree_flag = $pref['agree_flag']; + $agree_text = $pref['agree_text']; + $c = $pref['download_php'] ? " checked = 'checked' " : ""; + $sacc = (varset($pref['download_incinfo'],0) == '1') ? " checked = 'checked' " : ""; + $order_options = array( + "download_id" => "Id No.", + "download_datestamp" => LAN_DATE, + "download_requested" => ADLAN_24, + "download_name" => DOWLAN_59, + "download_author" => DOWLAN_15 + ); + $sort_options = array( + "ASC" => DOWLAN_62, + "DESC" => DOWLAN_63 + ); + $text = " +
+ +
\n +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
".LAN_DL_USE_PHP."" + .$frm->checkbox('download_php', '1', $pref['download_php']) + .$frm->label(LAN_DL_USE_PHP_INFO, 'download_php', '1') + ."
".LAN_DL_SUBSUB_CAT."" + .$frm->checkbox('download_subsub', '1', $pref['download_subsub']) + .$frm->label(LAN_DL_SUBSUB_CAT_INFO, 'download_subsub', '1') + ."
".LAN_DL_SUBSUB_COUNT."" + .$frm->checkbox('download_incinfo', '1', $pref['download_incinfo']) + .$frm->label(LAN_DL_SUBSUB_COUNT_INFO, 'download_incinfo', '1') + ."
".DOWLAN_55."".$frm->text('download_view', $pref['download_view'], '4', array('size'=>'4'))."
".DOWLAN_56."".$frm->selectbox('download_order', $order_options, $pref['download_order'])."
".LAN_ORDER."".$frm->selectbox('download_sort', $sort_options, $pref['download_sort'])."
".DOWLAN_160." + +
".DOWLAN_164." +
+
+
+
+
+ + + + + + + + + + + + + +
".DOWLAN_151."". r_userclass("download_reportbroken", $pref['download_reportbroken'])."
".DOWLAN_150."". ($pref['download_email'] ? "" : "")."
+
+
+
+
+ + + + + + + + + + + + + + + + + +
".DOWLAN_100."". ($agree_flag ? "" : "")."
".DOWLAN_101."".$frm->bbarea('agree_text',$agree_text)."
".DOWLAN_146."".$frm->bbarea('download_denied',$pref['download_denied'])."
+
+
+
+
+ + + + + + + + + +
".DOWLAN_XXX."//TODO
+
+
+
+ +
+
+
+ "; + $ns->tablerender(LAN_DL_OPTIONS, $text); + } + * + */ + + +/* + + + function show_upload_list() { global $ns, $sql, $gen, $e107, $tp; @@ -1670,6 +1693,12 @@ class adminDownload extends download $ns->tablerender(DOWLAN_22, $text); } + + + + + + function show_upload_filetypes() { global $ns; @@ -1858,7 +1887,9 @@ class adminDownload extends download "; $ns->tablerender(LAN_DL_OPTIONS, $text); - } + }*/ + +/* function create_category($subAction, $id) { @@ -1890,6 +1921,8 @@ class adminDownload extends download } } +*/ +/* function show_existing_mirrors() { global $sql, $ns, $tp, $subAction, $id, $delete, $del_id, $admin_log; @@ -2052,10 +2085,12 @@ class adminDownload extends download $admin_log->log_event('DOWNL_12',$logString,E_LOG_INFORMATIVE,''); } } - } + }*/ + // --------------------------------------------------------------------------- +/* function move_file($oldname,$newname) { global $ns; @@ -2089,36 +2124,49 @@ class adminDownload extends download return FALSE; } } + */ +/* + /** * * @private */ + /* function _getConditionList($name, $value) { - $text .= " - - "; - return $text; - } + $text .= " + + "; + return $text; + }*/ + /** * * @private */ + /* function _getStatusList($name, $value) { - $download_status[99]= ' '; - $download_status[0] = DOWLAN_122; - $download_status[1] = DOWLAN_123; - $download_status[2] = DOWLAN_124; - $text = ""; - foreach($download_status as $key=>$val){ - $sel = ($value == $key && $value != null) ? " selected='selected'" : ""; - $text .= "\n"; - } - return $text; - } + $download_status[99]= ' '; + $download_status[0] = DOWLAN_122; + $download_status[1] = DOWLAN_123; + $download_status[2] = DOWLAN_124; + $text = ""; + foreach($download_status as $key=>$val){ + $sel = ($value == $key && $value != null) ? " selected='selected'" : ""; + $text .= "\n"; + } + return $text; + } + */ + + + + + + function observer() { diff --git a/e107_plugins/download/handlers/download_class.php b/e107_plugins/download/handlers/download_class.php index f00d45f25..3601bf491 100644 --- a/e107_plugins/download/handlers/download_class.php +++ b/e107_plugins/download/handlers/download_class.php @@ -25,6 +25,12 @@ class download } function displayCategoryList() { } + + + + + + function getBreadcrumb($arr) { $dlbreadcrumb = array(); @@ -44,6 +50,11 @@ class download $dlbreadcrumb['fieldlist'] = implode(",", array_keys($dlbreadcrumb)); return $dlbreadcrumb; } + + + + + function getCategorySelectList($currentID=0, $incSubSub=true, $groupOnMain=true, $blankText=" ", $name="download_category") { global $sql,$parm; diff --git a/e107_plugins/download/includes/admin.php b/e107_plugins/download/includes/admin.php index 2eed63c35..52b0db2ca 100644 --- a/e107_plugins/download/includes/admin.php +++ b/e107_plugins/download/includes/admin.php @@ -208,132 +208,7 @@ class download_main_admin_ui extends e_admin_ui // default - true - TODO - move to displaySettings protected $batchDelete = true; - // UNDER CONSTRUCTION - // protected $displaySettings = array(); - - // UNDER CONSTRUCTION - // protected $disallowPages = array('main/create', 'main/prefs'); - - //TODO change the release_url type back to URL before release. - // required - /** - * (use this as starting point for wiki documentation) - * $fields format (string) $field_name => (array) $attributes - * - * $field_name format: - * 'table_alias_or_name.field_name.field_alias' (if JOIN support is needed) OR just 'field_name' - * NOTE: Keep in mind the count of exploded data can be 1 or 3!!! This means if you wanna give alias - * on main table field you can't omit the table (first key), alternative is just '.' e.g. '.field_name.field_alias' - * - * $attributes format: - * - title (string) Human readable field title, constant name will be accpeted as well (multi-language support - * - * - type (string) null (means system), number, text, dropdown, url, image, icon, datestamp, userclass, userclasses, user[_name|_loginname|_login|_customtitle|_email], - * boolean, method, ip - * full/most recent reference list - e_form::renderTableRow(), e_form::renderElement(), e_admin_form_ui::renderBatchFilter() - * for list of possible read/writeParms per type see below - * - * - data (string) Data type, one of the following: int, integer, string, str, float, bool, boolean, model, null - * Default is 'str' - * Used only if $dataFields is not set - * full/most recent reference list - e_admin_model::sanitize(), db::_getFieldValue() - * - dataPath (string) - xpath like path to the model/posted value. Example: 'dataPath' => 'prefix/mykey' will result in $_POST['prefix']['mykey'] - * - primary (boolean) primary field (obsolete, $pid is now used) - * - * - help (string) edit/create table - inline help, constant name will be accpeted as well, optional - * - note (string) edit/create table - text shown below the field title (left column), constant name will be accpeted as well, optional - * - * - validate (boolean|string) any of accepted validation types (see e_validator::$_required_rules), true == 'required' - * - rule (string) condition for chosen above validation type (see e_validator::$_required_rules), not required for all types - * - error (string) Human readable error message (validation failure), constant name will be accepted as well, optional - * - * - batch (boolean) list table - add current field to batch actions, in use only for boolean, dropdown, datestamp, userclass, method field types - * NOTE: batch may accept string values in the future... - * full/most recent reference type list - e_admin_form_ui::renderBatchFilter() - * - * - filter (boolean) list table - add current field to filter actions, rest is same as batch - * - * - forced (boolean) list table - forced fields are always shown in list table - * - nolist (boolean) list table - don't show in column choice list - * - noedit (boolean) edit table - don't show in edit mode - * - * - width (string) list table - width e.g '10%', 'auto' - * - thclass (string) list table header - th element class - * - class (string) list table body - td element additional class - * - * - readParms (mixed) parameters used by core routine for showing values of current field. Structure on this attribute - * depends on the current field type (see below). readParams are used mainly by list page - * - * - writeParms (mixed) parameters used by core routine for showing control element(s) of current field. - * Structure on this attribute depends on the current field type (see below). - * writeParams are used mainly by edit page, filter (list page), batch (list page) - * - * $attributes['type']->$attributes['read/writeParams'] pairs: - * - * - null -> read: n/a - * -> write: n/a - * - * - dropdown -> read: 'pre', 'post', array in format posted_html_name => value - * -> write: 'pre', 'post', array in format as required by e_form::selectbox() - * - * - user -> read: [optional] 'link' => true - create link to user profile, 'idField' => 'author_id' - tells to renderValue() where to search for user id (used when 'link' is true and current field is NOT ID field) - * 'nameField' => 'comment_author_name' - tells to renderValue() where to search for user name (used when 'link' is true and current field is ID field) - * -> write: [optional] 'nameField' => 'comment_author_name' the name of a 'user_name' field; 'currentInit' - use currrent user if no data provided; 'current' - use always current user(editor); '__options' e_form::userpickup() options - * - * - number -> read: (array) [optional] 'point' => '.', [optional] 'sep' => ' ', [optional] 'decimals' => 2, [optional] 'pre' => '€ ', [optional] 'post' => 'LAN_CURRENCY' - * -> write: (array) [optional] 'pre' => '€ ', [optional] 'post' => 'LAN_CURRENCY', [optional] 'maxlength' => 50, [optional] '__options' => array(...) see e_form class description for __options format - * - * - ip -> read: n/a - * -> write: [optional] element options array (see e_form class description for __options format) - * - * - text -> read: (array) [optional] 'htmltruncate' => 100, [optional] 'truncate' => 100, [optional] 'pre' => '', [optional] 'post' => ' px' - * -> write: (array) [optional] 'pre' => '', [optional] 'post' => ' px', [optional] 'maxlength' => 50 (default - 255), [optional] '__options' => array(...) see e_form class description for __options format - * - * - textarea -> read: (array) 'noparse' => '1' default 0 (disable toHTML text parsing), [optional] 'bb' => '1' (parse bbcode) default 0, - * [optional] 'parse' => '' modifiers passed to e_parse::toHTML() e.g. 'BODY', [optional] 'htmltruncate' => 100, - * [optional] 'truncate' => 100, [optional] 'expand' => '[more]' title for expand link, empty - no expand - * -> write: (array) [optional] 'rows' => '' default 15, [optional] 'cols' => '' default 40, [optional] '__options' => array(...) see e_form class description for __options format - * [optional] 'counter' => 0 number of max characters - has only visual effect, doesn't truncate the value (default - false) - * - * - bbarea -> read: same as textarea type - * -> write: (array) [optional] 'pre' => '', [optional] 'post' => ' px', [optional] 'maxlength' => 50 (default - 0), - * [optional] 'size' => [optional] - medium, small, large - default is medium, - * [optional] 'counter' => 0 number of max characters - has only visual effect, doesn't truncate the value (default - false) - * - * - image -> read: [optional] 'title' => 'SOME_LAN' (default - LAN_PREVIEW), [optional] 'pre' => '{e_PLUGIN}myplug/images/', - * 'thumb' => 1 (true) or number width in pixels, 'thumb_urlraw' => 1|0 if true, it's a 'raw' url (no sc path constants), - * 'thumb_aw' => if 'thumb' is 1|true, this is used for Adaptive thumb width - * -> write: (array) [optional] 'label' => '', [optional] '__options' => array(...) see e_form::imagepicker() for allowed options - * - * - icon -> read: [optional] 'class' => 'S16', [optional] 'pre' => '{e_PLUGIN}myplug/images/' - * -> write: (array) [optional] 'label' => '', [optional] 'ajax' => true/false , [optional] '__options' => array(...) see e_form::iconpicker() for allowed options - * - * - datestamp -> read: [optional] 'mask' => 'long'|'short'|strftime() string, default is 'short' - * -> write: (array) [optional] 'label' => '', [optional] 'ajax' => true/false , [optional] '__options' => array(...) see e_form::iconpicker() for allowed options - * - * - url -> read: [optional] 'pre' => '{ePLUGIN}myplug/'|'http://somedomain.com/', 'truncate' => 50 default - no truncate, NOTE: - * -> write: - * - * - method -> read: optional, passed to given method (the field name) - * -> write: optional, passed to given method (the field name) - * - * - hidden -> read: 'show' => 1|0 - show hidden value, 'empty' => 'something' - what to be shown if value is empty (only id 'show' is 1) - * -> write: same as readParms - * - * - upload -> read: n/a - * -> write: Under construction - * - * Special attribute types: - * - method (string) field name should be method from the current e_admin_form_ui class (or its extension). - * Example call: field_name($value, $render_action, $parms) where $value is current value, - * $render_action is on of the following: read|write|batch|filter, parms are currently used paramateres ( value of read/writeParms attribute). - * Return type expected (by render action): - * - read: list table - formatted value only - * - write: edit table - form element (control) - * - batch: either array('title1' => 'value1', 'title2' => 'value2', ..) or array('singleOption' => '') or rendered option group (string '' - * - filter: same as batch - * @var array - */ + protected $fields = array( 'checkboxes' => array('title'=> '', 'type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect'), 'download_id' => array('title'=> ID, 'type' => 'number', 'data' => 'int', 'width'=>'5%', 'thclass' => '', 'forced'=> TRUE, 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable @@ -350,19 +225,26 @@ class download_main_admin_ui extends e_admin_ui 'download_active' => array('title'=> DOWLAN_21, 'type' => 'method', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true), 'download_datestamp' => array('title'=> LAN_DATE, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'readParms' => 'long', 'writeParms' => ''), - 'download_thumb' => array('title'=> DOWLAN_20, 'type' => 'image', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), - 'download_image' => array('title'=> DOWLAN_19, 'type' => 'image', 'data' => 'str', 'width' => '20%', 'thclass' => 'center','readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE, 'batch' => FALSE, 'filter'=>FALSE), + 'download_thumb' => array('title'=> DOWLAN_20, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center','readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE ), + 'download_image' => array('title'=> DOWLAN_19, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center','readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE, 'batch' => FALSE, 'filter'=>FALSE), 'download_comment' => array('title'=> DOWLAN_102, 'type' => 'boolean', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true), - 'download_class' => array('title'=> DOWLAN_113, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int'), + 'download_class' => array('title'=> DOWLAN_113, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int','batch' => TRUE, 'filter'=>TRUE), 'download_mirror' => array('title'=> DOWLAN_128, 'type' => 'text', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), 'download_mirror_type' => array('title'=> DOWLAN_195, 'type' => 'method', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), - 'download_visible' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int'), + 'download_visible' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE), // 'download_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'left' ), 'issue' => array('title'=> 'Issue', 'type' => 'method', 'data' => null, 'nolist'=>TRUE, 'noedit'=>TRUE, 'filter'=>TRUE), 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE) ); + + protected $action = array(); + protected $subAction = array(); + protected $id = ""; + + + /* $columnInfo = array( "checkboxes" => array("title" => "", "forced"=> TRUE, "width" => "3%", "thclass" => "center first", "toggle" => "dl_selected"), @@ -410,9 +292,43 @@ $columnInfo = array( 'pref_name' => array('title'=> 'name', 'type' => 'text', 'data' => 'string', 'validate' => 'regex', 'rule' => '#^[\w]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore') ); + + public function observe() + { + if (isset($_POST['submit_download'])) // Create or Update a Download. + { + $this->submit_download(); + } + + if (isset($_POST['updatedownlaodoptions'])) // Save Download Options. + { + $this->saveSettings(); + } + + if (isset($_POST['submit_mirror'])) + { + $this->submit_mirror(); + } + + if (isset($_POST)) + { + e107::getCache()->clear("download_cat"); + } + } + + + // optional public function init() { + + $this->action = $_GET['mode']; + $this->subAction = $_GET['action']; + $this->id = $_GET['id']; + + $this->observe(); + + $categories = array(); if(e107::getDb()->db_Select('download_category')) { @@ -539,7 +455,7 @@ $columnInfo = array( function createPage() { global $adminDownload; - $adminDownload->create_download(); + $this->create_download(); } function importPage() @@ -549,8 +465,8 @@ $columnInfo = array( function settingsPage() { - global $adminDownload; - $adminDownload->show_download_options(); + // global $adminDownload; + $this->show_download_options(); } function limitsPage() @@ -566,8 +482,1186 @@ $columnInfo = array( function mirrorPage() { global $adminDownload; - $adminDownload->show_existing_mirrors(); + $this->show_existing_mirrors(); } + + + + function saveSettings() + { + global $admin_log,$pref; + + $tp = e107::getParser(); + + $temp = array(); + $temp['download_php'] = $_POST['download_php']; + $temp['download_view'] = $_POST['download_view']; + $temp['download_sort'] = $_POST['download_sort']; + $temp['download_order'] = $_POST['download_order']; + $temp['mirror_order'] = $_POST['mirror_order']; + $temp['recent_download_days'] = $_POST['recent_download_days']; + $temp['agree_flag'] = $_POST['agree_flag']; + $temp['download_email'] = $_POST['download_email']; + $temp['agree_text'] = $tp->toDB($_POST['agree_text']); + $temp['download_denied'] = $tp->toDB($_POST['download_denied']); + $temp['download_reportbroken'] = $_POST['download_reportbroken']; + if ($_POST['download_subsub']) $temp['download_subsub'] = '1'; else $temp['download_subsub'] = '0'; + if ($_POST['download_incinfo']) $temp['download_incinfo'] = '1'; else $temp['download_incinfo'] = '0'; + if ($admin_log->logArrayDiffs($temp, $pref, 'DOWNL_01')) + { + save_prefs(); + // e107::getMessage()->add(DOWLAN_65); + } + else + { + // e107::getMessage()->add(DOWLAN_8); + } + } + + + // Create Download FORM. + function create_download() + { + $action = $this->action; + $subAction = $this->subAction; + $id = $this->id; + + $sql = e107::getDb(); + $tp = e107::getParser(); + $fl = e107::getFile(); + + // print_a($this); + + global $e107, $cal, $rs, $ns, $file_array, $image_array, $thumb_array, $pst; + require_once(e_PLUGIN.'download/download_shortcodes.php'); + require_once(e_PLUGIN.'download/handlers/download_class.php'); + require_once(e_HANDLER."form_handler.php"); + + $download = new download; + + if ($file_array = $fl->get_files(e_DOWNLOAD, "","standard",5)) + { + sort($file_array); + } + if ($public_array = $fl->get_files(e_UPLOAD)) + { + foreach($public_array as $key=>$val) + { + $file_array[] = str_replace(e_UPLOAD,"",$val); + } + } + /* if ($sql->db_Select("rbinary")) //TODO Remove me. + { + while ($row = $sql->db_Fetch()) + { + extract($row); + $file_array[] = "Binary ".$binary_id."/".$binary_name; + } + } + */ + if ($image_array = $fl->get_files(e_FILE.'downloadimages/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) + { + sort($image_array); + } + if ($thumb_array = $fl->get_files(e_FILE.'downloadthumbs/', '\.gif$|\.jpg$|\.png$|\.GIF$|\.JPG$|\.PNG$','standard',2)) + { + sort($thumb_array); + } + + $frm = new e_form(); + $mirrorArray = array(); + + $download_status[0] = DOWLAN_122; + $download_status[1] = DOWLAN_123; + $download_status[2] = DOWLAN_124; + $preset = $pst->read_preset("admin_downloads"); // read preset values into array + extract($preset); + + if (!$sql->db_Select("download_category")) + { + $ns->tablerender(ADLAN_24, "
".DOWLAN_5."
"); + return; + } + $download_active = 1; + if ($_GET['action'] == "edit" && !$_POST['submit']) + { + if ($sql->db_Select("download", "*", "download_id=".intval($_GET['id']))) + { + $row = $sql->db_Fetch(); + extract($row); + + $mirrorArray = $this->makeMirrorArray($row['download_mirror']); + } + } + + if ($subAction == "dlm" && !$_POST['submit']) + { + require_once(e_PLUGIN.'download/download_shortcodes.php'); + if ($sql->db_Select("upload", "*", "upload_id=".$id)) + { + $row = $sql->db_Fetch(); + + $download_category = $row['upload_category']; + $download_name = $row['upload_name'].($row['upload_version'] ? " v" . $row['upload_version'] : ""); + $download_url = $row['upload_file']; + $download_author_email = $row['upload_email']; + $download_author_website = $row['upload_website']; + $download_description = $row['upload_description']; + $download_image = $row['upload_ss']; + $download_filesize = $row['upload_filesize']; + $image_array[] = array("path" => "", "fname" => $row['upload_ss']); + $download_author = substr($row['upload_poster'], (strpos($row['upload_poster'], ".")+1)); + } + } + + + $text = " +
+ +
+
+
+ + + + + +
".DOWLAN_13." +
".DOWLAN_131."   + +
+
+
+
+ + + + + + + + + +
".DOWLAN_149." + +
".DOWLAN_66." + +
+
+
+ + + + "; + } + else + { + $text .= DOWLAN_132."
"; + $mirrorList = $sql -> db_getList(); // Get the list of possible mirrors + $m_count = (count($mirrorArray) ? count($mirrorArray) : 1); // Count of mirrors actually in use (or count of 1 if none defined yet) + for($count = 1; $count <= $m_count; $count++) + { + $opt = ($count==1) ? "id='mirror'" : ""; + $text .=" +
+ + + "; + if (DOWNLOAD_DEBUG) + { + if ($id) + { + $text .= '('.$mirrorArray[($count-1)]['requests'].')'; + } + else + { + $text .= ""; + } + } + $text .= "
"; + } + $text .="
+ + + + + + + "; + } // End of mirror-related stuff + + $download_author = $subAction != "edit" && $download_author == "" ? USERNAME : $download_author;//TODO what if editing an no author specified + $download_author_email = $subAction != "edit" && $download_author_email == "" ? USEREMAIL : $download_author_email; + $text .= " +
".DOWLAN_128.""; + + // See if any mirrors to display + if (!$sql -> db_Select("download_mirror")) + { // No mirrors defined here + $text .= DOWLAN_144."
".DOWLAN_155." + ".DOWLAN_156."
+ ".DOWLAN_157." +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + if ($subAction == "dlm") { + $text .= " + + + + + + + + "; + } + + //triggerHook + $data = array('method'=>'form', 'table'=>'download', 'id'=>$id, 'plugin'=>'download', 'function'=>'create_download'); + $hooks = $e107->e_event->triggerHook($data); + if(!empty($hooks)) + { + $text .= " + + + "; + foreach($hooks as $hook) + { + if(!empty($hook)) + { + $text .= " + + + "; + } + } + } + + $text .= " + + + +
".DOWLAN_11.""; + $text .= $download->getCategorySelectList($download_category); + // $text .= download::getCategorySelectList($download_category); + + $text .= "
".DOWLAN_12." + toForm($download_name)."\" maxlength='200'/> +
".DOWLAN_15." + +
".DOWLAN_16." + +
".DOWLAN_17." + +
".DOWLAN_18." + "; + $text .= $frm->bbarea('download_description',$download_description); + + $text .= "
+ Activation between + + // TODO +
".DOWLAN_19.""; + /* + $text = ""; + */ + + $text .= $frm->imagepicker('download_image', $download_image,'','download'); + + if ($subAction == "dlm" && $download_image) + { + $text .= " + \n"; + } + $text .= "
".DOWLAN_20.""; + /* + $text .= " + "; + */ + + $text .= $frm->imagepicker('download_thumb', $download_thumb,'','downloadthumb'); + + + $text .= " +
".LAN_DATESTAMP.""; + if (!$download_datestamp){ + $download_datestamp = time(); + } + $cal_options['showsTime'] = false; + $cal_options['showOthers'] = false; + $cal_options['weekNumbers'] = false; + $cal_options['ifFormat'] = "%d/%m/%Y %H:%M:%S"; + $cal_options['timeFormat'] = "24"; + $cal_attrib['class'] = "tbox"; + $cal_attrib['size'] = "22"; + $cal_attrib['name'] = "download_datestamp"; + $cal_attrib['value'] = date("d/m/Y H:i:s", $download_datestamp); + $text .= $cal->make_input_field($cal_options, $cal_attrib); + $update_checked = ($_POST['update_datestamp']) ? "checked='checked'" : ""; + $text .= "   ".DOWLAN_148." +
".DOWLAN_21." + +
".DOWLAN_102.""; + if ($download_comment == "0") { + $text .= LAN_YES.": + ".LAN_NO.": "; + } else { + $text .= LAN_YES.": + ".LAN_NO.": "; + } + $text .= "
".DOWLAN_145."".r_userclass('download_visible', $download_visible, 'off', 'public, nobody, member, admin, classes, language')."
".DOWLAN_106."".r_userclass('download_class', $download_class, 'off', 'public, nobody, member, admin, classes, language')."
".DOWLAN_153." + +
".DOWLAN_103." + + +
".LAN_HOOKS."
".$hook['caption']."".$hook['text']."
"; + + + + if ($id && $subAction == "edit") + { + $text .= " "; + } else + { + $text .= ""; + } + + $text .= " +
+
+
+
+
"; + // $ns->tablerender(ADLAN_24, $text); + echo $text; + } + + + + // Actually save a new or edited download to the DB + function submit_download() + { + global $e107, $tp, $sql, $DOWNLOADS_DIRECTORY, $e_event; + + $action = $this->action; + $subAction = $this->subAction; + $id = $this->id; + + $sql = e107::getDb(); + $tp = e107::getParser(); + $fl = e107::getFile(); + $mes = e107::getMessage(); + + $dlInfo = array(); + $dlMirrors = array(); + + if ($subAction == 'edit') + { + if ($_POST['download_url_external'] == '') + { + $_POST['download_filesize_external'] = FALSE; + } + } + + if ($_POST['download_url_external'] && $_POST['download_url'] == '') + { + $dlInfo['download_url'] = $tp->toDB($_POST['download_url_external']); + $filesize = intval($_POST['download_filesize_external']); + } + else + { + $dlInfo['download_url'] = $tp->toDB($_POST['download_url']); + if ($_POST['download_filesize_external']) + { + $filesize = intval($_POST['download_filesize_external']); + } + else + { + if (strpos($DOWNLOADS_DIRECTORY, "/") === 0 || strpos($DOWNLOADS_DIRECTORY, ":") >= 1) + { + $filesize = filesize($DOWNLOADS_DIRECTORY.$dlInfo['download_url']); + } + else + { + $filesize = filesize(e_BASE.$DOWNLOADS_DIRECTORY.$dlInfo['download_url']); + } + } + } + + if (!$filesize) + { + if ($sql->db_Select("upload", "upload_filesize", "upload_file='{$dlInfo['download_url']}'")) + { + $row = $sql->db_Fetch(); + $filesize = $row['upload_filesize']; + } + } + $dlInfo['download_filesize'] = $filesize; + + + // ---- Move Images and Files ------------ + if ($_POST['move_image']) + { + if ($_POST['download_thumb']) + { + $oldname = e_UPLOAD.$_POST['download_thumb']; + $newname = e_FILE."downloadthumbs/".$_POST['download_thumb']; + if (!$this -> move_file($oldname,$newname)) + { + return; + } + } + if ($_POST['download_image']) + { + $oldname = e_UPLOAD.$_POST['download_image']; + $newname = e_FILE."downloadimages/".$_POST['download_image']; + if (!$this -> move_file($oldname,$newname)) + { + return; + } + } + } + + if ($_POST['move_file'] && $_POST['download_url']) + { + $oldname = e_UPLOAD.$_POST['download_url']; + $newname = $_POST['move_file'].$_POST['download_url']; + if (!$this -> move_file($oldname,$newname)) + { + return; + } + $dlInfo['download_url'] = str_replace(e_DOWNLOAD,"",$newname); + } + + + // ------------------------------------------ + + + $dlInfo['download_description'] = $tp->toDB($_POST['download_description']); + $dlInfo['download_name'] = $tp->toDB($_POST['download_name']); + $dlInfo['download_author'] = $tp->toDB($_POST['download_author']); + $dlInfo['download_author_email'] = $tp->toDB($_POST['download_author_email']); + $dlInfo['download_author_website'] = $tp->toDB($_POST['download_author_website']); + $dlInfo['download_category'] = intval($_POST['download_category']); + $dlInfo['download_active'] = intval($_POST['download_active']); + $dlInfo['download_thumb'] = $tp->toDB($_POST['download_thumb']); + $dlInfo['download_image'] = $tp->toDB($_POST['download_image']); + $dlInfo['download_comment'] = $tp->toDB($_POST['download_comment']); + $dlInfo['download_class'] = intval($_POST['download_class']); + $dlInfo['download_visible'] = intval($_POST['download_visible']); + + if(preg_match("#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#", $_POST['download_datestamp'], $matches)) + { + $dlInfo['download_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]); + } + else + { + $dlInfo['download_datestamp'] = time(); + } + + if($_POST['update_datestamp']) + { + $dlInfo['download_datestamp'] = time(); + } + + $mirrorStr = ""; + $mirrorFlag = FALSE; + + // See if any mirrors defined + // Need to check all the possible mirror names - might have deleted the first one if we're in edit mode + + if(count($_POST['download_mirror_name'])) + { + foreach ($_POST['download_mirror_name'] as $mn) + { + if ($mn) + { + $mirrorFlag = TRUE; + break; + } + } + } + + if ($mirrorFlag) + { + $mirrors = count($_POST['download_mirror_name']); + $mirrorArray = array(); + $newMirrorArray = array(); + if ($id && $sql->db_Select('download','download_mirror', 'download_id = '.$id)) // Get existing download stats + { + if ($row = $sql->db_Fetch()) + { + $mirrorArray = $this->makeMirrorArray($row['download_mirror'], TRUE); + } + } + for($a=0; $a<$mirrors; $a++) + { + $mid = trim($_POST['download_mirror_name'][$a]); + $murl = trim($_POST['download_mirror'][$a]); + $msize = trim($_POST['download_mirror_size'][$a]); + if ($mid && $murl) + { + $newMirrorArray[$mid] = array('id' => $mid, 'url' => $murl, 'requests' => 0, 'filesize' => $msize); + if (DOWNLOAD_DEBUG && !$id) + { + $newMirrorArray[$mid]['requests'] = intval($_POST['download_mirror_requests'][$a]); + } + } + } + // Now copy across any existing usage figures + foreach ($newMirrorArray as $k => $m) + { + if (isset($mirrorArray[$k])) + { + $newMirrorArray[$k]['requests'] = $mirrorArray[$k]['requests']; + } + } + $mirrorStr = $this->compressMirrorArray($newMirrorArray); + } + + $dlMirrors['download_mirror']=$mirrorStr; + $dlMirrors['download_mirror_type']=intval($_POST['download_mirror_type']); + + if ($id) // Its an edit + { + // Process triggers before calling admin_update so trigger messages can be shown + $data = array('method'=>'update', 'table'=>'download', 'id'=>$id, 'plugin'=>'download', 'function'=>'update_download'); + $hooks = $e107->e_event->triggerHook($data); + require_once(e_HANDLER."message_handler.php"); + + $mes->add($hooks, E_MESSAGE_SUCCESS); + + $updateArray = array_merge($dlInfo,$dlMirrors); + $updateArray['WHERE'] = 'download_id='.intval($id); + + $mes->autoMessage($sql->db_Update('download',$updateArray), 'update', DOWLAN_2." (".$_POST['download_name'].")"); + + $dlInfo['download_id'] = $id; + $this->downloadLog('DOWNL_06',$dlInfo,$dlMirrors); + $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings + unset($dlInfo['download_class']); // Also replicating 0.7 + $e_event->trigger('dlupdate', $dlInfo); + } + else // Its a new entry. + { + if ($download_id = $sql->db_Insert('download',array_merge($dlInfo,$dlMirrors))) + { + // Process triggers before calling admin_update so trigger messages can be shown + $data = array('method'=>'create', 'table'=>'download', 'id'=>$download_id, 'plugin'=>'download', 'function'=>'create_download'); + $hooks = $e107->e_event->triggerHook($data); + + $mes->add($hooks, E_MESSAGE_SUCCESS); + + $mes->autoMessage($download_id, 'insert', DOWLAN_1." (".$_POST['download_name'].")"); + + $dlInfo['download_id'] = $download_id; + $this->downloadLog('DOWNL_05',$dlInfo,$dlMirrors); + $dlInfo['download_datestamp'] = $time; // This is what 0.7 did, regardless of settings + unset($dlInfo['download_class']); // Also replicating 0.7 + $e_event->trigger("dlpost", $dlInfo); + + if ($_POST['remove_upload']) + { + $sql->db_Update("upload", "upload_active='1' WHERE upload_id='".$_POST['remove_id']."'"); + $mess = "
".$_POST['download_name']." ".DOWLAN_104; + $mess .= "

".DOWLAN_105.""; + $this->show_message($mess); + } + } + } + } + + + // Turn the array into a string which can be stored in the DB + function compressMirrorArray($source) + { + if (!is_array($source) || !count($source)) return ''; + $inter = array(); + foreach ($source as $s) + { + $inter[] = $s['id'].','.$s['url'].','.$s['requests'].','.$s['filesize']; + } + return implode(chr(1),$inter); + } + + + + + + + + function show_existing_mirrors() + { + $sql = e107::getDb(); + $tp = e107::getParser(); + $mes = e107::getMessage(); + $fl = e107::getFile(); + + $action = $this->action; + $subAction = $this->subAction; + $id = $this->id; + + global $delete, $del_id, $admin_log; + + require_once(e_HANDLER."form_handler.php"); + $frm = new e_form(); + + + if ($delete == "mirror") + { + $mes->autoMessage($sql -> db_Delete("download_mirror", "mirror_id=".$del_id), delete, DOWLAN_135); + $admin_log->log_event('DOWNL_14','ID: '.$del_id,E_LOG_INFORMATIVE,''); + } + + + if (!$sql -> db_Select("download_mirror")) + { + $mes->addInfo(DOWLAN_144); + // $text = "
".DOWLAN_144."
"; // No mirrors defined yet + } + else + { + + $text = "
+
+ + + + + + + + "; + + $mirrorList = $sql -> db_getList(); + + foreach($mirrorList as $mirror) + { + extract($mirror); + $text .= " + + + + + + + + "; + } + $text .= "
ID".DOWLAN_12."".DOWLAN_136."".LAN_OPTIONS."
$mirror_id".$tp -> toHTML($mirror_name)."".($mirror_image ? "" : DOWLAN_28)." + ".ADMIN_EDIT_ICON." + +
"; + + } + + // $ns -> tablerender(DOWLAN_138, $text); + echo $text; + + $imagelist = $fl->get_files(e_FILE.'downloadimages/'); + + if ($subAction == "edit" && !defined("SUBMITTED")) + { + $sql -> db_Select("download_mirror", "*", "mirror_id='".intval($id)."' "); + $mirror = $sql -> db_Fetch(); + extract($mirror); + $edit = TRUE; + } + else + { + unset($mirror_name, $mirror_url, $mirror_image, $mirror_location, $mirror_description); + $edit = FALSE; + } + + $text = "
+
\n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
".DOWLAN_12." + +
".DOWLAN_139." + +
".DOWLAN_136." + + + +
+ +
".DOWLAN_141." + +
".DOWLAN_18.""; + $text .= $frm->bbarea('mirror_description',$mirror_description); + $text .= "
+ ".($edit ? "" : "")." +
+
+
"; + + $caption = ($edit ? DOWLAN_142 : DOWLAN_143); + echo $text; + // $ns -> tablerender($caption, $text); + } + + function submit_mirror() + { + global $admin_log; + + $tp = e107::getParser(); + $sql = e107::getDb(); + $mes = e107::getMessage(); + + define("SUBMITTED", TRUE); + + if (isset($_POST['mirror_name']) && isset($_POST['mirror_url'])) + { + $name = $tp -> toDB($_POST['mirror_name']); + $url = $tp -> toDB($_POST['mirror_url']); + $location = $tp -> toDB($_POST['mirror_location']); + $description = $tp -> toDB($_POST['mirror_description']); + + $logString = $name.'[!br!]'.$url.'[!br!]'.$location.'[!br!]'.$description; + + if (isset($_POST['id'])) + { + $mes->autoMessage($sql -> db_Update("download_mirror", "mirror_name='{$name}', mirror_url='{$url}', mirror_image='".$tp->toDB($_POST['mirror_image'])."', mirror_location='{$location}', mirror_description='{$description}' WHERE mirror_id=".intval($_POST['id'])), 'update', DOWLAN_133); + $admin_log->log_event('DOWNL_13','ID: '.intval($_POST['id']).'[!br!]'.$logString,E_LOG_INFORMATIVE,''); + } + else + { + $mes->autoMessage($sql -> db_Insert("download_mirror", "0, '{$name}', '{$url}', '".$tp->toDB($_POST['mirror_image'])."', '{$location}', '{$description}', 0"), 'insert', DOWLAN_134); + $admin_log->log_event('DOWNL_12',$logString,E_LOG_INFORMATIVE,''); + } + } + } + + function show_download_options() + { + global $pref, $ns; + + require_once(e_HANDLER."form_handler.php"); + $frm = new e_form(true); //enable inner tabindex counter + + $agree_flag = $pref['agree_flag']; + $agree_text = $pref['agree_text']; + $c = $pref['download_php'] ? " checked = 'checked' " : ""; + $sacc = (varset($pref['download_incinfo'],0) == '1') ? " checked = 'checked' " : ""; + $order_options = array( + "download_id" => "Id No.", + "download_datestamp" => LAN_DATE, + "download_requested" => ADLAN_24, + "download_name" => DOWLAN_59, + "download_author" => DOWLAN_15 + ); + $sort_options = array( + "ASC" => DOWLAN_62, + "DESC" => DOWLAN_63 + ); + + $text = " +
+ + +
\n +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
".LAN_DL_USE_PHP."" + .$frm->checkbox('download_php', '1', $pref['download_php']) + .$frm->label(LAN_DL_USE_PHP_INFO, 'download_php', '1') + ."
".LAN_DL_SUBSUB_CAT."" + .$frm->checkbox('download_subsub', '1', $pref['download_subsub']) + .$frm->label(LAN_DL_SUBSUB_CAT_INFO, 'download_subsub', '1') + ."
".LAN_DL_SUBSUB_COUNT."" + .$frm->checkbox('download_incinfo', '1', $pref['download_incinfo']) + .$frm->label(LAN_DL_SUBSUB_COUNT_INFO, 'download_incinfo', '1') + ."
".DOWLAN_55."".$frm->text('download_view', $pref['download_view'], '4', array('size'=>'4'))."
".DOWLAN_56."".$frm->selectbox('download_order', $order_options, $pref['download_order'])."
".LAN_ORDER."".$frm->selectbox('download_sort', $sort_options, $pref['download_sort'])."
".DOWLAN_160." + +
".DOWLAN_164." +
+
+
+
+
+ + + + + + + + + + + + + +
".DOWLAN_151."". r_userclass("download_reportbroken", $pref['download_reportbroken'])."
".DOWLAN_150."". ($pref['download_email'] ? "" : "")."
+
+
+
+
+ + + + + + + + + + + + + + + + + +
".DOWLAN_100."". ($agree_flag ? "" : "")."
".DOWLAN_101."".$frm->bbarea('agree_text',$agree_text)."
".DOWLAN_146."".$frm->bbarea('download_denied',$pref['download_denied'])."
+
+
+
+
+ + + + + + + + + +
".DOWLAN_XXX."//TODO
+
+
+
+ +
+
+
+ "; + // $ns->tablerender(LAN_DL_OPTIONS, $text); + echo $text; + } + + + + + + function downloadLog($aText, &$dlInfo, &$mirrorInfo=NULL) + { + global $admin_log; + $logString = DOWLAN_9; + foreach ($dlInfo as $k => $v) + { + $logString .= '[!br!]'.$k.'=>'.$v; + } + if ($mirrorInfo != NULL) + { + foreach ($mirrorInfo as $k => $v) + { + $logString .= '[!br!]'.$k.'=>'.$v; + } + } + $admin_log->log_event($aText,$logString,E_LOG_INFORMATIVE,''); + } + + + + + + function move_file($oldname,$newname) + { + + $mes = e107::getMessage(); + + if (file_exists($newname)) + { + return TRUE; + } + + if (!file_exists($oldname) || is_dir($oldname)) + { + $mes->addError(DOWLAN_68 . " : ".$oldname); + return FALSE; + } + + $directory = dirname($newname); + if (is_writable($directory)) + { + if (!rename($oldname,$newname)) + { + $mes->addError(DOWLAN_152." ".$oldname ." -> ".$newname); + return FALSE; + } + else + { + return TRUE; + } + } + else + { + $mes->addError($directory ." ".LAN_NOTWRITABLE); + return FALSE; + } + } + + + + + + + + + + // Given the string which is stored in the DB, turns it into an array of mirror entries + // If $byID is true, the array index is the mirror ID. Otherwise its a simple array + function makeMirrorArray($source, $byID = FALSE) + { + $ret = array(); + if ($source) + { + $mirrorTArray = explode(chr(1), $source); + + $count = 0; + foreach($mirrorTArray as $mirror) + { + if ($mirror) + { + list($mid, $murl, $mreq, $msize) = explode(",", $mirror); + $ret[$byID ? $mid : $count] = array('id' => $mid, 'url' => $murl, 'requests' => $mreq, 'filesize' => $msize); + $count++; + } + } + } + return $ret; + } + + + } class download_main_admin_form_ui extends e_admin_form_ui