diff options
-rw-r--r-- | include/enotify.php | 84 | ||||
-rw-r--r-- | mod/item.php | 10 | ||||
-rw-r--r-- | util/wp/post_to_red/post_to_red.php | 299 | ||||
-rw-r--r-- | util/wp/post_to_red/readme.txt | 39 | ||||
-rw-r--r-- | version.inc | 2 | ||||
-rwxr-xr-x | view/tpl/email_notify_html.tpl | 2 |
6 files changed, 397 insertions, 39 deletions
diff --git a/include/enotify.php b/include/enotify.php index cfa8c25ae..808efef51 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -132,25 +132,28 @@ function notification($params) { //$possess_desc = str_replace('<!item_type!>',$possess_desc); // "a post" - $dest_str = sprintf(t('%1$s commented on [zrl=%2$s]a %3$s[/zrl]'), - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $itemlink, - $item_post_type); + $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]a %4$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $item_post_type); // "George Bull's post" if($p) - $dest_str = sprintf(t('%1$s commented on [zrl=%2$s]%3$s\'s %4$s[/zrl]'), - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $itemlink, - $p[0]['author']['xchan_name'], - $item_post_type); + $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]%4$s\'s %5$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $p[0]['author']['xchan_name'], + $item_post_type); // "your post" if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && ($p[0]['item_flags'] & ITEM_WALL)) - $dest_str = sprintf(t('%1$s commented on [zrl=%2$s]your %3$s[/zrl]'), - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $itemlink, - $item_post_type); + $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]your %4$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $item_post_type); // Some mail softwares relies on subject field for threading. // So, we cannot have different subjects for notifications of the same thread. @@ -158,7 +161,7 @@ function notification($params) { // differents subjects for messages on the same thread. $subject = sprintf( t('[Red:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']); - $preamble = sprintf( t('%s commented on an item/conversation you have been following.'), $sender['xchan_name']); + $preamble = sprintf( t('%1$s, %2$s commented on an item/conversation you have been following.'), $recip['channel_name'], $sender['xchan_name']); $epreamble = $dest_str; $sitelink = t('Please visit %s to view and/or reply to the conversation.'); @@ -170,11 +173,13 @@ function notification($params) { if($params['type'] == NOTIFY_WALL) { $subject = sprintf( t('[Red:Notify] %s posted to your profile wall') , $sender['xchan_name']); - $preamble = sprintf( t('%1$s posted to your profile wall at %2$s') , $sender['xchan_name'], $sitename); + $preamble = sprintf( t('%1$s, %2$s posted to your profile wall at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename); - $epreamble = sprintf( t('%1$s posted to [zrl=%2$s]your wall[/zrl]') , - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $params['link']); + $epreamble = sprintf( t('%1$s, %2$s posted to [zrl=%3$s]your wall[/zrl]') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $params['link']); + // FIXME - check the item privacy $private = false; @@ -199,9 +204,10 @@ function notification($params) { $subject = sprintf( t('[Red:Notify] %s tagged you') , $sender['xchan_name']); $preamble = sprintf( t('%1$s, %2$s tagged you at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename); - $epreamble = sprintf( t('%1$s [zrl=%2$s]tagged you[/zrl].') , - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $params['link']); + $epreamble = sprintf( t('%1$s, %2$s [zrl=%3$s]tagged you[/zrl].') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $params['link']); $sitelink = t('Please visit %s to view and/or reply to the conversation.'); $tsitelink = sprintf( $sitelink, $siteurl ); @@ -213,9 +219,10 @@ function notification($params) { $subject = sprintf( t('[Red:Notify] %1$s poked you') , $sender['xchan_name']); $preamble = sprintf( t('%1$s, %2$s poked you at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename); - $epreamble = sprintf( t('%1$s [zrl=%2$s]poked you[/zrl].') , - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $params['link']); + $epreamble = sprintf( t('%1$s, %2$s [zrl=%2$s]poked you[/zrl].') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $params['link']); $subject = str_replace('poked', t($params['activity']), $subject); $preamble = str_replace('poked', t($params['activity']), $preamble); @@ -229,10 +236,11 @@ function notification($params) { if($params['type'] == NOTIFY_TAGSHARE) { $subject = sprintf( t('[Red:Notify] %s tagged your post') , $sender['xchan_name']); - $preamble = sprintf( t('%1$s tagged your post at %2$s') , $sender['xchan_name'], $sitename); - $epreamble = sprintf( t('%1$s tagged [zrl=%2$s]your post[/zrl]') , - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', - $itemlink); + $preamble = sprintf( t('%1$s, %2$s tagged your post at %3$s') , $recip['channel_name'],$sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, %2$s tagged [zrl=%3$s]your post[/zrl]') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink); $sitelink = t('Please visit %s to view and/or reply to the conversation.'); $tsitelink = sprintf( $sitelink, $siteurl ); @@ -242,10 +250,11 @@ function notification($params) { if($params['type'] == NOTIFY_INTRO) { $subject = sprintf( t('[Red:Notify] Introduction received')); - $preamble = sprintf( t('You\'ve received an introduction from \'%1$s\' at %2$s'), $sender['xchan_name'], $sitename); - $epreamble = sprintf( t('You\'ve received [zrl=%1$s]an introduction[/zrl] from %2$s.'), - $itemlink, - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'); + $preamble = sprintf( t('%1$s, you\'ve received an introduction from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, you\'ve received [zrl=%2$s]an introduction[/zrl] from %3$s.'), + $recip['channel_name'], + $itemlink, + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'); $body = sprintf( t('You may visit their profile at %s'),$sender['xchan_url']); $sitelink = t('Please visit %s to approve or reject the introduction.'); @@ -256,11 +265,12 @@ function notification($params) { if($params['type'] == NOTIFY_SUGGEST) { $subject = sprintf( t('[Red:Notify] Friend suggestion received')); - $preamble = sprintf( t('You\'ve received a friend suggestion from \'%1$s\' at %2$s'), $sender['xchan_name'], $sitename); - $epreamble = sprintf( t('You\'ve received [zrl=%1$s]a friend suggestion[/zrl] for %2$s from %3$s.'), - $itemlink, - '[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]', - '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'); + $preamble = sprintf( t('%1$s, you\'ve received a friend suggestion from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, you\'ve received [zrl=%2$s]a friend suggestion[/zrl] for %3$s from %4$s.'), + $recip['channel_name'], + $itemlink, + '[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]', + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'); $body = t('Name:') . ' ' . $params['item']['name'] . "\n"; $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n"; diff --git a/mod/item.php b/mod/item.php index 7eebbe287..dba9f01b6 100644 --- a/mod/item.php +++ b/mod/item.php @@ -58,6 +58,12 @@ function item_post(&$a) { // If you are unsure, it is prudent (and important) to leave it unset. $origin = (($api_source && array_key_exists('origin',$_REQUEST)) ? intval($_REQUEST['origin']) : 1); + + // To represent message-ids on other networks - this will create an item_id record + + $namespace = (($api_source && array_key_exists('namespace',$_REQUEST)) ? strip_tags($_REQUEST['namespace']) : ''); + $remote_id = (($api_source && array_key_exists('remote_id',$_REQUEST)) ? strip_tags($_REQUEST['remote_id']) : ''); + $owner_hash = null; $message_id = ((x($_REQUEST,'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : ''); @@ -782,6 +788,10 @@ function item_post(&$a) { $page_type = 'BUILDBLOCK'; elseif($webpage & ITEM_PDL) $page_type = 'PDL'; + elseif($namespace && $remote_id) { + $page_type = $namespace; + $pagetitle = $remote_id; + } if($page_type) { 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..47af7789b --- /dev/null +++ b/util/wp/post_to_red/post_to_red.php @@ -0,0 +1,299 @@ +<?php +/* +Plugin Name: CrossPost to Red Matrix +Plugin URI: http://blog.duthied.com/2011/09/12/friendika-cross-poster-wordpress-plugin/ +Description: This plugin allows you to cross post to your Red Matrix account. Extended by Mike Macgirvin from a Friendica cross-posting tool +Version: 1.2 +Author: Devlon Duthied +Author URI: http://blog.duthied.com +*/ + +/* Copyright 2011 Devlon Duthie (email: duthied@gmail.com) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +define("post_to_red_path", WP_PLUGIN_URL . "/" . str_replace(basename( __FILE__), "", plugin_basename(__FILE__))); +define("post_to_red_version", "1.2"); +$plugin_dir = basename(dirname(__FILE__)); +$plugin = plugin_basename(__FILE__); + +define("post_to_red_acct_name", "post_to_red_admin_options"); + +function post_to_red_deactivate() { + delete_option('post_to_red_seed_location'); + delete_option('post_to_red_acct_name'); + delete_option('post_to_red_user_name'); + delete_option('post_to_red_password'); +} + +function post_to_red_get_seed_location() { + return get_option('post_to_red_seed_location'); +} + +function post_to_red_get_acct_name() { + return get_option('post_to_red_acct_name'); +} + +function post_to_red_get_channel_name() { + return get_option('post_to_red_channel_name'); +} + +function post_to_red_get_password() { + return get_option('post_to_red_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(); + $channel = post_to_red_get_channel_name(); + + if ((isset($user_name)) && (isset($password)) && (isset($seed_location))) { + // remove potential comments + $message = preg_replace('/<!--(.*)-->/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_namespace = 'wordpress'; + + $message_id = site_url() . '/' . $post_id; + + $message = $post->post_title . "<br /><br />" . $message; + + $message .= "<br /><br />permalink: " . $post->guid; + + if (isset($tag_string)) { + $message .= "<br />$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', 'namespace' => $message_namespace, '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(); + $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</br>"; + // echo "password: $password</br>"; + // echo "user_acct: $user_acct</br>"; + + echo <<<EOF + <div class='wrap'> + <h2>CrossPost to Red Matrix</h2> + <p>This plugin allows you to cross post to your Red Matrix channel.</p> + </div> + + <div class="wrap"> + <h2>Configuration</h2> + <form method="post" action="{$_SERVER["REQUEST_URI"]}"> + Enter the login details of your Red Matrix account<br /><br /> + <input type="text" name="post_to_red_acct_name" value="{$user_acct}"/> + Password: <input type="password" name="post_to_red_password" value="{$password}"/> + Red Matrix URL: <input type="text" name="post_to_red_url" value="{$seed_url}"/> + Optional channel nickname: <input type="text" name="post_to_red_channel" value="{$channel}"/> + <input type="submit" value="Save" name="submit" /> + </form> + <p></p> + </div> +EOF; + + if(isset($_POST['submit'])) { + echo "<div style='text-align:center;padding:4px;width:200px;background-color:#FFFF99;border:1xp solid #CCCCCC;color:#000000;'>Settings Saved!</div>"; + } +} + +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 '<input type="checkbox" name="post_to_red" value="1" /> 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); + } 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 = '<a href="options-general.php?page=xpost-to-redmatrix">Settings</a>'; + 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\>(.*?)\<\/b\>/is', + '/\<i\>(.*?)\<\/i\>/is', + '/\<u\>(.*?)\<\/u\>/is', + '/\<ul.*?\>(.*?)\<\/ul\>/is', + '/\<li\>(.*?)\<\/li\>/is', + '/\<img(.*?) src=\"(.*?)\" alt=\"(.*?)\" title=\"Smile(y?)\" \/\>/is', // some smiley + '/\<img(.*?) src=\"http:\/\/(.*?)\" (.*?)\>/is', + '/\<img(.*?) src=\"(.*?)\" alt=\":(.*?)\" .*? \/\>/is', // some smiley + '/\<div class=\"quotecontent\"\>(.*?)\<\/div\>/is', + '/\<div class=\"codecontent\"\>(.*?)\<\/div\>/is', + '/\<div class=\"quotetitle\"\>(.*?)\<\/div\>/is', + '/\<div class=\"codetitle\"\>(.*?)\<\/div\>/is', + '/\<cite.*?\>(.*?)\<\/cite\>/is', + '/\<blockquote.*?\>(.*?)\<\/blockquote\>/is', + '/\<div\>(.*?)\<\/div\>/is', + '/\<code\>(.*?)\<\/code\>/is', + '/\<br(.*?)\>/is', + '/\<strong\>(.*?)\<\/strong\>/is', + '/\<em\>(.*?)\<\/em\>/is', + '/\<a href=\"mailto:(.*?)\"(.*?)\>(.*?)\<\/a\>/is', + '/\<a .*?href=\"(.*?)\"(.*?)\>http:\/\/(.*?)\<\/a\>/is', + '/\<a .*?href=\"(.*?)\"(.*?)\>(.*?)\<\/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('<br>', '<br />'), "\n", $text); + $ntext = str_replace(array('<strong>', '</strong>'), array('[b]', '[/b]'), $ntext); + $ntext = str_replace(array('<em>', '</em>'), 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 == diff --git a/version.inc b/version.inc index ec2cb12cd..65cc36208 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2013-11-23.506 +2013-11-25.508 diff --git a/view/tpl/email_notify_html.tpl b/view/tpl/email_notify_html.tpl index 41bbe16a9..cf149341e 100755 --- a/view/tpl/email_notify_html.tpl +++ b/view/tpl/email_notify_html.tpl @@ -5,7 +5,7 @@ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> <body> -<table style="border:1px solid #ccc"> +<table style="border:1px solid #ccc; background-color: #FFFFFF; color: #000000;"> <tbody> <tr><td colspan="2" style="background:#c60032; color:#FFFFFF; font-weight:bold; font-family:'lucida grande', tahoma, verdana,arial, sans-serif; padding: 4px 8px; vertical-align: middle; font-size:16px; letter-spacing: -0.03em; text-align: left;"><img style="width:32px;height:32px; float:left;" src='{{$siteurl}}/images/rm-32.png'><div style="padding:7px; margin-left: 5px; float:left; font-size:18px;letter-spacing:1px;">{{$product}}</div><div style="clear: both;"></div></td></tr> |