CoreProgramBehavior.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\admin\behavior;
  3. /**
  4. * 系统行为扩展:
  5. */
  6. class CoreProgramBehavior {
  7. protected static $actionName;
  8. protected static $controllerName;
  9. protected static $moduleName;
  10. /**
  11. * 构造方法
  12. * @param Request $request Request对象
  13. * @access public
  14. */
  15. public function __construct()
  16. {
  17. }
  18. // 行为扩展的执行入口必须是run
  19. public function run(&$params){
  20. self::$actionName = request()->action();
  21. self::$controllerName = request()->controller();
  22. self::$moduleName = request()->module();
  23. // file_put_contents ( DATA_PATH."log.txt", date ( "Y-m-d H:i:s" ) . " " . var_export('admin_CoreProgramBehavior',true) . "\r\n", FILE_APPEND );
  24. $this->_initialize();
  25. }
  26. protected function _initialize() {
  27. $this->setChanneltypeStatus();
  28. }
  29. /**
  30. * 根据前端模板自动开启系统模型
  31. */
  32. protected function setChanneltypeStatus()
  33. {
  34. /*不在以下相应的控制器和操作名里不往下执行,以便提高性能*/
  35. $ctlActArr = array(
  36. 'Index@index',
  37. 'System@clearCache',
  38. );
  39. $ctlActStr = self::$controllerName.'@'.self::$actionName;
  40. if (!in_array($ctlActStr, $ctlActArr)) {
  41. return false;
  42. }
  43. /*--end*/
  44. $planPath = 'template/pc';
  45. $planPath = realpath($planPath);
  46. if (!file_exists($planPath)) {
  47. return false;
  48. }
  49. $ctl_name_arr = array();
  50. $dirRes = opendir($planPath);
  51. $view_suffix = config('template.view_suffix');
  52. while($filename = readdir($dirRes))
  53. {
  54. if(preg_match('/^(lists|view)?_/i', $filename) == 1)
  55. {
  56. $tplname = preg_replace('/([^_]+)?_([^\.]+)\.'.$view_suffix.'$/i', '${2}', $filename);
  57. $ctl_name_arr[] = ucwords($tplname);
  58. } elseif (preg_match('/\.'.$view_suffix.'$/i', $filename) == 1) {
  59. $tplname = preg_replace('/\.'.$view_suffix.'$/i', '', $filename);
  60. $ctl_name_arr[] = ucwords($tplname);
  61. }
  62. }
  63. $ctl_name_arr = array_unique($ctl_name_arr);
  64. if (!empty($ctl_name_arr)) {
  65. M('Channeltype')->where('id > 0')->cache(true,null,"channeltype")->update(array('status'=>0, 'update_time'=>getTime()));
  66. $map = array(
  67. 'ctl_name' => array('IN', $ctl_name_arr),
  68. );
  69. M('Channeltype')->where($map)->cache(true,null,"channeltype")->update(array('status'=>1, 'update_time'=>getTime()));
  70. }
  71. }
  72. }