1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 14:17:49 +02: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:
Cameron
2021-01-19 07:54:13 -08:00
parent 23d438a68b
commit 76144e6b4f
6 changed files with 79 additions and 13 deletions

View File

@@ -27,7 +27,7 @@ $sec_img = new secure_image;
e107::lan('core','contact'); e107::lan('core','contact');
define('PAGE_NAME', LANCONTACT_00); define('PAGE_NAME', LANCONTACT_00);
e107::canonical('contact');
require_once(HEADERF); require_once(HEADERF);
$tp = e107::getParser(); $tp = e107::getParser();

View File

@@ -775,11 +775,11 @@ class e107
/** /**
* Get folder name (e107_config) * Get folder name (e107_config)
* Replaces all $(*)_DIRECTORY globals * Replaces all $(*)_DIRECTORY globals.
* @example * @example
* Example: <code>$e107->getFolder('images')</code>; * Example: <code>$e107->getFolder('images')</code>;
* *
* @param string $for admin | plugin | * @param string $for admin | plugins | themes | files | handlers
* @return string * @return string
*/ */
public static function getFolder($for) public static function getFolder($for)
@@ -3769,6 +3769,24 @@ class e107
return null; 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 * 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 (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); return self::getUrl()->create($plugin, $key, $row);
} }

View File

@@ -13,11 +13,6 @@
if (!defined('e107_INIT')) { exit; } 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));
}

View File

@@ -348,6 +348,11 @@ class news_front
$newsRoute = 'list/'.$this->action; $newsRoute = 'list/'.$this->action;
break; break;
case 'item':
case 'extend':
$newsRoute = 'view/item';
break;
default: default:
$newsRoute = 'list/items'; $newsRoute = 'list/items';
break; 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') private function setNewsFrontMeta($news, $type='news')
{ {
@@ -545,6 +553,7 @@ class news_front
case "all": case "all":
e107::meta('robots', 'noindex'); e107::meta('robots', 'noindex');
break; break;
case "tag": case "tag":
@@ -590,12 +599,13 @@ class news_front
break; break;
case "news": case "news":
e107::canonical($this->route, $news);
break; break;
default: default:
e107::meta('robots', 'noindex'); e107::meta('robots', 'noindex');
// e107::canonical('news');
} }

View File

@@ -972,16 +972,41 @@ class e107Test extends \Codeception\Test\Unit
$obj = $this->e107; $obj = $this->e107;
// Test FULL url option on Legacy url with new options['mode']
$tests = array( $tests = array(
0 => array( 0 => array(
'plugin' => 'news', 'plugin' => 'news/view/item',
'key' => 'index', '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' => '', 'row' => '',
'options' => ['mode' => 'full'], '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(); $tests = array();

View File

@@ -25,6 +25,8 @@ e107::lan('gsitemap');
if(e_QUERY == "show" || !empty($_GET['show'])) if(e_QUERY == "show" || !empty($_GET['show']))
{ {
e107::canonical('gsitemap');
require_once(HEADERF); require_once(HEADERF);
$nfArray = $sql ->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true); $nfArray = $sql ->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);