Hi Jason,
(OT: I love your site, and have followed phpclasses for a long time.)
This is how my system works: There is a "
title page" which is the addressable URL of the webpage. The title page sets up page-specific parameters, such as title, keywords, page-specific scripts, the
content file, and booleans like whether or not to show a printer-friendly link, and show source. The code that you highlighted is the code for a title page. Once the title page has set the 'environment', it defines and includes the
template file.
As execution is handed over to the template file via the 'include' function, the real work gets done. (You can see the source code of the default template file at
http://test.freephile.com/inc/_showSour ... efault.php) The template file includes the "
header file" (
http://test.freephile.com/inc/_showSour ... header.php), which is a set of core library functions for the system. It is this header file that figures out what kind of "
content file" is used (xml, or regular content) and responds by selecting either the Expat parser, or else my custom parser (which is just a series of regex).
Code: Select all
<?php
// if the content file is an xml file, $contents is created by bmLoadXML
// otherwise, $contents is created by the custom BM parser
if (bmIsXML_Story($contentFile)) $contents = bmLoadXML($contentFile);
else $contents = getContents ($contentFile);
?>
If the content file is 'true' xml, then I use the Expat xml parser in conjunction with output buffering to stuff the content into a variable named
$contents If the content file is not true xml, then I use my own function called getContents to read the content file. With both methods of parsing the contents, a single variable called
$contents is created. Then a set of regex calls are made to find the pieces of the content within
$contents.
What is in the content file: Each content file has a main story, plus related links, plus a sidebar story, plus quotes. This is all maintained in a single file, rather than using a database. Using simple xml tags, I can easily see what is what when editing the content file. Using a simple xml parser, I can put the content into buckets in my template, for layout onscreen. Changing the template allows me infinite combinations for layout of the content.
Back to the problem
See the jobs page (
http://test.freephile.com/company/jobs.php) It errors out because it says that I'm calling an undefined function. In my jobs content page, in the main story section, I include a class file to parse RSS data feeds. (
http://test.freephile.com/inc/showSourc ... /_jobs.php). Since this content file is 'true' xml starting with the
Code: Select all
<?php
<?xml version="1.0" encoding="ISO-8859-1"?>
?>
line, it ends up being parsed by the Expat parser. That parser uses a Processing Instruction handler to eval any php code. By the time the php parser hands things off to the xml parser, the getFile function has already been included in the "Title file" by way of the template which includes /inc/_buildIndex.php at the very top. Here is the getFile function in case you're curious:
Code: Select all
<?php
function getFile ($url) {
$fp = @fopen($url, 'r') // get the page contents
or die("Cannot Open $url");
while ($line = @fgets($fp, 1024)) {
$contents .= $line;
}
fclose($fp);
return $contents;
}
?>
Now one thing I just noticed is that the error message says 'getfile' while the function is get
File. I don't think that case folding has anything to do with this discrepancy, since case folding acts on the tags, not the data being parsed.
If I simply remove the first <xml> declaration line and leave all other xml tags intact, the file will be parsed by my simple 'getContents' and 'getXML' functions, and php doesn't choke on the call to 'getFile' at all.
Maybe the problem is that I'm using output buffering, but I don't think that should create a scope problem. My guess is that the XML parsing ability of PHP was not meant to work within the context created by a parent script.
Again, I am using XML in the content file for my BlueMantis system to simplify editing of the content, and also to open up possibilities for displaying the content. I need to create a data structure, and have tried to use the DOM parser, without success. When using the event-based parser, I seem to be able to do a better job parsing and keeping everything in scope by just using regex.
I know this is a complex situation, and thank anyone in advance for helping me tackle it. If you are interested by this system, it will be released under the GPL as soon as possible. You can join me on the project at sourceforge. The name of the project is BlueMantis. BlueMantis is supposed to be a system for quickly generating websites that are easy to maintain, and the system allows advanced 3rd party Open Source projects to be easily plugged into the solution.