Completed
Push — master ( 330830...6eccd4 )
by
unknown
01:37
created

SmallWorldImages::createAlbum()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php namespace Xoopsmodules\smallworld;
2
/**
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * SmallWorld
14
 *
15
 * @copyright    The XOOPS Project (https://xoops.org)
16
 * @copyright    2011 Culex
17
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
18
 * @package      SmallWorld
19
 * @since        1.0
20
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
21
 */
22 View Code Duplication
class SmallWorldImages
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
23
{
24
    /**
25
     * @Create folders
26
     * @param  int $userID
27
     * @return void
28
     */
29
    public function createAlbum($userID)
30
    {
31
        $dir = XOOPS_ROOT_PATH . '/uploads/albums_smallworld';
32
        if (!file_exists($dir . '/' . $userID . '/thumbnails') || !file_exists($dir . '/' . $userID . '/')) {
33
            if (!is_dir($dir . '/')) {
34
                mkdir($dir, 0777);
35
            } else {
36
                mkdir($dir . '/' . $userID, 0777);
37
                mkdir($dir . '/' . $userID . '/thumbnails', 0777);
38
                Smallworld_CreateIndexFiles($dir . '/');
39
                Smallworld_CreateIndexFiles($dir . '/' . $userID . '/');
40
                Smallworld_CreateIndexFiles($dir . '/' . $userID . '/thumbnails/');
41
            }
42
        }
43
    }
44
45
    /**
46
     * @View user album. Userid = owner, user = visitor
47
     * @param  int $userID
48
     * @param  int $user
49
     * @return array|bool
50
     */
51
    public function viewalbum($userID, $user)
52
    {
53
        global $xoopsUser, $xoopsDB, $xoopsTpl;
54
        $post        = [];
55
        $checkFriend = new SmallWorldUser;
56
        if (0 != $checkFriend->friendcheck($userID, $user)) {
57
            // check friend is good to go
58
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_images') . " WHERE userid = '" . $user . "'";
59
            $result = $xoopsDB->query($sql);
60
            $i      = 0;
61
            while ($sqlfetch = $xoopsDB->fetchArray($result)) {
62
                $post[$i]['id']      = stripslashes($sqlfetch['id']);
63
                $post[$i]['userid']  = stripslashes($sqlfetch['userid']);
64
                $post[$i]['imgurl']  = stripslashes($sqlfetch['imgurl']);
65
                $post[$i]['desc']    = Smallworld_cleanup_string($sqlfetch['desc']);
66
                $post[$i]['alt']     = Smallworld_cleanup_string($sqlfetch['desc']);
67
                $post[$i]['time']    = stripslashes($sqlfetch['time']);
68
                $post[$i]['editimg'] = "<span class='smallworld_edit_imgdesc_holder'><img src='assets/images/edit_icon.png'></span> <a class='smallworld_edit_imgdesc' href='editimages.php'>" . _SMALLWORLD_EDITDESCRIPTION . '</a>';
69
                ++$i;
70
            }
71
72
            return $post;
73
        } else {
74
            //Not a friends album
75
            return false;
76
        }
77
    }
78
79
    /**
80
     * @Get image count for user
81
     * @param  int $userid
82
     * @return int
83
     */
84
    public function count($userid)
85
    {
86
        global $xoopsDB;
87
        $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_images') . " WHERE userid = '" . $userid . "'";
88
        $result = $xoopsDB->queryF($sql);
89
90
        return $xoopsDB->getRowsNum($result);
91
    }
92
}
93