1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
<?php
// thewall.php, thewall.common.php, thewall.server.php
// demonstrate a demonstrates a xajax implementation of a graffiti wall
// using xajax version 0.2
// http://xajaxproject.org
if (!defined ('MAX_SCRIBBLES'))
{
define ('MAX_SCRIBBLES', 5);
}
if (!defined ('DATA_FILE'))
{
define ('DATA_FILE', "thewall.dta");
}
class graffiti
{
var $html;
var $isValid = false;
function graffiti($sHandle, $sWords)
{
if (trim($sHandle) == "" || trim($sWords) == "")
{
return;
}
$this->html = "\n<div style=\"font-weight: bold;text-align:".$this->getRandomAlignment();
$this->html .= ";color:".$this->getRandomColor().";\">";
$this->html .= "<span style=\"font-size:".$this->getRandomFontSize()."%;\">";
$this->html .= strip_tags(stripslashes($sWords));
$this->html .= "</span><br/><span style=\"font-size: small;\">";
$this->html .= " ~ ".strip_tags(stripslashes($sHandle))." ".date("m/d/Y H:i:s")."</span></div>";
$this->isValid = true;
}
function getRandomFontSize()
{
srand((double)microtime()*1000003);
return rand(100,300);
}
function getRandomColor()
{
$sColor = "rgb(";
srand((double)microtime()*1000003);
$sColor .= rand(0,255).",";
srand((double)microtime()*1000003);
$sColor .= rand(0,255).",";
$sColor .= rand(0,255).")";
return $sColor;
}
function getRandomAlignment()
{
$sAlign = "";
srand((double)microtime()*1000003);
$textAlign = rand(0,2);
switch($textAlign)
{
case 0: $sAlign = "left"; break;
case 1: $sAlign = "right"; break;
case 2: $sAlign = "center"; break;
}
return $sAlign;
}
function save()
{
if ($this->isValid)
{
$rFile = @fopen(DATA_FILE,"a+");
if (!$rFile) {
return "ERROR: the graffiti data file could not be written to the " . dirname(realpath(DATA_FILE)) . " folder.";
}
fwrite($rFile, $this->html);
fclose($rFile);
return null;
}
else
{
return "Please supply both a handle and some graffiti to scribble on the wall.";
}
}
}
function scribble($aFormValues)
{
$sHandle = $aFormValues['handle'];
$sWords = $aFormValues['words'];
$objResponse = new xajaxResponse();
$objGraffiti = new graffiti($sHandle,$sWords);
$sErrMsg = $objGraffiti->save();
if (!$sErrMsg)
{
$objResponse->addScript("xajax_updateWall();");
$objResponse->addClear("words","value");
}
else
$objResponse->addAlert($sErrMsg);
return $objResponse;
}
function updateWall()
{
$objResponse = new xajaxResponse();
if (file_exists(DATA_FILE)) {
$aFile = @file(DATA_FILE);
if (!$aFile) {
$objResponse->addAlert("ERROR: the graffiti data file could not be written to the " . dirname(realpath(DATA_FILE)) . " folder.");
return $objResponse;
}
$sHtmlSave = implode("\n",array_slice($aFile, -MAX_SCRIBBLES));
$sHtmlSave=str_replace("\n\n","\n",$sHtmlSave);
}
else {
$sHtmlSave = "";
$aFile = array();
}
$rFile = @fopen(DATA_FILE,"w+");
if (!$rFile) {
$objResponse->addAlert("ERROR: the graffiti data file could not be written to the " . dirname(realpath(DATA_FILE)) . " folder.");
return $objResponse;
}
fwrite($rFile, $sHtmlSave);
fclose($rFile);
$sHtml = implode("\n",array_reverse(array_slice($aFile, -MAX_SCRIBBLES)));
$objResponse->addAssign("theWall","innerHTML",$sHtml);
return $objResponse;
}
require("thewall.common.php");
$xajax->processRequests();
?>
|