| 1 | <?php |
|---|
| 2 | // $Id: imagemanager.php,v 1.5 2005/09/04 20:46:08 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | |
|---|
| 28 | include './mainfile.php'; |
|---|
| 29 | if (!isset($_GET['target']) && !isset($_POST['target'])) { |
|---|
| 30 | exit(); |
|---|
| 31 | } |
|---|
| 32 | $op = 'list'; |
|---|
| 33 | if (isset($_GET['op']) && $_GET['op'] == 'upload') { |
|---|
| 34 | $op = 'upload'; |
|---|
| 35 | } elseif (isset($_POST['op']) && $_POST['op'] == 'doupload') { |
|---|
| 36 | $op = 'doupload'; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | if (!is_object($xoopsUser)) { |
|---|
| 40 | $group = array(XOOPS_GROUP_ANONYMOUS); |
|---|
| 41 | } else { |
|---|
| 42 | $group =& $xoopsUser->getGroups(); |
|---|
| 43 | } |
|---|
| 44 | if ($op == 'list') { |
|---|
| 45 | require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 46 | $xoopsTpl = new XoopsTpl(); |
|---|
| 47 | $xoopsTpl->assign('lang_imgmanager', _IMGMANAGER); |
|---|
| 48 | $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
|---|
| 49 | $target = htmlspecialchars($_GET['target'], ENT_QUOTES); |
|---|
| 50 | $xoopsTpl->assign('target', $target); |
|---|
| 51 | $imgcat_handler =& xoops_gethandler('imagecategory'); |
|---|
| 52 | $catlist =& $imgcat_handler->getList($group, 'imgcat_read', 1); |
|---|
| 53 | $catcount = count($catlist); |
|---|
| 54 | $xoopsTpl->assign('lang_align', _ALIGN); |
|---|
| 55 | $xoopsTpl->assign('lang_add', _ADD); |
|---|
| 56 | $xoopsTpl->assign('lang_close', _CLOSE); |
|---|
| 57 | if ($catcount > 0) { |
|---|
| 58 | $xoopsTpl->assign('lang_go', _GO); |
|---|
| 59 | $catshow = !isset($_GET['cat_id']) ? 0 : intval($_GET['cat_id']); |
|---|
| 60 | $catshow = (!empty($catshow) && in_array($catshow, array_keys($catlist))) ? $catshow : 0; |
|---|
| 61 | $xoopsTpl->assign('show_cat', $catshow); |
|---|
| 62 | if ($catshow > 0) { |
|---|
| 63 | $xoopsTpl->assign('lang_addimage', _ADDIMAGE); |
|---|
| 64 | } |
|---|
| 65 | $catlist = array('0' => '--') + $catlist; |
|---|
| 66 | $cat_options = ''; |
|---|
| 67 | foreach ($catlist as $c_id => $c_name) { |
|---|
| 68 | $sel = ''; |
|---|
| 69 | if ($c_id == $catshow) { |
|---|
| 70 | $sel = ' selected="selected"'; |
|---|
| 71 | } |
|---|
| 72 | $cat_options .= '<option value="'.$c_id.'"'.$sel.'>'.$c_name.'</option>'; |
|---|
| 73 | } |
|---|
| 74 | $xoopsTpl->assign('cat_options', $cat_options); |
|---|
| 75 | if ($catshow > 0) { |
|---|
| 76 | $image_handler = xoops_gethandler('image'); |
|---|
| 77 | $criteria = new CriteriaCompo(new Criteria('imgcat_id', $catshow)); |
|---|
| 78 | $criteria->add(new Criteria('image_display', 1)); |
|---|
| 79 | $total = $image_handler->getCount($criteria); |
|---|
| 80 | if ($total > 0) { |
|---|
| 81 | $imgcat_handler =& xoops_gethandler('imagecategory'); |
|---|
| 82 | $imgcat =& $imgcat_handler->get($catshow); |
|---|
| 83 | $xoopsTpl->assign('image_total', $total); |
|---|
| 84 | $xoopsTpl->assign('lang_image', _IMAGE); |
|---|
| 85 | $xoopsTpl->assign('lang_imagename', _IMAGENAME); |
|---|
| 86 | $xoopsTpl->assign('lang_imagemime', _IMAGEMIME); |
|---|
| 87 | $start = isset($_GET['start']) ? intval($_GET['start']) : 0; |
|---|
| 88 | $criteria->setLimit(10); |
|---|
| 89 | $criteria->setStart($start); |
|---|
| 90 | $storetype = $imgcat->getVar('imgcat_storetype'); |
|---|
| 91 | if ($storetype == 'db') { |
|---|
| 92 | $images =& $image_handler->getObjects($criteria, false, true); |
|---|
| 93 | } else { |
|---|
| 94 | $images =& $image_handler->getObjects($criteria, false, false); |
|---|
| 95 | } |
|---|
| 96 | $imgcount = count($images); |
|---|
| 97 | $max = ($imgcount > 10) ? 10 : $imgcount; |
|---|
| 98 | |
|---|
| 99 | for ($i = 0; $i < $max; $i++) { |
|---|
| 100 | if ($storetype == 'db') { |
|---|
| 101 | $lcode = '[img align=left id='.$images[$i]->getVar('image_id').']'.$images[$i]->getVar('image_nicename').'[/img]'; |
|---|
| 102 | $code = '[img id='.$images[$i]->getVar('image_id').']'.$images[$i]->getVar('image_nicename').'[/img]'; |
|---|
| 103 | $rcode = '[img align=right id='.$images[$i]->getVar('image_id').']'.$images[$i]->getVar('image_nicename').'[/img]'; |
|---|
| 104 | $src = XOOPS_URL."/image.php?id=".$images[$i]->getVar('image_id'); |
|---|
| 105 | } else { |
|---|
| 106 | $lcode = '[img align=left]'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'[/img]'; |
|---|
| 107 | $code = '[img]'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'[/img]'; |
|---|
| 108 | $rcode = '[img align=right]'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'[/img]'; |
|---|
| 109 | $src = XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name'); |
|---|
| 110 | } |
|---|
| 111 | $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)); |
|---|
| 112 | } |
|---|
| 113 | if ($total > 10) { |
|---|
| 114 | include_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|---|
| 115 | $nav = new XoopsPageNav($total, 10, $start, 'start', 'target='.$target.'&cat_id='.$catshow); |
|---|
| 116 | $xoopsTpl->assign('pagenav', $nav->renderNav()); |
|---|
| 117 | } |
|---|
| 118 | } else { |
|---|
| 119 | $xoopsTpl->assign('image_total', 0); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | $xoopsTpl->assign('xsize', 600); |
|---|
| 123 | $xoopsTpl->assign('ysize', 400); |
|---|
| 124 | } else { |
|---|
| 125 | $xoopsTpl->assign('xsize', 400); |
|---|
| 126 | $xoopsTpl->assign('ysize', 180); |
|---|
| 127 | } |
|---|
| 128 | $xoopsTpl->display('db:system_imagemanager.html'); |
|---|
| 129 | exit(); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | if ($op == 'upload') { |
|---|
| 133 | $imgcat_handler =& xoops_gethandler('imagecategory'); |
|---|
| 134 | $imgcat_id = intval($_GET['imgcat_id']); |
|---|
| 135 | $imgcat =& $imgcat_handler->get($imgcat_id); |
|---|
| 136 | $error = false; |
|---|
| 137 | if (!is_object($imgcat)) { |
|---|
| 138 | $error = true; |
|---|
| 139 | } else { |
|---|
| 140 | $imgcatperm_handler =& xoops_gethandler('groupperm'); |
|---|
| 141 | if (is_object($xoopsUser)) { |
|---|
| 142 | if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, $xoopsUser->getGroups())) { |
|---|
| 143 | $error = true; |
|---|
| 144 | } |
|---|
| 145 | } else { |
|---|
| 146 | if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, XOOPS_GROUP_ANONYMOUS)) { |
|---|
| 147 | $error = true; |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | if ($error != false) { |
|---|
| 152 | xoops_header(false); |
|---|
| 153 | echo '</head><body><div style="text-align:center;"><input value="'._BACK.'" type="button" onclick="javascript:history.go(-1);" /></div>'; |
|---|
| 154 | xoops_footer(); |
|---|
| 155 | exit(); |
|---|
| 156 | } |
|---|
| 157 | require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 158 | $xoopsTpl = new XoopsTpl(); |
|---|
| 159 | $xoopsTpl->assign('show_cat', $imgcat_id); |
|---|
| 160 | $xoopsTpl->assign('lang_imgmanager', _IMGMANAGER); |
|---|
| 161 | $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
|---|
| 162 | $xoopsTpl->assign('target', htmlspecialchars($_GET['target'], ENT_QUOTES)); |
|---|
| 163 | include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|---|
| 164 | $form = new XoopsThemeForm('', 'image_form', 'imagemanager.php'); |
|---|
| 165 | $form->setExtra('enctype="multipart/form-data"'); |
|---|
| 166 | $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 20, 255), true); |
|---|
| 167 | $form->addElement(new XoopsFormLabel(_IMAGECAT, $imgcat->getVar('imgcat_name'))); |
|---|
| 168 | $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', $imgcat->getVar('imgcat_maxsize')), true); |
|---|
| 169 | $form->addElement(new XoopsFormLabel(_IMGMAXSIZE, $imgcat->getVar('imgcat_maxsize'))); |
|---|
| 170 | $form->addElement(new XoopsFormLabel(_IMGMAXWIDTH, $imgcat->getVar('imgcat_maxwidth'))); |
|---|
| 171 | $form->addElement(new XoopsFormLabel(_IMGMAXHEIGHT, $imgcat->getVar('imgcat_maxheight'))); |
|---|
| 172 | $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id)); |
|---|
| 173 | $form->addElement(new XoopsFormHidden('op', 'doupload')); |
|---|
| 174 | $form->addElement(new XoopsFormToken(XoopsMultiTokenHandler::quickCreate('imagemanager'))); |
|---|
| 175 | $form->addElement(new XoopsFormHidden('target', $target)); |
|---|
| 176 | $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit')); |
|---|
| 177 | $form->assign($xoopsTpl); |
|---|
| 178 | $xoopsTpl->assign('lang_close', _CLOSE); |
|---|
| 179 | $xoopsTpl->display('db:system_imagemanager2.html'); |
|---|
| 180 | exit(); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | if ($op == 'doupload') { |
|---|
| 184 | if (!XoopsMultiTokenHandler::quickValidate('imagemanager')) { |
|---|
| 185 | exit(); |
|---|
| 186 | } |
|---|
| 187 | $image_nicename = isset($_POST['image_nicename']) ? $_POST['image_nicename'] : ''; |
|---|
| 188 | $xoops_upload_file = isset($_POST['xoops_upload_file']) ? $_POST['xoops_upload_file'] : array(); |
|---|
| 189 | $target = isset($_POST['target']) ? $_POST['target'] : ''; |
|---|
| 190 | $imgcat_id = isset($_POST['imgcat_id']) ? intval($_POST['imgcat_id']) : 0; |
|---|
| 191 | include_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
|---|
| 192 | $imgcat_handler =& xoops_gethandler('imagecategory'); |
|---|
| 193 | $imgcat =& $imgcat_handler->get($imgcat_id); |
|---|
| 194 | $error = false; |
|---|
| 195 | if (!is_object($imgcat)) { |
|---|
| 196 | $error = true; |
|---|
| 197 | } else { |
|---|
| 198 | $imgcatperm_handler =& xoops_gethandler('groupperm'); |
|---|
| 199 | if (is_object($xoopsUser)) { |
|---|
| 200 | if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, $xoopsUser->getGroups())) { |
|---|
| 201 | $error = true; |
|---|
| 202 | } |
|---|
| 203 | } else { |
|---|
| 204 | if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, XOOPS_GROUP_ANONYMOUS)) { |
|---|
| 205 | $error = true; |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | if ($error != false) { |
|---|
| 210 | xoops_header(false); |
|---|
| 211 | echo '</head><body><div style="text-align:center;"><input value="'._BACK.'" type="button" onclick="javascript:history.go(-1);" /></div>'; |
|---|
| 212 | xoops_footer(); |
|---|
| 213 | exit(); |
|---|
| 214 | } |
|---|
| 215 | $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')); |
|---|
| 216 | $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); |
|---|
| 217 | $uploader->setPrefix('img'); |
|---|
| 218 | if ($uploader->fetchMedia($xoops_upload_file[0])) { |
|---|
| 219 | if (!$uploader->upload()) { |
|---|
| 220 | $err = $uploader->getErrors(); |
|---|
| 221 | } else { |
|---|
| 222 | $image_handler =& xoops_gethandler('image'); |
|---|
| 223 | $image =& $image_handler->create(); |
|---|
| 224 | $image->setVar('image_name', $uploader->getSavedFileName()); |
|---|
| 225 | $image->setVar('image_nicename', $image_nicename); |
|---|
| 226 | $image->setVar('image_mimetype', $uploader->getMediaType()); |
|---|
| 227 | $image->setVar('image_created', time()); |
|---|
| 228 | $image->setVar('image_display', 1); |
|---|
| 229 | $image->setVar('image_weight', 0); |
|---|
| 230 | $image->setVar('imgcat_id', $imgcat_id); |
|---|
| 231 | if ($imgcat->getVar('imgcat_storetype') == 'db') { |
|---|
| 232 | $fp = @fopen($uploader->getSavedDestination(), 'rb'); |
|---|
| 233 | $fbinary = @fread($fp, filesize($uploader->getSavedDestination())); |
|---|
| 234 | @fclose($fp); |
|---|
| 235 | $image->setVar('image_body', $fbinary, true); |
|---|
| 236 | @unlink($uploader->getSavedDestination()); |
|---|
| 237 | } |
|---|
| 238 | if (!$image_handler->insert($image)) { |
|---|
| 239 | $err = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename')); |
|---|
| 240 | } |
|---|
| 241 | } |
|---|
| 242 | } else { |
|---|
| 243 | $err = _FAILFETCHIMG; |
|---|
| 244 | } |
|---|
| 245 | if (isset($err)) { |
|---|
| 246 | xoops_header(false); |
|---|
| 247 | xoops_error($err); |
|---|
| 248 | echo '</head><body><div style="text-align:center;"><input value="'._BACK.'" type="button" onclick="javascript:history.go(-1);" /></div>'; |
|---|
| 249 | xoops_footer(); |
|---|
| 250 | exit(); |
|---|
| 251 | } |
|---|
| 252 | header('location: imagemanager.php?cat_id='.$imgcat_id.'&target='.$target); |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | ?> |
|---|