--- ed_readmore.init.module	2007-12-08 10:28:59.000000000 +0200
+++ ed_readmore.module	2007-12-08 10:28:57.000000000 +0200
@@ -27,8 +27,8 @@ define('ED_READMORE_MODULE_VERSION', '$I
 define('ED_READMORE_READMORE_TWEAK_DEFAULT', TRUE);
 define('ED_READMORE_READMORE_INLINE_DEFAULT', TRUE);
 // use this for "fancy" default
-define('ED_READMORE_TEXT_DEFAULT', '&nbsp;read&nbsp;more&nbsp;&raquo;');
-//define('ED_READMORE_TEXT_DEFAULT', 'read more &raquo;');
+define('ED_READMORE_TEXT_DEFAULT', 'read more &raquo;');
+define('ED_READMORE_TITLE_DEFAULT', 'Read the rest of this posting.');
 
 /**
  * Place the teaser in the correct location in $thing
@@ -38,14 +38,16 @@ define('ED_READMORE_TEXT_DEFAULT', '&nbs
  */
 
 function _ed_readmore_place_readmore_link($thing, $link, $inlineflag) {
-  $read_more = " <span class='read-more'>" . $link . "</span>";
+  $read_more = "<span class='read-more'>" . $link . "</span>";
   if ($inlineflag) {
+    // (only if is inline) it must be prefixes with a nonbreaking space: &nbsp;
+    $read_more = '&nbsp;' . $read_more;
     // deal with broken strrpos on php4
     if (_ed_readmore_is_php4()) {
       $find_last = '_ed_readmore_strrpos_string';
     }
     else {
-      $find_last = 'strrpos';
+      $find_last = 'strripos';
     }
     // int strrpos ( string haystack, string needle [, int offset] )
     // substr_replace ( mixed string, string replacement, int start [, int length] )
@@ -76,14 +78,23 @@ function _ed_readmore_place_readmore_lin
 function ed_readmore_nodeapi(&$node, $op, $teaser, $page) {
   $enabled = variable_get('ed_readmore_readmore_tweak', ED_READMORE_READMORE_TWEAK_DEFAULT);
   $inlineflag = variable_get('ed_readmore_readmore_inline', ED_READMORE_READMORE_INLINE_DEFAULT);
-  $readmore_url = l(variable_get('ed_readmore_text', t(ED_READMORE_TEXT_DEFAULT)), "node/$node->nid", NULL, NULL, NULL, TRUE, TRUE);
+  // prepare the link text
+  $link_text = variable_get('ed_readmore_text', t(ED_READMORE_TEXT_DEFAULT));
+  $link_text = t($link_text); // this was added to allow localization of the link text
+  $link_text = str_replace(' ', '&nbsp;', $link_text); // prevent line break into the readmore link
+  $link_title = variable_get('ed_readmore_title', ED_READMORE_TITLE_DEFAULT); // native text
+  $link_title = t($link_title); // localized text
+  // $readmore_url is used for regular node teaser
+  $readmore_url = l($link_text, "node/$node->nid", array('title' => $link_title), NULL, NULL, FALSE, TRUE); 
+  // $readmore_url_rss is used for RSS teaser
+  $readmore_url_rss = l($link_text, "node/$node->nid", array('title' => $link_title), NULL, NULL, TRUE, TRUE); 
   if ($enabled) {
     if ($op == 'rss item') {
       $item_length = variable_get('feed_item_length', 'teaser'); // from node.module node_feed() code
       switch($item_length) {
         case 'teaser':
           if (strlen($node->teaser) < strlen($node->body)) {
-            $node->teaser = _ed_readmore_place_readmore_link($node->teaser, $readmore_url, $inlineflag);
+            $node->teaser = _ed_readmore_place_readmore_link($node->teaser, $readmore_url_rss, $inlineflag);
           }
           break;
       }
@@ -92,16 +103,19 @@ function ed_readmore_nodeapi(&$node, $op
     
     if ($op == 'view' ) {
       if ($teaser && $node->readmore) {
-        $node->readmore = false;
-        //
-        // since we are blowing away some of the implicit info ($node->readmore) let's remember that this was a teaser
-        $node->is_teaser = TRUE;
         $node->content[body]['#value'] = _ed_readmore_place_readmore_link($node->content[body]['#value'], $readmore_url, $inlineflag);
       }
     }
   }
 }
 
+function ed_readmore_link_alter($node, &$links) {
+  $remove = variable_get('ed_readmore_remove', TRUE);
+  if ($remove) {
+    unset($links['node_read_more']);
+  }
+}
+
 ###################################################
 #
 # DESCRIPTION:
@@ -127,7 +141,7 @@ function _ed_readmore_strrpos_string($ha
   if(trim($haystack) != "" && trim($needle) != "" && $offset <= strlen($haystack)) {
     $last_pos = $offset;
     $found = false;
-    while(($curr_pos = strpos($haystack, $needle, $last_pos)) !== false) {
+    while(($curr_pos = strpos(strtolower($haystack), strtolower($needle), $last_pos)) !== false) {
       $found = true;
       $last_pos = $curr_pos + 1;
     }
@@ -183,9 +197,15 @@ function ed_readmore_admin_settings() {
 
   $form['readmore']['ed_readmore_readmore_tweak'] = 
     array('#type' => 'checkbox', 
-          '#title'=> t('Relocate <strong>read more</strong> link from links section?'), 
+          '#title'=> t('Add <strong>read more</strong> link to the end of teaser?'), 
           '#default_value' => variable_get('ed_readmore_readmore_tweak', ED_READMORE_READMORE_TWEAK_DEFAULT), 
-          '#description' => t('Move Read More from links to end of teaser?  See <a target="_blank" href="http://www.angrydonuts.com/the_nuisance_of_the_read_more_fl">AngryDonuts.com</a> for details.'), 
+          '#description' => t('Add a <strong>read more</strong> link to the end of teaser.  See <a target="_blank" href="http://www.angrydonuts.com/the_nuisance_of_the_read_more_fl">AngryDonuts.com</a> for details.'), 
+          '#required'=>FALSE);
+  $form['readmore']['ed_readmore_remove'] = 
+    array('#type' => 'checkbox', 
+          '#title'=> t('Remove <strong>read more</strong> link from links section?'), 
+          '#default_value' => variable_get('ed_readmore_remove', TRUE), 
+          '#description' => t('Also remove the "read more" link from node links.'), 
           '#required'=>FALSE);
 
   $form['readmore']['ed_readmore_readmore_inline'] = 
@@ -201,6 +221,12 @@ function ed_readmore_admin_settings() {
           '#default_value' => variable_get('ed_readmore_text', t(ED_READMORE_TEXT_DEFAULT)), 
           '#description' => t('Enter the text you wish to display in the read more link.  May contain HTML.'), 
           '#required'=>TRUE);
+  $form['readmore']['ed_readmore_title'] = 
+    array('#type' => 'textfield', 
+          '#title'=> t('The title for the "read more" link'), 
+          '#default_value' => variable_get('ed_readmore_title', ED_READMORE_TITLE_DEFAULT), 
+          '#description' => t('Enter the text you wish to be used as title in the "read more" link. You should give this text in english. The module will localize this text when is displayed.'), 
+          '#required' => FALSE);
 
 
   return system_settings_form($form);
