Пример #1
0
 /**
  * Replace export process by saving each type in a separate file
  */
 public function export()
 {
     if (empty($_POST['export'])) {
         $this->addMessage('updated', "Types will be saved to your theme’s directory and imported automatically.");
         return;
         // Not exporting
     }
     $_POST = array();
     // Cancel export process
     $data = wpcf_admin_export_selected_data(array(), 'all', 'array');
     foreach ($data as $export_type => $exported) {
         $tagname = $exported['__key'];
         foreach ($exported as $id => $type) {
             if (empty($type['id']) && empty($type['ID'])) {
                 continue;
             }
             // not a type
             if ($export_type == 'groups') {
                 // Use name instead of ID for groups
                 $type['ID'] = $id = $type['__types_id'];
             }
             $this->normalizeType($type, $export_type);
             $type_data = array($export_type => array($id => $type, '__key' => $tagname));
             self::writeConfigs("types/{$export_type}/{$id}", $type_data);
             $index[$export_type][$id] = md5(serialize($type));
             $notices[] = $type['__types_title'];
         }
     }
     update_option('types-manager-index', $index);
     $this->addMessage('updated', "The following types were exported: " . implode(', ', $notices));
     // Ensure plugin is loaded
     self::writeConfigs("plugins/types", array('plugins' => array('wp-types' => 'Types')));
 }
Пример #2
0
 function wpcf_export_modules_items_taxonomies($res, $items)
 {
     foreach ($items as $ii => $item) {
         if (isset($item['id'])) {
             $items[$ii] = str_replace('12' . _TAX_MODULE_MANAGER_KEY_ . '21', '', $item['id']);
         }
     }
     $xmlstring = wpcf_admin_export_selected_data($items, 'taxonomies', 'module_manager');
     return $xmlstring;
 }
Пример #3
0
 function wpcf_export_modules_items_taxonomies($res, $items)
 {
     $items_exported = array();
     foreach ($items as $ii => $item) {
         if (isset($item['id'])) {
             $items_exported[$ii] = wpcf_modman_get_submitted_id(_TAX_MODULE_MANAGER_KEY_, $item['id']);
         }
     }
     require_once WPCF_INC_ABSPATH . '/import-export.php';
     $xmlstring = wpcf_admin_export_selected_data(array_values($items_exported), _TAX_MODULE_MANAGER_KEY_, 'module_manager');
     /* 
         the problem is that the wpcf_admin_export_selected_data returns the items $xmlstring['items'] 
         in wrong format (using the raw id) and also misses the rest of items fields (like details, etc..)
         
         use this debug function to see what the original items were and what are returned as items
         modman_log(array($items, $xmlstring['items']));
         *the idea was to add extra fields (like hash) on the passed items, not change their format*
         fix that here..
     */
     $returned_items = $xmlstring['items'];
     unset($xmlstring['items']);
     foreach ($items as $ii => $item) {
         $raw_id = wpcf_modman_get_submitted_id(_TAX_MODULE_MANAGER_KEY_, $item['id']);
         if (isset($returned_items[$raw_id])) {
             // keep the id, not overwrite it, to avoid rewid/namespacedid issues since array_merge is done
             $returned_items[$raw_id]['id'] = $item['id'];
             $items[$ii] = array_merge($items[$ii], $returned_items[$raw_id]);
             unset($returned_items[$raw_id]);
         }
     }
     //$items=array_merge($items, $returned_items); // add the fields also
     $xmlstring['items'] = $items;
     return $xmlstring;
 }
Пример #4
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);
}
Пример #5
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;
    }
}
Пример #6
0
 function wpcf_export_modules_items_taxonomies($res, $items)
 {
     foreach ($items as $ii => $item) {
         $items[$ii] = str_replace('12' . _TAX_MODULE_MANAGER_KEY_ . '21', '', $item);
     }
     require_once WPCF_INC_ABSPATH . '/import-export.php';
     $xmlstring = wpcf_admin_export_selected_data($items, 'taxonomies', 'module_manager');
     return $xmlstring;
 }