1
|
|
|
<?php namespace XoopsModules\Extgallery; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ExtGallery Class Manager |
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
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12
|
|
|
* |
13
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
14
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
15
|
|
|
* @author Zoullou (http://www.zoullou.net) |
16
|
|
|
* @package ExtGallery |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use XoopsModules\Extgallery; |
20
|
|
|
|
21
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class Extgallery\PublicCategoryHandler |
26
|
|
|
*/ |
27
|
|
|
class PublicCategoryHandler extends Extgallery\CategoryHandler |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Extgallery\PublicCategoryHandler constructor. |
31
|
|
|
* @param \XoopsDatabase $db |
32
|
|
|
*/ |
33
|
|
|
public function __construct(\XoopsDatabase $db) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
parent::__construct($db, 'public'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $data |
40
|
|
|
* |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function createCat($data) |
44
|
|
|
{ |
45
|
|
|
/** @var Extgallery\PublicCategory $cat */ |
46
|
|
|
$cat = $this->create(); |
47
|
|
|
$cat->setVars($data); |
48
|
|
|
|
49
|
|
|
if (!$this->hasValidParent($cat)) { |
50
|
|
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->insert($cat, true); |
54
|
|
|
$this->rebuild(); |
55
|
|
|
|
56
|
|
|
$criteria = new \CriteriaCompo(); |
|
|
|
|
57
|
|
|
$criteria->setSort('cat_id'); |
58
|
|
|
$criteria->setOrder('DESC'); |
59
|
|
|
$criteria->setLimit(1); |
60
|
|
|
|
61
|
|
|
$cat =& $this->getObjects($criteria); |
62
|
|
|
$cat = $cat[0]; |
63
|
|
|
|
64
|
|
|
$moduleId = $GLOBALS['xoopsModule']->getVar('mid'); |
|
|
|
|
65
|
|
|
|
66
|
|
|
// Retriving permission mask |
67
|
|
|
/** @var \XoopsGroupPermHandler $gpermHandler */ |
68
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
|
|
|
69
|
|
|
$moduleId = $GLOBALS['xoopsModule']->getVar('mid'); |
70
|
|
|
$groups = $GLOBALS['xoopsUser']->getGroups(); |
71
|
|
|
|
72
|
|
|
$criteria = new \CriteriaCompo(); |
73
|
|
|
$criteria->add(new \Criteria('gperm_name', 'extgallery_public_mask')); |
|
|
|
|
74
|
|
|
$criteria->add(new \Criteria('gperm_modid', $moduleId)); |
75
|
|
|
$permMask = $gpermHandler->getObjects($criteria); |
76
|
|
|
|
77
|
|
|
// Retriving group list |
78
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
79
|
|
|
$memberHandler = xoops_getHandler('member'); |
80
|
|
|
$glist = $memberHandler->getGroupList(); |
81
|
|
|
|
82
|
|
|
// Applying permission mask |
83
|
|
|
$permArray = include XOOPS_ROOT_PATH . '/modules/extgallery/include/perm.php'; |
|
|
|
|
84
|
|
|
$modulePermArray = $permArray['modulePerm']; |
85
|
|
|
$pluginPermArray = $permArray['pluginPerm']; |
86
|
|
|
|
87
|
|
|
foreach ($permMask as $perm) { |
88
|
|
|
foreach ($modulePermArray as $permMask) { |
89
|
|
|
if ($perm->getVar('gperm_itemid') == $permMask['maskId']) { |
90
|
|
|
$gpermHandler->addRight($permMask['name'], $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
foreach ($pluginPermArray as $permMask) { |
95
|
|
|
if ($perm->getVar('gperm_itemid') == $permMask['maskId']) { |
96
|
|
|
$gpermHandler->addRight($permMask['name'], $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
return true; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param \XoopsObject $cat |
105
|
|
|
* |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function hasValidParent(\XoopsObject $cat = null) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
// Check if haven't photo in parent category (parent category isn't an album) |
111
|
|
|
$parentCat = $this->get($cat->getVar('cat_pid')); |
|
|
|
|
112
|
|
|
|
113
|
|
|
return !$this->_isAlbum($parentCat); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return Extgallery\PublicPermHandler |
118
|
|
|
*/ |
119
|
|
|
public function getPermHandler() |
120
|
|
|
{ |
121
|
|
|
return Extgallery\PublicPermHandler::getInstance(); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.