1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
fabric.php
См. документацию.
1<?php
16class Fabric
17{
18 protected static array $defaultFunctionMap = [
19 'upper' => FunctionUpper::class,
20 'lower' => FunctionLower::class,
21 'translit' => FunctionTranslit::class,
22 'concat' => FunctionConcat::class,
23 'limit' => FunctionLimit::class,
24 'contrast' => FunctionContrast::class,
25 'min' => FunctionMin::class,
26 'max' => FunctionMax::class,
27 'distinct' => FunctionDistinct::class,
28 'ucfirst' => FunctionUcfirst::class,
29 'ucwords' => FunctionUcwords::class,
30 'striptags' => FunctionStripTags::class,
31 ];
32
33 protected static array $functionMap = [];
42 public static function createInstance($functionName, $data = null) //todo rename createInstance
43 {
44 if (!is_string($functionName))
45 {
46 return new FunctionBase($data);
47 }
48 if (isset(self::$defaultFunctionMap[$functionName]))
49 {
51 $functionClass = self::$defaultFunctionMap[$functionName];
52 return new $functionClass($data);
53 }
54 elseif (isset(self::$functionMap[$functionName]))
55 {
57 $functionClass = self::$functionMap[$functionName];
58 return new $functionClass($data);
59 }
60 else
61 {
62 $event = new \Bitrix\Main\Event("iblock", "OnTemplateGetFunctionClass", array($functionName));
63 $event->send();
64 if ($event->getResults())
65 {
66 foreach($event->getResults() as $evenResult)
67 {
68 if($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS)
69 {
70 $functionClass = $evenResult->getParameters();
71 if (is_string($functionClass) && class_exists($functionClass))
72 {
73 self::$functionMap[$functionName] = $functionClass;
74 }
75 break;
76 }
77 }
78 }
79 if (isset(self::$functionMap[$functionName]))
80 {
81 $functionClass = self::$functionMap[$functionName];
82 return new $functionClass($data);
83 }
84 }
85
86 return new FunctionBase($data);
87 }
88}
89
97{
98 protected $data = null;
99
103 function __construct($data = null)
104 {
105 $this->data = $data;
106 }
107
115 public function onPrepareParameters(\Bitrix\Iblock\Template\Entity\Base $entity, array $parameters)
116 {
117 $arguments = array();
119 foreach ($parameters as $parameter)
120 {
121 $arguments[] = $parameter->process($entity);
122 }
123 return $arguments;
124 }
125
133 public function calculate(array $parameters)
134 {
135 return "";
136 }
137
145 protected function parametersToString(array $parameters)
146 {
147 $result = array();
148 foreach ($parameters as $param)
149 {
150 if (is_array($param))
151 $result[] = implode(" ", $param);
152 elseif ($param != "")
153 $result[] = $param;
154 }
155 return implode(" ", $result);
156 }
157
165 protected function parametersToArray(array $parameters)
166 {
167 $result = array();
168 foreach ($parameters as $param)
169 {
170 if (is_array($param))
171 {
172 foreach ($param as $p)
173 $result[] = $p;
174 }
175 elseif ($param != "")
176 {
177 $result[] = $param;
178 }
179 }
180 return $result;
181 }
182}
183
191{
199 public function calculate(array $parameters)
200 {
201 return mb_strtoupper($this->parametersToString($parameters));
202 }
203}
204
212{
220 public function calculate(array $parameters)
221 {
222 return mb_strtolower($this->parametersToString($parameters));
223 }
224}
225
233{
241 public function calculate(array $parameters)
242 {
243 $changeCase = false;
244 $replaceChar = "";
245
246 if (
247 isset($this->data)
248 && isset($this->data["replace_space"])
249 && $this->data["replace_space"] != ""
250 )
251 {
252 $changeCase = isset($this->data[""])? $this->data["change_case"]: false;
253 $replaceChar = $this->data["replace_space"];
254 }
255
256 if (
257 isset($this->data)
258 && isset($this->data["change_case"])
259 && $this->data["change_case"] != ""
260 )
261 {
262 $changeCase = $this->data["change_case"];
263 }
264
265
266 return \CUtil::translit($this->parametersToString($parameters), LANGUAGE_ID, array(
267 //"max_len" => 50,
268 "change_case" => $changeCase, // 'L' - toLower, 'U' - toUpper, false - do not change
269 "replace_space" => $replaceChar,
270 "replace_other" => $replaceChar,
271 "delete_repeat_replace" => true,
272 ));
273 }
274}
275
283{
291 public function calculate(array $parameters)
292 {
293 $result = $this->parametersToArray($parameters);
294 $delimiter = array_pop($result);
295
296 return implode($delimiter, $result);
297 }
298}
299
307{
315 public function calculate(array $parameters)
316 {
317 $result = $this->parametersToArray($parameters);
318 $limit = array_pop($result);
319 $delimiter = array_pop($result);
320 $text = implode(" ", $result);
321
322 $result = preg_split("/([".preg_quote($delimiter, "/")."]+)/", $text);
323 return array_slice($result, 0, $limit);
324 }
325}
326
334{
342 public function calculate(array $parameters)
343 {
344 $result = $this->parametersToArray($parameters);
345 $limit = array_pop($result);
346 $delimiter = array_pop($result);
347 $text = strip_tags(implode(" ", $result));
348
349 $words = array();
350 $result = preg_split("/([".preg_quote($delimiter, "/")."]+)/", $text);
351 if ($result)
352 {
353 foreach ($result as $word)
354 {
355 if (mb_strlen($word) > 1)
356 $words[$word]++;
357 }
358 $len = log(max(20, array_sum($words)));
359 foreach ($words as $word => $count)
360 {
361 $words[$word] = log($count + 1) / $len;
362 }
363 arsort($words);
364 }
365 return array_keys(array_slice($words, 0, $limit));
366 }
367}
368
376{
384 public function calculate(array $parameters)
385 {
386 $result = $this->parametersToArray($parameters);
387 $asFloat = [];
388 foreach ($result as $rawValue)
389 {
390 if (!isset($asFloat[$rawValue]))
391 {
392 $value = preg_replace("/&\#[0-9]+;/", '', $rawValue);
393 $floatFalue = (float)preg_replace("/[^0-9.]+/", "", $value);
394 $asFloat[$rawValue] = $floatFalue;
395 }
396 }
397
398 if (empty($asFloat))
399 {
400 return '';
401 }
402 elseif (count($asFloat) == 1)
403 {
404 return end($result);
405 }
406 else
407 {
408 $min = min($asFloat);
409
410 return array_search($min, $asFloat);
411 }
412 }
413}
414
422{
430 public function calculate(array $parameters)
431 {
432 $result = $this->parametersToArray($parameters);
433 $asFloat = [];
434 foreach ($result as $rawValue)
435 {
436 if (!isset($asFloat[$rawValue]))
437 {
438 $value = preg_replace("/&\#[0-9]+;/", '', $rawValue);
439 $floatFalue = (float)preg_replace("/[^0-9.]+/", '', $value);
440 $asFloat[$rawValue] = $floatFalue;
441 }
442 }
443 if (empty($asFloat))
444 {
445 return '';
446 }
447 elseif (count($asFloat) == 1)
448 {
449 return end($result);
450 }
451 else
452 {
453 $max = max($asFloat);
454
455 return array_search($max, $asFloat);
456 }
457 }
458}
459
467{
475 public function calculate(array $parameters)
476 {
477 $result = array();
478 foreach ($this->parametersToArray($parameters) as $value)
479 $result[$value] = $value;
480 return array_values($result);
481 }
482}
$count
Определения admin_tab.php:4
Определения iblock.php:18
static array $functionMap
Определения fabric.php:33
static array $defaultFunctionMap
Определения fabric.php:18
parametersToArray(array $parameters)
Определения fabric.php:165
calculate(array $parameters)
Определения fabric.php:133
parametersToString(array $parameters)
Определения fabric.php:145
calculate(array $parameters)
Определения fabric.php:291
calculate(array $parameters)
Определения fabric.php:342
calculate(array $parameters)
Определения fabric.php:475
calculate(array $parameters)
Определения fabric.php:315
calculate(array $parameters)
Определения fabric.php:220
calculate(array $parameters)
Определения fabric.php:430
calculate(array $parameters)
Определения fabric.php:384
calculate(array $parameters)
Определения fabric.php:241
calculate(array $parameters)
Определения fabric.php:199
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
$p
Определения group_list_element_edit.php:23
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$text
Определения template_pdf.php:79
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$max
Определения template_copy.php:262