Author: nmathon Date: 2010-03-20 10:06:06 +0100 (Sat, 20 Mar 2010) New Revision: 28628
Modified: plugins/csSettingsPlugin/trunk/lib/BasecsSettings.class.php plugins/csSettingsPlugin/trunk/modules/csSetting/templates/indexSuccess.php Log: - Add support for CSRF Token in the admin form - Fix a cache bug when load data is done Modified: plugins/csSettingsPlugin/trunk/lib/BasecsSettings.class.php =================================================================== --- plugins/csSettingsPlugin/trunk/lib/BasecsSettings.class.php 2010-03-20 00:30:05 UTC (rev 28627) +++ plugins/csSettingsPlugin/trunk/lib/BasecsSettings.class.php 2010-03-20 09:06:06 UTC (rev 28628) @@ -1,12 +1,12 @@ <?php /** - * BasecsSettings - * - * @package + * BasecsSettings + * + * @package * @version $id$ * @copyright 2006-2007 Brent Shaffer - * @author Brent Shaffer <[email protected]> + * @author Brent Shaffer <[email protected]> * @license See LICENSE that came packaged with this software */ class BasecsSettings @@ -15,35 +15,35 @@ { return 'uploads/setting'; } - + static function isAuthenticated($user = null) { - if (!$user) + if (!$user) { $user = sfContext::getInstance()->getUser(); } - + $authMethod = sfConfig::get('app_csSettingsPlugin_authMethod'); $authCredential = sfConfig::get('app_csSettingsPlugin_authCredential'); - + $hasAccess = false; - if ($authMethod) + if ($authMethod) { $hasAccess = $user->$authMethod(); } - if (!$hasAccess && $authCredential) + if (!$hasAccess && $authCredential) { $hasAccess = $user->hasCredential($authCredential); } - + return $hasAccess; } /** - * get + * get * Returns the string value of a particular setting. - * - * @param string $setting + * + * @param string $setting * @static * @access public * @return string @@ -52,11 +52,11 @@ { // Pull from cached settings array $settingsArray = self::getSettingsArray(); - if (isset($settingsArray[$setting])) + if (isset($settingsArray[$setting])) { return $settingsArray[$setting]; } - + //Look in app.ymls for setting return sfConfig::get('app_'.self::settingize($setting)); } @@ -64,8 +64,8 @@ /** * getSetting * pulls the csSetting object for a given setting - * - * @param string $setting + * + * @param string $setting * @static * @access public * @return object csSetting @@ -73,19 +73,19 @@ static function getSetting($setting) { $objArray = self::getAllSettings(); - if (isset($objArray[$setting])) + if (isset($objArray[$setting])) { $ret = new csSetting(); $ret->fromArray($objArray[$setting]); return $ret; } - + return null; } - + /** - * getAllSettings - * Returns an array of all setting objects + * getAllSettings + * Returns an array of all setting objects * @static * @access public * @return array @@ -101,11 +101,11 @@ $objArray[$setting['slug']] = $setting->toArray(); $objArray[$setting['name']] = $setting->toArray(); } - + // Cache Settings $serialized = serialize($objArray); file_put_contents($cachePath, $serialized); - } + } else { // Pull settings array @@ -115,10 +115,10 @@ } /** - * getAll - * Returns an array of settings + * getAll + * Returns an array of settings * (key: setting slug or name, value: setting value) - * + * * @static * @access public * @return void @@ -129,16 +129,16 @@ if (!file_exists($cachePath)) { $settingsArray = array(); - foreach (Doctrine::getTable('csSetting')->findAll() as $setting) + foreach (Doctrine::getTable('csSetting')->findAll() as $setting) { $settingsArray[$setting['slug']] = $setting->getValue(); $settingsArray[$setting['name']] = $setting->getValue(); } - + // Cache Settings $serialized = serialize($settingsArray); file_put_contents($cachePath, $serialized); - } + } else { // Pull settings array @@ -146,25 +146,27 @@ } return $settingsArray; } - + static public function clearSettingsCache() { - foreach (self::getCache() as $cachedir) - { - $cachePath = sfConfig::get('sf_cache_dir').'/'.$cachedir; - if (file_exists($cachePath)) + if(is_array(self::getCache())){ + foreach (self::getCache() as $cachedir) { - unlink($cachePath); + $cachePath = sfConfig::get('sf_cache_dir').'/'.$cachedir; + if (file_exists($cachePath)) + { + unlink($cachePath); + } } } } - + static public function getCache($key = '') { $cache = sfConfig::get('app_csSettingsPlugin_cachepaths'); return $key ? $cache[$key] : $cache; } - + static public function settingize($anystring) { return str_replace('-', '_', Doctrine_Inflector::urlize(trim($anystring))); Modified: plugins/csSettingsPlugin/trunk/modules/csSetting/templates/indexSuccess.php =================================================================== --- plugins/csSettingsPlugin/trunk/modules/csSetting/templates/indexSuccess.php 2010-03-20 00:30:05 UTC (rev 28627) +++ plugins/csSettingsPlugin/trunk/modules/csSetting/templates/indexSuccess.php 2010-03-20 09:06:06 UTC (rev 28628) @@ -16,6 +16,9 @@ <div id="sf_admin_content"> <?php //use_helper('Form') ?> <?php echo form_tag('@cs_setting_save_all', array('multipart' => true)); ?> + <?php if ($form->isCSRFProtected()) : ?> + <?php echo $form['_csrf_token']->render(); ?> + <?php endif; ?> <?php include_partial('csSetting/list', array('pager' => $pager, 'sort' => $sort, 'helper' => $helper, 'form' => $form)) ?> <ul class="sf_admin_actions"> <?php include_partial('csSetting/list_batch_actions', array('helper' => $helper)) ?> -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
