1 | <?php |
||||||
2 | /** |
||||||
3 | * ExtGallery User area |
||||||
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 | use XoopsModules\Extgallery; |
||||||
19 | |||||||
20 | require_once __DIR__ . '/header.php'; |
||||||
21 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||||
22 | //require_once __DIR__ . '/class/Utility.php'; |
||||||
23 | |||||||
24 | /** @var Extgallery\Helper $helper */ |
||||||
25 | $helper = Extgallery\Helper::getInstance(); |
||||||
26 | |||||||
27 | if (\Xmf\Request::hasVar('op', 'GET')) { |
||||||
28 | $op = $_GET['op']; |
||||||
29 | } else { |
||||||
30 | $op = 'default'; |
||||||
31 | } |
||||||
32 | |||||||
33 | if (\Xmf\Request::hasVar('step', 'POST')) { |
||||||
34 | $step = $_POST['step']; |
||||||
35 | } else { |
||||||
36 | $step = 'default'; |
||||||
37 | } |
||||||
38 | |||||||
39 | if (!isset($GLOBALS['xoopsUser'])) { |
||||||
40 | redirect_header('index.php'); |
||||||
41 | } elseif (!$GLOBALS['xoopsUser']->isAdmin()) { |
||||||
42 | redirect_header('index.php'); |
||||||
43 | } |
||||||
44 | $moduleDirName = basename(__DIR__); |
||||||
45 | $utility = new Extgallery\Utility(); |
||||||
46 | switch ($op) { |
||||||
47 | case 'edit': |
||||||
48 | |||||||
49 | switch ($step) { |
||||||
50 | case 'enreg': |
||||||
51 | /** @var Extgallery\PublicPhotoHandler $photoHandler */ |
||||||
52 | $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto'); |
||||||
53 | $myts = \MyTextSanitizer::getInstance(); |
||||||
54 | $photo = $photoHandler->getPhoto($_POST['photo_id']); |
||||||
55 | |||||||
56 | $data['cat_id'] = $_POST['cat_id']; |
||||||
57 | $data['photo_desc'] = $_POST['photo_desc']; |
||||||
58 | $data['photo_title'] = $_POST['photo_title']; |
||||||
59 | $data['photo_weight'] = $_POST['photo_weight']; |
||||||
60 | |||||||
61 | if (\Xmf\Request::hasVar('photo_extra', 'POST')) { |
||||||
62 | $data['photo_extra'] = $_POST['photo_extra']; |
||||||
63 | } |
||||||
64 | |||||||
65 | $photoHandler->modifyPhoto(\Xmf\Request::getInt('photo_id', 0, 'POST'), $data); |
||||||
66 | |||||||
67 | // For xoops tag |
||||||
68 | if ((1 == $helper->getConfig('usetag')) && is_dir('../tag')) { |
||||||
69 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag'); |
||||||
70 | $tagHandler->updateByItem($_POST['tag'], $_POST['photo_id'], $xoopsModule->getVar('dirname'), 0); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
71 | } |
||||||
72 | |||||||
73 | // If the photo category change |
||||||
74 | if ($photo->getVar('cat_id') != $_POST['cat_id']) { |
||||||
75 | $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
||||||
76 | $oldCat = $catHandler->getCat($photo->getVar('cat_id')); |
||||||
0 ignored issues
–
show
The method
getCat() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
77 | $newCat = $catHandler->getCat($_POST['cat_id']); |
||||||
78 | |||||||
79 | // Set new category as album |
||||||
80 | $catHandler->modifyCat(['cat_id' => \Xmf\Request::getInt('cat_id', 0, 'POST'), 'cat_isalbum' => 1]); |
||||||
0 ignored issues
–
show
The method
modifyCat() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
81 | |||||||
82 | // Update album count |
||||||
83 | if (1 == $oldCat->getVar('cat_nb_photo')) { |
||||||
84 | $criteria = new \CriteriaCompo(); |
||||||
85 | $criteria->add(new \Criteria('nleft', $oldCat->getVar('nleft'), '<')); |
||||||
86 | $criteria->add(new \Criteria('nright', $oldCat->getVar('nright'), '>')); |
||||||
87 | $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album - 1', $criteria); |
||||||
0 ignored issues
–
show
The method
updateFieldValue() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
88 | } |
||||||
89 | |||||||
90 | if (0 == $newCat->getVar('cat_nb_photo')) { |
||||||
91 | $criteria = new \CriteriaCompo(); |
||||||
92 | $criteria->add(new \Criteria('nleft', $newCat->getVar('nleft'), '<')); |
||||||
93 | $criteria->add(new \Criteria('nright', $newCat->getVar('nright'), '>')); |
||||||
94 | $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria); |
||||||
95 | } |
||||||
96 | |||||||
97 | // Update photo count |
||||||
98 | $criteria = new \CriteriaCompo(); |
||||||
99 | $criteria->add(new \Criteria('nleft', $newCat->getVar('nleft'), '<=')); |
||||||
100 | $criteria->add(new \Criteria('nright', $newCat->getVar('nright'), '>=')); |
||||||
101 | $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + 1', $criteria); |
||||||
102 | |||||||
103 | $criteria = new \CriteriaCompo(); |
||||||
104 | $criteria->add(new \Criteria('nleft', $oldCat->getVar('nleft'), '<=')); |
||||||
105 | $criteria->add(new \Criteria('nright', $oldCat->getVar('nright'), '>=')); |
||||||
106 | $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo - 1', $criteria); |
||||||
107 | |||||||
108 | // If the old album don't contains other photo |
||||||
109 | if (0 == $photoHandler->nbPhoto($oldCat)) { |
||||||
110 | $catHandler->modifyCat(['cat_id' => $photo->getVar('cat_id'), 'cat_isalbum' => 0]); |
||||||
111 | redirect_header('public-categories.php?id=' . $photo->getVar('cat_id'), 3, _MD_EXTGALLERY_PHOTO_UPDATED); |
||||||
112 | } else { |
||||||
113 | redirect_header('public-album.php?id=' . $photo->getVar('cat_id'), 3, _MD_EXTGALLERY_PHOTO_UPDATED); |
||||||
114 | } |
||||||
115 | } else { |
||||||
116 | redirect_header('public-photo.php?photoId=' . $photo->getVar('photo_id'), 3, _MD_EXTGALLERY_PHOTO_UPDATED); |
||||||
117 | } |
||||||
118 | |||||||
119 | break; |
||||||
120 | case 'default': |
||||||
121 | default: |
||||||
122 | |||||||
123 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||||||
124 | $myts = \MyTextSanitizer::getInstance(); |
||||||
125 | /** @var Extgallery\PublicCategoryHandler $catHandler */ |
||||||
126 | $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
||||||
127 | /** @var Extgallery\PublicPhotoHandler $photoHandler */ |
||||||
128 | $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto'); |
||||||
129 | |||||||
130 | $photo = $photoHandler->getPhoto(\Xmf\Request::getInt('id', 0, 'GET')); |
||||||
131 | |||||||
132 | echo '<img src="' . XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name') . '">'; |
||||||
133 | |||||||
134 | $form = new \XoopsThemeForm(_MD_EXTGALLERY_MODIFY_PHOTO, 'add_photo', 'public-modify.php?op=edit', 'post', true); |
||||||
135 | $form->addElement(new \XoopsFormLabel(_MD_EXTGALLERY_CATEGORY, $catHandler->getLeafSelect('cat_id', false, $photo->getVar('cat_id')))); |
||||||
136 | $form->addElement(new \XoopsFormText(_MD_EXTGALLERY_PHOTO_WEIGHT, 'photo_weight', '3', '11', $photo->getVar('photo_weight')), false); |
||||||
137 | $form->addElement(new \XoopsFormText(_MD_EXTGALLERY_PHOTO_TITLE, 'photo_title', '50', '150', $photo->getVar('photo_title')), false); |
||||||
138 | //DNPROSSI - wysiwyg editors from xoopseditors |
||||||
139 | //TODO dohtml - dobr |
||||||
140 | $photo_desc = $myts->displayTarea($photo->getVar('photo_desc'), 0, 1, 1, 1, 0); |
||||||
141 | $editor = $utility::getWysiwygForm(_MD_EXTGALLERY_DESC, 'photo_desc', $photo_desc, 15, 60, '100%', '350px', 'hometext_hidden'); |
||||||
142 | $form->addElement($editor, false); |
||||||
143 | if ($helper->getConfig('display_extra_field')) { |
||||||
144 | $form->addElement(new \XoopsFormTextArea(_MD_EXTGALLERY_EXTRA_INFO, 'photo_extra', $photo->getVar('photo_extra'))); |
||||||
145 | } |
||||||
146 | |||||||
147 | // For xoops tag |
||||||
148 | if ((1 == $helper->getConfig('usetag')) && is_dir('../tag')) { |
||||||
149 | $tagId = $photo->isNew() ? 0 : $photo->getVar('photo_id'); |
||||||
150 | require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php'; |
||||||
151 | $form->addElement(new \XoopsModules\Tag\FormTag('tag', 60, 255, $tagId, 0)); |
||||||
152 | } |
||||||
153 | |||||||
154 | $form->addElement(new \XoopsFormHidden('photo_id', $_GET['id'])); |
||||||
155 | $form->addElement(new \XoopsFormHidden('step', 'enreg')); |
||||||
156 | $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||||||
157 | $form->display(); |
||||||
158 | |||||||
159 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||||||
160 | |||||||
161 | break; |
||||||
162 | } |
||||||
163 | |||||||
164 | break; |
||||||
165 | case 'delete': |
||||||
166 | /** @var Extgallery\PublicCategoryHandler $catHandler */ |
||||||
167 | $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
||||||
168 | /** @var Extgallery\PublicPhotoHandler $photoHandler */ |
||||||
169 | $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto'); |
||||||
170 | |||||||
171 | $photo = $photoHandler->getPhoto(\Xmf\Request::getInt('id', 0, 'GET')); |
||||||
172 | $photoHandler->deletePhoto($photo); |
||||||
173 | |||||||
174 | $cat = $catHandler->getCat($photo->getVar('cat_id')); |
||||||
175 | |||||||
176 | // Update photo count |
||||||
177 | $criteria = new \CriteriaCompo(); |
||||||
178 | $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<=')); |
||||||
179 | $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>=')); |
||||||
180 | $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo - 1', $criteria); |
||||||
181 | |||||||
182 | if (1 == $cat->getVar('cat_nb_photo')) { |
||||||
183 | // Update album count |
||||||
184 | $criteria = new \CriteriaCompo(); |
||||||
185 | $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<')); |
||||||
186 | $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>')); |
||||||
187 | $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album - 1', $criteria); |
||||||
188 | |||||||
189 | $catHandler->modifyCat(['cat_id' => $photo->getVar('cat_id'), 'cat_isalbum' => 0]); |
||||||
190 | |||||||
191 | redirect_header('public-categories.php?id=' . $photo->getVar('cat_id')); |
||||||
192 | } else { |
||||||
193 | redirect_header('public-album.php?id=' . $photo->getVar('cat_id')); |
||||||
194 | } |
||||||
195 | |||||||
196 | break; |
||||||
197 | } |
||||||
198 |