Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

class/publiccat.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ExtGallery Class Manager
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   {@link https://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Zoullou (http://www.zoullou.net)
15
 * @package     ExtGallery
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
19
20
require_once __DIR__ . '/catHandler.php';
21
22
/**
23
 * Class ExtgalleryPublicCat
24
 */
25
class ExtgalleryPublicCat extends ExtgalleryCat
26
{
27
    /**
28
     * ExtgalleryPublicCat constructor.
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
}
35
36
/**
37
 * Class ExtgalleryPublicCatHandler
38
 */
39
class ExtgalleryPublicCatHandler extends ExtgalleryCatHandler
40
{
41
    /**
42
     * ExtgalleryPublicCatHandler constructor.
43
     * @param XoopsDatabase $db
44
     */
45
    public function __construct(XoopsDatabase $db)
46
    {
47
        parent::__construct($db, 'public');
48
    }
49
50
    /**
51
     * @param $data
52
     *
53
     * @return bool
54
     */
55
    public function createCat($data)
0 ignored issues
show
createCat uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
56
    {
57
        /** @var ExtgalleryPublicCat $cat */
58
        $cat = $this->create();
59
        $cat->setVars($data);
60
61
        if (!$this->_haveValidParent($cat)) {
62
            return false;
63
        }
64
65
        $this->insert($cat, true);
66
        $this->rebuild();
67
68
        $criteria = new CriteriaCompo();
69
        $criteria->setSort('cat_id');
70
        $criteria->setOrder('DESC');
71
        $criteria->setLimit(1);
72
73
        $cat = $this->getObjects($criteria);
74
        $cat = $cat[0];
75
76
        $moduleId = $GLOBALS['xoopsModule']->getVar('mid');
77
78
        // Retriving permission mask
79
        /** @var XoopsGroupPermHandler $gpermHandler */
80
        $gpermHandler = xoops_getHandler('groupperm');
81
        $moduleId     = $GLOBALS['xoopsModule']->getVar('mid');
82
        $groups       = $GLOBALS['xoopsUser']->getGroups();
83
84
        $criteria = new CriteriaCompo();
85
        $criteria->add(new Criteria('gperm_name', 'extgallery_public_mask'));
86
        $criteria->add(new Criteria('gperm_modid', $moduleId));
87
        $permMask = $gpermHandler->getObjects($criteria);
88
89
        // Retriving group list
90
        /** @var \XoopsMemberHandler $memberHandler */
91
        $memberHandler = xoops_getHandler('member');
92
        $glist         = $memberHandler->getGroupList();
93
94
        // Applying permission mask
95
        $permArray       = include XOOPS_ROOT_PATH . '/modules/extgallery/include/perm.php';
96
        $modulePermArray = $permArray['modulePerm'];
97
        $pluginPermArray = $permArray['pluginPerm'];
98
99
        foreach ($permMask as $perm) {
100 View Code Duplication
            foreach ($modulePermArray as $permMask) {
101
                if ($perm->getVar('gperm_itemid') == $permMask['maskId']) {
102
                    $gpermHandler->addRight($permMask['name'], $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId);
103
                }
104
            }
105
106 View Code Duplication
            foreach ($pluginPermArray as $permMask) {
107
                if ($perm->getVar('gperm_itemid') == $permMask['maskId']) {
108
                    $gpermHandler->addRight($permMask['name'], $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId);
109
                }
110
            }
111
        }
112
    }
113
114
    /**
115
     * @param XoopsObject $cat
116
     *
117
     * @return bool
118
     */
119
    public function _haveValidParent(XoopsObject $cat = null)
120
    {
121
        // Check if haven't photo in parent category (parent category isn't an album)
122
        $parentCat = $this->get($cat->getVar('cat_pid'));
123
124
        return !$this->_isAlbum($parentCat);
125
    }
126
127
    /**
128
     * @return ExtgalleryPublicPermHandler
129
     */
130
    public function _getPermHandler()
131
    {
132
        return ExtgalleryPublicPermHandler::getInstance();
133
    }
134
}
135