/**
  * Import widgets and set necessary settings
  *
  * Import last step
  *
  * @since 1.0.0
  */
 function import_json()
 {
     do_action('cherry_plugin_import_json');
     if ($this->tools->is_package_install()) {
         $this->install_complete();
     }
     $this->remap_option_ids();
     $this->remap_slider_ids();
     $widgets_file = 'widgets.json';
     if (isset($_POST['file']) && $_POST['file']) {
         $widgets_file = $_POST['file'];
     }
     if (class_exists('Cherry_Options_Framework')) {
         $options_framework = Cherry_Options_Framework::get_instance();
         $options_framework->restore_default_settings_array();
     }
     $upload_dir = cherry_dm_get_upload_path();
     $json = $this->tools->get_contents($upload_dir . $widgets_file);
     if (false == $json) {
         $this->install_complete();
     }
     $upload_dir = wp_upload_dir();
     $upload_url = $upload_dir['url'] . '/';
     $json = preg_replace(array('/http:.[^\'\\"]*wp-content.[^\'\\"]*\\/(.[^\\/\'\\"]*\\.(?:jp[e]?g|png|mp4|ogg|webm))/', '/\\[template_url\\].{2}wp-content.[^\'\\"]*\\/(.[^\\/\'\\"]*\\.(?:jp[e]?g|png|mp4|ogg|webm))/'), array(trim(json_encode($upload_url . '$1'), "\""), trim(json_encode(str_replace(get_bloginfo('url'), '[template_url]', $upload_url) . '$1'), "\"")), $json);
     if (is_wp_error($json)) {
         exit('error');
     }
     $json_data = json_decode($json, true);
     $sidebar_data = $json_data[0];
     $widget_data = $json_data[1];
     if (!is_array($widget_data)) {
         $this->install_complete();
     }
     foreach ($widget_data as $widget_title => $widget_value) {
         if (!is_array($widget_value)) {
             continue;
         }
         foreach ($widget_value as $widget_key => $widget_value) {
             // fix for nav_menu widget
             if ('nav_menu' == $widget_title) {
                 if (is_array($widget_data[$widget_title][$widget_key])) {
                     if (array_key_exists('nav_menu_slug', $widget_data[$widget_title][$widget_key])) {
                         $nav_menu_slug = $widget_data[$widget_title][$widget_key]['nav_menu_slug'];
                         $term_id = term_exists($nav_menu_slug, 'nav_menu');
                         if ($term_id) {
                             if (is_array($term_id)) {
                                 $term_id = $term_id['term_id'];
                             }
                             $widget_data['nav_menu'][$widget_key]['nav_menu'] = $term_id;
                         }
                     }
                 }
             }
         }
     }
     $sidebar_data = array(array_filter($sidebar_data), $widget_data);
     if ($this->parse_widgets_data($sidebar_data)) {
         $this->install_complete();
     } else {
         exit('error');
     }
 }
function cherry_get_options($name)
{
    $options_framework = Cherry_Options_Framework::get_instance();
    return $options_framework->get_option_values($name);
}
 /**
  * Import widgets and set necessary settings
  *
  * Import last step
  *
  * @since 1.0.0
  */
 function import_json()
 {
     do_action('cherry_plugin_import_json');
     $this->remap_option_ids();
     $widgets_file = 'widgets.json';
     if (isset($_POST['file']) && $_POST['file']) {
         $widgets_file = $_POST['file'];
     }
     if (class_exists('Cherry_Options_Framework')) {
         $options_framework = Cherry_Options_Framework::get_instance();
         $options_framework->restore_default_settings_array();
     }
     $upload_dir = cherry_dm_get_upload_path();
     if (!file_exists($upload_dir . $widgets_file)) {
         exit('import_end');
     }
     $json = file_get_contents($upload_dir . $widgets_file);
     $_SESSION['files_to_remove'][] = $upload_dir . $widgets_file;
     $upload_dir = wp_upload_dir();
     $upload_url = $upload_dir['url'] . '/';
     $json = preg_replace('/http:.[^\'\\"]*wp-content.[^\'\\"]*\\/(.[^\\/\'\\"]*\\.(?:jp[e]?g|png))/', trim(json_encode($upload_url . '$1'), "\""), $json);
     if (is_wp_error($json)) {
         exit('error');
     }
     $json_data = json_decode($json, true);
     $sidebar_data = $json_data[0];
     $widget_data = $json_data[1];
     $rules_data = isset($json_data[2]) ? $json_data[2] : array();
     // get option value
     $themename = 'cherry';
     $options_type = get_option($themename . '_widget_rules_type');
     $options = get_option($themename . '_widget_rules');
     $custom_class = get_option($themename . '_widget_custom_class');
     $responsive = get_option($themename . '_widget_responsive');
     $users = get_option($themename . '_widget_users');
     // if this option is set at first time
     if (!is_array($options_type)) {
         $options_type = array();
     }
     // if this option is set at first time
     if (!is_array($options)) {
         $options = array();
     }
     // if this responsive is set at first time
     if (!is_array($responsive)) {
         $responsive = array();
     }
     // if this users is set at first time
     if (!is_array($users)) {
         $users = array();
     }
     if (!empty($rules_data) && is_array($rules_data)) {
         $new = array('widget_responsive');
         foreach ($rules_data as $key => $value) {
             foreach ($value as $val) {
                 $new[$key] = $val;
             }
         }
         $new['widget_responsive'] = isset($new['widget_responsive']) ? $new['widget_responsive'] : array();
         $options_type_new = array_merge($options_type, $new['widget_rules_type']);
         $options_new = array_merge($options, $new['widget_rules']);
         $custom_class_new = $new['widget_custom_class'];
         $responsive_new = array_merge($responsive, $new['widget_responsive']);
         $users_new = array_merge($users, $new['widget_users']);
         // update option
         update_option($themename . '_widget_rules_type', $options_type_new);
         update_option($themename . '_widget_rules', $options_new);
         update_option($themename . '_widget_custom_class', $custom_class_new);
         update_option($themename . '_widget_responsive' . $key, $responsive_new);
         update_option($themename . '_widget_users', $users_new);
     }
     if (!is_array($widget_data)) {
         exit('import_end');
     }
     foreach ($widget_data as $widget_title => $widget_value) {
         if (!is_array($widget_value)) {
             continue;
         }
         foreach ($widget_value as $widget_key => $widget_value) {
             // fix for nav_menu widget
             if ('nav_menu' == $widget_title) {
                 if (is_array($widget_data[$widget_title][$widget_key])) {
                     if (array_key_exists('nav_menu_slug', $widget_data[$widget_title][$widget_key])) {
                         $nav_menu_slug = $widget_data[$widget_title][$widget_key]['nav_menu_slug'];
                         $term_id = term_exists($nav_menu_slug, 'nav_menu');
                         if ($term_id) {
                             if (is_array($term_id)) {
                                 $term_id = $term_id['term_id'];
                             }
                             $widget_data['nav_menu'][$widget_key]['nav_menu'] = $term_id;
                         }
                     }
                 }
             }
         }
     }
     $sidebar_data = array(array_filter($sidebar_data), $widget_data);
     if ($this->parse_widgets_data($sidebar_data)) {
         /**
          * Hook fires after successfull demo content installation
          */
         do_action('cherry_data_manager_install_complete');
         if (!empty($_SESSION['files_to_remove'])) {
             foreach ($_SESSION['files_to_remove'] as $file) {
                 if (file_exists($file)) {
                     unlink($file);
                 }
             }
             unset($_SESSION['files_to_remove']);
         }
         exit('import_end');
     } else {
         exit('error');
     }
 }