예제 #1
0
 /**
  * Check if any filter stored in Session must be cleared.
  *
  * It return true when:
  *
  * 	- $this->auto_clear_filter is set to true
  * 	- HTTP referer doesn't belong to any CRUD action of the same Model and same prefix
  *
  * 		ex:	current page = admin_index
  *			referer      = admin_edit
  *			-> don't clean the filters)
  */
 private function must_clear_filter()
 {
     if ($this->auto_clear_filter == false) {
         return false;
     } else {
         if (isset($_SERVER['HTTP_REFERER'])) {
             $plugin = $this->controller->params['plugin'];
             $controller = $this->controller->params['controller'];
             $prefix = !empty($this->controller->params['prefix']) ? $this->controller->params['prefix'] . '_' : null;
             $index_action = Router::url(array('plugin' => $plugin, 'controller' => $controller, 'action' => $prefix . 'index'), true);
             $explicit_index_action = $index_action . '/index';
             $view_action = Router::url(array('plugin' => $plugin, 'controller' => $controller, 'action' => $prefix . 'view'), true);
             $add_action = Router::url(array('plugin' => $plugin, 'controller' => $controller, 'action' => $prefix . 'add'), true);
             $edit_action = Router::url(array('plugin' => $plugin, 'controller' => $controller, 'action' => $prefix . 'edit'), true);
             $delete_action = Router::url(array('plugin' => $plugin, 'controller' => $controller, 'action' => $prefix . 'delete'), true);
             if (in_array($_SERVER['HTTP_REFERER'], array($index_action, $explicit_index_action, $view_action, $add_action, $edit_action, $delete_action)) || StringTool::start_with($_SERVER['HTTP_REFERER'], StringTool::ensure_end_with($index_action, '/')) || StringTool::start_with($_SERVER['HTTP_REFERER'], StringTool::ensure_end_with($explicit_index_action, '/')) || StringTool::start_with($_SERVER['HTTP_REFERER'], StringTool::ensure_end_with($view_action, '/')) || StringTool::start_with($_SERVER['HTTP_REFERER'], StringTool::ensure_end_with($add_action, '/')) || StringTool::start_with($_SERVER['HTTP_REFERER'], StringTool::ensure_end_with($edit_action, '/')) || StringTool::start_with($_SERVER['HTTP_REFERER'], StringTool::ensure_end_with($delete_action, '/'))) {
                 return false;
             }
         }
         return true;
     }
 }