PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/d3diary/search.php

http://xoopscube-modules.googlecode.com/
PHP | 149 lines | 109 code | 28 blank | 12 comment | 19 complexity | fd76290a67d13b1b9b3f49f32e2f2630 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 d3diary_global_search_base( "'.$mydirname.'" , $keywords , $andor , $limit , $offset , $userid ) ;
  6. }
  7. ' ) ;
  8. if( ! function_exists( 'd3diary_global_search_base' ) ) {
  9. function d3diary_global_search_base($mydirname , $queryarray, $andor, $limit, $offset, $userid)
  10. {
  11. global $xoopsDB, $xoopsUser;
  12. require dirname(__FILE__).'/class/d3diaryConf.class.php';
  13. $d3dConf =& D3diaryConf::getInstance($mydirname, 0, "search");
  14. $func =& $d3dConf->func;
  15. $mod_config =& $d3dConf->mod_config;
  16. // for sanitizing contents
  17. $myts =& $d3dConf->myts;
  18. $ret = array();
  19. # if ( $userid != 0 ) {
  20. # return $ret;
  21. # }
  22. $uid = $d3dConf->uid;
  23. $editperm=0;
  24. if($d3dConf->mPerm->isadmin){$editperm=1;}
  25. $sql = "SELECT *
  26. FROM ".$xoopsDB->prefix($mydirname.'_config');
  27. $result = $xoopsDB->query($sql);
  28. $openarea = array(); $is_friend = array(); $is_friend2 = array();
  29. $showcontext = isset( $_GET['showcontext'] ) ? $_GET['showcontext'] : 0 ;
  30. if( $showcontext == 1){
  31. $q_diary = "d.diary,";
  32. }else{
  33. $q_diary = "";
  34. }
  35. if($d3dConf->mPerm->isadmin){
  36. $whr_openarea = " 1 ";
  37. } else {
  38. $_params4op['use_gp'] = $d3dConf->gPerm->use_gp;
  39. $_params4op['use_pp'] = $d3dConf->gPerm->use_pp;
  40. $whr_openarea = $d3dConf->mPerm->get_open_query( "search", $_params4op );
  41. }
  42. $sql = "SELECT d.bid, d.uid, d.title, ".$q_diary." d.create_time, d.openarea AS openarea_entry,
  43. d.vgids AS vgids, d.vpids AS vpids, cfg.openarea AS openarea,
  44. c.openarea AS openarea_cat, c.vgids AS vgids_cat, c.vpids AS vpids_cat
  45. FROM ".$xoopsDB->prefix($mydirname.'_diary')." d LEFT JOIN "
  46. .$xoopsDB->prefix($mydirname.'_config')." cfg ON d.uid=cfg.uid LEFT JOIN "
  47. .$xoopsDB->prefix($mydirname.'_category')." c ON (d.cid=c.cid AND (d.uid=c.uid OR c.uid='0')) WHERE "
  48. .$whr_openarea;
  49. if ( $userid != 0 ) {
  50. $sql .= " AND d.uid=".$userid." ";
  51. }
  52. // because count() returns 1 even if a supplied variable
  53. // is not an array, we must check if $querryarray is really an array
  54. $count = count($queryarray);
  55. if ( $count > 0 && is_array($queryarray) ) {
  56. $queryarray[0]=mysql_real_escape_string($queryarray[0]);
  57. $sql .= " AND ((d.title LIKE '%$queryarray[0]%' OR d.diary LIKE '%$queryarray[0]%') ";
  58. for ( $i = 1; $i < $count; $i++ ) {
  59. $queryarray[$i]=mysql_real_escape_string($queryarray[$i]);
  60. $sql .= " $andor ";
  61. $sql .= " (d.title LIKE '%$queryarray[$i]%' OR d.diary LIKE '%$queryarray[$i]%') ";
  62. }
  63. $sql .= ") ";
  64. }
  65. //var_dump($sql);
  66. $sql .= " ORDER BY d.create_time DESC";
  67. $result = $xoopsDB->query($sql,$limit,$offset);
  68. $i = 0;
  69. while ( $dbdat = $xoopsDB->fetchArray($result) ) {
  70. $dbdat['uid'] = intval($dbdat['uid']);
  71. $ret[$i]['image'] = "images/pencil.gif";
  72. $ret[$i]['link'] = "index.php?page=detail&amp;bid=".$dbdat['bid'];
  73. $ret[$i]['title'] = htmlspecialchars($dbdat['title'], ENT_QUOTES);
  74. $tmparray = preg_split("/[-: ]/", $dbdat['create_time']);
  75. $ret[$i]['time'] = mktime($tmparray[3], $tmparray[4], $tmparray[5], $tmparray[1], $tmparray[2], $tmparray[0]);
  76. $ret[$i]['uid'] = $dbdat['uid'];
  77. if( !empty($dbdat['diary']) ){
  78. //start main
  79. $context = $dbdat['diary'];
  80. // $context = strip_tags($myts->displayTarea(strip_tags($context)));
  81. // $context = strip_tags($context);
  82. $context = $func->substrTarea( $context, (int)$dbdat['dohtml'], $mod_config['preview_charmax'] , true, "" );
  83. $ret[$i]['context'] = d3diary_search_make_context3($context,$queryarray);
  84. //end main
  85. }
  86. $i++;
  87. }
  88. return $ret;
  89. }
  90. //nao-pon's hack
  91. function d3diary_search_make_context3($text,$words,$l=255)
  92. {
  93. static $strcut = "";
  94. if (!$strcut)
  95. $strcut = create_function ( '$a,$b,$c', (function_exists('mb_strcut'))?
  96. 'return mb_strcut($a,$b,$c);':
  97. 'return strcut($a,$b,$c);');
  98. if (!is_array($words)) $words = array();
  99. $ret = "";
  100. $q_word = str_replace(" ","|",preg_quote(join(' ',$words),"/"));
  101. if (preg_match("/$q_word/i",$text,$match))
  102. {
  103. $ret = ltrim(preg_replace('/\s+/', ' ', $text));
  104. list($pre, $aft)=preg_split("/$q_word/i", $ret, 2);
  105. $m = intval($l/2);
  106. if(strlen($pre) > $m){
  107. $ret = "... ";
  108. }
  109. $ret .= $strcut($pre, max(strlen($pre)-$m+1,0),$m).$match[0];
  110. $m = $l-strlen($ret);
  111. $ret .= $strcut($aft, 0, min(strlen($aft),$m));
  112. if (strlen($aft) > $m) $ret .= " ...";
  113. }
  114. if (!$ret)
  115. $ret = $strcut($text, 0, $l);
  116. return $ret;
  117. }
  118. }
  119. ?>