parent
c1facce646
commit
522e551ad1
@ -1,184 +1,199 @@ |
|||||||
<?php |
<?php |
||||||
include_once(CLASS_FILE); |
|
||||||
require_once(CLASS_SESSION_ACTION); |
include_once(CLASS_FILE); |
||||||
require_once(CLASS_MANAGER); |
require_once(CLASS_SESSION_ACTION); |
||||||
class Search |
require_once(CLASS_MANAGER); |
||||||
{ |
|
||||||
var $rootFolder = ''; |
class Search |
||||||
var $files = array(); |
{ |
||||||
var $rootFolderInfo = array(); |
var $rootFolder = ''; |
||||||
var $searchkeywords = array( |
var $files = array(); |
||||||
'mtime_from'=>'', |
var $rootFolderInfo = array(); |
||||||
'mtime_to'=>'', |
var $searchkeywords = array( |
||||||
'name'=>'', |
'mtime_from' => '', |
||||||
'size_from'=>'', |
'mtime_to' => '', |
||||||
'size_to'=>'', |
'name' => '', |
||||||
'recursive'=>'0', |
'size_from' => '', |
||||||
|
'size_to' => '', |
||||||
); |
'recursive' => '0', |
||||||
var $sessionAction = null; |
|
||||||
/** |
); |
||||||
* constructor |
var $sessionAction = null; |
||||||
* |
|
||||||
* @param string $rootFolder |
/** |
||||||
*/ |
* constructor |
||||||
function __construct($rootFolder) |
* |
||||||
{ |
* @param string $rootFolder |
||||||
$this->rootFolder = $rootFolder; |
*/ |
||||||
$this->sessionAction = new SessionAction(); |
function __construct($rootFolder) |
||||||
$objRootFolder = new file($this->rootFolder); |
{ |
||||||
$tem = $objRootFolder->getFileInfo(); |
$this->rootFolder = $rootFolder; |
||||||
$obj = new manager($this->rootFolder, false); |
$this->sessionAction = new SessionAction(); |
||||||
$obj->setSessionAction($this->sessionAction); |
$objRootFolder = new file($this->rootFolder); |
||||||
$selectedDocuments = $this->sessionAction->get(); |
$tem = $objRootFolder->getFileInfo(); |
||||||
$fileType = $obj->getFolderInfo($this->rootFolder); |
$obj = new manager($this->rootFolder, false); |
||||||
|
$obj->setSessionAction($this->sessionAction); |
||||||
foreach($fileType as $k=>$v) |
$selectedDocuments = $this->sessionAction->get(); |
||||||
{ |
$fileType = $obj->getFolderInfo($this->rootFolder); |
||||||
$tem[$k] = $v; |
|
||||||
} |
foreach ($fileType as $k => $v) { |
||||||
|
$tem[$k] = $v; |
||||||
$tem['path'] = backslashToSlash($this->rootFolder); |
} |
||||||
$tem['type'] = (is_dir($this->rootFolder)?'folder':'file'); |
|
||||||
$tem['size'] = (is_dir($this->rootFolder)?'':transformFileSize(@filesize($this->rootFolder))); |
$tem['path'] = backslashToSlash($this->rootFolder); |
||||||
//$tem['ctime'] = date(DATE_TIME_FORMAT, $tem['ctime']); |
$tem['type'] = (is_dir($this->rootFolder) ? 'folder' : 'file'); |
||||||
//$tem['mtime'] = date(DATE_TIME_FORMAT, $tem['mtime']); |
$tem['size'] = (is_dir($this->rootFolder) ? '' : transformFileSize(@filesize($this->rootFolder))); |
||||||
$tem['flag'] = (array_search($tem['path'], $selectedDocuments) !== false?($this->sessionAction->getAction() == "copy"?'copyFlag':'cutFlag'):'noFlag'); |
//$tem['ctime'] = date(DATE_TIME_FORMAT, $tem['ctime']); |
||||||
$tem['url'] = getFileUrl($this->rootFolder); |
//$tem['mtime'] = date(DATE_TIME_FORMAT, $tem['mtime']); |
||||||
$tem['friendly_path'] = transformFilePath($this->rootFolder); |
$tem['flag'] = (array_search( |
||||||
$tem['file'] = 0; |
$tem['path'], |
||||||
$tem['subdir'] = 0; |
$selectedDocuments |
||||||
$manager = null; |
) !== false ? ($this->sessionAction->getAction() == "copy" ? 'copyFlag' : 'cutFlag') : 'noFlag'); |
||||||
$this->rootFolderInfo = $tem; |
$tem['url'] = getFileUrl($this->rootFolder); |
||||||
$tem = null; |
$tem['friendly_path'] = transformFilePath($this->rootFolder); |
||||||
} |
$tem['file'] = 0; |
||||||
|
$tem['subdir'] = 0; |
||||||
|
$manager = null; |
||||||
|
$this->rootFolderInfo = $tem; |
||||||
/** |
$tem = null; |
||||||
* constructor |
} |
||||||
* |
|
||||||
* @param string $rootFolder |
|
||||||
*/ |
/** |
||||||
function Search($rootFolder) |
* constructor |
||||||
{ |
* |
||||||
$this->__construct($rootFolder); |
* @param string $rootFolder |
||||||
} |
*/ |
||||||
|
function Search($rootFolder) |
||||||
/** |
{ |
||||||
* change the search keyword individually |
$this->__construct($rootFolder); |
||||||
* |
} |
||||||
* @param string $key |
|
||||||
* @param string $value |
/** |
||||||
*/ |
* change the search keyword individually |
||||||
function addSearchKeyword($key, $value) |
* |
||||||
{ |
* @param string $key |
||||||
$this->searchkeywords[$key] = $value; |
* @param string $value |
||||||
} |
*/ |
||||||
/** |
function addSearchKeyword($key, $value) |
||||||
* change the search keywords |
{ |
||||||
* |
$this->searchkeywords[$key] = $value; |
||||||
* @param array $keywords |
} |
||||||
*/ |
|
||||||
function addSearchKeywords($keywords) |
/** |
||||||
{ |
* change the search keywords |
||||||
foreach($this->searchkeywords as $k=>$v) |
* |
||||||
{ |
* @param array $keywords |
||||||
if(array_key_exists($k, $keywords) !== false) |
*/ |
||||||
{ |
function addSearchKeywords($keywords) |
||||||
$this->searchkeywords[$k] = $keywords[$k]; |
{ |
||||||
} |
foreach ($this->searchkeywords as $k => $v) { |
||||||
} |
if (array_key_exists($k, $keywords) !== false) { |
||||||
} |
$this->searchkeywords[$k] = $keywords[$k]; |
||||||
/** |
} |
||||||
* get the file according to the search keywords |
} |
||||||
* |
} |
||||||
*/ |
|
||||||
function doSearch($baseFolderPath = null) |
/** |
||||||
{ |
* get the file according to the search keywords |
||||||
|
* |
||||||
$baseFolderPath = addTrailingSlash(backslashToSlash((is_null($baseFolderPath)?$this->rootFolder:$baseFolderPath))); |
*/ |
||||||
|
function doSearch($baseFolderPath = null) |
||||||
$dirHandler = @opendir($baseFolderPath); |
{ |
||||||
if($dirHandler) |
|
||||||
{ |
$baseFolderPath = addTrailingSlash( |
||||||
while(false !== ($file = readdir($dirHandler))) |
backslashToSlash((is_null($baseFolderPath) ? $this->rootFolder : $baseFolderPath)) |
||||||
{ |
); |
||||||
if($file != '.' && $file != '..') |
|
||||||
{ |
$dirHandler = @opendir($baseFolderPath); |
||||||
$path = $baseFolderPath . $file; |
if ($dirHandler) { |
||||||
if(is_file($path)) |
while (false !== ($file = readdir($dirHandler))) { |
||||||
{ |
if ($file != '.' && $file != '..') { |
||||||
$isValid = true; |
$path = $baseFolderPath.$file; |
||||||
|
if (is_file($path)) { |
||||||
$fileTime = @filemtime($path); |
$isValid = true; |
||||||
$fileSize = @filesize($path); |
|
||||||
if($this->searchkeywords['name'] !== '' && @eregi($this->searchkeywords['name'], $file) === false) |
$fileTime = @filemtime($path); |
||||||
{ |
$fileSize = @filesize($path); |
||||||
$isValid = false; |
if ($this->searchkeywords['name'] !== '' && @eregi( |
||||||
} |
$this->searchkeywords['name'], |
||||||
if($this->searchkeywords['mtime_from'] != '' && $fileTime < @strtotime($this->searchkeywords['mtime_from'])) |
$file |
||||||
{ |
) === false |
||||||
$isValid = false; |
) { |
||||||
} |
$isValid = false; |
||||||
if($this->searchkeywords['mtime_to'] != '' && $fileTime > @strtotime($this->searchkeywords['mtime_to'])) |
} |
||||||
{ |
if ($this->searchkeywords['mtime_from'] != '' && $fileTime < @strtotime( |
||||||
$isValid = false; |
$this->searchkeywords['mtime_from'] |
||||||
} |
) |
||||||
if($this->searchkeywords['size_from'] != '' && $fileSize < @strtotime($this->searchkeywords['size_from'])) |
) { |
||||||
{ |
$isValid = false; |
||||||
$isValid = false; |
} |
||||||
} |
if ($this->searchkeywords['mtime_to'] != '' && $fileTime > @strtotime( |
||||||
if($this->searchkeywords['size_to'] != '' && $fileSize > @strtotime($this->searchkeywords['size_to'])) |
$this->searchkeywords['mtime_to'] |
||||||
{ |
) |
||||||
$isValid = false; |
) { |
||||||
} |
$isValid = false; |
||||||
if($isValid && isListingDocument($path)) |
} |
||||||
{ |
if ($this->searchkeywords['size_from'] != '' && $fileSize < @strtotime( |
||||||
$finalPath = $path; |
$this->searchkeywords['size_from'] |
||||||
$objFile = new file($finalPath); |
) |
||||||
$tem = $objFile->getFileInfo(); |
) { |
||||||
$obj = new manager($finalPath, false); |
$isValid = false; |
||||||
$obj->setSessionAction($this->sessionAction); |
} |
||||||
$selectedDocuments = $this->sessionAction->get(); |
if ($this->searchkeywords['size_to'] != '' && $fileSize > @strtotime( |
||||||
$fileType = $obj->getFileType($finalPath); |
$this->searchkeywords['size_to'] |
||||||
|
) |
||||||
foreach($fileType as $k=>$v) |
) { |
||||||
{ |
$isValid = false; |
||||||
$tem[$k] = $v; |
} |
||||||
} |
if ($isValid && isListingDocument($path)) { |
||||||
|
$finalPath = $path; |
||||||
$tem['path'] = backslashToSlash($finalPath); |
$objFile = new file($finalPath); |
||||||
$tem['type'] = (is_dir($finalPath)?'folder':'file'); |
$tem = $objFile->getFileInfo(); |
||||||
/*$tem['size'] = transformFileSize($tem['size']); |
$obj = new manager($finalPath, false); |
||||||
$tem['ctime'] = date(DATE_TIME_FORMAT, $tem['ctime']); |
$obj->setSessionAction($this->sessionAction); |
||||||
$tem['mtime'] = date(DATE_TIME_FORMAT, $tem['mtime']);*/ |
$selectedDocuments = $this->sessionAction->get(); |
||||||
$tem['flag'] = (array_search($tem['path'], $selectedDocuments) !== false?($this->sessionAction->getAction() == "copy"?'copyFlag':'cutFlag'):'noFlag'); |
$fileType = $obj->getFileType($finalPath); |
||||||
$tem['url'] = getFileUrl($tem['path']); |
|
||||||
$this->rootFolderInfo['file']++; |
foreach ($fileType as $k => $v) { |
||||||
$manager = null; |
$tem[$k] = $v; |
||||||
$this->files[] = $tem; |
} |
||||||
$tem = null; |
|
||||||
} |
$tem['path'] = backslashToSlash($finalPath); |
||||||
}elseif(is_dir($path) && $this->searchkeywords['recursive']) |
$tem['type'] = (is_dir($finalPath) ? 'folder' : 'file'); |
||||||
{ |
/*$tem['size'] = transformFileSize($tem['size']); |
||||||
$this->doSearch($path); // For Chamilo this line replaces $this->Search($baseFolderPath); to run the search recursively from the root directory |
$tem['ctime'] = date(DATE_TIME_FORMAT, $tem['ctime']); |
||||||
} |
$tem['mtime'] = date(DATE_TIME_FORMAT, $tem['mtime']);*/ |
||||||
} |
$tem['flag'] = (array_search( |
||||||
} |
$tem['path'], |
||||||
} |
$selectedDocuments |
||||||
|
) !== false ? ($this->sessionAction->getAction( |
||||||
} |
) == "copy" ? 'copyFlag' : 'cutFlag') : 'noFlag'); |
||||||
|
$tem['url'] = getFileUrl($tem['path']); |
||||||
function getFoundFiles() |
$this->rootFolderInfo['file']++; |
||||||
{ |
$manager = null; |
||||||
return $this->files; |
$this->files[] = $tem; |
||||||
} |
$tem = null; |
||||||
|
} |
||||||
function getRootFolderInfo() |
} elseif (is_dir($path) && $this->searchkeywords['recursive']) { |
||||||
{ |
$this->doSearch( |
||||||
|
$path |
||||||
return $this->rootFolderInfo; |
); // For Chamilo this line replaces $this->Search($baseFolderPath); to run the search recursively from the root directory |
||||||
} |
} |
||||||
} |
} |
||||||
?> |
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
function getFoundFiles() |
||||||
|
{ |
||||||
|
return $this->files; |
||||||
|
} |
||||||
|
|
||||||
|
function getRootFolderInfo() |
||||||
|
{ |
||||||
|
|
||||||
|
return $this->rootFolderInfo; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue