|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Tag; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* XOOPS tag management module |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright {@link https://sourceforge.net/projects/xoops/ The XOOPS Project} |
|
19
|
|
|
* @license {@link https://www.fsf.org/copyleft/gpl.html GNU public license} |
|
20
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
21
|
|
|
* @since 1.00 |
|
22
|
|
|
*/ |
|
23
|
|
|
\xoops_load('xoopsformtext'); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class FormTag |
|
27
|
|
|
*/ |
|
28
|
|
|
class FormTag extends \XoopsFormText |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* TagFormTag constructor. |
|
32
|
|
|
* @param string $name "name" attribute |
|
33
|
|
|
* @param int $size size of input box |
|
34
|
|
|
* @param int $maxlength Maximum length of text |
|
35
|
|
|
* @param string|int $value Initial text or itemid |
|
36
|
|
|
* @param int $catid category id (applicable if $value is itemid) |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct($name, int $size, $maxlength, $value = '', $catid = 0) |
|
39
|
|
|
{ |
|
40
|
|
|
$helper = \XoopsModules\Tag\Helper::getInstance(); |
|
41
|
|
|
require_once $helper->path('include/vars.php'); |
|
42
|
|
|
$helper->loadLanguage('main'); |
|
43
|
|
|
|
|
44
|
|
|
if (!empty($value) && \is_numeric($value) && ($GLOBALS['xoopsModule'] instanceof \XoopsModule)) { |
|
45
|
|
|
$modid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
46
|
|
|
/** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
|
47
|
|
|
$tagHandler = $helper->getHandler('Tag'); |
|
48
|
|
|
$tags = $tagHandler->getByItem($value, $modid, $catid); |
|
|
|
|
|
|
49
|
|
|
if ($tags) { |
|
50
|
|
|
$value = \htmlspecialchars(\implode(', ', $tags), \ENT_QUOTES | \ENT_HTML5); |
|
51
|
|
|
} else { |
|
52
|
|
|
$value = ''; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
$caption = \_MD_TAG_TAGS; |
|
56
|
|
|
parent::__construct($caption, $name, $size, $maxlength, $value); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Prepare HTML for output |
|
61
|
|
|
* |
|
62
|
|
|
* @return string HTML |
|
63
|
|
|
*/ |
|
64
|
|
|
public function render(): string |
|
65
|
|
|
{ |
|
66
|
|
|
$delimiters = Utility::tag_get_delimiter(); |
|
67
|
|
|
foreach (\array_keys($delimiters) as $key) { |
|
68
|
|
|
$delimiters[$key] = "<em style='font-weight: bold; color: #ff0000; font-style: normal;'>" . \htmlspecialchars($delimiters[$key], \ENT_QUOTES | \ENT_HTML5) . '</em>'; |
|
69
|
|
|
} |
|
70
|
|
|
$class = (false !== $this->getClass()) ? "class='" . $this->getClass() . "' " : ''; |
|
71
|
|
|
$render = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "' " . $class . $this->getExtra() . '>' . \_MD_TAG_TAG_DELIMITER . ': [' . \implode( |
|
72
|
|
|
'], [', |
|
73
|
|
|
$delimiters |
|
74
|
|
|
) . ']'; |
|
75
|
|
|
|
|
76
|
|
|
return $render; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
\class_alias(FormTag::class, 'TagFormTag'); |
|
81
|
|
|
|