コード例 #1
0
ファイル: class.settings.php プロジェクト: laiello/punchcms
 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);
 }
コード例 #2
0
ファイル: class.impex.php プロジェクト: laiello/punchcms
 public static function export($intAccountId = 0, $exportFiles = true)
 {
     global $objLiveAdmin, $_CONF, $_PATHS;
     //*** Init DOM object.
     $objDoc = new DOMDocument("1.0", "UTF-8");
     $objDoc->formatOutput = false;
     $objDoc->preserveWhiteSpace = true;
     //*** Init Zip archive.
     $strZipName = $_PATHS['upload'] . "exportZip_" . rand() . ".zip";
     $objZip = new dZip($strZipName, true);
     //*** ACL. Users, groups and rights.
     $objAcl = self::exportAcl($objDoc, $intAccountId);
     //*** Products.
     $_CONF['app']['account'] = Account::getById($intAccountId);
     $objAccountProducts = AccountProduct::getByAccountId($intAccountId);
     $objProducts = $objDoc->createElement('products');
     foreach ($objAccountProducts as $objAccountProduct) {
         switch ($objAccountProduct->getProductId()) {
             case PRODUCT_PCMS:
                 $arrFiles = array();
                 //*** Settings.
                 $objSettings = $objDoc->createElement('settings');
                 $objDbSettings = SettingTemplate::select("SELECT * FROM pcms_setting_tpl ORDER BY section, sort");
                 foreach ($objDbSettings as $objDbSetting) {
                     $objSetting = $objDoc->createElement('setting');
                     $objSetting->setAttribute("name", $objDbSetting->getName());
                     $objSetting->setAttribute("value", Setting::getValueByName($objDbSetting->getName(), $intAccountId));
                     $objSetting->setAttribute("section", $objDbSetting->getSection());
                     $objSettings->appendChild($objSetting);
                 }
                 //*** Languages.
                 $objLanguages = $objDoc->createElement('languages');
                 $objContentLangs = ContentLanguage::select();
                 foreach ($objContentLangs as $objContentLang) {
                     $objLanguage = $objDoc->createElement('language');
                     $objLanguage->setAttribute("id", $objContentLang->getId());
                     $objLanguage->setAttribute("name", $objContentLang->getName());
                     $objLanguage->setAttribute("abbr", $objContentLang->getAbbr());
                     $objLanguage->setAttribute("default", $objContentLang->default);
                     $objLanguage->setAttribute("active", $objContentLang->getActive());
                     $objLanguage->setAttribute("sort", $objContentLang->getSort());
                     $objLanguage->setAttribute("username", $objContentLang->getUsername());
                     $objLanguages->appendChild($objLanguage);
                 }
                 //*** External feeds.
                 $objFeeds = $objDoc->createElement('feeds');
                 $objDbFeeds = Feed::select();
                 foreach ($objDbFeeds as $objDbFeed) {
                     $objFeed = $objDoc->createElement('feed');
                     $objFeed->setAttribute("id", $objDbFeed->getId());
                     $objFeed->setAttribute("name", $objDbFeed->getName());
                     $objFeed->setAttribute("feed", $objDbFeed->getFeed());
                     $objFeed->setAttribute("basepath", $objDbFeed->getBasepath());
                     $objFeed->setAttribute("refresh", $objDbFeed->getRefresh());
                     $objFeed->setAttribute("lastUpdate", $objDbFeed->getLastUpdate());
                     $objFeed->setAttribute("active", $objDbFeed->getActive());
                     $objFeed->setAttribute("sort", $objDbFeed->getSort());
                     $objFeed->setAttribute("created", $objDbFeed->getCreated());
                     $objFeed->setAttribute("modified", $objDbFeed->getModified());
                     $objFeeds->appendChild($objFeed);
                 }
                 //*** Storage items.
                 $objStorage = self::exportStorage($objDoc, $intAccountId, 0, $arrFiles);
                 //*** Templates.
                 $objTemplates = self::exportTemplate($objDoc, $intAccountId, 0);
                 //*** Elements.
                 $objElements = self::exportElement($objDoc, $intAccountId, 0, $arrFiles);
                 //*** Aliases.
                 $objAliases = $objDoc->createElement('aliases');
                 $objDbAliases = Alias::select();
                 foreach ($objDbAliases as $objDbAlias) {
                     $objAlias = $objDoc->createElement('alias');
                     $objAlias->setAttribute("language", $objDbAlias->getLanguageId());
                     $objAlias->setAttribute("cascade", $objDbAlias->getCascade());
                     $objAlias->setAttribute("alias", $objDbAlias->getAlias());
                     $objAlias->setAttribute("url", $objDbAlias->getUrl());
                     $objAlias->setAttribute("active", $objDbAlias->getActive());
                     $objAlias->setAttribute("sort", $objDbAlias->getSort());
                     $objAlias->setAttribute("created", $objDbAlias->getCreated());
                     $objAlias->setAttribute("modified", $objDbAlias->getModified());
                     $objAliases->appendChild($objAlias);
                 }
                 //*** Product.
                 $objProduct = $objDoc->createElement('pcms');
                 $objProduct->setAttribute("version", APP_VERSION);
                 $objProduct->setAttribute("expires", $objAccountProduct->getExpires());
                 $objProduct->appendChild($objSettings);
                 $objProduct->appendChild($objLanguages);
                 $objProduct->appendChild($objFeeds);
                 $objProduct->appendChild($objStorage);
                 $objProduct->appendChild($objTemplates);
                 $objProduct->appendChild($objElements);
                 $objProduct->appendChild($objAliases);
                 $objProducts->appendChild($objProduct);
                 //*** Files.
                 if ($exportFiles) {
                     $strServer = Setting::getValueByName("ftp_server");
                     if ($strServer != "localhost") {
                         $strLocation = "http://" . Setting::getValueByName("ftp_server") . Setting::getValueByName("file_folder");
                         $objZip = self::exportFilesToZip($objZip, $arrFiles, $strLocation);
                     }
                 }
                 break;
         }
     }
     //*** Account.
     $objDbAccount = Account::selectByPk($intAccountId);
     $objAccount = $objDoc->createElement('account');
     $objAccount->setAttribute("punchId", $objDbAccount->getPunchId());
     $objAccount->setAttribute("name", $objDbAccount->getName());
     $objAccount->setAttribute("uri", $objDbAccount->getUri());
     $objAccount->appendChild($objAcl);
     $objAccount->appendChild($objProducts);
     $objPunch = $objDoc->createElement('Punch');
     $objPunch->appendChild($objAccount);
     $objRoot = $objDoc->appendChild($objPunch);
     //*** Destroy temporary account object.
     unset($_CONF['app']['account']);
     //*** Return XML.
     $objZip->addFile(NULL, 'data.xml', "", $objDoc->saveXML());
     $objZip->save();
     return $strZipName;
 }
コード例 #3
0
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;
}