예제 #1
0
 /**
  * Create standard display vars for each view
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $controller_name = $request->getControllerName();
     $action_name = $request->getActionName();
     // redirect to facebook after share callback
     $url = $request->getRequestUri();
     if (strpos($url, '/fb-redirect') !== false) {
         $r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
         $r->gotoUrl('http://facebook.com')->redirectAndExit();
     }
     // add <head> code for all global pages
     $this->view->custom_head = Zend_Registry::get('config')->get('global_head') ? Zend_Registry::get('config')->get('global_head') : '';
     // global javascript vars
     $this->view->php_controller = $controller_name;
     $this->view->php_action = $action_name;
     // view perspective
     $this->view->view_perspective = 'global_view';
     // offset infinite scroll - for bots crawling without js
     if (isset($_GET['scroll_offset'])) {
         $scroll_offset = (int) $_GET['scroll_offset'];
         $this->view->post_page_number = $scroll_offset + 1;
     }
     // background image
     $this->view->app_background_image = Zend_Registry::get('config')->background;
     // for logged in users
     if (Zend_Auth::getInstance()->hasIdentity()) {
         // notifications
         $Notifications = new Application_Model_Notifications();
         $notifications_count = $Notifications->getUnreadNotificationsCount();
         $this->view->notifications_count = $notifications_count;
         $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/');
         $notifications_html = $this->view->render('/partial/notifications_popover.phtml');
         $this->view->notifications_html = $notifications_html;
         // new messages count
         $Messages = new Application_Model_Messages();
         $new_messages_count = $Messages->getMessagesCount(false, true);
         $this->view->new_messages_count = $new_messages_count;
     } else {
         // skip on ajax validator
         if ($action_name == 'validateformajax') {
             return;
         }
         $this->loginFormsLoader($request);
     }
     // attach app sidebar box
     Zend_Registry::get('hooks')->attach('hook_view_sidebar', 20, function () {
         echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/apps.phtml');
     });
     return;
 }
 /**
  * heartbeat actions (via continuous ajax call)
  */
 public function heartbeatAction()
 {
     $Notifications = new Application_Model_Notifications();
     $notifications = $Notifications->getNotifications(true, 10);
     $notifications_count = $Notifications->getUnreadNotificationsCount();
     $this->view->notifications = $notifications;
     $notifications_html = $this->view->render('/partial/notifications_popover.phtml');
     // new messages count
     $Messages = new Application_Model_Messages();
     $new_messages_count = $Messages->getMessagesCount(false, true);
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     // we will use timestamp format here since it's easier to calculate diff with ANSI SQL
     $ProfilesMeta->metaUpdate('last_heartbeat', time());
     $out = array('notification_count' => $notifications_count, 'notification_html' => $notifications_html, 'new_messages' => $new_messages_count);
     // trigger hooks
     Zend_Registry::get('hooks')->trigger('hook_app_heartbeat', $out);
     $this->_helper->json($out);
 }