PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/flatpress/fp-includes/smarty/SmartyValidate.class.php

https://bitbucket.org/alexandrul/flatpress
PHP | 662 lines | 387 code | 75 blank | 200 comment | 108 complexity | 14ad319caa2ea6a79aa8127cbfc48552 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MIT
  1. <?php
  2. /**
  3. * Project: SmartyValidate: Form Validator for the Smarty Template Engine
  4. * File: SmartyValidate.class.php
  5. * Author: Monte Ohrt <monte at newdigitalgroup dot com>
  6. * Website: http://www.phpinsider.com/php/code/SmartyValidate/
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * @link http://www.phpinsider.com/php/code/SmartyValidate/
  23. * @copyright 2001-2005 New Digital Group, Inc.
  24. * @author Monte Ohrt <monte at newdigitalgroup dot com>
  25. * @package SmartyValidate
  26. * @version 2.8
  27. */
  28. if(!defined('SMARTY_VALIDATE_DEFAULT_FORM'))
  29. define('SMARTY_VALIDATE_DEFAULT_FORM', 'default');
  30. class SmartyValidate {
  31. /**
  32. * Class Constructor
  33. */
  34. function SmartyValidate() { }
  35. /**
  36. * initialize the validator
  37. *
  38. * @param obj $smarty the smarty object
  39. * @param string $reset reset the default form?
  40. */
  41. function connect(&$smarty, $reset = false) {
  42. if(SmartyValidate::is_valid_smarty_object($smarty)) {
  43. SmartyValidate::_object_instance('Smarty', $smarty);
  44. SmartyValidate::register_form(SMARTY_VALIDATE_DEFAULT_FORM, $reset);
  45. } else {
  46. trigger_error("SmartyValidate: [connect] I need a valid Smarty object.");
  47. return false;
  48. }
  49. }
  50. /**
  51. * test if object is a valid smarty object
  52. *
  53. * @param obj $smarty_obj the smarty object
  54. */
  55. function is_valid_smarty_object(&$smarty_obj) {
  56. return (is_object($smarty_obj) && (strtolower(get_class($smarty_obj)) == 'smarty' || is_subclass_of($smarty_obj, 'smarty')));
  57. }
  58. /**
  59. * clear the entire SmartyValidate session
  60. *
  61. */
  62. function disconnect() {
  63. unset($_SESSION['SmartyValidate']);
  64. SmartyValidate::_object_instance('-', $_dummy);
  65. }
  66. /**
  67. * initialize the session data
  68. *
  69. * @param string $form the name of the form being validated
  70. * @param string $reset reset an already registered form?
  71. */
  72. function register_form($form, $reset = false) {
  73. if(SmartyValidate::is_registered_form($form) && !$reset) {
  74. return false;
  75. } else {
  76. $_SESSION['SmartyValidate'][$form] = array();
  77. $_SESSION['SmartyValidate'][$form]['registered_funcs']['criteria'] = array();
  78. $_SESSION['SmartyValidate'][$form]['registered_funcs']['transform'] = array();
  79. $_SESSION['SmartyValidate'][$form]['validators'] = array();
  80. $_SESSION['SmartyValidate'][$form]['is_error'] = false;
  81. $_SESSION['SmartyValidate'][$form]['is_init'] = true;
  82. SmartyValidate::_smarty_assign();
  83. return true;
  84. }
  85. }
  86. /**
  87. * unregister a form from the session
  88. *
  89. * @param string $form the name of the form being validated
  90. */
  91. function unregister_form($form) {
  92. unset($_SESSION['SmartyValidate'][$form]);
  93. }
  94. /**
  95. * test if the session data is initialized
  96. *
  97. * @param string $form the name of the form being validated
  98. */
  99. function is_registered_form($form = SMARTY_VALIDATE_DEFAULT_FORM) {
  100. return isset($_SESSION['SmartyValidate'][$form]);
  101. }
  102. function _failed_fields(&$formvars, $form = SMARTY_VALIDATE_DEFAULT_FORM, $revalidate = false)
  103. {
  104. // keep track of failed fields
  105. static $_failed_fields = array();
  106. if(isset($_failed_fields[$form]) && !$revalidate) {
  107. // already validated the form
  108. return $_failed_fields[$form];
  109. }
  110. // failed fields for current pass
  111. $_ret = array();
  112. $_sess =& $_SESSION['SmartyValidate'][$form]['validators'];
  113. foreach($_sess as $_key => $_val) {
  114. if(isset($_SESSION['SmartyValidate'][$form]['page'])
  115. && $_sess[$_key]['page'] != $_SESSION['SmartyValidate'][$form]['page']) {
  116. // not on page, do not validate
  117. continue;
  118. }
  119. $_full_field = $_field = $_sess[$_key]['field'];
  120. $_field_key = null;
  121. $_empty = isset($_sess[$_key]['empty']) ? $_sess[$_key]['empty'] : false;
  122. $_message = isset($_sess[$_key]['message']) ? $_sess[$_key]['message'] : null;
  123. if(is_array($_ret) && in_array($_full_field, $_ret)) {
  124. // already failed, skip this test
  125. continue;
  126. }
  127. // field is name-keyed array, pull it apart
  128. if(($_lpos = strpos($_field, '[')) !== false && ($_rpos = strpos($_field, ']')) !== false) {
  129. if (($_keylen = ($_rpos - $_lpos - 1)) > 0) {
  130. $_field_key = substr($_field, $_lpos+1, $_keylen);
  131. }
  132. $_field = substr($_field, 0, $_lpos);
  133. }
  134. if(isset($_sess[$_key]['transform'])) {
  135. $_trans_names = preg_split('![\s,]+!', $_sess[$_key]['transform'], -1, PREG_SPLIT_NO_EMPTY);
  136. if($_sess[$_key]['trim']) {
  137. // put trim on front of transform array
  138. array_unshift($_trans_names, 'trim');
  139. }
  140. foreach($_trans_names as $_trans_name) {
  141. if(substr($_trans_name,0,1) == '@') {
  142. // transformation will apply to entire array
  143. $_trans_on_array = true;
  144. $_trans_name = substr($_trans_name,1);
  145. } else {
  146. // transformation will apply to each array element
  147. $_trans_on_array = false;
  148. }
  149. if(strpos($_trans_name,':') !== false) {
  150. // transform has parameters, put them in $formvars
  151. $_trans_parts = explode(':', $_trans_name);
  152. $_trans_name = array_shift($_trans_parts);
  153. $_trans_index = 2;
  154. foreach($_trans_parts as $_trans_param) {
  155. $_trans_field = $_trans_name . $_trans_index;
  156. $_sess[$_key][$_trans_field] = $_trans_param;
  157. $_trans_index++;
  158. }
  159. }
  160. if(is_array($formvars[$_field]) && !$_trans_on_array) {
  161. if(isset($_field_key)) {
  162. // only apply to given key
  163. if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field][$_field_key], $_sess[$_key], $formvars, $form)) !== false)
  164. $formvars[$_field][$_field_key] = $_new_val;
  165. } else {
  166. // apply to all keys
  167. for($_x = 0, $_y = count($formvars[$_field]); $_x < $_y; $_x++) {
  168. if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field][$_x], $_sess[$_key], $formvars, $form)) !== false)
  169. $formvars[$_field][$_x] = $_new_val;
  170. }
  171. }
  172. } else {
  173. if(($_new_val = SmartyValidate::_execute_transform($_trans_name, $formvars[$_field], $_sess[$_key], $formvars, $form)) !== false)
  174. $formvars[$_field] = $_new_val;
  175. }
  176. }
  177. }
  178. if((!isset($formvars[$_field]) && (!isset($_FILES[$_field])))
  179. || (
  180. ((is_array($formvars[$_field]) && count($_field) == 0) || (is_string($formvars[$_field]) && strlen($formvars[$_field]) == 0)) && $_empty
  181. )
  182. ) {
  183. // field must exist, or else fails automatically
  184. $_sess[$_key]['valid'] = $_empty;
  185. } else {
  186. if(substr($_val['criteria'],0,1) == '@') {
  187. // criteria will apply to entire array or given key
  188. $_criteria_on_array = true;
  189. $_val['criteria'] = substr($_val['criteria'],1);
  190. } else {
  191. // criteria will apply to each array element
  192. $_criteria_on_array = false;
  193. }
  194. if(is_array($formvars[$_field]) && !$_criteria_on_array) {
  195. if(isset($_field_key)) {
  196. // only apply to given key
  197. $_sess[$_key]['valid'] = SmartyValidate::_is_valid_criteria($_val['criteria'], $formvars[$_field][$_field_key], $_empty, $_sess[$_key], $formvars, $form);
  198. } else {
  199. // apply to all keys
  200. for($_x = 0, $_y = count($formvars[$_field]); $_x < $_y; $_x++) {
  201. if(! $_sess[$_key]['valid'] = SmartyValidate::_is_valid_criteria($_val['criteria'], $formvars[$_field][$_x], $_empty, $_sess[$_key], $formvars, $form)) {
  202. // found invalid array element, exit for loop
  203. break;
  204. }
  205. }
  206. }
  207. } else {
  208. $_sess[$_key]['valid'] = SmartyValidate::_is_valid_criteria($_val['criteria'], $formvars[$_field], $_empty, $_sess[$_key], $formvars, $form);
  209. }
  210. }
  211. if(!$_sess[$_key]['valid']) {
  212. $_ret[] = $_full_field;
  213. if(isset($_sess[$_key]['halt']) && $_sess[$_key]['halt'])
  214. break;
  215. }
  216. }
  217. $_failed_fields[$form] = $_ret;
  218. return $_ret;
  219. }
  220. /**
  221. * validate the form
  222. *
  223. * @param string $formvars the array of submitted for variables
  224. * @param string $form the name of the form being validated
  225. */
  226. function is_valid(&$formvars, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  227. static $_is_valid = array();
  228. if(isset($_is_valid[$form])) {
  229. // already validated the form
  230. return $_is_valid[$form];
  231. }
  232. $_smarty_obj =& SmartyValidate::_object_instance('Smarty', $_dummy);
  233. if(!SmartyValidate::is_valid_smarty_object($_smarty_obj)) {
  234. trigger_error("SmartyValidate: [is_valid] No valid smarty object, call connect() first.");
  235. return false;
  236. }
  237. if(!SmartyValidate::is_registered_form($form)) {
  238. trigger_error("SmartyValidate: [is_valid] form '$form' is not registered.");
  239. return false;
  240. } elseif ($_SESSION['SmartyValidate'][$form]['is_init']) {
  241. // first run, skip validation
  242. return false;
  243. } elseif (count($_SESSION['SmartyValidate'][$form]['validators']) == 0) {
  244. // nothing to validate
  245. return true;
  246. }
  247. // check for failed fields
  248. $_failed_fields = SmartyValidate::_failed_fields($formvars, $form);
  249. $_ret = is_array($_failed_fields) && count($_failed_fields) == 0;
  250. // set validation state of form
  251. $_SESSION['SmartyValidate'][$form]['is_error'] = !$_ret;
  252. $_is_valid[$form] = $_ret;
  253. return $_ret;
  254. }
  255. /**
  256. * register a callable function for form verification
  257. *
  258. * @param string $func_name the function being registered
  259. */
  260. function register_object($object_name, &$object) {
  261. if(!is_object($object)) {
  262. trigger_error("SmartyValidate: [register_object] not a valid object.");
  263. return false;
  264. }
  265. SmartyValidate::_object_instance($object_name, $object);
  266. }
  267. /**
  268. * register a callable function for form verification
  269. *
  270. * @param string $func_name the function being registered
  271. */
  272. function is_registered_object($object_name) {
  273. $_object =& SmartyValidate::_object_instance($object_name, $_dummy);
  274. return is_object($_object);
  275. }
  276. /**
  277. * register a callable function for form verification
  278. *
  279. * @param string $func_name the function being registered
  280. */
  281. function register_criteria($name, $func_name, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  282. return SmartyValidate::_register_function('criteria', $name, $func_name, $form);
  283. }
  284. /**
  285. * register a callable function for form verification
  286. *
  287. * @param string $func_name the function being registered
  288. */
  289. function register_transform($name, $func_name, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  290. return SmartyValidate::_register_function('transform', $name, $func_name, $form);
  291. }
  292. /**
  293. * test if a criteria function is registered
  294. *
  295. * @param string $var the value being booleanized
  296. */
  297. function is_registered_criteria($name, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  298. if(!SmartyValidate::is_registered_form($form)) {
  299. trigger_error("SmartyValidate: [is_registered_criteria] form '$form' is not registered.");
  300. return false;
  301. }
  302. return isset($_SESSION['SmartyValidate'][$form]['registered_funcs']['criteria'][$name]);
  303. }
  304. /**
  305. * test if a tranform function is registered
  306. *
  307. * @param string $var the value being booleanized
  308. */
  309. function is_registered_transform($name, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  310. if(!SmartyValidate::is_registered_form($form)) {
  311. trigger_error("SmartyValidate: [is_registered_transform] form '$form' is not registered.");
  312. return false;
  313. }
  314. return isset($_SESSION['SmartyValidate'][$form]['registered_funcs']['transform'][$name]);
  315. }
  316. /**
  317. * register a validator
  318. *
  319. * @param string $id the id of the validator
  320. * @param string $field the field to be validated
  321. * @param string $criteria the name of the criteria function
  322. * @param string $empty allow field to be empty (optional)
  323. * @param string $halt stop validation if this one fails (optional)
  324. * @param string $transform transform function(s) to apply (optional)
  325. * @param string $form name of the form (optional)
  326. */
  327. function register_validator($id, $field, $criteria, $empty = false, $halt = false, $transform = null, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  328. if(!SmartyValidate::is_registered_form($form)) {
  329. trigger_error("SmartyValidate: [register_validator] form '$form' is not registered.");
  330. return false;
  331. }
  332. SmartyValidate::unregister_validator($id,$form);
  333. $_field = explode(':', $field);
  334. $_validator = array();
  335. foreach($_field as $_key => $_val) {
  336. if($_key == 0)
  337. $_validator['field'] = $_val;
  338. else {
  339. $_field_name = 'field';
  340. $_field_name .= $_key + 1;
  341. $_validator[$_field_name] = $_val;
  342. }
  343. }
  344. $_validator['id'] = $id;
  345. $_validator['criteria'] = $criteria;
  346. $_validator['message'] = '';
  347. $_validator['trim'] = false;
  348. $_validator['empty'] = $empty;
  349. $_validator['halt'] = $halt;
  350. $_validator['transform'] = $transform;
  351. $_SESSION['SmartyValidate'][$form]['validators'][] = $_validator;
  352. }
  353. /**
  354. * register a validator
  355. *
  356. * @param string $id the id of the validator
  357. * @param string $transform the name of the transform function(s)
  358. * @param string $form name of the form (optional)
  359. */
  360. function set_transform($id, $transform, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  361. if(($_validator_key = SmartyValidate::is_registered_validator($id,$form)) === false) {
  362. trigger_error("SmartyValidate: [set_transform] validator '$id' is not registered.");
  363. return false;
  364. }
  365. $_SESSION['SmartyValidate'][$form]['validators'][$_validator_key]['transform'] = $transform;
  366. }
  367. /**
  368. * test if a validator is registered
  369. *
  370. * @param string $id the validator to test
  371. */
  372. function is_registered_validator($id, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  373. if(!SmartyValidate::is_registered_form($form)) {
  374. trigger_error("SmartyValidate: [is_registered_validator] form '$form' is not registered.");
  375. return false;
  376. }
  377. foreach($_SESSION['SmartyValidate'][$form]['validators'] as $_key => $_val) {
  378. if($_SESSION['SmartyValidate'][$form]['validators'][$_key]['id'] == $id) {
  379. // return array index of validator
  380. return $_key;
  381. }
  382. }
  383. return false;
  384. }
  385. /**
  386. * unregister a validator
  387. *
  388. * @param string $id the validator to unregister
  389. */
  390. function unregister_validator($id, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  391. if(!SmartyValidate::is_registered_form($form)) {
  392. return false;
  393. }
  394. foreach($_SESSION['SmartyValidate'][$form]['validators'] as $_key => $_val) {
  395. if(isset($_SESSION['SmartyValidate'][$form]['validators'][$_key]['id'])
  396. && $_SESSION['SmartyValidate'][$form]['validators'][$_key]['id'] == $id) {
  397. unset($_SESSION['SmartyValidate'][$form]['validators'][$_key]);
  398. break;
  399. }
  400. }
  401. }
  402. /**
  403. * set the current page of the form
  404. *
  405. * @param string $page the name of the page being validated
  406. * @param string $form the name of the form being validated
  407. */
  408. function set_page($page, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  409. $_SESSION['SmartyValidate'][$form]['page'] = $page;
  410. $_SESSION['SmartyValidate'][$form]['is_error'] = false;
  411. $_SESSION['SmartyValidate'][$form]['is_init'] = true;
  412. }
  413. /**
  414. * return actual function name of registered func
  415. *
  416. * @param string $type the type of func
  417. * @param string $name the registered name
  418. * @param string $form the form name
  419. */
  420. function _execute_transform($name, $value, $params, &$formvars, $form) {
  421. if(SmartyValidate::is_registered_transform($name, $form)) {
  422. $_func_name = SmartyValidate::_get_registered_func_name('transform', $name, $form);
  423. } else {
  424. $_func_name = 'smarty_validate_transform_' . $name;
  425. if(!function_exists($_func_name)) {
  426. $_smarty_obj =& SmartyValidate::_object_instance('Smarty', $_dummy);
  427. if($_plugin_file = $_smarty_obj->_get_plugin_filepath('validate_transform', $name)) {
  428. include_once($_plugin_file);
  429. } else {
  430. trigger_error("SmartyValidate: [is_valid] transform function '$name' was not found.");
  431. return false;
  432. }
  433. }
  434. }
  435. if(strpos($_func_name,'->') !== false) {
  436. // object method
  437. preg_match('!(\w+)->(\w+)!', $_func_name, $_match);
  438. $_object_name = $_match[1];
  439. $_method_name = $_match[2];
  440. $_object =& SmartyValidate::_object_instance($_object_name, $_dummy);
  441. if(!method_exists($_object, $_method_name)) {
  442. trigger_error("SmartyValidate: [is_valid] method '$_method_name' is not valid for object '$_object_name'.");
  443. return false;
  444. }
  445. return $_object->$_method_name($value, $params, $formvars);
  446. } else {
  447. return $_func_name($value, $params, $formvars);
  448. }
  449. }
  450. /**
  451. * register a callable function for form verification
  452. *
  453. * @param string $func_name the function being registered
  454. */
  455. function _register_function($type, $name, $func_name, $form = SMARTY_VALIDATE_DEFAULT_FORM) {
  456. if(!SmartyValidate::is_registered_form($form)) {
  457. trigger_error("SmartyValidate: [register_$type] form '$form' is not registered.");
  458. return false;
  459. }
  460. if(strpos($func_name,'->') !== false) {
  461. // object method
  462. preg_match('!(\w+)->(\w+)!', $func_name, $_match);
  463. $_object_name = $_match[1];
  464. $_method_name = $_match[2];
  465. $_object =& SmartyValidate::_object_instance($_object_name, $_dummy);
  466. if(!method_exists($_object, $_method_name)) {
  467. trigger_error("SmartyValidate: [register_$type] method '$_method_name' is not valid for object '$_object_name'.");
  468. return false;
  469. }
  470. } elseif (strpos($func_name,'::') !== false) {
  471. // static method
  472. preg_match('!(\w+)::(\w+)!', $func_name, $_match);
  473. if(!is_callable(array($_match[1], $_match[2]))) {
  474. trigger_error("SmartyValidate: [register_$type] static method '$func_name' does not exist.");
  475. return false;
  476. }
  477. } elseif(!function_exists($func_name)) {
  478. trigger_error("SmartyValidate: [register_$type] function '$func_name' does not exist.");
  479. return false;
  480. }
  481. $_SESSION['SmartyValidate'][$form]['registered_funcs'][$type][$name] = $func_name;
  482. return true;
  483. }
  484. /**
  485. * return actual function name of registered func
  486. *
  487. * @param string $type the type of func
  488. * @param string $name the registered name
  489. * @param string $form the form name
  490. */
  491. function _get_registered_func_name($type,$name,$form) {
  492. return isset($_SESSION['SmartyValidate'][$form]['registered_funcs'][$type][$name])
  493. ? $_SESSION['SmartyValidate'][$form]['registered_funcs'][$type][$name]
  494. : false;
  495. }
  496. /**
  497. * booleanize a value
  498. *
  499. * @param string $var the value being booleanized
  500. */
  501. function _booleanize($var) {
  502. if(in_array(strtolower($var), array(true, 1, 'true','on','yes','y'),true)) {
  503. return true;
  504. }
  505. return false;
  506. }
  507. /**
  508. * validate criteria for given value
  509. *
  510. * @param string $criteria the criteria to test against
  511. * @param string $value the value being tested
  512. * @param string $empty skip empty values or not
  513. */
  514. function _is_valid_criteria($criteria, $value, $empty, &$params, &$formvars, $form) {
  515. if(SmartyValidate::is_registered_criteria($criteria,$form)) {
  516. $_func_name = SmartyValidate::_get_registered_func_name('criteria',$criteria, $form);
  517. } else {
  518. $_func_name = 'smarty_validate_criteria_' . $criteria;
  519. if(!function_exists($_func_name)) {
  520. $_smarty_obj =& SmartyValidate::_object_instance('Smarty', $_dummy);
  521. if($_plugin_file = $_smarty_obj->_get_plugin_filepath('validate_criteria', $criteria)) {
  522. include_once($_plugin_file);
  523. } else {
  524. trigger_error("SmartyValidate: [is_valid] criteria function '$criteria' was not found.");
  525. return false;
  526. }
  527. }
  528. }
  529. if(strpos($_func_name,'->') !== false) {
  530. // object method
  531. preg_match('!(\w+)->(\w+)!', $_func_name, $_match);
  532. $_object_name = $_match[1];
  533. $_method_name = $_match[2];
  534. $_object =& SmartyValidate::_object_instance($_object_name, $_dummy);
  535. if(!method_exists($_object, $_method_name)) {
  536. trigger_error("SmartyValidate: [is_valid] method '$_method_name' is not valid for object '$_object_name'.");
  537. return false;
  538. }
  539. return $_object->$_method_name($value, $empty, $params, $formvars);
  540. } else {
  541. return $_func_name($value, $empty, $params, $formvars);
  542. }
  543. }
  544. /**
  545. * get or set an object instance
  546. *
  547. * @param string $name the object name
  548. * @param object $object the object being set
  549. */
  550. function &_object_instance($name, &$object) {
  551. $return = false;
  552. static $_objects = array();
  553. if ($name=='-') {
  554. unset ($_objects);
  555. static $_objects = array();
  556. }
  557. if(!is_object($object)) {
  558. if (isset($_objects[$name]))
  559. return $_objects[$name];
  560. else
  561. return $return;
  562. } else {
  563. $_objects[$name] =& $object;
  564. return $object;
  565. }
  566. }
  567. /**
  568. * get or set the smarty object instance
  569. *
  570. * @param string $value the value being tested
  571. */
  572. function _smarty_assign($vars = array()) {
  573. $_smarty_obj =& SmartyValidate::_object_instance('Smarty', $_dummy);
  574. if(!is_object($_smarty_obj)) {
  575. trigger_error("SmartyValidate: [assign] no valid smarty object found, call connect() first.");
  576. return false;
  577. }
  578. if(!empty($vars)) {
  579. $_smarty_obj->assign($vars);
  580. }
  581. foreach($_SESSION['SmartyValidate'] as $_key => $_val) {
  582. $_info[$_key]['is_error'] = isset($_SESSION['SmartyValidate'][$_key]['is_error']) ? $_SESSION['SmartyValidate'][$_key]['is_error'] : null;
  583. }
  584. $_smarty_obj->assign('validate', $_info);
  585. }
  586. }
  587. ?>