/** * loading posts after initial load (via ajax) * * pages 2, 3... */ public function loadAction() { $wall_id = (int) $this->getRequest()->getParam('wall_id'); $search_term = $this->getRequest()->getParam('term'); $search_context = $this->getRequest()->getParam('context'); $Posts = new Application_Model_Posts(); $Profiles = new Application_Model_Profiles(); $profile_type = 'feed'; if ($wall_id > 0) { $wall_profile = $Profiles->getProfileByField('id', $wall_id); $profile_type = $wall_profile->type; } if ($this->getRequest()->getParam('post_page_number')) { $Posts->page_number = (int) $this->getRequest()->getParam('post_page_number'); } else { $Posts->page_number = 2; } if ($search_context) { // retrieve posts on search context $data = $Posts->getPosts(null, false, array('term' => $search_term, 'context' => $search_context)); } else { // plain posts on wall $data = $Posts->getPosts($wall_id); } $this->view->posts_data = $data; $this->view->profile_type = $profile_type; // stop load if there are no more posts if (count($data) >= Zend_Registry::get('config')->get('limit_posts')) { $stop_loading = false; } else { $stop_loading = true; } // Add coment form $add_comment_form = new Application_Form_AddComment(); $this->view->add_comment_form = $add_comment_form; $page_number = $Posts->page_number + 1; $posts = $this->view->render('/partial/posts.phtml'); $out = array('posts' => $posts, 'post_page_number' => $page_number, 'stop' => $stop_loading); $this->_helper->json($out); }
/** * 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(''); } } }
/** * 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'); }
/** * 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'); }