ILIAS  release_8 Revision v8.24
class.ilSkinFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
27 protected ilLanguage $lng;
28
30 {
31 $this->lng = $lng;
32
33 if ($config) {
34 $this->config = $config;
35 } else {
36 $this->config = new ilSystemStyleConfig();
37 }
38 }
39
44 public function skinFromXML(string $path = ''): ilSkin
45 {
46 try {
47 $xml = new SimpleXMLElement(file_get_contents($path));
48 } catch (Exception $e) {
50 }
51
52 $id = basename(dirname($path));
53 $skin = new ilSkin($id, (string) $xml->attributes()['name']);
54 $skin->setVersion((string) $xml->attributes()['version']);
55
59 $last_style = null;
60
61 foreach ($xml->children() as $style_xml) {
62 $style = ilSkinStyle::parseFromXMLElement($style_xml);
63
67 if ($style_xml->getName() == 'substyle') {
68 if (!$last_style) {
70 }
71 $style->setSubstyleOf($last_style->getId());
72 } else {
73 $last_style = $style;
74 }
75 $skin->addStyle($style);
76 }
77 return $skin;
78 }
79
85 public function skinStyleContainerFromId(
86 string $skin_id,
87 ilSystemStyleMessageStack $message_stack
89 if (!$skin_id) {
91 }
92
93 if ($skin_id != 'default') {
94 return new ilSkinStyleContainer(
95 $this->lng,
96 $this->skinFromXML($this->config->getCustomizingSkinPath() . $skin_id . '/template.xml'),
97 $message_stack,
98 $this->config
99 );
100 } else {
101 return new ilSkinStyleContainer(
102 $this->lng,
103 $this->skinFromXML($this->config->getDefaultTemplatePath()),
104 $message_stack,
105 $this->config,
106 );
107 }
108 }
109
115 string $import_zip_path,
116 string $name,
117 ilSystemStyleMessageStack $message_stack
119 $skin_id = preg_replace('/[^A-Za-z0-9\-_]/', '', rtrim($name, '.zip'));
120
121 while (ilStyleDefinition::skinExists($skin_id, $this->config)) {
122 $skin_id .= 'Copy';
123 }
124
125 $skin_path = $this->config->getCustomizingSkinPath() . $skin_id;
126
127 mkdir($skin_path, 0775, true);
128
129 $temp_zip_path = $skin_path . '/' . $name;
130 rename($import_zip_path, $temp_zip_path);
131
132 ilFileUtils::unzip($temp_zip_path);
133 unlink($temp_zip_path);
134
135 return $this->skinStyleContainerFromId($skin_id, $message_stack);
136 }
137
144 ilFileSystemHelper $file_system,
145 ilSystemStyleMessageStack $message_stack,
146 string $new_skin_txt_addon = 'Copy'
148 $new_skin_id_addon = '';
149 $new_skin_name_addon = '';
150
152 $container->getSkin()->getId() . $new_skin_id_addon,
153 $container->getSystemStylesConf()
154 )) {
155 $new_skin_id_addon .= $new_skin_txt_addon;
156 $new_skin_name_addon .= ' ' . $new_skin_txt_addon;
157 }
158
159 $new_skin_path = rtrim($container->getSkinDirectory(), '/') . $new_skin_id_addon;
160
161 mkdir($new_skin_path, 0775, true);
162 $file_system->recursiveCopy($container->getSkinDirectory(), $new_skin_path);
163 $skin_container = $this->skinStyleContainerFromId($container->getSkin()->getId() . $new_skin_id_addon, $message_stack);
164 $skin_container->getSkin()->setName($skin_container->getSkin()->getName() . $new_skin_name_addon);
165 $skin_container->getSkin()->setVersion('0.1');
166 $skin_container->updateSkin($skin_container->getSkin());
167 return $skin_container;
168 }
169}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
File System Helper, to reduce deps.
recursiveCopy(string $src, string $dest)
Recursive copy of a folder.
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
language handling
Factory to create Skin classes holds an manages the basic data of a skin as provide by the template o...
skinStyleContainerFromId(string $skin_id, ilSystemStyleMessageStack $message_stack)
Get container class is responsible for all file system related actions related actions of a skin such...
skinStyleContainerFromZip(string $import_zip_path, string $name, ilSystemStyleMessageStack $message_stack)
Imports a skin from zip.
__construct(ilLanguage $lng, ?ilSystemStyleConfig $config=null)
copyFromSkinStyleContainer(ilSkinStyleContainer $container, ilFileSystemHelper $file_system, ilSystemStyleMessageStack $message_stack, string $new_skin_txt_addon='Copy')
Copies a complete Skin.
ilSystemStyleConfig $config
This class is responsible for all file system related actions related actions of a skin such as copyi...
static parseFromXMLElement(SimpleXMLElement $xml_element)
ilSkin holds an manages the basic data of a skin as provide by the template of the skin.
static skinExists(string $skin_id, ?ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
ilSystemStyleConfig wraps all 'constants' to ensure the testability of all classes using those 'const...
Class for advanced editing exception handling in ILIAS.
Used to stack messages to be shown to the user.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$path
Definition: ltiservices.php:32
if($format !==null) $name
Definition: metadata.php:247
$xml
Definition: metadata.php:351
$container
@noRector
Definition: wac.php:14