Example #1
0
 function import()
 {
     global $wpdb, $XT_Theme, $wp_filesystem;
     ob_start();
     require_once XT_PARENT_DIR . '/lib/classes/autoimporter.class.php';
     if (empty($wp_filesystem)) {
         require_once ABSPATH . '/wp-admin/includes/file.php';
         WP_Filesystem();
     }
     $upload_dir = XT_Theme::get_upload_dir();
     $importPath = $upload_dir["dir"] . '/import/';
     if (!$wp_filesystem->is_dir($importPath)) {
         wp_mkdir_p($importPath);
     }
     $placeholders = true;
     if (strpos($_SERVER['HTTP_HOST'], 'xplodedthemes') !== false || strpos($_SERVER['HTTP_HOST'], XT_THEME_ID . '.dev') !== false) {
         $placeholders = false;
     }
     $placeholders = true;
     $file = $importPath . 'default-data.xml';
     $theme = !empty($_POST["theme"]) && $_POST["theme"] != 'default' ? '-' . sanitize_text_field($_POST["theme"]) : '';
     $redux = !empty($_POST["redux"]) ? esc_url_raw($_POST["redux"]) : '';
     $revslider = !empty($_POST["revslider"]) ? esc_url_raw($_POST["revslider"]) : '';
     $widgets = !empty($_POST["widgets"]) ? esc_url_raw($_POST["widgets"]) : '';
     $theme_child = !empty($_POST["theme"]) && $_POST["theme"] != 'default' ? sanitize_text_field($_POST["theme"]) . "\\/" : '';
     $xml_import_url = XT_IMPORT_URL . '/default-data' . $theme . '.xml';
     $file_content = xt_get_url_contents($xml_import_url);
     if (!empty($file_content) && $placeholders) {
         $file_content = preg_replace("/http:\\/\\/" . XT_THEME_ID . ".xplodedthemes\\.com\\/" . $theme_child . "wp-content\\/uploads\\/(.*?).(jpg|jpeg|png|gif)\\</", "http://placehold.it/400x400/f3f3f3/f3f3f3/placeholder.jpg<", $file_content);
     }
     if (empty($file_content)) {
         $message = 'Something went wrong! The theme was not able to fetch the default data xml from our server.<br><br>';
         $message .= 'Please make sure your server support either <b>allow_url_open</b> or <b>cURL</b><br><br>';
         $message .= 'You can also manually download the xml file and import it using WordPress Importer: <br><br><a target="_blank" href="' . $xml_import_url . '>Download XML Import File</a><br><br>';
         $message .= '<b>Note:</b> Manually importing the xml will only include page and post contents excluding revolution sliders, widgets and theme panel settings.';
         $data['error'] = true;
         $data['msg'] = '<p style="color: red;">' . $message . '</p>';
         die(json_encode($data));
     }
     if (!empty($file_content) && !$wp_filesystem->put_contents($file, $file_content, FS_CHMOD_FILE)) {
         $message = "Something went wrong! Don't worry, you have 2 different ways to fix it.<br><br>";
         $message .= "<strong>Option 1)</strong> Make sure your WordPress uploads directory is writable<br>To do this, you need to set the folder permission to 777. Check this video to know how to set folder permission using FileZilla: <a href='http://www.youtube.com/watch?v=MKgfquaVAgM'>http://www.youtube.com/watch?v=MKgfquaVAgM</a><br><br>";
         $message .= "<strong>Option 2)</strong> Import the default data using Wordpress Importer. Check our <a target='_blank' href='" . XT_DOCS_URL . "'>documentation</a> for more info";
         $data['error'] = true;
         $data['msg'] = '<p style="color: red;">' . $message . '</p>';
         die(json_encode($data));
     }
     if (!empty($file_content) && @file_exists($file)) {
         /* Flush Data
            ========================================================================== */
         $removed = array();
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->posts}")) {
             $removed[] = __('Posts removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->postmeta}")) {
             $removed[] = __('Postmeta removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->comments}")) {
             $removed[] = __('Comments removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->commentmeta}")) {
             $removed[] = __('Commentmeta removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->links}")) {
             $removed[] = __('Links removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->terms}")) {
             $removed[] = __('Terms removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->term_relationships}")) {
             $removed[] = __('Term relationships removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("TRUNCATE TABLE {$wpdb->term_taxonomy}")) {
             $removed[] = __('Term Taxonomy removed', XT_TEXT_DOMAIN);
         }
         if ($wpdb->query("DELETE FROM {$wpdb->options} WHERE `option_name` LIKE ('%_transient_%')")) {
             $removed[] = __('Transients removed', XT_TEXT_DOMAIN);
         }
         $wpdb->query("OPTIMIZE TABLE {$wpdb->options}");
         foreach ($removed as $item) {
             $output[] = '' . $item . '<br>';
         }
         $output[] = '<hr>';
         /* Import XML
            ========================================================================== */
         $args = array('file' => $file, 'map_user_id' => 1);
         auto_import($args);
         $output[] = '<p>' . __('Imported WordPress Content', XT_TEXT_DOMAIN) . '</p>';
         /* Import Widgets
            ========================================================================== */
         if (!empty($widgets)) {
             $widgets_options = xt_get_url_contents($widgets);
             if (!empty($widgets_options)) {
                 $widgets_options = json_decode($widgets_options, true);
                 foreach ($widgets_options as $option) {
                     $key = $option["option_name"];
                     $value = unserialize($option["option_value"]);
                     if ($key == 'widget_nav_menu' && !empty($value) && is_array($value)) {
                         foreach ($value as $k => $v) {
                             if (!empty($value[$k]['nav_menu'])) {
                                 $value[$k]['nav_menu'] = '';
                             }
                         }
                     }
                     delete_option($key);
                     add_option($key, $value);
                 }
             }
             $output[] = '<p>' . __('Imported Widgets and assigned them to sidebars.', XT_TEXT_DOMAIN) . '</p>';
         }
         /* Set Menu Location
            ========================================================================== */
         if (!empty($XT_Theme->menus)) {
             $default_menu_id = 'main-menu';
             $menu_id = (int) $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug = %s", $default_menu_id));
             $locations = get_theme_mod('nav_menu_locations');
             foreach ($XT_Theme->menus as $id => $menu) {
                 $locations[$id] = $menu_id;
             }
             set_theme_mod('nav_menu_locations', $locations);
             $output[] = '<p>' . __('Imported Menus and assigned them to menu locations.', XT_TEXT_DOMAIN) . '</p>';
         }
         /* Import Redux Settings
            ========================================================================== */
         if (!empty($redux)) {
             $import = xt_get_url_contents($redux);
             if (!empty($import)) {
                 $imported_options = json_decode($import, true);
             }
             if (!empty($imported_options) && is_array($imported_options) && isset($imported_options['redux-backup']) && $imported_options['redux-backup'] == '1') {
                 unset($imported_options['defaults'], $imported_options['compiler'], $imported_options['import'], $imported_options['import_code']);
                 update_option(XT_THEME_ID, $imported_options);
                 $output[] = '<p>' . __('Imported Theme Options', XT_TEXT_DOMAIN) . '</p>';
             }
         }
         /* Import Revolution Sliders
            ========================================================================== */
         if (!empty($revslider) && function_exists('is_plugin_active') && is_plugin_active('revslider/revslider.php')) {
             $this->get_and_save($revslider);
             $output[] = '<p>' . __('Imported Revolution Sliders', XT_TEXT_DOMAIN) . '</p>';
         }
         /* Import Essential Grid
            ========================================================================== */
         if (!empty($essgrid) && function_exists('is_plugin_active') && is_plugin_active('essential-grid/essential-grid.php')) {
             $this->get_and_save($essgrid);
             $output[] = '<p>' . __('Imported Essential Grid Data', XT_TEXT_DOMAIN) . '</p>';
         }
         flush_rewrite_rules();
         $data['error'] = false;
         $data['msg'] = implode('', $output) . '<p style="color: green;"><strong>' . __('Import Succeeded!', XT_TEXT_DOMAIN) . '</strong></p>';
     } else {
         $data['error'] = true;
         $data['msg'] = '<p style="color: red;"><strong>' . __('Import file is missing:', XT_TEXT_DOMAIN) . ' ' . $file . '</strong></p>';
     }
     ob_end_clean();
     die(json_encode($data));
 }
Example #2
0
function blog_display_posts()
{
    global $content, $blogSettings, $data_index;
    // Declare GLOBAL variables
    $Blog = new Blog();
    // Create a new instance of the Blog class
    $slug = base64_encode(return_page_slug());
    // Determine the page we are on.
    $blogSettings = $Blog->getSettingsData();
    // Get the blog's settings
    $blog_slug = base64_encode($blogSettings["blogurl"]);
    // What page should the blog show on?
    if ($slug == $blog_slug) {
        // If we are on the page that should be showing the blog...
        $content = '';
        // Legacy support
        ob_start();
        // Create a buffer to load everything into
        switch (true) {
            // Ok, so what are we going to do?
            case isset($_GET['post']) == true:
                // Display a post
                $post_file = BLOGPOSTSFOLDER . $_GET['post'] . '.xml';
                // Get the post's XML file
                show_blog_post($post_file);
                // Show the post
                break;
            case isset($_POST['search_blog']) == true:
                // Search the blog
                search_posts($_POST['keyphrase']);
                // Search the blog with the given keyphrase
                break;
            case isset($_GET['archive']) == true:
                // View the archives
                $archive = $_GET['archive'];
                // @TODO: Redundant? Revision required...
                show_blog_archive($archive);
                // Show the requested archive
                break;
            case isset($_GET['tag']) == true:
                // Show specific post by tag
                $tag = $_GET['tag'];
                // @TODO: Redundant? Revision required...
                show_blog_tag($tag);
                // Show all posts that have the given tag
                break;
            case isset($_GET['category']) == true:
                // Show a category of posts
                $category = $_GET['category'];
                // @TODO: Redundant? Revision required...
                show_blog_category($category);
                // Show posts from the requested category
                break;
            case isset($_GET['import']):
                // RSS Auto-Importer
                auto_import();
                // Let the RSS Auto-Importer do its thing
                break;
            default:
                // None of the above?
                show_all_blog_posts();
                // Lets just show all the posts then
                break;
        }
        $content = ob_get_contents();
        // Legacy support
        ob_end_clean();
        // Output the buffer to the user.
    }
    return $content;
    // legacy support for non filter hook calls to this function
}
Example #3
0
function iron_import_default_data()
{
    global $wpdb;
    require_once IRON_PARENT_DIR . '/includes/classes/autoimporter.class.php';
    $importPath = IRON_PARENT_DIR . '/import/';
    $placeholders = true;
    /*
    	if($_SERVER['HTTP_HOST'] == 'irontemplates.com' || $_SERVER['HTTP_HOST'] == 'staging.irontemplates.com' || strpos($_SERVER['HTTP_HOST'], '.dev') !== false) {
    		$placeholders = false;
    	}
    */
    $file = $importPath . 'default-data.xml';
    $file_tmp = $importPath . 'default-data-tmp.xml';
    $theme = !empty($_POST["theme"]) && $_POST["theme"] != 'default' ? '-' . $_POST["theme"] : '';
    $redux = !empty($_POST["redux"]) ? $_POST["redux"] : '';
    $revslider = !empty($_POST["revslider"]) ? $_POST["revslider"] : '';
    $file_content = file_get_contents('http://irontemplates.com/import/' . IRON_TEXT_DOMAIN . '/default-data' . $theme . '.xml');
    if ($placeholders) {
        //$file_content = preg_replace("/http:\/\/irontemplates\.com\/wp-demos\/(.*?)\/wp-content\/uploads\/(.*?).(jpg|jpeg|png|gif)\</", "http://placehold.it/400x400/text/color/placeholder.jpg<", $file_content);
    }
    if (!is_writable($file) || !file_put_contents($file, $file_content)) {
        $message = "Oops! An issue has been found. Don't worry, you have 2 different ways to fix it.<br><br>";
        $message .= "<strong>Option 1)</strong> Make sure this file is writable: " . $file . "<br>To do this, you need to set this folder permission and this file permission to 777. Check this video to know how to set folder permission using FileZilla: <a href='http://www.youtube.com/watch?v=MKgfquaVAgM'>http://www.youtube.com/watch?v=MKgfquaVAgM</a><br><br>";
        $message .= "<strong>Option 2)</strong> Import the default data using Wordpress importer. Read this faq for more info: <a href='http://it.ticksy.com/faq/180'>http://it.ticksy.com/faq/1800</a>";
        $data['error'] = true;
        $data['msg'] = '<p style="color: red;">' . $message . '</p>';
        die(json_encode($data));
    }
    if (@file_exists($file)) {
        if (@copy($file, $file_tmp)) {
            /* Import Reduc Settings
               ========================================================================== */
            if (!empty($redux)) {
                set_transient('redux-opts-saved', '1', 1000);
                $import = wp_remote_retrieve_body(wp_remote_get($redux));
                $imported_options = unserialize(trim($import, '###'));
                if (is_array($imported_options) && isset($imported_options['redux-opts-backup']) && $imported_options['redux-opts-backup'] == '1') {
                    $imported_options['imported'] = 1;
                    global $Redux_Options;
                    $Redux_Options->options = $imported_options;
                    update_option(IRON_TEXT_DOMAIN, $imported_options);
                }
            }
            if (!empty($revslider) && function_exists('is_plugin_active') && is_plugin_active('revslider/revslider.php')) {
                $revslider_data = file_get_contents($revslider);
                $revslider_data = json_decode($revslider_data, true);
                $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "revslider_css");
                $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "revslider_layer_animations");
                $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "revslider_sliders");
                $wpdb->query("TRUNCATE TABLE " . $wpdb->prefix . "revslider_slides");
                if (!empty($revslider_data["sliders"])) {
                    $styles = $revslider_data["styles"];
                    $animations = $revslider_data["animations"];
                    $sliders = $revslider_data["sliders"];
                    $slides = $revslider_data["slides"];
                    foreach ($styles as $style) {
                        $wpdb->insert($wpdb->prefix . 'revslider_css', $style);
                    }
                    foreach ($animations as $animation) {
                        $wpdb->insert($wpdb->prefix . 'revslider_layer_animations', $animation);
                    }
                    foreach ($sliders as $slider) {
                        $wpdb->insert($wpdb->prefix . 'revslider_sliders', $slider);
                    }
                    foreach ($slides as $slide) {
                        $wpdb->insert($wpdb->prefix . 'revslider_slides', $slide);
                    }
                }
            }
            /* Import XML
               ========================================================================== */
            $args = array('file' => $file_tmp, 'map_user_id' => 1);
            $removed = array();
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->posts}")) {
                $removed[] = __('Posts removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->postmeta}")) {
                $removed[] = __('Postmeta removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->comments}")) {
                $removed[] = __('Comments removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->commentmeta}")) {
                $removed[] = __('Commentmeta removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->links}")) {
                $removed[] = __('Links removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->terms}")) {
                $removed[] = __('Terms removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->term_relationships}")) {
                $removed[] = __('Term relationships removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("TRUNCATE TABLE {$wpdb->term_taxonomy}")) {
                $removed[] = __('Term Taxonomy removed', IRON_TEXT_DOMAIN);
            }
            if ($wpdb->query("DELETE FROM {$wpdb->options} WHERE `option_name` LIKE ('%_transient_%')")) {
                $removed[] = __('Transients removed', IRON_TEXT_DOMAIN);
            }
            $wpdb->query("OPTIMIZE TABLE {$wpdb->options}");
            foreach ($removed as $item) {
                $output[] = '' . $item . '<br>';
            }
            $output[] = '<hr>';
            ob_start();
            auto_import($args);
            $raw = ob_get_contents();
            ob_end_clean();
            $output[] = $raw;
            /* Ugly hack to avoid duplicated Menu Items
               ========================================================================== */
            $keep_safe = array();
            $results = $wpdb->get_results("select MIN(m2.meta_value) as parent from {$wpdb->postmeta} m1\r\n\t\t\tINNER JOIN {$wpdb->postmeta} m2 ON m1.post_id = m2.post_id AND m2.meta_key = '_menu_item_menu_item_parent'\r\n\t\t\tWHERE m1.meta_key = '_menu_item_object_id' AND m2.meta_value != 0 group by m1.meta_value having count(*) > 1");
            foreach ($results as $res) {
                $keep_safe[] = $res->parent;
            }
            $results = $wpdb->get_results("select MAX(m2.meta_value) as parent, m1.post_id, m1.meta_value, MAX(m1.meta_id) from {$wpdb->postmeta} m1\r\n\t\t\tINNER JOIN {$wpdb->postmeta} m2 ON m1.post_id = m2.post_id AND m2.meta_key = '_menu_item_menu_item_parent'\r\n\t\t\tWHERE m1.meta_key = '_menu_item_object_id' AND m2.meta_value != 0 group by m1.meta_value having count(*) > 1");
            foreach ($results as $res) {
                $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE `post_id` = {$res->post_id}");
                wp_delete_post($res->post_id);
                $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE `post_id` = {$res->parent}");
                wp_delete_post($res->parent);
            }
            $results = $wpdb->get_results("select m1.post_id, m1.meta_value, MAX(m1.meta_id) from {$wpdb->postmeta} m1\r\n\t\t\tINNER JOIN {$wpdb->postmeta} m2 ON m1.post_id = m2.post_id AND m2.meta_key = '_menu_item_menu_item_parent'\r\n\t\t\tWHERE m1.meta_key = '_menu_item_object_id' AND m2.meta_value = 0 group by m1.meta_value having count(*) > 1");
            foreach ($results as $res) {
                if (!in_array($res->post_id, $keep_safe)) {
                    $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE `post_id` = {$res->post_id}");
                    wp_delete_post($res->post_id);
                }
            }
            /* Set Menu Location
               ========================================================================== */
            $menu_slug = 'main-menu';
            $menu_id = (int) $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE slug = '" . $menu_slug . "'");
            if (is_numeric($menu_id)) {
                $locations = get_theme_mod('nav_menu_locations');
                $locations[$menu_slug] = $menu_id;
                set_theme_mod('nav_menu_locations', $locations);
            }
            /* Setup Widgets
               ========================================================================== */
            /**
             * Default sidebars also set in /admin/options.php:widget_areas
             */
            if (class_exists('WP_Widget')) {
                // Disable default WordPress sidebars from fresh install
                //update_option( 'widget_search', array() );
                update_option('widget_recent-posts', array());
                update_option('widget_recent-comments', array());
                update_option('widget_archives', array());
                update_option('widget_categories', array());
                update_option('widget_meta', array());
                update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), IRON_SIDEBAR_PREFIX . '0' => array(), IRON_SIDEBAR_PREFIX . '1' => array(), IRON_SIDEBAR_PREFIX . '2' => array(), IRON_SIDEBAR_PREFIX . '3' => array(), IRON_SIDEBAR_PREFIX . '4' => array()));
                global $wp_registered_sidebars;
                ### Setup Widget Instances
                $sidebar_widgets = wp_get_sidebars_widgets();
                $widget_areas = get_iron_option('widget_areas', null, array());
                ### Sidebar "Default Footer"
                if (array_key_exists(IRON_SIDEBAR_PREFIX . '2', $sidebar_widgets)) {
                    $sidebar_widgets[IRON_SIDEBAR_PREFIX . '2'] = array('iron-newsletter-2');
                    update_option('widget_iron-newsletter', array(2 => array('title' => __('Subscribe to our newsletter', IRON_TEXT_DOMAIN)), '_multiwidget' => 1));
                    set_iron_option('footer-area_id', IRON_SIDEBAR_PREFIX . '2');
                }
                ### Sidebar "Default Blog Sidebar"
                if (array_key_exists(IRON_SIDEBAR_PREFIX . '0', $sidebar_widgets)) {
                    $sidebar_widgets[IRON_SIDEBAR_PREFIX . '0'] = array('iron-terms-2');
                    update_option('widget_iron-terms', array(2 => array('title' => __('Categories'), 'taxonomy' => 'category', 'count' => 1, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
                    $query = new WP_Query(array('post_type' => 'page', 'posts_per_page' => -1, 'no_found_rows' => true, 'meta_query' => array(array('key' => '_wp_page_template', 'value' => 'index', 'compare' => 'LIKE'))));
                    if ($query->have_posts()) {
                        foreach ($query->posts as $post) {
                            update_post_meta($post->ID, 'sidebar-position', 'right', 'disabled');
                            update_post_meta($post->ID, 'sidebar-area_id', IRON_SIDEBAR_PREFIX . '0', '');
                        }
                    }
                }
                ### Sidebar "Default Video Sidebar"
                if (array_key_exists(IRON_SIDEBAR_PREFIX . '1', $sidebar_widgets)) {
                    $sidebar_widgets[IRON_SIDEBAR_PREFIX . '1'] = array('iron-terms-3');
                    $widget_instances = get_option('widget_iron-terms');
                    unset($widget_instances['_multiwidget']);
                    $widget_instances[] = array('title' => __('Categories'), 'taxonomy' => 'video-category', 'count' => 1, 'hierarchical' => 0, 'dropdown' => 0);
                    $widget_instances['_multiwidget'] = 1;
                    update_option('widget_iron-terms', $widget_instances);
                    $query = new WP_Query(array('post_type' => 'page', 'posts_per_page' => -1, 'no_found_rows' => true, 'meta_query' => array(array('key' => '_wp_page_template', 'value' => 'archive-video', 'compare' => 'LIKE'))));
                    if ($query->have_posts()) {
                        foreach ($query->posts as $post) {
                            update_post_meta($post->ID, 'sidebar-position', 'right', 'disabled');
                            update_post_meta($post->ID, 'sidebar-area_id', IRON_SIDEBAR_PREFIX . '1', '');
                        }
                    }
                }
                wp_set_sidebars_widgets($sidebar_widgets);
                $output[] = '<hr>';
                $output[] = '<p>' . __('Widgets assigned to sidebars.', IRON_TEXT_DOMAIN) . '</p>';
            }
            /* ========================================================================== */
            flush_rewrite_rules();
            $data['error'] = false;
            $data['msg'] = implode('', $output) . '<p style="color: green;"><strong>' . __('Import Succeded!', IRON_TEXT_DOMAIN) . '</strong></p>';
        } else {
            $data['error'] = true;
            $data['msg'] = '<p style="color: red;"><strong>' . __('Unable to generate temporary copy of import file. Permission denied.', IRON_TEXT_DOMAIN) . '</strong></p>';
        }
    } else {
        $data['error'] = true;
        $data['msg'] = '<p style="color: red;"><strong>' . __('Import file is missing:', IRON_TEXT_DOMAIN) . ' ' . $file . '</strong></p>';
    }
    die(json_encode($data));
}
Example #4
0
        function st_save_ajax()
        {
            check_ajax_referer('GE Trends-settings', 'security');
            $data = $_POST;
            unset($data['security'], $data['action']);
            $v3 = '';
            $fl = '';
            global $wp_registered_sidebars;
            $sidebars = $wp_registered_sidebars;
            if ($data['new_sidebar'] != '') {
                $new_sidebar = str_replace(array("\n", "\r", "\t"), '', $data['new_sidebar']);
                $new_sidebar_id = str_replace(array(' ', ',', '.', '"', "'", '/', "\\", '+', '=', ')', '(', '*', '&', '^', '%', '$', '#', '@', '!', '~', '`', '<', '>', '?', '[', ']', '{', '}', '|', ':'), '_', $new_sidebar);
                $new_sidebar = str_replace(array(' ', ',', '.', '"', "'", '/', "\\", '+', '=', ')', '(', '*', '&', '^', '%', '$', '#', '@', '!', '~', '`', '<', '>', '?', '[', ']', '{', '}', '|', ':'), '_', $new_sidebar);
                $new_sidebars[$new_sidebar_id] = $new_sidebar;
                $fl = 0;
                if (is_array($sidebars) && !empty($sidebars)) {
                    foreach ($sidebars as $sidebar) {
                        if ($sidebar['id'] == $new_sidebar_id) {
                            $fl = 1;
                        }
                    }
                }
                //$cb_sidebars = array();
                $cb_sidebars = unserialize(get_option('cb4_new_sidebar'));
                $cb_sidebars[$new_sidebar_id] = $new_sidebar;
                $cb_sidebars1 = serialize($cb_sidebars);
                if ($fl == 0) {
                    update_option('cb4_new_sidebar', $cb_sidebars1);
                    $v3 = '1';
                }
                $sidebs_del = $cb_sidebars;
            } else {
                $sidebs_del = unserialize(get_option('cb4_new_sidebar'));
            }
            $fl_dl = 0;
            if (is_array($sidebars) && !empty($sidebars)) {
                foreach ($sidebars as $sidebar) {
                    $sid_id = $sidebar['id'];
                    $del_sid = 'del-' . $sid_id;
                    if (isset($data[$del_sid])) {
                        if ($data[$del_sid] == 'del') {
                            if ($sidebs_del[$sid_id]) {
                                unset($sidebs_del[$sid_id]);
                                $fl_dl = 1;
                            }
                        }
                    } else {
                        $data[$del_sid] = '';
                    }
                }
            }
            if ($fl_dl == 1) {
                $sidebs_del = serialize($sidebs_del);
                update_option('cb4_new_sidebar', $sidebs_del);
                $v3 = '1';
            }
            $adi_thumb = '';
            update_option('cb4_adi_thumb', $adi_thumb);
            $scroll = esc_attr($data['scroll']);
            update_option('cb4_scroll', $scroll);
            $usescroll = esc_attr($data['usescroll']);
            update_option('cb4_usescroll', $usescroll);
            $mheadertype = esc_attr($data['mheadertype']);
            update_option('cb4_mheadertype', $mheadertype);
            if (!isset($data['rev_slider_name'])) {
                $data['rev_slider_name'] = '';
            }
            $rev_slider_name = esc_attr($data['rev_slider_name']);
            update_option('cb4_rev_slider_name', $rev_slider_name);
            $woo_per_page = esc_attr($data['woo_per_page']);
            update_option('cb4_woo_per_page', $woo_per_page);
            $woo_cols = esc_attr($data['woo_cols']);
            update_option('cb4_woo_cols', $woo_cols);
            $woo_related_n = esc_attr($data['woo_related_n']);
            update_option('cb4_woo_related_n', $woo_related_n);
            $woo_related_c = esc_attr($data['woo_related_c']);
            update_option('cb4_woo_related_c', $woo_related_c);
            $iconspos = esc_attr($data['iconspos']);
            update_option('cb4_iconspos', $iconspos);
            $icons_bottom_margin = esc_attr($data['icons_bottom_margin']);
            update_option('cb4_icons_bottom_margin', $icons_bottom_margin);
            $adi_st = '';
            update_option('cb4_adi_st', $adi_st);
            $bg_fixed = esc_attr($data['bg_fixed']);
            update_option('cb4_bg_fixed', $bg_fixed);
            $bg_str = esc_attr($data['bg_str']);
            update_option('cb4_bg_str', $bg_str);
            $bgf_str = esc_attr($data['bgf_str']);
            update_option('cb4_bgf_str', $bgf_str);
            $admin_theme = '';
            update_option('cb4_admin_theme', $admin_theme);
            $disable_pp = esc_attr($data['disable_pp']);
            update_option('cb4_disable_pp', $disable_pp);
            $shad = esc_attr($data['shad']);
            update_option('cb4_shad', $shad);
            $shad2 = esc_attr($data['shad2']);
            update_option('cb4_shad2', $shad2);
            $add_css = esc_attr($data['add_css']);
            update_option('cb4_add_css', $add_css);
            $h_title = esc_attr($data['h_title']);
            update_option('cb4_h_title', $h_title);
            $h_more = esc_attr($data['h_more']);
            update_option('cb4_h_more', $h_more);
            $under = esc_attr($data['under']);
            update_option('cb4_under', $under);
            if (!isset($data['topw'])) {
                $data['topw'] = '';
            }
            $topw = esc_attr($data['topw']);
            update_option('cb4_top_widget', $topw);
            $wid = esc_attr($data['wid']);
            update_option('cb4_wid', $wid);
            $slide_type = esc_attr($data['slide_type']);
            update_option('cb4_slide_type', $slide_type);
            $h1fs = esc_attr($data['h1fs']);
            update_option('cb4_h1fs', $h1fs);
            $bodyfs = esc_attr($data['bodyfs']);
            update_option('cb4_bodyfs', $bodyfs);
            $h1fts = esc_attr($data['h1fts']);
            update_option('cb4_h1fts', $h1fts);
            $h2fs = esc_attr($data['h2fs']);
            update_option('cb4_h2fs', $h2fs);
            $h3fs = esc_attr($data['h3fs']);
            update_option('cb4_h3fs', $h3fs);
            $h4fs = esc_attr($data['h4fs']);
            update_option('cb4_h4fs', $h4fs);
            $h5fs = esc_attr($data['h5fs']);
            update_option('cb4_h5fs', $h5fs);
            $h6fs = esc_attr($data['h6fs']);
            update_option('cb4_h6fs', $h6fs);
            $headh = esc_attr($data['headh']);
            update_option('cb4_headh', $headh);
            $headhc = esc_attr($data['headhc']);
            update_option('cb4_headhc', $headhc);
            $slide_home = esc_attr($data['slide_home']);
            update_option('cb4_slide_home', $slide_home);
            $meta_description = esc_attr($data['meta_description']);
            update_option('cb4_meta_description', $meta_description);
            $meta_keywords = esc_attr($data['meta_keywords']);
            update_option('cb4_meta_keywords', $meta_keywords);
            $editor_style = '';
            update_option('cb4_editor_style', $editor_style);
            $full_slider = esc_attr($data['full_slider']);
            update_option('cb4_full_slider', $full_slider);
            $full_slider_interval = esc_attr($data['full_slider_interval']);
            update_option('cb4_full_slider_interval', $full_slider_interval);
            $full_slider_effect = esc_attr($data['full_slider_effect']);
            update_option('cb4_full_slider_effect', $full_slider_effect);
            $full_slider_t_speed = esc_attr($data['full_slider_t_speed']);
            update_option('cb4_full_slider_t_speed', $full_slider_t_speed);
            if (!isset($full_slider_page)) {
                $full_slider_page = '';
            }
            if (!isset($data['full_slider_page'])) {
                $data['full_slider_page'] = '';
            }
            $full_slider_page = esc_attr($data['full_slider_page']);
            update_option('cb4_full_slider_page', $full_slider_page);
            $full_slider_where = esc_attr($data['full_slider_where']);
            update_option('cb4_full_slider_where', $full_slider_where);
            $full_slider_bar = esc_attr($data['full_slider_bar']);
            update_option('cb4_full_slider_bar', $full_slider_bar);
            $full_slider_style = esc_attr($data['full_slider_style']);
            update_option('cb4_full_slider_style', $full_slider_style);
            $full_slider_thumbs = esc_attr($data['full_slider_thumbs']);
            update_option('cb4_full_slider_thumbs', $full_slider_thumbs);
            $full_slider_nav = esc_attr($data['full_slider_nav']);
            update_option('cb4_full_slider_nav', $full_slider_nav);
            $fixed_top = esc_attr($data['fixed_top']);
            update_option('cb4_fixed_top', $fixed_top);
            $social_foot = esc_attr($data['social_foot']);
            update_option('cb4_social_foot', $social_foot);
            $social_fb = esc_attr($data['social_fb']);
            update_option('cb4_social_fb', $social_fb);
            $social_tw = esc_attr($data['social_tw']);
            update_option('cb4_social_tw', $social_tw);
            $social_in = esc_attr($data['social_in']);
            update_option('cb4_social_in', $social_in);
            $social_yt = esc_attr($data['social_yt']);
            update_option('cb4_social_yt', $social_yt);
            $social_vi = esc_attr($data['social_vi']);
            update_option('cb4_social_vi', $social_vi);
            $social_rss = esc_attr($data['social_rss']);
            update_option('cb4_social_rss', $social_rss);
            $c_name = '';
            update_option('cb4_c_name', $c_name);
            $c_email = '';
            update_option('cb4_c_email', $c_email);
            $c_message = '';
            update_option('cb4_c_message', $c_message);
            $c_thanks = '';
            update_option('cb4_c_thanks', $c_thanks);
            $c_error = '';
            update_option('cb4_c_error', $c_error);
            $r_use = esc_attr($data['r_use']);
            update_option('cb4_r_use', $r_use);
            $r_public = esc_attr($data['r_public']);
            update_option('cb4_r_public', $r_public);
            $r_private = esc_attr($data['r_private']);
            update_option('cb4_r_private', $r_private);
            $r_template = esc_attr($data['r_template']);
            update_option('cb4_r_template', $r_template);
            $page_id = '';
            update_option('cb4_page_id', $page_id);
            $show_logo_text = esc_attr($data['show_logo_text']);
            update_option('cb4_show_logo_text', $show_logo_text);
            $logomt = esc_attr($data['logomt']);
            update_option('cb4_logomt', $logomt);
            $logo_text = esc_attr($data['logo_text']);
            update_option('cb4_logo_text', $logo_text);
            $logo_slogan = esc_attr($data['logo_slogan']);
            update_option('cb4_logo_slogan', $logo_slogan);
            $home_template = esc_attr($data['home_template']);
            update_option('cb4_home_template', $home_template);
            $home_limit = esc_attr($data['home_limit']);
            update_option('cb4_home_limit', $home_limit);
            $color_style = esc_attr($data['color_style']);
            update_option('cb4_color_style', $color_style);
            $font_family = esc_attr($data['font_family']);
            update_option('cb4_font_family', $font_family);
            $font_family_google = esc_attr($data['font_family_google']);
            update_option('cb4_font_family_google', $font_family_google);
            $font_family_head = esc_attr($data['font_family_head']);
            update_option('cb4_font_family_head', $font_family_head);
            $font_family_google_head = esc_attr($data['font_family_google_head']);
            update_option('cb4_font_family_google_head', $font_family_google_head);
            $font_family_google_head_title = esc_attr($data['font_family_google_head_title']);
            update_option('cb4_font_family_google_head_title', $font_family_google_head_title);
            $font_family_google_head_title2 = esc_attr($data['font_family_google_head_title2']);
            update_option('cb4_font_family_google_head_title2', $font_family_google_head_title2);
            $show_bread = esc_attr($data['show_bread']);
            update_option('cb4_show_bread', $show_bread);
            $background = '';
            update_option('cb4_background', $background);
            $background_color = esc_attr($data['background_color']);
            update_option('cb4_background_color', $background_color);
            $cbackground_color = esc_attr($data['cbackground_color']);
            update_option('cb4_cbackground_color', $cbackground_color);
            $text_color = esc_attr($data['text_color']);
            update_option('cb4_text_color', $text_color);
            $logo_shad = esc_attr($data['logo_shad']);
            update_option('cb4_logo_shad', $logo_shad);
            $slogan_color = esc_attr($data['slogan_color']);
            update_option('cb4_slogan_color', $slogan_color);
            $logo_color = esc_attr($data['logo_color']);
            update_option('cb4_logo_color', $logo_color);
            $middle_background = esc_attr($data['middle_background']);
            update_option('cb4_middle_background', $middle_background);
            $middle_backgroundi = esc_attr($data['middle_backgroundi']);
            update_option('cb4_middle_backgroundi', $middle_backgroundi);
            $middle_backgroundc = esc_attr($data['middle_backgroundc']);
            update_option('cb4_middle_backgroundc', $middle_backgroundc);
            $middle_nbackgroundc = esc_attr($data['middle_nbackgroundc']);
            update_option('cb4_middle_nbackgroundc', $middle_nbackgroundc);
            $ht_background = esc_attr($data['ht_background']);
            update_option('cb4_ht_background', $ht_background);
            $htb_background = esc_attr($data['htb_background']);
            update_option('cb4_htb_background', $htb_background);
            $footer_background = esc_attr($data['footer_background']);
            update_option('cb4_footer_background', $footer_background);
            $show_footer = esc_attr($data['show_footer']);
            update_option('cb4_show_footer', $show_footer);
            $wayp = esc_attr($data['wayp']);
            update_option('cb4_wayp', $wayp);
            $show_comments = esc_attr($data['show_comments']);
            update_option('cb4_show_comments', $show_comments);
            $show_midb = esc_attr($data['show_midb']);
            update_option('cb4_show_midb', $show_midb);
            $disable_rounded = '';
            update_option('cb4_disable_rounded ', $disable_rounded);
            $google_analytics = esc_attr($data['google_analytics']);
            update_option('cb4_google_analytics', $google_analytics);
            $not_error = esc_attr($data['not_error']);
            update_option('cb4_not_error', $not_error);
            $not_desc = esc_attr($data['not_desc']);
            update_option('cb4_not_desc', $not_desc);
            $menu_font_size = esc_attr($data['menu_font_size']);
            update_option('cb4_menu_font_size', $menu_font_size);
            $headings_color = esc_attr($data['headings_color']);
            update_option('cb4_headings_color', $headings_color);
            $links_color = esc_attr($data['links_color']);
            update_option('cb4_links_color', $links_color);
            $pfilter_color = esc_attr($data['pfilter_color']);
            update_option('cb4_pfilter_color', $pfilter_color);
            $pfilter_bgcolor = esc_attr($data['pfilter_bgcolor']);
            update_option('cb4_pfilter_bgcolor', $pfilter_bgcolor);
            $links_hover_color = esc_attr($data['links_hover_color']);
            update_option('cb4_links_hover_color', $links_hover_color);
            $stripes_bg_schema = esc_attr($data['stripes_bg_schema']);
            update_option('cb4_stripes_bg_schema', $stripes_bg_schema);
            $stripes_bg_schema2 = esc_attr($data['stripes_bg_schema2']);
            update_option('cb4_stripes_bg_schema2', $stripes_bg_schema2);
            $menu_color = esc_attr($data['menu_color']);
            update_option('cb4_menu_color', $menu_color);
            $menu_font_color = '';
            update_option('cb4_menu_font_color', $menu_font_color);
            $menu_hover_color = '';
            update_option('cb4_menu_hover_color', $menu_hover_color);
            $logo_font = esc_attr($data['logo_font']);
            update_option('cb4_logo_font', $logo_font);
            $home_number = esc_attr($data['home_number']);
            update_option('cb4_home_number', $home_number);
            $home_cat = esc_attr($data['home_cat']);
            update_option('cb4_home_cat', $home_cat);
            $slide_bg = '';
            update_option('cb4_slide_bg', $slide_bg);
            $s_easing = esc_attr($data['s_easing']);
            update_option('cb4_s_easing', $s_easing);
            $s_ani_time = esc_attr($data['s_ani_time']);
            update_option('cb4_s_ani_time', $s_ani_time);
            $s_resize = esc_attr($data['s_resize']);
            update_option('cb4_s_resize', $s_resize);
            $s_height = esc_attr($data['s_height']);
            update_option('cb4_s_height', $s_height);
            $s_link = esc_attr($data['s_link']);
            update_option('cb4_s_link', $s_link);
            $s_text = esc_attr($data['s_text']);
            update_option('cb4_s_text', $s_text);
            $s_delay = esc_attr($data['s_delay']);
            update_option('cb4_s_delay', $s_delay);
            $s_auto = esc_attr($data['s_auto']);
            update_option('cb4_s_auto', $s_auto);
            $cat = esc_attr($data['cat']);
            update_option('cb4_cat', $cat);
            $hide_top = esc_attr($data['hide_top']);
            update_option('cb4_hide_top', $hide_top);
            $sideb_col = esc_attr($data['sideb_col']);
            update_option('cb4_sideb_col', $sideb_col);
            $mwid = '';
            update_option('cb4_mwid', $mwid);
            $post_details = esc_attr($data['post_details']);
            update_option('cb4_post_details', $post_details);
            $sideb_page = esc_attr($data['sideb_page']);
            update_option('cb4_sideb_page', $sideb_page);
            $color_schema = esc_attr($data['color_schema']);
            update_option('cb4_color_schema', $color_schema);
            $color_master = esc_attr($data['color_master']);
            update_option('cb4_color_master', $color_master);
            $fadecolor = esc_attr($data['fadecolor']);
            update_option('cb4_fadecolor', $fadecolor);
            $o_con = esc_attr($data['o_con']);
            update_option('cb4_o_con', $o_con);
            $sidebar_shop = esc_attr($data['sidebar_shop']);
            update_option('cb4_sidebar_shop', $sidebar_shop);
            $o_head = esc_attr($data['o_head']);
            update_option('cb4_o_head', $o_head);
            $o_mid = esc_attr($data['o_mid']);
            update_option('cb4_o_mid', $o_mid);
            $o_foot = esc_attr($data['o_foot']);
            update_option('cb4_o_foot', $o_foot);
            $bors = esc_attr($data['bors']);
            update_option('cb4_bors', $bors);
            $bors_h = esc_attr($data['bors_h']);
            update_option('cb4_bors_h', $bors_h);
            $bors_f = esc_attr($data['bors_f']);
            update_option('cb4_bors_f', $bors_f);
            $logo_f = esc_attr($data['logo_f']);
            update_option('cb4_logo_f', $logo_f);
            $h_sid = esc_attr($data['h_sid']);
            update_option('cb4_h_sid', $h_sid);
            $menu_f = esc_attr($data['menu_f']);
            update_option('cb4_menu_f', $menu_f);
            $mw = esc_attr($data['mw']);
            update_option('cb4_mw', $mw);
            $mwh = esc_attr($data['mwh']);
            update_option('cb4_mwh', $mwh);
            $sideb_blog = '';
            update_option('cb4_sideb_blog', $sideb_blog);
            $sideb_post = esc_attr($data['sideb_post']);
            update_option('cb4_sideb_post', $sideb_post);
            $headertransparent = esc_attr($data['headertransparent']);
            update_option('cb4_headertransparent', $headertransparent);
            $slidertoptint = esc_attr($data['slidertoptint']);
            update_option('cb4_slidertoptint', $slidertoptint);
            $showtopwidget = esc_attr($data['showtopwidget']);
            update_option('cb4_showtopwidget', $showtopwidget);
            $showmenusearch = esc_attr($data['showmenusearch']);
            update_option('cb4_showmenusearch', $showmenusearch);
            $headings_up = esc_attr($data['headings_up']);
            update_option('cb4_headings_up', $headings_up);
            $headings_upw = esc_attr($data['headings_upw']);
            update_option('cb4_headings_upw', $headings_upw);
            $headings_upw_t = esc_attr($data['headings_upw_t']);
            update_option('cb4_headings_upw_t', $headings_upw_t);
            $headings_icons_size = esc_attr($data['headings_icons_size']);
            update_option('cb4_headings_icons_size', $headings_icons_size);
            $icons_name = $data['icons_name'];
            $icons_link = $data['icons_link'];
            $icons_val = $data['icons_val'];
            $icons_color = $data['icons_color'];
            $headins_icons_array = array();
            if (isset($icons_name) && is_array($icons_name)) {
                for ($i = 0; $i < sizeof($icons_name); $i++) {
                    $headins_icons_array[$i]['icon'] = $icons_val[$i];
                    $headins_icons_array[$i]['link'] = $icons_link[$i];
                    $headins_icons_array[$i]['name'] = $icons_name[$i];
                    $headins_icons_array[$i]['color'] = $icons_color[$i];
                }
            }
            update_option('cb4_headings_icons', serialize($headins_icons_array));
            $demol = esc_attr($data['demol']);
            $demol_att = esc_attr($data['demo_atts']);
            if ($demol != '') {
                require get_template_directory() . '/inc/cb-install.php';
                if ($demol_att == 'yes') {
                    $auto_import_att = '1';
                } else {
                    $auto_import_att = '0';
                }
                require get_template_directory() . '/inc/autoimporter/autoimporter.php';
                if ($demol == 'onepage') {
                    $args = array('file' => get_template_directory() . '/docs/import/demo_content_one_page.xml', 'map_user_id' => 1);
                } else {
                    $args = array('file' => get_template_directory() . '/docs/import/demo_content.xml', 'map_user_id' => 1);
                }
                ob_start();
                auto_import($args, $auto_import_att);
                $con = ob_get_contents();
                ob_end_clean();
                $v3 = '1';
                update_option('show_on_front ', 'page');
                if ($demol == 'onepage') {
                    update_option('page_on_front ', '437');
                } else {
                    update_option('page_on_front ', '437');
                }
                $demo_widget = esc_attr($data['demo_widget']);
                if ($demo_widget != '') {
                    class Widget_Data_Importer
                    {
                        /**
                         * Import widgets
                         * @param array $import_array
                         */
                        public static function parse_import_data($import_array)
                        {
                            $sidebars_data = $import_array[0];
                            $widget_data = $import_array[1];
                            $current_sidebars = get_option('sidebars_widgets');
                            foreach ($current_sidebars as &$current) {
                                if (!is_array($current) && !is_numeric($current)) {
                                    $current = array();
                                }
                            }
                            global $wp_registered_sidebars;
                            foreach ($wp_registered_sidebars as $key => $value) {
                                if (!array_key_exists($key, $current_sidebars)) {
                                    $current_sidebars[$key] = array();
                                }
                            }
                            $new_widgets = array();
                            foreach ($sidebars_data as $import_sidebar => $import_widgets) {
                                foreach ($import_widgets as $import_widget) {
                                    //if the sidebar exists
                                    if (isset($current_sidebars[$import_sidebar])) {
                                        $title = trim(substr($import_widget, 0, strrpos($import_widget, '-')));
                                        $index = trim(substr($import_widget, strrpos($import_widget, '-') + 1));
                                        $current_widget_data = get_option('widget_' . $title);
                                        $new_widget_name = self::get_new_widget_name($title, $index);
                                        $new_index = trim(substr($new_widget_name, strrpos($new_widget_name, '-') + 1));
                                        if (!empty($new_widgets[$title]) && is_array($new_widgets[$title])) {
                                            while (array_key_exists($new_index, $new_widgets[$title])) {
                                                $new_index++;
                                            }
                                        }
                                        $current_sidebars[$import_sidebar][] = $title . '-' . $new_index;
                                        if (array_key_exists($title, $new_widgets)) {
                                            $new_widgets[$title][$new_index] = $widget_data[$title][$index];
                                            $multiwidget = $new_widgets[$title]['_multiwidget'];
                                            unset($new_widgets[$title]['_multiwidget']);
                                            $new_widgets[$title]['_multiwidget'] = $multiwidget;
                                        } else {
                                            $current_widget_data[$new_index] = $widget_data[$title][$index];
                                            $current_multiwidget = $current_widget_data['_multiwidget'];
                                            $new_multiwidget = $widget_data[$title]['_multiwidget'];
                                            $multiwidget = $current_multiwidget != $new_multiwidget ? $current_multiwidget : 1;
                                            unset($current_widget_data['_multiwidget']);
                                            $current_widget_data['_multiwidget'] = $multiwidget;
                                            $new_widgets[$title] = $current_widget_data;
                                        }
                                    }
                                }
                            }
                            if (isset($new_widgets) && isset($current_sidebars)) {
                                update_option('sidebars_widgets', $current_sidebars);
                                foreach ($new_widgets as $title => $content) {
                                    update_option('widget_' . $title, $content);
                                }
                                return true;
                            }
                            return false;
                        }
                        /**
                         * Parse JSON import file and load
                         */
                        public static function ajax_import_widget_data()
                        {
                            $up_file = get_template_directory() . '/docs/import/widget_data.json';
                            $json = self::get_widget_settings_json();
                            if (is_wp_error($json)) {
                                wp_die($json->get_error_message());
                            }
                            if (!($json_data = json_decode($json[0], true))) {
                                return;
                            }
                            if (isset($json_data[0])) {
                                foreach (self::order_sidebar_widgets($json_data[0]) as $sidebar_name => $widget_list) {
                                    if (count($widget_list) == 0) {
                                        continue;
                                    }
                                    $sidebar_info = self::get_sidebar_info($sidebar_name);
                                    if ($sidebar_info) {
                                        foreach ($widget_list as $widget) {
                                            $widget_options = false;
                                            $widget_type = trim(substr($widget, 0, strrpos($widget, '-')));
                                            $widget_type_index = trim(substr($widget, strrpos($widget, '-') + 1));
                                            foreach ($json_data[1] as $name => $option) {
                                                if ($name == $widget_type) {
                                                    $widget_type_options = $option;
                                                    break;
                                                }
                                            }
                                            if (!isset($widget_type_options) || !$widget_type_options) {
                                                continue;
                                            }
                                            $widget_title = isset($widget_type_options[$widget_type_index]['title']) ? $widget_type_options[$widget_type_index]['title'] : '';
                                            $widget_options = $widget_type_options[$widget_type_index];
                                            $new_widgets[$widget_type][$widget_type_index] = 'on';
                                            ?>
								<?php 
                                        }
                                        ?>


								<?php 
                                    }
                                    ?>
								<?php 
                                }
                                ?>
								<?php 
                            }
                            $widgets = $new_widgets;
                            $import_file = $up_file;
                            $json_data = file_get_contents($import_file);
                            $json_data = json_decode($json_data, true);
                            $sidebar_data = $json_data[0];
                            $widget_data = $json_data[1];
                            foreach ($sidebar_data as $title => $sidebar) {
                                $count = count($sidebar);
                                for ($i = 0; $i < $count; $i++) {
                                    $widget = array();
                                    $widget['type'] = trim(substr($sidebar[$i], 0, strrpos($sidebar[$i], '-')));
                                    $widget['type-index'] = trim(substr($sidebar[$i], strrpos($sidebar[$i], '-') + 1));
                                    if (!isset($widgets[$widget['type']][$widget['type-index']])) {
                                        unset($sidebar_data[$title][$i]);
                                    }
                                }
                                $sidebar_data[$title] = array_values($sidebar_data[$title]);
                            }
                            foreach ($widgets as $widget_title => $widget_value) {
                                foreach ($widget_value as $widget_key => $widget_value) {
                                    $widgets[$widget_title][$widget_key] = $widget_data[$widget_title][$widget_key];
                                }
                            }
                            $sidebar_data = array(array_filter($sidebar_data), $widgets);
                            $response['id'] = self::parse_import_data($sidebar_data) ? true : new WP_Error('widget_import_submit', 'Unknown Error');
                        }
                        /**
                         * Read uploaded JSON file
                         * @return type
                         */
                        public static function get_widget_settings_json()
                        {
                            $up_file = get_template_directory() . '/docs/import/widget_data.json';
                            $file_contents = file_get_contents($up_file);
                            return array($file_contents, $up_file);
                        }
                        /**
                         *
                         * @param string $widget_name
                         * @param string $widget_index
                         * @return string
                         */
                        public static function get_new_widget_name($widget_name, $widget_index)
                        {
                            $current_sidebars = get_option('sidebars_widgets');
                            $all_widget_array = array();
                            foreach ($current_sidebars as $sidebar => $widgets) {
                                if (!empty($widgets) && is_array($widgets) && $sidebar != 'wp_inactive_widgets') {
                                    foreach ($widgets as $widget) {
                                        $all_widget_array[] = $widget;
                                    }
                                }
                            }
                            while (in_array($widget_name . '-' . $widget_index, $all_widget_array)) {
                                $widget_index++;
                            }
                            $new_widget_name = $widget_name . '-' . $widget_index;
                            return $new_widget_name;
                        }
                        /**
                         *
                         * @global type $wp_registered_sidebars
                         * @param type $sidebar_id
                         * @return boolean
                         */
                        public static function get_sidebar_info($sidebar_id)
                        {
                            global $wp_registered_sidebars;
                            //since wp_inactive_widget is only used in widgets.php
                            if ($sidebar_id == 'wp_inactive_widgets') {
                                return array('name' => 'Inactive Widgets', 'id' => 'wp_inactive_widgets');
                            }
                            foreach ($wp_registered_sidebars as $sidebar) {
                                if (isset($sidebar['id']) && $sidebar['id'] == $sidebar_id) {
                                    return $sidebar;
                                }
                            }
                            return false;
                        }
                        /**
                         *
                         * @param array $sidebar_widgets
                         * @return type
                         */
                        public static function order_sidebar_widgets($sidebar_widgets)
                        {
                            $inactive_widgets = false;
                            //seperate inactive widget sidebar from other sidebars so it can be moved to the end of the array, if it exists
                            if (isset($sidebar_widgets['wp_inactive_widgets'])) {
                                $inactive_widgets = $sidebar_widgets['wp_inactive_widgets'];
                                unset($sidebar_widgets['wp_inactive_widgets']);
                                $sidebar_widgets['wp_inactive_widgets'] = $inactive_widgets;
                            }
                            return $sidebar_widgets;
                        }
                    }
                    ob_start();
                    $importer = new Widget_Data_Importer();
                    $importer->ajax_import_widget_data();
                    $con = ob_get_contents();
                    ob_end_clean();
                    $v3 = '1';
                }
            }
            $logo_old = '';
            $bg_old = $data['bg_old'];
            $favi_old = '';
            if ($data['upload_logo'] && $data['upload_logo'] != '') {
                $upload_logo = esc_attr($data['upload_logo']);
                $remove_logo = '';
                if ($remove_logo == 'yes') {
                    $upload_logo = '';
                }
                if ($upload_logo != $logo_old && $upload_logo != '') {
                    update_option('cb4_upload_logo', $upload_logo);
                }
            }
            if ($data['upload_bg'] && $data['upload_bg'] != '') {
                $upload_bg = esc_attr($data['upload_bg']);
                if (!isset($data['remove_bg'])) {
                    $data['remove_bg'] = '';
                }
                $remove_bg = esc_attr($data['remove_bg']);
                if ($remove_bg == 'yes') {
                    $upload_bg = '';
                }
                update_option('cb4_upload_bg', $upload_bg);
            }
            if ($data['middle_backgroundi'] && $data['middle_backgroundi'] != '') {
                $middle_backgroundi = esc_attr($data['middle_backgroundi']);
                if (!isset($data['remove_bgi'])) {
                    $data['remove_bgi'] = '';
                }
                $remove_bgi = esc_attr($data['remove_bgi']);
                if ($remove_bgi == 'yes') {
                    $middle_backgroundi = '';
                }
                update_option('cb4_middle_backgroundi', $middle_backgroundi);
            }
            if ($data['favi'] && $data['favi'] != '') {
                $favi = esc_attr($data['favi']);
                if ($favi != $favi_old && $favi != '') {
                    update_option('cb4_favi', $favi);
                }
            }
            $dda = '1';
            if ($v3 == '1') {
                $dda = '3';
            } else {
                $dda = '1';
            }
            die($dda);
        }
Example #5
0
 function import_xml_ajax()
 {
     require_once TT_FW_DIR . '/extensions/autoimport/autoimporter.php';
     if (!class_exists('Auto_Importer')) {
         die('Auto_Importer not found');
     }
     // call the function
     $args = array('file' => TT_THEME_DIR . '/theme_config/import.xml', 'map_user_id' => 1);
     auto_import($args);
 }
Example #6
0
/** 
* Conditionals to display posts/search/archive/tags/category/importer on front end of website
* 
* @return void
*/
function blog_display_posts()
{
    global $content, $blogSettings;
    $Blog = new Blog();
    $slug = base64_encode(return_page_slug());
    $blogSettings = $Blog->getSettingsData();
    $blog_slug = base64_encode($blogSettings["blogurl"]);
    if ($slug == $blog_slug) {
        $content = '';
        ob_start();
        if ($blogSettings["displaycss"] == 'Y') {
            echo "<style>\n";
            echo $blogSettings["csscode"];
            echo "\n</style>";
        }
        switch (true) {
            case isset($_GET['post']) == true:
                $post_file = BLOGPOSTSFOLDER . $_GET['post'] . '.xml';
                show_blog_post($post_file);
                break;
            case isset($_POST['search_blog']) == true:
                search_posts($_POST['keyphrase']);
                break;
            case isset($_GET['archive']) == true:
                $archive = $_GET['archive'];
                show_blog_archive($archive);
                break;
            case isset($_GET['tag']) == true:
                $tag = $_GET['tag'];
                show_blog_tag($tag);
                break;
            case isset($_GET['category']) == true:
                $category = $_GET['category'];
                show_blog_category($category);
                break;
            case isset($_GET['import']):
                auto_import();
                break;
            default:
                show_all_blog_posts();
                break;
        }
        $content = ob_get_contents();
        ob_end_clean();
    }
    return $content;
    // legacy support for non filter hook calls to this function
}
Example #7
0
function hnm_import_data()
{
    require_once get_template_directory() . '/includes/import/class-importer.php';
    if (!class_exists('Auto_Importer')) {
        die('Auto_Importer not found');
    }
    $args = array('file' => get_template_directory() . '/includes/import/data.xml', 'map_user_id' => 1);
    auto_import($args);
}