/**
  * Post comment (via ajax)
  */
 public function postcommentAction()
 {
     $add_comment_form = new Application_Form_AddComment();
     $json = array();
     $request = $this->getRequest();
     if ($request->isPost() && $add_comment_form->isValid($_POST)) {
         $comment_content = $add_comment_form->getValue('comment');
         $comment_content = Application_Plugin_Common::prepareComment($comment_content);
         // drop on false
         if ($comment_content === false) {
             $this->getHelper('json')->sendJson(false);
         }
         $resource_type = $add_comment_form->getValue('resource_type');
         $resource_id = (int) $add_comment_form->getValue('resource_id');
         $Comments = new Application_Model_Comments();
         $Comments->addComment($comment_content, $resource_id, $resource_type);
         $new_comments_data = $Comments->getCommentsForResources(array($resource_id), $resource_type);
         if (isset($new_comments_data[$resource_id])) {
             $add_comment_form->reset();
             $this->view->comments = $new_comments_data[$resource_id];
             $this->view->resource_type = $resource_type;
             $this->view->resource_id = $resource_id;
             $this->view->add_comment_form = $add_comment_form;
             $comments_html = $this->view->render('/partial/comments.phtml');
             $json['html'] = $comments_html;
         }
     }
     $json['errors'] = $add_comment_form->getMessages();
     $this->getHelper('json')->sendJson($json);
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }