forked from tad0616/tad_player
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
275 lines (229 loc) · 9.38 KB
/
Copy pathfunction.php
File metadata and controls
275 lines (229 loc) · 9.38 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
use XoopsModules\Tadtools\Utility;
use XoopsModules\Tad_player\Tools;
//判斷是否對該模組有管理權限
if (!isset($tad_player_adm)) {
$tad_player_adm = isset($xoopsUser) && \is_object($xoopsUser) ? $xoopsUser->isAdmin() : false;
}
//路徑導覽
function tad_player_breadcrumb($pcsn = '0', $array = [])
{
$item = '';
if (is_array($array)) {
foreach ($array as $cate) {
$url = ($pcsn == $cate['pcsn']) ? "<a href='index.php?pcsn={$cate['pcsn']}' style='color: gray;'>{$cate['title']}</a>" : "<a href='index.php?pcsn={$cate['pcsn']}'>{$cate['title']}</a>";
$active = ($pcsn == $cate['pcsn']) ? " class='active'" : '';
if (!empty($cate['sub']) and is_array($cate['sub']) and ($pcsn != $cate['pcsn'] or 0 == $pcsn)) {
$item .= "
<li class='dropdown'>
<a class='dropdown-toggle' data-toggle='dropdown' href='index.php?pcsn={$cate['pcsn']}'>
{$cate['title']} <span class='caret'></span>
</a>
<ul class='dropdown-menu' role='menu'>";
foreach ($cate['sub'] as $sub_pcsn => $sub_title) {
$item .= "<li><a href='index.php?pcsn={$sub_pcsn}'>{$sub_title}</a></li>\n";
}
$item .= '
</ul>
</li>';
} else {
$item .= "<li{$active}>{$url} </li>";
}
}
}
$main = "
<ul class='breadcrumb'>
$item
</ul>
";
return $main;
}
//底下影片數
function count_video_num($pcsn = '0')
{
global $xoopsDB;
//其底下所有子目錄的影片數
$sql = 'SELECT `pcsn` FROM `' . $xoopsDB->prefix('tad_player_cate') . '` WHERE `of_csn` = ?';
$result = Utility::query($sql, 'i', [$pcsn]) or Utility::web_error($sql, __FILE__, __LINE__);
$sub_count = 0;
while (list($sub_pcsn) = $xoopsDB->fetchRow($result)) {
$sub = count_video_num($sub_pcsn);
$sub_count += $sub['num'];
}
$pic = '';
//該目錄影片數
$sql = 'SELECT `psn`, `image`, `location` FROM `' . $xoopsDB->prefix('tad_player') . '` WHERE `pcsn` = ? ORDER BY RAND()';
$result = Utility::query($sql, 'i', [$pcsn]) or Utility::web_error($sql, __FILE__, __LINE__);
$count = $xoopsDB->getRowsNum($result);
while (list($psn, $image, $location) = $xoopsDB->fetchRow($result)) {
if (0 === mb_strpos($image, 'http')) {
$pic = $image;
break;
} elseif (!empty($image) and file_exists(Tools::_TAD_PLAYER_IMG_DIR . "{$psn}.png")) {
$pic = Tools::_TAD_PLAYER_IMG_URL . "{$psn}.png";
break;
}
$ext = mb_substr($location, -3);
if ('mp3' === $ext) {
$pic = 'mp3.png';
} else {
$pic = 'flv.png';
}
$pic = "images/$pic";
break;
}
$counter['num'] = $count + $sub_count;
$counter['rel_num'] = $count;
$counter['img'] = empty($pic) ? get_cate_image($pcsn) : $pic;
return $counter;
}
//隨機取得底下影片的縮圖
function get_cate_image($pcsn = '0')
{
global $xoopsDB;
$sql = 'SELECT `psn`, `image` FROM `' . $xoopsDB->prefix('tad_player') . '` WHERE `pcsn` = ? AND `image` != "" ORDER BY RAND() LIMIT 0,1';
$result = Utility::query($sql, 'i', [$pcsn]) or Utility::web_error($sql, __FILE__, __LINE__);
list($psn, $image) = $xoopsDB->fetchRow($result);
if (empty($image)) {
$sql = 'SELECT `pcsn` FROM `' . $xoopsDB->prefix('tad_player_cate') . '` WHERE `of_csn` =? ORDER BY RAND()';
$result = Utility::query($sql, 'i', [$pcsn]) or Utility::web_error($sql, __FILE__, __LINE__);
while (list($pcsn) = $xoopsDB->fetchRow($result)) {
$image = get_cate_image($pcsn);
if ($image) {
return $image;
}
}
} else {
return $image;
}
}
//熱門影片
function hot_media()
{
global $xoopsDB;
$sql = 'SELECT a.`psn`, a.`pcsn`, a.`title`, a.`counter`, b.`title` FROM `' . $xoopsDB->prefix('tad_player') . '` AS a LEFT JOIN `' . $xoopsDB->prefix('tad_player_cate') . '` AS b ON a.`pcsn`=b.`pcsn` ORDER BY a.`counter` DESC LIMIT 0,10';
$result = Utility::query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
$i = 0;
while (list($psn, $pcsn, $title, $counter, $cate_title) = $xoopsDB->fetchRow($result)) {
$hot_media[$i]['psn'] = $psn;
$hot_media[$i]['title'] = $title;
$hot_media[$i]['counter'] = $counter;
$i++;
}
return $hot_media;
}
//新增資料到tad_player_cate中
function add_tad_player_cate()
{
global $xoopsDB;
if (empty($_POST['new_pcsn'])) {
return;
}
$sql = 'INSERT INTO `' . $xoopsDB->prefix('tad_player_cate') . '` (`of_csn`, `title`, `enable_group`, `sort`) VALUES (?, ?, ?, ?)';
Utility::query($sql, 'issi', [$_POST['pcsn'], $_POST['new_pcsn'], '1', 0]) or Utility::web_error($sql, __FILE__, __LINE__);
//取得最後新增資料的流水編號
$pcsn = $xoopsDB->getInsertId();
return $pcsn;
}
//取得所有類別標題
function tad_player_get_all_news_cate($of_csn = 0, $code = 'big5')
{
global $xoopsDB;
$sql = 'SELECT `pcsn`, `title`, `enable_group` FROM `' . $xoopsDB->prefix('tad_player_cate') . '` WHERE `of_csn`=? ORDER BY `sort`';
$result = Utility::query($sql, 'i', [$of_csn]) or Utility::web_error($sql, __FILE__, __LINE__);
$option = '';
while (list($pcsn, $title, $enable_group) = $xoopsDB->fetchRow($result)) {
$have_sub = tad_player_chk_cate_have_sub($pcsn);
if ('utf8' === $code) {
$title = Utility::to_utf8($title);
}
$option .= "<li><a href='index.php?pcsn=$pcsn'>$title</a>";
if ($have_sub) {
$option .= "\n<ul>\n";
$option .= "<li parentId='$pcsn'><a href='#'>Loading</a></li>";
$option .= "\n</ul>\n";
}
$option .= '</li>';
}
return $option;
}
//檢查有無子選項
function tad_player_chk_cate_have_sub($pcsn = 0)
{
global $xoopsDB;
$sql = 'SELECT `pcsn` FROM `' . $xoopsDB->prefix('tad_player_cate') . '` WHERE `of_csn`=?';
$result = Utility::query($sql, 'i', [$pcsn]) or redirect_header($_SERVER['PHP_SELF'], 3, _MD_TADPLAYER_DB_SELECT_ERROR1);
while (list($sub_pcsn) = $xoopsDB->fetchRow($result)) {
if (!empty($sub_pcsn)) {
return true;
}
}
return false;
}
//刪除tad_player某筆資料資料
function delete_tad_player($psn = '')
{
global $xoopsDB, $isUploader, $tad_player_adm;
if (!$tad_player_adm and !$isUploader) {
redirect_header('index.php', 3, _TAD_PERMISSION_DENIED);
}
//刪除檔案
$file = Tools::get_tad_player($psn);
$file['location'] = Utility::auto_charset($file['location'], false);
$file['image'] = Utility::auto_charset($file['location'], false);
unlink(Tools::_TAD_PLAYER_FLV_DIR . "{$psn}_{$file['location']}");
unlink(Tools::_TAD_PLAYER_IMG_DIR . "s_{$psn}.png");
unlink(Tools::_TAD_PLAYER_IMG_DIR . "{$psn}_{$file['image']}");
Tools::mk_list_json($file['pcsn']);
$sql = 'DELETE FROM `' . $xoopsDB->prefix('tad_player') . '` WHERE `psn`=?';
Utility::query($sql, 'i', [$psn]) or Utility::web_error($sql, __FILE__, __LINE__);
}
//取得分類下拉選單
function get_tad_player_cate_option($of_csn = 0, $level = 0, $v = '', $show_dot = '1', $optgroup = true, $kind = 'view')
{
global $xoopsDB;
$dot = ('1' == $show_dot) ? str_repeat(_MD_TADPLAYER_BLANK, $level) : '';
$level += 1;
$sql = 'SELECT COUNT(*), `pcsn` FROM `' . $xoopsDB->prefix('tad_player') . '` GROUP BY `pcsn`';
$result = Utility::query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
while (list($count, $pcsn) = $xoopsDB->fetchRow($result)) {
$cate_count[$pcsn] = $count;
}
$option = ($of_csn) ? '' : "<option value='0'>" . _MD_TADPLAYER_CATE_SELECT . '</option>';
$sql = 'SELECT `pcsn`, `title` FROM `' . $xoopsDB->prefix('tad_player_cate') . '` WHERE `of_csn`=? ORDER BY `sort`';
$result = Utility::query($sql, 'i', [$of_csn]) or Utility::web_error($sql, __FILE__, __LINE__);
if ($kind) {
$ok_cat = Tools::chk_cate_power($kind);
}
while (list($pcsn, $title) = $xoopsDB->fetchRow($result)) {
if ($kind) {
if (!in_array($pcsn, $ok_cat)) {
continue;
}
}
$selected = ($v == $pcsn) ? 'selected' : '';
$counter = (empty($cate_count[$pcsn])) ? 0 : $cate_count[$pcsn];
$option .= "<option value='{$pcsn}' $selected >{$dot}{$title} ($counter)</option>";
$option .= get_tad_player_cate_option($pcsn, $level, $v, $show_dot, $optgroup, $kind);
}
return $option;
}
//取得tad_player_cate所有資料陣列
function get_tad_player_cate_all()
{
global $xoopsDB;
$sql = 'SELECT `pcsn`, `title` FROM `' . $xoopsDB->prefix('tad_player_cate') . '`';
$result = Utility::query($sql) or Utility::web_error($sql, __FILE__, __LINE__);
$data = [];
while (list($pcsn, $title) = $xoopsDB->fetchRow($result)) {
$data[$pcsn] = $title;
}
return $data;
}
//計數器
function add_counter($psn = '')
{
global $xoopsDB;
$sql = 'UPDATE `' . $xoopsDB->prefix('tad_player') . '` SET `counter` = `counter` + 1 WHERE `psn` = ?';
Utility::query($sql, 'i', [$psn]) or Utility::web_error($sql, __FILE__, __LINE__);
}