array('controller' =>'CONTROLLER_CLASS'[, 'index' => 'list', 'path' => 'CONTROLLER SCRIPT PATH', 'ui' => 'UI CLASS NAME child of e_admin_ui', 'uipath' => 'UI SCRIPT PATH']); * Note - default mode/action is autodetected in this order: * - $defaultMode/$defaultAction (owned by dispatcher - see below) * - $adminMenu (first key if admin menu array is not empty) * - $modes (first key == mode, corresponding 'index' key == action) * @var array */ protected $modes = array ( 'main' => array ( 'controller' => 'download_main_admin_ui', 'path' => null, 'ui' => 'download_main_admin_form_ui', 'uipath' => null ), 'cat' => array ( 'controller' => 'download_cat_ui', 'path' => null, 'ui' => 'download_cat_form_ui', 'uipath' => null ) ); /* Both are optional protected $defaultMode = null; protected $defaultAction = null; */ /** * Format: 'MODE/ACTION' => array('caption' => 'Menu link title'[, 'url' => '{e_PLUGIN}release/admin_config.php', 'perm' => '0']); * Additionally, any valid e_admin_menu() key-value pair could be added to the above array * @var array */ protected $adminMenu = array( 'main/list' => array('caption'=> 'Manage', 'perm' => 'P'), 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 'cat/list' => array('caption'=> DOWLAN_31, 'perm'=>'P'), 'cat/create' => array('caption'=> "Create Category", 'perm' => 'Q'), 'main/settings' => array('caption'=> 'Settings', 'perm' => 'P'), 'main/maint' => array('caption'=> DOWLAN_165, 'perm' => 'P'), 'main/limits' => array('caption'=> DOWLAN_112, 'perm' => 'P'), 'main/mirror' => array('caption'=> DOWLAN_128, 'perm' => 'P') ); /* $var['main']['text'] = DOWLAN_29; $var['main']['link'] = e_SELF; $var['create']['text'] = DOWLAN_30; $var['create']['link'] = e_SELF."?create"; $var['cat']['text'] = DOWLAN_31; $var['cat']['link'] = e_SELF."?cat"; $var['cat']['perm'] = "Q"; $var['opt']['text'] = LAN_OPTIONS; $var['opt']['link'] = e_SELF."?opt"; $var['maint']['text'] = DOWLAN_165; $var['maint']['link'] = e_SELF."?maint"; $var['limits']['text'] = DOWLAN_112; $var['limits']['link'] = e_SELF."?limits"; $var['mirror']['text'] = DOWLAN_128; $var['mirror']['link'] = e_SELF."?mirror"; e_admin_menu(DOWLAN_32, $action, $var); unset($var); $var['ulist']['text'] = DOWLAN_22; $var['ulist']['link'] = e_SELF."?ulist";; $var['filetypes']['text'] = DOWLAN_23; $var['filetypes']['link'] = e_SELF."?filetypes"; $var['uopt']['text'] = LAN_OPTIONS; $var['uopt']['link'] = e_SELF."?uopt"; */ /** * Optional, mode/action aliases, related with 'selected' menu CSS class * Format: 'MODE/ACTION' => 'MODE ALIAS/ACTION ALIAS'; * This will mark active main/list menu item, when current page is main/edit * @var array */ protected $adminMenuAliases = array( 'main/edit' => 'main/list', 'cat/edit' => 'cat/list' ); /** * Navigation menu title * @var string */ protected $menuTitle = 'Downloads Menu'; } class download_cat_ui extends e_admin_ui { protected $pluginTitle = 'Download Categories'; protected $pluginName = 'download'; protected $table = "download_category"; protected $pid = "download_category_id"; protected $perPage = 0; //no limit protected $listOrder = 'download_category_order'; // protected $defaultOrderField = 'download_category_parent,download_category_order'; // protected $listQry = "SELECT * FROM #faq_info"; // without any Order or Limit. // protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}"; protected $fields = array( 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 'download_category_icon' => array('title'=> LAN_ICON, 'type' => 'icon', 'width' => '5%', 'thclass' => 'center','class'=>'center' ), 'download_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE), 'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left'), 'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'download_category_parent' => array('title'=> 'Parent', 'type' => 'method', 'width' => '5%', 'batch' => TRUE, 'filter'=>TRUE), 'download_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE), 'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ), 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center') ); function getDownloadCategoryTree($id = false, $default = 'n/a') { // TODO get faq category tree $sql = e107::getDb(); $sql -> db_Select_gen('SELECT * FROM #download_category ORDER BY download_category_order'); $cats = array(); $cats[0] = $default; while($row = $sql->db_Fetch()) { $cats[$row['download_category_id']] = $row['download_category_name']; } if($id) { return $cats[$id]; } return $cats; } } class download_cat_form_ui extends e_admin_form_ui { public function download_category_parent($curVal,$mode) { // TODO - catlist combo without current cat ID in write mode, parents only for batch/filter // Get UI instance $controller = $this->getController(); switch($mode) { case 'read': return e107::getParser()->toHTML($controller->getDownloadCategoryTree($curVal), false, 'TITLE'); break; case 'write': return $this->selectbox('download_category_parent', $controller->getDownloadCategoryTree(), $curVal); break; case 'filter': case 'batch': return $controller->getDownloadCategoryTree(); break; } } } class download_main_admin_ui extends e_admin_ui { // required protected $pluginTitle = "Downloads"; protected $pluginName = 'download'; protected $table = "download"; // DB Table, table alias is supported. Example: 'r.release' protected $listQry = "SELECT m.*,u.user_id,u.user_name FROM #download AS m LEFT JOIN #user AS u ON m.download_author = u.user_id "; // without any Order or Limit. //required - default column user prefs protected $fieldpref = array('checkboxes', 'download_id', 'download_category', 'download_name', 'fb_template', 'fb_class', 'fb_order', 'options'); // // optional - required only in case of e.g. tables JOIN. This also could be done with custom model (set it in init()) //protected $editQry = "SELECT * FROM #release WHERE release_id = {ID}"; // required - if no custom model is set in init() (primary id) protected $pid = "download_id"; // optional protected $perPage = 10; // default - true - TODO - move to displaySettings protected $batchDelete = true; 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 'download_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''), 'download_url' => array('title'=> DOWLAN_13, 'type' => 'url', 'data' => 'str', 'width'=>'auto', 'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE), 'download_author' => array('title'=> LAN_AUTHOR, 'type' => 'user', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'download_author_email' => array('title'=> DOWLAN_16, 'type' => 'email', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'download_author_website' => array('title'=> DOWLAN_17, 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'download_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'download_filesize' => array('title'=> DOWLAN_66, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => 'right', 'class' => 'right'), 'download_requested' => array('title'=> DOWLAN_29, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => 'right', 'class' => 'right'), 'download_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => 'auto', 'batch' => TRUE, 'filter'=>TRUE), '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' => '100px', 'thclass' => 'center', 'class'=>'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', 'class'=>'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','batch' => TRUE, 'filter'=>TRUE), 'download_visible' => array('title'=> LAN_VISIBILITY, '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_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"), "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) ); */ // FORMAT field_name=>type - optional if fields 'data' attribute is set or if custom model is set in init() /*protected $dataFields = array();*/ // optional, could be also set directly from $fields array with attributes 'validate' => true|'rule_name', 'rule' => 'condition_name', 'error' => 'Validation Error message' /*protected $validationRules = array( 'release_url' => array('required', '', 'Release URL', 'Help text', 'not valid error message') );*/ // optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName); protected $prefs = array( 'pref_type' => array('title'=> 'type', 'type'=>'text', 'data' => 'string', 'validate' => true), 'pref_folder' => array('title'=> 'folder', 'type' => 'boolean', 'data' => 'integer'), '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')) { //$categories[0] = LAN_SELECT; while ($row = e107::getDb()->db_Fetch()) { $id = $row['download_category_id']; $categories[$id] = $row['download_category_name']; } } $this->fields['download_category']['writeParms'] = $categories; // DEPRECATED //$this->fields['fb_rendertype']['writeParms'] = array(FBLAN_23,FBLAN_24); //$this->fields['fb_mode']['writeParms'] = array(FBLAN_13,FBLAN_14); $this->fields['download_category']['readParms'] = $categories; // Custom filter queries if($_GET['filter_options']) { list($filter,$mode) = explode("__",$_GET['filter_options']); if($mode == 'missing') { $this->filterQry = $this->missingFiles(); } if($mode == 'nocategory') { $this->filterQry = "SELECT * FROM `#download` WHERE download_category=0"; } if($mode == 'duplicates') { $this->filterQry = "SELECT GROUP_CONCAT(d.download_id SEPARATOR ',') as gc, d.download_id, d.download_name, d.download_url, dc.download_category_name FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id=d.download_category GROUP BY d.download_url HAVING COUNT(d.download_id) > 1"; } if($mode == "filesize") { $this->filterQry = $this->missingFiles('filesize'); } } } /* * Return a query for Missing Files and Filesize mismatch */ public function missingFiles($mode='missing') { $sql = e107::getDb(); $count = array(); if ($sql->db_Select_gen("SELECT * FROM `#download` ORDER BY download_id")) { while($row = $sql->db_Fetch()) { if (!is_readable(e_DOWNLOAD.$row['download_url'])) { $count[] = $row['download_id']; } elseif($mode == 'filesize') { $filesize = filesize(e_DOWNLOAD.$row['download_url']); if ($filesize <> $row['download_filesize']) { $count[] = $row['download_id']; } } } } if($count > 0) { return "SELECT * FROM `#download` WHERE download_id IN (".implode(",",$count).")"; } } function orphanFiles() //TODO { $files = e107::getFile()->get_files(e_DOWNLOAD); $foundSome = false; foreach($files as $file) { if (0 == $sql->db_Count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { if (!$foundSome) { // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); $text .= '
'; $text .= ''; $text .= ''; $text .= ''; $text .= ''; $text .= ''; $text .= ''; $foundSome = true; } $filesize = (is_readable(e_DOWNLOAD.$row['download_url']) ? $e107->parseMemorySize(filesize(e_DOWNLOAD.$file['fname'])) : DOWLAN_181); $filets = (is_readable(e_DOWNLOAD.$row['download_url']) ? $gen->convert_date(filectime(e_DOWNLOAD.$file['fname']), "long") : DOWLAN_181); $text .= ''; $text .= ''; $text .= ''; $text .= ''; } } } function createPage() { global $adminDownload; $this->create_download(); } function importPage() { $this->batchImportForm(); } function settingsPage() { // global $adminDownload; $this->show_download_options(); } function limitsPage() { showLimits(); } function maintPage() { showMaint(); } function mirrorPage() { global $adminDownload; $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_182.''.DOWLAN_66.''.LAN_OPTIONS.'
'.$tp->toHTML($file['fname']).''.$filets.''.$filesize.'
".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 { function download_category($curVal,$mode) // not really necessary since we can use 'dropdown' - but just an example of a custom function. { if($mode == 'read') { return $curVal.' (custom!)'; } if($mode == 'batch') // Custom Batch List for release_type { return array('theme'=>"Theme","plugin"=>'Plugin'); } if($mode == 'filter') // Custom Filter List for release_type { return array('theme'=>"Theme","plugin"=>'Plugin'); } $types = array("theme","plugin"); $text = ""; return $text; } function download_active($curVal,$mode) { $download_status[0] = DOWLAN_122; // Inactive; $download_status[1] = DOWLAN_123; // Active $download_status[2] = DOWLAN_124; if($mode == 'read') { $status = array(ADMIN_FALSE_ICON,ADMIN_TRUE_ICON,ADMIN_WARNING_ICON); return $status[$curVal]; } if($mode == 'batch' || $mode == 'filter') // Custom Batch List for download_active { return $download_status; } return " "; } // Filter List for 'Issues' function issue($curVal,$mode) { if($mode == 'filter') { return array( 'duplicates' => DOWLAN_166, 'orphans' => DOWLAN_167, // TODO 'missing' => DOWLAN_168, 'nocategory' => DOWLAN_178, 'filesize' => DOWLAN_66, 'log' => DOWLAN_171 ); } return " "; } function download_mirror_type($curVal,$mode) { switch ($curVal) { case 1: return DOWLAN_196; break; default: // return DOWLAN_197; } } }