encode($items); } //------------------------------------------------------------------------------ function make_list($dir, $item, $subdir, $content) { // make list of found items // search if (ext_isFTPMode()) { find_item_ftp($dir, $item, $list, $subdir, $content); } else { find_item($dir, $item, $list, $subdir, $content); } if (is_array($list)) sort($list); return $list; } function find_item_ftp($dir,$item,&$list,$recur, $content) { // find items $homedir = realpath($GLOBALS['home_dir']); $opendir = $dir; // convert shell-wildcards to PCRE Regex Syntax $pat=str_replace("?",".",str_replace("*",".*",str_replace(".","\\.",$item))); if( !is_dir( $dir )) { $opendir = get_abs_dir($dir); } $handle = @$GLOBALS['ext_File']->opendir( $opendir ); if($handle===false && $dir=="") { $handle = @$GLOBALS['ext_File']->opendir($homedir . $GLOBALS['separator']); } if($handle===false) { ext_Result::sendResult('search', false, $opendir .": ".$GLOBALS["error_msg"]["opendir"]); } while(($new_item=$GLOBALS['ext_File']->readdir($handle))!==false) { if( is_array( $new_item )) { $abs_new_item = $new_item; } else { $abs_new_item = get_abs_item($dir, $new_item); } //if(!$GLOBALS['ext_File']->file_exists($abs_new_item)) continue; if(!get_show_item($dir, $new_item)) continue; $isDir = get_is_dir($abs_new_item); // match? $include = false; if(@preg_match('@'.$pat.'@is',$new_item) > 0 ) { $include = true; } if (!$isDir && $include && $content && $GLOBALS['ext_File']->filesize($abs_new_item) < 524288) { $data = $GLOBALS['ext_File']->file_get_contents( $abs_new_item ); $pattern = preg_quote($content, '/'); // finalise the regular expression, matching the whole line $pattern = "/^.*$pattern.*\$/m"; if (preg_match('@'. $pattern.'@is', $data) > 0 ) { $include = true; } } if( $include ) { $list[]=array($dir,$new_item); } // search sub-directories if($isDir && $recur) { find_item($abs_new_item,$pat,$list,$recur, $content); } } $GLOBALS['ext_File']->closedir($handle); } function find_item($dir,$pat,&$files,$subdir, $content) { if (!is_dir($dir)) { $dir = get_abs_dir($dir); } if( !$subdir ) { $files = glob($dir.'/'.$pat); } else { $files = glob_recursive($dir.'/'.$pat); } if($files===false) { ext_Result::sendResult('search', false, $dir .": ".$GLOBALS["error_msg"]["opendir"]); } if( $content ) { $newList = array(); foreach( $files as $file ) { $contents = file_get_contents($file); $pattern = preg_quote($content, '/'); // finalise the regular expression, matching the whole line $pattern = "/^.*$pattern.*\$/m"; // search, and store all matching occurences in $matches if(preg_match_all($pattern, $contents, $matches)){ $newList[] = $file; } } $files = $newList; } if( !empty( $_POST['mdate_start'] )) { $mdate_start = strtotime($_POST['mdate_start']); if( empty($_POST['mdate_end'] )) { $mdate_end = time(); } else { $mdate_end = strtotime( $_POST['mdate_end'] ); } if( $mdate_start && $mdate_end ) { $newList = array(); foreach( $files as $file ) { $filemtime = filemtime( $file ); if( $filemtime > $mdate_start && $filemtime < $mdate_end ) { $newList[] = $file; } } $files = $newList; } } if( !empty( $_POST['age_value'] )) { $age_value =(int)$_POST['age_value']; $age_units = array("minutes", "hours", "days", "weeks", "months", "years"); if (in_array($_POST['age_unit'], $age_units)) { $age_unit = $_POST['age_unit']; } else { $age_unit = "days"; } $age_time = strtotime("-".$age_value." ".$age_unit); if( $age_time ) { $newList = array(); foreach( $files as $file ) { $filemtime = filemtime( $file ); if( $filemtime > $age_time ) { $newList[] = $file; } } $files = $newList; } } $newList = array(); foreach( $files as $file ) { $newList[] = array(dirname($file),basename($file)); } $files = $newList; } function get_result_array($list) { // print table of found items if(!is_array($list)) return; $cnt = count($list); $array = array(); for($i=0;$i<$cnt;++$i) { $dir = $list[$i][0]; $item = $list[$i][1]; $s_dir=str_ireplace($GLOBALS['home_dir'], '', $dir ); if(strlen($s_dir)>65) $s_dir=substr($s_dir,0,62)."..."; $s_item=str_ireplace($GLOBALS['home_dir'], '', $item ); if(strlen($s_item)>45) $s_item=substr($s_item,0,42)."..."; $link = ""; $target = ""; if(get_is_dir($dir,$item)) { $img = "dir.png"; $link = ext_make_link("list",get_rel_item($dir, $item),NULL); } else { $img = get_mime_type( $item, "img"); //if(get_is_editable($dir,$item) || get_is_image($dir,$item)) { $link = $GLOBALS["home_url"]."/".get_rel_item($dir, $item); $target = "_blank"; //} } $array[$i]['last_mtime'] = ext_isFTPMode() ? $GLOBALS['ext_File']->filemtime($GLOBALS['home_dir'].'/'.$dir.'/'.$item) : filemtime($dir.'/'.$item); $array[$i]['file_id'] = md5($s_dir.$s_item); $array[$i]['dir'] = str_ireplace($GLOBALS['home_dir'], '', $dir ); $array[$i]['s_dir'] = empty($s_dir) ? '' : $s_dir; $array[$i]['file'] = htmlentities($s_item, ENT_QUOTES ); $array[$i]['link'] = $link; $array[$i]['icon'] = _EXT_URL."/images/$img"; } return $array; } /** * Recursive implementation of glob * @param $pattern * @param int $flags * @return array */ function glob_recursive($pattern, $flags = 0) { $files = glob($pattern, $flags); if ($files === false) return array(); foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags)); } return $files; } //------------------------------------------------------------------------------ function show_searchform($dir='') { ?> { "height":400, "autoScroll":true, items: [ new Ext.TabPanel({ activeTab: 0, items: [{ "title":"", "height": "370", "autoScroll":true, "items": new Ext.DataView({ "id": "dataview", tpl: new Ext.XTemplate( '', '
', '

', '{s_dir}/{file}, {lastModified:date("M j, Y")}', '

', '
' ), store: new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: "" }), reader: new Ext.data.JsonReader({ root: 'items', totalProperty: 'totalCount', id: 'file_id' }, [ {name: 'fileId', mapping: 'file_id'}, {name: 'file', mapping: 'file'}, {name: 'dir', mapping: 'dir'}, {name: 's_dir', mapping: 's_dir'}, {name: 'lastModified', mapping: 'last_mtime', type: 'date', dateFormat: 'timestamp'} ]), baseParams: { limit:20, option: "com_extplorer", action:"search", dir: "", content: '0', subdir: '1' } }), itemSelector: 'div.search-item' }), tbar: [ 'Search: ', ' ', new Ext.app.SearchField({ store: Ext.getCmp("dataview").store, width:320, value: "*" }) ], bbar: new Ext.PagingToolbar({ store: Ext.getCmp("dataview").store, pageSize: 20, displayInfo: true, displayMsg: 'Results {0} - {1} of {2}', emptyMsg: "No files to display" }) }, { title: "Search Options", xtype:"form", layout: "form", "height": "350", items: [ { id:'myGroup', xtype: 'checkboxgroup', fieldLabel: 'Extensive Search', itemCls: 'x-check-group-alt', // Put all controls in a single column with width 100% columns: 1, items: [ { boxLabel: 'Search within Subdirectories?', name: 'subdir', checked: true, tooltip: "?", "listeners": { "check": { fn: function(box, checked) { Ext.getCmp("dataview").store.baseParams.subdir = (checked ? '1' : '0'); } } } } ] },{ fieldLabel: "", xtype: "textfield", width: 200, id: "contentfield", name: "content", "listeners": { "change": { fn: function(field, newValue) { Ext.getCmp("dataview").store.baseParams.content = newValue; } } } }, { xtype: "compositefield", items: [ { xtype: "checkbox", fieldLabel: "Modification Date between", "listeners": { "check": { fn: function(box, checked) { if( checked ) {Ext.getCmp( "mdate_start" ).enable(); Ext.getCmp( "mdate_end" ).enable(); } else { Ext.getCmp( "mdate_start" ).disable(); Ext.getCmp( "mdate_end" ).disable(); Ext.getCmp("dataview").store.baseParams.mdate_start = ""; Ext.getCmp("dataview").store.baseParams.mdate_end = ""; } } } } }, new Ext.form.DateField({ tooltip: 'Start', name: 'mdate_start', id: 'mdate_start', "listeners": { "change": { fn: function(field, newValue) { Ext.getCmp("dataview").store.baseParams.mdate_start = newValue; } } }, width:90, disabled: true }), new Ext.form.DateField({ tooltip: 'End', name: 'mdate_end', id: 'mdate_end', disabled: true, "listeners": { "change": { fn: function(field, newValue) { Ext.getCmp("dataview").store.baseParams.mdate_end = newValue; } } }, width:90 }) ] }, { xtype: "compositefield", items: [ { xtype: "checkbox", name: "age_enabled", fieldLabel: "max. File Age", "listeners": { "check": { fn: function(box, checked) { if( checked ) {Ext.getCmp( "age_unit" ).enable(); Ext.getCmp( "age_value" ).enable(); } else { Ext.getCmp( "age_value" ).disable(); Ext.getCmp( "age_unit" ).disable(); Ext.getCmp("dataview").store.baseParams.age_value = ""; Ext.getCmp("dataview").store.baseParams.age_unit = ""; } } } } }, { xtype: "textfield", name: "age_value", id: "age_value", value: 1, width: 40, "listeners": { "change": { fn: function(field, newValue) { Ext.getCmp("dataview").store.baseParams.age_value = newValue; } } }, disabled: true }, new Ext.form.ComboBox({ triggerAction: 'all', lazyRender:true, mode: 'local', disabled: true, name: "age_unit", id: "age_unit", value: "days", "listeners": { "change": { fn: function(field, newValue) { Ext.getCmp("dataview").store.baseParams.age_unit = newValue; } } }, store: new Ext.data.ArrayStore({ id: 0, fields: [ 'myId', 'displayText' ], data: [["minute", 'Minute(s)'], ["hours", 'Hour(s)'], ["days", "Day(s)"], ["weeks", "Week(s)"], ["months", "Month(s)"], ["years", "Year(s)" ] ] }), valueField: 'myId', displayField: 'displayText' }) ] } ] }] }) ] }