ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSystemStyleIcon.php
Go to the documentation of this file.
1<?php
2include_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 if($this->getType() == "svg"){
59 $icon = file_get_contents($this->getPath());
60 foreach($color_changes as $old_color => $new_color){
61 $icon = preg_replace ( '/'.$old_color.'/i' , $new_color, $icon, -1 );
62 }
63 file_put_contents ($this->getPath(),$icon);
64 }
65 $this->extractColorSet();
66 }
67
71 public function getType()
72 {
73 return $this->type;
74 }
75
79 public function setType($type)
80 {
81 $this->type = $type;
82 }
83
87 public function getName()
88 {
89 return $this->name;
90 }
91
95 public function setName($name)
96 {
97 $this->name = $name;
98 }
99
100
104 public function __toString()
105 {
106 return $this->getName();
107 }
108
112 public function getPath()
113 {
114 return $this->path;
115 }
116
120 public function setPath($path)
121 {
122 $this->path = $path;
123 }
124
128 public function getColorSet()
129 {
130 if(!$this->color_set){
131 $this->extractColorSet();
132 }
133 return $this->color_set;
134 }
135
139 protected function extractColorSet(){
140 $regex_for_extracting_color = '/(?<=#)[\dabcdef]{6}/i';
141
142 $this->color_set = new ilSystemStyleIconColorSet();
143 if($this->getType() == "svg"){
144 $icon_content = file_get_contents($this->getPath());
145 $color_matches = [];
146 preg_match_all ($regex_for_extracting_color ,$icon_content,$color_matches);
147 if(is_array($color_matches) && is_array($color_matches[0]))
148 foreach($color_matches[0] as $color_value){
149 $numeric = strtoupper(str_replace("#","",$color_value));
150 $color = new ilSystemStyleIconColor($numeric,$color_value,$numeric,$color_value);
151 $this->getColorSet()->addColor($color);
152 }
153 }
154 }
155
159 public function setColorSet($color_set)
160 {
161 $this->color_set = $color_set;
162 }
163
168 public function usesColor($color_id){
169 return $this->getColorSet()->doesColorExist($color_id);
170 }
171}
An exception for terminatinating execution or to throw for unit testing.
Abstracts an Icon and the necessary actions to get all colors out of an svg Icon.
__construct($name, $path, $type)
ilSystemStyleIcon constructor.
extractColorSet()
Extracts all colors from the icon by parsing the svg file for a regular expresion.
changeColors(array $color_changes)
Changes colors in the svg file of the icon and updates the icon abstraction by extracting the colors ...