Does anyone know of a Drupal module that is compatible with 4.7x that will allow me to create a list of urls and associate certain keywords with those urls, so that when any of the keywords listed are displayed in a page or story, that keyword will get linked to the specified url? I don't want to have to manually type in the link on every page or story...it would be much easier to change a link if I had to in the future, and the change would be made automatically across all posts that are using the link.

Thanks

Comments

robclay’s picture

I copied this from here awhile back, but could not bring it up again when I did a search - so the credit goes to someone, I just cannot remember who:

This has not been tried by me with my latest site, but worked in Drupal 4.6...

Basically copy this and paste in a text file - then rename to stringreplacer.module, and place into the modules directory.

     
    function stringreplacer_help($section) {
        switch ($section) {
            case 'admin/modules#description': return t('Filter to let you replace strings with others of your choice');
            break;
        }
    }
     
    function stringreplacer_filter($op, $delta = 0, $format = -1, $text = '') {
        switch ($op) {
            case 'list': return array(0 => t('String replacement'));
            break;
            case 'no cache': break;
            case 'description': return t('Replaces strings with other ones.');
            break;
            case 'prepare': return $text;
            break;
            case 'process': // Lets do our thing. This is the juicy stuff ;-)
            $replacements = variable_get('stringreplacer_replacements_'.$format, array());
            return str_replace(array_keys($replacements), $replacements, $text);
            break;
            case 'settings': // I use this extra variable here for this to work indendent of the outside.
            if (variable_get('stringreplacer_dirty', 0) == 1) {
                $lines = explode("\n", variable_get('stringreplacer_textarea_'.$format, array()));
                $replacements = array();
                foreach ($lines as $line) {
                    $pieces = explode("=>", $line);
                    if (count($pieces) == 2) {
                        // accepted submitted set
                        $string = trim($pieces[0]);
                        $replacement = trim($pieces[1]);
                        $replacements[$string] = $replacement;
                    }
                }
                variable_set('stringreplacer_replacements_'.$format, $replacements);
                variable_set('stringreplacer_dirty', 0);
            }
            $content = '<p>'.t('Write in which strings you want to replace and their replacements in this form:').'</p>';
            $content .= t('<p>string =&amp;gt; replacement&lt;br /&gt;Help me! =&amp;gt; Please help me&lt;br /&gt;plz =&amp;gt; please&lt;br /&gt;google =&amp;gt; &amp;lt;a href=&amp;quot;http://google.com&amp;quot;&amp;gt;google&amp;lt;/a&amp;gt;</p>');
                $content .= ' < p > '.t('Note that other filters might not allow or does something with certain text/characters, and thus needs to be configured properly. For instance, if you want to replace with PHP, make sure PHP is allowed').' < /p > ';
                 
                $txtarea_content = '';
                foreach (variable_get('stringreplacer_replacements_'.$format, array()) as $string => $replacement) {
                $txtarea_content .= "$string => $replacement\n";
                }
                 
                $content .= form_textarea(
                t('Replacements'),
                'stringreplacer_textarea_'.$format,
                $txtarea_content, // htmlentities taken care of automagically
                50, 10, '', NULL, TRUE
                );
                variable_set('stringreplacer_dirty', 1); // process in prepare
                $content = form_group('String replacement', $content);
                return $content;
                break;
                default:
                return $text;
                }
                }