Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Send message
  */
 public function sendMessage($to_user_id, $content, $message_type = 'pm')
 {
     if (!Zend_Auth::getInstance()->hasIdentity() || strlen($content) < 1) {
         return false;
     }
     $from_user_id = Zend_Auth::getInstance()->getIdentity()->id;
     if (!$to_user_id || $from_user_id == $to_user_id) {
         return false;
     }
     $ret = $this->insert(array('type' => $message_type, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'content' => $content, 'is_new' => 1, 'is_hidden' => 0, 'sent_on' => Application_Plugin_Common::now()));
     $Notifications = new Application_Model_Notifications();
     $Notifications->pushNotification(array($to_user_id), 8, 'profile', $from_user_id, false);
     return $ret;
 }
Ejemplo n.º 3
0
 /**
  * Like toggle
  */
 public function toggleLike($resource_id, $resource_type)
 {
     if (!Zend_Auth::getInstance()->hasIdentity() || !$resource_id || !$resource_type) {
         return null;
     }
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     if ($this->isLiked($resource_id, $resource_type)) {
         $result = $this->delete(array('resource_id = ?' => (int) $resource_id, 'resource_type = ?' => $resource_type, 'user_id = ?' => (int) $user_id));
         $state = 0;
     } else {
         $data = array('user_id' => (int) $user_id, 'resource_type' => $resource_type, 'resource_id' => (int) $resource_id, 'created_on' => Application_Plugin_Common::now());
         $ret = $this->insert($data);
         $state = 1;
     }
     $likes_count = $this->getLikesCount($resource_id, $resource_type);
     // notify author
     $Notifications = new Application_Model_Notifications();
     if ($state == 1) {
         // find resource author
         switch ($resource_type) {
             case 'post':
                 $Posts = new Application_Model_Posts();
                 $resource_author = array($Posts->getPostAuthorId($resource_id));
                 break;
             case 'comment':
                 $Comments = new Application_Model_Comments();
                 $resource_author = array($Comments->getCommentAuthorId($resource_id));
                 break;
             case 'image':
                 $Images = new Application_Model_Images();
                 $resource_author = array($Images->getImageOwnerId($resource_id));
                 break;
             default:
                 $resource_author = false;
                 break;
         }
         if ($resource_author) {
             // notify resource owner
             $Notifications->pushNotification($resource_author, 2, 'like', $ret);
         }
     }
     return array('count' => $likes_count, 'state' => $state);
 }
 /**
  * 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);
 }
Ejemplo n.º 5
0
 /**
  * Add comment
  */
 public function addComment($content, $resource_id, $resource_type)
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return false;
     }
     if (!is_string($content) || !is_string($resource_type) || strlen($content) < 1) {
         return false;
     }
     $content = Application_Plugin_Common::limitInput($content);
     $author_id = Zend_Auth::getInstance()->getIdentity()->id;
     // find resource author
     switch ($resource_type) {
         case 'post':
             $Posts = new Application_Model_Posts();
             $resource_author = $Posts->getPostAuthorId($resource_id);
             $resource_wall = $Posts->getPostsWallProfileData($resource_id);
             // for page comments written by page admin switch owner to be a page itself
             if ($resource_wall['type'] == 'page' && $resource_wall['owner'] == $author_id) {
                 $author_id = $resource_wall['id'];
                 $resource_author = $author_id;
             }
             break;
         case 'image':
             $Images = new Application_Model_Images();
             $image = $Images->getImage($resource_id);
             $resource_author = $image['data']['uploaded_by'];
             break;
         default:
             $resource_author = 0;
             break;
     }
     $ret = $this->insert(array('author_id' => $author_id, 'resource_type' => $resource_type, 'resource_id' => $resource_id, 'created_on' => Application_Plugin_Common::now(), 'content' => $content, 'is_hidden' => 0));
     $this->markOldAsHidden($resource_type, $resource_id);
     $Notifications = new Application_Model_Notifications();
     // notify all users involved in comment discussion
     $notify_users = $this->getUsersCommented($resource_type, $resource_id, true);
     // notify resource author if not already on the list
     if (array_search($resource_author, $notify_users) === false) {
         $notify_users[] = $resource_author;
     }
     $Notifications->pushNotification($notify_users, 1, 'comment', $ret);
     // trigger hooks
     $data = array('comment_id' => $ret, 'content' => $content);
     Zend_Registry::get('hooks')->trigger('hook_data_aftersavecomment', $data);
     return $ret;
 }
Ejemplo n.º 6
0
 /**
  * Reject group membership request
  */
 public function rejectGroupMembership($user_id, $follow_id)
 {
     $ret = $this->removeConnections($user_id, $follow_id);
     // notify user who sent the request that his request is accepted
     $Notifications = new Application_Model_Notifications();
     $Notifications->pushNotification(array($user_id), 11, 'profile', $follow_id);
     return $ret;
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
            $Notifications = new Application_Model_Notifications();
            $Notifications->pushNotification(array($profile->id), 1001, 'post', $post_id);
        }
    }, $content);
});
// push comment mention notifications
$this->attach('hook_data_aftersavecomment', 10, function ($data) {
    $comment_id = $data['comment_id'];
    $Comments = new Application_Model_Comments();
    $comment = $Comments->getComment($comment_id);
    $content = $data['content'];
    $users = preg_replace_callback("/(^|[\t\r\n\\s])@(\\w+)/u", function ($match) use($comment_id) {
        $Profiles = new Application_Model_Profiles();
        $profile = $Profiles->getProfile($match[2]);
        if ($profile && $profile->type == 'user') {
            $Notifications = new Application_Model_Notifications();
            $Notifications->pushNotification(array($profile->id), 1001, 'comment', $comment_id);
        }
    }, $content);
});
// notifications
$this->attach('hook_data_notificationsfix', 10, function (&$data) {
    $baseURL = Application_Plugin_Common::getFullBaseUrl();
    $transl = Zend_Registry::get('Zend_Translate');
    foreach ($data as &$row) {
        // user mentioned inside post/comment
        if ($row['notification_type'] == 1001) {
            $row['do_send_email'] = false;
            if ($row['commented_post_id']) {
                $row['html_link'] = '<a href="' . $baseURL . '/profiles/showpost/name/' . $row['commented_post_on_wall'] . '/post/' . $row['commented_post_id'] . '">';
                $row['view_from_name'] = $row['comment_author_name'];
 /**
  * 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'));
         }
     }
 }
 /**
  * clear notifications (via ajax)
  */
 public function clearnotificationsAction()
 {
     $Notifications = new Application_Model_Notifications();
     $out = $Notifications->clearNotifications();
     $this->_helper->json($out);
 }
Ejemplo n.º 11
0
 /**
  * Add new post
  */
 public function addPost(array $content, $wall_id, $privacy, $attached_files)
 {
     if (!Zend_Auth::getInstance()->hasIdentity() || strlen($content['content']) < 1 && empty($attached_files)) {
         return false;
     }
     $content['content'] = Application_Plugin_Common::limitInput($content['content']);
     $Connections = new Application_Model_Connections();
     $Profiles = new Application_Model_Profiles();
     $Images = new Application_Model_Images();
     $PostsMeta = new Application_Model_PostsMeta();
     $wall_profile = $Profiles->getProfileByField('id', $wall_id);
     $author_id = Zend_Auth::getInstance()->getIdentity()->id;
     $insert_id = $this->insert(array('author_id' => $author_id, 'wall_id' => $wall_id, 'created_on' => Application_Plugin_Common::now(), 'content' => $content['content'], 'is_hidden' => 0, 'privacy' => $privacy));
     // write post's meta data
     if (isset($content['meta'])) {
         foreach ($content['meta'] as $metakey => $metavalue) {
             $ret = $PostsMeta->metaUpdate($insert_id, $metakey, $metavalue);
         }
     }
     // move tmp file to posts folder and add meta data to post
     if (!empty($attached_files)) {
         $i = 0;
         foreach ($attached_files as $file) {
             ++$i;
             $file_data = array('name' => basename($file), 'size' => filesize($file));
             // check max images per post
             if ($i > Zend_Registry::get('config')->get('max_images_per_post')) {
                 break;
             }
             $Storage = new Application_Model_Storage();
             $StorageAdapter = $Storage->getAdapter();
             $original_filename = '';
             if (Zend_Registry::get('config')->get('resample_images')) {
                 Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $file_data['name'], TMP_PATH . '/thumb_' . $file_data['name']);
                 $filename = $StorageAdapter->moveFileToStorage('thumb_' . $file_data['name'], 'posts');
                 if (Zend_Registry::get('config')->get('keep_original')) {
                     $original_filename = $StorageAdapter->moveFileToStorage($file_data['name'], 'posts');
                 } else {
                     $original_filename = '';
                     unlink(TMP_PATH . '/' . $file_data['name']);
                     // clean up
                 }
             } else {
                 $filename = $StorageAdapter->moveFileToStorage($file_data['name'], 'posts');
             }
             // in case this is not a user's wall - image owner will become the network
             // (image owner could become the wall owner but that's a bad idea)
             if ($wall_profile['id'] != $author_id) {
                 $owner = 0;
             } else {
                 $owner = $author_id;
             }
             $Images->addImage($filename, $file_data['size'], $owner, $author_id, $insert_id, 0, $original_filename);
         }
     }
     // post on someone else's wall, notify wall owner
     if ($wall_profile['type'] === 'user' && $wall_id != $author_id) {
         $Notifications = new Application_Model_Notifications();
         $Notifications->pushNotification(array($wall_id), 7, 'post', $insert_id);
     }
     // trigger hooks
     $data = array('post_id' => $insert_id, 'content' => $content);
     Zend_Registry::get('hooks')->trigger('hook_data_aftersavepost', $data);
     return true;
 }