Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
helper.php
1<?php
13class Helper
14{
23 public static function splitTemplate($template)
24 {
25 if (preg_match("/\\/(l|t.?)+\$/", $template, $match))
26 {
27 return array(mb_substr($template, 0, -mb_strlen($match[0])), mb_substr($match[0], 1));
28 }
29 else
30 {
31 return array($template, "");
32 }
33 }
34
42 public static function splitModifiers($modifiers)
43 {
44 if (preg_match_all("/(l|t.?)/", $modifiers, $match))
45 return $match[0];
46 else
47 return array();
48 }
49
57 public static function convertArrayToModifiers(array $template)
58 {
59 $TEMPLATE = $template["TEMPLATE"] ?? '';
60 $modifiers = "";
61 if (isset($template["LOWER"]) && $template["LOWER"] === "Y")
62 {
63 $modifiers .= "l";
64 }
65 if (isset($template["TRANSLIT"]) && $template["TRANSLIT"] === "Y")
66 {
67 $modifiers .= "t";
68 if (isset($template["SPACE"]) && is_string($template["SPACE"]) && $template["SPACE"] !== "")
69 {
70 $modifiers .= $template["SPACE"];
71 }
72 }
73 if ($modifiers !== "")
74 {
75 $modifiers = "/" . $modifiers;
76 }
77
78 return $TEMPLATE.$modifiers;
79 }
80
90 public static function convertModifiersToArray(array $template = null)
91 {
92 if ($template === null)
93 {
94 $template = array(
95 "TEMPLATE" => "",
96 );
97 }
98
99 $TEMPLATE = $template["TEMPLATE"];
100 $LOWER = "N";
101 $TRANSLIT = "N";
102 $SPACE = "";
103
104 [$TEMPLATE, $modifiers] = self::splitTemplate($TEMPLATE);
105 foreach(self::splitModifiers($modifiers) as $mod)
106 {
107 if ($mod == "l")
108 {
109 $LOWER = "Y";
110 }
111 else
112 {
113 $TRANSLIT = "Y";
114 $SPACE = mb_substr($mod, 1);
115 }
116 }
117
118 $template["TEMPLATE"] = $TEMPLATE;
119 $template["LOWER"] = $LOWER;
120 $template["TRANSLIT"] = $TRANSLIT;
121 $template["SPACE"] = $SPACE;
122
123 return $template;
124 }
125
136 public static function makeFileName(
137 \Bitrix\Iblock\InheritedProperty\BaseTemplate $ipropTemplates,
138 string $templateName,
139 array $fields,
140 array $file
141 ): string
142 {
143 if (!isset($file['name']))
144 {
145 return '';
146 }
147
148 if (preg_match("/^(.+)(\\.[a-zA-Z0-9]+)\$/", $file["name"], $fileName))
149 {
150 if (!isset($fields["IPROPERTY_TEMPLATES"]) || $fields["IPROPERTY_TEMPLATES"][$templateName] == "")
151 {
152 $templates = $ipropTemplates->findTemplates();
153 $TEMPLATE = ($templates[$templateName]["TEMPLATE"] ?? '');
154 }
155 else
156 {
157 $TEMPLATE = $fields["IPROPERTY_TEMPLATES"][$templateName];
158 }
159
160 if ($TEMPLATE != "")
161 {
162 [$template, $modifiers] = Helper::splitTemplate($TEMPLATE);
163 if ($template != "")
164 {
165 $values = $ipropTemplates->getValuesEntity();
166 $entity = $values->createTemplateEntity();
167 $entity->setFields($fields);
168 return \Bitrix\Iblock\Template\Engine::process($entity, $TEMPLATE).$fileName[2];
169 }
170 elseif ($modifiers != "")
171 {
172 $simpleTemplate = new NodeRoot;
173 $simpleTemplate->addChild(new NodeText($fileName[1]));
174 $simpleTemplate->setModifiers($modifiers);
175 $baseEntity = new Entity\Base(0);
176 return $simpleTemplate->process($baseEntity).$fileName[2];
177 }
178 }
179 }
180
181 return $file["name"];
182 }
183}
static makeFileName(\Bitrix\Iblock\InheritedProperty\BaseTemplate $ipropTemplates, string $templateName, array $fields, array $file)
Definition helper.php:136
static convertArrayToModifiers(array $template)
Definition helper.php:57
static convertModifiersToArray(array $template=null)
Definition helper.php:90
static splitModifiers($modifiers)
Definition helper.php:42
static splitTemplate($template)
Definition helper.php:23
addChild(NodeBase $child)
Definition engine.php:268