public static function loadLanguageForTopLevelCat() { $app = JFactory::getApplication(); $view = $app->input->getString('view', ''); $id = $app->input->getInt('id', 0); if (isset($view)) { switch ($view) { case 'category': $topLevelCats = JUDirectoryHelper::getCatsByLevel(1, $id); break; case 'listing': $catId = JUDirectoryFrontHelperCategory::getMainCategoryId($id); $topLevelCats = JUDirectoryHelper::getCatsByLevel(1, $catId); break; } if (!empty($topLevelCats)) { $topLevelCat = $topLevelCats[0]; if ($view == 'category' || $view == 'listing') { JUDirectoryFrontHelperLanguage::loadLanguageFile('com_judirectory_' . $topLevelCat->id, JPATH_SITE); } } } return; }
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 delete($pk = null) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judirectory/tables'); $k = $this->_tbl_key; $pk = is_null($pk) ? $this->{$k} : $pk; $db = JFactory::getDbo(); $query = "DELETE FROM #__judirectory_subscriptions WHERE item_id = {$pk} AND type = 'listing'"; $db->setQuery($query); $db->execute(); $query = "SELECT * FROM #__judirectory_comments WHERE listing_id = " . $pk; $db->setQuery($query); $commentIds = $db->loadColumn(); if ($commentIds) { $commentTable = JTable::getInstance("Comment", "JUDirectoryTable"); foreach ($commentIds as $commentId) { $commentTable->delete($commentId); } } $query = "SELECT id FROM #__judirectory_rating WHERE listing_id = {$pk}"; $db->setQuery($query); $ratingItemIds = $db->loadColumn(); if ($ratingItemIds) { $ratingTable = JTable::getInstance("Rating", "JUDirectoryTable"); foreach ($ratingItemIds as $ratingItemId) { $ratingTable->delete($ratingItemId); } } $query = "DELETE FROM #__judirectory_reports WHERE item_id = {$pk} AND type = 'listing'"; $db->setQuery($query); $db->execute(); $query = "SELECT id FROM #__judirectory_collections_items WHERE listing_id = {$pk}"; $db->setQuery($query); $collectionItemIds = $db->loadColumn(); if ($collectionItemIds) { $collectionItemTable = JTable::getInstance("CollectionItem", "JUDirectoryTable"); foreach ($collectionItemIds as $collectionItemId) { $collectionItemTable->delete($collectionItemId); } } JUDirectoryHelper::deleteLogs('listing', $pk); $query = "DELETE FROM #__judirectory_mailqs\n\t\t\t WHERE item_id =" . $pk . "\n\t\t\t\t\t\tAND email_id IN (SELECT id FROM #__judirectory_emails WHERE (`event` LIKE 'listing.%' AND `event` != 'listing.delete'))"; $db->setQuery($query); $db->execute(); $query = $db->getQuery(true); $query->select('id'); $query->from('#__judirectory_listings'); $query->where('approved=' . -$pk); $db->setQuery($query); $tempListingIds = $db->loadColumn(); if (count($tempListingIds)) { foreach ($tempListingIds as $tempListingId) { $this->deleteMainData($tempListingId, true); } } $cat_id = JUDirectoryFrontHelperCategory::getMainCategoryId($this->id); $this->deleteMainData($pk); if (parent::delete($pk)) { $app = JFactory::getApplication(); if ($app->isSite()) { $registry = new JRegistry(); $registry->loadObject($this); $mailData = $registry->toArray(); $mailData['cat_id'] = $cat_id; if ($this->approved < 1) { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.reject', $this->id, $mailData); } else { JUDirectoryFrontHelperMail::sendEmailByEvent('listing.delete', $this->id, $mailData); } } return true; } else { return false; } }
public static function getTemplateStyleOfListing($listingId) { $storeId = md5(__METHOD__ . "::" . (int) $listingId); if (!isset(self::$cache[$storeId])) { $listingObject = JUDirectoryHelper::getListingById($listingId); $styleId = $listingObject->style_id; if ($styleId == -2) { $templateStyleObject = self::getDefaultTemplateStyle(); } elseif ($styleId == -1) { $mainCategoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); $templateStyleObject = self::getTemplateStyleOfCategory($mainCategoryId); } else { $templateStyleObject = self::getTemplateStyleObject($styleId); } if (is_object($templateStyleObject)) { self::$cache[$storeId] = $templateStyleObject; } else { self::$cache[$storeId] = self::getDefaultTemplateStyle(); } } return self::$cache[$storeId]; }
public static function getListingLayout($listingId) { $storeId = md5(__METHOD__ . "::" . $listingId); if (!isset(self::$cache[$storeId])) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('layout'); $query->from('#__judirectory_listings'); $query->where('id =' . $listingId); $db->setQuery($query); $layout = $db->loadResult(); if ($layout == -2) { $params = JUDirectoryHelper::getParams(null, $listingId); $layout = $params->get('layout_listing', '_:default'); } elseif ($layout == -1) { $parentId = (int) JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); if ($parentId == 0) { $params = JUDirectoryHelper::getParams(null, $listingId); $layout = $params->get('layout_listing', '_:default'); } else { $layout = JUDirectoryFrontHelperListing::getListingLayoutFromCategory($parentId); } } else { $layout = trim($layout); } self::$cache[$storeId] = $layout; } return self::$cache[$storeId]; }
protected function _setBreadcrumb() { $categoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($this->item->id); $app = JFactory::getApplication(); $pathway = $app->getPathway(); $pathwayArray = array(); if ($categoryId) { $pathwayArray = JUDirectoryFrontHelperBreadcrumb::getBreadcrumbCategory($categoryId); } else { $pathwayArray[] = JUDirectoryFrontHelperBreadcrumb::getRootPathway(); } $linkListing = JRoute::_(JUDirectoryHelperRoute::getListingRoute($this->item->id)); $pathwayArray[] = JUDirectoryFrontHelperBreadcrumb::createPathwayItem($this->item->title, $linkListing); if ($this->_layout == 'print') { $pathwayArray[] = JUDirectoryFrontHelperBreadcrumb::createPathwayItem('PRINT'); $document = JFactory::getDocument(); $document->setMetaData('robots', 'noindex, nofollow'); } $pathway->setPathway($pathwayArray); }
public function importData($importData, $config = array(), $start = 0) { if (empty($importData)) { return false; } $app = JFactory::getApplication(); $dataCSV = $app->getUserState('csv.dataCSV'); $indexRow = $start + 1; foreach ($importData as $index => $data) { $indexRow++; if (is_object($data)) { $data = get_object_vars($data); } $importType = $this->getImportType($data, $config); if ($importType == 0) { $this->addLog($indexRow, $importType, JText::_('COM_JUDIRECTORY_CSV_PROCESS_SKIP_LISTING_MESSAGE')); $dataCSV['total_skip']++; continue; } $titleFieldId = JUDirectoryFrontHelperField::getField('title')->id; if (!$data['id'] && (!isset($data[$titleFieldId]) || !$data[$titleFieldId])) { $this->addLog($index, $importType, JText::_('COM_JUDIRECTORY_CSV_PROCESS_EMPTY_ID_AND_TITLE'), 'Error'); $dataCSV['total_error']++; continue; } $categoryFieldId = JUDirectoryFrontHelperField::getField('cat_id')->id; if (isset($data[$categoryFieldId]) && $data[$categoryFieldId]) { $data['main_cat'] = explode(",", $data[$categoryFieldId])[0]; } else { if ($data['id']) { $data['main_cat'] = JUDirectoryFrontHelperCategory::getMainCategoryId($data['id']); } else { $data['main_cat'] = $config['default_main_cat_id']; } } if (!$data['main_cat']) { $this->addLog($index, $importType, JText::_('COM_JUDIRECTORY_CSV_PROCESS_EMPTY_CAT'), 'Error'); continue; } $data = $this->prepareDataToImport($data, $importType, $config); if (JUDirectoryHelper::hasCSVPlugin()) { $JUDirectoryCsv = new JUDirectoryCSV($this); if ($JUDirectoryCsv->insertUpdateListing($data, $indexRow, $importType)) { if ($importType == 1) { $dataCSV['total_insert']++; } else { $dataCSV['total_update']++; } } else { $dataCSV['total_error']++; } } } $app->setUserState('csv.dataCSV', $dataCSV); $this->writeToLogFile(); }
public static function getFeed($feedListings, &$document) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $params = JUDirectoryHelper::getParams(); $image = $params->get('rss_thumbnail_source', 'image'); $feedEmail = $params->get('rss_email', 'none'); $siteEmail = $app->get('mailfrom'); foreach ($feedListings as $listing) { $title = $listing->title; $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); $categoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($listing->id); $category = JUDirectoryFrontHelperCategory::getCategory($categoryId); $feedItem = new JFeedItem(); $feedItem->title = $title; $feedItem->link = JRoute::_(JUDirectoryHelperRoute::getListingRoute($listing->id)); if ($feedEmail != 'none') { $user = JFactory::getUser($listing->created_by); $feedItem->author = $listing->created_by_alias ? $listing->created_by_alias : $user->name; if ($feedEmail == 'site') { $feedItem->authorEmail = $siteEmail; } elseif ($feedEmail === 'author') { $feedItem->authorEmail = $listing->email ? $listing->email : $user->email; } } $feedItem->category = $category->title; @($date = $listing->publish_up ? date('r', strtotime($listing->publish_up)) : ''); $feedItem->date = $date; $feedItem->description = ""; if ($params->get('rss_show_thumbnail', 1)) { if ($image == 'image' && $listing->image) { $imageUrl = JUDirectoryHelper::getListingImage($listing->image); } else { $query = "SELECT file_name FROM #__judirectory_images WHERE listing_id = " . $listing->id . " ORDER BY ordering ASC LIMIT 1"; $db->setQuery($query); $firstImage = $db->loadResult(); $imageUrl = JUri::root() . JUDirectoryFrontHelper::getDirectory("listing_small_image_directory", "media/com_judirectory/images/gallery/small/", true) . $firstImage; } $feedItem->description = "<img src='" . $imageUrl . "' align=\"" . $params->get('rss_thumbnail_alignment', 'left') . "\" />"; } $feedItem->description .= $listing->introtext; $document->addItem($feedItem); } }
public function PHPValidate($values) { $rootCat = JUDirectoryFrontHelperCategory::getRootCategory(); // 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); } $mainCatId = $values['main']; $secondaryCatIds = array_filter(explode(",", $values['secondary'])); if (!$mainCatId) { return JText::_("COM_JUDIRECTORY_PLEASE_SELECT_A_CATEGORY"); } if ($mainCatId == $rootCat->id && !$params->get('allow_add_listing_to_root', 0)) { return JText::_("COM_JUDIRECTORY_CAN_NOT_ADD_LISTING_TO_ROOT_CATEGORY"); } if (!JUDirectoryHelper::getCategoryById($mainCatId)) { return JText::_("COM_JUDIRECTORY_INVALID_CATEGORY"); } if ($params->get('max_cats_per_listing', 0) && count($secondaryCatIds) + 1 > $params->get('max_cats_per_listing', 0)) { return JText::sprintf("COM_JUDIRECTORY_NUMBER_OF_CATEGORY_OVER_MAX_N_CATEGORIES", $params->get('max_cats_per_listing', 0)); } if (!$this->listing_id) { // If has not permission to submit in this main category if (!JUDirectoryFrontHelperPermission::canSubmitListing($mainCatId)) { $category = JUDirectoryHelper::getCategoryById($mainCatId); return JText::sprintf("COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_SUBMIT_LISTING_TO_THIS_CATEGORY", $category->title); } } else { $mainCatIdDB = JUDirectoryFrontHelperCategory::getMainCategoryId($this->listing_id); // Change category -> check submit permission in new cat if ($mainCatId != $mainCatIdDB) { // If has not permission to submit in this main category if (!JUDirectoryFrontHelperPermission::canSubmitListing($mainCatId)) { $category = JUDirectoryHelper::getCategoryById($mainCatId); return JText::sprintf("COM_JUDIRECTORY_YOU_ARE_NOT_AUTHORIZED_TO_SUBMIT_LISTING_TO_THIS_CATEGORY", $category->title); } } $app = JFactory::getApplication(); // Front-end if ($app->isSite()) { // Can not change main cat when edit listing if ($mainCatId != $mainCatIdDB) { if (!$params->get('can_change_main_category', 1)) { return false; } } // Can not change secondary cats when edit listing if (!$params->get('can_change_secondary_categories', 1)) { $secondaryCatIdsDB = $this->getSecondaryCategoryIds($this->listing_id); if (count($secondaryCatIds) && count($secondaryCatIdsDB)) { if (array_diff($secondaryCatIds, $secondaryCatIdsDB) || array_diff($secondaryCatIdsDB, $secondaryCatIds)) { return false; } } } } } return true; }
public static function findItemIdOfListing($id) { $catId = JUDirectoryFrontHelperCategory::getMainCategoryId($id); return self::findItemIdOfCategory($catId); }
public static function canAutoApprovalListingWhenEdit($listingId, $newMainCategoryId) { $listingObject = JUDirectoryHelper::getListingById($listingId); if ($listingObject->approved == 1) { $originalListingId = $listingObject->id; $originalListingObject = $listingObject; $mainCategoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($originalListingObject->id); $params = JUDirectoryHelper::getParams($newMainCategoryId); } elseif ($listingObject->approved < 0) { $tempListingObject = $listingObject; $originalListingId = abs($listingObject->approved); $originalListingObject = JUDirectoryHelper::getListingById($originalListingId); $mainCategoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($originalListingObject->id); $params = JUDirectoryHelper::getParams($newMainCategoryId); } else { return false; } $isListingOwner = JUDirectoryFrontHelperPermission::isListingOwner($originalListingObject->id); $autoApprovalForListingOwner = $params->get('listing_owner_can_edit_listing_auto_approval', 1); if ($isListingOwner && $autoApprovalForListingOwner) { return true; } $user = JFactory::getUser(); if ($mainCategoryId == $newMainCategoryId) { if ($user->authorise('judir.listing.edit.auto_approval', 'com_judirectory.category.' . $mainCategoryId)) { return true; } } else { if ($user->authorise('judir.listing.create.auto_approval', 'com_judirectory.category.' . $newMainCategoryId)) { return true; } } if (!$user->get('guest')) { $autoApprovalListingThreshold = (int) $params->get('auto_approval_listing_threshold', 0); if ($autoApprovalListingThreshold > 0) { $totalApprovedListingsOfUser = JUDirectoryFrontHelperListing::getTotalListingsOfUserApprovedByMod($user->id); if ($totalApprovedListingsOfUser >= $autoApprovalListingThreshold) { return true; } } } return false; }
public static function getCurrentCatId() { $app = JFactory::getApplication(); $option = $app->input->getString('option', ''); $view = $app->input->getString('view', ''); $catId = JUDirectoryFrontHelperCategory::getRootCategory()->id; if ($option == 'com_judirectory' && $view) { if ($view == 'listing') { $listingId = $app->input->getInt('id', 0); if ($listingId > 0) { $catId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); } } elseif ($view == 'category' || $view == 'categories') { $catId = $app->input->getInt('id', 0); } } return $catId; }
public function validateFields($fieldsData, $listingId) { $app = JFactory::getApplication(); $params = JUDirectoryHelper::getParams(); $db = JFactory::getDbo(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $error = false; $isNew = $listingId == 0 ? true : false; $categoriesField = JUDirectoryFrontHelperField::getField('cat_id', $listingId); if ($this->getListingSubmitType($listingId) == 'submit' && $categoriesField->canSubmit() || $this->getListingSubmitType($listingId) == 'edit' && $categoriesField->canEdit()) { $fieldValueCategories = $fieldsData[$categoriesField->id]; $categoriesField->is_new = $isNew; $categoriesField->fields_data = $fieldsData; $fieldValueCategories = $categoriesField->filterField($fieldValueCategories); $valid = $categoriesField->PHPValidate($fieldValueCategories); if ($valid === true) { $fieldsData[$categoriesField->id] = $fieldValueCategories; $catId = $fieldsData[$categoriesField->id]['main']; } else { $this->setError($valid); if ($isNew) { return false; } $catId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); $error = true; unset($fieldsData[$categoriesField->id]); } } else { $catId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); } $form = $this->getFormDefault(); $xml_field_name_publishing = array(); $elementsInPublishing = $form->xpath('//fieldset[@name="publishing"]/field | //field[@fieldset="publishing"]'); foreach ($elementsInPublishing as $elementsInPublishingKey => $elementsInPublishingVal) { $elementInPublishing = $elementsInPublishingVal->attributes(); $xml_field_name_publishing[] = (string) $elementInPublishing['name']; } $query = $db->getQuery(true); $query->select("field.*"); $query->from("#__judirectory_fields AS field"); $query->select("plg.folder"); $query->join("", "#__judirectory_plugins AS plg ON field.plugin_id = plg.id"); $query->join("", "#__judirectory_fields_groups AS field_group ON field_group.id = field.group_id"); $query->join("", "#__judirectory_categories AS c ON (c.fieldgroup_id = field.group_id OR field.group_id = 1 )"); $query->where("field_group.published = 1"); $query->where("field.published = 1"); $query->where('field.publish_up <= ' . $db->quote($nowDate)); $query->where('(field.publish_down = ' . $db->quote($nullDate) . ' OR field.publish_down >= ' . $db->quote($nowDate) . ')'); $query->where("(c.id = " . $catId . " OR field.group_id = 1)"); $query->where("field.field_name != 'cat_id'"); if ($app->isSite() && !$params->get('submit_form_show_tab_publishing', 0)) { if (!empty($xml_field_name_publishing)) { $query->where('field.field_name NOT IN (' . implode(',', $db->quote($xml_field_name_publishing)) . ')'); } } $query->group('field.id'); if (!JUDIRPROVERSION) { $query->where("field.field_name != 'locations'"); $query->where("field.field_name != 'addresses'"); } $db->setQuery($query); $fields = $db->loadObjectList(); foreach ($fields as $field) { $fieldObj = JUDirectoryFrontHelperField::getField($field, $listingId); if ($this->getListingSubmitType($listingId) == 'submit' && $fieldObj->canSubmit() || $this->getListingSubmitType($listingId) == 'edit' && $fieldObj->canEdit()) { $fieldValue = isset($fieldsData[$field->id]) ? $fieldsData[$field->id] : null; $fieldObj->is_new = $isNew; $fieldObj->fields_data = $fieldsData; $fieldValue = $fieldObj->filterField($fieldValue); $valid = $fieldObj->PHPValidate($fieldValue); if ($valid === true) { $fieldsData[$field->id] = $fieldValue; } else { $error = true; unset($fieldsData[$field->id]); $this->setError($valid); } } } if ($error) { return false; } else { return $fieldsData; } }
public function setSessionCommentForm($listingId) { $session = JFactory::getSession(); $app = JFactory::getApplication(); $criteriaRatingValues = array('judir-comment-rating-single' => $app->input->getFloat('judir_comment_rating_single', 0)); $mainCatId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); $criteriaArray = JUDirectoryFrontHelperCriteria::getCriteriasByCatId($mainCatId); if (count($criteriaArray)) { foreach ($criteriaArray as $value) { $criteriaRatingValues[$value->id] = $app->input->getString('criteria-' . $value->id, ''); } } $commentForm = array(); $commentForm['rating'] = $criteriaRatingValues; $commentForm['title'] = $app->input->getString('title', ''); $commentForm['guest_name'] = $app->input->getString('guest_name', ''); $commentForm['guest_email'] = $app->input->getString('guest_email', ''); $commentForm['comment'] = $app->input->getString('comment', ''); $commentForm['parent_id'] = $app->input->getInt('parent_id', ''); $commentForm['comment_language'] = $app->input->getString('comment_language', '*'); if ($app->input->getString('website', '')) { $commentForm['website'] = $app->input->getString('website', ''); } $session->set('judirectory_commentform_' . $listingId, $commentForm); }
public function delete() { JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN')); $cid = JFactory::getApplication()->input->get('id', array(), 'array'); if (!is_array($cid) || count($cid) < 1) { JError::raiseWarning(500, JText::_('COM_JUDIRECTORY_NO_ITEM_SELECTED')); $this->setRedirect($this->getReturnPage()); } else { $model = $this->getModel(); jimport('joomla.utilities.arrayhelper'); JArrayHelper::toInteger($cid); if ($model->delete($cid)) { $this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid))); } else { $this->setMessage($model->getError()); } $isListingPublished = JUDirectoryFrontHelperListing::isListingPublished($cid[0]); if ($isListingPublished) { $mainCategoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($cid[0]); $this->setRedirect(JRoute::_(JUDirectoryHelperRoute::getCategoryRoute($mainCategoryId), false)); } else { $this->setRedirect($this->getReturnPage()); } } }