Scripturizer in PHP

UPDATE 12/23/2004: I’ve moved my ver­sion of the code to the new WP Plu­g­ins repos­i­to­ry, so you can down­load it at http://dev.wp-plugins.org/file/scripturizer/trunk/scripturizer.php

UPDATE: plans are afoot to merge the three exist­ing code­bas­es (Dean’s, Scott Yang’s, and this one) into a sin­gle Source­forge project. (UPDATE 12/23/2004: noth­ing has real­ly come of that–we’re all a lit­tle busy and haven’t real­ly worked to make it hap­pen. Oh well…)


Not real­iz­ing that Mean Dean was port­ing Scrip­tur­iz­er to PHP, I went ahead and did it so that I could begin using it on this Word­Press site. At about the same time Scott Yang made one, so there are two ver­sions out there. Sor­ry about that.

I orig­i­nal­ly was­n’t going to pack­age it for release, but it turns out that I had to do it to actu­al­ly use it on my site :), and so I fig­ured I might as well put it in the pub­lic ver­sion to make it easy for any­one else to use. Also, fig­ur­ing out how to use add_action was nonob­vi­ous (at least when I first did this–I believe the doc­u­men­ta­tion has improved con­sid­er­ably), so I want­ed to pro­vide a clear exam­ple.

It extends the func­tion­al­i­ty of the orig­i­nal and also changes the data per­ma­nent­ly in the user’s data­base (as opposed to Scot­t’s, which fil­ters it on the fly). You can set mine to do that (see the source code), but Scot­t’s will work that way out of the box. Which you pre­fer is up to you. Mine is more effi­cient, his affects all the archives with­out mak­ing you man­u­al­ly edit any­thing.

Usage: just copy the source code to a file named scripturize.php in your wp-con­tent/­plu­g­ins fold­er. Go to your admin­is­tra­tion pan­el, click on Plu­g­ins, and acti­vate it. Then just refer to the Bible in your posts. If you don’t want a Bible ref­er­ence hyper­linked, be sure to enclose it in pre­for­mat­ting tags, like so:

<pre>John 3:16</pre>

Changes from Dean’s orig­i­nal:

  • You can spec­i­fy a trans­la­tion you want to link to by putting the stan­dard abbre­vi­a­tion after the ref­er­ence like so: John 3:16, NIV or 2 Cor 5:20 (NET). This one is huge, for me.
  • Added New Eng­lish Trans­la­tion. I like this trans­la­tion for sev­er­al rea­sons, but most­ly for its philo­soph­i­cal under­pin­nings.
  • Made syn­tax a lit­tle more per­mis­sive. For instance, you can now spec­i­fy a ref­er­ence by say­ing Gen. 12:1 or Gen 12:1 (period/no peri­od).
  • Made syn­tax a lit­tle less per­mis­sive as regards white­space. Just write things nor­mal­ly and every­thing will work fine (I changed this to cor­rect some errors I was see­ing where­in the link would run into the blank space after the ref­er­ence).
  • The reg­u­lar expres­sions han­dle link­ing a lit­tle bit dif­fer­ent­ly. It does some­thing more use­ful when con­front­ed with a crazy ref­er­ence like Rom 1:3, 5–8, 10,12 that the online Bibles don’t know what to do with.
  • As I men­tioned, by default it will actu­al­ly change your post as stored in your data­base. For­ev­er. Irre­versibly. With no back­up. Just be aware of that.
  • You can now spec­i­fy a default trans­la­tion. It is ini­tial­ly set to the NIV, because I assume that’s what most peo­ple will want.

Please Report Bugs In Bug Track­er
I’d real­ly like to know if you catch any bugs. I use this plu­g­in myself, so bugs direct­ly affect me! 🙂

There is a bug track­er set up at http://dev.wp-plugins.org/newticket, so please report any prob­lems there.

30 thoughts on “Scripturizer in PHP”

  1. Glen,

    Great! Well done. Actu­al­ly, I have also recent­ly dis­cov­ered NET bible and have been using it as a ref­er­ence to pre­pare for stud­ies. Can’t get rid of ESV because the church here uses it 🙂

    Per­form­ing the fil­ter­ing at publish/edit time is real­ly a great idea in reduc­ing CPU load, as I have been think­ing ways to speed up lay­ers and lay­ers of Word­Press con­tent fil­ter plu­g­ins. Got a 5‑year-old 400Mhz box serv­ing my site, which would take 1+ sec­ond to gen­er­ate the index page 🙁

    In Christ,

  2. Awe­some. Will you post here (or com­ment here, then I’ll get noti­fied by my RSS read­er) when this merging/sourceforge thing hap­pens?
    *smiles sweet­ly*

  3. I’ve found a “fea­ture”: Scrip­tur­iz­er does­n’t work (noth­ing hap­pens) if there are any lit­er­al apos­tro­phes any­where in the post. As a workround, you can use &apos; to include apos­tro­phes.

  4. I’ve found a “fea­ture” — scrip­tur­iz­er does­n’t work (noth­ing hap­pens) if there are any lit­er­al apos­tro­phes (ASCII 39) any­where in the post!

  5. Can’t get it to work. Copied the code etc. uploaded the php file, acti­vat­ed it, all as spec­i­fied.
    But when I type a ref­er­ence it remains com­plete­ly un-scrip­tur­ized… can’t work out why. I must have done some­thing wrong…but it’s weird…

  6. It seems that if the scrip­ture ref­er­ence is on a line by itself, it works fine, but some­times if it is in the mid­dle of a sen­tence, it does­n’t come though.

  7. Thanks for pro­vid­ing this resource — and I need your help. I am try­ing to install this plu­g­in into my new site, but I keep get­ting a “call to unde­fined” error around line 52. Not know­ing any­thing about PHP, I can’t fig­ure out what the prob­lem is. Would you have any idea?

    Thanks,
    Pas­tor Hal Atkins

  8. I’ve tried to repli­cate the bugs peo­ple have describes but have been unable to do so. Specif­i­cal­ly, I can’t repli­cate a sce­nario where Scrip­tur­iz­er fails with a sin­gle ’ nor where it fails in the midst of a sen­tence (and I can’t fig­ure out what’s wrong near line 52). If any­one can point me to a URL that fails it would real­ly help me debug this thing.

    Also, I haven’t heard from Dean or Scott in a while about merg­ing our code­bas­es. I assume they got busy, so I’ll con­tact them again…

  9. Awe­some plu­g­in. The apos­tro­phe thing is a prob­lem, though, and the fix above (using &apos;) does­n’t work. You have to use &#39; for all apos­tro­phes.

  10. I installed the plu­g­in and acti­vat­ed it. Then went to write and got the fol­low­ing error

    Parse error: parse error, unex­pect­ed T_STRING in …/wp-content/plugins/scripturizer.php on line 52

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

    any ideas?

    bri­an

  11. I’m get­ting a sim­i­lar error to Bri­an in #17 above, except in line 55. Line 55 reads:

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

    Ideas?

  12. I too get an error after acti­vat­ing. I get the fol­low­ing 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’);

    func­tion scrip­tur­ize ($text = ‘’,$bible = DEFAULT_BIBLE_TRANSLATION){
    // skip every­thing with­in a hyper­link, 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 prob­lem. The code in the text box has been run through Word­Press’ out­put fil­ter and the sin­gle quo­ta­tion mark has been turned into a fan­cy apos­tro­phe.

    The short-term solu­tion is to do a search and replace.

    The long-term solu­tion is for me to fix this…

  14. I think I must be doing some­thing wrong, but when I upload the scripturize.php file to the plu­g­ins fold­er and then go to it thru the admin inter­face to acti­vate it, the whole code is there instead of an acti­vate link. I’ve tried this three dif­fer­ent times from 3 dif­fer­ent sources with the same result. All of my oth­er plu­g­ins have just dropped right in. Any idea of what I may be doing wrong or what may be caus­ing this?

    Peace,
    Paul

  15. Hi, I’m get­ting the same prob­lem as #20 and #22. When I look at the file, the line with the prob­lem 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 apos­tro­phe prob­lem? It’s the only thing keep­ing the script from being effec­tive.

Comments are closed.