-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp_api.php
79 lines (66 loc) · 2.57 KB
/
app_api.php
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
<?php
use Xmf\Request;
use XoopsModules\Tadgallery\Tadgallery;
use XoopsModules\Tadtools\Utility;
require_once __DIR__ . '/header.php';
header('HTTP/1.1 200 OK');
$xoopsLogger->activated = false;
$tadgallery = new Tadgallery();
/*-----------執行動作判斷區----------*/
$op = Request::getString('op');
$cate = Request::getInt('cate');
$nsn = Request::getInt('nsn');
$fsn = Request::getInt('fsn');
$of_csn = Request::getInt('of_csn');
header("Content-Type: application/json; charset=utf-8");
switch ($op) {
case 'get_data':
die(json_encode(get_data($cate), 256));
case 'get_cates':
die(json_encode(get_cates($cate), 256));
}
//列出所有tad_photos資料
function get_data($csn = 0)
{
global $tadgallery;
$tadgallery->set_only_enable();
$tadgallery->set_only_thumb(true);
$tadgallery->set_view_csn($csn);
$data['photos'] = $tadgallery->get_photos(0, 'app');
$data['cates'] = get_cates($csn);
return $data;
}
function get_cates($of_csn = 0)
{
global $tadgallery, $xoopsDB;
$cate = $all_cates = [];
$cate_count = $tadgallery->get_tad_gallery_cate_count();
$of_csn = (int) $of_csn;
$sql = 'SELECT `csn`, `of_csn`, `title`, `sort`, `cover` FROM `' . $xoopsDB->prefix('tad_gallery_cate') . '` WHERE `of_csn`=? AND `enable`=? AND (`enable_group`=? OR `enable_group` LIKE ?) ORDER BY `sort`';
$result = Utility::query($sql, 'isss', [$of_csn, '1', '%3%', '']);
while (list($csn, $of_csn, $title, $sort, $cover) = $xoopsDB->fetchRow($result)) {
if (empty($cover)) {
$cover = $tadgallery->random_cover($csn);
} elseif (strpos('http', $cover) === false) {
if ('small' == substr($cover, 0, 5)) {
$m_cover = str_replace(['small/', '_s_'], ['medium/', '_m_'], $cover);
// $cover_path = XOOPS_ROOT_PATH . '/uploads/tadgallery/' . $m_cover;
if (file_exists(XOOPS_ROOT_PATH . '/uploads/tadgallery/' . $m_cover)) {
$cover = $m_cover;
}
}
$cover = XOOPS_URL . '/uploads/tadgallery/' . $cover;
}
$cate['csn'] = (int) $csn;
$cate['title'] = $title;
$cate['of_csn'] = (int) $of_csn;
$cate['dir_count'] = (int) $cate_count[$csn]['dir'];
$cate['file_count'] = (int) $cate_count[$csn]['file'];
$cate['sort'] = (int) $sort;
$cate['cover'] = $cover;
// $cate['old_ccover_pathover'] = $cover_path;
$cate['url'] = XOOPS_URL . "/modules/tadgallery/index.php?csn={$csn}";
$all_cates[] = $cate;
}
return $all_cates;
}