From b21191b0a1b089240bdf345c490208d9a0f4a59e Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 11 Dec 2020 11:26:22 -0800 Subject: [PATCH] gSitemap converted to admin-ui. (incomplete). Enable debug to view old code. --- e107_plugins/gsitemap/admin_config.php | 576 ++++++++++++++++++++++++- 1 file changed, 572 insertions(+), 4 deletions(-) diff --git a/e107_plugins/gsitemap/admin_config.php b/e107_plugins/gsitemap/admin_config.php index f9cc51cab..a9c3bbbf5 100644 --- a/e107_plugins/gsitemap/admin_config.php +++ b/e107_plugins/gsitemap/admin_config.php @@ -15,14 +15,582 @@ if(!getperms("P") || !e107::isInstalled('gsitemap')) e107::redirect('admin'); exit(); } -require_once(e_ADMIN."auth.php"); -require_once(e_HANDLER."userclass_class.php"); +//require_once(e_ADMIN."auth.php"); +//require_once(e_HANDLER."userclass_class.php"); e107::lan('gsitemap',true); -$gsm = new gsitemap; -//todo Use ADMIN-UI + +class gsitemap_adminArea extends e_admin_dispatcher +{ + + protected $modes = array( + + 'main' => array( + 'controller' => 'gsitemap_ui', + 'path' => null, + 'ui' => 'gsitemap_form_ui', + 'uipath' => null + ), + + + ); + + + protected $adminMenu = array( + + 'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'), + 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), + + 'main/div0' => array('divider'=> true), + 'main/import' => array('caption'=> 'Import', 'perm' => 'P'), + 'main/instructions' => array('caption'=> 'Instructions', 'perm' => 'P'), + + ); + + protected $adminMenuAliases = array( + 'main/edit' => 'main/list' + ); + + protected $menuTitle = LAN_PLUGIN_GSITEMAP_NAME; +} + + + + + +class gsitemap_ui extends e_admin_ui +{ + + protected $pluginTitle = LAN_PLUGIN_GSITEMAP_NAME; + protected $pluginName = 'gsitemap'; + // protected $eventName = 'gsitemap-gsitemap'; // remove comment to enable event triggers in admin. + protected $table = 'gsitemap'; + protected $pid = 'gsitemap_id'; + protected $perPage = 10; + protected $batchDelete = true; + protected $batchExport = true; + protected $batchCopy = true; + + // protected $sortField = 'somefield_order'; + // protected $sortParent = 'somefield_parent'; + // protected $treePrefix = 'somefield_title'; + + protected $tabs = array(LAN_GENERAL,LAN_ADVANCED); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. + + // protected $listQry = "SELECT * FROM `#tableName` WHERE field != '' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. + + protected $listOrder = 'gsitemap_id DESC'; + + protected $fields = array ( + 'checkboxes' => array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => true, 'class' => 'center', 'toggle' => 'e-multiselect', 'readParms' => array (), 'writeParms' => array (),), + 'gsitemap_id' => array ( 'title' => LAN_ID, 'type'=>'number', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_name' => array ( 'title' => LAN_TITLE, 'type' => 'text', 'data' => 'safestr', 'width' => 'auto', 'inline' => true, 'help' => '', 'readParms' => array (), 'writeParms' => array ('size'=>'xxlarge'), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_url' => array ( 'title' => LAN_URL, 'type' => 'url', 'data' => 'safestr', 'width' => 'auto', 'inline' => true, 'help' => '', 'readParms' => array (), 'writeParms' => array ('size'=>'xxlarge'), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_table' => array ( 'title' => 'Table', 'tab'=>1, 'type' => 'text', 'data' => 'safestr', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left', 'batch' => false,), + 'gsitemap_table_id' => array ( 'title' => LAN_ID, 'tab'=>1,'type' => 'number', 'data' => 'int', 'width' => '5%', 'readonly' => false, 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_lastmod' => array ( 'title' => GSLAN_27, 'tab'=>1, 'type' => 'datestamp', 'readonly'=>2, 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left', 'filter' => false, 'batch' => false,), + 'gsitemap_freq' => array ( 'title' => GSLAN_28, 'type' => 'dropdown', 'data' => 'safestr', 'width' => 'auto', 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left', 'filter' => false, 'batch' => false,), + 'gsitemap_priority' => array ( 'title' => 'Priority', 'type' => 'method', 'data' => 'safestr', 'width' => 'auto', 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left', 'filter' => false, 'batch' => false,), + 'gsitemap_cat' => array ( 'title' => LAN_CATEGORY, 'tab'=>1, 'type' => 'text', 'data' => 'safestr', 'width' => 'auto', 'batch' => true, 'filter' => true, 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_order' => array ( 'title' => LAN_ORDER, 'type' => 'number', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_img' => array ( 'title' => LAN_IMAGE, 'type' => 'image', 'data' => 'safestr', 'width' => 'auto', 'help' => '', 'readParms' => 'thumb=80x80', 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',), + 'gsitemap_active' => array ( 'title' => LAN_VISIBILITY, 'type' => 'userclass', 'data' => 'int', 'width' => 'auto', 'filter' => true, 'help' => '', 'readParms' => array (), 'writeParms' => array (), 'class' => 'left', 'thclass' => 'left',), + 'options' => array ( 'title' => LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => true, 'readParms' => array (), 'writeParms' => array (),), + ); + + protected $fieldpref = array('gsitemap_name','gsitemap_url','gsitemap_lastmod','gsitemap_freq','gsitemap_priority'); + + + // protected $preftabs = array('General', 'Other' ); + protected $prefs = array( + ); + + protected $freqList = array + ( + "always" => GSLAN_11, + "hourly" => GSLAN_12, + "daily" => GSLAN_13, + "weekly" => GSLAN_14, + "monthly" => GSLAN_15, + "yearly" => GSLAN_16, + "never" => LAN_NEVER + ); + + + public function init() + { + // This code may be removed once plugin development is complete. + if(!e107::isInstalled('gsitemap')) + { + e107::getMessage()->addWarning("This plugin is not yet installed. Saving and loading of preference or table data will fail."); + } + + // Set drop-down values (if any). + $this->fields['gsitemap_table']['writeParms']['optArray'] = array('gsitemap_table_0','gsitemap_table_1', 'gsitemap_table_2'); // Example Drop-down array. + $this->fields['gsitemap_cat']['writeParms']['optArray'] = array('gsitemap_cat_0','gsitemap_cat_1', 'gsitemap_cat_2'); // Example Drop-down array. + $this->fields['gsitemap_freq']['writeParms']['optArray'] = $this->freqList; + + + + } + + /** + * @return array + */ + + // ------- Customize Create -------- + + public function beforeCreate($new_data,$old_data) + { + return $new_data; + } + + public function afterCreate($new_data, $old_data, $id) + { + // do something + } + + public function onCreateError($new_data, $old_data) + { + // do something + } + + + // ------- Customize Update -------- + + public function beforeUpdate($new_data, $old_data, $id) + { + return $new_data; + } + + public function afterUpdate($new_data, $old_data, $id) + { + // do something + } + + public function onUpdateError($new_data, $old_data, $id) + { + // do something + } + + // left-panel help menu area. (replaces e_help.php used in old plugins) + public function renderHelp() + { + $caption = LAN_HELP; + $text = 'Some help text'; + + return array('caption'=>$caption,'text'=> $text); + + } + + public function importPage() + { + global $PLUGINS_DIRECTORY; + + $ns = e107::getRender(); + $sql = e107::getDb(); + //$sql2 = e107::getDb('sql2'); not used? + $frm = e107::getForm(); + $mes = e107::getMessage(); + + $existing = array(); + $sql->select("gsitemap"); + while($row = $sql->fetch()) + { + $existing[] = $row['gsitemap_name']; + } + + + $importArray = array(); + + /* sitelinks ... */ + $sql->select("links", "*", "ORDER BY link_order ASC", "no-where"); + $nfArray = $sql->db_getList(); + foreach($nfArray as $row) + { + if(!in_array($row['link_name'], $existing)) + { + $importArray[] = array( + 'table' => 'links', + 'id' => $row['link_id'], + 'name' => $row['link_name'], + 'url' => $row['link_url'], + 'type' => GSLAN_1); + } + } + + /* custom pages ... */ + $query = "SELECT p.page_id, p.page_title, p.page_sef, p.page_chapter, ch.chapter_sef as chapter_sef, b.chapter_sef as book_sef FROM #page as p + LEFT JOIN #page_chapters as ch ON p.page_chapter = ch.chapter_id + LEFT JOIN #page_chapters as b ON ch.chapter_parent = b.chapter_id + WHERE page_title !='' ORDER BY page_datestamp ASC"; + + $data = $sql->retrieve($query,true); + + foreach($data as $row) + { + if(!in_array($row['page_title'], $existing)) + { + $route = ($row['page_chapter'] == 0) ? "page/view/other" : "page/view/index"; + + $importArray[] = array( + 'table' => 'page', + 'id' => $row['page_id'], + 'name' => $row['page_title'], + 'url' => e107::getUrl()->create($route, $row, array('full'=>1, 'allow' => 'page_sef,page_title,page_id, chapter_sef, book_sef')), + 'type' => "Page" + ); + } + } + + + + /* Plugins.. - currently: forums ... */ + $addons = e107::getAddonConfig('e_gsitemap', null, 'import'); + + foreach($addons as $plug => $config) + { + + foreach($config as $row) + { + if(!in_array($row['name'], $existing)) + { + $importArray[] = $row; + } + } + + } + + $editArray = $_POST; + + $text = " +
+ + + + + + + + + + + + + + + + + "; + + foreach($importArray as $k=>$ia) + { + $id = 'gs-'.$k; + $text .= " + + + + + + + "; + } + + $text .= " + + + + +
".GSLAN_2."".LAN_TYPE."".LAN_NAME."".LAN_URL."
".$ia['name']."".str_replace(SITEURL,"",$ia['url'])."
+
".GSLAN_8."   ".GSLAN_9." :    ".GSLAN_10." + + + +

+ +
+ +
+
+ ". + $frm->admin_button('import_links',GSLAN_18)." +
+
+ "; + + return $text; + // return $ns->tablerender(GSLAN_7, $mes->render(). $text, 'default', true); + + unset($PLUGINS_DIRECTORY); + + } + + + public function instructionsPage() + { + $mes = e107::getMessage(); + $ns = e107::getRender(); + + + $LINK_1 = "https://www.google.com/accounts/ServiceLogin?service=sitemaps"; + $LINK_2 = "http://www.google.com/support/webmasters/?hl=en"; + + $srch[0] = "[URL]"; + $repl[0] = "".$LINK_1.""; + + $srch[1] = "[URL2]"; + $repl[1] = "
".SITEURL."gsitemap.php
"; + + $srch[2] = "["; + $repl[2] = ""; + + $srch[3] = "]"; + $repl[3] = ""; + + // $text = "".GSLAN_33."

"; +$text = " +