Кракозябры при стандартном поиске джумлы
Убираются путем хака самой джумлы, сам я другой способ не нашел,
в файле search.html.php
строка ~ 176
меняем строку echo $row->title;
на: echo stripslashes(stripslashes(html_entity_decode($row->title)));
Для того чтобы заработал расширенный поиск соби, версия 284:
Редактируем axsearch.class.php (смотрите комменты DAV)
<?php
/**
* @version $Id: axsearch.class.php 3395 2008-01-19 11:53:31Z Radek Suski $
* @package: Sigsiu Online Business Index 2
* ===================================================
* @author
* Name: Sigrid & Radek Suski, Sigsiu.NET
* Email:
sobi@sigsiu.net
* Url:
Для просмотра ссылки Войди или Зарегистрируйся
* ===================================================
* @copyright Copyright (C) 2007 Sigsiu.NET (
Для просмотра ссылки Войди или Зарегистрируйся). All rights reserved.
* @license see
Для просмотра ссылки Войди или Зарегистрируйся GNU/LGPL.
* You can use, redistribute this file and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*/
// no direct access
defined( '_SOBI2_' ) || ( trigger_error("Restricted access", E_USER_ERROR) && exit() );
//dav
function utf8win1251($s){
$out="";$c1="";$byte2=false;
for ($c=0;$c<strlen($s);$c++){
$i=ord($s[$c]);
if ($i<=127) $out.=$s[$c];
if ($byte2){
$new_c2=($c1&3)*64+($i&63);
$new_c1=($c1>>2)&5;
$new_i=$new_c1*256+$new_c2;
if ($new_i==1025) $out_i=168; else
if ($new_i==1105) $out_i=184; else $out_i=$new_i-848;
$out.=chr($out_i);
$byte2=false;
}
if (($i>>5)==6) {$c1=$i;$byte2=true;}
}
return $out;
}
//dav
class sobiAxSearch {
function search()
{
$config =& sobi2Config::getInstance();
$database = $config->getDb();
define("_SOBI_AJAX_SEARCH", true);
//dav header("Content-Type: application/x-javascript; "._ISO);
header("Content-Type: application/x-javascript; charset=windows-1251"); //DAV
$searchString = sobi2Config::request($_REQUEST, "sobi2Search");
$searchString = utf8win1251($searchString); //dav
$searchString = str_replace("%20", " ", $searchString);
//dav $searchString = $config->stringDecode( $searchString );
$searchString = addslashes($searchString);
$phrase = sobi2Config::request($_REQUEST, "searchphrase");
$phrase = utf8win1251($phrase); //dav
$cookieDomain = str_replace("http://", null, $config->getLiveSite());
$searching = false;
$dataForFields = array();
/* gettings the fields for search */
$fields = array();
$query = "SELECT `fieldid` FROM `#__sobi2_fields` " .
"WHERE `in_search`= 2 AND `enabled` = 1 " .
"ORDER BY position";
$database->setQuery($query);
$fieldids = $database->loadObjectList();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
if($fieldids) {
sobi2Config::import("field.class");
foreach($fieldids as $fieldid) {
$fields[] = new sobiField($fieldid->fieldid);
}
}
/* getting input from select boxes */
$break = false;
foreach($fields as $field) {
$getField = sobi2Config::request($_REQUEST, $field->fieldname, null);
$getField = $config->stringDecode( $getField );
$getFieldCookie = $config->getSobiStr( str_replace( "\\", null, $getField ));
$getField = $config->clearSQLinjection($getField);
$getField = utf8win1251($getField); //dav
setcookie("sobi2SearchCookie[{$field->fieldname}]", $getFieldCookie, 0, "/", $cookieDomain);
if(!empty($getField) && $getField != 'all') {
$searching = true;
$dataForFields += array($field->fieldname => $getField);
/* checkbox handling */
if($getField == '-1') {
$getField = 0;
}
if(!isset($sIDs)) {
$sIDs = array();
}
$now = $config->getTimeAndDate();
$ids = ( !empty($sIDs) ) ? implode( " , ", $sIDs ) : null;
if ($ids) {
$idTest = " AND item.itemid IN ({$ids}) ";
}
else {
$idTest = null;
}
$query = "SELECT DISTINCT item.itemid " .
"FROM `#__sobi2_fields` AS sobifields " .
"LEFT JOIN `#__sobi2_fields_data` AS sdata ON sobifields.fieldid = sdata.fieldid " .
"LEFT JOIN `#__sobi2_language` AS snames ON snames.fieldid = sobifields.fieldid " .
"LEFT JOIN `#__sobi2_item` AS item ON sdata.itemid = item.itemid " .
"WHERE (snames.langKey = '{$field->fieldname}' AND sdata.data_txt = '{$getField}') {$idTest}".
" AND item.published = 1 AND (item.publish_down > '{$now}' OR item.publish_down = '{$config->nullDate}' )";
$database->setQuery($query);
$arr = $database->loadResultArray();
if ($database->getErrorNum()) {
trigger_error("axSearchSobi2: DB reports: ".$database->stderr(), E_USER_WARNING);
}
if(is_array($arr) && empty($arr)) {
$sIDs = array();
$break = true;
break;
}
elseif(!empty($sIDs) && is_array($arr)) {
$sIDs = array_intersect($sIDs, $arr);
}
elseif(is_array($arr)) {
$sIDs = $arr;
}
elseif(!is_array($arr) ) {
$sIDs = array();
break;
}
}
}
/* search string handling */
if(!$break && (!empty($searchString) && trim($searchString) != trim(_SOBI2_SEARCH_INPUTBOX) && (!isset($sIDs) || !empty($sIDs)))) {
$searching = true;
$searchString = $config->clearSQLinjection(trim($searchString));
switch ($phrase) {
case 'exact':
$words = $searchString;
$where = null;
$or = null;
if( $config->key( "search", "exact_rlike", true ) ) {
$r = "R";
$wcs = "[[:<:]]";
$wce = "[[:>:]]";
if( $words[0] == "&" ) {
$words = substr( $words, 1 );
}
}
else {
$r = null;
$wcs = "%";
$wce = "%";
}
if( $config->key( "search", "title", true ) ) {
$where .= "LOWER(title) {$r}LIKE '{$wcs}{$words}{$wce}' ";
$or = "OR";
}
if( $config->key( "search", "metakey", true ) ) {
$where .= "{$or} LOWER(metakey) {$r}LIKE '{$wcs}{$words}{$wce}' ";
$or = "OR";
}
if( $config->key( "search", "metadesc", true ) ) {
$where .= "{$or} LOWER(metadesc) {$r}LIKE '{$wcs}{$words}{$wce}' ";
}
break;
case 'all':
case 'any':
/* handling for data from checkbox group or select lists */
$str = $searchString;
$opt = explode( " ", $searchString );
if( count( $opt ) ) {
$options = array();
foreach ( $opt as $o ) {
$options[] = $config->getSobiStr( $o );
}
$opt = implode( "','", $options );
$query = "SELECT GROUP_CONCAT( DISTINCT `langKey` SEPARATOR ' ' ) FROM `#__sobi2_language` WHERE `langValue` IN('{$opt}') AND `sobi2Section` = 'field_opt'";
$database->setQuery( $query );
$opt = $database->loadResult();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
if( $opt ) {
$str .= " ".$opt;
}
}
/* handling for data from checkbox group or select lists */
$words = explode( ' ', $str );
if($phrase == 'all') {
$where = implode("%' AND {=|=} LIKE '%", $words);
$words = implode("%' AND LOWER(sdata.data_txt) LIKE '%", $words);
}
elseif ($phrase == 'any') {
$where = implode("%' OR {=|=} LIKE '%", $words);
$words = implode("%' OR LOWER(sdata.data_txt) LIKE '%", $words);
}
break;
}
if( $phrase == "exact" && $config->key( "search", "exact_rlike", true ) ) {
$words = "LOWER(sdata.data_txt) RLIKE '[[:<:]]{$words}[[:>:]]'";
} else {
$words = "LOWER(sdata.data_txt) LIKE '%{$words}%'";
}
/*
* now get the fields in there we have to looking for
*/
$query = "SELECT sobifields.fieldid " .
"FROM `#__sobi2_fields` AS sobifields " .
"WHERE ((`in_search` = 1 OR `in_search` = 2 ) AND `enabled` = 1)";
$database->setQuery( $query );
$fields = $database->loadResultArray();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
if(is_array($fields) && !empty($fields)) {
$sIDs2 = array();
foreach ($fields as $field) {
$query = "SELECT DISTINCT `itemid` " .
"FROM `#__sobi2_fields` AS sfield " .
"LEFT JOIN `#__sobi2_fields_data` AS sdata ON sfield.fieldid = sdata.fieldid " .
"WHERE (sfield.fieldid = '{$field}' AND ( {$words} ) )";
$database->setQuery($query);
$arr = $database->loadResultArray();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
if(!empty($arr)) {
$sIDs2 = array_merge($sIDs2, $arr);
}
}
}
/* looking in the items table self */
if($phrase != 'exact') {
$title = str_replace("{=|=}", "LOWER(title)", $where);
$metakey = str_replace("{=|=}", "LOWER(metakey)", $where);
$metadesc = str_replace("{=|=}", "LOWER(metadesc)", $where);
$title = $config->key( "search", "title", true ) ? "LOWER(title) LIKE '%{$title}%' OR" : null;
$metakey = $config->key( "search", "metakey", true ) ? "LOWER(metakey) LIKE '%{$metakey}%' OR " : null;
$metadesc = $config->key( "search", "metadesc", true )? "LOWER(metadesc) LIKE '%{$metadesc}%' " : null;
$query = "SELECT DISTINCT `itemid` FROM `#__sobi2_item` WHERE ( {$title} {$metakey} {$metadesc} )";
}
else {
$query = "SELECT DISTINCT `itemid` FROM `#__sobi2_item` WHERE ({$where})";
}
$database->setQuery($query);
$arr = $database->loadResultArray();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
if(!empty($arr)) {
$sIDs2 = array_merge($sIDs2, $arr);
}
}
/* here we have all ids from select boxes and all ids from string search */
/* no both results */
if(isset($sIDs) && isset($sIDs2)) {
$sIDs = array_intersect($sIDs, $sIDs2);
}
else {
/* didn't search in select boxes */
if(!isset($sIDs) && isset($sIDs2)) {
$sIDs = $sIDs2;
}
else if(!isset($sIDs)) {
$sIDs = array();
}
}
if(!isset($sIDs) || empty($sIDs)) {
$sIDs = array();
}
$sIDs = array_unique($sIDs);
/* searching in categories */
$cid = (int) sobi2Config::request($_REQUEST, "sobiCid", 0);
setcookie("sobi2SearchCookie[cid]", $cid, 0, "/", $cookieDomain);
if(!empty($sIDs) || !$searching) {
if($cid && $cid !=0) {
if(!is_array($sIDs) || empty($sIDs)) {
$itids = null;
}
else {
$ids = implode(" , ", $sIDs);
$itids = "AND itemid IN ({$ids})";
}
$cids = array();
$config->getChildCats($cid, $cids);
$cids = implode(" , ", $cids);
$query = "SELECT itemid FROM #__sobi2_cat_items_relations WHERE catid IN({$cids}) {$itids} ;";
$database->setQuery($query);
$sIDs = $database->loadResultArray();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
}
}
/* getting plugins modifications */
$pluginsOutput = null;
if(!empty($config->S2_plugins)) {
foreach ($config->S2_plugins as $plugin) {
if(method_exists($plugin,"onAjaxSearchResult")) {
$plugin->onAjaxSearchResult($sIDs, $dataForFields, $pluginsOutput);
}
}
}
$total = count( $sIDs );
if( $total ) {
$whereId = implode(" , ", $sIDs);
$now = $config->getTimeAndDate();
$query = "SELECT COUNT(itemid) FROM `#__sobi2_item` " .
"WHERE ( itemid IN ({$whereId}) AND `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}' ) ) ";
$database->setQuery($query);
if($database->loadResult()) {
$total = $database->loadResult();
}
else {
$total = 0;
}
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
}
$items = array();
$page = 0;
$pages = 0;
if($total) {
/*
* now we have all id's from items contains search strings
*/
$limit = $config->itemsInLine * $config->lineOnSite;
$pages = ceil($total/$limit);
$limitstart = (int) sobi2Config::request($_REQUEST, "SobiSearchPage", 0);
setcookie("sobi2SearchCookie[SobiSearchPage]", $limitstart, 0, "/", $cookieDomain);
if($limitstart == -1) {
$limitstart = $pages - 1;
}
$page = $limitstart;
$limitstart *= $limit;
$limit = $config->itemsInLine * $config->lineOnSite;
$limits = " LIMIT {$limitstart}, {$limit} ";
$config->listingOrdering = str_replace("relation.",null,$config->listingOrdering);
$query = "SELECT itemid, title, owner, image, background, icon, metadesc, publish_up FROM `#__sobi2_item` AS items " .
"WHERE ( items.itemid IN ({$whereId}) AND `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}' ) ) ORDER BY {$config->listingOrdering} {$limits}";
$database->setQuery($query);
$items = $database->loadObjectList();
if ( $database->getErrorNum() ) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
if(!count($items) && $total) {
$query = "SELECT itemid, title, owner, image, background, icon, metadesc, publish_up FROM `#__sobi2_item` AS items " .
"WHERE ( items.itemid IN ({$whereId}) AND `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}' ) ) ORDER BY {$config->listingOrdering} LIMIT 0, {$limit}";
$database->setQuery($query);
$items = $database->loadObjectList();
if ($database->getErrorNum()) {
trigger_error("DB reports: ".$database->stderr(), E_USER_WARNING);
}
}
}
$searchString = str_replace("\\", null, $searchString);
if($total) {
defined( '_PN_LT' ) || define('_PN_LT','<');
defined( '_PN_RT' ) || define('_PN_RT','>');
defined( '_PN_START' ) || define('_PN_START','Start');
defined( '_PN_PREVIOUS' ) || define('_PN_PREVIOUS','Previous');
defined( '_PN_NEXT' ) || define('_PN_NEXT','Next');
defined( '_PN_END' ) || define('_PN_END','End');
}
$searchString = $config->getSobiStr( $searchString );
setcookie("sobi2SearchCookie[sobi2Search]", $searchString, 0, "/", $cookieDomain);
setcookie("sobi2SearchCookie[searchphrase]", $phrase, 0, "/", $cookieDomain);
$config->set( "searchResults", $items );
HTML_SOBI::axSearchResults($searchString, $items, $total, $pluginsOutput, $pages, $page);
}
function searchSobi( $catid = 0 )
{
$config =& sobi2Config::getInstance();
$mainframe =& $config->getMainframe();
$database =& $config->getDb();
$sobi2Frontend =& $config->getFrontend();
$autoSearch = false;
$cid = sobi2Config::request($_REQUEST, "sobiCid", -9);
$reset = sobi2Config::request($_REQUEST, "reset", 0 );
if( !$reset ) {
$cookieValues = sobi2Config::request($_COOKIE, "sobi2SearchCookie", null);
if($cookieValues) {
foreach ($cookieValues as $k => $v) {
$cookieValues[$k] = $v;
}
}
}
$selectedCats = array();
if($cid < 0 && is_array($cookieValues) && key_exists("cid", $cookieValues) && !empty($cookieValues["cid"])) {
$cid = (int) $cookieValues["cid"];
}
if( $cid > 0 ) {
$config->getParentCats($cid, $selectedCats);
$selectedCats = array_reverse($selectedCats);
}
$cid = ($cid > 0) ? $cid : 0;
$autoSearch = $cid ? true : $autoSearch;
array_unshift($selectedCats, 1);
$page = (int) sobi2Config::request($_REQUEST, "SobiSearchPage", -9);
if($page < 0 && is_array($cookieValues) && key_exists("SobiSearchPage", $cookieValues) && !empty($cookieValues["SobiSearchPage"])) {
$page = (int) $cookieValues["SobiSearchPage"];
}
else {
$page = 0;
}
$searchString = sobi2Config::request($_REQUEST, "sobi2Search", null);
$searchString = utf8win1251($searchString); //dav
$searchString = str_replace("%20", " ", $searchString);
$phrase = sobi2Config::request($_REQUEST, 'searchphrase', null);