function wptouch_repair_active_theme_from_cloud(&$error_condition)
{
    global $wptouch_pro;
    $result = true;
    $error_condition = false;
    $settings = wptouch_get_settings();
    $wptouch_pro->setup_bncapi();
    // We need to download the theme and then repair it
    $themes = $wptouch_pro->get_available_themes(true);
    if (isset($themes[$settings->current_theme_friendly_name])) {
        require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
        $theme_to_install = $themes[$settings->current_theme_friendly_name];
        $addon_installer = new WPtouchAddonThemeInstaller();
        $result = $addon_installer->install($theme_to_install->base, $theme_to_install->download_url, 'themes');
        if ($result) {
            $wptouch_pro->repair_active_theme(WPTOUCH_BASE_CONTENT_DIR . '/themes', $settings->current_theme_friendly_name);
        }
    }
    return $result;
}
Exemplo n.º 2
0
function wptouch_auto_update_themes_addons()
{
    global $wptouch_pro;
    if (!isset($wptouch_pro->post)) {
        require_once WPTOUCH_DIR . '/core/theme-hashes.php';
        $theme_hashes = wptouch_get_hashes();
        if (current_user_can('manage_options')) {
            $current_theme = $wptouch_pro->get_current_theme_info();
            $available_themes = $wptouch_pro->get_available_themes(true);
            $available_addons = $wptouch_pro->get_available_addons(true);
            $updates = 0;
            $backed_up = false;
            $errors = array();
            if (count($available_themes) > 0 || count($available_addons) > 0) {
                require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
                foreach ($available_themes as $name => $theme) {
                    $hash = false;
                    $safe_to_install_theme = false;
                    $skip_upgrade = false;
                    if (isset($theme->upgrade_available) && $theme->upgrade_available) {
                        if (!is_object($current_theme) || $name != $current_theme->name) {
                            $safe_to_install_theme = true;
                        } else {
                            if ($name == $current_theme->name && $theme->cloud_version < $theme->version) {
                                $skip_upgrade = true;
                            } else {
                                $hash = md5_dir(WP_CONTENT_DIR . $current_theme->location);
                                if (in_array($theme->version, $theme_hashes[$theme->base]) && $hash == $theme_hashes[$theme->base][$theme->version]) {
                                    // OK to upgrade the active theme (it's the same as when it shipped)
                                    $safe_to_install_theme = true;
                                }
                            }
                        }
                        // Hashes didn't match.
                        if ($safe_to_install_theme === false && $skip_upgrade === false) {
                            $copied_theme = wptouch_pro_copy_theme($theme->name, $theme->location);
                            if (is_array($copied_theme)) {
                                wptouch_pro_activate_theme($copied_theme['name'], $copied_theme['location']);
                                $backed_up = $theme->name;
                            }
                        }
                        if ($skip_upgrade === false) {
                            $installer = new WPtouchAddonThemeInstaller();
                            $installer->install($theme->base, $theme->download_url, 'themes');
                            if ($installer->had_error()) {
                                $errors[] = $installer->error_text();
                            } else {
                                $updates++;
                            }
                        }
                    }
                }
                foreach ($available_addons as $name => $addon) {
                    if (isset($addon->upgrade_available) && $addon->upgrade_available && isset($addon->download_url)) {
                        $installer = new WPtouchAddonThemeInstaller();
                        $installer->install($addon->base, $addon->download_url, 'extensions');
                        if ($installer->had_error()) {
                            $errors[] = $installer->error_text();
                        } else {
                            $updates++;
                        }
                    }
                }
                if ($backed_up) {
                    $backed_up = sprintf(__('%sYour customizations to %s have been saved as a new theme and the original reinstalled for your reference.', 'wptouch-pro'), '</p><p>', $backed_up);
                }
                if ($updates && count($errors) > 0) {
                    echo '<div id="message" class="error"><p>' . __('WPtouch Pro: Some themes or extensions could not be auto-updated. Please check the WPtouch Pro Themes &amp; Extensions page to manually update them.', 'wptouch-pro') . $backed_up . '</p></div>';
                } elseif ($updates) {
                    echo '<div id="message" class="updated"><p>' . __('WPtouch Pro: Your themes and extensions have been automatically updated. Thank you for updating WPtouch Pro!', 'wptouch-pro') . $backed_up . '</p></div>';
                }
            }
        }
    }
}
function wptouch_update_all_addons()
{
    global $wptouch_pro;
    if (current_user_can('manage_options')) {
        $available_addons = $wptouch_pro->get_available_addons(true);
        $updates = 0;
        $errors = array();
        if (count($available_addons) > 0) {
            require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
            foreach ($available_addons as $name => $addon) {
                if (isset($addon->extension_upgrade_available) && $addon->extension_upgrade_available && isset($addon->download_url)) {
                    $installer = new WPtouchAddonThemeInstaller();
                    $installer->install($addon->base, $addon->download_url, 'extensions');
                    if ($installer->had_error()) {
                        $errors[] = $installer->error_text();
                    } else {
                        $updates++;
                    }
                }
            }
            if ($updates && count($errors) > 0) {
                echo json_encode(array('status' => '0', 'error' => __('Some extensions could not be updated.', 'wptouch-pro')));
            } elseif ($updates) {
                echo json_encode(array('status' => '1'));
            }
        } else {
            echo json_encode(array('status' => '1'));
        }
    }
}
function wptouch_pro_admin_ajax_intercept($ajax_action)
{
    global $wptouch_pro;
    switch ($ajax_action) {
        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();
            // 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 'reset-license-info':
            $bnc_settings = wptouch_get_settings('bncid');
            $bnc_settings->bncid = '';
            $bnc_settings->wptouch_license_key = '';
            $bnc_settings->license_accepted = false;
            $bnc_settings->license_accepted_time = 0;
            $bnc_settings->next_update_check_time = 0;
            $bnc_settings->license_expired = false;
            $bnc_settings->license_expiry_date = 0;
            $bnc_settings->save();
            break;
        case 'download-addon':
            global $wptouch_pro;
            require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
            $addon_installer = new WPtouchAddonThemeInstaller();
            $addon_installer->install($wptouch_pro->post['base'], $wptouch_pro->post['url'], 'extensions');
            $result = array();
            if (file_exists(WPTOUCH_BASE_CONTENT_DIR . '/extensions/' . $wptouch_pro->post['base'])) {
                $result['status'] = 1;
            } else {
                $result['status'] = 0;
                if ($addon_installer->had_error()) {
                    $result['error'] = $addon_installer->error_text();
                } else {
                    $result['error'] = __('Unknown error', 'wptouch-pro');
                }
            }
            echo json_encode($result);
            break;
        case 'download-theme':
            global $wptouch_pro;
            require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
            $addon_installer = new WPtouchAddonThemeInstaller();
            $addon_installer->install($wptouch_pro->post['base'], $wptouch_pro->post['url'], 'themes');
            $result = array();
            if (file_exists(WPTOUCH_BASE_CONTENT_DIR . '/themes/' . $wptouch_pro->post['base'])) {
                $result['status'] = 1;
            } else {
                $result['status'] = 0;
                if ($addon_installer->had_error()) {
                    $result['error'] = $addon_installer->error_text();
                } else {
                    $result['error'] = __('Unknown error', 'wptouch-pro');
                }
            }
            echo json_encode($result);
            break;
    }
}