protected function saveSettings($values) { $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $config->modules->contrib->CurryCron->token = $values['token']; $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); }
protected function saveConfig(array $values) { $this->addBreadcrumb('Configurations', url('', array('module'))); $this->addBreadcrumb('saveConfig', url()); $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $config->modules = array('contrib' => array('CurryGearman' => array('jobHandler' => trim($values['job_handler']) ?: null, 'token' => $values['token']))); try { $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); $this->flushConfigCache(); $this->addMessage("Settings saved.", self::MSG_SUCCESS); } catch (Exception $e) { $this->addMessage($e->getMessage(), self::MSG_ERROR); } }
/** {@inheritdoc} */ public function showMain() { if (!is_writable(Curry_Core::$config->curry->configPath)) { $this->addMessage("Configuration file doesn't seem to be writable.", self::MSG_ERROR); } $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $pages = PagePeer::getSelect(); $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('enabled' => array('checkbox', array('label' => 'Enable domain mapping', 'value' => $config->curry->domainMapping->enabled)), 'default_base_page' => array('select', array('label' => 'Default base page', 'description' => 'The default base page will only be used if there are no other domains matching and domain mapping is enabled', 'value' => $config->curry->domainMapping->default, 'multiOptions' => array('' => '[ None ]') + $pages))))); $domainForm = new Curry_Form_Dynamic(array('legend' => 'Domain', 'elements' => array('domain' => array('text', array('label' => 'Domain', 'description' => 'You can use default as a wildcard to fetch unmatched domains.', 'required' => true)), 'base_page' => array('select', array('label' => 'Base page', 'multiOptions' => array('' => '[ None ]') + $pages, 'required' => true)), 'include_www' => array('checkbox', array('label' => 'Include www'))))); $form->addSubForm(new Curry_Form_MultiForm(array('legend' => '', 'cloneTarget' => $domainForm, 'defaults' => $config->curry->domainMapping->domains ? $config->curry->domainMapping->domains->toArray() : array())), 'domainMapping'); $form->addElement('submit', 'save', array('label' => 'Save')); if (isPost() && $form->isValid($_POST)) { $values = $form->getValues(); if (!$config->curry->domainMapping) { $config->curry->domainMapping = array(); } $config->curry->domainMapping->enabled = count($values['domainMapping']) ? (bool) $values['enabled'] : false; $config->curry->domainMapping->default = $values['default_base_page']; $config->curry->domainMapping->domains = $values['domainMapping']; try { $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); if (extension_loaded('apc')) { if (function_exists('apc_delete_file')) { @apc_delete_file(Curry_Core::$config->curry->configPath); } else { @apc_clear_cache(); } } $this->addMessage("Settings saved.", self::MSG_SUCCESS); } catch (Exception $e) { $this->addMessage($e->getMessage(), self::MSG_ERROR); } } $this->addMainContent($form); }
public function testArgumentOverride() { $config = new Zend_Config(array('test' => 'foo')); $writer = new Zend_Config_Writer_Array(); $writer->write($this->_tempName, $config); $config = new Zend_Config(include $this->_tempName); $this->assertEquals('foo', $config->test); }
/** * Migrate curry to newer version. */ public function showUpgrade() { $this->addMainMenu(); $releases = self::getReleases(); if ($releases === null) { $this->addMessage('Unable to check for new releases', self::MSG_WARNING); } else { $latest = count($releases) ? array_pop($releases) : null; if ($latest) { $this->addMessage('Installed version: ' . Curry_Core::VERSION); $this->addMessage('Latest version: ' . $latest->version); if (version_compare($latest->version, Curry_Core::VERSION, '>')) { $this->addMessage('New release found: ' . $latest->name); } else { $this->addMessage('You already have the latest version.', self::MSG_SUCCESS); } } else { $this->addMessage('No releases could be found.', self::MSG_WARNING); } } if (!Curry_Core::requireMigration()) { return; } $form = self::getButtonForm('migrate', 'Migrate'); if (isPost() && $form->isValid($_POST) && $form->migrate->isChecked()) { $currentVersion = Curry_Core::$config->curry->migrationVersion; while ($currentVersion < Curry_Core::MIGRATION_VERSION) { $nextVersion = $currentVersion + 1; $migrateMethod = 'doMigrate' . $nextVersion; if (method_exists($this, $migrateMethod)) { try { if ($this->{$migrateMethod}()) { // update configuration migrateVersion number $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $config->curry->migrateVersion = $nextVersion; $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); $currentVersion = $nextVersion; $this->addMessage('Migration to version ' . $nextVersion . ' was successful!', self::MSG_SUCCESS); } else { $this->addMessage("Migrating to version {$nextVersion} returned failure.", self::MSG_ERROR); break; } } catch (Exception $e) { $this->addMessage("Unable to migrate to version {$nextVersion}: " . $e->getMessage(), self::MSG_ERROR); break; } } else { $this->addMessage("Unable to find migration method '{$migrateMethod}'.", self::MSG_ERROR); break; } } } else { $backupUrl = url('', array('module', 'view' => 'Bundle')); $this->addMessage('Curry CMS has been updated and you need to migrate your project before you can continue using the backend. You should <a href="' . $backupUrl . '">backup</a> your data and click the migrate button when you\'re ready!', Curry_Backend::MSG_WARNING, false); $this->addMainContent($form); } }
/** * write config to a file * * @param array $_data * @param boolean $_merge * @param string $_filename * @return Zend_Config */ public function writeConfigToFile($_data, $_merge, $_filename) { // merge config data and active config if ($_merge) { $activeConfig = Setup_Core::get(Setup_Core::CONFIG); $config = new Zend_Config($activeConfig->toArray(), true); $config->merge(new Zend_Config($_data)); } else { $config = new Zend_Config($_data); } // write to file Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating config.inc.php'); $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => $_filename)); $writer->write(); return $config; }
public function writeOauthToken($token, $tokenSecret) { $config = Tweetgater_Twitter::getConfigFile(true); $config->oauth->token = $token; $config->oauth->tokenSecret = $tokenSecret; $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => Tweetgater_Twitter::getConfigFilePath())); $writer->write(); }
/** * Create cached version of navigation translations file for the give file and locale * * @param string $filepath Navigation translation file path Filepath * @param string $locale Locale * @param string $userLevel User level for which the file is created * @throws Zend_Config_Exception * @throws iMSCP_Exception */ function layout_createNavigationFile($filepath, $locale, $userLevel) { $translationsCacheDir = CACHE_PATH . '/translations/navigation'; if (!is_dir($translationsCacheDir)) { if (!@mkdir($translationsCacheDir)) { throw new iMSCP_Exception('Unable to create cache directory for navigation translations'); } } $config = new Zend_Config(include $filepath); $writter = new Zend_Config_Writer_Array(); $writter->setConfig($config); $writter->write($translationsCacheDir . '/' . $userLevel . '_' . $locale . '.php'); }
/** * Do auto rebuild. * * * Backup database. * * Rebuild propel class files. * * Create tables. * * Restore database. * */ public function doAutoRebuild() { if (!is_writable(Curry_Core::$config->curry->configPath)) { $this->addMessage("Configuration file doesn't seem to be writable.", self::MSG_ERROR); return; } $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $restoreConfig = clone $config; $config->curry->backend->noauth = true; if (!$config->curry->maintenance->enabled || $config->curry->maintenance->page) { $config->curry->maintenance->enabled = true; $config->curry->maintenance->page = false; $config->curry->maintenance->message = "Rebuilding database, please wait..."; } $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); try { $filename = Curry_Backend_DatabaseHelper::createBackupName('backup_%Y-%m-%d_%H-%M-%S_autorebuild.txt'); $this->beginDetails('Dumping database to: ' . $filename); $status = Curry_Backend_DatabaseHelper::dumpDatabase($filename, null, $this); $this->endDetails(); if (!$status) { throw new Exception('Aborting: There was an error when dumping the database.'); } if (class_exists('Project', false)) { throw new Exception('Aborting: Table named Project detected, autorebuild will fail, use manual build/restore or rename the project table'); } if (!$this->doPropelGen()) { throw new Exception('Failed to rebuild propel'); } if (!$this->doPropelGen('insert-sql')) { throw new Exception('Failed to rebuild database'); } // use remote url to restore (because rebuilding above may change class definitions) $url = url('', array("module", "view" => "AutoRestore", "file" => $filename)); $content = file_get_contents($url->getAbsolute('&', true)); $this->addMessage('Restore: ' . $content, $content == 'ok' ? self::MSG_SUCCESS : self::MSG_ERROR); } catch (Exception $e) { $this->addMessage($e->getMessage(), self::MSG_ERROR); } if ($restoreConfig !== null) { $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $restoreConfig); } }
private static function writeCacheFile($cacheFile, $config) { require_once 'Zend/Config/Writer/Array.php'; $writer = new Zend_Config_Writer_Array(); $writer->write($cacheFile, $config); }
/** * Translate a phrase of words, or array of phrases * * @param string|array $phrase * @param array $params Params are used to replace in $phrase * @param string $langCode Default is null. If $langCode == null, it will use Vi_Registry::get('langCode') * * @return string|array * @throws Exception if language file is not readable, or $phrase is not string/array * * @example * $this->translate2('Version {{0}} is good', * array('1.0'), 'en'); * //Result: 'Version 1.0 is good'; * * * $this->translate2(array('Version {{0}} is good', * 'But version {{0}} is better than version {{1}}'), * array( * array( * '1.0' * ), * array( * '2.0', * '1.0' * ) * ), * 'en'); * * //Result: array('Version 1.0 is good', 'But version 2.0 is better than version 1.0') */ public function translate2($phrase, $params = array(), $langCode = null) { if (null == $langCode) { $langCode = Vi_Registry::get('langCode'); } else { /** * @TODO Check $langCode to sure it has in system's languages */ } if (null == $phrase) { return ''; } if (!isset($this->_name[self::$currentType])) { $this->_name[self::$currentType] = ''; } if (!isset($this->_translatedPhrases[self::$currentType])) { $this->_translatedPhrases[self::$currentType] = array(); } if (!isset($this->_translatedPhrases[self::$currentType][$langCode])) { $this->_translatedPhrases[self::$currentType][$langCode] = array(); } /** * Detect module, or layout, or sticker */ if (self::$currentType == self::TYPE_MODULE) { $path = 'languages/module.' . self::$currentName; } elseif (self::$currentType == self::TYPE_LAYOUT) { $config = Vi_Registry::get('config'); self::$currentName = $config['layoutCollection']; $path = 'languages/layout.' . self::$currentName; } else { $path = 'languages/sticker.' . self::$currentName; } /** * Load language file */ $this->_filePath = "{$path}.{$langCode}.php"; if (!is_writable('languages')) { throw new Exception('Language folder languages' . '" is not writable. Please change it to 777 mode.'); } if ($this->_name[self::$currentType] != self::$currentName || empty($this->_translatedPhrases[self::$currentType][$langCode])) { if (is_file($this->_filePath)) { if (is_readable($this->_filePath)) { $this->_translatedPhrases[self::$currentType][$langCode] = (require_once "{$this->_filePath}"); } else { throw new Exception("Permission denied. Language file ({$this->_filePath}) is not readable."); } $this->isTranslated = true; } else { $this->isTranslated = false; } $this->_name[self::$currentType] = self::$currentName; } /** * Begin translation */ $return = ''; if (is_string($phrase)) { if (array_key_exists($phrase, $this->_translatedPhrases[self::$currentType][$langCode])) { $return = $this->_translatedPhrases[self::$currentType][$langCode][$phrase]; if (null == $return) { return "[{$phrase}]"; } else { return $return; } } else { /** * Not is translated yet */ $this->isTranslated = false; $this->_translatedPhrases[self::$currentType][$langCode][$phrase] = ''; $return = "[{$phrase}]"; } } elseif (is_array($phrase)) { foreach ($phrase as $item) { if (array_key_exists($item, $this->_translatedPhrases[self::$currentType][$langCode])) { $return[$item] = $this->_translatedPhrases[self::$currentType][$langCode][$item]; if (null == $return[$item]) { $return[$item] = "[{$item}]"; } } else { /** * Not is translated yet */ $this->isTranslated = false; $this->_translatedPhrases[self::$currentType][$langCode][$item] = ''; $return[$item] = "[{$item}]"; } } } else { throw new Exception("The param of Vi_Language::translate() is not correct. Params have to be string or array"); } /** * Write language file */ if (!$this->isTranslated) { $this->_writer->write($this->_filePath, new Zend_Config($this->_translatedPhrases[self::$currentType][$langCode])); } /** * Translate with params */ if (is_array($params) && !empty($params)) { if (is_string($phrase)) { $find = array(); $replace = array(); for ($i = 0; $i < count($params); $i++) { $find[] = "{{$i}}"; $replace[] = $params[$i]; } $return = str_replace($find, $replace, $return); } elseif (is_array($phrase)) { foreach ($phrase as $index => $item) { if (is_array($params[$index]) && !empty($params[$index])) { $find = array(); $replace = array(); for ($i = 0; $i < count($params[$index]); $i++) { $find[] = "{{$i}}"; $replace[] = $params[$index][$i]; } $return[$item] = str_replace($find, $replace, $return[$item]); } } } } return $return; }
/** * Unregister a callback so that it is not executed for a specific hook. * * @param string $name * @param callback $callback */ public static function unregisterHook($name, $callback) { $config = new Zend_Config(require Curry_Core::$config->curry->hooksPath, true); $hooks = $config->toArray(); if (array_key_exists($name, $hooks)) { foreach ($hooks[$name] as $key => $hook) { if ($hook === $callback) { unset($hooks[$name][$key]); } } } self::$hooks = $hooks; $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->hooksPath, new Zend_Config($hooks)); }
public function saveConfiguration($values) { // Restore database from backup? if ($values['template'] == 'backup') { if (!Curry_Backend_DatabaseHelper::restoreFromFile('db.txt')) { $this->addMessage('Unable to restore database content from db.txt', self::MSG_WARNING); } } // Create admin user if ($values['admin']['username']) { $access = array('*', 'Curry_Backend_Content/*'); $adminRole = self::createRole('Super', $access); $adminUser = self::createUser($values['admin']['username'], $values['admin']['password'], $adminRole); if ($adminUser->isNew()) { self::createFilebrowserAccess($adminRole, 'Root', ''); } $adminUser->save(); } // Create light user if ($values['user']['username']) { $access = array('Curry_Backend_FileBrowser', 'Curry_Backend_Page', 'Curry_Backend_Profile', 'Curry_Backend_Translations', 'Curry_Backend_Content/*'); $userRole = self::createRole('User', $access); $user = self::createUser($values['user']['username'], $values['user']['password'], $userRole); if ($user->isNew()) { $user->save(); self::createFilebrowserAccess($user, 'Home', 'user-content/' . $user->getUserId() . '/'); self::createFilebrowserAccess($userRole, 'Shared', 'content/'); } $user->save(); } if ($values['template'] != 'backup') { // Create default meta-data items $metadatas = array('Title' => 'text', 'Keywords' => 'textarea', 'Description' => 'textarea', 'Image' => 'previewImage'); foreach ($metadatas as $name => $type) { $metadata = new Metadata(); $metadata->setName($name); $metadata->setDisplayName($name); $metadata->setType($type); $metadata->save(); } $page = new Page(); $page->setName("Home"); $page->setURL("/"); $page->setVisible(true); $page->setEnabled(true); $page->makeRoot(); $page->save(); $page->createDefaultRevisions(); $page->save(); $pageRev = $page->getWorkingPageRevision(); $pageRev->setTemplate('Root.html'); $pageRev->save(); $pa = new PageAccess(); $pa->setPage($page); $pa->setPermSubpages(true); $pa->setPermVisible(true); $pa->setPermCreatePage(true); $pa->setPermCreateModule(true); $pa->setPermPublish(true); $pa->setPermProperties(true); $pa->setPermContent(true); $pa->setPermMeta(true); $pa->setPermModules(true); $pa->setPermRevisions(true); $pa->setPermPermissions(true); $pa->save(); } // Create template root $templateRoot = Curry_Core::$config->curry->template->root; if (!file_exists($templateRoot)) { @mkdir($templateRoot, 0777, true); } switch ($values['template']) { case 'empty': case 'curry': $source = Curry_Util::path(Curry_Core::$config->curry->wwwPath, 'shared', 'backend', 'common', 'templates', 'project-empty.html'); $templateFile = Curry_Util::path($templateRoot, 'Root.html'); if (!file_exists($templateFile)) { @copy($source, $templateFile); } break; case 'twitter-bootstrap': case 'html5boilerplate': } if (file_exists(Curry_Core::$config->curry->configPath)) { $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true); $config->curry->name = $values['name']; $config->curry->adminEmail = $values['email']; if ($values['base_url']) { $config->curry->baseUrl = $values['base_url']; } else { unset($config->curry->baseUrl); } $config->curry->developmentMode = (bool) $values['development_mode']; $config->curry->secret = sha1(uniqid(mt_rand(), true) . microtime()); $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); } return true; }
protected function saveToCurryConfig($values, &$config) { $this->ignoredPaths = (array) explode("\r\n", $values['ignore_paths']); // cleanup last empty value from array $this->ignoredPaths = array_filter($this->ignoredPaths, function ($val) { return !empty($val); }); $this->ignoredFileExtensions = (array) explode("\r\n", $values['ignore_file_extensions']); $this->ignoredFileExtensions = array_filter($this->ignoredFileExtensions, function ($val) { return !empty($val); }); $config->project->cleanup_file_system->ignore_paths = implode(',', $this->ignoredPaths); $config->project->cleanup_file_system->ignore_file_extensions = implode(',', $this->ignoredFileExtensions); try { $writer = new Zend_Config_Writer_Array(); $writer->write(Curry_Core::$config->curry->configPath, $config); if (extension_loaded('apc')) { if (function_exists('apc_delete_file')) { @apc_delete_file(Curry_Core::$config->curry->configPath); } else { @apc_clear_cache(); } } $this->addMessage("Settings saved.", self::MSG_SUCCESS); } catch (Exception $e) { throw $e; } }
/** * @param $pathToSave Путь к файлу в котором будет сохранен конфиг приложения. */ protected function _saveCache($pathToSave) { $writer = new Zend_Config_Writer_Array(); $options = $this->getOptions(); if (array_key_exists('config', $options)) { unset($options['config']); } $writer->setConfig(new Zend_Config($options)); try { $writer->write($pathToSave); } catch (Zend_Config_Exception $exception) { return; } }
public function writeConfigData() { try { $configArray = array("entrada_url" => $this->entrada_url, "entrada_relative" => $this->entrada_relative, "entrada_absolute" => $this->entrada_absolute, "entrada_storage" => $this->entrada_storage, "database" => array("adapter" => $this->database_adapter, "host" => $this->database_host, "username" => $this->database_username, "password" => $this->database_password, "entrada_database" => $this->entrada_database, "auth_database" => $this->auth_database, "clerkship_database" => $this->clerkship_database), "admin" => array("firstname" => $this->admin_firstname, "lastname" => $this->admin_lastname, "email" => $this->admin_email), "auth_username" => $this->auth_username, "auth_password" => $this->auth_password); $config = new Zend_Config($configArray); $writer = new Zend_Config_Writer_Array(); $writer->write($this->config_file_path, $config); } catch (Zend_Config_Exception $e) { return false; } return true; }
private function makeFile($gen_type, $gen_action = NULL) { $cnf = Zend_Registry::get('cnf'); $action = $this->model->getPrefix($gen_action); $type = $this->model->getSuffix($gen_type); $dirname = $cnf->path->modules . $this->modulename . "/{$type}s/"; $template = $this->model->getTemplate($gen_type, $gen_action); switch ($gen_type) { case Step4Model::GEN_CONTROLLER: $filename = $cnf->path->modules . $this->modulename . "/controllers/" . ucfirst($action) . "Controller.php"; break; case Step4Model::GEN_MODEL: $filename = $cnf->path->models . $this->modulename . "Model.php"; break; case Step4Model::GEN_VIEW: $dirname .= "/scripts/{$action}/"; $filename = $cnf->path->modules . $this->modulename . "/views/scripts/{$action}/index.tpl"; break; case Step4Model::GEN_CONFIG: $filename = $cnf->path->modules . $this->modulename . "/config.php"; break; } if (!is_dir($dirname)) { mkdir($dirname, 0777, true); } if ($gen_type != Step4Model::GEN_CONFIG) { $file = fopen($filename, "w+") or die("Failed on create {$filename}"); fwrite($file, $template); fclose($file); } else { $c = new Zend_Config($this->view->step3_data, true); $c->tablename = $this->tablename; $config = new Zend_Config_Writer_Array(array('config' => $c, 'filename' => $filename)); $config->write(); } return $this; }