/** * Retrieve the unique URL for a category * * @param string $url * @param int[optional] $id The id of the category to ignore. * @return string */ public static function getURLForCategory($url, $id = null) { $url = SpoonFilter::urlise((string) $url); $db = BackendModel::getDB(); // new category if ($id === null) { if ((bool) $db->getVar('SELECT 1 FROM faq_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? LIMIT 1', array(BL::getWorkingLanguage(), $url))) { $url = BackendModel::addNumber($url); return self::getURLForCategory($url); } } else { if ((bool) $db->getVar('SELECT 1 FROM faq_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? AND i.id != ? LIMIT 1', array(BL::getWorkingLanguage(), $url, $id))) { $url = BackendModel::addNumber($url); return self::getURLForCategory($url, $id); } } return $url; }
/** * Retrieve the unique URL for a category * * @return string * @param string $URL The string wheron the URL will be based. * @param int[optional] $id The id of the category to ignore. */ public static function getURLForCategory($URL, $id = null) { // redefine URL $URL = SpoonFilter::urlise((string) $URL); // get db $db = BackendModel::getDB(); // new category if ($id === null) { // get number of categories with this URL $number = (int) $db->getVar('SELECT COUNT(i.id) FROM blog_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ?', array(BL::getWorkingLanguage(), $URL)); // already exists if ($number != 0) { // add number $URL = BackendModel::addNumber($URL); // try again return self::getURLForCategory($URL); } } else { // get number of items with this URL $number = (int) $db->getVar('SELECT COUNT(i.id) FROM blog_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? AND i.id != ?', array(BL::getWorkingLanguage(), $URL, $id)); // already exists if ($number != 0) { // add number $URL = BackendModel::addNumber($URL); // try again return self::getURLForCategory($URL, $id); } } // return the unique URL! return $URL; }
/** * Retrieve the unique URL for a category * * @param string $url * @param int[optional] $id The id of the category to ignore. * @return string */ public static function getURLForCategory($url, $id = null) { $url = SpoonFilter::urlise((string) $url); $db = BackendModel::getDB(); // new category if ($id === null) { // get number of categories with this URL $number = (int) $db->getVar('SELECT COUNT(i.id) FROM faq_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ?', array(BL::getWorkingLanguage(), $url)); // already exists if ($number != 0) { $url = BackendModel::addNumber($url); return self::getURLForCategory($url); } } else { // get number of items with this URL $number = (int) $db->getVar('SELECT COUNT(i.id) FROM faq_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? AND i.id != ?', array(BL::getWorkingLanguage(), $url, $id)); // already exists if ($number != 0) { $url = BackendModel::addNumber($url); return self::getURLForCategory($url, $id); } } return $url; }
/** * Get a unique URL for a tag * * @param string $URL The URL to use as a base. * @param int[optional] $id The ID to ignore. * @return string */ public static function getURL($URL, $id = null) { $URL = SpoonFilter::urlise((string) $URL); $language = BL::getWorkingLanguage(); // get db $db = BackendModel::getDB(); // no specific id if ($id === null) { // get number of tags with the specified url $number = (int) $db->getVar('SELECT COUNT(i.id) FROM tags AS i WHERE i.url = ? AND i.language = ?', array($URL, $language)); // 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 $URL = self::getURL($URL, $id); } } else { // redefine $id = (int) $id; // get number of tags with the specified url $number = (int) $db->getVar('SELECT COUNT(i.id) FROM tags AS i WHERE i.url = ? AND i.language = ? AND i.id != ?', array($URL, $language, $id)); // 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 $URL = self::getURL($URL, $id); } } return $URL; }
/** * Retrieve the unique URL for a category * * @param string $URL The string wheron the URL will be based. * @param int[optional] $id The id of the category to ignore. * @return string */ public static function getURLForCategory($URL, $id = null) { // redefine URL $URL = (string) $URL; // get db $db = BackendModel::getDB(); // new category if ($id === null) { // already exists if ((bool) $db->getVar('SELECT 1 FROM blog_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? LIMIT 1', array(BL::getWorkingLanguage(), $URL))) { $URL = BackendModel::addNumber($URL); return self::getURLForCategory($URL); } } else { // already exists if ((bool) $db->getVar('SELECT 1 FROM blog_categories AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.language = ? AND m.url = ? AND i.id != ? LIMIT 1', array(BL::getWorkingLanguage(), $URL, $id))) { $URL = BackendModel::addNumber($URL); return self::getURLForCategory($URL, $id); } } return $URL; }
/** * Retrieve a unique URL for a profile based on the display name. * * @return string The unique URL. * @param string $displayName The display name to base on. * @param int[optional] $id The id of the profile to ignore. */ public static function getUrl($displayName, $id = null) { // decode specialchars $displayName = SpoonFilter::htmlspecialcharsDecode((string) $displayName); // urlise $url = SpoonFilter::urlise((string) $displayName); // get db $db = BackendModel::getDB(); // new item if ($id === null) { // get number of profiles with this URL $number = (int) $db->getVar('SELECT COUNT(p.id) FROM profiles AS p WHERE p.url = ?', (string) $url); // already exists if ($number != 0) { // add number $url = BackendModel::addNumber($url); // try again return self::getURL($url); } } else { // get number of profiles with this URL $number = (int) $db->getVar('SELECT COUNT(p.id) FROM profiles AS p WHERE p.url = ? AND p.id != ?', array((string) $url, (int) $id)); // already exists if ($number != 0) { // add number $url = BackendModel::addNumber($url); // try again return self::getURL($url, $id); } } // cough up new url return $url; }
/** * 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) { // 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 { // 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 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; }