Jul 20, 2008

Flat-file Cms - tutorial inspired by jlhaslip

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Flat-file Cms - tutorial inspired by jlhaslip

Tsunami
Ok, for this tutorial i am only going to show you how to add updates to your site simply by storing the information into a text file, and then displaying it with predefined formatting... OK lets get down to business...

Lets start out by making a PHP file and call it mycms.php

put this code at the top of the page. What this will do is allow us to edit the selected update when it comes time and show and hide the add an update field and validate the form..
CODE

<html><head>
<script language="javascript">
function ShowHide(id1, id2) {
if (id1 != '') expMenu(id1);
if (id2 != '') expMenu(id2);
}
function expMenu(id) {
var itm = null;
if (document.getElementById) {
itm = document.getElementById(id);
} else if (document.all){
itm = document.all[id];
} else if (document.layers){
itm = document.layers[id];
}

if (!itm) {
// do nothing
}
else if (itm.style) {
if (itm.style.display == "none") { itm.style.display = ""; }
else { itm.style.display = "none"; }
}
else { itm.visibility = "show"; }
}
function ValidateForm(isMsg) {
MessageLength = document.REPLIER.Post.value.length;
errors = "";

if (isMsg == 1)
{
if (document.REPLIER.msg_title.value.length < 2)
{
errors = "You must enter a message title";
}
}

if (MessageLength < 2) {
errors = "You must enter a message to post!";
}
if (MessageMax !=0) {
if (MessageLength > MessageMax) {
errors = "The maximum allowed length is " + MessageMax + " characters. Current Characters: " + MessageLength;
}
}
if (errors != "" && Override == "") {
alert(errors);
return false;
} else {
document.REPLIER.submit.disabled = true;
return true;
}
}
function goupdates()
{
uid = updateinfo.update.value;
theurl = "mycms.php?action=edit&uid=" + uid;
location.href = theurl;
}
</script>
</head>


now... we will have a variable called "action" to tell the page exactly what to do. this will decide what to show, like if action is set to display it will display the updates or if it is set to edit then it will edit them... ect ect... right now we want to check and see if it is set to edit so that we can edit the updates.

CODE

<?
if(strtolower($_GET['action']) == "edit")
{


ok... now we have to access our updates.txt file that we will create later on. If you have read my tutorial of flatfile membership systems you might know that i like to use the file() method and i also like to use is the explode() function... so lets see the code for this

CODE


$updates = file('updates.txt');
foreach($updates as $Key=> $Val)
{
   $update[$Key] = explode("|##|", $Val);
}
?>


Pretty simple, reads the file to an array then breaks it up into smaller arrays based on the location of |##| seperators.

and now comes the fun part... making the gui... im not going to go into to much detail on explaining this because all this is is nothing more than a simple form which the information is filled out using php... so here we go:
CODE


<center>
<table align="center"><tr><td rowspan="3"> <form name="updateinfo">
<SELECT NAME=update SIZE=6 width=120 onChange="goupdates();">
<?
for($K = sizeof($updates) - 1; $K > 0 ; $K--)
{
echo "<option value='" . $K . "'>" . $update[$K][2];

}
?>

</SELECT></td><td>Title:</td><td><input type="text" name="title" width="100" value="<? if($_GET['uid']) echo $update[$_GET['uid']][2]; ?>"></td></tr><tr><td>Author:</td><td><input type="text" name="author" readonly='1' width="100" value="<? if($_GET['uid']) echo $update[$_GET['uid']][0]; ?>"></td></tr> <tr><td>Date:</td><td><input type="text" name="date" width="100" value="<? if($_GET['uid']) echo $update[$_GET['uid']][1]; ?>"></td></tr><tr><td colspan="3">Body:</td></tr><tr><td colspan="3"><textarea cols="40" rows="10" name="body" id="wysiwyg"><? if($_GET['uid']){ echo $update[$_GET['uid']][3];} ?></textarea> </form><form action="mycms.php?action=delete&uid=<? echo $_GET['uid']; ?>" method="POST"> </td></tr><tr><td colspan="3"><table width="100" align="center"><tr><td><input type="submit" value="Delete" width=100"></form></td><td><td><td><a href="java script:ShowHide('new_open','new_closed') "> <input type="button" value="Add" width="100" onClick="java script:ShowHide('topic_open','topic_closed')"> </a></td></tr></table></td></tr><tr><td colspan="3"><center><input type="button" value="Delete All" width="300"></center></td></tr></table>
<br><br>

<div id='topic_open' style='display:none;z-index:2;'>
<div border-style='dashed'>
<form action="mycms.php?action=add" method="POST" name="REPLIER" onSubmit="return ValidateForm();" >
<table width="500" border="0">
<tr><td width="100"><font color="#000"><b>Post Title:</b></font></td><td width="400">
<input type="text" size="40" maxlength="50" name="title" value="" tabindex="1" class="forminput" /></td></tr><tr><td width="100"><font color="#000000"><b>Author:</b></font></td><td width="400">
<input type="text" size="40" maxlength="50" name="user" value="" tabindex="1" class="forminput" /></td></tr><tr><td colspan="2"><center>
<textarea id="postbody" cols="80" rows="20" name="Post" tabindex="3" class="textinput"></textarea>
</center></td></tr><tr><td colspan="2">
<?
print '<input type="hidden" name="name" value="' . $name .'" readonly>';
?>
<center>
<input type="submit" name="submit" value="Post Update" tabindex="4" class="forminput"/></center>
</td>
</tr>
</table>
</form>
</div>
</div>

</center>
<?
}


And thats it for the gui... now lets go on to the Add page just paste this after that code above and here it is... im not gonna go to much into this either because its basically the same thing as with the membership tutorial only applied a lil differently...

CODE


if(strtolower($_GET['action']) == "add")
{
$title = $_POST["title"];
$content = $_POST["Post"];
$user = $_POST["user"];



$openname = fopen("updates.txt", "a");

$month = date("m");
$day = date("d");
$year = date("y");
$date = $month . '/' . $day . '/' . $year;
fwrite($openname, $user . "|##|" . $date . "|##|" . $title . "|##|" . $content . "\r\n");
fclose($openname);

?>

<html><head><title>Please stand by...</title><meta http-equiv="refresh" content="2; url=mycms.php?action=edit" />

</head>
<body>
<table width="100%" height="85%" align="center">
<tr>
<td valign="middle">
<table align="center" cellpadding="4" class="tablefill">
<tr>
<td width="100%" align="center">
Thank you... your update has been added <br>
(<a href="mycsm.php?action=edit">Or click here if you do not wish to wait</a>)
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?
}



ok... now were almost done... just a couple more things to add and then where done...
this is the delete page... just add at the bottom... still fairly simple...

CODE

if(strtolower($_GET['action']) == "delete")
{
$fileh = file('updates.txt');
$file2 = fopen('updates.txt','w');
for($K = 0; $K < sizeof($fileh); $K++)
{
if ($K != $_GET['uid'])
{
fwrite($file2,$fileh[$K]);
}
}
fclose($file2);

?>
<html><head>
<meta http-equiv='refresh' content='2; url=mycms.php?action=edit'/>
<script type="text/javascript"> </script>

</head>
<body>
<table width='100%' height='85%' align='center'>
<tr>
<td valign='middle'>
<table align='center' cellpadding="4" class="outside" border='1'>
<tr>
<td width="100%" align="center">

Please wait as we delete the update<br /><br />
(<a href='mycms.php?action=edit'>Or click here if you do not wish to wait</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?
}


ok now all we need to do is to display it... so go ahead and add this bit of code

CODE

if(!$_GET['action'])
{
$updates = file('updates.txt');
foreach($updates as $Key=> $Val)
{
$update[$Key] = explode("|##|", $Val);
}

$find1[] = "|#title#|";
$find1[] = "|#author#|";
$find1[] = "|#date#|";
$find1[] = "|#body#|";

for($k = sizeof($updates) - 1; $k>0;$k--)
{
$replace1[0] = $update[$k][2];
$replace1[1] = $update[$k][0];
$replace1[2] = $update[$k][1];
$replace1[3] = $update[$k][3];
$content1 = str_replace($find1, $replace1, $updates[0]);
echo $content1 . "<br>";
}
}
?>



then save that and now we want to make a text file called updates.txt and chmod it to 777.
now we want to open the file and make the first line equal to the coding for the display placing tags that corrispond to to the data we want to enter... use |#title#| for the title, |#author#| for the autor, and |#date#| for the date and |#body#| for the body

make sure it all is on the one line... its easy... just code it, and then take out all the new lines so that it all is squished on to the same one.. biggrin.gif and it will work

to put ur updates anywhere just use
CODE

include('mycms.php');


and bam! your done...


previews:
View Updates
Edit Updates
Full Source


 

 

 


Reply

truefusion
Hey, nice script you have here. I can see this going places. Will there be a part 2 of this, with more advanced features? I'm sure this will be very useful. Keep up the good work. wink.gif

Btw, i noticed the date isn't really used when viewing the updates: why is that?

Reply

Tsunami
of course there is going to be a part 2... with editing and delete all functions and such... also i hope to make a wysiwyg editor for editing the main body with buttons to insert different information. like the post date the post author, viewers ip address and other things that you can do with php

what u mean the data isnt really used?


Reply

truefusion
QUOTE(Tsunami @ Nov 24 2006, 01:07 AM) *
what u mean the data isnt really used?

When viewing the updates, there's no title attribute, or whatever, that shows when [such-and-such] was posted. Usually, in the case of updates, you inform the readers when [such-and-such] was posted. I know the code can be easily modifed to have this implemented, but just wondering. tongue.gif

Reply

iGuest
Already existing flat file systems
Flat-file Cms

Found this article on already exisiting flat file systems such as forums, cms, dbms etc

www.Mabaloo.Com/Web-Development/Building-a-fully-function-website-but-without-a-DATABASE.Html

-reply by Girish Singh

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : flat, file, cms, inspired, jlhaslip

  1. Debug Exe Files
    How to debug an exe file. (4)
  2. Make A Moderately-secure Password System Using Javascript
    using file redirection to hide the password. (4)
    JavaScript is very handy at making forms, allowing for much more customization and easier ways to
    send data. So making Login forms using JavaScript may seem to many to be a very feasable idea.
    However, JavaScript is very bad at protecting Passwords, as since the passwords are not encypted and
    the whole JavaScript code is in the page, a person could just view the Page Source and find out
    everything. Even if you use an external JavaScript, it would still be poor as the file name for the
    external JavaScript would still be revealed. But I have an answer! There is a rela....
  3. Install An Aef Forum Onto The Trap17
    From a zip file (11)
    Installing an AEF Forum on the Trap17 Server Preparation for Installing the AEF Forum
    The following items are required for the installation of the packaage onto your site: 1. - a copy
    of the AEF Forum zip package from http://anelectron.com/download.php 2. - a MySql Database 3. - a
    Database User 4. - a password for the Database User 5. - Privileges allowed for the Database User
    The details for ensuring that you have all of these items are as follows: 1. - a copy of the AEF
    Forum zip package from http://anelectron.com/download.php . Simply browse to t....
  4. How To Make A Simple File Based Shoutbox Using Php And Html
    (8)
    A simple tut to make a simple shoutbox. Let me jump right in. First of all you need the standard
    equipment for PHP, an IDE like XAMPP and an editor like PHP EDITOR 2OO7. Were going to make a
    simple guestbook using three files, webpage.php, shout.php and shout.txt. Webpage.php can be
    changed to whatver you want, it will be the page on which the guestbok is shown, you could even use
    this code and add it to another php page n your site. Shout.php is the proccessing page and
    shout.txt is where the shouts are stored. Firstly we need to make the visual design of the box.....
  5. *nix File Permissions - An Overview
    (6)
    I was originally going to post this in a reply, but felt it would deviate from the topic.
    Here's a brief overview of the three numbers in a permission "code": -The first number is for
    the owner of the file. If you set a file at 600, the owner will have read and write access and
    everyone else is locked out. -The second number is for the users group (users are placed into groups
    to get special rights sometimes). Generally you will not give write access to a user's group.
    -The third number is for the rest of the world, including web users. Setting any value that wi....
  6. Starting Or Stopping Apache And Mysql Server Via Batch File
    (0)
    Hi guys, this is a litte tutorial about how we start and stop the Apache and MySQL in Windows NT
    (2000, XP, 2003) via a batch file script. As we know in Windows NT based system Apache and MySQL
    installed as Windows Services. So we can stop and start it using NET command. For more information
    about DOS command, type HELP at command prompt. I assuming that your MySQL service name is "mysql"
    and your Apache (Apache 2.0.x) service name is "apache2". If you want to chek it click Start > Run >
    services.msc > OK. Windows IS NOT Case Sensitive. Let's get started!. 1. ....
  7. How To Fix Codecs And Movie File Problems
    ...a short but very useful tutorial (0)
    How to Fix Codecs and Movie File Problems For all of you who are having trouble with
    codecs, either not being able to play a movie you've downloaded or not having any
    sound/picture, this guide should help you. The Easy Quick-Fix Method For the lazy people
    amoung you who want the simplest possible solution, may I present Video LAN Player (VLC) ,
    it's a good video/audio player and comes with all the codecs you will need and has many
    features making it my player of choice. The (New) Other Method The Combined Community Codec
    Pack (C....
  8. The Many Ways To Bypas File Hosting Annoyances
    (5)
    I've done a lot of research on this subject because it is much more common for people to upload
    files using file hosting services such as megaupload and rapidshare. They continue to try to push on
    their premium accounts on to the daily users who don't really want to put up any money for
    downloading which should be free.So i've compiled a few techniques I've used to bypass the
    limits of free downloading accounts and leave you feeling just as content with yourself as if you
    had a premium account. Download Managers: Now with the prominent use of file hosts ....
  9. Unencrypted But Invisible File Storage
    It can have a password, it can be unlocked. (0)
    This method works, but unfortunately compression software can open the file without the password.
    Also, you can try creating a new user account. When it asks "Make files and folders private?" click
    Yes, make private. Name the new user account anything using NO spaces/uppercase letters, but not
    something like "privatefiles" or something like that. Try accessing the files in C:\Documents
    and Settings\ >. You cannot open the folder. Now to ensure that user is always hidden in My
    Computer, click Start > Run. 1. Type in command.com . This should bring up a blac....
  10. Using A Secure File Transfer Client
    A discussion of FTP, FTPS, SCP, and SFTP (0)
    Using a Secure File Transfer Client Almost everyone who creates a web site is faced with
    the problem of getting their files from their local computer to their web server. There are a few
    different protocols (methods) through which to accomplish this, and some have definite advantages
    over others. Here are the major ones, listed loosely in order of increasing security. Note: All
    of the programs recommended in this tutorial are for Windows only. Command line alternatives are
    accessible via the terminal for both Linux and OS X. FTP First a note on using ....
  11. How To: Make A Simple Php Site
    Making one file show up on all pages using php (21)
    I have looked all over the site and could not find anything that was like this simple, or just like
    this at all.. For some people i know that you are using a basic HTML site...and having a big menu
    if you want to add somthing you have to go into every one of the pages and add or remove or edit
    what you want to do, but with somthing verry simple all you would have to do is edit one file, and
    all of the pages that have the PHP script on them would suddenly change to what that one file is.
    So to start off if you are planning on using this little tirck, the page that you a....
  12. Transfer File Of Any Size Using Winsock Control
    Winsock Help (5)
    This tutorial shows how to transfer file of any size using winsock control. - Open VB; - Select
    standard exe; - Press Ctrl + t to show the add component window; - Select winsock control and
    microsoft common dialog; - Add one winsock control in the project; - Name it winsock1; - If you want
    to add chat then add another winsock and name it winsock2; - Insert another winsock object if you
    want to add chat also; - Add a microsoft common dialog box; - Name it cd; - We will use this
    winsock1 object to transfer the file and winsock2 for chat; ------------- The basic idea : ....
  13. Networking Tutorial: File And Printer Sharing
    A basic computer networking tutorial (0)
    Network Setup: Newbie Install Click start, then right click computer Ensure that the full
    computer name is memorable and that each machine is on the same workgroup. After you've done
    this, you are ready to configure advanced features, such as file and printer sharing. Adding a
    Printer Locally Firstly, you need to configure your printer (on the machine which is
    directly connected to the printer) for printer sharing. Click start, control panel,
    printers/scanners, then right click on your local printer and click 'properties'. Browse to
    the shari....
  14. How To: Change Your Website's Index File
    a simple trick using .htaccess (18)
    How To: Change Your Website's Index File a simple trick using the .htaccess file A simple
    tutorial which only involves editing one little file. Useful for those of us who have mime-typed
    extensions or who are creating lots of test design files and want an easy way to make the design
    they like best their default file. Create a file called .htaccess in the /public_html/ folder if
    you don't have it. I think one should be there already when you get your site so if it isn't
    you should create it anyway! In the file write the following: CODE Di....
  15. Shut Down, Restart, Log Off Xp Using A Batch File
    Undocumented feature for XP (0)
    This is a copy of a tutorial I created for astahost.com. I'm copying it here as a courtesy to
    trap17 members. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> QUOTE
    How to shutdown a XP Pro computer when you are connected using RDC (Remote Desktop Connection)
    using a batch file or RPC (Remote Procedure Command) This is useful if you can't get to the
    computer but have remote access to the computer via a network or the internet. First To show you
    what you will see at a command prompt (command.com) when you type: "shutdown /?" Wit....

    1. Looking for flat, file, cms, inspired, jlhaslip

Searching Video's for flat, file, cms, inspired, jlhaslip
advertisement



Flat-file Cms - tutorial inspired by jlhaslip



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE