public function checkin($pks = array()) { $pks = (array) $pks; $table = $this->getTable(); $count = 0; if (empty($pks)) { $pks = array((int) $this->getState($this->getName() . '.id')); } foreach ($pks as $pk) { if ($table->load($pk)) { if ($table->checked_out > 0) { if (JUDirectoryFrontHelperPermission::canCheckInComment($pk)) { if (!$table->checkin($pk)) { $this->setError($table->getError()); return false; } $count++; } else { $this->setError(JText::_('COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_CHECK_IN_COMMENT')); return false; } } } else { $this->setError($table->getError()); return false; } } return $count; }
public static function isListingPublished($listingId) { $listingObject = JUDirectoryHelper::getListingById($listingId); if (!is_object($listingObject)) { return false; } $catPublished = JUDirectoryFrontHelperPermission::canDoCategory($listingObject->cat_id); if (!$catPublished) { return false; } $db = JFactory::getDbo(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_listings'); $query->where('approved = 1'); $query->where('published = 1'); $query->where('(publish_up = ' . $db->quote($nullDate) . ' OR publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(publish_down = ' . $db->quote($nullDate) . ' OR publish_down >= ' . $db->quote($nowDate) . ')'); $query->where('id =' . $listingId); $db->setQuery($query); $result = $db->loadResult(); if ($result) { return true; } return false; }
protected function allowAdd($data = array()) { if (empty($data)) { $catId = JFactory::getApplication()->input->get('cat_id'); if (!JUDirectoryFrontHelperPermission::canSubmitListing($catId)) { return false; } } return true; }
public function display($tpl = null) { $this->model = $this->getModel(); $this->state = $this->get('State'); $this->params = $this->state->params; $this->tag = $this->get('Tag'); if (!is_object($this->tag)) { JError::raiseError(404, JText::_('COM_JUDIRECTORY_TAG_NOT_FOUND')); return false; } $user = JFactory::getUser(); $uri = JUri::getInstance(); $this->items = $this->get('Items'); foreach ($this->items as $item) { $item->report_link = JRoute::_(JUDirectoryHelperRoute::getReportListingRoute($item->id)); $item->claim_link = JRoute::_(JUDirectoryHelperRoute::getClaimListingRoute($item->id)); if ($item->checked_out > 0 && $item->checked_out != $user->get('id')) { if (JUDirectoryFrontHelperPermission::canCheckInListing($item->id)) { $item->checkin_link = JRoute::_('index.php?option=com_judirectory&task=forms.checkin&id=' . $item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri))); } } else { $item->edit_link = JRoute::_('index.php?option=com_judirectory&task=form.edit&id=' . $item->id . '&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); if ($item->published == 1) { $item->editstate_link = JRoute::_('index.php?option=com_judirectory&task=forms.unpublish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); } else { $item->editstate_link = JRoute::_('index.php?option=com_judirectory&task=forms.publish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); } } $item->delete_link = JRoute::_('index.php?option=com_judirectory&task=forms.delete&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $item->event = new stdClass(); $context = 'com_judirectory.listing_list'; $results = $dispatcher->trigger('onContentAfterTitle', array($context, &$this->item, &$this->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$this->item, &$this->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($context, &$this->item, &$this->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); } $this->pagination = $this->get('Pagination'); $this->token = JSession::getFormToken(); if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->show_feed = JUDIRPROVERSION ? $this->params->get('rss_display_icon', 1) : 0; $rssLink = JRoute::_(JUDirectoryHelperRoute::getTagRoute($this->tag->id, false, true)); $this->rss_link = JRoute::_($rssLink, false); $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
protected function getListQuery() { $db = $this->getDbo(); $date = JFactory::getDate(); $now = $date->toSql(); $nullDate = $db->getNullDate(); $query = $db->getQuery(true); $query->select('listing.id, listing.title, listing.alias, listing.created, listing.access'); $query->from('#__judirectory_listings AS listing'); $query->join('', '#__judirectory_listings_xref AS listingxref ON dxref.doc_id = listing.id AND dxref.main = 1'); $query->select('c.title AS category_title'); $query->join('', '#__judirectory_categories AS c ON c.id = dxref.cat_id'); $categoryIdArrayCanAccess = JUDirectoryFrontHelperPermission::getAccessibleCategoryIds(); if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) { $query->where('c.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')'); } else { $query->where('c.id IN("")'); } $query->select('vl.title AS access_title'); $query->join('LEFT', '#__viewlevels AS vl ON vl.id = listing.access'); $access = $this->getState('filter.access'); if ($access) { $query->where('listing.access = ' . (int) $access); } $categoryId = $this->getState('filter.catid'); if (is_numeric($categoryId)) { $query->where('c.id = ' . (int) $categoryId); } $query->where('c.published = 1'); $query->where('c.publish_up <= ' . $db->quote($now)); $query->where('(c.publish_down = ' . $db->quote($nullDate) . ' OR c.publish_down > ' . $db->quote($now) . ')'); $featured = $this->getState('filter.featured', ''); if ($featured !== '') { $query->where('listing.featured = ' . (int) $featured); } $query->where('listing.approved = 1'); $query->where('listing.published = 1'); $query->where('listing.publish_up <= ' . $db->quote($now)); $query->where('(listing.publish_down = ' . $db->quote($nullDate) . ' OR listing.publish_down > ' . $db->quote($now) . ')'); $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('listing.id = ' . (int) substr($search, 3)); } else { $search = $db->Quote('%' . $db->getEscaped($search, true) . '%'); $query->where('listing.title LIKE ' . $search); } } $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); if ($orderCol) { $query->order($orderCol . ' ' . $orderDirn); } return $query; }
public function display($tpl = null) { $app = JFactory::getApplication(); $categoryId = $app->input->getInt('id', 1); $this->category = JUDirectoryFrontHelperCategory::getCategory($categoryId); $error = array(); if (!JUDirectoryFrontHelperPermission::canDoCategory($this->category->id, true, $error)) { $user = JFactory::getUser(); if ($user->id) { return JError::raiseError($error['code'], $error['message']); } else { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app = JFactory::getApplication(); $app->redirect($loginUrl, JText::_('COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning'); return false; } } $model = $this->getModel(); $this->model = $model; $this->state = $this->get('State'); $this->params = $this->state->params; if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->parent_id = $this->category->id; $this->subcategory_level = (int) $this->params->get('all_categories_subcategory_level', -1); $this->all_categories = $model->getCategoriesRecursive($this->category->id, $this->subcategory_level); $firstCategory = $this->all_categories[0]; $this->category->total_childs = $firstCategory->total_childs; $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
/** * ------------------------------------------------------------------------ * JUDirectory for Joomla 2.5, 3.x * ------------------------------------------------------------------------ * * @copyright Copyright (C) 2010-2015 JoomUltra Co., Ltd. All Rights Reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author JoomUltra Co., Ltd * @website http://www.joomultra.com * @----------------------------------------------------------------------@ */ // No direct access to this file defined('_JEXEC') or die('Restricted access'); //@todo properties has called in view $user = JFactory::getUser(); $isOwnDashboard = JUDirectoryFrontHelperPermission::isOwnDashboard(); JLoader::register('JUDirectoryAvatarHelper', JPATH_SITE . '/components/com_judirectory/helpers/avatar.php'); $avatar = JUDirectoryAvatarHelper::getJUAvatar($user->id); $userId = JUDirectoryFrontHelper::getDashboardUserId(); $linkDashboard = JRoute::_(JUDirectoryHelperRoute::getDashboardRoute($userId)); $linkUserProfile = JRoute::_(JUDirectoryHelperRoute::getUserProfileRoute()); $linkCreateListing = JRoute::_(JUDirectoryHelperRoute::getFormRoute()); $linkUserComments = JRoute::_(JUDirectoryHelperRoute::getUserCommentsRoute($userId)); $linkUserCollection = JRoute::_(JUDirectoryHelperRoute::getCollectionsRoute($userId)); $linkUserListings = JRoute::_(JUDirectoryHelperRoute::getUserListingsRoute($userId)); $linkUserSubscriptions = JRoute::_(JUDirectoryHelperRoute::getUserSubscriptionsRoute($userId)); $linkLogOutReturn = JRoute::_('index.php', false); ?> <div class="navbar"> <div class="navbar-inner"> <ul class="nav">
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']; } }
public function getOutput($options = array()) { if (!$this->isPublished()) { return ""; } $options = new JRegistry($options); $this->initMultipleRatingField(); $this->loadDefaultAssets(); if ($this->listing->cat_id) { $this->criteriaGroupId = JUDirectoryFrontHelperCriteria::getCriteriaGroupIdByCategoryId($this->listing->cat_id); } if (JUDirectoryHelper::hasMultiRating()) { if ($this->criteriaGroupId) { $this->criteriaObjectList = JUDirectoryFrontHelperCriteria::getCriteriasByCatId($this->listing->cat_id); } } $this->selectedStar = round($this->listing->rating * $this->totalStars / 10, 2); if ($this->isDetailsView($options)) { $this->canRateListing = JUDirectoryFrontHelperPermission::canRateListing($this->listing_id); $document = JFactory::getDocument(); $document->addStyleSheet(JUri::root(true) . "/components/com_judirectory/assets/css/jquery.rating.css"); $document->addScript(JUri::root(true) . "/components/com_judirectory/assets/js/jquery.MetaData.js"); $document->addScript(JUri::root(true) . "/components/com_judirectory/assets/js/jquery.rating.js"); $singleRatingScript = ' jQuery(document).ready(function ($) { $(".judir-single-rating").rating({ callback: function (value) { var str = $(this).attr("name"); var patt = /^judir-listing-rating-result-(.*)$/i; var result = str.match(patt); var listingId = result[1]; var ratingValue = $(this).val(); var objectListing = {}; var token = $("#judir-single-rating-token").attr("name"); objectListing.listing_id = listingId; objectListing.ratingValue = ratingValue; if ($.isNumeric(listingId) && (ratingValue > 0 && ratingValue <= 10)) { $.ajax({ type: "POST", url : "index.php?option=com_judirectory&task=listing.singleRating&" + token + "=1", data: objectListing }).done(function (msg) { alert(msg); }); } } }); });'; if ($this->canRateListing) { $document->addScriptDeclaration($singleRatingScript); } } if (is_object($this->multiRating)) { return $this->multiRating->getOutput($options); } else { $this->setVariable('options', $options); $this->setVariable('className', __CLASS__); return $this->fetch('output.php', __CLASS__); } }
public function getRelatedCategories($categoryId, $ordering = 'crel.ordering', $direction = 'ASC') { $storeId = md5(__METHOD__ . "::" . $categoryId . "::" . $ordering . "::" . $direction); if (!isset($this->cache[$storeId])) { $params = $this->getState('params'); $showEmptyCategory = $params->get('show_empty_related_category', 1); $user = JFactory::getUser(); $levels = $user->getAuthorisedViewLevels(); $levelsStr = implode(',', $levels); $db = JFactory::getDbo(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('c.*'); $query->from('#__judirectory_categories AS c'); $query->join('INNER', '#__judirectory_categories_relations AS crel ON c.id=crel.cat_id_related'); $query->where('crel.cat_id =' . $categoryId); $query->where('c.published = 1'); $query->where('(c.publish_up = ' . $db->quote($nullDate) . ' OR c.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(c.publish_down = ' . $db->quote($nullDate) . ' OR c.publish_down >= ' . $db->quote($nowDate) . ')'); $query->where('c.access IN (' . $levelsStr . ')'); $categoryIdArrayCanAccess = JUDirectoryFrontHelperPermission::getAccessibleCategoryIds(); if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) { $query->where('c.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')'); } else { $query->where('c.id IN("")'); } $app = JFactory::getApplication(); $tag = JFactory::getLanguage()->getTag(); if ($app->getLanguageFilter()) { $query->where('c.language IN (' . $db->quote($tag) . ',' . $db->quote('*') . ',' . $db->quote('') . ')'); } $query->order($ordering . ' ' . $direction); $query->group('c.id'); $db->setQuery($query); $categoriesBefore = $db->loadObjectList(); $categoriesAfter = array(); foreach ($categoriesBefore as $category) { $showTotalSubCats = $params->get('show_total_subcats_of_relcat', 0); $showTotalChildListings = $params->get('show_total_listings_of_relcat', 0); $nestedCategories = null; if ($showTotalChildListings || $showTotalSubCats) { $nestedCategories = JUDirectoryFrontHelperCategory::getCategoriesRecursive($category->id, true, true, true, false, false, true); if ($showTotalChildListings) { $category->total_listings = JUDirectoryFrontHelperCategory::getTotalListingsInCategory($category->id, $nestedCategories); } if ($showTotalSubCats) { $category->total_nested_categories = JUDirectoryFrontHelperCategory::getTotalSubCategoriesInCategory($category->id, $nestedCategories); } } $registry = new JRegistry(); $registry->loadString($category->images); $category->images = $registry->toObject(); $category->link = JRoute::_(JUDirectoryHelperRoute::getCategoryRoute($category->id)); if (!$showEmptyCategory) { if (is_null($nestedCategories)) { $nestedCategories = JUDirectoryFrontHelperCategory::getCategoriesRecursive($category->id, true, true, true, false, false, true); } if (!isset($category->total_nested_categories)) { $category->total_nested_categories = JUDirectoryFrontHelperCategory::getTotalSubCategoriesInCategory($category->id, $nestedCategories); } if (!isset($category->total_listings)) { $category->total_listings = JUDirectoryFrontHelperCategory::getTotalListingsInCategory($category->id, $nestedCategories); } if ($category->total_nested_categories > 0 || $category->total_listings > 0) { $categoriesAfter[] = $category; } } else { $categoriesAfter[] = $category; } } $this->cache[$storeId] = $categoriesAfter; } return $this->cache[$storeId]; }
public function loadCategories() { $app = JFactory::getApplication(); $rootCat = JUDirectoryFrontHelperCategory::getRootCategory(); $type = $app->input->get('type', ''); $catId = $app->input->getInt('id', 0); $catObj = JUDirectoryHelper::getCategoryById($catId); $params = JUDirectoryHelper::getParams($catId); $date = JFactory::getDate(); $back = false; if ($catId != 0) { if ($type == 'category') { $back = true; } elseif ($catId == $rootCat->id && $params->get('allow_add_listing_to_root', 0) || $catId != $rootCat->id) { $back = true; } } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->SELECT('title, id, published, parent_id, publish_up, publish_down'); $query->FROM('#__judirectory_categories'); $query->WHERE('parent_id = ' . $catId); $query->ORDER('lft'); $db->setQuery($query); $rows = $db->loadObjectList(); $html = ""; if ($back) { $html .= '<option value="' . $catObj->parent_id . '" data-update="noupdate">' . JText::_('COM_JUDIRECTORY_BACK_TO_PARENT_CATEGORY') . '</option>'; } foreach ($rows as $row) { if ($type == 'listing') { $canDoCreate = JUDirectoryFrontHelperPermission::canSubmitListing($row->id); if (!$canDoCreate) { continue; } } if ($row->published != 1 || $row->publish_up > $date->toSql() || $row->publish_down > $db->getNullDate() && $row->publish_down <= $date->toSql()) { $row->title = "[" . $row->title . "]"; } $html .= "<option value=\"" . $row->id . "\">" . $row->title . "</option>"; } $data['path'] = JUDirectoryHelper::generateCategoryPath($catId, 'li'); $data['html'] = $html; return json_encode($data); }
public static function appendDataToListingObjList(&$listingObjectList, $params, $usingForMod = false) { if (is_array($listingObjectList) && count($listingObjectList)) { $user = JFactory::getUser(); foreach ($listingObjectList as $listingObject) { JUDirectoryHelper::getListingById($listingObject->id, false, $listingObject); $listingObject->params = JUDirectoryFrontHelperListing::getListingDisplayParams($listingObject->id); if (!$user->get('guest')) { $canEditListing = JUDirectoryFrontHelperPermission::canEditListing($listingObject->id); $canEditStateListing = JUDirectoryFrontHelperPermission::canEditStateListing($listingObject); $canDeleteListing = JUDirectoryFrontHelperPermission::canDeleteListing($listingObject->id); $listingObject->params->set('access-edit', $canEditListing); $listingObject->params->set('access-edit-state', $canEditStateListing); $listingObject->params->set('access-delete', $canDeleteListing); } if ($listingObject->published != 1) { $listingObject->label_unpublished = true; } else { $listingObject->label_unpublished = false; } $listingObject->label_pending = false; $nowDate = JFactory::getDate()->toSql(); if (intval($listingObject->publish_up) > 0) { if (strtotime($listingObject->publish_up) > strtotime($nowDate)) { $listingObject->label_pending = true; } } $listingObject->label_expired = false; if (intval($listingObject->publish_down) > 0) { if (intval($listingObject->publish_up) > 0) { if (strtotime($listingObject->publish_up) <= strtotime($nowDate)) { if (strtotime($listingObject->publish_down) < strtotime($nowDate)) { $listingObject->label_expired = true; } } } else { if (strtotime($listingObject->publish_down) < strtotime($nowDate)) { $listingObject->label_expired = true; } } } if ($params->get('show_new_label', 1) && JUDirectoryFrontHelper::isWithinXDays($listingObject->publish_up, $params->get('num_day_to_show_as_new', 10))) { $listingObject->label_new = true; } else { $listingObject->label_new = false; } if ($params->get('show_updated_label', 1) && JUDirectoryFrontHelper::isWithinXDays($listingObject->updated, $params->get('num_day_to_show_as_updated', 10))) { $listingObject->label_updated = true; } else { $listingObject->label_updated = false; } if ($params->get('show_hot_label', 1) && JUDirectoryFrontHelperListing::checkHotListing($listingObject->publish_up, $params->get('num_hit_per_day_to_be_hot', 100), $listingObject->hits)) { $listingObject->label_hot = true; } else { $listingObject->label_hot = false; } if ($params->get('show_featured_label', 1) && $listingObject->featured) { $listingObject->label_featured = true; } else { $listingObject->label_featured = false; } } } }
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; }
protected function canDelete($record) { $rootComment = JUDirectoryFrontHelperComment::getRootComment(); if (isset($record->id) && $record->id == $rootComment->id) { return false; } $app = JFactory::getApplication(); if ($app->isSite()) { return JUDirectoryFrontHelperPermission::canDeleteComment($record->id); } return parent::canDelete($record); }
echo $this->commentObj->id; ?> "> <input name="subscribe" id="comment-reply-subscribe-<?php echo $this->commentObj->id; ?> " class="comment-subscribe" type="checkbox" value="1"/> <?php echo JText::_('COM_JUDIRECTORY_COMMENT_SUBSCRIBE'); ?> </label> </div> <?php } if (JUDirectoryFrontHelperPermission::showCaptchaWhenComment($this->item->id)) { echo JUDirectoryFrontHelperCaptcha::getCaptcha(true); } ?> </div> <div class="comment-form-submit clearfix"> <button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('listing.addComment', 'judir-comment-reply-form-<?php echo $this->commentObj->id; ?> ');"><?php echo JText::_('COM_JUDIRECTORY_SUBMIT'); ?> </button> <input type="reset" name="reply-reset" class="btn"
public static function getTotalListingsInCategory($categoryId, $nestedCategoryIds = null) { if (is_null($nestedCategoryIds)) { $nestedCategories = JUDirectoryFrontHelperCategory::getCategoriesRecursive($categoryId, true, true, true); $nestedCategoryIds = array(); foreach ($nestedCategories as $nestedCategory) { $nestedCategoryIds[] = $nestedCategory->id; } } if (!is_array($nestedCategoryIds) || !count($nestedCategoryIds)) { return 0; } $storeId = md5(__METHOD__ . "::" . serialize($nestedCategoryIds)); if (!isset(self::$cache[$storeId])) { $user = JFactory::getUser(); $levels = $user->getAuthorisedViewLevels(); $levelsStr = implode(',', $levels); $db = JFactory::getDbo(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_listings AS listing'); $query->join('', '#__judirectory_listings_xref AS listingxref ON listing.id = listingxref.listing_id'); $query->join('', '#__judirectory_categories AS c ON c.id = listingxref.cat_id'); if (is_array($nestedCategoryIds) && count($nestedCategoryIds) > 0) { $query->where('(c.id IN (' . implode(",", $nestedCategoryIds) . '))'); } else { $query->where('(c.id IN (""))'); } $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("")'); } $query->where('listing.approved = 1'); $query->where('listing.published = 1'); $query->where('(listing.publish_up = ' . $db->quote($nullDate) . ' OR listing.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(listing.publish_down = ' . $db->quote($nullDate) . ' OR listing.publish_down >= ' . $db->quote($nowDate) . ')'); if ($user->get('guest')) { $query->where('listing.access IN (' . $levelsStr . ')'); } else { $query->where('(listing.access IN (' . $levelsStr . ') OR listing.created_by = ' . $user->id . ')'); } $app = JFactory::getApplication(); $tagLanguage = JFactory::getLanguage()->getTag(); if ($app->getLanguageFilter()) { $query->where('listing.language IN (' . $db->quote($tagLanguage) . ',' . $db->quote('*') . ',' . $db->quote('') . ')'); } $db->setQuery($query); self::$cache[$storeId] = $db->loadResult(); } return self::$cache[$storeId]; }
public function getCatIdTree($catId, $includeItSelf = true) { $catId = (int) $catId; if (!$catId) { return null; } if (!JUDirectoryFrontHelperPermission::canDoCategory($catId)) { return null; } $cat_id_arr = array(); if ($includeItSelf) { $cat_id_arr[] = $catId; } $db = JFactory::getDbo(); $query = "SELECT id FROM #__judirectory_categories WHERE parent_id = " . $catId; $db->setQuery($query); $child_cat_ids = $db->loadColumn(); foreach ($child_cat_ids as $child_cat_id) { $cat_id_arr[] = $child_cat_id; $child_cat_id_arr = $this->getCatIdTree($child_cat_id, false); if ($child_cat_id_arr) { $cat_id_arr = array_merge($cat_id_arr, $child_cat_id_arr); } } return array_unique($cat_id_arr); }
protected function canEditState($record) { $app = JFactory::getApplication(); if ($app->isSite()) { return JUDirectoryFrontHelperPermission::canEditStateListing($record); } return true; }
public static function canViewDashboard() { $params = JUDirectoryHelper::getParams(); $public_user_dashboard = $params->get("public_user_dashboard", 0); $user = JFactory::getUser(); if ($public_user_dashboard) { $app = JFactory::getApplication(); $userId = $app->input->getInt('id', 0); if ($user->id == 0 && $userId == 0) { return false; } return true; } else { if ($user->id == 0) { return false; } else { $isOwnDashboard = JUDirectoryFrontHelperPermission::isOwnDashboard(); return $isOwnDashboard; } } }
public function getTotalListingsAssignTag($tagId) { $user = JFactory::getUser(); $levels = $user->getAuthorisedViewLevels(); $levelsStr = implode(',', $levels); $db = $this->getDbo(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_listings AS listing'); $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("")'); } $query->where('listing.approved = 1'); $query->where('listing.published = 1'); $query->where('(listing.publish_up = ' . $db->quote($nullDate) . ' OR listing.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(listing.publish_down = ' . $db->quote($nullDate) . ' OR listing.publish_down >= ' . $db->quote($nowDate) . ')'); if ($user->get('guest')) { $query->where('listing.access IN (' . $levelsStr . ')'); } else { $query->where('(listing.access IN (' . $levelsStr . ') OR (listing.created_by = ' . $user->id . '))'); } $app = JFactory::getApplication(); $languageTag = JFactory::getLanguage()->getTag(); if ($app->getLanguageFilter()) { $query->where('listing.language IN (' . $db->quote($languageTag) . ',' . $db->quote('*') . ',' . $db->quote('') . ')'); } $query->join('', '#__judirectory_tags_xref AS tag_xref ON tag_xref.listing_id = listing.id'); $query->join('', '#__judirectory_tags AS tag ON tag.id = tag_xref.tag_id'); $query->where('tag.published = 1'); $query->where('(tag.publish_up = ' . $db->quote($nullDate) . ' OR tag.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(tag.publish_down = ' . $db->quote($nullDate) . ' OR tag.publish_down >= ' . $db->quote($nowDate) . ')'); $query->where('tag.id =' . $tagId); $db->setQuery($query); return (int) $db->loadResult(); }
public static function isEmptyCat($catId) { $categoryIdArrayCanAccess = JUDirectoryFrontHelperPermission::getAccessibleCategoryIds(); if (empty($categoryIdArrayCanAccess)) { return true; } $user = JFactory::getUser(); $levelsArray = $user->getAuthorisedViewLevels(); $levelString = implode(',', $levelsArray); $db = JFactory::getDBO(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_categories AS c'); $query->where('c.parent_id = ' . $catId); $query->where('c.published = 1'); $query->where('(c.publish_up = ' . $db->quote($nullDate) . ' OR c.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(c.publish_down = ' . $db->quote($nullDate) . ' OR c.publish_down >= ' . $db->quote($nowDate) . ')'); $query->where('c.access IN (' . $levelString . ')'); $query->where('c.id IN (' . implode(",", $categoryIdArrayCanAccess) . ')'); $app = JFactory::getApplication(); $tagLanguage = JFactory::getLanguage()->getTag(); if ($app->getLanguageFilter()) { $query->where('c.language IN (' . $db->quote($tagLanguage) . ',' . $db->quote('*') . ')'); } $db->setQuery($query); $totalSubCats = $db->loadResult(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_listings AS listing'); $query->where('listingxref.cat_id = ' . $catId); $query->where('listing.approved = 1'); $query->where('listing.published = 1'); $query->where('(listing.publish_up = ' . $db->quote($nullDate) . ' OR listing.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(listing.publish_down = ' . $db->quote($nullDate) . ' OR listing.publish_down >= ' . $db->quote($nowDate) . ')'); if ($user->get('guest')) { $query->where('listing.access IN (' . $levelString . ')'); } else { $query->where('(listing.access IN (' . $levelString . ') OR (listing.created_by = ' . $user->id . '))'); } $query->join('INNER', '#__judirectory_listings_xref AS listingxref ON listing.id = listingxref.listing_id'); $query->where('listingxref.cat_id IN (' . implode(",", $categoryIdArrayCanAccess) . ')'); $app = JFactory::getApplication(); $tagLanguage = JFactory::getLanguage()->getTag(); if ($app->getLanguageFilter()) { $query->where('listing.language IN (' . $db->quote($tagLanguage) . ',' . $db->quote('*') . ')'); } $query->group('listing.id'); $db->setQuery($query); $totalListings = $db->loadResult(); if (!$totalSubCats && !$totalListings) { return true; } else { return false; } }
public static function getCategoryOptions($catId = 1, $fetchSelf = true, $checkCreatedPermission = false, $checkPublished = false, $ignoredCatId = array(), $startLevel = 0, $separation = '|—') { $categoryTree = self::getCategoryTree($catId, $fetchSelf, $checkPublished); if ($categoryTree) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $options = array(); $ignoredCatIdArr = array(); if ($ignoredCatId) { foreach ($ignoredCatId as $cat_id) { if (!in_array($cat_id, $ignoredCatIdArr)) { $_categoryTree = self::getCategoryTree($cat_id, true); foreach ($_categoryTree as $category) { if (!in_array($category->id, $ignoredCatIdArr)) { $ignoredCatIdArr[] = $category->id; } } } } } foreach ($categoryTree as $key => $item) { if ($app->isSite()) { $accessibleCategoryIds = JUDirectoryFrontHelperPermission::getAccessibleCategoryIds(); if (!is_array($accessibleCategoryIds)) { $accessibleCategoryIds = array(); } if (!in_array($item->id, $accessibleCategoryIds)) { continue; } } if ($ignoredCatIdArr && in_array($item->id, $ignoredCatIdArr)) { continue; } $disable = false; if ($checkCreatedPermission) { if ($checkCreatedPermission == "category") { $assetName = 'com_judirectory.category.' . (int) $item->id; $candoCreate = $user->authorise('judir.category.create', $assetName); if (!$candoCreate) { $disable = true; } } elseif ($checkCreatedPermission == "listing") { $assetName = 'com_judirectory.category.' . (int) $item->id; $candoCreate = $user->authorise('judir.listing.create', $assetName); if (!$candoCreate) { $disable = true; } if ($item->id == 1 && !$disable) { $params = JUDirectoryHelper::getParams(); if (!$params->get('allow_add_listing_to_root', 0)) { $disable = true; } } } } if ($item->published != 1) { $item->title = "[" . $item->title . "]"; } if ($key == 0) { $firstLevel = $item->level - $startLevel; } $level = $item->level - $firstLevel; $options[] = JHtml::_('select.option', $item->id, str_repeat($separation, $level) . $item->title, 'value', 'text', $disable); } } return $options; }
protected function getListQuery() { $listOrder = $this->state->get('list.ordering'); $listDirn = $this->state->get('list.direction'); $search = $this->state->get('filter.search'); $user = JFactory::getUser(); $levels = $user->getAuthorisedViewLevels(); $levelsStr = implode(',', $levels); $db = $this->getDBO(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('listing.*'); $query->from('#__judirectory_listings AS listing'); $query->join('', '#__judirectory_listings_xref AS listingxref ON listingxref.listing_id = listing.id AND listingxref.main = 1'); $query->select('c.title AS category_title'); $query->join('', '#__judirectory_categories AS c ON listingxref.cat_id = c.id'); $categoryIdArrayCanAccess = JUDirectoryFrontHelperPermission::getAccessibleCategoryIds(); if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0) { $query->where('c.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')'); } else { $query->where('c.id IN("")'); } $query->select('ua.name AS created_by'); $query->join('LEFT', '#__users AS ua ON ua.id = listing.created_by'); $query->select('vl.title AS access_level'); $query->join('LEFT', '#__viewlevels AS vl ON vl.id = listing.access'); $query->where('listing.approved = 1'); $query->where('listing.published = 1'); $query->where('(listing.publish_up = ' . $db->quote($nullDate) . ' OR listing.publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(listing.publish_down = ' . $db->quote($nullDate) . ' OR listing.publish_down >= ' . $db->quote($nowDate) . ')'); if ($user->get('guest')) { $query->where('listing.access IN (' . $levelsStr . ')'); } else { $query->where('(listing.access IN (' . $levelsStr . ') OR (listing.created_by = ' . $user->id . '))'); } $catid = $this->getState('filter.catid'); if ($catid) { $query->where('c.id = ' . $db->quote($catid)); } $access = $this->getState('filter.access'); if ($access) { $query->where('listing.access = ' . (int) $access); } $published = $this->getState('filter.published', ''); if ($published !== '') { $query->where('listing.published = ' . (int) $published); } $featured = $this->getState('filter.featured', ''); if ($featured !== '') { $query->where('listing.featured = ' . (int) $featured); } if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('listing.id = ' . (int) substr($search, 3)); } elseif (stripos($search, 'author:') === 0) { $search = substr($search, 7); $search = $db->quote('%' . $db->escape($search, true) . '%'); $query->where('c.title LIKE ' . $search); } elseif (stripos($search, 'created_by:') === 0) { $search = substr($search, 11); if (is_numeric($search)) { $query->where('listing.created_by = 0 OR listing.created_by IS NULL'); } else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); $query->where('(ua.name LIKE ' . $search . ' OR ua.username LIKE ' . $search . ')'); } } else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); $query->where('listing.title LIKE ' . $search); } } $orderingAllow = array('listing.id', 'listing.title', 'listing.author', 'c.title', 'l.title', 'listing.featured', 'listing.published', 'listing.created'); if (in_array($listOrder, $orderingAllow)) { if ($listOrder == 'c.title' || $listOrder == 'l.title') { $query->order($listOrder . " " . $listDirn . ', listing.title'); } else { $query->order($listOrder . ' ' . $listDirn); } } return $query; }
protected function getAllCategoryOptions() { $rootCat = JUDirectoryFrontHelperCategory::getRootCategory(); JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judirectory/tables"); $categoryTable = JTable::getInstance('Category', 'JUDirectoryTable'); $categoryTree = $categoryTable->getTree($rootCat->id); foreach ($categoryTree as $key => $cat) { $canSubmitListing = JUDirectoryFrontHelperPermission::canSubmitListing($cat->id); // Unset category that user can not submit listing if (!$canSubmitListing) { unset($categoryTree[$key]); continue; } // Unpublished category wrap by [] if ($cat->published != 1) { $categoryTree[$key]->title = "[" . $cat->title . "]"; } $categoryTree[$key]->title = str_repeat('|—', $cat->level) . $categoryTree[$key]->title; } // getParams by cat_id if possible if (isset($this->listing) && $this->listing->cat_id) { $params = JUDirectoryHelper::getParams($this->listing->cat_id); } else { $params = JUDirectoryHelper::getParams(null, $this->listing_id); } if ($params->get('allow_add_listing_to_root', 0)) { array_unshift($categoryTree, JHtml::_('select.option', $rootCat->id, JText::_('COM_JUDIRECTORY_ROOT'), 'id', 'title')); } return $categoryTree; }
public function display($tpl = null) { $model = $this->getModel(); $this->model = $model; $this->state = $this->get('State'); $params = $this->state->params; $this->params = $params; $this->token = JSession::getFormToken(); $this->root_category = JUDirectoryFrontHelperCategory::getRootCategory(); $categoryId = $this->state->get('category.id', $this->root_category->id); if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } $error = array(); if (!JUDirectoryFrontHelperPermission::canDoCategory($categoryId, true, $error)) { $user = JFactory::getUser(); if ($user->id) { return JError::raiseError($error['code'], $error['message']); } else { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app = JFactory::getApplication(); $app->redirect($loginUrl, JText::_('COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning'); return false; } } $topLevelCats = JUDirectoryHelper::getCatsByLevel(1, $categoryId); if (is_array($topLevelCats) && count($topLevelCats) > 0) { $this->tl_catid = $topLevelCats[0]->id; } $this->category = JUDirectoryFrontHelperCategory::getCategory($categoryId); $this->show_feed = JUDIRPROVERSION ? $this->params->get('rss_display_icon', 1) : 0; $this->rss_link = JRoute::_(JUDirectoryHelperRoute::getCategoryRoute($this->category->id, null, true)); if (isset($this->category->images) && !empty($this->category->images) && !empty($this->category->images->detail_image)) { $this->category->images->detail_image_src = JUri::root(true) . '/' . JUDirectoryFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judirectory/images/category/detail/', true) . $this->category->images->detail_image; } $this->category->images->detail_image_width = (int) $this->params->get('category_image_width', 200); $this->category->images->detail_image_height = (int) $this->params->get('category_image_height', 200); if ($this->params->get('category_show_description', 1)) { $this->category->description = $this->category->introtext . $this->category->fulltext; } else { $this->category->description = $this->category->fulltext; } $categoryDescLimit = (int) $this->params->get('category_desc_limit', 0); if ($categoryDescLimit > 0) { $this->category->description = JUDirectoryFrontHelperString::truncateHtml($this->category->description, $categoryDescLimit); } if ($this->params->get('plugin_support', 0)) { $this->category->description = JHtml::_('content.prepare', $this->category->description, '', 'com_judirectory.category'); } $this->category->class_sfx = htmlspecialchars($this->category->class_sfx); $relatedCatOrdering = $this->params->get('related_category_ordering', 'crel.ordering'); $relatedCatDirection = $this->params->get('related_category_direction', 'ASC'); $this->related_cats = $model->getRelatedCategories($this->category->id, $relatedCatOrdering, $relatedCatDirection); if (is_array($this->related_cats) && count($this->related_cats) > 0) { foreach ($this->related_cats as $relatedCategory) { if (isset($relatedCategory->images->intro_image) && !empty($relatedCategory->images->intro_image)) { $relatedCategory->images->intro_image_src = JUri::root(true) . '/' . JUDirectoryFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judirectory/images/category/intro/', true) . $relatedCategory->images->intro_image; } $relatedCategory->images->intro_image_width = (int) $this->params->get('related_category_intro_image_width', 200); $relatedCategory->images->intro_image_height = (int) $this->params->get('related_category_intro_image_height', 200); if ($this->params->get('related_category_show_introtext', 1)) { $relatedCategoryDescLimit = (int) $this->params->get('related_category_introtext_character_limit', 500); if ($relatedCategoryDescLimit > 0) { $relatedCategory->introtext = JUDirectoryFrontHelperString::truncateHtml($relatedCategory->introtext, $relatedCategoryDescLimit); } if ($params->get('plugin_support', 0)) { $relatedCategory->introtext = JHtml::_('content.prepare', $relatedCategory->introtext, '', 'com_judirectory.category'); } } else { $relatedCategory->introtext = ''; } } } $subCatOrdering = $this->params->get('subcategory_ordering', 'title'); $subCatDirection = $this->params->get('subcategory_direction', 'ASC'); $this->subcategories = $model->getSubCategories($this->category->id, $subCatOrdering, $subCatDirection); if (is_array($this->subcategories) && count($this->subcategories) > 0) { foreach ($this->subcategories as $subCategory) { if (isset($subCategory->images->intro_image) && !empty($subCategory->images->intro_image)) { $subCategory->images->intro_image_src = JUri::root(true) . '/' . JUDirectoryFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judirectory/images/category/intro/', true) . $subCategory->images->intro_image; } $subCategory->images->intro_image_width = (int) $this->params->get('subcategory_intro_image_width', 200); $subCategory->images->intro_image_height = (int) $this->params->get('subcategory_intro_image_height', 200); if ($this->params->get('subcategory_show_introtext', 1)) { $subCategoryDescLimit = (int) $this->params->get('subcategory_introtext_character_limit', 500); if ($subCategoryDescLimit > 0) { $subCategory->introtext = JUDirectoryFrontHelperString::truncateHtml($subCategory->introtext, $subCategoryDescLimit); } if ($this->params->get('plugin_support', 0)) { $subCategory->introtext = JHtml::_('content.prepare', $subCategory->introtext, '', 'com_judirectory.category'); } } else { $subCategory->introtext = ''; } } } $this->category->can_submit_listing = JUDirectoryFrontHelperPermission::canSubmitListing($this->category->id); if ($this->category->can_submit_listing && $this->params->get('show_submit_listing_btn_in_category', 1)) { $this->category->submit_listing_link = JUDirectoryFrontHelperListing::getAddListingLink($this->category->id); } $this->items = array(); if ($this->category->show_item) { $user = JFactory::getUser(); $uri = JUri::getInstance(); $this->items = $this->get('Items'); foreach ($this->items as $item) { $item->report_link = JRoute::_(JUDirectoryHelperRoute::getReportListingRoute($item->id)); $item->claim_link = JRoute::_(JUDirectoryHelperRoute::getClaimListingRoute($item->id)); if ($item->checked_out > 0 && $item->checked_out != $user->get('id')) { if (JUDirectoryFrontHelperPermission::canCheckInListing($item->id)) { $item->checkin_link = JRoute::_('index.php?option=com_judirectory&task=forms.checkin&id=' . $item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri))); } } else { $item->edit_link = JRoute::_('index.php?option=com_judirectory&task=form.edit&id=' . $item->id . '&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); if ($item->published == 1) { $item->editstate_link = JRoute::_('index.php?option=com_judirectory&task=forms.unpublish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); } else { $item->editstate_link = JRoute::_('index.php?option=com_judirectory&task=forms.publish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); } } $item->delete_link = JRoute::_('index.php?option=com_judirectory&task=forms.delete&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDirectoryHelperRoute::findItemIdOfListing($item->id)); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $item->event = new stdClass(); $context = 'com_judirectory.listing_list'; $results = $dispatcher->trigger('onContentAfterTitle', array($context, &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($context, &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); } $this->pagination = $this->get('Pagination'); //print_r($this->pagination); } $this->locations = JUDirectoryFrontHelper::getLocations($this->items); //print_r($this->locations); $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
public function validateCriteria($data) { $listingId = $data['listing_id']; $params = JUDirectoryHelper::getParams(null, $listingId); $dataValid = array(); $canRateListing = JUDirectoryFrontHelperPermission::canRateListing($listingId); if ($canRateListing && $params->get('enable_listing_rate_in_comment_form', 1)) { $mainCatId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); $criteriaArray = JUDirectoryFrontHelperCriteria::getCriteriasByCatId($mainCatId); $postCriteria = $data['criteria']; if (count($criteriaArray) > 0) { foreach ($criteriaArray as $key => $criteria) { if ($criteria->required) { if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10) { $criteria->value = $postCriteria[$criteria->id]; } else { echo JText::_('Invalid Field ' . $criteria->title); exit; } } else { if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10) { $criteria->value = $postCriteria[$criteria->id]; } else { unset($criteriaArray[$key]); } } } $dataValid['criteria_array'] = $criteriaArray; } else { if ($params->get('require_listing_rate_in_comment_form', 1)) { if ($data['judir_comment_rating_single'] <= 0 && $data['judir_comment_rating_single'] > 10) { return false; } $dataValid['ratingValue'] = $data['judir_comment_rating_single']; } } } return $dataValid; }
public function filterField($values) { $oldImages = $values ? $values : array(); $app = JFactory::getApplication(); $newImages = $app->input->files->get('field_' . $this->id); $gallery = $gallery['old'] = $gallery['new'] = array(); $params = JUDirectoryHelper::getParams(null, $this->listing_id); $maxUploadImage = 4; $count = 0; if ($this->listing_id) { $db = JFactory::getDbo(); $query = 'SELECT id FROM #__judirectory_images WHERE listing_id = ' . (int) $this->listing_id; $db->setQuery($query); $imageIds = $db->loadColumn(); foreach ($oldImages as $key => $image) { if (!in_array($image['id'], $imageIds)) { continue; } if ($maxUploadImage > 0 && $count >= $maxUploadImage) { break; } $gallery['old'][] = $image; if (!$image['remove']) { $count++; } } } $error = array(); if ($newImages && ($count < $maxUploadImage && $maxUploadImage > 0 || $maxUploadImage <= 0)) { $legal_extensions = "jpeg,jpg,png,gif,bmp"; $legal_mime = "image/jpeg,image/pjpeg,image/png,image/gif,image/bmp,image/x-windows-bmp"; $image_min_width = $params->get("image_min_width", 50); $image_min_height = $params->get("image_min_height", 50); $image_max_width = $params->get("image_max_width", 1024); $image_max_height = $params->get("image_max_height", 1024); $image_max_size = $params->get("image_max_size", 400) * 1024; $num_files_exceed_limit = 0; $num_files_invalid_dimension = 0; foreach ($newImages as $image) { if ($image['name']) { $image['name'] = str_replace(' ', '_', JFile::makeSafe($image['name'])); if ($count >= $maxUploadImage) { $num_files_exceed_limit++; continue; } if (!JUDirectoryFrontHelperPermission::canUpload($image, $error, $legal_extensions, $image_max_size, true, $legal_mime, '', $legal_extensions)) { continue; } $image_dimension = getimagesize($image['tmp_name']); if ($image_dimension[0] < $image_min_width || $image_dimension[1] < $image_min_height || $image_dimension[0] > $image_max_width || $image_dimension[1] > $image_max_height) { $num_files_invalid_dimension++; continue; } $gallery['new'][] = $image; $count++; } } $app = JFactory::getApplication(); if ($error) { foreach ($error as $key => $count) { switch ($key) { case 'WARN_SOURCE': case 'WARN_FILENAME': case 'WARN_FILETYPE': case 'WARN_FILETOOLARGE': case 'WARN_INVALID_IMG': case 'WARN_INVALID_MIME': case 'WARN_IEXSS': $error_str = JText::plural("COM_JUDIRECTORY_N_FILE_" . $key, $count); break; } $app->enqueueMessage($error_str, 'notice'); } } if ($num_files_exceed_limit) { $image_upload_limit = JUDirectoryHelper::formatBytes($image_max_size * 1024); $app->enqueueMessage(JText::plural('COM_JUDIRECTORY_N_IMAGES_ARE_NOT_SAVED_BECAUSE_THEY_EXCEEDED_FILE_SIZE_LIMIT', $num_files_exceed_limit, $image_upload_limit), 'notice'); } if ($num_files_invalid_dimension) { $app->enqueueMessage(JText::plural('COM_JUDIRECTORY_N_IMAGES_ARE_NOT_SAVED_BECAUSE_THEY_ARE_NOT_VALID_DIMENSION', $num_files_invalid_dimension, $image_min_width, $image_max_width, $image_min_height, $image_max_height), 'notice'); } } $gallery['count'] = $count; return $gallery; }