File manager - Edit - /home/jardides/www/Jardi-design/sitetest/components/com_hotspots/models/json.php
Back
<?php /** * @package Hotspots * @author DanielDimitrov <daniel@compojoom.com> * @date 01.07.13 * * @copyright Copyright (C) 2008 - 2013 compojoom.com . All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('_JEXEC') or die('Restricted access'); jimport('joomla.application.component.model'); /** * This doesn't make a lot of sence. * We should use the hotspots model instead of this one.. * TODO: refactor in a future version * * @since 3.0 */ class HotspotsModelJson extends JModelLegacy { private $hotspots = null; private $catid = null; /** * Constructor * */ public function __construct() { parent::__construct(); $this->catid = JFactory::getApplication()->input->getString('cat', 1); } /** * Populate state * * @return void */ protected function populateState() { $app = JFactory::getApplication(); $this->setState('filter.language', $app->getLanguageFilter()); } /** * this function is nearly the same as the one in the Hotspots model * TODO: think of a way to combine the functions and get rid of that model * * @return array with objects */ public function getHotspots() { if (!$this->hotspots) { JPluginHelper::importPlugin('hotspots'); $dispatcher = JDispatcher::getInstance(); $db = JFactory::getDBO(); $offset = JFactory::getApplication()->input->getInt('offset'); $cats = $this->getCats(); $searchWord = JFactory::getApplication()->input->getString('search', null); $query = $db->getQuery(true); $dispatcher->trigger('onBeforeBuildQuery', array(&$this, &$query)); $query->select('SQL_CALC_FOUND_ROWS m.id as hotspots_id, m.*') ->from('#__hotspots_marker as m') ->where(implode(' AND ', $this->buildWhereQuery($cats))) ->order('m.' . HotspotsHelperSettings::get('hotspots_order', 'name ASC')); if ($searchWord) { // Restrict by search term $this->buildWhereSearchQuery($searchWord, $query); } $dispatcher->trigger('onAfterBuildQuery', array(&$this, &$query)); $db->setQuery($query, $offset, HotspotsHelperSettings::get('marker_list_length', 20)); $rows = $db->loadObjectList(); $this->hotspots['hotspots'] = $rows; $db->setQuery('SELECT FOUND_ROWS()'); $this->hotspots['viewCount'] = $db->loadResult(); } return $this->hotspots; } /** * Gets the category ids * * @return array */ private function getCats() { $secure = array(); if ($this->catid) { $cats = explode(';', $this->catid); if (is_array($cats)) { foreach ($cats as $cat) { if (is_numeric($cat) && $cat > 0) { $secure[] = $cat; } } } } else { // There is no category filter set, let's enforce that only published categories are used $catObject = JCategories::getInstance('Hotspots')->get(); $cats = $catObject->getChildren(true); foreach ($cats as $cat) { $secure[] = $cat->id; } } return $secure; } /** * the Where part of the query * * @param null $cats - the category * * @return array */ public function buildWhereQuery($cats = null) { $db = JFactory::getDBO(); $input = JFactory::getApplication()->input; $where = array(); $secure = array(); foreach ($cats as $cat) { $secure[] = $db->quote($cat); } if (count($secure)) { $where[] = ' m.catid IN (' . implode(',', $secure) . ')'; } $level = $input->getInt('level'); $levels = array(0, 1); /** * at small zoomelevels we can end up having 2 datelines * because of this our queries will fail. To go around that * problem we will get all hohtspots in the categories * a nasty trick, but it should work in most situations... */ if (!in_array($level, $levels)) { $ne = $input->getString('ne'); $sw = $input->getString('sw'); list($nelat, $nelng) = explode(',', $ne); list($swlat, $swlng) = explode(',', $sw); /** * We need to take in account the meridian in the Mercator * projection of the map. In the Mercator projection the meridian of the earth * is at the left and right edges. When you slide to the left the * or right, the map will wrap as you move past the meridian * at +/- 180 degrees. In that case, the bounds are partially split * across the left and right edges of the map and the northeast * corner is actually positioned at a poin that is greater than 180 degree. * The gmaps API automatiacally adjusts the longitude values to fit * between -180 and +180 degrees so we ned to request 2 portions of the map * from our database convering the left and right sides. */ if ($nelng > $swlng) { $where[] = ' (m.gmlng > ' . $db->quote($swlng) . ' AND m.gmlng < ' . $db->quote($nelng) . ')'; $where[] = ' (m.gmlat <= ' . $db->quote($nelat) . ' AND m.gmlat >= ' . $db->quote($swlat) . ')'; } else { $where[] = ' (m.gmlng >= ' . $db->quote($swlng) . ' OR m.gmlng <= ' . $db->quote($nelng) . ')'; $where[] = ' (m.gmlat <= ' . $db->quote($nelat) . ' AND m.gmlat >= ' . $db->quote($swlat) . ')'; } } $where[] = ' m.state = 1'; $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSQL()); $where[] = ('(m.publish_up = ' . $nullDate . ' OR m.publish_up <= ' . $nowDate . ')'); $where[] = ('(m.publish_down = ' . $nullDate . ' OR m.publish_down >= ' . $nowDate . ')'); if ($this->getState('filter.language')) { $where[] = 'm.language in (' . $db->quote($input->getString('hs-language')) . ',' . $db->quote('*') . ')'; } $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $where[] = 'm.access IN (' . $groups . ')'; return $where; } /** * The where part of the query for a search * * @param string $sentence - the word we search for * @param object &$q - the query * * @return void */ public function buildWhereSearchQuery($sentence, &$q) { $name = $q->quoteName('m.name'); $description = $q->quoteName('m.description'); $descriptionSmall = $q->quoteName('m.description_small'); $plz = $q->quoteName('m.plz'); $catName = $q->quoteName('c.title'); $street = $q->quoteName('m.street'); $country = $q->quoteName('m.country'); $town = $q->quoteName('m.town'); $and = array(); $cats = $this->getCats(); if (count($cats)) { $q->select('c.title'); $q->leftJoin('#__categories AS c ON c.id = m.catid'); } if (preg_match('/"([^"]+)"/', $sentence, $m)) { /* * example: * 1. "test something" else * will match -> "something else" AND else * 2. test something else * will match -> test OR something OR else */ $searchWord = $q->Quote('%' . $q->escape(trim($m[1]), true) . '%', false); $search[] = $name . ' LIKE ' . $searchWord; $search[] = $description . ' LIKE ' . $searchWord; $search[] = $descriptionSmall . ' LIKE ' . $searchWord; $search[] = $plz . ' LIKE ' . $searchWord; if (count($cats)) { $search[] = $catName . ' LIKE ' . $searchWord; } $search[] = $street . ' LIKE ' . $searchWord; $search[] = $country . ' LIKE ' . $searchWord; $search[] = $town . ' LIKE ' . $searchWord; $word = trim(str_replace('"' . $m[1] . '"', '', $sentence)); if ($word) { $searchWord = $q->Quote('%' . $q->escape(trim($word), true) . '%', false); $and[] = $name . ' LIKE ' . $searchWord; $and[] = $description . ' LIKE ' . $searchWord; $and[] = $descriptionSmall . ' LIKE ' . $searchWord; $and[] = $plz . ' LIKE ' . $searchWord; if (count($cats)) { $and[] = $catName . ' LIKE ' . $searchWord; } $and[] = $street . ' LIKE ' . $searchWord; $and[] = $country . ' LIKE ' . $searchWord; $and[] = $town . ' LIKE ' . $searchWord; } } else { $words = explode(' ', $sentence); foreach ($words as $word) { $searchWord = $q->Quote('%' . $q->escape($word, true) . '%', false); $search[] = $name . ' LIKE ' . $searchWord; $search[] = $description . ' LIKE ' . $searchWord; $search[] = $descriptionSmall . ' LIKE ' . $searchWord; $search[] = $plz . ' LIKE ' . $searchWord; if (count($cats)) { $search[] = $catName . ' LIKE ' . $searchWord; } $search[] = $street . ' LIKE ' . $searchWord; $search[] = $country . ' LIKE ' . $searchWord; $search[] = $town . ' LIKE ' . $searchWord; } } $q->where('(' . implode(' OR ', $search) . ')'); if (count($and)) { $q->where('(' . implode(' OR ', $and) . ')'); } } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings