Go to the documentation of this file.00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 require "MagicConfig.php";
00021
00022 class Magic
00023 {
00024 function Magic()
00025 {
00026 $this->config = new MagicConfig();
00027 }
00028
00029 function load_file($filename)
00030 {
00031 if (!($filehandle = @fopen($filename, "rb"))) return undef;
00032 set_magic_quotes_runtime(0);
00033 $text = fread($filehandle, filesize($filename));
00034 set_magic_quotes_runtime(get_magic_quotes_gpc());
00035 fclose($filehandle);
00036 return $text;
00037 }
00038
00039 function _is_ascii($file)
00040 {
00041 $arr = unpack("C*", $file);
00042 for($i=1; $i<sizeof($arr); $i++)
00043 {
00044 if ($arr[$i]<32 && $arr[$i]!=13 && $arr[$i]!=10) return false;
00045 }
00046 return true;
00047 }
00048
00049 function get_language($filename)
00050 {
00051
00052 $extensionspl = explode($this->config->separator, $filename);
00053 $extension = $extensionspl[sizeof($extensionspl)-1];
00054 $langstr = $this->config->extensions[$extension];
00055
00056 $langarr = explode("|", $langstr);
00057
00058
00059 if (sizeof($langarr)==1 && $langarr[0]!="") return $langstr;
00060
00061
00062
00063
00064
00065 $this->config->file = $this->load_file($filename);
00066 if ($this->config->file == undef) return "illegal";
00067 $this->is_ascii = $this->_is_ascii($this->config->file);
00068
00069 if (isset($langstr))
00070 {
00071
00072
00073
00074 $outarray = array();
00075 foreach($langarr as $lang)
00076 {
00077 if ($this->is_ascii && in_array($lang, $this->config->langfunctions))
00078 array_push($outarray, $lang);
00079 else if(in_array($lang, $this->config->binfunctions))
00080 array_push($outarray, $lang);
00081 }
00082 $testarray = $outarray;
00083 }
00084 else
00085 {
00086 if ($this->is_ascii) $testarray = $this->config->langfunctions;
00087 else $testarray = $this->config->binfunctions;
00088 }
00089 foreach($testarray as $test)
00090 {
00091 $func = "detect_".$test;
00092 if ($this->config->$func()) return $test;
00093 }
00094 }
00095 }
00096
00097 ?>