Public Member Functions | |
| Magic () | |
| load_file ($filename) | |
| _is_ascii ($file) | |
| get_language ($filename) | |
Definition at line 22 of file Magic.php.
| Magic::_is_ascii | ( | $ | file | ) |
Definition at line 39 of file Magic.php.
References $file.
Referenced by get_language().
{
$arr = unpack("C*", $file);
for($i=1; $i<sizeof($arr); $i++)
{
if ($arr[$i]<32 && $arr[$i]!=13 && $arr[$i]!=10) return false;
}
return true;
}
Here is the caller graph for this function:| Magic::get_language | ( | $ | filename | ) |
Definition at line 49 of file Magic.php.
References $lang, _is_ascii(), and load_file().
{
// First attempt a match with the filename extension.
$extensionspl = explode($this->config->separator, $filename);
$extension = $extensionspl[sizeof($extensionspl)-1];
$langstr = $this->config->extensions[$extension];
// We may have a choice of languages, so check.
$langarr = explode("|", $langstr);
// Got one language? Good!
if (sizeof($langarr)==1 && $langarr[0]!="") return $langstr;
// Now the real magic starts :o) We may have a narrowed-down set of options from
// the tests above, which will speed things up a little.
// Get one /big/ string.
$this->config->file = $this->load_file($filename);
if ($this->config->file == undef) return "illegal";
$this->is_ascii = $this->_is_ascii($this->config->file);
if (isset($langstr))
{
// We don't know if all of the types are in our magic file, so filter out those that
// aren't.
$outarray = array();
foreach($langarr as $lang)
{
if ($this->is_ascii && in_array($lang, $this->config->langfunctions))
array_push($outarray, $lang);
else if(in_array($lang, $this->config->binfunctions))
array_push($outarray, $lang);
}
$testarray = $outarray;
}
else
{
if ($this->is_ascii) $testarray = $this->config->langfunctions;
else $testarray = $this->config->binfunctions;
}
foreach($testarray as $test)
{
$func = "detect_".$test;
if ($this->config->$func()) return $test;
}
}
Here is the call graph for this function:| Magic::load_file | ( | $ | filename | ) |
Definition at line 29 of file Magic.php.
Referenced by get_language().
{
if (!($filehandle = @fopen($filename, "rb"))) return undef;
set_magic_quotes_runtime(0);
$text = fread($filehandle, filesize($filename));
set_magic_quotes_runtime(get_magic_quotes_gpc());
fclose($filehandle);
return $text;
}
Here is the caller graph for this function:| Magic::Magic | ( | ) |
Definition at line 24 of file Magic.php.
{
$this->config = new MagicConfig();
}
1.7.1