コード例 #1
0
/**
 * Custom Export function for Module Manager.
 *
 * Exports selected items (by ID) and of specified type (eg views, view-templates).
 * Returns xml string.
 *
 * @global type $iclTranslationManagement
 * @param array $items
 * @param type $_type
 * @param type $return mixed array|xml|download
 * @return string
 */
function wpcf_admin_export_selected_data(array $items, $_type = 'all', $return = 'download', $use_cache = false)
{
    global $wpcf;
    require_once WPCF_EMBEDDED_ABSPATH . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    $data['settings'] = wpcf_get_settings();
    if ('user_groups' == $_type || 'all' == $_type) {
        // Get groups
        if (empty($items)) {
            $groups = get_posts('post_type=wp-types-user-group&post_status=null&numberposts=-1');
        } else {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            foreach ($items as $k => $item) {
                if (isset($item['id'])) {
                    $items[$k] = intval(wpcf_modman_get_submitted_id('groups', $item['id']));
                }
            }
            $args = array('post__in' => $items, 'post_type' => 'wp-types-user-group', 'post_status' => 'all', 'posts_per_page' => -1);
            $groups = get_posts($args);
        }
        if (!empty($groups)) {
            $data['user_groups'] = array('__key' => 'group');
            foreach ($groups as $key => $post) {
                $post = (array) $post;
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $_data = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $_meta = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if (in_array($meta_key, array('_wp_types_group_showfor', '_wp_types_group_fields', '_wp_types_group_admin_styles'))) {
                            $_meta[$meta_key] = $meta_value[0];
                        }
                    }
                    if (!empty($_meta)) {
                        $_data['meta'] = $_meta;
                    }
                }
                $_data['checksum'] = $_data['hash'] = $wpcf->export->generate_checksum('group', $post['ID']);
                $_data['__types_id'] = $post['post_name'];
                $_data['__types_title'] = $post['post_title'];
                $data['user_groups']['group-' . $post['ID']] = $_data;
            }
        }
        if (!empty($items)) {
            // Get fields by group
            // TODO Document why we use by_group
            $fields = array();
            foreach ($groups as $key => $post) {
                $fields = array_merge($fields, wpcf_admin_fields_get_fields_by_group($post->ID, 'slug', false, false, false, 'wp-types-user-group', 'wpcf-usermeta', $use_cache));
            }
        } else {
            // Get fields
            $fields = wpcf_admin_fields_get_fields(false, false, false, 'wpcf-usermeta');
        }
        if (!empty($fields)) {
            // Add checksums before WPML
            foreach ($fields as $field_id => $field) {
                // TODO WPML and others should use hook
                $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
                $fields[$field_id]['__types_id'] = $field_id;
                $fields[$field_id]['__types_title'] = $field['name'];
                $fields[$field_id]['checksum'] = $fields[$field_id]['hash'] = $wpcf->export->generate_checksum('field', $field_id);
            }
            // WPML
            global $iclTranslationManagement;
            if (!empty($iclTranslationManagement)) {
                foreach ($fields as $field_id => $field) {
                    // TODO Check this for all fields
                    if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                        $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                    }
                }
            }
            $data['user_fields'] = $fields;
            $data['user_fields']['__key'] = 'field';
        }
    }
    if ('groups' == $_type || 'all' == $_type) {
        // Get groups
        if (empty($items)) {
            $groups = get_posts('post_type=wp-types-group&post_status=null&numberposts=-1');
        } else {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            foreach ($items as $k => $item) {
                if (isset($item['id'])) {
                    $items[$k] = intval(wpcf_modman_get_submitted_id('groups', $item['id']));
                }
            }
            $args = array('post__in' => $items, 'post_type' => 'wp-types-group', 'post_status' => 'all', 'posts_per_page' => -1);
            $groups = get_posts($args);
        }
        if (!empty($groups)) {
            $data['groups'] = array('__key' => 'group');
            foreach ($groups as $key => $post) {
                $post = (array) $post;
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $_data = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $_meta = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if (in_array($meta_key, array('_wp_types_group_terms', '_wp_types_group_post_types', '_wp_types_group_fields', '_wp_types_group_templates', '_wpcf_conditional_display', '_wp_types_group_filters_association', '_wp_types_group_admin_styles'))) {
                            $_meta[$meta_key] = $meta_value[0];
                            $_meta[$meta_key] = maybe_unserialize($_meta[$meta_key]);
                        }
                    }
                    if (!empty($_meta)) {
                        $_data['meta'] = $_meta;
                    }
                }
                $_data['checksum'] = $_data['hash'] = $wpcf->export->generate_checksum('group', $post['ID']);
                $_data['__types_id'] = $post['post_name'];
                $_data['__types_title'] = $post['post_title'];
                $data['groups']['group-' . $post['ID']] = $_data;
            }
        }
        if (!empty($items)) {
            // Get fields by group
            // TODO Document why we use by_group
            $fields = array();
            foreach ($groups as $key => $post) {
                $fields = array_merge($fields, wpcf_admin_fields_get_fields_by_group($post->ID, 'slug', false, false, false, 'wp-types-group', 'wpcf-fields', $use_cache));
            }
        } else {
            // Get fields
            $fields = wpcf_admin_fields_get_fields();
        }
        if (!empty($fields)) {
            // Add checksums before WPML
            foreach ($fields as $field_id => $field) {
                // TODO WPML and others should use hook
                $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
                $fields[$field_id]['__types_id'] = $field_id;
                $fields[$field_id]['__types_title'] = $field['name'];
                $fields[$field_id]['checksum'] = $fields[$field_id]['hash'] = $wpcf->export->generate_checksum('field', $field_id);
            }
            // WPML
            global $iclTranslationManagement;
            if (!empty($iclTranslationManagement)) {
                foreach ($fields as $field_id => $field) {
                    // TODO Check this for all fields
                    if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                        $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                    }
                }
            }
            $data['fields'] = $fields;
            $data['fields']['__key'] = 'field';
        }
    }
    // Get custom types
    if ('types' == $_type || 'all' == $_type) {
        // Get custom types
        // TODO Document $items
        if (!empty($items)) {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            //            $custom_types = array_intersect_key( get_option( 'wpcf-custom-types',
            //                            array() ), array_flip( $items ) );
            $_items = array();
            foreach ($items as $k => $item) {
                if (is_array($item) && isset($item['id'])) {
                    $_items[$item['id']] = true;
                } else {
                    $_items[$item] = true;
                }
            }
            $custom_types = array_intersect_key(get_option('wpcf-custom-types', array()), $_items);
        } else {
            $custom_types = get_option('wpcf-custom-types', array());
        }
        // Get custom types
        if (!empty($custom_types)) {
            foreach ($custom_types as $key => $type) {
                $custom_types[$key]['id'] = $key;
                $custom_types[$key] = apply_filters('wpcf_export_custom_post_type', $custom_types[$key]);
                $custom_types[$key]['__types_id'] = $key;
                $custom_types[$key]['__types_title'] = $type['labels']['name'];
                $custom_types[$key]['checksum'] = $custom_types[$key]['hash'] = $wpcf->export->generate_checksum('custom_post_type', $key, $type);
            }
            $data['types'] = $custom_types;
            $data['types']['__key'] = 'type';
        }
        if (!empty($items)) {
            // Get post relationships only for items
            $relationships_all = get_option('wpcf_post_relationship', array());
            $relationships = array();
            foreach ($relationships_all as $parent => $children) {
                if (in_array($parent, $items)) {
                    foreach ($children as $child => $childdata) {
                        if (in_array($child, $items)) {
                            if (!isset($relationships[$parent])) {
                                $relationships[$parent] = array();
                            }
                            $relationships[$parent][$child] = $childdata;
                        }
                    }
                }
            }
        } else {
            // Get post relationships
            $relationships = get_option('wpcf_post_relationship', array());
        }
        if (!empty($relationships)) {
            $data['post_relationships']['data'] = json_encode($relationships);
        }
    }
    // Get custom tax
    if ('taxonomies' == $_type || 'all' == $_type) {
        if (!empty($items)) {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            //            $custom_taxonomies = array_intersect_key( get_option( 'wpcf-custom-taxonomies',
            //                            array() ), array_flip( $items ) );
            $_items = array();
            foreach ($items as $k => $item) {
                if (is_array($item) && isset($item['id'])) {
                    $_items[$item['id']] = true;
                } else {
                    $_items[$item] = true;
                }
            }
            $custom_taxonomies = array_intersect_key(get_option('wpcf-custom-taxonomies', array()), $_items);
        } else {
            // Get custom tax
            $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
        }
        if (!empty($custom_taxonomies)) {
            foreach ($custom_taxonomies as $key => $tax) {
                $custom_taxonomies[$key]['id'] = $key;
                $custom_taxonomies[$key] = apply_filters('wpcf_export_custom_post_type', $custom_taxonomies[$key]);
                $custom_taxonomies[$key]['__types_id'] = $key;
                $custom_taxonomies[$key]['__types_title'] = $tax['labels']['name'];
                $custom_taxonomies[$key]['checksum'] = $wpcf->export->generate_checksum('custom_taxonomy', $key, $tax);
            }
            $data['taxonomies'] = $custom_taxonomies;
            $data['taxonomies']['__key'] = 'taxonomy';
        }
    }
    /*
     *
     * Since Types 1.2
     */
    if ($return == 'array') {
        return $data;
    } else {
        if ($return == 'xml') {
            return $xml->array2xml($data, 'types');
        } else {
            if ($return == 'module_manager') {
                $items = array();
                // Re-arrange fields
                if (!empty($data['fields'])) {
                    foreach ($data['fields'] as $_data) {
                        if (is_array($_data) && isset($_data['__types_id']) && isset($_data['checksum'])) {
                            $_item = array();
                            $_item['hash'] = $_item['checksum'] = $_data['checksum'];
                            $_item['id'] = $_data['__types_id'];
                            $_item['title'] = $_data['__types_title'];
                            $items['__fields'][$_data['__types_id']] = $_item;
                        }
                    }
                }
                // Add checksums to items
                foreach ($data as $_t => $type) {
                    foreach ($type as $_data) {
                        // Skip fields
                        if ($_t == 'fields') {
                            continue;
                        }
                        if (is_array($_data) && isset($_data['__types_id']) && isset($_data['checksum'])) {
                            $_item = array();
                            $_item['hash'] = $_item['checksum'] = $_data['checksum'];
                            $_item['id'] = $_data['__types_id'];
                            $_item['title'] = $_data['__types_title'];
                            $items[$_data['__types_id']] = $_item;
                        }
                    }
                }
                return array('xml' => $xml->array2xml($data, 'types'), 'items' => $items);
            }
        }
    }
    // Offer for download
    $data = $xml->array2xml($data, 'types');
    $sitename = sanitize_title(get_bloginfo('name'));
    if (empty($sitename)) {
        $sitename = 'wp';
    }
    $sitename .= '.';
    $filename = $sitename . 'types.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['embedded-settings']) && $_POST['embedded-settings'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    $code .= "\r\n?" . ">";
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'types.' . date('Y-m-d') . '.zip';
        $temp_dir = wpcf_get_temporary_directory();
        if (empty($temp_dir)) {
            die(__('There is a problem with temporary directory.'));
        }
        $file = tempnam($temp_dir, "zip");
        $zip = new ZipArchive();
        $zip->open($file, ZipArchive::OVERWRITE);
        /**
         * if sys_get_temp_dir fail in case of open_basedir restriction,
         * try use wp_upload_dir instead. if this fail too, send pure
         * xml file to user
         */
        if (empty($zip->filename)) {
            $temp_dir = wp_upload_dir();
            $temp_dir = $temp_dir['basedir'];
            $file = tempnam($temp_dir, "zip");
            $zip = new ZipArchive();
            $zip->open($file, ZipArchive::OVERWRITE);
        }
        /**
         * send a zip file
         */
        if (!empty($zip->filename)) {
            $zip->addFromString('settings.xml', $data);
            $zip->addFromString('settings.php', $code);
            $zip->close();
            $data = file_get_contents($file);
            header("Content-Description: File Transfer");
            header("Content-Disposition: attachment; filename=" . $zipname);
            header("Content-Type: application/zip");
            header("Content-length: " . strlen($data) . "\n\n");
            header("Content-Transfer-Encoding: binary");
            echo $data;
            unlink($file);
            die;
        }
    }
    /**
     * download the xml if fail downloading zip
     */
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=" . $filename);
    header("Content-Type: application/xml");
    header("Content-length: " . strlen($data) . "\n\n");
    echo $data;
    die;
}
コード例 #2
0
/**
* wpv_admin_export_selected_data
*
* Custom Export function for Module Manager - Exports selected items (by ID) and of specified type (eg views, view-templates)
*
* Note: whatever chage done here must be done too in wpv_admin_export_data()
*
* @param $items 'all' returns all items | array() to be used in post__in argument
* @param $type 'view' | 'view-template'
* @param $mode 'xml' returns a string to be converted to XML | 'module_manager' returns an array() compatible with Module Manager export
*
* @return mixed xml-string or array()
+
* @since 1.2.0
*/
function wpv_admin_export_selected_data($items, $type = 'view', $mode = 'xml')
{
    global $wpdb, $WPV_settings, $_wp_additional_image_sizes;
    require_once WPV_PATH_EMBEDDED . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    $items_hash = array();
    $export = false;
    // flag
    // SRDJAN - add siteurl, upload url, record taxonomies old IDs
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382866/comments
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142389966/comments
    //    $data['site_url'] = get_site_url();
    // TODO this might not be needed, it's not used here
    if (is_multisite()) {
        $upload_directory = get_option('fileupload_url');
    } else {
        $wp_upload_dir = wp_upload_dir();
        $upload_directory = $wp_upload_dir['baseurl'];
    }
    // Basic arguments for the query
    $args = array('posts_per_page' => -1, 'post_status' => 'any');
    // Adjust names
    $view_types = array('view' => array('key' => 'views'), 'view-template' => array('key' => 'view-templates'));
    // Set what to export and the post__in query arg if needed
    if (is_string($items) && 'all' === $items) {
        $export = true;
    } elseif (is_array($items) && !empty($items)) {
        $args['post__in'] = $items;
        $export = true;
    }
    // Check we are exporting the right type and then set the post_type query arg
    if (!in_array($type, array_keys($view_types))) {
        $export = false;
    } else {
        $args['post_type'] = $type;
        $vkey = $view_types[$type]['key'];
    }
    // Return if we won't export
    if (!$export) {
        return '';
    }
    /**
     * wpv_filter_view_extra_fields_for_import_export
     *
     * Filter set the postmeta needed for Views export and import, beyond the settings and layout settings
     *
     * @param (array) The postmeta keys
     *
     * @since 1.7
     */
    $extra_metas = apply_filters('wpv_filter_view_extra_fields_for_import_export', array());
    // Start collecting data to export
    switch ($type) {
        // If exporting Views
        case 'view':
            // Get the views
            $views = get_posts($args);
            if (!empty($views)) {
                // Compose the image size array
                if (!isset($_wp_additional_image_sizes) || !is_array($_wp_additional_image_sizes)) {
                    $_wp_additional_image_sizes = array();
                }
                $attached_images_sizes = array_merge(array_keys($_wp_additional_image_sizes), array('thumbnail', 'medium', 'large'));
                // Create the data['views'] array
                $data['views'] = array('__key' => 'view');
                // Loop through the returned Views to take their data
                foreach ($views as $key => $post) {
                    $post = (array) $post;
                    // Only export items with post_name
                    if ($post['post_name']) {
                        $hash_data = array();
                        $post_data = array();
                        $this_settings = array();
                        $this_layout_settings = array();
                        $this_settings_metaboxes = array('filter_meta_html', 'filter_meta_html_css', 'filter_meta_html_js', 'layout_meta_html_css', 'layout_meta_html_js');
                        $this_layout_settings_metaboxes = array('layout_meta_html');
                        // Basic data
                        $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                        foreach ($copy_data as $copy) {
                            if (isset($post[$copy])) {
                                $post_data[$copy] = $post[$copy];
                            }
                        }
                        $data['views']['view-' . $post['ID']] = $post_data;
                        $hash_basics = array('post_title', 'post_name', 'post_type', 'post_status');
                        foreach ($hash_basics as $basics) {
                            if (isset($data['views']['view-' . $post['ID']][$basics])) {
                                $hash_data[$basics] = $data['views']['view-' . $post['ID']][$basics];
                            }
                        }
                        if (isset($data['views']['view-' . $post['ID']]['post_content'])) {
                            $hash_data['post_content'] = preg_replace('/\\s+/', '', str_replace("\n", "", $data['views']['view-' . $post['ID']]['post_content']));
                        }
                        if (isset($data['views']['view-' . $post['ID']]['post_excerpt'])) {
                            $hash_data['post_excerpt'] = preg_replace('/\\s+/', '', str_replace("\n", "", $data['views']['view-' . $post['ID']]['post_excerpt']));
                        }
                        // Meta data
                        $meta = get_post_custom($post['ID']);
                        if (!empty($meta)) {
                            $data['view']['view-' . $post['ID']]['meta'] = array();
                            foreach ($meta as $meta_key => $meta_value) {
                                // View settings
                                if ($meta_key == '_wpv_settings') {
                                    $value = maybe_unserialize($meta_value[0]);
                                    $this_settings = $value;
                                    // Add any taxonomy terms so we can re-map when we import.
                                    if (!empty($value['taxonomy_terms'])) {
                                        $taxonomy = $value['taxonomy_type'][0];
                                        foreach ($value['taxonomy_terms'] as $term_id) {
                                            if (!isset($data['terms_map']['term_' . $term_id])) {
                                                $term = get_term($term_id, $taxonomy);
                                                if (isset($term) && !is_wp_error($term)) {
                                                    $data['terms_map']['term_' . $term->term_id]['old_id'] = $term->term_id;
                                                    $data['terms_map']['term_' . $term->term_id]['slug'] = $term->slug;
                                                    $data['terms_map']['term_' . $term->term_id]['taxonomy'] = $taxonomy;
                                                }
                                            }
                                        }
                                    }
                                    /**
                                     * wpv_filter_adjust_view_settings_for_export
                                     *
                                     * Filter to adjust Views settings on export
                                     *
                                     * Some View settings are stored as indexed arrays, producing errors on index 0
                                     * We need to transform those indexed arrays into associative arrays before export, that will be restored on import
                                     * Also, some settings contain IDs pointing to other Views or Content Templates
                                     * We need to transform them into names, that will be restored on import
                                     *
                                     * @param (array) $value The View settings
                                     * @param (array) $post The post object as an array
                                     *
                                     * @since 1.7
                                     */
                                    $value = apply_filters('wpv_filter_adjust_view_settings_for_export', $value, $post);
                                    // Add the data to export
                                    $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                                    // Add the hash for Module Manager if needed
                                    if ('module_manager' == $mode) {
                                        $hash_data['meta'][$meta_key] = $value;
                                        // Correct possible elements with changing format
                                        if (isset($value['taxonomy_hide_empty'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_hide_empty'] = strval($value['taxonomy_hide_empty']);
                                        }
                                        if (isset($value['taxonomy_include_non_empty_decendants'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_include_non_empty_decendants'] = strval($value['taxonomy_include_non_empty_decendants']);
                                        }
                                        if (isset($value['taxonomy_pad_counts'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_pad_counts'] = strval($value['taxonomy_pad_counts']);
                                        }
                                        if (isset($value['post_type_dont_include_current_page'])) {
                                            $hash_data['meta'][$meta_key]['post_type_dont_include_current_page'] = strval($value['post_type_dont_include_current_page']);
                                        }
                                        if (isset($value['pagination']['preload_images'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['preload_images'] = strval($value['pagination']['preload_images']);
                                        }
                                        if (isset($value['pagination']['cache_pages'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['cache_pages'] = strval($value['pagination']['cache_pages']);
                                        }
                                        if (isset($value['pagination']['preload_pages'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['preload_pages'] = strval($value['pagination']['preload_pages']);
                                        }
                                        if (isset($value['pagination']['spinner_image'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['spinner_image'] = basename($value['pagination']['spinner_image']);
                                        }
                                        if (isset($value['rollover']['preload_images'])) {
                                            $hash_data['meta'][$meta_key]['rollover']['preload_images'] = strval($value['rollover']['preload_images']);
                                        }
                                        if (isset($value['offset'])) {
                                            $hash_data['meta'][$meta_key]['offset'] = strval($value['offset']);
                                        }
                                        if (isset($value['taxonomy_offset'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_offset'] = strval($value['taxonomy_offset']);
                                        }
                                        if (isset($value['filter_meta_html'])) {
                                            $hash_data['meta'][$meta_key]['filter_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['filter_meta_html']));
                                        }
                                        if (isset($value['generated_filter_meta_html'])) {
                                            $hash_data['meta'][$meta_key]['generated_filter_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['generated_filter_meta_html']));
                                        }
                                        if (isset($value['filter_meta_html_css'])) {
                                            $hash_data['meta'][$meta_key]['filter_meta_html_css'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['filter_meta_html_css']));
                                        }
                                        if (isset($value['filter_meta_html_js'])) {
                                            $hash_data['meta'][$meta_key]['filter_meta_html_js'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['filter_meta_html_js']));
                                        }
                                        if (isset($value['layout_meta_html_css'])) {
                                            $hash_data['meta'][$meta_key]['layout_meta_html_css'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['layout_meta_html_css']));
                                        }
                                        if (isset($value['layout_meta_html_js'])) {
                                            $hash_data['meta'][$meta_key]['layout_meta_html_js'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['layout_meta_html_js']));
                                        }
                                        if (isset($value['author_mode'])) {
                                            $hash_data['meta'][$meta_key]['author_mode'] = reset($value['author_mode']);
                                        }
                                        if (isset($value['taxonomy_parent_mode'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_parent_mode'] = reset($value['taxonomy_parent_mode']);
                                        }
                                        if (isset($value['taxonomy_search_mode'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_search_mode'] = reset($value['taxonomy_search_mode']);
                                        }
                                        if (isset($value['search_mode'])) {
                                            $hash_data['meta'][$meta_key]['search_mode'] = reset($value['search_mode']);
                                        }
                                        if (isset($value['id_mode'])) {
                                            $hash_data['meta'][$meta_key]['id_mode'] = reset($value['id_mode']);
                                        }
                                        $cursed_array = array('filter_controls_enable', 'filter_controls_param', 'filter_controls_mode', 'filter_controls_field_name', 'filter_controls_label', 'filter_controls_type', 'filter_controls_values');
                                        foreach ($cursed_array as $cursed) {
                                            if (isset($hash_data['meta'][$meta_key][$cursed])) {
                                                unset($hash_data['meta'][$meta_key][$cursed]);
                                            }
                                        }
                                    }
                                } else {
                                    if ($meta_key == '_wpv_layout_settings') {
                                        $value = maybe_unserialize($meta_value[0]);
                                        $this_layout_settings = $value;
                                        /**
                                         * wpv_filter_adjust_view_layout_settings_for_export
                                         *
                                         * Filter to adjust Views layouts settings on export
                                         *
                                         * @param (array) $value The View layout settings
                                         * @param (array) $post The View post object as an array
                                         *
                                         * @since 1.7
                                         */
                                        $value = apply_filters('wpv_filter_adjust_view_layout_settings_for_export', $value, $post);
                                        // Add the data to export
                                        $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                                        // Add the hash for Module Manager if needed
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta'][$meta_key] = $value;
                                            if (isset($value['layout_meta_html'])) {
                                                $hash_data['meta'][$meta_key]['layout_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['layout_meta_html']));
                                            }
                                            if (isset($value['generated_layout_meta_html'])) {
                                                $hash_data['meta'][$meta_key]['generated_layout_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['generated_layout_meta_html']));
                                            }
                                        }
                                    } else {
                                        if (in_array($meta_key, $extra_metas)) {
                                            $value = maybe_unserialize($meta_value[0]);
                                            /**
                                             * wpv_filter_adjust_view_extra_fields_for_export
                                             *
                                             * Filter to adjust Views postmeta needed on export
                                             *
                                             * @param (array) $value The postmeta value
                                             * @param (array) $post The View post object as an array
                                             * @meta_key (string) The postmeta key being adjusted
                                             *
                                             * @since 1.7
                                             */
                                            $value = apply_filters('wpv_filter_adjust_view_extra_fields_for_export', $value, $post, $meta_key);
                                            if (!empty($value)) {
                                                $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                                            }
                                        }
                                    }
                                }
                            }
                            // If there is no settings, layout settings or description meta, unset the key
                            if (empty($data['views']['view-' . $post['ID']]['meta'])) {
                                unset($data['views']['view-' . $post['ID']]['meta']);
                            }
                        }
                        // Juan - add images for exporting
                        // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                        $att_args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post['ID']);
                        $attachments = get_posts($att_args);
                        if ($attachments) {
                            $data['views']['view-' . $post['ID']]['attachments'] = array();
                            if ('module_manager' == $mode) {
                                $hash_data['attachments'] = array();
                            }
                            foreach ($attachments as $attachment) {
                                $image_type = get_post_mime_type($attachment->ID);
                                if ($image_type && ($image_type == 'image/jpeg' || $image_type == 'image/png' || $image_type == 'image/gif')) {
                                    // Add the attachment to the exported data
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID] = array();
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['title'] = $attachment->post_title;
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['content'] = $attachment->post_content;
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['excerpt'] = $attachment->post_excerpt;
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['status'] = $attachment->post_status;
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['alt'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                                    $imdata = base64_encode(file_get_contents($attachment->guid));
                                    if ('module_manager' == $mode) {
                                        $hash_data['attachments'][] = md5($imdata);
                                    }
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['data'] = $imdata;
                                    preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $attachment->guid, $matches);
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['filename'] = basename($matches[0]);
                                    if (isset($this_settings['pagination']['spinner_image_uploaded']) && $attachment->guid == $this_settings['pagination']['spinner_image_uploaded']) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['custom_spinner'] = 'this';
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_settings']['pagination']['spinner_image_uploaded'] = md5($imdata);
                                        }
                                    }
                                    // Get the src for every attachment size
                                    $imthumbs = array();
                                    foreach ($attached_images_sizes as $ts) {
                                        $imthumbs[$ts] = wp_get_attachment_image_src($attachment->ID, $ts);
                                    }
                                    // @todo apply the same logic as in natural export
                                    // @todo use $this_settings_metaboxes and $this_layout_settings_metaboxes
                                    // Adjust the Filter MetaHTML content
                                    if (isset($this_settings['filter_meta_html'])) {
                                        $pos = strpos($this_settings['filter_meta_html'], $attachment->guid);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html'] = $attachment->guid;
                                            if ('module_manager' == $mode) {
                                                $hash_data['meta']['_wpv_settings']['filter_meta_html'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['filter_meta_html']);
                                            }
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($this_settings['filter_meta_html'], $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_sizes'][$thumbsize] = $thumbdata[0];
                                                    if ('module_manager' == $mode) {
                                                        $hash_data['meta']['_wpv_settings']['filter_meta_html'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['filter_meta_html']);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // Adjust the Filter MetaHTML CSS content
                                    if (isset($this_settings['filter_meta_html_css'])) {
                                        $pos = strpos($this_settings['filter_meta_html_css'], $attachment->guid);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_css'] = $attachment->guid;
                                            if ('module_manager' == $mode) {
                                                $hash_data['meta']['_wpv_settings']['filter_meta_html_css'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['filter_meta_html_css']);
                                            }
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($this_settings['filter_meta_html_css'], $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                                    if ('module_manager' == $mode) {
                                                        $hash_data['meta']['_wpv_settings']['filter_meta_html_css'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['filter_meta_html_css']);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // Adjust the Filter MetaHTML JS content
                                    if (isset($this_settings['filter_meta_html_js'])) {
                                        $pos = strpos($this_settings['filter_meta_html_js'], $attachment->guid);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_js'] = $attachment->guid;
                                            if ('module_manager' == $mode) {
                                                $hash_data['meta']['_wpv_settings']['filter_meta_html_js'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['filter_meta_html_js']);
                                            }
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($this_settings['filter_meta_html_js'], $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                                    if ('module_manager' == $mode) {
                                                        $hash_data['meta']['_wpv_settings']['filter_meta_html_js'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['filter_meta_html_js']);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // Adjust the Layout MetaHTML content
                                    if (isset($this_layout_settings['layout_meta_html'])) {
                                        $pos = strpos($this_layout_settings['layout_meta_html'], $attachment->guid);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html'] = $attachment->guid;
                                            if ('module_manager' == $mode) {
                                                $hash_data['meta']['_wpv_layout_settings']['layout_meta_html'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_layout_settings']['layout_meta_html']);
                                            }
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($this_layout_settings['layout_meta_html'], $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_sizes'][$thumbsize] = $thumbdata[0];
                                                    if ('module_manager' == $mode) {
                                                        $hash_data['meta']['_wpv_layout_settings']['layout_meta_html'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_layout_settings']['layout_meta_html']);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // Adjust the Layout MetaHTML CSS content
                                    if (isset($this_settings['layout_meta_html_css'])) {
                                        $pos = strpos($this_settings['layout_meta_html_css'], $attachment->guid);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_css'] = $attachment->guid;
                                            if ('module_manager' == $mode) {
                                                $hash_data['meta']['_wpv_settings']['layout_meta_html_css'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['layout_meta_html_css']);
                                            }
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($this_settings['layout_meta_html_css'], $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                                    if ('module_manager' == $mode) {
                                                        $hash_data['meta']['_wpv_settings']['layout_meta_html_css'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['layout_meta_html_css']);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // Adjust the Layout MetaHTML JS content
                                    if (isset($this_settings['layout_meta_html_js'])) {
                                        $pos = strpos($this_settings['layout_meta_html_js'], $attachment->guid);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_js'] = $attachment->guid;
                                            if ('module_manager' == $mode) {
                                                $hash_data['meta']['_wpv_settings']['layout_meta_html_js'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['layout_meta_html_js']);
                                            }
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($this_settings['layout_meta_html_js'], $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                                    if ('module_manager' == $mode) {
                                                        $hash_data['meta']['_wpv_settings']['layout_meta_html_js'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['layout_meta_html_js']);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // Adjust the full content
                                    $poscont = strpos($data['views']['view-' . $post['ID']]['post_content'], $attachment->guid);
                                    if ($poscont !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_post_content'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['post_content'] = str_replace($attachment->guid, md5($imdata), $hash_data['post_content']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($data['views']['view-' . $post['ID']]['post_content'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['post_content'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['post_content']);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if ('module_manager' == $mode) {
                            //Emerson: Fix issues in inconsistent hash in MM 1.1
                            //Added recursive sorting of keys prior to hashing to provide a consistent hash result during the import.
                            //Remove some keys for consistency.
                            if (isset($hash_data['meta']['_wpv_settings']['pagination']['mode'])) {
                                unset($hash_data['meta']['_wpv_settings']['pagination']['mode']);
                            }
                            if (isset($hash_data['meta']['_wpv_settings']['post_category']) && !empty($hash_data['meta']['_wpv_settings']['post_category'])) {
                                foreach ($hash_data['meta']['_wpv_settings']['post_category'] as $post_category_hashing_key => $post_category_hashing_value) {
                                    if ($post_category_hashing_key != '__key') {
                                        unset($hash_data['meta']['_wpv_settings']['post_category'][$post_category_hashing_key]);
                                    }
                                }
                            }
                            $items_hash[$post['ID']] = md5(serialize(wpv_ksort_by_string_views($hash_data)));
                        }
                    }
                }
            }
            break;
            // If exporting Content Templates
        // If exporting Content Templates
        case 'view-template':
            // Get the Content templates
            $view_templates = get_posts($args);
            if (!empty($view_templates)) {
                // Compose the image size array
                if (!isset($_wp_additional_image_sizes) || !is_array($_wp_additional_image_sizes)) {
                    $_wp_additional_image_sizes = array();
                }
                $attached_images_sizes = array_merge(array_keys($_wp_additional_image_sizes), array('thumbnail', 'medium', 'large'));
                // Create the $data['view-template'] array
                $data['view-templates'] = array('__key' => 'view-template');
                // Start collecting data
                foreach ($view_templates as $key => $post) {
                    $post = (array) $post;
                    // Only add Content Templates with a post_name
                    if ($post['post_name']) {
                        $post_data = array();
                        // Basic data
                        $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                        foreach ($copy_data as $copy) {
                            if (isset($post[$copy])) {
                                $post_data[$copy] = $post[$copy];
                            }
                        }
                        // Content Template meta data
                        $output_mode = get_post_meta($post['ID'], '_wpv_view_template_mode', true);
                        $template_extra_css = get_post_meta($post['ID'], '_wpv_view_template_extra_css', true);
                        $template_extra_js = get_post_meta($post['ID'], '_wpv_view_template_extra_js', true);
                        $template_description = get_post_meta($post['ID'], '_wpv-content-template-decription', true);
                        $post_data['template_mode'] = $output_mode;
                        $post_data['template_extra_css'] = $template_extra_css;
                        $post_data['template_extra_js'] = $template_extra_js;
                        $post_data['template_description'] = $template_description;
                        // Juan - add images for exporting
                        // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                        $att_args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post['ID']);
                        $attachments = get_posts($att_args);
                        if ($attachments) {
                            $post_data['attachments'] = array();
                            foreach ($attachments as $attachment) {
                                $image_type = get_post_mime_type($attachment->ID);
                                if ($image_type && ($image_type == 'image/jpeg' || $image_type == 'image/png' || $image_type == 'image/gif')) {
                                    $post_data['attachments']['attach_' . $attachment->ID] = array();
                                    $post_data['attachments']['attach_' . $attachment->ID]['title'] = $attachment->post_title;
                                    $post_data['attachments']['attach_' . $attachment->ID]['content'] = $attachment->post_content;
                                    $post_data['attachments']['attach_' . $attachment->ID]['excerpt'] = $attachment->post_excerpt;
                                    $post_data['attachments']['attach_' . $attachment->ID]['status'] = $attachment->post_status;
                                    $post_data['attachments']['attach_' . $attachment->ID]['alt'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                                    $imdata = base64_encode(file_get_contents($attachment->guid));
                                    $post_data['attachments']['attach_' . $attachment->ID]['data'] = $imdata;
                                    preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $attachment->guid, $matches);
                                    $post_data['attachments']['attach_' . $attachment->ID]['filename'] = basename($matches[0]);
                                    $imthumbs = array();
                                    foreach ($attached_images_sizes as $ts) {
                                        $imthumbs[$ts] = wp_get_attachment_image_src($attachment->ID, $ts);
                                    }
                                    // Adjust images in CSS
                                    if (isset($template_extra_css)) {
                                        $pos = strpos($template_extra_css, $attachment->guid);
                                        if ($pos !== false) {
                                            $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_css'] = $attachment->guid;
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($template_extra_css, $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                                }
                                            }
                                        }
                                    }
                                    // Adjust images in JS
                                    if (isset($template_extra_js)) {
                                        $posjs = strpos($template_extra_js, $attachment->guid);
                                        if ($posjs !== false) {
                                            $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_js'] = $attachment->guid;
                                        }
                                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                                $pos = strpos($template_extra_js, $thumbdata[0]);
                                                if ($pos !== false) {
                                                    $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                                }
                                            }
                                        }
                                    }
                                    //Adjust images in content
                                    $poscont = strpos($post_data['post_content'], $attachment->guid);
                                    if ($poscont !== false) {
                                        $post_data['attachments']['attach_' . $attachment->ID]['on_post_content'] = $attachment->guid;
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($post_data['post_content'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $post_data['attachments']['attach_' . $attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // Add the data to export
                        $data['view-templates']['view-template-' . $post['ID']] = $post_data;
                        if ('module_manager' == $mode) {
                            $hash_data = $post_data;
                            $hash_data['post_content'] = preg_replace('/\\s+/', '', str_replace("\n", "", $post_data['post_content']));
                            $hash_data['template_extra_css'] = preg_replace('/\\s+/', '', str_replace("\n", "", $post_data['template_extra_css']));
                            $hash_data['template_extra_js'] = preg_replace('/\\s+/', '', str_replace("\n", "", $post_data['template_extra_js']));
                            if (isset($post_data['attachments'])) {
                                unset($hash_data['attachments']);
                                $hash_data['attachments'] = array();
                                foreach ($post_data['attachments'] as $key => $attvalues) {
                                    $hash_data['attachments'][] = md5($attvalues['data']);
                                    if (isset($attvalues['on_meta_html_css'])) {
                                        $hash_data['template_extra_css'] = str_replace($attvalues['on_meta_html_css'], md5($attvalues['data']), $hash_data['template_extra_css']);
                                    }
                                    if (isset($attvalues['on_meta_html_css_sizes']) && is_array($attvalues['on_meta_html_css_sizes'])) {
                                        foreach ($attvalues['on_meta_html_css_sizes'] as $tsize => $turl) {
                                            $hash_data['template_extra_css'] = str_replace($turl, md5($attvalues['data']) . '_' . $tsize, $hash_data['template_extra_css']);
                                        }
                                    }
                                    if (isset($attvalues['on_meta_html_js'])) {
                                        $hash_data['template_extra_js'] = str_replace($attvalues['on_meta_html_js'], $attvalues['data'], $hash_data['template_extra_js']);
                                    }
                                    if (isset($attvalues['on_meta_html_js_sizes']) && is_array($attvalues['on_meta_html_js_sizes'])) {
                                        foreach ($attvalues['on_meta_html_js_sizes'] as $tsize => $turl) {
                                            $hash_data['template_extra_js'] = str_replace($turl, md5($attvalues['data']) . '_' . $tsize, $hash_data['template_extra_js']);
                                        }
                                    }
                                    if (isset($attvalues['on_post_content'])) {
                                        $hash_data['post_content'] = str_replace($attvalues['on_post_content'], $attvalues['data'], $hash_data['post_content']);
                                    }
                                    if (isset($attvalues['on_post_content_sizes']) && is_array($attvalues['on_post_content_sizes'])) {
                                        foreach ($attvalues['on_post_content_sizes'] as $tsize => $turl) {
                                            $hash_data['post_content'] = str_replace($turl, md5($attvalues['data']) . '_' . $tsize, $hash_data['post_content']);
                                        }
                                    }
                                }
                            }
                            unset($hash_data['ID']);
                            $items_hash[$post['ID']] = md5(serialize($hash_data));
                        }
                    }
                }
            }
            break;
    }
    /** EMERSON: Add content template and WordPress archives assignments to post types in settings, add to export XML */
    /** START */
    if ('module_manager' == $mode && 'view-template' == $type) {
        //This is a module manager export request for Content Template
        if (!$WPV_settings->is_empty()) {
            $wpv_settings_to_export = array();
            foreach ($WPV_settings as $option_name => $option_value) {
                if (strpos($option_name, 'views_template_for_') === 0) {
                    $item_name = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} \n\t\t\t\t\t\t\tWHERE ID = %s \n\t\t\t\t\t\t\tLIMIT 1", $option_value));
                    if ($item_name) {
                        $wpv_settings_to_export[$option_name] = $item_name;
                    }
                }
            }
            $data['settings'] = $wpv_settings_to_export;
        }
    } elseif ('module_manager' == $mode && 'view' == $type) {
        //This is a module manager export request for WordPress archives
        if (!$WPV_settings->is_empty()) {
            $wpv_settings_to_export = array();
            foreach ($WPV_settings as $option_name => $option_value) {
                if (strpos($option_name, 'view_') === 0) {
                    $item_name = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} \n\t\t\t\t\t\t\tWHERE ID = %s \n\t\t\t\t\t\t\tLIMIT 1", $option_value));
                    if ($item_name) {
                        $wpv_settings_to_export[$option_name] = $item_name;
                    }
                }
            }
            $data['settings'] = $wpv_settings_to_export;
        }
    }
    /** END */
    // Compose the XML string
    $xmldata = $xml->array2xml($data, 'views');
    if ('xml' == $mode) {
        return $xmldata;
    } elseif ('module_manager' == $mode) {
        $export_data = array('xml' => $xmldata, 'items_hash' => $items_hash);
        return $export_data;
    }
}
コード例 #3
0
 /** Returns XML content of export if sensible, otherwise FALSE*/
 public function wcviews_export_settings()
 {
     $woocommerce_views_export_xml = FALSE;
     if (defined('WOOCOMMERCE_VIEWS_PLUGIN_PATH')) {
         //Define the parser path
         $array_xml_parser = WOOCOMMERCE_VIEWS_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'array2xml.php';
         if (file_exists($array_xml_parser)) {
             //Define array of important WooCommerce Views settings for exporting.
             $woocommerceviews_options_for_exporting = array('woocommerce_views_theme_template_file', 'woocommerce_views_theme_archivetemplate_file', 'woocommerce_views_wrap_the_content');
             $woocommerce_views_settings = array();
             //Loop through the settings and assign to array
             foreach ($woocommerceviews_options_for_exporting as $key => $value) {
                 $the_value = get_option($value);
                 if ($the_value) {
                     $woocommerce_views_settings[$value] = $the_value;
                 }
             }
             //Parser exists, require once
             require_once $array_xml_parser;
             //Instantiate
             $xml = new ICL_Array2XML();
             //Define anchor name
             $anchor_name = 'woocommerce_views_export_settings';
             //Get XML only if array is not empty
             if (!empty($woocommerce_views_settings)) {
                 $woocommerce_views_export_xml = $xml->array2xml($woocommerce_views_settings, $anchor_name);
             }
         }
     }
     return $woocommerce_views_export_xml;
 }
コード例 #4
0
 private static function toXml($data, $root_element)
 {
     require_once WPCF_EMBEDDED_ABSPATH . '/common/array2xml.php';
     $xml = new \ICL_Array2XML();
     return $xml->array2xml($data, $root_element);
 }
コード例 #5
0
/**
 * Exports data to XML.
 */
function wpcf_admin_export_data()
{
    require_once WPCF_EMBEDDED_ABSPATH . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    // Get groups
    $groups = get_posts('post_type=wp-types-group&post_status=null&numberposts=-1');
    if (!empty($groups)) {
        $data['groups'] = array('__key' => 'group');
        foreach ($groups as $key => $post) {
            $post = (array) $post;
            $post_data = array();
            $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
            foreach ($copy_data as $copy) {
                if (isset($post[$copy])) {
                    $post_data[$copy] = $post[$copy];
                }
            }
            $data['groups']['group-' . $post['ID']] = $post_data;
            $meta = get_post_custom($post['ID']);
            if (!empty($meta)) {
                $data['groups']['group-' . $post['ID']]['meta'] = array();
                foreach ($meta as $meta_key => $meta_value) {
                    if (in_array($meta_key, array('_wp_types_group_terms', '_wp_types_group_post_types', '_wp_types_group_fields'))) {
                        $data['groups']['group-' . $post['ID']]['meta'][$meta_key] = $meta_value[0];
                    }
                }
                if (empty($data['groups']['group-' . $post['ID']]['meta'])) {
                    unset($data['groups']['group-' . $post['ID']]['meta']);
                }
            }
        }
    }
    // Get fields
    $fields = wpcf_admin_fields_get_fields();
    if (!empty($fields)) {
        // WPML
        global $iclTranslationManagement;
        if (!empty($iclTranslationManagement)) {
            foreach ($fields as $field_id => $field) {
                // @todo Fix for added fields
                if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                    $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                }
            }
        }
        $data['fields'] = $fields;
        $data['fields']['__key'] = 'field';
    }
    // Get custom types
    $custom_types = get_option('wpcf-custom-types', array());
    if (!empty($custom_types)) {
        foreach ($custom_types as $key => $type) {
            $custom_types[$key]['id'] = $key;
        }
        $data['types'] = $custom_types;
        $data['types']['__key'] = 'type';
    }
    // Get custom tax
    $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
    if (!empty($custom_taxonomies)) {
        foreach ($custom_taxonomies as $key => $tax) {
            $custom_taxonomies[$key]['id'] = $key;
        }
        $data['taxonomies'] = $custom_taxonomies;
        $data['taxonomies']['__key'] = 'taxonomy';
    }
    // Offer for download
    $data = $xml->array2xml($data, 'types');
    $sitename = sanitize_title(get_bloginfo('name'));
    if (!empty($sitename)) {
        $sitename .= '.';
    }
    $filename = $sitename . 'types.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['embedded-settings']) && $_POST['embedded-settings'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    $code .= "\r\n?>";
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'types.' . date('Y-m-d') . '.zip';
        $file = tempnam("tmp", "zip");
        $zip = new ZipArchive();
        $zip->open($file, ZipArchive::OVERWRITE);
        $zip->addFromString('settings.xml', $data);
        $zip->addFromString('settings.php', $code);
        $zip->close();
        $data = file_get_contents($file);
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $zipname);
        header("Content-Type: application/zip");
        header("Content-length: " . strlen($data) . "\n\n");
        header("Content-Transfer-Encoding: binary");
        echo $data;
        unlink($file);
        die;
    } else {
        // download the xml.
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Content-Type: application/xml");
        header("Content-length: " . strlen($data) . "\n\n");
        echo $data;
        die;
    }
}
コード例 #6
0
/**
 * Custom Export function for Module Manager.
 *
 * Exports selected items (by ID) and of specified type (eg views, view-templates).
 * Returns xml string.
 *
 * @global type $iclTranslationManagement
 * @param array $items
 * @param type $_type
 * @param type $return mixed array|xml|download
 * @return string
 */
function wpcf_admin_export_selected_data(array $items, $_type = 'all', $return = 'download', $use_cache = false)
{
    global $wpcf;
    $xml = new ICL_Array2XML();
    $data = array();
    $data['settings'] = wpcf_get_settings();
    if ('user_groups' == $_type || 'all' == $_type) {
        // Get groups
        if (empty($items)) {
            $groups = get_posts(array('post_type' => TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'post_status' => null, 'numberposts' => '-1'));
        } else {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            foreach ($items as $k => $item) {
                if (isset($item['id'])) {
                    $items[$k] = intval(wpcf_modman_get_submitted_id('groups', $item['id']));
                }
            }
            $args = array('post__in' => $items, 'post_type' => TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'post_status' => 'all', 'posts_per_page' => -1);
            $groups = get_posts($args);
        }
        if (!empty($groups)) {
            $data['user_groups'] = array('__key' => 'group');
            foreach ($groups as $key => $post) {
                $post = (array) $post;
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $_data = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $_meta = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if (in_array($meta_key, array('_wp_types_group_showfor', '_wp_types_group_fields', '_wp_types_group_admin_styles'))) {
                            $_meta[$meta_key] = $meta_value[0];
                        }
                    }
                    if (!empty($_meta)) {
                        $_data['meta'] = $_meta;
                    }
                }
                $_data['checksum'] = $_data['hash'] = $wpcf->export->generate_checksum('group', $post['ID']);
                $_data['__types_id'] = $post['post_name'];
                $_data['__types_title'] = $post['post_title'];
                $data['user_groups']['group-' . $post['ID']] = $_data;
            }
        }
        if (!empty($items)) {
            // Get fields by group
            // TODO Document why we use by_group
            $fields = array();
            foreach ($groups as $key => $post) {
                $fields = array_merge($fields, wpcf_admin_fields_get_fields_by_group($post->ID, 'slug', false, false, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta', $use_cache));
            }
        } else {
            // Get fields
            $fields = wpcf_admin_fields_get_fields(false, false, false, 'wpcf-usermeta');
        }
        if (!empty($fields)) {
            // Add checksums before WPML
            foreach ($fields as $field_id => $field) {
                // TODO WPML and others should use hook
                $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
                $fields[$field_id]['__types_id'] = $field_id;
                $fields[$field_id]['__types_title'] = $field['name'];
                $fields[$field_id]['checksum'] = $fields[$field_id]['hash'] = $wpcf->export->generate_checksum('field', $field_id);
            }
            // WPML
            // todo remove WPML dependency, see https://onthegosystems.myjetbrains.com/youtrack/issue/types-749#comment=102-105900
            global $iclTranslationManagement;
            if (!empty($iclTranslationManagement)) {
                foreach ($fields as $field_id => $field) {
                    // TODO Check this for all fields
                    if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                        $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                    }
                }
            }
            $data['user_fields'] = $fields;
            $data['user_fields']['__key'] = 'field';
        }
    }
    // Export term field groups and term field definitions.
    if (in_array($_type, array('term_groups', 'all'))) {
        $ie_controller = Types_Import_Export::get_instance();
        $data['term_groups'] = $ie_controller->export_field_groups_for_domain(Types_Field_Utils::DOMAIN_TERMS);
        $data['term_fields'] = $ie_controller->export_field_definitions_for_domain(Types_Field_Utils::DOMAIN_TERMS);
    }
    if ('groups' == $_type || 'all' == $_type) {
        // Get groups
        if (empty($items)) {
            $groups = get_posts('post_type=wp-types-group&post_status=null&numberposts=-1');
        } else {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            foreach ($items as $k => $item) {
                if (isset($item['id'])) {
                    $items[$k] = intval(wpcf_modman_get_submitted_id('groups', $item['id']));
                }
            }
            $args = array('post__in' => $items, 'post_type' => TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'post_status' => 'all', 'posts_per_page' => -1);
            $groups = get_posts($args);
        }
        if (!empty($groups)) {
            $data['groups'] = array('__key' => 'group');
            foreach ($groups as $key => $post) {
                $post = (array) $post;
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $_data = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $_meta = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if (in_array($meta_key, array('_wp_types_group_terms', '_wp_types_group_post_types', '_wp_types_group_fields', '_wp_types_group_templates', '_wpcf_conditional_display', '_wp_types_group_filters_association', '_wp_types_group_admin_styles'))) {
                            $_meta[$meta_key] = $meta_value[0];
                            $_meta[$meta_key] = maybe_unserialize($_meta[$meta_key]);
                        }
                    }
                    if (!empty($_meta)) {
                        $_data['meta'] = $_meta;
                    }
                }
                $_data['checksum'] = $_data['hash'] = $wpcf->export->generate_checksum('group', $post['ID']);
                $_data['__types_id'] = $post['post_name'];
                $_data['__types_title'] = $post['post_title'];
                $data['groups']['group-' . $post['ID']] = $_data;
            }
        }
        if (!empty($items)) {
            // Get fields by group
            // TODO Document why we use by_group
            $fields = array();
            foreach ($groups as $key => $post) {
                $fields = array_merge($fields, wpcf_admin_fields_get_fields_by_group($post->ID, 'slug', false, false, false, TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'wpcf-fields', $use_cache));
            }
        } else {
            // Get fields
            $fields = wpcf_admin_fields_get_fields();
        }
        if (!empty($fields)) {
            // Add checksums before WPML
            foreach ($fields as $field_id => $field) {
                // TODO WPML and others should use hook
                $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
                $fields[$field_id]['__types_id'] = $field_id;
                $fields[$field_id]['__types_title'] = $field['name'];
                $fields[$field_id]['checksum'] = $fields[$field_id]['hash'] = $wpcf->export->generate_checksum('field', $field_id);
            }
            // WPML
            // todo remove WPML dependency, see https://onthegosystems.myjetbrains.com/youtrack/issue/types-749#comment=102-105900
            global $iclTranslationManagement;
            if (!empty($iclTranslationManagement)) {
                foreach ($fields as $field_id => $field) {
                    // TODO Check this for all fields
                    if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                        $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                    }
                }
            }
            $data['fields'] = $fields;
            $data['fields']['__key'] = 'field';
        }
    }
    // Get custom types
    if ('types' == $_type || 'all' == $_type) {
        $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
        // Get custom types
        // TODO Document $items
        if (!empty($items)) {
            /*
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            $_items = array();
            foreach ($items as $k => $item) {
                if (is_array($item) && isset($item['id'])) {
                    $_items[$item['id']] = true;
                } else {
                    $_items[$item] = true;
                }
            }
            $custom_types = array_intersect_key($custom_types, $_items);
        }
        // Get custom types
        if (!empty($custom_types)) {
            foreach ($custom_types as $key => $type) {
                if (isset($type['custom-field-group']) && is_array($type['custom-field-group']) && !empty($type['custom-field-group'])) {
                    foreach ($type['custom-field-group'] as $custom_field_group_id => $senseless_as_it_is_always_one) {
                        $custom_field_group = get_post($custom_field_group_id);
                        // unset custom field USING ID AS KEY AND "1" AS VALUE from custom post type
                        unset($custom_types[$key]['custom-field-group'][$custom_field_group_id]);
                        // continue with next if this custom field group no longer exists
                        if (!is_object($custom_field_group)) {
                            continue;
                        }
                        // set custom field, generating an unique key (but without a particular meaning) AND ID AS VALUE to custom post type
                        $custom_types[$key]['custom-field-group']['group_' . $custom_field_group_id] = $custom_field_group_id;
                    }
                }
                $custom_types[$key]['id'] = $key;
                $custom_types[$key] = apply_filters('wpcf_export_custom_post_type', $custom_types[$key]);
                $custom_types[$key]['__types_id'] = $key;
                $custom_types[$key]['__types_title'] = $type['labels']['name'];
                $custom_types[$key]['checksum'] = $custom_types[$key]['hash'] = $wpcf->export->generate_checksum('custom_post_type', $key, $type);
            }
            $data['types'] = $custom_types;
            $data['types']['__key'] = 'type';
        }
        if (!empty($items)) {
            // Get post relationships only for items
            $relationships_all = get_option('wpcf_post_relationship', array());
            $relationships = array();
            foreach ($relationships_all as $parent => $children) {
                if (in_array($parent, $items)) {
                    foreach ($children as $child => $childdata) {
                        if (in_array($child, $items)) {
                            if (!isset($relationships[$parent])) {
                                $relationships[$parent] = array();
                            }
                            $relationships[$parent][$child] = $childdata;
                        }
                    }
                }
            }
        } else {
            // Get post relationships
            $relationships = get_option('wpcf_post_relationship', array());
        }
        if (!empty($relationships)) {
            $data['post_relationships']['data'] = json_encode($relationships);
        }
    }
    // Get custom tax
    if ('taxonomies' == $_type || 'all' == $_type) {
        if (!empty($items)) {
            /*
             *
             * This fails
             * $items are in form of:
             * 0 => array('id' => 'pt', ...)
             */
            //            $custom_taxonomies = array_intersect_key( get_option( WPCF_OPTION_NAME_CUSTOM_TAXONOMIES,
            //                            array() ), array_flip( $items ) );
            $_items = array();
            foreach ($items as $k => $item) {
                if (is_array($item) && isset($item['id'])) {
                    $_items[$item['id']] = true;
                } else {
                    $_items[$item] = true;
                }
            }
            $custom_taxonomies = array_intersect_key(get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array()), $_items);
        } else {
            // Get custom tax
            $custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
        }
        if (!empty($custom_taxonomies)) {
            foreach ($custom_taxonomies as $key => $tax) {
                $custom_taxonomies[$key]['id'] = $key;
                $custom_taxonomies[$key] = apply_filters('wpcf_filter_export_custom_taxonomy', $custom_taxonomies[$key]);
                $custom_taxonomies[$key]['__types_id'] = $key;
                $custom_taxonomies[$key]['__types_title'] = $tax['labels']['name'];
                $custom_taxonomies[$key]['checksum'] = $wpcf->export->generate_checksum('custom_taxonomy', $key, $tax);
            }
            $data['taxonomies'] = $custom_taxonomies;
            $data['taxonomies']['__key'] = 'taxonomy';
        }
    }
    /*
     *
     * Since Types 1.2
     */
    if ($return == 'array') {
        return $data;
    } else {
        if ($return == 'xml') {
            return $xml->array2xml($data, 'types');
        } else {
            if ($return == 'module_manager') {
                $items = array();
                // Re-arrange fields
                if (!empty($data['fields'])) {
                    foreach ($data['fields'] as $_data) {
                        if (is_array($_data) && isset($_data['__types_id']) && isset($_data['checksum'])) {
                            $_item = array();
                            $_item['hash'] = $_item['checksum'] = $_data['checksum'];
                            $_item['id'] = $_data['__types_id'];
                            $_item['title'] = $_data['__types_title'];
                            $items['__fields'][$_data['__types_id']] = $_item;
                        }
                    }
                }
                // Add checksums to items
                foreach ($data as $_t => $type) {
                    foreach ($type as $_data) {
                        // Skip fields
                        if ($_t == 'fields') {
                            continue;
                        }
                        if (is_array($_data) && isset($_data['__types_id']) && isset($_data['checksum'])) {
                            $_item = array();
                            $_item['hash'] = $_item['checksum'] = $_data['checksum'];
                            $_item['id'] = $_data['__types_id'];
                            $_item['title'] = $_data['__types_title'];
                            $items[$_data['__types_id']] = $_item;
                        }
                    }
                }
                return array('xml' => $xml->array2xml($data, 'types'), 'items' => $items);
            }
        }
    }
    // Offer for download
    $data = $xml->array2xml($data, 'types');
    $sitename = sanitize_title(get_bloginfo('name'));
    if (empty($sitename)) {
        $sitename = 'wp';
    }
    $sitename .= '.';
    $filename = $sitename . 'types.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= "\r\n?" . ">";
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'types.' . date('Y-m-d') . '.zip';
        $temp_dir = wpcf_get_temporary_directory();
        if (empty($temp_dir)) {
            die(__('There is a problem with temporary directory.', 'wpcf'));
        }
        $file = tempnam($temp_dir, "zip");
        $zip = new ZipArchive();
        $zip->open($file, ZipArchive::OVERWRITE);
        /**
         * if sys_get_temp_dir fail in case of open_basedir restriction,
         * try use wp_upload_dir instead. if this fail too, send pure
         * xml file to user
         */
        if (empty($zip->filename)) {
            $temp_dir = wp_upload_dir();
            $temp_dir = $temp_dir['basedir'];
            $file = tempnam($temp_dir, "zip");
            $zip = new ZipArchive();
            $zip->open($file, ZipArchive::OVERWRITE);
        }
        /**
         * send a zip file
         */
        if (!empty($zip->filename)) {
            $zip->addFromString('settings.xml', $data);
            $zip->addFromString('settings.php', $code);
            $zip->close();
            $data = file_get_contents($file);
            header("Content-Description: File Transfer");
            header("Content-Disposition: attachment; filename=" . $zipname);
            header("Content-Type: application/zip");
            header("Content-length: " . strlen($data) . "\n\n");
            header("Content-Transfer-Encoding: binary");
            echo $data;
            unlink($file);
            die;
        }
    }
    /**
     * download the xml if fail downloading zip
     */
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=" . $filename);
    header("Content-Type: application/xml");
    header("Content-length: " . strlen($data) . "\n\n");
    echo $data;
    die;
}
コード例 #7
0
function wpv_admin_export_selected_data($items, $type = 'view', $mode = 'xml')
{
    global $WP_Views;
    require_once WPV_PATH_EMBEDDED . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    $items_hash = array();
    // SRDJAN - add siteurl, upload url, record taxonomies old IDs
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382866/comments
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142389966/comments
    //    $data['site_url'] = get_site_url();
    if (is_multisite()) {
        $upload_directory = get_option('fileupload_url');
    } else {
        $wp_upload_dir = wp_upload_dir();
        $upload_directory = $wp_upload_dir['baseurl'];
    }
    $args = array('posts_per_page' => -1, 'post_status' => 'any');
    $export = false;
    $view_types = array('view' => array('key' => 'views'), 'view-template' => array('key' => 'view-templates'));
    if (is_string($items) && 'all' === $items) {
        $export = true;
    } elseif (is_array($items) && !empty($items)) {
        $args['post__in'] = $items;
        $export = true;
    }
    if (!in_array($type, array_keys($view_types))) {
        $export = false;
    } else {
        $args['post_type'] = $type;
        $vkey = $view_types[$type]['key'];
    }
    if (!$export) {
        return '';
    }
    switch ($type) {
        case 'view':
            // Get the views
            $views = get_posts($args);
            if (!empty($views)) {
                global $_wp_additional_image_sizes;
                $attached_images_sizes = array_merge(array_keys($_wp_additional_image_sizes), array('thumbnail', 'medium', 'large'));
                $data['views'] = array('__key' => 'view');
                foreach ($views as $key => $post) {
                    $post = (array) $post;
                    if ($post['post_name']) {
                        $hash_data = array();
                        $post_data = array();
                        $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                        foreach ($copy_data as $copy) {
                            if (isset($post[$copy])) {
                                $post_data[$copy] = $post[$copy];
                            }
                        }
                        $data['views']['view-' . $post['ID']] = $post_data;
                        $hash_basics = array('post_title', 'post_name', 'post_type', 'post_status');
                        foreach ($hash_basics as $basics) {
                            if (isset($data['views']['view-' . $post['ID']][$basics])) {
                                $hash_data[$basics] = $data['views']['view-' . $post['ID']][$basics];
                            }
                        }
                        if (isset($data['views']['view-' . $post['ID']]['post_content'])) {
                            $hash_data['post_content'] = preg_replace('/\\s+/', '', str_replace("\n", "", $data['views']['view-' . $post['ID']]['post_content']));
                        }
                        if (isset($data['views']['view-' . $post['ID']]['post_excerpt'])) {
                            $hash_data['post_excerpt'] = preg_replace('/\\s+/', '', str_replace("\n", "", $data['views']['view-' . $post['ID']]['post_excerpt']));
                        }
                        $meta = get_post_custom($post['ID']);
                        if (!empty($meta)) {
                            $data['view']['view-' . $post['ID']]['meta'] = array();
                            foreach ($meta as $meta_key => $meta_value) {
                                if ($meta_key == '_wpv_settings') {
                                    $value = maybe_unserialize($meta_value[0]);
                                    // Add any taxonomy terms so we can re-map when we import.
                                    if (!empty($value['taxonomy_terms'])) {
                                        $taxonomy = $value['taxonomy_type'][0];
                                        foreach ($value['taxonomy_terms'] as $term_id) {
                                            $term = get_term($term_id, $taxonomy);
                                            $data['terms_map']['term_' . $term->term_id]['old_id'] = $term->term_id;
                                            $data['terms_map']['term_' . $term->term_id]['slug'] = $term->slug;
                                            $data['terms_map']['term_' . $term->term_id]['taxonomy'] = $taxonomy;
                                        }
                                    }
                                    if (isset($value['author_mode'])) {
                                        $value['author_mode']['type'] = $value['author_mode'][0];
                                        unset($value['author_mode'][0]);
                                    }
                                    $value = $WP_Views->convert_ids_to_names_in_settings($value);
                                    $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                                    if ('module_manager' == $mode) {
                                        $hash_data['meta'][$meta_key] = $value;
                                        // Correct possible elements with changing format
                                        if (isset($value['taxonomy_hide_empty'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_hide_empty'] = strval($value['taxonomy_hide_empty']);
                                        }
                                        if (isset($value['taxonomy_include_non_empty_decendants'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_include_non_empty_decendants'] = strval($value['taxonomy_include_non_empty_decendants']);
                                        }
                                        if (isset($value['taxonomy_pad_counts'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_pad_counts'] = strval($value['taxonomy_pad_counts']);
                                        }
                                        if (isset($value['post_type_dont_include_current_page'])) {
                                            $hash_data['meta'][$meta_key]['post_type_dont_include_current_page'] = strval($value['post_type_dont_include_current_page']);
                                        }
                                        if (isset($value['pagination']['preload_images'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['preload_images'] = strval($value['pagination']['preload_images']);
                                        }
                                        if (isset($value['pagination']['cache_pages'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['cache_pages'] = strval($value['pagination']['cache_pages']);
                                        }
                                        if (isset($value['pagination']['preload_pages'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['preload_pages'] = strval($value['pagination']['preload_pages']);
                                        }
                                        if (isset($value['pagination']['spinner_image'])) {
                                            $hash_data['meta'][$meta_key]['pagination']['spinner_image'] = basename($value['pagination']['spinner_image']);
                                        }
                                        if (isset($value['rollover']['preload_images'])) {
                                            $hash_data['meta'][$meta_key]['rollover']['preload_images'] = strval($value['rollover']['preload_images']);
                                        }
                                        if (isset($value['offset'])) {
                                            $hash_data['meta'][$meta_key]['offset'] = strval($value['offset']);
                                        }
                                        if (isset($value['taxonomy_offset'])) {
                                            $hash_data['meta'][$meta_key]['taxonomy_offset'] = strval($value['taxonomy_offset']);
                                        }
                                        if (isset($value['filter_meta_html'])) {
                                            $hash_data['meta'][$meta_key]['filter_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['filter_meta_html']));
                                        }
                                        if (isset($value['generated_filter_meta_html'])) {
                                            $hash_data['meta'][$meta_key]['generated_filter_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['generated_filter_meta_html']));
                                        }
                                        if (isset($value['filter_meta_html_css'])) {
                                            $hash_data['meta'][$meta_key]['filter_meta_html_css'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['filter_meta_html_css']));
                                        }
                                        if (isset($value['filter_meta_html_js'])) {
                                            $hash_data['meta'][$meta_key]['filter_meta_html_js'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['filter_meta_html_js']));
                                        }
                                        if (isset($value['layout_meta_html_css'])) {
                                            $hash_data['meta'][$meta_key]['layout_meta_html_css'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['layout_meta_html_css']));
                                        }
                                        if (isset($value['layout_meta_html_js'])) {
                                            $hash_data['meta'][$meta_key]['layout_meta_html_js'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['layout_meta_html_js']));
                                        }
                                        if (isset($value['author_mode'])) {
                                            $hash_data['meta'][$meta_key]['author_mode'] = reset($value['author_mode']);
                                        }
                                        $cursed_array = array('filter_controls_enable', 'filter_controls_param', 'filter_controls_mode', 'filter_controls_field_name', 'filter_controls_label', 'filter_controls_type', 'filter_controls_values');
                                        foreach ($cursed_array as $cursed) {
                                            if (isset($hash_data['meta'][$meta_key][$cursed])) {
                                                unset($hash_data['meta'][$meta_key][$cursed]);
                                            }
                                        }
                                    }
                                }
                                if ($meta_key == '_wpv_layout_settings') {
                                    $value = maybe_unserialize($meta_value[0]);
                                    $value = $WP_Views->convert_ids_to_names_in_layout_settings($value);
                                    $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                                    if ('module_manager' == $mode) {
                                        $hash_data['meta'][$meta_key] = $value;
                                        if (isset($value['layout_meta_html'])) {
                                            $hash_data['meta'][$meta_key]['layout_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['layout_meta_html']));
                                        }
                                        if (isset($value['generated_layout_meta_html'])) {
                                            $hash_data['meta'][$meta_key]['generated_layout_meta_html'] = preg_replace('/\\s+/', '', str_replace("\n", "", $value['generated_layout_meta_html']));
                                        }
                                    }
                                }
                            }
                            if (empty($data['views']['view-' . $post['ID']]['meta'])) {
                                unset($data['views']['view-' . $post['ID']]['meta']);
                            }
                        }
                        // Juan - add images for exporting
                        // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                        $att_args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post['ID']);
                        $attachments = get_posts($att_args);
                        if ($attachments) {
                            $data['views']['view-' . $post['ID']]['attachments'] = array();
                            if ('module_manager' == $mode) {
                                $hash_data['attachments'] = array();
                            }
                            foreach ($attachments as $attachment) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID] = array();
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['title'] = $attachment->post_title;
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['content'] = $attachment->post_content;
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['excerpt'] = $attachment->post_excerpt;
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['status'] = $attachment->post_status;
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['alt'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                                $imdata = base64_encode(file_get_contents($attachment->guid));
                                if ('module_manager' == $mode) {
                                    $hash_data['attachments'][] = md5($imdata);
                                }
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['data'] = $imdata;
                                preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $attachment->guid, $matches);
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['filename'] = basename($matches[0]);
                                $this_settings = get_post_meta($post['ID'], '_wpv_settings', true);
                                $this_layout_settings = get_post_meta($post['ID'], '_wpv_layout_settings', true);
                                if (isset($this_settings['pagination']['spinner_image_uploaded']) && $attachment->guid == $this_settings['pagination']['spinner_image_uploaded']) {
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['custom_spinner'] = 'this';
                                    if ('module_manager' == $mode) {
                                        $hash_data['meta']['_wpv_settings']['pagination']['spinner_image_uploaded'] = md5($imdata);
                                    }
                                }
                                $imthumbs = array();
                                foreach ($attached_images_sizes as $ts) {
                                    $imthumbs[$ts] = wp_get_attachment_image_src($attachment->ID, $ts);
                                }
                                if (isset($this_settings['filter_meta_html'])) {
                                    $pos = strpos($this_settings['filter_meta_html'], $attachment->guid);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_settings']['filter_meta_html'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['filter_meta_html']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($this_settings['filter_meta_html'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['meta']['_wpv_settings']['filter_meta_html'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['filter_meta_html']);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isset($this_settings['filter_meta_html_css'])) {
                                    $pos = strpos($this_settings['filter_meta_html_css'], $attachment->guid);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_css'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_settings']['filter_meta_html_css'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['filter_meta_html_css']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($this_settings['filter_meta_html_css'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['meta']['_wpv_settings']['filter_meta_html_css'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['filter_meta_html_css']);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isset($this_settings['filter_meta_html_js'])) {
                                    $pos = strpos($this_settings['filter_meta_html_js'], $attachment->guid);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_js'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_settings']['filter_meta_html_js'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['filter_meta_html_js']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($this_settings['filter_meta_html_js'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['meta']['_wpv_settings']['filter_meta_html_js'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['filter_meta_html_js']);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isset($this_layout_settings['layout_meta_html'])) {
                                    $pos = strpos($this_layout_settings['layout_meta_html'], $attachment->guid);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_layout_settings']['layout_meta_html'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_layout_settings']['layout_meta_html']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($this_layout_settings['layout_meta_html'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['meta']['_wpv_layout_settings']['layout_meta_html'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_layout_settings']['layout_meta_html']);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isset($this_settings['layout_meta_html_css'])) {
                                    $pos = strpos($this_settings['layout_meta_html_css'], $attachment->guid);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_css'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_settings']['layout_meta_html_css'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['layout_meta_html_css']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($this_settings['layout_meta_html_css'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['meta']['_wpv_settings']['layout_meta_html_css'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['layout_meta_html_css']);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isset($this_settings['layout_meta_html_js'])) {
                                    $pos = strpos($this_settings['layout_meta_html_js'], $attachment->guid);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_js'] = $attachment->guid;
                                        if ('module_manager' == $mode) {
                                            $hash_data['meta']['_wpv_settings']['layout_meta_html_js'] = str_replace($attachment->guid, md5($imdata), $hash_data['meta']['_wpv_settings']['layout_meta_html_js']);
                                        }
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($this_settings['layout_meta_html_js'], $thumbdata[0]);
                                            if ($pos !== false) {
                                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                                if ('module_manager' == $mode) {
                                                    $hash_data['meta']['_wpv_settings']['layout_meta_html_js'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['meta']['_wpv_settings']['layout_meta_html_js']);
                                                }
                                            }
                                        }
                                    }
                                }
                                $poscont = strpos($data['views']['view-' . $post['ID']]['post_content'], $attachment->guid);
                                if ($poscont !== false) {
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_post_content'] = $attachment->guid;
                                    if ('module_manager' == $mode) {
                                        $hash_data['post_content'] = str_replace($attachment->guid, md5($imdata), $hash_data['post_content']);
                                    }
                                }
                                foreach ($imthumbs as $thumbsize => $thumbdata) {
                                    if (!empty($thumbdata) && isset($thumbdata[0])) {
                                        $pos = strpos($data['views']['view-' . $post['ID']]['post_content'], $thumbdata[0]);
                                        if ($pos !== false) {
                                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
                                            if ('module_manager' == $mode) {
                                                $hash_data['post_content'] = str_replace($thumbdata[0], md5($imdata) . '_' . $thumbsize, $hash_data['post_content']);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if ('module_manager' == $mode) {
                            $items_hash[$post['ID']] = md5(serialize($hash_data));
                        }
                    }
                }
            }
            break;
        case 'view-template':
            // Get the view templates
            $view_templates = get_posts($args);
            if (!empty($view_templates)) {
                global $_wp_additional_image_sizes;
                $attached_images_sizes = array_merge(array_keys($_wp_additional_image_sizes), array('thumbnail', 'medium', 'large'));
                $data['view-templates'] = array('__key' => 'view-template');
                foreach ($view_templates as $key => $post) {
                    $post = (array) $post;
                    if ($post['post_name']) {
                        $post_data = array();
                        $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                        foreach ($copy_data as $copy) {
                            if (isset($post[$copy])) {
                                $post_data[$copy] = $post[$copy];
                            }
                        }
                        $output_mode = get_post_meta($post['ID'], '_wpv_view_template_mode', true);
                        $template_extra_css = get_post_meta($post['ID'], '_wpv_view_template_extra_css', true);
                        $template_extra_js = get_post_meta($post['ID'], '_wpv_view_template_extra_js', true);
                        $post_data['template_mode'] = $output_mode;
                        $post_data['template_extra_css'] = $template_extra_css;
                        $post_data['template_extra_js'] = $template_extra_js;
                        // Juan - add images for exporting
                        // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                        $att_args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post['ID']);
                        $attachments = get_posts($att_args);
                        if ($attachments) {
                            $post_data['attachments'] = array();
                            foreach ($attachments as $attachment) {
                                $post_data['attachments']['attach_' . $attachment->ID] = array();
                                $post_data['attachments']['attach_' . $attachment->ID]['title'] = $attachment->post_title;
                                $post_data['attachments']['attach_' . $attachment->ID]['content'] = $attachment->post_content;
                                $post_data['attachments']['attach_' . $attachment->ID]['excerpt'] = $attachment->post_excerpt;
                                $post_data['attachments']['attach_' . $attachment->ID]['status'] = $attachment->post_status;
                                $post_data['attachments']['attach_' . $attachment->ID]['alt'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                                $imdata = base64_encode(file_get_contents($attachment->guid));
                                $post_data['attachments']['attach_' . $attachment->ID]['data'] = $imdata;
                                preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $attachment->guid, $matches);
                                $post_data['attachments']['attach_' . $attachment->ID]['filename'] = basename($matches[0]);
                                $imthumbs = array();
                                foreach ($attached_images_sizes as $ts) {
                                    $imthumbs[$ts] = wp_get_attachment_image_src($attachment->ID, $ts);
                                }
                                if (isset($template_extra_css)) {
                                    $pos = strpos($template_extra_css, $attachment->guid);
                                    if ($pos !== false) {
                                        $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_css'] = $attachment->guid;
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($template_extra_css, $thumbdata[0]);
                                            if ($pos !== false) {
                                                $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                            }
                                        }
                                    }
                                }
                                if (isset($template_extra_js)) {
                                    $posjs = strpos($template_extra_js, $attachment->guid);
                                    if ($posjs !== false) {
                                        $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_js'] = $attachment->guid;
                                    }
                                    foreach ($imthumbs as $thumbsize => $thumbdata) {
                                        if (!empty($thumbdata) && isset($thumbdata[0])) {
                                            $pos = strpos($template_extra_js, $thumbdata[0]);
                                            if ($pos !== false) {
                                                $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                            }
                                        }
                                    }
                                }
                                $poscont = strpos($post_data['post_content'], $attachment->guid);
                                if ($poscont !== false) {
                                    $post_data['attachments']['attach_' . $attachment->ID]['on_post_content'] = $attachment->guid;
                                }
                                foreach ($imthumbs as $thumbsize => $thumbdata) {
                                    if (!empty($thumbdata) && isset($thumbdata[0])) {
                                        $pos = strpos($post_data['post_content'], $thumbdata[0]);
                                        if ($pos !== false) {
                                            $post_data['attachments']['attach_' . $attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
                                        }
                                    }
                                }
                            }
                        }
                        $data['view-templates']['view-template-' . $post['ID']] = $post_data;
                        if ('module_manager' == $mode) {
                            $hash_data = $post_data;
                            $hash_data['post_content'] = preg_replace('/\\s+/', '', str_replace("\n", "", $post_data['post_content']));
                            $hash_data['template_extra_css'] = preg_replace('/\\s+/', '', str_replace("\n", "", $post_data['template_extra_css']));
                            $hash_data['template_extra_js'] = preg_replace('/\\s+/', '', str_replace("\n", "", $post_data['template_extra_js']));
                            if (isset($post_data['attachments'])) {
                                unset($hash_data['attachments']);
                                $hash_data['attachments'] = array();
                                foreach ($post_data['attachments'] as $key => $attvalues) {
                                    $hash_data['attachments'][] = md5($attvalues['data']);
                                    if (isset($attvalues['on_meta_html_css'])) {
                                        $hash_data['template_extra_css'] = str_replace($attvalues['on_meta_html_css'], md5($attvalues['data']), $hash_data['template_extra_css']);
                                    }
                                    if (isset($attvalues['on_meta_html_css_sizes']) && is_array($attvalues['on_meta_html_css_sizes'])) {
                                        foreach ($attvalues['on_meta_html_css_sizes'] as $tsize => $turl) {
                                            $hash_data['template_extra_css'] = str_replace($turl, md5($attvalues['data']) . '_' . $tsize, $hash_data['template_extra_css']);
                                        }
                                    }
                                    if (isset($attvalues['on_meta_html_js'])) {
                                        $hash_data['template_extra_js'] = str_replace($attvalues['on_meta_html_js'], $attvalues['data'], $hash_data['template_extra_js']);
                                    }
                                    if (isset($attvalues['on_meta_html_js_sizes']) && is_array($attvalues['on_meta_html_js_sizes'])) {
                                        foreach ($attvalues['on_meta_html_js_sizes'] as $tsize => $turl) {
                                            $hash_data['template_extra_js'] = str_replace($turl, md5($attvalues['data']) . '_' . $tsize, $hash_data['template_extra_js']);
                                        }
                                    }
                                    if (isset($attvalues['on_post_content'])) {
                                        $hash_data['post_content'] = str_replace($attvalues['on_post_content'], $attvalues['data'], $hash_data['post_content']);
                                    }
                                    if (isset($attvalues['on_post_content_sizes']) && is_array($attvalues['on_post_content_sizes'])) {
                                        foreach ($attvalues['on_post_content_sizes'] as $tsize => $turl) {
                                            $hash_data['post_content'] = str_replace($turl, md5($attvalues['data']) . '_' . $tsize, $hash_data['post_content']);
                                        }
                                    }
                                }
                            }
                            unset($hash_data['ID']);
                            $items_hash[$post['ID']] = md5(serialize($hash_data));
                        }
                    }
                }
            }
            break;
    }
    // Offer for download
    $xmldata = $xml->array2xml($data, 'views');
    if ('xml' == $mode) {
        return $xmldata;
    } elseif ('module_manager' == $mode) {
        $export_data = array('xml' => $xmldata, 'items_hash' => $items_hash);
        return $export_data;
    }
}
コード例 #8
0
ファイル: wpv-import-export.php プロジェクト: juslee/e27
/**
 * Exports data to XML.
 */
function wpv_admin_export_data($download = true)
{
    global $WP_Views;
    require_once WPV_PATH_EMBEDDED . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    // SRDJAN - add siteurl, upload url, record taxonomies old IDs
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382866/comments
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142389966/comments
    $data['site_url'] = get_site_url();
    if (is_multisite()) {
        $data['fileupload_url'] = get_option('fileupload_url');
    } else {
        $wp_upload_dir = wp_upload_dir();
        $data['fileupload_url'] = $wp_upload_dir['baseurl'];
    }
    $taxonomies = get_taxonomies('', 'objects');
    foreach ($taxonomies as $category) {
        $terms = get_terms($category->name, array('hide_empty' => 0));
        if (!empty($terms)) {
            foreach ($terms as $term) {
                $data['terms_map']['term_' . $term->term_id]['old_id'] = $term->term_id;
                $data['terms_map']['term_' . $term->term_id]['slug'] = $term->slug;
                $data['terms_map']['term_' . $term->term_id]['taxonomy'] = $category->name;
            }
        }
    }
    // Get the views
    $views = get_posts('post_type=view&post_status=any&posts_per_page=-1');
    if (!empty($views)) {
        $data['views'] = array('__key' => 'view');
        foreach ($views as $key => $post) {
            $post = (array) $post;
            if ($post['post_name']) {
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $data['views']['view-' . $post['ID']] = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $data['view']['view-' . $post['ID']]['meta'] = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if ($meta_key == '_wpv_settings') {
                            $value = maybe_unserialize($meta_value[0]);
                            $value = $WP_Views->convert_ids_to_names_in_settings($value);
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                        if ($meta_key == '_wpv_layout_settings') {
                            $value = maybe_unserialize($meta_value[0]);
                            $value = $WP_Views->convert_ids_to_names_in_layout_settings($value);
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                    }
                    if (empty($data['views']['view-' . $post['ID']]['meta'])) {
                        unset($data['views']['view-' . $post['ID']]['meta']);
                    }
                }
            }
        }
    }
    // Get the view templates
    $view_templates = get_posts('post_type=view-template&post_status=any&posts_per_page=-1');
    if (!empty($view_templates)) {
        $data['view-templates'] = array('__key' => 'view-template');
        foreach ($view_templates as $key => $post) {
            $post = (array) $post;
            if ($post['post_name']) {
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $output_mode = get_post_meta($post['ID'], '_wpv_view_template_mode', true);
                $post_data['template_mode'] = $output_mode;
                $data['view-templates']['view-template-' . $post['ID']] = $post_data;
            }
        }
    }
    // Get settings
    $options = $WP_Views->get_options();
    if (!empty($options)) {
        foreach ($options as $option_name => $option_value) {
            if (strpos($option_name, 'view_') === 0 || strpos($option_name, 'views_template_') === 0) {
                $post = get_post($option_value);
                if (!empty($post)) {
                    $options[$option_name] = $post->post_name;
                }
            }
        }
        $data['settings'] = $options;
    }
    // Offer for download
    $data = $xml->array2xml($data, 'views');
    $sitename = sanitize_key(get_bloginfo('name'));
    if (!empty($sitename)) {
        $sitename .= '.';
    }
    $filename = $sitename . 'views.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['import-mode']) && $_POST['import-mode'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    if (isset($_POST['aid']) && $_POST['aid'] != '' && isset($_POST['akey']) && $_POST['aid'] != '') {
        $code .= '$affiliate_id="' . $_POST['aid'] . '";' . "\r\n";
        $code .= '$affiliate_key="' . $_POST['akey'] . '";' . "\r\n";
    }
    $code .= "\r\n?>";
    if (!$download) {
        return $data;
    }
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'views.' . date('Y-m-d') . '.zip';
        $zip = new ZipArchive();
        $file = tempnam("tmp", "zip");
        $zip->open($file, ZipArchive::OVERWRITE);
        $res = $zip->addFromString('settings.xml', $data);
        $zip->addFromString('settings.php', $code);
        $zip->close();
        $data = file_get_contents($file);
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $zipname);
        header("Content-Type: application/zip");
        header("Content-length: " . strlen($data) . "\n\n");
        header("Content-Transfer-Encoding: binary");
        echo $data;
        unlink($file);
        die;
    } else {
        // download the xml.
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Content-Type: application/xml");
        header("Content-length: " . strlen($data) . "\n\n");
        echo $data;
        die;
    }
}
コード例 #9
0
/**
 * Exports data to XML.
 */
function wpcf_admin_export_data($download = true)
{
    /*
     * 
     * 
     * Since Types 1.2
     * Merged function with Module Manager
     * /embedded/includes/module-manager.php
     * wpcf_admin_export_selected_data( array $items, $_type = 'all', $return = 'download' )
     */
    $return = $download ? 'download' : 'xml';
    return wpcf_admin_export_selected_data(array(), 'all', $return);
    /*
     * 
     * TODO Types 1.2.1 Merged so remove from here 
     */
    require_once WPCF_EMBEDDED_ABSPATH . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    // Get groups
    $groups = get_posts('post_type=wp-types-group&post_status=null&numberposts=-1');
    if (!empty($groups)) {
        $data['groups'] = array('__key' => 'group');
        foreach ($groups as $key => $post) {
            $post = (array) $post;
            $post_data = array();
            $copy_data = array('ID', 'post_content', 'post_title', 'post_excerpt', 'post_type', 'post_status');
            foreach ($copy_data as $copy) {
                if (isset($post[$copy])) {
                    $post_data[$copy] = $post[$copy];
                }
            }
            $_data = $post_data;
            $meta = get_post_custom($post['ID']);
            if (!empty($meta)) {
                $_meta = array();
                foreach ($meta as $meta_key => $meta_value) {
                    if (in_array($meta_key, array('_wp_types_group_terms', '_wp_types_group_post_types', '_wp_types_group_fields', '_wp_types_group_templates', '_wpcf_conditional_display'))) {
                        $_meta[$meta_key] = $meta_value[0];
                    }
                }
                if (!empty($_meta)) {
                    $_data['meta'] = $_meta;
                }
            }
            $_data['checksum'] = md5(serialize($_data));
            $data['groups']['group-' . $post['ID']] = $_data;
        }
        if ($specific == 'groups') {
            return $data['groups'];
        }
    }
    // Get fields
    $fields = wpcf_admin_fields_get_fields();
    if (!empty($fields)) {
        // Add checksums before WPML
        foreach ($fields as $field_id => $field) {
            // TODO WPML and others should use hook
            $fields[$field_id] = apply_filters('wpcf_export_field', $fields[$field_id]);
            $fields[$field_id]['checksum'] = md5($field_id . serialize($field));
        }
        // WPML
        global $iclTranslationManagement;
        if (!empty($iclTranslationManagement)) {
            foreach ($fields as $field_id => $field) {
                // TODO Check this for all fields
                if (isset($iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id])) {
                    $fields[$field_id]['wpml_action'] = $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id];
                }
            }
        }
        $data['fields'] = $fields;
        $data['fields']['__key'] = 'field';
    }
    // Get custom types
    $custom_types = get_option('wpcf-custom-types', array());
    if (!empty($custom_types)) {
        foreach ($custom_types as $key => $type) {
            $custom_types[$key]['id'] = $key;
            $custom_types[$key] = apply_filters('wpcf_export_custom_post_type', $custom_types[$key]);
            $custom_types[$key]['checksum'] = md5($key . serialize($custom_types[$key]));
        }
        $data['types'] = $custom_types;
        $data['types']['__key'] = 'type';
    }
    // Get custom tax
    $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
    if (!empty($custom_taxonomies)) {
        foreach ($custom_taxonomies as $key => $tax) {
            $custom_taxonomies[$key]['id'] = $key;
            $custom_taxonomies[$key] = apply_filters('wpcf_export_custom_post_type', $custom_taxonomies[$key]);
            $custom_taxonomies[$key]['checksum'] = md5($key . serialize($custom_taxonomies[$key]));
        }
        $data['taxonomies'] = $custom_taxonomies;
        $data['taxonomies']['__key'] = 'taxonomy';
    }
    // Get post relationships
    $relationships = get_option('wpcf_post_relationship', array());
    if (!empty($relationships)) {
        $data['post_relationships']['data'] = serialize($relationships);
        $data['post_relationships']['__key'] = 'post_relationship';
    }
    // Offer for download
    $data = $xml->array2xml($data, 'types');
    $sitename = sanitize_title(get_bloginfo('name'));
    if (!empty($sitename)) {
        $sitename .= '.';
    }
    $filename = $sitename . 'types.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['embedded-settings']) && $_POST['embedded-settings'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    $code .= "\r\n?>";
    if (!$download) {
        return $data;
    }
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'types.' . date('Y-m-d') . '.zip';
        $temp_dir = sys_get_temp_dir();
        $file = tempnam($temp_dir, "zip");
        $zip = new ZipArchive();
        $zip->open($file, ZipArchive::OVERWRITE);
        $zip->addFromString('settings.xml', $data);
        $zip->addFromString('settings.php', $code);
        $zip->close();
        $data = file_get_contents($file);
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $zipname);
        header("Content-Type: application/zip");
        header("Content-length: " . strlen($data) . "\n\n");
        header("Content-Transfer-Encoding: binary");
        echo $data;
        unlink($file);
        die;
    } else {
        // download the xml.
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Content-Type: application/xml");
        header("Content-length: " . strlen($data) . "\n\n");
        echo $data;
        die;
    }
}
コード例 #10
0
/**
 * Exports data to XML.
 * Note: whatever chage done here must be done too in wpv_admin_export_selected_data()
 */
function wpv_admin_export_data($download = true)
{
    global $WP_Views;
    require_once WPV_PATH_EMBEDDED . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    // SRDJAN - add siteurl, upload url, record taxonomies old IDs
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382866/comments
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142389966/comments
    $data['site_url'] = get_site_url();
    if (is_multisite()) {
        $data['fileupload_url'] = get_option('fileupload_url');
    } else {
        $wp_upload_dir = wp_upload_dir();
        $data['fileupload_url'] = $wp_upload_dir['baseurl'];
    }
    // Get the views
    $views = get_posts('post_type=view&post_status=any&posts_per_page=-1');
    if (!empty($views)) {
        global $_wp_additional_image_sizes;
        if (!isset($_wp_additional_image_sizes) || !is_array($_wp_additional_image_sizes)) {
            $_wp_additional_image_sizes = array();
        }
        $attached_images_sizes = array_merge(array_keys($_wp_additional_image_sizes), array('thumbnail', 'medium', 'large'));
        $data['views'] = array('__key' => 'view');
        foreach ($views as $key => $post) {
            $post = (array) $post;
            if ($post['post_name']) {
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $data['views']['view-' . $post['ID']] = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $data['view']['view-' . $post['ID']]['meta'] = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if ($meta_key == '_wpv_settings') {
                            $value = maybe_unserialize($meta_value[0]);
                            // Add any taxonomy terms so we can re-map when we import.
                            if (!empty($value['taxonomy_terms'])) {
                                $taxonomy = $value['taxonomy_type'][0];
                                foreach ($value['taxonomy_terms'] as $term_id) {
                                    $term = get_term($term_id, $taxonomy);
                                    if (isset($term) && !is_wp_error($term)) {
                                        $data['terms_map']['term_' . $term->term_id]['old_id'] = $term->term_id;
                                        $data['terms_map']['term_' . $term->term_id]['slug'] = $term->slug;
                                        $data['terms_map']['term_' . $term->term_id]['taxonomy'] = $taxonomy;
                                    }
                                }
                            }
                            if (isset($value['author_mode'])) {
                                $value['author_mode']['type'] = $value['author_mode'][0];
                                unset($value['author_mode'][0]);
                            }
                            if (isset($value['taxonomy_parent_mode'])) {
                                $value['taxonomy_parent_mode']['state'] = $value['taxonomy_parent_mode'][0];
                                unset($value['taxonomy_parent_mode'][0]);
                            }
                            if (isset($value['taxonomy_search_mode'])) {
                                $value['taxonomy_search_mode']['state'] = $value['taxonomy_search_mode'][0];
                                unset($value['taxonomy_search_mode'][0]);
                            }
                            if (isset($value['search_mode'])) {
                                $value['search_mode']['state'] = $value['search_mode'][0];
                                unset($value['search_mode'][0]);
                            }
                            if (isset($value['id_mode'])) {
                                $value['id_mode']['state'] = $value['id_mode'][0];
                                unset($value['id_mode'][0]);
                            }
                            if (isset($value['users_mode'])) {
                                $value['users_mode']['type'] = $value['users_mode'][0];
                                unset($value['users_mode'][0]);
                            }
                            $value = $WP_Views->convert_ids_to_names_in_settings($value);
                            if (isset($value['post_id_ids_list']) && !empty($value['post_id_ids_list'])) {
                                $value['post_id_ids_list'] = $WP_Views->convert_ids_to_names_in_filters($value['post_id_ids_list']);
                            }
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                        if ($meta_key == '_wpv_layout_settings') {
                            $value = maybe_unserialize($meta_value[0]);
                            $value = $WP_Views->convert_ids_to_names_in_layout_settings($value);
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                        if ($meta_key == '_wpv_description') {
                            $value = maybe_unserialize($meta_value[0]);
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                    }
                    if (empty($data['views']['view-' . $post['ID']]['meta'])) {
                        unset($data['views']['view-' . $post['ID']]['meta']);
                    }
                }
                // Juan - add images for exporting
                // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                $att_args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post['ID']);
                $attachments = get_posts($att_args);
                if ($attachments) {
                    $data['views']['view-' . $post['ID']]['attachments'] = array();
                    foreach ($attachments as $attachment) {
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID] = array();
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['title'] = $attachment->post_title;
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['content'] = $attachment->post_content;
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['excerpt'] = $attachment->post_excerpt;
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['status'] = $attachment->post_status;
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['alt'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                        $imdata = base64_encode(file_get_contents($attachment->guid));
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['data'] = $imdata;
                        preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $attachment->guid, $matches);
                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['filename'] = basename($matches[0]);
                        $this_settings = get_post_meta($post['ID'], '_wpv_settings', true);
                        $this_layout_settings = get_post_meta($post['ID'], '_wpv_layout_settings', true);
                        if (isset($this_settings['pagination']['spinner_image_uploaded']) && $attachment->guid == $this_settings['pagination']['spinner_image_uploaded']) {
                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['custom_spinner'] = 'this';
                        }
                        $imthumbs = array();
                        foreach ($attached_images_sizes as $ts) {
                            $imthumbs[$ts] = wp_get_attachment_image_src($attachment->ID, $ts);
                        }
                        if (isset($this_settings['filter_meta_html'])) {
                            $pos = strpos($this_settings['filter_meta_html'], $attachment->guid);
                            if ($pos !== false) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($this_settings['filter_meta_html'], $thumbdata[0]);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        if (isset($this_settings['filter_meta_html_css'])) {
                            $pos = strpos($this_settings['filter_meta_html_css'], $attachment->guid);
                            if ($pos !== false) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_css'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($this_settings['filter_meta_html_css'], $thumbdata[0]);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        if (isset($this_settings['filter_meta_html_js'])) {
                            $pos = strpos($this_settings['filter_meta_html_js'], $attachment->guid);
                            if ($pos !== false) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_js'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($this_settings['filter_meta_html_js'], $thumbdata[0]);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_filter_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        if (isset($this_layout_settings['layout_meta_html'])) {
                            $pos = strpos($this_layout_settings['layout_meta_html'], $attachment->guid);
                            if ($pos !== false) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($this_layout_settings['layout_meta_html'], $thumbdata[0]);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        if (isset($this_settings['layout_meta_html_css'])) {
                            $pos = strpos($this_settings['layout_meta_html_css'], $attachment->guid);
                            if ($pos !== false) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_css'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($this_settings['layout_meta_html_css'], $thumbdata[0]);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        if (isset($this_settings['layout_meta_html_js'])) {
                            $pos = strpos($this_settings['layout_meta_html_js'], $attachment->guid);
                            if ($pos !== false) {
                                $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_js'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($this_settings['layout_meta_html_js'], $thumbdata[0]);
                                    if ($pos !== false) {
                                        $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_layout_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        $poscont = strpos($data['views']['view-' . $post['ID']]['post_content'], $attachment->guid);
                        if ($poscont !== false) {
                            $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_post_content'] = $attachment->guid;
                        }
                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                $pos = strpos($data['views']['view-' . $post['ID']]['post_content'], $thumbdata[0]);
                                if ($pos !== false) {
                                    $data['views']['view-' . $post['ID']]['attachments']['attach_' . $attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Get the Content templates
    $view_templates = get_posts('post_type=view-template&post_status=any&posts_per_page=-1');
    if (!empty($view_templates)) {
        global $_wp_additional_image_sizes;
        if (!isset($_wp_additional_image_sizes) || !is_array($_wp_additional_image_sizes)) {
            $_wp_additional_image_sizes = array();
        }
        $attached_images_sizes = array_merge(array_keys($_wp_additional_image_sizes), array('thumbnail', 'medium', 'large'));
        $data['view-templates'] = array('__key' => 'view-template');
        foreach ($view_templates as $key => $post) {
            $post = (array) $post;
            if ($post['post_name']) {
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $output_mode = get_post_meta($post['ID'], '_wpv_view_template_mode', true);
                $template_extra_css = get_post_meta($post['ID'], '_wpv_view_template_extra_css', true);
                $template_extra_js = get_post_meta($post['ID'], '_wpv_view_template_extra_js', true);
                $template_description = get_post_meta($post['ID'], '_wpv-content-template-decription', true);
                $post_data['template_mode'] = $output_mode;
                $post_data['template_extra_css'] = $template_extra_css;
                $post_data['template_extra_js'] = $template_extra_js;
                $post_data['template_description'] = $template_description;
                // Juan - add images for exporting
                // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                $att_args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post['ID']);
                $attachments = get_posts($att_args);
                if ($attachments) {
                    $post_data['attachments'] = array();
                    foreach ($attachments as $attachment) {
                        $post_data['attachments']['attach_' . $attachment->ID] = array();
                        $post_data['attachments']['attach_' . $attachment->ID]['title'] = $attachment->post_title;
                        $post_data['attachments']['attach_' . $attachment->ID]['content'] = $attachment->post_content;
                        $post_data['attachments']['attach_' . $attachment->ID]['excerpt'] = $attachment->post_excerpt;
                        $post_data['attachments']['attach_' . $attachment->ID]['status'] = $attachment->post_status;
                        $post_data['attachments']['attach_' . $attachment->ID]['alt'] = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                        $imdata = base64_encode(file_get_contents($attachment->guid));
                        $post_data['attachments']['attach_' . $attachment->ID]['data'] = $imdata;
                        preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $attachment->guid, $matches);
                        $post_data['attachments']['attach_' . $attachment->ID]['filename'] = basename($matches[0]);
                        $imthumbs = array();
                        foreach ($attached_images_sizes as $ts) {
                            $imthumbs[$ts] = wp_get_attachment_image_src($attachment->ID, $ts);
                        }
                        if (isset($template_extra_css)) {
                            $pos = strpos($template_extra_css, $attachment->guid);
                            if ($pos !== false) {
                                $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_css'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($template_extra_css, $thumbdata[0]);
                                    if ($pos !== false) {
                                        $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        if (isset($template_extra_js)) {
                            $posjs = strpos($template_extra_js, $attachment->guid);
                            if ($posjs !== false) {
                                $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_js'] = $attachment->guid;
                            }
                            foreach ($imthumbs as $thumbsize => $thumbdata) {
                                if (!empty($thumbdata) && isset($thumbdata[0])) {
                                    $pos = strpos($template_extra_js, $thumbdata[0]);
                                    if ($pos !== false) {
                                        $post_data['attachments']['attach_' . $attachment->ID]['on_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
                                    }
                                }
                            }
                        }
                        $poscont = strpos($post_data['post_content'], $attachment->guid);
                        if ($poscont !== false) {
                            $post_data['attachments']['attach_' . $attachment->ID]['on_post_content'] = $attachment->guid;
                        }
                        foreach ($imthumbs as $thumbsize => $thumbdata) {
                            if (!empty($thumbdata) && isset($thumbdata[0])) {
                                $pos = strpos($post_data['post_content'], $thumbdata[0]);
                                if ($pos !== false) {
                                    $post_data['attachments']['attach_' . $attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
                                }
                            }
                        }
                    }
                }
                $data['view-templates']['view-template-' . $post['ID']] = $post_data;
            }
        }
    }
    // Get settings
    $options = get_option('wpv_options');
    if (!empty($options)) {
        foreach ($options as $option_name => $option_value) {
            if (strpos($option_name, 'view_') === 0 || strpos($option_name, 'views_template_') === 0) {
                $post = get_post($option_value);
                if (!empty($post)) {
                    $options[$option_name] = $post->post_name;
                }
            }
        }
        $data['settings'] = $options;
    }
    // Offer for download
    $data = $xml->array2xml($data, 'views');
    $sitename = sanitize_key(get_bloginfo('name'));
    if (!empty($sitename)) {
        $sitename .= '.';
    }
    $filename = $sitename . 'views.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['import-mode']) && $_POST['import-mode'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    if (isset($_POST['aid']) && $_POST['aid'] != '' && isset($_POST['akey']) && $_POST['aid'] != '') {
        $code .= '$affiliate_id="' . $_POST['aid'] . '";' . "\r\n";
        $code .= '$affiliate_key="' . $_POST['akey'] . '";' . "\r\n";
    }
    $code .= "\r\n?>";
    if (!$download) {
        return $data;
    }
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'views.' . date('Y-m-d') . '.zip';
        $zip = new ZipArchive();
        $file = tempnam(sys_get_temp_dir(), "zip");
        $zip->open($file, ZipArchive::OVERWRITE);
        $res = $zip->addFromString('settings.xml', $data);
        $zip->addFromString('settings.php', $code);
        $zip->close();
        $data = file_get_contents($file);
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $zipname);
        header("Content-Type: application/zip");
        header("Content-length: " . strlen($data) . "\n\n");
        header("Content-Transfer-Encoding: binary");
        echo $data;
        unlink($file);
        die;
    } else {
        // download the xml.
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Content-Type: application/xml");
        header("Content-length: " . strlen($data) . "\n\n");
        echo $data;
        die;
    }
}
コード例 #11
0
/**
 * Exports data to XML.
 */
function wpv_admin_export_data()
{
    global $WP_Views;
    require_once WPV_PATH_EMBEDDED . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();
    // Get the views
    $views = get_posts('post_type=view&post_status=any&posts_per_page=-1');
    if (!empty($views)) {
        $data['views'] = array('__key' => 'view');
        foreach ($views as $key => $post) {
            $post = (array) $post;
            if ($post['post_name']) {
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $data['views']['view-' . $post['ID']] = $post_data;
                $meta = get_post_custom($post['ID']);
                if (!empty($meta)) {
                    $data['view']['view-' . $post['ID']]['meta'] = array();
                    foreach ($meta as $meta_key => $meta_value) {
                        if ($meta_key == '_wpv_settings') {
                            $value = maybe_unserialize($meta_value[0]);
                            $value = $WP_Views->convert_ids_to_names_in_settings($value);
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                        if ($meta_key == '_wpv_layout_settings') {
                            $value = maybe_unserialize($meta_value[0]);
                            $value = $WP_Views->convert_ids_to_names_in_layout_settings($value);
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        }
                    }
                    if (empty($data['views']['view-' . $post['ID']]['meta'])) {
                        unset($data['views']['view-' . $post['ID']]['meta']);
                    }
                }
            }
        }
    }
    // Get the view templates
    $view_templates = get_posts('post_type=view-template&post_status=any&posts_per_page=-1');
    if (!empty($view_templates)) {
        $data['view-templates'] = array('__key' => 'view-template');
        foreach ($view_templates as $key => $post) {
            $post = (array) $post;
            if ($post['post_name']) {
                $post_data = array();
                $copy_data = array('ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status');
                foreach ($copy_data as $copy) {
                    if (isset($post[$copy])) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $output_mode = get_post_meta($post['ID'], '_wpv_view_template_mode', true);
                $post_data['template_mode'] = $output_mode;
                $data['view-templates']['view-template-' . $post['ID']] = $post_data;
            }
        }
    }
    // Get settings
    $options = $WP_Views->get_options();
    if (!empty($options)) {
        foreach ($options as $option_name => $option_value) {
            if (strpos($option_name, 'view_') === 0 || strpos($option_name, 'views_template_') === 0) {
                $post = get_post($option_value);
                if (!empty($post)) {
                    $options[$option_name] = $post->post_name;
                }
            }
        }
        $data['settings'] = $options;
    }
    // Offer for download
    $data = $xml->array2xml($data, 'views');
    $sitename = sanitize_key(get_bloginfo('name'));
    if (!empty($sitename)) {
        $sitename .= '.';
    }
    $filename = $sitename . 'views.' . date('Y-m-d') . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .= isset($_POST['import-mode']) && $_POST['import-mode'] == 'ask' ? 0 : 1;
    $code .= ';' . "\r\n";
    if (isset($_POST['aid']) && $_POST['aid'] != '' && isset($_POST['akey']) && $_POST['aid'] != '') {
        $code .= '$affiliate_id="' . $_POST['aid'] . '";' . "\r\n";
        $code .= '$affiliate_key="' . $_POST['akey'] . '";' . "\r\n";
    }
    $code .= "\r\n?>";
    if (class_exists('ZipArchive')) {
        $zipname = $sitename . 'views.' . date('Y-m-d') . '.zip';
        $zip = new ZipArchive();
        $file = tempnam("tmp", "zip");
        $zip->open($file, ZipArchive::OVERWRITE);
        $res = $zip->addFromString('settings.xml', $data);
        $zip->addFromString('settings.php', $code);
        $zip->close();
        $data = file_get_contents($file);
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $zipname);
        header("Content-Type: application/zip");
        header("Content-length: " . strlen($data) . "\n\n");
        header("Content-Transfer-Encoding: binary");
        echo $data;
        unlink($file);
        die;
    } else {
        // download the xml.
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=" . $filename);
        header("Content-Type: application/xml");
        header("Content-length: " . strlen($data) . "\n\n");
        echo $data;
        die;
    }
}
コード例 #12
0
/**
 * Exports data to XML.
 * Note: whatever chage done here must be done too in wpv_admin_export_selected_data()
 */
function wpv_admin_export_data( $download = true ) {
    global $WP_Views, $_wp_additional_image_sizes;

    require_once WPV_PATH_EMBEDDED . '/common/array2xml.php';
    $xml = new ICL_Array2XML();
    $data = array();

    // SRDJAN - add siteurl, upload url, record taxonomies old IDs
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142382866/comments
    // https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/142389966/comments
    $data['site_url'] = get_site_url();
    if ( is_multisite() ) {
        $data['fileupload_url'] = get_option('fileupload_url');
    } else {
        $wp_upload_dir = wp_upload_dir();
        $data['fileupload_url'] = $wp_upload_dir['baseurl'];
    }
	
	/**
	* wpv_filter_view_extra_fields_for_import_export
	*
	* Filter set the postmeta needed for Views export and import, beyond the settings and layout settings
	*
	* @param (array) The postmeta keys
	*
	* @since 1.7
	*/
	
	$extra_metas = apply_filters( 'wpv_filter_view_extra_fields_for_import_export', array() );

    // Get the views
    $views = get_posts( 'post_type=view&post_status=any&posts_per_page=-1' );
    if ( ! empty( $views ) ) {
		if ( 
			! isset( $_wp_additional_image_sizes ) 
			|| ! is_array( $_wp_additional_image_sizes ) 
		) {
			$_wp_additional_image_sizes = array();
		}
		$attached_images_sizes = array_merge(
			// additional thumbnail sizes
			array_keys( $_wp_additional_image_sizes ),
			// wp default thumbnail sizes
			array( 'thumbnail', 'medium', 'large' )
		);
        $data['views'] = array( '__key' => 'view' );
        foreach ( $views as $key => $post ) {
            $post = (array) $post;
            if ( $post['post_name'] ) {
                $post_data = array();
				$this_settings = array();
				$this_layout_settings = array();
				$this_settings_metaboxes = array(
					'filter_meta_html',
					'filter_meta_html_css',
					'filter_meta_html_js',
					'layout_meta_html_css',
					'layout_meta_html_js'
				);
				$this_layout_settings_metaboxes = array(
					'layout_meta_html'
				);
                $copy_data = array( 'ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status' );
                foreach ( $copy_data as $copy ) {
                    if ( isset( $post[$copy] ) ) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $data['views']['view-' . $post['ID']] = $post_data;
                $meta = get_post_custom( $post['ID'] );
                if ( ! empty( $meta ) ) {
                    $data['view']['view-' . $post['ID']]['meta'] = array();
                    foreach ( $meta as $meta_key => $meta_value ) {
                        if ( $meta_key == '_wpv_settings' ) {
                            $value = maybe_unserialize( $meta_value[0] );
							$this_settings = $value;
                            // Add data from the taxonomy terms query filter so we can re-map when we import
                            if ( ! empty( $value['taxonomy_terms'] ) ) {
                    			$taxonomy = $value['taxonomy_type'][0];
                                foreach ( $value['taxonomy_terms'] as $term_id ) {
                                    if ( ! isset( $data['terms_map']['term_' . $term_id] ) ) {
										$term = get_term( $term_id, $taxonomy );
										if ( 
											isset( $term ) 
											&& ! is_wp_error( $term ) 
										) {
											$data['terms_map']['term_' . $term->term_id]['old_id'] = $term->term_id;
											$data['terms_map']['term_' . $term->term_id]['slug'] = $term->slug;
											$data['terms_map']['term_' . $term->term_id]['taxonomy'] = $taxonomy;
										}
									}
                                }
                            }
							
							/**
							* wpv_filter_adjust_view_settings_for_export
							*
							* Filter to adjust Views settings on export
							*
							* Some View settings are stored as indexed arrays, producing errors on index 0
							* We need to transform those indexed arrays into associative arrays before export, that will be restored on import
							* Also, some settings contain IDs pointing to other Views or Content Templates
							* We need to transform them into names, that will be restored on import
							*
							* @param (array) $value The View settings
							* @param (array) $post The View post object as an array
							*
							* @since 1.7
							*/
							
							$value = apply_filters( 'wpv_filter_adjust_view_settings_for_export', $value, $post );
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        } else if ( $meta_key == '_wpv_layout_settings' ) {
                            $value = maybe_unserialize( $meta_value[0] );
							$this_layout_settings = $value;
							
							/**
							* wpv_filter_adjust_view_layout_settings_for_export
							*
							* Filter to adjust Views layouts settings on export
							*
							* @param (array) $value The View layout settings
							* @param (array) $post The View post object as an array
							*
							* @since 1.7
							*/
							
							$value = apply_filters( 'wpv_filter_adjust_view_layout_settings_for_export', $value, $post );
                            $data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
                        } else {
							if ( in_array( $meta_key, $extra_metas ) ) {
								$value = maybe_unserialize( $meta_value[0] );
								
								/**
								* wpv_filter_adjust_view_extra_fields_for_export
								*
								* Filter to adjust Views postmeta needed on export
								*
								* @param (array) $value The postmeta value
								* @param (array) $post The View post object as an array
								* @meta_key (string) The postmeta key being adjusted
								*
								* @since 1.7
								*/
								
								$value = apply_filters( 'wpv_filter_adjust_view_extra_fields_for_export', $value, $post, $meta_key );
								if ( ! empty( $value ) ) {
									$data['views']['view-' . $post['ID']]['meta'][$meta_key] = $value;
								}
							}
						}
                    }
                    if ( empty( $data['views']['view-' . $post['ID']]['meta'] ) ) {
                        unset( $data['views']['view-' . $post['ID']]['meta'] );
                    }
                }
                // Juan - add images for exporting
				// https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
				$att_args = array( 
					'post_type' => 'attachment', 
					'numberposts' => -1, 
					'post_status' => null, 
					'post_parent' => $post['ID'] 
				);
				$attachments = get_posts( $att_args );
				if ( $attachments ) {
					$data['views']['view-' . $post['ID']]['attachments'] = array();
					foreach ( $attachments as $attachment ) {
						$image_type = get_post_mime_type( $attachment->ID );	
						if ( 
							$image_type 
							&& (
								$image_type == 'image/jpeg' 
								|| $image_type == 'image/png' 
								|| $image_type == 'image/gif'
							) 
						) {
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID] = array();
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['title'] = $attachment->post_title;
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['content'] = $attachment->post_content;
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['excerpt'] = $attachment->post_excerpt;
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['status'] = $attachment->post_status;
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['alt'] = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true );
							$imdata = base64_encode( file_get_contents( $attachment->guid ) );
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['data'] = $imdata;
							preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $attachment->guid, $matches );
							$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['filename'] = basename( $matches[0] );
							// NOTE we adjust the 'spinner_image' for pagination and dps on import
							if ( 
								isset( $this_settings['pagination']['spinner_image_uploaded'] ) 
								&& $attachment->guid == $this_settings['pagination']['spinner_image_uploaded'] 
							) {
								$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['custom_spinner'] = 'this';
							}
							if ( 
								isset( $this_settings['dps']['spinner_image_uploaded'] ) 
								&& $attachment->guid == $this_settings['dps']['spinner_image_uploaded'] 
							) {
								$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['dps_custom_spinner'] = 'this';
							}
							$imthumbs = array();
							foreach ( $attached_images_sizes as $ts ) {
								$imthumbs[$ts] = wp_get_attachment_image_src( $attachment->ID, $ts );
							}
							foreach ( $imthumbs as $thumbsize => $thumbdata ) {
								if ( 
									isset( $this_settings['pagination']['spinner_image_uploaded'] ) 
									&& $thumbdata == $this_settings['pagination']['spinner_image_uploaded'] 
								) {
									$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['custom_spinner'] = 'this_' . $thumbsize;
								}
								if ( 
									isset( $this_settings['dps']['spinner_image_uploaded'] ) 
									&& $thumbdata == $this_settings['dps']['spinner_image_uploaded'] 
								) {
									$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['dps_custom_spinner'] = 'this_' . $thumbsize;
								}
							}
							foreach ( $this_settings_metaboxes as $metabox_id ) {
								if ( isset( $this_settings[$metabox_id] ) ) {
									$pos = strpos( $this_settings[$metabox_id], $attachment->guid );
									if ( $pos !== false ) {
										$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['on_' . $metabox_id] = $attachment->guid;
									}
									foreach ( $imthumbs as $thumbsize => $thumbdata ) {
										if ( 
											! empty( $thumbdata ) 
											&& isset( $thumbdata[0] ) 
										) {
											$pos = strpos( $this_settings[$metabox_id], $thumbdata[0] );
											if ( $pos !== false ) {
												$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['on_' . $metabox_id . '_sizes'][$thumbsize] = $thumbdata[0];
											}
										}
									}
								}
							}
							foreach ( $this_layout_settings_metaboxes as $metabox_id ) {
								if ( isset( $this_layout_settings[$metabox_id] ) ) {
									$pos = strpos( $this_layout_settings[$metabox_id], $attachment->guid );
									if ( $pos !== false ) {
										$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['on_' . $metabox_id] = $attachment->guid;
									}
									foreach ( $imthumbs as $thumbsize => $thumbdata ) {
										if ( 
											! empty( $thumbdata) 
											&& isset( $thumbdata[0] ) 
										) {
											$pos = strpos( $this_layout_settings[$metabox_id], $thumbdata[0] );
											if ( $pos !== false ) {
												$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['on_' . $metabox_id . '_sizes'][$thumbsize] = $thumbdata[0];
											}
										}
									}
								}
							}
							$poscont = strpos( $data['views']['view-' . $post['ID']]['post_content'], $attachment->guid );
							if ( $poscont !== false ) {
								$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['on_post_content'] = $attachment->guid;
							}
							foreach ( $imthumbs as $thumbsize => $thumbdata ) {
								if (
									! empty( $thumbdata ) 
									&& isset( $thumbdata[0] )
								) {
									$pos = strpos( $data['views']['view-' . $post['ID']]['post_content'], $thumbdata[0] );
									if ( $pos !== false ) {
										$data['views']['view-' . $post['ID']]['attachments']['attach_'.$attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
									}
								}
							}
						}
					}
				}
			}
		}
	}

    // Get the Content Templates
    $view_templates = get_posts( 'post_type=view-template&post_status=any&posts_per_page=-1' );
    if ( ! empty( $view_templates ) ) {
		if ( 
			! isset( $_wp_additional_image_sizes ) 
			|| ! is_array( $_wp_additional_image_sizes ) 
		) {
			$_wp_additional_image_sizes = array();
		}
		$attached_images_sizes = array_merge(
			// additional thumbnail sizes
			array_keys( $_wp_additional_image_sizes ),
			// wp default thumbnail sizes
			array( 'thumbnail', 'medium', 'large' )
		);
        $data['view-templates'] = array( '__key' => 'view-template' );
        foreach ( $view_templates as $key => $post ) {
            $post = (array) $post;
            if ( $post['post_name'] ) {
                $post_data = array();
                $copy_data = array( 'ID', 'post_content', 'post_title', 'post_name', 'post_excerpt', 'post_type', 'post_status' );
                foreach ( $copy_data as $copy ) {
                    if ( isset( $post[$copy] ) ) {
                        $post_data[$copy] = $post[$copy];
                    }
                }
                $output_mode = get_post_meta( $post['ID'], '_wpv_view_template_mode', true );
				$template_extra_css = get_post_meta( $post['ID'], '_wpv_view_template_extra_css', true );
				$template_extra_js = get_post_meta( $post['ID'], '_wpv_view_template_extra_js', true );
				$template_description = get_post_meta( $post['ID'], '_wpv-content-template-decription', true );
				$post_data['template_mode'] = $output_mode;
				$post_data['template_extra_css'] = $template_extra_css;
				$post_data['template_extra_js'] = $template_extra_js;
				$post_data['template_description'] = $template_description;
                // Juan - add images for exporting
				// https://icanlocalize.basecamphq.com/projects/7393061-wp-views/todo_items/150919286/comments
                $att_args = array( 
					'post_type' => 'attachment',
					'numberposts' => -1,
					'post_status' => null,
					'post_parent' => $post['ID'] 
				);
				$attachments = get_posts( $att_args );
				if ( $attachments ) {
					$post_data['attachments'] = array();
					foreach ( $attachments as $attachment ) {
						$image_type = get_post_mime_type( $attachment->ID );	
						if ( 
							$image_type 
							&& (
								$image_type == 'image/jpeg' 
								|| $image_type == 'image/png' 
								|| $image_type == 'image/gif'
							) 
						) {
							$post_data['attachments']['attach_'.$attachment->ID] = array();
							$post_data['attachments']['attach_'.$attachment->ID]['title'] = $attachment->post_title;
							$post_data['attachments']['attach_'.$attachment->ID]['content'] = $attachment->post_content;
							$post_data['attachments']['attach_'.$attachment->ID]['excerpt'] = $attachment->post_excerpt;
							$post_data['attachments']['attach_'.$attachment->ID]['status'] = $attachment->post_status;
							$post_data['attachments']['attach_'.$attachment->ID]['alt'] = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true );
							$imdata = base64_encode( file_get_contents( $attachment->guid ) );
							$post_data['attachments']['attach_'.$attachment->ID]['data'] = $imdata;
							preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $attachment->guid, $matches );
							$post_data['attachments']['attach_'.$attachment->ID]['filename'] = basename( $matches[0] );
							$imthumbs = array();
							foreach ( $attached_images_sizes as $ts ) {
								$imthumbs[$ts] = wp_get_attachment_image_src( $attachment->ID, $ts );
							}
							if ( isset( $template_extra_css ) ) {
								$pos = strpos( $template_extra_css, $attachment->guid );
								if ( $pos !== false ) {
									$post_data['attachments']['attach_'.$attachment->ID]['on_meta_html_css'] = $attachment->guid;
								}
								foreach ( $imthumbs as $thumbsize => $thumbdata ) {
									if ( 
										! empty( $thumbdata ) 
										&& isset( $thumbdata[0] ) 
									) {
										$pos = strpos( $template_extra_css, $thumbdata[0] );
										if ( $pos !== false ) {
											$post_data['attachments']['attach_'.$attachment->ID]['on_meta_html_css_sizes'][$thumbsize] = $thumbdata[0];
										}
									}
								}
							}
							if ( isset( $template_extra_js ) ) {
								$posjs = strpos( $template_extra_js, $attachment->guid );
								if ( $posjs !== false ) {
									$post_data['attachments']['attach_'.$attachment->ID]['on_meta_html_js'] = $attachment->guid;
								}
								foreach ( $imthumbs as $thumbsize => $thumbdata ) {
									if ( 
										! empty( $thumbdata ) 
										&& isset( $thumbdata[0] ) 
									) {
										$pos = strpos( $template_extra_js, $thumbdata[0] );
										if ( $pos !== false ) {
											$post_data['attachments']['attach_'.$attachment->ID]['on_meta_html_js_sizes'][$thumbsize] = $thumbdata[0];
										}
									}
								}
							}
							$poscont = strpos( $post_data['post_content'], $attachment->guid );
							if ( $poscont !== false ) {
								$post_data['attachments']['attach_'.$attachment->ID]['on_post_content'] = $attachment->guid;
							}
							foreach ( $imthumbs as $thumbsize => $thumbdata ) {
								if ( 
									! empty( $thumbdata ) 
									&& isset( $thumbdata[0] ) 
								) {
									$pos = strpos( $post_data['post_content'], $thumbdata[0] );
									if ( $pos !== false ) {
										$post_data['attachments']['attach_'.$attachment->ID]['on_post_content_sizes'][$thumbsize] = $thumbdata[0];
									}
								}
							}
						}
					}
				}
                $data['view-templates']['view-template-' . $post['ID']] = $post_data;
            }
        }
    }

    // Get settings
    global $WPV_settings;
    if ( ! $WPV_settings->is_empty() ) {
		global $wpdb;
		$wpv_settings_to_export = array();
        foreach ( $WPV_settings as $option_name => $option_value ) {
            if ( 
				strpos( $option_name, 'view_' ) === 0 
				|| strpos( $option_name, 'views_template_' ) === 0 
			) {
                $item_name = $wpdb->get_var( 
					$wpdb->prepare( 
						"SELECT post_name FROM {$wpdb->posts} 
						WHERE ID = %s 
						LIMIT 1", 
						$option_value 
					) 
				);
				if ( $item_name ) {
					$wpv_settings_to_export[$option_name] = $item_name;
				}
            } else if (
				in_array( $option_name, array( 'wpv_custom_inner_shortcodes', 'wpv_custom_conditional_functions' ) )
				&& is_array( $option_value )
			) {
				$sanitized_option_value = array();
				foreach ( $WPV_settings[$option_name] as $candidate_value ) {
					$sanitized_key = str_replace( '::', '-_paamayim_-', $candidate_value );
					$sanitized_option_value[$sanitized_key] = $candidate_value;
				}
				$wpv_settings_to_export[$option_name] = $sanitized_option_value;
			} else if ( 
				'wpv_framework_keys' == $option_name 
				&& is_array( $option_value )
			) {
				foreach ( $WPV_settings['wpv_framework_keys'] as $framework_id => $framework_keys ) {
					if ( 
						is_array( $framework_keys ) 
						&& ! empty( $framework_keys )
					) {
						$sanitized_framework_keys = array();
						foreach ( $framework_keys as $candidate_key ) {
							$sanitized_framework_keys[$candidate_key] = $candidate_key;
						}
						$wpv_settings_to_export['wpv_framework_keys'][$framework_id] = $sanitized_framework_keys;
					}
				}
			} else {
				$wpv_settings_to_export[$option_name] = $option_value;
			}
        }
        $data['settings'] = $wpv_settings_to_export;
    }

    // Offer for download
    $data = $xml->array2xml($data, 'views');

    $sitename = sanitize_key( get_bloginfo( 'name' ) );
    if ( ! empty( $sitename ) ) {
        $sitename .= '.';
    }
    $filename = $sitename . 'views.' . date( 'Y-m-d' ) . '.xml';
    $code = "<?php\r\n";
    $code .= '$timestamp = ' . time() . ';' . "\r\n";
    $code .= '$auto_import = ';
    $code .=  ( isset( $_POST['import-mode'] ) && $_POST['import-mode'] == 'ask' ) ? 0 : 1;
    $code .= ';' . "\r\n";
    if ( isset($_POST['aid'] ) && $_POST['aid'] != '' && isset( $_POST['akey'] ) && $_POST['akey'] != '' ) {
        $code .= '$affiliate_id="' . $_POST['aid'] . '";' . "\r\n";
        $code .= '$affiliate_key="' . $_POST['akey'] . '";' . "\r\n";
    }
    $code .= "\r\n?>";

    if ( ! $download ) {
        return $data;
    }
    if ( class_exists( 'ZipArchive' ) ) {
        $zipname = $sitename . 'views.' . date( 'Y-m-d' ) . '.zip';
        $zip = new ZipArchive();
        $file = tempnam( sys_get_temp_dir(), "zip" );
        $zip->open( $file, ZipArchive::OVERWRITE );
        $res = $zip->addFromString( 'settings.xml', $data );
        $zip->addFromString( 'settings.php', $code );
        $zip->close();
        $data = file_get_contents( $file );
        header( "Content-Description: File Transfer" );
        header( "Content-Disposition: attachment; filename=" . $zipname );
        header( "Content-Type: application/zip" );
        header( "Content-length: " . strlen($data) . "\n\n" );
        header( "Content-Transfer-Encoding: binary" );
        echo $data;
        unlink( $file );
        die();
    } else {
        // download the xml.
        header( "Content-Description: File Transfer" );
        header( "Content-Disposition: attachment; filename=" . $filename );
        header( "Content-Type: application/xml" );
        header( "Content-length: " . strlen( $data ) . "\n\n" );
        echo $data;
        die();
    }
}