Categories
Package/plugin/module WordPress

Plugin: Dynamic Text Replace

Name:
Dynamic Text Replace
Author:
Scott Reilly
Version:
0.9.1
Last updated:
30 March 2005
Download:
Description:

Define your own custom dynamic text replacement pseudo-functions (i.e. ::google(“search terms here”)::)

Notes:

This plugin serves a different need than the Text Replace plugin (also written by me). Dynamic Text Replace allows you to easily pre-define text replacement template strings and allow for text to be passed in.

It comes preloaded with pseudo-functions that facilitate making links to: amazon.com, answers.com, codex.wordpress.org, google.com, imdb.com, and wikipedia.com. The beauty is that you can create your own very easily!

::amazon(“ASIN/ISBN goes here”, “What you want as the link text”)::
::answers(“dictionary word or search terms go here”, “Link text here”)::
::codex(“Use Custom Fields”, “Learn how to use custom fields”)::
::google(“Search terms go here”, “Link text here”)::
::imdb(“Search terms go here”, “Link text here”)::
::wikipedia(“Search terms here”, “Link text here”)::

In all cases, the second argument is optional. If not provided, the first argument will also be used as the link text. Double-quoting of arguments isn’t required, though it is recommended.

An Admin options page for the plugin greatly faciliates creation of new dynamic text replacements and also provides further documentation. In a nutshell, dynamic shortcuts are defined like:

amazon => <a href='http://www.amazon.com/exec/obidos/ASIN/%text%'>%display%</a>

%text% represents the first argument to the pseudo-function.
%display% represents the second argument to the pseudo-function
%text_altered% (used in the other preloaded dynamic shortcuts) is used when the first argument has been altered, which is handled in a special section of the plugin that you’d have to modify yourself if it is a feature you intend to utilize

Installation:
  1. Download the file dynamic-text-replace.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( dynamic-text-replace.phps ) into a file called dynamic-text-replace.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Activate the plugin from your WordPress admin ‘Plugins’ page.
  3. In WordPress’s Admin section, click the Options tab. Then click the “Dynamic Text Replace” subtab. Define new
    text replacement pseudo-functions according to the instructions and using the preloaded examples for reference.
  4. Use the shortcuts in a post.
Functions:

function c2c_dynamic_text_replace( $text )

  • $text : Text to be scanned for dynamic shortcuts
Tips & Examples:

(See notes section above)

Release Log:
  • 30 Mar 2005 : v0.9.1 —
    • Options page for the plugin now viewable for users with userlevel of 8 or higher.
    • Removed inadvertantly left behind debugging output code.
  • 29 Mar 2005 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements:
N/A

41 replies on “Plugin: Dynamic Text Replace”

Spooky or what, I already use your fantastic [url=”http://www.coffee2code.com/archives/2004/06/29/plugin-text-replace/”]Text Replace[/url] and I stopped by the site to suggest a similar modification to facilitate the above. Looks like you’re well ahead of me!
Installed.

WordPress Plugin: Dynamic Text Replace

Dynamic Text Replace is a plugin for WordPres 1.5 which allows you to define your own custom dynamic text replacement pseudo-functions (i.e. ::google(“search terms here”)::)

Dynamic Text Replace allows you to easily pre-define text replacement tem…

david: So in your Admin page, under the “Options” tab, there isn’t a “Dynamic Text Replace” sub-tab? Hrmm. The bug mentioned in the code is one in which a cleaner method of creating option pages wasn’t properly implemented in WP 1.5, so I had to do an alternate method which was equally valid. You seem to be using 1.5.1-alpha, which I haven’t tested on yet. The aforementioned bug was probably fixed in 1.5.1 and may’ve broken my approach in some fashion. I’ll test it out soon and see what I discover.

Hi Scott,

Thank you for the plugin! Very nice and simple to use. I did get the new tab logged as the admin . Maybe David should try it as admin? One thing I noticed was that a have a line appear on top of my posts for every use of a pseudo-function as such:

key was (wikipedia), text was (pvc), display was (PVC)

key was (wikipedia), text was (psat), display was (PSAT)

Is this a “side effect” or have I missed some “tweak” in the documentation?

Cheers,

Og

Ah, yes, Og’s right. The options sub-tab was only set to display for the site admin (and anyone else of user level 10). I just made an update to the plugin so it displays for user level 8 or higher.

And thanks for the other catch, Og. I inadvertantly left behind some debugging code, which I’ve removed in the next version.

Plugin updated to v0.9.1

Changes in the release:
* Options page for plugin now viewable for users with userlevel of 8 or higher.
* Removed debugging output code. (Thanks, Og!)

I think this plug-in would be more useful if it can support more than one variable. I’ve made minor amendment on the helper function as below. Hope you don’t mind. 😛


function __c2c_dynamic_text_replace_helper( $key, $text, $display='' ) {
  $separator = "||";
  $answer = '';
  $text_altered = '';
  if ( '' == $display ) $display = $text;
  $options = get_option('c2c_dynamic_text_replace');
  $pseudo_functions  = $options['pseudo_functions'];
  if (!empty($pseudo_functions)) {
    // Got special handling you want done on the text?  Do it here by setting the value for $text_altered
    switch ($key) {
      case 'answers' :
        $text_altered = str_replace(' ', '%20', $text);
        break;
      case 'google' :
      case 'imdb' :
        $text_altered = wp_specialchars(implode("+", explode(" ", $text)));
        break;
      case 'codex' :
      case 'wikipedia' :
        $text_altered = str_replace(' ', '_', $text);
        break;
    }

    if (strpos($text, $separator)) {
      $vars = explode($separator, $text);
      $answer = str_replace(array_fill(1,count($vars),$separator), $vars , $pseudo_functions[$key]);
      $answer = str_replace("%display%", $display, $answer);
    }
    else {
      $answer = str_replace("%text%", $text, $pseudo_functions[$key]);
      $answer = str_replace("%display%", $display, $answer);
    }
  }
  return str_replace("%text_altered%", ($text_altered)?$text_altered:$text, $answer);
} // end function __c2c_dynamic_text_replace_helper()

This version should be ok.

Sample Usage => No need of FLASHIFIER plugin now

1) Add this in POST:-

::flash(“01.swf$$310$$228”)::

2) Add this Pseudo-function:-

flash =>


function __c2c_dynamic_text_replace_helper( $key, $text, $display='' ) {
$separator = "$";
$answer = '';
$text_altered = '';
if ( '' == $display ) $display = $text;
$options = get_option('c2c_dynamic_text_replace');
$pseudo_functions = $options['pseudo_functions'];
if (!empty($pseudo_functions)) {
// Got special handling you want done on the text? Do it here by setting the value for $text_altered
switch ($key) {
case 'answers' :
$text_altered = str_replace(' ', '%20', $text);
break;
case 'google' :
case 'imdb' :
$text_altered = wp_specialchars(implode("+", explode(" ", $text)));
break;
case 'codex' :
case 'wikipedia' :
$text_altered = str_replace(' ', '_', $text);
break;
}

if (strpos($text, $separator.$separator)) {
$vars = explode($separator.$separator, $text);
for ($i = 1; $i

I have two ideas for your addon.

1. External Link Icon for every pseudo-function. Like the external icon on Wikipedia. WOuld be very nice.

2. Title value, i.e. ::amazon(“675327472657″,”Hellsing DVD Box”,”The complete Hellsing anime collection in one box.”)::. Would be nice, because withe the title value links would get a little popup with info exspecially when you use fancy tooltip plugin.

I hope you could think about these two little ideas, would be great.

I logged in as admin and activate the plugin but when i go to the options to click on the dynamic replace tab. It will always display

Forbidden
You don’t have permission to access /MobileGate/wp-admin/F:/xampplite/htdocs/MobileGate/wp-content/plugins/dynamic-text-replace.php on this server.

——————————————————————————–

Apache/2.0.53 (Win32) mod_ssl/2.0.53 OpenSSL/0.9.7e PHP/5.0.3 Server at ilsdev.psa Port 80

Why is it so? izzit about the permission of the directory of the files or some error of the versions?

[…] A volte i cambiamenti che un autore applica al suo blog non sono visibili ‘in superficie’, soprattutto quando si tratta di migliorie funzionali al meccanismo di editing e pubblicazione. E’ il caso del nuovo plug-in che sto per adottare nella preparazione di questo blog: si chiama ‘Text replace‘ ed e’ l’equivalente di quelle che in gergo informatico vengono chiamate ‘macro’, ovvero sistemi per automatizzare determinate operazioni. Anzi, piu’ precisamente somiglia moltissimo al meccanismo di sostituzione automatica del testo che troviamo in Microsoft Word, e che aiuta a digitare parole o frasi di uso frequente associandole a una breve sequenza di caratteri, che una volta digitati sono automaticamente ‘tradotti’ nella parola o frase scelta. Nel caso del mio blog, visto che ancora adesso mi ritrovo quasi sempre a digitare carattere per carattere i tag HTML che aprono una pagina linkata in una nuova finestra oppure quelli che definiscono l’allineamento delle immagini rispetto al testo, credo che l’adozione di questo plug-in si rivelera’ una mano santa, come si suol dire. L’autore di Text Replace ha creato anche un plug-in piu’ evoluto, che si chiama Dynamic Text Replace e puo’ essere utilizzato, per esempio, per inserire automaticamente dei link che possono avere parametri diversi, come una ricerca di Google o un riferimento a un libro su Amazon. Inoltre, dello stesso autore, vi segnalo l’interessante Random File, che come dice il nome permette di inserire un file a caso scelto da una cartella sul server, per esempio per cambiare un’immagine all’interno dell’intestazione (come nel template Random Image). Un plug-in simile a questo e’ Random Witty Text, che come si capisce dal nome e’ specifico per l’inserimento di una porzione di testo prelevata a caso da un file, per esempio una citazione famosa o una barzelletta. Se volete approfondire l’argomento plug-in, ho inserito contestualmente a questo post anche qualche nuovo link nella sezione Blog World qui a fianco. Ah, ovviamente il titolo di questo post si riferiva al sito Cofee2Code, se c’e’ ancora qualcuno che si sta chiedendo cosa c’entra il caffe’ in tutto questo (a parte che si tratta della mia ‘droga’ quotidiana). […]

I would really like to see a function that returns all the Dynamic Text Codes that are available. That way I could easily remember how and what I set up as well as other writers on the blog coul look up what is available since they do not have access to the plugin page.

Thanks so much!

Does this parse during posting, or during display?

I utilize external blog editors (qumana, flock, and ecto), as opposed to the WP post page. If this only parses during posting, then it’s pretty much not useful to me.

Also, is there support now (or maybe in future) for amazon affiliate IDs?

WordPress von der Rückseite – Teil 2

Nachdem es im ersten Teil hauptsächlich um die Gründe für WordPress ging, will ich heute eines der eingesetzten PlugIns vorstellen.
Dynamic Text Replace
Wer oft Links nach dem gleichen Muster schreiben muß, wird “Dynamic Te…

I use the plugin to quickly provide links to Yahoo finance for stock ticker symbols in my blog, as well as wikipedia. It’s fantastic.

However, when I link to single character symbols like AT&T (Symbol is T) the plugin inserts an extra quote mark.

Here’s the script:

ticker =&gt; (<a href='http://finance.yahoo.com/q?d=t&amp;s=%text%' title='%text%' rel="nofollow">%text%</a>)

and I insert this into the post text

::ticker("Q"):: Where Q is for Quest

and I get the following output.

( Q” )

If I use a space after the Q::ticker("Q "):: it works fine. But I then have a space where I don’t want one.

The problem exceeds my php skills…. any assistance welcome.

Google Dynamic Text Replace WordPress Plugin

Name: Dynamic Text Replace Author: Scott Reilly Version: 0.9.1 Last
updated: 30 March 2005 Download: [ zip ] | [ view source (.phps) ]
Description: Define your own custom dynamic text replacement pseudo-
functions (i.e. ::google(“search terms her…

It works fine for me in WP2, only thing that seems to not work is if the search term contains a comma. This has been a problem I encounter when entering a link for wikipedia. eg. ::wikipedia(“Dogtown, California”,”Dogtown”)::

Other than that works fine in WP2

I tried installing this on a WP 2.0.2 install, and kept getting an error. On line 188, I believe that you need to end the heredoc with just END and the semicolon. The comment needs to go on another line. Once I did this, things seemed to work.

Yep, thanks. that works!

thus

change line 188 (or 187 in my file…)
“END;} //end c2c_admin_dynamic_text_replace()”

in:
“END;
} //end c2c_admin_dynamic_text_replace()”

Comments are closed.