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 ), 'mirror' => array( 'controller' => 'download_mirror_ui', 'path' => null, 'ui' => 'download_mirror_form_ui', 'uipath' => null ), 'broken' => array( 'controller' => 'download_broken_ui', 'path' => null, 'ui' => 'download_broken_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 e107::getNav()->admin() key-value pair could be added to the above array * @var array */ protected $adminMenu = array( 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'), 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 'other0' => array('divider'=> true), 'cat/list' => array('caption'=> LAN_CATEGORIES, 'perm'=>'P'), 'cat/create' => array('caption'=> LAN_CREATE_CATEGORY, 'perm' => 'Q'), 'other1' => array('divider'=> true), 'mirror/list' => array('caption'=> DOWLAN_128, 'perm' => 'P'), 'mirror/create' => array('caption'=> DOWLAN_143, 'perm' => 'P'), 'other2' => array('divider'=> true), 'broken/list' => array('caption'=> LAN_DL_BROKENDOWNLOADSREPORTS, 'perm' => 'P'), 'other3' => array('divider'=> true), 'main/settings' => array('caption'=> LAN_PREFS, '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"; e107::getNav()->admin(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 = LAN_PLUGIN_DOWNLOAD_NAME; } class download_cat_ui extends e_admin_ui { protected $pluginTitle = LAN_PLUGIN_DOWNLOAD_NAME; protected $pluginName = 'download'; protected $eventName = 'download-category'; protected $table = "download_category"; protected $pid = "download_category_id"; protected $perPage = 0; //no limit protected $batchCopy = true; // initiate as a parent/child tree. protected $sortField = 'download_category_order'; protected $sortParent = 'download_category_parent'; protected $treePrefix = 'download_category_name'; // protected $orderStep = // automatic // protected $listOrder = // automatic //legacy URL scheme protected $url = array('route'=>'download/list/category', 'vars' => array('id' => 'download_category_id', 'name' => 'download_category_sef'), 'name' => 'download_category_name', 'description' => ''); // 'link' only needed if profile not provided. protected $fields = array( 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 'download_category_icon' => array('title'=> LAN_ICON, 'type' => 'method', 'width' => '5%', 'thclass' => 'center','class'=>'center','writeParms'=>'glyphs=1' ), 'download_category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readParms'=>'link=sef&target=blank'), 'download_category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=>'str', 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'size=xxlarge'), 'download_category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'data'=>'str', 'batch'=>true, 'inline' => true, 'width' => 'auto', 'thclass' => 'left', 'writeParms'=>'sef=download_category_name&size=xxlarge'), 'download_category_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'data'=>'str', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'download_category_parent' => array('title'=> LAN_PARENT, 'type' => 'method', 'width' => '5%', 'batch' => TRUE, 'filter'=>TRUE), 'download_category_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'inline' => true, 'width' => 'auto', 'data' => 'int', 'batch' => TRUE, 'filter'=>TRUE), 'download_category_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'nolist'=>true, 'data'=>'int', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ), 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort'=>1) ); protected $fieldpref = array('download_category_icon', 'download_category_id', 'download_category_name', 'download_category_sef', 'download_category_class', 'download_category_order'); protected $downloadCats = array(); function init() { if(deftrue('e_DEBUG')) { $this->fields['download_category_order']['nolist'] = false; } $this->setDownloadCategoryTree(); } private function setDownloadCategoryTree() { $sql = e107::getDb(); $qry = $this->getParentChildQry(true); $sql->gen($qry); $this->downloadCats[0] = LAN_NONE; while($row = $sql->fetch()) { $num = (int) $row['_depth'] - 1; if($num < 0) { $num = 0; } $id = $row['download_category_id']; $this->downloadCats[$id] = str_repeat(" ",$num).$row['download_category_name']; } if($this->getAction() === 'edit') // make sure parent is not the same as ID. { $r = $this->getId(); unset($this->downloadCats[$r]); } } function getDownloadCategoryTree($id = false) { if($id) { return $this->downloadCats[$id]; } return $this->downloadCats; } } 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->select('download_category_parent', $controller->getDownloadCategoryTree(), $curVal); break; case 'filter': case 'batch': return $controller->getDownloadCategoryTree(); break; } } public function download_category_icon($curVal,$mode) { if(!empty($curVal) && strpos($curVal, chr(1))) { list($curVal,$tmp) = explode(chr(1),$curVal); } switch($mode) { case 'read': return e107::getParser()->toIcon($curVal, array('legacy'=>'{e_IMAGE}icons/')); break; case 'write': return $this->iconpicker('download_category_icon', $curVal,null,array('glyphs'=>true, 'legacyPath'=>'{e_IMAGE}icons/')); break; case 'filter': case 'batch': return null; break; } } } class download_main_admin_ui extends e_admin_ui { // required protected $pluginTitle = LAN_PLUGIN_DOWNLOAD_NAME; protected $pluginName = 'download'; protected $eventName = 'download'; protected $table = "download"; // DB Table, table alias is supported. Example: 'r.release' protected $listQry = "SELECT m.*, c.download_category_sef, u.user_id,u.user_name FROM #download AS m lEFT JOIN #download_category AS c on m.download_category = c.download_category_id 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_image', 'download_id', 'download_datestamp', 'download_category', 'download_name', 'download_active', 'download_class', 'fb_order', 'options'); // Security modes protected $security_options = array( 'none' => LAN_DL_SECURITY_MODE_NONE, 'nginx-secure_link_md5' => LAN_DL_SECURITY_MODE_NGINX_SECURELINKMD5 ); // 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'=> LAN_ID, 'type' => 'text', 'data' => 'int', 'width'=>'5%', 'thclass' => '', 'forced'=> TRUE, 'readParms'=>'url=item&target=blank', 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable 'download_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data' => 'str', 'inline'=>true, 'width' => 'auto', 'thclass' => ''), 'download_url' => array('title'=> DOWLAN_13, 'type' => 'url', 'data' => 'str', 'width'=>'auto', 'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE), 'download_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'data' => 'str', 'width'=>'auto', 'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE, 'writeParms'=>'sef=download_name'), 'download_keywords' => array('title'=> LAN_KEYWORDS, 'type' => 'tags', 'inline'=>true, 'data' => 'str', 'width'=>'auto', 'thclass' => ''), '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', 'inline'=>true, '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&legacyPath={e_FILE}downloadthumbs', 'writeParms' => 'media=download_image', '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&legacyPath={e_FILE}downloadimages', 'writeParms' => 'media=download_image', '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', 'inline'=>true, 'data' => 'int','batch' => TRUE, 'filter'=>TRUE), 'download_visible' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'inline'=>true, '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"=>LAN_ID, "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') ); /** * @var e_parse */ private $tp; /** * @inheritDoc */ public function __construct($request, $response, $params = array()) { parent::__construct($request, $response, $params); $this->tp = e107::getParser(); } 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 = $this->getMode(); // vartrue($_GET['mode']); $this->subAction = $this->getAction(); // vartrue($_GET['action']); $this->id = $this->getId(); // vartrue($_GET['id']); $this->observe(); $categories = array(); if(e107::getDb()->select('download_category')) { //$categories[0] = LAN_SELECT; while ($row = e107::getDb()->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(vartrue($_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->gen("SELECT * FROM `#download` ORDER BY download_id")) { while($row = $sql->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 { $sql = e107::getDb(); $tp = e107::getParser(); $files = e107::getFile()->get_files(e_DOWNLOAD); $foundSome = false; foreach($files as $file) { if (0 == $sql->count('download', '(*)', " WHERE download_url='".$file['fname']."'")) { if (!$foundSome) { // $text .= $rs->form_open("post", e_SELF."?".e_QUERY, "myform"); $text .= '