0.2 final
This commit is contained in:
parent
00ac80b615
commit
2c16178e2c
7 changed files with 146 additions and 128 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "lib/acTwitterConversation"]
|
||||
path = lib/acTwitterConversation
|
||||
url = https://github.com/adriancrepaz/acTwitterConversation.git
|
|
@ -25,35 +25,6 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the form submission of the Options page and handle all of the values there.
|
||||
* You'll need to validate/santize things, and probably store options in the DB. When you're
|
||||
* done, set $this->step = 'import' to continue, or 'options' to show the options form again.
|
||||
*
|
||||
function handle_request_options() {
|
||||
$bools = array('auto_import','auto_approve');
|
||||
|
||||
foreach ( $bools as $bool ) {
|
||||
if ( isset( $_POST[$bool] ) )
|
||||
$_POST[$bool] = true;
|
||||
else
|
||||
$_POST[$bool] = false;
|
||||
}
|
||||
|
||||
// If there were errors, output them, otherwise store options and start importing
|
||||
if ( count( $this->errors ) ) {
|
||||
$this->step = 'greet';
|
||||
} else {
|
||||
$this->set_option( array(
|
||||
'auto_import' => (bool) $_POST['auto_import'],
|
||||
'auto_approve' => (bool) $_POST['auto_approve'],
|
||||
) );
|
||||
|
||||
$this->step = 'options';
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* implementation for all the requests for one method of one post
|
||||
*
|
||||
|
@ -75,8 +46,8 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
|
|||
__( 'Missing syndication URL.', 'keyring')
|
||||
);
|
||||
|
||||
$photo_id = trim(end((explode('/', rtrim($syndication_url, '/')))));
|
||||
if (empty($photo_id))
|
||||
$silo_id = trim(end((explode('/', rtrim($syndication_url, '/')))));
|
||||
if (empty($silo_id))
|
||||
return new Keyring_Error(
|
||||
'keyring-500px-reactions-photo-id-not-found',
|
||||
__( 'Cannot get photo ID out of syndication URL.', 'keyring' )
|
||||
|
@ -89,7 +60,7 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
|
|||
sprintf(__( 'Function is missing for this method (%s), cannot proceed!', 'keyring'), $method)
|
||||
);
|
||||
|
||||
return $this->$func ( $post_id, $photo_id );
|
||||
return $this->$func ( $post_id, $silo_id );
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,8 +68,8 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
|
|||
* VOTES (LIKES)
|
||||
*
|
||||
*/
|
||||
function get_votes ( &$post_id, &$photo_id ) {
|
||||
$baseurl = sprintf("https://api.500px.com/v1/photos/%s/votes", $photo_id);
|
||||
function get_votes ( &$post_id, &$silo_id ) {
|
||||
$baseurl = sprintf("https://api.500px.com/v1/photos/%s/votes", $silo_id);
|
||||
|
||||
$res = $this->request ( $baseurl, 'users' );
|
||||
$tpl = __( '<a href="%s" rel="nofollow">%s</a> liked this photo on <a href="https://500px.com" rel="nofollow">500px.com</a>','keyring');
|
||||
|
@ -111,8 +82,8 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
|
|||
/**
|
||||
* FAVS
|
||||
*/
|
||||
function get_favs ( &$post_id, &$photo_id ) {
|
||||
$baseurl = sprintf("https://api.500px.com/v1/photos/%s/favorites", $photo_id);
|
||||
function get_favs ( &$post_id, &$silo_id ) {
|
||||
$baseurl = sprintf("https://api.500px.com/v1/photos/%s/favorites", $silo_id);
|
||||
$res = $this->request ( $baseurl, 'users' );
|
||||
|
||||
$tpl = __( '<a href="%s" rel="nofollow">%s</a> added this photo to their favorites on <a href="https://500px.com" rel="nofollow">500px.com</a>','keyring');
|
||||
|
@ -163,8 +134,8 @@ class Keyring_500px_Reactions extends Keyring_Reactions_Base {
|
|||
/**
|
||||
* COMMENTS
|
||||
*/
|
||||
function get_comments ( &$post_id, &$photo_id ) {
|
||||
$baseurl = sprintf("https://api.500px.com/v1/photos/%s/comments", $photo_id);
|
||||
function get_comments ( &$post_id, &$silo_id ) {
|
||||
$baseurl = sprintf("https://api.500px.com/v1/photos/%s/comments", $silo_id);
|
||||
|
||||
$results = $this->request ( $baseurl, 'comments' );
|
||||
if ($results && is_array($results) && !empty($results)) {
|
||||
|
|
|
@ -9,7 +9,7 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base {
|
|||
const KEYRING_SERVICE = 'Keyring_Service_Facebook';
|
||||
const KEYRING_NAME = 'facebook';
|
||||
const REQUESTS_PER_LOAD = 3; // How many remote requests should be made before reloading the page?
|
||||
const NUM_PER_REQUEST = 100; // Number of images per request to ask for
|
||||
const NUM_PER_REQUEST = 100; // Number of posts per request to ask for
|
||||
|
||||
const SILONAME = 'facebook.com';
|
||||
|
||||
|
@ -27,35 +27,6 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base {
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the form submission of the Options page and handle all of the values there.
|
||||
* You'll need to validate/santize things, and probably store options in the DB. When you're
|
||||
* done, set $this->step = 'import' to continue, or 'options' to show the options form again.
|
||||
*
|
||||
function handle_request_options() {
|
||||
$bools = array('auto_import','auto_approve');
|
||||
|
||||
foreach ( $bools as $bool ) {
|
||||
if ( isset( $_POST[$bool] ) )
|
||||
$_POST[$bool] = true;
|
||||
else
|
||||
$_POST[$bool] = false;
|
||||
}
|
||||
|
||||
// If there were errors, output them, otherwise store options and start importing
|
||||
if ( count( $this->errors ) ) {
|
||||
$this->step = 'greet';
|
||||
} else {
|
||||
$this->set_option( array(
|
||||
'auto_import' => (bool) $_POST['auto_import'],
|
||||
'auto_approve' => (bool) $_POST['auto_approve'],
|
||||
) );
|
||||
|
||||
$this->step = 'options';
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
function make_all_requests( $method, $post ) {
|
||||
extract($post);
|
||||
|
||||
|
@ -71,8 +42,8 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base {
|
|||
__( 'Missing syndication URL.', 'keyring')
|
||||
);
|
||||
|
||||
$photo_id = trim(end((explode('/', rtrim($syndication_url, '/')))));
|
||||
if (empty($photo_id))
|
||||
$silo_id = trim(end((explode('/', rtrim($syndication_url, '/')))));
|
||||
if (empty($silo_id))
|
||||
return new Keyring_Error(
|
||||
'keyring-facebook-reactions-photo-id-not-found',
|
||||
__( 'Cannot get photo ID out of syndication URL.', 'keyring' )
|
||||
|
@ -85,16 +56,16 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base {
|
|||
sprintf(__( 'Function is missing for this method (%s), cannot proceed!', 'keyring'), $method)
|
||||
);
|
||||
|
||||
return $this->$func ( $post_id, $photo_id );
|
||||
return $this->$func ( $post_id, $silo_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* FAVS
|
||||
*/
|
||||
|
||||
function get_likes ( $post_id, $fb_id ) {
|
||||
function get_likes ( $post_id, $silo_id ) {
|
||||
$res = array();
|
||||
$baseurl = sprintf( "https://graph.facebook.com/v%s/%s/likes?", static::GRAPHAPI, $fb_id );
|
||||
$baseurl = sprintf( "https://graph.facebook.com/v%s/%s/likes?", static::GRAPHAPI, $silo_id );
|
||||
|
||||
$params = array(
|
||||
'access_token' => $this->service->token->token,
|
||||
|
@ -122,9 +93,7 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base {
|
|||
'comment_author_email' => $element->id . '@' . static::SILONAME,
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_type' => $type,
|
||||
// DON'T set the date unless it's provided - not with favs & votes
|
||||
//'comment_date' => date("Y-m-d H:i:s"),
|
||||
//'comment_date_gmt' => date("Y-m-d H:i:s"),
|
||||
// DON'T set the date unless it's provided - not with likes
|
||||
'comment_agent' => get_class($this),
|
||||
'comment_approved' => $auto,
|
||||
'comment_content' => sprintf( $tpl, $author_url, $name ),
|
||||
|
@ -141,9 +110,9 @@ class Keyring_Facebook_Reactions extends Keyring_Reactions_Base {
|
|||
* comments
|
||||
*/
|
||||
|
||||
function get_comments ( $post_id, $fb_id ) {
|
||||
function get_comments ( $post_id, $silo_id ) {
|
||||
$res = array();
|
||||
$baseurl = sprintf( "https://graph.facebook.com/v%s/%s/comments?", static::GRAPHAPI, $fb_id );
|
||||
$baseurl = sprintf( "https://graph.facebook.com/v%s/%s/comments?", static::GRAPHAPI, $silo_id );
|
||||
|
||||
$params = array(
|
||||
'access_token' => $this->service->token->token,
|
||||
|
|
|
@ -24,36 +24,6 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the form submission of the Options page and handle all of the values there.
|
||||
* You'll need to validate/santize things, and probably store options in the DB. When you're
|
||||
* done, set $this->step = 'import' to continue, or 'options' to show the options form again.
|
||||
*
|
||||
function handle_request_options() {
|
||||
$bools = array('auto_import','auto_approve');
|
||||
|
||||
foreach ( $bools as $bool ) {
|
||||
if ( isset( $_POST[$bool] ) )
|
||||
$_POST[$bool] = true;
|
||||
else
|
||||
$_POST[$bool] = false;
|
||||
}
|
||||
|
||||
// If there were errors, output them, otherwise store options and start importing
|
||||
if ( count( $this->errors ) ) {
|
||||
$this->step = 'greet';
|
||||
} else {
|
||||
$this->set_option( array(
|
||||
'auto_import' => (bool) $_POST['auto_import'],
|
||||
'auto_approve' => (bool) $_POST['auto_approve'],
|
||||
) );
|
||||
|
||||
$this->step = 'options';
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
function make_all_requests( $method, $post ) {
|
||||
extract($post);
|
||||
|
||||
|
@ -69,8 +39,8 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
__( 'Missing syndication URL.', 'keyring')
|
||||
);
|
||||
|
||||
$photo_id = trim(end((explode('/', rtrim($syndication_url, '/')))));
|
||||
if (empty($photo_id))
|
||||
$silo_id = trim(end((explode('/', rtrim($syndication_url, '/')))));
|
||||
if (empty($silo_id))
|
||||
return new Keyring_Error(
|
||||
'keyring-flickr-reactions-photo-id-not-found',
|
||||
__( 'Cannot get photo ID out of syndication URL.', 'keyring' )
|
||||
|
@ -83,16 +53,16 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
sprintf(__( 'Function is missing for this method (%s), cannot proceed!', 'keyring'), $method)
|
||||
);
|
||||
|
||||
return $this->$func ( $post_id, $photo_id );
|
||||
return $this->$func ( $post_id, $silo_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* FAVS
|
||||
*/
|
||||
|
||||
function get_favs ( $post_id, $photo_id ) {
|
||||
function get_favs ( $post_id, $silo_id ) {
|
||||
|
||||
$results = $this->query_favs( $photo_id );
|
||||
$results = $this->query_favs( $silo_id );
|
||||
|
||||
if ($results && is_array($results) && !empty($results)) {
|
||||
|
||||
|
@ -133,7 +103,7 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
function query_favs ( $photo_id ) {
|
||||
function query_favs ( $silo_id ) {
|
||||
|
||||
$page = 1;
|
||||
$finished = false;
|
||||
|
@ -145,7 +115,7 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
$params = array(
|
||||
'method' => 'flickr.photos.getFavorites',
|
||||
'api_key' => $this->service->key,
|
||||
'photo_id' => $photo_id,
|
||||
'photo_id' => $silo_id,
|
||||
'per_page' => self::NUM_PER_REQUEST,
|
||||
'page' => $page,
|
||||
);
|
||||
|
@ -173,8 +143,8 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
/**
|
||||
* COMMENTS
|
||||
*/
|
||||
function get_comments ( $post_id, $photo_id ) {
|
||||
$results = $this->query_comments( $photo_id );
|
||||
function get_comments ( $post_id, $silo_id ) {
|
||||
$results = $this->query_comments( $silo_id );
|
||||
|
||||
if ($results && is_array($results) && !empty($results)) {
|
||||
|
||||
|
@ -216,7 +186,7 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
function query_comments ( $photo_id ) {
|
||||
function query_comments ( $silo_id ) {
|
||||
$res = array();
|
||||
|
||||
$baseurl = "https://api.flickr.com/services/rest/?";
|
||||
|
@ -226,7 +196,7 @@ class Keyring_Flickr_Reactions extends Keyring_Reactions_Base {
|
|||
$params = array(
|
||||
'method' => 'flickr.photos.comments.getList',
|
||||
'api_key' => $this->service->key,
|
||||
'photo_id' => $photo_id,
|
||||
'photo_id' => $silo_id,
|
||||
);
|
||||
|
||||
$url = $baseurl . http_build_query( $params );
|
||||
|
|
|
@ -30,6 +30,16 @@ License: GPLv3
|
|||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO // IDEAS
|
||||
*
|
||||
* instead of one gigantic importer, we could fire up a schedule per host
|
||||
* to import all the reactions from all the networks for that particular post
|
||||
* the question is, how good is the schedule in wp-cron, could it handle
|
||||
* thousands of schedules?
|
||||
*
|
||||
*/
|
||||
|
||||
// Load Importer API
|
||||
if ( !function_exists( 'register_importer ' ) )
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
@ -312,15 +322,27 @@ abstract class Keyring_Reactions_Base {
|
|||
* enough to allow for redirecting the user if necessary.
|
||||
*/
|
||||
protected function handle_request() {
|
||||
|
||||
// Only interested in POST requests and specific GETs
|
||||
if ( empty( $_GET['import'] ) || static::SLUG != $_GET['import'] )
|
||||
return;
|
||||
|
||||
// Heading to a specific step of the importer
|
||||
if ( !empty( $_REQUEST['step'] ) && ctype_alpha( $_REQUEST['step'] ) )
|
||||
if ( !empty( $_REQUEST['step'] ) && ctype_alpha( $_REQUEST['step'] ) ) {
|
||||
$this->step = (string) $_REQUEST['step'];
|
||||
}
|
||||
|
||||
switch ( $this->step ) {
|
||||
case 'importsingle':
|
||||
if ( empty( $_REQUEST['post_id'] ) || ctype_alpha( $_REQUEST['post_id'] ) ) {
|
||||
$this->step = 'greet';
|
||||
// fall through here, no break
|
||||
}
|
||||
else {
|
||||
$post_id = $_REQUEST['post_id'];
|
||||
$this->do_single_import($post_id);
|
||||
break;
|
||||
}
|
||||
case 'greet':
|
||||
if ( !empty( $_REQUEST[ static::SLUG . '_token' ] ) ) {
|
||||
|
||||
|
@ -375,6 +397,8 @@ abstract class Keyring_Reactions_Base {
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -397,7 +421,8 @@ abstract class Keyring_Reactions_Base {
|
|||
case 'import':
|
||||
$this->do_import();
|
||||
break;
|
||||
|
||||
case 'import_single':
|
||||
$this->do_single_import();
|
||||
case 'done':
|
||||
$this->done();
|
||||
break;
|
||||
|
@ -426,7 +451,7 @@ abstract class Keyring_Reactions_Base {
|
|||
.keyring-importer li { list-style-type: square; }
|
||||
</style>
|
||||
<div class="wrap keyring-importer">
|
||||
<?php screen_icon(); ?>
|
||||
<?php //screen_icon(); ?>
|
||||
<h2><?php printf( __( '%s Importer', 'keyring' ), esc_html( static::LABEL ) ); ?></h2>
|
||||
<?php
|
||||
if ( count( $this->errors ) ) {
|
||||
|
@ -635,6 +660,72 @@ abstract class Keyring_Reactions_Base {
|
|||
$this->footer();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function do_single_import( $post_id ) {
|
||||
defined( 'WP_IMPORTING' ) or define( 'WP_IMPORTING', true );
|
||||
do_action( 'import_start' );
|
||||
set_time_limit( 0 );
|
||||
|
||||
$this->header();
|
||||
echo '<p>' . __( 'Importing Reactions...' ) . '</p>';
|
||||
|
||||
$syndication_url = false;
|
||||
|
||||
// Need a token to do anything with this
|
||||
if ( !$this->service->get_token() )
|
||||
return;
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/post.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/comment.php';
|
||||
|
||||
$post = get_post($post_id);
|
||||
if (!$post)
|
||||
return false;
|
||||
|
||||
$syndication_urls = get_post_meta ( $post->ID, 'syndication_urls', true );
|
||||
if (strstr( $syndication_urls, static::SILONAME )) {
|
||||
$syndication_urls = explode("\n", $syndication_urls );
|
||||
|
||||
foreach ( $syndication_urls as $url ) {
|
||||
if (strstr( $url, static::SILONAME )) {
|
||||
$syndication_url = $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$syndication_url)
|
||||
return false;
|
||||
|
||||
$todo = array (
|
||||
'post_id' => $post->ID,
|
||||
'syndication_url' => $syndication_url,
|
||||
);
|
||||
|
||||
$msg = sprintf(__('Starting auto import for #%s', 'keyring'), $post->ID );
|
||||
Keyring_Util::debug($msg);
|
||||
|
||||
|
||||
foreach ( $this->methods as $method => $type ) {
|
||||
$msg = sprintf(__('Processing %s for post #%s', 'keyring'), $method, $post->ID);
|
||||
Keyring_Util::debug($msg);
|
||||
|
||||
$result = $this->make_all_requests( $method, $todo );
|
||||
|
||||
if ( Keyring_Util::is_error( $result ) )
|
||||
print $result;
|
||||
}
|
||||
|
||||
|
||||
$this->importer_goto( 'done', 1 );
|
||||
$this->footer();
|
||||
|
||||
do_action( 'import_end' );
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a cron request to pick up importing reactions from where we left off.
|
||||
* Since the posts array & the post pointer stays untouched until the import
|
||||
|
@ -1070,6 +1161,3 @@ $keyring_reactions = apply_filters( 'keyring_reactions', $keyring_reactions );
|
|||
foreach ( $keyring_reactions as $keyring_reaction )
|
||||
require $keyring_reaction;
|
||||
unset( $keyring_reactions, $keyring_reaction );
|
||||
|
||||
|
||||
?>
|
||||
|
|
1
lib/acTwitterConversation
Submodule
1
lib/acTwitterConversation
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit e192896817919b3cd399ac02b70c27c8bad3ce0f
|
22
readme.txt
22
readme.txt
|
@ -11,11 +11,22 @@ A social reactions ( comments, like, favs, etc. ) importer.
|
|||
|
||||
== Description ==
|
||||
|
||||
A [backfeed](http://indiewebcamp.com/backfeed) to have all the reaction from all the social networks you have a copy of your post at!
|
||||
A [backfeed](http://indiewebcamp.com/backfeed) plugin to have all the reaction from all the social networks you have a copy of your post at.
|
||||
|
||||
Using the `syndication_urls` post meta field populated by either the [Syndication Links](https://wordpress.org/plugins/syndication-links/) plugin or by hand the Keyring Reactions Importer will pull all the comments, favs, likes, votes, etc. from any supported networks to comments in WordPress.
|
||||
= How it works =
|
||||
* it checks the `syndication_urls` post meta field populated either by the [Syndication Links](https://wordpress.org/plugins/syndication-links/) plugin or by hand (one syndicated url per line)
|
||||
* based on the activated and available importers it will fire up scheduled jobs to import reactions for each and every post we have the syndication link for the [silo](http://indiewebcamp.com/silo) available
|
||||
|
||||
Currently supported networks:
|
||||
= Required plugins =
|
||||
* [Keyring](https://wordpress.org/plugins/keyring)
|
||||
* note: to use 500px, you'll need a [not-yet-merged addition to Keyring for 500px](https://github.com/petermolnar/keyring/blob/master/includes/services/extended/500px.php)
|
||||
|
||||
|
||||
|
||||
= Recommended plugins =
|
||||
* [Syndication Links](https://wordpress.org/plugins/syndication-links/)
|
||||
|
||||
= Currently supported networks =
|
||||
|
||||
* [500px](https://500px.com/) - comments, favs, likes
|
||||
* [Flickr](https://flickr.com/) - comments, favs
|
||||
|
@ -25,6 +36,11 @@ The plugin uses the brilliant [Keyring](https://wordpress.org/plugins/keyring/)
|
|||
|
||||
== Installation ==
|
||||
|
||||
1. Upload contents of `keyring-reactions-importer.zip` to the `/wp-content/plugins/` directory
|
||||
2. Go to Admin -> Tools -> Import
|
||||
3. Activate the desired importer.
|
||||
4. Make sure WP-Cron is not disabled fully in case you wish to use auto-import.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 0.2 =
|
||||
|
|
Loading…
Reference in a new issue