public function execute($filterChain)
 {
     $context = $this->getContext();
     $session_user = $context->getUser();
     $cookie_name = sfConfig::get('app_remember_key_cookie_name', 'c2corg_remember');
     $cookie_value = $context->getRequest()->getCookie($cookie_name);
     if ($this->isFirstCall() && !$session_user->isConnected() && !is_null($cookie_value)) {
         c2cTools::log('{rememberFilter} user has a cookie, trying to auto login');
         $remember_key = RememberKey::getKey($cookie_value);
         if ($remember_key) {
             c2cTools::log('{rememberFilter} user found from his cookie');
             $user = $remember_key->getUser();
             if ($user->exists()) {
                 $session_user->signIn($user->get('private_data')->getLoginName(), $user->get('private_data')->getPassword(), true, true);
             }
             // User has signed in, and is now correctly in symfony session. However, forums
             // and several personnalization functions rely on cookies, that will be sent with the request,
             // but are not yet 'available' from javascript if the value expired from previous sessions (they will be on next page)
             // easiest solution is to force the browser to reload the current page
             // we only do this for GET requests
             $request = $this->getContext()->getRequest();
             if ($request->getMethod() == sfRequest::GET) {
                 // symfony 1.0 getUriPrefix is not working well with https on haproxy
                 // it then tries to redirect to https://site.org:80, which is wrong
                 $proto = $request->isSecure() ? 'https' : 'http';
                 $request_uri = $proto . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
                 $this->getContext()->getController()->redirect($request_uri);
                 exit;
             }
         } else {
             // delete cookie value in client so that no more requests are made to the db
             sfContext::getInstance()->getResponse()->setCookie($cookie_name, '');
             // log this
             c2cTools::log('{rememberFilter} user has unknown remember key!');
             c2cActions::statsdIncrement('bad_remember_cookie', 'symfony.' . sfConfig::get('sf_environment') . '.users.');
         }
     }
     $filterChain->execute();
 }
 /**
  * Executes list action, adding parkings linked to routes
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $routes = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     // if they are criterias on the summit (snam, srnam, salt, styp)
     // we might have only some of the associated summits and not the 'best one' (ticket #337)
     // so we must add a new request to get the summits, display the best one and add a note to explain that the
     // other summit is associated
     // FIXME would be nice to put all in a single request (before), but I didn't manage to do it
     // TODO not working right now
     //if ($this->hasRequestParameter('snam') || $this->hasRequestParameter('srnam') ||
     //    $this->hasRequestParameter('salt') || $this->hasRequestParameter('styp'))
     //{
     // $routes = Route::addBestSummitName($routes, '');
     //}
     $timer = new sfTimer();
     Parking::addAssociatedParkings($routes, 'pr');
     // add associated parkings infos to $routes
     c2cActions::statsdTiming('parking.addAssociatedParkings', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($routes, 'ro', true);
     // number of associated outings
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($routes);
     $this->items = Language::parseListItems($routes, 'Route');
 }
 /**
  * RSS list of latest created documents.
  */
 public function executeLatest()
 {
     $timer = new sfTimer('executeLatest');
     $this->documents = Document::getLastDocs($this->__(' :') . ' ');
     $this->setLayout(false);
     $this->setCacheControl(3600);
     c2cActions::statsdTiming('document.executeLatest', $timer->getElapsedTime('executeLatest'));
 }
 /**
  * Executes this filter.
  *
  * @param sfFilterChain The filter chain
  *
  * @throws <b>sfInitializeException</b> If an error occurs during view initialization.
  * @throws <b>sfViewException</b>       If an error occurs while executing the view.
  */
 public function execute($filterChain)
 {
     // get the context and controller
     $context = $this->getContext();
     $controller = $context->getController();
     // get the current action instance
     $actionEntry = $controller->getActionStack()->getLastEntry();
     $actionInstance = $actionEntry->getActionInstance();
     // get the current action information
     $moduleName = $context->getModuleName();
     $actionName = $context->getActionName();
     // get the request method
     $method = $context->getRequest()->getMethod();
     $viewName = null;
     $statsdPrefix = c2cActions::statsdPrefix($moduleName, $actionName);
     if (sfConfig::get('sf_cache')) {
         // get current uri adapted for cache
         $uri = MyCacheFilter::getCurrentCacheUri();
         // best way would be to modify uri (and not the whole cache management system)
         // but we have no way to extend getCurrentInternalUri method in sfRouting class just for cache
         if (null !== $context->getResponse()->getParameter($uri . '_action', null, 'symfony/cache')) {
             // action in cache, so go to the view
             $viewName = sfView::SUCCESS;
         }
     }
     if (!$viewName) {
         if (($actionInstance->getRequestMethods() & $method) != $method) {
             // this action will skip validation/execution for this method
             // get the default view
             $viewName = $actionInstance->getDefaultView();
         } else {
             // set default validated status
             $validated = true;
             // get the current action validation configuration
             $validationConfig = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . $actionName . '.yml';
             // load validation configuration
             // do NOT use require_once
             if (null !== ($validateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfig, true))) {
                 // create validator manager
                 $validatorManager = new sfValidatorManager();
                 $validatorManager->initialize($context);
                 require $validateFile;
                 // process validators
                 $validated = $validatorManager->execute();
             }
             // process manual validation
             $validateToRun = 'validate' . ucfirst($actionName);
             $manualValidated = method_exists($actionInstance, $validateToRun) ? $actionInstance->{$validateToRun}() : $actionInstance->validate();
             // action is validated if:
             // - all validation methods (manual and automatic) return true
             // - or automatic validation returns false but errors have been 'removed' by manual validation
             $validated = $manualValidated && $validated || $manualValidated && !$validated && !$context->getRequest()->hasErrors();
             // register fill-in filter
             if (null !== ($parameters = $context->getRequest()->getAttribute('fillin', null, 'symfony/filter'))) {
                 $this->registerFillInFilter($filterChain, $parameters);
             }
             if ($validated) {
                 if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                     $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $moduleName, $actionName));
                 }
                 // execute the action
                 $statsdTimer = new sfTimer();
                 $actionInstance->preExecute();
                 c2cActions::statsdTiming('execution.action.preExecute', $statsdTimer->getElapsedTime(), $statsdPrefix);
                 $statsdTimer = new sfTimer();
                 $viewName = $actionInstance->execute();
                 c2cActions::statsdTiming('execution.action.execute', $statsdTimer->getElapsedTime(), $statsdPrefix);
                 if ($viewName == '') {
                     $viewName = sfView::SUCCESS;
                 }
                 $statsdTimer = new sfTimer();
                 $actionInstance->postExecute();
                 c2cActions::statsdTiming('execution.action.postExecute', $statsdTimer->getElapsedTime(), $statsdPrefix);
                 if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                     $timer->addTime();
                 }
             } else {
                 if (sfConfig::get('sf_logging_enabled')) {
                     $this->context->getLogger()->info('{sfFilter} action validation failed');
                 }
                 // validation failed
                 $handleErrorToRun = 'handleError' . ucfirst($actionName);
                 $viewName = method_exists($actionInstance, $handleErrorToRun) ? $actionInstance->{$handleErrorToRun}() : $actionInstance->handleError();
                 if ($viewName == '') {
                     $viewName = sfView::ERROR;
                 }
             }
         }
     }
     if ($viewName == sfView::HEADER_ONLY) {
         $context->getResponse()->setHeaderOnly(true);
         // execute next filter
         $filterChain->execute();
     } else {
         if ($viewName != sfView::NONE) {
             if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                 $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $moduleName, $actionName));
             }
             // get the view instance
             $statsdTimer = new sfTimer();
             $viewInstance = $controller->getView($moduleName, $actionName, $viewName);
             c2cActions::statsdTiming("execution.view.{$viewName}.getView", $statsdTimer->getElapsedTime(), $statsdPrefix);
             $statsdTimer = new sfTimer();
             $viewInstance->initialize($context, $moduleName, $actionName, $viewName);
             c2cActions::statsdTiming("execution.view.{$viewName}.initialize", $statsdTimer->getElapsedTime(), $statsdPrefix);
             $statsdTimer = new sfTimer();
             $viewInstance->execute();
             c2cActions::statsdTiming("execution.view.{$viewName}.execute", $statsdTimer->getElapsedTime(), $statsdPrefix);
             // render the view and if data is returned, stick it in the
             // action entry which was retrieved from the execution chain
             $statsdTimer = new sfTimer();
             $viewData = $viewInstance->render();
             c2cActions::statsdTiming("execution.view.{$viewName}.render", $statsdTimer->getElapsedTime(), $statsdPrefix);
             if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                 $timer->addTime();
             }
             if ($controller->getRenderMode() == sfView::RENDER_VAR) {
                 $actionEntry->setPresentation($viewData);
             } else {
                 // execute next filter
                 $filterChain->execute();
             }
         }
     }
 }
 /**
  * Executes list action, adding ratings from routes linked to outings
  */
 public function executeList()
 {
     // redirect to user outings list if connected and if myoutings criteria is set
     if ($this->getUser()->isConnected() && $this->getRequestParameter('myoutings')) {
         sfLoader::loadHelpers(array('Pagination'));
         $user_id = $this->getUser()->getId();
         $this->redirect(_addUrlParameters(_getBaseUri(), array('myoutings'), array('users' => $user_id)));
     }
     // TODO something to do if outings where filtered on route ratings?
     parent::executeList();
     $format = $this->format;
     if (in_array('cond', $format) && !in_array('json', $format)) {
         $this->setTemplate('conditions');
         if (in_array('full', $format)) {
             $this->setPageTitle($this->__('conditions and comments'));
         } else {
             $this->setPageTitle($this->__('recent conditions'));
         }
     }
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $show_images = $this->show_images;
     $timer = new sfTimer();
     $outings = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     $outings = Outing::getAssociatedCreatorData($outings);
     // retrieve outing creator names
     c2cActions::statsdTiming('outing.getAssociatedCreatorData', $timer->getElapsedTime());
     $timer = new sfTimer();
     $outings = Outing::getAssociatedRoutesData($outings);
     // retrieve associated route ratings
     c2cActions::statsdTiming('outing.getAssociatedRoutesData', $timer->getElapsedTime());
     if (!in_array('list', $format)) {
         $timer = new sfTimer();
         $outings = Language::getTheBestForAssociatedAreas($outings);
         c2cActions::statsdTiming('language.getTheBestForAssociatedAreas', $timer->getElapsedTime());
     }
     // add images infos
     if ($show_images) {
         $timer = new sfTimer();
         Image::addAssociatedImages($outings, 'oi');
         c2cActions::statsdTiming('image.addAssociatedImages', $timer->getElapsedTime());
     }
     Area::sortAssociatedAreas($outings);
     $this->items = Language::parseListItems($outings, 'Outing', !$show_images);
 }
 /**
  * Executes list action
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $summits = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($summits, 'sr', true);
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($summits);
     $this->items = Language::parseListItems($summits, 'Summit');
 }
 /**
  * Executes list action
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $sites = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     Parking::addAssociatedParkings($sites, 'pt');
     // add associated parkings infos to $sites
     c2cActions::statsdTiming('parking.addAssociatedParkings', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($sites, 'to', true);
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($sites);
     $this->items = Language::parseListItems($sites, 'Site');
 }