Esempio n. 1
0
function wptouch_settings_process($wptouch_pro)
{
    if (isset($wptouch_pro->post['wptouch-reset-3'])) {
        $wptouch_pro->verify_post_nonce();
        // Clear the cookie
        setcookie('wptouch-admin-menu', 0, time() - 3600);
        WPTOUCH_DEBUG(WPTOUCH_INFO, "Settings are being reset");
        $wptouch_pro->erase_all_settings();
        $wptouch_pro->reset_icon_states();
        $wptouch_pro->reload_settings();
        require_once WPTOUCH_DIR . '/core/menu.php';
        // Check for multisite reset
        if (wptouch_is_multisite_enabled() && wptouch_is_multisite_primary()) {
            delete_site_option(WPTOUCH_MULTISITE_LICENSED);
        }
        $wptouch_pro->redirect_to_page(admin_url('admin.php?page=wptouch-admin-touchboard'));
        wptouch_delete_all_transients();
    } else {
        if (isset($wptouch_pro->post['wptouch-submit-3'])) {
            $wptouch_pro->verify_post_nonce();
            if (isset($wptouch_pro->post['wptouch_restore_settings']) && strlen($wptouch_pro->post['wptouch_restore_settings'])) {
                require_once 'admin-backup-restore.php';
                wptouch_restore_settings($wptouch_pro->post['wptouch_restore_settings']);
                return;
            }
            $new_settings = array();
            $modified_domains = array();
            // Search for all the settings to update
            foreach ($wptouch_pro->post as $key => $content) {
                if (preg_match('#^wptouch__(.*)__(.*)#', $key, $match)) {
                    $setting_domain = $match[1];
                    $setting_name = $match[2];
                    // Decode slashes on strings
                    if (is_string($content)) {
                        $content = htmlspecialchars_decode($content);
                    }
                    $new_settings[$setting_domain][$setting_name] = apply_filters('wptouch_modify_setting__' . $setting_domain . '__' . $setting_name, $content);
                    // Flag which domains have been modified
                    $modified_domains[$setting_domain] = 1;
                    if (isset($wptouch_pro->post['hid-wptouch__' . $match[1] . '__' . $match[2]])) {
                        // This is a checkbox
                        $new_settings[$setting_domain][$setting_name] = 1;
                    }
                }
            }
            // Do a loop and find all the checkboxes that should be disabled
            foreach ($wptouch_pro->post as $key => $content) {
                if (preg_match('#^hid-wptouch__(.*)__(.*)#', $key, $match)) {
                    $setting_domain = $match[1];
                    $setting_name = $match[2];
                    $new_settings[$setting_domain][$setting_name] = isset($new_settings[$setting_domain][$setting_name]) ? 1 : 0;
                    $modified_domains[$setting_domain] = 1;
                }
            }
            // Update all the domains that have been modified
            foreach ($modified_domains as $domain => $ignored_value) {
                $settings = $wptouch_pro->get_settings($domain);
                // Update settings with new values
                foreach ($new_settings[$domain] as $key => $value) {
                    if (isset($settings->{$key})) {
                        $settings->{$key} = $value;
                    }
                }
                $settings->save();
            }
            // Handle automatic backup
            $settings = wptouch_get_settings();
            if ($settings->automatically_backup_settings) {
                require_once 'admin-backup-restore.php';
                wptouch_backup_settings();
            }
            wptouch_delete_all_transients();
        }
    }
}
 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;
 }
Esempio n. 3
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;
 }