Created
August 2, 2012 06:49
-
-
Save maximevalette/3234614 to your computer and use it in GitHub Desktop.
Import G+ vers WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('Europe/Paris'); | |
# Mettez le bon chemin pour le fichier wp-blog-header.php de votre blog WordPress | |
include(dirname(__FILE__).'/../../../wp-blog-header.php'); | |
# Par défaut le fichier gplus.last est dans le même répertoire que le script | |
$gplus_file = dirname(__FILE__)."/gplus.last"; | |
$limit_date = strtotime(trim(file_get_contents($gplus_file))); | |
$last_date = false; | |
# Indiquez votre ID Google+ et la clé API que vous venez de créer | |
$user_id = ""; | |
$api_key = ""; | |
# Indiquez l'ID du compte WordPress depuis lequel vous souhaitez poster | |
$wp_author_id = 0; | |
# Indiquez les ID des catégories si vous le souhaitez dans le tableau ci-dessous | |
$wp_cat_ids = array(); | |
# On appelle le JSON de nos dernières activités publiques | |
$str = file_get_contents("https://www.googleapis.com/plus/v1/people/".$user_id."/activities/public?key=".$api_key); | |
$json = json_decode($str); | |
foreach ($json->items as $item) { | |
# On enregistre la date du dernier post pour éviter de le réimporter plus tard | |
if (!$last_date) { | |
file_put_contents($gplus_file,$item->published); | |
$last_date = true; | |
} | |
# Si on arrive à la limite de date configurée avant la boucle, le boulot est fini | |
if (strtotime($item->published) <= $limit_date) break; | |
$post_note = null; | |
$post_link = null; | |
$post_title = null; | |
$post_photo = null; | |
$post_photo_title = null; | |
# Le but est de récupérer le lien et le titre de l'article posté avec le statut G+ | |
if (is_array($item->object->attachments)) { | |
foreach ($item->object->attachments as $att) { | |
if ($att->objectType == 'article') { | |
$post_link = (string)$att->url; | |
$post_title = html_entity_decode((string)$att->displayName,ENT_QUOTES,'UTF-8'); | |
break; | |
} | |
} | |
} | |
# On garde notre petit commentaire avec tout cela | |
$post_note = html_entity_decode($item->object->content,ENT_QUOTES,'UTF-8'); | |
# Et on poste le tout sur WordPress | |
$post = array( | |
'post_title' => $post_title, | |
'post_author' => $wp_author_id, | |
'post_category' => $wp_cat_ids, | |
'post_content' => $post_note, | |
'post_status' => 'publish', | |
'post_type' => 'post' | |
); | |
$new_post_id = wp_insert_post($post); | |
} |
I'm using that personally yes. I've made that script simple as everyone can make its own version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe you can add the type support and set it to something like "aside" ?