mirror of
https://github.com/e107inc/e107.git
synced 2025-01-16 20:28:28 +01:00
Issue #4352 Added canonical for home page and frontpage setting.
This commit is contained in:
parent
f091709847
commit
e57b1a9b61
14
class2.php
14
class2.php
@ -1712,6 +1712,20 @@ if(!isset($_E107['no_online']))
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dbg->logTime('(After Go online)');
|
$dbg->logTime('(After Go online)');
|
||||||
|
$dbg->logTime('Frontpage detection');
|
||||||
|
|
||||||
|
$fpUrl = str_replace(SITEURL, '', rtrim(e_REQUEST_URL, '?/'));
|
||||||
|
$fpPref = e107::getFrontpage();
|
||||||
|
|
||||||
|
if($fpUrl === $fpPref)
|
||||||
|
{
|
||||||
|
e107::canonical('_SITEURL_');
|
||||||
|
}
|
||||||
|
unset($fpUrl, $fpPref);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Cookie
|
* Set Cookie
|
||||||
|
@ -32,7 +32,7 @@ $mes = e107::getMessage();
|
|||||||
$frontPref = e107::pref('core'); // Get prefs
|
$frontPref = e107::pref('core'); // Get prefs
|
||||||
|
|
||||||
// Get list of possible options for front page
|
// Get list of possible options for front page
|
||||||
|
$front_page = array();
|
||||||
// Welcome message is 'hardcoded' intentionally
|
// Welcome message is 'hardcoded' intentionally
|
||||||
$front_page['wmessage'] = array(
|
$front_page['wmessage'] = array(
|
||||||
'page' => 'index.php',
|
'page' => 'index.php',
|
||||||
@ -91,10 +91,10 @@ if(is_array($frontPref['frontpage']))
|
|||||||
$i = 1;
|
$i = 1;
|
||||||
foreach($frontPref['frontpage'] as $class => $val)
|
foreach($frontPref['frontpage'] as $class => $val)
|
||||||
{
|
{
|
||||||
if($class == 'all')
|
if($class == 'all' || $class === 0)
|
||||||
{
|
{
|
||||||
$class = e_UC_PUBLIC;
|
$class = e_UC_PUBLIC;
|
||||||
$gotpub = TRUE;
|
$gotpub = true;
|
||||||
}
|
}
|
||||||
if($val)
|
if($val)
|
||||||
{ // Only add non-null pages
|
{ // Only add non-null pages
|
||||||
|
@ -25,9 +25,8 @@ class core_index_index_controller extends eController
|
|||||||
* - http://NotMysite.com/someurl/ (redirect) - really not sure who'd need that...
|
* - http://NotMysite.com/someurl/ (redirect) - really not sure who'd need that...
|
||||||
* @throws eException
|
* @throws eException
|
||||||
*/
|
*/
|
||||||
public function actionIndex()
|
public function actionIndex($fpref =null) // used for testing.
|
||||||
{
|
{
|
||||||
$pref = eFront::app()->getPref();
|
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
$indexRoute = 'index/index/index';
|
$indexRoute = 'index/index/index';
|
||||||
|
|
||||||
@ -36,71 +35,17 @@ class core_index_index_controller extends eController
|
|||||||
include (e_BASE.'index_include.php');
|
include (e_BASE.'index_include.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
$location = '';
|
$location = e107::getFrontpage();
|
||||||
$class_list = explode(',', USERCLASS_LIST);
|
|
||||||
|
|
||||||
if (isset($pref['frontpage']['all']) && $pref['frontpage']['all'])
|
if($location === false)
|
||||||
{ // 0.7 method
|
|
||||||
$location = $pref['frontpage']['all'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // This is the 'new' method - assumes $pref['frontpage'] is an ordered list of rules
|
|
||||||
if(!empty($pref['frontpage']))
|
|
||||||
{
|
|
||||||
foreach ($pref['frontpage'] as $fk=>$fp)
|
|
||||||
{
|
|
||||||
if (in_array($fk, $class_list))
|
|
||||||
{
|
|
||||||
$location = $fp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$location)
|
|
||||||
{ // Try and use the 'old' method (this bit can go later)
|
|
||||||
if (ADMIN)
|
|
||||||
{
|
|
||||||
$location = $pref['frontpage'][e_UC_ADMIN];
|
|
||||||
}
|
|
||||||
elseif (USER)
|
|
||||||
{ // This is the key bit - what to do for a 'normal' logged in user
|
|
||||||
// We have USERCLASS_LIST - comma separated. Also e_CLASS_REGEXP
|
|
||||||
$inclass = false;
|
|
||||||
foreach ($class_list as $fp_class)
|
|
||||||
{
|
|
||||||
if (!$inclass && check_class($fp_class['userclass_id']))
|
|
||||||
{
|
|
||||||
$location = $pref['frontpage'][$fp_class['userclass_id']];
|
|
||||||
$inclass = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$location = $location ? $location : $pref['frontpage'][e_UC_MEMBER];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$location = $pref['frontpage'][e_UC_GUEST];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$location = trim($location);
|
|
||||||
$request = $this->getRequest();
|
|
||||||
|
|
||||||
// Defaults to news
|
|
||||||
if(!$location) $location = 'url:/news';
|
|
||||||
// Former Welcome Message front-page. Should be handled by current theme layout
|
|
||||||
elseif($location == 'index.php' || $location == 'url:/' || $location == 'route:/' || $location == '/')
|
|
||||||
{
|
{
|
||||||
define('e_FRONTPAGE', true);
|
define('e_FRONTPAGE', true);
|
||||||
$this->_forward('front');
|
$this->_forward('front');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
elseif($location[0] === '{')
|
|
||||||
{
|
|
||||||
$location = $tp->replaceConstants($location, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$request = $this->getRequest();
|
||||||
// new url format; if set to 'url:' only it'll resolve current main module (if any)
|
// new url format; if set to 'url:' only it'll resolve current main module (if any)
|
||||||
if(strpos($location, 'url:') === 0)
|
if(strpos($location, 'url:') === 0)
|
||||||
{
|
{
|
||||||
@ -153,13 +98,16 @@ class core_index_index_controller extends eController
|
|||||||
elseif(strpos($location, '.php') !== false)
|
elseif(strpos($location, '.php') !== false)
|
||||||
{
|
{
|
||||||
list($page, $qstr) = explode("?", $location."?");
|
list($page, $qstr) = explode("?", $location."?");
|
||||||
|
|
||||||
$request->setLegacyPage($page)
|
$request->setLegacyPage($page)
|
||||||
->setLegacyQstring($qstr);
|
->setLegacyQstring($qstr);
|
||||||
|
|
||||||
$request->routed = true;
|
$request->routed = true;
|
||||||
define('e_FRONTPAGE', true);
|
define('e_FRONTPAGE', true);
|
||||||
|
define('e_URL_LEGACY', $location);
|
||||||
|
|
||||||
eFront::isLegacy('{e_BASE}'.$page);
|
eFront::isLegacy('{e_BASE}'.$page);
|
||||||
|
e107::canonical('_SITEURL_');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Redirect
|
// Redirect
|
||||||
@ -183,4 +131,5 @@ class core_index_index_controller extends eController
|
|||||||
// switch off tablerender
|
// switch off tablerender
|
||||||
$this->getResponse()->setParam('render', false);
|
$this->getResponse()->setParam('render', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ function wmessage_shortcode($parm='')
|
|||||||
// return;
|
// return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
$front_qry = '';
|
||||||
if ($parm != 'force')
|
if ($parm != 'force')
|
||||||
{
|
{
|
||||||
$full_url = 'news.php'; // Set a default in case
|
$full_url = 'news.php'; // Set a default in case
|
||||||
$front_qry = '';
|
|
||||||
$uc_array = explode(',', USERCLASS_LIST);
|
$uc_array = explode(',', USERCLASS_LIST);
|
||||||
if(varset($pref['frontpage']))
|
if(varset($pref['frontpage']))
|
||||||
{
|
{
|
||||||
@ -112,4 +112,3 @@ function wmessage_shortcode($parm='')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
@ -106,6 +106,12 @@ class e_url
|
|||||||
$pref = e107::getPref();
|
$pref = e107::getPref();
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
|
|
||||||
|
if(empty($this->_request)) // likely 'index.php' ie. the home page.
|
||||||
|
{
|
||||||
|
$this->_request = e107::getFrontPage();
|
||||||
|
e107::canonical('_SITEURL_');
|
||||||
|
}
|
||||||
|
|
||||||
if(empty($this->_config) || empty($this->_request) || $this->_request === 'index.php' || $this->isLegacy() === true)
|
if(empty($this->_config) || empty($this->_request) || $this->_request === 'index.php' || $this->isLegacy() === true)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -187,6 +193,18 @@ class e_url
|
|||||||
{
|
{
|
||||||
define('e_PAGE', basename($file));
|
define('e_PAGE', basename($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$fpUrl = str_replace(SITEURL, '', rtrim(e_REQUEST_URL, '?/'));
|
||||||
|
$fpPref = e107::getFrontpage();
|
||||||
|
|
||||||
|
if($fpUrl === $fpPref)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
unset($fpUrl, $fpPref);
|
||||||
|
|
||||||
|
|
||||||
$this->_include= $file;
|
$this->_include= $file;
|
||||||
return true;
|
return true;
|
||||||
// exit;
|
// exit;
|
||||||
@ -1255,6 +1273,7 @@ class eRouter
|
|||||||
{
|
{
|
||||||
$f = e107::getFile();
|
$f = e107::getFile();
|
||||||
$ret = array('core' => array(), 'plugin' => array(), 'override' => array());
|
$ret = array('core' => array(), 'plugin' => array(), 'override' => array());
|
||||||
|
$plugins = array();
|
||||||
|
|
||||||
if($type == 'all' || $type = 'core')
|
if($type == 'all' || $type = 'core')
|
||||||
{
|
{
|
||||||
|
@ -361,6 +361,83 @@ class e107
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the frontpage setting (ie. selected in e107_admin/frontpage.php) for the current user.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getFrontpage()
|
||||||
|
{
|
||||||
|
|
||||||
|
$fpref = e107::getPref('frontpage');
|
||||||
|
$location = '';
|
||||||
|
$class_list = explode(',', USERCLASS_LIST);
|
||||||
|
|
||||||
|
if(isset($fpref['all']) && $fpref['all'])
|
||||||
|
{ // 0.7 method
|
||||||
|
$location = $fpref['all'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // This is the 'new' method - assumes $fpref is an ordered list of rules
|
||||||
|
if(!empty($fpref))
|
||||||
|
{
|
||||||
|
foreach($fpref as $fk => $fp)
|
||||||
|
{
|
||||||
|
if(in_array($fk, $class_list))
|
||||||
|
{
|
||||||
|
$location = $fp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$location)
|
||||||
|
{ // Try and use the 'old' method (this bit can go later)
|
||||||
|
if(ADMIN)
|
||||||
|
{
|
||||||
|
$location = $fpref[e_UC_ADMIN];
|
||||||
|
}
|
||||||
|
elseif(USER)
|
||||||
|
{ // This is the key bit - what to do for a 'normal' logged in user
|
||||||
|
// We have USERCLASS_LIST - comma separated. Also e_CLASS_REGEXP
|
||||||
|
$inclass = false;
|
||||||
|
foreach($class_list as $fp_class)
|
||||||
|
{
|
||||||
|
if(!$inclass && check_class($fp_class['userclass_id']))
|
||||||
|
{
|
||||||
|
$location = $fpref[$fp_class['userclass_id']];
|
||||||
|
$inclass = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$location = $location ? $location : $fpref[e_UC_MEMBER];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$location = $fpref[e_UC_GUEST];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$location = trim($location);
|
||||||
|
|
||||||
|
|
||||||
|
// Defaults to news
|
||||||
|
if(!$location)
|
||||||
|
{
|
||||||
|
$location = 'url:/news';
|
||||||
|
}
|
||||||
|
// Former Welcome Message front-page. Should be handled by current theme layout
|
||||||
|
elseif($location == 'index.php' || $location == 'url:/' || $location == 'route:/' || $location == '/')
|
||||||
|
{
|
||||||
|
$location = false;
|
||||||
|
}
|
||||||
|
elseif($location[0] === '{')
|
||||||
|
{
|
||||||
|
$location = e107::getParser()->replaceConstants($location, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $location;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cloning is not allowed
|
* Cloning is not allowed
|
||||||
*
|
*
|
||||||
@ -3771,7 +3848,7 @@ class e107
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick method to set alias - uses e107::url format.
|
* Quick method to set alias - uses e107::url format.
|
||||||
* @param string $plugin if empty will return the last assigned canonical url.
|
* @param string $plugin if empty will return the last assigned canonical url._SITEURL_ will set canonical to the SITEURL.
|
||||||
* @param string|array $key
|
* @param string|array $key
|
||||||
* @param array $row
|
* @param array $row
|
||||||
*/
|
*/
|
||||||
@ -3785,21 +3862,35 @@ class e107
|
|||||||
return $alreadyDone;
|
return $alreadyDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($alreadyDone) && $url = e107::url($plugin, $key, $row, array('mode' => 'full')))
|
if(empty($alreadyDone))
|
||||||
{
|
{
|
||||||
self::getJs()->addLink(array('rel'=>"canonical", "href" => $url));
|
if($plugin === '_SITEURL_')
|
||||||
e107::setRegistry('core/e107/canonical', $url);
|
{
|
||||||
|
$url = SITEURL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$url = e107::url($plugin, $key, $row, array('mode' => 'full'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($url))
|
||||||
|
{
|
||||||
|
self::getJs()->addLink(array('rel'=>"canonical", "href" => $url));
|
||||||
|
e107::setRegistry('core/e107/canonical', $url);
|
||||||
|
$message = "Debug: Setting Canonical URL: <b><a href='".$url."'>".$url."</a></b>";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($alreadyDone))
|
if(!empty($alreadyDone))
|
||||||
{
|
{
|
||||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||||
$url = "More than one canonical was set: ".print_a($backtrace[1], true);
|
$message = "Debug: More than one canonical was attempted. This was ignored: ".print_a($backtrace[1], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deftrue('e_DEBUG_CANONICAL'))
|
if(deftrue('e_DEBUG_CANONICAL') && !empty($message))
|
||||||
{
|
{
|
||||||
self::getMessage()->addInfo("Debug Canonical URL: <a href='".$url."'>".$url."</a>");
|
self::getMessage()->addInfo($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +21,31 @@ class page_frontpage // include plugin-folder in the name.
|
|||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
$config = array();
|
$config = array();
|
||||||
|
|
||||||
|
// require_once(e_PLUGIN."page/includes/pageHelper.php");
|
||||||
|
|
||||||
// Retrieve all custom pages
|
// Retrieve all custom pages
|
||||||
if($sql->select('page', 'page_id, page_title, page_sef', "menu_name IS NULL OR menu_name=''"))
|
if($sql->select('page', 'page_id, page_title, page_sef, page_chapter', "menu_name IS NULL OR menu_name=''"))
|
||||||
{
|
{
|
||||||
$config['title'] = FRTLAN_30;
|
$config['title'] = FRTLAN_30;
|
||||||
|
|
||||||
while($row = $sql->fetch())
|
while($row = $sql->fetch())
|
||||||
{
|
{
|
||||||
$config['page'][] = array('page' => 'page.php?'.$row['page_id'], 'title' => $row['page_title']); // TODO SEF URL
|
/*if(!empty($row['page_chapter']))
|
||||||
|
{
|
||||||
|
pageHelper::addSefFields($row, 'page_chapter');
|
||||||
|
$url = e107::url('page/view', $row);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$url = e107::url('page/view/other', $row);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do NOT add SEF to the 'page' value below.
|
||||||
|
* XXX legacy URL method uses page.php?x to 'include' the file on the frontpage.
|
||||||
|
* XXX Switching to sef will cause a redirect on SITEURL to the SEF url instead.
|
||||||
|
*/
|
||||||
|
$config['page'][] = array('page' => 'page.php?'.$row['page_id'], 'title' => $row['page_title']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user