1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 14:17:49 +02:00

SEF URL generation support in e_url.php

This commit is contained in:
Cameron
2017-04-14 11:55:41 -07:00
parent 90d533ba52
commit b664a751a4
4 changed files with 56 additions and 5 deletions

View File

@@ -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.": <b>".$table."</b><br />".$success. LAN_EURL_SURL_UPD);
}
if($failed)
{
e107::getMessage()->addError($failed. LAN_EURL_SURL_NUPD);
e107::getMessage()->addError(LAN_EURL_TABLE.": <b>".$table."</b><br />".$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 .= "<tr><td>".$label."</td><td>".$selector."</td></tr>";
$text .= "<tr><td>".$label."</td><td>".$selector."</td><td>";
$text .= (!empty($generate[$plug])) ? $form->admin_button('generate['.$plug.']', $plug,'delete', LAN_EURL_REBUILD) : "";
$text .= "</td></tr>";
}

View File

@@ -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);

View File

@@ -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");

View File

@@ -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}',
);