ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Magic Class Reference
+ Collaboration diagram for Magic:

Public Member Functions

 Magic ()
 
 load_file ($filename)
 
 _is_ascii ($file)
 
 get_language ($filename)
 

Detailed Description

Definition at line 22 of file Magic.php.

Member Function Documentation

◆ _is_ascii()

Magic::_is_ascii (   $file)

Definition at line 39 of file Magic.php.

References $file.

Referenced by get_language().

40  {
41  $arr = unpack("C*", $file);
42  for($i=1; $i<sizeof($arr); $i++)
43  {
44  if ($arr[$i]<32 && $arr[$i]!=13 && $arr[$i]!=10) return false;
45  }
46  return true;
47  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the caller graph for this function:

◆ get_language()

Magic::get_language (   $filename)

Definition at line 49 of file Magic.php.

References $filename, $lang, $test, _is_ascii(), array, and load_file().

50  {
51  // First attempt a match with the filename extension.
52  $extensionspl = explode($this->config->separator, $filename);
53  $extension = $extensionspl[sizeof($extensionspl)-1];
54  $langstr = $this->config->extensions[$extension];
55  // We may have a choice of languages, so check.
56  $langarr = explode("|", $langstr);
57 
58  // Got one language? Good!
59  if (sizeof($langarr)==1 && $langarr[0]!="") return $langstr;
60 
61  // Now the real magic starts :o) We may have a narrowed-down set of options from
62  // the tests above, which will speed things up a little.
63 
64  // Get one /big/ string.
65  $this->config->file = $this->load_file($filename);
66  if ($this->config->file == undef) return "illegal";
67  $this->is_ascii = $this->_is_ascii($this->config->file);
68 
69  if (isset($langstr))
70  {
71  // We don't know if all of the types are in our magic file, so filter out those that
72  // aren't.
73 
74  $outarray = array();
75  foreach($langarr as $lang)
76  {
77  if ($this->is_ascii && in_array($lang, $this->config->langfunctions))
78  array_push($outarray, $lang);
79  else if(in_array($lang, $this->config->binfunctions))
80  array_push($outarray, $lang);
81  }
82  $testarray = $outarray;
83  }
84  else
85  {
86  if ($this->is_ascii) $testarray = $this->config->langfunctions;
87  else $testarray = $this->config->binfunctions;
88  }
89  foreach($testarray as $test)
90  {
91  $func = "detect_".$test;
92  if ($this->config->$func()) return $test;
93  }
94  }
load_file($filename)
Definition: Magic.php:29
Create styles array
The data for the language used.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
_is_ascii($file)
Definition: Magic.php:39
$test
Definition: Utf8Test.php:84
+ Here is the call graph for this function:

◆ load_file()

Magic::load_file (   $filename)

Definition at line 29 of file Magic.php.

References $filename, and $text.

Referenced by get_language().

30  {
31  if (!($filehandle = @fopen($filename, "rb"))) return undef;
32  set_magic_quotes_runtime(0);
33  $text = fread($filehandle, filesize($filename));
34  set_magic_quotes_runtime(get_magic_quotes_gpc());
35  fclose($filehandle);
36  return $text;
37  }
$text
+ Here is the caller graph for this function:

◆ Magic()

Magic::Magic ( )

Definition at line 24 of file Magic.php.

25  {
26  $this->config = new MagicConfig();
27  }

The documentation for this class was generated from the following file: