From 6baeb189c54acc4b300b36efc927fef3ba955c89 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 22 Nov 2013 20:46:45 -0800 Subject: [PATCH] Added Rebuild option for SEF Urls. --- e107_admin/eurl.php | 116 ++++++++++++++++++++++++++++----- e107_core/url/news/sef_url.php | 1 + e107_core/url/page/sef_url.php | 1 + 3 files changed, 103 insertions(+), 15 deletions(-) diff --git a/e107_admin/eurl.php b/e107_admin/eurl.php index cf4f8be0d..2c99eddd7 100644 --- a/e107_admin/eurl.php +++ b/e107_admin/eurl.php @@ -62,14 +62,80 @@ class eurl_admin_ui extends e_admin_controller_ui public function init() { + + if(is_array($_POST['rebuild'])) + { + $table = key($_POST['rebuild']); + list($primary, $input, $output) = explode("::",$_POST['rebuild'][$table]); + $this->rebuild($table, $primary, $input, $output); + } + + $this->api = e107::getInstance(); $this->addTitle(LAN_EURL_NAME); if($this->getAction() != 'settings') return; + + } + /** + * Rebuild SEF Urls for a particular table + * @param $table + * @param primary field id. + * @param input field (title) + * @param output field (sef) + */ + private function rebuild($table, $primary, $input,$output) + { + if(empty($table) || empty($input) || empty($output) || empty($primary)) + { + e107::getMessage()->addError("Missing Generator data"); + return; + } + + $sql = e107::getDb(); + + $data = $sql->retrieve($table, $primary.",".$input, $input ." != '' ", true); + + $success = 0; + $failed = 0; + + foreach($data as $row) + { + $sef = eHelper::title2sef($row[$input]); + + if($sql->update($table, $output ." = '".$sef."' WHERE ".$primary. " = ".intval($row[$primary]). " LIMIT 1")!==false) + { + $success++; + } + else + { + $failed++; + } + + // echo $row[$input]." => ".$output ." = '".$sef."' WHERE ".$primary. " = ".intval($row[$primary]). " LIMIT 1
"; + + } + + if($success) + { + e107::getMessage()->addSuccess($success." SEF URLs were updated."); + } + + if($failed) + { + e107::getMessage()->addError($failed." SEF URLs were NOT updated."); + } + + + } + + + + public function HelpObserver() { @@ -231,15 +297,15 @@ class eurl_admin_ui extends e_admin_controller_ui ".LAN_EURL_LEGEND_CONFIG." - - - + + + - + @@ -429,6 +495,8 @@ class eurl_admin_form_ui extends e_admin_form_ui { $text = ''; $tp = e107::getParser(); + $frm = e107::getForm(); + if(empty($data)) { return " @@ -444,10 +512,11 @@ class eurl_admin_form_ui extends e_admin_form_ui foreach ($data as $obj) { - $admin = $obj->config->admin(); - $section = vartrue($admin['labels'], array()); - $rowspan = count($obj->locations)+1; - $module = $obj->module; + $admin = $obj->config->admin(); + $section = vartrue($admin['labels'], array()); + $rowspan = count($obj->locations)+1; + $module = $obj->module; + $generate = vartrue($admin['generate'], array()); /* $info .= " @@ -505,24 +574,41 @@ class eurl_admin_form_ui extends e_admin_form_ui } $selected = varset($obj->current[$module]) == $location ? "selected='selected'" : ''; - $opt .= ""; - + $opt .= ""; + $info .= " - +

".vartrue($section['description'], LAN_EURL_PROFILE_INFO)."

".implode("
", $exampleUrl)."
+ + + + "; } + $info .= "
".LAN_TYPE." ".LAN_URL."".LAN_OPTIONS."
".$label." ".LAN_EURL_LOCATION.": ".$path." -

".vartrue($section['description'], LAN_EURL_PROFILE_INFO)."

".implode("
", $exampleUrl)."
"; + + $title = vartrue($section['name'], eHelper::labelize($obj->module)); - $title = vartrue($section['name'], eHelper::labelize($obj->module)); - $text .= " + $text .= " ".$this->moreInfo($title, $info)." - + + "; + + $bTable = ($admin['generate']['table']); + $bInput = $admin['generate']['input']; + $bOutput = $admin['generate']['output']; + $bPrimary = $admin['generate']['primary']; + + + $text .= (is_array($admin['generate'])) ? $frm->admin_button('rebuild['.$bTable.']', $bPrimary."::".$bInput."::".$bOutput,'delete',"Rebuild") : ""; + + + $text .= " "; } diff --git a/e107_core/url/news/sef_url.php b/e107_core/url/news/sef_url.php index 0e82ee9a7..3e829f48c 100644 --- a/e107_core/url/news/sef_url.php +++ b/e107_core/url/news/sef_url.php @@ -139,6 +139,7 @@ class core_news_sef_url extends eUrlConfig 'description' => LAN_EURL_NEWS_REWRITEX_DESCR, // 'examples' => array('{SITEURL}news/1/news-title') ), + 'generate' => array('table'=> 'news', 'primary'=>'news_id', 'input'=>'news_title', 'output'=>'news_sef'), 'form' => array(), // Under construction - additional configuration options 'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity ); diff --git a/e107_core/url/page/sef_url.php b/e107_core/url/page/sef_url.php index f6d8d7019..52d433d08 100644 --- a/e107_core/url/page/sef_url.php +++ b/e107_core/url/page/sef_url.php @@ -54,6 +54,7 @@ class core_page_sef_url extends eUrlConfig 'description' => LAN_EURL_PAGE_SEF_DESCR, // 'examples' => array("{SITEURL}page/1/page-name") ), + 'generate' => array('table'=> 'page', 'primary'=>'page_id', 'input'=>'page_title', 'output'=>'page_sef'), 'form' => array(), // Under construction - additional configuration options 'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity );