function approve($comment_ids)
 {
     if (!is_array($comment_ids) || empty($comment_ids)) {
         $this->setError('COM_JUDIRECTORY_NO_ITEM_SELECTED');
         return false;
     }
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables');
     $comment_table = JTable::getInstance("Comment", "JUDirectoryTable");
     $count = 0;
     $comment_ids = (array) $comment_ids;
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     $listingIds = array();
     foreach ($comment_ids as $comment_id) {
         $comment_table->reset();
         if ($comment_table->load($comment_id) && $comment_table->parent_id == $rootComment->id && $comment_table->approved == 0) {
             $listingIds[$comment_table->listing_id] = $comment_table->listing_id;
         }
         $user = JFactory::getUser();
         $date = JFactory::getDate();
         $comment_table->approved = 1;
         $comment_table->published = 1;
         $comment_table->approved_by = $user->id;
         $comment_table->approved_time = $date->toSql();
         $comment_table->store();
         $count++;
         JUDirectoryFrontHelperMail::sendEmailByEvent('comment.approve', $comment_id);
         $logData = array('user_id' => $comment_table->user_id, 'event' => 'comment.approve', 'item_id' => $comment_id, 'listing_id' => $comment_table->listing_id, 'value' => 0, 'reference' => '');
         JUDirectoryFrontHelperLog::addLog($logData);
     }
     foreach ($listingIds as $listingId) {
         JUDirectoryHelper::rebuildRating($listingId);
     }
     return $count;
 }
Example #2
0
 public function publish()
 {
     JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));
     $cid = JFactory::getApplication()->input->get('id', array(), 'array');
     $data = array('publish' => 1, 'unpublish' => 0);
     $task = $this->getTask();
     $value = JArrayHelper::getValue($data, $task, 0, 'int');
     if (empty($cid)) {
         JError::raiseWarning(500, JText::_('COM_JUDIRECTORY_NO_ITEM_SELECTED'));
     } else {
         $model = $this->getModel();
         JArrayHelper::toInteger($cid);
         if (!$model->publish($cid, $value)) {
             JError::raiseWarning(500, $model->getError());
         } else {
             if ($value == 1) {
                 $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
             } elseif ($value == 0) {
                 $ntext = $this->text_prefix . '_N_ITEMS_UNPUBLISHED';
             }
             foreach ($cid as $id) {
                 JUDirectoryFrontHelperMail::sendEmailByEvent('listing.editstate', $id);
             }
             $this->setMessage(JText::plural($ntext, count($cid)));
             $user = JFactory::getUser();
             foreach ($cid as $id) {
                 $logData = array('user_id' => $user->id, 'event' => 'listing.editstate', 'item_id' => $id, 'listing_id' => $id, 'value' => $value, 'reference' => '');
                 JUDirectoryFrontHelperLog::addLog($logData);
             }
         }
     }
     $this->setRedirect(JRoute::_($this->getReturnPage()));
 }
Example #3
0
 public function updateComment()
 {
     JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
     $user = JFactory::getUser();
     $model = $this->getModel();
     $app = JFactory::getApplication();
     $data = $app->input->getArray($_POST);
     $listingId = $data['listing_id'];
     $commentId = $data['comment_id'];
     $canEditComment = JUDirectoryFrontHelperPermission::canEditComment($commentId);
     $redirectUrl = JRoute::_(JUDirectoryHelperRoute::getListingRoute($listingId) . '#comment-item-' . $commentId);
     if (!$canEditComment) {
         $this->setMessage(JText::_('COM_JUDIRECTORY_UPDATE_COMMENT_ERROR'));
         $this->setRedirect($redirectUrl);
         return false;
     }
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $ratingValue = $this->validateCriteria($data);
     if ($ratingValue) {
         $data = array_merge($data, $ratingValue);
     } else {
         $this->setMessage(JText::_('COM_JUDIRECTORY_UPDATE_COMMENT_ERROR'));
         $this->setRedirect($redirectUrl);
         return false;
     }
     JUDirectoryHelper::obCleanData();
     if ($model->updateComment($data, $params)) {
         $logData = array('user_id' => $user->id, 'event' => 'comment.edit', 'item_id' => $commentId, 'listing_id' => $listingId, 'value' => 0, 'reference' => '');
         JUDirectoryFrontHelperLog::addLog($logData);
         $this->setMessage(JText::_('COM_JUDIRECTORY_UPDATE_COMMENT_SUCCESSFULLY'));
         $this->setRedirect($redirectUrl);
         return true;
     } else {
         $this->setMessage(JText::_('COM_JUDIRECTORY_UPDATE_COMMENT_ERROR'));
         $this->setRedirect($redirectUrl);
         return false;
     }
 }
Example #4
0
 public function save($data)
 {
     $dispatcher = JDispatcher::getInstance();
     $table = $this->getTable();
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     $app = JFactory::getApplication();
     JPluginHelper::importPlugin('content');
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) {
         $table->setLocation($data['parent_id'], 'last-child');
     }
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     if (isset($data['rules'])) {
         $rules = new JAccessRules($data['rules']);
         $table->setRules($rules);
     }
     $this->prepareTable($table);
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
     $this->setState($this->getName() . '.id', $table->id);
     $this->cleanCache();
     if (!$isNew && $app->isSite()) {
         $user = JFactory::getUser();
         $logData = array('user_id' => $user->id, 'event' => 'comment.edit', 'item_id' => $table->id, 'listing_id' => $table->listing_id, 'value' => 0, 'reference' => '');
         JUDirectoryFrontHelperLog::addLog($logData);
     }
     return $table->id;
 }
Example #5
0
 public function saveListingAddLog($table, $isNew)
 {
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         $user = JFactory::getUser();
         if ($isNew) {
             $logData = array('user_id' => $user->id, 'event' => 'listing.create', 'item_id' => $table->id, 'listing_id' => $table->id, 'value' => 0, 'reference' => '');
         } else {
             $logData = array('user_id' => $user->id, 'event' => 'listing.edit', 'item_id' => $table->id, 'listing_id' => $table->id, 'value' => 0, 'reference' => '');
         }
         JUDirectoryFrontHelperLog::addLog($logData);
     }
 }
Example #6
0
 public function voteComment($commentId)
 {
     $commentObj = JUDirectoryFrontHelperComment::getCommentObject($commentId);
     if (!$commentObj) {
         return;
     }
     $vote_up = JFactory::getApplication()->input->getInt('vote_up', 0);
     $helpful_votes = intval($commentObj->helpful_votes);
     $total_votes = intval($commentObj->total_votes);
     $params = JUDirectoryHelper::getParams(null, $commentObj->listing_id);
     $allow_vote_down_comment = $params->get('allow_vote_down_comment', 1);
     if (!$allow_vote_down_comment) {
         $like_system = true;
         if ($vote_up != 1) {
             $voteType = 0;
             $reference = 'unlike';
             $total_votes--;
             $helpful_votes--;
         } else {
             $voteType = 1;
             $reference = 'like';
             $total_votes++;
             $helpful_votes++;
         }
     } else {
         $like_system = false;
         if ($vote_up != 1) {
             $voteType = -1;
             $reference = 'vote_down';
             $total_votes++;
         } else {
             $voteType = 1;
             $reference = 'vote_up';
             $total_votes++;
             $helpful_votes++;
         }
     }
     $votedValue = $this->getCommentVotedValue($commentObj->id);
     if ($allow_vote_down_comment && $votedValue || $votedValue == $voteType) {
         $return = array();
         $return['message'] = JText::_('COM_JUDIRECTORY_VOTING_ERROR');
         $return['like_system'] = $like_system;
         $return['vote_type'] = null;
         JUDirectoryHelper::obCleanData();
         echo json_encode($return);
         exit;
     }
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->update('#__judirectory_comments')->set('helpful_votes = ' . $helpful_votes)->set('total_votes = ' . $total_votes)->where('id = ' . $commentObj->id);
     $db->setQuery($query);
     if ($db->execute()) {
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('judirectory');
         $dispatcher->trigger('onVoteComment', $commentObj, $like_system, $voteType);
         $user = JFactory::getUser();
         $userId = $user->id;
         $logData = array('user_id' => $user->id, 'event' => 'comment.vote', 'item_id' => $commentObj->id, 'listing_id' => $commentObj->listing_id, 'value' => $voteType, 'reference' => $reference);
         JUDirectoryFrontHelperLog::addLog($logData);
         if ($userId > 0) {
             $cookieName = 'judir-comment-vote-' . $commentObj->id . '_' . $userId;
         } else {
             $ipAddress = JUDirectoryFrontHelper::getIpAddress();
             $ipAddress = str_replace('.', '_', $ipAddress);
             $cookieName = 'judir-comment-vote-' . $commentObj->id . '_' . $ipAddress;
         }
         $config = JFactory::getConfig();
         $cookie_domain = $config->get('cookie_domain', '');
         $cookie_path = $config->get('cookie_path', '/');
         setcookie($cookieName, $voteType, time() + 60 * 60 * 24 * 30, $cookie_path, $cookie_domain);
         $return = array();
         $return['message'] = JText::sprintf('COM_JUDIRECTORY_N_HELPFUL_VOTES_N_TOTAL_VOTES', $helpful_votes, $total_votes);
         $return['like_system'] = $like_system;
         $return['vote_type'] = $voteType;
     } else {
         $return = array();
         $return['message'] = JText::_('COM_JUDIRECTORY_VOTING_ERROR');
         $return['like_system'] = $like_system;
         $return['vote_type'] = null;
     }
     JUDirectoryHelper::obCleanData();
     echo json_encode($return);
     exit;
 }