Herself's Webtools

Scripts, HowTos, Templates, Plugins, Widgets, Tips and Useful Information

Archive for the ‘perl’ Category

How to convert your old Perl-CGI scripts to work in your blog using PHP

without comments

The original TimesToCome site was created in 1997. The web has changed a great deal since then but my scripts hadn’t. I just hacked my blogs to use the PERL scripts. Converting them to work in your blog without using PERL or CGI is actually quite simple.

The first thing to do is convert your old CGI scripts to PHP. Your forms will remain the same except for the name of the script they are calling. ( <form method=”post” action=”new-script-url”> ) I found that User Friendly Forms in PHP, and PHP Form Handling gave me enough information to convert the forms from PERL to PHP. Most of what works in PERL, works in PHP, you’ll find very little needs to be changed. ( ‘PHP Black Book’ is the best book I’ve found so far. )

Once you have a working PHP form you need to incorporate it into your blog. To do this you need to create a page template. The easiest way is to copy an existing page template in your theme. The archives.php page usually works well.

Remove the archives information from the page. I deleted everything after <div id=”content” class=”pages”> down to the matching </div> tag for that division. Your template may be slightly different.

Now copy and paste your PHP form – everything between <body> and </body> into that space between <div id=”content” class=”pages”> and </div>.

Rename the page to something useful, and don’t forget to change the ‘Template Name: xxxx ‘ in the template.

Now log into your WordPress or other blog. Create a new page, name it something useful. Then go to the templated drop down menu (‘Templates’) and select your newly created template from the menu. Save and publish.

If you wish to use multiple pages for your form just create multiple pages. If you wish it to reload the same page when the script runs, call yourself in the action= and place a hidden check that lets you know if this page is being loaded or if the form is filled out and submitted.

Put the hidden check if form submitted in the form:

<input type=”hidden” name=”submit_check” value=”1″ />

The check for it in the part of the form you do your calculations:
if ($_POST['submit_check'] == 1 ) { /*do something*/ }

See example: Calorie calculator
Download example: Calories example php form in a WP blog

Written by timestocome

June 23rd, 2008 at 5:00 am

Posted in cgi,how to,perl,php

Perl script to build blog archives by subject

without comments

I found that lots of people were hunting around the TimesToCome Mobile Blog for posts that weren’t easily findable. You can tell this by looking in your log files. If you see some of your top views are for http://yourblog.com/label/something then people aren’t finding posts. 

Make it easier for them. Add in an archive by subject post and make it easy to find.

I haven’t figured out how to fully automate it but in the meantime, I wrote a couple of PERL scripts, one for WordPress and one for Blogger that fetch your RSS feed, pull out the links, sort them by subject and stick them in an HTML file. You can open the file in any editor and cut and paste it into a post. You’ll want to re-run it once a month or so and update your archive post.

Blogger archive building tool
WordPress archive building tool

Directions are in each file, it’s pretty painless. In WordPress you have to temporarily up your feed count. In both you just have to switch the temp url to your RSS url feed.

See also:
Installing PERL Modules

Written by timestocome

September 12th, 2007 at 5:00 am