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
This commit is contained in:
parent
b5758344d1
commit
c0a535f83c
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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');
|
||||
|
||||
|
||||
@ -46,11 +45,15 @@
|
||||
|
||||
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;
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
{validate_init form=$admin_panel_id}
|
||||
{validate id="content" message=$panelstrings.error.content append="error"}
|
||||
|
||||
<h2>{$panelstrings.head}</h2>
|
||||
{include file=shared:errorlist.tpl}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user