All pastes #674163 Raw Edit

Something

public php v1 · immutable
#674163 ·published 2007-08-28 23:30 UTC
rendered paste body
	/**	 * @param string $query String to search for	 * @param string $dir The folder to search (recursive)	 * @param string $mode Should be f (files), d (directories), or fd (both)	 */	public function __construct($query, $dir, $mode)	{		if (strlen($query) < 2 || strlen($query) > 20)		{			throw new ExceptionDisplay('Search query is either too long or too short.');		}		$mode = self::clean_mode($mode);		$dir = Item::make_sure_slash();		DirectoryList::__construct($dir);		$this -> matches = array();		$this -> total_size = new Size(0);		$this -> total_downloads = $this -> total_folders = $this -> total_files = 0;		foreach ($this as $item)		{			if ($item == '..')			{				continue;			}			if (@is_dir($dir . $item))			{				if (stripos($mode, 'd') !== false && self::match($item, $query))				{					$temp = new DirItem($dir, $item);					$this -> matches[] = $temp;					if ($temp -> __get('size') -> __get('bytes') !== false)					{						$this -> total_size -> add_size($temp -> __get('size'));					}					$this -> total_folders++;				}				$sub_search = new Search($query, $dir . $item, $mode);				$this -> merge($sub_search);			}			else if (stripos($mode, 'f') !== false && self::match($item, $query))			{				$temp = new FileItem($dir, $item);				$this -> matches[] = $temp;				$this -> total_size -> add_size($temp -> __get('size'));				$this -> total_downloads += $temp -> __get('downloads');				$this -> total_files++;			}		}		global $words, $config, $subdir;		$link = ' <a class="autoindex_a" href="' . $_SERVER['PHP_SELF']		. '?dir=' . Url::translate_uri($subdir) . '">'		. Url::html_output($dir) . '</a> ';		$this -> path_nav = $words -> __get('search results for')		. $link . $words -> __get('and its subdirectories');		$this -> contents = $this -> matches;		unset($this -> matches);	}