[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wysiwyg/shared/tiny_mce/plugins/ibrowser/scripts/ -> rfiles.php (source)

   1  <?php
   2      // ================================================

   3      // PHP image browser - iBrowser 

   4      // ================================================

   5      // iBrowser dialog - file functions

   6      // ================================================

   7      // Developed: net4visions.com

   8      // Copyright: net4visions.com

   9      // License: GPL - see license.txt

  10      // (c)2005 All rights reserved.

  11      // ================================================

  12      // Revision: 1.0                   Date: 08/02/2006

  13      // ================================================

  14      
  15      //-------------------------------------------------------------------------

  16      // include configuration settings

  17      include dirname(__FILE__) . '/../config/config.inc.php';
  18      include dirname(__FILE__) . '/../langs/lang.class.php';    
  19      //-------------------------------------------------------------------------

  20          
  21      // language settings    

  22      $l = (isset($_REQUEST['lang']) ? new PLUG_Lang($_REQUEST['lang']) : new PLUG_Lang($cfg['lang']));
  23      $l->setBlock('ibrowser');
  24      //-------------------------------------------------------------------------    

  25      // parameters

  26      $param  = (isset($_REQUEST['param']) ? $_REQUEST['param'] : '');
  27      if (isset($param)) {
  28          $param  = explode('|', $param);
  29      }    
  30      // set action    

  31      $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : '');            
  32      // set image library        

  33      $clib = (isset($_REQUEST['clib']) ? $_REQUEST['clib'] : (isset($_REQUEST['ilibs']) ? $_REQUEST['ilibs'] : $cfg['ilibs'][0]['value']));    
  34      // set current file

  35      $cfile = (isset($_REQUEST['cfile']) ? $_REQUEST['cfile'] : '');    
  36      // set new file

  37      $nfile = (isset($_REQUEST['nfile']) ? $_REQUEST['nfile'] : '');
  38      // set list view    

  39      $list = (isset($_REQUEST['flist']) ? $_REQUEST['flist'] : $cfg['list']);    
  40      //-------------------------------------------------------------------------

  41      // file/directory actions            

  42      if ($param[0] == 'delete') {            // ACTION: delete image
  43          $action = $param[0];                
  44          $cfile  = $param[1];                 // current filename            

  45          if(!deleteImg($clib, $cfile)) {
  46              echo $l->m('er_001') . ': ' . $l->m('er_030');            
  47          };    
  48      } else if ($param[0] == 'rename') {        // ACTION: rename image            
  49          $action = $param[0];    
  50          $cfile  = $param[1];                 // current filename

  51          $nfile  = $param[2];                 // new filename

  52          if(!$nfile = renameImg($clib, $cfile, $nfile)) {
  53              echo $l->m('er_001') . ': ' . $l->m('er_033');    
  54          };
  55      } else if ($param[0] == 'upload') {        // ACTION: upload image        
  56          $action = $param[0];        
  57          $chkT   = (isset($_REQUEST['chkThumbSize']) ? $_REQUEST['chkThumbSize'] : Array() );     // thumb-sizes in Array                                

  58          $selR   = (isset($_REQUEST['selRotate']) ? $_REQUEST['selRotate'] : '');    // auto rotate    

  59          if (isset($_FILES['nfile']['name'][0])) {            
  60              if (!$nfile = uploadImg($clib, $chkT, $selR)) {    
  61                  echo $l->m('er_001') . ': ' . $l->m('er_028');    
  62              }    
  63          };    
  64      } else if ($param[0] == 'create') {        // ACTION: create directory            
  65          $action = $param[0];    
  66          $nfile  = $param[1];                 // new filename

  67          if(!createDir($clib, $nfile)) {
  68              echo $l->m('er_001') . ': ' . $l->m('er_034');    
  69          };
  70      } else if ($param[0] == 'update') {        // ACTION: update image list and select current image            
  71          $action = $param[0];                
  72          $cfile  = $param[1];                // current filename

  73      } else if ($param[0] == 'switch') {        // ACTION: switch image list view (list or thumbnails)            
  74          $action = $param[0];                
  75          $cfile  = $param[1];                // current filename    

  76      }        
  77  ?>
  78  <!-- do not delete this line - it's need for proper working of the resizeDialogToContent() function -->
  79  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  80  <html xmlns="http://www.w3.org/1999/xhtml">
  81  <head>
  82  <title><?php echo $l->m('im_002'); ?></title>
  83  <meta http-equiv="Pragma" content="no-cache">
  84  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $l->getCharset(); ?>">
  85  <style type="text/css">
  86  <!--
  87  @import url("../css/style.css");
  88  
  89  html, body {
  90      margin: 0px;
  91      padding: 0px;
  92  }
  93  
  94  -->
  95  </style>
  96  <?php if ($list == false) { // thumbnail view ?> 
  97      <style type="text/css">
  98      <!--
  99          div#iselDiv li {
 100              margin: 5px;
 101              padding: 5px;
 102              display: block;
 103              border: 1px solid #cccccc;    
 104              float: left;    
 105          }
 106      -->
 107      </style>
 108  <?php } else { // list view ?>
 109      <style type="text/css">
 110      <!--
 111          div#iselDiv li {
 112              margin: 0px;
 113              padding: 0px;
 114              display: block;        
 115              padding-left: 5px;
 116              padding-right: 5px;            
 117          }
 118      -->
 119      </style>
 120  <?php }; ?>
 121  <script language="JavaScript" type="text/JavaScript">
 122  <!--
 123  // ============================================================

 124  // = image list item V 1.0, date: 01/21/2005                  =

 125  // ============================================================    

 126      // list item hover

 127      function li_over() {
 128          if (this.className != 'cimgdown') {
 129              this.className   = 'cimgover';
 130          }
 131      }
 132      // list item out

 133      function li_out() {
 134          if (this.className != 'cimgdown') {
 135              this.className   = 'cimgup';
 136          }
 137      }
 138      // list item down

 139      function li_down() {
 140          if (this.className != 'cimgdown') {
 141              this.className  = 'cimgdown';
 142          }
 143      }
 144      // list item click

 145      function li_click() {        
 146          x = document.getElementById('iselDiv').getElementsByTagName('li');
 147          for (var i = 0; i < x.length; i++) {
 148              if (x[i].className == 'cimgdown') {
 149                  if (x[i] != this) {
 150                      x[i].className = 'cimgup';
 151                  }
 152              }
 153          }        
 154          imageChangeClick(this);        
 155      }    
 156  // ============================================================

 157  // = init filelist - set attributes V 1.0, date: 04/18/2005   =

 158  // ============================================================

 159  	function init() {        
 160          var formObj = document.forms[0];
 161          // init mouse events on image list <li>

 162          var x = document.getElementById('iselDiv').getElementsByTagName('li');
 163          for (var i = 0; i < x.length; i++) {
 164              if (x[i].className == 'cimgup') {
 165                  x[i].onmouseover = li_over;
 166                  x[i].onmouseout  = li_out;
 167                  x[i].onmousedown = li_down;
 168                  x[i].onclick     = li_click;
 169              }
 170          }        
 171          
 172          // actions

 173          var action = formObj.action.value;        
 174          if (action == 'upload') {
 175              var tfile = '<?php echo $nfile; ?>';            
 176              getObject(tfile);
 177              self.parent.hideloadmessage();                
 178          } else if (action == 'rename') {
 179              var tfile = '<?php echo $nfile; ?>';            
 180              getObject(tfile);
 181          } else if (action == 'update') {
 182              var tfile = '<?php echo $cfile; ?>';            
 183              getObject(tfile);
 184          } else if (action == 'switch') {
 185              var tfile = '<?php echo $cfile; ?>';            
 186              getObject(tfile);                    
 187          } else if (action == 'delete') {            
 188              imageChangeClick();
 189          } else if (formObj.action.value == 'create') {    
 190              // parent needs to be refreshed if directory got created    

 191              parent.document.location.reload();     
 192          }
 193      }
 194  // ============================================================

 195  // = image change - set attributes V 1.0, date: 04/18/2005    =

 196  // ============================================================    

 197      function imageChangeClick(obj) {
 198          var formObj = document.forms[0];
 199          var action  = formObj.action.value;    
 200          if (obj) {
 201              parent.document.getElementById('cimg').attributes['cfile'].value   = obj.attributes['ifile'].value;
 202              parent.document.getElementById('cimg').attributes['csize'].value   = obj.attributes['isize'].value;
 203              parent.document.getElementById('cimg').attributes['cheight'].value = obj.attributes['iheight'].value;
 204              parent.document.getElementById('cimg').attributes['cwidth'].value  = obj.attributes['iwidth'].value;
 205              parent.document.getElementById('cimg').attributes['ctype'].value   = obj.attributes['itype'].value;
 206              parent.document.getElementById('cimg').attributes['cmdate'].value  = obj.attributes['imdate'].value;
 207              parent.document.getElementById('cimg').attributes['ccdate'].value  = obj.attributes['icdate'].value;        
 208          }
 209          self.parent.imageChange(action);
 210          formObj.action.value = null; // resetting action status        

 211      }
 212  // ============================================================

 213  // = get current file - set attrib V 1.0, date: 04/18/2005    =

 214  // ============================================================        

 215  	function getObject(tfile) {    
 216          var x = document.getElementById('iselDiv').getElementsByTagName('li');
 217          for (var i = 0; i < x.length; i++) {
 218              if (x[i].attributes['ifile'].value == tfile) {                    
 219                  x[i].className = 'cimgdown';
 220                  imageChangeClick(x[i]);
 221              }
 222          }    
 223      }
 224  // ============================================================

 225  // = load/hide message, date: 02/08/2005                      =

 226  // ============================================================

 227  	function hideloadmessage() {
 228          document.getElementById('dialogLoadMessage').style.display = 'none'
 229      }
 230  -->
 231  </script>
 232  <title>Image list</title>
 233  <meta http-equiv="Pragma" content="no-cache">
 234  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $l->getCharset(); ?>">
 235  </head>
 236  <body onload="init(); hideloadmessage();" dir="<?php echo $l->getDir(); ?>">
 237  <?php include  'loadmsg.php'; ?>
 238  <form id="rfiles" name="rfiles" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" target="_self">
 239    <input type="hidden" name="lang" value="<?php echo $l->lang; ?>" />
 240    <input type="hidden" id= "action" name="action" value="<?php echo $action; ?>" />    
 241    <div id="iselDiv">
 242      <ul>
 243        <?php echo getItems($cfg['root_dir'] . $clib, $cfg['valid'], $list); ?>
 244      </ul>
 245    </div>
 246  </form>
 247  </body>
 248  </html>
 249  <?php
 250      // get images

 251  	function getItems($path, $valid, $list) {            
 252          global $cfg;
 253          global $l;        
 254          
 255          $path = str_replace('//','/', $path); // remove double slash in path if any        

 256          $retstr = '';                                        
 257          if ($handle = @opendir($path)) {            
 258              $files = array();
 259              $valids = implode('|', $valid);            
 260              while (($file = readdir($handle)) !== false) {                                                            
 261                  if (is_file($path . $file) && eregi('\.(' . $valids . ')$', $file, $matches)) {                                                                                   
 262                      $files[$path . $file] = $matches[0];
 263                  }
 264              }
 265              closedir($handle);                                               
 266              ksort($files);                            
 267              $dfmt = "m-d-Y";
 268              foreach ($files as $filename => $ext) {                                        
 269                  $size     = @getimagesize($path . basename($filename));        
 270                  if( $size === false ) {
 271                       continue;
 272                  }
 273                  $fsize    = filesize($path . basename($filename));                        
 274                  $modified = date($dfmt, filemtime($path . basename($filename)));
 275                  $created  = date($dfmt, filectime($path . basename($filename)));                                
 276                  $ctype    = iType($size[2]);                
 277                  if ($list == true || $list == 1) {
 278                      $retstr .= '<li class="cimgup" ifile="' . basename($filename) . '" iwidth="' . htmlentities($size[0], ENT_QUOTES) . '" iheight="' . htmlentities($size[1], ENT_QUOTES) . '" itype="' . htmlentities($size[2] . '|' . $ctype, ENT_QUOTES) . '" imdate="' . htmlentities($modified, ENT_QUOTES) . '" icdate="' . htmlentities($created, ENT_QUOTES) . '" isize="' .filesize_h($fsize,2) . '">' . htmlentities(basename($filename), ENT_QUOTES,$l->getCharset()) . '</li>' . "\n";
 279                  } else {
 280                      $src     = 'phpThumb/phpThumb.php?src=' . absPath(str_replace($cfg['root_dir'],'', $path)) . basename($filename) . '&w=48&h=48&far=1&bg=ffffff&f=jpg';                 
 281                      $retstr .= '<li class="cimgup" ifile="' . basename($filename) . '" iwidth="' . htmlentities($size[0], ENT_QUOTES) . '" iheight="' . htmlentities($size[1], ENT_QUOTES) . '" itype="' . htmlentities($size[2] . '|' . $ctype, ENT_QUOTES) . '" imdate="' . htmlentities($modified, ENT_QUOTES) . '" icdate="' . htmlentities($created, ENT_QUOTES) . '" isize="' .filesize_h($fsize,2) . '">' . '<img src="' . $src . '" width="48" height="48" alt="' . basename($filename) . '; ' . htmlentities($size[0], ENT_QUOTES) . ' x ' . htmlentities($size[1], ENT_QUOTES) . 'px;' . '" title="' . basename($filename) . '; ' . htmlentities($size[0], ENT_QUOTES) . ' x ' . htmlentities($size[1], ENT_QUOTES) . 'px;' . '"/>' . '</li>' . "\n";
 282                  }
 283              }            
 284              return $retstr;
 285          }
 286          echo $l->m('er_036');            
 287          return false;        
 288      }
 289      // get image types

 290  	function iType($type) {        
 291          switch ($type) {
 292              case 1:
 293                  $str = 'GIF'; break;
 294                 case 2:
 295                     $str = 'JPG'; break;
 296                 case 3:
 297                     $str = 'PNG'; break;
 298                 case 4:
 299                     $str = 'SWF'; break;
 300              case 5:
 301                     $str = 'PSD'; break;
 302              case 6:
 303                     $str = 'BMP'; break;
 304              case 7:
 305                     $str = 'TIFF'; break;
 306              case 8:
 307                     $str = 'TIFF'; break;
 308              case 15:
 309                     $str = 'WBMP'; break;
 310              default:
 311                     $str = 'n/a'; break;
 312          }
 313          return $str;
 314      }
 315      
 316      //-------------------------------------------------------------------------

 317      // Return the human readable size of a file

 318      // @param int $size a file size

 319      // @param int $dec a number of decimal places

 320  	function filesize_h($size, $dec = 1) {
 321          $sizes = array('b', 'kb', 'mb', 'gb');
 322          $count = count($sizes);
 323          $i = 0;
 324          while ($size >= 1024 && ($i < $count - 1)) {
 325              $size /= 1024;
 326              $i++;
 327          }
 328          return round($size, $dec) . '|' . $sizes[$i];
 329      }
 330      
 331      //-------------------------------------------------------------------------

 332      // delete image

 333  	function deleteImg($clib, $cfile) {        
 334            global $cfg;          
 335            global $l;
 336            
 337            if (!$cfg['delete']) {
 338              return false;
 339          }        
 340          $path = str_replace('//', '/', $cfg['root_dir'] . $clib);     // remove double slash in path        

 341          return @unlink($path . $cfile);                             // returns true or false                 

 342      }
 343      
 344      //-------------------------------------------------------------------------

 345      // rename image    

 346  	function renameImg($clib, $cfile, $nfile) {        
 347          global $cfg;          
 348            global $l;
 349                  
 350          if (!$cfg['rename']) {
 351              return false;
 352          }
 353          
 354          // check new file extension

 355          $ext = strtolower(substr($nfile,strrpos($nfile, '.')+1));
 356          if (!in_array($ext, $cfg['valid'])) {                         // invalid image / file extension            
 357              echo $l->m('er_029');            
 358              return false;
 359          }
 360          
 361          $path = str_replace('//', '/', $cfg['root_dir'] . $clib);     // remove double slash in path                    

 362          if (file_exists($path . $cfile)) {        
 363              $nfile = fixFileName($nfile);                             // remove invalid characters in file name

 364              $nfile = chkFileName($path, $nfile);                     // rename if file already exists

 365              
 366              @rename($path . $cfile, $path . $nfile);                
 367               return $nfile;            
 368          }
 369          return false;
 370      }
 371      
 372      //-------------------------------------------------------------------------

 373      // create directory

 374  	function createDir($clib, $nfile) {        
 375            global $cfg;          
 376            global $l; 
 377           
 378            if (!$cfg['create']) {
 379              return false;
 380          }
 381          
 382          $nfile = fixFileName($nfile);
 383          $tfile = $nfile;
 384          $path = str_replace('//', '/', $cfg['root_dir'] . $clib);     // remove double slash in path        

 385          
 386          // renaming directory if it already exists

 387          // keep looping and incrementing _i filenumber until a non-existing one is found        

 388          $i = 1;
 389          while (file_exists($path . $nfile)) {            
 390              $nfile = $tfile . '_' . $i;                
 391              $i++;
 392          }        
 393          
 394          $perm = 0777;
 395          $oumask = umask(0);
 396          umask();
 397          if(@mkdir($path . $nfile, $perm)) {
 398              umask($oumask);
 399              return true;
 400          }
 401          umask($oumask);
 402          return false;    
 403      }    
 404      //-------------------------------------------------------------------------

 405      // upload image

 406  	function uploadImg($clib, $chkT, $selR) {         
 407          global $cfg;
 408            global $l;
 409            
 410            if (!$cfg['upload']) {
 411              return false;
 412          }
 413          
 414          foreach ($_FILES['nfile']['size'] as $key => $size) {            
 415              if ($size > 0) {            
 416                  // get file extension and check for validity                 

 417                  $ext = pathinfo($_FILES['nfile']['name'][$key]);
 418                  $ext = strtolower($ext['extension']);                
 419                  if (!in_array($ext, $cfg['valid'])) {                         // invalid image            
 420                      echo $l->m('er_029');            
 421                      return false;
 422                  }
 423                  
 424                  $path  = str_replace('//', '/', $cfg['root_dir'] . $clib);     // remove double slash in path    

 425                  $nfile = fixFileName($_FILES['nfile']['name'][$key]);         // remove invalid characters in filename                    

 426                  
 427                  // move file to temp directory for processing

 428                  if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $cfg['temp'] . '/' . $nfile)) { // upload image to temp dir
 429                      echo $l->m('er_028');                
 430                      return false;
 431                  }
 432                  
 433                  $size = getimagesize($cfg['temp'] . '/' . $nfile);    
 434                  
 435                  // process (thumbnail) images            

 436                  $arr = $cfg['thumbs'];                
 437                  foreach($arr as $key => $thumb) {
 438                      if (in_array($key, $chkT)) {                                        
 439                          // create new phpThumb() object

 440                          require_once(dirname(__FILE__) . '/phpThumb/phpthumb.class.php');
 441                          $phpThumb = new phpThumb();                            // create object

 442                          // parameters

 443                          $phpThumb->config_cache_disable_warning = true;        // disable cache warning            

 444                          $phpThumb->config_output_format = $ext;                // output format    

 445                          $phpThumb->src = $cfg['temp'] . '/' . $nfile;        // destination

 446                          $phpThumb->q = 95;                                     // compression level for jpeg

 447                          if ($selR != '') {                                    // set auto rotate
 448                              $phpThumb->ar = $selR;
 449                          };                                        
 450                          //-------------------------------------------------------------------------

 451                          if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) {    // size value is set -> RESIZING and source image is larger than preset sizes
 452                              // resize parameters

 453                              if ($size[0] < $size[1]) {                      // portrait
 454                                  $phpThumb->h  =