/** * Magic 'call' method to provide the nicer URLs * and make things automated * * @param string $name * @param array $args * @return strng */ public function __call($name, $args) { $this->setTitle(t('Settings')); $this->setOutputType(self::_OT_CONFIG); $name = substr($name, 0, -7); // Display correct view switch ($name) { case 'index': $name = 'general'; case 'general': $this->setTitle(t('General settings')); $view = $this->loadView('general.html'); break; case 'email': $this->setTitle(t('Email settings')); $view = $this->loadView('email.html'); break; case 'locale': $this->setTitle(t('Locale settings')); $view = $this->loadView('locale.html'); /** * Get all available layouts that can be installed */ $availableLocales = $this->_i18n->getAvailableLangs(); if (($installable = $this->_cache->get('settings_installable_i18n')) === false) { $installable = null; if (ini_get('allow_url_fopen')) { $version = str_replace('-', '/', zula_version_map(_PROJECT_VERSION)); $json = @file_get_contents('http://releases.tangocms.org/' . $version . '/i18n/locales.json'); if (isset($http_response_header[0]) && strpos($http_response_header[0], 200) !== false) { // Only show langs that are not already 'installed' $installable = array_diff_key(json_decode($json, true), $availableLocales); } } if ($installable === null) { $this->_log->message('failed to get list of locales, check "allow_url_fopen"', Log::L_WARNING); } else { $this->_cache->add('settings_installable_i18n', $installable); } } $view->assign(array('LOCALES' => $availableLocales, 'INSTALLABLE' => (array) $installable)); break; case 'security': $this->setTitle(t('Server & security settings')); $view = $this->loadView('security.html'); break; case 'cache': $this->setTitle(t('Cache & performance settings')); $view = $this->loadView('cache.html'); break; case 'editing': $this->setTitle(t('Editing settings')); $view = $this->loadView('editing.html'); break; default: throw new Module_ControllerNoExist(); } // Assign the settings/config items/values foreach ($this->config[$name] as &$val) { try { $val = $this->_config->get($val); } catch (Config_KeyNoExist $e) { $val = ''; } } if (!trim($this->config['locale']['DATE_TIMEZONE'])) { $this->config['locale']['DATE_TIMEZONE'] = date_default_timezone_get(); } $view->assign(array('CONFIG' => $this->config[$name])); $view->assignHtml(array('CSRF' => $this->_input->createToken(true))); return $view->getOutput(); }
/** * Update the settings based on the post-data provided * * @param string $name * @param array $args * @return string */ public function __call($name, $args) { $name = substr($name, 0, -7); if (!$this->_acl->check('settings_update')) { throw new Module_NoPermission(); } else { if (!in_array($name, $this->categories)) { throw new Module_ControllerNoExist(); } else { if (!$this->_input->checkToken()) { $this->_event->error(Input::csrfMsg()); return zula_redirect($this->_router->makeUrl('settings', $name)); } } } $this->setTitle(t('Update settings')); // Update all of the provided settings, or insert if they don't exist foreach ($this->_input->post('setting') as $key => $val) { if (strpos($key, 'cache') !== 0) { if (substr($key, 8, 9) == 'mail/smtp' && !$this->_acl->check('settings_access_smtp')) { continue; } try { $this->_config_sql->update($key, $val); } catch (Config_KeyNoExist $e) { $this->_sql->insert('config', array('name' => $key, 'value' => $val)); } } } /** * Category specific things to do when updating * the settings or other things (ACL forms etc). */ switch ($name) { case 'general': $this->_cache->delete('view_default_tags'); break; case 'cache': try { $this->_config_ini->update('cache/type', $this->_input->post('setting/cache\\/type')); $this->_config_ini->update('cache/ttl', $this->_input->post('setting/cache\\/ttl')); $this->_config_ini->update('cache/js_aggregate', $this->_input->post('setting/cache\\/js_aggregate')); $this->_config_ini->update('cache/google_cdn', $this->_input->post('setting/cache\\/google_cdn')); $this->_config_ini->writeIni(); // Clear cache if needbe if ($this->_input->post('cache_purge')) { $this->_cache->purge(); } } catch (Exception $e) { $this->_event->error($e->getMessage()); $this->_log->message($e->getMessage(), Log::L_WARNING); } break; case 'locale': try { $this->_config_ini->update('locale/default', $this->_input->post('setting/locale\\/default')); $this->_config_ini->writeIni(); } catch (Exception $e) { $this->_event->error($e->getMessage()); $this->_log->message($e->getMessage(), Log::L_WARNING); } if (($pkg = $this->_input->post('lang_pkg')) !== 'none') { // Download and install a new locale if (!zula_supports('zipExtraction')) { $this->_event->error(t('Cannot install locale, server does not support zip extraction')); } else { if (!preg_match('#^[a-z]{2}_[A-Z]{2}$#', $pkg)) { $this->_event->error(t('Provided locale is invalid, unable to install')); } else { if (!zula_is_writable($this->_zula->getDir('locale'))) { $this->_event->error(t('Locale directory is not writable, unable to install')); } else { $version = str_replace('-', '/', zula_version_map(_PROJECT_VERSION)); $zipDest = $this->_zula->getDir('tmp') . '/i18n-' . $pkg . '.zip'; $copyResult = @copy('http://releases.tangocms.org/' . $version . '/i18n/' . $pkg . '.zip', $zipDest); if ($copyResult) { // Extract the archive to the locale dir $zip = new ZipArchive(); if ($zip->open($zipDest)) { $zip->extractTo($this->_zula->getDir('locale')); $zip->close(); $this->_event->success(t('Locale successfully installed')); } else { $this->_event->error(t('Could not install locale, zip extraction failed')); } unlink($zipDest); } else { $this->_event->error(t('Failed to get remote language archive')); } } } } } break; } $this->_event->success(t('Updated settings')); return zula_redirect($this->_router->makeUrl('settings', $name)); }