/** * 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; }
/** * Assign the labels */ private function parseLabels() { $actions = FrontendLanguage::getActions(); $errors = FrontendLanguage::getErrors(); $labels = FrontendLanguage::getLabels(); $messages = FrontendLanguage::getMessages(); // execute addslashes on the values for the locale, will be used in JS if ($this->addSlashes) { foreach ($actions as &$value) { if (!is_array($value)) { $value = addslashes($value); } } foreach ($errors as &$value) { if (!is_array($value)) { $value = addslashes($value); } } foreach ($labels as &$value) { if (!is_array($value)) { $value = addslashes($value); } } foreach ($messages as &$value) { if (!is_array($value)) { $value = addslashes($value); } } } // assign actions $this->assignArray($actions, 'act'); // assign errors $this->assignArray($errors, 'err'); // assign labels $this->assignArray($labels, 'lbl'); // assign messages $this->assignArray($messages, 'msg'); }
/** * Assign the labels * * @return void */ private function parseLabels() { // assign actions $this->assignArray(FrontendLanguage::getActions(), 'act'); // assign errors $this->assignArray(FrontendLanguage::getErrors(), 'err'); // assign labels $this->assignArray(FrontendLanguage::getLabels(), 'lbl'); // assign messages $this->assignArray(FrontendLanguage::getMessages(), 'msg'); }