--- hellotxtpress.php.orig	2009-11-24 15:45:47.000000000 +0100
+++ hellotxtpress.php	2010-05-20 09:26:05.000000000 +0200
@@ -3,9 +3,16 @@
 Plugin Name: HelloTxt post
 Plugin URI: http://hellotxt.com/app/wp-plugin/hellotxt.zip
 Description: Auto post your blogs on HelloTxt.
-Version: 1.0
+Version: 1.1
 Author: Fabrizio Giordano
 Author URI: http://fabriziogiordano.com
+Version 1.1: 	Patrick Vande Walle <patrick@vande-walle.eu> - 19-11-2009
+		- added configuration option for URL shortener
+		- added configuration option for post prefix
+		- Replace WP smart quotes by plain ones. (from WP Laconica Tools)
+	     	- Don't resend a post that was already submitted (from WP Laconica Tools)
+Version 1.1.1: 	Patrick Vande Walle <patrick@vande-walle.eu> - 19-05-2010
+		- added configuration option for Twitter hash tags
 */
 
 function hellotxtpost_install() {
@@ -19,6 +26,10 @@
 }
 
 function send_to_hellotxt($post_ID) {
+  // don't resend
+    $has_been_sent = get_post_meta($post_ID, 'sent_to_hellotxt', true);
+    if ($has_been_sent != 'yes')
+        {
 	$app_key = '1GNntqlC6X7UtVwj';
 	$user_key = get_option('hellotxt_user_key');
 	$group = get_option('hellotxt_group');
@@ -33,17 +44,70 @@
 	curl_setopt($ch, CURLOPT_POSTFIELDS, 
 		"app_key=".$app_key.
 		"&user_key=".$user_key.
-		"&body=".$posted->post_title.' - '.$posted->guid.
+		"&body=".get_option('hellotxt_post_prefix').fix_quote_entities($posted->post_title).' - *'.shorten_url($posted->guid).' '.get_option('hellotxt_post_hashtags').
 		"&group=".$group.
 		"&"); // add POST fields
 	$result = curl_exec($ch); // run the whole process
-	curl_close($ch);  
+	curl_close($ch);
+	add_post_meta($post_ID, 'sent_to_hellotxt', 'yes');  //add meta to say it was posted
+	}
+}
+
+function shorten_url($long_url) {
+        $shortened_url = '';
+        $url = get_option('hellotxt_url_stem').urlencode($long_url);
+        $chst = curl_init();
+        curl_setopt($chst, CURLOPT_URL, $url);
+        # return the transfer as a string
+        curl_setopt($chst, CURLOPT_RETURNTRANSFER, 1);
+        $shortened_url = curl_exec($chst);
+        curl_close($chst);
+        return $shortened_url;
+}
+
+/*
+ * In the database, quotes are stored as is but when pulled out, WP replaces with cute
+ * named entities, like left and right quotes. This introduces ampersands which truncate
+ * the post field sent to Laconica.  Just urlencoding these isn't helpful because they
+ * are escaped in Laconica and appear as things like &#8220; literally on the page.
+ * Changing them into plain old quotes, single and double, works best.
+ */
+function fix_quote_entities($title)
+{
+  // this only handles the common entities, the ones that are guessable from
+  // their name
+  $title = html_entity_decode($title, ENT_QUOTES);
+  // WordPress uses unicode escapes, preferentially
+  $title = str_replace("&#8217;", "'", $title);
+  $title = str_replace("&#8220;", '"', $title);
+  $title = str_replace("&#8221;", '"', $title);
+  $title = str_replace("&#8230;", '...', $title);
+  $title = str_replace("&#8211;", '--', $title);
+  $title = str_replace("&#038;", '&', $title);
+
+  return $title;
 }
+
+
+
 function hellotxtpost_menu() {
   add_options_page('HelloTxt Post Options', 'HelloTxt Post', 8, __FILE__, 'hellotxtpost_options');
 }
 
 function hellotxtpost_options() {
+
+if (get_option('hellotxt_url_stem')== FALSE){
+	add_option('hellotxt_url_stem', 'http://pra.im/api.php?url=');
+	}
+
+if (get_option('hellotxt_post_prefix')== FALSE){
+        add_option('hellotxt_post_prefix','New blog post: ');
+        }
+
+if (get_option('hellotxt_post_hashtags')== FALSE){
+        add_option('hellotxt_post_hashtags','#fb');
+        }
+
 echo '<div class="wrap">';
 echo '<h2>HelloTxt post</h2>';
 
@@ -66,10 +130,25 @@
 	  </td>';
 echo '</tr>';
 
+echo '<tr valign="top">';
+echo '<th scope="row">URL shortener string: </th>';
+echo '<td><input type="text" size="60" name="hellotxt_url_stem" value="'.get_option('hellotxt_url_stem').'" /></td>';
+echo '</tr>';
+
+echo '<tr valign="top">';
+echo '<th scope="row">Post prefix: </th>';
+echo '<td><input type="text" size="60" name="hellotxt_post_prefix" value="'.get_option('hellotxt_post_prefix').'" /></td>';
+echo '</tr>';
+
+echo '<tr valign="top">';
+echo '<th scope="row">Post hash tags: </th>';
+echo '<td><input type="text" size="60" name="hellotxt_post_hashtags" value="'.get_option('hellotxt_post_hashtags').'" /></td>';
+echo '</tr>';
+
 echo '</table>';
 
 echo '<input type="hidden" name="action" value="update" />';
-echo '<input type="hidden" name="page_options" value="hellotxt_user_key,hellotxt_group" />';
+echo '<input type="hidden" name="page_options" value="hellotxt_user_key,hellotxt_group,hellotxt_url_stem,hellotxt_post_prefix,hellotxt_post_hashtags" />';
 
 echo '<p class="submit">';
 echo '<input type="submit" name="Submit" value="'._e('Save Changes').'" />';
@@ -87,4 +166,3 @@
 // Create the publish post action
 add_action('publish_post', 'send_to_hellotxt');
 ?>
-

