forked from tad0616/tad_blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
414 lines (340 loc) · 16.2 KB
/
Copy pathindex.php
File metadata and controls
414 lines (340 loc) · 16.2 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<?php
use Xmf\Request;
use XoopsModules\Tadtools\AccessibilityFixer;
use XoopsModules\Tadtools\CkEditor;
use XoopsModules\Tadtools\SweetAlert;
use XoopsModules\Tadtools\TadDataCenter;
use XoopsModules\Tadtools\TadUpFiles;
use XoopsModules\Tadtools\Utility;
/**
* module
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @package
* @since
* @author
* @version $Id $
**/
/*-----------引入檔案區--------------*/
require_once __DIR__ . '/header.php';
$GLOBALS['xoopsOption']['template_main'] = 'tad_blocks_index.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
if (!$xoopsUser) {
redirect_header('index.php', 3, _MD_TAD_BLOCKS_NO_PERMISSION);
}
/*-----------執行動作判斷區----------*/
$op = Request::getString('op');
$TDC = Request::getVar('TDC', [], null, 'array', 2);
$type = Request::getString('type');
$bid = Request::getInt('bid');
$bbid = Request::getInt('bbid');
$files_sn = Request::getInt('files_sn');
$old_display = Request::getString('display');
switch ($op) {
case "tufdl":
$TadUpFiles = new TadUpFiles("tad_blocks");
$TadUpFiles->add_file_counter($files_sn);
exit;
case "block_form":
block_form($type, $bid, $bbid);
break;
case "block_save":
block_save($type, $TDC, $bid, $bbid, $old_display);
header("location: {$_SERVER['PHP_SELF']}");
exit;
case "block_del":
block_del($bid);
header("location: {$_SERVER['PHP_SELF']}");
exit;
default:
my_blocks();
$op = 'my_blocks';
break;
}
/*-----------秀出結果區--------------*/
$xoopsTpl->assign('toolbar', Utility::toolbar_bootstrap($interface_menu, false, $interface_icon));
$xoopsTpl->assign('now_op', $op);
$xoTheme->addStylesheet('modules/tad_blocks/css/module.css');
$xoTheme->addStylesheet('modules/tadtools/css/my-input.css');
include_once XOOPS_ROOT_PATH . '/footer.php';
/*-----------功能函數區--------------*/
//
function my_blocks()
{
global $xoopsDB, $xoopsTpl, $tad_blocks_adm, $xoopsUser, $position_arr, $type_arr, $tags;
$show_file = ['pic', 'img', 'icon'];
$show_link = ['link'];
$module_dirname = 'tad_blocks';
$uid = $xoopsUser ? $xoopsUser->uid() : 0;
$TadDataCenter = new TadDataCenter($module_dirname);
$my_blocks = [];
$where_uid = $tad_blocks_adm ? '' : "where a.`uid`='{$uid}'";
$sql = 'SELECT a.`type`, a.`bid` as `bbid`, b.* FROM `' . $xoopsDB->prefix('tad_blocks') . '` as a LEFT JOIN `' . $xoopsDB->prefix('newblocks') . '` as b ON a.`bid`=b.`bid` ' . $where_uid . ' ORDER BY a.`bid` DESC';
$result = Utility::query($sql) or Utility::web_error($sql);
while ($all = $xoopsDB->fetchArray($result)) {
$TadDataCenter->set_col('bid', $all['bid']);
$block = $TadDataCenter->getData();
$all['position'] = $position_arr[$all['side']];
$all['type'] = $type_arr[$all['type']];
$all['block'] = $block;
$all['clean_title'] = $all['title'];
$all['pic'] = '';
foreach ($tags as $tag) {
$start = strpos($all['title'], "[$tag]");
if ($start !== false) {
$all['tag'] = "<span class='badge badge-success bg-success'>$tag</span>";
$all['clean_title'] = substr($all['title'], 0, $start);
if (in_array($tag, $show_file)) {
$start = $start + strlen("[$tag]");
$pic = substr($all['title'], $start);
$all['pic'] = "<img src='{$pic}' alt='[$tag]'>";
}
}
}
$my_blocks[] = $all;
}
if (empty($my_blocks)) {
header("location:index.php?op=block_form");
exit;
} else {
$SweetAlert = new SweetAlert();
$SweetAlert->render("block_del", "index.php?op=block_del&bid=", 'bid');
$xoopsTpl->assign('position_arr', $position_arr);
$xoopsTpl->assign('my_blocks', $my_blocks);
}
}
//區塊編輯表單
function block_form($type = '', $bid = 0, $bbid = 0)
{
global $xoopsDB, $xoopsTpl, $xoopsUser, $type_arr, $tags, $tad_blocks_adm;
$type = Utility::check_string($type);
$module_dirname = 'tad_blocks';
$uid = $xoopsUser ? $xoopsUser->uid() : 0;
$and_uid = $tad_blocks_adm ? '' : "AND `uid`={$uid}";
//判斷目前使用者是否有:建立自訂區塊
$add_block = Utility::power_chk($module_dirname, 1);
$xoopsTpl->assign('add_block', $add_block);
$block = [];
if ($add_block) {
$TadDataCenter = new TadDataCenter('tad_blocks');
if ($bid or $bbid) {
if ($bid) {
$sql = 'SELECT `title`, `weight`, `side`, `content`, `visible` FROM `' . $xoopsDB->prefix('newblocks') . '` WHERE `bid` = ?';
$result = Utility::query($sql, 'i', [$bid]) or Utility::web_error($sql);
list($title, $weight, $side, $content, $visible) = $xoopsDB->fetchRow($result);
foreach ($tags as $tag) {
$start = strpos($title, "[$tag]");
if ($start !== false) {
$title = substr($title, 0, $start);
break;
}
}
$xoopsTpl->assign('bid', $bid);
} else {
$xoopsTpl->assign('bbid', $bbid);
$bid = $bbid;
}
$sql = 'SELECT `type` FROM `' . $xoopsDB->prefix('tad_blocks') . '` WHERE `bid`=? ' . $and_uid;
$result = Utility::query($sql, 'i', [$bid]) or Utility::web_error($sql);
list($type) = $xoopsDB->fetchRow($result);
if (empty($type)) {
$sql = 'REPLACE INTO `' . $xoopsDB->prefix('tad_blocks') . '` (`bid`, `type`, `uid`, `create_date`) VALUES (?, ?, ?, NOW())';
Utility::query($sql, 'isi', [$bid, (string) $type, $uid]) or Utility::web_error($sql);
$TadDataCenter->set_col('bid', $bid);
$TadDataCenter->set_var('auto_col_id', true);
$data_arr['title'][0] = $title;
// 加了addslashes()在匯入既有區塊會有問題
// $data_arr['content'][0] = addslashes($content);
$data_arr['content'][0] = $content;
$TadDataCenter->saveCustomData($data_arr);
}
} else {
$side = 0;
$weight = 0;
}
if ($type) {
require __DIR__ . "/type/{$type}/func.php";
$block = get_content($bid);
} else {
// 傳回陣列的項目
if ($bid) {
$TadDataCenter->set_col('bid', $bid);
$block = $TadDataCenter->getData();
}
$CkEditor = new CkEditor($module_dirname, "TDC[content]", $block['content'][0]);
$CkEditor->setHeight(350);
$editor = $CkEditor->render();
$xoopsTpl->assign('editor', $editor);
}
$xoopsTpl->assign('title', $title);
$xoopsTpl->assign('side', $side);
$xoopsTpl->assign('weight', $weight);
$xoopsTpl->assign('type', $type);
$xoopsTpl->assign('visible', $visible);
$xoopsTpl->assign('display', $block['display'][0]);
include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
$groups = $block['groups'] ? $block['groups'] : [1, 2, 3];
// $sel_grp = new \XoopsFormSelectCheckGroup('groups', "TDC[groups]", $groups);
$sel_grp = new \XoopsFormSelectGroup('groups', "TDC[groups]", true, $groups, 6, true);
$xoopsTpl->assign('sel_grp', $sel_grp->render());
$xoopsTpl->assign('type_arr', $type_arr);
tad_themes_setup();
}
}
//儲存並建立區塊
function block_save($type = '', $TDC = [], $bid = '', $bbid = '', $old_display = '')
{
global $xoopsDB, $xoopsUser, $tags, $tad_blocks_adm;
$type = Utility::check_string($type);
$mk_pic = ['pic', 'img'];
$module_dirname = 'tad_blocks';
$uid = $xoopsUser ? $xoopsUser->uid() : 0;
$title = $TDC['title'];
$side = $TDC['side'];
$weight = (int) $TDC['weight'];
if ($type == 'link' && !empty($TDC['url_json_code'])) {
$link_arr = json_decode($TDC['url_json_code'], true);
$maxKey = max(array_keys($TDC['url'])) + 1;
if (!empty($link_arr)) {
foreach ($link_arr as $item) {
$TDC['img_url'][$maxKey] = '';
$TDC['url'][$maxKey] = $item['url'];
$TDC['text'][$maxKey] = $item['title'];
$TDC['target'][$maxKey] = '_blank';
$maxKey++;
}
}
}
if (!empty($type)) {
require __DIR__ . "/type/{$type}/func.php";
$content = mk_content($bid, $TDC);
} else {
$content = $TDC['content'];
}
if (empty($type)) {
$content = AccessibilityFixer::of($content);
}
$last_modified = time();
if (empty($bid)) {
// 新增區塊
$sql = 'REPLACE INTO `' . $xoopsDB->prefix('newblocks') . '` (`mid`, `func_num`, `options`, `name`, `title`, `content`, `side`, `weight`, `visible`, `block_type`, `c_type`, `isactive`, `bcachetime`, `last_modified`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
Utility::query($sql, 'iissssiiissiii', [0, 0, '', _MD_TAD_BLOCKS_CUSTOMIZED, $title, $content, $side, $weight, 1, 'C', 'H', 1, 0, $last_modified]) or Utility::web_error($sql);
$bid = $xoopsDB->getInsertId();
if ($bid) {
// 新增區塊顯示方式
$sql = 'REPLACE INTO `' . $xoopsDB->prefix('block_module_link') . '` (`block_id`, `module_id`) VALUES (?, ?)';
Utility::query($sql, 'ii', [$bid, $TDC['display']]) or Utility::web_error($sql);
// 新增區塊讀取權限
foreach ($_POST['TDC']['groups'] as $group_id) {
$sql = 'REPLACE INTO `' . $xoopsDB->prefix('group_permission') . '` (`gperm_groupid`, `gperm_itemid`, `gperm_modid`, `gperm_name`) VALUES (?, ?, 1, ?)';
Utility::query($sql, 'iis', [$group_id, $bid, 'block_read']) or Utility::web_error($sql);
}
$TDC['groups'] = $_POST['TDC']['groups'];
$TadDataCenter = new TadDataCenter($module_dirname);
// 從舊設定來新增模組
if (!empty($bbid)) {
// 新增區塊設定
$sql = 'UPDATE `' . $xoopsDB->prefix('tad_blocks') . '` SET `bid`=?, `type`=?, `uid`=?, `create_date`=now() WHERE `bid`=?';
Utility::query($sql, 'isii', [$bid, $type, $uid, $bbid]) or Utility::web_error($sql);
$TadDataCenter->set_col('bid', $bid);
$TadDataCenter->set_var('auto_col_id', true);
$TadDataCenter->saveData($TDC);
$TadDataCenter->set_col('bid', $bbid);
$TadDataCenter->delData();
} else {
// 新增區塊設定
$sql = 'REPLACE INTO `' . $xoopsDB->prefix('tad_blocks') . '` (`bid`, `type`, `uid`, `create_date`) VALUES (?, ?, ?, NOW())';
Utility::query($sql, 'isi', [$bid, $type, $uid]) or Utility::web_error($sql);
$TadDataCenter->set_col('bid', $bid);
$TadDataCenter->set_var('auto_col_id', true);
$TadDataCenter->saveData($TDC);
}
}
} else {
$sql = 'SELECT * FROM `' . $xoopsDB->prefix('newblocks') . '` WHERE `bid`=?';
$result = Utility::query($sql, 'i', [$bid]) or die($sql);
$block = $xoopsDB->fetchArray($result);
foreach ($tags as $tag) {
$start = strpos($block['title'], "[$tag]");
if ($start !== false) {
if (!empty($title) and in_array($tag, $mk_pic)) {
$TadDataCenter = new TadDataCenter('tad_blocks');
$TadDataCenter->set_col('block_logo', 0);
$logo_setting = $TadDataCenter->getData();
if ($logo_setting) {
foreach ($logo_setting as $key => $value) {
$$key = $value[0];
}
}
$tag2 = "[$tag]" . Utility::mkTitlePic('/uploads/bid', $bid, $title, $size, $border_size, $color, $border_color, $font_file_sn, $shadow_color, $shadow_x, $shadow_y, $shadow_size);
} elseif ($tag == 'hide') {
$tag2 = '[hide]';
} else {
$tag2 = substr($block['title'], $start);
}
}
}
$and_uid = $tad_blocks_adm ? '' : "AND `uid`={$uid}";
// 更新區塊設定
$sql = 'UPDATE `' . $xoopsDB->prefix('tad_blocks') . '` SET `create_date`=NOW() WHERE `bid`=? ' . $and_uid;
if (Utility::query($sql, 'i', [$bid], true, false, null, true)) {
// 更新區塊
$sql = 'UPDATE `' . $xoopsDB->prefix('newblocks') . '` SET `title`=?, `content`=?, `side`=?, `weight`=?, `last_modified`=? WHERE `bid`=?';
Utility::query($sql, 'ssiiii', [$title . $tag2, $content, $side, $weight, $last_modified, $bid]) or Utility::web_error($sql);
// 更新區塊顯示方式
if ($old_display != $TDC['display']) {
$sql = 'UPDATE `' . $xoopsDB->prefix('block_module_link') . '` SET `module_id`=? WHERE `block_id`=?';
Utility::query($sql, 'ii', [$TDC['display'], $bid]) or Utility::web_error($sql);
}
// 刪除區塊權限
$sql = 'DELETE FROM `' . $xoopsDB->prefix('group_permission') . '` WHERE `gperm_itemid`=? AND `gperm_modid`=1 AND `gperm_name`=?';
Utility::query($sql, 'is', [$bid, 'block_read']) or Utility::web_error($sql);
// 更新區塊讀取權限
foreach ($_POST['TDC']['groups'] as $group_id) {
$sql = 'REPLACE INTO `' . $xoopsDB->prefix('group_permission') . '` (`gperm_groupid`, `gperm_itemid`, `gperm_modid`, `gperm_name`) VALUES (?, ?, 1, ?)';
Utility::query($sql, 'iis', [$group_id, $bid, 'block_read']) or Utility::web_error($sql);
}
$TDC['groups'] = $_POST['TDC']['groups'];
$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col('bid', $bid);
$TadDataCenter->set_var('auto_col_id', true);
$TadDataCenter->saveData($TDC);
} else {
Utility::web_error($sql);
}
}
}
//刪除區塊
function block_del($bid = '')
{
global $xoopsDB, $xoopsUser, $tad_blocks_adm;
$module_dirname = 'tad_blocks';
$uid = $xoopsUser ? $xoopsUser->uid() : 0;
$and_uid = $tad_blocks_adm ? '' : "AND `uid`={$uid}";
// 刪除區塊設定
$sql = 'DELETE FROM `' . $xoopsDB->prefix('tad_blocks') . '` WHERE `bid`=? ' . $and_uid;
if (Utility::query($sql, 'i', [$bid], true, false, null, true)) {
$TadDataCenter = new TadDataCenter($module_dirname);
$TadDataCenter->set_col('bid', $bid);
$TadDataCenter->delData();
// 刪除區塊
$sql = 'DELETE FROM `' . $xoopsDB->prefix('newblocks') . '` WHERE `bid` = ?';
Utility::query($sql, 'i', [$bid]) or Utility::web_error($sql);
// 刪除區塊顯示方式
$sql = 'DELETE FROM `' . $xoopsDB->prefix('block_module_link') . '` WHERE `block_id` = ?';
Utility::query($sql, 'i', [$bid]) or Utility::web_error($sql);
// 刪除區塊權限
$sql = 'DELETE FROM `' . $xoopsDB->prefix('group_permission') . '` WHERE `gperm_itemid` = ? AND `gperm_modid` = 1 AND `gperm_name` = ?';
Utility::query($sql, 'is', [$bid, 'block_read']) or Utility::web_error($sql);
} else {
Utility::web_error($sql);
}
}