$nonce = wp_create_nonce('cctm_download_definition'); $save_me = CCTM_ImportExport::get_payload_from_data(CCTM::$data); $save_me = json_encode($save_me); $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', sprintf(__('Your Custom Content Type definition %s should begin downloading shortly. If there is a problem downloading, you can copy the text below into a text editor and save it with a <code>.cctm.json</code> extension.', CCTM_TXTDOMAIN), '<strong>' . CCTM_ImportExport::get_download_title($sanitized['title']) . '</strong>')); $data['msg'] .= "<textarea rows='10' cols='100'>{$save_me}</textarea>"; // Save the options: anything that's in the form is considered a valid "info" key. self::$data['export_info'] = $sanitized; update_option(self::db_key, self::$data); // Fire off a request to download the file: //$data['msg'] .= sprintf('<script type="text/javascript" src="%s"></script>', CCTM_URL.'/js/download_def.js'); $data['msg'] .= sprintf('<script type="text/javascript">window.location="%s"</script>', CCTM_URL . '/ajax-controllers/download_def.php'); } elseif ($_POST['export_type'] == 'to_library') { // Save the options: anything that's in the form is considered a valid "info" key. self::$data['export_info'] = $sanitized; update_option(self::db_key, self::$data); if (CCTM_ImportExport::export_to_local_webserver()) { $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('Your Custom Content Type definition has been saved to your library. <a href="?page=cctm_tools&a=import_def">Click here</a> to view your library.', CCTM_TXTDOMAIN)); } else { $data['msg'] = CCTM::format_errors(); } } } // Populate the values $data['title'] = CCTM::get_value(self::$data['export_info'], 'title'); $data['author'] = CCTM::get_value(self::$data['export_info'], 'author'); $data['url'] = CCTM::get_value(self::$data['export_info'], 'url'); $data['description'] = CCTM::get_value(self::$data['export_info'], 'description'); $data['template_url'] = CCTM::get_value(self::$data['export_info'], 'template_url'); $data['content'] = CCTM::load_view('export.php', $data); print CCTM::load_view('templates/default.php', $data); /*EOF*/
self::set_flash($data['msg']); } // Refresh the list of files print '<script type="text/javascript">window.location.replace("?page=cctm_tools&a=import_def");</script>'; return; } elseif (wp_verify_nonce($nonce, 'cctm_delete_defs')) { $defs = CCTM::get_value($_POST, 'defs', array()); if (CCTM_ImportExport::delete_defs($defs)) { $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('Files have been removed from your library.', CCTM_TXTDOMAIN)); CCTM::set_flash($data['msg']); print '<script type="text/javascript">window.location.replace("?page=cctm_tools&a=import_def");</script>'; return; } else { $data['msg'] = CCTM::format_errors(); } } elseif (wp_verify_nonce($nonce, 'cctm_activate_def')) { if (CCTM_ImportExport::activate_def($_POST['def'])) { $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('The definition was imported successfully!', CCTM_TXTDOMAIN)); CCTM::set_flash($data['msg']); print '<script type="text/javascript">window.location.replace("?page=cctm_tools&a=import_def");</script>'; return; } else { $data['msg'] = CCTM::format_errors(); } } else { $data['msg'] = __('Invalid submission.', CCTM_TXTDOMAIN); } } $data['content'] = CCTM::load_view('import.php', $data); print CCTM::load_view('templates/default.php', $data); /*EOF*/
include_once CCTM_PATH . '/includes/CCTM_ImportExport.php'; // Make sure a file was specified $filename = CCTM::get_value($_REQUEST, 'file'); if (empty($filename)) { print CCTM::format_error_msg(__('Definition file not specified.', CCTM_TXTDOMAIN)); exit; } // Make sure the filename is legit if (!CCTM_ImportExport::is_valid_basename($filename)) { print CCTM::format_error_msg(__('Invalid filename: the definition filename should not contain spaces and should use an extension of <code>.cctm.json</code>.', CCTM_TXTDOMAIN)); exit; } // Load up this thing... errors will be thrown $upload_dir = wp_upload_dir(); $dir = $upload_dir['basedir'] . '/' . CCTM::base_storage_dir . '/' . CCTM::def_dir . '/'; $data = CCTM_ImportExport::load_def_file($dir . $filename); $data['filename'] = $filename; // Bail if there were errors if (!empty(CCTM::$errors)) { print CCTM::format_errors(); exit; } // Check encoding, warn if it differs (warn only: it may not be a problem for the importer) // See http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=322 $this_charset = get_bloginfo('charset'); if (isset($data['export_info']['_charset']) && $data['export_info']['_charset'] != $this_charset) { CCTM::$errors['encoding'] = sprintf(__("Your site's encoding differs from the encoding used to create this definition file. This may create problems if the post-type and field definitions use foreign characters. Adding the following to your wp-config.php file may alleviate problems with character encoding: <code>define('DB_CHARSET', '%s');</code>", CCTM_TXTDOMAIN), $data['export_info']['_charset']); } print CCTM::format_errors(); // but do NOT exit. It's only a warning, so we continue. print CCTM::load_view('preview_def.php', $data);
<?php //if ( ! defined('CCTM_PATH')) exit('No direct script access allowed'); //if (!current_user_can('manage_options')) exit('You do not have permission to do that.'); /*------------------------------------------------------------------------------ Standalone controller to cough up a download. ------------------------------------------------------------------------------*/ require_once '../../../../wp-load.php'; require_once '../includes/constants.php'; require_once '../includes/CCTM.php'; require_once CCTM_PATH . '/includes/CCTM_ImportExport.php'; CCTM_ImportExport::export_to_desktop(); /*EOF*/
if (!defined('CCTM_PATH')) { exit('No direct script access allowed'); } if (!current_user_can('administrator')) { exit('Admins only.'); } /*------------------------------------------------------------------------------ @param string local name of the uploaded file (stored in wp-content/uploads/cctm/defs) ------------------------------------------------------------------------------*/ require_once CCTM_PATH . '/includes/CCTM_ImportExport.php'; // Validate: check file name if (!CCTM_ImportExport::is_valid_basename($file)) { $msg = '<div class="error"><p>' . sprintf(__('Bad filename: %s. No special characters or spaces allowed.', CCTM_TXTDOMAIN), '<strong>' . htmlspecialchars($filename) . '</strong>') . '</p></div>'; self::set_flash($msg); return self::page_import(); } $upload_dir = wp_upload_dir(); $dir = $upload_dir['basedir'] . '/' . self::base_storage_dir . '/' . self::def_dir; $data_raw = file_get_contents($dir . '/' . $file); $data = json_decode($data_raw, true); // Check the contents of the array if (!CCTM_ImportExport::is_valid_upload_structure($data)) { $msg = '<div class="error"><p>' . sprintf(__('%s contained an incompatible data structure.', CCTM_TXTDOMAIN), '<strong>' . htmlspecialchars($file) . '</strong>') . '</p></div>'; self::set_flash($msg); return self::page_import(); } $settings = get_option(CCTM::db_key_settings, array()); $settings['candidate'] = $data; update_option(CCTM::db_key_settings, $settings); return self::page_import(); /*EOF*/