ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSystemStyleIcon.php
Go to the documentation of this file.
1 <?php
2 include_once("Services/Style/System/classes/Icons/class.ilSystemStyleIconColorSet.php");
3 
4 
12 {
13 
18  protected $path = "";
19 
24  protected $name = "";
25 
30  protected $type = "";
31 
37  protected $color_set = null;
38 
45  public function __construct($name, $path, $type)
46  {
47  $this->setName($name);
48  $this->setType($type);
49  $this->setPath($path);
50  }
51 
52 
57  public function changeColors(array $color_changes)
58  {
59  if ($this->getType() == "svg") {
60  $icon = file_get_contents($this->getPath());
61  foreach ($color_changes as $old_color => $new_color) {
62  $icon = preg_replace('/' . $old_color . '/i', $new_color, $icon, -1);
63  }
64  file_put_contents($this->getPath(), $icon);
65  }
66  $this->extractColorSet();
67  }
68 
72  public function getType()
73  {
74  return $this->type;
75  }
76 
80  public function setType($type)
81  {
82  $this->type = $type;
83  }
84 
88  public function getName()
89  {
90  return $this->name;
91  }
92 
96  public function setName($name)
97  {
98  $this->name = $name;
99  }
100 
101 
105  public function __toString()
106  {
107  return $this->getName();
108  }
109 
113  public function getPath()
114  {
115  return $this->path;
116  }
117 
121  public function setPath($path)
122  {
123  $this->path = $path;
124  }
125 
131  public function getDirRelToCustomizing()
132  {
133  return dirname(strstr($this->getPath(), 'global/skin'));
134  }
135 
139  public function getColorSet()
140  {
141  if (!$this->color_set) {
142  $this->extractColorSet();
143  }
144  return $this->color_set;
145  }
146 
150  protected function extractColorSet()
151  {
152  $regex_for_extracting_color = '/(?<=#)[\dabcdef]{6}/i';
153 
154  $this->color_set = new ilSystemStyleIconColorSet();
155  if ($this->getType() == "svg") {
156  $icon_content = file_get_contents($this->getPath());
157  $color_matches = [];
158  preg_match_all($regex_for_extracting_color, $icon_content, $color_matches);
159  if (is_array($color_matches) && is_array($color_matches[0])) {
160  foreach ($color_matches[0] as $color_value) {
161  $numeric = strtoupper(str_replace("#", "", $color_value));
162  $color = new ilSystemStyleIconColor($numeric, $color_value, $numeric, $color_value);
163  $this->getColorSet()->addColor($color);
164  }
165  }
166  }
167  }
168 
172  public function setColorSet($color_set)
173  {
174  $this->color_set = $color_set;
175  }
176 
181  public function usesColor($color_id)
182  {
183  return $this->getColorSet()->doesColorExist($color_id);
184  }
185 }
__construct($name, $path, $type)
ilSystemStyleIcon constructor.
extractColorSet()
Extracts all colors from the icon by parsing the svg file for a regular expresion.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon. ...
Create styles array
The data for the language used.
getDirRelToCustomizing()
Only get dir rel to the Customizing dir without name and extension from.
changeColors(array $color_changes)
Changes colors in the svg file of the icon and updates the icon abstraction by extracting the colors ...