Exemple #1
0
 public function timeAgo($timestamp)
 {
     $timeAgo = CakeTime::timeAgoInWords($timestamp, array('accuracy' => array('hour' => 'hour'), 'end' => '1 year'));
     $timeAgo = trim(str_replace('ago', '', str_replace('second', 'seconde', str_replace('hour', 'heure', str_replace('day', 'jour', str_replace('week', 'semaine', str_replace('month', 'mois', $timeAgo)))))));
     if ($timeAgo == 'just now') {
         $timeAgo = 'il y a quelques secondes';
     } else {
         $timeAgo = 'il y a ' . $timeAgo;
     }
     return $timeAgo;
 }
Exemple #2
0
 public function afterFind($results, $primary = false)
 {
     Configure::write('debug', 2);
     App::uses("CakeTime", "Utility");
     $gc = new CakeTime();
     parent::afterFind($results, $primary);
     if (isset($results[0]['Order']['timestamp'])) {
         foreach ($results as $key => $val) {
             $results[$key]['Order']['created'] = $gc->timeAgoInWords($results[$key]['Order']['timestamp']);
         }
     }
     return $results;
 }
 /**
  * Auth Login page
  */
 public function admin_login()
 {
     if (Configure::read('Backend.Auth.enabled') !== true) {
         if (isset($this->Auth)) {
             $this->redirect($this->Auth->loginAction);
         } else {
             $this->redirect('/');
         }
     }
     $this->layout = "Backend.auth";
     $defaultRedirect = Configure::read('Backend.Dashboard.url') ? Configure::read('Backend.Dashboard.url') : array('plugin' => 'backend', 'controller' => 'backend', 'action' => 'dashboard');
     $redirect = false;
     if ($this->request->is('post')) {
         if (!$this->Auth->login()) {
             //Event Backend.Auth.onLoginFail
             $eventData = array('user' => $this->request->data['BackendUser'], 'ip' => $this->request->clientIp());
             // $event = new CakeEvent('Backend.Controller.Auth.onLoginFail', $this, $eventData);
             // $this->getEventManager()->dispatch($event);
             $this->Session->setFlash(__d('backend', 'Login failed'), 'error', array(), 'auth');
         } else {
             //Event Backend.Auth.onLogin
             $event = new CakeEvent('Backend.Controller.Auth.onLogin', $this, $this->Auth->user());
             //$this->getEventManager()->dispatch($event);
             $this->Session->setFlash(__d('backend', 'Login successful'), 'success');
             if ($this->Auth->user('lastlogin')) {
                 $this->Session->setFlash(__d('backend', 'Last login: %s', CakeTime::timeAgoInWords($this->Auth->user('last_login'))), 'default', array(), 'auth');
             }
             //TODO should the event result return an redirect url?
             if ($event->result) {
                 $redirect = $event->result;
             } else {
                 $redirect = $this->Auth->redirect();
             }
             $redirect = Router::normalize($redirect);
             if ($redirect == '/' || !preg_match('/^\\/admin\\//', $redirect) || $redirect == '/admin/backend') {
                 $redirect = $defaultRedirect;
             }
             $this->redirect($redirect);
         }
     } elseif ($this->Auth->user()) {
         $redirect = $this->referer($defaultRedirect, true);
         $this->redirect($redirect);
     }
     $this->set(compact('redirect'));
 }
Exemple #4
0
 /**
  * Formats a date into a phrase expressing the relative time.
  *
  * ## Addition options
  *
  * - `element` - The element to wrap the formatted time in.
  *   Has a few additional options:
  *   - `tag` - The tag to use, defaults to 'span'.
  *   - `class` - The class name to use, defaults to `time-ago-in-words`.
  *   - `title` - Defaults to the $dateTime input.
  *
  * @param int|string|DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object
  * @param array               $options  Default format if timestamp is used in $dateString
  *
  * @return string Relative time string.
  * @see  CakeTime::timeAgoInWords()
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 public function timeAgoInWords($dateTime, $options = array())
 {
     $element = NULL;
     if (!empty($options['element'])) {
         $element = array('tag' => 'span', 'class' => 'time-ago-in-words', 'title' => $dateTime);
         if (is_array($options['element'])) {
             $element = $options['element'] + $element;
         } else {
             $element['tag'] = $options['element'];
         }
         unset($options['element']);
     }
     $relativeDate = $this->_engine->timeAgoInWords($dateTime, $options);
     if ($element) {
         $relativeDate = sprintf('<%s%s>%s</%s>', $element['tag'], $this->_parseAttributes($element, array('tag')), $relativeDate, $element['tag']);
     }
     return $relativeDate;
 }
 /**
  * Operate over workers by sending a PCNTL signal.
  *
  * Note: The workers status is conveniently stored by ResqueStatus.
  *
  * @return void
  * @see ResqueStatus\ResqueStatus::isSchedulerWorker()
  */
 protected function _sendSignal($title, $workers, $noWorkersMessage, $listTitle, $allActionMessage, $promptMessage, $schedulerWorkerActionMessage, $workerActionMessage, $formatListItem, $successCallback, $signal, $schedulerWorkerAction = null)
 {
     if (!function_exists('pcntl_signal')) {
         return $this->out('<error>' . __d('cake_resque', "This function requires the PCNTL extension") . '</error>');
     }
     $ResqueStatus = $this->ResqueStatus;
     if ($formatListItem === null) {
         $formatListItem = function ($worker, $i) use($ResqueStatus) {
             App::uses('CakeTime', 'Utility');
             return sprintf("    [%3d] - %s, started %s", $i, $ResqueStatus->isSchedulerWorker($worker) ? '<comment>**Scheduler Worker**</comment>' : $worker, CakeTime::timeAgoInWords(call_user_func(CakeResqueShell::$cakeResque . '::getWorkerStartDate', $worker)));
         };
     }
     $this->out('<info>' . $title . '</info>');
     if (empty($workers)) {
         $this->out('   ' . $noWorkersMessage);
     } else {
         $workerIndex = array();
         if (!$this->params['all'] && count($workers) > 1) {
             $this->out($listTitle . ':');
             $i = 1;
             foreach ($workers as $worker) {
                 $this->out($formatListItem($worker, $i++));
             }
             $options = range(1, $i - 1);
             if ($i > 2) {
                 $this->out('    [all] - ' . $allActionMessage);
                 $options[] = 'all';
             }
             $in = $this->in($promptMessage . ': ', $options);
             if ($in == 'all') {
                 $workerIndex = range(1, count($workers));
             } else {
                 $workerIndex[] = $in;
             }
         } else {
             $workerIndex = range(1, count($workers));
         }
         foreach ($workerIndex as $index) {
             $worker = $workers[$index - 1];
             list($hostname, $pid, $queue) = explode(':', (string) $worker);
             if (Configure::read('CakeResque.Scheduler.enabled') === true && $ResqueStatus->isSchedulerWorker($worker)) {
                 if ($schedulerWorkerAction !== null) {
                     $schedulerWorkerAction($worker);
                 }
                 $this->out($schedulerWorkerActionMessage, 0);
             } else {
                 $this->out($workerActionMessage($pid), 0);
             }
             $killResponse = $this->_kill($signal, $pid);
             $successCallback($worker);
             if ($killResponse['code'] === 0) {
                 $this->out('<success>' . __d('cake_resque', 'Done') . '</success>');
             } else {
                 $this->out('<error>' . $killResponse['message'] . '</error>');
             }
         }
     }
     $this->out('');
 }