Index: relatedlinks.module =================================================================== --- relatedlinks.module (revision 1772) +++ relatedlinks.module (revision 1778) @@ -97,7 +97,9 @@ // Fall through. case 'insert': if (in_array('manual', variable_get('relatedlinks_types', array('parsed')))) { - _relatedlinks_add_links($node->nid, explode("\n", $node->relatedlinks), RELATEDLINKS_MANUAL); + // Reverse the array to maintain the original ordering + // across multiple node updates. + _relatedlinks_add_links($node->nid, array_reverse(explode("\n", $node->relatedlinks)), RELATEDLINKS_MANUAL); } if (in_array('parsed', variable_get('relatedlinks_types', array('parsed')))) { // Rather than parsing out only the URI + link text, an attempt is @@ -137,8 +139,34 @@ return; } - $relatedlinks = !empty($node->relatedlinks) ? implode("\n", $node->relatedlinks) : ''; + // Get the links to be placed in the text field. + if (!empty($node->relatedlinks)) { + $relatedlinks = $node->relatedlinks; + // The links that come in from the database are HTML-formatted. + // This isn't very user friendly, so we're splitting each into + // the URL and the title, separated by a space. Or if there isn't + // a separate title, just list the URL. + foreach ($relatedlinks as $index => $link) { + preg_match('#href="([^"]*)"#',$link,$matches); + $url = $matches[1]; + + preg_match('#>([^<]*)<#',$link,$matches); + $title = $matches[1]; + + if ($url == $title) { + $relatedlinks[$index] = $url; + } + else { + $relatedlinks[$index] = $url . " " . $title; + } + } + $relatedlinks = implode("\n", $relatedlinks); + } + else { + $relatedlinks = ''; + } + $form['relatedlinks_fieldset'] = array( '#type' => 'fieldset', '#title' => t('Related links'), @@ -151,8 +179,8 @@ '#type' => 'textarea', '#default_value' => $relatedlinks, '#rows' => 3, - '#description' => t('To manually define links to related material, enter 1 -HTML-formatted link per line. Example: <a href="http://www.example.com">Clickable text</a>.') + '#notinymce' => TRUE, + '#description' => t('To manually define links to related material, enter one URL and title (separated by a space) per line. Example: "http://www.example.com Clickable Text". Alternately, you can enter an internal site address. Example: "about About Us" If no title is submitted, the URL itself will become the title.') ); } } @@ -269,6 +297,25 @@ foreach ($links as $link) { $link = trim($link); if (!empty($link)) { + + // Manual links need to be converted from a user-friendly format + // to HTML format because they are entered by the user. + if ($type == RELATEDLINKS_MANUAL) { + // Get the URL and the title from the text. + $url_and_title = explode(" ", $link); + $url = array_shift($url_and_title); + $title = implode(" ", $url_and_title); + + // If there is no title, the title will become the URL itself. + if (!$title) { + $title = $url; + } + + // Construct the HTML-formatted link. + $link = "$title"; + } + + // Insert it into the database. db_query("INSERT INTO {relatedlinks} (nid, link, type) VALUES (%d, '%s', %d)", $nid, $link, $type); } }