1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Smallworld; |
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
|
|
|
* SmallWorld |
17
|
|
|
* |
18
|
|
|
* @package \XoopsModules\Smallworld |
19
|
|
|
* @license GNU GPL (https://www.gnu.org/licenses/gpl-2.0.html/) |
20
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
21
|
|
|
* @copyright 2011 Culex |
22
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
23
|
|
|
* @link https://github.com/XoopsModules25x/smallworld |
24
|
|
|
* @since 1.0 |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
* Images Class |
30
|
|
|
* |
31
|
|
|
* Handles album creation and retrieval |
32
|
|
|
* |
33
|
|
|
*/ |
34
|
|
|
class Images |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Create album folders |
38
|
|
|
* |
39
|
|
|
* @todo use \Smallworld\SysUtility::createFolder() to refactor this method |
40
|
|
|
* @param int $userId |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function createAlbum($userId) |
44
|
|
|
{ |
45
|
|
|
//@todo change $dir to XOOPS_UPLOAD_PATH . /smallworld/albums/[$userId] |
46
|
|
|
$dir = XOOPS_UPLOAD_PATH . '/albums_smallworld'; |
47
|
|
|
if (!file_exists($dir . '/' . $userId . '/thumbnails') || !file_exists($dir . '/' . $userId . '/')) { |
48
|
|
|
if (!is_dir($dir . '/')) { |
49
|
|
|
if (!mkdir($dir, 0777) && !is_dir($dir)) { |
50
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
51
|
|
|
} |
52
|
|
|
} else { |
53
|
|
View Code Duplication |
if (!mkdir($concurrentDirectory = $dir . '/' . $userId, 0777) && !is_dir($concurrentDirectory)) { |
|
|
|
|
54
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); |
55
|
|
|
} |
56
|
|
View Code Duplication |
if (!mkdir($concurrentDirectory = $dir . '/' . $userId . '/thumbnails', 0777) && !is_dir($concurrentDirectory)) { |
|
|
|
|
57
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); |
58
|
|
|
} |
59
|
|
|
file_put_contents("{$dir}/index.html", '<script>history.go(-1);</script>'); |
60
|
|
|
file_put_contents("{$dir}/{$userId}/index.html", '<script>history.go(-1);</script>'); |
61
|
|
|
file_put_contents("{$dir}/{$userId}/thumbnails/index.html", '<script>history.go(-1);</script>'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* View user album |
68
|
|
|
* |
69
|
|
|
* @param int $userId owner |
70
|
|
|
* @param int $user visitors |
71
|
|
|
* @return array|bool |
72
|
|
|
*/ |
73
|
|
|
public function viewalbum($userId, $user) |
74
|
|
|
{ |
75
|
|
|
$post = []; |
76
|
|
|
$checkFriend = new User(); |
77
|
|
|
$foundArray = $checkFriend->friendcheck((int)$userId, (int)$user); |
78
|
|
|
if (0 < count($foundArray)) { |
79
|
|
|
// check friend is good to go |
80
|
|
|
$sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_images') . " WHERE userid = '" . (int)$user . "'"; |
81
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); |
82
|
|
|
while (false !== ($sqlfetch = $GLOBALS['xoopsDB']->fetchArray($result))) { |
83
|
|
|
$post[] = [ |
84
|
|
|
'id' => stripslashes($sqlfetch['id']), |
85
|
|
|
'userid' => stripslashes($sqlfetch['userid']), |
86
|
|
|
'imgurl' => stripslashes($sqlfetch['imgurl']), |
87
|
|
|
'desc' => smallworld_cleanup_string($sqlfetch['desc']), |
88
|
|
|
'alt' => smallworld_cleanup_string($sqlfetch['desc']), |
89
|
|
|
'time' => stripslashes($sqlfetch['time']), |
90
|
|
|
'editimg' => "<span class='smallworld_edit_imgdesc_holder'><img src='" . Helper::getInstance()->url('images/edit_icon.png') . "'></span> <a class='smallworld_edit_imgdesc' href='editimages.php'>" . _SMALLWORLD_EDITDESCRIPTION . '</a>' |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $post; |
95
|
|
|
} |
96
|
|
|
//Not a friends album |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get image count for user |
102
|
|
|
* |
103
|
|
|
* @param int $userid |
104
|
|
|
* @return int |
105
|
|
|
*/ |
106
|
|
View Code Duplication |
public function count($userid) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_images') . " WHERE userid = '" . $userid . "'"; |
109
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
110
|
|
|
|
111
|
|
|
return $GLOBALS['xoopsDB']->getRowsNum($result); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.