XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
object.php
Go to the documentation of this file.
1 <?php
21 defined('XOOPS_ROOT_PATH') or die('Restricted access');
30 define('XOBJ_DTYPE_TXTBOX', 1);
31 define('XOBJ_DTYPE_TXTAREA', 2);
32 define('XOBJ_DTYPE_INT', 3);
33 define('XOBJ_DTYPE_URL', 4);
34 define('XOBJ_DTYPE_EMAIL', 5);
35 define('XOBJ_DTYPE_ARRAY', 6);
36 define('XOBJ_DTYPE_OTHER', 7);
37 define('XOBJ_DTYPE_SOURCE', 8);
38 define('XOBJ_DTYPE_STIME', 9);
39 define('XOBJ_DTYPE_MTIME', 10);
40 define('XOBJ_DTYPE_LTIME', 11);
41 define('XOBJ_DTYPE_FLOAT', 13);
42 define('XOBJ_DTYPE_DECIMAL', 14);
43 define('XOBJ_DTYPE_ENUM', 15);
44 // YOU SHOULD NEVER USE THE FOLLOWING TYPES, THEY WILL BE REMOVED
47 define('XOBJ_DTYPE_UNICODE_URL', 18);
51 // Addition for 2.5.5
52 define('XOBJ_DTYPE_DATE', 22);
53 define('XOBJ_DTYPE_TIME', 23);
54 define('XOBJ_DTYPE_TIMESTAMP', 24);
59 {
66  var $vars = array();
67 
74  var $cleanVars = array();
75 
82  var $_isNew = false;
83 
90  var $_isDirty = false;
91 
98  var $_errors = array();
99 
105  var $_filters = array();
106 
107 
115  function XoopsObject()
116  {
117  }
118 
125  function setNew()
126  {
127  $this->_isNew = true;
128  }
129  function unsetNew()
130  {
131  $this->_isNew = false;
132  }
133  function isNew()
134  {
135  return $this->_isNew;
136  }
137 
146  function setDirty()
147  {
148  $this->_isDirty = true;
149  }
150  function unsetDirty()
151  {
152  $this->_isDirty = false;
153  }
154  function isDirty()
155  {
156  return $this->_isDirty;
157  }
158 
173  function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $enumerations = '')
174  {
175  $this->vars[$key] = array('value' => $value , 'required' => $required , 'data_type' => $data_type , 'maxlength' => $maxlength , 'changed' => false , 'options' => $options, 'enumeration' => $enumerations);
176  }
177 
185  function assignVar($key, $value)
186  {
187  if (isset($key) && isset($this->vars[$key])) {
188  switch ($this->vars[$key]['data_type']) {
189  case XOBJ_DTYPE_UNICODE_ARRAY:
190  if (is_array($value)) {
191  $this->vars[$key]['value'] =& array_walk($value, "xoops_aw_decode");
192  } else {
193  $this->vars[$key]['value'] =& xoops_convert_decode($value);
194  }
195  break;
196  case XOBJ_DTYPE_UNICODE_URL:
197  case XOBJ_DTYPE_UNICODE_EMAIL:
198  case XOBJ_DTYPE_UNICODE_OTHER:
199  case XOBJ_DTYPE_UNICODE_TXTBOX:
200  case XOBJ_DTYPE_UNICODE_TXTAREA:
201  $this->vars[$key]['value'] =& xoops_convert_decode($value);
202  break;
203  case XOBJ_DTYPE_DATE:
204  if (!is_string($value)&&is_numeric($value)) {
205  $this->vars[$key]['value'] =& date(_DBDATESTRING, $value);
206  } else {
207  $this->vars[$key]['value'] =& date(_DBDATESTRING, strtotime($value));
208  }
209  break;
210  case XOBJ_DTYPE_TIME:
211  if (!is_string($value)&&is_numeric($value)) {
212  $this->vars[$key]['value'] =& date(_DBTIMESTRING, $value);
213  } else {
214  $this->vars[$key]['value'] =& date(_DBTIMESTRING, strtotime($value));
215  }
216  break;
217  case XOBJ_DTYPE_TIMESTAMP:
218  if (!is_string($value)&&is_numeric($value)) {
219  $this->vars[$key]['value'] =& date(_DBTIMESTAMPSTRING, $value);
220  } else {
221  $this->vars[$key]['value'] =& date(_DBTIMESTAMPSTRING, strtotime($value));
222  }
223  break;
224  // YOU SHOULD NOT USE THE ABOVE TYPES, THEY WILL BE REMOVED
225  default:
226  $this->vars[$key]['value'] =& $value;
227  }
228  }
229  }
230 
237  function assignVars($var_arr)
238  {
239  foreach ($var_arr as $key => $value) {
240  $this->assignVar($key, $value);
241  }
242  }
243 
252  function setVar($key, $value, $not_gpc = false)
253  {
254  if (!empty($key) && isset($value) && isset($this->vars[$key])) {
255  $this->vars[$key]['value'] =& $value;
256  $this->vars[$key]['not_gpc'] = $not_gpc;
257  $this->vars[$key]['changed'] = true;
258  $this->setDirty();
259  }
260  }
261 
269  function setVars($var_arr, $not_gpc = false)
270  {
271  foreach ($var_arr as $key => $value) {
272  $this->setVar($key, $value, $not_gpc);
273  }
274  }
275 
282  function destoryVars($var)
283  {
284  if (empty($var)) {
285  return true;
286  }
287  $var = !is_array($var) ? array($var) : $var;
288  foreach ($var as $key) {
289  if (!isset($this->vars[$key])) {
290  continue;
291  }
292  $this->vars[$key]['changed'] = null;
293  }
294  return true;
295  }
296 
308  function setFormVars($var_arr = null, $pref = 'xo_', $not_gpc = false)
309  {
310  $len = strlen($pref);
311  foreach ($var_arr as $key => $value) {
312  if ($pref == substr($key, 0, $len)) {
313  $this->setVar(substr($key, $len), $value, $not_gpc);
314  }
315  }
316  }
317 
324  function &getVars()
325  {
326  return $this->vars;
327  }
328 
337  function getValues($keys = null, $format = 's', $maxDepth = 1)
338  {
339  if (!isset($keys)) {
340  $keys = array_keys($this->vars);
341  }
342  $vars = array();
343  foreach ($keys as $key) {
344  if (isset($this->vars[$key])) {
345  if (is_object($this->vars[$key]) && is_a($this->vars[$key], 'XoopsObject')) {
346  if ($maxDepth) {
347  $vars[$key] = $this->vars[$key]->getValues(null, $format, $maxDepth - 1);
348  }
349  } else {
350  $vars[$key] = $this->getVar($key, $format);
351  }
352  }
353  }
354  return $vars;
355  }
356 
367  function getVar($key, $format = 's')
368  {
369  $ret = null;
370  if (!isset($this->vars[$key])) {
371  return $ret;
372  }
373  $ret = $this->vars[$key]['value'];
375  switch ($this->vars[$key]['data_type']) {
376  case XOBJ_DTYPE_UNICODE_TXTBOX:
377  case XOBJ_DTYPE_TXTBOX:
378  switch (strtolower($format)) {
379  case 's':
380  case 'show':
381  case 'e':
382  case 'edit':
383  return $ts->htmlSpecialChars($ret);
384  break 1;
385  case 'p':
386  case 'preview':
387  case 'f':
388  case 'formpreview':
389  return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
390  break 1;
391  case 'n':
392  case 'none':
393  default:
394  break 1;
395  }
396  break;
397  case XOBJ_DTYPE_UNICODE_TXTAREA:
398  case XOBJ_DTYPE_TXTAREA:
399  switch (strtolower($format)) {
400  case 's':
401  case 'show':
402  $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
403  $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
404  $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
405  $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
406  $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
407  return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
408  break 1;
409  case 'e':
410  case 'edit':
411  return htmlspecialchars($ret, ENT_QUOTES);
412  break 1;
413  case 'p':
414  case 'preview':
415  $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
416  $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
417  $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
418  $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
419  $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
420  return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
421  break 1;
422  case 'f':
423  case 'formpreview':
424  return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
425  break 1;
426  case 'n':
427  case 'none':
428  default:
429  break 1;
430  }
431  break;
432  case XOBJ_DTYPE_UNICODE_ARRAY:
433  switch (strtolower($format)) {
434  case 'n':
435  case 'none':
436  break 1;
437  default:
438  if (!is_array($ret)) {
439  if ($ret != '') {
440  $ret = unserialize($ret);
441  }
442  $ret = is_array($ret) ? $ret : array();
443  if (is_array($ret)) {
444  $ret = array_walk($ret, "xoops_aw_decode");
445  }
446  }
447  return $ret;
448  break 1;
449  }
450  break;
451  case XOBJ_DTYPE_ARRAY:
452  switch (strtolower($format)) {
453  case 'n':
454  case 'none':
455  break 1;
456  default:
457  if (!is_array($ret)) {
458  if ($ret != '') {
459  $ret = unserialize($ret);
460  }
461  $ret = is_array($ret) ? $ret : array();
462  }
463  return $ret;
464  break 1;
465  }
466  break;
467  case XOBJ_DTYPE_SOURCE:
468  switch (strtolower($format)) {
469  case 's':
470  case 'show':
471  break 1;
472  case 'e':
473  case 'edit':
474  return htmlspecialchars($ret, ENT_QUOTES);
475  break 1;
476  case 'p':
477  case 'preview':
478  return $ts->stripSlashesGPC($ret);
479  break 1;
480  case 'f':
481  case 'formpreview':
482  return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
483  break 1;
484  case 'n':
485  case 'none':
486  default:
487  break 1;
488  }
489  break;
490  case XOBJ_DTYPE_DATE:
491  switch (strtolower($format)) {
492  case 's':
493  case 'show':
494  if (is_string($ret)&&!is_numeric($ret)) {
495  return date(_DBDATESTRING, strtotime($ret));
496  } else {
497  return date(_DBDATESTRING, $ret);
498  }
499  break 1;
500  case 'e':
501  case 'edit':
502  if (is_string($ret)&&!is_numeric($ret)) {
503  return htmlspecialchars(date(_DBDATESTRING, strtotime($ret)), ENT_QUOTES);
504  } else {
505  return htmlspecialchars(date(_DBDATESTRING, $ret), ENT_QUOTES);
506  }
507  break 1;
508  case 'p':
509  case 'preview':
510  if (is_string($ret)&&!is_numeric($ret)) {
511  return $ts->stripSlashesGPC(date(_DBDATESTRING, strtotime($ret)));
512  } else {
513  return $ts->stripSlashesGPC(date(_DBDATESTRING, $ret));
514  }
515  break 1;
516  case 'f':
517  case 'formpreview':
518  if (is_string($ret)&&!is_numeric($ret)) {
519  return htmlspecialchars($ts->stripSlashesGPC(date(_DBDATESTRING, strtotime($ret))), ENT_QUOTES);
520  } else {
521  return htmlspecialchars($ts->stripSlashesGPC(date(_DBDATESTRING, $ret)), ENT_QUOTES);
522  }
523  break 1;
524  case 'n':
525  case 'none':
526  default:
527  break 1;
528  }
529  case XOBJ_DTYPE_TIME:
530  switch (strtolower($format)) {
531  case 's':
532  case 'show':
533  if (is_string($ret)&&!is_numeric($ret)) {
534  return date(_DBTIMESTRING, strtotime($ret));
535  } else {
536  return date(_DBTIMESTRING, $ret);
537  }
538  break 1;
539  case 'e':
540  case 'edit':
541  if (is_string($ret)&&!is_numeric($ret)) {
542  return htmlspecialchars(date(_DBTIMESTRING, strtotime($ret)), ENT_QUOTES);
543  } else {
544  return htmlspecialchars(date(_DBTIMESTRING, $ret), ENT_QUOTES);
545  }
546  break 1;
547  case 'p':
548  case 'preview':
549  if (is_string($ret)&&!is_numeric($ret)) {
550  return $ts->stripSlashesGPC(date(_DBTIMESTRING, strtotime($ret)));
551  } else {
552  return $ts->stripSlashesGPC(date(_DBTIMESTRING, $ret));
553  }
554  break 1;
555  case 'f':
556  case 'formpreview':
557  if (is_string($ret)&&!is_numeric($ret)) {
558  return htmlspecialchars($ts->stripSlashesGPC(date(_DBTIMESTRING, strtotime($ret))), ENT_QUOTES);
559  } else {
560  return htmlspecialchars($ts->stripSlashesGPC(date(_DBTIMESTRING, $ret)), ENT_QUOTES);
561  }
562  break 1;
563  case 'n':
564  case 'none':
565  default:
566  break 1;
567  }
568  case XOBJ_DTYPE_TIMESTAMP:
569  switch (strtolower($format)) {
570  case 's':
571  case 'show':
572  if (is_string($ret)&&!is_numeric($ret)) {
573  return date(_DBTIMESTAMPSTRING, strtotime($ret));
574  } else {
575  return date(_DBTIMESTAMPSTRING, $ret);
576  }
577  break 1;
578  case 'e':
579  case 'edit':
580  if (is_string($ret)&&!is_numeric($ret)) {
581  return htmlspecialchars(date(_DBTIMESTAMPSTRING, strtotime($ret)), ENT_QUOTES);
582  } else {
583  return htmlspecialchars(date(_DBTIMESTAMPSTRING, $ret), ENT_QUOTES);
584  }
585  break 1;
586  case 'p':
587  case 'preview':
588  if (is_string($ret)&&!is_numeric($ret)) {
589  return $ts->stripSlashesGPC(date(_DBTIMESTAMPSTRING, strtotime($ret)));
590  } else {
591  return $ts->stripSlashesGPC(date(_DBTIMESTAMPSTRING, $ret));
592  }
593  break 1;
594  case 'f':
595  case 'formpreview':
596  if (is_string($ret)&&!is_numeric($ret)) {
597  return htmlspecialchars($ts->stripSlashesGPC(date(_DBTIMESTAMPSTRING, strtotime($ret))), ENT_QUOTES);
598  } else {
599  return htmlspecialchars($ts->stripSlashesGPC(date(_DBTIMESTAMPSTRING, $ret)), ENT_QUOTES);
600  }
601  break 1;
602  case 'n':
603  case 'none':
604  default:
605  break 1;
606  }
607  default:
608  if ($this->vars[$key]['options'] != '' && $ret != '') {
609  switch (strtolower($format)) {
610  case 's':
611  case 'show':
612  $selected = explode('|', $ret);
613  $options = explode('|', $this->vars[$key]['options']);
614  $i = 1;
615  $ret = array();
616  foreach ($options as $op) {
617  if (in_array($i, $selected)) {
618  $ret[] = $op;
619  }
620  $i++;
621  }
622  return implode(', ', $ret);
623  case 'e':
624  case 'edit':
625  $ret = explode('|', $ret);
626  break 1;
627  default:
628  break 1;
629  }
630  }
631  break;
632  }
633  return $ret;
634  }
635 
645  function cleanVars()
646  {
648  $existing_errors = $this->getErrors();
649  $this->_errors = array();
650  foreach ($this->vars as $k => $v) {
651  $cleanv = $v['value'];
652  if (!$v['changed']) {
653  } else {
654  $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
655  switch ($v['data_type']) {
656  case XOBJ_DTYPE_TIMESTAMP:
657  $cleanv = !is_string($cleanv)&&is_numeric($cleanv) ? date(_DBTIMESTAMPSTRING, $cleanv) : date(_DBTIMESTAMPSTRING, strtotime($cleanv));
658  break;
659  case XOBJ_DTYPE_TIME:
660  $cleanv = !is_string($cleanv)&&is_numeric($cleanv) ? date(_DBTIMESTRING, $cleanv) : date(_DBTIMESTRING, strtotime($cleanv));
661  break;
662  case XOBJ_DTYPE_DATE:
663  $cleanv = !is_string($cleanv)&&is_numeric($cleanv) ? date(_DBDATESTRING, $cleanv) : date(_DBDATESTRING, strtotime($cleanv));
664  break;
665  case XOBJ_DTYPE_TXTBOX:
666  if ($v['required'] && $cleanv != '0' && $cleanv == '') {
667  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
668  continue;
669  }
670  if (isset($v['maxlength']) && strlen($cleanv) > intval($v['maxlength'])) {
671  $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, intval($v['maxlength'])));
672  continue;
673  }
674  if (!$v['not_gpc']) {
675  $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
676  } else {
677  $cleanv = $ts->censorString($cleanv);
678  }
679  break;
680  case XOBJ_DTYPE_TXTAREA:
681  if ($v['required'] && $cleanv != '0' && $cleanv == '') {
682  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
683  continue;
684  }
685  if (!$v['not_gpc']) {
686  $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
687  } else {
688  $cleanv = $ts->censorString($cleanv);
689  }
690  break;
691  case XOBJ_DTYPE_SOURCE:
692  if (!$v['not_gpc']) {
693  $cleanv = $ts->stripSlashesGPC($cleanv);
694  } else {
695  $cleanv = $cleanv;
696  }
697  break;
698  case XOBJ_DTYPE_INT:
699  $cleanv = intval($cleanv);
700  break;
701 
702  case XOBJ_DTYPE_EMAIL:
703  if ($v['required'] && $cleanv == '') {
704  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
705  continue;
706  }
707  if ($cleanv != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
708  $this->setErrors("Invalid Email");
709  continue;
710  }
711  if (!$v['not_gpc']) {
712  $cleanv = $ts->stripSlashesGPC($cleanv);
713  }
714  break;
715  case XOBJ_DTYPE_URL:
716  if ($v['required'] && $cleanv == '') {
717  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
718  continue;
719  }
720  if ($cleanv != '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
721  $cleanv = 'http://' . $cleanv;
722  }
723  if (!$v['not_gpc']) {
724  $cleanv =& $ts->stripSlashesGPC($cleanv);
725  }
726  break;
727  case XOBJ_DTYPE_ARRAY:
728  $cleanv = (array) $cleanv;
729  $cleanv = serialize($cleanv);
730  break;
731  case XOBJ_DTYPE_STIME:
732  case XOBJ_DTYPE_MTIME:
733  case XOBJ_DTYPE_LTIME:
734  $cleanv = !is_string($cleanv) ? intval($cleanv) : strtotime($cleanv);
735  break;
736  case XOBJ_DTYPE_FLOAT:
737  $cleanv = floatval($cleanv);
738  break;
739  case XOBJ_DTYPE_DECIMAL:
740  $cleanv = doubleval($cleanv);
741  break;
742  case XOBJ_DTYPE_ENUM:
743  if (!in_array($cleanv, $v['enumeration'])) {
744  $this->setErrors("Invalid Enumeration");
745  continue;
746  }
747  break;
748  case XOBJ_DTYPE_UNICODE_TXTBOX:
749  if ($v['required'] && $cleanv != '0' && $cleanv == '') {
750  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
751  continue;
752  }
753  $cleanv = xoops_convert_encode($cleanv);
754  if (isset($v['maxlength']) && strlen($cleanv) > intval($v['maxlength'])) {
755  $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, intval($v['maxlength'])));
756  continue;
757  }
758  if (!$v['not_gpc']) {
759  $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
760  } else {
761  $cleanv = $ts->censorString($cleanv);
762  }
763  break;
764  case XOBJ_DTYPE_UNICODE_TXTAREA:
765  if ($v['required'] && $cleanv != '0' && $cleanv == '') {
766  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
767  continue;
768  }
769  $cleanv = xoops_convert_encode($cleanv);
770  if (!$v['not_gpc']) {
771  $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
772  } else {
773  $cleanv = $ts->censorString($cleanv);
774  }
775  break;
776  case XOBJ_DTYPE_UNICODE_EMAIL:
777  if ($v['required'] && $cleanv == '') {
778  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
779  continue;
780  }
781  if ($cleanv != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
782  $this->setErrors("Invalid Email");
783  continue;
784  }
785  $cleanv = xoops_convert_encode($cleanv);
786  if (!$v['not_gpc']) {
787  $cleanv = $ts->stripSlashesGPC($cleanv);
788  }
789  break;
790  case XOBJ_DTYPE_UNICODE_URL:
791  if ($v['required'] && $cleanv == '') {
792  $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
793  continue;
794  }
795  if ($cleanv != '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
796  $cleanv = 'http://' . $cleanv;
797  }
798  $cleanv = xoops_convert_encode($cleanv);
799  if (!$v['not_gpc']) {
800  $cleanv =& $ts->stripSlashesGPC($cleanv);
801  }
802  break;
803  case XOBJ_DTYPE_UNICODE_ARRAY:
804  $cleanv = serialize(array_walk($cleanv, 'xoops_aw_encode'));
805  break;
806  default:
807  break;
808 
809  }
810  }
811  $this->cleanVars[$k] = str_replace('\\"', '"', $cleanv);
812  unset($cleanv);
813  }
814  if (count($this->_errors) > 0) {
815  $this->_errors = array_merge($existing_errors, $this->_errors);
816  return false;
817  }
818  $this->_errors = array_merge($existing_errors, $this->_errors);
819  $this->unsetDirty();
820  return true;
821  }
822 
829  function registerFilter($filtername)
830  {
831  $this->_filters[] = $filtername;
832  }
833 
839  function _loadFilters()
840  {
841  static $loaded;
842  if (isset($loaded)) {
843  return;
844  }
845  $loaded = 1;
846 
847  $path = empty($this->plugin_path) ? dirname(__FILE__) . '/filters' : $this->plugin_path;
848  if (file_exists($file = $path . '/filter.php')) {
849  include_once $file;
850  foreach ($this->_filters as $f) {
851  if (file_exists($file = $path . '/' . strtolower($f) . 'php')) {
852  include_once $file;
853  }
854  }
855  }
856  }
857 
870  function loadFilters($method)
871  {
872  $this->_loadFilters();
873 
874  xoops_load('XoopsCache');
875  $class = get_class($this);
876  if (!$modules_active = XoopsCache::read('system_modules_active')) {
877  $module_handler =& xoops_gethandler('module');
878  $modules_obj = $module_handler->getObjects(new Criteria('isactive', 1));
879  $modules_active = array();
880  foreach (array_keys($modules_obj) as $key) {
881  $modules_active[] = $modules_obj[$key]->getVar('dirname');
882  }
883  unset($modules_obj);
884  XoopsCache::write('system_modules_active', $modules_active);
885  }
886  foreach ($modules_active as $dirname) {
887  if (file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/filter/' . $class . '.' . $method . '.php')) {
888  include_once $file;
889  if (function_exists($class . '_' . $method)) {
890  call_user_func_array($dirname . '_' . $class . '_' . $method, array(&$this));
891  }
892  }
893  }
894  }
895 
902  function &xoopsClone()
903  {
904  $class = get_class($this);
905  $clone = null;
906  $clone = new $class();
907  foreach ($this->vars as $k => $v) {
908  $clone->assignVar($k, $v['value']);
909  }
910  // need this to notify the handler class that this is a newly created object
911  $clone->setNew();
912  return $clone;
913  }
914 
921  function setErrors($err_str)
922  {
923  if (is_array($err_str)) {
924  $this->_errors = array_merge($this->_errors, $err_str);
925  } else {
926  $this->_errors[] = trim($err_str);
927  }
928  }
929 
936  function getErrors()
937  {
938  return $this->_errors;
939  }
940 
947  function getHtmlErrors()
948  {
949  $ret = '<h4>Errors</h4>';
950  if (!empty($this->_errors)) {
951  foreach ($this->_errors as $error) {
952  $ret .= $error . '<br />';
953  }
954  } else {
955  $ret .= 'None<br />';
956  }
957  return $ret;
958  }
959 
967  function toArray()
968  {
969  return $this->getValues();
970  }
971 }
972 
984 {
992  var $db;
993 
1001  {
1002  $this->db =& $db;
1003  }
1004 
1010  function &create()
1011  {
1012  }
1013 
1020  function &get($int_id)
1021  {
1022  }
1023 
1030  function insert(&$object)
1031  {
1032  }
1033 
1040  function delete(&$object)
1041  {
1042  }
1043 }
1044 
1055 {
1067 
1081  var $handlers = array('read' => null , 'stats' => null , 'joint' => null , 'write' => null , 'sync' => null);
1082 
1090  var $table;
1108  function __construct($db = null, $table = '', $className = '', $keyName = '', $identifierName = '')
1109  {
1111  $table = $db->prefix($table);
1112  $this->XoopsObjectHandler($db);
1113  $this->table = $table;
1114  $this->keyName = $keyName;
1115  $this->className = $className;
1116  if ($identifierName) {
1117  $this->identifierName = $identifierName;
1118  }
1119  }
1120 
1127  {
1129  }
1130 
1140  function setHandler($handler = null, $args = null, $path = null)
1141  {
1142  $this->handler = null;
1143  if (is_object($handler)) {
1144  $this->handler = $handler;
1145  } else if (is_string($handler)) {
1146  xoops_load('XoopsModelFactory');
1147  $this->handler = XoopsModelFactory::loadHandler($this, $handler, $args, $path);
1148  }
1149  return $this->handler;
1150  }
1151 
1160  function loadHandler($name, $args = null)
1161  {
1162  static $handlers;
1163  if (!isset($handlers[$name])) {
1164  xoops_load('XoopsModelFactory');
1165  $handlers[$name] = XoopsModelFactory::loadHandler($this, $name, $args);
1166  } else {
1167  $handlers[$name]->setHandler($this);
1168  $handlers[$name]->setVars($args);
1169  }
1170  return $handlers[$name];
1171 
1183  }
1184 
1195  function __call($name, $args)
1196  {
1197  if (is_object($this->handler) && is_callable(array($this->handler , $name))) {
1198  return call_user_func_array(array($this->handler , $name), $args);
1199  }
1200  foreach (array_keys($this->handlers) as $_handler) {
1201  $handler = $this->loadHandler($_handler);
1202  if (is_callable(array($handler, $name))) {
1203  return call_user_func_array(array($handler , $name), $args);
1204  }
1205  }
1206 
1207  return null;
1208  }
1209 
1221  function &create($isNew = true)
1222  {
1223  $obj = new $this->className();
1224  if ($isNew === true) {
1225  $obj->setNew();
1226  }
1227  return $obj;
1228  }
1229 
1238  function &get($id = null, $fields = null)
1239  {
1240  $object = null;
1241  if (empty($id)) {
1242  $object = $this->create();
1243  return $object;
1244  }
1245  if (is_array($fields) && count($fields) > 0) {
1246  $select = implode(',', $fields);
1247  if (!in_array($this->keyName, $fields)) {
1248  $select .= ', ' . $this->keyName;
1249  }
1250  } else {
1251  $select = '*';
1252  }
1253  $sql = sprintf('SELECT %s FROM %s WHERE %s = %s', $select, $this->table, $this->keyName, $this->db->quote($id));
1254  //$sql = "SELECT {$select} FROM {$this->table} WHERE {$this->keyName} = " . $this->db->quote($id);
1255  if (!$result = $this->db->query($sql)) {
1256  return $object;
1257  }
1258  if (!$this->db->getRowsNum($result)) {
1259  return $object;
1260  }
1261  $object =& $this->create(false);
1262  $object->assignVars($this->db->fetchArray($result));
1263 
1264  return $object;
1265  }
1281  function insert(&$object, $force = true)
1282  {
1283  $handler = $this->loadHandler('write');
1284  return $handler->insert($object, $force);
1285  }
1286 
1294  function delete(&$object, $force = false)
1295  {
1296  $handler = $this->loadHandler('write');
1297  return $handler->delete($object, $force);
1298  }
1299 
1308  function deleteAll($criteria = null, $force = true, $asObject = false)
1309  {
1310  $handler = $this->loadHandler('write');
1311  return $handler->deleteAll($criteria, $force, $asObject);
1312  }
1313 
1323  function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
1324  {
1325  $handler = $this->loadHandler('write');
1326  return $handler->updateAll($fieldname, $fieldvalue, $criteria, $force);
1327  }
1344  function &getObjects($criteria = null, $id_as_key = false, $as_object = true)
1345  {
1346  $handler = $this->loadHandler('read');
1347  $ret = $handler->getObjects($criteria, $id_as_key, $as_object);
1348  return $ret;
1349  }
1350 
1360  function &getAll($criteria = null, $fields = null, $asObject = true, $id_as_key = true)
1361  {
1362  $handler = $this->loadHandler('read');
1363  $ret = $handler->getAll($criteria, $fields, $asObject, $id_as_key);
1364  return $ret;
1365  }
1366 
1375  function getList($criteria = null, $limit = 0, $start = 0)
1376  {
1377  $handler = $this->loadHandler('read');
1378  $ret = $handler->getList($criteria, $limit, $start);
1379  return $ret;
1380  }
1381 
1388  function &getIds($criteria = null)
1389  {
1390  $handler = $this->loadHandler('read');
1391  $ret = $handler->getIds($criteria);
1392  return $ret;
1393  }
1394 
1407  function &getByLimit($limit = 0, $start = 0, $criteria = null, $fields = null, $asObject = true)
1408  {
1409  $handler = $this->loadHandler('read');
1410  $ret = $handler->getByLimit($limit, $start, $criteria, $fields, $asObject);
1411  return $ret;
1412  }
1427  function getCount($criteria = null)
1428  {
1429  $handler = $this->loadHandler('stats');
1430  return $handler->getCount($criteria);
1431  }
1432 
1439  function getCounts($criteria = null)
1440  {
1441  $handler = $this->loadHandler('stats');
1442  return $handler->getCounts($criteria);
1443  }
1462  function &getByLink($criteria = null, $fields = null, $asObject = true, $field_link = null, $field_object = null)
1463  {
1464  $handler = $this->loadHandler('joint');
1465  $ret = $handler->getByLink($criteria, $fields, $asObject, $field_link, $field_object);
1466  return $ret;
1467  }
1468 
1475  function getCountByLink($criteria = null)
1476  {
1477  $handler = $this->loadHandler('joint');
1478  $ret = $handler->getCountByLink($criteria);
1479  return $ret;
1480  }
1481 
1488  function getCountsByLink($criteria = null)
1489  {
1490  $handler = $this->loadHandler('joint');
1491  $ret = $handler->getCountsByLink($criteria);
1492  return $ret;
1493  }
1494 
1502  function updateByLink($data, $criteria = null)
1503  {
1504  $handler = $this->loadHandler('joint');
1505  $ret = $handler->updateByLink($data, $criteria);
1506  return $ret;
1507  }
1508 
1515  function deleteByLink($criteria = null)
1516  {
1517  $handler = $this->loadHandler('joint');
1518  $ret = $handler->deleteByLink($criteria);
1519  return $ret;
1520  }
1537  function cleanOrphan($table_link = '', $field_link = '', $field_object = '')
1538  {
1539  $handler = $this->loadHandler('sync');
1540  $ret = $handler->cleanOrphan($table_link, $field_link, $field_object);
1541  return $ret;
1542  }
1543 
1549  function synchronization()
1550  {
1551  $retval = $this->cleanOrphan();
1552  return $retval;
1553  }
1561  function convertResultSet($result, $id_as_key = false, $as_object = true)
1562  {
1563  trigger_error(__CLASS__ . "::" .__FUNCTION__ . ' is deprecated', E_USER_WARNING);
1564  return false;
1565  }
1567 }
1568 
1569 ?>