Jump to content

Opinion on best way to do this.


cooldude832

Recommended Posts

I'm rewriting my CMS a bit and now I want to be able to include php support in my content sections of the page

 

The content section will be stored as a BLOB in a mysql table and I already have the retrival working

 

My question is when I retrieve the content it comes out of mysql as a big long string, when portions of it need to be evalulated using eval() to run the php that is in them.

 

I'm using a delimeter rihgt now of

 

to define the begining and end of a php block.  What do you all think is the best method of separating the 1 string of content into the sections of it like

 

HTML DATA

PHP BLOCK

HTML DATA

PHP BLOCK

 

sorta like that, but in an unpredictable number of times.

 

<?php
$content = "<h3>Hows it going?</h3>[code=php:0]echo "<br />Hello World!<br />";

";<h2>The world responds, Welcome!</h2>";

?>

[/code]

 

That is what the content looks like

Link to comment
Share on other sites

Just use the PHP opening and closing tags:

 

Hello, the time is now <?php echo date('r') ?>!

<?php
// page content is stored in $content...

ob_start();
eval('?>' . $content);
$parsed_content = ob_get_contents();
ob_end_clean();
?>

 

Syntax highlighting broke, but it should work.

Link to comment
Share on other sites

I'd thing that bog down the work if I have to write a ton of temp files and delete on load outs.

 

The eval combo is working.

 

However if I write the content to a temp file and then store that as text (each time its updated + a 1 time weekly cron caching)  I think I get a good full text search pool. 

 

You think?

Link to comment
Share on other sites

I already have backup systems in place and a tiered admin based system.  So I can prevent most people other than me from accessing certain page or certain parts such as php.

 

My main goal of it was to allow my contributing users to upload pages with BB style code so that when they want to upload their articles I don't have to do it myself. 

 

I also then took it a step further and said well i'm lazy and don't want to have to FTP to mod a page so i'll give my self access.  And my event secretary access and so forth.

 

Ideally I want to eventually roll it out as a complete CMS package but thats a way of way.

 

 

I questioned the allowing php as the first thing I had.  The backups are emailed to me, and the system can restore on a single click off a db dump.

Link to comment
Share on other sites

Why wud u need the full power of php?

Just a question, as i did write a limited gd language for users to be able to generate their own dynamic image signatures.

So ya may want to think of going the same way.

trying to limit a powerful language, may be more cumbersome than thought initially.

when developing a limiting language may be simpler

 

Link to comment
Share on other sites

than consider something where the code is stored in the db.

 

create a random filename

 

store the content into the temp file

start ob_start buffering

include the file

grab the contents

stop buffering

delete the temp file

 

 

now ya have the output contents in a string,

which ya can do whatever ya want

to prevent the user created routine from doing things inadvertently to global vars

ya may want to save/restore the global vars and put the above into a function.

 

 

 

Link to comment
Share on other sites

I've thought this through enough to realize that limiting the power of your php is just not good, joomla and all those CMS that let you baby in some php aren't what i want.  I know how php works, and the people who will have power to adjust the php in it will also have knowledge of it.  I have a dual back up system on it.

1) It backs up daily/weekly based on settings

2) It backs up 4 saves back of each file so you can roll back if you do somethign really bad.  Now mind you deleting a file will total nuke all roll back, but that is what back up 1 does

 

back up 1 is a compelte zip + mysql dump of the server that you can reload from a single file.  It will dezip that pile rebuild mysql and restory the whole server to the zip's content.

Link to comment
Share on other sites

Okay, than definely try using temp files :)

 

function docode($code)
{
  file_put_contents($tfn="tmp/". time() . ".tmp",$code)
  ob_start();
  include($tfn);
  $contents=ob_get_contents();
  ob_end_clean();
  unlink($tfn);
  return($contents);
}

 

should do the trick :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.