×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Search Plugin Not working

Search Plugin Not working 11 years 6 months ago #18055

  • Laurent Orluc
  • Laurent Orluc's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 1
  • Thank you received: 0
Well, the search plugin provided with version 3.1.1 of hotspots is not working at all, here is a corrected version of it

It's sad to pay for things that we have to correct ! this is not serious !

This code should be placed in plugins/search/hotspots/hotspots.php

<?php
/* * *************************************************************
* Copyright notice
*
* Copyright 2011 Daniel Dimitrov. ( compojoom.com )
* All rights reserved
*
* This script is part of the Hotspots project. The Hotspots project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* www.gnu.org/copyleft/gpl.html .
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

defined('_JEXEC') or die('Restricted access');

jimport('joomla.plugin.plugin');

function HotSpotAreas() {
return array('hotspots' => 'Territoires');
}

class plgSearchHotspots extends JPlugin {

/**
* Constructor
*
* @access protected
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.5
*/
public function __construct(& $subject, $config) {

parent::__construct($subject, $config);
$this->loadLanguage();
}

// **************************************
// Joomla 1.5
// **************************************

/**
* @return array An array of search areas
*/
function onSearchAreas() {
//return $this->areas();
return HotSpotAreas();
}

function onSearch($text, $phrase='', $ordering='', $areas=null) {
return $this->search($text, $phrase = '', $ordering = '', $areas = null);
}

// **************************************
// Joomla 1.7
// **************************************

/**
* @return array An array of search areas
*/
function onContentSearchAreas() {
return HotSpotAreas();
}

function onContentSearch($text, $phrase='', $ordering='', $areas=null) {
return $this->search($text, $phrase = '', $ordering = '', $areas);
}


// ****************************************
// Search function that do the job
// ****************************************

private function search($text, $phrase='', $ordering='', $areas=null) {
if (!$text) {
return array();
}

if (is_array($areas)) {
if (!array_intersect($areas, array_keys(HotSpotAreas()))) {
return array();
}
}
$db = & JFactory::getDBO();
if ($phrase == 'exact') {
$text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
$where = "(LOWER(m.name) LIKE $text)
OR (LOWER(m.description_small) LIKE $text)" .
" OR (LOWER(m.description) LIKE $text)
OR (LOWER(m.street) LIKE $text)" .
" OR (LOWER(m.plz) LIKE $text)";
} else {
$words = explode(' ', $text);
$wherees = array();
foreach ($words as $word) {
$word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
$wheres[] = "(LOWER(m.name) LIKE $word)
OR (LOWER(m.description_small) LIKE $word)" .
" OR (LOWER(m.description) LIKE $word)
OR (LOWER(m.street) LIKE $word)" .
" OR (LOWER(m.plz) LIKE $word)";
}
if ($phrase == 'all') {
$seperator = "AND";
} else {
$seperator = "OR";
}
$where = '(' . implode(") $seperator (", $wheres) . ')';
}
$where .= ' AND c.published = 1 AND m.published = 1';

switch ($ordering) {
case 'oldest':
$order = 'm.postdate ASC';
break;
case 'alpha':
$order = 'm.name ASC';
break;
case 'newest':
default:
$order = 'm.created DESC';
break;
}
jimport('joomla.html.parameter');
$plugin = & JPluginHelper::getPlugin('search', 'hotspots');
$pluginParams = new JParameter($plugin->params);
$limit = $pluginParams->get('search_limit', 50);

$query = "SELECT m.id, m.name AS title, m.description_small AS text, m.created, m.catid, " .
" 'Territoire' AS section," .
" c.cat_name, " .
" '2' AS browsernav" .
' FROM ' . $db->nameQuote('#__hotspots_marker') . ' AS m' .
' LEFT JOIN ' . $db->nameQuote('#__hotspots_categorie') . ' AS c' .
' ON m.catid = c.id ' .
" WHERE $where" .
" ORDER BY $order";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();

if (is_array($rows)) {
foreach ($rows as $key => $row) {
$urlcat = $row->catid . ':' . JFilterOutput::stringURLSafe($row->cat_name);
$urlid = $row->id . ':' . JFilterOutput::stringURLSafe($row->title);
$itemId = $this->getHotspotsItemid('com_hotspots');
$rows[$key]->href = JRoute::_("index.php?option=com_hotspots&view=hotspot&catid=" . $urlcat . "&id=" . $urlid . '&Itemid=' . $itemId);
}
}

return $rows;
}

/**
*
* @staticvar <int> $ids
* @param <string> $component
* @return <int>
*/
function getHotspotsItemid($component='') {
static $ids;
if (!isset($ids)) {
$ids = array();
}
if (!isset($ids[$component])) {
$database = & JFactory::getDBO();
$query = "SELECT id FROM #__menu"
. "\n WHERE link LIKE '%option=$component%'"
. "\n AND type = 'component'"
. "\n AND published = 1 LIMIT 1";
$database->setQuery($query);
$ids[$component] = $database->loadResult();
}
return $ids[$component];
}

}

Search Plugin Not working 11 years 6 months ago #18056

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Laurent,
I'm sorry about that! I'll fix it in the next update!
Thank you for helping!
Daniel
  • Page:
  • 1
Time to create page: 0.134 seconds