2 namespace wcf\data\smiley
;
3 use wcf\data\DatabaseObject
;
4 use wcf\data\ITitledObject
;
6 use wcf\util\StringUtil
;
11 * @author Alexander Ebert
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\Data\Smiley
16 * @property-read integer $smileyID unique id of the smiley
17 * @property-read integer $packageID id of the package which delivers the smiley
18 * @property-read integer|null $categoryID id of the category the smiley belongs to or `null` if it belongs to the default category
19 * @property-read string $smileyPath path to the smiley file relative to wcf's default path
20 * @property-read string $smileyPath2x path to the smiley file relative to wcf's default path (2x version)
21 * @property-read string $smileyTitle title of the smiley or name of language item that contains the title
22 * @property-read string $smileyCode code used for displaying the smiley
23 * @property-read string $aliases alternative codes used for displaying the smiley
24 * @property-read integer $showOrder position of the smiley in relation to the other smileys in the same category
26 class Smiley
extends DatabaseObject
implements ITitledObject
{
35 public function getTitle() {
36 return WCF
::getLanguage()->get($this->smileyTitle
);
40 * Returns the url to this smiley.
44 public function getURL() {
45 return WCF
::getPath().$this->smileyPath
;
49 * Returns the url to the 2x version of the smiley.
53 public function getURL2x() {
54 return ($this->smileyPath2x
) ? WCF
::getPath().$this->smileyPath2x
: '';
58 * Returns all aliases for this smiley.
62 public function getAliases() {
63 if (!$this->aliases
) return [];
65 return explode("\n", StringUtil
::unifyNewlines($this->aliases
));
69 * Returns the height of the smiley.
73 public function getHeight() {
74 if ($this->height
=== null) {
77 $file = WCF_DIR
. $this->smileyPath
;
78 if (file_exists($file) && preg_match('~\.(gif|jpe?g|png)$~', $file)) {
79 $data = getimagesize($file);
80 if ($data !== false) {
81 // index '1' contains the height of the image
82 $this->height
= $data[1];
91 * Returns the html code to render the smiley.
93 * @param string $class (additional) class(es) of the smiley element
96 public function getHtml($class = '') {
97 $srcset = ($this->smileyPath2x
) ?
' srcset="' . StringUtil
::encodeHTML($this->getURL2x()) . ' 2x"' : '';
98 $height = ($this->getHeight()) ?
' height="' . $this->getHeight() . '"' : '';
100 $class = ' ' . $class;
103 $title = StringUtil
::encodeHTML(WCF
::getLanguage()->get($this->smileyTitle
));
105 return '<img src="' . StringUtil
::encodeHTML($this->getURL()) . '" alt="' . StringUtil
::encodeHTML($this->smileyCode
) . '" title="' . $title . '" class="smiley' . $class . '"' . $srcset . $height . '>';