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;
}
 function can_perform_cloud_install($theme = true)
 {
     require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
     $installer = new WPtouchAddonThemeInstaller();
     if ($theme) {
         return $installer->can_perform_install('themes');
     } else {
         return $installer->can_perform_install('extensions');
     }
 }
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'));
        }
    }
}
Beispiel #4
0
 function setup_languages()
 {
     $current_locale = get_locale();
     // Check for language override
     $settings = wptouch_get_settings();
     if (is_network_admin()) {
         $locale_setting = 'force_network_locale';
     } else {
         $locale_setting = 'force_locale';
     }
     $destination_directory = wptouch_get_multsite_aware_install_path('lang');
     // Auto download code for language files
     if ($current_locale != 'en_US' || $settings->{$locale_setting} != 'auto' && $settings->{$locale_setting} != 'en_US') {
         if ($settings->{$locale_setting} != 'auto') {
             $current_locale = $settings->{$locale_setting};
         }
         $this->setup_bncapi();
         $bnc_api = $this->get_bnc_api();
         $list = false;
         if (false === ($list = get_site_transient('_wptouch_language_info'))) {
             $list = $bnc_api->translations_get_list();
             set_site_transient('_wptouch_language_info', $list, 3600 * 24);
         }
         $language_file = 'wptouch-pro-' . $current_locale . '.mo';
         if (isset($list[$language_file])) {
             $should_install = false;
             if (!file_exists($destination_directory . '/' . $language_file)) {
                 $should_install = true;
             } else {
                 $language_file_size = filesize($destination_directory . '/' . $language_file);
                 if ($language_file_size != $list[$language_file]['size']) {
                     $should_install = true;
                 }
             }
             if ($should_install) {
                 require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
                 $installer = new WPtouchAddonThemeInstaller();
                 $language_to_install = $list[$language_file];
                 $installer->install_anywhere($language_file, $language_to_install['file'], $destination_directory);
             }
         }
     }
     if (!empty($current_locale)) {
         $current_locale = apply_filters('wptouch_language', $current_locale);
         $use_lang_file = false;
         $custom_lang_file = $destination_directory . '/wptouch-pro-' . $current_locale . '.mo';
         if (file_exists($custom_lang_file) && is_readable($custom_lang_file)) {
             $use_lang_file = $custom_lang_file;
             $rel_path = str_replace(WP_CONTENT_DIR, '..', $destination_directory);
             $use_lang_rel_path = $rel_path;
         } else {
             $lang_file = WPTOUCH_DIR . '/lang/wptouch-pro-' . $current_locale . '.mo';
             if (file_exists($lang_file) && is_readable($lang_file)) {
                 $use_lang_file = $lang_file;
                 if (defined('WPTOUCH_IS_FREE')) {
                     $use_lang_rel_path = 'wptouch/lang';
                 } else {
                     $use_lang_rel_path = 'wptouch-pro/lang';
                 }
             }
         }
         add_filter('plugin_locale', array(&$this, 'get_wordpress_locale'), 10, 2);
         $this->locale = $current_locale;
         if ($use_lang_file) {
             $can_load = true;
             if (is_admin() && !$settings->translate_admin) {
                 $can_load = false;
             }
             if ($can_load) {
                 load_plugin_textdomain('wptouch-pro', false, $use_lang_rel_path);
                 WPTOUCH_DEBUG(WPTOUCH_INFO, 'Loading language file ' . $use_lang_file);
             }
         }
         do_action('wptouch_language_loaded', $this->locale);
     }
 }
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_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;
    }
}