/** * Read / Compose a new message (via ajax) */ public function newAction() { $current_user = Zend_Auth::getInstance()->getIdentity(); $request = $this->getRequest(); $to_user = $request->getParam('to', false); $offset = $request->getParam('offset', false); $Profiles = new Application_Model_Profiles(); $ProfilesMeta = new Application_Model_ProfilesMeta(); $Connections = new Application_Model_Connections(); $Messages = new Application_Model_Messages(); $Notifications = new Application_Model_Notifications(); $message_form = new Application_Form_Message(); $this->view->message_form = $message_form; $user = $Profiles->getProfile($to_user); $json_ret = array('errors' => '', 'html' => '', 'offset' => ''); if (!$user || !isset($user->id) || $user->type != 'user') { $json_ret['errors'] = $this->view->translate('This user does not exist'); // exit $this->getHelper('json')->sendJson($json_ret); } $users_meta = $ProfilesMeta->getMetaValues($user->id); // check private message privacy if ($current_user->role != 'admin' && $current_user->role != 'reviewer' && isset($users_meta['contact_privacy']) && $users_meta['contact_privacy'] == 'f' && !$Connections->areFriends($current_user->id, $user->id)) { $json_ret['errors'] = $this->view->translate('Private profile (friends only)'); // exit $this->getHelper('json')->sendJson($json_ret); } $this->view->to_screen_name = $user->screen_name; if ($request->isPost() && $message_form->isValid($_POST)) { $content = $message_form->getValue('content'); $result = $Messages->sendMessage($user->id, $content); if (!$result) { $json_ret['errors'] = $this->view->translate('Server-side error'); // exit $this->getHelper('json')->sendJson($json_ret); } // mark as read $Messages->markAsRead($user->id); } // get new messages $messages = $Messages->getMessages($user->id, $offset); // clear email notifications since you are looking at them right now $Notifications->clearEmailNotifications(8); if (!empty($messages)) { // send last visible message $last = end($messages); $json_ret['offset'] = $last['message_id']; foreach ($messages as $message) { $this->view->message = $message; $json_ret['html'] .= $this->view->render('/partial/message.phtml'); } } $this->getHelper('json')->sendJson($json_ret); }
/** * Change notifications */ public function changenotificationsAction() { $this->buildMenu(); $Notifications = new Application_Model_Notifications(); $notifications_form = new Application_Form_Notifications(); $this->view->notifications_form = $notifications_form; $request = $this->getRequest(); $ProfilesMeta = new Application_Model_ProfilesMeta(); if ($request->isPost()) { // Form Submitted... if ($notifications_form->isValid($_POST)) { Application_Plugin_Common::redirectOnDemoAccount(); // clear email notifications up to now $Notifications->clearEmailNotifications(); $elements = $notifications_form->getElements(); $bulk_notifications = array(); foreach ($elements as $element) { $element_id = $element->getId(); if ($element_id == 'submitbtn' || $element_id == 'identifier') { continue; } $bulk_notifications[$element_id] = $element->getValue(); } $ProfilesMeta->metaUpdate('bulk_notifications', json_encode($bulk_notifications)); Application_Plugin_Alerts::success($this->view->translate('Notifications updated')); } } }