filter.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * ZenTaoPHP的验证和过滤类。
  4. * The validater and fixer class file of ZenTaoPHP framework.
  5. *
  6. * The author disclaims copyright to this source code. In place of
  7. * a legal notice, here is a blessing:
  8. *
  9. * May you do good and not evil.
  10. * May you find forgiveness for yourself and forgive others.
  11. * May you share freely, never taking more than you give.
  12. */
  13. helper::import(dirname(dirname(__FILE__)) . '/base/filter/filter.class.php');
  14. /**
  15. * validater类,检查数据是否符合规则。
  16. * The validater class, checking data by rules.
  17. *
  18. * @package framework
  19. */
  20. class validater extends baseValidater
  21. {
  22. /**
  23. * 检查文件名。
  24. * Check file name.
  25. *
  26. * @param string $var
  27. * @static
  28. * @access public
  29. * @return bool
  30. */
  31. public static function checkFileName($var)
  32. {
  33. return !preg_match('/>+|<+/', $var);
  34. }
  35. }
  36. /**
  37. * fixer类,处理数据。
  38. * fixer class, to fix data types.
  39. *
  40. * @package framework
  41. */
  42. class fixer extends baseFixer
  43. {
  44. /**
  45. * 过滤Emoji表情。
  46. * Filter Emoji.
  47. *
  48. * @param string $value
  49. * @access public
  50. * @return object
  51. */
  52. public function filterEmoji($value)
  53. {
  54. if(is_object($value) or is_array($value))
  55. {
  56. foreach($value as $subValue)
  57. {
  58. $subValue = $this->filterEmoji($subValue);
  59. }
  60. }
  61. else
  62. {
  63. $value = preg_replace_callback('/./u', function (array $match)
  64. {
  65. return strlen($match[0]) >= 4 ? '' : $match[0];
  66. }, $value);
  67. }
  68. return $value;
  69. }
  70. /**
  71. * 对工作流配置的日期格式字段赋予NULL默认值。
  72. * Assign a default value of NULL to the date format field of the workflow configuration.
  73. *
  74. * @param string $fieldName
  75. * @access public
  76. * @return mixed
  77. * @param string $fields
  78. */
  79. public function get($fields = '')
  80. {
  81. global $config, $app;
  82. if($config->edition != 'open' && empty($app->installing) && (!defined('RUN_MODE') || !in_array(RUN_MODE, array('api', 'test'))))
  83. {
  84. $moduleName = $app->getModuleName();
  85. $methodName = $app->getMethodName();
  86. $flow = $app->control->loadModel('workflow')->getByModule($moduleName);
  87. if(!$flow) return parent::get($fields);
  88. $action = $app->control->loadModel('workflowaction')->getByModuleAndAction($flow->module, $methodName);
  89. if(!$action || $action->extensionType != 'extend') return parent::get($fields);
  90. $fieldList = $app->control->workflowaction->getPageFields($flow->module, $action->action);
  91. $layouts = $app->control->loadModel('workflowlayout')->getFields($moduleName, $methodName);
  92. if($layouts)
  93. {
  94. foreach($fieldList as $key => $field)
  95. {
  96. if($field->buildin || !$field->show || !isset($layouts[$field->field])) continue;
  97. if($field->control == 'date' || $field->control == 'datetime')
  98. {
  99. if(empty($this->data->{$field->field})) $this->data->{$field->field} = NULL;
  100. }
  101. }
  102. }
  103. }
  104. return parent::get($fields);
  105. }
  106. }