Esempio n. 1
0
 public static function getMessages()
 {
     $session = \DF\Session::get('alerts');
     $messages = (array) $session->messages;
     unset($session->messages);
     return count($messages) > 0 ? $messages : false;
 }
Esempio n. 2
0
 /**
  * Returns the time in local and GMT.
  */
 public function timeAction()
 {
     $this->setCacheLifetime(0);
     // Re-enable session management for this API function.
     \DF\Session::enable();
     $tz_info = \PVL\Timezone::getInfo();
     return $this->returnSuccess(array('timestamp' => time(), 'gmt_datetime' => $tz_info['now_utc']->format('Y-m-d g:i:s'), 'gmt_date' => $tz_info['now_utc']->format('F j, Y'), 'gmt_time' => $tz_info['now_utc']->format('g:ia'), 'gmt_timezone' => 'GMT', 'gmt_timezone_abbr' => 'GMT', 'local_datetime' => $tz_info['now']->format('Y-m-d g:i:s'), 'local_date' => $tz_info['now']->format('F j, Y'), 'local_time' => $tz_info['now']->format('g:ia'), 'local_timezone' => $tz_info['code'], 'local_timezone_abbr' => $tz_info['abbr']));
 }
Esempio n. 3
0
 public function preDispatch()
 {
     parent::preDispatch();
     // Disable session creation.
     \DF\Session::disable();
     // Disable rendering.
     $this->doNotRender();
     // Allow AJAX retrieval.
     $this->response->setHeader('Access-Control-Allow-Origin', '*');
     // Fix the base URL prefixed with '//'.
     \DF\Url::forceSchemePrefix(true);
     $this->_time_start = microtime(true);
     // Set all API calls to be public cache-controlled by default.
     $this->setCachePrivacy('public');
     $this->setCacheLifetime(30);
 }
Esempio n. 4
0
 public function tuneinAction()
 {
     $this->forceInsecure();
     // Disable session creation.
     \DF\Session::disable();
     // Switch to maintenance theme.
     $this->view->setTemplateAfter('maintenance');
     $this->view->embed_mode = $this->getParam('embed', 'false') == 'true';
     $this->view->skin = $this->getParam('skin');
     $autoplay = $this->getParam('autoplay');
     if ($this->hasParam('autoplay')) {
         $autoplay = $autoplay === 'true' || $autoplay === '1';
     } else {
         $autoplay = false;
     }
     $this->view->autoplay = $autoplay;
     $this->view->standalone = true;
     $this->_initStations();
 }
Esempio n. 5
0
 protected function _vote($value)
 {
     // Re-enable session creation.
     \DF\Session::enable();
     $sh_id = (int) $this->getParam('sh_id');
     $sh = SongHistory::find($sh_id);
     if ($sh instanceof SongHistory) {
         if ($value == 0) {
             $vote_result = $sh->clearVote();
         } else {
             $vote_result = $sh->vote($value);
         }
         if ($vote_result) {
             return $this->returnSuccess('OK');
         } else {
             return $this->returnError('Vote could not be applied.');
         }
     } else {
         return $this->returnError('Song history record not found.');
     }
 }
Esempio n. 6
0
 /**
  * ArrayAccess form of __unset
  *
  * @param mixed $name
  */
 public function offsetUnset($name)
 {
     unset($this->_data[$name]);
     if (\DF\Session::isActive()) {
         \DF\Session::start();
         unset($_SESSION[$this->_namespace][$name]);
     }
 }
Esempio n. 7
0
 protected function clearStoredReferrer($namespace = 'default')
 {
     $session = Session::get('referrer_' . $namespace);
     unset($session->url);
 }
Esempio n. 8
0
 public static function handle(\Exception $e, \Phalcon\DiInterface $di)
 {
     if ($e instanceof \DF\Exception\NotLoggedIn) {
         // Redirect to login page for not-logged-in users.
         \DF\Flash::addMessage('You must be logged in to access this page!');
         // Set referrer for login redirection.
         $session = \DF\Session::get('referrer_login');
         $session->url = \DF\Url::current($di);
         // Redirect to login page.
         $login_url = $di->get('url')->get('account/login');
         $response = $di->get('response');
         $response->redirect($login_url, 302);
         $response->send();
         return;
     } elseif ($e instanceof \DF\Exception\PermissionDenied) {
         // Bounce back to homepage for permission-denied users.
         \DF\Flash::addMessage('You do not have permission to access this portion of the site.', \DF\Flash::ERROR);
         $home_url = $di->get('url')->get('');
         $response = $di->get('response');
         $response->redirect($home_url, 302);
         $response->send();
         return;
     } elseif ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) {
         // Handle 404 page not found exception
         if ($di->has('view')) {
             $view = $di->get('view');
             $view->disable();
         }
         $view = \DF\Phalcon\View::getView(array());
         $result = $view->getRender('error', 'pagenotfound');
         $response = $di->get('response');
         $response->setStatusCode(404, "Not Found");
         $response->setContent($result);
         $response->send();
         return;
     } elseif ($e instanceof \DF\Exception\Bootstrap) {
         // Bootstrapping error; cannot render template for error display.
         if (DF_APPLICATION_ENV != 'production') {
             self::renderPretty($e, $di);
             return;
         } else {
             $response = $di->get('response');
             $response->setStatusCode(500, "Internal Server Error");
             $exception_msg = "<b>Application core exception: </b>\n<blockquote>" . $e->getMessage() . "</blockquote>" . "\n" . "on line <b>" . $e->getLine() . "</b> of <i>" . $e->getFile() . "</i>";
             $response->setContent($exception_msg);
             $response->send();
             return;
         }
     } else {
         if ($di->has('view')) {
             $view = $di->get('view');
             $view->disable();
         }
         $show_debug = false;
         if ($di->has('acl')) {
             $acl = $di->get('acl');
             if ($acl->isAllowed('administer all')) {
                 $show_debug = true;
             }
         }
         if (DF_APPLICATION_ENV != 'production') {
             $show_debug = true;
         }
         if ($show_debug) {
             self::renderPretty($e, $di);
             return;
         } else {
             $view = \DF\Phalcon\View::getView(array());
             $view->setVar('exception', $e);
             $result = $view->getRender('error', 'general');
             $response = $di->get('response');
             $response->setStatusCode(500, "Internal Server Error");
             $response->setContent($result);
             $response->send();
             return;
         }
     }
 }
Esempio n. 9
0
 public function logoutAction()
 {
     $this->auth->logout();
     \DF\Session::destroy();
     $this->redirectToRoute(array('module' => 'default'));
 }
Esempio n. 10
0
 public function getSession()
 {
     $class_name = strtolower(str_replace(array('\\', '_'), array('', ''), get_called_class()));
     return \DF\Session::get('auth_' . $class_name . '_user');
 }
Esempio n. 11
0
 public static function getSession()
 {
     return \DF\Session::getNamespace('customization');
 }