1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
use XoopsModules\Songlist\Form\SelectCategoryForm; |
4
|
|
|
use XoopsModules\Songlist\Form\SelectGenreForm; |
5
|
|
|
use XoopsModules\Songlist\Form\SelectVoiceForm; |
6
|
|
|
use XoopsModules\Songlist\Helper; |
7
|
|
|
use XoopsModules\Songlist\AlbumsHandler; |
8
|
|
|
use XoopsModules\Songlist\ArtistsHandler; |
9
|
|
|
use XoopsModules\Songlist\SongsHandler; |
10
|
|
|
use XoopsModules\Songlist\Utf8mapHandler; |
|
|
|
|
11
|
|
|
|
12
|
|
|
require_once __DIR__ . '/header.php'; |
13
|
|
|
|
14
|
|
|
global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit, $singer; |
15
|
|
|
|
16
|
|
|
$category_element = new SelectCategoryForm('', 'cid', ($_GET['cid'] ?? $cid)); |
17
|
|
|
$genre_element = new SelectGenreForm('', 'gid', $gid); |
18
|
|
|
$voice_element = new SelectVoiceForm('', 'vcid', $vcid); |
19
|
|
|
|
20
|
|
|
/** @var AlbumsHandler $albumsHandler */ |
21
|
|
|
$albumsHandler = Helper::getInstance()->getHandler('Albums'); |
22
|
|
|
/** @var ArtistsHandler $artistsHandler */ |
23
|
|
|
$artistsHandler = Helper::getInstance()->getHandler('Artists'); |
24
|
|
|
/** @var SongsHandler $songsHandler */ |
25
|
|
|
$songsHandler = Helper::getInstance()->getHandler('Songs'); |
26
|
|
|
/** @var Utf8mapHandler $utf8mapHandler */ |
27
|
|
|
$utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
28
|
|
|
|
29
|
|
|
switch ($op) { |
30
|
|
|
default: |
31
|
|
|
case 'search': |
32
|
|
|
$url = $songsHandler->getSearchURL(); |
33
|
|
|
if (!mb_strpos($url, $_SERVER['REQUEST_URI'])) { |
34
|
|
|
header('HTTP/1.1 301 Moved Permanently'); |
35
|
|
|
header('Location: ' . $url); |
36
|
|
|
exit(0); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
switch ($fct) { |
40
|
|
|
default: |
41
|
|
|
case 'titleandlyrics': |
42
|
|
|
$criteria = new \CriteriaCompo(); |
43
|
|
|
foreach (explode(' ', $value) as $keyword) { |
44
|
|
|
$criteria->add(new \Criteria('title', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE')); |
45
|
|
|
$criteria->add(new \Criteria('lyrics', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE')); |
46
|
|
|
} |
47
|
|
|
break; |
48
|
|
|
case 'albums': |
49
|
|
|
$criteria = new \CriteriaCompo(); |
50
|
|
|
foreach (explode(' ', $value) as $keyword) { |
51
|
|
|
$criteria->add(new \Criteria('title', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE')); |
52
|
|
|
} |
53
|
|
|
$albums = $albumsHandler->getObjects($criteria, true); |
54
|
|
|
$criteria = new \CriteriaCompo(); |
55
|
|
|
foreach ($albums as $abid => $album) { |
56
|
|
|
$criteria->add(new \Criteria('abid', $abid), 'OR'); |
57
|
|
|
} |
58
|
|
|
break; |
59
|
|
|
case 'artists': |
60
|
|
|
$criteria = new \CriteriaCompo(); |
61
|
|
|
foreach (explode(' ', $value) as $keyword) { |
62
|
|
|
$criteria->add(new \Criteria('name', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE')); |
63
|
|
|
} |
64
|
|
|
$artists = $artistsHandler->getObjects($criteria, true); |
65
|
|
|
$criteria = new \CriteriaCompo(); |
66
|
|
|
if (is_array($artists)) { |
67
|
|
|
foreach ($artists as $aid => $artist) { |
68
|
|
|
$criteria->add(new \Criteria('aids', '%"' . $aid . '"%', 'LIKE'), 'OR'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
break; |
72
|
|
|
case 'lyrics': |
73
|
|
|
$criteria = new \CriteriaCompo(); |
74
|
|
|
foreach (explode(' ', $value) as $keyword) { |
75
|
|
|
$criteria->add(new \Criteria('lyrics', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE')); |
76
|
|
|
} |
77
|
|
|
break; |
78
|
|
|
case 'title': |
79
|
|
|
$criteria = new \CriteriaCompo(); |
80
|
|
|
foreach (explode(' ', $value) as $keyword) { |
81
|
|
|
$criteria->add(new \Criteria('title', '%' . $utf8mapHandler->convert($keyword) . '%', 'LIKE')); |
82
|
|
|
} |
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (0 != $gid && $GLOBALS['songlistModuleConfig']['genre']) { |
87
|
|
|
$criteria->add(new \Criteria('gids', '%"' . $gid . '"%', 'LIKE')); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (0 != $vcid && $GLOBALS['songlistModuleConfig']['voice']) { |
91
|
|
|
$criteria->add(new \Criteria('vcid', $vcid)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (0 != ($_GET['cid'] ?? $cid)) { |
95
|
|
|
$criteria->add(new \Criteria('cid', ($_GET['cid'] ?? $cid))); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$pagenav = new \XoopsPageNav($songsHandler->getCount($criteria), $limit, $start, 'start', "?op=$op&fct=$fct&gid=$gid&vcid=$vcid&value=$value&limit=$limit"); |
99
|
|
|
|
100
|
|
|
$criteria->setLimit($limit); |
101
|
|
|
$criteria->setStart($start); |
102
|
|
|
|
103
|
|
|
$songs = $songsHandler->getObjects($criteria, false); |
104
|
|
|
|
105
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'songlist_search_index.tpl'; |
106
|
|
|
require_once $GLOBALS['xoops']->path('/header.php'); |
107
|
|
|
if ($GLOBALS['songlistModuleConfig']['force_jquery'] && !isset($GLOBALS['loaded_jquery'])) { |
108
|
|
|
$GLOBALS['xoTheme']->addScript(XOOPS_URL . _MI_SONGLIST_JQUERY, ['type' => 'text/javascript']); |
109
|
|
|
$GLOBALS['loaded_jquery'] = true; |
110
|
|
|
} |
111
|
|
|
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . _MI_SONGLIST_STYLESHEET, ['type' => 'text/css']); |
112
|
|
|
$GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
113
|
|
|
$GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
114
|
|
|
foreach ($songs as $song) { |
115
|
|
|
$GLOBALS['xoopsTpl']->append('results', $song->toArray(true)); |
116
|
|
|
} |
117
|
|
|
$GLOBALS['xoopsTpl']->assign('songs', true); |
118
|
|
|
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
119
|
|
|
$GLOBALS['xoopsTpl']->assign('category_element', $category_element->render()); |
120
|
|
|
$GLOBALS['xoopsTpl']->assign('genre_element', $genre_element->render()); |
121
|
|
|
$GLOBALS['xoopsTpl']->assign('voice_element', $voice_element->render()); |
122
|
|
|
$GLOBALS['xoopsTpl']->assign('cid', $_SESSION['cid']); |
123
|
|
|
$GLOBALS['xoopsTpl']->assign('uri', $_SERVER['REQUEST_URI']); |
124
|
|
|
require_once $GLOBALS['xoops']->path('/footer.php'); |
125
|
|
|
break; |
126
|
|
|
case 'category': |
127
|
|
|
switch ($fct) { |
128
|
|
|
default: |
129
|
|
|
case 'set': |
130
|
|
|
$_SESSION['cid'] = $id; |
131
|
|
|
break; |
132
|
|
|
case 'home': |
133
|
|
|
unset($_SESSION['cid']); |
134
|
|
|
break; |
135
|
|
|
} |
136
|
|
|
redirect_header($_SERVER['SCRIPT_NAME'] . "?op=item&fct=list&id=$id&value=$value&start=$start&limit=$limit", 10, _MD_SONGLIST_MSG_CATEGORYCHANGED); |
137
|
|
|
} |
138
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: