Passed
Pull Request — master (#81)
by Michael
02:46
created

audios.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * Module: Yogurt
17
 *
18
 * @category        Module
19
 * @package         yogurt
20
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
21
 * @copyright       {@link https://xoops.org/ XOOPS Project}
22
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 */
24
25
use XoopsModules\Yogurt;
26
use Xmf\Request;
27
28
const NBAUDIO = 'nbAudio';
29
30
$GLOBALS['xoopsOption']['template_main'] = 'yogurt_audios.tpl';
31
require __DIR__ . '/header.php';
32
33
$controller = new Yogurt\AudioController($xoopsDB, $xoopsUser);
34
35
/**
36
 * Fetching numbers of groups friends videos pictures etc...
37
 */
38
$nbSections = $controller->getNumbersSections();
39
40
$start = Request::getInt('start', 0, 'GET');
41
42
/**
43
 * Fetching numbers of groups friends videos pictures etc...
44
 */
45
$nbSections = $controller->getNumbersSections();
46
47
/**
48
 * Criteria for Audio
49
 */
50
$criteriaUidAudio = new Criteria('uid_owner', $controller->uidOwner);
51
$criteriaUidAudio->setStart($start);
52
$criteriaUidAudio->setLimit($helper->getConfig('audiosperpage'));
53
54
/**
55
 * Get all audios of this user and assign them to template
56
 */
57
$audiosArray = [];
58
$audios      = $controller->getAudio($criteriaUidAudio);
59
60
/**
61
 * If there is no audio files show in template lang_noaudioyet
62
 */
63
if (isset($nbSections[NBAUDIO]) && 0 === $nbSections[NBAUDIO]) {
64
//    $lang_noaudioyet = _MD_YOGURT_NOTHINGYET;
65
//    $xoopsTpl->assign('lang_nopicyet', $lang_noaudioyet);
66
    echo '<script>alert("Please add some audio files here")</script>';
67
} else {
68
69
    /**
70
     * Lets populate an array with the data from the pictures
71
     */
72
    $i = 0;
73
    foreach ($audios as $audio) {
74
        $audiosArray[$i]['audio_id']     = $audio->getVar('audio_id', 's');
75
        $audiosArray[$i]['title']        = $audio->getVar('title', 's');
76
        $audiosArray[$i]['author']       = $audio->getVar('author', 's');
77
        $audiosArray[$i]['description']  = $audio->getVar('description', 's');
78
        $audiosArray[$i]['filename']     = $audio->getVar('filename', 's');
79
        $audiosArray[$i]['uid_owner']    = $audio->getVar('uid_owner', 's');
80
        $audiosArray[$i]['date_created'] = formatTimeStamp($audio->getVar('date_created', 's'));
81
        $audiosArray[$i]['date_updated'] = formatTimeStamp($audio->getVar('date_updated', 's'));
82
        $xoopsTpl->assign('audios', $audiosArray);
83
        $i++;
84
    }
85
}
86
87
$xoopsTpl->assign('audios', $audios);
88
$nbAudio = $nbSections[NBAUDIO] ?? 0;
89
try {
90
    $audiosArray = $controller->assignAudioContent($nbAudio, $audios);
91
} catch (\RuntimeException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
92
}
93
94
if (is_array($audiosArray) && count($audiosArray) > 0) {
0 ignored issues
show
The condition is_array($audiosArray) is always false.
Loading history...
95
    $xoopsTpl->assign('audios', $audiosArray);
96
    $audio_list = [];
97
    foreach ($audiosArray as $audio_item) {
98
        $audio_list[] = XOOPS_UPLOAD_URL . '/yogurt/audio/' . $audio_item['filename']; // . ' | ';
99
    }
100
    //$audio_list = substr($audio_list,-2);
101
    $xoopsTpl->assign('audio_list', $audio_list);
102
} else {
103
    $xoopsTpl->assign('lang_noaudioyet', _MD_YOGURT_NOAUDIOYET);
104
}
105
$pageNav = '';
106
if (isset($nbSections[NBAUDIO]) && $nbSections[NBAUDIO] > 0) {
107
    $pageNav = $controller->getAudiosNavBar($nbSections[NBAUDIO], $helper->getConfig('audiosperpage'), $start, 2);
108
}
109
$xoTheme->addScript('https://unpkg.com/wavesurfer.js');
110
111
//meta language names
112
$xoopsTpl->assign('lang_meta', _MD_YOGURT_META);
113
$xoopsTpl->assign('lang_title', _MD_YOGURT_META_TITLE);
114
$xoopsTpl->assign('lang_album', _MD_YOGURT_META_ALBUM);
115
$xoopsTpl->assign('lang_artist', _MD_YOGURT_META_ARTIST);
116
$xoopsTpl->assign('lang_year', _MD_YOGURT_META_YEAR);
117
118
//form actions
119
$xoopsTpl->assign('lang_delete', _MD_YOGURT_DELETE);
120
$xoopsTpl->assign('lang_editdesc', _MD_YOGURT_EDIT_DESC);
121
$xoopsTpl->assign('lang_makemain', _MD_YOGURT_MAKEMAIN);
122
123
//Form Submit
124
$xoopsTpl->assign('lang_selectaudio', _MD_YOGURT_AUDIO_SELECT);
125
$xoopsTpl->assign('lang_authorLabel', _MD_YOGURT_AUDIO_AUTHOR);
126
$xoopsTpl->assign('lang_titleLabel', _MD_YOGURT_AUDIO_TITLE);
127
$xoopsTpl->assign('lang_submitValue', _MD_YOGURT_AUDIO_SUBMIT);
128
$xoopsTpl->assign('lang_addaudios', _MD_YOGURT_AUDIO_ADD);
129
130
$xoopsTpl->assign('width', $helper->getConfig('width_tube'));
131
$xoopsTpl->assign('height', $helper->getConfig('height_tube'));
132
$xoopsTpl->assign('player_from_list', _MD_YOGURT_PLAYER);
133
$xoopsTpl->assign('lang_audiohelp', sprintf(_MD_YOGURT_AUDIO_ADD_HELP, $helper->getConfig('maxfilesize')));
134
$xoopsTpl->assign('max_youcanupload', $helper->getConfig('maxfilesize'));
135
136
$xoopsTpl->assign('lang_mysection', _MD_YOGURT_MYAUDIOS);
137
$xoopsTpl->assign('section_name', _MD_YOGURT_AUDIOS);
138
139
//Page Navigation
140
$xoopsTpl->assign('pageNav', $pageNav);
141
142
require __DIR__ . '/footer.php';
143
require dirname(__DIR__, 2) . '/footer.php';
144