<?php // class_chalkboard.php
error_reporting(E_ALL);
Class Chalkboard
{
public function __construct()
{
// DEFINE OUR LOCAL VARIABLES
$this->file = 'chalkboard.txt';
$this->pass = 'Murray';
$this->size = 380;
// LOAD THE CHALKBOARD TEXT
$this->chalkboard_text = @file_get_contents($this->file);
$this->chalkboard_text = nl2br($this->chalkboard_text);
// CREATE THE STYLE SHEET
$this->chalkboard_css = <<<CHALKCSS
<style type="text/css">
#chalkboard {
border:0px;
margin:0px;
padding:0px;
width:350px;
height:450px;
padding:50px;
overflow:hidden;
background-image:url("chalkboard_background.png");
background-repeat:no-repeat;
font-family:"Comic Sans MS", cursive, sans-serif;
font-size:1.1em;
color:white;
}
#chalkboard p {
border:0px;
margin:0px;
padding:0px;
width:250px;
}
</style>
CHALKCSS;
// CREATE THE DIV FOR THE CHALKBOARD
$this->chalkboard_div = <<<CHALKDIV
<div id="chalkboard">
<p>$this->chalkboard_text</p>
</div>
CHALKDIV;
} // END CONSTRUCTOR
public function render()
{
echo $this->chalkboard_css;
echo $this->chalkboard_div;
} // END RENDER
public function update()
{
// IF THE DATA IS POSTED
if (!empty($_POST))
{
if ($_POST["chalkboard_pass"] == $this->pass)
{
$this->chalkboard_text = trim(stripslashes($_POST["chalkboard_text"]));
$this->chalkboard_text = strip_tags($this->chalkboard_text, '<b><i><br>');
$this->chalkboard_text = substr($this->chalkboard_text, 0, $this->size);
file_put_contents($this->file, $this->chalkboard_text);
}
else
{
die("{$_POST["chalkboard_pass"]} IS NOT THE RIGHT PASSWORD");
}
}
// CREATE THE FORM TO RECEIVE THE CHALKBOARD CONTENTS
$this->chalkboard_form = <<<CHALKFORM
<form method="post">
<textarea name="chalkboard_text" id="chalkboard">$this->chalkboard_text</textarea>
<br/>
Password: <input type="password" name="chalkboard_pass" />
<br/>
<input type="submit" value="Update the Chalkboard" />
</form>
CHALKFORM;
// ECHO THE STYLESHEET AND FORM INTO THE BROWSER STREAM
echo $this->chalkboard_css;
echo $this->chalkboard_form;
} // END UPDATE
} // END CLASS ChalkBoard
<?php // chalkboard_render.php
error_reporting(E_ALL);
require_once('class_chalkboard.php');
$c = new Chalkboard;
$c->render();
<?php // chalkboard_update.php
error_reporting(E_ALL);
require_once('class_chalkboard.php');
$c = new Chalkboard;
$c->update();
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)