[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ecrire/ -> images.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2004 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  require dirname(__FILE__).'/inc/prepend.php';
  24  require_once dirname(__FILE__).'/../inc/classes/class.imgmanager.php';
  25  require_once dirname(__FILE__).'/../inc/libs/lib.image.php';
  26  
  27  $auth->check(5);
  28  
  29  include dirname(__FILE__).'/inc/connexion.php';
  30  
  31  $page_title = __('Manage images');
  32  
  33  $img_p = dc_img_root;
  34  $img_p = path::real($img_p);
  35  $p = !empty($_REQUEST['p']) ? $_REQUEST['p'] : '';
  36  $mode = !isset($mode) ? '' : $mode;
  37  
  38  $pscript = ($mode == 'popup') ? 'images-popup.php' : 'images.php';
  39  
  40  $imgM = new imgmanager($img_p,$p,dc_img_url,$pscript);
  41  
  42  $err = '';
  43  
  44  # Upload d'image
  45  if (!$imgM->isExclude() && $imgM->isWritable() && !empty($_FILES['up_img']))
  46  {
  47      $tmp_file = $_FILES['up_img']['tmp_name'];
  48      $img_name = $_FILES['up_img']['name'];
  49      $up_dir = $imgM->root.'/'.$imgM->base_path;
  50      
  51      if (version_compare(phpversion(),'4.2.0','>=')) {
  52          $upd_error = $_FILES['up_img']['error'];
  53      } else {
  54          $upd_error = 0;
  55      }
  56      
  57      if($upd_error != 0)
  58      {
  59          switch ($upd_error) {
  60              case 1:
  61              case 2:
  62                  $err .= '<li>'.__('File size exceeds the authorized limit').'</li>';
  63                  break;
  64              case 3:
  65                  $err .= '<li>'.__('File was only partially uploaded').'</li>';
  66                  break;
  67              case 4:
  68                  $err .= '<li>'.__('No file').'</li>';
  69                  break; 
  70          }
  71      }
  72      elseif(@move_uploaded_file($tmp_file,$up_dir.'/'.$img_name))
  73      {
  74          $dest_img = $up_dir.'/'.$img_name;
  75          
  76          if(filesize($dest_img) > dc_upload_size)
  77          {
  78              $err .= '<li>'.__('File size exceeds the authorized limit').'</li>'; 
  79          }
  80          else
  81          {    
  82              if(($img_size = @getimagesize($dest_img)) === false)
  83              {
  84                  $err .= '<li>'.sprintf(__('The file %s is not an image'),
  85                  '<strong>'.$img_name.'</strong>').'</li>';
  86              }
  87              else
  88              {
  89                  $max_s = explode('x',dc_max_img_size);
  90                  $max_w = (int) $max_s[0];
  91                  $max_h = isset($max_s[1]) ? (int) $max_s[1] : 0;
  92                  
  93                  if ($max_w > 0 && $img_size[0] > $max_w)
  94                  {
  95                      $err .= '<li>'.__('Image is too large').'</li>';
  96                  }
  97                  elseif ($max_h > 0 && $img_size[1] > $max_h)
  98                  {
  99                      $err .= '<li>'.__('Image is too large').'</li>';
 100                  }
 101              }
 102          }
 103          
 104          if ($err != '')
 105          {
 106              unlink($dest_img);
 107          }
 108          else
 109          {
 110              chmod($up_dir.'/'.$img_name,fileperms($up_dir) & ~0111);
 111              # On fait le thumbnail
 112              if (($img_type = images::type($dest_img)) !== false)
 113              {
 114                  $tn_file = preg_replace('/^(.*)([.]\\w+)$/','$1.TN__$2',$up_dir.'/'.$img_name);
 115                  images::cropImg($dest_img,$tn_file,$img_type,140,140);
 116              }
 117              
 118              $msg = __('Image uploaded');
 119              header('Location: '.$pscript.'?p='.$p.'&msg='.rawurlencode($msg));
 120              exit();
 121          }
 122      }
 123      else
 124      {
 125          $err .= '<li>'.__('An error occured while uploading the image').'</li>';
 126      }
 127  }
 128  
 129  # Création d'une miniature
 130  if (!$imgM->isExclude() && $imgM->isImg() && isset($_GET['tn']))
 131  {
 132      $type = $imgM->getImgType();
 133      
 134      if ($type != 'png' && $type != 'jpeg')
 135      {
 136          $err .= '<li>'.__('Wrong image type').'</li>';
 137      }
 138      elseif (!$imgM->isParentWritable())
 139      {
 140          $err .= '<li>'.__('This folder is not writable.').'</li>';
 141      }
 142      else
 143      {
 144          $img_file = $imgM->root.'/'.$imgM->base_path;
 145          $tn_file = preg_replace('/^(.*)([.]\\w+)$/','$1.TN__$2',$img_file);
 146          
 147          if (images::cropImg($img_file,$tn_file,$type,140,140) !== false) {
 148              header('Location: '.$pscript.'?p='.dirname($p));
 149              exit;
 150          }
 151      }
 152  }
 153  
 154  # Suppression
 155  if (!$imgM->isExclude() && $imgM->isDeletable() && isset($_GET['del']))
 156  {
 157      if ($imgM->isImg()) {
 158          $img_tn = $imgM->getThumb(NULL,true);
 159      }
 160      if ($imgM->delete() === false) {
 161          $err .= '<li>'.__('Cannot delete.').'</li>';
 162      } else {
 163          if (!empty($img_tn)) {
 164              @unlink($img_tn);
 165          }
 166          header('Location: '.$pscript.'?p='.dirname($p));
 167          exit;
 168      }
 169  }
 170  
 171  # Création d'un répertoire
 172  if (!$imgM->isExclude() && $imgM->isWritable() && !empty($_POST['new_dir']))
 173  {
 174      if ($imgM->newDir($_POST['new_dir']) !== false) {
 175          header('Location: '.$pscript.'?p='.$p);
 176          exit;
 177      } else {
 178          $err = '<li>'.__('Cannot create this directory.').'</li>';
 179      }
 180  }
 181  
 182  # Affichage
 183  if ($mode == 'popup') {
 184      openPopup($page_title);
 185      echo '<script type="text/javascript" src="js/toolbar.js"></script>';
 186      echo
 187      '<script type="text/javascript">'.
 188      "if (document.getElementById) {
 189          var tbImg = new dcToolBar(window.opener.document.getElementById('p_content'),
 190          window.opener.document.getElementById('p_format'),'images/');
 191      }
 192      </script>";
 193      
 194  } else {
 195      # Sous menu
 196      $mySubMenu->addItem(
 197          __('Back to list of entries'),'index.php','images/ico_retour.png',false);
 198      
 199      openPage($page_title);
 200  }
 201  
 202  
 203  echo '<h2>'.$page_title.'</h2>';
 204  
 205  if ($err != '')
 206  {
 207      echo '<div class="erreur"><p><strong>'.__('Error(s)').' :</strong></p>'.
 208          '<ul>'.$err.'</ul></div>';
 209  }
 210  
 211  echo '<h3>'.__('Your images').'</h3>';
 212  
 213  echo '<p>'.$imgM->getNavBar().'</p>';
 214  
 215  # Affichage des image
 216  if (!$imgM->isExclude() && $imgM->isDir() && ($f_list = $imgM->getDir()) !== false)
 217  {
 218      $redir_link = ''.$pscript.'?p='.$imgM->base_path;
 219      
 220      foreach ($f_list['dirs'] as $k => $v)
 221      {
 222          $action = '';
 223          
 224          if ($v['del']) {
 225              $action .= '<a href="'.$redir_link.'/%2$s&amp;del=1" '.
 226              'onclick="return window.confirm(\''.
 227              addslashes(sprintf(__('Are you sure you want to delete this %s?'),__('directory'))).'\');">'.
 228              '<img src="images/delete.png" alt="'.__('delete').'" '.
 229              'title="'.__('delete').'"/></a>';
 230          }
 231          
 232          $action = '<p class="action">'.$action.'</p>';
 233          
 234          $dir_link =
 235          '<div class="imgBrowsedir">'.
 236          '<p class="thumbnail small">'.
 237          '<a href="%1$s">'.
 238          '<img src="images/directory.png" alt="" /></a>'.
 239          '<a href="%1$s">%2$s</a></p>'.
 240          $action.
 241          '</div>';
 242          
 243          echo $imgM->listDir($k,$v,$dir_link);
 244      }
 245      
 246      foreach ($f_list['files'] as $k => $v)
 247      {
 248          $action = '';
 249          
 250          if ($v['del']) {
 251              $action .= '<a href="'.$redir_link.'/%2$s&amp;del=1" '.
 252              'onclick="return window.confirm(\''.
 253              addslashes(sprintf(__('Are you sure you want to delete this %s?'),__('file'))).'\');">'.
 254              '<img src="images/delete.png" alt="'.__('delete').'" '.
 255              'title="'.__('delete').'"/></a>';
 256          }
 257          
 258          $action = '<p class="action">'.$action.'</p>';
 259          
 260          if ($mode != 'popup') {
 261              $img_href = '%1$s';
 262          } else {
 263              $img_href = '%1$s" '.
 264              'onclick="tbImg.insImg(\'%4$s\'); '.
 265              'window.close(); return false;';
 266          }
 267          
 268          $img_link =
 269          '<div class="imgBrowse">'.
 270          '<p class="thumbnail small">'.
 271          '<br /><a href="'.$img_href.'">%2$s</a>'.
 272          '<br /><br /> <a href="'.$pscript.'?p='.$imgM->base_path.'/%2$s&amp;tn=1">'.
 273          __('Try to create thumbnail').'</a></p>'.
 274          $action.
 275          '</div>';
 276          
 277          $img_link_tn =
 278          '<div class="imgBrowse">'.
 279          '<p class="thumbnail small">'.
 280          '<a href="'.$img_href.'"><img src="%3$s" alt="%2$s" /></a>'.
 281          '<a href="'.$img_href.'">%2$s</a></p>'.
 282          $action.
 283          '</div>';
 284          
 285          if (!preg_match('/TN__[.]\w+$/',$k))
 286          {
 287              # Thumbnail ?
 288              if (($tn_url = $imgM->getThumb($k)) !== false) {
 289                  echo $imgM->listImg($k,$v,$img_link_tn);
 290              } else {
 291                  echo $imgM->listImg($k,$v,$img_link);
 292              }
 293          }
 294      }
 295  }
 296  
 297  # Formulaire
 298  
 299  if ($imgM->isWritable())
 300  {
 301      echo
 302      '<form enctype="multipart/form-data" action="'.$pscript.'" method="post">'.
 303      '<fieldset class="clear"><legend>'.__('Upload an image').'</legend>'.
 304      '<p><label for="up_img">'.
 305      sprintf(__('Choose a file (max size %s)'),files::size(dc_upload_size)).'&nbsp;: </label>'.
 306      '<input name="up_img" id="up_img" type="file" />'.
 307      '<input type="hidden" name="MAX_FILE_SIZE" value="'.dc_upload_size.'" />'.
 308      '<input type="hidden" name="mode" value="'.$mode.'" />'.
 309      '<input type="hidden" name="p" value="'.$p.'" />'.
 310      '&nbsp;<input class="submit" type="submit" value="'.__('send').'" /></p>'.
 311      '</fieldset>'.
 312      '</form>';
 313      
 314      echo
 315      '<form action="'.$pscript.'" method="post">'.
 316      '<fieldset><legend>'.__('New directory').'</legend>'.
 317      '<p><label for="new_dir">'.__('Name').' : </label>'.
 318      form::field('new_dir',20,255,'').
 319      '<input type="hidden" name="mode" value="'.$mode.'" />'.
 320      '<input type="hidden" name="p" value="'.$p.'" />'.
 321      '&nbsp;<input class="submit" type="submit" value="'.__('save').'" /></p>'.
 322      '</fieldset>'.
 323      '</form>';
 324  }
 325  
 326  if ($mode == 'popup') {
 327      closePopup();
 328  } else {
 329      closePage();
 330  }
 331  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7