1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Allow Sitelinks to be switched between auto-generated SEF Urls and regular URLs. Requires link_owner (plugin directory) field value with corresponding e_url.php configuration.

This commit is contained in:
Cameron 2015-03-31 10:21:50 -07:00
parent afb8d290e5
commit 20f2b552da
16 changed files with 218 additions and 25 deletions

View File

@ -178,13 +178,13 @@ class eurl_admin_ui extends e_admin_controller_ui
{
$text .= "<h5>".$plug."</h5>";
$text .= "<table class='table table-striped table-bordered'>";
$text .= "<tr><th>Regular Expression</th>
$text .= "<tr><th>Key</th><th>Regular Expression</th>
<th>".LAN_URL."</th>
</tr>";
foreach($val as $k=>$v)
{
$text .= "<tr><td style='width:50%'>".$v['regex']."</td><td>".$v['redirect']."</td></tr>";
$text .= "<tr><td style='width:20%'>".$k."</td><td style='width:40%'>".$v['regex']."</td><td style='width:40%'>".$v['redirect']."</td></tr>";
}

View File

@ -84,8 +84,8 @@ class links_admin_ui extends e_admin_ui
'link_category' => array('title'=> LAN_TEMPLATE, 'type' => 'dropdown', 'inline'=>true, 'batch'=>true, 'filter'=>true, 'width' => 'auto'),
'link_parent' => array('title'=> 'Sublink of', 'type' => 'method', 'width' => 'auto', 'batch'=>true, 'filter'=>true, 'thclass' => 'left first'),
'link_url' => array('title'=> LAN_URL, 'width'=>'auto', 'type'=>'url', 'inline'=>true, 'required'=>true,'validate' => true, 'writeParms'=>'size=xxlarge'),
// 'link_sefurl' => array('title'=> LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'width' => 'auto'),
'link_url' => array('title'=> LAN_URL, 'width'=>'auto', 'type'=>'method', 'inline'=>true, 'required'=>true,'validate' => true, 'writeParms'=>'size=xxlarge'),
'link_sefurl' => array('title'=> LAN_SEFURL, 'type' => 'method', 'inline'=>false, 'width' => 'auto', 'help'=>'Enable to override URL with a dynamically created Search-Engine-Friendly URL'), //TODO LAN
'link_class' => array('title'=> LAN_USERCLASS, 'type' => 'userclass','inline'=>true, 'writeParms' => 'classlist=public,guest,nobody,member,classes,admin,main', 'batch'=>true, 'filter'=>true, 'width' => 'auto'),
'link_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'width' => 'auto'), // 'method'=>'tinymce_plugins', ?
'link_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'width' => 'auto', 'nolist'=>false, 'inline' => true),
@ -634,8 +634,88 @@ class links_admin_form_ui extends e_admin_form_ui
return $this->linkFunctions;
}
}
function link_sefurl($curVal,$mode)
{
if($mode == 'read')
{
return $curVal; // $this->linkFunctions[$curVal];
}
if($mode == 'write')
{
$plugin = $this->getController()->getModel()->get('link_owner');
$obj = e107::getAddon($plugin,'e_url');
$config = e107::callMethod($obj,'config');
$opts = array();
if(empty($config))
{
return $this->hidden('link_sefurl','')."<span class='label label-warning'>Not available</span>"; //TODO Generic LAN
}
foreach($config as $k=>$v)
{
if(strpos($v['regex'],')')===false) // only provide urls without dynamic elements.
{
$opts[] = $k;
}
}
return $this->select('link_sefurl', $opts, $curVal, array('useValues'=>true,'defaultValue'=>'','default'=>'('.LAN_DISABLED.')'));
}
}
function link_url($curVal,$mode)
{
if($mode == 'read')
{
$owner = $this->getController()->getListModel()->get('link_owner');
$sef = $this->getController()->getListModel()->get('link_sefurl');
if(!empty($owner) && !empty($sef))
{
$curVal = str_replace(e_HTTP,'',e107::url($owner,$sef));
}
return $curVal; // $this->linkFunctions[$curVal];
}
if($mode == 'write')
{
$owner = $this->getController()->getModel()->get('link_owner');
$sef = $this->getController()->getModel()->get('link_sefurl');
if(!empty($owner) && !empty($sef))
{
$text = str_replace(e_HTTP,'',e107::url($owner,$sef)); // dynamically created.
$text .= $this->hidden('link_url',$curVal);
$text .= " <span class='label label-warning'>Auto-generated</span>";
return $text;
}
return $this->text('link_url', $curVal, 255, array('size'=>'xxlarge'));
}
if($mode == 'inline')
{
$sef = $this->getController()->getListModel()->get('link_sefurl');
if(empty($sef))
{
return array('inlineType'=>'text');
}
return false;
}
}
/**
*

View File

@ -2647,6 +2647,8 @@ class e107
}
e107::getMessage()->addDebug("e_url.php in <b>".e_PLUGIN.$plugin."</b> is missing the key: <b>".$key."</b>. Or, you may need to <a href='".e_ADMIN."db.php?mode=plugin_scan'>scan your plugin directories</a> to register e_url.php");
return false;
/*

View File

@ -3448,7 +3448,14 @@ class e_form
$mode = preg_replace('/[^\w]/', '', vartrue($_GET['mode'], ''));
$methodParms = call_user_func_array(array($this, $method), array($value, 'inline', $parms));
if(!empty($methodParms['inlineType']))
{
$attributes['inline'] = $methodParms['inlineType'];
$methodParms = (!empty($methodParms['inlineData'])) ? $methodParms['inlineData'] : null;
}
if(is_string($attributes['inline'])) // text, textarea, select, checklist.
{
switch ($attributes['inline'])
@ -3459,6 +3466,7 @@ class e_form
break;
case 'select':
case 'dropdown':
$xtype = 'select';
break;
@ -3473,14 +3481,14 @@ class e_form
break;
}
}
if(!empty($xtype))
{
$value = $this->renderInline($field, $id, $attributes['title'], $_value, $value, $xtype, $methodParms);
}
$value = $this->renderInline($field, $id, $attributes['title'], $_value, $value, $xtype, $methodParms);
// $source = str_replace('"',"'",json_encode($methodParms, JSON_FORCE_OBJECT));
// $value = "<a class='e-tip e-editable editable-click' data-type='select' data-value='".$_value."' data-name='".$field."' data-source=\"".$source."\" title=\"".LAN_EDIT." ".$attributes['title']."\" data-pk='".$id."' data-url='".e_SELF."?mode=&amp;action=inline&amp;id={$id}&amp;ajax_used=1' href='#'>".$value."</a>";
}
break;

View File

@ -30,9 +30,9 @@ class sitelinks
{
while ($row = $sql->fetch())
{
if($row['link_sefurl'])
if(!empty($row['link_sefurl']) && !empty($row['link_owner']))
{
$this->sefList[$row['link_sefurl']] = $row['link_url'];
$this->sefList[$row['link_sefurl']] = e107::url($row['link_owner'],$row['link_url']);
}
// if (substr($row['link_name'], 0, 8) == 'submenu.'){
@ -1704,6 +1704,11 @@ class navigation_shortcodes extends e_shortcode
function sc_link_url($parm='')
{
$tp = e107::getParser();
if(!empty($this->var['link_owner']) && !empty($this->var['link_sefurl']))
{
return e107::url($this->var['link_owner'],$this->var['link_sefurl']);
}
if(strpos($this->var['link_url'], e_HTTP) === 0)
{

View File

@ -14,7 +14,7 @@
<link url="admin_config.php?mode=options" description="Configure Blank Prefs" icon="manage" >Blank Prefs</link>
</adminLinks>
<siteLinks>
<link url="{e_PLUGIN}_blank/_blank.php" perm='everyone' sef='blank-plugin'>LAN_PLUGIN__BLANK_LINK</link>
<link url="{e_PLUGIN}_blank/_blank.php" perm='everyone' sef='index'>LAN_PLUGIN__BLANK_LINK</link>
</siteLinks>
<pluginPrefs>
<pref name="blank_pref_1">1</pref>

View File

@ -15,7 +15,7 @@
<link url="admin_config.php" description="Configure FAQs" icon="images/icon_32.png" iconSmall="images/icon_16.png" primary="true" >LAN_PLUGIN_FAQS_NAME</link>
</adminLinks>
<siteLinks>
<link url="{e_PLUGIN}faqs/faqs.php" description="FAQs" icon="images/icon_32.png" iconSmall="images/icon_16.png" function="faqCategories">LAN_PLUGIN_FAQS_NAME</link>
<link url="{e_PLUGIN}faqs/faqs.php" sef='index' description="FAQs" icon="images/icon_32.png" iconSmall="images/icon_16.png" >LAN_PLUGIN_FAQS_NAME</link>
</siteLinks>
<pluginPrefs>
<pref name="add_faq">255</pref>

View File

@ -0,0 +1,54 @@
<?php
/*
* e107 Bootstrap CMS
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* IMPORTANT: Make sure the redirect script uses the following code to load class2.php:
*
* if (!defined('e107_INIT'))
* {
* require_once("../../class2.php");
* }
*
*/
if (!defined('e107_INIT')) { exit; }
// v2.x Standard - Simple mod-rewrite module.
class forum_url // plugin-folder + '_url'
{
function config()
{
$config = array();
$config['index'] = array(
'regex' => '^forum/?$', // matched against url, and if true, redirected to 'redirect' below.
'sef' => 'forum', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}forum/forum.php', // file-path of what to load when the regex returns true.
);
$config['topic'] = array(
'regex' => '^forum/(.*)/(.*)$',
'sef' => 'forum/{forum_sef}/{topic_sef}',
'redirect' => '{e_PLUGIN}forum/forum_viewtopic.php?id=$1'
);
$config['forum'] = array(
'regex' => '^forum/(.*)$',
'sef' => 'forum/{forum_sef}',
'redirect' => '{e_PLUGIN}forum/forum_viewforum.php?id=$1'
);
return $config;
}
}

View File

@ -508,7 +508,7 @@ if (e_QUERY == 'new')
$frm = e107::getForm();
$breadarray = array(
array('text'=> $forum->prefs->get('title'), 'url' => e_REQUEST_URL )
array('text'=> $forum->prefs->get('title'), 'url' => e107::url('forum','index') )
);
$fVars->FORUM_BREADCRUMB = $frm->breadcrumb($breadarray);

View File

@ -1810,7 +1810,7 @@ class e107forum
$breadcrumb = array();
$breadcrumb[] = array('text'=> LAN_PLUGIN_FORUM_NAME , 'url'=> e107::getUrl()->create('forum/forum/main'));
$breadcrumb[] = array('text'=> LAN_PLUGIN_FORUM_NAME , 'url'=> e107::url('forum','index'));
if($forumInfo['sub_parent'])
{

View File

@ -11,7 +11,7 @@
<link url="forum_admin.php?opt" description="Forum Preferences" icon="settings" perm="mainadmin" >Preferences</link>
</adminLinks>
<siteLinks>
<link url="{e_PLUGIN}forum/forum.php" perm='everyone'>Forum</link>
<link url="{e_PLUGIN}forum/forum.php" sef='index' perm='everyone' lan='LAN_PLUGIN_FORUM_NAME'>Forum</link>
</siteLinks>
<pluginPrefs>
<pref name="show_topics">1</pref>

View File

@ -7,7 +7,7 @@
<link url='admin_gallery.php' description='LAN_CONFIGURE' icon='images/gallery_32.png' iconSmall='images/gallery_16.png' primary='true' >LAN_CONFIGURE</link>
</adminLinks>
<siteLinks>
<link url="{e_PLUGIN}gallery/gallery.php" sef="gallery" perm="everyone" >LAN_PLUGIN_GALLERY_TITLE</link>
<link url="{e_PLUGIN}gallery/gallery.php" sef="index" perm="everyone" >LAN_PLUGIN_GALLERY_TITLE</link>
</siteLinks>
<mainPrefs>
</mainPrefs>

View File

@ -7,7 +7,7 @@
<link url='admin_config.php' description='Configure gSitemap' icon='images/icon.png' iconSmall='images/icon_16.png' primary='true' >LAN_CONFIGURE</link>
</adminLinks>
<siteLinks>
<link name="" url="gsitemap.php?show" sef="sitemap" lan="GSLAN_Name">Sitemap</link>
<link name="" url="gsitemap.php?show" sef="index" lan="GSLAN_Name">Sitemap</link>
</siteLinks>
<pluginPrefs>
</pluginPrefs>

View File

@ -0,0 +1,40 @@
<?php
/*
* e107 Bootstrap CMS
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* IMPORTANT: Make sure the redirect script uses the following code to load class2.php:
*
* if (!defined('e107_INIT'))
* {
* require_once("../../class2.php");
* }
*
*/
if (!defined('e107_INIT')) { exit; }
// v2.x Standard - Simple mod-rewrite module.
class log_url // plugin-folder + '_url'
{
function config()
{
$config = array();
$config['index'] = array(
'regex' => '^stats/?$', // matched against url, and if true, redirected to 'redirect' below.
'sef' => 'stats', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}log/stats.php?1', // file-path of what to load when the regex returns true.
);
return $config;
}
}

View File

@ -6,7 +6,7 @@
<link url='admin_config.php' description='ADSTAT_L33' icon='images/stats_32.png' iconSmall='images/stats_16.png' primary='true' >LAN_PLUGIN_LOG_CONFIGURE</link>
</adminLinks>
<siteLinks>
<link url="{e_PLUGIN}log/stats.php?1" >LAN_PLUGIN_LOG_LINK</link>
<link url="{e_PLUGIN}log/stats.php?1" sef='index' >LAN_PLUGIN_LOG_LINK</link>
</siteLinks>
<mainPrefs>
<pref name="statActivate">0</pref>

View File

@ -9,14 +9,18 @@
*/
require_once('../../class2.php');
if (!defined('e107_INIT'))
{
require_once("../../class2.php");
}
if (!e107::isInstalled('log'))
{
header('Location: '.e_BASE.'index.php');
exit;
}
include_lan(e_PLUGIN.'log/languages/'.e_LANGUAGE.'.php');
e107::includeLan(e_PLUGIN.'log/languages/'.e_LANGUAGE.'.php');
$bar = (file_exists(THEME.'images/bar.png') ? THEME_ABS.'images/bar.png' : e_IMAGE_ABS.'generic/bar.png');
$mes = e107::getMessage();