PageRenderTime 70ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/d3forum/search.php

http://xoopscube-modules.googlecode.com/
PHP | 101 lines | 70 code | 21 blank | 10 comment | 13 complexity | 43fa536ae8371869ae3f63459f6cec2e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. eval( '
  3. function '.$mydirname.'_global_search( $keywords , $andor , $limit , $offset , $userid )
  4. {
  5. return d3forum_global_search_base( "'.$mydirname.'" , $keywords , $andor , $limit , $offset , $userid ) ;
  6. }
  7. ' ) ;
  8. if( ! function_exists( 'd3forum_global_search_base' ) ) {
  9. function d3forum_global_search_base( $mydirname , $keywords , $andor , $limit , $offset , $userid )
  10. {
  11. $myts =& MyTextsanitizer::getInstance() ;
  12. $db =& Database::getInstance() ;
  13. $andor = strtoupper( $andor ) ;
  14. $userid = intval( $userid ) ;
  15. // naao from
  16. require_once dirname(__FILE__).'/include/main_functions.php' ;
  17. // get all forums
  18. $sql = "SELECT forum_id, forum_external_link_format FROM ".$db->prefix($mydirname."_forums") ;
  19. $frs = $db->query( $sql ) ;
  20. $d3com = array() ;
  21. while( $forum_row = $db->fetchArray( $frs ) ) {
  22. // d3comment object
  23. $temp_forum_id = intval($forum_row['forum_id']);
  24. if( ! empty( $forum_row['forum_external_link_format'] ) ) {
  25. $d3com[$temp_forum_id] =& d3forum_main_get_comment_object( $mydirname , $forum_row['forum_external_link_format'] ) ;
  26. } else {
  27. $d3com[$temp_forum_id] = false ;
  28. }
  29. }
  30. // naao to
  31. // XOOPS Search module
  32. $showcontext = empty( $_GET['showcontext'] ) ? 0 : 1 ;
  33. $select4con = $showcontext ? "p.post_text" : "'' AS post_text" ;
  34. require_once dirname(__FILE__).'/include/common_functions.php' ;
  35. $whr_forum = "t.forum_id IN (".implode(",",d3forum_get_forums_can_read( $mydirname )).")" ;
  36. $whr_uid = $userid > 0 ? "p.uid=$userid" : "1" ;
  37. $whr_query = $andor == 'OR' ? '0' : '1' ;
  38. if( is_array( $keywords ) ) foreach( $keywords as $word ) {
  39. // I know this is not a right escaping, but I can't believe $keywords :-)
  40. $word4sql = addslashes( stripslashes( $word ) ) ;
  41. $whr_query .= $andor == 'EXACT' ? ' AND' : ' '.$andor ;
  42. $whr_query .= " (p.subject LIKE '%$word4sql%' OR p.post_text LIKE '%$word4sql%')" ;
  43. }
  44. //$sql = "SELECT p.post_id,p.topic_id,p.post_time,p.uid,p.subject,p.html,p.smiley,p.xcode,p.br,$select4con FROM ".$db->prefix($mydirname."_posts")." p LEFT JOIN ".$db->prefix($mydirname."_topics")." t ON t.topic_id=p.topic_id WHERE ($whr_forum) AND ($whr_uid) AND ($whr_query) AND ! topic_invisible ORDER BY p.post_time DESC" ;
  45. //naao
  46. $sql = "SELECT p.post_id,p.topic_id,p.post_time,p.uid,p.subject,p.html,p.smiley,p.xcode,p.br,$select4con,t.topic_external_link_id,f.forum_id FROM ".$db->prefix($mydirname."_posts")." p LEFT JOIN ".$db->prefix($mydirname."_topics")." t ON t.topic_id=p.topic_id LEFT JOIN ".$db->prefix($mydirname."_forums")." f ON t.forum_id = f.forum_id WHERE ($whr_forum) AND ($whr_uid) AND ($whr_query) AND ! topic_invisible ORDER BY p.post_time DESC" ;
  47. $result = $db->query( $sql , $limit , $offset ) ;
  48. $ret = array() ;
  49. $context = '' ;
  50. while( list( $post_id , $topic_id , $post_time , $uid , $subject , $html , $smiley , $xcode , $br , $text , $external_link_id, $forum_id ) = $db->fetchRow( $result ) ) {
  51. // get context for module "search"
  52. if( function_exists( 'search_make_context' ) && $showcontext ) {
  53. if( function_exists( 'easiestml' ) ) $text = easiestml( $text ) ;
  54. $full_context = strip_tags( $myts->displayTarea( $text , $html , $smiley , $xcode , 1 , $br ) ) ;
  55. $context = search_make_context( $full_context , $keywords ) ;
  56. }
  57. // naao from
  58. $can_display = true; //default
  59. if( is_object( $d3com[intval($forum_id)]) ) {
  60. $d3com_obj = $d3com[intval($forum_id)];
  61. if( ( $external_link_id = $d3com_obj->validate_id( $external_link_id ) ) === false ) {
  62. $can_display = false;
  63. }
  64. }
  65. if ($can_display == true) {
  66. $ret[] = array(
  67. 'link' => "index.php?post_id=$post_id" ,
  68. 'title' => htmlspecialchars( $subject, ENT_QUOTES ) ,
  69. 'time' => $post_time ,
  70. 'uid' => $uid ,
  71. 'context' => $context ,
  72. ) ;
  73. } // naao to
  74. }
  75. return $ret;
  76. }
  77. }
  78. ?>