From c0a535f83c3f9c24148010da49983c732a82bc0f Mon Sep 17 00:00:00 2001 From: real_nowhereman Date: Mon, 24 Mar 2008 20:31:37 +0000 Subject: [PATCH] merging to trunk session-fix; it probably DIDN'T fix a heck, but at least ported the admin panel to a session-independent validating system --- admin/includes/panels.prototypes.php | 109 +++++++++++++++--------- admin/panels/entry/admin.entry.cats.php | 21 +++-- admin/panels/entry/admin.entry.cats.tpl | 3 - fp-includes/core/core.session.php | 9 +- 4 files changed, 80 insertions(+), 62 deletions(-) diff --git a/admin/includes/panels.prototypes.php b/admin/includes/panels.prototypes.php index 8448b54..9dddb32 100644 --- a/admin/includes/panels.prototypes.php +++ b/admin/includes/panels.prototypes.php @@ -194,61 +194,86 @@ var $validators = array(); - function exec() { - - if (empty($_POST)) - SmartyValidate::disconnect($this->smarty); - - $form_id = get_class($this); - - SmartyValidate::connect($this->smarty); - if (!SmartyValidate::is_registered_form($form_id)) - SmartyValidate::register_form($form_id); - - $this->setup(); - - $retval = 0; - - if (empty($_POST)) { - if ($validators =& $this->validators) { - foreach ($validators as $validator) { - $validator[6]=$form_id; - call_user_func_array(array('SmartyValidate', 'register_validator'), $validator); - } - } - - if ($this->commands) { - foreach($this->commands as $cmd) { - if (isset($_GET[ $cmd ])) { - return $this->docommand($cmd); - } - } - } - - lang_load($this->langres); - $retval = $this->main(); - } else { - $retval = $this->onsubmit(); - } - - return $retval; - + function dummy() { + } + // just dummy, remove once transition is complete + function exec() { + $this->smarty->register_function('validate_init', array(&$this, 'dummy')); + $this->smarty->register_function('validate', array(&$this, 'dummy')); + return parent::exec(); + } function onsubmit() { + + global $lang; + $result = 0; - if(SmartyValidate::is_valid($_POST, get_class($this))) { + $dummyarr = array(); + $errors = array(); + $lang_loaded = false; + $l = null; + + foreach ($this->validators as $valid_arr) { + + + # array('subject', 'subject', 'notEmpty', false, false, 'func1,func2'); + + list($vid, $field, $validatorname, $empty, $halt, $funcs) = $valid_arr; + + $includepath = SMARTY_DIR . 'plugins/'; + + $string = @$_POST[$field]; + + // execute functions on string + if ($string) { + $func_arr = explode(',', $funcs); + foreach($func_arr as $f) { + $string = @$f($string); + } + } + + include_once ( + $includepath . + 'validate_criteria.' . + $validatorname . + '.php' + ); + + # smarty_validate_criteria_notEmpty + + $valid_f = 'smarty_validate_criteria_' . $validatorname; + + if ( ! $valid_f($string, $empty, $dummyarr, $dummyarr ) ) { + + if (!$lang_loaded) { + $lang = lang_load('admin.'.ADMIN_PANEL); + $l =& $lang['admin'][ADMIN_PANEL][ADMIN_PANEL_ACTION]; + } + + $errors[$field] = $l['error'][$field]; + if ($halt) + break; + } + + + } + + if(!$errors) { $result = parent::onsubmit(); - } else $result = $this->onerror(); + } else { + $this->smarty->assign('error', $errors); + $result = $this->onerror(); + } return $result; } function onerror() { - return true; + return PANEL_NOREDIRECT; } diff --git a/admin/panels/entry/admin.entry.cats.php b/admin/panels/entry/admin.entry.cats.php index e241063..a2e7568 100755 --- a/admin/panels/entry/admin.entry.cats.php +++ b/admin/panels/entry/admin.entry.cats.php @@ -14,9 +14,8 @@ */ - class admin_entry_cats extends AdminPanelActionValidated { + class admin_entry_cats extends AdminPanelAction { - var $validators = array(array('content', 'content', 'notEmpty', false, false, 'trim,stripslashes')); var $events = array('save'); @@ -45,13 +44,17 @@ function onsave() { - - $str=(stripslashes($_POST['content'])); - $success = io_write_file(CONTENT_DIR . 'categories.txt', $str); - entry_categories_encode(); - $this->smarty->assign('success', ( $success )? 1 : -1 ); - $this->smarty->assign('catdefs', $str); - + + $str = stripslashes( trim( @$_POST['content'] ) ) ; + + if ($str) { + $success = io_write_file(CONTENT_DIR . 'categories.txt', $str); + entry_categories_encode(); + $this->smarty->assign('success', ( $success )? 1 : -1 ); + } else { + $this->smarty->assign('success', -1 ); + } + return PANEL_REDIRECT_CURRENT; } diff --git a/admin/panels/entry/admin.entry.cats.tpl b/admin/panels/entry/admin.entry.cats.tpl index 899b6ac..91240de 100755 --- a/admin/panels/entry/admin.entry.cats.tpl +++ b/admin/panels/entry/admin.entry.cats.tpl @@ -1,6 +1,3 @@ -{validate_init form=$admin_panel_id} -{validate id="content" message=$panelstrings.error.content append="error"} -

{$panelstrings.head}

{include file=shared:errorlist.tpl} diff --git a/fp-includes/core/core.session.php b/fp-includes/core/core.session.php index c7cc9e5..581cc9e 100755 --- a/fp-includes/core/core.session.php +++ b/fp-includes/core/core.session.php @@ -2,21 +2,14 @@ - function sess_setup($lifetime=3600) { + function sess_setup() { if (SESSION_PATH != '') session_save_path(SESSION_PATH); - $cparams=session_get_cookie_params(); - if ($cparams['lifetime']>0 && $lifetime==0 ) - $lifetime = $cparams['lifetime']; - - session_set_cookie_params($lifetime); - session_name(SESS_COOKIE); session_start(); - }