/** * Get import action URL * * @since 1.0.0 * @return string Import action URL */ function cherry_dm_get_import_action_url() { global $cherry_data_manager; $upload_dir = cherry_dm_get_upload_path(); $upload_nonce = wp_create_nonce('cherry_dm_content_upload'); return apply_filters('cherry_data_manager_import_action', add_query_arg(array('action' => 'cherry_dm_content_handle_load', 'dir' => urlencode($upload_dir), '_wpnonce' => $upload_nonce), admin_url('admin-ajax.php'))); }
/** * Include assets * * @since 1.0.0 */ function assets() { wp_enqueue_style('cherry-ui-elements', CHERRY_DATA_MANAGER_URI . 'assets/css/cherry-ui.css', array(), '1.0.0'); wp_enqueue_style($this->slug . '-style', CHERRY_DATA_MANAGER_URI . 'assets/css/style.css', '', CHERRY_DATA_MANAGER_VERSION); if ($this->is_manager_page($this->import_page)) { wp_deregister_script('heartbeat'); wp_enqueue_script($this->slug . '-importer', CHERRY_DATA_MANAGER_URI . 'assets/js/importer.js', array('jquery'), CHERRY_DATA_MANAGER_VERSION, true); wp_localize_script($this->slug . '-importer', 'cherry_data_manager_ajax', array('nonce' => wp_create_nonce('cherry_data_manager_ajax'))); $autoload = !empty($_SESSION['cherry_data']['sample']) ? 'yes' : 'no'; // setup js trigger for manual/automatic upload wp_localize_script($this->slug . '-importer', 'cherry_dm_import_trigger', array('autoload' => apply_filters('cherry_data_manager_content_autoload', $autoload))); // setup localized data for importer $import_texts = array('error_upload' => __('Upload Error', $this->slug), 'error_size' => __('The file is too big!', $this->slug), 'error_type' => __('The file type is error!', $this->slug), 'error_folder' => __('Folder cannot be uploaded!', $this->slug), 'uploading' => __('Uploading', $this->slug), 'upload' => __('Upload', $this->slug), 'upload_complete' => __('Upload Complete', $this->slug), 'item' => __('item', $this->slug), 'items' => __('items', $this->slug), 'uploaded_status_text' => __('Sample data installing. Some steps may take some time depending on your server settings. Please be patient.', $this->slug), 'uploaded_status_text_1' => __('Upload complete please click Continue Install button to proceed.', $this->slug), 'import_xml' => __('Importing XML', $this->slug), 'import_options' => __('Importing options', $this->slug), 'import_custom_tables' => __('Importing custom database tables', $this->slug), 'import_categories' => __('Importing categories', $this->slug), 'import_tags' => __('Importing tags', $this->slug), 'process_terms' => __('Processing dependencies', $this->slug), 'import_posts' => __('Importing posts. This may take some time. Please wait.', $this->slug), 'attach_terms' => __('Attaching terms to imported posts. This may take some time. Please wait.', $this->slug), 'attach_comments' => __('Attaching comments to imported posts. This may take some time. Please wait.', $this->slug), 'attach_postmeta' => __('Attaching metadata to imported posts. This may take some time. Please wait.', $this->slug), 'import_menu_item' => __('Importing menu items. This may take some time. Please wait.', $this->slug), 'import_attachment' => __('Importing media library.', $this->slug), 'import_attachment_metadata' => __('Importing attachements meta.', $this->slug), 'generate_attachment_metadata_step_1' => __('Generate attachements meta. Preparing. This may take some time. Please wait.', $this->slug), 'generate_attachment_metadata_step_2' => __('Generate attachements meta. Processing. This may take some time. Please wait.', $this->slug), 'generate_attachment_metadata_step_3' => __('Generate attachements meta. Finishing. This may take some time. Please wait.', $this->slug), 'generate_attachment_metadata_step_4' => __('Cropping attachements meta. Preparing. This may take some time. Please wait.', $this->slug), 'generate_attachment_metadata_step_5' => __('Cropping attachements meta. Processing. This may take some time. Please wait.', $this->slug), 'generate_attachment_metadata_step_6' => __('Cropping attachements meta. Finishing. This may take some time. Please wait.', $this->slug), 'import_parents' => __('Generating content hierarchy', $this->slug), 'update_featured_images' => __('Updating featured images', $this->slug), 'update_attachment' => __('Updating attachments', $this->slug), 'import_json' => __('Importing JSON', $this->slug), 'import_complete' => __('Installing content complete', $this->slug), 'instal_error' => __('Installing content error', $this->slug), 'confirm_load' => __("ATTENTION! Installing Sample Data will overwrite your current content.\nSo we don't recommend you to install Sample Data on a live website.\n\nClick OK to proceed", $this->slug)); wp_localize_script($this->slug . '-importer', 'cherry_dm_import_texts', $import_texts); // setup additional JS varaibles for importer $max_size = cherry_dm_get_upload_size(); $upload_dir = cherry_dm_get_upload_path(); $action_url = cherry_dm_get_import_action_url(); if (isset($_GET['type'])) { $type = $_GET['type']; } else { $type = 'demo'; } $import_vars = array('max_file_size' => $max_size['size'], 'action_url' => $action_url, 'type' => $type, 'nonce' => wp_create_nonce('cherry-dm-nonce')); wp_localize_script($this->slug . '-importer', 'cherry_dm_import_vars', $import_vars); } if ($this->is_manager_page($this->export_page)) { wp_enqueue_script($this->slug . '-exporter', CHERRY_DATA_MANAGER_URI . 'assets/js/exporter.js', array('jquery'), CHERRY_DATA_MANAGER_VERSION, true); } }
/** * 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'); } }
/** * process automatic file upload from TM cloud * * @since 1.0.0 */ public function process_auto_upload() { //make sure request is comming from Ajax $xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; if (!$xhr) { header('HTTP/1.1 500 Error: Request must come from Ajax!'); exit; } if (!wp_verify_nonce($_REQUEST['nonce'], 'cherry-dm-nonce')) { } global $cherry_data_manager; ob_start(); $response = array('type' => 'error'); /** * Filter sample data remote link * * @since 1.0.9 * @param string $url remote sample data URL */ $url = apply_filters('cherry_data_manager_cloud_sample_data_url', false); if (!$url) { if (!isset($_SESSION['cherry_data']['sample'])) { $response['message'] = __('Can\'t find link to sample data', $cherry_data_manager->slug); ob_clean(); wp_send_json($response); } $url = $_SESSION['cherry_data']['sample']; } $res = $this->fs_connect(array(cherry_dm_get_upload_path())); if (!$res) { $response['message'] = __('Can\'t connect to file system', $cherry_data_manager->slug); ob_clean(); wp_send_json($response); } $download = $this->download_package($url); $working_dir = $this->unpack_package($download, true); $response['type'] = 'success'; $response['message'] = __('File imported', $cherry_data_manager->slug); ob_clean(); wp_send_json($response); }
/** * 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'); } }