1<?php 2/** 3 * 4 * @author Timon Amstutz <timon.amstutz@ilub.unibe.ch> 5 * @version $Id$* 6 */ 7class ilSkinStyleXML 8{ 9 /** 10 * Id of the skin. Currently css and less files are named accordingely 11 * @var string 12 */ 13 protected $id = ""; 14 15 /** 16 * Name of the style visible in all UI elements 17 * 18 * @var string 19 */ 20 protected $name = ""; 21 22 /** 23 * Directory to store sound files into 24 * 25 * @var string 26 */ 27 protected $sound_directory = ""; 28 29 /** 30 * Directory to store image files into 31 * 32 * @var string 33 */ 34 protected $image_directory = ""; 35 36 /** 37 * Directory to store fonts into 38 * 39 * @var string 40 */ 41 protected $font_directory = ""; 42 43 /** 44 * Css file name of the skin 45 * 46 * @var string 47 */ 48 protected $css_file = ""; 49 50 /** 51 * Parent of the skin if set 52 * 53 * @var string 54 */ 55 protected $substyle_of = ""; 56 57 /** 58 * ilSkinStyleXML constructor. 59 * @param $id 60 * @param $name 61 * @param string $css_file 62 * @param string $image_directory 63 * @param string $font_directory 64 * @param string $sound_directory 65 * @param string $parent_style 66 * @throws ilSystemStyleException 67 */ 68 public function __construct($id, $name, $css_file = "", $image_directory = "", $font_directory = "", $sound_directory = "", $parent_style = "") 69 { 70 $this->setId($id); 71 $this->setName($name); 72 73 if ($css_file == "") { 74 $css_file = $this->getId(); 75 } 76 77 if ($image_directory == "") { 78 $image_directory = "images"; 79 } 80 81 if ($font_directory == "") { 82 $font_directory = "fonts"; 83 } 84 85 if ($sound_directory == "") { 86 $sound_directory = "sound"; 87 } 88 89 $this->setCssFile($css_file); 90 $this->setImageDirectory($image_directory); 91 $this->setFontDirectory($font_directory); 92 $this->setSoundDirectory($sound_directory); 93 $this->setSubstyleOf($parent_style); 94 } 95 96 /** 97 * @param SimpleXMLElement $xml_element 98 * @return ilSkinStyleXML 99 * @throws ilSystemStyleException 100 */ 101 public static function parseFromXMLElement(SimpleXMLElement $xml_element) 102 { 103 $style = new self( 104 (string) $xml_element->attributes()["id"], 105 (string) $xml_element->attributes()["name"], 106 (string) $xml_element->attributes()["css_file"], 107 (string) $xml_element->attributes()["image_directory"], 108 (string) $xml_element->attributes()["font_directory"], 109 (string) $xml_element->attributes()["sound_directory"] 110 ); 111 return $style; 112 } 113 114 /** 115 * @return string 116 */ 117 public function getId() 118 { 119 return $this->id; 120 } 121 122 /** 123 * @param $id 124 * @throws ilSystemStyleException 125 */ 126 public function setId($id) 127 { 128 if (strpos($id, ' ') !== false) { 129 throw new ilSystemStyleException(ilSystemStyleException::INVALID_CHARACTERS_IN_ID, $id); 130 } 131 $this->id = str_replace(" ", "_", $id); 132 } 133 134 /** 135 * @return string 136 */ 137 public function getName() 138 { 139 return $this->name; 140 } 141 142 /** 143 * @param string $name 144 */ 145 public function setName($name) 146 { 147 $this->name = $name; 148 } 149 150 /** 151 * @return string 152 */ 153 public function getSoundDirectory() 154 { 155 return $this->sound_directory; 156 } 157 158 /** 159 * @param string $sound_directory 160 */ 161 public function setSoundDirectory($sound_directory) 162 { 163 $this->sound_directory = $sound_directory; 164 } 165 166 /** 167 * @return string 168 */ 169 public function getImageDirectory() 170 { 171 return $this->image_directory; 172 } 173 174 /** 175 * @param string $image_directory 176 */ 177 public function setImageDirectory($image_directory) 178 { 179 $this->image_directory = $image_directory; 180 } 181 182 /** 183 * @return string 184 */ 185 public function getCssFile() 186 { 187 return $this->css_file; 188 } 189 190 /** 191 * @param string $css_file 192 */ 193 public function setCssFile($css_file) 194 { 195 $this->css_file = $css_file; 196 } 197 198 /** 199 * @return string 200 */ 201 public function getFontDirectory() 202 { 203 return $this->font_directory; 204 } 205 206 /** 207 * @param string $font_directory 208 */ 209 public function setFontDirectory($font_directory) 210 { 211 $this->font_directory = $font_directory; 212 } 213 214 /** 215 * Returns the parent style of this style if set 216 * 217 * @return string 218 */ 219 public function getSubstyleOf() 220 { 221 return $this->substyle_of; 222 } 223 224 /** 225 * Sets style as sub style of another 226 * 227 * @param string $substyle_of 228 */ 229 public function setSubstyleOf($substyle_of) 230 { 231 $this->substyle_of = $substyle_of; 232 } 233 234 /** 235 * Return wheter this style is a substyle of another 236 * 237 * @return bool 238 */ 239 public function isSubstyle() 240 { 241 return $this->getSubstyleOf() != ""; 242 } 243 244 /** 245 * Checks if a resource (folder) relative to the style is referenced by this style. Used to decide if folder can be deleted. 246 * 247 * @param $resource 248 * @return bool 249 */ 250 public function referencesResource($resource) 251 { 252 return $this->getCssFile() == $resource 253 || $this->getImageDirectory() == $resource 254 || $this->getFontDirectory() == $resource 255 || $this->getSoundDirectory() == $resource; 256 } 257} 258