mirror of
https://github.com/e107inc/e107.git
synced 2025-03-14 01:19:44 +01:00
Issue #4352 e107::canonical() method added.
Use define('e_DEBUG_CANONICAL', true); in e107_config.php to test usage.
This commit is contained in:
parent
23d438a68b
commit
76144e6b4f
@ -27,7 +27,7 @@ $sec_img = new secure_image;
|
||||
e107::lan('core','contact');
|
||||
|
||||
define('PAGE_NAME', LANCONTACT_00);
|
||||
|
||||
e107::canonical('contact');
|
||||
require_once(HEADERF);
|
||||
|
||||
$tp = e107::getParser();
|
||||
|
@ -775,11 +775,11 @@ class e107
|
||||
|
||||
/**
|
||||
* Get folder name (e107_config)
|
||||
* Replaces all $(*)_DIRECTORY globals
|
||||
* Replaces all $(*)_DIRECTORY globals.
|
||||
* @example
|
||||
* Example: <code>$e107->getFolder('images')</code>;
|
||||
*
|
||||
* @param string $for admin | plugin |
|
||||
* @param string $for admin | plugins | themes | files | handlers
|
||||
* @return string
|
||||
*/
|
||||
public static function getFolder($for)
|
||||
@ -3769,6 +3769,24 @@ class e107
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick method to set alias - uses e107::url format.
|
||||
* @param string $plugin
|
||||
* @param null $key
|
||||
* @param array $row
|
||||
*/
|
||||
public static function canonical($plugin = '', $key = 'index', $row = array())
|
||||
{
|
||||
if($url = e107::url($plugin, $key, $row, array('mode' => 'full')))
|
||||
{
|
||||
self::getJs()->addLink(array('rel'=>"canonical", "href" => $url));
|
||||
}
|
||||
if(deftrue('e_DEBUG_CANONICAL'))
|
||||
{
|
||||
self::getMessage()->addInfo("Debug Canonical URL: ".$url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a plugin's search engine-friendly URL with HTML special characters escaped
|
||||
*
|
||||
@ -3805,6 +3823,22 @@ class e107
|
||||
|
||||
if (in_array($tmp[0], $legacy))
|
||||
{
|
||||
if(isset($options['mode']) && $options['mode'] === 'full')
|
||||
{
|
||||
if(is_array($row))
|
||||
{
|
||||
$row['full'] = 1;
|
||||
}
|
||||
elseif(is_string($row))
|
||||
{
|
||||
$row .= '&full=1';
|
||||
}
|
||||
elseif(is_null($row))
|
||||
{
|
||||
$row = 'full=1';
|
||||
}
|
||||
}
|
||||
|
||||
return self::getUrl()->create($plugin, $key, $row);
|
||||
}
|
||||
|
||||
|
@ -13,11 +13,6 @@
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
if(deftrue('USER_AREA') && (defset('e_PAGE') === 'gsitemap.php'))
|
||||
{
|
||||
$canonicalurl = e107::url('gsitemap', 'index', null, array('mode' => 'full'));
|
||||
e107::link(array('rel'=>"canonical", "href" =>$canonicalurl));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -348,6 +348,11 @@ class news_front
|
||||
$newsRoute = 'list/'.$this->action;
|
||||
break;
|
||||
|
||||
case 'item':
|
||||
case 'extend':
|
||||
$newsRoute = 'view/item';
|
||||
break;
|
||||
|
||||
default:
|
||||
$newsRoute = 'list/items';
|
||||
break;
|
||||
@ -531,7 +536,10 @@ class news_front
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $news news and category table row. ie. news_id, news_title, news_sef ... category_id etc.
|
||||
* @param string $type
|
||||
*/
|
||||
private function setNewsFrontMeta($news, $type='news')
|
||||
{
|
||||
|
||||
@ -545,6 +553,7 @@ class news_front
|
||||
|
||||
case "all":
|
||||
e107::meta('robots', 'noindex');
|
||||
|
||||
break;
|
||||
|
||||
case "tag":
|
||||
@ -590,12 +599,13 @@ class news_front
|
||||
break;
|
||||
|
||||
case "news":
|
||||
|
||||
e107::canonical($this->route, $news);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
e107::meta('robots', 'noindex');
|
||||
// e107::canonical('news');
|
||||
}
|
||||
|
||||
|
||||
|
@ -972,16 +972,41 @@ class e107Test extends \Codeception\Test\Unit
|
||||
|
||||
$obj = $this->e107;
|
||||
|
||||
// Test FULL url option on Legacy url with new options['mode']
|
||||
$tests = array(
|
||||
0 => array(
|
||||
'plugin' => 'news',
|
||||
'key' => 'index',
|
||||
'plugin' => 'news/view/item',
|
||||
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
|
||||
'row' => array(),
|
||||
'options' => ['mode' => 'full'],
|
||||
),
|
||||
1 => array(
|
||||
'plugin' => 'news/view/item',
|
||||
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
|
||||
'row' => 'full=1&encode=0',
|
||||
'options' => ['mode' => 'full'],
|
||||
),
|
||||
2 => array(
|
||||
'plugin' => 'news/view/item',
|
||||
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
|
||||
'row' => '',
|
||||
'options' => ['mode' => 'full'],
|
||||
'_expected_' => 'https://localhost/e107/news'
|
||||
),
|
||||
3 => array(
|
||||
'plugin' => 'news/view/item',
|
||||
'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'),
|
||||
'row' => null,
|
||||
'options' => ['mode' => 'full'],
|
||||
),
|
||||
|
||||
);
|
||||
foreach($tests as $v)
|
||||
{
|
||||
$result = $obj::url($v['plugin'], $v['key'], $v['row'], $v['options']);
|
||||
$this->assertStringContainsString('http', $result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$tests = array();
|
||||
|
||||
|
@ -25,6 +25,8 @@ e107::lan('gsitemap');
|
||||
|
||||
if(e_QUERY == "show" || !empty($_GET['show']))
|
||||
{
|
||||
e107::canonical('gsitemap');
|
||||
|
||||
require_once(HEADERF);
|
||||
|
||||
$nfArray = $sql ->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user