/**
  * 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;
 }
 /**
  * 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);
         }
     }
 }
示例#3
0
    $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');
    foreach ($data as &$row) {