1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Songlist; |
4
|
|
|
|
5
|
|
|
use Criteria; |
6
|
|
|
use MyTextSanitizer; |
7
|
|
|
use XoopsObject; |
8
|
|
|
|
9
|
|
|
require_once \dirname(__DIR__) . '/include/songlist.object.php'; |
10
|
|
|
// require_once \dirname(__DIR__) . '/include/songlist.form.php'; |
11
|
|
|
use XoopsModules\Songlist\Form\FormController; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Songs |
15
|
|
|
*/ |
16
|
|
|
class Songs extends XoopsObject |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Songs constructor. |
20
|
|
|
* @param null $fid |
|
|
|
|
21
|
|
|
*/ |
22
|
|
|
public function __construct($fid = null) |
23
|
|
|
{ |
24
|
|
|
$this->initVar('sid', \XOBJ_DTYPE_INT, 0, false); |
25
|
|
|
$this->initVar('cid', \XOBJ_DTYPE_INT, 0, false); |
26
|
|
|
$this->initVar('gids', \XOBJ_DTYPE_ARRAY, 0, false); |
27
|
|
|
$this->initVar('vcid', \XOBJ_DTYPE_INT, 0, false); |
28
|
|
|
$this->initVar('aids', \XOBJ_DTYPE_ARRAY, [], false); |
29
|
|
|
$this->initVar('abid', \XOBJ_DTYPE_INT, 0, false); |
30
|
|
|
$this->initVar('songid', \XOBJ_DTYPE_TXTBOX, null, false, 32); |
31
|
|
|
$this->initVar('traxid', \XOBJ_DTYPE_TXTBOX, null, false, 32); |
32
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
33
|
|
|
$this->initVar('lyrics', \XOBJ_DTYPE_OTHER, null, false); |
34
|
|
|
$this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
35
|
|
|
$this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
36
|
|
|
$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
37
|
|
|
$this->initVar('tags', \XOBJ_DTYPE_TXTBOX, null, false, 255); |
38
|
|
|
$this->initVar('mp3', \XOBJ_DTYPE_OTHER, null, false, 500); |
39
|
|
|
$this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
40
|
|
|
$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param bool $as_array |
45
|
|
|
* @return array|string |
46
|
|
|
*/ |
47
|
|
|
public function getForm($as_array = false) |
48
|
|
|
{ |
49
|
|
|
return FormController::getFormSongs($this, $as_array); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param bool $extra |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
public function toArray($extra = true): array |
57
|
|
|
{ |
58
|
|
|
$ret = parent::toArray(); |
59
|
|
|
|
60
|
|
|
$GLOBALS['myts'] = MyTextSanitizer::getInstance(); |
61
|
|
|
|
62
|
|
|
$ret['lyrics'] = $GLOBALS['myts']->displayTarea($this->getVar('lyrics'), true, true, true, true, true); |
63
|
|
|
|
64
|
|
|
$form = $this->getForm(true); |
65
|
|
|
foreach ($form as $key => $element) { |
66
|
|
|
$ret['form'][$key] = $element->render(); |
67
|
|
|
} |
68
|
|
|
foreach (['created', 'updated'] as $key) { |
69
|
|
|
if ($this->getVar($key) > 0) { |
70
|
|
|
$ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
71
|
|
|
$ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$ret['url'] = $this->getURL(); |
76
|
|
|
|
77
|
|
|
$ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
78
|
|
|
|
79
|
|
|
if (!empty($ret['mp3'])) { |
80
|
|
|
$ret['mp3'] = '<embed flashvars="playerID=1&bg=0xf8f8f8&leftbg=0x3786b3&lefticon=0x78bee3&rightbg=0x3786b3&rightbghover=0x78bee3&righticon=0x78bee3&righticonhover=0x3786b3&text=0x666666&slider=0x3786b3&track=0xcccccc&border=0x666666&loader=0x78bee3&loop=no&soundFile=' |
81
|
|
|
. $ret['mp3'] |
82
|
|
|
. "\" quality='high' menu='false' wmode='transparent' pluginspage='https://www.macromedia.com/go/getflashplayer' src='" |
83
|
|
|
. XOOPS_URL |
84
|
|
|
. "/images/form/player.swf' width=290 height=24 type='application/x-shockwave-flash'></embed>"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$helper = Helper::getInstance(); |
88
|
|
|
if (1 == $helper->getConfig('tags') |
89
|
|
|
&& \class_exists(\XoopsModules\Tag\Tagbar::class) |
90
|
|
|
&& \xoops_isActiveModule('tag')) { |
91
|
|
|
$tagbarObj = new \XoopsModules\Tag\Tagbar(); |
92
|
|
|
$ret['tagbar'] = $tagbarObj->getTagbar($this->getVar('sid'), $this->getVar('cid')); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$extrasHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras'); |
96
|
|
|
$fieldHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Field'); |
97
|
|
|
$visibilityHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Visibility'); |
98
|
|
|
|
99
|
|
|
$extras = $extrasHandler->get($this->getVar('sid')); |
100
|
|
|
if ($extras) { |
|
|
|
|
101
|
|
|
if (\is_object($GLOBALS['xoopsUser'])) { |
102
|
|
|
$fields_id = $visibilityHandler->getVisibleFields([], $GLOBALS['xoopsUser']->getGroups()); |
103
|
|
|
} elseif (!\is_object($GLOBALS['xoopsUser'])) { |
104
|
|
|
$fields_id = $visibilityHandler->getVisibleFields([], []); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if (\count($fields_id) > 0) { |
|
|
|
|
108
|
|
|
$criteria = new Criteria('field_id', '(' . \implode(',', $fields_id) . ')', 'IN'); |
109
|
|
|
$criteria->setSort('field_weight'); |
110
|
|
|
$fields = $fieldHandler->getObjects($criteria, true); |
111
|
|
|
foreach ($fields as $id => $field) { |
112
|
|
|
if (\in_array($this->getVar('cid'), $field->getVar('cids'), true)) { |
113
|
|
|
$ret['fields'][$id]['title'] = $field->getVar('field_title'); |
114
|
|
|
if (\is_object($GLOBALS['xoopsUser'])) { |
115
|
|
|
$ret['fields'][$id]['value'] = htmlspecialchars_decode($field->getOutputValue($GLOBALS['xoopsUser'], $extras)); |
116
|
|
|
} elseif (!\is_object($GLOBALS['xoopsUser'])) { |
117
|
|
|
$ret['fields'][$id]['value'] = htmlspecialchars_decode($extras->getVar($field->getVar('field_name'))); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if (!$extra) { |
125
|
|
|
return $ret; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
if (0 != $this->getVar('cid')) { |
129
|
|
|
$categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category'); |
130
|
|
|
$category = $categoryHandler->get($this->getVar('cid')); |
131
|
|
|
$ret['category'] = $category->toArray(false); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if (0 != \count($this->getVar('gids'))) { |
|
|
|
|
135
|
|
|
$i = 0; |
136
|
|
|
$genreHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre'); |
137
|
|
|
$ret['genre'] = ''; |
138
|
|
|
$genres = $genreHandler->getObjects(new Criteria('gid', '(' . \implode(',', $this->getVar('gids')) . ')', 'IN'), true); |
|
|
|
|
139
|
|
|
foreach ($genres as $gid => $genre) { |
140
|
|
|
$ret['genre_array'][$gid] = $genre->toArray(false); |
141
|
|
|
++$i; |
142
|
|
|
$ret['genre'] .= $genre->getVar('name') . ($i < \count($genres) ? ', ' : ''); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
if (0 != $this->getVar('vcid')) { |
146
|
|
|
$voiceHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice'); |
147
|
|
|
$voice = $voiceHandler->get($this->getVar('vcid')); |
148
|
|
|
$ret['voice'] = $voice->toArray(false); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if (0 != \count($this->getVar('aids'))) { |
152
|
|
|
$artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists'); |
153
|
|
|
foreach ($this->getVar('aids') as $aid) { |
154
|
|
|
$artist = $artistsHandler->get($aid); |
155
|
|
|
$ret['artists_array'][$aid] = $artist->toArray(false); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if (0 != $this->getVar('abid')) { |
160
|
|
|
$albumsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums'); |
161
|
|
|
$albums = $albumsHandler->get($this->getVar('abid')); |
162
|
|
|
if (null !== $albums) { |
163
|
|
|
$ret['albums'] = $albums->toArray(false); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $ret; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function getURL(): string |
175
|
|
|
{ |
176
|
|
|
global $file, $op, $fct, $id, $value, $vcid, $gid, $cid, $start, $limit; |
177
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
178
|
|
|
return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/index/' . \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('title'))) . '/item-item-' . $this->getVar('sid') . $GLOBALS['songlistModuleConfig']['endofurl']; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return XOOPS_URL . '/modules/songlist/index.php?op=item&fct=item&id=' . $this->getVar('sid') . '&value=' . \urlencode($value ?? '') . '&vcid=' . $vcid . '&gid=' . $gid . '&cid=' . $cid; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|