Esempio n. 1
0
 public function errorAction()
 {
     Zend_Registry::set('CMS', false);
     $errors = $this->_getParam('error_handler');
     $this->_setLayoutForErrorResponse();
     if (!$errors) {
         return;
     }
     if (!$this->view) {
         $bootstrap = Zend_Registry::get('application')->getBootstrap();
         $this->view = $bootstrap->getResource('View');
     }
     switch ($errors->type) {
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
         case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
             // 404 error -- controller or action not found
             $this->getResponse()->setHttpResponseCode(404);
             $this->view->httpCode = 404;
             $this->view->message = 'Page not found';
             break;
         default:
             // application error
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->httpCode = 500;
             $this->view->message = 'Application error';
             break;
     }
     $this->view->exception = $errors->exception;
     $this->view->request = $errors->request;
     $displayErrorsConfig = ini_get('display_errors');
     $this->view->displayErrors = $displayErrorsConfig;
     if ($displayErrorsConfig) {
         if ($errors->exception instanceof Zend_Db_Exception) {
             $profiler = Zend_Db_Table::getDefaultAdapter()->getProfiler();
             if ($profiler && $profiler->getLastQueryProfile()) {
                 $this->view->lastQuery = $profiler->getLastQueryProfile()->getQuery();
             }
         }
         return;
     }
     // Oh dear, this is the production environment. This is serious.
     // Better log the error and mail a crash report to a nerd somewhere.
     if ($this->getResponse()->getHttpResponseCode() != 500) {
         return;
     }
     Garp_ErrorHandler::logErrorToFile($errors);
     $sentry = Garp_Service_Sentry::getInstance();
     if ($sentry->isActive()) {
         $sentry->log($errors->exception);
         return;
     }
     if (!Garp_ErrorHandler::logErrorToSlack($errors)) {
         Garp_ErrorHandler::mailErrorToAdmin($errors);
     }
 }
Esempio n. 2
0
 /**
  * Load translation data
  *
  * @param  string|array  $data
  * @param  string        $locale  Locale/Language to add data for, identical with locale identifier,
  *                                see Zend_Locale for more information
  * @param  array         $options OPTIONAL Options to use
  * @return array
  */
 protected function _loadTranslationData($data, $locale, array $options = array())
 {
     $data = array();
     try {
         $i18nModelFactory = new Garp_I18n_ModelFactory($locale);
         $snippetModel = $i18nModelFactory->getModel('Snippet');
         $out = array();
         $data = $snippetModel->fetchAll($snippetModel->select()->from($snippetModel->getName(), array('identifier', 'text' => new Zend_Db_Expr('IF(text IS NULL, IF(name IS NULL, identifier, name), text)')))->where('has_text = ?', 1)->orWhere('has_name = ?', 1)->order('identifier ASC'));
         $data = $this->_reformatData($data);
     } catch (Zend_Db_Adapter_Exception $e) {
         Garp_ErrorHandler::handlePrematureException($e);
     }
     $out[$locale] = $data;
     return $out;
 }
Esempio n. 3
0
 /**
  * Create a unique token for the currently logged in user.
  * @param String $input Serialized user data
  * @return String
  */
 public function createToken($input)
 {
     $config = $this->getConfigValues();
     $salt = $config['salt'];
     $token = '';
     $token .= !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $token .= md5($input);
     $token .= md5($salt);
     /**
      * Embed an outline of the User table columns in the token. That way, whenever the
      * database changes, all current cookies are made invalid and users have to generate a
      * new cookie afresh by logging in.
      * This ensures the user cookies always contains all the columns.
      */
     $columns = '';
     try {
         $userModel = new Model_User();
         $columns = $userModel->info(Zend_Db_Table_Abstract::COLS);
         $columns = implode('.', $columns);
     } catch (Zend_Db_Adapter_Exception $e) {
         Garp_ErrorHandler::handlePrematureException($e);
     }
     $token .= $columns;
     $token = md5($token);
     return $token;
 }