Exemplo n.º 1
0
 /**
  * Method to publish, unpublish, approve or reject one or more comments
  *
  * @param   array   $cid      Array of comment IDs to perform the task on
  * @param   int     $publish  1 for publishing or approving, 0 for unpublishing or rejecting
  * @param   string  $task     The task to perform ('publish' or 'approve')
  * @return  int     The number of successfully processed comments, false otherwise
  * @since   1.5.5
  */
 public function publish($cid, $publish = 1, $task = 'publish')
 {
     JArrayHelper::toInteger($cid);
     $cids = implode(',', $cid);
     $column = 'approved';
     if ($task == 'publish') {
         $column = 'published';
     }
     $query = $this->_db->getQuery(true)->update(_JOOM_TABLE_COMMENTS)->set($column . ' = ' . (int) $publish)->where('cmtid IN (' . $cids . ' )');
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         return false;
     }
     // Message about new comment to image owner
     if ($column == 'approved' && $publish && $this->_config->get('jg_msg_comment_toowner')) {
         require_once JPATH_COMPONENT_SITE . '/helpers/messenger.php';
         $messenger = new JoomMessenger();
         foreach ($cid as $id) {
             // Load comment data
             $comment = $this->getTable('joomgallerycomments');
             $comment->load($id);
             if (!($name = $comment->cmtname)) {
                 $user = JFactory::getUser($comment->userid);
                 $name = $this->_config->get('jg_realname') ? $this->_user->get('name') : $this->_user->get('username');
             }
             // Load image data
             $image = $this->getTable('joomgalleryimages');
             $image->load($comment->cmtpic);
             if ($image->owner && $image->owner != $comment->userid) {
                 $mode = $messenger->getModeData('comment');
                 $message = array('from' => $this->_user->get('id'), 'subject' => JText::_('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_TO_OWNER_SUBJECT'), 'body' => JText::sprintf('COM_JOOMGALLERY_MESSAGE_NEW_COMMENT_TO_OWNER_BODY', $name, $image->imgtitle, $image->id), 'type' => $mode['type']);
                 $message['recipient'] = $image->owner;
                 $messenger->send($message);
             }
         }
     }
     return count($cid);
 }