public function getName() { $strReturn = ""; $objSetting = SettingTemplate::selectByPK($this->getSettingId()); if (is_object($objSetting)) { $strReturn = $objSetting->getName(); } return $strReturn; }
function __construct($intAccountId = 0) { global $_CONF; if ($intAccountId == 0) { $this->AccountId = $_CONF['app']['account']->getId(); } else { $this->AccountId = $intAccountId; } $objSettings = SettingTemplate::select("SELECT * FROM pcms_setting_tpl ORDER BY section, sort"); parent::__construct($objSettings); }
public static function selectByName($strName) { global $_CONF; self::$object = "SettingTemplate"; self::$table = "pcms_setting_tpl"; $strSql = sprintf("SELECT * FROM " . self::$table . " WHERE name = %s ORDER BY section, sort", self::quote($strName)); $objSettings = self::select($strSql); if ($objSettings->count() > 0) { return $objSettings->current(); } }
public static function import($strXml, $blnOverwrite = false, $blnKeepSettings = false) { global $objLiveAdmin, $intDefaultLanguage, $_CONF; $objReturn = NULL; $objSettings = NULL; $blnZip = false; //*** Init DOM object. $objDoc = new DOMDocument("1.0", "UTF-8"); $objDoc->formatOutput = false; $objDoc->preserveWhiteSpace = true; if (is_file($strXml)) { $objZip = new dUnzip2($strXml); if (is_object($objZip)) { //*** Zip file. $strXml = $objZip->unzip('data.xml'); if ($strXml !== false) { //*** Fix a unicode bug. Replace forbidden characters (The first 8). for ($intCount = 1; $intCount < 9; $intCount++) { $strHex = str_pad(dechex($intCount), 4, "0", STR_PAD_LEFT); $strXml = preg_replace('/\\x{' . $strHex . '}/u', "", $strXml); } $strXml = preg_replace('/\\x{001f}/u', "", $strXml); $objDoc->loadXML($strXml); $blnZip = true; } } else { //*** XML file. $objDoc->load($strXml); } } else { $objDoc->loadXML($strXml); } //*** Build data structure. foreach ($objDoc->childNodes as $rootNode) { if ($rootNode->nodeName == "Punch") { //*** Valid Punch XML. foreach ($rootNode->childNodes as $accountNode) { if ($accountNode->nodeName == "account") { //*** Account node. if ($blnOverwrite) { $objAccount = Account::getByPunchId($accountNode->getAttribute("punchId")); if (is_object($objAccount) && $blnKeepSettings) { //*** Save settings. $objSettings = Settings::getByAccount($objAccount->getId()); } //*** Remove account. if (is_object($objAccount)) { $objAccount->delete(); } } //*** Create account. $objAccount = new Account(); $objAccount->setPunchId($accountNode->getAttribute("punchId")); $objAccount->setName($accountNode->getAttribute("name")); $objAccount->setUri($accountNode->getAttribute("uri")); $objAccount->setTimeZoneId(42); $objAccount->save(); //*** Create temporary account object. $_CONF['app']['account'] = $objAccount; foreach ($accountNode->childNodes as $childNode) { $arrUserIds = array(); $arrGroupIds = array(); switch ($childNode->nodeName) { case "acl": self::importAcl($childNode, $objAccount->getId(), $arrUserIds, $arrGroupIds); break; case "products": //*** Add products to the account. foreach ($childNode->childNodes as $productNode) { switch ($productNode->nodeName) { case "pcms": //*** Add PunchCMS product to the account. $objAccountProduct = new AccountProduct(); $objAccountProduct->setAccountId($objAccount->getId()); $objAccountProduct->setProductId(PRODUCT_PCMS); $objAccountProduct->setExpires($productNode->getAttribute("expires")); $objAccountProduct->save(); $arrStorageIds[0] = 0; $arrFeedIds[0] = 0; //*** Add PunchCMS data to the account. foreach ($productNode->childNodes as $pcmsNode) { switch ($pcmsNode->nodeName) { case "settings": //*** Add settings to the account. if ($blnKeepSettings && is_object($objSettings)) { foreach ($objSettings as $objSetting) { $objSetting->setId(0); $objSetting->setAccountId($objAccount->getId()); $objSetting->save(); } } else { foreach ($pcmsNode->childNodes as $settingNode) { $objSettingTemplate = SettingTemplate::selectByName($settingNode->getAttribute("name")); if (is_object($objSettingTemplate)) { $objSetting = new Setting(); $objSetting->setAccountId($objAccount->getId()); $objSetting->setSettingId($objSettingTemplate->getId()); $objSetting->setValue($settingNode->getAttribute("value")); $objSetting->save(); } } } break; case "languages": //*** Add languages to the account. $arrLanguageIds[0] = 0; foreach ($pcmsNode->childNodes as $languageNode) { $objLanguage = new ContentLanguage(); $objLanguage->setAccountId($objAccount->getId()); $objLanguage->setName($languageNode->getAttribute("name")); $objLanguage->setAbbr($languageNode->getAttribute("abbr")); $objLanguage->default = $languageNode->getAttribute("default"); $objLanguage->setActive($languageNode->getAttribute("active")); $objLanguage->setSort($languageNode->getAttribute("sort")); $objLanguage->setUsername($languageNode->getAttribute("username")); $objLanguage->save(); $arrLanguageIds[$languageNode->getAttribute("id")] = $objLanguage->getId(); if ($languageNode->getAttribute("default") == 1) { $intDefaultLanguage = $objLanguage->getId(); } } break; case "feeds": //*** Add feeds to the account. $arrFeedIds[0] = 0; foreach ($pcmsNode->childNodes as $feedNode) { $objFeed = new Feed(); $objFeed->setAccountId($objAccount->getId()); $objFeed->setName($feedNode->getAttribute("name")); $objFeed->setFeed($feedNode->getAttribute("feed")); $objFeed->setBasePath($feedNode->getAttribute("basepath")); $objFeed->setRefresh($feedNode->getAttribute("refresh")); $objFeed->setLastUpdate($feedNode->getAttribute("lastUpdate")); $objFeed->setActive($feedNode->getAttribute("active")); $objFeed->setSort($feedNode->getAttribute("sort")); $objFeed->save(); $arrFeedIds[$feedNode->getAttribute("id")] = $objFeed->getId(); } break; case "storage": //*** Add media items to the account. self::importStorage($pcmsNode, $objAccount->getId(), $arrStorageIds); break; case "templates": //*** Add templates to the account. $arrTemplateIds[0] = 0; $arrTemplateFieldIds[0] = 0; $arrLinkFieldIds = array(); self::importTemplates($pcmsNode, $objAccount->getId(), $arrTemplateIds, $arrTemplateFieldIds, $arrLinkFieldIds); break; case "elements": //*** Add elements to the account. $arrElementIds[0] = 0; $arrElementFieldIds["link"][0] = 0; $arrElementFieldIds["largeText"][0] = 0; self::importElements($pcmsNode, $objAccount->getId(), $arrTemplateIds, $arrTemplateFieldIds, $arrElementIds, $arrElementFieldIds, $arrLinkFieldIds, $arrLanguageIds, $arrUserIds, $arrGroupIds, $arrStorageIds, $arrFeedIds); break; case "aliases": //*** Add aliases to the account. foreach ($pcmsNode->childNodes as $aliasNode) { $objAlias = new Alias(); $objAlias->setAccountId($objAccount->getId()); $objAlias->setAlias($aliasNode->getAttribute("alias")); if (array_key_exists($aliasNode->getAttribute("url"), $arrElementIds)) { $objAlias->setUrl($arrElementIds[$aliasNode->getAttribute("url")]); } else { $objAlias->setUrl(0); } if (array_key_exists($aliasNode->getAttribute("language"), $arrLanguageIds)) { $objAlias->setLanguageId($arrLanguageIds[$aliasNode->getAttribute("language")]); } else { $objAlias->setLanguageId(0); } $objAlias->setCascade($aliasNode->getAttribute("cascade")); $objAlias->setActive($aliasNode->getAttribute("active")); $objAlias->setSort($aliasNode->getAttribute("sort")); $objAlias->setCreated($aliasNode->getAttribute("created")); $objAlias->setModified($aliasNode->getAttribute("modified")); $objAlias->save(); } break; } } //*** Adjust the links for deeplink fields. self::adjustDeeplinks($arrElementFieldIds["link"], $arrElementIds, $arrLanguageIds); //*** Adjust the links in large text fields. self::adjustTextlinks($arrElementFieldIds["largeText"], $arrElementIds, $arrLanguageIds, $arrStorageIds); break; } } break; } } //*** Destroy temporary account object. unset($_CONF['app']['account']); $objReturn = $objAccount; } } } } //*** Files. if ($blnZip && is_object($objReturn)) { self::importFiles($objZip, $objReturn); if ($blnKeepSettings) { //*** Move files to remote server. self::moveImportedFiles($objReturn); } } return $objReturn; }
function parseSetting($intElmntId, $strCommand) { global $_PATHS, $objLang, $_CLEAN_POST, $_CONF, $objLiveUser; $objTpl = new HTML_Template_IT($_PATHS['templates']); $objTpl->loadTemplatefile("setting.tpl.htm"); //*** Post the profile form if submitted. if (count($_CLEAN_POST) > 0 && !empty($_CLEAN_POST['dispatch']) && $_CLEAN_POST['dispatch'] == "editSettings") { //*** The element form has been posted. $blnError = false; //*** Check sanitized input. if (is_null($_CLEAN_POST["dispatch"])) { $blnError = true; } if ($blnError === true) { //*** Display global error. $objTpl->setVariable("ERROR_SETTINGS_MAIN", $objLang->get("main", "formerror")); } else { //*** Remove current settings. Setting::clearFields(); //*** Save the settings. foreach ($_REQUEST as $key => $value) { if ($value != "" && substr($key, 0, 4) == "sfv_") { //*** Get the template Id from the request $intTemplateFieldId = substr($key, 4); //*** Is the Id really an Id? if (is_numeric($intTemplateFieldId)) { //*** Save the setting. if (!empty($value)) { $objField = new Setting(); $objField->setAccountId($_CONF['app']['account']->getId()); $objField->setSettingId($intTemplateFieldId); $objField->setUsername($objLiveUser->getProperty('name')); $objSettingTemplate = SettingTemplate::selectByPk($intTemplateFieldId); switch ($objSettingTemplate->getType()) { case "text": case "number": case "password": $objField->setValue($value); break; case "checkbox": $objField->setValue(1); break; } $objField->save(); } } } } //*** Move imported files to the remote server. ImpEx::moveImportedFiles($_CONF['app']['account']); header("Location: " . Request::getURI() . "/?cid=" . $_POST["cid"]); exit; } } $objTpl->setVariable("SETTINGS", $objLang->get("settings", "label")); $objSections = SettingTemplate::select("SELECT DISTINCT section FROM pcms_setting_tpl ORDER BY sort"); foreach ($objSections as $objSection) { //*** Fields. $strSql = sprintf("SELECT * FROM pcms_setting_tpl WHERE section = '%s' ORDER BY sort", $objSection->getSection()); $objSettings = SettingTemplate::select($strSql); foreach ($objSettings as $objSetting) { $strValue = Setting::getValueByName($objSetting->getName()); $objTpl->setCurrentBlock("setting.{$objSetting->getType()}"); $objTpl->setVariable("FIELD_ID", "sfv_{$objSetting->getId()}"); $objTpl->setVariable("FIELD_LABEL", $objLang->get($objSetting->getName(), "settingsLabel")); switch ($objSetting->getType()) { case "text": case "password": $objTpl->setVariable("FIELD_VALUE", $strValue); $objTpl->setVariable("FIELD_TYPE", $objSetting->getType()); break; case "number": $objTpl->setVariable("FIELD_VALUE", $strValue); break; case "checkbox": $strValue = $strValue ? "checked=\"checked\"" : ""; $objTpl->setVariable("FIELD_VALUE", $strValue); break; } $objTpl->parseCurrentBlock(); } $objTpl->setCurrentBlock("section"); $objTpl->setVariable("SECTION", $objSetting->getSection()); if ($objSections->key() != 0) { $objTpl->setVariable("CLASS", " class=\"anchor\""); } $objTpl->parseCurrentBlock(); //*** Tabs. $objTpl->setCurrentBlock("section.tab"); $objTpl->setVariable("SECTION", $objSection->getSection()); $objTpl->setVariable("LABEL", $objLang->get("section_{$objSection->getSection()}", "settingsLabel")); if ($objSections->key() == 0) { $objTpl->setVariable("CLASS", " class=\"on\""); } $objTpl->parseCurrentBlock(); } $objTpl->setVariable("LABEL_SAVE", $objLang->get("save", "button")); $objTpl->setVariable("CID", NAV_PCMS_SETTINGS); $objTpl->setVariable("CMD", $strCommand); $objTpl->setVariable("EID", $intElmntId); $objTpl->parseCurrentBlock(); $strReturn = $objTpl->get(); return $strReturn; }