From e2a9fef94fab2226e3db9e05fb3c629b21232d0d Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 7 Apr 2017 17:04:28 -0700 Subject: [PATCH] Admin area Theme Manager rewrite - finally uses the admin-ui. --- e107_admin/theme.php | 1631 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1631 insertions(+) create mode 100644 e107_admin/theme.php diff --git a/e107_admin/theme.php b/e107_admin/theme.php new file mode 100644 index 000000000..70c9a9c5b --- /dev/null +++ b/e107_admin/theme.php @@ -0,0 +1,1631 @@ + 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' => 'theme_admin_ui', + 'path' => null, + 'ui' => 'theme_admin_form_ui', + 'uipath' => null + ), + 'convert' => array( + 'controller' => 'theme_builder', + 'path' => null, + 'ui' => 'theme_admin_form_ui', + 'uipath' => null + ), + ); + + + protected $adminMenu = array( + 'main/main' => array('caption'=> TPVLAN_33, 'perm' => '0'), + 'main/admin' => array('caption'=> TPVLAN_34, 'perm' => '0'), + 'main/choose' => array('caption'=> TPVLAN_51, 'perm' => '0'), + 'main/online' => array('caption'=> TPVLAN_62, 'perm' => '0'), + 'main/upload' => array('caption'=> TPVLAN_38, 'perm' => '0'), + 'convert/main' => array('caption'=> ADLAN_CL_6, 'perm' => '0') + ); + + + protected $adminMenuAliases = array( + 'main/edit' => 'main/list' + ); + + protected $adminMenuIcon = 'e-themes-24'; + + protected $menuTitle = TPVLAN_26; + + function init() + { + + } + + + + function handleAjax() + { + if(empty($_GET['action'])) + { + return null; + } + + + require_once(e_HANDLER."theme_handler.php"); + $themec = new themeHandler; + + switch ($_GET['action']) + { + case 'login': + $mp = $themec->getMarketplace(); + echo $mp->renderLoginForm(); + exit; + break; + + /* + case 'download': + $string = base64_decode($_GET['src']); + parse_str($string, $p); + $mp = $themec->getMarketplace(); + $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); + // Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers) + echo "
Connecting...\n"; flush();
+					// download and flush
+					$mp->download($p['id'], $p['mode'], $p['type']);
+					echo "
"; flush(); + exit; + break; + */ + + case 'info': + if(!empty($_GET['src'])) + { + $string = base64_decode($_GET['src']); + parse_str($string,$p); + $themeInfo = e107::getSession()->get('thememanager/online/'.intval($p['id'])); + echo $themec->renderThemeInfo($themeInfo); + } + break; + + case 'preview': + // Theme Info Ajax + $tm = (string) $_GET['id']; + $data = $themec->getThemeInfo($tm); + echo $themec->renderThemeInfo($data); + // exit; + break; + + } + /* + if(vartrue($_GET['src'])) // Process Theme Download. + { + $string = base64_decode($_GET['src']); + parse_str($string,$p); + + if(vartrue($_GET['info'])) + { + echo $themec->renderThemeInfo($p); + // print_a($p); + exit; + } + + $remotefile = $p['url']; + + e107::getFile()->download($remotefile,'theme'); + exit; + + } + */ + // Theme Info Ajax + // FIXME addd action=preview to the url, remove this block + if(!empty($_GET['id'])) + { + $tm = (string) $_GET['id']; + $data = $themec->getThemeInfo($tm); + echo $themec->renderThemeInfo($data); + } + + require_once(e_ADMIN."footer.php"); + exit; + + } + + + + +} + + + +class theme_admin_ui extends e_admin_ui +{ + // required + protected $pluginTitle = TPVLAN_26; + protected $pluginName = 'core'; + protected $table = false; + protected $listQry = false; + protected $pid = "id"; + protected $perPage = 10; + protected $batchDelete = false; + + // protected \$sortField = 'somefield_order'; + // protected \$sortParent = 'somefield_parent'; + // protected \$treePrefix = 'somefield_title'; + protected $grid = array('price'=>'price', 'version'=>'version','title'=>'name', 'image'=>'thumbnail', 'body'=>'', 'class'=>'col-md-2', 'perPage'=>12, 'carousel'=>true); + + + protected $fields = array( + 'checkboxes' => array('title'=> '', 'type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect'), + 'id' => array('title'=> LAN_ID, 'type' => 'number', 'data' => 'int', 'width'=>'5%', 'thclass' => '', 'class'=>'center', 'forced'=> TRUE, 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable + 'name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width'=>'5%', 'thclass' => '', 'forced'=> TRUE, 'primary'=>TRUE/*, 'noedit'=>TRUE*/), //Primary ID is not editable + 'thumbnail' => array('title'=> LAN_IMAGE, 'type' => 'image', 'readParms'=>array('thumb'=>1,'w'=>300,'h'=>169,'crop'=>1, 'link'=>false, 'fallback'=>'{e_IMAGE}admin_images/nopreview.png'), 'data' => 'str', 'width'=>'auto', 'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE), + 'folder' => array('title'=> 'Folder', 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''), + 'category' => array('title'=> LAN_CATEGORY, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''), + 'version' => array('title'=> 'Version', 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''), + 'price' => array('title'=> LAN_AUTHOR, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), + // 'blank_authorURL' => array('title'=> "Url", 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), + // 'blank_date' => array('title'=> LAN_DATE, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'readParms' => 'long', 'writeParms' => 'type=datetime'), + // 'blank_compatibility' => array('title'=> 'Compatible', 'type' => 'text', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), + // 'blank_url' => array('title'=> LAN_URL, 'type' => 'file', 'data' => 'str', 'width' => '20%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'parms' => 'truncate=30', 'validate' => false, 'help' => 'Enter blank URL here', 'error' => 'please, ener valid URL'), + // 'test_list_1' => array('title'=> 'test 1', 'type' => 'boolean', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true), + 'options' => array('title'=> LAN_OPTIONS, 'type' => 'method', 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE) + ); + + //required - default column user prefs + // protected $fieldpref = array('checkboxes', 'blank_id', 'blank_type', 'blank_url', 'blank_compatibility', 'options'); + + // optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName); + protected $prefs = array(); + + protected $themeObj; + + public function __construct($request,$response,$params=array()) + { + require_once(e_HANDLER."theme_handler.php"); + $this->themeObj = new themeHandler; // handles POSTed data. + parent::__construct($request,$response,$params); + } + + // optional + public function init() + { + + e107::css('inline', ' + + + .admin-ui-grid .price { + position: absolute; + /* bottom: 68px;*/ + top:0; + right: 18px; + } + + .overlay-title { padding-bottom:7px } + + '); + + + + + $this->themeObj ->postObserver(); + + $this->grid['template'] = ' + +
+
{IMAGE} +
+
{TITLE} v{VERSION}
+ {OPTIONS} +
+
+ +
+ + + '; + } + + public function _setTreeModel() + { + if($this->getAction() === 'online') + { + $this->_tree_model = new theme_admin_online_tree_model; + } + else + { + $this->_tree_model = new theme_admin_tree_model;// new theme_model_admin_tree(); + } + + return $this; + } + + public function ChooseObserver() // action = choose + { + $param = array(); + $this->perPage = 0; + $param['limitFrom'] = (int) $this->getQuery('from', 0); + $param['limitTo'] = 0 ; // (int) $this->getPerPage(); + $param['searchqry'] = $this->getQuery('searchquery', ''); + + $this->getTreeModel()->setParams($param)->load(); // load the tree model above from the class below. + } + + public function OnlineObserver() + { + $this->ChooseObserver(); + } + + public function ChooseAjaxObserver() + { + $this->ChooseObserver(); + } + + public function MainPage() + { + return $this->renderThemeConfig('front'); + } + + public function AdminPage() + { + return $this->renderThemeConfig('admin'); + } + + private function search($name, $searchVal, $submitName, $filterName='', $filterArray=false, $filterVal=false) + { + $frm = e107::getForm(); + + return $frm->search($name, $searchVal, $submitName, $filterName, $filterArray, $filterVal); + + } + + public function OnlinePageOld() + { + global $e107SiteUsername, $e107SiteUserpass; + $xml = e107::getXml(); + $mes = e107::getMessage(); + $frm = e107::getForm(); + + require_once(e_HANDLER.'e_marketplace.php'); + + $mp = new e_marketplace(); // autodetect the best method + $from = intval(varset($_GET['frm'])); + $limit = 96; // FIXME - ajax pages load + $srch = preg_replace('/[^\w]/','', vartrue($_GET['srch'])); + + // check for cURL + if(!function_exists('curl_init')) + { + $mes->addWarning(TPVLAN_79); + } + + // auth + $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); + + // do the request, retrieve and parse data + $xdata = $mp->call('getList', array( + 'type' => 'theme', + 'params' => array('limit' => $limit, 'search' => $srch, 'from' => $from) + )); + $total = $xdata['params']['count']; + + + + $amount =$limit; + + + $c = 1; + + $text = "