83b33384a8a73331d7f88144cefabc92418c311a
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\message\embedded\object;
3 use wcf\data\page\Page;
4 use wcf\data\page\PageCache;
5
6 /**
7 * Parses embedded pages and outputs their link or title.
8 *
9 * @author Alexander Ebert
10 * @copyright 2001-2016 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package WoltLabSuite\Core\System\Message\Embedded\Object
13 */
14 class PageMessageEmbeddedObjectHandler extends AbstractSimpleMessageEmbeddedObjectHandler {
15 /**
16 * @inheritDoc
17 */
18 public function loadObjects(array $objectIDs) {
19 $pages = [];
20
21 foreach ($objectIDs as $objectID) {
22 $page = PageCache::getInstance()->getPage($objectID);
23 if ($page !== null) {
24 $pages[$objectID] = $page;
25 }
26 }
27
28 return $pages;
29 }
30
31 /**
32 * @inheritDoc
33 */
34 public function validateValues($objectType, $objectID, array $values) {
35 return array_filter($values, function($value) {
36 return (PageCache::getInstance()->getPage($value) !== null);
37 });
38 }
39
40 /**
41 * @inheritDoc
42 */
43 public function replaceSimple($objectType, $objectID, $value, array $attributes) {
44 /** @var Page $page */
45 $page = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.page', $value);
46 if ($page === null) {
47 return null;
48 }
49
50 $return = (!empty($attributes['return'])) ? $attributes['return'] : 'link';
51 switch ($return) {
52 case 'title':
53 return $page->getTitle();
54 break;
55
56 case 'link':
57 default:
58 return $page->getLink();
59 break;
60 }
61 }
62 }