Scripturizer in PHP

UPDATE 12/23/2004: I’ve moved my version of the code to the new WP Plugins repository, so you can download it at http://dev.wp-plugins.org/file/scripturizer/trunk/scripturizer.php

UPDATE: plans are afoot to merge the three existing codebases (Dean’s, Scott Yang’s, and this one) into a single Sourceforge project. (UPDATE 12/23/2004: nothing has really come of that–we’re all a little busy and haven’t really worked to make it happen. Oh well…)


Not realizing that Mean Dean was porting Scripturizer to PHP, I went ahead and did it so that I could begin using it on this WordPress site. At about the same time Scott Yang made one, so there are two versions out there. Sorry about that.

I originally wasn’t going to package it for release, but it turns out that I had to do it to actually use it on my site :), and so I figured I might as well put it in the public version to make it easy for anyone else to use. Also, figuring out how to use add_action was nonobvious (at least when I first did this–I believe the documentation has improved considerably), so I wanted to provide a clear example.

It extends the functionality of the original and also changes the data permanently in the user’s database (as opposed to Scott’s, which filters it on the fly). You can set mine to do that (see the source code), but Scott’s will work that way out of the box. Which you prefer is up to you. Mine is more efficient, his affects all the archives without making you manually edit anything.

Usage: just copy the source code to a file named scripturize.php in your wp-content/plugins folder. Go to your administration panel, click on Plugins, and activate it. Then just refer to the Bible in your posts. If you don’t want a Bible reference hyperlinked, be sure to enclose it in preformatting tags, like so: 

<pre>John 3:16</pre>

Changes from Dean’s original:

  • You can specify a translation you want to link to by putting the standard abbreviation after the reference like so: John 3:16, NIV or 2 Cor 5:20 (NET). This one is huge, for me.
  • Added New English Translation. I like this translation for several reasons, but mostly for its philosophical underpinnings.
  • Made syntax a little more permissive. For instance, you can now specify a reference by saying Gen. 12:1 or Gen 12:1 (period/no period).
  • Made syntax a little less permissive as regards whitespace. Just write things normally and everything will work fine (I changed this to correct some errors I was seeing wherein the link would run into the blank space after the reference).
  • The regular expressions handle linking a little bit differently. It does something more useful when confronted with a crazy reference like Rom 1:3, 5–8, 10,12 that the online Bibles don’t know what to do with.
  • As I mentioned, by default it will actually change your post as stored in your database. Forever. Irreversibly. With no backup. Just be aware of that.
  • You can now specify a default translation. It is initially set to the NIV, because I assume that’s what most people will want.

Please Report Bugs In Bug Tracker
I’d really like to know if you catch any bugs. I use this plugin myself, so bugs directly affect me! 🙂

There is a bug tracker set up at http://dev.wp-plugins.org/newticket, so please report any problems there. 

30 thoughts on “Scripturizer in PHP”

  1. Glen,

    Great! Well done. Actually, I have also recently discovered NET bible and have been using it as a reference to prepare for studies. Can’t get rid of ESV because the church here uses it 🙂 

    Performing the filtering at publish/edit time is really a great idea in reducing CPU load, as I have been thinking ways to speed up layers and layers of WordPress content filter plugins. Got a 5‑year-old 400Mhz box serving my site, which would take 1+ second to generate the index page 🙁

    In Christ,

  2. Awesome. Will you post here (or comment here, then I’ll get notified by my RSS reader) when this merging/sourceforge thing happens?
    *smiles sweetly*

  3. I’ve found a “feature”: Scripturizer doesn’t work (nothing happens) if there are any literal apostrophes anywhere in the post. As a workround, you can use &apos; to include apostrophes.

  4. I’ve found a “feature” — scripturizer doesn’t work (nothing happens) if there are any literal apostrophes (ASCII 39) anywhere in the post!

  5. Can’t get it to work. Copied the code etc. uploaded the php file, activated it, all as specified.
    But when I type a reference it remains completely un-scripturized… can’t work out why. I must have done something wrong…but it’s weird…

  6. It seems that if the scripture reference is on a line by itself, it works fine, but sometimes if it is in the middle of a sentence, it doesn’t come though.

  7. Thanks for providing this resource — and I need your help. I am trying to install this plugin into my new site, but I keep getting a “call to undefined” error around line 52. Not knowing anything about PHP, I can’t figure out what the problem is. Would you have any idea? 

    Thanks,
    Pastor Hal Atkins

  8. I’ve tried to replicate the bugs people have describes but have been unable to do so. Specifically, I can’t replicate a scenario where Scripturizer fails with a single ’ nor where it fails in the midst of a sentence (and I can’t figure out what’s wrong near line 52). If anyone can point me to a URL that fails it would really help me debug this thing.

    Also, I haven’t heard from Dean or Scott in a while about merging our codebases. I assume they got busy, so I’ll contact them again…

  9. Awesome plugin. The apostrophe thing is a problem, though, and the fix above (using &apos;) doesn’t work. You have to use &#39; for all apostrophes.

  10. I installed the plugin and activated it. Then went to write and got the following error

    Parse error: parse error, unexpected T_STRING in …/wp-content/plugins/scripturizer.php on line 52

    Line 52 reads
     // we skip tags because something like John 3:16 should not be messed with

    any ideas?

    brian

  11. I’m getting a similar error to Brian in #17 above, except in line 55. Line 55 reads:

    if (preg_match($split_regex,$value)) {

    Ideas?

  12. I too get an error after activating. I get the following error:

    Parse error: parse error, unexpected T_AS in /home2/brianath/public_html/wordpress/wp-content/plugins/scripturize.php on line 53

    For me, Line 53 is:

    $anchor_regex = ‘’;

    And just in case it may be an error before that, the last few lines of code (48 to 57):
    DEFAULT_BIBLE_TRANSLATION’,‘NIV’);

    function scripturize ($text = ‘’,$bible = DEFAULT_BIBLE_TRANSLATION){
    // skip everything within a hyperlink, a 

     block, a  block, or a tag
        // we skip tags because something like John 3:16 should not be messed with
            $anchor_regex = ‘’;
        $pre_regex = ‘
    .*

    ’;
    $code_regex = ‘.*’;
    $tag_regex = ‘ (?:[^>s]*)(?:s[^>]*){0,1}>’; // $tag_regex=’ [^>]+>’;
    $split_regex = “/((?:$anchor_regex)|(?:$pre_regex)|(?:$code_regex)|(?:$tag_regex))/i”;

  13. I see the problem. The code in the text box has been run through WordPress’ output filter and the single quotation mark has been turned into a fancy apostrophe.

    The short-term solution is to do a search and replace.

    The long-term solution is for me to fix this…

  14. I think I must be doing something wrong, but when I upload the scripturize.php file to the plugins folder and then go to it thru the admin interface to activate it, the whole code is there instead of an activate link. I’ve tried this three different times from 3 different sources with the same result. All of my other plugins have just dropped right in. Any idea of what I may be doing wrong or what may be causing this?

    Peace,
    Paul

  15. Hi, I’m getting the same problem as #20 and #22. When I look at the file, the line with the problem seems to be $anchor_regex = ‘’;

    Has a solution to this been found?
    Please send me an email, since I might forget to check back! Thanks.

  16. Great script, but have you had a chance to review the apostrophe problem? It’s the only thing keeping the script from being effective.

Comments are closed.