Example #1
0
 /**
  * Compute the tag
  *
  * @return string the PHP / HTML content computed
  * @access private
  */
 protected function _compute()
 {
     if ($this->_parameters['context'] == CMS_XMLTag::HTML_CONTEXT) {
         if (!isset($this->_computeParams['visualization']) || !isset($this->_computeParams['object']) || !$this->_computeParams['object'] instanceof CMS_page) {
             return '';
         }
         $public = $this->_computeParams['visualization'] == PAGE_VISUALMODE_PRINT || $this->_computeParams['visualization'] == PAGE_VISUALMODE_HTML_PUBLIC;
         return CMS_tree::getPageValue($this->_computeParams['object']->getID(), $this->_attributes['name'], $public);
     } else {
         return '$content .= CMS_tree::getPageValue($parameters[\'pageID\'], \'' . $this->_attributes['name'] . '\', (isset($public_search) ? $public_search : false));';
     }
 }
Example #2
0
/**
 * Builds a link from a linktype and a link template which may contain the special string {{href}}
 *
 * @param integer $type The type of the link
 * @param array(string) $parameters The links parameters in this order : internalLink page ID, external URL, file URL
 * @param string $template The link template
 * @param array $popup The popup parameter $popupInfo[0] : boolean is popup active ?, $popupInfo[1] : integer popup size X, $popupInfo[2] : integer popup size Y
 * @return string The link built.
 * @access public
 */
function buildLink($type, $parameters, $template, $popupInfo = false)
{
    switch ($type) {
        case RESOURCE_LINK_TYPE_INTERNAL:
            $href = CMS_tree::getPageValue($parameters[0], 'url');
            $target = "_top";
            break;
        case RESOURCE_LINK_TYPE_EXTERNAL:
            $href = $parameters[1];
            if (substr($href, 0, 4) != 'http') {
                $href = 'http://' . $href;
            }
            $target = "_blank";
            break;
        case RESOURCE_LINK_TYPE_FILE:
            $href = $parameters[2];
            if (substr($href, 0, 4) != 'http') {
                $href = 'http://' . $href;
            }
            $target = "_blank";
            break;
        default:
            return '';
            break;
    }
    if ($popupInfo != false && is_array($popupInfo) && $popupInfo[0] != 0 && $href) {
        $href = "javascript:openWindow('" . $href . "', 'popup', " . $popupInfo[1] . ", " . $popupInfo[2] . ", 'yes', 'yes', 'no', 40, 40);";
        $target = "";
    }
    if ($href) {
        $template = str_replace("{{target}}", $target, $template);
        return str_replace("{{href}}", $href, $template);
    }
}
Example #3
0
 /**
  * Get : a full XHTML a tag
  *
  * @param string $module If false, only returns the filename
  * @param string $dataLocation Where does the data lies ? @see CMS_resource constants
  * @param string $attrs, any attributes to append into A tag 
  * @return string, the XHTML Tag
  * @access public
  */
 function getHTML($label = false, $module = MOD_STANDARD_CODENAME, $dataLocation = RESOURCE_DATA_LOCATION_EDITED, $attrs = false, $hrefOnly = false)
 {
     if ($label) {
         $this->_label = $label;
     }
     // Building href
     $s = '';
     $href = '';
     $onClick = '';
     switch ($this->_linkType) {
         case RESOURCE_LINK_TYPE_INTERNAL:
             // Get internal page URL
             switch ($dataLocation) {
                 case RESOURCE_DATA_LOCATION_PUBLIC:
                 case RESOURCE_DATA_LOCATION_EDITED:
                 default:
                     if (sensitiveIO::isPositiveInteger($this->_internalLink) && ($href = CMS_tree::getPageValue($this->_internalLink, 'url'))) {
                         $href = PATH_PAGES_WR && strpos($href, PATH_PAGES_WR) !== false || stripos($href, 'http') !== false ? $href : PATH_PAGES_WR . $href;
                     }
                     break;
             }
             // Set a popup link, not a trivial link
             if (isset($this->_popup['width']) && isset($this->_popup['height']) && $this->_popup['width'] > 0 && $this->_popup['height'] > 0) {
                 $onClick = "javascript:CMS_openPopUpPage('" . $href . "', 'popup_page', " . $this->_popup['width'] . ", " . $this->_popup['height'] . ");return false;";
             }
             break;
         case RESOURCE_LINK_TYPE_EXTERNAL:
             $href = io::htmlspecialchars($this->_externalLink);
             $href = str_replace('&', '&', $href);
             if (strtolower(substr($href, 0, 4)) != 'http') {
                 $href = 'http://' . $href;
             }
             // Set a popup link, not a trivial link
             if (isset($this->_popup['width']) && $this->_popup['width'] > 0 && isset($this->_popup['height']) && $this->_popup['height'] > 0) {
                 $onClick = "javascript:CMS_openPopUpPage('" . $href . "', 'external', " . $this->_popup['width'] . ", " . $this->_popup['height'] . ");return false;";
             }
             break;
         case RESOURCE_LINK_TYPE_FILE:
             if (is_file($this->getFileLink(true, $module, $dataLocation, PATH_RELATIVETO_FILESYSTEM))) {
                 $href = $this->getFileLink(true, $module, $dataLocation, PATH_RELATIVETO_WEBROOT);
                 // Set a popup link, not a trivial link
                 if (isset($this->_popup['width']) && $this->_popup['width'] > 0 && isset($this->_popup['height']) && $this->_popup['height'] > 0) {
                     $onClick = "javascript:CMS_openPopUpPage('" . $href . "', 'file', " . $this->_popup['width'] . ", " . $this->_popup['height'] . ");return false;";
                 }
             }
             break;
     }
     if ($hrefOnly) {
         return $href;
     }
     if ($this->_target) {
         $target = ' target="' . $this->_target . '"';
     }
     // Get onClick
     if ($onClick != '') {
         $onClick = ' onClick="' . $onClick . '"';
     }
     // Return Link
     if (trim($href) != '') {
         if (!$attrs) {
             $attrs = $this->getAttributesString();
         }
         $attrs = ' ' . trim($attrs);
         $s = '<a href="' . $href . '"' . $onClick . $target . $attrs . '>' . $this->_label . '</a>';
     }
     return $s;
 }
 public function getPageTitle()
 {
     $pageId = $this->getValue('page');
     return CMS_tree::getPageValue($pageId, 'title');
 }
Example #5
0
 /**
  * Create the redirection of an alias
  *
  * @return boolean true on success, false on failure
  * @access public
  * @static
  */
 function redirect()
 {
     //get aliases for current folder
     $dirname = array_pop(explode(DIRECTORY_SEPARATOR, dirname($_SERVER['SCRIPT_NAME'])));
     $aliases = CMS_module_cms_aliases::getByName($dirname);
     if (!$aliases) {
         //no alias found, go to 404
         CMS_grandFather::raiseError('No alias found for directory ' . dirname($_SERVER['SCRIPT_NAME']));
         CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
     }
     //check each aliases returned to get the one which respond to current alias
     $matchAlias = false;
     $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']);
     $websites = array();
     if ($domain) {
         $websites = CMS_websitesCatalog::getWebsitesFromDomain($domain);
     }
     foreach ($aliases as $alias) {
         if (!$matchAlias && dirname($_SERVER['SCRIPT_NAME']) == substr($alias->getPath(), 0, -1)) {
             if ($websites) {
                 foreach ($websites as $website) {
                     //alias match path, check for website
                     if (!$alias->getWebsites() || !$website || in_array($website->getId(), $alias->getWebsites())) {
                         //alias match website, use it
                         $matchAlias = $alias;
                     }
                 }
             } else {
                 //alias match path, check for website
                 if (!$alias->getWebsites()) {
                     //alias match website, use it
                     $matchAlias = $alias;
                 }
             }
         }
     }
     if (!$matchAlias) {
         //no alias found, go to 404
         CMS_grandFather::raiseError('No alias found for directory ' . dirname($_SERVER['SCRIPT_NAME']) . ' and domain ' . $domain);
         CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
     }
     //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 {
             //no valid page set, go to 404
             $matchAlias->raiseError('No page set for alias ' . $matchAlias->getID());
             CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
         }
         if (!$page || $page->hasError()) {
             //no valid page found, go to 404
             $matchAlias->raiseError('Invalid page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
             CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
         }
         //return page path
         $pPath = $page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM);
         if ($pPath) {
             if (file_exists($pPath)) {
                 return $pPath;
             } elseif ($page->regenerate(true)) {
                 clearstatcache();
                 if (file_exists($pPath)) {
                     return $pPath;
                 }
             }
         }
         //no valid url page found, go to 404
         $matchAlias->raiseError('Invalid url page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
         CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
     } else {
         //this is a redirection
         $params = isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';
         if (isset($_SERVER['HTTP_REFERER'])) {
             header("Referer: " . $_SERVER['HTTP_REFERER']);
         }
         if (io::isPositiveInteger($matchAlias->getPageID())) {
             //it's a redirection to an Automne Page
             $page = CMS_tree::getPageById($matchAlias->getPageID());
             if ($page && !$page->hasError()) {
                 $pageURL = CMS_tree::getPageValue($matchAlias->getPageID(), 'url');
                 if ($pageURL) {
                     CMS_view::redirect($pageURL . $params, true, $matchAlias->isPermanent() ? 301 : 302);
                 } else {
                     //no valid url page found, go to 404
                     $matchAlias->raiseError('Invalid url page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
                     CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
                 }
             } else {
                 //no valid page found, go to 404
                 $matchAlias->raiseError('Invalid page ' . $matchAlias->getPageID() . ' for alias ' . $matchAlias->getID());
                 CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
             }
         } elseif ($matchAlias->getURL()) {
             //it's a redirection to an URL
             CMS_view::redirect($matchAlias->getURL(), true, $matchAlias->isPermanent() ? 301 : 302);
         } else {
             //no valid redirection found, go to 404
             $matchAlias->raiseError('Invalid redirection for alias ' . $matchAlias->getID());
             CMS_view::redirect(PATH_SPECIAL_PAGE_NOT_FOUND_WR, true, 301);
         }
     }
 }
Example #6
0
 /**
  * get object HTML description for admin search detail. Usually, the label.
  *
  * @return string : object HTML description
  * @access public
  */
 function getHTMLDescription()
 {
     global $cms_language;
     if (is_object($this->_subfieldValues[0]) && $this->_subfieldValues[0]->getValue()) {
         return '<a href="#" href="#" onclick="Automne.utils.getPageById(' . $this->_subfieldValues[0]->getValue() . ');Ext.WindowMgr.getActive().close();">' . CMS_tree::getPageValue($this->_subfieldValues[0]->getValue(), 'title') . ' (' . $this->_subfieldValues[0]->getValue() . ')</a>';
     }
     return '';
 }
Example #7
0
 /**
  * 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;
 }