| search.php |
|
1 <?php
2 /* 3 +----------------------------------------------------------------+ 4 | | 5 | GaMerZ File Explorer Version 1.20 | 6 | Copyright (c) 2004-2008 Lester "GaMerZ" Chan | 7 | | 8 | File Written By: | 9 | - Lester "GaMerZ" Chan | 10 | - http://lesterchan.net | 11 | | 12 | File Information: | 13 | - Search For Files | 14 | - search.php | 15 | | 16 +----------------------------------------------------------------+ 17 */ 18 19 20 ### Require Config, Setting And Function Files 21 require('config.php'); 22 require('settings.php'); 23 require('functions.php'); 24 25 ### Start Timer 26 StartTimer(); 27 28 ### Check Whether Search Is Enabled 29 if(!$can_search) { 30 display_error('The Administrator Has Disabled The Searching Of Files'); 31 } 32 33 ### Variables Variables Variables 34 $get_sort_order = trim($_GET['order']); 35 $get_sort_by = trim($_GET['by']); 36 $search_keyword = trim(strip_tags(stripslashes($_GET['search']))); 37 $search_in = trim(strip_tags(stripslashes($_GET['in']))); 38 39 ### Process Search 40 if(!empty($_GET['search'])) { 41 // Variables Variables Variables 42 $sort_order = ''; 43 $sort_order_text = ''; 44 $sort_order_image = ''; 45 $sort_by = ''; 46 $search_results = array(); 47 48 // Determine Sort Order 49 if(empty($get_sort_order)) { $get_sort_order = $default_sort_order; } 50 switch($get_sort_order) { 51 case 'asc': 52 $sort_order = SORT_ASC; 53 $sort_order_text = 'Ascending'; 54 $sort_order_image = $gfe_url.'/resources/arrow_ascending.gif'; 55 break; 56 case 'desc': 57 default: 58 $sort_order = SORT_DESC; 59 $sort_order_text = 'Descending'; 60 $sort_order_image = $gfe_url.'/resources/arrow_descending.gif'; 61 } 62 63 // Determine Sort By 64 if(empty($get_sort_by)) { $get_sort_by = $default_sort_by; } 65 switch($get_sort_by) { 66 case 'name': 67 case 'size': 68 case 'type': 69 case 'date': 70 $sort_by = $get_sort_by; 71 break; 72 default: 73 $sort_by = 'date'; 74 } 75 // Determine Search In 76 if(empty($search_in)) { 77 $search_in = 'all'; 78 } 79 80 // List All The files 81 list_files($root_directory); 82 83 // Check For Matches 84 foreach($gmz_files as $gmz_file) { 85 if($search_in != 'all') { 86 if(strpos(strtolower($gmz_file['name']), strtolower($search_keyword)) !== false && strpos($gmz_file['path'], $search_in) !== false) { 87 $search_results[] = $gmz_file; 88 } 89 } else { 90 if(strpos(strtolower($gmz_file['name']), strtolower($search_keyword)) !== false) { 91 $search_results[] = $gmz_file; 92 } 93 } 94 } 95 96 // We Do Not Need The File Listings Anymore 97 unset($gmz_files); 98 99 // Sort The Array 100 if($sort_by == 'name') { 101 $search_results = array_alphabetsort($search_results, $sort_by, $sort_order); 102 } elseif($sort_by == 'type') { 103 $search_results = array_alphabetsort($search_results, $sort_by, $sort_order); 104 } else { 105 usort($search_results, 'array_numbersort'); 106 if($sort_order == SORT_DESC) { 107 $search_results = array_reverse($search_results); 108 } 109 } 110 } else { 111 // List All Directories 112 list_directories($root_directory); 113 } 114 ?> 115 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 116 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 117 <head> 118 <title><?php echo $site_name; ?> - Search<?php if(!empty($search_keyword)) echo ' - '.$search_keyword; ?></title> 119 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 120 <link rel="shortcut icon" href="<?php echo $gfe_url; ?>/resources/favicon.ico" type="image/ico" /> 121 <style type="text/css" media="screen, print"> 122 @import url( <?php echo $gfe_url; ?>/resources/style.css ); 123 </style> 124 <script src="<?php echo $gfe_url; ?>/resources/javascript.js" type="text/javascript"></script> 125 </head> 126 <body> 127 128 <!-- Breadcrumbs --> 129 <div id="Breadcrumbs"><a href="<?php echo url('home', 'dir'); ?>">Home</a> <b>»</b><?php if(!empty($search_keyword)) { echo " <a href=\"$gfe_url/search.php\">Search</a> <b>»</b> $search_keyword"; } else { echo ' Search'; } ?></div> 130 131 <!-- Search Files --> 132 <form id="search" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 133 <table border="0" cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 134 <tr> 135 <td class="Header" colspan="2" style="width: 100%;" title="Search Engine">Search Engine</td> 136 </tr> 137 <tr> 138 <td title="Search Term:">Search Term:</td> 139 <td title="Search Term"> 140 <input type="text" name="search" class="TextField" size="30" maxlength="30" value="<?php echo $search_keyword; ?>" /> 141 </td> 142 </tr> 143 <tr> 144 <td title="Search In:">Search In:</td> 145 <td title="Search In"> 146 <select name="in" size="1"> 147 <option value="all">All Folders</option> 148 <?php 149 foreach($gmz_directories as $gmz_directory) { 150 if($gmz_directory == $search_in) { 151 echo "<option value=\"$gmz_directory\" selected=\"selected\">$gmz_directory</option>\n"; 152 } else { 153 echo "<option value=\"$gmz_directory\">$gmz_directory</option>\n"; 154 } 155 } 156 ?> 157 </select> 158 </td> 159 </tr> 160 <tr> 161 <td title="Sort By:">Sort By:</td> 162 <td title="Sort By"> 163 <select name="by" size="1"> 164 <option value="name"<?php if($sort_by == 'name') { echo ' selected="selected"'; } ?>>File Name</option> 165 <option value="size"<?php if($sort_by == 'size') { echo ' selected="selected"'; } ?>>File Size</option> 166 <option value="type"<?php if($sort_by == 'type') { echo ' selected="selected"'; } ?>>File Type</option> 167 <option value="date"<?php if($sort_by == 'date') { echo ' selected="selected"'; } ?>>File Date</option> 168 </select> 169 </td> 170 </tr> 171 <tr> 172 <td title="Sort Order:">Sort Order:</td> 173 <td title="Sort Order"> 174 <select name="order" size="1"> 175 <option value="asc"<?php if($sort_order_text == 'Ascending') { echo ' selected="selected"'; } ?>>Ascending</option> 176 <option value="desc"<?php if($sort_order_text == 'Descending') { echo ' selected="selected"'; } ?>>Descending</option> 177 </select> 178 </td> 179 </tr> 180 <tr> 181 <td colspan="2" style="text-align: center;"><input type="submit" value="Search" class="Button" /></td> 182 </tr> 183 </table> 184 </form> 185 <?php 186 ### If Not Searching, Don't Display Results Page 187 if(!empty($search_keyword)) { 188 ?> 189 <!-- List Search Results Files --> 190 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 191 <tr> 192 <td class="Header" colspan="2" title="File Name">Name</td> 193 <td class="Header" title="File Size">Size</td> 194 <td class="Header" title="File Type">Type</td> 195 <td class="Header" title="File Date">Date</td> 196 </tr> 197 <?php 198 if(!empty($search_results)) { 199 foreach($search_results as $key => $value) { 200 $file_name = $value['name']; 201 $file_size = format_size($value['size']); 202 $file_date = date('jS F Y', $value['date']); 203 $file_extension = $value['type']; 204 $file_extension_icon = $extensions[$value['ext']][1]; 205 $total_size += $value['size']; 206 if(!is_file($gfe_directory.'/resources/icons/'.$file_extension_icon)) { 207 $file_extension = 'Unknown'; 208 $file_extension_icon = 'unknown.gif'; 209 } 210 echo '<tr onmouseover="this.className=\'MouseOver\';" onmouseout="this.className=\'MouseOut\';">'."\n"; 211 echo "<td style=\"width: 1%;\" title=\"$file_name ($file_size)\"><img src=\"$gfe_url/resources/icons/$file_extension_icon\" alt=\"$file_name ($file_size)\" /></td>\n"; 212 echo "<td style=\"width: 50%;\" title=\"File: $file_name\"><a href=\"".url($value['path'],'file')."\">$file_name</a></td>\n"; 213 echo "<td style=\"width: 9%;\" title=\"Size: $file_size\">$file_size</td>\n"; 214 echo "<td style=\"width: 20%;\" title=\"Type: $file_extension\">$file_extension</td>\n"; 215 echo "<td style=\"width: 20%;\" title=\"Date: $file_date\">$file_date</td>\n"; 216 echo '</tr>'."\n"; 217 } 218 } else { 219 echo "<tr><td colspan=\"5\" style=\"text-align: center;\" title=\"No Files Found With The Search Term '$search_keyword'\"><b>No Files Found With The Search Term '$search_keyword'</b></td></tr>"; 220 } 221 222 // File Stats Variables 223 $total_files = sizeof($search_results); 224 $total_size = format_size($total_size); 225 $total_files_name = 'Files'; 226 if($total_files <= 1) { $total_files_name = 'File'; } 227 ?> 228 </table> 229 230 <!-- Search Results Information --> 231 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 232 <tr> 233 <td class="Footer" style="width: 95%;" title="<?php echo $total_files.' '.$total_files_name; ?>"><?php echo $total_files.' '.$total_files_name; ?></td> 234 <td class="Footer" style="width: 5%; text-align: center;" title="Size: <?php echo $total_size; ?>"><?php echo $total_size; ?></td> 235 </tr> 236 </table> 237 <?php 238 } 239 ?> 240 <!-- Search Path --> 241 <div id="BottomBreadcrumbs"><?php echo $gfe_url.'/search.php'; ?></div> 242 243 <!-- Copyright --> 244 <p style="text-align: center;"> 245 Powered By <a href="http://lesterchan.net/">GaMerZ File Explorer Version <?php echo $gfe_version; ?></a><br />Copyright © 2004-<?php echo date('Y'); ?> Lester "GaMerZ" Chan, All Rights Reserved.<br /><br />Page Generated In <?php echo StopTimer(); ?> Seconds 246 </p> 247 </body> 248 </html> |
| 248 Lines | Download 'search.php' | 9KB |