/** * Get the page online URL. * * @param boolean $printPage Do we want the print page URL ? * @param boolean $returnFilenameOnly : return only the page filename (default false) * @param constant $relativeTo : get URL relative to webroot (PATH_RELATIVETO_WEBROOT) or file system (PATH_RELATIVETO_FILESYSTEM) * @param boolean $force : get URL even if page is not published (default : false) * @param boolean $doNotShorten : get full page URL (default : false) * @return string The url; complete with PATH and website information. Empty string if page not published. * @access public */ function getURL($printPage = false, $returnFilenameOnly = false, $relativeTo = PATH_RELATIVETO_WEBROOT, $force = false, $doNotShorten = false) { if ($force || $this->getLocation() == RESOURCE_LOCATION_USERSPACE && $this->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { $ws = $this->getWebsite(); $wsURL = ''; if (is_object($ws)) { if ($relativeTo == PATH_RELATIVETO_WEBROOT) { $wsURL = $ws->getURL(); if ($this->isHTTPS()) { $wsURL = str_ireplace('http://', 'https://', $wsURL); } //if this page is a website root, try to shorten page url using only website domain - do not shorten in Automne admin (_dc parameter) if (!$printPage && !$returnFilenameOnly && !isset($_REQUEST['_dc']) && !$doNotShorten) { //check if page website is the main for the domain if (CMS_websitesCatalog::isWebsiteRoot($this->getID())) { $mainWS = CMS_websitesCatalog::getWebsiteFromDomain(@parse_url($wsURL, PHP_URL_HOST)); if ($mainWS && $mainWS->getID() == $ws->getID()) { return $wsURL . PATH_REALROOT_WR . (substr($wsURL . PATH_REALROOT_WR, -1) === '/' ? '' : '/'); } else { return $wsURL . $ws->getPagesPath(PATH_RELATIVETO_WEBROOT) . '/'; } } else { //query modules to get new page URL $modules = CMS_modulesCatalog::getAll(); foreach ($modules as $module) { if (method_exists($module, 'getPageURL')) { $url = $module->getPageURL($this); if ($url) { return $wsURL . $url; } } } } } } $wsPagesPath = $ws->getPagesPath($relativeTo); } else { return ''; } $filename = $this->_getFilename(); if (STRIP_PHP_EXTENSION && $relativeTo == PATH_RELATIVETO_WEBROOT) { $filename = substr($filename, 0, -4); } if ($printPage) { if ($returnFilenameOnly) { return "print-" . $filename; } else { return $wsURL . $wsPagesPath . "/print-" . $filename; } } else { if ($returnFilenameOnly) { return $filename; } else { return $wsURL . $wsPagesPath . "/" . $filename; } } } return ''; }
/** * Return a valid page for a given URL * * @param string $pageUrl the page URL * @param boolean $useDomain : use queried domain to found root page associated (default : true) * @return CMS_page if page found, false otherwise * @access public */ function getPageFromURL($pageUrl, $useDomain = true) { $urlinfo = @parse_url($pageUrl); if (!isset($urlinfo['path'])) { //no alias can exists without path return false; } //strip final slash from path $urlinfo['path'] = substr($urlinfo['path'], -1) == '/' ? substr($urlinfo['path'], 0, -1) : $urlinfo['path']; //get aliases for current folder $dirname = array_pop(explode('/', $urlinfo['path'])); $aliases = CMS_module_cms_aliases::getByName($dirname); if (!$aliases) { return false; } //check each aliases returned to get the one which respond to current alias $matchAlias = false; $website = false; if ($useDomain) { $httpHost = @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) ? @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST']; //search page id by domain address $domain = isset($urlinfo['host']) ? $urlinfo['host'] : $httpHost; $website = CMS_websitesCatalog::getWebsiteFromDomain($domain); } foreach ($aliases as $alias) { if (!$matchAlias && $urlinfo['path'] == substr($alias->getPath(), 0, -1)) { //alias match path, check for website if (!$alias->getWebsites() || !$website || in_array($website->getId(), $alias->getWebsites())) { //alias match website, use it $matchAlias = $alias; } } } if (!$matchAlias) { return false; } //if alias is used as a page url, return page if ($matchAlias->urlReplaced()) { if (io::isPositiveInteger($matchAlias->getPageID())) { $page = CMS_tree::getPageById($matchAlias->getPageID()); } else { return false; } if (!$page || $page->hasError()) { return false; } return $page; } return false; }
// | Author: Sébastien Pauchet <*****@*****.**> | // +----------------------------------------------------------------------+ /** * Automne index handler. Redirect to correct website accordingly to queried domain * * @package Automne * @subpackage frontend * @author Sébastien Pauchet <*****@*****.**> */ require_once dirname(__FILE__) . '/cms_rc_frontend.php'; $httpHost = null; if (isset($_SERVER['HTTP_HOST'])) { $httpHost = @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) ? @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST']; } //search page id by domain address $website = CMS_websitesCatalog::getWebsiteFromDomain($httpHost, '', $isAlt); //redirect to website main domain if current domain is an altdomain and need redirection if ($website && $isAlt && $website->redirectAltDomain()) { CMS_view::redirect($website->getURL(), true, 301); } if (!$website) { $website = CMS_websitesCatalog::getMainWebsite(); } $rootPage = $website->getRoot(); if ($rootPage->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { //redirect to subpage if any $redirectlink = $rootPage->getRedirectLink(true); while ($redirectlink && $redirectlink->hasValidHREF() && sensitiveIO::IsPositiveInteger($redirectlink->getInternalLink())) { $rootPage = new CMS_page($redirectlink->getInternalLink()); if ($rootPage->getPublication() == RESOURCE_PUBLICATION_PUBLIC) { $redirectlink = $rootPage->getRedirectLink(true);
* @author Sébastien Pauchet <*****@*****.**> */ // ************************************************************************* // ** REDIRECTION HANDLER. KEEP ALL THIS PHP CODE IN 403 ERROR DOCUMENT ! ** // ** YOU CAN DEFINE YOUR OWN ERROR PAGE WITH THE FILE /403.html ** // ************************************************************************* //disactive HTML compression define("ENABLE_HTML_COMPRESSION", false); require_once dirname(__FILE__) . '/cms_rc_frontend.php'; //send 403 error code header('HTTP/1.x 403 Forbidden', true, 403); //try to get website by domain to serve specific 403 page $domain = @parse_url($_SERVER['REQUEST_URI'], PHP_URL_HOST) ? @parse_url($_SERVER['REQUEST_URI'], PHP_URL_HOST) : (@parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) ? @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST']); $path = @parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if ($domain && strpos($path, 'htaccess.txt') === false) { $website = CMS_websitesCatalog::getWebsiteFromDomain($domain); if ($website && !$website->hasError()) { //check if website has a 403 page defined $page403 = $website->get403(); if ($page403) { $pPath = $page403->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM); if ($pPath) { if (file_exists($pPath)) { $cms_page_included = true; require $pPath; exit; } elseif ($page403->regenerate(true)) { clearstatcache(); if (file_exists($pPath)) { $cms_page_included = true; require $pPath;
/** * Return a valid page for a given URL * * @param string $pageUrl the page URL * @param boolean $useDomain : use queried domain to found root page associated (default : true) * @return CMS_page if page found, false otherwise * @access public */ static function analyseURL($pageUrl, $useDomain = true) { if (strpos($pageUrl, PATH_FORBIDDEN_WR) === 0 || strpos($pageUrl, PATH_SPECIAL_PAGE_NOT_FOUND_WR) === 0) { return false; } $requestedPageId = null; $urlinfo = @parse_url($pageUrl); if (isset($urlinfo['path'])) { $pathinfo = pathinfo($urlinfo['path']); $basename = isset($pathinfo['filename']) ? $pathinfo['filename'] : $pathinfo['basename']; } //if extension exists and is not PHP, return if (isset($pathinfo['extension']) && $pathinfo['extension'] && $pathinfo['extension'] != 'php') { return false; } if (isset($urlinfo['query'])) { $querystring = $urlinfo['query']; } //if basename found try to get page id if (isset($urlinfo['path']) && $urlinfo['path'] != PATH_REALROOT_WR . '/' && $basename && (isset($pathinfo['extension']) && strtolower($pathinfo['extension']) == 'php' || !isset($pathinfo['extension']))) { //search page id in basename (declare matching patterns by order of research) $patterns[] = "#^([0-9]+)-#U"; // for request like id-page_title.php $patterns[] = "#^print-([0-9]+)-#U"; // for request like print-id-page_title.php $patterns[] = "#_([0-9]+)_\$#U"; // for request like _id_id_.php : old V3 style url $patterns[] = "#^([0-9]+)\$#U"; // for request like id $count = 0; while (!preg_match($patterns[$count], $basename, $requestedPageId) && $count + 1 < sizeof($patterns)) { $count++; } if (isset($requestedPageId[1]) && sensitiveIO::IsPositiveInteger($requestedPageId[1]) && CMS_tree::getPageValue($requestedPageId[1], 'exists')) { //try to instanciate the requested page $cms_page = CMS_tree::getPageByID($requestedPageId[1]); if ($cms_page && !$cms_page->hasError()) { return $cms_page; } } } if ($useDomain) { $httpHost = @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) ? @parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST) : $_SERVER['HTTP_HOST']; //search page id by domain address $domain = isset($urlinfo['host']) ? $urlinfo['host'] : $httpHost; $domainfound = CMS_websitesCatalog::getWebsiteFromDomain($domain, isset($urlinfo['path']) && $urlinfo['path'] != PATH_REALROOT_WR . '/' ? $urlinfo['path'] : ''); if (is_object($domainfound)) { $cms_page = $domainfound->getRoot(); if ($cms_page && !$cms_page->hasError()) { return $cms_page; } } } //query modules to get page from them $modules = CMS_modulesCatalog::getAll(); foreach ($modules as $module) { if (method_exists($module, 'getPageFromURL')) { $cms_page = $module->getPageFromURL($pageUrl, $useDomain); if ($cms_page) { return $cms_page; } } } return false; }