OrderPK ! ù`¿Þ Þ blogger-importer-blogitem.phpnu „[µü¤ get_item_tags(SIMPLEPIE_NAMESPACE_ATOMPUB, 'control')) && !empty($control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data']))
{
$draft = ('yes' == $control[0]['child'][SIMPLEPIE_NAMESPACE_ATOMPUB]['draft'][0]['data']);
}
return $draft;
}
//Tried using date functions from http://core.trac.wordpress.org/attachment/ticket/7652/7652-separate.diff
//but ended up with 1970s dates so returned to Otto's version which is much simplified
function get_updated()
{
$temparray = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated');
if (isset($temparray[0]['data']))
return $this->convert_date($temparray[0]['data']);
else
return null;
}
function get_published()
{
$temparray = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published');
if (isset($temparray[0]['data']))
return $this->convert_date($temparray[0]['data']);
else
return null;
}
function get_geotags()
{//Return an array of geo tags see http://codex.wordpress.org/Geodata
//example source
// Rådhuspladsen 3, 1550 Copenhagen, Denmark
// 55.6760968 12.5683371
$latlong = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEOTAG, 'point');
if (isset($latlong[0]['data'])) {
preg_match('/([0-9.-]+).+?([0-9.-]+)/', $latlong[0]['data'], $matches);
$lat=(float)$matches[1];
$long=(float)$matches[2];
}
if (!isset($lat) |!isset($long)) {
return null; //Without lat long we can't have a valid location
}
$address = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEOTAG, 'featurename');
if (isset($address[0]['data']))
$geo_address = $address[0]['data'];
else
$geo_address = null;
$geo = array('geo_latitude' => $lat, 'geo_longitude' => $long, 'geo_address' => $geo_address );
return $geo;
}
function convert_date($date)
{
preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.[0-9]+)?(Z|[\+|\-][0-9]{2,4}){0,1}#', $date, $date_bits);
$offset = iso8601_timezone_to_offset($date_bits[7]);
$timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
$timestamp -= $offset; // Convert from Blogger local time to GMT
$timestamp += get_option('gmt_offset') * 3600; // Convert from GMT to WP local time
return gmdate('Y-m-d H:i:s', $timestamp);
}
//Don't Sanitize the ID, the default get_id was cleaning our IDs and that meant that nested comments did not work
function get_id($hash = false, $fn = 'md5')
{
if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
{
return $return[0]['data'];
}
}
//Prefiltered links
function get_links($rel = 'alternate') {
$mylinks = array();
foreach ($rel as $type)
{
$links =parent::get_links($type);
if (!is_null($links)) {
foreach ($links as $link) {
$mylinks[] = array('rel' => $type, 'href' => $link);
}
}
}
return $mylinks;
}
//Preprocessed categories
function get_categories() {
$cats = parent::get_categories();
$mycats = array();
if (!is_null($cats)) {
foreach ($cats as $cat) {
$mycats[] = $cat->term;
}
}
return $mycats;
}
//What is the source of this item e.g. a comment linked to a post
//10/3/2014 Added error handling for where the comment links to a post that no longer exists on blogger.
function get_source() {
$temp = $this->get_item_tags(SIMPLEPIE_NAMESPACE_THREAD, 'in-reply-to');
if (!is_null($temp)){
foreach ($temp as $t) {
if (isset($t['attribs']['']['source'])) {
$source = $t['attribs']['']['source'];
}
}
return $source;
}
}
}
}
?>PK ! Tž¸‹ ‹ blogger-entry.phpnu „[µü¤ links as $link) {
// save the self link as meta
if ($link['rel'] == 'self')
{
$postself = $link['href'];
$parts = parse_url($link['href']);
$this->old_permalink = $parts['path'];
}
// get the old URI for the page when available
if ($link['rel'] == 'alternate')
{
$parts = parse_url($link['href']);
$this->bookmark = $parts['path'];
}
// save the replies feed link as meta (ignore the comment form one)
if ($link['rel'] == 'replies' && false === strpos($link['href'], '#comment-form'))
{
$this->postreplies = $link['href'];
}
}
}
function import() {
$post_date = $this->published;
$post_content = $this->content;
$post_title = $this->title;
$post_author = $this->author;
$post_status = $this->isDraft ? 'draft' : 'publish';
//AGC:24/10/2013 Turn off the pingbacks
$post_pingback = Blogger_Importer::POST_PINGBACK;
// N.B. Clean up of $post_content is now part of the sanitize class
// Check for duplication part of calling function
$post = compact('post_date', 'post_content', 'post_author', 'post_title', 'post_status', 'post_pingback');
$post_id = wp_insert_post($post);
if (is_wp_error($post_id))
return $post_id;
wp_create_categories(array_map('addslashes', $this->categories), $post_id);
add_post_meta($post_id, 'blogger_blog', $this->blogurl, true);
add_post_meta($post_id, 'blogger_author', $this->bloggerauthor, true);
if (!$this->isDraft && isset($this->bookmark))
add_post_meta($post_id, 'blogger_permalink', $this->bookmark, true);
add_post_meta($post_id, 'blogger_internal', $this->old_permalink, true);
if (isset($this->geotags)) {
add_post_meta($post_id,'geo_latitude',$this->geotags['geo_latitude']);
add_post_meta($post_id,'geo_longitude',$this->geotags['geo_longitude']);
add_post_meta($post_id,'geo_public',1);
if (isset($this->geotags['geo_address'])) {
add_post_meta($post_id,'geo_address',$this->geotags['geo_address']);
}
}
return $post_id;
}
function post_exists() {
$p = $this->get_post_by_oldID($this->old_permalink);
if ($p == 0 && isset($this->bookmark)) {
$p = $this->get_post_by_oldID($this->bookmark);
}
return $p;
}
function get_post_by_oldID($oldID) {
//Check to see if this post has been loaded already
//Can we use get_posts for this?
global $wpdb;
$query = "SELECT post_id FROM $wpdb->postmeta m inner join $wpdb->posts p on p.ID = m.post_id where meta_key = 'blogger_internal' and meta_value = '%s' and p.post_type = 'post' LIMIT 0 , 1";
$p = (int) $wpdb->get_var( $wpdb->prepare($query, $oldID) );
return $p;
}
}
}
PK ! æ,;² ² blogger-importer-sanitize.phpnu „[µü¤ 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite',
'q' => 'cite');
public function __construct()
{
parent::__construct();
}
function _normalize_tag($matches)
{
return '<' . strtolower($matches[1]);
}
function sanitize($data, $type, $base = '')
{
//Simplified function
$data = trim($data);
// Normalise tags (string replacement is case sensitive)
$data = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $data);
// Remappings
$data = str_replace(' ', ' ', $data);
$data = str_replace('
', '', $data);
//Workshopshed: > Workshopshed:
$data = preg_replace('|()(?).*(.*)()|', '$2', $data);
//N.B. Don't strip comments as blogger uses which is the same as WordPress
// Comments might also contain section targetting e.g.
//Now clean up
foreach ($this->strip_htmltags as $tag)
{
$pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU';
while (preg_match($pcre, $data))
{
$data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data);
}
}
foreach ($this->strip_attributes as $attrib)
{
$data = preg_replace('/(<[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?' .
SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\1\2\3>', $data);
}
// Replace relative URLs
$this->base = $base;
foreach ($this->replace_url_attributes as $element => $attributes)
{
$data = $this->replace_urls($data, $element, $attributes);
}
// Images are handled as a separate step as we need to download them
// Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data
$data = trim($data);
return $data;
}
function replace_urls($data, $tag, $attributes)
{
//This seems to do nothing at all!?
if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
{
$elements = SimplePie_Misc::get_element($tag, $data);
foreach ($elements as $element)
{
if (is_array($attributes))
{
foreach ($attributes as $attribute)
{
if (isset($element['attribs'][$attribute]['data']))
{
$element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base);
$new_element = SimplePie_Misc::element_implode($element);
$data = str_replace($element['full'], $new_element, $data);
$element['full'] = $new_element;
}
}
} elseif (isset($element['attribs'][$attributes]['data']))
{
$element['attribs'][$attributes]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attributes]['data'], $this->base);
$data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data);
}
}
}
return $data;
}
//Latest SimplePie checks for this function
public function set_registry(SimplePie_Registry $registry)
{
parent::set_registry($registry);
}
}
?>PK ! n}
uninstall.phpnu „[µü¤ =' ) ) {
require_once ABSPATH . WPINC . '/class-simplepie.php';
} else {
require_once ABSPATH . WPINC . '/class-feed.php';
}
// Custom classes used by importer
require_once dirname( __FILE__ ) . '/blogger-importer-sanitize.php';
require_once dirname( __FILE__ ) . '/blogger-importer-blogitem.php';
require_once dirname( __FILE__ ) . '/blogger-entry.php';
require_once dirname( __FILE__ ) . '/comment-entry.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
/**
* Blogger Importer class for managing the import process of a XML file
*
*/
if ( !class_exists( 'Blogger_Importer' ) ) {
class Blogger_Importer extends WP_Importer {
const IMPORT_IMG = true; // Should we import the images (boolean)
const LARGE_IMAGE_SIZE = '1024'; // The size of large images downloaded (string)
const POST_PINGBACK = 0; // Turn off the post pingback, set to 1 to re-enabled(bool)
private $id = null; // XML attachment ID
private $author_mapping = array();
private $authors = array();
private $comments_done = 0;
private $comments_skipped = 0;
private $host = null;
private $images_done = 0;
private $images_progress = 0;
private $images_skipped = 0;
private $import_data = null;
private $links_done = 0;
private $links_progress = 0;
private $posts_done = 0;
private $posts_skipped = 0;
private $processed_authors = array();
private $version = null;
/**
* Registered callback function for the Blogger Importer
*
* Manages the three separate stages of the XML import process
*/
function dispatch() {
$this->header();
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
switch ( $step ) {
case 0:
$this->greet();
break;
case 1:
check_admin_referer( 'import-upload' );
if ( $this->handle_upload() )
$this->import_options();
break;
case 2:
check_admin_referer( 'import-blogger' );
$this->id = (int) $_POST['import_id'];
$file = get_attached_file( $this->id );
set_time_limit(0);
$this->import( $file );
break;
}
$this->footer();
}
/**
* The main controller for the actual import stage.
*
* @param string $file Path to the XML file for importing
*/
function import( $file ) {
add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
$this->import_start( $file );
$this->get_author_mapping();
wp_suspend_cache_invalidation( true );
$this->process_posts();
$this->process_comments();
if (Blogger_Importer::IMPORT_IMG)
{
$this->process_images();
}
$this->process_links();
wp_suspend_cache_invalidation( false );
// update incorrect/missing information in the DB
//$this->backfill_parents();
//$this->backfill_attachment_urls();
//$this->remap_featured_images();
$this->import_end();
}
/**
* Parses the XML file and prepares us for the task of processing parsed data
*
* @param string $file Path to the XML file for importing
*/
function import_start( $file ) {
if ( ! is_file($file) ) {
echo '
' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . ' ';
echo __( 'The file does not exist, please try again.', 'blogger-importer' ) . '
' . __( 'Sorry, there has been an error.', 'blogger-importer' ) . ' ';
printf( __( 'The export file could not be found at %s. It is likely that this was caused by a permissions problem.', 'blogger-importer' ), esc_html( $file['file'] ) );
echo '