PHP Code in Generated pages (General)
Hi, this has not been explained in previous requests. In Version 2.0.beta.1, I want to embed PHP code in CMS pages. Example...
<h1>My Page</h1>
<p>Here is a paragraph</p>
<p>Here is a paragraph with some PHP...
<?php echo 'PHP Stuff Here'; ?>
</p>
I can add this code in the page editor, but the PHP is stripped out when the page is displayed; instead, empty space is rendered by Firefox (confirmed via 'View Page Source' a blank line tag shows instead. Is this a config in phpsqlitecms or is it a PHP config issue?
Note that adding PHP code as above will display if added to Templates, but not in CMS pages, so I suspect the issue is somewhere in phpsqlitecms.
Please clarify.
PHP Code in Generated pages
Many CMS developers discourage PHP embedded within the HTML coming out of the editor. It's dangerous and the developers know that if something goes wrong, people will complain to them about allowing PHP in HTML. So they avoid it.
Unless your site is a hacking site and not a production site, it is far more secure to put PHP code in template where it belongs.
However, I've done a couple of hacking sites with embedded PHP. The *relatively* easy way to do is just to allow the editor to mangle the PHP code and then take the "tidy" code, that is,
<pre>
<? echo 'hello world'; ?>
</pre>
and apply the transforms,
<pre>
content = content.replace(/<\?/gi, "<?");
content = content.replace(/\?>/gi, "?>");
</pre>
restoring the PHP tag to
<pre>
<?php echo 'hello world'; ?>
</pre>
The fixup code above is Javascript, but the same thing can be done with PHP.
There are numerous threads on using the code cleanup module at the TinyMCE forum.
http://tinymce.moxiecode.com/punbb/viewtopic.php?id=3460
You will still have problems with escapes like,
<pre>
<?php echo 'I\'m saying hello world' ?>
</pre>
The whole issue of embedded PHP is a big pain and probably not worth the time and effort. phpSqliteCMS has good support for templates so it is probably quicker and easier to create a new template.
- Bill B
P.S. about PHP Code in Generated pages
I just noticed that the built in editor is not mangling PHP tags. So, apparently the "tidy" function is being executed before the HTML content of the page is evaluated. In other words, you would have to explicitly deactivate the safeguards the developers put into the system to get the PHP tags to execute.
Doesn't sound like a good idea to me.
Bill B