I am currently developing somthing like a CMS, but without using any database. A really big problem for me is how can you change (and later format content via tinymce (or similar) ) and then save it into a php file?
My configuration file for each page looks like this:
<?php
$title = 'Title of the page';
$contenttitle = <<<HTML
Something like a short summary, displayed at the top
HTML;
$content = <<<HTML
main content
HTML;
$foldername = basename(__FILE__, '.php');
include '../template/standard/layout/index.php'; ?>
Now, I want to be able to open a script in the browser where I can select the file I want to edit and see text boxes with content of $title, $contenttitle and $content. So, in fact we open a file, look for these 3 variables, display their content and change them (overwrite the file).
How can this be solved?
This is just an example approach that may help you:
Write a php/html file which will print out a form for you:
<form method="post"> <input type="text" name="title" value=""/>
<input type="text" name="contenttitle" value=""/>
<textarea name="content">">
<input type="submit" value="save"/> </form>
Handle your form in the php file:
if (!empty($_POST)) {
$result = array( 'title' => htmlspecialchars($_POST['title']), 'contenttitle' => htmlspecialchars($_POST['contenttitle']), 'content' => htmlspecialchars($_POST['content']) );
// save it to a file by serialiing $filename = uniqid().'.text'; // you may play around with file names, rewrite this line so it will suit your convention - you may use counter of the files
file_put_content($filename, serialize($result));
}
To retrieve file and print it use something like this:
$file = $_GET['name']; $file = str_replace(array('/', '.', '\'), '', $file); // for security reasons
$content = file_get_contents($file.'.text'); // note this is an example extension
$data = unserialize($content);
echo '<h1>'.$data['title'].'</h1>';
echo '<h2>'.$data['contenttitle'].'</h2>';
echo '<p>'.$data['content'].'</p>';