예제 #1
0
function wptouch_admin_handle_ajax(&$wptouch_pro, $ajax_action)
{
    switch ($ajax_action) {
        case 'dismiss-warning':
            $wptouch_pro->check_plugins_for_warnings();
            $settings = $wptouch_pro->get_settings();
            if ($wptouch_pro->post['plugin']) {
                if (!in_array($wptouch_pro->post['plugin'], $settings->dismissed_warnings)) {
                    $settings->dismissed_warnings[] = $wptouch_pro->post['plugin'];
                    $settings->save();
                }
            }
            echo wptouch_get_plugin_warning_count();
            break;
        case 'delete-image-upload':
            if (isset($wptouch_pro->post['setting_name'])) {
                $wptouch_pro->update_encoded_setting($wptouch_pro->post['setting_name'], false);
                echo '0';
            }
            break;
        case 'delete-custom-icon':
            if (current_user_can('upload_files')) {
                if (isset($wptouch_pro->post['icon_name'])) {
                    $icon_location = WPTOUCH_CUSTOM_ICON_DIRECTORY . '/' . $wptouch_pro->post['icon_name'];
                    unlink($icon_location);
                    echo '0';
                }
            }
            break;
        case 'load-plugin-compat-list':
            $wptouch_pro->generate_plugin_hook_list(true);
            $compat_settings = wptouch_get_settings('compat');
            if (is_array($compat_settings->plugin_hooks) && count($compat_settings->plugin_hooks)) {
                $changed = false;
                foreach ($compat_settings->plugin_hooks as $name => $value) {
                    if (!isset($compat_settings->enabled_plugins[$name])) {
                        $compat_settings->enabled_plugins[$name] = 1;
                        $changed = true;
                    }
                }
                if ($changed) {
                    $compat_settings->save();
                }
            }
            echo wptouch_capture_include_file(WPTOUCH_DIR . '/admin/settings/html/plugin-compat-ajax.php');
            break;
        case 'prep-settings-download':
            require_once WPTOUCH_DIR . '/core/admin-backup-restore.php';
            $backup_file = wptouch_backup_settings();
            echo $backup_file;
            break;
        case 'load-upgrade-area':
            $content = wp_remote_get('http://wptouch-pro-4.s3.amazonaws.com/free-upgrade-area/page.xhtml');
            if (!is_wp_error($content)) {
                echo $content['body'];
            }
            break;
        case 'download-icon-set':
            global $wptouch_pro;
            require_once WPTOUCH_DIR . '/core/icon-set-installer.php';
            $icon_set_installer = new WPtouchIconSetInstaller();
            $icon_set_installer->install($wptouch_pro->post['base'], $wptouch_pro->post['url']);
            if (file_exists(WPTOUCH_BASE_CONTENT_DIR . '/icons/' . $wptouch_pro->post['base'])) {
                echo '1';
            } else {
                echo '0';
            }
            break;
        case 'get-icon-set-info':
            require_once WPTOUCH_DIR . '/core/admin-icons.php';
            echo wptouch_capture_include_file(WPTOUCH_DIR . '/admin/settings/html/installed_icon_sets_ajax.php');
            break;
        case 'admin-change-log':
            if (!defined('WPTOUCH_IS_FREE')) {
                $change_log = wp_remote_get(WPTOUCH_PRO_README_FILE);
            } else {
                $change_log = wp_remote_get('http://plugins.svn.wordpress.org/wptouch/trunk/readme.txt');
            }
            if (!is_wp_error($change_log)) {
                $content = $change_log['body'];
                $result = preg_match_all("#= Version (.*) =(.*)\n=#iUs", $content, $matches);
                if ($result) {
                    $entries = count($matches[0]);
                    for ($i = 0; $i < $entries; $i++) {
                        echo '<h4 style="font-family: Helvetica, sans-serif">' . sprintf(__('Version %s', 'wptouch-pro'), $matches[1][$i]) . '</h4><ul  style="font-family: Helvetica, sans-serif; font-size: 13px">';
                        echo str_replace('* ', '<li style="padding-top:3px;padding-bottom:3px;">', str_replace("\n", "</li>\n", $matches[2][$i]));
                        echo '</ul>';
                    }
                }
            } else {
                echo __('There is a temporary issue retrieving the change-log.  Please try again later.', 'wptouch-pro');
            }
            break;
        case 'load-addon-browser':
            require_once WPTOUCH_DIR . '/admin/settings/html/extension-browser-ajax.php';
            break;
        case 'repair-active-theme':
            $result = wptouch_repair_active_theme_from_cloud($errors);
            if (wptouch_migration_is_theme_broken()) {
                echo '0';
            } else {
                echo '1';
            }
            break;
        case 'wizard-language':
            $settings = $wptouch_pro->get_settings();
            if ($wptouch_pro->post['force_locale'] && $settings->force_locale != $wptouch_pro->post['force_locale']) {
                $settings->force_locale = $wptouch_pro->post['force_locale'];
                $settings->save();
                echo '1';
            } elseif ($wptouch_pro->post['force_network_locale'] && $settings->force_network_locale != $wptouch_pro->post['force_network_locale']) {
                $settings->force_network_locale = $wptouch_pro->post['force_network_locale'];
                $settings->save();
                echo '1';
            } else {
                echo '0';
            }
            break;
        case 'wizard-update-extensions':
            $result = json_decode(wptouch_update_all_addons());
            echo $result['status'];
            break;
        case 'wizard-theme':
            if (isset($wptouch_pro->post['theme'])) {
                wptouch_activate_theme($wptouch_pro->post['theme']);
                echo '1';
            } else {
                echo '0';
            }
            break;
        case 'wizard-extensions':
            if (isset($wptouch_pro->post['extensions'])) {
                foreach ($wptouch_pro->post['extensions'] as $extension) {
                    wptouch_activate_addon($extension);
                }
                echo '1';
            } else {
                echo '0';
            }
            break;
        case 'wizard-pages':
            $settings = $wptouch_pro->get_settings();
            if (get_option('show_on_front') == 'page' && isset($wptouch_pro->post['homepage_redirect_wp_target'])) {
                $settings->homepage_landing = 'select';
                $settings->homepage_redirect_wp_target = $wptouch_pro->post['homepage_redirect_wp_target'];
            }
            $settings->save();
            $settings = $wptouch_pro->get_settings('foundation');
            $settings->latest_posts_page = $wptouch_pro->post['latest_posts_page'];
            $settings->save();
            echo '1';
            break;
        case 'wizard-wptouch_message':
            $settings = $wptouch_pro->get_settings();
            if ($wptouch_pro->post['show_wptouch_in_footer'] == 'true') {
                $wptouch_pro->post['show_wptouch_in_footer'] = 1;
            } else {
                $wptouch_pro->post['show_wptouch_in_footer'] = 0;
            }
            if (isset($wptouch_pro->post['show_wptouch_in_footer']) && $settings->show_wptouch_in_footer != $wptouch_pro->post['show_wptouch_in_footer']) {
                $settings->show_wptouch_in_footer = $wptouch_pro->post['show_wptouch_in_footer'];
                $settings->save();
                echo '1';
            } else {
                echo '0';
            }
            break;
        case 'wizard-scan_for_analytics':
            $result = wp_remote_get(home_url());
            $result_info = array();
            if ($result && is_array($result) && isset($result['body'])) {
                if (preg_match_all('#(<script>.*</script>)#iUs', $result['body'], $match)) {
                    foreach ($match[0] as $possible_analytics) {
                        $search_for = array('GoogleAnalyticsObject');
                        foreach ($search_for as $search_phrase) {
                            if (preg_match('#' . $search_phrase . '#iU', $possible_analytics, $ga_match)) {
                                // Found Google Analytics code
                                $result_info['code'] = 'found';
                                $result_info['success'] = sprintf(__('Code found! %s Analytics was automatically configured for you.', 'wptouch-pro'), '<br />');
                                $result_info['fragment'] = htmlentities($possible_analytics);
                                // If Google, retrieve the site ID
                                if ($search_phrase == 'GoogleAnalyticsObject') {
                                    preg_match('/\'(UA-.*?)\'/s', $possible_analytics, $id_match);
                                    if (count($id_match) == 2) {
                                        $result_info['site_id'] = $id_match[1];
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (is_array($result) && !isset($result_info['code'])) {
                $result_info['code'] = 'noresult';
                $result_info['msg'] = __('Unable to find your Google Analytics code. You can enter it manually in the settings later.', 'wptouch-pro');
            }
            echo json_encode($result_info);
            break;
        case 'wizard-analytics':
            $settings = $wptouch_pro->get_settings();
            if ($wptouch_pro->post['analytics_google_id']) {
                $settings->analytics_google_id = $wptouch_pro->post['analytics_google_id'];
                $settings->analytics_embed_method = 'simple';
                $settings->save();
            }
            break;
        case 'wizard-multisite':
            $settings = $wptouch_pro->get_settings('bncid');
            if ($wptouch_pro->post['multisite_control'] == 'true') {
                $wptouch_pro->post['multisite_control'] = 1;
            } else {
                $wptouch_pro->post['multisite_control'] = 0;
            }
            $settings->multisite_control = $wptouch_pro->post['multisite_control'];
            $settings->save();
            break;
        case 'network-wizard-complete':
            $settings = $wptouch_pro->get_settings();
            $settings->show_network_wizard = false;
            $settings->save();
            break;
        case 'wizard-complete':
            $settings = $wptouch_pro->get_settings();
            if (defined('WPTOUCH_IS_FREE')) {
                $settings->show_free_wizard = false;
            } else {
                $settings->show_wizard = false;
            }
            $settings->save();
            break;
        case 'activate-license-key':
            $email = $wptouch_pro->post['email'];
            $key = $wptouch_pro->post['key'];
            $settings = wptouch_get_settings('bncid');
            $old_settings = $settings;
            $settings->bncid = $email;
            $settings->wptouch_license_key = $key;
            WPTOUCH_DEBUG(WPTOUCH_INFO, "Attempting site activation with email [" . $email . "] and key [" . $key . "]");
            $settings->save();
            $wptouch_pro->bnc_api = false;
            $wptouch_pro->setup_bncapi($email, $key, true);
            // let's try to activate the license
            $wptouch_pro->activate_license();
            // Check to see if the credentials were valid
            if ($wptouch_pro->bnc_api->response_code >= 406 && $wptouch_pro->bnc_api->response_code <= 408) {
                WPTOUCH_DEBUG(WPTOUCH_WARNING, "Activation response code was [" . $wptouch_pro->bnc_api->response_code . "]");
                echo '2';
            } else {
                if ($wptouch_pro->bnc_api->server_down) {
                    // Server is unreachable for some reason
                    WPTOUCH_DEBUG(WPTOUCH_WARNING, "Activation response code was [SERVER UNREACHABLE]");
                    echo '4';
                } else {
                    if ($wptouch_pro->bnc_api->verify_site_license()) {
                        // Activation successful
                        WPTOUCH_DEBUG(WPTOUCH_WARNING, "Activation successful, response code was [" . $wptouch_pro->bnc_api->response_code . "]");
                        $settings = wptouch_get_settings('bncid');
                        $settings->license_accepted = 1;
                        $settings->license_accepted_time = time();
                        $settings->save();
                        echo '1';
                    } else {
                        $bnc_info = $wptouch_pro->bnc_api->check_api();
                        if (isset($bnc_info['license_expired']) && $bnc_info['license_expired']) {
                            WPTOUCH_DEBUG(WPTOUCH_WARNING, "Failure: license is expired [" . $wptouch_pro->bnc_api->response_code . "]");
                            echo '5';
                        } else {
                            // No more licenses - might be triggered another way
                            WPTOUCH_DEBUG(WPTOUCH_WARNING, "Failure: activation response code was [" . $wptouch_pro->bnc_api->response_code . "]");
                            echo '3';
                        }
                    }
                }
            }
            break;
        case 'go-pro':
            $result = wptouch_free_go_pro();
            echo $result;
            break;
        case 'multisite_deploy':
            $source_site = $wptouch_pro->post['source_site'];
            $current_blog_id = get_current_blog_id();
            // Switch to the source site
            if ($current_blog_id != $source_site) {
                switch_to_blog($source_site);
                $wptouch_pro->settings_object = array();
            }
            $main_settings = $wptouch_pro->get_raw_settings('wptouch_pro');
            $foundation_settings = $wptouch_pro->get_raw_settings('foundation');
            $compat_settings = $wptouch_pro->get_raw_settings('compat');
            $colors = foundation_get_theme_colors();
            $color_settings = array();
            // Deploy color settings
            foreach ($colors as $color) {
                if (!isset($color_settings[$color->domain])) {
                    $new_settings = wptouch_get_settings($color->domain);
                    $color_settings[$color->domain] = $new_settings;
                }
            }
            $destination_sites = $wptouch_pro->post['deploy_sites'];
            foreach ($destination_sites as $site) {
                $update_customizer = false;
                $real_site = str_replace('site-', '', $site);
                restore_current_blog();
                switch_to_blog($real_site);
                $destination_main_settings = $wptouch_pro->get_raw_settings('wptouch_pro');
                if (!$destination_main_settings) {
                    $destination_main_settings = $wptouch_pro->get_setting_defaults('wptouch_pro');
                    $destination_main_settings = 'wptouch_pro';
                }
                $destination_foundation_settings = $wptouch_pro->get_raw_settings('foundation');
                if (!$destination_foundation_settings) {
                    $destination_foundation_settings = $wptouch_pro->get_setting_defaults('foundation');
                    $destination_foundation_settings->domain = 'foundation';
                }
                $destination_compat_settings = $wptouch_pro->get_raw_settings('compat');
                if (!$destination_compat_settings) {
                    $destination_compat_settings = $wptouch_pro->get_setting_defaults('compat');
                    $destination_compat_settings->domain = 'compat';
                }
                if ($wptouch_pro->post['deploy_general']) {
                    // Deploy general settings
                    $destination_main_settings->new_display_mode = $main_settings->new_display_mode;
                    $destination_main_settings->show_switch_link = $main_settings->show_switch_link;
                    $destination_foundation_settings->allow_zoom = $foundation_settings->allow_zoom;
                    $destination_foundation_settings->smart_app_banner = $foundation_settings->smart_app_banner;
                    $destination_main_settings->analytics_embed_method = $main_settings->analytics_embed_method;
                    $destination_main_settings->analytics_google_id = $main_settings->analytics_google_id;
                    $destination_main_settings->custom_stats_code = $main_settings->custom_stats_code;
                    $destination_main_settings->show_wptouch_in_footer = $main_settings->show_wptouch_in_footer;
                }
                if ($wptouch_pro->post['deploy_compat']) {
                    // Deploy compatiblitiy settings
                    $destination_main_settings->process_desktop_shortcodes = $main_settings->process_desktop_shortcodes;
                    $destination_main_settings->remove_shortcodes = $main_settings->remove_shortcodes;
                    $destination_compat_settings->plugin_hooks = $compat_settings->plugin_hooks;
                    $destination_compat_settings->enabled_plugins = $compat_settings->enabled_plugins;
                }
                if ($wptouch_pro->post['deploy_devices']) {
                    // Deploy device settings
                    $destination_main_settings->enable_ios_phone = $main_settings->enable_ios_phone;
                    $destination_main_settings->enable_android_phone = $main_settings->enable_android_phone;
                    $destination_main_settings->enable_blackberry_phone = $main_settings->enable_blackberry_phone;
                    $destination_main_settings->enable_firefox_phone = $main_settings->enable_firefox_phone;
                    $destination_main_settings->enable_opera_phone = $main_settings->enable_opera_phone;
                    $destination_main_settings->enable_windows_phone = $main_settings->enable_windows_phone;
                    $destination_main_settings->enable_ios_tablet = $main_settings->enable_ios_tablet;
                    $destination_main_settings->enable_android_tablet = $main_settings->enable_android_tablet;
                    $destination_main_settings->enable_windows_tablet = $main_settings->enable_windows_tablet;
                    $destination_main_settings->enable_kindle_tablet = $main_settings->enable_kindle_tablet;
                    $destination_main_settings->enable_blackberry_tablet = $main_settings->enable_blackberry_tablet;
                    $destination_main_settings->enable_webos_tablet = $main_settings->enable_webos_tablet;
                    $destination_main_settings->custom_user_agents = $main_settings->custom_user_agents;
                }
                if ($wptouch_pro->post['deploy_menus']) {
                    // Deploy menu settings
                    $destination_main_settings->enable_parent_items = $main_settings->enable_parent_items;
                    $destination_main_settings->enable_menu_icons = $main_settings->enable_menu_icons;
                }
                if ($wptouch_pro->post['deploy_themes']) {
                    // Deploy theme settings
                    $destination_main_settings->current_theme_friendly_name = $main_settings->current_theme_friendly_name;
                    $destination_main_settings->current_theme_location = $main_settings->current_theme_location;
                    $destination_main_settings->current_theme_name = $main_settings->current_theme_name;
                    $update_customizer = true;
                }
                if ($wptouch_pro->post['deploy_extensions']) {
                    // Deploy extension settings
                    $destination_main_settings->active_addons = $main_settings->active_addons;
                }
                if ($wptouch_pro->post['deploy_colors']) {
                    //echo $wptouch_pro->post[ 'deploy_colors' ];
                    // Deploy color settings
                    $destination_color_settings = array();
                    foreach ($colors as $color) {
                        if (!isset($destination_color_settings[$color->domain])) {
                            $new_settings = wptouch_get_settings($color->domain);
                            $destination_color_settings[$color->domain] = $new_settings;
                        }
                    }
                    foreach ($colors as $color) {
                        $setting_name = $color->setting;
                        $destination_color_settings[$color->domain]->{$setting_name} = $color_settings[$color->domain]->{$setting_name};
                    }
                    foreach ($destination_color_settings as $settings_object) {
                        $settings_object->save();
                    }
                    $update_customizer = true;
                }
                if ($wptouch_pro->post['deploy_social_media']) {
                    // Deploy social media settings
                    $destination_foundation_settings->social_facebook_url = $foundation_settings->social_facebook_url;
                    $destination_foundation_settings->social_twitter_url = $foundation_settings->social_twitter_url;
                    $destination_foundation_settings->social_google_url = $foundation_settings->social_google_url;
                    $destination_foundation_settings->social_instagram_url = $foundation_settings->social_instagram_url;
                    $destination_foundation_settings->social_tumblr_url = $foundation_settings->social_tumblr_url;
                    $destination_foundation_settings->social_pinterest_url = $foundation_settings->social_pinterest_url;
                    $destination_foundation_settings->social_vimeo_url = $foundation_settings->social_vimeo_url;
                    $destination_foundation_settings->social_youtube_url = $foundation_settings->social_youtube_url;
                    $destination_foundation_settings->social_linkedin_url = $foundation_settings->social_linkedin_url;
                    $destination_foundation_settings->social_yelp_url = $foundation_settings->social_yelp_url;
                    $destination_foundation_settings->social_email_url = $foundation_settings->social_email_url;
                    $destination_foundation_settings->social_rss_url = $foundation_settings->social_rss_url;
                    $update_customizer = true;
                }
                if ($wptouch_pro->post['deploy_social_sharing']) {
                    // Deploy social sharing icons
                    $destination_foundation_settings->show_share = $foundation_settings->show_share;
                    $destination_foundation_settings->share_on_pages = $foundation_settings->share_on_pages;
                    $destination_foundation_settings->share_location = $foundation_settings->share_location;
                    $destination_foundation_settings->share_colour_scheme = $foundation_settings->share_colour_scheme;
                    $update_customizer = true;
                }
                $destination_foundation_settings->save();
                $destination_main_settings->save();
                $destination_compat_settings->save();
                if ($update_customizer) {
                    wptouch_initialize_customizer(true);
                }
            }
            // Switch to the original site
            if ($current_blog_id != $source_site) {
                restore_current_blog();
            }
            break;
        default:
            do_action('wptouch_admin_ajax_' . $ajax_action, $wptouch_pro);
            do_action('wptouch_admin_ajax_intercept', $ajax_action);
            break;
    }
}
예제 #2
0
 function admin_initialize()
 {
     $is_plugins_page = strpos($_SERVER['REQUEST_URI'], 'plugins.php') !== false;
     // We need the BNCAPI for checking for plugin updates and all the wptouch-pro admin functions
     if ($this->admin_is_wptouch_page() || $is_plugins_page) {
         $this->setup_bncapi();
     }
     // Only check for updates explicitly on plugins page
     if ($is_plugins_page) {
         $can_check_for_update = true;
         if ($can_check_for_update) {
             WPTOUCH_DEBUG(WPTOUCH_INFO, 'Checking for product update');
             $this->check_for_update(true);
         }
     }
     // load the core AJAX on all pages
     $theme_broken = wptouch_migration_is_theme_broken() && !wptouch_can_repair_active_theme();
     if ($this->admin_is_wptouch_page() || $theme_broken) {
         $ajax_params = array('admin_ajax_nonce' => wp_create_nonce('wptouch_admin_ajax'));
         wp_enqueue_script('wptouch-pro-ajax', WPTOUCH_URL . '/admin/js/wptouch-ajax.js', array('jquery'));
         wp_localize_script('wptouch-pro-ajax', 'WPtouchAjax', $ajax_params);
         if ($theme_broken) {
             wp_enqueue_script('wptouch-cloud-migrate', WPTOUCH_URL . '/admin/js/wptouch-admin-migrate.js', array('wptouch-pro-ajax'), false, WPTOUCH_VERSION);
         }
     }
     // Check for broken plugins
     wptouch_migration_check_for_broken_extensions();
     //  load the rest of the admin scripts when we're looking at the WPtouch Pro page
     if ($this->admin_is_wptouch_page()) {
         $localize_params = array('admin_url' => get_bloginfo('wpurl') . '/wp-admin', 'plugin_admin_image_url' => WPTOUCH_ADMIN_URL . '/images', 'admin_nonce' => wp_create_nonce('wptouch_admin'), 'plugin_url' => admin_url('admin.php?page=' . $_GET['page']), 'text_preview_title' => __('Unsupported Browser', 'wptouch-pro'), 'text_preview_content' => __('Theme Preview requires Chrome or Safari.', 'wptouch-pro'), 'reset_settings' => __("This will reset all WPtouch Pro settings.\nAre you sure?", 'wptouch-pro'), 'reset_menus' => __("This will reset all WPtouch Pro menu and icon settings.\nAre you sure?", 'wptouch-pro'), 'cloud_offline' => __("Offline", 'wptouch-pro'), 'cloud_offline_message' => __("You appear to be offline. Connect to the internet to see available BraveNewCloud items.", 'wptouch-pro'), 'cloud_download_fail' => __('The item failed to download for this reason: %reason%', 'wptouch-pro'));
         wp_enqueue_script('jquery-plugins', WPTOUCH_URL . '/admin/js/wptouch-admin-plugins.js', 'jquery', md5(WPTOUCH_VERSION));
         wp_enqueue_script('jquery-ui-draggable');
         wp_enqueue_script('jquery-ui-droppable');
         wp_enqueue_script('wptouch-pro-admin', WPTOUCH_URL . '/admin/js/wptouch-admin-3.js', array('jquery-plugins', 'wptouch-pro-ajax', 'jquery', 'jquery-ui-draggable', 'jquery-ui-droppable'));
         // Set up AJAX requests here
         wp_localize_script('jquery-plugins', 'WPtouchCustom', $localize_params);
     }
     $this->setup_wptouch_admin_ajax();
 }
예제 #3
0
function wptouch_admin_handle_ajax($wptouch_pro, $ajax_action)
{
    switch ($ajax_action) {
        case 'dismiss-warning':
            $wptouch_pro->check_plugins_for_warnings();
            $settings = $wptouch_pro->get_settings();
            if ($wptouch_pro->post['plugin']) {
                if (!in_array($wptouch_pro->post['plugin'], $settings->dismissed_warnings)) {
                    $settings->dismissed_warnings[] = $wptouch_pro->post['plugin'];
                    $settings->save();
                }
            }
            echo wptouch_get_plugin_warning_count();
            break;
        case 'enable-menu-item':
            if (isset($wptouch_pro->post['is_checked']) && isset($wptouch_pro->post['page_id'])) {
                $page_id = $wptouch_pro->post['page_id'];
                // save the icon state
                if ($wptouch_pro->post['is_checked']) {
                    delete_post_meta($page_id, '_wptouch_pro_menu_item_disabled');
                } else {
                    update_post_meta($page_id, '_wptouch_pro_menu_item_disabled', '1');
                }
                echo '0';
            }
            break;
        case 'update-page-icon':
            if (isset($wptouch_pro->post['page_id']) && isset($wptouch_pro->post['image_file'])) {
                $page_id = $wptouch_pro->post['page_id'];
                $image_file = str_replace(wptouch_check_url_ssl(site_url()), '', $wptouch_pro->post['image_file']);
                // save the icon state
                update_post_meta($page_id, '_wptouch_pro_menu_item_icon', $image_file);
                echo '0';
            }
            break;
        case 'reset-page-icons-and-state':
            $wptouch_pro->reset_icon_states();
            echo '0';
            break;
        case 'set-default-icon':
            $settings = wptouch_get_settings();
            $settings->default_menu_icon = str_replace(wptouch_check_url_ssl(site_url()), '', $wptouch_pro->post['image_file']);
            $settings->save();
            echo '0';
            break;
        case 'reset-page-icon':
            if (isset($wptouch_pro->post['page_id'])) {
                delete_post_meta($wptouch_pro->post['page_id'], '_wptouch_pro_menu_item_icon');
                echo '0';
            }
            break;
        case 'delete-image-upload':
            if (isset($wptouch_pro->post['setting_name'])) {
                $wptouch_pro->update_encoded_setting($wptouch_pro->post['setting_name'], false);
                echo '0';
            }
            break;
        case 'delete-custom-icon':
            if (current_user_can('upload_files')) {
                if (isset($wptouch_pro->post['icon_name'])) {
                    $icon_location = WPTOUCH_CUSTOM_ICON_DIRECTORY . '/' . $wptouch_pro->post['icon_name'];
                    unlink($icon_location);
                    echo '0';
                }
            }
            break;
        case 'load-news':
            echo wptouch_capture_include_file(WPTOUCH_DIR . '/admin/html/news.php');
            break;
        case 'load-notifications':
        case 'load-notifications-plugin':
            wptouch_notification_setup();
            $result = array();
            $result['html'] = wptouch_capture_include_file(WPTOUCH_DIR . '/admin/html/notification-content.php');
            $result['count'] = wptouch_get_notification_count();
            echo json_encode($result);
            break;
        case 'dismiss-notification':
            wptouch_notification_setup();
            $settings = wptouch_get_settings();
            if (!in_array($wptouch_pro->post['notification_key'], $settings->dismissed_notifications)) {
                $settings->dismissed_notifications[] = $wptouch_pro->post['notification_key'];
                $settings->save();
            }
            $result = array();
            $result['html'] = wptouch_capture_include_file(WPTOUCH_DIR . '/admin/html/notification-content.php');
            $result['count'] = wptouch_get_notification_count();
            echo json_encode($result);
            break;
        case 'load-plugin-compat-list':
            $wptouch_pro->generate_plugin_hook_list(true);
            $compat_settings = wptouch_get_settings('compat');
            if (is_array($compat_settings->plugin_hooks) && count($compat_settings->plugin_hooks)) {
                $changed = false;
                foreach ($compat_settings->plugin_hooks as $name => $value) {
                    if (!isset($compat_settings->enabled_plugins[$name])) {
                        $compat_settings->enabled_plugins[$name] = 1;
                        $changed = true;
                    }
                }
                if ($changed) {
                    $compat_settings->save();
                }
            }
            echo wptouch_capture_include_file(WPTOUCH_DIR . '/admin/settings/html/plugin-compat-ajax.php');
            break;
        case 'prep-settings-download':
            require_once WPTOUCH_DIR . '/core/admin-backup-restore.php';
            $backup_file = wptouch_backup_settings();
            echo $backup_file;
            break;
        case 'load-touchboard-area':
            if (defined('WPTOUCH_IS_FREE')) {
                $content = wp_remote_get('http://wptouch-pro-3.s3.amazonaws.com/WPtouchBoard/free/page.xhtml');
            } else {
                $content = wp_remote_get('http://wptouch-pro-3.s3.amazonaws.com/WPtouchBoard/pro/3.4/page.xhtml');
            }
            if (!is_wp_error($content)) {
                echo $content['body'];
            }
            break;
        case 'load-upgrade-area':
            $content = wp_remote_get('http://wptouch-pro-3.s3.amazonaws.com/WPtouchBoard/upgrade/page.xhtml');
            if (!is_wp_error($content)) {
                echo $content['body'];
            }
            break;
        case 'download-icon-set':
            global $wptouch_pro;
            require_once WPTOUCH_DIR . '/core/icon-set-installer.php';
            $icon_set_installer = new WPtouchIconSetInstaller();
            $icon_set_installer->install($wptouch_pro->post['base'], $wptouch_pro->post['url']);
            if (file_exists(WPTOUCH_BASE_CONTENT_DIR . '/icons/' . $wptouch_pro->post['base'])) {
                echo '1';
            } else {
                echo '0';
            }
            break;
        case 'get-icon-set-info':
            require_once WPTOUCH_DIR . '/core/admin-icons.php';
            echo wptouch_capture_include_file(WPTOUCH_DIR . '/admin/settings/html/installed_icon_sets_ajax.php');
            break;
        case 'admin-change-log':
            if (!defined('WPTOUCH_IS_FREE')) {
                $change_log = wp_remote_get(WPTOUCH_PRO_README_FILE);
            } else {
                $change_log = wp_remote_get('http://plugins.svn.wordpress.org/wptouch/trunk/readme.txt');
            }
            if (!is_wp_error($change_log)) {
                $content = $change_log['body'];
                $result = preg_match_all("#= Version (.*) =(.*)\n=#iUs", $content, $matches);
                if ($result) {
                    $entries = count($matches[0]);
                    for ($i = 0; $i < $entries; $i++) {
                        echo '<h4 style="font-family: Helvetica, sans-serif">' . sprintf(__('Version %s', 'wptouch-pro'), $matches[1][$i]) . '</h4><ul  style="font-family: Helvetica, sans-serif; font-size: 13px">';
                        echo str_replace('* ', '<li style="padding-top:3px;padding-bottom:3px;">', str_replace("\n", "</li>\n", $matches[2][$i]));
                        echo '</ul>';
                    }
                }
            } else {
                echo __('There is a temporary issue retrieving the change-log.  Please try again later.', 'wptouch-pro');
            }
            break;
        case 'load-addon-browser':
            require_once WPTOUCH_DIR . '/admin/settings/html/extension-browser-ajax.php';
            break;
        case 'load-theme-browser':
            require_once WPTOUCH_DIR . '/admin/settings/html/theme-browser-ajax.php';
            break;
        case 'repair-active-theme':
            $result = wptouch_repair_active_theme_from_cloud($errors);
            if (wptouch_migration_is_theme_broken()) {
                echo '0';
            } else {
                echo '1';
            }
            break;
        default:
            do_action('wptouch_admin_ajax_' . $ajax_action);
            do_action('wptouch_admin_ajax_intercept', $ajax_action);
            break;
    }
}
예제 #4
0
 function admin_initialize()
 {
     $is_plugins_page = strpos($_SERVER['REQUEST_URI'], 'plugins.php') !== false;
     $is_wizard_page = strpos($_SERVER['REQUEST_URI'], '?page=wptouch-admin-wizard') !== false;
     // We need the BNCAPI for checking for plugin updates and all the wptouch-pro admin functions
     if ($this->admin_is_wptouch_page() || $is_plugins_page) {
         $this->setup_bncapi();
     }
     // Only check for updates explicitly on plugins page
     if ($is_plugins_page) {
         $can_check_for_update = true;
         if ($can_check_for_update) {
             WPTOUCH_DEBUG(WPTOUCH_INFO, 'Checking for product update');
             $this->check_for_update(true);
         }
     }
     // Remodal, load everywhere except wizard
     if (!$is_wizard_page) {
         wp_enqueue_script('wptouch-remodal', WPTOUCH_URL . '/admin/js/wptouch-admin-remodal.js', array('wptouch-pro-ajax'), md5(WPTOUCH_VERSION), true);
         wp_enqueue_style('wptouch-remodal', WPTOUCH_URL . '/admin/css/wptouch-admin-remodal.css', false, md5(WPTOUCH_VERSION));
     }
     // load the core AJAX on all pages
     $theme_broken = wptouch_migration_is_theme_broken() && !wptouch_can_repair_active_theme();
     if ($this->admin_is_wptouch_page() || $theme_broken) {
         $ajax_params = array('admin_ajax_nonce' => wp_create_nonce('wptouch_admin_ajax'));
         wp_enqueue_script('wptouch-pro-ajax', WPTOUCH_URL . '/admin/js/wptouch-ajax.js', array('jquery'), md5(WPTOUCH_VERSION), true);
         wp_localize_script('wptouch-pro-ajax', 'WPtouchAjax', $ajax_params);
         if ($theme_broken && !defined('WPTOUCH_IS_FREE')) {
             wp_enqueue_script('wptouch-cloud-migrate', WPTOUCH_URL . '/admin/js/wptouch-admin-migrate.js', array('wptouch-pro-ajax'), md5(WPTOUCH_VERSION));
         }
     }
     // Check for broken plugins
     wptouch_migration_check_for_broken_extensions();
     //  load the rest of the admin scripts when we're looking at the WPtouch Pro page
     if ($this->admin_is_wptouch_page()) {
         $localize_params = array('admin_url' => get_bloginfo('wpurl') . '/wp-admin', 'plugin_admin_image_url' => WPTOUCH_ADMIN_URL . '/images', 'admin_nonce' => wp_create_nonce('wptouch_admin'), 'plugin_url' => admin_url('admin.php?page=' . $_GET['page']), 'reset_settings' => wptouchize_it(__("This will reset all WPtouch Pro settings.\nAre you sure?", 'wptouch-pro')), 'reset_delete' => __("This will reset all WPtouch Pro settings and delete the wptouch-data folder.\nAre you sure?", 'wptouch-pro'), 'reset_delete_deactivate' => __("This will reset all WPtouch Pro settings, delete the wptouch-data folder, and deactivate the plugin. Are you sure?", 'wptouch-pro'), 'cloud_download_fail' => __('The item failed to download for this reason: %reason%', 'wptouch-pro'), 'remove_license' => __('You are about to reset your license information. Proceed?', 'wptouch-pro'), 'upload_complete' => __('Upload Complete!', 'wptouch-pro'), 'upload_invalid' => __('Upload Failed: Not a valid image.', 'wptouch-pro'), 'saving_settings' => __('WPtouch is saving settings. Please do not refresh the page while saving.', 'wptouch-pro'), 'install_themes' => __('Install Themes', 'wptouch-pro'), 'install_extensions' => __('Install Extensions', 'wptouch-pro'), 'install' => __('Install', 'wptouch-pro'), 'installing' => __('Installing', 'wptouch-pro'), 'installed' => __('Installed', 'wptouch-pro'), 'download' => __('Download', 'wptouch-pro'), 'is_network_admin' => is_network_admin());
         // 4.0 Adding some easing :)
         wp_enqueue_script('jquery-easing', '//cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js', array('jquery'), md5(WPTOUCH_VERSION), false);
         if (strpos($_SERVER['REQUEST_URI'], 'wptouch-admin-wizard') == true) {
             // 4.0 Wizard Script
             wp_enqueue_script('wptouch-wizard', WPTOUCH_URL . '/admin/js/wptouch-admin-wizard.js', array('jquery', 'wptouch-admin-plugins'), md5(WPTOUCH_VERSION), false);
         }
         wp_enqueue_script('wptouch-admin-plugins', WPTOUCH_URL . '/admin/js/wptouch-admin-plugins.js', array('jquery'), md5(WPTOUCH_VERSION), false);
         wp_localize_script('wptouch-admin-plugins', 'WPtouchCustom', $localize_params);
         if (strpos($_SERVER['REQUEST_URI'], 'wptouch-admin-wizard') == false) {
             wp_enqueue_script('wptouch-pro-admin', WPTOUCH_URL . '/admin/js/wptouch-admin-4.js', array('wptouch-admin-plugins', 'wptouch-pro-ajax', 'jquery', 'jquery-easing'), md5(WPTOUCH_VERSION), false);
             if (defined('WPTOUCH_IS_FREE')) {
                 wp_enqueue_style('wp-color-picker');
                 wp_enqueue_script('wptouch-pro-admin-color', WPTOUCH_URL . '/admin/js/wptouch-admin-color.js', array('wptouch-pro-admin', 'wp-color-picker'), md5(WPTOUCH_VERSION), false);
             }
         }
     } else {
         // Not a WPtouch admin page
         $localize_params = array('admin_url' => get_bloginfo('wpurl') . '/wp-admin', 'admin_nonce' => wp_create_nonce('wptouch_admin'));
         wp_enqueue_script('wptouch-pro-ajax', WPTOUCH_URL . '/admin/js/wptouch-ajax.js', array('jquery'), md5(WPTOUCH_VERSION), false);
         $ajax_params = array('admin_ajax_nonce' => wp_create_nonce('wptouch_admin_ajax'));
         wp_localize_script('wptouch-pro-ajax', 'WPtouchAjax', $ajax_params);
     }
     $this->setup_wptouch_admin_ajax();
 }