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

audios.php (1 issue)

Severity
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
     * Lets populate an array with the data from the pictures
70
     */
71
    $i = 0;
72
    foreach ($audios as $audio) {
73
        $audiosArray[$i]['audio_id']     = $audio->getVar('audio_id', 's');
74
        $audiosArray[$i]['title']        = $audio->getVar('title', 's');
75
        $audiosArray[$i]['author']       = $audio->getVar('author', 's');
76
        $audiosArray[$i]['description']  = $audio->getVar('description', 's');
77
        $audiosArray[$i]['filename']     = $audio->getVar('filename', 's');
78
        $audiosArray[$i]['uid_owner']    = $audio->getVar('uid_owner', 's');
79
        $audiosArray[$i]['date_created'] = formatTimeStamp($audio->getVar('date_created', 's'));
80
        $audiosArray[$i]['date_updated'] = formatTimeStamp($audio->getVar('date_updated', 's'));
81
        $xoopsTpl->assign('audios', $audiosArray);
82
        $i++;
83
    }
84
}
85
86
$xoopsTpl->assign('audios', $audios);
87
$nbAudio = $nbSections[NBAUDIO] ?? 0;
88
try {
89
    $audiosArray = $controller->assignAudioContent($nbAudio, $audios);
90
} catch (\RuntimeException $e) {
91
}
92
93
if (is_array($audiosArray) && count($audiosArray) > 0) {
0 ignored issues
show
The condition is_array($audiosArray) is always false.
Loading history...
94
    $xoopsTpl->assign('audios', $audiosArray);
95
    $audio_list = [];
96
    foreach ($audiosArray as $audio_item) {
97
        $audio_list[] = XOOPS_UPLOAD_URL . '/yogurt/audio/' . $audio_item['filename']; // . ' | ';
98
    }
99
    //$audio_list = substr($audio_list,-2);
100
    $xoopsTpl->assign('audio_list', $audio_list);
101
} else {
102
    $xoopsTpl->assign('lang_noaudioyet', _MD_YOGURT_NOAUDIOYET);
103
}
104
$pageNav = '';
105
if (isset($nbSections[NBAUDIO]) && $nbSections[NBAUDIO] > 0) {
106
    $pageNav = $controller->getAudiosNavBar($nbSections[NBAUDIO], $helper->getConfig('audiosperpage'), $start, 2);
107
}
108
$xoTheme->addScript('https://unpkg.com/wavesurfer.js');
109
110
//meta language names
111
$xoopsTpl->assign('lang_meta', _MD_YOGURT_META);
112
$xoopsTpl->assign('lang_title', _MD_YOGURT_META_TITLE);
113
$xoopsTpl->assign('lang_album', _MD_YOGURT_META_ALBUM);
114
$xoopsTpl->assign('lang_artist', _MD_YOGURT_META_ARTIST);
115
$xoopsTpl->assign('lang_year', _MD_YOGURT_META_YEAR);
116
117
//form actions
118
$xoopsTpl->assign('lang_delete', _MD_YOGURT_DELETE);
119
$xoopsTpl->assign('lang_editdesc', _MD_YOGURT_EDIT_DESC);
120
$xoopsTpl->assign('lang_makemain', _MD_YOGURT_MAKEMAIN);
121
122
//Form Submit
123
$xoopsTpl->assign('lang_selectaudio', _MD_YOGURT_AUDIO_SELECT);
124
$xoopsTpl->assign('lang_authorLabel', _MD_YOGURT_AUDIO_AUTHOR);
125
$xoopsTpl->assign('lang_titleLabel', _MD_YOGURT_AUDIO_TITLE);
126
$xoopsTpl->assign('lang_submitValue', _MD_YOGURT_AUDIO_SUBMIT);
127
$xoopsTpl->assign('lang_addaudios', _MD_YOGURT_AUDIO_ADD);
128
129
$xoopsTpl->assign('width', $helper->getConfig('width_tube'));
130
$xoopsTpl->assign('height', $helper->getConfig('height_tube'));
131
$xoopsTpl->assign('player_from_list', _MD_YOGURT_PLAYER);
132
$xoopsTpl->assign('lang_audiohelp', sprintf(_MD_YOGURT_AUDIO_ADD_HELP, $helper->getConfig('maxfilesize')));
133
$xoopsTpl->assign('max_youcanupload', $helper->getConfig('maxfilesize'));
134
135
$xoopsTpl->assign('lang_mysection', _MD_YOGURT_MYAUDIOS);
136
$xoopsTpl->assign('section_name', _MD_YOGURT_AUDIOS);
137
138
//Page Navigation
139
$xoopsTpl->assign('pageNav', $pageNav);
140
141
require __DIR__ . '/footer.php';
142
require dirname(__DIR__, 2) . '/footer.php';
143