/**
  * 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);
 }
 /**
  * Accept / Remove group membership
  */
 public function membershipAction()
 {
     $user_name = $this->getRequest()->getParam('name');
     $group_name = $this->getRequest()->getParam('group');
     $action = $this->getRequest()->getParam('do');
     $Connections = new Application_Model_Connections();
     $Profiles = new Application_Model_Profiles();
     // get user
     $user_profile = $Profiles->getProfile($user_name);
     // get group and check ownership
     $group_profile = $Profiles->getProfile($group_name, false, true);
     if (!$group_profile || !$user_profile) {
         $this->redirect('');
     }
     if ($action == 'join') {
         $Connections->acceptGroupMembership($user_profile->id, $group_profile->id);
     } else {
         $Connections->rejectGroupMembership($user_profile->id, $group_profile->id);
     }
     // reload to group page
     $this->redirect($group_name);
 }
 /**
  * can post here?
  */
 public function canPostHere($user_id, $profile_type, $profile_id, $profile_owner)
 {
     $Connections = new Application_Model_Connections();
     // only account owner and friends can post to each other walls.
     if ($profile_type == 'user' && $user_id != $profile_id && !$Connections->areFriends($profile_id, $user_id)) {
         return false;
     }
     // only group members can post to a group
     if ($profile_type == 'group' && !$Connections->areFriends($profile_id, $user_id)) {
         return false;
     }
     // only page owner can write to a page
     if ($profile_type == 'page' && $user_id !== $profile_owner) {
         return false;
     }
     return true;
 }
示例#4
0
 /**
  * Permanently remove all profile's associated data
  */
 public function removeAllProfilesData($profile_id)
 {
     // check if exists
     $profile = $this->getProfileByField('id', $profile_id);
     if (!$profile) {
         return false;
     }
     $Images = new Application_Model_Images();
     $Images->removeUsersImages($profile_id);
     $Albums = new Application_Model_Albums();
     $Albums->deleteAlbums($profile_id);
     $Comments = new Application_Model_Comments();
     $Comments->deleteComments($profile_id);
     $Connections = new Application_Model_Connections();
     $Connections->removeUsersConnections($profile_id);
     $Likes = new Application_Model_Likes();
     $Likes->removeUsersLikes($profile_id);
     $Notifications = new Application_Model_Notifications();
     $Notifications->removeUsersNotifications($profile_id);
     $Reports = new Application_Model_Reports();
     $Reports->removeUsersReports($profile_id);
     $Posts = new Application_Model_Posts();
     $Posts->removeUsersPosts($profile_id);
     $Messages = new Application_Model_Messages();
     $Messages->removeUsersMessages($profile_id);
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $ProfilesMeta->removeMetaForProfile($profile_id);
     return true;
 }
 /**
  * Show group members
  */
 public function membersAction()
 {
     $Connections = new Application_Model_Connections();
     // flush if user not found
     if (!$this->profile || $this->profile->type !== 'group') {
         $this->redirect('');
     }
     $total_count = $Connections->getFriends($this->profile->id, false, true);
     $this->view->title = $this->view->translate('Members');
     $this->view->title_number = $total_count;
     $Connections->page_number = $this->preparePagination($total_count);
     $this->view->members = $Connections->getFriends($this->profile->id);
     $this->prepareProfile($this->profile);
     $this->render('memberslist');
 }