| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       *
 
     | 
  
  
    | 
      4
     | 
    
       * @category        admin
 
     | 
  
  
    | 
      5
     | 
    
       * @package         media
 
     | 
  
  
    | 
      6
     | 
    
       * @author          WebsiteBaker Project
 
     | 
  
  
    | 
      7
     | 
    
       * @copyright       Ryan Djurovich
 
     | 
  
  
    | 
      8
     | 
    
       * @copyright       WebsiteBaker Org. e.V.
 
     | 
  
  
    | 
      9
     | 
    
       * @link            http://websitebaker.org/
 
     | 
  
  
    | 
      10
     | 
    
       * @license         http://www.gnu.org/licenses/gpl.html
 
     | 
  
  
    | 
      11
     | 
    
       * @platform        WebsiteBaker 2.8.3
 
     | 
  
  
    | 
      12
     | 
    
       * @requirements    PHP 5.3.6 and higher
 
     | 
  
  
    | 
      13
     | 
    
       * @version         $Id: rename.php 2 2017-07-02 15:14:29Z Manuela $
 
     | 
  
  
    | 
      14
     | 
    
       * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/media/rename.php $
 
     | 
  
  
    | 
      15
     | 
    
       * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
 
     | 
  
  
    | 
      16
     | 
    
       *
 
     | 
  
  
    | 
      17
     | 
    
       */
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      require(dirname(dirname(__DIR__)).'/config.php');
 
     | 
  
  
    | 
      20
     | 
    
      
 
     | 
  
  
    | 
      21
     | 
    
      // Create admin object
 
     | 
  
  
    | 
      22
     | 
    
      require_once(WB_PATH.'/framework/class.admin.php');
 
     | 
  
  
    | 
      23
     | 
    
      $admin = new admin('Media', 'media_rename', false);
     | 
  
  
    | 
      24
     | 
    
      
 
     | 
  
  
    | 
      25
     | 
    
      // Include the WB functions file
 
     | 
  
  
    | 
      26
     | 
    
      require_once(WB_PATH.'/framework/functions.php');
 
     | 
  
  
    | 
      27
     | 
    
      
 
     | 
  
  
    | 
      28
     | 
    
      // Get the current dir
 
     | 
  
  
    | 
      29
     | 
    
      $directory = $admin->get_get('dir');
     | 
  
  
    | 
      30
     | 
    
      $directory = ($directory == '/') ?  '' : $directory;
 
     | 
  
  
    | 
      31
     | 
    
      
 
     | 
  
  
    | 
      32
     | 
    
      $dirlink = 'browse.php?dir='.$directory;
 
     | 
  
  
    | 
      33
     | 
    
      $rootlink = 'browse.php?dir=';
 
     | 
  
  
    | 
      34
     | 
    
      // $file_id = intval($admin->get_get('id'));
     | 
  
  
    | 
      35
     | 
    
      
 
     | 
  
  
    | 
      36
     | 
    
      // first Check to see if it contains ..
 
     | 
  
  
    | 
      37
     | 
    
      if (!check_media_path($directory)) {
     | 
  
  
    | 
      38
     | 
    
          $admin->print_error($MESSAGE['MEDIA_DIR_DOT_DOT_SLASH'],$rootlink, false);
 
     | 
  
  
    | 
      39
     | 
    
      }
 
     | 
  
  
    | 
      40
     | 
    
      
 
     | 
  
  
    | 
      41
     | 
    
      // Get the temp id
 
     | 
  
  
    | 
      42
     | 
    
      $file_id = intval($admin->checkIDKEY('id', false, $_SERVER['REQUEST_METHOD']))-1;
     | 
  
  
    | 
      43
     | 
    
      if ($file_id===false) {
     | 
  
  
    | 
      44
     | 
    
          $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$dirlink, false);
 
     | 
  
  
    | 
      45
     | 
    
      }
 
     | 
  
  
    | 
      46
     | 
    
      
 
     | 
  
  
    | 
      47
     | 
    
      $DIR  = array();
 
     | 
  
  
    | 
      48
     | 
    
      $FILE = array();
 
     | 
  
  
    | 
      49
     | 
    
      // Get home folder not to show
 
     | 
  
  
    | 
      50
     | 
    
      $home_folders = get_home_folders();
 
     | 
  
  
    | 
      51
     | 
    
      // Check for potentially malicious files
 
     | 
  
  
    | 
      52
     | 
    
      $forbidden_file_types  = preg_replace( '/\s*[,;\|#]\s*/','|',RENAME_FILES_ON_UPLOAD);
 
     | 
  
  
    | 
      53
     | 
    
      // Figure out what folder name the temp id is
 
     | 
  
  
    | 
      54
     | 
    
      if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$directory)) {
     | 
  
  
    | 
      55
     | 
    
          // Loop through the files and dirs an add to list
 
     | 
  
  
    | 
      56
     | 
    
         while (false !== ($file = readdir($handle))) {
     | 
  
  
    | 
      57
     | 
    
              $info = pathinfo($file);
 
     | 
  
  
    | 
      58
     | 
    
              $ext = isset($info['extension']) ? $info['extension'] : '';
 
     | 
  
  
    | 
      59
     | 
    
              if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
     | 
  
  
    | 
      60
     | 
    
                  if( !preg_match('/'.$forbidden_file_types.'$/i', $ext) ) {
     | 
  
  
    | 
      61
     | 
    
                      if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
     | 
  
  
    | 
      62
     | 
    
                          if(!isset($home_folders[$directory.'/'.$file])) {
     | 
  
  
    | 
      63
     | 
    
                              $DIR[] = $file;
 
     | 
  
  
    | 
      64
     | 
    
                          }
 
     | 
  
  
    | 
      65
     | 
    
                      } else {
     | 
  
  
    | 
      66
     | 
    
                          $FILE[] = $file;
 
     | 
  
  
    | 
      67
     | 
    
                      }
 
     | 
  
  
    | 
      68
     | 
    
                  }
 
     | 
  
  
    | 
      69
     | 
    
              }
 
     | 
  
  
    | 
      70
     | 
    
          }
 
     | 
  
  
    | 
      71
     | 
    
      closedir($handle);
 
     | 
  
  
    | 
      72
     | 
    
      }
 
     | 
  
  
    | 
      73
     | 
    
      
 
     | 
  
  
    | 
      74
     | 
    
          $iSortFlags = ((version_compare(PHP_VERSION, '5.4.0', '<'))?SORT_REGULAR:SORT_NATURAL|SORT_FLAG_CASE);
 
     | 
  
  
    | 
      75
     | 
    
          sort($DIR, $iSortFlags);
 
     | 
  
  
    | 
      76
     | 
    
          sort($FILE, $iSortFlags);
 
     | 
  
  
    | 
      77
     | 
    
          $aListDir = array_merge($DIR,$FILE);
 
     | 
  
  
    | 
      78
     | 
    
          $temp_id = 0;
 
     | 
  
  
    | 
      79
     | 
    
          if(isset($aListDir)) {
     | 
  
  
    | 
      80
     | 
    
              foreach($aListDir AS $name)
 
     | 
  
  
    | 
      81
     | 
    
              {
     | 
  
  
    | 
      82
     | 
    
                  if(!isset($rename_file)&& ($file_id == $temp_id)) {
     | 
  
  
    | 
      83
     | 
    
                      $rename_file = $name;
 
     | 
  
  
    | 
      84
     | 
    
                      $type = is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$rename_file)?'folder':'file';
 
     | 
  
  
    | 
      85
     | 
    
                  }
 
     | 
  
  
    | 
      86
     | 
    
                  $temp_id++;
 
     | 
  
  
    | 
      87
     | 
    
              }
 
     | 
  
  
    | 
      88
     | 
    
          }
 
     | 
  
  
    | 
      89
     | 
    
      /*
 
     | 
  
  
    | 
      90
     | 
    
      print '<pre  class="mod-pre rounded">function <span>'.__FUNCTION__.'( '.$file_id.'=='.$temp_id.' );</span>  filename: <span>'.basename(__FILE__).'</span>  line: '.__LINE__.' -> <br />';
 
     | 
  
  
    | 
      91
     | 
    
      print_r( $rename_file.' '.$type ); print '</pre>'; flush (); //  ob_flush();;sleep(10); die();
 
     | 
  
  
    | 
      92
     | 
    
      print '<pre  class="mod-pre rounded">function <span>'.__FUNCTION__.'( '.' );</span>  filename: <span>'.basename(__FILE__).'</span>  line: '.__LINE__.' -> <br />';
 
     | 
  
  
    | 
      93
     | 
    
      print_r( $aListDir ); print '</pre>'; flush (); //  ob_flush();;sleep(10); die();
 
     | 
  
  
    | 
      94
     | 
    
      */
 
     | 
  
  
    | 
      95
     | 
    
      
 
     | 
  
  
    | 
      96
     | 
    
      if(!isset($rename_file)) {
     | 
  
  
    | 
      97
     | 
    
          $admin->print_error($MESSAGE['MEDIA_FILE_NOT_FOUND'], $dirlink, false);
 
     | 
  
  
    | 
      98
     | 
    
      }
 
     | 
  
  
    | 
      99
     | 
    
      
 
     | 
  
  
    | 
      100
     | 
    
      $sExtension = '';
 
     | 
  
  
    | 
      101
     | 
    
      $sBasename = $rename_file;
 
     | 
  
  
    | 
      102
     | 
    
      preg_match (
 
     | 
  
  
    | 
      103
     | 
    
          '/^(?:.*?[\/])?([^\/]*?)\.([^\.]*)$/iU',
 
     | 
  
  
    | 
      104
     | 
    
          str_replace('\\', '/', $rename_file),
     | 
  
  
    | 
      105
     | 
    
          $aMatches
 
     | 
  
  
    | 
      106
     | 
    
      );
 
     | 
  
  
    | 
      107
     | 
    
      if (sizeof($aMatches) == 3) {
     | 
  
  
    | 
      108
     | 
    
          $sBasename  = $aMatches[1];
 
     | 
  
  
    | 
      109
     | 
    
          $sExtension = $aMatches[2];
 
     | 
  
  
    | 
      110
     | 
    
      }
 
     | 
  
  
    | 
      111
     | 
    
      
 
     | 
  
  
    | 
      112
     | 
    
      // Setup template object, parse vars to it, then parse it
 
     | 
  
  
    | 
      113
     | 
    
      // Create new template object
 
     | 
  
  
    | 
      114
     | 
    
      $template = new Template(dirname($admin->correct_theme_source('media_rename.htt')));
     | 
  
  
    | 
      115
     | 
    
      $template->set_file('page', 'media_rename.htt');
     | 
  
  
    | 
      116
     | 
    
      $template->set_block('page', 'main_block', 'main');
     | 
  
  
    | 
      117
     | 
    
      //echo WB_PATH.'/media/'.$directory.'/'.$rename_file;
 
     | 
  
  
    | 
      118
     | 
    
      if($type == 'folder') {
     | 
  
  
    | 
      119
     | 
    
          $template->set_var('DISPlAY_EXTENSION', 'hide');
     | 
  
  
    | 
      120
     | 
    
          $extension = '';
 
     | 
  
  
    | 
      121
     | 
    
      } else {
     | 
  
  
    | 
      122
     | 
    
          $template->set_var('DISPlAY_EXTENSION', '');
     | 
  
  
    | 
      123
     | 
    
          $extension = strstr($rename_file, '.');
 
     | 
  
  
    | 
      124
     | 
    
      }
 
     | 
  
  
    | 
      125
     | 
    
      
 
     | 
  
  
    | 
      126
     | 
    
      if($type == 'folder') {
     | 
  
  
    | 
      127
     | 
    
          $type = $TEXT['FOLDER'];
 
     | 
  
  
    | 
      128
     | 
    
      } else {
     | 
  
  
    | 
      129
     | 
    
          $type = $TEXT['FILE'];
 
     | 
  
  
    | 
      130
     | 
    
      }
 
     | 
  
  
    | 
      131
     | 
    
      
 
     | 
  
  
    | 
      132
     | 
    
      $template->set_var(array(
 
     | 
  
  
    | 
      133
     | 
    
                          'THEME_URL' => THEME_URL,
 
     | 
  
  
    | 
      134
     | 
    
                          'FILENAME' => $rename_file,
 
     | 
  
  
    | 
      135
     | 
    
                          'BASENAME' => $sBasename,
 
     | 
  
  
    | 
      136
     | 
    
                          'DIR' => $directory,
 
     | 
  
  
    | 
      137
     | 
    
                          'FILE_ID' => $admin->getIDKEY($file_id),
 
     | 
  
  
    | 
      138
     | 
    
                          // 'FILE_ID' => $file_id,
 
     | 
  
  
    | 
      139
     | 
    
                          'TYPE' => $type,
 
     | 
  
  
    | 
      140
     | 
    
                          'EXTENSION' => $sExtension,
 
     | 
  
  
    | 
      141
     | 
    
                          'FTAN' => $admin->getFTAN()
 
     | 
  
  
    | 
      142
     | 
    
                      )
 
     | 
  
  
    | 
      143
     | 
    
                  );
 
     | 
  
  
    | 
      144
     | 
    
      
 
     | 
  
  
    | 
      145
     | 
    
      
 
     | 
  
  
    | 
      146
     | 
    
      // Insert language text and messages
 
     | 
  
  
    | 
      147
     | 
    
      $template->set_var(array(
 
     | 
  
  
    | 
      148
     | 
    
                          'TEXT_TO' => $TEXT['TO'],
 
     | 
  
  
    | 
      149
     | 
    
                          'TEXT_RENAME' => $TEXT['RENAME'],
 
     | 
  
  
    | 
      150
     | 
    
                          'TEXT_CANCEL' => $TEXT['CANCEL'],
 
     | 
  
  
    | 
      151
     | 
    
                          'TEXT_UP' => $TEXT['UP'],
 
     | 
  
  
    | 
      152
     | 
    
                          'TEXT_OVERWRITE_EXISTING' => $TEXT['OVERWRITE_EXISTING']
 
     | 
  
  
    | 
      153
     | 
    
                      )
 
     | 
  
  
    | 
      154
     | 
    
                  );
 
     | 
  
  
    | 
      155
     | 
    
      
 
     | 
  
  
    | 
      156
     | 
    
      // Parse template object
 
     | 
  
  
    | 
      157
     | 
    
      $template->parse('main', 'main_block', false);
     | 
  
  
    | 
      158
     | 
    
      $template->pparse('output', 'page');
     |