/home/a/aquarion/sites/www.aquarionics.com/epistula/chapters/sysadmin.inc.php
All my code (That is, anything not in the "Others" list on the right) is BSD licenced.
You can also view this page as text/plain or colour-coded source
<?PHP
/*******************************************************************************
Chapter - Sysadmin
********************************************************************************
Add, Edit and Admin site.
$Id: sysadmin.inc.php,v 1.3 2004/08/17 19:59:35 aquarion Exp $
$log$
*******************************************************************************/
header("Expires: 0");
/* Sysadmin.inc. Display the articles section of Epistula
26/11/2002 - aq - First version.
(Various changes, not logged, must get CVS at some point)
11/01/2004 - aq - Fixing Category problem (not removing things from categories)
12/13/2004 - aq - Fixing Preview
13/12/2005 - aq - Auth of comments, mass delete of QVs
*/
if (! $user = validate_user($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], "sysadmin")){ // Validate User is a hidden function until the user system is written :-)
// Bad or no username/password.
// Send HTTP 401 error to make the
// browser prompt the user.
header("WWW-Authenticate: " .
"Basic realm=Protected Page: " .
"Enter your username and password " .
"for access.");
header("HTTP/1.0 401 Unauthorized");
// Display message if user cancels dialog
$page->content .= "<h2>Authorization Failed</h2>"
."<p>Without a valid username and password,"
."access to this page cannot be granted."
."please click ‘reload’ and enter a"
."username and password when prompted."
."</p>";
#die();
} else {
if($_POST['saveloc']){
setcookie ("location", $_POST['location'],time()+3600000);
}
#I'm a bad person. I should really have done this with the platform-
#independant code, but the site's been down two weeks now, and I can't
#be bothered. I'll fix it later. Aquarion, 2002-12-09
/*
$items = array(
array(
type = "inputbox",
name = "title",
size = "20",
maxsize = "255",
description = "Entry title"
),
array(
type = "inputbox",
name = "author",
size = "20",
maxsize = "255",
description = "Entry Author",
value = 0
),
array(
type = "textarea",
name = "content",
width = "40",
maxsize = "30",
description = "Entry Content"
),
array(
type = "submit",
name = "submit"
value = "Send Entry"
),
)
$form = array (
name => "newjournal",
method = "POST",
items = $items
);
*/
include("include/prackback.inc");
/**
void function (void)
Short description.
*/
function showForm($action, $item){
$buttons .= "<input type=\"submit\" value=\"Spellcheck\" name=\"submit\">"
. "<input type=\"submit\" value=\"Preview\" name=\"submit\">"
. "<input type=\"submit\" value=\"Post\" name=\"submit\">";
$out = "<form method=post action=\"$action\">\n"
."<label for=\"type\">Type</label> ";
if ($item->id != 0) {
$type = get_class($item);
$out .= "<input type=\"hidden\" name=\"type\" value=\"".$type."\">".$type."<br>\n";
$out .= "<label for=\"id\">ID</label> <input type=\"hidden\" name=\"id\" value=\"".$item->id."\">".$item->id."<br>\n";
$out .= "<label for=\"edit\">Edited</label> <span name=\"edit\">".date("Y-m-d\TH:i:00O")."<br>\n";
} else {
$out .= "<select name=\"type\">"
."<option value=\"journal\">Journal Entry</option>"
."<option value=\"article\">Article</option>"
."<option value=\"writing\">Writing</option>"
."</select><br>\n";
}
$out .= "<label for=\"title\">Title</label> <input type=\"text\" name=\"title\" value=\"".$item->title."\"><br>\n"
. "<label for=\"location\">Location</label> <select name=\"location\" id=\"location\">";
$q = "select * from location order by country, name";
$r = safequery($q);
while ($row = mysql_fetch_assoc($r)){
$out .= "<option value=\"".$row['latlong']."\"";
if ($row['latlong'] == $item->location){
$out .= " selected";
}
$out .= ">".$row['country']." - ".$row['name']."</option>\n";
}
$out .= "</select>"
."<INPUT TYPE=\"checkbox\" NAME=\"saveloc\"> Save"
."<br>"
."<label for=\"author\">Author</label> <input type=\"text\" name=\"author\" value=\"".$item->author."\">(Aquarion)<br>\n"
."<label for=\"format\">Format</label> \n"
."<select name=\"format\">\n";
$formats = array( "textile" => "Textile", "html" => "HTML", "text" => "Plain Text");
foreach ($formats as $format => $label){
if ($item->format == $format){
$out .= "\t<option value=\"".$format."\" selected>";
} else {
$out .= "\t<option value=\"".$format."\">";
}
$out .= $label."</option>\n";
};
$out .= "</select>\n"
."<label for=\"description\">Description</label><br><textarea name=\"description\" rows=\"5\" cols=\"72\">".$item->description."</textarea>\n"
."<label for=\"content\">Content</label><br><textarea name=\"content\" rows=\"40\" cols=\"72\">".htmlentities($item->content)."</textarea>\n"
.$buttons
."<h3>Categories</h3>\n";
/**
void function (void)
Short description.
*/
function recurseCats($cats,$level)
{
foreach($cats as $cat){
if ($cat['parent'] == $level) {
if ($cat['newstatus'] == true) {
$checked = " checked";
} else {
$checked = "";
}
$out .= "<input type=\"checkbox\" name=\"cat_".$cat['id']."\"".$checked.">".$cat['name']." - ".$cat['description'] . "<br>";
$below = recurseCats($cats,$cat['id']);
if ($below != "") {
$out .= "<div class=\"indented\">".$below."</div>";
}
}
}
return $out;
} // end func
$out .= recurseCats($item->cats,0);
/*$out .= "<H3>Attachment</H3>\n";
$out .= "<label for=\"attachthis\">Attach File?</label><input type=\"checkbox\" name=\"attachthis\"><br>\n";
$out .= "File: <input type=file name=\"attachfile\"><br>\n";
$out .= "Description: <input type=\"text\" name=\"description\">\n";*/
$out .= "<h3>Trackbacks</h3>\n";
$out .= "<textarea name=\"trackbacks\" rows=\"4\" cols=\"60\">".$_POST['trackbacks']."</textarea>\n";
/*$out .= "<H3>Filters & Tests</H3>\n";
if ($item->filters['htmlize'] == true) {
$checked = " checked";
} else {
$checked = "";
}
$out .= "<label for=\"htmlize\">Convert to HTML?</label><input type=\"checkbox\" name=\"htmlize\"".$checked."><br>\n";
if ($item->filters['tagify'] == true) {
$checked = " checked";
} else {
$checked = "";
}
$out .= "<label for=\"tagify\">Convert Acronyms?</label><input type=\"checkbox\" name=\"tagify\"".$checked."><br>\n";*/
$out .= "<H3>Actions</H3>\n";
if ($item->actions['pingThings'] == true) {
$checked = " checked";
} else {
$checked = "";
}
$out .= "<label for=\"pingThings\">Ping Services?</label><input type=\"checkbox\" name=\"pingThings\"".$checked."><br>\n";
if ($item->actions['pingBack'] == true) {
$checked = " checked";
} else {
$checked = "";
}
$out .= "<label for=\"pingBack\">Scan for Pingback?</label><input type=\"checkbox\" name=\"pingBack\"".$checked."><br>\n";
$out .= $buttons
."</form>\n";
return $out;
} // end func
function postAttachment($item, $file, $description){
global $_EP;
$item = explode("-",$item);
if (file_exists($_EP['webdir']."/".$_EP['attachdir']."/".$item[0])){
if (is_dir($_EP['webdir']."/".$_EP['attachdir']."/".$item[0])){
if (is_writable($_EP['webdir']."/".$_EP['attachdir']."/".$item[0])){
$out .= "*and* I can write to it. Yayness.<br>";
} else {
panic("Couldn't write to attachment directory!",$_EP['webdir']."/".$_EP['attachdir']."/".$item[0]);
}
} else {
panic("Attachment directory isn't a directory!!",$_EP['webdir']."/".$_EP['attachdir']."/".$item[0]);
}
} elseif (!mkdir($_EP['webdir']."/".$_EP['attachdir']."/".$item[0], 0775)){
panic("Couldn't create attachment directory!", $_EP['webdir']."/".$_EP['attachdir']."/".$item[0]);
}
$extension = substr($file['name'], strrpos($file['name'],".")+1);
$filename = $_EP['attachdir']."/".$item[0]."/".$item[1].".".$extension;
$alphabet = range("A", "z");
array_splice($alphabet, 26, 6); // lose special charecters
$index = 0;
while (file_exists($_EP['webdir']."/".$filename)){
$filename = $_EP['attachdir']."/".$item[0]."/".$item[1].$alphabet[$index].".".$extension;
$index++;
}
move_uploaded_file($file['tmp_name'], $_EP['webdir']."/".$filename);
/*mysql> describe attachment;
+-----------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+----------------+
| id | bigint(20) | | PRI | NULL | auto_increment |
| page_id | bigint(20) | YES | | NULL | |
| page_type | tinytext | YES | | NULL | |
| file | tinytext | YES | | NULL | |
| mimetype | tinytext | YES | | NULL | |
+-----------+------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)*/
$q = "insert into attachment (page_id, page_type, file, mimetype, description, size)"
." values (".$item[1].", \"".$item[0]."\", \"".$filename."\","
." \"".$file['type']."\", \"".$description."\", ".$file['size'].")";
safequery($q);
deleteCache($item[1],$item[0]);
return $out;
}
#array_shift($wanted);
$file = implode("/",$wanted);
$page->bgcolor = "#400000";
$page->fgcolor = "#FFFFFF";
//menu
$options = array(
array (
'link' => "/sysadmin/",
'name' => "Front Page"
),
array (
'link' => "/sysadmin/new",
'name' => "New Journal Entry, Article or Writing"
), array (
'link' => "/sysadmin/attach",
'name' => "Attach Files"
),
array (
'link' => "/sysadmin/crossreference",
'name' => "Link Stuff",
'title' => "Ph34r 7h3 !n7er7`//ingu|ari7y"
),
array (
'link' => "/sysadmin/trackback",
'name' => "Send a Trackback"
),
array (
'link' => "/sysadmin/newcategory",
'name' => "New Category"
),
array (
'link' => "/sysadmin/newlink",
'name' => "New Link"
),
array (
'link' => "/sysadmin/gallery",
'name' => "New Gallery"
),
array (
'link' => "/sysadmin/locations",
'name' => "Admin Locations"
),
array (
'link' => "/sysadmin/clearcache",
'name' => "Clear Cache"
)
);
$admin = array(
array (
'link' => "/sysadmin/admin_comment",
'name' => "Comments"
),
array (
'link' => "/sysadmin/admin_unauthed",
'name' => "Untrusted Comments"
),
array (
'link' => "/sysadmin/admin_qv",
'name' => "X-Refs"
),
);
$page->localnav .= $page->menu($options)."<hr>".$page->menu($admin);
$type = array("article");
$display = "full";
$limit = 10;
switch ($wanted[1]){
case "gallery":
/*CREATE TABLE gallery (
id int(10) unsigned NOT NULL auto_increment,
title tinytext NOT NULL,
directory tinytext,
description tinytext,
date_created datetime NOT NULL default '0000-00-00 00:00:00',
date_edited timestamp(14) NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;*/
$q = "select * from category";
$r = safequery($q);
while ($row = mysql_fetch_assoc($r)){
$cat = "cat_".$row['id'];
if (isset($_POST[$cat])){
$row['newstatus'] = true;
}
$allcats[] = $row;
}
$showForm = true;
if (isset($_POST['submit'])){
if ($_POST['dirlist'] == "usetext"){
$directory = $_POST['directory'];
} else {
$directory = $_POST['dirlist'];
}
$q = "select id from gallery where title = \"".$_POST['title']."\" or directory = \"".$directory."\"";
$r = safequery($q);
$q_auth = "select id from user where id = ".$_POST['author'];
$r_auth = safequery($q_auth);
if ($_POST['date'] != ""){
$date = strtotime($_POST['date']);
if ($date != -1){
$date = "UNIX_TIMESTAMP($date)";
} else {
$date = false;
}
} else {
$date = "NOW()";
}
if (!$date){
$out .= "<h2>Couldn't create Gallery, Couldn't understand the date. Try yyyy-mm-ddthhmm :)</h2>";
} elseif ($directory == ""){
$out .= "<h2>Couldn't create Gallery, Directory is required</h2>";
} elseif ($_POST['title'] == ""){
$out .= "<h2>Couldn't create Gallery, Title is required</h2>";
} elseif (mysql_num_rows($r) != 0){
$row = mysql_fetch_assoc($r);
$out .= "<h2>Couldn't create Gallery, Gallery <a href=\"".getPermalink("gallery",$row['id'])."\">".$row['id']."</a> is too similer</h2>";
} elseif (mysql_num_rows($r_auth) == 0){
$out .= "<h2>Couldn't create Gallery, You don't exist :)</h2>";
} else {
$auth = mysql_fetch_array($r_auth);
$q = "select * from category";
$r = safequery($q);
$cats = 0;
$setcats = array();
while ($row = mysql_fetch_assoc($r)){
if (isset($_POST['cat_'.$row['id']])){
$setcats[] = $row['id'];
$cats++;
}
}
if ($cats == 0){
$out .= "<h2>Couldn't create Gallery, You didn't select any categories</h2>";
} else {
$q = "insert into gallery (title,directory,description,date_created,author) values (\"".$_POST['title']."\", \"".$directory."\", \"".$_POST['description']."\", $date, ".$auth[0].")";
#$out = $q;
safequery($q);
$id = mysql_insert_id();
deleteCache($id,"gallery");
$link = getPermalink("gallery",$id);
foreach ($setcats as $thiscat){
safequery("insert into cat_links (page_id, page_type, cat_id) values ($id, 'gallery', ".$thiscat.")");
$showForm = false;
}
$out .= "<h2>created Gallery <a href=\"".$link."\">".$_POST['title']."</a></h2>";
}
}
}
if ($showForm){
function recurseCats($cats,$level)
{
foreach($cats as $cat){
if ($cat['parent'] == $level) {
if ($cat['newstatus'] == true) {
$checked = " checked";
} else {
$checked = "";
}
$out .= "<input type=\"checkbox\" name=\"cat_".$cat['id']."\"".$checked.">".$cat['name']." - ".$cat['description'] . "<br>";
$below = recurseCats($cats,$cat['id']);
if ($below != "") {
$out .= "<div class=\"indented\">".$below."</div>";
}
}
}
return $out;
} // end func
$out .= "<form method=post action=\"/sysadmin/gallery\">"
. "<label for=\"title\">Title</label><input type=\"text\" name=\"title\" id=\"title\" value=\"".$_POST['title']."\"><br>\n"
. "<label for=\"date\">Date</label><input type=\"text\" name=\"date\" id=\"date\" value=\"".$_POST['date']."\"><br>\n"
. "<label for=\"author\">Author</label><input type=\"hidden\" name=\"author\" id=\"author\" value=\"".$user['id']."\">".$user['nickname']."<br>\n"
. "<label for=\"dirlist\">Directory</label>".$_EP['galleryRoot']
. "/<select name=\"dirlist\" id=\"dirlist\">"
. " <option value=\"usetext\">--- Use Textbox Below --- </option>";
$res = safequery("select directory from gallery");
while ($row = mysql_fetch_array($res)){
$galleries[] = $row[0];
}
$readdir = opendir($_EP['webdir']."/".$_EP['galleryRoot']) or die('Could not open '.$_EP['galleryRoot']);
while($file = readdir($readdir)){
if(is_dir($_EP['galleryRoot']."/".$file) && ($file != "." && $file != "..") ){
if (!array_search ($file, $galleries)){
$out .= "<option> ".$file."</option>\n";
}
}
}
$out .= "</select><br>\n"
. "<label for=\"directory\">Directory</label>".$_EP['galleryRoot']."/<input type=\"text\" name=\"directory\" id=\"directory\"><br>\n"
. "<label for=\"description\">Description</label><input type=\"text\" name=\"description\" id=\"description\"><br>\n"
. "<input type=\"submit\" name=\"submit\"><br>"
.recurseCats($allcats,0)
. "<input type=\"submit\" name=\"submit\"><br>"
. "</form>";
}
$page->content = $out;
break;
case "clearitemcache":
$page->content = trawl($cache);
break;
case "clearcache":
if ($_POST['item']){
$item = explode("-",$_POST['item']);
$return = deleteCache($item[1],$item[0]);
$out .= "<ul>\n";
foreach ($return as $line){
$out .= "\t<li>$line</li>\n";
}
$out .= "</ul>\n";
} else {
$readdir = opendir($_EP['cachedir']) or die('Could not open '.$dir);
while($file = readdir($readdir)){
if ($file == "." || $file == ".."){
} elseif ($file[0] != "_") {
$out .= $file." (Not Cache)<br>\n";
} elseif (rmfile($_EP['cachedir']."/".$file)) {
$out .= $file." (Y)<br>";
} else {
$out .= $file." (N)<br>";
}
}
}
$page->content = $out;
break;
case "postentry":
$page->title = "Postit";
if ($_POST['type'] != ""){
$type = $_POST['type'];
} else {
panic("Fatality","Type is required","");
}
$error = array();
#$page->content .= print_r_to_var($_POST);
if ($_POST['id'] ) {
$post = new $type($_POST['id']);
} else {
$post = new $type;
}
#if ($cats == 0){
# panic("Fatality","You didn't select any categories!","");
#}
#$post = new $_POST['type']();
if ($_POST['title'] != ""){
$post->title = $_POST['title'];
} else {
$error[] = "Didn't specify a Title";
}
$post->format = $_POST['format'];
$post->author = $user['id'];
if ($_POST['content'] != ""){
$post->content = stripslashes($_POST['content']);
} else {
$error[] = "Content is empty";
}
$post->location = stripslashes($_POST['location']);
$post->description = stripslashes($_POST['description']);
$q = "select * from category";
$r = safequery($q);
$cats = 0;
while ($row = mysql_fetch_assoc($r)){
if (isset($_POST['cat_'.$row['id']])){
$post->cats[$row['id']]['newstatus'] = true;
#$page->content .= $row['name']."<br>";
#$cata[] = $row['id'];
$cats++;
} else{
$post->cats[$row['id']]['newstatus'] = false;
}
}
if ($cats == 0){
$error[] = "No categories selected.";
}
/* Actions */
if ($_POST['pingThings']){
$post->actions['pingThings'] = true;
} else {
$post->actions['pingThings'] = false;
}
if ($_POST['pingBack']){
$post->actions['pingBack'] = true;
} else {
$post->actions['pingBack'] = false;
}
/* Filters */
if ($_POST['htmlize']){
$post->filters['htmlize'] = true;
} else {
$post->filters['htmlize'] = false;
}
if ($_POST['tagify']){
$post->filters['tagify'] = true;
} else {
$post->filters['tagify'] = false;
}
switch ($_POST['submit']) {
case "Post":
if (count($error) == 0) {
$post->save();
$page->content .= $page->buildlist($post->debug);
$trackbacks = explode("\n", $_POST['trackbacks']);
foreach ($trackbacks as $tb){
if ($tb != ""){
$log .= trackBack($tb, $type, $id);
}
}
} else {
$page->content .= $page->buildlist($error);
$page->content .= showForm("/sysadmin/postentry");
}
break;
case 'Preview':
$page->content .= $page->item(process(stripslashes($_POST['content']),$post->format));
#break;
case 'Spellcheck':
$checker = new Spellchecker;
$text = strip_tags(process(stripslashes($_POST['content']),$post->format));
$num_errors = $checker->check($text);
if ($num_errors > 0) {
$out .= "<h3>Spell Check</h3>";
$out .= "<p>Items <span class=\"spellCorrect\">like this</span> could be errors, hover over for suggestions. Items <span class=\"spellNoSuggest\">like this</span> arn't in the dictionary, and the spell checker has no idea.</p>";
$errors = $checker->getErrors();
$oldtext = $text;
foreach ($errors as $word => $suggestions) {
$title = trim(implode(', ', $suggestions));
if ($title == ""){
$span = '<|-|'.$title.'|-|>'.$word.'</-|>';
} else {
$span = '<||| |||>'.$word.' ('.$title.')</||>';
}
# $text = str_replace($word, $span, $text);
$text = preg_replace("/(\W|^)$word(\W|\$)/i", "$1$span$2", $text);
}
//if ($title == ""){
$text = str_replace('<|-|', '<span class="spellNoSuggest"', $text);
$text = str_replace('|-|>', '>', $text);
$text = str_replace('</-|>', '</span>', $text);
//} else {*/
$text = str_replace('<|||', '<span class="spellCorrect" title="', $text);
$text = str_replace('|||>', '">', $text);
$text = str_replace('</||>', '</span>', $text);
//}
$page->content .= process($page->comment_box($text),"textile");
}
$post->doFilters($page->content);
#$page->content .= $page->show();
$page->content .= showForm("/sysadmin/postentry", $post);
break;
#}
}
/*$fp = fopen ($_EP['cachedir']."/postlog", "a");
if ($fp){
fwrite ($fp, $log);
$page->content .= $page->ulink("viewlog","View Log of this entry");
} else {
$page->content .= "Couldn't write log";
}*/
if ($post->id){
$page->content = "<h1>ID <a href=\"".getPermalink($type, $post->id)."\">".$post->id."</a></h1>".$page->content;
}
break;
case "new":
$page->title = "New Thing";
$post = new journal;
$page->content .= showForm("/sysadmin/postentry", $post);
break;
case "edit":
$item = explode("-",$_REQUEST['item']);
$post = new $item[0]($item[1]);
$page->title = "Edit ".$post->title;
$page->content .= showForm("/sysadmin/postentry", $post);
break;
case "trackback":
$out .= "<form method=post action=\"sendtrackback\">\n";
#global $types;
$out .= "<label for=\"item\">Trackback from what?</label>";
$out .= "<select name=\"item\">\n";
foreach ($types as $type){
$q = "select id, title from $type order by date_created desc limit 10";
$res = safequery($q);
$out .= "\t<optgroup label=\"".ucwords($type)."\">\n";
while ($row = mysql_fetch_assoc($res)){
$out .= "\t\t<option value=\"".$type."-".$row['id']."\">"
."(".substr(ucwords($type),0,1).") ".$row['title']." - ".$row['id']."</option>\n";
}
$out .= "\t</optgroup>\n";
}
$out .= "</select><br>\n";
$out .= "<label for=\"trackback\">To which tB URL?</label>";
$out .= "<input type=\"text\" name=\"trackback\">";
$out .= "<input type=\"submit\">\n";
$out .= "</form>\n";
$page->content .= $out;
break;
case "sendtrackback":
$item = explode("-",$_POST['item']);
$page->content .= trackBack($_POST['trackback'], $item[0], $item[1]);
break;
case "delete":
$item = explode("-",$_REQUEST['item']);
$post = new $item[0]($item[1]);
$page->title = "Delete ".$post->title;
if (isset($_POST['reallymeanit'])){
$post->remove();
$page->forwardto("/sysadmin/");
} else {
$page->content .= "Do you really, Really want to do this? Delete ".$item[0]." entry ".$item[1]."?\n"
."<form method=post action=\"/sysadmin/delete\">\n"
."<input type=\"hidden\" name=\"item\" value=\"".$_REQUEST['item']."\">"
."<input type=\"submit\" name=\"reallymeanit\">\n"
."</form>";
}
break;
case "viewlog":
ob_start();
readfile($_EP['cachedir']."/postlog");
$b = ob_get_contents();
ob_end_clean();
$page->content .= "<pre>".$b."</pre>";
break;
case "crossreference":
$out .= "<form method=post action=\"crossreference\">\n";
/*+----------------+------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | | PRI | NULL | auto_increment |
| title | tinytext | | | | |
| date_created | datetime | | | 0000-00-00 00:00:00 | |
| date_edited | timestamp(14) | YES | | NULL | |
| attachfromtype | tinytext | YES | | NULL | |
| attachfromid | int(10) unsigned | | | 0 | |
| attachtotype | tinytext | YES | | NULL | |
| attachtoid | int(10) unsigned | | | 0 | |
| type | tinyint(4) | | | 0 | |
+----------------+------------------+------+-----+---------------------+----------------+*/
if (isset($_POST['submit'])) {
$type = 0;
$toIsURL = false;
if ($_POST['to'] == "textbox") {
if (preg_match("/^http:\/\//i",$_POST['to_text'])){
$post_to = $_POST['to_text'];
$type = 3;
$toIsURL = true;
} else {
$post_to = $_POST['to_text'];
}
} else {
$post_to = $_POST['to'];
}
if ($_POST['from'] == "textbox") {
$post_from = $_POST['from_text'];
} else {
$post_from = $_POST['from'];
}
if ($post_from == "" || $post_to == "") {
$page->content .= $page->item("All fields required.");
} elseif ($post_from == $post_to) {
$page->content .=