<?php
/*
	copyright 2004 - ivan ribas (ivan@dospeixos.net)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

class filter {
	
	var $files;
	var $dirs;
	var $extensions;

	/**
	 * we do not want to display . and .. so we add them 
	 * to the filter in the class constructor.
	 */ 

	function filter() {
		$this->add_dir(".");
		$this->add_dir("..");
		$this->add_dir("cuest");
	}

	/**
	 * this function adds a file name to the filter
	 * so files with this name will not be displayed.
	 */

	function add_file($name) {
		$this->files[]=$name;
	}

	/**
	 * adds a directory name to the filter so we do are not	 
	 * going to display directories with this name.
	 */

	function add_dir($name) {
		$this->dirs[]=$name;
	}

	/**
	 * adds an extension to the filter. We are not going
	 * to display files with this extension.
	 * (ej. exe)
	 */

	function add_extension($name) {
		$this->extensions[]=$name;
	}

	/**
	 * returns true if the filename is in the filter
	 * or it has an extension which is in the extensions filter.
	 */

	function in_file_filter($name) {
		if((!is_array($this->files) || 
			!in_array($name,$this->files)) &&
			!$this->in_extension_filter($name)) 
			return false;
		return true;
	}
	
	/**
	 * returns true if the name is in the directory filter
	 */
	
	function in_dir_filter($name) {
		if(!is_array($this->dirs) || 
			!in_array($name,$this->dirs)) return false;
		return true;
	}

	/**
	 * returns true if the filename has an extension which is
	 * in the extensions filter.
	 */

	function in_extension_filter($name) {
		$ex=explode(".",$name);
		if(!is_array($ex)) return false;
		$extension=$ex[count($ex)-1];
		if(!is_array($this->extensions) 
			|| !in_array($extension,$this->extensions)) return false;
		return true;
	}
}
?>
