From ac3ae83a1646404bcd096891bf5da7b47314cfb3 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Nov 2013 18:03:12 -0800 Subject: wordpress-to-red cross-posting tool ported from Friendica --- util/wp/post_to_red/post_to_red.php | 286 ++++++++++++++++++++++++++++++++++++ util/wp/post_to_red/readme.txt | 39 +++++ 2 files changed, 325 insertions(+) create mode 100644 util/wp/post_to_red/post_to_red.php create mode 100644 util/wp/post_to_red/readme.txt (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php new file mode 100644 index 000000000..8e62a1a56 --- /dev/null +++ b/util/wp/post_to_red/post_to_red.php @@ -0,0 +1,286 @@ +/Uis', '', $post->post_content); + + // get any tags and make them hashtags + $post_tags = get_the_tags($post_id); + if ($post_tags) { + foreach($post_tags as $tag) { + $tag_string .= "#" . $tag->name . " "; + } + } + + $message = $post->post_title . "

" . $message; + + $message .= "

permalink: " . $post->guid; + + if (isset($tag_string)) { + $message .= "
$tag_string"; + } + + $bbcode = xpost_to_html2bbcode($message); + + $url = $seed_location . '/api/statuses/update'; + + + + $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); + $body = array('status' => $bbcode,'source' => 'WordPress'); + if($channel) + $body['channel'] = $channel; + + // post: + $request = new WP_Http; + $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); + + } + + } +} + +function post_to_red_displayAdminContent() { + + $seed_url = post_to_red_get_seed_location(); + $password = post_to_red_get_password(); + $user_acct = post_to_red_get_acct_name(); + $channel = post_to_red_get_channel_name(); + + // debug... + // echo "seed location: $seed_url
"; + // echo "password: $password
"; + // echo "user_acct: $user_acct
"; + + echo << +

CrossPost to Red Matrix

+

This plugin allows you to cross post to your Red Matrix channel.

+ + +
+

Configuration

+
+ Enter the login details of your Red Matrix account

+   + Password:   + Red Matrix URL:   + Optional channel nickname:   + +
+

+
+EOF; + + if(isset($_POST['submit'])) { + echo "
Settings Saved!
"; + } +} + +function post_to_red_post_checkbox() { + add_meta_box( + 'post_to_red_meta_box_id', + 'Cross Post to Red Matrix', + 'post_to_red_post_meta_content', + 'post', + 'normal', + 'default' + ); +} + +function post_to_red_post_meta_content($post_id) { + wp_nonce_field(plugin_basename( __FILE__ ), 'post_to_red_nonce'); + echo ' Cross post?'; +} + +function post_to_red_post_field_data($post_id) { + + // check if this isn't an auto save + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) + return; + + // security check +// if (!wp_verify_nonce( $_POST['post_to_red_nonce'], plugin_basename( __FILE__ ))) +// return; + + // now store data in custom fields based on checkboxes selected + if (isset($_POST['post_to_red'])) { + update_post_meta($post_id, 'post_to_red', 1); + } else { + update_post_meta($post_id, 'post_to_red', 0); + } +} + +function post_to_red_display_admin_page() { + + if ((isset($_REQUEST["post_to_red_acct_name"])) && (isset($_REQUEST["post_to_red_password"]))) { + + $password = $_REQUEST["post_to_red_password"]; + $red_url = $_REQUEST["post_to_red_url"]; + + update_option('post_to_red_acct_name', $_REQUEST["post_to_red_acct_name"]); + update_option('post_to_red_channel_name', $channelname); + update_option('post_to_red_seed_location', $red_url); + update_option('post_to_red_password', $password); + + } + + post_to_red_displayAdminContent(); +} + +function post_to_red_settings_link($links) { + $settings_link = 'Settings'; + array_unshift($links, $settings_link); + return $links; +} + +function post_to_red_admin() { + add_options_page("Crosspost to redmatrix", "Crosspost to redmatrix", "manage_options", "xpost-to-redmatrix", "post_to_red_display_admin_page"); +} + +register_deactivation_hook( __FILE__, 'post_to_red_deactivate' ); + +add_filter("plugin_action_links_$plugin", "post_to_red_settings_link"); + +add_action("admin_menu", "post_to_red_admin"); +add_action('publish_post', 'post_to_red_post'); +add_action('add_meta_boxes', 'post_to_red_post_checkbox'); +add_action('save_post', 'post_to_red_post_field_data'); + +// from: +// http://www.docgate.com/tutorial/php/how-to-convert-html-to-bbcode-with-php-script.html +function xpost_to_html2bbcode($text) { + $htmltags = array( + '/\(.*?)\<\/b\>/is', + '/\(.*?)\<\/i\>/is', + '/\(.*?)\<\/u\>/is', + '/\(.*?)\<\/ul\>/is', + '/\(.*?)\<\/li\>/is', + '/\/is', // some smiley + '/\/is', + '/\/is', // some smiley + '/\
(.*?)\<\/div\>/is', + '/\
(.*?)\<\/div\>/is', + '/\
(.*?)\<\/div\>/is', + '/\
(.*?)\<\/div\>/is', + '/\(.*?)\<\/cite\>/is', + '/\(.*?)\<\/blockquote\>/is', + '/\(.*?)\<\/div\>/is', + '/\(.*?)\<\/code\>/is', + '/\/is', + '/\(.*?)\<\/strong\>/is', + '/\(.*?)\<\/em\>/is', + '/\(.*?)\<\/a\>/is', + '/\http:\/\/(.*?)\<\/a\>/is', + '/\(.*?)\<\/a\>/is' + ); + + $bbtags = array( + '[b]$1[/b]', + '[i]$1[/i]', + '[u]$1[/u]', + '[list]$1[/list]', + '[*]$1', + '$3', + '[img]http://$2[/img]' . "\n", + ':$3', + '\[quote\]$1\[/quote\]', + '\[code\]$1\[/code\]', + '', + '', + '', + '\[quote\]$1\[/quote\]', + '$1', + '\[code\]$1\[/code\]', + "\n", + '[b]$1[/b]', + '[i]$1[/i]', + '[email=$1]$3[/email]', + '[url]$1[/url]', + '[url=$1]$3[/url]' + ); + + $text = str_replace ("\n", ' ', $text); + $ntext = preg_replace ($htmltags, $bbtags, $text); + $ntext = preg_replace ($htmltags, $bbtags, $ntext); + + // for too large text and cannot handle by str_replace + if (!$ntext) { + $ntext = str_replace(array('
', '
'), "\n", $text); + $ntext = str_replace(array('', ''), array('[b]', '[/b]'), $ntext); + $ntext = str_replace(array('', ''), array('[i]', '[/i]'), $ntext); + } + + $ntext = strip_tags($ntext); + + $ntext = trim(html_entity_decode($ntext,ENT_QUOTES,'UTF-8')); + return $ntext; +} + + diff --git a/util/wp/post_to_red/readme.txt b/util/wp/post_to_red/readme.txt new file mode 100644 index 000000000..e27c46236 --- /dev/null +++ b/util/wp/post_to_red/readme.txt @@ -0,0 +1,39 @@ +=== CrossPost to redmatrix === +Contributors: duthied, macgirvin +Donate link: TBD +Tags: redmatrix, crosspost +Requires at least: 3.2 +Tested up to: 3.2 +Stable tag: 1.2 + +CrossPost to Red Matrix for WordPress + +== Description == +This plugin allows you to cross post to your Red Matrix account. + +**Note, this plugin converts the html from wordpress into bbcode. +The bbcode conversion doesn't handle height and width of an image, so be warned that if you post a very large +image that is resized via height and with attributes, those attributes won't be honored in the resulatant post. + +== Changelog == += 1.2 = +* ensured no function name collision + += 1.1 = +* Added feedback to settings form post. + += 1.0 = +* Initial release. + +== Installation == + +1. Install the plugin from your Wordpress admin panel. + +OR + +1. Upload the plugin folder to the `/wp-content/plugins/` directory. +2. Activate the plugin through the 'Plugins' menu in WordPress. +3. On the settings page enter your account name and password and the nickname of the channel to post to - then click the submit button +4. To cross-post ensure the check box in the 'Cross Post To redmatrix' is checked before publishing. + +== Frequently Asked Questions == -- cgit v1.2.3 From c63a18a2506778fff37c3e82881e90e24ce545a8 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Nov 2013 20:28:51 -0800 Subject: Add some message_id meta information for wordpress posts so we'll know where to send comments --- util/wp/post_to_red/post_to_red.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 8e62a1a56..095884007 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -78,6 +78,10 @@ function post_to_red_post($post_id) { } } + $message_namespace = 'wordpress'; + + $message_id = $site_url() . '/' . $post_id; + $message = $post->post_title . "

" . $message; $message .= "

permalink: " . $post->guid; @@ -93,7 +97,7 @@ function post_to_red_post($post_id) { $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); - $body = array('status' => $bbcode,'source' => 'WordPress'); + $body = array('status' => $bbcode,'source' => 'WordPress', 'namespace' => $message_namespace, 'remote_id' => $message_id); if($channel) $body['channel'] = $channel; -- cgit v1.2.3 From 2b47d36a11cd7203c26c50c6cd504726c2cd9b39 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Nov 2013 23:15:07 -0800 Subject: wordpress publish hook was called before the meta storage hook so the plugin would only work on edited posts. This may be a wordpress version issue because you'd think somebody would've noticed it before. --- util/wp/post_to_red/post_to_red.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 095884007..47af7789b 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -55,12 +55,19 @@ function post_to_red_get_password() { } function post_to_red_post($post_id) { - + $post = get_post($post_id); + if (isset($_POST['post_to_red'])) { + update_post_meta($post_id, 'post_to_red', 1); + } else { + update_post_meta($post_id, 'post_to_red', 0); + } + + // if meta has been set if (get_post_meta($post_id, "post_to_red", true) == 1) { - + $user_name = post_to_red_get_acct_name(); $password = post_to_red_get_password(); $seed_location = post_to_red_get_seed_location(); @@ -80,7 +87,7 @@ function post_to_red_post($post_id) { $message_namespace = 'wordpress'; - $message_id = $site_url() . '/' . $post_id; + $message_id = site_url() . '/' . $post_id; $message = $post->post_title . "

" . $message; @@ -148,6 +155,7 @@ EOF; } function post_to_red_post_checkbox() { + add_meta_box( 'post_to_red_meta_box_id', 'Cross Post to Red Matrix', @@ -170,8 +178,9 @@ function post_to_red_post_field_data($post_id) { return; // security check -// if (!wp_verify_nonce( $_POST['post_to_red_nonce'], plugin_basename( __FILE__ ))) -// return; + if((! array_key_exists('post_to_red_nonce', $_POST)) + || (!wp_verify_nonce( $_POST['post_to_red_nonce'], plugin_basename( __FILE__ )))) + return; // now store data in custom fields based on checkboxes selected if (isset($_POST['post_to_red'])) { -- cgit v1.2.3 From cbe096dd90292613e21725c8468eaf77f934d079 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 25 Nov 2013 14:20:57 -0800 Subject: wp-to-red: now supports editing, titles, and native permalinks --- util/wp/post_to_red/post_to_red.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 47af7789b..00c9b6b73 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -91,8 +91,6 @@ function post_to_red_post($post_id) { $message = $post->post_title . "

" . $message; - $message .= "

permalink: " . $post->guid; - if (isset($tag_string)) { $message .= "
$tag_string"; } @@ -104,7 +102,14 @@ function post_to_red_post($post_id) { $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); - $body = array('status' => $bbcode,'source' => 'WordPress', 'namespace' => $message_namespace, 'remote_id' => $message_id); + $body = array( + 'title' => xpost_to_html2bbcode($post->post_title), + 'status' => $bbcode, + 'source' => 'WordPress', + 'namespace' => 'wordpress', + 'remote_id' => $message_id, + 'permalink' => $post->guid; + ); if($channel) $body['channel'] = $channel; -- cgit v1.2.3 From 6f6fcddfc3fc9bb2e63dd615f29116ced49838d5 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Nov 2013 16:38:48 -0800 Subject: api fixes --- util/wp/post_to_red/post_to_red.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 00c9b6b73..4c353468c 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -108,7 +108,7 @@ function post_to_red_post($post_id) { 'source' => 'WordPress', 'namespace' => 'wordpress', 'remote_id' => $message_id, - 'permalink' => $post->guid; + 'permalink' => $post->guid ); if($channel) $body['channel'] = $channel; @@ -117,6 +117,15 @@ function post_to_red_post($post_id) { $request = new WP_Http; $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); +// if($result['response']['code'] == 200) { +// $j = json_decode($result['body'],true); +// if($j && $j['id']) { +// // store the red id in case we need to delete it in the future. +// +// } +// } +// logger('post_to_red returns: ' . print_r($result,true)); + } } -- cgit v1.2.3 From ef53c72a708ed2b1ba4cc1ffc6a926a33ba6a2f2 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Nov 2013 17:02:49 -0800 Subject: delete from the wp side as well as from the red side --- util/wp/post_to_red/post_to_red.php | 52 +++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 4c353468c..d89ab91be 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -85,12 +85,8 @@ function post_to_red_post($post_id) { } } - $message_namespace = 'wordpress'; - $message_id = site_url() . '/' . $post_id; - $message = $post->post_title . "

" . $message; - if (isset($tag_string)) { $message .= "
$tag_string"; } @@ -98,8 +94,6 @@ function post_to_red_post($post_id) { $bbcode = xpost_to_html2bbcode($message); $url = $seed_location . '/api/statuses/update'; - - $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); $body = array( @@ -117,20 +111,49 @@ function post_to_red_post($post_id) { $request = new WP_Http; $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); -// if($result['response']['code'] == 200) { -// $j = json_decode($result['body'],true); -// if($j && $j['id']) { -// // store the red id in case we need to delete it in the future. -// -// } -// } -// logger('post_to_red returns: ' . print_r($result,true)); + } + + } +} + + +function post_to_red_delete_post($post_id) { + + $post = get_post($post_id); + + // if meta has been set + if (get_post_meta($post_id, "post_to_red", true) == 1) { + + $user_name = post_to_red_get_acct_name(); + $password = post_to_red_get_password(); + $seed_location = post_to_red_get_seed_location(); + $channel = post_to_red_get_channel_name(); + + if ((isset($user_name)) && (isset($password)) && (isset($seed_location))) { + + $message_id = site_url() . '/' . $post_id; + $url = $seed_location . '/api/statuses/destroy'; + + $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); + $body = array( + 'namespace' => 'wordpress', + 'remote_id' => $message_id, + ); + if($channel) + $body['channel'] = $channel; + + // post: + $request = new WP_Http; + $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); } } } + + + function post_to_red_displayAdminContent() { $seed_url = post_to_red_get_seed_location(); @@ -239,6 +262,7 @@ add_action("admin_menu", "post_to_red_admin"); add_action('publish_post', 'post_to_red_post'); add_action('add_meta_boxes', 'post_to_red_post_checkbox'); add_action('save_post', 'post_to_red_post_field_data'); +add_action('before_delete_post', 'post_to_red_delete_post'); // from: // http://www.docgate.com/tutorial/php/how-to-convert-html-to-bbcode-with-php-script.html -- cgit v1.2.3 From 64b71a231b9f8e01490b78316205923c77c68c48 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Nov 2013 18:33:49 -0800 Subject: link the plugins at both ends so that each can discover a post that was imported/exported to/from the other and keep track of updates accordingly --- util/wp/post_to_red/post_to_red.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index d89ab91be..55177238d 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -59,14 +59,11 @@ function post_to_red_post($post_id) { $post = get_post($post_id); if (isset($_POST['post_to_red'])) { - update_post_meta($post_id, 'post_to_red', 1); - } else { - update_post_meta($post_id, 'post_to_red', 0); - } - + update_post_meta($post_id, 'post_to_red', '1'); + } // if meta has been set - if (get_post_meta($post_id, "post_to_red", true) == 1) { + if (get_post_meta($post_id, "post_to_red", true) === '1') { $user_name = post_to_red_get_acct_name(); $password = post_to_red_get_password(); @@ -122,7 +119,7 @@ function post_to_red_delete_post($post_id) { $post = get_post($post_id); // if meta has been set - if (get_post_meta($post_id, "post_to_red", true) == 1) { + if (get_post_meta($post_id, "post_to_red", true) == '1') { $user_name = post_to_red_get_acct_name(); $password = post_to_red_get_password(); @@ -221,10 +218,8 @@ function post_to_red_post_field_data($post_id) { // now store data in custom fields based on checkboxes selected if (isset($_POST['post_to_red'])) { - update_post_meta($post_id, 'post_to_red', 1); - } else { - update_post_meta($post_id, 'post_to_red', 0); - } + update_post_meta($post_id, 'post_to_red', '1'); + } } function post_to_red_display_admin_page() { -- cgit v1.2.3 From fd57b63c1d8e840db6902c7f8e04f69de2c58a3b Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Nov 2013 21:21:40 -0800 Subject: add terms and categories, fix a delivery loop (stops at one cycle but we don't need a post coming back that we just sent out). --- util/wp/post_to_red/post_to_red.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 55177238d..427e0f5e2 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -119,7 +119,7 @@ function post_to_red_delete_post($post_id) { $post = get_post($post_id); // if meta has been set - if (get_post_meta($post_id, "post_to_red", true) == '1') { + if ((get_post_meta($post_id, "post_to_red", true) == '1') || (get_post_meta($post_id, "post_from_red", true) == '1')) { $user_name = post_to_red_get_acct_name(); $password = post_to_red_get_password(); -- cgit v1.2.3 From b67347d9a03f92738eaa6b6de3f2b526f35d99d0 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 27 Nov 2013 16:32:17 -0800 Subject: add xmlrpc method for importing red comments --- util/wp/post_to_red/post_to_red.php | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 427e0f5e2..7fbf1eb76 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -259,6 +259,87 @@ add_action('add_meta_boxes', 'post_to_red_post_checkbox'); add_action('save_post', 'post_to_red_post_field_data'); add_action('before_delete_post', 'post_to_red_delete_post'); +add_filter('xmlrpc_methods', 'red_xmlrpc_methods'); + + +function red_xmlrpc_methods($methods) { + $methods['red.Comment'] = 'red_comment'; + return $methods; +} + +function red_comment($args) { + global $wp_xmlrpc_server; + $wp_xmlrpc_server->escape( $args ); + + $blog_id = $args[0]; + $username = $args[1]; + $password = $args[2]; + $post = $args[3]; + $content_struct = $args[4]; + + if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) ) + return $wp_xmlrpc_server->error; + + if ( is_numeric($post) ) + $post_id = absint($post); + else + $post_id = url_to_postid($post); + + if ( ! $post_id ) + return new IXR_Error( 404, __( 'Invalid post ID.' ) ); + if ( ! get_post($post_id) ) + return new IXR_Error( 404, __( 'Invalid post ID.' ) ); + + $comment['comment_post_ID'] = $post_id; + + $comment['comment_author'] = ''; + if ( isset($content_struct['author']) ) + $comment['comment_author'] = $content_struct['author']; + + $comment['comment_author_email'] = ''; + if ( isset($content_struct['author_email']) ) + $comment['comment_author_email'] = $content_struct['author_email']; + + $comment['comment_author_url'] = ''; + if ( isset($content_struct['author_url']) ) + $comment['comment_author_url'] = $content_struct['author_url']; + + $comment['user_ID'] = 0; + + if ( get_option('require_name_email') ) { + if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] ) + return new IXR_Error( 403, __( 'Comment author name and email are required' ) ); + elseif ( !is_email($comment['comment_author_email']) ) + return new IXR_Error( 403, __( 'A valid email address is required' ) ); + } + + if(isset($content_struct['comment_id'])) { + $comment['comment_ID'] = intval($content_struct['comment_id']); + $edit = true; + } + $comment['comment_post_ID'] = $post_id; + $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0; + $comment['comment_content'] = isset($content_struct['content']) ? $content_struct['content'] : null; + + do_action('xmlrpc_call', 'red.Comment'); + + if($edit) { + $result = wp_update_comment($comment); + $comment_ID = $comment['comment_ID']; + } + else { + $comment_ID = wp_new_comment( $comment ); + if($comment_ID) + wp_set_comment_status($comment_ID,'approve'); + } + + do_action( 'xmlrpc_call_success_red_Comment', $comment_ID, $args ); + + return $comment_ID; +} + + + // from: // http://www.docgate.com/tutorial/php/how-to-convert-html-to-bbcode-with-php-script.html function xpost_to_html2bbcode($text) { -- cgit v1.2.3 From 21e465e48ae918b75d011d0fc5de1864bb474edc Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 27 Nov 2013 20:56:08 -0800 Subject: add photos to red-to-wordpress comments --- util/wp/post_to_red/post_to_red.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 7fbf1eb76..71ae88aa8 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -261,6 +261,8 @@ add_action('before_delete_post', 'post_to_red_delete_post'); add_filter('xmlrpc_methods', 'red_xmlrpc_methods'); +add_filter('get_avatar', 'post_to_red_get_avatar',10,5); + function red_xmlrpc_methods($methods) { $methods['red.Comment'] = 'red_comment'; @@ -333,11 +335,29 @@ function red_comment($args) { wp_set_comment_status($comment_ID,'approve'); } + if(isset($content_struct['red_avatar'])) + add_comment_meta($comment_ID,'red_avatar',$content_struct['red_avatar'],true); + do_action( 'xmlrpc_call_success_red_Comment', $comment_ID, $args ); return $comment_ID; } +function post_to_red_get_avatar($avatar,$id_or_email,$size,$default,$alt) { + + if(! is_object($id_or_email)) + return $avatar; + if((! array_key_exists('comment_author_email',$id_or_email)) || (empty($id_or_email->comment_author_email))) + return $avatar; + if((! array_key_exists('comment_ID', $id_or_email)) || (! intval($id_or_email->comment_ID))) + return $avatar; + $l = get_comment_meta($id_or_email->comment_ID,'red_avatar',true); + if($l) { + $safe_alt = esc_attr($alt); + $avatar = "{$safe_alt}"; + } + return $avatar; +} // from: -- cgit v1.2.3 From aab9b30d03e2cad7be2207fa22dcd6ddad224369 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Nov 2013 00:16:13 -0800 Subject: synchronise deletion of comments between red and wp --- util/wp/post_to_red/post_to_red.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 71ae88aa8..7eb8697ad 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -148,6 +148,37 @@ function post_to_red_delete_post($post_id) { } } +function post_to_red_delete_comment($post_id) { + + // The comment may already be destroyed so we can't query it or the parent post. That means + // we have to make a network call for any deleted comment to see if it's registered on Red. + // We really need a "before_delete_comment" action in WP to make + // this more efficient. + + $user_name = post_to_red_get_acct_name(); + $password = post_to_red_get_password(); + $seed_location = post_to_red_get_seed_location(); + $channel = post_to_red_get_channel_name(); + + if ((isset($user_name)) && (isset($password)) && (isset($seed_location))) { + + $message_id = site_url() . '/' . $post_id; + $url = $seed_location . '/api/statuses/destroy'; + + $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); + $body = array( + 'namespace' => 'wordpress', + 'comment_id' => $message_id, + ); + if($channel) + $body['channel'] = $channel; + + // post: + $request = new WP_Http; + $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); + } +} + @@ -259,6 +290,8 @@ add_action('add_meta_boxes', 'post_to_red_post_checkbox'); add_action('save_post', 'post_to_red_post_field_data'); add_action('before_delete_post', 'post_to_red_delete_post'); +add_action('delete_comment', 'post_to_red_delete_comment'); + add_filter('xmlrpc_methods', 'red_xmlrpc_methods'); add_filter('get_avatar', 'post_to_red_get_avatar',10,5); -- cgit v1.2.3 From b707495b5072d6f15e801155b2ce54854224b33c Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 29 Nov 2013 03:10:15 -0800 Subject: channel wasn't getting saved --- util/wp/post_to_red/post_to_red.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 7eb8697ad..81ae9b3ed 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -259,6 +259,8 @@ function post_to_red_display_admin_page() { $password = $_REQUEST["post_to_red_password"]; $red_url = $_REQUEST["post_to_red_url"]; + $channelname = $_REQUEST['post_to_red_channel']; + update_option('post_to_red_acct_name', $_REQUEST["post_to_red_acct_name"]); update_option('post_to_red_channel_name', $channelname); -- cgit v1.2.3 From 25f067c954c9f2b9e64a2174dc4fad41d9d085a1 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 1 Dec 2013 14:06:45 -0800 Subject: add categories and optional backlink to exported WP posts --- util/wp/post_to_red/post_to_red.php | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 81ae9b3ed..11b1b48f7 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -69,6 +69,7 @@ function post_to_red_post($post_id) { $password = post_to_red_get_password(); $seed_location = post_to_red_get_seed_location(); $channel = post_to_red_get_channel_name(); + $backlink = get_option('post_to_red_backlink'); if ((isset($user_name)) && (isset($password)) && (isset($seed_location))) { // remove potential comments @@ -88,7 +89,23 @@ function post_to_red_post($post_id) { $message .= "
$tag_string"; } + $cats = ''; + + $terms = get_the_terms($post_id,'category'); + if($terms) { + foreach($terms as $term) { + if(strlen($cats)) + $cats .= ','; + $cats .= $term->name; + } + } + + + $bbcode = xpost_to_html2bbcode($message); + + if($backlink) + $bbcode .= "\n\n" . _('Source:') . ' ' . '[url]' . get_permalink($post_id) . '[/url]'; $url = $seed_location . '/api/statuses/update'; @@ -103,7 +120,9 @@ function post_to_red_post($post_id) { ); if($channel) $body['channel'] = $channel; - + if($cats) + $body['category'] = $cats; + // post: $request = new WP_Http; $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); @@ -188,7 +207,8 @@ function post_to_red_displayAdminContent() { $password = post_to_red_get_password(); $user_acct = post_to_red_get_acct_name(); $channel = post_to_red_get_channel_name(); - + $backlink = get_option('post_to_red_backlink'); + $backlink_checked = ((intval($backlink)) ? ' checked="checked" ' : ''); // debug... // echo "seed location: $seed_url
"; // echo "password: $password
"; @@ -204,10 +224,11 @@ function post_to_red_displayAdminContent() {

Configuration

Enter the login details of your Red Matrix account

-   - Password:   - Red Matrix URL:   - Optional channel nickname:   + Login (email):
+ Password:
+ Red Matrix URL:
+ Optional channel nickname:
+ Add permalink to posts?

@@ -266,7 +287,7 @@ function post_to_red_display_admin_page() { update_option('post_to_red_channel_name', $channelname); update_option('post_to_red_seed_location', $red_url); update_option('post_to_red_password', $password); - + update_option('post_to_red_backlink', $_REQUEST['post_to_red_backlink']); } post_to_red_displayAdminContent(); -- cgit v1.2.3 From 9f2efb0291e18ed9c042e8c018b8481c69179f26 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Dec 2013 23:55:57 -0800 Subject: ensure that every imported channel has a primary hubloc --- util/wp/post_to_red/post_to_red.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 11b1b48f7..43e24283c 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -356,7 +356,7 @@ function red_comment($args) { $comment['comment_author_email'] = ''; if ( isset($content_struct['author_email']) ) - $comment['comment_author_email'] = $content_struct['author_email']; + $comment['comment_author_email'] = 'zot:' . $content_struct['author_email']; $comment['comment_author_url'] = ''; if ( isset($content_struct['author_url']) ) -- cgit v1.2.3 From d96f5e2c081b582a77097b06706416d5ff371211 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 2 Dec 2013 23:57:50 -0800 Subject: undo last change to comment_email - these are checked for validity --- util/wp/post_to_red/post_to_red.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 43e24283c..11b1b48f7 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -356,7 +356,7 @@ function red_comment($args) { $comment['comment_author_email'] = ''; if ( isset($content_struct['author_email']) ) - $comment['comment_author_email'] = 'zot:' . $content_struct['author_email']; + $comment['comment_author_email'] = $content_struct['author_email']; $comment['comment_author_url'] = ''; if ( isset($content_struct['author_url']) ) -- cgit v1.2.3 From d8903f09f5a6d637b4258632eee16859373e1893 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 4 Dec 2013 00:19:29 -0800 Subject: include re-organisation and more doco, post_to_red fix ampersands in categories --- util/wp/post_to_red/post_to_red.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util/wp') diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php index 11b1b48f7..e7f18985e 100644 --- a/util/wp/post_to_red/post_to_red.php +++ b/util/wp/post_to_red/post_to_red.php @@ -96,7 +96,7 @@ function post_to_red_post($post_id) { foreach($terms as $term) { if(strlen($cats)) $cats .= ','; - $cats .= $term->name; + $cats .= htmlspecialchars_decode($term->name, ENT_COMPAT); } } -- cgit v1.2.3