forked from XoopsModules25x/songlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
albums.php
228 lines (208 loc) · 10 KB
/
albums.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php declare(strict_types=1);
use XoopsModules\Songlist\Helper;
use XoopsModules\Songlist\CategoryHandler;
use XoopsModules\Songlist\AlbumsHandler;
require_once __DIR__ . '/header.php';
global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
/** @var CategoryHandler $categoryHandler */
$categoryHandler = Helper::getInstance()->getHandler('Category');
$criteria_cat = new \CriteriaCompo();
$cids = $categoryHandler->GetCatAndSubCat($_SESSION['cid']);
if ($_SESSION['cid'] > 0) {
$cids[$_SESSION['cid']] = $_SESSION['cid'];
}
if (count($cids) > 0 && 0 != $_SESSION['cid']) {
$criteria_cat->add(new \Criteria('cid', '(' . implode(',', $cids) . ')', 'IN'), 'OR');
} else {
$criteria_cat->add(new \Criteria(''), 'OR');
}
$criteria_cat->setSort('created');
$criteria_cat->setOrder('ASC');
$criteria = new \Criteria('pid', $_SESSION['cid']);
$criteria->setSort('weight');
$criteria->setOrder('ASC');
$categories = $categoryHandler->getObjects($criteria, false);
$cat = [];
$col = 1;
$row = 1;
foreach ($categories as $category) {
$cat[$row][$col] = $category->toArray(true);
$cat[$row][$col]['width'] = floor(100 / $GLOBALS['songlistModuleConfig']['cols']) . '%';
++$col;
if ($col > $GLOBALS['songlistModuleConfig']['cols']) {
++$row;
$col = 1;
}
}
if (1 != $col) {
$col--;
for ($j = $col; $j <= $GLOBALS['songlistModuleConfig']['cols']; ++$j) {
$cat[$row][$j][$categoryHandler->keyName] = 0;
$cat[$row][$j]['width'] = floor(100 / $GLOBALS['songlistModuleConfig']['cols']) . '%';
}
}
/** @var AlbumsHandler $albumsHandler */
$albumsHandler = Helper::getInstance()->getHandler('Albums');
switch ($op) {
default:
case 'item':
switch ($fct) {
default:
case 'list':
$pagenav = new \XoopsPageNav($albumsHandler->getCount($criteria_cat), $limit, $start, 'start', "op=$op&fct=$fct&id=$id&value=$value&limit=$limit");
$criteria_cat->setLimit($limit);
$criteria_cat->setStart($start);
$albums = $albumsHandler->getObjects($criteria_cat, false);
$ret = [];
$col = 1;
$row = 1;
foreach ($albums as $album) {
$ret[$row][$col] = $album->toArray(true);
$ret[$row][$col]['width'] = floor(100 / $GLOBALS['songlistModuleConfig']['cols']) . '%';
++$col;
if ($col > $GLOBALS['songlistModuleConfig']['cols']) {
++$row;
$col = 1;
}
}
if (1 != $col) {
for ($j = $col; $j <= $GLOBALS['songlistModuleConfig']['cols']; ++$j) {
$ret[$row][$j][$albumsHandler->keyName] = 0;
$ret[$row][$j]['width'] = floor(100 / $GLOBALS['songlistModuleConfig']['cols']) . '%';
}
}
$url = $albumsHandler->getURL();
if (!mb_strpos($url, $_SERVER['REQUEST_URI'])) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit(0);
}
$GLOBALS['xoopsOption']['template_main'] = 'songlist_albums_index.tpl';
require_once $GLOBALS['xoops']->path('/header.php');
if ($GLOBALS['songlistModuleConfig']['force_jquery'] && !isset($GLOBALS['loaded_jquery'])) {
$GLOBALS['xoTheme']->addScript(XOOPS_URL . _MI_SONGLIST_JQUERY, ['type' => 'text/javascript']);
$GLOBALS['loaded_jquery'] = true;
}
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . _MI_SONGLIST_STYLESHEET, ['type' => 'text/css']);
$GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']);
$GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']);
$GLOBALS['xoopsTpl']->assign('results', $ret);
$GLOBALS['xoopsTpl']->assign('categories', $cat);
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav());
$GLOBALS['xoopsTpl']->assign('uri', $_SERVER['REQUEST_URI']);
if (0 != $_SESSION['cid']) {
$category = $categoryHandler->get($_SESSION['cid']);
$GLOBALS['xoopsTpl']->assign('category', $category->toArray(true));
}
require_once $GLOBALS['xoops']->path('/footer.php');
break;
case 'item':
$album = $albumsHandler->get($id);
$url = $album->getURL(true);
if (!mb_strpos($url, $_SERVER['REQUEST_URI'])) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit(0);
}
$GLOBALS['xoopsOption']['template_main'] = 'songlist_albums_item.tpl';
require_once $GLOBALS['xoops']->path('/header.php');
if ($GLOBALS['songlistModuleConfig']['force_jquery'] && !isset($GLOBALS['loaded_jquery'])) {
$GLOBALS['xoTheme']->addScript(XOOPS_URL . _MI_SONGLIST_JQUERY, ['type' => 'text/javascript']);
$GLOBALS['loaded_jquery'] = true;
}
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . _MI_SONGLIST_STYLESHEET, ['type' => 'text/css']);
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . _MI_SONGLIST_STYLESHEET, ['type' => 'text/css']);
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . _MI_SONGLIST_STYLESHEET, ['type' => 'text/css']);
$GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']);
$GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']);
$GLOBALS['xoopsTpl']->assign('songs', false);
$GLOBALS['xoopsTpl']->assign('album', $album->toArray(true));
$GLOBALS['xoopsTpl']->assign('categories', $cat);
$GLOBALS['xoopsTpl']->assign('uri', $_SERVER['REQUEST_URI']);
require_once $GLOBALS['xoops']->path('/footer.php');
break;
}
break;
case 'browseby':
switch ($fct) {
default:
case 'title':
case 'lyrics':
case 'artist':
case 'album':
$browse_criteria = new \CriteriaCompo();
switch ($value) {
case '0':
for ($u = 0; $u < 10; ++$u) {
$browse_criteria->add(new \Criteria('title', $u . '%', 'LIKE'), 'OR');
}
break;
default:
$browse_criteria->add(new \Criteria('title', \mb_strtoupper($value) . '%', 'LIKE'), 'OR');
$browse_criteria->add(new \Criteria('title', \mb_strtolower($value) . '%', 'LIKE'), 'OR');
break;
}
$criteria = new \CriteriaCompo($criteria_cat, 'AND');
$criteria->add($browse_criteria);
}
$pagenav = new \XoopsPageNav($albumsHandler->getCount($criteria), $limit, $start, 'start', "op=$op&fct=$fct&id=$id&value=$value&limit=$limit");
$criteria->setLimit($limit);
$criteria->setStart($start);
$albums = $albumsHandler->getObjects($criteria, false);
$ret = [];
$col = 1;
$row = 1;
foreach ($albums as $album) {
$ret[$row][$col] = $album->toArray(true);
$ret[$row][$col]['width'] = floor(100 / $GLOBALS['songlistModuleConfig']['cols']) . '%';
++$col;
if ($col > $GLOBALS['songlistModuleConfig']['cols']) {
++$row;
$col = 1;
}
}
if (1 != $col) {
$col--;
for ($j = $col; $j <= $GLOBALS['songlistModuleConfig']['cols']; ++$j) {
$ret[$row][$j][$albumsHandler->keyName] = 0;
$ret[$row][$j]['width'] = floor(100 / $GLOBALS['songlistModuleConfig']['cols']) . '%';
}
}
$url = $albumsHandler->getURL();
if (!mb_strpos($url, $_SERVER['REQUEST_URI'])) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit(0);
}
$GLOBALS['xoopsOption']['template_main'] = 'songlist_albums_index.tpl';
require_once $GLOBALS['xoops']->path('/header.php');
if ($GLOBALS['songlistModuleConfig']['force_jquery'] && !isset($GLOBALS['loaded_jquery'])) {
$GLOBALS['xoTheme']->addScript(XOOPS_URL . _MI_SONGLIST_JQUERY, ['type' => 'text/javascript']);
$GLOBALS['loaded_jquery'] = true;
}
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . _MI_SONGLIST_STYLESHEET, ['type' => 'text/css']);
$GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']);
$GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']);
$GLOBALS['xoopsTpl']->assign('results', $ret);
$GLOBALS['xoopsTpl']->assign('songs', false);
$GLOBALS['xoopsTpl']->assign('categories', $cat);
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav());
if (0 != $_SESSION['cid']) {
$category = $categoryHandler->get($_SESSION['cid']);
$GLOBALS['xoopsTpl']->assign('category', $category->toArray(true));
}
$GLOBALS['xoopsTpl']->assign('uri', $_SERVER['REQUEST_URI']);
require_once $GLOBALS['xoops']->path('/footer.php');
break;
case 'category':
switch ($fct) {
default:
case 'set':
$_SESSION['cid'] = $id;
break;
case 'home':
unset($_SESSION['cid']);
break;
}
redirect_header($_SERVER['SCRIPT_NAME'] . "?op=item&fct=list&id=0&value=%&start=$start&limit=$limit&cid=" . $_SESSION['cid'], 10, _MD_SONGLIST_MSG_CATEGORYCHANGED);
}