/** * Add post submit */ public function submitAddPostForm($form) { $Profiles = new Application_Model_Profiles(); $current_user_id = Zend_Auth::getInstance()->getIdentity()->id; // default user wall $profile = Zend_Auth::getInstance()->getIdentity(); // writing on other user wall? if ($this->request->getParam('name')) { $profile = $Profiles->getProfile($this->request->getParam('name')); } if (!$this->canPostHere($current_user_id, $profile->type, $profile->id, $profile->owner)) { return false; } // submit? if (isset($_POST['identifier']) && $_POST['identifier'] == 'AddPost' && $form->isValid($_POST)) { $content = $form->getValue('content'); $content = Application_Plugin_Common::preparePost($content); $Posts = new Application_Model_Posts(); // save received filename to session form_unique_key $form_unique_key = (int) $_POST['form_unique_key']; $attached_files = @glob(TMP_PATH . '/post_' . Zend_Auth::getInstance()->getIdentity()->name . '_' . $form_unique_key . '*'); if ($this->show_privacy) { $Posts->addPost($content, $profile->id, Zend_Registry::get('default_privacy'), $attached_files); } else { // most restrictive, for groups and pages privacy is controlled when fetching posts $Posts->addPost($content, $profile->id, 'friends', $attached_files); } // flush content $form->getElement('content')->setValue(''); $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector'); $redirector->gotoUrl($this->callbackurl); } return $form; }
public function showAction() { $posts = new Application_Model_Posts(); //Pega todos os posts $listaPost = $posts->fetchAll(); //Pega o primeiro post $post = $listaPost->getRow(0); //busca todos os comentarios relacionados com o post $listaPostComments = $post->findDependentRowset('Application_Model_Comments'); //Coloca na variavel post $this->view->comments = $listaPostComments; }
/** * Main Feed / Login Page */ public function indexAction() { $request = $this->getRequest(); $Connections = new Application_Model_Connections(); $limit = Zend_Registry::get('config')->get('sidebar_max_users'); // put addPost form on the front page $this->_helper->addPostFormLoader(); if (Zend_Auth::getInstance()->hasIdentity()) { $this->view->sidebar_myprofile = true; } else { $this->view->sidebar_login = true; } // attach sidebar box Zend_Registry::get('hooks')->attach('hook_view_sidebar', 2, function () { echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/myprofile.phtml'); echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/loginregister.phtml'); }); // load initial posts $Posts = new Application_Model_Posts(); // Add coment form $add_comment_form = new Application_Form_AddComment(); $this->view->add_comment_form = $add_comment_form; // offset infinite scroll if ($this->view->post_page_number) { $Posts->page_number = $this->view->post_page_number; } $data = $Posts->getPosts(); $this->view->posts_data = $data; $this->view->profile_type = 'feed'; // continue to load posts with ajax if (count($data) >= Zend_Registry::get('config')->get('limit_posts')) { $this->view->php_loadPostURL = $this->_helper->url->url(array('controller' => 'posts', 'action' => 'load'), 'default', true); } // auto show image (shares) $image_uid = $request->getParam('showimage', 0); if ($image_uid) { if (!Zend_Auth::getInstance()->hasIdentity()) { $this->redirect(''); } $Images = new Application_Model_Images(); $image = $Images->getImageByUID($image_uid); if (isset($image)) { $this->view->auto_show_image = $image['id']; $this->view->auto_show_image_file_name = $image['file_name']; } else { Application_Plugin_Alerts::error($this->view->translate('Resource does not exists'), 'on'); $this->redirect(''); } } }
/** * 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; }
/** * 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); }
/** * Fetch and prepare posts for view */ public function preparePosts($search_context) { $Posts = new Application_Model_Posts(); // offset infinite scroll if ($this->view->post_page_number) { $Posts->page_number = $this->view->post_page_number; } // retrieve posts $this->view->posts_data = $Posts->getPosts(null, false, array('term' => $this->search_term, 'context' => $search_context)); if (count($this->view->posts_data) > 0) { // Add comment form $add_comment_form = new Application_Form_AddComment(); $this->view->add_comment_form = $add_comment_form; } else { Application_Plugin_Alerts::info($this->view->translate('Nothing found...'), 'off'); } // continue to load posts with ajax (v1.5+) if (count($this->view->posts_data) >= Zend_Registry::get('config')->get('limit_posts')) { $this->view->php_loadPostURL = $this->_helper->url->url(array('controller' => 'posts', 'action' => 'load', 'term' => $this->search_term, 'context' => $search_context), 'default', true); } $this->view->profile_type = 'feed'; // set single view script $this->render('posts'); }
/** * Método utilizado para excluir posts. Aguarda um parametro do tipo Int id. * @param int $id * @method deleteAction * @access public * @return void */ public function deleteAction() { $post = new Application_Model_Posts(); $id = $this->_getParam('id'); $post->delete('id =' . $id); $this->_redirect('/post/retrieve'); }
/** * Delete image */ public function deleteImage($image_id, $resource) { $image = $this->getImage($image_id); // check if owner or an admin if ($this->getImageOwnerId($image_id) != Zend_Auth::getInstance()->getIdentity()->id && Zend_Auth::getInstance()->getIdentity()->role !== 'admin') { return false; } // delete connected comments, likes and reports $Posts = new Application_Model_Posts(); $Posts->deleteConnectedResourcesData('image', $image_id); $Storage = new Application_Model_Storage(); $StorageAdapter = $Storage->getAdapter(); $StorageAdapter->deleteFileFromStorage($image['data']['file_name'], $resource); if ($image['data']['original']) { $StorageAdapter->deleteFileFromStorage($image['data']['original'], $resource); } $result = $this->delete(array('id = ?' => $image_id)); return $result; }
/** * 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; }
/** * Edit reported post */ public function editpostAction() { $Reports = new Application_Model_Reports(); $total_counts = $Reports->getTotalCount(); $this->buildMenu($total_counts); $request = $this->getRequest(); $page = (int) $request->getParam('page'); $post_id = (int) $request->getParam('post'); $Posts = new Application_Model_Posts(); $post = $Posts->getPost($post_id); // load and fill up form $edit_post_form = new Application_Form_EditPost(); $edit_post_form->getElement('content')->setValue($post['content']); $edit_post_form->getElement('privacy')->setValue($post['privacy']); $this->view->edit_post_form = $edit_post_form; if ($request->isPost() && $edit_post_form->isValid($_POST)) { $content = $edit_post_form->getElement('content')->getValue(); $privacy = $edit_post_form->getElement('privacy')->getValue(); $new_post_content = Application_Plugin_Common::preparePost($content); $Posts->updatePost($post_id, $new_post_content, $privacy); Application_Plugin_Alerts::success($this->view->translate('Post updated')); if ($page > 0) { $this->redirect('reports/reviewposts/page/' . $page); } } }
* @author Milos Stojanovic * @copyright 2014 interactive32.com */ $this->attach('hook_data_renderoutput', 10, function (&$data) { $content =& $data['content']; $base_url = Application_Plugin_Common::getFullBaseUrl(); $search_url = $base_url . '/search/posts/?term=%23'; // hashtags $content = preg_replace("/(^|[\t\r\n\\s])#([\\p{L}\\p{N}\\-_]+)/u", " <a href='{$search_url}\$2'>#\$2</a> ", $content); // usertags $content = preg_replace("/(^|[\t\r\n\\s])@(\\w+)/u", " <a href='{$base_url}/\$2'>@\$2</a>", $content); }); // push post mention notifications $this->attach('hook_data_aftersavepost', 10, function ($data) { $post_id = $data['post_id']; $Posts = new Application_Model_Posts(); $post = $Posts->getPost($post_id); $content = $data['content']['content']; $users = preg_replace_callback("/(^|[\t\r\n\\s])@(\\w+)/u", function ($match) use($post_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, '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();
/** * Show single post on profile's wall */ public function showpostAction() { $post_id = $this->getRequest()->getParam('post'); // important, flush if profile not found if (!$this->profile) { $this->redirect(''); } $this->prepareProfile($this->profile); // load addPost form if ($this->profile->type === 'user') { $show_privacy_btn = true; } else { $show_privacy_btn = false; } $this->_helper->addPostFormLoader($this->profile->name, $show_privacy_btn); // load single post $Posts = new Application_Model_Posts(); // Add coment form $add_comment_form = new Application_Form_AddComment(); $this->view->add_comment_form = $add_comment_form; $Posts->show_hidden_comments = true; $data = $Posts->getPosts(null, $post_id); if (!$data) { Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('This post is private or does not exists'), 'off'); } $this->view->posts_data = $data; $this->view->profile_type = $this->profile->type; // render classic profile view $this->render('show'); }
/** * get share modal content (via ajax) */ public function shareAction() { $request = $this->getRequest(); $resource_type = $request->getParam('resource_type', 0); $resource_id = $request->getParam('resource_id', 0); $base_link = Application_Plugin_Common::getFullBaseUrl(); $repost_link = false; switch ($resource_type) { case 'post': $Posts = new Application_Model_Posts(); $post = $Posts->getPost($resource_id); $profile = $Posts->getProfileDataByPostWall($resource_id); $profile_name = $profile['name']; $direct_link = $base_link . '/profiles/showpost/name/' . $profile_name . '/post/' . $resource_id; $repost_link = $base_link . '/posts/repost/post_id/' . $resource_id; break; case 'profile': $direct_link = $base_link . '/' . $resource_id; break; case 'image': $Images = new Application_Model_Images(); $image = $Images->getImage($resource_id); $direct_link = $base_link . '/index/index/showimage/' . $image['data']['uid']; break; default: $direct_link = $base_link; break; } // drop repost link if not logged in if (!Zend_Auth::getInstance()->hasIdentity()) { $repost_link = false; } $this->view->repost_link = $repost_link; $this->view->direct_link = $direct_link; // trigger hooks Zend_Registry::get('hooks')->trigger('hook_app_share', $this); $html = $this->view->render('/partial/share_modal_content.phtml'); $this->getHelper('json')->sendJson($html); }