function on_save_backup() { if (!current_user_can('manage_options')) { wp_die(__('Cheatin’ uh?', XF_TEXTDOMAIN)); } check_admin_referer('xtreme_backend_settings'); $redirect = $_POST['_wp_http_referer']; if (isset($_POST['xtreme_export'])) { require_once XF_ADMIN_DIR . '/includes/xtreme-xmlprocessor.php'; $xml = new xtreme_xml_processor(); $xml->backup_as_xml(XF_VERSION, get_option(XF_OPTIONS), get_option(XF_LAYOUTS), get_option(XF_TEMPLATES), get_option(XF_WIDGET_PERMISSIONS), is_multisite() ? get_blog_option(XF_SITE_ID, XF_WIDGET_BURNING_REG, array()) : get_option(XF_WIDGET_BURNING_REG, array()), get_option('sidebars_widgets'), $this->_collect_widgets()); } //should we import an existing file ? if (isset($_POST['xtreme_import'])) { if (!current_user_can('upload_files')) { wp_die(__('Cheatin’ uh?', XF_TEXTDOMAIN)); } if (isset($_FILES) == true && empty($_FILES) == false) { if (!$_FILES['xml_file']['error'] && $_FILES['xml_file']['size'] > 0) { require_once XF_ADMIN_DIR . '/includes/xtreme-xmlprocessor.php'; $xml = new xtreme_xml_processor(); $saved_options = $xml->restore_from_xml(XF_VERSION, $_FILES['xml_file']['tmp_name']); @unlink($_FILES['xml_file']['tmp_name']); if (!is_array($saved_options)) { wp_redirect(admin_url('admin.php?page=xtreme_backup&error=' . $saved_options)); exit; } update_option(XF_OPTIONS, $saved_options[XF_OPTIONS]); update_option(XF_LAYOUTS, $saved_options[XF_LAYOUTS]); update_option(XF_TEMPLATES, $saved_options[XF_TEMPLATES]); update_option(XF_WIDGET_PERMISSIONS, $saved_options[XF_WIDGET_PERMISSIONS]); if (is_multisite() && XF_IS_MAIN_BLOG) { update_blog_option(XF_SITE_ID, XF_WIDGET_BURNING_REG, $saved_options[XF_WIDGET_BURNING_REG]); } if (isset($_POST['permit_widget_import']) && $_POST['permit_widget_import'] == 1) { update_option('sidebars_widgets', $saved_options['sidebars-widgets']); $widgets = $saved_options['widgets']; foreach ($widgets as $key => $value) { update_option($key, $value); } $redirect .= '&message=1'; } else { $redirect .= '&message=2'; } if (isset($saved_options[XF_VERSION_FIELD])) { //we import an old (lower) version backup and have to patch it upto current version update_option(XF_VERSION_FIELD, $saved_options[XF_VERSION_FIELD]); xtreme_validate_framework(); } require_once XF_ADMIN_DIR . '/xtreme-basemod-css.php'; require_once XF_ADMIN_DIR . '/xtreme-patch-css.php'; require_once XF_ADMIN_DIR . '/xtreme-production-css.php'; $basemod = new Xtreme_Basemod_CSS(); $basemod->write(); $patch = new Xtreme_Patch_CSS(); $patch->write(); $production = new Xtreme_Production_CSS(); $production->write(); } else { $redirect .= '&error=4'; } } else { $redirect .= '&error=4'; } } wp_redirect($redirect); }
function xtreme_validate_framework() { //check if we activated or previewed the first time and attached the missing options $needed_options = array(XF_OPTIONS, XF_LAYOUTS, XF_TEMPLATES, XF_WIDGET_PERMISSIONS); $install_options = array(); foreach ($needed_options as $option) { if (get_option($option) === false) { $install_options[] = $option; } } if (count($install_options) > 0 || version_compare(get_option(XF_VERSION_FIELD), XF_VERSION, '<')) { $file_xml = XF_ADMIN_DIR . '/install/xtreme-one-install-config.xml'; $defaults = false; if (file_exists($file_xml)) { $processor = new xtreme_xml_processor(); $xml = file_get_contents($file_xml); $xml = str_replace('[install]', XF_ACTIVE_STYLESHEET, $xml); $defaults = $processor->_convert_to_array(XF_VERSION, $xml); } if ($defaults !== false && is_array($defaults)) { //perform install first foreach ($install_options as $option) { if (isset($defaults[$option])) { update_option($option, $defaults[$option]); } } //perform upgrade secondly if (version_compare(get_option(XF_VERSION_FIELD), XF_VERSION, '<')) { foreach ($needed_options as $option) { if (!in_array($option, $install_options)) { $o = get_option($option); $n = $defaults[$option]; if (is_array($n) || is_array($o)) { if (!is_array($n)) { $n = xtreme_merge_options(array(), $o); } elseif (!is_array($o)) { if (!empty($o)) { $n = xtreme_merge_options($n, (array) $o); } } else { $n = xtreme_merge_options($n, $o); } } else { $n = $o; } update_option($option, $n); } } update_option(XF_VERSION_FIELD, XF_VERSION); if (is_admin()) { global $xtreme_backend; $xtreme_backend->generate_theme(); } } } else { $errors = get_option(XF_UPDATE_ERRORS, array()); $error = __('There was an error during install/upgrade of <b>Xtreme One</b> Theme Framework. The default value definition file is missing or damaged.', XF_TEXTDOMAIN); if (!in_array($error, $errors)) { $errors[] = $error; } update_option(XF_UPDATE_ERRORS, $errors); } } }