c390ccc761d8dd72fc4da53742fde1a34f48045c
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\message\embedded\object;
3 use wcf\data\object\type\ObjectType;
4 use wcf\data\DatabaseObjectDecorator;
5 use wcf\util\ArrayUtil;
6
7 /**
8 * Provides default implementations for message embedded object handlers.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2016 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.message.embedded.object
15 * @category Community Framework
16 *
17 * @method ObjectType getDecoratedObject()
18 * @mixin ObjectType
19 */
20 abstract class AbstractMessageEmbeddedObjectHandler extends DatabaseObjectDecorator implements IMessageEmbeddedObjectHandler {
21 /**
22 * @inheritDoc
23 */
24 protected static $baseClass = ObjectType::class;
25
26 /**
27 * Parses given message for specific bbcode parameters.
28 *
29 * @param string $message
30 * @param string $bbcode bbcode name
31 * @return array
32 */
33 public static function getTextParameters($message, $bbcode) {
34 if (preg_match_all('~\['.$bbcode.'\](.*?)\[/'.$bbcode.'\]~i', $message, $matches)) {
35 $results = ArrayUtil::trim($matches[1]);
36 $results = array_unique($results);
37
38 return $results;
39 }
40
41 return [];
42 }
43
44 /**
45 * Parses given message for specific bbcode parameters.
46 *
47 * @param string $message
48 * @param string $bbcode bbcode name
49 * @return array
50 */
51 public static function getFirstParameters($message, $bbcode) {
52 $pattern = '~\['.$bbcode.'=
53 (\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|(?:[^,\]]*))
54 (?:,(?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*))*
55 \]~ix';
56
57 if (preg_match_all($pattern, $message, $matches)) {
58 foreach ($matches[1] as &$value) {
59 // remove quotes
60 if (mb_substr($value, 0, 1) == "'" && mb_substr($value, -1) == "'") {
61 $value = str_replace("\'", "'", $value);
62 $value = str_replace("\\\\", "\\", $value);
63
64 $value = mb_substr($value, 1, -1);
65 }
66 }
67
68 $results = ArrayUtil::trim($matches[1]);
69 $results = array_unique($results);
70
71 return $results;
72 }
73
74 return [];
75 }
76 }