Add missing `license` element in `package.xsd`
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / page / content / PageContent.class.php
1 <?php
2 namespace wcf\data\page\content;
3 use wcf\data\DatabaseObject;
4 use wcf\data\ILinkableObject;
5 use wcf\system\html\output\HtmlOutputProcessor;
6 use wcf\system\html\simple\HtmlSimpleParser;
7 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
8 use wcf\system\request\LinkHandler;
9 use wcf\system\WCF;
10
11 /**
12 * Represents a page content.
13 *
14 * @author Marcel Werk
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Data\Page\Content
18 * @since 3.0
19 *
20 * @property-read integer $pageContentID unique id of the page content
21 * @property-read integer $pageID id of the page the page content belongs to
22 * @property-read integer $languageID id of the page content's language
23 * @property-read string $title title of the page in the associated language
24 * @property-read string $content actual content of the page in the associated language
25 * @property-read string $metaDescription meta description of the page in the associated language
26 * @property-read string $metaKeywords meta keywords of the page in the associated language
27 * @property-read string $customURL custom url of the page in the associated language
28 * @property-read integer $hasEmbeddedObjects is `1` if the page content contains embedded objects, otherwise `0`
29 */
30 class PageContent extends DatabaseObject implements ILinkableObject {
31 /**
32 * @inheritDoc
33 */
34 protected static $databaseTableName = 'page_content';
35
36 /**
37 * @inheritDoc
38 */
39 protected static $databaseTableIndexName = 'pageContentID';
40
41 /**
42 * Returns the page's formatted content.
43 *
44 * @return string
45 */
46 public function getFormattedContent() {
47 MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.page.content', [$this->pageContentID]);
48
49 $processor = new HtmlOutputProcessor();
50 $processor->process($this->content, 'com.woltlab.wcf.page.content', $this->pageContentID);
51
52 return $processor->getHtml();
53 }
54
55 /**
56 * Parses simple placeholders embedded in raw html.
57 *
58 * @return string parsed content
59 */
60 public function getParsedContent() {
61 MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.page.content', [$this->pageContentID]);
62
63 return HtmlSimpleParser::getInstance()->replaceTags('com.woltlab.wcf.page.content', $this->pageContentID, $this->content);
64 }
65
66 /**
67 * Parses simple placeholders embedded in HTML with template scripting.
68 *
69 * @param string $templateName content template name
70 * @return string parsed template
71 */
72 public function getParsedTemplate($templateName) {
73 MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.page.content', [$this->pageContentID]);
74 HtmlSimpleParser::getInstance()->setContext('com.woltlab.wcf.page.content', $this->pageContentID);
75
76 WCF::getTPL()->registerPrefilter(['simpleEmbeddedObject']);
77
78 $returnValue = WCF::getTPL()->fetch($templateName);
79
80 WCF::getTPL()->removePrefilter('simpleEmbeddedObject');
81
82 return $returnValue;
83 }
84
85 /**
86 * Returns a certain page content.
87 *
88 * @param integer $pageID
89 * @param integer $languageID
90 * @return PageContent|null
91 */
92 public static function getPageContent($pageID, $languageID) {
93 if ($languageID !== null) {
94 $sql = "SELECT *
95 FROM wcf" . WCF_N . "_page_content
96 WHERE pageID = ?
97 AND languageID = ?";
98 $statement = WCF::getDB()->prepareStatement($sql);
99 $statement->execute([$pageID, $languageID]);
100 }
101 else {
102 $sql = "SELECT *
103 FROM wcf" . WCF_N . "_page_content
104 WHERE pageID = ?
105 AND languageID IS NULL";
106 $statement = WCF::getDB()->prepareStatement($sql);
107 $statement->execute([$pageID]);
108 }
109
110 if (($row = $statement->fetchSingleRow()) !== false) {
111 return new PageContent(null, $row);
112 }
113
114 return null;
115 }
116
117 /**
118 * @inheritDoc
119 */
120 public function getLink() {
121 return LinkHandler::getInstance()->getCmsLink($this->pageID, $this->languageID);
122 }
123 }