示例#1
0
 protected function allowEdit($data = array(), $key = 'id')
 {
     $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     if ($recordId && $recordId == $rootComment->id) {
         return false;
     }
     if ($user->authorise('core.edit', 'com_judirectory')) {
         return true;
     }
     if ($user->authorise('core.edit.own', 'com_judirectory')) {
         $ownerId = (int) isset($data['user_id']) ? $data['user_id'] : 0;
         if (empty($ownerId) && $recordId) {
             $record = $this->getModel()->getItem($recordId);
             if (empty($record)) {
                 return false;
             }
             $ownerId = $record->user_id;
         }
         if ($ownerId == $userId) {
             return true;
         }
     }
     return parent::allowEdit($data, $key);
 }
 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;
 }
示例#3
0
 public function display($tpl = null)
 {
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     $this->state = $this->get('State');
     $this->canDo = JUDirectoryHelper::getActions('com_judirectory');
     $this->groupCanDoManage = JUDirectoryHelper::checkGroupPermission("comment.edit");
     $this->groupCanDoDelete = JUDirectoryHelper::checkGroupPermission("comments.delete");
     $this->rootComment = JUDirectoryFrontHelperComment::getRootComment();
     foreach ($this->items as &$item) {
         $this->ordering[$item->parent_id][] = $item->id;
     }
     $this->addToolBar();
     if (JUDirectoryHelper::isJoomla3x()) {
         $layout = JFactory::getApplication()->input->get('layout', '');
         if ($layout != 'modal') {
             $this->filterForm = $this->get('FilterForm');
             $this->activeFilters = $this->get('ActiveFilters');
         }
     }
     parent::display($tpl);
     $this->setDocument();
 }
示例#4
0
 public function display($tpl = null)
 {
     $this->items = $this->get('Items');
     $this->params = JUDirectoryHelper::getParams();
     $this->state = $this->get('State');
     $this->pagination = $this->get('Pagination');
     $this->root_comment = JUDirectoryFrontHelperComment::getRootComment();
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $this->order_name_array = array('cm.title' => JText::_('COM_JUDIRECTORY_FIELD_TITLE'), 'cm.created' => JText::_('COM_JUDIRECTORY_FIELD_CREATED'), 'r.score' => JText::_('COM_JUDIRECTORY_FIELD_RATING_SCORE'), 'cm.helpful_votes' => JText::_('COM_JUDIRECTORY_FIELD_HELPFUL_VOTES'), 'cm.total_votes' => JText::_('COM_JUDIRECTORY_FIELD_TOTAL_VOTES'));
     $this->order_dir_array = array('ASC' => JText::_('COM_JUDIRECTORY_ASC'), 'DESC' => JText::_('COM_JUDIRECTORY_DESC'));
     $this->listOrder = $this->escape($this->state->get('list.ordering'));
     $this->listDirn = $this->escape($this->state->get('list.direction'));
     $this->_prepareDocument();
     $this->_setBreadcrumb();
     parent::display($tpl);
 }
示例#5
0
 public function addComment()
 {
     JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
     $user = JFactory::getUser();
     $model = $this->getModel();
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     $data = $_POST;
     $listingId = $data['listing_id'];
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $parentId = $data['parent_id'];
     $model->setSessionCommentForm($listingId);
     if (strlen($data['title']) < 6) {
         $this->setError(JText::_('COM_JUDIRECTORY_COMMENT_INVALID_TITLE'));
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
         return false;
     }
     if (strlen($data['guest_name']) < 1) {
         $this->setError(JText::_('COM_JUDIRECTORY_COMMENT_INVALID_NAME'));
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
         return false;
     }
     if (isset($data['guest_email'])) {
         if (!preg_match('/^[\\w\\.-]+@[\\w\\.-]+\\.[\\w\\.-]{2,6}$/', $data['guest_email'])) {
             $this->setError(JText::_('COM_JUDIRECTORY_COMMENT_INVALID_EMAIL'));
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     }
     if (isset($data['website'])) {
         if (!preg_match('/^(https?:\\/\\/)?([\\w\\.-]+)\\.([\\w\\.-]{2,6})([\\/\\w \\.-]*)*\\/?$/i', $data['website'])) {
             $this->setError(JText::_('COM_JUDIRECTORY_COMMENT_INVALID_WEBSITE'));
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     }
     if (isset($data['comment_language'])) {
         $langArray = JHtml::_('contentlanguage.existing');
         $langKey = array_keys($langArray);
         array_unshift($langKey, '*');
         if (!in_array($data['comment_language'], $langKey)) {
             $this->setError(JText::_('COM_JUDIRECTORY_COMMENT_INVALID_LANGUAGE'));
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     }
     $minCharacter = $params->get('min_comment_characters', 20);
     $maxCharacter = $params->get('max_comment_characters', 1000);
     $comment = $data['comment'];
     $comment = JUDirectoryFrontHelperComment::parseCommentText($comment, $listingId);
     $comment = strip_tags($comment);
     $commentCharacter = strlen($comment);
     if ($commentCharacter < $minCharacter || $commentCharacter > $maxCharacter) {
         $this->setError(JText::_('COM_JUDIRECTORY_COMMENT_INVALID_COMMENT'));
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
         return false;
     }
     $showCaptcha = JUDirectoryFrontHelperPermission::showCaptchaWhenComment($listingId);
     if ($showCaptcha) {
         $validCaptcha = JUDirectoryFrontHelperCaptcha::checkCaptcha();
         if (!$validCaptcha) {
             if ($parentId == $rootComment->id) {
                 $form = '#judir-comment-form';
             } else {
                 $form = '#comment-reply-wrapper-' . $parentId;
             }
             $this->setError(JText::_('COM_JUDIRECTORY_INVALID_CAPTCHA'));
             $this->setMessage($this->getError(), 'error');
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId . $form, false));
             return false;
         }
     }
     if ($user->get('guest')) {
         if (!$model->checkNameOfGuest($listingId)) {
             $this->setError(JText::_('COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_COMMENT_ON_THIS_LISTING'));
             $this->setMessage($model->getError(), 'error');
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
         if (!$model->checkEmailOfGuest()) {
             $this->setMessage($model->getError(), 'error');
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     }
     if ($parentId == $rootComment->id) {
         $canComment = JUDirectoryFrontHelperPermission::canComment($listingId, $data['guest_email']);
         if (!$canComment) {
             $this->setError(JText::_('COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_COMMENT_ON_THIS_LISTING'));
             $this->setMessage($this->getError(), 'error');
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     } elseif ($parentId > 0 && $parentId != $rootComment->id) {
         $canReplyComment = JUDirectoryFrontHelperPermission::canReplyComment($listingId, $parentId);
         if (!$canReplyComment) {
             $this->setError(JText::_('COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_REPLY_THIS_COMMENT'));
             $this->setMessage($this->getError(), 'error');
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     } else {
         $this->setError(JText::_('COM_JUDIRECTORY_INVALID_DATA'));
         $this->setMessage($this->getError(), 'error');
         $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
         return false;
     }
     $dataValid = array();
     if ($parentId == $rootComment->id) {
         $canRateListing = JUDirectoryFrontHelperPermission::canRateListing($listingId);
         if ($canRateListing) {
             $dataValid = $this->validateCriteria($data, $parentId);
             if (!$dataValid) {
                 $this->setError(JText::_('COM_JUDIRECTORY_INVALID_RATING_VALUE'));
                 $this->setMessage($this->getError(), 'error');
                 $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
                 return false;
             }
         }
     }
     $requiredPostNames = array('title', 'guest_name', 'guest_email', 'comment', 'parent_id', 'listing_id');
     if ($params->get('website_field_in_comment_form', 0) == 2) {
         array_push($requiredPostNames, 'website');
     }
     if ($parentId == $rootComment->id && $params->get('filter_comment_language', 0)) {
         array_push($requiredPostNames, 'comment_language');
     }
     foreach ($requiredPostNames as $requiredPostName) {
         if (trim($data[$requiredPostName]) == '') {
             $this->setError(JText::_('COM_JUDIRECTORY_INVALID_INPUT_DATA'));
             $this->setMessage($this->getError(), 'error');
             $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_item . '&id=' . $listingId, false));
             return false;
         }
     }
     $acceptedPostNames = array('title', 'guest_name', 'guest_email', 'language', 'website', 'comment', 'parent_id', 'listing_id', 'subscribe');
     if ($params->get('website_field_in_comment_form', 0) == 2 || $params->get('website_field_in_comment_form', 0) == 1) {
         array_push($acceptedPostNames, 'website');
     }
     if ($params->get('filter_comment_language', 0)) {
         array_push($acceptedPostNames, 'comment_language');
     }
     foreach ($acceptedPostNames as $acceptedPostName) {
         if (isset($data[$acceptedPostName])) {
             $dataValid[$acceptedPostName] = $data[$acceptedPostName];
         }
     }
     $newCommentId = $model->saveComment($dataValid);
     if (!$newCommentId) {
         $this->setError($model->getError());
         $this->setMessage($this->getError(), 'error');
         $redirectUrl = JRoute::_(JUDirectoryHelperRoute::getListingRoute($listingId), false);
         $this->setRedirect($redirectUrl);
         return false;
     }
     $session = JFactory::getSession();
     $timeNow = JFactory::getDate()->toSql();
     $timeNowStamp = strtotime($timeNow);
     $sessionCommentOnListingTime = 'judir-commented-' . $listingId;
     $sessionCommentTime = 'judir-commented';
     $session->set($sessionCommentOnListingTime, $timeNowStamp);
     $session->set($sessionCommentTime, $timeNowStamp);
     $session->clear('judirectory_commentform_' . $listingId);
     $this->setMessage(JText::_('COM_JUDIRECTORY_ADD_COMMENT_SUCCESSFULLY'));
     $redirectUrl = JRoute::_(JUDirectoryHelperRoute::getListingRoute($listingId) . '#comment-item-' . $newCommentId, false);
     $this->setRedirect($redirectUrl);
     return true;
 }
示例#6
0
    protected function getInput()
    {
        $app = JFactory::getApplication();
        JHtml::_('behavior.modal', 'a.modal');
        $id = $this->form->getValue('id', null, 0);
        $script = array();
        $script[] = 'function commentURL() {
				     	var commenturl = document.id("commenturl").getAttribute("href");
						commenturl = commenturl + "&listing_id="+document.id(jform_listing_id).value;
						document.id("commenturl").setAttribute("href", commenturl);
						return true;
			  		}';
        $script[] = 'function jSelectComment_' . $this->id . '(id, title, level) {
			        	if(id != document.id("' . $this->id . '").value){
							document.id("' . $this->id . '").value = id;
		        			document.id("' . $this->id . '_name").value = title;
		        			level = parseInt(level) + 1
		        			document.id("jform_level").value = level;
				        	
		        		}
				        SqueezeBox.close();
					}';
        JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
        $html = array();
        $link = 'index.php?option=com_judirectory&amp;view=comments&amp;layout=modal&amp;tmpl=component&amp;id=' . $id . '&amp;function=jSelectComment_' . $this->id;
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('title');
        $query->from('#__judirectory_comments');
        $query->where('id = ' . (int) $this->value);
        $db->setQuery($query);
        $title = $db->loadResult();
        if (empty($title)) {
            $rootComment = JUDirectoryFrontHelperComment::getRootComment();
            $title = $rootComment->title;
            $value = $rootComment->id;
        } else {
            $value = $this->value;
        }
        $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
        $joomla_version_arr = explode(".", JVERSION);
        $priVersion = $joomla_version_arr[0];
        if ($priVersion == 3) {
            $html[] = '<span class="' . ($app->isAdmin() ? 'input-append' : '') . '">';
            $html[] = '<input type="text" id="' . $this->id . '_name" value="' . $title . '" disabled="disabled" size="' . $this->element['size'] . '" />';
            if ($app->isAdmin()) {
                $html[] = '<a class="modal btn hasTooltip" title="' . JHtml::tooltipText('COM_JUDIRECTORY_SELECT_COMMENT') . '"  href="' . $link . '&amp;' . JSession::getFormToken() . '=1" rel="{handler: \'iframe\', size: {x: 800, y: 450}}"><i class="icon-list"></i> ' . JText::_('COM_JUDIRECTORY_SELECT') . '</a>';
            }
            $html[] = '</span>';
        } else {
            $html[] = '<div class="fltlft">';
            $html[] = '<input type="text" id="' . $this->id . '_name" value="' . $title . '" disabled="disabled" size="' . $this->element['size'] . '" />';
            $html[] = '</div>';
            if ($app->isAdmin()) {
                $html[] = '<div class="button2-left">';
                $html[] = '<div class="blank">';
                $html[] = '<a onclick="commentURL();" id="commenturl" class="modal" title="' . JText::_('COM_JUDIRECTORY_SELECT_COMMENT') . '"  href="' . $link . '&amp;' . JSession::getFormToken() . '=1" rel="{handler: \'iframe\', size: {x: 800, y: 450}}">' . JText::_('COM_JUDIRECTORY_SELECT_COMMENT') . '</a>';
                $html[] = '</div>';
                $html[] = '</div>';
            }
        }
        $class = '';
        if ($this->required) {
            $class = ' class="required modal-value"';
        }
        $html[] = '<input type="hidden" id="' . $this->id . '"' . $class . ' name="' . $this->name . '" value="' . $value . '" />';
        return implode("\n", $html);
    }
示例#7
0
 protected function _prepareData()
 {
     $this->token = JSession::getFormToken();
     $this->session = JFactory::getSession();
     $this->item->related_listings = $this->model->getRelatedListings($this->item->id);
     if (count($this->item->related_listings)) {
         foreach ($this->item->related_listings as $listingRelated) {
             $listingRelated->link = JRoute::_(JUDirectoryHelperRoute::getListingRoute($listingRelated->id));
             $listingRelated->image = JUDirectoryHelper::getListingImage($listingRelated->image);
         }
     }
     $additionFields = $ignoredFields = array();
     $this->item->fieldLocations = JUDirectoryFrontHelperField::getField('locations', $this->item);
     $this->item->fieldGallery = JUDirectoryFrontHelperField::getField('gallery', $this->item);
     $this->item->fields = JUDirectoryFrontHelperField::getFields($this->item, 2, array(), array('gallery', 'locations'), $additionFields);
     $user = JFactory::getUser();
     $uri = JUri::getInstance();
     if ($this->item->checked_out > 0 && $this->item->checked_out != $user->get('id')) {
         if (JUDirectoryFrontHelperPermission::canCheckInListing($this->item->id)) {
             $this->item->checkin_link = JRoute::_('index.php?option=com_judirectory&task=forms.checkin&id=' . $this->item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri)));
         }
     } else {
         $this->item->edit_link = JRoute::_('index.php?option=com_judirectory&task=form.edit&id=' . $this->item->id . '&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($this->item->id));
         if ($this->item->published == 1) {
             $this->item->editstate_link = JRoute::_('index.php?option=com_judirectory&task=forms.unpublish&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($this->item->id));
         } else {
             $this->item->editstate_link = JRoute::_('index.php?option=com_judirectory&task=forms.publish&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($this->item->id));
         }
     }
     $this->item->delete_link = JRoute::_('index.php?option=com_judirectory&task=forms.delete&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($this->item->id));
     $this->item->contact_link = JRoute::_(JUDirectoryHelperRoute::getContactRoute($this->item->id));
     $this->item->report_link = JRoute::_(JUDirectoryHelperRoute::getReportListingRoute($this->item->id));
     $this->item->claim_link = JRoute::_(JUDirectoryHelperRoute::getClaimListingRoute($this->item->id));
     $this->item->print_link = JRoute::_(JUDirectoryHelperRoute::getListingRoute($this->item->id) . '&layout=print&tmpl=component&print=1');
     $this->item->comment = new stdClass();
     $this->item->comment->total_comments_no_filter = $this->model->getTotalCommentsOfListing($this->item->id);
     $this->root_comment = JUDirectoryFrontHelperComment::getRootComment();
     $langArray = JHtml::_('contentlanguage.existing');
     $JAll = new JObject();
     $JAll->text = JText::_('JALL');
     $JAll->value = '*';
     array_unshift($langArray, $JAll);
     $this->langArray = $langArray;
     $this->item->comment->items = $this->get('Items');
     foreach ($this->item->comment->items as $comment) {
         if (JUDirectoryFrontHelperPermission::canCheckInComment($comment->id)) {
             $uri = JUri::getInstance();
             $comment->checkout_link = 'index.php?option=com_judirectory&task=modcomments.checkin&cid=' . $comment->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri));
         } else {
             $comment->checkout_link = '';
         }
     }
     $this->item->comment->pagination = $this->get('Pagination');
     $this->item->comment->total_comments = $this->get('Total');
     $this->item->comment->parent_id = $this->root_comment->id;
     $this->website_field_in_comment_form = $this->params->get('website_field_in_comment_form', 0);
     $this->min_comment_characters = $this->params->get('min_comment_characters', 20);
     $this->max_comment_characters = $this->params->get('max_comment_characters', 1000);
     $this->allow_vote_comment = $this->params->get('allow_vote_comment', 1);
     $this->allow_vote_down_comment = $this->params->get('allow_vote_down_comment', 1);
     $this->order_comment_name_array = $this->model->getCommentOrderingOptions();
     $this->order_comment_dir_array = array('ASC' => JText::_('COM_JUDIRECTORY_ASC'), 'DESC' => JText::_('COM_JUDIRECTORY_DESC'));
     $this->total_stars = $this->params->get('number_rating_stars', 5);
     $this->filter_comment_stars = array('' => JText::_('COM_JUDIRECTORY_ANY_STAR'));
     for ($i = 0; $i <= $this->total_stars; $i++) {
         $score = $i == 0 ? 0 : round(($i - 1) * 10 / $this->total_stars, 5) . ',' . round($i * 10 / $this->total_stars, 5);
         $this->filter_comment_stars[$score] = JText::plural('COM_JUDIRECTORY_N_STAR', $i);
     }
     if ($this->params->get('filter_comment_language', 0)) {
         $this->list_lang_comment = $this->escape($this->state->get('list.lang'));
     }
     $this->list_order_comment = $this->escape($this->state->get('list.ordering'));
     $this->list_dir_comment = $this->escape($this->state->get('list.direction'));
     $this->filter_comment_star = $this->state->get('list.star_filter', '');
     $this->website = $this->title = $this->email = $this->comment = $this->name = '';
     $this->language = '*';
     $form = $this->session->get('judirectory_commentform_' . $this->item->id, null);
     $this->form = $form;
     if (!empty($form) && $form['parent_id'] == $this->root_comment->id) {
         $this->title = $form['title'];
         $this->name = $form['guest_name'];
         $this->email = $form['guest_email'];
         $this->comment = $form['comment'];
         $this->website = isset($form['website']) ? $form['website'] : '';
         $this->language = $form['comment_language'];
     }
 }
示例#8
0
 protected function canEditState($record)
 {
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     if (isset($record->id) && $record->id == $rootComment->id) {
         return false;
     }
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         $modCanEditState = JUDirectoryFrontHelperModerator::checkModeratorCanDoWithComment($record->id, 'comment_edit_state');
         if ($modCanEditState) {
             return true;
         }
         return false;
     }
     return parent::canEditState($record);
 }
示例#9
0
 protected function getListQuery()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('cm.*, r.score');
     $query->from('#__judirectory_comments AS cm');
     $query->join('LEFT', '#__judirectory_rating AS r ON cm.rating_id = r.id');
     $query->where('cm.published  = 1');
     $query->where('cm.approved  = 1');
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     $query->where('cm.id != ' . $rootComment->id);
     $params = $this->getState('params');
     if ($params->get('top_comment_level', 'toplevel') == 'toplevel') {
         $query->where('cm.level = 1');
     }
     $ordering = $this->getState('list.ordering', 'cm.created');
     $direction = $this->getState('list.direction', 'desc');
     $query->order($ordering . ' ' . $direction);
     return $query;
 }
示例#10
0
 public function saveComment($postData = array())
 {
     $user = JFactory::getUser();
     $nowDate = JFactory::getDate()->toSql();
     $title = htmlspecialchars($postData['title']);
     $comment = htmlspecialchars($postData['comment'], ENT_NOQUOTES);
     if ($user->get('guest')) {
         $guestName = strip_tags($postData['guest_name']);
         $guestEmail = strip_tags($postData['guest_email']);
     } else {
         $guestName = '';
         $guestEmail = '';
     }
     $website = isset($postData['website']) ? strip_tags($postData['website']) : '';
     $listingId = (int) $postData['listing_id'];
     $params = JUDirectoryHelper::getParams(null, $listingId);
     $totalVotes = 0;
     $helpfulVotes = 0;
     $ipAddress = JUDirectoryFrontHelper::getIpAddress();
     $parentId = (int) $postData['parent_id'];
     $rootComment = JUDirectoryFrontHelperComment::getRootComment();
     if ($parentId == $rootComment->id) {
         $approved = JUDirectoryFrontHelperPermission::canAutoApprovalComment($listingId);
         $level = 1;
         if ($params->get('filter_comment_language', 0)) {
             $language = $postData['comment_language'];
         } else {
             $language = '*';
         }
     } else {
         $approved = JUDirectoryFrontHelperPermission::canAutoApprovalReplyComment($listingId);
         $parentComment = $this->getCommentObject($parentId);
         $level = $parentComment->level + 1;
         $language = '*';
     }
     if ($approved) {
         $approved = 1;
         $published = 1;
     } else {
         $approved = 0;
         $published = 0;
     }
     $dataComment = array('title' => $title, 'comment' => $comment, 'user_id' => $user->id, 'guest_name' => $guestName, 'guest_email' => $guestEmail, 'website' => $website, 'listing_id' => $listingId, 'created' => $nowDate, 'total_votes' => $totalVotes, 'helpful_votes' => $helpfulVotes, 'ip_address' => $ipAddress, 'approved' => $approved, 'published' => $published, 'parent_id' => $parentId, 'level' => $level, 'language' => $language);
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables');
     $commentTable = JTable::getInstance('Comment', 'JUDirectoryTable');
     $commentTable->setLocation($postData['parent_id'], 'last-child');
     $commentTable->bind($dataComment);
     if (!$commentTable->check() || !$commentTable->store()) {
         $this->setError($commentTable->getError());
         return false;
     }
     $canRateListing = JUDirectoryFrontHelperPermission::canRateListing($listingId);
     if ($canRateListing && $params->get('enable_listing_rate_in_comment_form', 1) && $commentTable->parent_id == $rootComment->id) {
         $postData['approved'] = $approved;
         $criteriaArray = array();
         if (isset($postData['criteria_array'])) {
             if (JUDirectoryHelper::hasMultiRating()) {
                 $criteriaArray = $postData['criteria_array'];
                 $saveRating = $this->saveRating($postData, $listingId, $criteriaArray, $commentTable->id);
             }
         } else {
             if (isset($postData['ratingValue'])) {
                 $saveRating = $this->saveRating($postData, $listingId, $criteriaArray, $commentTable->id);
             }
         }
         if (!$saveRating) {
             $this->setError(JText::_('COM_JUDIRECTORY_SAVE_RATING_FAILED'));
             return false;
         }
     }
     if (JUDIRPROVERSION && isset($postData['subscribe']) && $postData['subscribe']) {
         $subscriptionData = array();
         $subscriptionData['user_id'] = $user->id;
         $subscriptionData['type'] = 'comment';
         $subscriptionData['comment_id'] = $commentTable->id;
         $subscriptionData['name'] = $user->id == 0 ? $guestName : $user->username;
         $subscriptionData['email'] = $user->id == 0 ? $guestEmail : $user->email;
         $subscriptionData['item_id'] = $commentTable->id;
         $subscriptionData['ip_address'] = $ipAddress;
         $subscriptionData['created'] = $nowDate;
         $subscriptionData['published'] = $user->id == 0 && $params->get('activate_subscription_by_email', 1) ? 0 : 1;
         require_once JPATH_SITE . '/components/com_judirectory/models/subscribe.php';
         JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_judirectory/models');
         $subscribeModel = JModelLegacy::getInstance('Subscribe', 'JUDirectoryModel');
         if (!$subscribeModel->add($subscriptionData)) {
             $this->setError(JText::_('COM_JUDIRECTORY_SUBSCRIBE_FAILED'));
             return false;
         }
     }
     if ($commentTable->parent_id == $rootComment->id) {
         JUDirectoryFrontHelperMail::sendEmailByEvent('comment.create', $commentTable->id);
         $logData = array('item_id' => $commentTable->id, 'listing_id' => $listingId, 'user_id' => $user->id, 'event' => 'comment.create');
         $commentSubmitType = 'create';
     } else {
         JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reply', $commentTable->id);
         $logData = array('user_id' => $user->id, 'event' => 'comment.reply', 'item_id' => $commentTable->id, 'listing_id' => $listingId, 'value' => 0, 'reference' => $commentTable->parent_id);
         $commentSubmitType = 'reply';
     }
     JUDirectoryFrontHelperLog::addLog($logData);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('judirectory');
     $dispatcher->trigger('onCommentSubmit', array($commentTable, $commentSubmitType));
     return $commentTable->id;
 }