Index: relatedlinks.module =================================================================== --- relatedlinks.module (revision 1376) +++ relatedlinks.module (revision 1377) @@ -1,5 +1,5 @@ ' . '
Taxonomy Links
' . '
Related taxonomy nodes can also be listed.
' . - ''); + '' . + 'Parsed and manual links are updated when the node is edited. ' . + 'Taxonomy links are determined on the fly.'); } } @@ -86,6 +91,22 @@ switch ($op) { case 'load': $links = _relatedlinks_get_links($node->nid, RELATEDLINKS_MANUAL); + + // 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 ($links as $index => $link) { + $html_chunks = explode('"', $link); + $url = $html_chunks[1]; + $title = substr($html_chunks[2], 1, -4); + if ($url == $title) { + $links[$index] = $url; + } else { + $links[$index] = $url . " " . $title; + } + } + $node->relatedlinks = !empty($links) ? implode("\n", $links) : ''; break; case 'delete': @@ -95,10 +116,14 @@ _relatedlinks_delete_links($node->nid); // 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); + if (in_array('manual', + variable_get('relatedlinks_types', array('parsed')))) { + _relatedlinks_add_links($node->nid, + explode("\n", $node->relatedlinks), + RELATEDLINKS_MANUAL); } - if (in_array('parsed', variable_get('relatedlinks_types', array('parsed')))) { + if (in_array('parsed', + variable_get('relatedlinks_types', array('parsed')))) { // Rather than parsing out only the URI + link text, an attempt is // made to retain any other attributes present. preg_match_all('#(]+>[^<]+)#', $node->body, $matches); @@ -149,7 +174,12 @@ '#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>.'), +# '#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>.'), + '#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". If no title is submitted,' . + ' the URL itself will become the title.'), ); } } @@ -283,7 +313,27 @@ foreach ($links as $link) { $link = trim($link); if (!empty($link)) { - db_query("INSERT INTO {relatedlinks} (nid, link, type) VALUES (%d, '%s', %d)", $nid, $link, $type); + + // 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); } } }