function parseLanguage($intLangId, $strCommand) { global $_PATHS, $objLang, $_CLEAN_POST, $_CONF, $objLiveUser; $objTpl = new HTML_Template_IT($_PATHS['templates']); $objTpl->loadTemplatefile("language.tpl.htm"); switch ($strCommand) { case CMD_LIST: case CMD_ADD: case CMD_EDIT: //*** Post the profile form if submitted. if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "editLanguage") { //*** The element form has been posted. $blnError = false; //*** Check sanitized input. if (is_null($_CLEAN_POST["frm_active"])) { $blnError = true; } if (is_null($_CLEAN_POST["frm_name"])) { $blnError = true; } if (is_null($_CLEAN_POST["frm_apiname"])) { $blnError = true; } if (is_null($_CLEAN_POST["dispatch"])) { $blnError = true; } if ($blnError === true) { //*** Display global error. $objTpl->setVariable("FORM_ACTIVE_VALUE", $_POST["frm_active"] == "on" ? "checked=\"checked\"" : ""); $objTpl->setVariable("FORM_NAME_VALUE", $_POST["frm_name"]); $objTpl->setVariable("FORM_APINAME_VALUE", $_POST["frm_apiname"]); $objTpl->setVariable("ERROR_LANGUAGE_MAIN", $objLang->get("main", "formerror")); } else { //*** Input is valid. Save the language. if ($strCommand == CMD_EDIT) { $objLanguage = ContentLanguage::selectByPK($intLangId); } else { $objLanguage = new ContentLanguage(); } $objLanguage->setAccountId($_CONF['app']['account']->getId()); $objLanguage->setActive($_CLEAN_POST["frm_active"] == "on" ? 1 : 0); $objLanguage->setName($_CLEAN_POST["frm_name"]); $objLanguage->setAbbr($_CLEAN_POST["frm_apiname"]); $objLanguage->save(); header("Location: " . Request::getURI() . "/?cid=" . NAV_PCMS_LANGUAGES); exit; } } $objLangs = ContentLanguage::select(); foreach ($objLangs as $objLanguage) { $objTpl->setCurrentBlock("multiview-item"); $objTpl->setVariable("MULTIITEM_VALUE", $objLanguage->getId()); $objTpl->setVariable("BUTTON_REMOVE_HREF", "javascript:ContentLanguage.remove({$objLanguage->getId()});"); $objTpl->setVariable("BUTTON_REMOVE", $objLang->get("delete", "button")); $objTpl->setVariable("MULTIITEM_HREF", "?cid=" . NAV_PCMS_LANGUAGES . "&eid={$objLanguage->getId()}&cmd=" . CMD_EDIT); $strValue = htmlspecialchars($objLanguage->getName()); $strShortValue = getShortValue($strValue, 50); $intSize = strlen($strValue); $objTpl->setVariable("MULTIITEM_NAME", $intSize > 50 ? $strShortValue : $strValue); $objTpl->setVariable("MULTIITEM_TITLE", $intSize > 50 ? $strValue : ""); $objTpl->setVariable("MULTIITEM_ABBR", $objLanguage->getAbbr()); if ($objLanguage->default > 0) { $strValue = $objLang->get("standardLanguage", "label"); } else { $strValue = "<a href=\"javascript:;\" onclick=\"ContentLanguage.setDefault({$objLanguage->getId()})\" rel=\"internal\">" . $objLang->get("standardLanguage", "button") . "</a>"; } $objTpl->setVariable("MULTIITEM_META", $strValue); if (!$objLanguage->getActive()) { $objTpl->setVariable("MULTIITEM_ACTIVE", " class=\"inactive\""); } $objTpl->parseCurrentBlock(); } $objTpl->setVariable("LANGUAGES", $objLang->get("languages", "label")); $objTpl->setVariable("BUTTON_ADD", $objLang->get("languageAdd", "button")); $objTpl->setVariable("BUTTON_ADD_HREF", "ContentLanguage.prepareAdd()"); //*** Form variables. if ($strCommand == CMD_EDIT) { $objLanguage = ContentLanguage::selectByPK($intLangId); $objTpl->setVariable("FORM_ACTIVE_VALUE", $objLanguage->getActive() ? "checked=\"checked\"" : ""); $objTpl->setVariable("FORM_NAME_VALUE", $objLanguage->getName()); $objTpl->setVariable("FORM_APINAME_VALUE", $objLanguage->getAbbr()); $objTpl->setVariable("FRM_HEADER", $objLang->get("editLanguage", "form")); $objTpl->setVariable("FRM_STYLE", ""); $objTpl->setVariable("CMD", CMD_EDIT); } else { $objTpl->setVariable("FRM_HEADER", $objLang->get("addLanguage", "form")); $objTpl->setVariable("FRM_STYLE", " style=\"display:none\""); $objTpl->setVariable("CMD", CMD_ADD); } $objTpl->setVariable("FRM_LABEL_ACTIVE", $objLang->get("active", "form")); $objTpl->setVariable("FRM_LABEL_NAME", $objLang->get("name", "form")); $objTpl->setVariable("FRM_LABEL_ABBR", $objLang->get("shortName", "form")); $objTpl->setVariable("FRM_DESCR_ABBR", $objLang->get("shortName", "tip")); $objTpl->setVariable("FRM_LABEL_SAVE", $objLang->get("save", "button")); $objTpl->setVariable("CID", NAV_PCMS_LANGUAGES); $objTpl->setVariable("EID", $intLangId); $objTpl->parseCurrentBlock(); $strReturn = $objTpl->get(); break; case CMD_REMOVE: if (strpos($intLangId, ',') !== false) { //*** Multiple elements submitted. $arrLanguages = explode(',', $intLangId); $objLanguages = ContentLanguage::selectByPK($arrLanguages); foreach ($objLanguages as $objLanguage) { $objLanguage->delete(); } } else { //*** Single element submitted. $objLanguage = ContentLanguage::selectByPK($intLangId); $objLanguage->delete(); } //*** Redirect the page. $strReturnTo = request('returnTo'); if (empty($strReturnTo)) { header("Location: " . Request::getUri() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST); exit; } else { header("Location: " . Request::getURI() . $strReturnTo); exit; } break; case CMD_SET_DEFAULT: if ($intLangId > 0) { ContentLanguage::setDefault($intLangId); } //*** Redirect the page. $strReturnTo = request('returnTo'); if (empty($strReturnTo)) { header("Location: " . Request::getUri() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST); exit; } else { header("Location: " . Request::getURI() . $strReturnTo); exit; } break; } return $strReturn; }
public static function sort($intLangId) { $lastSort = 0; $arrItemlist = request("itemlist"); if (is_array($arrItemlist) && count($arrItemlist) > 0) { //*** Loop through the items and manipulate the sort order. foreach ($arrItemlist as $value) { $lastSort++; $objLanguage = ContentLanguage::selectByPK($value); $objLanguage->setSort($lastSort); $objLanguage->save(false); } } }
$objTemp->default = $_CONF['app']['languageDefault']; $objTemp->setActive(TRUE); $objCms->setLanguage($objTemp); //*** Check if the current alias is forcing a language switch. if (!empty($strRewrite)) { $strRewrite = $objCms->cleanRewrite($strRewrite); //*** Get aliases for this URL. $objUrls = Alias::selectByAlias($strRewrite); if (!is_null($objUrls) && $objUrls->count() > 0) { //*** Check if the current language is in the list of aliases. $blnFoundLanguage = false; foreach ($objUrls as $objUrl) { $intLanguage = $objUrl->getLanguageId(); if (($intLanguage == 0 || $intLanguage == $objCms->getLanguage()->getId()) && $objUrl->getActive()) { $blnFoundLanguage = true; break; } } if (!$blnFoundLanguage) { //*** Current language is not valid for this alias. $objUrls->rewind(); $objUrl = $objUrls->current(); if ($objUrl->getActive()) { $objLanguage = ContentLanguage::selectByPK($objUrl->getLanguageId()); if (is_object($objLanguage) && $objLanguage->getActive()) { Request::redirect("/language/" . $objLanguage->getAbbr() . "/" . $objUrl->getAlias()); } } } } }
function parseAlias($intAliasId, $strCommand) { global $_PATHS, $_CLEAN_POST, $_CONF, $objLang, $objLiveUser; $objTpl = new HTML_Template_IT($_PATHS['templates']); $objTpl->loadTemplatefile("alias.tpl.htm"); $blnError = false; switch ($strCommand) { case CMD_LIST: case CMD_ADD: case CMD_EDIT: //*** Post the profile form if submitted. if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "editAlias") { //*** The element form has been posted. //*** Check sanitized input. if (is_null($_CLEAN_POST["frm_active"])) { $blnError = true; } if (is_null($_CLEAN_POST["frm_alias"])) { $blnError = true; } if (is_null($_CLEAN_POST["frm_language"])) { $blnError = true; } if (is_null($_CLEAN_POST["frm_element"])) { $blnError = true; } if (is_null($_CLEAN_POST["dispatch"])) { $blnError = true; } if ($blnError === true) { //*** Display global error. $objTpl->setVariable("FORM_ACTIVE_VALUE", $_POST["frm_active"] == "on" ? "checked=\"checked\"" : ""); $objTpl->setVariable("FORM_ALIAS_VALUE", $_POST["frm_alias"]); $objTpl->setVariable("ERROR_ALIAS_MAIN", $objLang->get("main", "formerror")); } else { //*** Input is valid. Save the alias. if ($strCommand == CMD_EDIT) { $objAlias = Alias::selectByPK($intAliasId); } else { $objAlias = new Alias(); } $objAlias->setAccountId($_CONF['app']['account']->getId()); $objAlias->setActive($_POST["frm_active"] == "on" ? 1 : 0); $objAlias->setLanguageId(empty($_CLEAN_POST["frm_language"]) ? 0 : $_CLEAN_POST["frm_language"]); $objAlias->setAlias($_CLEAN_POST["frm_alias"]); $objAlias->setUrl($_CLEAN_POST["frm_element"]); $objAlias->save(); header("Location: " . Request::getURI() . "/?cid=" . NAV_PCMS_ALIASES); exit; } } //*** Initiate child element loop. $objAliases = Alias::selectSorted(); $totalCount = 0; $listCount = 0; $intPosition = request("pos"); $intPosition = !empty($intPosition) && is_numeric($intPosition) ? $intPosition : 0; $intPosition = floor($intPosition / $_SESSION["listCount"]) * $_SESSION["listCount"]; //*** Find total count. foreach ($objAliases as $objAlias) { $strAlias = $objAlias->getAlias(); if (!empty($strAlias)) { $totalCount++; } } $objAliases->seek($intPosition); $objLanguages = ContentLanguage::select(); foreach ($objAliases as $objAlias) { $strAlias = $objAlias->getAlias(); if (!empty($strAlias)) { $strUrl = $objAlias->getUrl(); if (is_numeric($strUrl)) { $objElement = Element::selectByPk($strUrl); if (is_object($objElement)) { $strUrlHref = "?eid={$strUrl}&cmd=" . CMD_EDIT . "&cid=" . NAV_PCMS_ELEMENTS; $strUrl = Element::recursivePath($strUrl); } else { $strUrlHref = "?cid=" . NAV_PCMS_ALIASES; $strUrl = "<b>" . $objLang->get("aliasUnavailable", "label") . "</b>"; } } $objTpl->setCurrentBlock("multiview-item"); $objTpl->setVariable("MULTIITEM_VALUE", $objAlias->getId()); $objTpl->setVariable("BUTTON_REMOVE_HREF", "javascript:Alias.remove({$objAlias->getId()});"); $objTpl->setVariable("BUTTON_REMOVE", $objLang->get("delete", "button")); $objTpl->setVariable("MULTIITEM_HREF", "?cid=" . NAV_PCMS_ALIASES . "&eid={$objAlias->getId()}&cmd=" . CMD_EDIT); $objTpl->setVariable("MULTIITEM_TYPE_CLASS", "alias"); $objTpl->setVariable("MULTIITEM_ALIAS", $objAlias->getAlias()); $objTpl->setVariable("MULTIITEM_POINTS_TO", $objLang->get("pointsTo", "label")); $objTpl->setVariable("MULTIITEM_URL", $strUrl); $objTpl->setVariable("MULTIITEM_URL_HREF", $strUrlHref); if ($objLanguages->count() > 1) { if ($objAlias->getLanguageId() > 0) { $strLanguage = ContentLanguage::selectByPK($objAlias->getLanguageId())->getName(); $objTpl->setVariable("MULTIITEM_LANGUAGE", sprintf($objLang->get("forLanguage", "label"), $strLanguage)); } else { $objTpl->setVariable("MULTIITEM_LANGUAGE", $objLang->get("forAllLanguages", "label")); } } else { $objTpl->setVariable("MULTIITEM_LANGUAGE", ""); } if (!$objAlias->getActive()) { $objTpl->setVariable("MULTIITEM_ACTIVE", " class=\"inactive\""); } $objTpl->parseCurrentBlock(); $listCount++; if ($listCount >= $_SESSION["listCount"]) { break; } } } //*** Render page navigation. $pageCount = ceil($totalCount / $_SESSION["listCount"]); if ($pageCount > 0) { $currentPage = ceil(($intPosition + 1) / $_SESSION["listCount"]); $previousPos = $intPosition - $_SESSION["listCount"] > 0 ? $intPosition - $_SESSION["listCount"] : 0; $nextPos = $intPosition + $_SESSION["listCount"] < $totalCount ? $intPosition + $_SESSION["listCount"] : $intPosition; $objTpl->setVariable("PAGENAV_PAGE", sprintf($objLang->get("pageNavigation", "label"), $currentPage, $pageCount)); $objTpl->setVariable("PAGENAV_PREVIOUS", $objLang->get("previous", "button")); $objTpl->setVariable("PAGENAV_PREVIOUS_HREF", "?cid=" . NAV_PCMS_ALIASES . "&pos={$previousPos}"); $objTpl->setVariable("PAGENAV_NEXT", $objLang->get("next", "button")); $objTpl->setVariable("PAGENAV_NEXT_HREF", "?cid=" . NAV_PCMS_ALIASES . "&pos={$nextPos}"); //*** Top page navigation. for ($intCount = 0; $intCount < $pageCount; $intCount++) { $objTpl->setCurrentBlock("multiview-pagenavitem-top"); $position = $intCount * $_SESSION["listCount"]; if ($intCount != $intPosition / $_SESSION["listCount"]) { $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_ALIASES . "&pos={$position}\""); } $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1); $objTpl->parseCurrentBlock(); } //*** Bottom page navigation. for ($intCount = 0; $intCount < $pageCount; $intCount++) { $objTpl->setCurrentBlock("multiview-pagenavitem-bottom"); $position = $intCount * $_SESSION["listCount"]; if ($intCount != $intPosition / $_SESSION["listCount"]) { $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_ALIASES . "&pos={$position}\""); } $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1); $objTpl->parseCurrentBlock(); } } //*** Render list action pulldown. $arrActions[$objLang->get("choose", "button")] = 0; $arrActions[$objLang->get("delete", "button")] = "delete"; foreach ($arrActions as $key => $value) { $objTpl->setCurrentBlock("multiview-listactionitem"); $objTpl->setVariable("LIST_ACTION_TEXT", $key); $objTpl->setVariable("LIST_ACTION_VALUE", $value); $objTpl->parseCurrentBlock(); } $objTpl->setCurrentBlock("multiview"); $objTpl->setVariable("ACTIONS_OPEN", $objLang->get("pcmsOpenActionsMenu", "menu")); $objTpl->setVariable("ACTIONS_CLOSE", $objLang->get("pcmsCloseActionsMenu", "menu")); $objTpl->setVariable("LIST_LENGTH_HREF_10", "href=\"?list=10&cid=" . NAV_PCMS_ALIASES . "\""); $objTpl->setVariable("LIST_LENGTH_HREF_25", "href=\"?list=25&cid=" . NAV_PCMS_ALIASES . "\""); $objTpl->setVariable("LIST_LENGTH_HREF_100", "href=\"?list=100&cid=" . NAV_PCMS_ALIASES . "\""); switch ($_SESSION["listCount"]) { case 10: $objTpl->setVariable("LIST_LENGTH_HREF_10", ""); break; case 25: $objTpl->setVariable("LIST_LENGTH_HREF_25", ""); break; case 100: $objTpl->setVariable("LIST_LENGTH_HREF_100", ""); break; } $objTpl->setVariable("LIST_LENGTH_HREF", "&cid=" . NAV_PCMS_ALIASES); $objTpl->setVariable("LIST_WITH_SELECTED", $objLang->get("withSelected", "label")); $objTpl->setVariable("LIST_ACTION_ONCHANGE", "Alias.multiDo(this, this[this.selectedIndex].value)"); $objTpl->setVariable("LIST_ITEMS_PER_PAGE", $objLang->get("itemsPerPage", "label")); $objTpl->setVariable("BUTTON_LIST_SELECT", $objLang->get("selectAll", "button")); $objTpl->setVariable("BUTTON_LIST_SELECT_HREF", "javascript:Alias.multiSelect()"); $objTpl->parseCurrentBlock(); //*** Form variables. $intActiveLanguage = 0; if ($strCommand == CMD_EDIT) { $objAlias = Alias::selectByPK($intAliasId); $intActiveLanguage = $objAlias->getLanguageId(); $objTpl->setVariable("FORM_ACTIVE_VALUE", $objAlias->getActive() ? "checked=\"checked\"" : ""); $objTpl->setVariable("FORM_ALIAS_VALUE", $objAlias->getAlias()); $objTpl->setVariable("FORM_URL_VALUE", $objAlias->getUrl()); $objTpl->setVariable("FRM_HEADER", $objLang->get("editAlias", "form")); $objTpl->setVariable("FRM_STYLE", ""); $objTpl->setVariable("CMD", CMD_EDIT); $objTpl->touchBlock("alias.edit"); } else { $objTpl->setVariable("FORM_ACTIVE_VALUE", "checked=\"checked\""); $objTpl->setVariable("FRM_HEADER", $objLang->get("addAlias", "form")); if (!$blnError) { $objTpl->setVariable("FRM_STYLE", " style=\"display:none\""); } $objTpl->setVariable("CMD", CMD_ADD); $objTpl->touchBlock("alias.add"); } //*** Languages. $objLanguages = ContentLanguage::select(); foreach ($objLanguages as $objLanguage) { $objTpl->setCurrentBlock("language.item"); $objTpl->setVariable("ID", $objLanguage->getId()); $objTpl->setVariable("LABEL", $objLanguage->getName()); $objTpl->setVariable("SELECTED", $intActiveLanguage == $objLanguage->getId() ? " selected=\"selected\"" : ""); $objTpl->parseCurrentBlock(); } $objTpl->setVariable("ALIASES", $objLang->get("aliases", "label")); $objTpl->setVariable("BUTTON_ADD", $objLang->get("aliasAdd", "button")); $objTpl->setVariable("FRM_LABEL_ACTIVE", $objLang->get("active", "form")); $objTpl->setVariable("FRM_LABEL_ALIAS", $objLang->get("alias", "form")); $objTpl->setVariable("FRM_DESCR_ALIAS", $objLang->get("alias", "tip")); $objTpl->setVariable("FRM_LABEL_LANGUAGE", $objLang->get("language", "form")); $objTpl->setVariable("FRM_DESCR_LANGUAGE", $objLang->get("language", "tip")); $objTpl->setVariable("FRM_LABEL_ALL_LANGUAGES", $objLang->get("allLanguages", "form")); $objTpl->setVariable("FRM_LABEL_URL", $objLang->get("element", "form")); $objTpl->setVariable("FRM_LABEL_SAVE", $objLang->get("save", "button")); $objTpl->setVariable("CID", NAV_PCMS_ALIASES); $objTpl->setVariable("EID", $intAliasId); $objTpl->parseCurrentBlock(); $strReturn = $objTpl->get(); break; case CMD_REMOVE: if (strpos($intAliasId, ',') !== false) { //*** Multiple elements submitted. $arrAliases = explode(',', $intAliasId); $objAliases = Alias::selectByPK($arrAliases); foreach ($objAliases as $objAlias) { $objAlias->delete(); } } else { //*** Single element submitted. $objAlias = Alias::selectByPK($intAliasId); $objAlias->delete(); } //*** Redirect the page. $strReturnTo = request('returnTo'); if (empty($strReturnTo)) { header("Location: " . Request::getUri() . "/?cid=" . request("cid") . "&cmd=" . CMD_LIST); exit; } else { header("Location: " . Request::getURI() . $strReturnTo); exit; } break; } return $strReturn; }