function handle_upload_file()
 {
     $this->cleanup_post_and_get();
     header('HTTP/1.1 200 OK');
     $nonce = $this->post['wp_nonce'];
     if (wp_verify_nonce($nonce, 'wptouch_admin')) {
         switch ($this->post['file_type']) {
             case 'homescreen_image':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading new HOMESCREEN image');
                 // Move uploaded file
                 if (isset($_FILES['myfile'])) {
                     $temp_name = $_FILES['myfile']['tmp_name'];
                     $real_name = $_FILES['myfile']['name'];
                     $destination_file = WPTOUCH_CUSTOM_UPLOAD_DIRECTORY . '/' . $real_name;
                     if (file_exists($destination_file)) {
                         unlink($destination_file);
                     }
                     move_uploaded_file($temp_name, $destination_file);
                     require_once WPTOUCH_DIR . '/core/settings.php';
                     do_action('wptouch_post_process_image_file', $destination_file, wptouch_decode_encoded_setting($this->post['setting_name']));
                     $image_file = str_replace(WPTOUCH_BASE_CONTENT_DIR, '', $destination_file);
                     $this->update_encoded_setting($this->post['setting_name'], $image_file);
                 }
                 echo WPTOUCH_BASE_CONTENT_URL . $image_file;
                 break;
             case 'custom_image':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading new CUSTOM image');
                 if (isset($_FILES['myfile'])) {
                     $temp_name = $_FILES['myfile']['tmp_name'];
                     $real_name = $_FILES['myfile']['name'];
                     $destination_file = WPTOUCH_CUSTOM_ICON_DIRECTORY . '/' . $real_name;
                     if (file_exists($destination_file)) {
                         unlink($destination_file);
                     }
                     move_uploaded_file($temp_name, $destination_file);
                 }
                 break;
             case 'settings_backup':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading SETTINGS BACKUP file');
                 if (isset($_FILES['myfile'])) {
                     $temp_name = $_FILES['myfile']['tmp_name'];
                     if (file_exists($temp_name)) {
                         $settings_info = $this->load_file($temp_name);
                         if ($settings_info) {
                             require_once WPTOUCH_DIR . '/core/admin-backup-restore.php';
                             wptouch_restore_settings($settings_info);
                         }
                         unlink($temp_name);
                     }
                 }
                 break;
             default:
                 // For different file uploads
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Handling default file upload');
                 do_action('wptouch_upload_file', $this->post['file_type']);
                 break;
         }
     }
     die;
 }
示例#2
0
 function handle_upload_file()
 {
     $this->cleanup_post_and_get();
     header('HTTP/1.1 200 OK');
     $nonce = $this->post['wp_nonce'];
     if (wp_verify_nonce($nonce, 'wptouch_admin') && current_user_can('manage_options')) {
         switch ($this->post['file_type']) {
             case 'homescreen_image':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading new HOMESCREEN image');
                 if ($this->is_image_file($_FILES['myfile']['name'])) {
                     // Move uploaded file
                     if (isset($_FILES['myfile'])) {
                         $temp_name = $_FILES['myfile']['tmp_name'];
                         $real_name = $_FILES['myfile']['name'];
                         $real_name = str_replace(' ', '-', $real_name);
                         $destination_file = WPTOUCH_CUSTOM_UPLOAD_DIRECTORY . '/' . $real_name;
                         if (file_exists($destination_file)) {
                             unlink($destination_file);
                         }
                         move_uploaded_file($temp_name, $destination_file);
                         require_once WPTOUCH_DIR . '/core/settings.php';
                         do_action('wptouch_post_process_image_file', $destination_file, wptouch_decode_encoded_setting($this->post['setting_name']));
                         $image_file = str_replace(WPTOUCH_BASE_CONTENT_DIR, '', $destination_file);
                         $this->update_encoded_setting($this->post['setting_name'], $image_file);
                     }
                     echo WPTOUCH_BASE_CONTENT_URL . $image_file;
                 } else {
                     echo 'invalid image';
                     WPTOUCH_DEBUG(WPTOUCH_INFO, 'Not a valid image');
                 }
                 break;
             case 'custom_image':
                 if ($this->is_image_file($_FILES['myfile']['name'])) {
                     WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading new CUSTOM image');
                     if (isset($_FILES['myfile'])) {
                         $temp_name = $_FILES['myfile']['tmp_name'];
                         $real_name = $_FILES['myfile']['name'];
                         $real_name = str_replace(' ', '-', $real_name);
                         $destination_file = WPTOUCH_CUSTOM_ICON_DIRECTORY . '/' . $real_name;
                         if (file_exists($destination_file)) {
                             unlink($destination_file);
                         }
                         move_uploaded_file($temp_name, $destination_file);
                     }
                 } else {
                     echo 'invalid image';
                     WPTOUCH_DEBUG(WPTOUCH_INFO, 'Not a valid image');
                 }
                 break;
             case 'settings_backup':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading SETTINGS BACKUP file');
                 if (isset($_FILES['myfile'])) {
                     $temp_name = $_FILES['myfile']['tmp_name'];
                     if (file_exists($temp_name)) {
                         $settings_info = $this->load_file($temp_name);
                         if ($settings_info) {
                             require_once WPTOUCH_DIR . '/core/admin-backup-restore.php';
                             wptouch_restore_settings($settings_info);
                         }
                         unlink($temp_name);
                     }
                 }
                 break;
             case 'theme':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading THEME file');
                 if (isset($_FILES['theme-upload'])) {
                     $temp_name = $_FILES['theme-upload']['tmp_name'];
                     $destination_path = wptouch_get_multsite_aware_install_path('themes');
                     require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
                     $installer = new WPtouchAddonThemeInstaller();
                     $installer->install_anywhere(false, false, $destination_path, $temp_name);
                 }
                 break;
             case 'extension':
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Uploading EXTENSION file');
                 if (isset($_FILES['extension-upload'])) {
                     $temp_name = $_FILES['extension-upload']['tmp_name'];
                     $destination_path = wptouch_get_multsite_aware_install_path('extensions');
                     require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
                     $installer = new WPtouchAddonThemeInstaller();
                     $installer->install_anywhere(false, false, $destination_path, $temp_name);
                 }
                 break;
             default:
                 // For different file uploads
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Handling default file upload');
                 do_action('wptouch_upload_file', $this->post['file_type']);
                 break;
         }
     }
     die;
 }