ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 41 of file Magic.php.

References $file, and $i.

Referenced by get_language().

42  {
43  $arr = unpack("C*", $file);
44  for ($i=1; $i<sizeof($arr); $i++) {
45  if ($arr[$i]<32 && $arr[$i]!=13 && $arr[$i]!=10) {
46  return false;
47  }
48  }
49  return true;
50  }
$i
Definition: disco.tpl.php:19
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 52 of file Magic.php.

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

53  {
54  // First attempt a match with the filename extension.
55  $extensionspl = explode($this->config->separator, $filename);
56  $extension = $extensionspl[sizeof($extensionspl)-1];
57  $langstr = $this->config->extensions[$extension];
58  // We may have a choice of languages, so check.
59  $langarr = explode("|", $langstr);
60 
61  // Got one language? Good!
62  if (sizeof($langarr)==1 && $langarr[0]!="") {
63  return $langstr;
64  }
65 
66  // Now the real magic starts :o) We may have a narrowed-down set of options from
67  // the tests above, which will speed things up a little.
68 
69  // Get one /big/ string.
70  $this->config->file = $this->load_file($filename);
71  if ($this->config->file == undef) {
72  return "illegal";
73  }
74  $this->is_ascii = $this->_is_ascii($this->config->file);
75 
76  if (isset($langstr)) {
77  // We don't know if all of the types are in our magic file, so filter out those that
78  // aren't.
79 
80  $outarray = array();
81  foreach ($langarr as $lang) {
82  if ($this->is_ascii && in_array($lang, $this->config->langfunctions)) {
83  array_push($outarray, $lang);
84  } elseif (in_array($lang, $this->config->binfunctions)) {
85  array_push($outarray, $lang);
86  }
87  }
88  $testarray = $outarray;
89  } else {
90  if ($this->is_ascii) {
91  $testarray = $this->config->langfunctions;
92  } else {
93  $testarray = $this->config->binfunctions;
94  }
95  }
96  foreach ($testarray as $test) {
97  $func = "detect_" . $test;
98  if ($this->config->$func()) {
99  return $test;
100  }
101  }
102  }
load_file($filename)
Definition: Magic.php:29
Create styles array
The data for the language used.
_is_ascii($file)
Definition: Magic.php:41
$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"))) {
32  return undef;
33  }
34  set_magic_quotes_runtime(0);
35  $text = fread($filehandle, filesize($filename));
36  set_magic_quotes_runtime(get_magic_quotes_gpc());
37  fclose($filehandle);
38  return $text;
39  }
$text
Definition: errorreport.php:18
+ 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: