コード例 #1
0
ファイル: globals.php プロジェクト: sumwander/unyil
function wptouch_get_bloginfo($setting_name)
{
    global $wptouch_pro;
    $settings = $wptouch_pro->get_settings();
    $setting = false;
    switch ($setting_name) {
        case 'foundation_directory':
            $setting = WPTOUCH_DIR . '/themes/foundation';
            break;
        case 'foundation_url':
            $setting = WPTOUCH_URL . '/themes/foundation';
            break;
        case 'template_directory':
        case 'template_url':
            $setting = $wptouch_pro->get_template_directory_uri(false);
            break;
        case 'child_theme_directory_uri':
            $setting = $wptouch_pro->get_stylesheet_directory_uri(false);
            break;
        case 'theme_root_directory':
            $setting = $wptouch_pro->get_current_theme_directory();
            break;
        case 'theme_root_url':
            $setting = $wptouch_pro->get_current_theme_uri();
            break;
        case 'site_title':
            if ($settings->site_title != '') {
                $setting = $settings->site_title;
            } else {
                $setting = get_bloginfo('name');
            }
            break;
        case 'wptouch_directory':
            $setting = WPTOUCH_DIR;
            break;
        case 'wptouch_url':
            $setting = WPTOUCH_URL;
            break;
        case 'version':
            $setting = WPTOUCH_VERSION;
            break;
        case 'theme_count':
            $themes = $wptouch_pro->get_available_themes();
            $setting = count($themes);
            break;
        case 'icon_set_count':
            $icon_sets = $wptouch_pro->get_available_icon_packs();
            // Remove the custom icon count
            $setting = count($icon_sets) - 1;
            break;
        case 'icon_count':
            $icon_sets = $wptouch_pro->get_available_icon_packs();
            $total_icons = 0;
            foreach ($icon_sets as $setname => $set) {
                if ($setname == "Custom Icons") {
                    continue;
                }
                $icons = $wptouch_pro->get_icons_from_packs($setname);
                $total_icons += count($icons);
            }
            $setting = $total_icons;
            break;
        case 'support_licenses_remaining':
            $licenses = $wptouch_pro->bnc_api->user_list_licenses();
            if ($licenses) {
                $setting = $licenses['remaining'];
            } else {
                $setting = 0;
            }
            break;
        case 'support_licenses_total':
            $licenses = $wptouch_pro->bnc_api->get_total_licenses();
            if ($licenses) {
                $setting = $licenses;
            } else {
                $setting = 0;
            }
            break;
        case 'active_theme_friendly_name':
            $theme_info = $wptouch_pro->get_current_theme_info();
            if ($theme_info) {
                $setting = $theme_info->name;
            }
            break;
        case 'rss_url':
            if ($settings->menu_custom_rss_url) {
                $setting = $settings->menu_custom_rss_url;
            } else {
                $setting = get_bloginfo('rss2_url');
            }
            break;
        case 'warnings':
            $setting = wptouch_get_plugin_warning_count();
            break;
        case 'url':
            if ($settings->homepage_landing != 'none') {
                if ($settings->homepage_landing == 'custom') {
                    $setting = $settings->homepage_redirect_custom_target;
                } else {
                    $redirect_target = $settings->homepage_redirect_wp_target;
                    if (function_exists('icl_object_id')) {
                        $redirect_target = icl_object_id($redirect_target, 'page', true);
                    }
                    $setting = get_permalink($redirect_target);
                }
            } else {
                $setting = home_url();
            }
            break;
        case 'search_url':
            if (function_exists('home_url')) {
                $setting = home_url();
            } else {
                $setting = get_bloginfo('home');
            }
            break;
        default:
            // proxy other values to the original get_bloginfo function
            $setting = get_bloginfo($setting_name);
            break;
    }
    return $setting;
}
コード例 #2
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;
    }
}
コード例 #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 '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;
    }
}
コード例 #4
0
 function admin_ajax_handler()
 {
     if (current_user_can('manage_options')) {
         // Check security nonce
         $wptouch_nonce = $this->post['wptouch_nonce'];
         if (!wp_verify_nonce($wptouch_nonce, 'wptouch_admin')) {
             WPTOUCH_DEBUG(WPTOUCH_SECURITY, 'Invalid security nonce for AJAX call');
             exit;
         }
         $this->setup_bncapi();
         header('HTTP/1.1 200 OK');
         $wptouch_ajax_action = $this->post['wptouch_action'];
         switch ($wptouch_ajax_action) {
             case 'support-posting':
                 if (WPTOUCH_PRO_BETA) {
                     $result = $this->bnc_api->post_support_topic($this->post['title'], $this->post['tags'], $this->post['desc'], true);
                 } else {
                     $result = $this->bnc_api->post_support_topic($this->post['title'], $this->post['tags'], $this->post['desc']);
                 }
                 if ($result) {
                     echo 'ok';
                 }
                 break;
             case 'profile':
                 include WPTOUCH_ADMIN_AJAX_DIR . '/profile.php';
                 break;
             case 'regenerate-plugin-list':
                 $this->generate_plugin_hook_list(true);
                 echo 'ok';
                 break;
             case 'activate-license':
                 $this->activate_license();
                 include WPTOUCH_ADMIN_AJAX_DIR . '/profile.php';
                 break;
             case 'remove-license':
                 $this->remove_license();
                 include WPTOUCH_ADMIN_AJAX_DIR . '/profile.php';
                 break;
             case 'update-icon-pack':
                 require_once WPTOUCH_ADMIN_DIR . '/template-tags/icons.php';
                 include WPTOUCH_ADMIN_AJAX_DIR . '/icon-area.php';
                 break;
             case 'set-menu-icon':
                 $settings = $this->get_settings();
                 // Clean up SSL links
                 if (strpos($this->post['icon'], WP_CONTENT_URL) !== false) {
                     $icon_location = bnc_wptouch_sslize(str_replace(WP_CONTENT_URL, '', $this->post['icon']));
                 } else {
                     $icon_location = bnc_wptouch_sslize(str_replace(WP_CONTENT_URL, '', $this->post['icon']));
                     //		$icon_location = bnc_wptouch_sslize( str_replace( str_replace( 'http://', 'https://', WP_CONTENT_URL ), '', $this->post['icon'] ) );
                 }
                 $settings->temp_menu_icons[$this->post['title']] = $icon_location;
                 $this->save_settings($settings);
                 break;
             case 'reset-menu-icons':
                 require_once WPTOUCH_ADMIN_DIR . '/template-tags/icons.php';
                 $settings = $this->get_settings();
                 $settings->temp_menu_icons = $settings->menu_icons = array();
                 $settings->temp_disabled_menu_items = $settings->disabled_menu_items = array();
                 $this->save_settings($settings);
                 require_once WPTOUCH_DIR . '/include/template-tags/menu.php';
                 echo wptouch_get_site_menu_icon(WPTOUCH_ICON_DEAULT);
                 break;
             case 'enable-menu-item':
                 $settings = $this->get_settings();
                 $title = (int) $this->post['title'];
                 if (isset($settings->temp_disabled_menu_items[$title])) {
                     unset($settings->temp_disabled_menu_items[$title]);
                     $this->save_settings($settings);
                 }
                 break;
             case 'disable-menu-item':
                 $items_to_disable = $this->parent_and_children_menu_ids($this->post['title']);
                 if (count($items_to_disable)) {
                     $settings = $this->get_settings();
                     foreach ($items_to_disable as $key => $item) {
                         $settings->temp_disabled_menu_items[$item] = 1;
                     }
                     $this->save_settings($settings);
                 }
                 break;
             case 'remove-menu-icon':
                 require_once WPTOUCH_ADMIN_DIR . '/template-tags/icons.php';
                 $settings = $this->get_settings();
                 if (isset($settings->temp_menu_icons[$this->post['title']])) {
                     unset($settings->temp_menu_icons[$this->post['title']]);
                     $this->save_settings($settings);
                 }
                 require_once WPTOUCH_DIR . '/include/template-tags/menu.php';
                 echo wptouch_get_site_menu_icon(WPTOUCH_ICON_DEFAULT);
                 break;
             case 'manage-upload':
                 switch ($_FILES['userfile']['type']) {
                     case 'image/png':
                     case 'image/x-png':
                         move_uploaded_file($_FILES['userfile']['tmp_name'], WPTOUCH_CUSTOM_ICON_DIRECTORY . '/' . str_replace(' ', '-', $_FILES['userfile']['name']));
                         echo 'icon-done';
                         break;
                     case 'application/x-zip-compressed':
                     case 'application/zip':
                         move_uploaded_file($_FILES['userfile']['tmp_name'], WPTOUCH_TEMP_DIRECTORY . '/' . $_FILES['userfile']['name']);
                         $settings = $this->get_settings();
                         $settings->temp_icon_file_to_unzip = WPTOUCH_TEMP_DIRECTORY . '/' . $_FILES['userfile']['name'];
                         $this->save_settings($settings);
                         echo 'zip';
                         break;
                     default:
                         WPTOUCH_DEBUG(WPTOUCH_WARNING, 'Unknown file mime type ' . $_FILES['userfile']['type']);
                         echo 'invalid';
                         break;
                 }
                 break;
             case 'manage-unzip-set':
                 $settings = $this->get_settings();
                 $directory_name = basename(strtolower($settings->temp_icon_file_to_unzip), '.zip') . '-' . time();
                 @$this->create_directory_if_not_exist(WPTOUCH_CUSTOM_SET_DIRECTORY . '/' . $directory_name);
                 $destination_file = WPTOUCH_CUSTOM_SET_DIRECTORY . '/' . $directory_name . '/' . basename(strtolower($settings->temp_icon_file_to_unzip));
                 @rename($settings->temp_icon_file_to_unzip, $destination_file);
                 ob_start();
                 system('unzip -d "' . WPTOUCH_CUSTOM_SET_DIRECTORY . '/' . $directory_name . '" "' . $destination_file . '"');
                 ob_end_clean();
                 @unlink($destination_file);
                 @unlink($settings->temp_icon_file_to_unzip);
                 if (file_exists(WPTOUCH_CUSTOM_SET_DIRECTORY . '/' . $directory_name . '/wptouch.info')) {
                     echo 'done';
                 } else {
                     $settings->temp_icon_set_for_readme = WPTOUCH_CUSTOM_SET_DIRECTORY . '/' . $directory_name . '/wptouch.info';
                     $this->save_settings($settings);
                     echo 'create-readme';
                 }
                 break;
             case 'delete-icon-pack':
                 $pack = $this->get_icon_pack($this->post['set']);
                 if ($pack) {
                     $this->remove_directory($pack->location);
                 }
                 break;
             case 'delete-icon':
                 $icon_to_delete = bnc_wptouch_sslize(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $this->post['icon']));
                 @unlink($icon_to_delete);
                 break;
             case 'activate-theme':
                 $settings = wptouch_get_settings();
                 $theme_location = $this->post['location'];
                 $theme_name = $this->post['name'];
                 if ($settings->current_theme_location != $theme_location) {
                     $paths = explode('/', ltrim(rtrim($theme_location, '/'), '/'));
                     $settings->current_theme_name = $paths[count($paths) - 1];
                     unset($paths[count($paths) - 1]);
                     $settings->current_theme_location = '/' . implode('/', $paths);
                     $settings->current_theme_friendly_name = $theme_name;
                     remove_all_filters('wptouch_theme_menu');
                     remove_all_filters('wptouch_default_settings');
                     $this->save_settings($settings);
                 }
                 break;
             case 'copy-theme':
                 $copy_src = WP_CONTENT_DIR . $this->post['location'];
                 $theme_name = $this->convert_to_class_name($this->post['name']);
                 $num = $this->get_theme_copy_num($theme_name);
                 $copy_dest = WPTOUCH_CUSTOM_THEME_DIRECTORY . '/' . $theme_name . '-copy-' . $num;
                 @$this->create_directory_if_not_exist($copy_dest);
                 $this->recursive_copy($copy_src, $copy_dest);
                 $readme_file = $copy_dest . '/readme.txt';
                 $readme_info = $this->load_file($readme_file);
                 if ($readme_info) {
                     if (preg_match('#Theme Name: (.*)#', $readme_info, $matches)) {
                         $readme_info = str_replace($matches[0], 'Theme Name: ' . $matches[1] . ' Copy #' . $num, $readme_info);
                         $f = fopen($readme_file, "w+t");
                         if ($f) {
                             fwrite($f, $readme_info);
                             fclose($f);
                         }
                     }
                 } else {
                     WPTOUCH_DEBUG(WPTOUCH_ERROR, "Unable to modify readme.txt file after copy");
                 }
                 break;
             case 'make-child-theme':
                 $copy_src = WP_CONTENT_DIR . $this->post['location'];
                 $theme_name = $this->convert_to_class_name($this->post['name']);
                 $num = $this->get_theme_copy_num($theme_name);
                 $copy_dest = WPTOUCH_CUSTOM_THEME_DIRECTORY . '/' . $theme_name . '-child-' . $num;
                 @$this->create_directory_if_not_exist($copy_dest);
                 $this->copy_file($copy_src . '/readme.txt', $copy_dest . '/readme.txt');
                 $this->copy_file($copy_src . '/screenshot.png', $copy_dest . '/screenshot.png');
                 $readme_file = $copy_dest . '/readme.txt';
                 if (file_exists($readme_file)) {
                     $readme_info = $this->load_file($readme_file);
                     if ($readme_info) {
                         if (preg_match('#Theme Name: (.*)#', $readme_info, $matches)) {
                             $readme_info = str_replace($matches[0], 'Theme Name: ' . $matches[1] . ' Child #' . $num, $readme_info);
                             $readme_info = $readme_info . "\nParent: " . $this->post['name'];
                             $f = fopen($readme_file, "w+t");
                             if ($f) {
                                 fwrite($f, $readme_info);
                                 fclose($f);
                             }
                             @$this->copy_file(WPTOUCH_CHILD_THEME_TEMPLATE_DIRECTORY . '/root-functions.php', $copy_dest . '/root-functions.php');
                         }
                         $all_files = $this->get_files_in_directory($copy_src, false);
                         if ($all_files) {
                             foreach ($all_files as $file_name) {
                                 if (is_dir($file_name)) {
                                     @$this->create_directory_if_not_exist($copy_dest . '/' . basename($file_name));
                                     @$this->copy_file(WPTOUCH_CHILD_THEME_TEMPLATE_DIRECTORY . '/style.css', $copy_dest . '/' . basename($file_name) . '/style.css');
                                     @$this->copy_file(WPTOUCH_CHILD_THEME_TEMPLATE_DIRECTORY . '/functions.php', $copy_dest . '/' . basename($file_name) . '/functions.php');
                                 }
                             }
                         }
                     } else {
                         WPTOUCH_DEBUG(WPTOUCH_ERROR, "Unable to modify readme.txt file after copy");
                     }
                 }
                 break;
             case 'delete-theme':
                 $delete_src = WP_CONTENT_DIR . $this->post['location'];
                 $this->recursive_delete($delete_src);
                 @rmdir($delete_src);
                 break;
             case 'dismiss-warning':
                 $settings = $this->get_settings();
                 if ($this->post['plugin']) {
                     if (!in_array($this->post['plugin'], $settings->dismissed_warnings)) {
                         $settings->dismissed_warnings[] = $this->post['plugin'];
                         $this->save_settings($settings);
                     }
                 }
                 echo wptouch_get_plugin_warning_count();
                 break;
             case 'reset-all-licenses':
                 if ($this->bnc_api->reset_all_licenses('wptouch-pro')) {
                     echo 'ok';
                 } else {
                     echo 'fail';
                 }
                 break;
             default:
                 //echo WPTOUCH_ADMIN_AJAX_DIR . '/' . basename( $wptouch_ajax_action ) . '.php';
                 if (file_exists(WPTOUCH_ADMIN_AJAX_DIR . '/' . basename($wptouch_ajax_action) . '.php')) {
                     include WPTOUCH_ADMIN_AJAX_DIR . '/' . basename($wptouch_ajax_action) . '.php';
                 }
                 break;
         }
     } else {
         WPTOUCH_DEBUG(WPTOUCH_SECURITY, 'Insufficient security privileges for AJAX call');
     }
     die;
 }