Exemplo n.º 1
0
 protected function getValue()
 {
     $app = JFactory::getApplication();
     if ($app->isSite() && isset($this->listing->total_comments) && !is_null($this->listing->total_comments)) {
         return $this->listing->total_comments;
     }
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     if ($app->isSite()) {
         $query = $db->getQuery(true);
         $query->select('COUNT(*)');
         $query->from('#__judirectory_comments AS cm');
         $query->where('listing_id =' . $this->listing_id);
         $query->where('level = 1');
         $query->where('approved = 1');
         $moderator = JUDirectoryFrontHelperModerator::getModerator($this->listing->cat_id);
         $getAll = false;
         if ($user->authorise('core.admin', 'com_judirectory')) {
             $getAll = true;
         }
         if (is_object($moderator)) {
             if ($moderator->comment_edit || $moderator->comment_edit_state || $moderator->comment_delete) {
                 $getAll = true;
             }
         }
         if (!$getAll) {
             $query->where('published = 1');
             $params = JUDirectoryHelper::getParams(null, $this->listing_id);
             $negative_vote_comment = $params->get('negative_vote_comment');
             if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) {
                 $query->where('(total_votes - helpful_votes) <' . $negative_vote_comment);
             }
         }
     } else {
         $query = $db->getQuery(true);
         $query->select('COUNT(*)');
         $query->from('#__judirectory_comments AS cm');
         $query->where('listing_id =' . $this->listing_id);
         $query->where('level = 1');
         $query->where('approved = 1');
     }
     $db->setQuery($query);
     $totalComments = $db->loadResult();
     return $totalComments;
 }
Exemplo n.º 2
0
 public function delete($pk = null, $children = true)
 {
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     if ($this->_trackAssets) {
         $name = $this->_getAssetName();
         $asset = JTable::getInstance('Asset');
         if (!$asset->_lock()) {
             return false;
         }
         if ($asset->loadByName($name)) {
             if (!$asset->delete(null, $children)) {
                 $this->setError($asset->getError());
                 $asset->_unlock();
                 return false;
             }
             $asset->_unlock();
         } else {
             $this->setError($asset->getError());
             $asset->_unlock();
             return false;
         }
     }
     if (!($node = $this->_getNode($pk))) {
         $this->_unlock();
         return false;
     }
     $commentObjList = array();
     if ($children) {
         $tree = $this->getTree($pk);
         foreach ($tree as $comment) {
             $this->_delete($comment);
             $commentObjList[] = JUDirectoryFrontHelperComment::getCommentObject($comment->id);
         }
         if (!$this->_lock()) {
             return false;
         }
         $query = $this->_db->getQuery(true);
         $query->delete();
         $query->from($this->_tbl);
         $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('lft = lft - ' . (int) $node->width);
         $query->where('lft > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('rgt = rgt - ' . (int) $node->width);
         $query->where('rgt > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
     } else {
         $this->_delete($node);
         if (!$this->_lock()) {
             return false;
         }
         $query = $this->_db->getQuery(true);
         $query->delete();
         $query->from($this->_tbl);
         $query->where('lft = ' . (int) $node->lft);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('lft = lft - 1');
         $query->set('rgt = rgt - 1');
         $query->set('level = level - 1');
         $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('parent_id = ' . (int) $node->parent_id);
         $query->where('parent_id = ' . (int) $node->{$k});
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('lft = lft - 2');
         $query->where('lft > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('rgt = rgt - 2');
         $query->where('rgt > ' . (int) $node->rgt);
         $this->_runQuery($query, 'JLIB_DATABASE_ERROR_DELETE_FAILED');
     }
     $this->_unlock();
     if ($children && !empty($commentObjList)) {
         foreach ($commentObjList as $commentObj) {
             if ($commentObj->approved == 0) {
                 JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reject', $commentObj->id, get_object_vars($commentObj));
             } elseif (JUDirectoryFrontHelperModerator::isModerator()) {
                 JUDirectoryFrontHelperMail::sendEmailByEvent('comment.moddelete', $commentObj->id, get_object_vars($commentObj));
             } else {
                 JUDirectoryFrontHelperMail::sendEmailByEvent('comment.userdelete', $commentObj->id, get_object_vars($commentObj));
             }
         }
     } else {
         $commentObj = JUDirectoryFrontHelperComment::getCommentObject($node->id);
         if ($commentObj->approved == 0) {
             JUDirectoryFrontHelperMail::sendEmailByEvent('comment.reject', $commentObj->id, get_object_vars($commentObj));
         } elseif (JUDirectoryFrontHelperModerator::isModerator()) {
             JUDirectoryFrontHelperMail::sendEmailByEvent('comment.moddelete', $commentObj->id, get_object_vars($commentObj));
         } else {
             JUDirectoryFrontHelperMail::sendEmailByEvent('comment.userdelete', $commentObj->id, get_object_vars($commentObj));
         }
     }
     return true;
 }
Exemplo n.º 3
0
							<span> <a
									href="<?php 
echo $this->subscriptions;
?>
"><?php 
echo JText::_('COM_JUDIRECTORY_SUBSCRIPTIONS');
?>
</a></span>
						</li>
					</ul>
				</div>
			</div>
		</div>

		<?php 
$isModerator = JUDirectoryFrontHelperModerator::isModerator();
if ($isModerator) {
    ?>
			<div id="quick-box-wrapper">
				<div class="quick-box">
					<div class="quick-box-head">
						<div class="quick-box-title"><?php 
    echo JText::_('COM_JUDIRECTORY_MODERATOR_AREA');
    ?>
</div>
					</div>
					<div class="quick-box-body clearfix">
						<ul class="stat-list">

							<li>
								<span class="stat-info"><?php 
Exemplo n.º 4
0
				<th style="width:5%" class="center">
					<?php 
echo JText::_('COM_JUDIRECTORY_FIELD_ID');
?>
				</th>
			</tr>
			</thead>

			<tbody>
			<?php 
if (is_array($this->items) && count($this->items)) {
    // @todo recheck hosting
    require_once JPATH_SITE . '/components/com_judirectory/models/listing.php';
    $listingModel = JModelLegacy::getInstance('Listing', 'JUDirectoryModel');
    foreach ($this->items as $i => $item) {
        $canEdit = JUDirectoryFrontHelperModerator::checkModeratorCanDoWithComment($item->id, 'comment_edit');
        ?>
					<tr>
						<td class="center">
							<input type="checkbox" checked="checked" class="judir-cb" name="cid[]"
							       value="<?php 
        echo $item->id;
        ?>
" id="judir-cb-<?php 
        echo $i;
        ?>
"/>
						</td>

						<td>
							<?php 
Exemplo n.º 5
0
    public static function optimizeListListingQuery(&$query, $massSelect = false)
    {
        $user = JFactory::getUser();
        $query->select('cmain.id AS cat_id');
        $query->join('', '#__judirectory_listings_xref AS listingxmain ON listing.id = listingxmain.listing_id AND listingxmain.main = 1');
        $query->join('', '#__judirectory_categories AS cmain ON cmain.id = listingxmain.cat_id');
        $categoryIdArrayCanAccess = JUDirectoryFrontHelperPermission::getAccessibleCategoryIds();
        if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) {
            $query->where('cmain.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')');
        } else {
            $query->where('cmain.id IN("")');
        }
        if ($massSelect) {
            $commentsField = new JUDirectoryFieldCore_comments();
            if ($commentsField->canView(array("view" => "list"))) {
                $isModerator = JUDirectoryFrontHelperModerator::isModerator();
                if (!$isModerator && !$user->authorise('core.admin', 'com_judirectory')) {
                    $params = JUDirectoryHelper::getParams();
                    $negative_vote_comment = $params->get('negative_vote_comment');
                    if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) {
                        $query->select('(SELECT COUNT(*) FROM #__judirectory_comments AS cm WHERE cm.listing_id = listing.id AND cm.approved = 1 AND cm.published = 1 AND cm.level = 1
										AND (cm.total_votes - cm.helpful_votes) < ' . $negative_vote_comment . ' ) AS total_comments');
                    } else {
                        $query->select('(SELECT COUNT(*) FROM #__judirectory_comments AS cm WHERE cm.listing_id = listing.id AND cm.approved = 1 AND cm.published = 1 AND cm.level = 1) AS total_comments');
                    }
                }
            }
            $subscriptionsField = new JUDirectoryFieldCore_subscriptions();
            if ($subscriptionsField->canView(array("view" => "list"))) {
                $query->select('(SELECT COUNT(*) FROM #__judirectory_subscriptions AS sub WHERE sub.item_id = listing.id AND sub.type = "listing" AND sub.published = 1) AS total_subscriptions');
            }
            $reportsField = new JUDirectoryFieldCore_reports();
            if ($reportsField->canView(array("view" => "list"))) {
                $query->select('(SELECT COUNT(*) FROM #__judirectory_reports AS r WHERE r.item_id = listing.id AND r.type = "listing") AS total_reports');
            }
            $categoriesField = new JUDirectoryFieldCore_categories();
            if ($categoriesField->canView(array("view" => "list"))) {
                $query->select('(SELECT GROUP_CONCAT(catids.id ORDER BY listingx_catids.main DESC, listingx_catids.ordering ASC SEPARATOR ",") FROM (#__judirectory_categories AS catids JOIN #__judirectory_listings_xref AS listingx_catids ON catids.id = listingx_catids.cat_id) WHERE listing.id = listingx_catids.listing_id GROUP BY listing.id) AS cat_ids');
                $query->select('(SELECT GROUP_CONCAT(cattitles.title ORDER BY listingx_cattitles.main DESC, listingx_cattitles.ordering ASC SEPARATOR "|||") FROM (#__judirectory_categories AS cattitles JOIN #__judirectory_listings_xref AS listingx_cattitles ON cattitles.id = listingx_cattitles.cat_id) WHERE listing.id = listingx_cattitles.listing_id GROUP BY listing.id) AS cat_titles');
            }
            $tagsField = new JUDirectoryFieldCore_tags();
            if ($tagsField->canView(array("view" => "list"))) {
                $query->select('IFNULL ((SELECT GROUP_CONCAT(tagids.id ORDER BY tx_tagids.ordering ASC SEPARATOR ",") FROM (#__judirectory_tags AS tagids JOIN #__judirectory_tags_xref AS tx_tagids ON tagids.id = tx_tagids.tag_id) WHERE listing.id = tx_tagids.listing_id GROUP BY listing.id), "") AS tag_ids');
                $query->select('IFNULL ((SELECT GROUP_CONCAT(tagtitles.title ORDER BY tx_tagtitles.ordering ASC SEPARATOR "|||") FROM (#__judirectory_tags AS tagtitles JOIN #__judirectory_tags_xref AS tx_tagtitles ON tagtitles.id = tx_tagtitles.tag_id) WHERE listing.id = tx_tagtitles.listing_id GROUP BY listing.id), "") AS tag_titles');
            }
            $app = JFactory::getApplication();
            $accessLevel = implode(',', $user->getAuthorisedViewLevels());
            $db = JFactory::getDbo();
            $date = JFactory::getDate();
            $nullDate = $db->quote($db->getNullDate());
            $nowDate = $db->quote($date->toSql());
            $fieldQuery = $db->getQuery(true);
            $fieldQuery->select('field.id');
            $fieldQuery->from('#__judirectory_fields AS field');
            $fieldQuery->where('field.field_name = ""');
            $fieldQuery->where('field.list_view = 1');
            $fieldQuery->where('field.published = 1');
            $fieldQuery->where('field.publish_up <= ' . $nowDate);
            $fieldQuery->where('(field.publish_down = ' . $nullDate . ' OR field.publish_down > ' . $nowDate . ')');
            $fieldQuery->where('field.access IN (' . $accessLevel . ')');
            $view = $app->input->get('view', '');
            if ($view == 'category' || $view == 'tree') {
                $cat_id = $app->input->getInt('id', 0);
                $category = JUDirectoryHelper::getCategoryById($cat_id);
                if (is_object($category)) {
                    $fieldQuery->where('field.group_id = ' . $category->fieldgroup_id);
                }
            } else {
                $fieldQuery->join('', '#__judirectory_categories AS c ON (field.group_id = c.fieldgroup_id OR field.group_id = 1)');
                if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) {
                    $fieldQuery->where('c.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')');
                } else {
                    $fieldQuery->where('c.id IN("")');
                }
            }
            $fieldQuery->join('', '#__judirectory_fields_groups AS field_group ON field.group_id = field_group.id');
            $fieldQuery->where('field_group.published = 1');
            $fieldQuery->where('field_group.access IN (' . $accessLevel . ')');
            $fieldQuery->group('field.id');
            $db->setQuery($fieldQuery);
            $fields = $db->loadObjectList();
            foreach ($fields as $field) {
                $query->select('IFNULL (fields_values_' . $field->id . '.value, "") AS field_values_' . $field->id);
                $query->join('LEFT', '#__judirectory_fields_values AS fields_values_' . $field->id . ' ON fields_values_' . $field->id . '.listing_id = listing.id AND fields_values_' . $field->id . '.field_id = ' . $field->id);
            }
        }
    }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 public function canSubmit($userID = null)
 {
     if (!$this->isPublished()) {
         return false;
     }
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return true;
     } else {
         if ($userID) {
             $user = JFactory::getUser($userID);
         } else {
             $user = JFactory::getUser();
         }
         if ($app->input->getInt('approve', 0) == 1) {
             if (is_object($this->listing) && $this->listing->approved <= 0) {
                 $modCanApprove = JUDirectoryFrontHelperModerator::checkModeratorCanDoWithListing($this->listing->cat_id, 'listing_approve');
                 if ($modCanApprove) {
                     return true;
                 }
             }
         }
         $approvalOption = $app->input->post->get("approval_option");
         $approvalOptionArray = array("ignore", "approve", "delete");
         if (in_array($approvalOption, $approvalOptionArray)) {
             if (is_object($this->listing) && $this->listing->approved <= 0) {
                 $categoriesField = new JUDirectoryFieldCore_categories();
                 $newMainCategory = $this->fields_data[$categoriesField->id]['main'];
                 if ($newMainCategory) {
                     $modCanApprove = JUDirectoryFrontHelperModerator::checkModeratorCanDoWithListing($newMainCategory, 'listing_approve');
                     if ($modCanApprove) {
                         return true;
                     }
                 }
             }
         }
         if ($user) {
             $assetName = 'com_judirectory.field.' . (int) $this->id;
             return $user->authorise("judir.field.value.submit", $assetName);
         }
     }
     return false;
 }
Exemplo n.º 8
0
 public static function canCheckInComment($commentId)
 {
     JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judirectory/tables");
     $commentTable = JTable::getInstance('Comment', 'JUDirectoryTable');
     $commentTable->load($commentId);
     if (property_exists($commentTable, 'checked_out') && property_exists($commentTable, 'checked_out_time') && $commentTable->checked_out > 0) {
         $user = JFactory::getUser();
         $isModerator = JUDirectoryFrontHelperModerator::isModerator();
         $isCommentOwner = JUDirectoryFrontHelperPermission::isCommentOwner($commentId);
         if ($isModerator || $isCommentOwner || $commentTable->checked_out == $user->id) {
             $canEditComment = JUDirectoryFrontHelperPermission::canEditComment($commentId);
             if ($canEditComment) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 9
0
 public function getTotalChildComments($parentId)
 {
     $listingId = (int) $this->getState('listing.id');
     $mainCategoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId);
     $user = JFactory::getUser();
     $params = $this->getState('params');
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select('COUNT(*)');
     $query->from('#__judirectory_comments AS cm');
     $query->where('cm.approved = 1');
     $query->where('cm.parent_id = ' . $parentId);
     $maxLevel = $params->get('max_comment_level', 5);
     $query->where('cm.level <= ' . $maxLevel);
     $getAll = false;
     $isModerator = JUDirectoryFrontHelperModerator::isModerator();
     if ($isModerator) {
         $moderator = JUDirectoryFrontHelperModerator::getModerator($mainCategoryId);
         if ($user->authorise('core.admin', 'com_judirectory') || $moderator && ($moderator->comment_edit || $moderator->comment_edit_state || $moderator->comment_delete)) {
             $getAll = true;
         }
     }
     if (!$getAll) {
         $query->where('cm.published = 1');
         $negative_vote_comment = $params->get('negative_vote_comment');
         if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) {
             $query->where('(cm.total_votes - cm.helpful_votes) <' . $negative_vote_comment);
         }
     }
     $db->setQuery($query);
     return $db->loadResult();
 }