Navigation:  "The Jet Engine" PHP Application Framework > Programming Concepts > Jet Engine Objects > iTemplate System: Overview >

Custom Plugins

Previous pageReturn to chapter overviewNext page

A Custom Plugin is one that's called from within a page template, like this:

 

       <!-- PLUGIN:CUSTOM:bamboozle -->

 

When iTemplate encounters this while parsing a page template, it looks for a file called "bamboozle.inc" in the $data_dir/custom/ directory.  If it finds that file, it "includes" it into the application, and then attempts to run a function bearing the same name, in this case "bamboozle".

 

So, in order to write a custom plugin, called "bamboozle", you must create a file called "bamboozle.inc", with a function called "bamboozle" in it (that returns some sort of output), and place it in the $data_dir/custom/ directory.

 

Custom plugins can contain more than one function (you might need some helper functions), and do not necessarily have to output anything (although they usually do).   Here's a couple of example custom plugins, that make use of some of the programming concepts that were covered in the earlier parts of the documentation.

 

Here are a few useful examples.:

 

<!-- PLUGIN:CUSTOM:newsfeed -->

This plugin will connect to a news service, and get some topical headlines in HTML format from them to display on screen.

 

File: data/custom/newsfeed.inc

 

function newsfeed() {

  global $CGI;

 

  // Which headlines to get.  If the user has run a search in Hyperseek, use

  // the "Terms" that they typed in to get the headlines, otherwise, default

  // to the generic Top Stories feed.

 

  $terms = 'Top Stories';

  if ( ! empty($CGI['Terms']) ) { $terms = $CGI['Terms']; }

 

  $terms = urlencode($terms);  // Make it url friendly.

 

  $newsurl = "http://www.somenewsfeed.com/feedme.php?feed=$terms&format=html";

 

  $feed = implode("", file($newsurl));

 

  return $feed;

 

}

 

 

<!-- PLUGIN:CUSTOM:dynacron -->

This plugin will be run on every page view.  It doesn't output anything at all, but does some cleanup work on the server.

This might be the only way that you can run an automated task on your server, as some hosting companies don't allow

their users to run real "cron jobs"

 

File: data/custom/dynacron.inc

 

function dynacron() {

 

  $hour = date("h");

  $minute = date("i");

 

  // At 1am, 4am, or 8am Do something

  if ( $hour == 1 && $minute == 0 ) { do_cron_job_1(); }

  elseif ( $hour == 4 && $minute == 0 ) { do_cron_job_2(); }

  elseif ( $hour == 8 && $minute == 0 ) { do_cron_job_3(); }

 

  // Write to a log file, so you don't repeat the same task when

  // another user comes to this page a second later.... and then

  // just return control to the browser, with no output.

 

  write_file("$data_dir/cron.log", "Finished Cron Job $x\n");

 

  return;

 

}

 

function cron_job_1() {

 

  // Do something important ....

 

  return;

}

 

function cron_job_2() {

 

  // Do something important ....

 

  return;

}

 

function cron_job_3() {

 

  // Do something important ....

 

  return;

}


This help file was created with an unregistered evaluation copy of Help & Manual. © EC Software. All rights reserved. This message will not appear if you compile this help file with the registered version of Help & Manual.