hope this can be added in the near future.
1 2 /**
3 * XOOPS image 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 The XOOPS Project http://sourceforge.net/projects/xoops/
13 * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14 * @package core
15 * @since 2.0.0
16 * @version $Id: imagemanager.php 4941 2010-07-22 17:13:36Z beckmi $
17 */
18
19 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
20
21 if (!isset($_REQUEST['target'])) {
22 exit('Target not set');
23 }
24
25 $target = $_REQUEST['target'];
26 $op = 'list';
27 if (isset($_GET['op']) && $_GET['op'] == 'upload') {
28 $op = 'upload';
29 } elseif (isset($_POST['op']) && $_POST['op'] == 'doupload') {
30 $op = 'doupload';
31 }
32
33 if (!is_object($xoopsUser)) {
34 $group = array(XOOPS_GROUP_ANONYMOUS);
35 } else {
36 $group = $xoopsUser->getGroups();
37 }
38 if ($op == 'list') {
39 require_once $GLOBALS['xoops']->path('class/template.php');
40 $xoopsTpl = new XoopsTpl();
41 $xoopsTpl->assign('lang_imgmanager', _IMGMANAGER);
42 $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
43 $target = htmlspecialchars($target, ENT_QUOTES);
44 $xoopsTpl->assign('target', $target);
45 $imgcat_handler =& xoops_gethandler('imagecategory');
46 $catlist =& $imgcat_handler->getList($group, 'imgcat_read', 1);
47 $catcount = count($catlist);
48 $xoopsTpl->assign('lang_align', _ALIGN);
49 $xoopsTpl->assign('lang_add', _ADD);
50 $xoopsTpl->assign('lang_close', _CLOSE);
51 if ($catcount > 0) {
52 $xoopsTpl->assign('lang_go', _GO);
53 $catshow = (!isset($_GET['cat_id'])) ? 0 : intval($_GET['cat_id']);
54 $catshow = (!empty($catshow) && in_array($catshow, array_keys($catlist))) ? $catshow : 0;
55 $xoopsTpl->assign('show_cat', $catshow);
56 if ($catshow > 0) {
57 $xoopsTpl->assign('lang_addimage', _ADDIMAGE);
58 }
59 $catlist = array('0' => '--') + $catlist;
60 $cat_options = '';
61 foreach ($catlist as $c_id => $c_name) {
62 $sel = '';
63 if ($c_id == $catshow) {
64 $sel = ' selected="selected"';
65 }
66 $cat_options .= '';
67 }
68 $xoopsTpl->assign('cat_options', $cat_options);
69 if ($catshow > 0) {
70 $image_handler =& xoops_gethandler('image');
71 $criteria = new CriteriaCompo(new Criteria('imgcat_id', $catshow));
72 $criteria->add(new Criteria('image_display', 1));
73 $total = $image_handler->getCount($criteria);
74 if ($total > 0) {
75 $imgcat_handler =& xoops_gethandler('imagecategory');
76 $imgcat =& $imgcat_handler->get($catshow);
77 $xoopsTpl->assign('image_total', $total);
78 $xoopsTpl->assign('lang_image', _IMAGE);
79 $xoopsTpl->assign('lang_imagename', _IMAGENAME);
80 $xoopsTpl->assign('lang_imagemime', _IMAGEMIME);
81 $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
82 $criteria->setLimit(10);
83 $criteria->setStart($start);
84 $storetype = $imgcat->getVar('imgcat_storetype');
85 if ($storetype == 'db') {
86 $criteria->setSort('i.image_weight ASC, i.image_id');
87 $criteria->setOrder('DESC');
88 $images = $image_handler->getObjects($criteria, false, true);
89 } else {
90 $criteria->setSort('image_weight ASC, image_id');
91 $criteria->setOrder('DESC');
92 $images = $image_handler->getObjects($criteria, false, false);
93 }
94 $imgcount = count($images);
95 $max = ($imgcount > 10) ? 10 : $imgcount;
96
97 for ($i = 0; $i < $max; $i++) {
98 if ($storetype == 'db') {
99 $lcode = '[img align=left id=' . $images[$i]->getVar('image_id') . ']' . $images[$i]->getVar('image_nicename') . '[/img]';
100 $code = '[img align=center id=' . $images[$i]->getVar('image_id') . ']' . $images[$i]->getVar('image_nicename') . '[/img]';
101 $rcode = '[img align=right id=' . $images[$i]->getVar('image_id') . ']' . $images[$i]->getVar('image_nicename') . '[/img]';
102 $src = XOOPS_URL . "/image.php?id=" . $images[$i]->getVar('image_id');
103 } else {
104 $lcode = '[img align=left]' . XOOPS_UPLOAD_URL . '/' . $images[$i]->getVar('image_name') . '[/img]';
105 $code = '[img align=center]' . XOOPS_UPLOAD_URL . '/' . $images[$i]->getVar('image_name') . '[/img]';
106 $rcode = '[img align=right]' . XOOPS_UPLOAD_URL . '/' . $images[$i]->getVar('image_name') . '[/img]';
107 $src = XOOPS_UPLOAD_URL . '/' . $images[$i]->getVar('image_name');
108 }
109 $xoopsTpl->append('images', array('id' => $images[$i]->getVar('image_id'), 'nicename' => $images[$i]->getVar('image_nicename'), 'mimetype' => $images[$i]->getVar('image_mimetype'), 'src' => $src, 'lxcode' => $lcode, 'xcode' => $code, 'rxcode' => $rcode));
110 }
111 if ($total > 10) {
112 include_once $GLOBALS['xoops']->path('class/pagenav.php');
113 $nav = new XoopsPageNav($total, 10, $start, 'start', 'target='.$target.'&cat_id='.$catshow);
114 $xoopsTpl->assign('pagenav', $nav->renderNav());
115 }
116 } else {
117 $xoopsTpl->assign('image_total', 0);
118 }
119 }
120 $xoopsTpl->assign('xsize', 600);
121 $xoopsTpl->assign('ysize', 400);
122 } else {
123 $xoopsTpl->assign('xsize', 400);
124 $xoopsTpl->assign('ysize', 180);
125 }
126 $xoopsTpl->display('db:system_imagemanager.html');
127 exit();
128 }
129
130 if ($op == 'upload') {
131 $imgcat_handler =& xoops_gethandler('imagecategory');
132 $imgcat_id = intval($_GET['imgcat_id']);
133 $imgcat =& $imgcat_handler->get($imgcat_id);
134 $error = false;
135 if (!is_object($imgcat)) {
136 $error = true;
137 } else {
138 $imgcatperm_handler =& xoops_gethandler('groupperm');
139 if (is_object($xoopsUser)) {
140 if (! $imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, $xoopsUser->getGroups())) {
141 $error = true;
142 }
143 } else {
144 if (! $imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, XOOPS_GROUP_ANONYMOUS)) {
145 $error = true;
146 }
147 }
148 }
149 if ($error != false) {
150 xoops_header(false);
151 echo '._BACK.'" type="button" onclick="javascript:history.go(-1);" />';
152 xoops_footer();
153 exit();
154 }
155 require_once $GLOBALS['xoops']->path('class/template.php');
156 $xoopsTpl = new XoopsTpl();
157 $xoopsTpl->assign('show_cat', $imgcat_id);
158 $xoopsTpl->assign('lang_imgmanager', _IMGMANAGER);
159 $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
160 $xoopsTpl->assign('target', htmlspecialchars($_GET['target'], ENT_QUOTES));
161 include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
162 $form = new XoopsThemeForm('', 'image_form', 'imagemanager.php', 'post', true);
163 $form->setExtra('enctype="multipart/form-data"');
164 $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 20, 255), true);
165 $form->addElement(new XoopsFormLabel(_IMAGECAT, $imgcat->getVar('imgcat_name')));
166 $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', $imgcat->getVar('imgcat_maxsize')), true);
167 $form->addElement(new XoopsFormLabel(_IMGMAXSIZE, $imgcat->getVar('imgcat_maxsize')));
168 $form->addElement(new XoopsFormLabel(_IMGMAXWIDTH, $imgcat->getVar('imgcat_maxwidth')));
169 $form->addElement(new XoopsFormLabel(_IMGMAXHEIGHT, $imgcat->getVar('imgcat_maxheight')));
170 $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
171 $form->addElement(new XoopsFormHidden('op', 'doupload'));
172 $form->addElement(new XoopsFormHidden('target', $target));
173 $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
174 $form->assign($xoopsTpl);
175 $xoopsTpl->assign('lang_close', _CLOSE);
176 $xoopsTpl->display('db:system_imagemanager2.html');
177 exit();
178 }
179
180 if ($op == 'doupload') {
181 if ($GLOBALS['xoopsSecurity']->check()) {
182 $image_nicename = isset($_POST['image_nicename']) ? $_POST['image_nicename'] : '';
183 $xoops_upload_file = isset($_POST['xoops_upload_file']) ? $_POST['xoops_upload_file'] : array();
184 $imgcat_id = isset($_POST['imgcat_id']) ? intval($_POST['imgcat_id']) : 0;
185 include_once $GLOBALS['xoops']->path('class/uploader.php');
186 $imgcat_handler =& xoops_gethandler('imagecategory');
187 $imgcat =& $imgcat_handler->get($imgcat_id);
188 $error = false;
189 if (!is_object($imgcat)) {
190 $error = true;
191 } else {
192 $imgcatperm_handler =& xoops_gethandler('groupperm');
193 if (is_object($xoopsUser)) {
194 if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, $xoopsUser->getGroups())) {
195 $error = true;
196 }
197 } else {
198 if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, XOOPS_GROUP_ANONYMOUS)) {
199 $error = true;
200 }
201 }
202 }
203 }
204 else {
205 $error = true;
206 }
207 if ($error != false) {
208 xoops_header(false);
209 echo '' . implode('
', $GLOBALS['xoopsSecurity']->getErrors()) . '
. _BACK . '" type="button" onclick="javascript:history.go(-1);" />';
210 xoops_footer();
211 exit();
212 }
213 $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $imgcat->getVar('imgcat_maxsize'), $imgcat->getVar('imgcat_maxwidth'), $imgcat->getVar('imgcat_maxheight'));
214 $uploader->setPrefix('img');
215 if ($uploader->fetchMedia($xoops_upload_file[0])) {
216 if (!$uploader->upload()) {
217 $err = $uploader->getErrors();
218 } else {
219 $image_handler =& xoops_gethandler('image');
220 $image =& $image_handler->create();
221 $image->setVar('image_name', $uploader->getSavedFileName());
222 $image->setVar('image_nicename', $image_nicename);
223 $image->setVar('image_mimetype', $uploader->getMediaType());
224 $image->setVar('image_created', time());
225 $image->setVar('image_display', 1);
226 $image->setVar('image_weight', 0);
227 $image->setVar('imgcat_id', $imgcat_id);
228 if ($imgcat->getVar('imgcat_storetype') == 'db') {
229 $fp = @fopen($uploader->getSavedDestination(), 'rb');
230 $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
231 @fclose($fp);
232 $image->setVar('image_body', $fbinary, true);
233 @unlink($uploader->getSavedDestination());
234 }
235 if (!$image_handler->insert($image)) {
236 $err = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'));
237 }
238 }
239 } else {
240 $err = sprintf(_FAILFETCHIMG, 0);
241 $err .= '
' . implode('
', $uploader->getErrors(false));
242 }
243 if (isset($err)) {
244 xoops_header(false);
245 xoops_error($err);
246 echo '. _BACK . '" type="button" onclick="javascript:history.go(-1);" />';
247 xoops_footer();
248 exit();
249 }
250 header('location: imagemanager.php?cat_id=' . $imgcat_id . '&target=' . $target);
251 }
252
253 ?>