/** * WordPress lacks an "onUpdate" event, so this is a home-rolled way I can run * a specific bit of code when a new version of the plugin is installed. The way * this works is the names of all files inside of the updates/ folder are loaded * into an array, e.g. 0.9.4, 0.9.5. When the first new page request comes through * WP, the database is in the old state, whereas the code is new, so the database * will say e.g. that the plugin version is 0.1 and the code will say the plugin version * is 0.2. All the available updates are included and their contents are executed * in order. This ensures that all update code is run sequentially. * * Any version prior to 0.9.4 is considered "version 0" by this process. * */ public static function check_for_updates() { // If it's not a new install, we check for updates if (version_compare(self::get_stored_version(), self::get_current_version(), '<')) { // set the flag define('CCTM_UPDATE_MODE', 1); cctm_run_tests(); // Load up available updates in order // Older systems don't have FilesystemIterator // $updates = new FilesystemIterator(CCTM_PATH.'/updates', FilesystemIterator::KEY_AS_PATHNAME); $updates = scandir(CCTM_PATH . '/updates'); foreach ($updates as $file) { // Skip the gunk if ($file === '.' || $file === '..') { continue; } if (is_dir(CCTM_PATH . '/updates/' . $file)) { continue; } if (substr($file, 0, 1) == '.') { continue; } // skip non-php files if (pathinfo(CCTM_PATH . '/updates/' . $file, PATHINFO_EXTENSION) != 'php') { continue; } // We don't want to re-run older updates $this_update_ver = substr($file, 0, -4); if (version_compare(self::get_stored_version(), $this_update_ver, '<')) { // Run the update by including the file include CCTM_PATH . '/updates/' . $file; // timestamp the update self::$data['cctm_update_timestamp'] = time(); // req's new data structure // store the new version after the update self::$data['cctm_version'] = $this_update_ver; // req's new data structure update_option(self::db_key, self::$data); } } // Clear the cache and such unset(CCTM::$data['cache']); unset(CCTM::$data['warnings']); // Mark the update self::$data['cctm_version'] = self::get_current_version(); update_option(self::db_key, self::$data); } // If this is empty, then it is a first install, so we timestamp it // and prep the data structure if (empty(CCTM::$data)) { // TODO: run tests CCTM::$data['cctm_installation_timestamp'] = time(); CCTM::$data['cctm_version'] = CCTM::get_current_version(); CCTM::$data['export_info'] = array('title' => 'CCTM Site', 'author' => get_option('admin_email', ''), 'url' => get_option('siteurl', 'http://wpcctm.com/'), 'description' => __('This site was created in part using the Custom Content Type Manager', CCTM_TXTDOMAIN)); update_option(CCTM::db_key, CCTM::$data); } }
if (!isset($data['help']) || empty($data['help'])) { $data['help'] = 'http://code.google.com/p/wordpress-custom-content-type-manager/'; } ?> <div class="wrap"> <?php /*---------------- HEADER and TABS --------------------------- */ ?> <div id="cctm_header"> <img src="<?php print CCTM_URL; ?> /images/cctm-logo.png" alt="custom-content-type-manager-logo" width="88" height="55" style="float:left; margin-right:20px;"/> <p class="cctm_header_text">Custom Content Type Manager <span class="cctm_version">[<?php print CCTM::get_current_version(); ?> ]</span> <a href="<?php print $data['help']; ?> " target="_new" title="Contextual Help" style="text-decoration: none;"> <img src="<?php print CCTM_URL; ?> /images/question-mark.gif" width="16" height="16" /> </a> <br/> <span class="cctm_page_title"><?php print $data['page_title']; ?>
/** * Convert the CCTM self::$data (i.e. THE data) to the data structure we use in * an export file. * * @param mixed from CCTM::$data * @return mixed groomed data with some tracking info appended */ public static function get_payload_from_data($data) { $payload = array(); // Grab the important stuff $payload['export_info'] = CCTM::get_value($data, 'export_info'); $payload['post_type_defs'] = CCTM::get_value($data, 'post_type_defs', array()); $payload['custom_field_defs'] = CCTM::get_value($data, 'custom_field_defs', array()); // 1. Filter out absolute paths used for menu icons (they won't translate to a new server). foreach ($payload['post_type_defs'] as $post_type => $def) { if (isset($payload['post_type_defs'][$post_type]['menu_icon']) && !empty($payload['post_type_defs'][$post_type]['menu_icon'])) { $payload['post_type_defs'][$post_type]['menu_icon'] = self::make_img_path_rel($payload['post_type_defs'][$post_type]['menu_icon']); } } // 2. Zero out any default values for referential fields (any other site won't have the same post IDs to support them) // See http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=66 foreach ($payload['custom_field_defs'] as $field => $field_def) { if (in_array($field_def['type'], self::$referential_field_types)) { $payload['custom_field_defs'][$field]['default_value'] = ''; } } // Append additional tracking info // consider user data: http://codex.wordpress.org/get_currentuserinfo $payload['export_info']['_timestamp_export'] = time(); $payload['export_info']['_source_site'] = site_url(); $payload['export_info']['_charset'] = get_bloginfo('charset'); $payload['export_info']['_language'] = get_bloginfo('language'); $payload['export_info']['_wp_version'] = get_bloginfo('version'); $payload['export_info']['_cctm_version'] = CCTM::get_current_version(); return $payload; }