[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/ -> imagemanager.php (source)

   1  <?php
   2  // $Id: imagemanager.php 506 2006-05-26 23:10:37Z skalpa $

   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($_REQUEST['target'])) {
  30      exit();
  31  }
  32  $target = $_REQUEST['target'];
  33  $op = 'list';
  34  if (isset($_GET['op']) && $_GET['op'] == 'upload') {
  35      $op = 'upload';
  36  } elseif (isset($_POST['op']) && $_POST['op'] == 'doupload') {
  37      $op = 'doupload';
  38  }
  39  
  40  if (!is_object($xoopsUser)) {
  41      $group = array(XOOPS_GROUP_ANONYMOUS);
  42  } else {
  43      $group =& $xoopsUser->getGroups();
  44  }
  45  if ($op == 'list') {
  46      require_once  XOOPS_ROOT_PATH.'/class/template.php';
  47      $xoopsTpl = new XoopsTpl();
  48      $xoopsTpl->assign('lang_imgmanager', _IMGMANAGER);
  49      $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
  50      $target = htmlspecialchars($target, ENT_QUOTES);
  51      $xoopsTpl->assign('target', $target);
  52      $imgcat_handler =& xoops_gethandler('imagecategory');
  53      $catlist =& $imgcat_handler->getList($group, 'imgcat_read', 1);
  54      $catcount = count($catlist);
  55      $xoopsTpl->assign('lang_align', _ALIGN);
  56      $xoopsTpl->assign('lang_add', _ADD);
  57      $xoopsTpl->assign('lang_close', _CLOSE);
  58      if ($catcount > 0) {
  59          $xoopsTpl->assign('lang_go', _GO);
  60          $catshow = !isset($_GET['cat_id']) ? 0 : intval($_GET['cat_id']);
  61          $catshow = (!empty($catshow) && in_array($catshow, array_keys($catlist))) ? $catshow : 0;
  62          $xoopsTpl->assign('show_cat', $catshow);
  63          if ($catshow > 0) {
  64              $xoopsTpl->assign('lang_addimage', _ADDIMAGE);
  65          }
  66          $catlist = array('0' => '--') + $catlist;
  67          $cat_options = '';
  68          foreach ($catlist as $c_id => $c_name) {
  69              $sel = '';
  70              if ($c_id == $catshow) {
  71                  $sel = ' selected="selected"';
  72              }
  73              $cat_options .= '<option value="'.$c_id.'"'.$sel.'>'.$c_name.'</option>';
  74          }
  75          $xoopsTpl->assign('cat_options', $cat_options);
  76          if ($catshow > 0) {
  77              $image_handler = xoops_gethandler('image');
  78              $criteria = new CriteriaCompo(new Criteria('imgcat_id', $catshow));
  79              $criteria->add(new Criteria('image_display', 1));
  80              $total = $image_handler->getCount($criteria);
  81              if ($total > 0) {
  82                  $imgcat_handler =& xoops_gethandler('imagecategory');
  83                  $imgcat =& $imgcat_handler->get($catshow);
  84                  $xoopsTpl->assign('image_total', $total);
  85                  $xoopsTpl->assign('lang_image', _IMAGE);
  86                  $xoopsTpl->assign('lang_imagename', _IMAGENAME);
  87                  $xoopsTpl->assign('lang_imagemime', _IMAGEMIME);
  88                  $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
  89                  $criteria->setLimit(10);
  90                  $criteria->setStart($start);
  91                  $storetype = $imgcat->getVar('imgcat_storetype');
  92                  if ($storetype == 'db') {
  93                      $images =& $image_handler->getObjects($criteria, false, true);
  94                  } else {
  95                      $images =& $image_handler->getObjects($criteria, false, false);
  96                  }
  97                  $imgcount = count($images);
  98                  $max = ($imgcount > 10) ? 10 : $imgcount;
  99  
 100                  for ($i = 0; $i < $max; $i++) {
 101                      if ($storetype == 'db') {
 102                          $lcode = '[img align=left id='.$images[$i]->getVar('image_id').']'.$images[$i]->getVar('image_nicename').'[/img]';
 103                          $code = '[img id='.$images[$i]->getVar('image_id').']'.$images[$i]->getVar('image_nicename').'[/img]';
 104                          $rcode = '[img align=right id='.$images[$i]->getVar('image_id').']'.$images[$i]->getVar('image_nicename').'[/img]';
 105                          $src = XOOPS_URL."/image.php?id=".$images[$i]->getVar('image_id');
 106                      } else {
 107                          $lcode = '[img align=left]'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'[/img]';
 108                          $code = '[img]'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'[/img]';
 109                          $rcode = '[img align=right]'.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'[/img]';
 110                          $src = XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name');
 111                      }
 112                      $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));
 113                  }
 114                  if ($total > 10) {
 115                      include_once  XOOPS_ROOT_PATH.'/class/pagenav.php';
 116                      $nav = new XoopsPageNav($total, 10, $start, 'start', 'target='.$target.'&amp;cat_id='.$catshow);
 117                      $xoopsTpl->assign('pagenav', $nav->renderNav());
 118                  }
 119              } else {
 120                  $xoopsTpl->assign('image_total', 0);
 121              }
 122          }
 123          $xoopsTpl->assign('xsize', 600);
 124          $xoopsTpl->assign('ysize', 400);
 125      } else {
 126          $xoopsTpl->assign('xsize', 400);
 127          $xoopsTpl->assign('ysize', 180);
 128      }
 129      $xoopsTpl->display('db:system_imagemanager.html');
 130      exit();
 131  }
 132  
 133  if ($op == 'upload') {
 134      $imgcat_handler =& xoops_gethandler('imagecategory');
 135      $imgcat_id = intval($_GET['imgcat_id']);
 136      $imgcat =& $imgcat_handler->get($imgcat_id);
 137      $error = false;
 138      if (!is_object($imgcat)) {
 139          $error = true;
 140      } else {
 141          $imgcatperm_handler =& xoops_gethandler('groupperm');
 142          if (is_object($xoopsUser)) {
 143              if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, $xoopsUser->getGroups())) {
 144                  $error = true;
 145              }
 146          } else {
 147              if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, XOOPS_GROUP_ANONYMOUS)) {
 148                  $error = true;
 149              }
 150          }
 151      }
 152      if ($error != false) {
 153          xoops_header(false);
 154          echo '</head><body><div style="text-align:center;"><input value="'._BACK.'" type="button" onclick="javascript:history.go(-1);" /></div>';
 155          xoops_footer();
 156          exit();
 157      }
 158      require_once  XOOPS_ROOT_PATH.'/class/template.php';
 159      $xoopsTpl = new XoopsTpl();
 160      $xoopsTpl->assign('show_cat', $imgcat_id);
 161      $xoopsTpl->assign('lang_imgmanager', _IMGMANAGER);
 162      $xoopsTpl->assign('sitename', htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES));
 163      $xoopsTpl->assign('target', htmlspecialchars($_GET['target'], ENT_QUOTES));
 164      include_once  XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
 165      $form = new XoopsThemeForm('', 'image_form', 'imagemanager.php', 'post', true);
 166      $form->setExtra('enctype="multipart/form-data"');
 167      $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 20, 255), true);
 168      $form->addElement(new XoopsFormLabel(_IMAGECAT, $imgcat->getVar('imgcat_name')));
 169      $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', $imgcat->getVar('imgcat_maxsize')), true);
 170      $form->addElement(new XoopsFormLabel(_IMGMAXSIZE, $imgcat->getVar('imgcat_maxsize')));
 171      $form->addElement(new XoopsFormLabel(_IMGMAXWIDTH, $imgcat->getVar('imgcat_maxwidth')));
 172      $form->addElement(new XoopsFormLabel(_IMGMAXHEIGHT, $imgcat->getVar('imgcat_maxheight')));
 173      $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
 174      $form->addElement(new XoopsFormHidden('op', 'doupload'));
 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 ($GLOBALS['xoopsSecurity']->check()) {
 185          $image_nicename = isset($_POST['image_nicename']) ? $_POST['image_nicename'] : '';
 186          $xoops_upload_file = isset($_POST['xoops_upload_file']) ? $_POST['xoops_upload_file'] : array();
 187          $imgcat_id = isset($_POST['imgcat_id']) ? intval($_POST['imgcat_id']) : 0;
 188          include_once  XOOPS_ROOT_PATH.'/class/uploader.php';
 189          $imgcat_handler =& xoops_gethandler('imagecategory');
 190          $imgcat =& $imgcat_handler->get($imgcat_id);
 191          $error = false;
 192          if (!is_object($imgcat)) {
 193              $error = true;
 194          } else {
 195              $imgcatperm_handler =& xoops_gethandler('groupperm');
 196              if (is_object($xoopsUser)) {
 197                  if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, $xoopsUser->getGroups())) {
 198                      $error = true;
 199                  }
 200              } else {
 201                  if (!$imgcatperm_handler->checkRight('imgcat_write', $imgcat_id, XOOPS_GROUP_ANONYMOUS)) {
 202                      $error = true;
 203                  }
 204              }
 205          }
 206      }
 207      else {
 208          $error = true;
 209      }
 210      if ($error != false) {
 211          xoops_header(false);
 212          echo '</head><body><div style="text-align:center;">'.implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()).'<br /><input value="'._BACK.'" type="button" onclick="javascript:history.go(-1);" /></div>';
 213          xoops_footer();
 214          exit();
 215      }
 216      $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'));
 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 = sprintf(_FAILFETCHIMG, 0);
 244          $err .= '<br />'.implode('<br />', $uploader->getErrors(false));
 245      }
 246      if (isset($err)) {
 247          xoops_header(false);
 248          xoops_error($err);
 249          echo '</head><body><div style="text-align:center;"><input value="'._BACK.'" type="button" onclick="javascript:history.go(-1);" /></div>';
 250          xoops_footer();
 251          exit();
 252      }
 253      header('location: imagemanager.php?cat_id='.$imgcat_id.'&target='.$target);
 254  }
 255  
 256  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics