public function initialize($Controller)
 {
     parent::initialize($Controller);
     $this->__checkBadLogins();
     $this->__blockByIp();
     $this->__setupAuth();
     $this->__setupSecurity();
 }
Ejemplo n.º 2
0
 public function initialize(Controller $Controller)
 {
     parent::initialize($Controller);
     $this->countryDataFile = dirname(dirname(dirname(__FILE__))) . DS . 'Lib' . DS . 'geoip' . DS . 'country.dat';
     $this->cityDataFile = dirname(dirname(dirname(__FILE__))) . DS . 'Lib' . DS . 'geoip' . DS . 'city.dat';
     $this->__autoUserLocation();
     return true;
 }
Ejemplo n.º 3
0
 public function initialize($Controller)
 {
     parent::initialize($Controller);
     if ($this->getAction(false) == 'cancel') {
         $Controller->Event->trigger('editCanceled', !empty($Controller->request->data[$Controller->modelClass]['id']) ? $Controller->request->data[$Controller->modelClass]['id'] : null);
         $Controller->redirect($Controller->getPageRedirectVar());
     }
 }
Ejemplo n.º 4
0
 public function beforeRender($Controller)
 {
     parent::beforeRender($Controller);
     if (empty($this->Controller->modelClass) || !$this->Controller->{$this->Controller->modelClass}->Behaviors->attached('Upload')) {
         // no model being used.
         return;
     }
     $fileUploadConfig = array();
     $this->set(compact('fileUploadConfig'));
 }
Ejemplo n.º 5
0
 /**
  * Bind the behavior for view counts.
  *
  * This is done here due to the fact that we need to know what action
  * we are on, and its only used some of the time. The other option is
  * to bind it always and unbind it here but that is more overhead.
  *
  * @var object $Controller the controller being used
  * @var array $settings the config
  *
  * @return null nothing needed
  */
 public function initialize(Controller $Controller, $settings = array())
 {
     parent::initialize($Controller);
     if ($this->Controller->Session->read('Spam.bot') || strstr($this->Controller->request->url, '?spam=true')) {
         return;
     }
     if (empty($this->Controller->modelClass)) {
         // no model being used.
         return;
     }
     $settings = array_merge($this->__settings, (array) $settings);
     $check = $settings['admin'] === false && !(isset($Controller->request->params['admin']) && $Controller->request->params['admin']) && in_array($Controller->request->params['action'], $settings['actions']);
     if ($check) {
         $Controller->{$Controller->modelClass}->Behaviors->attach('ViewCounter.Viewable');
         $Controller->{$Controller->modelClass}->__referer = $this->Controller->referer();
     }
 }
Ejemplo n.º 6
0
 public function __construct(ComponentCollection $collection, $settings = array())
 {
     parent::__construct($collection, $settings);
 }
Ejemplo n.º 7
0
 public function beforeRender(Controller $Controller)
 {
     parent::beforeRender($Controller);
     if ($Controller->layout == 'ajax') {
         return;
     }
     if (!empty($Controller->viewVars['error']) && $Controller->viewVars['error'] instanceof Exception) {
         $error = $Controller->viewVars['error'];
         unset($Controller->viewVars['error']);
     }
     $layout = array_values($Controller->viewVars);
     $theme = current(Set::extract('/Layout/theme_id', $layout));
     $layout = current(Set::extract('/Layout/layout', $layout));
     if (!empty($error)) {
         $Controller->viewVars['error'] = $error;
         $layout = 'error';
     }
     if ($layout) {
         Configure::write('Themes.default_layout', $layout);
     }
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeStart');
     if (isset($event['setupThemeStart'][$Controller->plugin])) {
         if (is_string($event['setupThemeStart'][$Controller->plugin])) {
             $Controller->theme = $event['setupThemeStart'][$Controller->plugin];
             return true;
         } else {
             if ($event['setupThemeStart'][$Controller->plugin] === false) {
                 return false;
             }
         }
     }
     $Controller->layout = Configure::read('Themes.default_layout');
     $theme = Cache::read('currentTheme');
     if ($theme === false) {
         $theme = ClassRegistry::init('Themes.Theme')->getCurrentTheme();
     }
     if (!empty($theme['Theme']['default_layout'])) {
         $Controller->layout = $theme['Theme']['default_layout'];
     }
     if (isset($Controller->request->params['admin']) && $Controller->request->params['admin']) {
         $Controller->layout = Configure::read('Themes.default_layout_admin');
     }
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeLayout', array('layout' => $Controller->layout, 'params' => $Controller->request->params));
     if (isset($event['setupThemeLayout'][$Controller->plugin]) && is_string($event['setupThemeLayout'][$Controller->plugin])) {
         $Controller->layout = $event['setupThemeLayout'][$Controller->plugin];
     }
     if (!isset($theme['Theme']['name'])) {
         $theme['Theme'] = array('name' => null);
     } else {
         $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeSelector', array('theme' => $theme['Theme'], 'params' => $Controller->request->params));
         if (isset($event['setupThemeSelector'][$Controller->plugin])) {
             if (is_array($event['setupThemeSelector'][$Controller->plugin])) {
                 $theme['Theme'] = $event['setupThemeSelector'][$Controller->plugin];
                 if (!isset($theme['Theme']['name'])) {
                     $this->cakeError('eventError', array('message' => 'The theme is invalid.', 'event' => $event));
                 }
             }
         }
     }
     $Controller->theme = $theme['Theme']['name'];
     Configure::write('Theme', $theme['Theme']);
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeRoutes', array('params' => $Controller->request->params));
     if (isset($event['setupThemeRoutes'][$Controller->plugin]) && !$event['setupThemeRoutes'][$Controller->plugin]) {
         return false;
     }
     if (empty($routes)) {
         $routes = Classregistry::init('Routes.Route')->getRoutes();
     }
     $currentRoute = Router::currentRoute(Configure::read('CORE.current_route'));
     if (!empty($routes) && is_object($currentRoute)) {
         foreach ($routes as $route) {
             if ($route['Route']['url'] == $currentRoute->template) {
                 if (!empty($route['Route']['theme'])) {
                     $Controller->theme = $route['Route']['theme'];
                 }
                 if (!empty($route['Route']['layout'])) {
                     $Controller->layout = $route['Route']['layout'];
                 }
             }
         }
     }
     $event = $Controller->Event->trigger($Controller->plugin . '.setupThemeEnd', array('theme' => $Controller->theme, 'params' => $Controller->request->params));
     if (isset($event['setupThemeEnd'][$Controller->plugin])) {
         if (is_string($event['setupThemeEnd'][$Controller->plugin])) {
             $Controller->theme = $event['setupThemeEnd'][$Controller->plugin];
         }
     }
     return true;
 }