forked from XoopsModules25x/songlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
137 lines (123 loc) · 6.05 KB
/
search.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
<?php declare(strict_types=1);
use XoopsModules\Songlist\Form\SelectCategoryForm;
use XoopsModules\Songlist\Form\SelectGenreForm;
use XoopsModules\Songlist\Form\SelectVoiceForm;
use XoopsModules\Songlist\Helper;
use XoopsModules\Songlist\AlbumsHandler;
use XoopsModules\Songlist\ArtistsHandler;
use XoopsModules\Songlist\SongsHandler;
use XoopsModules\Songlist\Utf8mapHandler;
require_once __DIR__ . '/header.php';
global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit, $singer;
$category_element = new SelectCategoryForm('', 'cid', ($_GET['cid'] ?? $cid));
$genre_element = new SelectGenreForm('', 'gid', $gid);
$voice_element = new SelectVoiceForm('', 'vcid', $vcid);
/** @var AlbumsHandler $albumsHandler */
$albumsHandler = Helper::getInstance()->getHandler('Albums');
/** @var ArtistsHandler $artistsHandler */
$artistsHandler = Helper::getInstance()->getHandler('Artists');
/** @var SongsHandler $songsHandler */
$songsHandler = Helper::getInstance()->getHandler('Songs');
/** @var Utf8mapHandler $utf8mapHandler */
$utf8mapHandler = Helper::getInstance()->getHandler('Utf8map');
switch ($op) {
default:
case 'search':
$url = $songsHandler->getSearchURL();
if (!mb_strpos($url, $_SERVER['REQUEST_URI'])) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $url);
exit(0);
}
switch ($fct) {
default:
case 'titleandlyrics':
$criteria = new \CriteriaCompo();
foreach (explode(' ', $value) as $keyword) {
$criteria->add(new \Criteria('title', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE'));
$criteria->add(new \Criteria('lyrics', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE'));
}
break;
case 'albums':
$criteria = new \CriteriaCompo();
foreach (explode(' ', $value) as $keyword) {
$criteria->add(new \Criteria('title', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE'));
}
$albums = $albumsHandler->getObjects($criteria, true);
$criteria = new \CriteriaCompo();
foreach ($albums as $abid => $album) {
$criteria->add(new \Criteria('abid', $abid), 'OR');
}
break;
case 'artists':
$criteria = new \CriteriaCompo();
foreach (explode(' ', $value) as $keyword) {
$criteria->add(new \Criteria('name', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE'));
}
$artists = $artistsHandler->getObjects($criteria, true);
$criteria = new \CriteriaCompo();
if (is_array($artists)) {
foreach ($artists as $aid => $artist) {
$criteria->add(new \Criteria('aids', '%"' . $aid . '"%', 'LIKE'), 'OR');
}
}
break;
case 'lyrics':
$criteria = new \CriteriaCompo();
foreach (explode(' ', $value) as $keyword) {
$criteria->add(new \Criteria('lyrics', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE'));
}
break;
case 'title':
$criteria = new \CriteriaCompo();
foreach (explode(' ', $value) as $keyword) {
$criteria->add(new \Criteria('title', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE'));
}
break;
}
if (0 != $gid && $GLOBALS['songlistModuleConfig']['genre']) {
$criteria->add(new \Criteria('gids', '%"' . $gid . '"%', 'LIKE'));
}
if (0 != $vcid && $GLOBALS['songlistModuleConfig']['voice']) {
$criteria->add(new \Criteria('vcid', $vcid));
}
if (0 != ($_GET['cid'] ?? $cid)) {
$criteria->add(new \Criteria('cid', ($_GET['cid'] ?? $cid)));
}
$pagenav = new \XoopsPageNav($songsHandler->getCount($criteria), $limit, $start, 'start', "?op=$op&fct=$fct&gid=$gid&vcid=$vcid&value=$value&limit=$limit");
$criteria->setLimit($limit);
$criteria->setStart($start);
$songs = $songsHandler->getObjects($criteria, false);
$GLOBALS['xoopsOption']['template_main'] = 'songlist_search_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']);
foreach ($songs as $song) {
$GLOBALS['xoopsTpl']->append('results', $song->toArray(true));
}
$GLOBALS['xoopsTpl']->assign('songs', true);
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav());
$GLOBALS['xoopsTpl']->assign('category_element', $category_element->render());
$GLOBALS['xoopsTpl']->assign('genre_element', $genre_element->render());
$GLOBALS['xoopsTpl']->assign('voice_element', $voice_element->render());
$GLOBALS['xoopsTpl']->assign('cid', $_SESSION['cid']);
$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=$id&value=$value&start=$start&limit=$limit", 10, _MD_SONGLIST_MSG_CATEGORYCHANGED);
}