From 59e19a1f45a3502559dd1df33c453aa2f99cb995 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 25 Oct 2014 01:03:36 -0700 Subject: moved post_to_red to its own project ( https://github.com/friendica/wptored ), which I was planning to do anyway since it's kind of lost in the util folder, but also because having it there may present licensing issues, as it's GPL. --- util/wp/post_to_red/post_to_red.php | 493 ------------------------------------ util/wp/post_to_red/readme.txt | 39 --- 2 files changed, 532 deletions(-) delete mode 100644 util/wp/post_to_red/post_to_red.php delete 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 deleted file mode 100644 index ea6026ae2..000000000 --- a/util/wp/post_to_red/post_to_red.php +++ /dev/null @@ -1,493 +0,0 @@ -/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_id = site_url() . '/' . $post_id; - - if (isset($tag_string)) { - $message .= "
$tag_string"; - } - - $cats = ''; - - $terms = get_the_terms($post_id,'category'); - if($terms) { - foreach($terms as $term) { - if(strlen($cats)) - $cats .= ','; - $cats .= htmlspecialchars_decode($term->name, ENT_COMPAT); - } - } - - - - $bbcode = xpost_to_html2bbcode($message); - - if($backlink) - $bbcode .= "\n\n" . _('Source:') . ' ' . '[url]' . get_permalink($post_id) . '[/url]'; - - $url = $seed_location . '/api/statuses/update'; - - $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password")); - $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; - if($cats) - $body['category'] = $cats; - - // post: - $request = new WP_Http; - $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers)); - - } - - } -} - - -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') || (get_post_meta($post_id, "post_from_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_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)); - } -} - - - - -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(); - $backlink = get_option('post_to_red_backlink'); - $backlink_checked = ((intval($backlink)) ? ' checked="checked" ' : ''); - // 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

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

-
-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((! 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'])) { - update_post_meta($post_id, 'post_to_red', '1'); - } -} - -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"]; - $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); - 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(); -} - -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'); -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); - - -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'); - } - - 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: -// http://www.docgate.com/tutorial/php/how-to-convert-html-to-bbcode-with-php-script.html - -//function exists also in post to friendica plugin; load only if not yet loaded by that plugin -if(!function_exists('xpost_to_html2bbcode')) { - 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 deleted file mode 100644 index e27c46236..000000000 --- a/util/wp/post_to_red/readme.txt +++ /dev/null @@ -1,39 +0,0 @@ -=== 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