function test_write() { // write simple structure, with 24 char padding $data = array('one' => 'two', 'three' => true); $ini = "; <?php /*\n\none = two\nthree = On\n\n; */ ?>"; $this->assertEquals($ini, Ini::write($data)); // write with sections $data = array('Section' => array('one' => 'http://www.foo.com/', 'two' => false)); $ini = "; <?php /*\n\n[Section]\n\none = \"http://www.foo.com/\"\ntwo = Off\n\n; */ ?>"; $this->assertEquals($ini, Ini::write($data)); }
} else { $resources = User::acl()->resources(); foreach ($resources as $resource => $label) { if (isset($_POST['resources'][$resource])) { unset($resources[$resource]); } else { $resources[$resource] = false; } } $resources['default'] = true; $_POST['resources'] = $resources; } // save the file $acl = User::acl(); unset($acl->rules[$_GET['role']]); unset($acl->rules[$_POST['name']]); $acl->add_role($_POST['name'], $_POST['resources']['default']); foreach ($_POST['resources'] as $resource => $allow) { if ($allow) { $acl->allow($_POST['name'], $resource); } else { $acl->deny($_POST['name'], $resource); } } if (!Ini::write($acl->rules, conf('Paths', 'access_control_list'))) { $form->controller->add_notification(__('Unable to save the file.')); return false; } $form->controller->add_notification(__('Role saved.')); $form->controller->redirect('/user/roles'); });
<?php /** * Add a new language to the list, including its name, * code, locale, character set, and fallback. */ $this->require_acl('admin', 'translator'); $page->layout = 'admin'; $page->title = __('Add language'); $form = new Form('post', $this); require_once 'apps/translator/lib/Functions.php'; echo $form->handle(function ($form) { // Add to lang/languages.php $_POST['code'] = strtolower($_POST['code']); $_POST['locale'] = strtolower($_POST['locale']); if (!empty($_POST['locale'])) { $lang = $_POST['code'] . '_' . $_POST['locale']; } else { $lang = $_POST['code']; } $i18n = $form->controller->i18n(); $i18n->languages[$lang] = array('name' => $_POST['name'], 'code' => $_POST['code'], 'locale' => $_POST['locale'], 'charset' => $_POST['charset'], 'fallback' => $_POST['fallback'], 'default' => 'Off', 'date_format' => $_POST['date_format'], 'short_format' => $_POST['short_format'], 'time_format' => $_POST['time_format']); uasort($i18n->languages, 'translator_sort_languages'); if (!Ini::write($i18n->languages, 'lang/languages.php')) { return false; } $form->controller->add_notification(__('Language added.')); $form->controller->redirect('/translator/index'); });
/** * Perform the installation associated with the step. * Variables required by the installation are stored within the session. * * @author KnowledgeTree Team * @access public */ public function installStep() { // get data from the server $conf = $this->getDataFromSession("configuration"); $server = $conf['server']; $paths = $conf['paths']; // initialise writing to config.ini $configPath = realpath('../../config/config.ini'); $ini = false; if (file_exists($configPath)) { $ini = new Ini($configPath); } // initialise the db connection // retrieve database information from session $dbconf = $this->getDataFromSession("database"); // make db connection $this->_dbhandler->load($dbconf['dhost'], $dbconf['duname'], $dbconf['dpassword'], $dbconf['dname']); // add db config to server variables $server = $this->registerDBConfig($server, $dbconf); $table = 'config_settings'; // write server settings to config_settings table and config.ini foreach ($server as $item) { switch ($item['where']) { case 'file': $value = $item['value']; if ($value == 'yes') { $value = 'true'; } if ($value == 'no') { $value = 'false'; } if (!$ini === false) { $ini->updateItem($item['section'], $item['setting'], $value); } break; case 'db': $value = mysql_real_escape_string($item['value']); $setting = mysql_real_escape_string($item['setting']); $sql = "UPDATE {$table} SET value = '{$value}' WHERE item = '{$setting}'"; $this->_dbhandler->query($sql); break; } } // write the paths to the config_settings table if (is_array($paths)) { foreach ($paths as $item) { if (empty($item['setting'])) { continue; } $value = mysql_real_escape_string($item['path']); $setting = mysql_real_escape_string($item['setting']); $sql = "UPDATE {$table} SET value = '{$value}' WHERE item = '{$setting}'"; $this->_dbhandler->query($sql); } } // write out the config.ini file if (!$ini === false) { $ini->write(); } // close the database connection $this->_dbhandler->close(); }
if (!preg_match($valid_setting_name, $setting)) { Cli::out('Invalid setting name: ' . $setting, 'error'); return; } if ($inner !== null && !preg_match($valid_inner_name, $inner)) { Cli::out('Invalid setting key name: ' . $inner, 'error'); return; } // build an updated config to save $settings = conf(); if ($inner !== null) { $merged = array_replace_recursive($settings, array($section => array($setting => array($inner => $value)))); } else { $merged = array_replace_recursive($settings, array($section => array($setting => $value))); } if (!Ini::write($merged, 'conf/' . ELEFANT_ENV . '.php')) { Cli::out('Unable to save changes to: conf/' . ELEFANT_ENV . '.php', 'error'); } // show setting info } else { // list sections if (!isset($_SERVER['argv'][2])) { $settings = conf(); $sections = array_keys($settings); sort($sections); echo join(', ', $sections) . "\n"; return; } $parts = explode('.', $_SERVER['argv'][2]); // list settings in section if (count($parts) === 1) {
<?php /** * Global site settings manager. */ // keep unauthorized users out $this->require_acl('admin', 'settings'); // set the layout and page title $page->layout = 'admin'; $page->title = __('Site Settings'); // create the form $form = new Form('post', $this); // set the form data from the global conf() settings, since they've already // been rewritten with the Appconf::storyteller() ones in bootstrap.php $form->data = array('site_name' => conf('General', 'site_name'), 'site_domain' => conf('General', 'site_domain') ? conf('General', 'site_domain') : $_SERVER['HTTP_HOST'], 'email_from' => conf('General', 'email_from'), 'timezone' => conf('General', 'timezone'), 'google_analytics_id' => conf('General', 'google_analytics_id')); echo $form->handle(function ($form) { // merge the new values into the settings $merged = Appconf::merge('admin', array('Site Settings' => array('site_name' => $_POST['site_name'], 'site_domain' => $_POST['site_domain'], 'email_from' => $_POST['email_from'], 'timezone' => $_POST['timezone'], 'google_analytics_id' => $_POST['google_analytics_id']))); // save the settings to disk if (!Ini::write($merged, 'conf/app.admin.' . ELEFANT_ENV . '.php')) { printf('<p>%s</p>', __('Unable to save changes. Check your permissions and try again.')); return; } // redirect to the main admin page with a notification $form->controller->add_notification(__('Settings saved.')); $form->controller->redirect('/'); });
<?php // keep unauthorized users out $this->require_admin(); // set the layout and page title $page->layout = 'admin'; $page->title = __('Files - Settings'); // create the form $form = new Form('post', $this); // set the form data from the app settings $form->data = array('aviary_key' => Appconf::filemanager('General', 'aviary_key')); echo $form->handle(function ($form) { // merge the new values into the settings $merged = Appconf::merge('filemanager', array('General' => array('aviary_key' => $_POST['aviary_key']))); // save the settings to disk if (!Ini::write($merged, 'conf/app.filemanager.' . ELEFANT_ENV . '.php')) { printf('<p>%s</p>', __('Unable to save changes. Check your permissions and try again.')); return; } // redirect to the main admin page with a notification $form->controller->add_notification(__('Settings saved.')); $form->controller->redirect('/filemanager/index'); });
function test_write_with_assoc() { $data = array('Section' => array('one' => array('a' => 'one', 'b' => 'two'))); $ini = "; <?php /*\n\n[Section]\n\none[a] = one\none[b] = two\n\n; */ ?>"; $this->assertEquals($ini, Ini::write($data)); }