<?php

class AKB_FILEINDEX {

	/**
	* @var array $indexTypes Store a list of available indexes extension
	*/
	var $indexTypes = array();

	/**
	* @var array $validExtensions Store a list of valid extensions
	*/
	var $validExtensions = array();

	/**
	* AKB_FileIndex
	* The class constructor that Initialize the available index type and its extension
	*
	* @return void
	*/
	function AKB_FileIndex () {
		$this->InitIndexTypes();
	}

	
	/**
	* InitIndexTypes
	* Initialize the available index type and extensions
	*
	* @return void
	*/
	function InitIndexTypes () {
		$this->indexTypes['Default_Plugin']=array('htm','html','shtml','shtm','txt','php','asp','cfm','cfml','pl','cgi','aspx','jsp');
		$this->indexTypes['External_Doc_Plugin']=array('doc');
		$this->indexTypes['Docx_Plugin']=array('docx');
		$this->indexTypes['External_Ppt_Plugin']=array('ppt');
		$this->indexTypes['Pdf_Plugin']=array('pdf');
		$this->indexTypes['Image_Plugin']=array('jpg','jpeg','tiff');
	}

	/**
	* GetExtension
	* Get the extensions for particular plugin
	* 
	* @param string $type
	*
	* @return mixed
	*/
	function GetExtension ($type) {
		if (isset($this->indexTypes[$type])) {
			return $this->indexTypes[$type];
		}
		return false;
	}

	/**
	* SetValidExtension
	* Set all the valid Extension according to what are enabled by user
	* 
	* @return void
	*/
	function SetValidExtension () {
		$this->validExtensions = array();
		if ($GLOBALS['enableAttachmentSearch']) {
			// get the selected index plugins.
			$tmp = $this->indexTypes;
			$tmpExtensions = array();
			foreach ($tmp as $eachType) {
				while (list($k, $v) = each($tmp)) {
					if (strstr($GLOBALS['indexPlugins'], $k)) {
						$tmpExtensions = array_merge($tmpExtensions, $v);
					}
				}
			}
//			$this->validExtensions = array_combine($tmpExtensions, $tmpExtensions);
			foreach($tmpExtensions as $key1 => $value1) {
		        $this->validExtensions[(string)$value1] = $tmpExtensions[$key1];
		    }
		}
	}

	/**
	* getValidExtension
	* Get all the valid Extension according to what are enabled by user
	* 
	* @return Array
	*/
	function getValidExtension () {
		$this->SetValidExtension();
		return $this->validExtensions;
	}
	
	/**
	* GetPlugin
	* 
	* @param String $extension 
	* 
	* @return Mixed
	*
	*/
	function getPlugin($extension) {
		while (list($k, $v) = each($this->indexTypes)) {
			if (in_array($extension, $v)) {
				reset($this->indexTypes);
				return $k;
			}
		}
		reset($this->indexTypes);
		return false;
	}
}

?>