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