public function fetchAll() { $resultSet = $this->getDbTable()->fetchAll(); $entries = array(); foreach ($resultSet as $row) { $entries = new Application_Model_Comments(); $entries->setId($row->id)->setUsername($row->user_name)->setDescription($row->description)->setDateCreated($row->date_created)->setPrimId($row->prim_id); $entries[] = $entries; } return $entries; }
public function indexAction() { $comments = new Application_Model_Comments(); //Pega todos os comentarios $listaComments = $comments->fetchAll(); //Pega o primeiro comentario $comment = $listaComments->getRow(1); //Busca o post que tem o comentario $listaPost = $comment->findParentRow('Application_Model_Posts'); $this->view->post = $listaPost; }
/** * 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); }
/** * Edit comment (ajax) */ public function editAction() { $request = $this->getRequest(); $user_role = Zend_Auth::getInstance()->getIdentity()->role; $comment_id = (int) $request->getParam('id', false); $Comments = new Application_Model_Comments(); $comment = $Comments->getComment($comment_id); if (!$comment && !isset($comment['content'])) { $this->getHelper('json')->sendJson($this->view->translate('Resource not available')); return; } // check if my comment or an admin if ($Comments->getCommentAuthorId($comment_id) != Zend_Auth::getInstance()->getIdentity()->id && ($user_role != 'admin' && $user_role != 'reviewer')) { $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted')); return; } // load and fill up form $edit_comment_form = new Application_Form_EditComment(); $edit_comment_form->getElement('comment')->setValue($comment['content']); // get and render form only if ($request->isPost() && $request->getParam('form_render')) { $edit_comment_form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/comments/edit/id/' . $comment_id); $this->getHelper('json')->sendJson($edit_comment_form->render()); return; } if ($request->isPost() && $edit_comment_form->isValid($_POST)) { $comment_content = $edit_comment_form->getElement('comment')->getValue(); $comment_content = Application_Plugin_Common::prepareComment($comment_content); // drop on false if ($comment_content === false) { $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted')); return; } $ret = $Comments->updateComment($comment_id, $comment_content); $this->getHelper('json')->sendJson($this->view->RenderOutput($comment_content, 'comment')); return; } $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted')); return; }
public function retrieveAction() { $comments = new Application_Model_Comments(); $data = $comments->fetchAll(); $this->view->data = $data; }
/** * 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 comment */ public function editcommentAction() { $Reports = new Application_Model_Reports(); $total_counts = $Reports->getTotalCount(); $this->buildMenu($total_counts); $request = $this->getRequest(); $page = (int) $request->getParam('page'); $comment_id = (int) $request->getParam('comment'); $Comments = new Application_Model_Comments(); $comment = $Comments->getComment($comment_id); // load and fill up form $edit_comment_form = new Application_Form_EditComment(); $edit_comment_form->getElement('comment')->setValue($comment['content']); $this->view->edit_comment_form = $edit_comment_form; if ($request->isPost() && $edit_comment_form->isValid($_POST)) { $comment_content = $edit_comment_form->getElement('comment')->getValue(); $comment_content = Application_Plugin_Common::prepareComment($comment_content); // drop on false if ($comment_content === false) { return; } $Comments->updateComment($comment_id, $comment_content); Application_Plugin_Alerts::success($this->view->translate('Comment updated')); if ($page > 0) { $this->redirect('reports/reviewcomments/page/' . $page); } } }
$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(); $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');
/** * Fix posts data */ public function fixData($data) { if (!is_array($data) || empty($data)) { return; } $all_post_ids = $all_post_authors = array(); // find all post id's and authors foreach ($data as $tmp) { $all_post_ids[] = $tmp['post_id']; $all_post_authors[] = $tmp['author_id']; } // retrieve comments for these posts $Comments = new Application_Model_Comments(); $post_comments = $Comments->getCommentsForResources($all_post_ids, 'post', $this->show_hidden_comments); // retrieve attached images for these posts $Images = new Application_Model_Images(); $post_images = $Images->getPostsImages($all_post_ids); // retrieve likes for these posts $Likes = new Application_Model_Likes(); $post_likes = $Likes->getLikesForPosts($all_post_ids, 'post'); // retrieve authors meta data $ProfilesMeta = new Application_Model_ProfilesMeta(); $profiles_meta = $ProfilesMeta->getMetaForProfiles($all_post_authors); // fix posts foreach ($data as &$post) { // depreciated $post['is_reported'] = 0; // blend in comments if (!empty($post_comments[$post['post_id']])) { $comments = $post_comments[$post['post_id']]; // trigger comments hooks Zend_Registry::get('hooks')->trigger('hook_data_comments', $comments); $post['comments'] = $comments; } // blend in images if (!empty($post_images[$post['post_id']])) { $post['post_images'] = $post_images[$post['post_id']]; } // blend in likes if (!empty($post_likes[$post['post_id']])) { $post['likes_count'] = $post_likes[$post['post_id']]['likes_count']; $post['is_liked'] = $post_likes[$post['post_id']]['is_liked']; } else { $post['likes_count'] = 0; $post['is_liked'] = 0; } // blend in author meta_data if (!empty($profiles_meta[$post['author_id']])) { $post['author_meta'] = $profiles_meta[$post['author_id']]; } // shares if (isset($post['rich_content_json'])) { $rich_content = json_decode($post['rich_content_json']); if ($rich_content->type == 'share') { $original_post_id = (int) $rich_content->data->post; if ($original_post_id) { $original_post = $this->getPosts(null, $original_post_id, false, true); if ($original_post !== null) { // copy from original $copycat = $post; $post = $original_post[0]; $post['copycat'] = $copycat; } else { // original content was removed $translator = Zend_Registry::get('Zend_Translate'); $post['post_content'] = $translator->translate('Resource not available'); } } } } // trigger post hooks Zend_Registry::get('hooks')->trigger('hook_data_postcontent', $post); } return $data; }
public function deleteAction() { $cid = $this->getRequest()->getParam('cid'); if ($cid) { $model = new Application_Model_Comments(); $model->deleteComment($cid); } $this->redirect('comments/list'); }
/** * get lightbox data (via ajax) */ public function getlightboxdataAction() { $Comments = new Application_Model_Comments(); $Images = new Application_Model_Images(); $Likes = new Application_Model_Likes(); $Reports = new Application_Model_Reports(); $Albums = new Application_Model_Albums(); $add_comment_form = new Application_Form_AddComment(); $request = $this->getRequest(); $resource_id = $request->getParam('resource_id', 0); $context = $request->getParam('context'); $image = $Images->getImage($resource_id, $context); if (!$image) { $this->getHelper('json')->sendJson(false); return; } $resource_type = 'image'; $this->view->resource_type = $resource_type; $this->view->resource_id = $resource_id; $this->view->context = $context; $dropdown_options = array(); $this->view->can_rotate = false; if (Zend_Auth::getInstance()->hasIdentity()) { // if owner is viewing, add albums for moving if ($image['data']['owner_id'] == Zend_Auth::getInstance()->getIdentity()->id) { $albums = $Albums->getAlbums(Zend_Auth::getInstance()->getIdentity()->id, false); if (!empty($albums)) { foreach ($albums as $album) { $dropdown_options[] = array('id' => $album['id'], 'name' => Zend_Registry::get('Zend_Translate')->translate('Move to ') . $album['name']); } } } // add move to cover / profile options if (!empty($dropdown_options)) { $dropdown_options[] = array('id' => 'divider'); } $dropdown_options[] = array('id' => 'avatar', 'name' => Zend_Registry::get('Zend_Translate')->translate('Set as profile picture')); $dropdown_options[] = array('id' => 'cover', 'name' => Zend_Registry::get('Zend_Translate')->translate('Set as cover picture')); // if owner, admin or reviewer - add trash link if ($image['data']['uploaded_by'] == Zend_Auth::getInstance()->getIdentity()->id || Zend_Auth::getInstance()->getIdentity()->role == 'admin' || Zend_Auth::getInstance()->getIdentity()->role == 'reviewer') { // add trash $dropdown_options[] = array('id' => 'divider'); $dropdown_options[] = array('id' => 'trash', 'name' => Zend_Registry::get('Zend_Translate')->translate('Delete Image')); } // if owner - add rotate link if ($image['data']['uploaded_by'] == Zend_Auth::getInstance()->getIdentity()->id) { $this->view->can_rotate = true; } } $this->view->dropdown_options = $dropdown_options; // comments $show_hidden_comments = $context == 'single' ? true : false; $new_comments_data = $Comments->getCommentsForResources(array($resource_id), $resource_type, $show_hidden_comments); $add_comment_form->reset(); $this->view->comments = isset($new_comments_data[$resource_id]) ? $new_comments_data[$resource_id] : array(); $this->view->add_comment_form = $add_comment_form; // likes $this->view->is_liked = $Likes->isLiked($resource_id, $resource_type); $this->view->likes_count = $Likes->getLikesCount($resource_id, $resource_type); // reports $this->view->is_reported = $Reports->isReported($resource_id, $resource_type); $this->view->resource_owner_name = 'not-used'; $this->view->btn_title = Zend_Registry::get('Zend_Translate')->translate('Report'); $this->view->class = 'btn btn-default btn-xs'; $this->view->image = $image; $html = $this->view->render('/partial/lightbox.phtml'); $this->getHelper('json')->sendJson($html); }