С версии: 2.0
Автор: Tijs Verkoyen (tijs@netlash.com)
Автор: Davy Hellemans (davy@netlash.com)
Автор: Dieter Vanden Eynde (dieter@netlash.com)
Пример #1
0
 /**
  * Get an unique URL for a page
  *
  * @param string $url      The URL to base on.
  * @param int    $id       The id to ignore.
  * @param int    $parentId The parent for the page to create an url for.
  * @param bool   $isAction Is this page an action.
  *
  * @return string
  */
 public static function getURL($url, $id = null, $parentId = 0, $isAction = false)
 {
     $url = (string) $url;
     $parentIds = array((int) $parentId);
     // 0, 1, 2, 3, 4 are all top levels, so we should place them on the same level
     if ($parentId == 0 || $parentId == 1 || $parentId == 2 || $parentId == 3 || $parentId == 4) {
         $parentIds = array(0, 1, 2, 3, 4);
     }
     // get db
     $db = BackendModel::getContainer()->get('database');
     // no specific id
     if ($id === null) {
         // no items?
         if ((bool) $db->getVar('SELECT 1
              FROM pages AS i
              INNER JOIN meta AS m ON i.meta_id = m.id
              WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ? AND m.url = ?
                 AND i.language = ?
              LIMIT 1', array('active', $url, BL::getWorkingLanguage()))) {
             // add a number
             $url = BackendModel::addNumber($url);
             // recall this method, but with a new URL
             return self::getURL($url, null, $parentId, $isAction);
         }
     } else {
         // one item should be ignored
         // there are items so, call this method again.
         if ((bool) $db->getVar('SELECT 1
              FROM pages AS i
              INNER JOIN meta AS m ON i.meta_id = m.id
              WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ?
                 AND m.url = ? AND i.id != ? AND i.language = ?
              LIMIT 1', array('active', $url, $id, BL::getWorkingLanguage()))) {
             // add a number
             $url = BackendModel::addNumber($url);
             // recall this method, but with a new URL
             return self::getURL($url, $id, $parentId, $isAction);
         }
     }
     // get full URL
     $fullURL = self::getFullURL($parentId) . '/' . $url;
     // get info about parent page
     $parentPageInfo = self::get($parentId, null, BL::getWorkingLanguage());
     // does the parent have extras?
     if ($parentPageInfo['has_extra'] == 'Y' && !$isAction) {
         // set locale
         FrontendLanguage::setLocale(BL::getWorkingLanguage(), true);
         // get all on-site action
         $actions = FrontendLanguage::getActions();
         // if the new URL conflicts with an action we should rebuild the URL
         if (in_array($url, $actions)) {
             // add a number
             $url = BackendModel::addNumber($url);
             // recall this method, but with a new URL
             return self::getURL($url, $id, $parentId, $isAction);
         }
     }
     // check if folder exists
     if (is_dir(PATH_WWW . '/' . $fullURL) || is_file(PATH_WWW . '/' . $fullURL)) {
         // add a number
         $url = BackendModel::addNumber($url);
         // recall this method, but with a new URL
         return self::getURL($url, $id, $parentId, $isAction);
     }
     // check if it is an application
     if (array_key_exists(trim($fullURL, '/'), \ApplicationRouting::getRoutes())) {
         // add a number
         $url = BackendModel::addNumber($url);
         // recall this method, but with a new URL
         return self::getURL($url, $id, $parentId, $isAction);
     }
     // return the unique URL!
     return $url;
 }
Пример #2
0
    /**
     * Get an unique URL for a page
     *
     * @param string $URL The URL to base on.
     * @param int[optional] $id The id to ignore.
     * @param int[optional] $parentId The parent for the page to create an url for.
     * @param bool[optional] $isAction Is this page an action.
     * @return string
     */
    public static function getURL($URL, $id = null, $parentId = 0, $isAction = false)
    {
        $URL = (string) $URL;
        $parentIds = array((int) $parentId);
        // 0, 1, 2, 3, 4 are all toplevels, so we should place them on the same level
        if ($parentId == 0 || $parentId == 1 || $parentId == 2 || $parentId == 3 || $parentId == 4) {
            $parentIds = array(0, 1, 2, 3, 4);
        }
        // get db
        $db = BackendModel::getDB();
        // no specific id
        if ($id === null) {
            // get number of childs within this parent with the specified URL
            $number = (int) $db->getVar('SELECT COUNT(i.id)
				 FROM pages AS i
				 INNER JOIN meta AS m ON i.meta_id = m.id
				 WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ? AND m.url = ? AND i.language = ?', array('active', $URL, BL::getWorkingLanguage()));
            // no items?
            if ($number != 0) {
                // add a number
                $URL = BackendModel::addNumber($URL);
                // recall this method, but with a new URL
                return self::getURL($URL, null, $parentId, $isAction);
            }
        } else {
            // get number of childs within this parent with the specified URL
            $number = (int) $db->getVar('SELECT COUNT(i.id)
				 FROM pages AS i
				 INNER JOIN meta AS m ON i.meta_id = m.id
				 WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ? AND m.url = ? AND i.id != ? AND i.language = ?', array('active', $URL, $id, BL::getWorkingLanguage()));
            // there are items so, call this method again.
            if ($number != 0) {
                // add a number
                $URL = BackendModel::addNumber($URL);
                // recall this method, but with a new URL
                return self::getURL($URL, $id, $parentId, $isAction);
            }
        }
        // get full URL
        $fullURL = self::getFullUrl($parentId) . '/' . $URL;
        // get info about parent page
        $parentPageInfo = self::get($parentId, null, BL::getWorkingLanguage());
        // does the parent have extra's?
        if ($parentPageInfo['has_extra'] == 'Y' && !$isAction) {
            // set locale
            FrontendLanguage::setLocale(BackendLanguage::getWorkingLanguage(), true);
            // get all onsite action
            $actions = FrontendLanguage::getActions();
            // if the new URL conflicts with an action we should rebuild the URL
            if (in_array($URL, $actions)) {
                // add a number
                $URL = BackendModel::addNumber($URL);
                // recall this method, but with a new URL
                return self::getURL($URL, $id, $parentId, $isAction);
            }
        }
        // check if folder exists
        if (SpoonDirectory::exists(PATH_WWW . '/' . $fullURL)) {
            // add a number
            $URL = BackendModel::addNumber($URL);
            // recall this method, but with a new URL
            return self::getURL($URL, $id, $parentId, $isAction);
        }
        // check if it is an appliation
        if (in_array(trim($fullURL, '/'), array_keys(ApplicationRouting::getRoutes()))) {
            // add a number
            $URL = BackendModel::addNumber($URL);
            // recall this method, but with a new URL
            return self::getURL($URL, $id, $parentId, $isAction);
        }
        // return the unique URL!
        return $URL;
    }