What's the best way to include PHP in nodes? We're converting some sites over to a Drupal 6 multi site and we have a number of existing pages that make heavy use of PHP.

What's the easiest way to include these scripts, assuming that they may want to live in different menus in different languages, and that we want these pages to also work like other pages on our site (e.g. take advantage of Rules, Views, CCK etc).


Using hook_menu() to create a MENU_CALLBACK seems to mean we couldn't
treat them like other pages (have people edit titles/content, use
Views/Rules etc).
Using hook_nodeapi() to add the PHP only works if it is always at the end (or beginning) of any content.
Using the PHP filter to include a file works, but means editors would need the right to use PHP.


The solution I'm leaning towards is creating a custom filter that replaces a keyword/token with a file/function so editors would add {{FOO_SCRIPT}} to their page and the relevant code would get included.

Is there a better way?
Normally I do heavy php lifting on nodes in hook_preprocess_node(&amp;$vars) and parse / include content in the $vars.

hook_nodeapi() is of course another way to go about it and your additional content will be available in many different $operations, I don't use hook_nodeapi() unless I'm altering data that gets saved, deleted etc within nodes - for display layer stuff hook_preprocess_node() always treats me well.

If you could expand on what sort of preprocessing and content you are including in nodes I'm sure we could go into more details into the best suited solution :)

Update: Given the variety of the tasks you aim to use (APIs, Additional DB Calls, or User Input Parsing etc), I'd definately recommend you use hook_nodeapi so you have the fine grained control over the context. preprocess is view layer only and I feel as though you will likely want to hook the nodeapi(&amp;$node, $op = 'load') so as to make your data entries high level enough to have the information widely accessible (like $node-&gt;your_custom_api_field in a node.tpl.php)

I highly recommend that you try to stay with Drupal's conventions as much as possible. Using database functions etc. Checkout the http://drupal.org/project/data module and possibly http://drupal.org/project/schema which both help working with your own tables (and the data module even helps expose that table to views so you can stay with Drupal core more!)

p.s.

My advice is to create a custom module for each data module you have so it can have it use it's own hook_nodeapi and any other hook's that may be required :)