From b664a751a4448140e903a0222381dc94a8705188 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 14 Apr 2017 11:55:41 -0700 Subject: [PATCH] SEF URL generation support in e_url.php --- e107_admin/eurl.php | 42 ++++++++++++++++++++--- e107_handlers/e107_class.php | 10 ++++++ e107_languages/English/admin/lan_eurl.php | 1 + e107_plugins/download/e_url.php | 8 ++++- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/e107_admin/eurl.php b/e107_admin/eurl.php index fd87ffec7..b2940820b 100644 --- a/e107_admin/eurl.php +++ b/e107_admin/eurl.php @@ -125,6 +125,10 @@ class eurl_admin_ui extends e_admin_controller_ui list($primary, $input, $output) = explode("::",$_POST['rebuild'][$table]); $this->rebuild($table, $primary, $input, $output); } + + + + $this->api = e107::getInstance(); @@ -144,7 +148,7 @@ class eurl_admin_ui extends e_admin_controller_ui * @param input field (title) * @param output field (sef) */ - private function rebuild($table, $primary, $input,$output) + private function rebuild($table, $primary='', $input='',$output='') { if(empty($table) || empty($input) || empty($output) || empty($primary)) { @@ -178,12 +182,12 @@ class eurl_admin_ui extends e_admin_controller_ui if($success) { - e107::getMessage()->addSuccess($success. LAN_EURL_SURL_UPD); + e107::getMessage()->addSuccess(LAN_EURL_TABLE.": ".$table."
".$success. LAN_EURL_SURL_UPD); } if($failed) { - e107::getMessage()->addError($failed. LAN_EURL_SURL_NUPD); + e107::getMessage()->addError(LAN_EURL_TABLE.": ".$table."
".$failed. LAN_EURL_SURL_NUPD); } @@ -432,6 +436,28 @@ class eurl_admin_ui extends e_admin_controller_ui public function ConfigObserver() { + + if(!empty($_POST['generate'])) + { + $gen = e107::getUrlConfig('generate'); + $id = key($_POST['generate']); + + if(empty($gen[$id])) + { + e107::getMessage()->addDebug("Empty"); + return null; + } + + foreach($gen[$id] as $conf) + { + $this->rebuild($conf['table'], $conf['primary'], $conf['input'], $conf['output']); + } + + } + + + + if(isset($_POST['update'])) { $config = is_array($_POST['eurl_config']) ? e107::getParser()->post_toForm($_POST['eurl_config']) : ''; @@ -527,6 +553,7 @@ class eurl_admin_ui extends e_admin_controller_ui $repl = array(SITEURL,SITEURL.$PLUGINS_DIRECTORY); $profiles = e107::getUrlConfig('profiles'); + $generate = e107::getUrlConfig('generate'); $form = $this->getUI(); @@ -548,7 +575,14 @@ class eurl_admin_ui extends e_admin_controller_ui $label = e107::getPlugLan($plug,'name'); - $text .= "".$label."".$selector.""; + $text .= "".$label."".$selector.""; + + + + + $text .= (!empty($generate[$plug])) ? $form->admin_button('generate['.$plug.']', $plug,'delete', LAN_EURL_REBUILD) : ""; + + $text .= ""; } diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index b2b490379..7673ce281 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -2489,6 +2489,16 @@ class e107 continue; } + if($mode === 'generate') + { + if(!empty($obj->generate)) + { + $new_addon[$key] = $obj->generate; + } + + continue; + } + $profile = !empty($url_profiles[$key]) ? $url_profiles[$key] : null; $array = self::callMethod($obj, $methodName,$profile); diff --git a/e107_languages/English/admin/lan_eurl.php b/e107_languages/English/admin/lan_eurl.php index 49daa02f4..4659291fb 100644 --- a/e107_languages/English/admin/lan_eurl.php +++ b/e107_languages/English/admin/lan_eurl.php @@ -133,3 +133,4 @@ define("LAN_EURL_CORE_INDEX_INFO", "Front Page can't have an alias."); define("LAN_EURL_REBUILD", "Rebuild"); define("LAN_EURL_REGULAR_EXPRESSION", "Regular Expression"); define("LAN_EURL_KEY", "Key"); +define("LAN_EURL_TABLE", "Table"); diff --git a/e107_plugins/download/e_url.php b/e107_plugins/download/e_url.php index 21daefdd2..cf9ef3de3 100644 --- a/e107_plugins/download/e_url.php +++ b/e107_plugins/download/e_url.php @@ -33,6 +33,12 @@ class download_url // plugin-folder + '_url' 'non-numeric' => array('label' => 'Friendly (experimental)', 'examples' => array('{SITEURL}download/my-category/my-sub-category/my-file-name')), ); + // Batch generate SEF URls on tables. + public $generate = array( + 0 => array('table'=> 'download', 'primary'=>'download_id', 'input'=>'download_name', 'output'=>'download_sef'), + 1 => array('table'=> 'download_category', 'primary'=>'download_category_id', 'input'=>'download_category_name', 'output'=>'download_category_sef') + ); + function config($profile=null) { @@ -67,7 +73,7 @@ class download_url // plugin-folder + '_url' $config['category'] = array( - 'regex' => '^{alias}/category/([\d]*)/(.*)$', + 'regex' => '^{alias}/([^\/]*)/(.*)$', 'redirect' => '{e_PLUGIN}download/download.php?action=list&id=$1', 'sef' => '{alias}/{download_category_sef}', );