-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathAd.class.php
More file actions
95 lines (82 loc) · 2.86 KB
/
Ad.class.php
File metadata and controls
95 lines (82 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace wcf\data\ad;
use wcf\data\condition\Condition;
use wcf\data\DatabaseObject;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\ad\location\IAdLocation;
use wcf\system\condition\ConditionHandler;
use wcf\system\request\IRouteController;
use wcf\system\WCF;
use wcf\util\StringUtil;
/**
* Represents an ad.
*
* @author Matthias Schmidt
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @property-read int $adID unique id of the ad
* @property-read int $objectTypeID id of the `com.woltlab.wcf.adLocation` object type
* @property-read string $adName name of the ad shown in ACP
* @property-read ?string $ad ad text
* @property-read 0|1 $isDisabled is `1` if the ad is disabled and thus not shown, otherwise `0`
* @property-read int $showOrder position of the ad in relation to the other ads at the same location
*/
class Ad extends DatabaseObject implements IRouteController
{
/**
* Returns the conditions of the ad.
*
* @return Condition[]
*/
public function getConditions()
{
return ConditionHandler::getInstance()->getConditions('com.woltlab.wcf.condition.ad', $this->adID);
}
/**
* Returns the location of the ad.
*
* @return string
*/
public function getLocation()
{
$objectType = ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID);
$location = WCF::getLanguage()->get('wcf.acp.ad.location.' . $objectType->objectType);
if ($objectType->categoryname != 'com.woltlab.wcf.global') {
$location = WCF::getLanguage()->get('wcf.acp.ad.location.category.' . $objectType->categoryname) . ': ' . $location;
}
return $location;
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return $this->adName;
}
/**
* Returns the HTML code used to display the ad.
*
* @return string
* @since 5.2
*/
public function getHtmlCode()
{
$output = $this->ad;
$objectType = ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID);
if (WCF::getUser()->userID) {
$output = \strtr($output, ['{$username}' => StringUtil::encodeHTML(WCF::getUser()->username)]);
} else {
$output = \strtr(
$output,
['{$username}' => StringUtil::encodeHTML(WCF::getLanguage()->get('wcf.user.guest'))]
);
}
if ($objectType->className && \is_subclass_of($objectType->className, IAdLocation::class)) {
/** @var IAdLocation $adLocation */
$adLocation = $objectType->getProcessor();
$output = $adLocation->replaceVariables($output);
}
return $output;
}
}