| 1 | <?php |
|---|
| 2 | // ------------------------------------------------------------------------ // |
|---|
| 3 | // XOOPS - PHP Content Management System // |
|---|
| 4 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 5 | // <http://www.xoops.org/> // |
|---|
| 6 | // ------------------------------------------------------------------------ // |
|---|
| 7 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 8 | // it under the terms of the GNU General Public License as published by // |
|---|
| 9 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 10 | // (at your option) any later version. // |
|---|
| 11 | // // |
|---|
| 12 | // You may not change or alter any portion of this comment or credits // |
|---|
| 13 | // of supporting developers from this source code or any supporting // |
|---|
| 14 | // source code which is considered copyrighted (c) material of the // |
|---|
| 15 | // original comment or credit authors. // |
|---|
| 16 | // // |
|---|
| 17 | // This program is distributed in the hope that it will be useful, // |
|---|
| 18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 20 | // GNU General Public License for more details. // |
|---|
| 21 | // // |
|---|
| 22 | // You should have received a copy of the GNU General Public License // |
|---|
| 23 | // along with this program; if not, write to the Free Software // |
|---|
| 24 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 25 | // ------------------------------------------------------------------------- // |
|---|
| 26 | // Author: Tobias Liegl (AKA CHAPI) // |
|---|
| 27 | // Site: http://www.chapi.de // |
|---|
| 28 | // Project: The XOOPS Project // |
|---|
| 29 | // ------------------------------------------------------------------------- // |
|---|
| 30 | // Hacker: GIJ=CHECKMATE (AKA GIJOE) // |
|---|
| 31 | // Site: http://www.peak.ne.jp/xoops/ // |
|---|
| 32 | // ------------------------------------------------------------------------- // |
|---|
| 33 | |
|---|
| 34 | if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ; |
|---|
| 35 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; |
|---|
| 36 | if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ; |
|---|
| 37 | $mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ; |
|---|
| 38 | |
|---|
| 39 | include_once( XOOPS_ROOT_PATH . "/modules/$mydirname/include/constants.inc.php" ) ; |
|---|
| 40 | |
|---|
| 41 | if( ! class_exists( 'TinyDTextSanitizer' ) ) { |
|---|
| 42 | include_once( XOOPS_ROOT_PATH . "/modules/$mydirname/class/tinyd.textsanitizer.php" ) ; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | eval( ' |
|---|
| 47 | |
|---|
| 48 | function tinycontent'.$mydirnumber.'_search( $keywords , $andor , $limit , $offset , $userid ) |
|---|
| 49 | { |
|---|
| 50 | return tinyd_search_base( "'.$mydirname.'" , "'.$mydirnumber.'" , $keywords , $andor , $limit , $offset , $userid ) ; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | ' ) ; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | if( ! function_exists( 'tinyd_search_base' ) ) { |
|---|
| 57 | |
|---|
| 58 | function tinyd_search_base( $mydirname , $mydirnumber , $keywords , $andor , $limit , $offset , $userid ) |
|---|
| 59 | { |
|---|
| 60 | // get my config |
|---|
| 61 | $module_handler =& xoops_gethandler('module'); |
|---|
| 62 | $config_handler =& xoops_gethandler('config'); |
|---|
| 63 | $module =& $module_handler->getByDirname($mydirname); |
|---|
| 64 | $config =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
|---|
| 65 | |
|---|
| 66 | $myts =& TinyDTextSanitizer::getInstance() ; |
|---|
| 67 | $db =& Database::getInstance() ; |
|---|
| 68 | |
|---|
| 69 | // XOOPS Search module |
|---|
| 70 | $showcontext = empty( $_GET['showcontext'] ) ? 0 : 1 ; |
|---|
| 71 | $select4con = $showcontext ? "text" : "'' AS text" ; |
|---|
| 72 | |
|---|
| 73 | $sql = "SELECT storyid,title,link,UNIX_TIMESTAMP(last_modified),$select4con FROM ".$db->prefix( "tinycontent$mydirnumber" )." WHERE visible AND ! (nohtml & 8) " ; |
|---|
| 74 | |
|---|
| 75 | if( ! empty( $userid ) ) { |
|---|
| 76 | $sql .= " AND 0 "; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | $whr = "" ; |
|---|
| 80 | if( is_array( $keywords ) && count( $keywords ) > 0 ) { |
|---|
| 81 | $whr = "AND (" ; |
|---|
| 82 | switch( strtolower( $andor ) ) { |
|---|
| 83 | case "and" : |
|---|
| 84 | foreach( $keywords as $keyword ) { |
|---|
| 85 | $whr .= "CONCAT(title,' ',text) LIKE '%$keyword%' AND " ; |
|---|
| 86 | } |
|---|
| 87 | $whr = substr( $whr , 0 , -5 ) ; |
|---|
| 88 | break ; |
|---|
| 89 | case "or" : |
|---|
| 90 | foreach( $keywords as $keyword ) { |
|---|
| 91 | $whr .= "CONCAT(title,' ',text) LIKE '%$keyword%' OR " ; |
|---|
| 92 | } |
|---|
| 93 | $whr = substr( $whr , 0 , -4 ) ; |
|---|
| 94 | break ; |
|---|
| 95 | default : |
|---|
| 96 | $whr .= "CONCAT(title,' ',text) LIKE '%{$keywords[0]}%'" ; |
|---|
| 97 | break ; |
|---|
| 98 | } |
|---|
| 99 | $whr .= ")" ; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | $sql = "$sql $whr ORDER BY storyid ASC" ; |
|---|
| 103 | $result = $db->query( $sql , $limit , $offset ) ; |
|---|
| 104 | $ret = array() ; |
|---|
| 105 | $context = '' ; |
|---|
| 106 | while( list( $id , $title , $link , $timestamp , $text ) = $db->fetchRow( $result ) ) { |
|---|
| 107 | |
|---|
| 108 | // get context for module "search" |
|---|
| 109 | if( function_exists( 'search_make_context' ) && $showcontext ) { |
|---|
| 110 | $full_context = strip_tags( $myts->displayTarea( $text , 1 , 1 , 1 , 1 , 1 ) ) ; |
|---|
| 111 | if( function_exists( 'easiestml' ) ) $full_context = easiestml( $full_context ) ; |
|---|
| 112 | $context = search_make_context( $full_context , $keywords ) ; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | if( ! empty( $config['tc_force_mod_rewrite'] ) ) { |
|---|
| 116 | if( ! empty( $config['tc_modulesless_dir'] ) ) { |
|---|
| 117 | $href = '../../' . $config['tc_modulesless_dir'] . '/' . sprintf( TC_REWRITE_FILENAME_FMT , $id ) ; |
|---|
| 118 | } else { |
|---|
| 119 | $href = TC_REWRITE_DIR . sprintf( TC_REWRITE_FILENAME_FMT , $id ) ; |
|---|
| 120 | } |
|---|
| 121 | } else { |
|---|
| 122 | if( $link == TC_WRAPTYPE_USEREWRITE ) { |
|---|
| 123 | $href = TC_REWRITE_DIR . sprintf( TC_REWRITE_FILENAME_FMT , $id ) ; |
|---|
| 124 | } else if( $link == TC_WRAPTYPE_CONTENTBASE ) { |
|---|
| 125 | $href = "content/index.php?id=$id" ; |
|---|
| 126 | } else { |
|---|
| 127 | $href = "index.php?id=$id" ; |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | $ret[] = array( |
|---|
| 132 | "image" => "images/content.gif" , |
|---|
| 133 | "link" => $href , |
|---|
| 134 | "title" => $title , |
|---|
| 135 | "time" => $timestamp , |
|---|
| 136 | "uid" => "0" , |
|---|
| 137 | "context" => $context |
|---|
| 138 | ) ; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | return $ret ; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | ?> |
|---|