|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Suico; |
|
4
|
|
|
|
|
5
|
|
|
use Criteria; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
|
|
8
|
|
|
/* |
|
9
|
|
|
You may not change or alter any portion of this comment or credits |
|
10
|
|
|
of supporting developers from this source code or any supporting source code |
|
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
|
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* @category Module |
|
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
20
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
21
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
|
22
|
|
|
*/ |
|
23
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
|
24
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
25
|
|
|
require_once XOOPS_ROOT_PATH . '/class/criteria.php'; |
|
26
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class AudioController |
|
30
|
|
|
*/ |
|
31
|
|
|
class AudioController extends Controller |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Fetch audios |
|
35
|
|
|
* @param object $criteria |
|
36
|
|
|
* @return array of video objects |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getAudio( |
|
39
|
|
|
$criteria |
|
40
|
|
|
) { |
|
41
|
|
|
return $this->audioFactory->getObjects($criteria); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Assign Audio Content to Template |
|
46
|
|
|
* @param int $countAudios |
|
47
|
|
|
* @param array $audios |
|
48
|
|
|
* @return bool|array |
|
49
|
|
|
* @throws Exception |
|
50
|
|
|
* @throws Exception |
|
51
|
|
|
*/ |
|
52
|
|
|
public function assignAudioContent( |
|
53
|
|
|
$countAudios, |
|
54
|
|
|
$audios |
|
55
|
|
|
) { |
|
56
|
|
|
if (0 === $countAudios) { |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
//audio info |
|
60
|
|
|
/** |
|
61
|
|
|
* Lets populate an array with the data from the audio |
|
62
|
|
|
*/ |
|
63
|
|
|
$i = 0; |
|
64
|
|
|
$audiosArray = []; |
|
65
|
|
|
foreach ($audios as $audio) { |
|
66
|
|
|
$audiosArray[$i]['filename'] = $audio->getVar('filename', 's'); |
|
67
|
|
|
$audiosArray[$i]['title'] = $audio->getVar('title', 's'); |
|
68
|
|
|
$audiosArray[$i]['id'] = $audio->getVar('audio_id', 's'); |
|
69
|
|
|
$audiosArray[$i]['author'] = $audio->getVar('author', 's'); |
|
70
|
|
|
$audiosArray[$i]['date_created'] = \formatTimestamp($audio->getVar('date_created', 's')); |
|
71
|
|
|
$audiosArray[$i]['date_updated'] = \formatTimestamp($audio->getVar('date_updated', 's')); |
|
72
|
|
|
$audio_path = XOOPS_ROOT_PATH . '/uploads/suico/audio/' . $audio->getVar('filename', 's'); |
|
73
|
|
|
// echo $audio_path; |
|
74
|
|
|
$mp3filemetainfo = new Id3v1($audio_path, true); |
|
75
|
|
|
$mp3filemetainfoarray = []; |
|
76
|
|
|
$mp3filemetainfoarray['Title'] = $mp3filemetainfo->getTitle(); |
|
77
|
|
|
$mp3filemetainfoarray['Artist'] = $mp3filemetainfo->getArtist(); |
|
78
|
|
|
$mp3filemetainfoarray['Album'] = $mp3filemetainfo->getAlbum(); |
|
79
|
|
|
$mp3filemetainfoarray['Year'] = $mp3filemetainfo->getYear(); |
|
80
|
|
|
$audiosArray[$i]['meta'] = $mp3filemetainfoarray; |
|
81
|
|
|
$i++; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $audiosArray; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Create a page navbar for videos |
|
89
|
|
|
* @param $countAudios |
|
90
|
|
|
* @param int $audiosPerPage the number of videos in a page |
|
91
|
|
|
* @param int $start at which position of the array we start |
|
92
|
|
|
* @param int $interval how many pages between the first link and the next one |
|
93
|
|
|
* @return string|null |
|
94
|
|
|
* @return string|null |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getAudiosNavBar( |
|
97
|
|
|
$countAudios, |
|
98
|
|
|
$audiosPerPage, |
|
99
|
|
|
$start, |
|
100
|
|
|
$interval |
|
101
|
|
|
) { |
|
102
|
|
|
$pageNav = new \XoopsPageNav($countAudios, $audiosPerPage, $start, 'start', 'uid=' . $this->uidOwner); |
|
103
|
|
|
|
|
104
|
|
|
return $pageNav->renderImageNav($interval); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return bool|void |
|
109
|
|
|
*/ |
|
110
|
|
|
public function checkPrivilege() |
|
111
|
|
|
{ |
|
112
|
|
|
if (0 === $this->helper->getConfig('enable_audio')) { |
|
113
|
|
|
\redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 3, \_MD_SUICO_AUDIO_ENABLED_NOT); |
|
114
|
|
|
} |
|
115
|
|
|
$criteria = new Criteria('config_uid', $this->owner->getVar('uid')); |
|
|
|
|
|
|
116
|
|
|
if (1 === $this->configsFactory->getCount($criteria)) { |
|
117
|
|
|
$configs = $this->configsFactory->getObjects($criteria); |
|
118
|
|
|
$config = $configs[0]->getVar('audio'); |
|
119
|
|
|
if (!$this->checkPrivilegeLevel($config)) { |
|
120
|
|
|
\redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 10, \_MD_SUICO_NOPRIVILEGE); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return true; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|