/** * 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; }
/** * Edit post (ajax) */ public function editAction() { $request = $this->getRequest(); $post_id = (int) $request->getParam('post'); $Posts = new Application_Model_Posts(); $post = $Posts->getPost($post_id, true); $posts_wall_profile = $Posts->getPostsWallProfileData($post_id); if (!$post) { $this->getHelper('json')->sendJson($this->view->translate('Resource not available')); return; } // load and fill up form $edit_post_form = new Application_Form_EditPost(); $edit_post_form->getElement('content')->setValue(html_entity_decode($post['content'])); $edit_post_form->getElement('privacy')->setValue($post['privacy']); // no privacy edit for groups & pages if ($posts_wall_profile['type'] == 'group' || $posts_wall_profile['type'] == 'page') { $edit_post_form->removeElement('privacy'); } // get and render form only if ($request->isPost() && $request->getParam('form_render')) { $edit_post_form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/posts/edit/post/' . $post_id); $this->getHelper('json')->sendJson($edit_post_form->render()); return; } if ($request->isPost() && $edit_post_form->isValid($_POST)) { $content = $edit_post_form->getElement('content')->getValue(); if ($edit_post_form->getElement('privacy') && $edit_post_form->getElement('privacy')->getValue()) { $privacy = $edit_post_form->getElement('privacy')->getValue(); } else { $privacy = $post['privacy']; } $new_post_content = Application_Plugin_Common::preparePost($content); $Posts->updatePost($post_id, $new_post_content, $privacy); $this->getHelper('json')->sendJson($this->view->RenderOutput($new_post_content['content'], 'post')); return; } $this->getHelper('json')->sendJson($this->view->translate('Error - not permitted')); return; }