PDA

View Full Version : CMS Questions - Just Brainstorming.



alexjewell
06-30-2007, 11:49 PM
Pretty soon, I'm going to need a CMS (Content Management System) for a client and since it's the first one I'll ever be making, I want to clear some things up.

My plan is to use an XML document, as the following:



<about1>
About content here, paragraph 1...
</about1>
<about 2>
About content here, paragraph 2...
</about2>

<services1>
Services content here, p1...
</services1>
<services2>
Services, p2
</services2>


Except I plan on doing this with several other 'pages', content, links, etc.

Then, for the CMS, using explode:



if(file_exists('content.xml')){
$edit = @include('content.xml');
$about = explode('<about2>',$edit);
$about1 = $about[0]; // About, Paragraph 1
$about = explode('<services1>',$about[1]);
$about2 = $about[0]; // About, Paragraph 2
$services = explode('<services2>',$about[1]);
$services1 = $services[0]; // Services, Paragraph 1
$services2 = $services[1]; // Services, Paragraph 2
// And on...

$about1 = explode('About',$about1);
$about1 = explode('</about1>',$about1[1]);
$about1 = $about1[0]; // About, Paragraph 1
// And on...

echo '<textarea>'.$about1.'</textarea>';
}


I left a lot out of the code, but I have you the general idea of what I want to do. Is there some easier way to do this? Then, I'm wondering how I would actually replace the information once the client submits their changes?

alexjewell
07-01-2007, 12:00 AM
Alright, I've talked to Twey and I have found out of easier ways to do this, but am unsure about where to start. I'm thinking of using:

http://us2.php.net/manual/en/function.xml-parse-into-struct.php

Any ideas?
Then, in reference to my second question, how to then write the edited info back into the XML document?

djr33
07-01-2007, 12:13 AM
Not sure on that function, but seems like a reasonable approach. I'd just play with it, using examples from the page.
As for writing, just use fopen, fwrite, fclose loops, creating the same structure as before in the xml.

However, a database might be a better approach if you need to rapidly access chunks.

alexjewell
07-01-2007, 08:31 PM
I've changed directions. I'm thinking about doing one PHP file, inc.php, that would look like the following:



$about = <<<ABOUT101291
about content...
ABOUT101291;

$services = <<<SERVICES101291
services content...
SERVICES101291;

// And have a variable for each page


But, my question is...when I write the edited content back to inc.php from the form, how do I just rewrite one variable without having to rewrite the whole page?! Is this possible, or do I have to go with a different file for each page?

I'm going to be using a WYSIWYG editor, too.

Twey
07-01-2007, 09:02 PM
This is a really poor idea. Writing all the data to a single flat file is inefficient, and greatly increases the possibility that one update will overwrite another.

thetestingsite
07-01-2007, 09:05 PM
I would think that either using flat files for every variable, or using a single MySQL database would be the best idea; but that's just my opinion.

alexjewell
07-01-2007, 10:24 PM
Alright, I think I've solved the problem with the help of djr33. Thanks.

alexjewell
07-02-2007, 01:00 AM
The code is finally working, and I thought I'd post it here for anyone interested:

index.php:


<?php

include('inc.php');
include('layout.php');

?>

<textarea name="about" readonly><?=$about?></textarea><br />
<a href="edit.php?edit_file=about">Edit</a>

<br /><br />

<textarea name="services" readonly><?=$services?></textarea><br />
<a href="edit.php?edit_file=services">Edit</a>

<br /><br />

<textarea name="links" readonly><?=$links?></textarea><br />
<a href="edit.php?edit_file=links">Edit</a>


inc.php:


<?php

$about = <<<ABOUT101291
about content
ABOUT101291;

$services = <<<SERVICES101291
services content
SERVICES101291;

$links = <<<LINKS101291
links content
LINKS101291;

?>


edit.php:


<?php

include('inc.php');
include('layout.php');

$array = array('about','services','links');

if(@$_GET['edit_file']){
$edit_file = $_GET['edit_file'];

if(in_array($edit_file,$array)){ ?>

<form method="post" action="confirm.php?edit_file=<?=$edit_file?>">
<textarea name="<?=$edit_file?>"><?=$$edit_file?></textarea><br />
<input type="hidden" name="auth" value="yes" />
<input type="submit" value="Submit" />
</form>

<?php }

else { echo '<p>The file chosen to edit does not exist.</p>';}

}

else { echo '<p>There is no file to edit.</p>';}

?>


write.php:


<?php

include('inc.php');

echo '<html>
<head>
<title>CMS Example</title>'."\n\n";

$php_file = @file_get_contents('inc.php');
$success = 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=yes';
$fail = 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=no';
$fail2 = 'http://www.flamehtmlstudios.com/clients/cms/result.php?result=no2';

if(@$_GET['edit_file']){
$edit_file = $_GET['edit_file'];

if(@$_POST[$edit_file]){
$page = $_POST[$edit_file];
$pageu = strtoupper($edit_file);
$newcontent = '$'.$edit_file.' = <<<'.$pageu.'101291'."\n".$page."\n".$pageu.'101291;';

list($a,$b) = explode('$'.$edit_file,$php_file,2);
list($b,$c) = explode($pageu."101291;",$b,2);
$php_final = $a."\n\n".$newcontent."\n\n".$c;


$file = 'inc.php';
$file = @fopen($file,'w+');
@fwrite($file,$php_final);
@fclose($file);

echo '<meta http-equiv="refresh" content="0;url='.$success.'">';}

else {?> <meta http-equiv="refresh" content="0;url=<?=$fail?>"> <?php }
}

else { ?> <meta http-equiv="refresh" content="0;url=<?=$fail2?>"> <?php }

echo "\n\n".'</head>
<body>
</body>
</html>';

?>


confirm.php:


<?php

include('inc.php');
include('layout.php');

if(@$_GET['edit_file']){
$edit_file = $_GET['edit_file'];

if($_POST['auth'] == 'yes'){
$page = $_POST[$edit_file]; ?>

<form method="post" action="write.php?edit_file=<?=$edit_file?>">
<textarea name="<?=$edit_file?>" readonly><?=$page?></textarea><br />
<input type="button" value="Edit" />
<input type="submit" value="Submit" />
</form>

<?php }

else { echo'<p>Please go <a href="edit.php?edit_file='.$edit_file.'">back</a> and fill in the textbox.</p>';}

}

else { echo'<p>There is no file to edit.</p>';}

?>


result.php:


<?php

include('layout.php');

$error = '<p>There has been an error in trying to edit the page.</p>';

if($_GET['result']){
$result = $_GET['result'];

if($result == 'yes'){
echo '<p>The page has been edited successfully.</p>';}

else if ($result == 'no' || $result == 'no2'){
echo $error;}

else{echo $error;} }

else{echo $error;}

?>


then layout.php just includes some styling.

Twey
07-02-2007, 07:06 AM
It's still a really bad way to do things. You'd've been far better off with the database or even the XML files.

djr33
07-02-2007, 07:15 AM
Why would xml be better than php? PHP is secure, requires formatting, and xml requires formatting and isn't secure. I don't really see how that helps, since both are text.
A database would be better, if possible (alex said it isn't), but I don't really see the downside to php in this case.

Twey
07-02-2007, 07:26 AM
PHP is secure, requires formatting, and xml requires formatting and isn't secure.The PHP method done above is far more limited, and treats each element as just a big block of HTML, which would make it a nightmare when it comes to a point where one wants to split things up more -- say, subheadings. PHP is no more secure than XML: with read permissions and filesystem access, anyone can read either; without, no-one can. The only way XML could be less secure is if permissions are set up incorrectly. Another disadvantage of using a flat file (of any kind) is the increased scope and likelihood of data overwrite. Say person A edits the "about" page. While she's editing it, person B starts editing the "services" page, then hits the button to save. If that save occurs after person A's edit page has read in the article data, but before she's saved it, all of person A's data will be overwritten -- even though they were working on completely different articles. The more users there are, the higher the chance of this scenario happening becomes.
<input type="button" value="Edit" />Why are you using XHTML?

alexjewell
07-02-2007, 01:05 PM
Yeah, but the client's server does not support any databases...maybe Access, but I'm NOT doing Access. Ha.

There's only 2 possible people who would be using this and I'll tell them not to use it at the same time, to prevent the data overwrite.

I'm also not planning on making this overly complicated. I'm going to have a simple HTML reference, as well as a simple WYSIWYG I found.

And I'm sorry Twey, it's a habit of mine. I automatically do a space slash on self-closing tags. :)