3 namespace wcf\data\template
;
5 use wcf\data\DatabaseObject
;
6 use wcf\data\package\PackageCache
;
7 use wcf\system\application\ApplicationHandler
;
12 * Represents a template.
14 * @author Alexander Ebert
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\Template
19 * @property-read int $templateID unique id of the template
20 * @property-read int $packageID id of the package which delivers the template
21 * @property-read string $templateName name of the template
22 * @property-read string $application abbreviation of the application to which the template belongs
23 * @property-read int|null $templateGroupID id of the template group to which the template belongs or `null` if the template belongs to no template group
24 * @property-read int $lastModificationTime timestamp at which the template has been edited the last time
26 class Template
extends DatabaseObject
29 * list of system critical templates
32 protected static $systemCriticalTemplates = ['headIncludeJavaScript', 'wysiwyg', 'wysiwygToolbar'];
34 /** @noinspection PhpMissingParentConstructorInspection */
39 public function __construct($id, $row = null, ?DatabaseObject
$object = null)
42 $sql = "SELECT template.*, template_group.templateGroupFolderName,
44 FROM wcf" . WCF_N
. "_template template
45 LEFT JOIN wcf" . WCF_N
. "_template_group template_group
46 ON (template_group.templateGroupID = template.templateGroupID)
47 LEFT JOIN wcf" . WCF_N
. "_package package
48 ON (package.packageID = template.packageID)
49 WHERE template.templateID = ?";
50 $statement = WCF
::getDB()->prepareStatement($sql);
51 $statement->execute([$id]);
52 $row = $statement->fetchArray();
55 // get relative directory of the template the application
57 if ($row['application'] != 'wcf') {
58 $application = ApplicationHandler
::getInstance()->getApplication($row['application']);
60 $application = ApplicationHandler
::getInstance()->getWCF();
62 $row['packageDir'] = PackageCache
::getInstance()->getPackage($application->packageID
)->packageDir
;
66 } elseif ($object !== null) {
70 $this->handleData($row);
74 * Returns the path to this template.
78 public function getPath()
80 /** @noinspection PhpUndefinedFieldInspection */
81 return FileUtil
::getRealPath(WCF_DIR
. $this->packageDir
) . 'templates/' . $this->templateGroupFolderName
. $this->templateName
. '.tpl';
85 * Returns the source of this template.
89 public function getSource()
91 return @\file_get_contents
($this->getPath());
95 * Returns true if current template is considered system critical and
96 * may not be customized at any point.
100 public function canCopy()
102 if (self
::isSystemCritical($this->templateName
)) {
103 // system critical templates cannot be modified, because whatever the
104 // gain of a customized version is, the damage potential is much higher
112 * Returns true if current template is considered system critical and
113 * may not be customized at any point.
115 * @param string $templateName
118 public static function isSystemCritical($templateName)
120 return \
in_array($templateName, self
::$systemCriticalTemplates);