1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ajaxfilelist.php - supply list of file attachments for a page |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
6
|
|
|
* @license gwiki/docs/license.txt GNU General Public License (GPL) |
7
|
|
|
* @since 1.0 |
8
|
|
|
* @author Richard Griffith <[email protected]> |
9
|
|
|
* @package gwiki |
10
|
|
|
*/ |
11
|
|
|
include __DIR__ . '/../../mainfile.php'; |
12
|
|
|
$xoopsLogger->activated = false; |
13
|
|
|
|
14
|
|
|
header('Pragma: public'); |
15
|
|
|
header('Cache-Control: no-cache'); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param $string |
19
|
|
|
* |
20
|
|
|
* @return string |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
function cleaner($string) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$string = stripcslashes($string); |
25
|
|
|
$string = html_entity_decode($string); |
26
|
|
|
$string = strip_tags($string); // DANGER -- kills wiki text |
27
|
|
|
$string = trim($string); |
28
|
|
|
$string = stripslashes($string); |
29
|
|
|
|
30
|
|
|
return $string; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param $uid |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
function getUserName($uid) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
global $xoopsConfig; |
41
|
|
|
|
42
|
|
|
$uid = (int)$uid; |
43
|
|
|
|
44
|
|
|
if ($uid > 0) { |
45
|
|
|
$memberHandler = xoops_getHandler('member'); |
46
|
|
|
$user = $memberHandler->getUser($uid); |
47
|
|
|
if (is_object($user)) { |
48
|
|
|
return "<a href=\"" . XOOPS_URL . "/userinfo.php?uid=$uid\">" . htmlspecialchars($user->getVar('uname'), ENT_QUOTES) . '</a>'; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $xoopsConfig['anonymous']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// $_GET variables we use |
56
|
|
|
unset($page, $bid, $id); |
57
|
|
|
$page = isset($_GET['page']) ? cleaner($_GET['page']) : ''; |
58
|
|
|
|
59
|
|
|
$dir = basename(__DIR__); |
60
|
|
|
|
61
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('gwiki_page_files') . ' WHERE keyword = \'' . $page . '\' ' . ' ORDER BY file_name '; |
62
|
|
|
$result = $xoopsDB->query($sql); |
63
|
|
|
|
64
|
|
|
$filess = array(); |
65
|
|
|
|
66
|
|
|
for ($i = 0, $iMax = $xoopsDB->getRowsNum($result); $i < $iMax; ++$i) { |
67
|
|
|
$row = $xoopsDB->fetchArray($result); |
68
|
|
|
$row['iconlink'] = XOOPS_URL . '/modules/' . $dir . '/assets/icons/48px/' . $row['file_icon'] . '.png'; |
69
|
|
|
$row['userlink'] = getUserName($row['file_uid']); |
70
|
|
|
$row['size'] = number_format($row['file_size']); |
71
|
|
|
$row['date'] = date($xoopsModuleConfig['date_format'], $row['file_upload_date']); |
72
|
|
|
|
73
|
|
|
$files[] = $row; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$jsonimages = json_encode($files); |
77
|
|
|
echo $jsonimages; |
78
|
|
|
exit; |
79
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.