5.2 $parts_new = pathinfo( $upload['url'] ); $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new; } return $post_id; } /** * Attempt to download a remote file attachment * * @param string $url URL of item to fetch * @param array $post Attachment details * @return array|WP_Error Local file location details on success, WP_Error otherwise */ function fetch_remote_file( $url, $post ) { // extract the file name and extension from the url $file_name = basename( $url ); // get placeholder file in the upload dir with a unique, sanitized filename $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] ); if ( $upload['error'] ) return new WP_Error( 'upload_dir_error', $upload['error'] ); // fetch the remote url and write it to the placeholder file $headers = wp_get_http( $url, $upload['file'] ); // request failed if ( ! $headers ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') ); } // make sure the fetch was successful if ( $headers['response'] != '200' ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($headers['response']), get_status_header_desc($headers['response']) ) ); } $filesize = filesize( $upload['file'] ); if ( isset( $headers['content-length'] ) && $filesize != $headers['content-length'] ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __('Remote file is incorrect size', 'wordpress-importer') ); } if ( 0 == $filesize ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wordpress-importer') ); } $max_size = (int) $this->max_attachment_size(); if ( ! empty( $max_size ) && $filesize > $max_size ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer'), size_format($max_size) ) ); } // keep track of the old and new urls so we can substitute them later $this->url_remap[$url] = $upload['url']; $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed? // keep track of the destination if the remote url is redirected somewhere else if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url ) $this->url_remap[$headers['x-final-location']] = $upload['url']; return $upload; } /** * Attempt to associate posts and menu items with previously missing parents * * An imported post's parent may not have been imported when it was first created * so try again. Similarly for child menu items and menu items which were missing * the object (e.g. post) they represent in the menu */ function backfill_parents() { global $wpdb; // find parents for post orphans foreach ( $this->post_orphans as $child_id => $parent_id ) { $local_child_id = $local_parent_id = false; if ( isset( $this->processed_posts[$child_id] ) ) $local_child_id = $this->processed_posts[$child_id]; if ( isset( $this->processed_posts[$parent_id] ) ) $local_parent_id = $this->processed_posts[$parent_id]; if ( $local_child_id && $local_parent_id ) $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' ); } // all other posts/terms are imported, retry menu items with missing associated object $missing_menu_items = $this->missing_menu_items; foreach ( $missing_menu_items as $item ) $this->process_menu_item( $item ); // find parents for menu item orphans foreach ( $this->menu_item_orphans as $child_id => $parent_id ) { $local_child_id = $local_parent_id = 0; if ( isset( $this->processed_menu_items[$child_id] ) ) $local_child_id = $this->processed_menu_items[$child_id]; if ( isset( $this->processed_menu_items[$parent_id] ) ) $local_parent_id = $this->processed_menu_items[$parent_id]; if ( $local_child_id && $local_parent_id ) update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id ); } } /** * Use stored mapping information to update old attachment URLs */ function backfill_attachment_urls() { global $wpdb; // make sure we do the longest urls first, in case one is a substring of another uksort( $this->url_remap, array(&$this, 'cmpr_strlen') ); foreach ( $this->url_remap as $from_url => $to_url ) { // remap urls in post_content $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) ); // remap enclosure urls $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) ); } } /** * Update _thumbnail_id meta to new, imported attachment IDs */ function remap_featured_images() { // cycle through posts that have a featured image foreach ( $this->featured_images as $post_id => $value ) { if ( isset( $this->processed_posts[$value] ) ) { $new_id = $this->processed_posts[$value]; // only update if there's a difference if ( $new_id != $value ) update_post_meta( $post_id, '_thumbnail_id', $new_id ); } } } /** * Parse a WXR file * * @param string $file Path to WXR file for parsing * @return array Information gathered from the WXR file */ function parse( $file ) { $parser = new WXR_Parser(); return $parser->parse( $file ); } // Display import page title function header() { echo '
'; screen_icon(); echo '

' . __( 'Import WordPress', 'wordpress-importer' ) . '

'; $updates = get_plugin_updates(); $basename = plugin_basename(__FILE__); if ( isset( $updates[$basename] ) ) { $update = $updates[$basename]; echo '

'; printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version ); echo '

'; } } // Close div.wrap function footer() { echo '
'; } /** * Display introductory text and file upload form */ function greet() { echo '
'; echo '

'.__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ).'

'; echo '

'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ).'

'; wp_import_upload_form( 'admin.php?import=wordpress&step=1' ); echo '
'; } /** * Decide if the given meta key maps to information we will want to import * * @param string $key The meta key to check * @return string|bool The key if we do want to import, false if not */ function is_valid_meta_key( $key ) { // skip attachment metadata since we'll regenerate it from scratch // skip _edit_lock as not relevant for import if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) return false; return $key; } /** * Decide whether or not the importer is allowed to create users. * Default is true, can be filtered via import_allow_create_users * * @return bool True if creating users is allowed */ function allow_create_users() { return apply_filters( 'import_allow_create_users', true ); } /** * Decide whether or not the importer should attempt to download attachment files. * Default is true, can be filtered via import_allow_fetch_attachments. The choice * made at the import options screen must also be true, false here hides that checkbox. * * @return bool True if downloading attachments is allowed */ function allow_fetch_attachments() { return apply_filters( 'import_allow_fetch_attachments', true ); } /** * Decide what the maximum file size for downloaded attachments is. * Default is 0 (unlimited), can be filtered via import_attachment_size_limit * * @return int Maximum attachment file size to import */ function max_attachment_size() { return apply_filters( 'import_attachment_size_limit', 0 ); } /** * Added to http_request_timeout filter to force timeout at 60 seconds during import * @return int 60 */ function bump_request_timeout( $val ) { return 60; } // return the difference in length between two strings function cmpr_strlen( $a, $b ) { return strlen($b) - strlen($a); } } } // class_exists( 'WP_Importer' ) function wordpress_importer_init() { load_plugin_textdomain( 'wordpress-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); /** * WordPress Importer object for registering the import callback * @global WP_Import $wp_import */ $GLOBALS['wp_import'] = new WP_Import(); register_importer( 'wordpress', 'WordPress', __('Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.', 'wordpress-importer'), array( $GLOBALS['wp_import'], 'dispatch' ) ); } add_action( 'admin_init', 'wordpress_importer_init' ); gger we can swap /sXXX/ with for example /s1600/ to get a larger file. // Use a standardised large size so we can control quality vs filesize. $pattern = '/(\/)(s\d*)(\/)/i'; $replacement = '$1s'.Blogger_Importer::LARGE_IMAGE_SIZE. '$3'; $img = preg_replace($pattern, $replacement, $img); } return $img; } function image_filter($url) { // Do we exclude this particular image? // Don't include images that are already loaded onto this site // Could use a apply_filter here to allow users to add their own tweeks return (substr($url, 0, strlen(site_url())) == site_url()); } function import_image($post_id, $lowrez, $highrez, $description, $imgcount, $postcontent, $blogname, $author) { /* Import a new image unless we specifically filter it out or if it has already been downloaded on another page. Based on http://wordpress.stackexchange.com/questions//media-sideload-image-file-name and the tumblr-importer Simple filename cleaning as characters such as +, % cause issues ref: http://wordpress.org/extend/plugins/uploadplus/ It's processing links of a form similar to these as provided by the "get_images" function or If the high resolution (linked) file is not an image then the low resolution version is downloaded. */ $lowrez_old = $lowrez; $highrez_old = $highrez; $highrezispage = false; $lowrez = $this->image_urlremap($lowrez, false); if ($lowrez == '') return new WP_Error('Not an image', $message = __('Lowrez not an image', 'blogger-importer'), $data = array($lowrez_old, $highrez_old)); if ($highrez != '') { $highrez = $this->image_urlremap($highrez, true); } else { $highrez = $this->image_urlremap($lowrez, true); } if (!$att_id = $this->image_exists($lowrez)) { //Option to add a timeout to download_url, but don't use the wp_remote_get timeout as that's much shorter than the default here of 300s $tmp = @download_url($highrez); if (is_wp_error($tmp)) { @unlink($tmp); // clean up, copied this from other examples but how is this supposed to work if $tmp is an error?? //Don't exit as can still try the small image } // If the highrez was not an image then try the lowrex if (!$this->is_image($tmp, $highrez)) { $highrezispage = true; //That image was not valid $tmp = @download_url($lowrez); // Option to add a timeout here if (is_wp_error($tmp)) { @unlink($tmp); // clean up return $tmp; // output wp_error } if (!$this->is_image($tmp, $lowrez)) { @unlink($tmp); // clean up None of items are actually images, for example might be a single pixel, deliberately filtered out or a 404 error? return new WP_Error('No Images', __('None of the images are valid', 'blogger-importer'), $data = array($lowrez_old, $highrez_old)); } } $new_name = preg_replace('/[^A-Za-z0-9._ ]/i', '-', basename($lowrez)); $file_array = array('name' => $new_name, 'tmp_name' => $tmp); $att_id = media_handle_sideload($file_array, $post_id, $description, array('post_excerpt' => $description)); if (is_wp_error($att_id)) { @unlink($file_array['tmp_name']); return $att_id; } // Link attachment upto old url, store the author so we can replace it later add_post_meta($att_id, 'blogger_permalink', $lowrez); add_post_meta($att_id, 'blogger_blog', $blogname, true); add_post_meta($att_id, 'blogger_author', $author, true); if ($highrezispage) //Not an image so store so we can link later add_post_meta($att_id, 'blogger_largeimgispage', true); } else { //Image already exists, check if the high rez one was valid last time $tmp = get_post_meta($att_id, 'blogger_largeimgispage', true); if ($tmp == true) $highrezispage = true; } //Always treat picassa webs as image so they get replaced with the new High rez link if (substr($highrez, 0, 27) == 'http://picasaweb.google.com') $highrezispage = false; //Replace the image strings if (!$highrezispage && $highrez_old != '') { $imagesrc = wp_get_attachment_image_src($att_id, 'full'); $highrez_new = reset($imagesrc); $postcontent = str_replace($highrez_old, $highrez_new, $postcontent); } $imagesrc = wp_get_attachment_image_src($att_id, 'medium'); $lowrez_new = reset($imagesrc); $postcontent = str_replace($lowrez_old, $lowrez_new, $postcontent); //Set the first image to be the post thumbnail (zero index) if ($imgcount == 0) { set_post_thumbnail($post_id, $att_id); } //media handle sideload moves the file so there should be no temp file left but cleanup just incase. @unlink($tmp); // incase something goes wrong if ($postcontent == '') { return new WP_Error('Empty Content', __("Attempting to write back empty content", 'blogger-importer'), $data = array($lowrez_old, $highrez_old)); } return $postcontent; } function is_image($file, $filename) { //Is the downloaded file really an image //e.g. it looked like an image from the URL but when downloaded it was something else perhaps a html page //Also filter out tracking images of 1 pixel square //Found that wp_check_filetype_and_ext and wp_match_mime_types was giving false positives $imgstats = @getimagesize($file); if (!$imgstats) { return false; } return (($imgstats[0] > 1) && ($imgstats[1] > 1)); } function image_exists($lowrez) { global $wpdb; return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta m ON p.ID = m.post_id AND meta_key = 'blogger_permalink' WHERE post_type = 'attachment' AND meta_value = %s LIMIT 0 , 1", $lowrez)); } function process_links() { //Update all of the links in the blog global $wpdb; $postsprocessed = $this->links_progress; if ($postsprocessed == 0) { $linksprocessed = 0; } else { $linksprocessed = $this->links_done; } $batchsize = 20; $oldurlsearch = $this->host; if (substr($oldurlsearch, 0, 3) == 'www.') { $oldurlsearch = substr($oldurlsearch, 3, strlen($oldurlsearch - 3)); } $oldurlsearch = str_replace('.', '\.', $oldurlsearch); $blogspot = stripos($oldurlsearch, '\.blogspot\.'); if ($blogspot) { //Blogspot addresses can be international e.g. myblog.blogspot.com, myblog.blogspot.com.au or myblog.blogspot.co.uk or myblog.blogspot.de both resolve to the same blog. //See http://www.searchenginejournal.com/google-blogger-url-censorship/39724/ $oldurlsearch = substr($oldurlsearch, 0, $blogspot + 12). '[\w\.]{2,6}'; } $loadedposts = get_posts(array('meta_key' => 'blogger_blog', 'meta_value' => $this->host, 'posts_per_page' => $batchsize, 'offset' => $postsprocessed, 'post_status' => array('draft', 'publish', 'future'))); //Stop if nothing left if (count($loadedposts) == 0) { return true; } foreach($loadedposts as $importedpost) { $importedcontent = $importedpost->post_content; $regexp = ']*href=([\"\'`])(https?:\/\/(?:www\.)*'.$oldurlsearch.'\/)([^\" >]*?)\1[^>]*>(.*)<\/a>'; if (preg_match_all("/$regexp/siU", $importedcontent, $matches, PREG_SET_ORDER)) { foreach($matches as $match) { $HostURL = substr($match[2], 0, strlen($match[2]) - 1); //e.g. http://minitemp.blogspot.co.uk $PageURL = '/'.$match[3]; //e.g. '/2011/04/what-happens-if-blog-title-is-really.html' $sql = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta m inner join $wpdb->posts p on p.id = m.post_id and post_type = 'post' where meta_key = '%s' and meta_value = '%s' ", 'blogger_permalink', $PageURL); $linkpostid = $wpdb->get_var($sql); if ($linkpostid != 0) { $NewURL = get_permalink($linkpostid); } else { // Page not found, update content with just the new domain $NewURL = site_url($PageURL); } $importedcontent = str_replace($HostURL.$PageURL, $NewURL, $importedcontent); $linksprocessed++; } if ($importedcontent == '') { return new WP_Error('Empty Content', __("Attempting to write back empty content")); } $importedpost->post_content = $importedcontent; wp_update_post($importedpost); } $postsprocessed++; //For some reason the intermediate values are not getting written, is it that the options are cached hence not read back? $this->links_done = $linksprocessed; $this->links_progress = $postsprocessed; } unset($loadedposts); return; } function isurlimage($srcurl) { //Process picasaweb links and files that are images if (substr($srcurl, 0, 27) == 'http://picasaweb.google.com') return true; return preg_match('/(?i)\.(jpe?g|png|gif|bmp)$/i', $srcurl); } /** * Parse the atom file * * @param string $file Path to XML file for parsing * @return SimplePie object of the feed */ function parse( $file ) { $data = file_get_contents( $file ); // parse the feed $feed = new SimplePie(); //set_xxxx methods depreciated (and not working?) replaced with get_registry as per docs $reg = $feed->get_registry(); $reg->register('Sanitize', 'Blogger_Importer_Sanitize'); $feed->sanitize = $reg->create('Sanitize'); //Should not really need to do this but there seems to be an issue with the SimplePie class? $reg->register('Item', 'WP_SimplePie_Blog_Item'); $feed->set_raw_data( $data ); $feed->init(); return $feed; } // Display import page title function header() { echo '
'; screen_icon(); echo '

' . __( 'Import Blogger', 'blogger-importer' ) . '

'; } // Close div.wrap function footer() { echo '
'; } /** * Display introductory text and file upload form */ function greet() { echo '
'; echo '

'.__( 'Howdy! Upload your Blogger Exported XML file and we’ll import the contents from it into this site.', 'blogger-importer' ).'

'; echo '

'.__( 'Choose an XML file to upload, then click Upload file and import.', 'blogger-importer' ).'

'; wp_import_upload_form( 'admin.php?import=blogger&step=1' ); echo '
'; } /** * Decide if the given meta key maps to information we will want to import * * @param string $key The meta key to check * @return string|bool The key if we do want to import, false if not */ function is_valid_meta_key( $key ) { // skip attachment metadata since we'll regenerate it from scratch // skip _edit_lock as not relevant for import if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) return false; return $key; } /** * Decide whether or not the importer is allowed to create users. * Default is true, can be filtered via import_allow_create_users * * @return bool True if creating users is allowed */ function allow_create_users() { return apply_filters( 'import_allow_create_users', true ); } /** * Added to http_request_timeout filter to force timeout at 60 seconds during import * @return int 60 */ function bump_request_timeout( $val ) { return 60; } // return the difference in length between two strings function cmpr_strlen( $a, $b ) { return strlen($b) - strlen($a); } } } // class_exists( 'Blogger_Importer' ) function blogger_importer_init() { load_plugin_textdomain( 'blogger-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); /** * WordPress Importer object for registering the import callback * @global WP_Import $wp_import */ $GLOBALS['wp_import'] = new Blogger_Importer(); register_importer('blogger', __('Blogger', 'blogger-importer'), __('Import posts, comments, and categories from a Blogger blog and migrate authors to WordPress users.', 'blogger-importer'), array( $GLOBALS['wp_import'], 'dispatch' ) ); } add_action( 'admin_init', 'blogger_importer_init' );
Warning: Cannot modify header information - headers already sent by (output started at /homepages/24/d369708980/htdocs/app498605015/wp-content/mu-plugins/wordpress-importer/wordpress-importer.php:257) in /homepages/24/d369708980/htdocs/app498605015/wp-login.php on line 421

Warning: Cannot modify header information - headers already sent by (output started at /homepages/24/d369708980/htdocs/app498605015/wp-content/mu-plugins/wordpress-importer/wordpress-importer.php:257) in /homepages/24/d369708980/htdocs/app498605015/wp-login.php on line 434
Acceder ‹ COMODIDAD Y HUMOR — WordPress

Funciona gracias a WordPress

ERROR: Las cookies se han bloqueado debido a un resultado no esperado. Para obtener ayuda, por favor mira esta documentación o inténtalo en los foros de soporte.


← Volver a COMODIDAD Y HUMOR