PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website các món ăn và ẩm thực php/bbqvietnam.com/administrator/components/com_ninjaxplorer/include/fun_search.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 152 lines | 83 code | 13 blank | 56 comment | 21 complexity | d0668569869ce058b409215ea144b713 MD5 | raw file
  1. <?php
  2. /** ensure this file is being included by a parent file */
  3. defined('_JEXEC') or die('Restricted access');
  4. /*------------------------------------------------------------------------------
  5. The contents of this file are subject to the Mozilla Public License
  6. Version 1.1 (the "License"); you may not use this file except in
  7. compliance with the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS"
  10. basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  11. License for the specific language governing rights and limitations
  12. under the License.
  13. The Original Code is fun_search.php, released on 2003-03-31.
  14. The Initial Developer of the Original Code is The QuiX project.
  15. Alternatively, the contents of this file may be used under the terms
  16. of the GNU General Public License Version 2 or later (the "GPL"), in
  17. which case the provisions of the GPL are applicable instead of
  18. those above. If you wish to allow use of your version of this file only
  19. under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision by
  21. deleting the provisions above and replace them with the notice and
  22. other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this file
  24. under either the MPL or the GPL."
  25. ------------------------------------------------------------------------------*/
  26. /*------------------------------------------------------------------------------
  27. Author: The QuiX project
  28. quix@free.fr
  29. http://www.quix.tk
  30. http://quixplorer.sourceforge.net
  31. Comment:
  32. QuiXplorer Version 2.3
  33. File-Search Functions
  34. Have Fun...
  35. ------------------------------------------------------------------------------*/
  36. //------------------------------------------------------------------------------
  37. function find_item($dir,$pat,&$list,$recur) { // find items
  38. $handle=@opendir(get_abs_dir($dir));
  39. if($handle===false) return; // unable to open dir
  40. while(($new_item=readdir($handle))!==false) {
  41. if(!@file_exists(get_abs_item($dir, $new_item))) continue;
  42. if(!get_show_item($dir, $new_item)) continue;
  43. // match?
  44. if(@eregi($pat,$new_item)) $list[]=array($dir,$new_item);
  45. // search sub-directories
  46. if(get_is_dir($dir, $new_item) && $recur) {
  47. find_item(get_rel_item($dir,$new_item),$pat,$list,$recur);
  48. }
  49. }
  50. closedir($handle);
  51. }
  52. //------------------------------------------------------------------------------
  53. function make_list($dir,$item,$subdir) { // make list of found items
  54. // convert shell-wildcards to PCRE Regex Syntax
  55. $pat="^".str_replace("?",".",str_replace("*",".*",str_replace(".","\.",$item)))."$";
  56. // search
  57. find_item($dir,$pat,$list,$subdir);
  58. if(is_array($list)) sort($list);
  59. return $list;
  60. }
  61. //------------------------------------------------------------------------------
  62. function print_table($list) { // print table of found items
  63. if(!is_array($list)) return;
  64. $cnt = count($list);
  65. for($i=0;$i<$cnt;++$i) {
  66. $dir = $list[$i][0]; $item = $list[$i][1];
  67. $s_dir=$dir; if(strlen($s_dir)>65) $s_dir=substr($s_dir,0,62)."...";
  68. $s_item=$item; if(strlen($s_item)>45) $s_item=substr($s_item,0,42)."...";
  69. $link = ""; $target = "";
  70. if(get_is_dir($dir,$item)) {
  71. $img = "dir.png";
  72. $link = make_link("list",get_rel_item($dir, $item),NULL);
  73. } else {
  74. $img = get_mime_type($dir, $item, "img");
  75. //if(get_is_editable($dir,$item) || get_is_image($dir,$item)) {
  76. $link = $GLOBALS["home_url"]."/".get_rel_item($dir, $item);
  77. $target = "_blank";
  78. //}
  79. }
  80. echo "<tr><td>" . "<img border=\"0\" width=\"22\" height=\"22\" ";
  81. echo "align=\"absmiddle\" src=\""._QUIXPLORER_URL."/images/" . $img . "\" alt=\"\">&nbsp;";
  82. /*if($link!="")*/ echo"<a href=\"".$link."\" target=\"".$target."\">";
  83. //else echo "<a>";
  84. echo $s_item."</a></td><td><a href=\"" . make_link("list",$dir,null)."\"> /";
  85. echo $s_dir."</a></td></tr>\n";
  86. }
  87. }
  88. //------------------------------------------------------------------------------
  89. function search_items($dir) { // search for item
  90. if(isset($GLOBALS['__POST']["searchitem"])) {
  91. $searchitem=stripslashes($GLOBALS['__POST']["searchitem"]);
  92. $subdir=(isset($GLOBALS['__POST']["subdir"]) && $GLOBALS['__POST']["subdir"]=="y");
  93. $list=make_list($dir,$searchitem,$subdir);
  94. } else {
  95. $searchitem=NULL;
  96. $subdir=true;
  97. }
  98. $msg=$GLOBALS["messages"]["actsearchresults"];
  99. if($searchitem!=NULL) $msg.=": (/" . get_rel_item($dir, $searchitem).")";
  100. show_header($msg);
  101. // Search Box
  102. echo "<br><table><form name=\"searchform\" action=\"".make_link("search",$dir,null);
  103. echo "\" method=\"post\">\n<tr><td><input name=\"searchitem\" type=\"text\" size=\"25\" value=\"";
  104. echo $searchitem."\"><INPUT type=\"submit\" value=\"".$GLOBALS["messages"]["btnsearch"];
  105. echo "\">&nbsp;<input type=\"button\" value=\"".$GLOBALS["messages"]["btnclose"];
  106. echo "\" onClick=\"javascript:location='".make_link("list",$dir,NULL);
  107. echo "';\"></td></tr><tr><td><input type=\"checkbox\" name=\"subdir\" value=\"y\"";
  108. echo ($subdir?" checked>":">").$GLOBALS["messages"]["miscsubdirs"]."</td></tr></form></table>\n";
  109. // Results
  110. if($searchitem!=NULL) {
  111. echo "<table width=\"95%\"><tr><td colspan=\"2\"><hr></td></tr>\n";
  112. if(count($list)>0) {
  113. // table header
  114. echo "<tr>\n<td width=\"42%\" class=\"header\"><b>".$GLOBALS["messages"]["nameheader"];
  115. echo "</b></td>\n<td width=\"58%\" class=\"header\"><b>".$GLOBALS["messages"]["pathheader"];
  116. echo "</b></td></tr>\n<tr><td colspan=\"2\"><hr></td></tr>\n";
  117. // make & print table of found items
  118. print_table($list);
  119. echo "<tr><td colspan=\"2\"><hr></td></tr>\n<tr><td class=\"header\">".count($list)." ";
  120. echo $GLOBALS["messages"]["miscitems"].".</td><td class=\"header\"></td></tr>\n";
  121. } else {
  122. echo "<tr><td>".$GLOBALS["messages"]["miscnoresult"]."</td></tr>";
  123. }
  124. echo "<tr><td colspan=\"2\"><hr></td></tr></table>\n";
  125. }
  126. ?><script language="JavaScript1.2" type="text/javascript">
  127. <!--
  128. if(document.searchform) document.searchform.searchitem.focus();
  129. // -->
  130. </script><?php
  131. }
  132. //------------------------------------------------------------------------------
  133. ?>