I've got 2 methods of storing pages. The first is simple; store it in a file. The second is to store it in the database which is I'm having issues with.
The whole "system" is based around an "engine" which outputs the page by injecting it into a HTML template. To put it simply: the code must be executed before it reaches the engine. Hopefully this will make a little more sense with some code.
page.class.php
...
// Page was found in the database
$this->name = $pageVariables['name'];
$this->requiredAuth = $pageVariables['requiredAuth'];
if ($parsed) {
ob_start();
echo $pageVariables['content'];
$this->contents = ob_get_clean();
var_dump($this->contents);
} else {
$this->contents = $pageVariables['content'];
}
...
// File exists on the system, load it
$fileContents = file_get_contents($this->url);
if ($parsed) {
ob_start();
include($this->url);
$this->contents = ob_get_clean();
var_dump($this-contents);
if (isset($pageName)) {
$this->name = $pageName;
}
if (isset($requiredAuth)) {
$this->requiredAuth = $requiredAuth;
}
if (isset($useEngine)) {
$this->useEngine = $useEngine;
}
} else {
$this->contents = $fileContents;
}
The if ($parsed) {...}
is there so the page can be fetched un-parsed for editing purposes.
Obviously that is a cut down version, but I hope that shows enough.
If I load a page with the code
Hello World<br>
<?php echo 'Hello World'; ?>
from the database the output I get is
Hello World<br>
<?php echo 'Hello World'; ?>
however, the same code stored in a file outputs
Hello World
Hello World
I have tried using eval(), but that will only evaluate PHP code, and fails when I include the HTML/PHP mixture.
Maybe there's a better way of going about this (storing it, executing etc), but this is the issue as I currently see it.