<?php
/************************************
* Cadence
* Remotely Hosted Guestbook Script.
* (c) 2006, Dennis Pedrie
* www.CadenceBook.com
* post.php
* Last Modified 1-6-06
***********************************
* Cadence Guestbook is licensed under
* a Creative Commons License.
* More information is available by visiting
* http://creativecommons.org/licenses/by/3.0/
* or the LICENSE file in the Cadence Root Folder
***********************************/
/**
* Post Class. Manages Post-Related Functions
*
* @name post
* @package Cadence Guestbook
* @author Dennis Pedrie
* @copyright Dennis Pedrie
* @version 1.0
*/
class post {
/**
* Checks User's browser
*
* @name checkbrowser
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @return string
*
**/
function checkbrowser() {
global $LANG;
if (eregi("MSIE",$_SERVER['HTTP_USER_AGENT'])) {
return $LANG['ie'];
}
if (eregi("Mozilla/5.0",$_SERVER['HTTP_USER_AGENT'])) {
return $LANG['firefox'];
}
if (eregi("Opera",$_SERVER['HTTP_USER_AGENT'])) {
return $LANG['opera'];
}
else {
return $LANG['otherbrowser'];
}
}
/**
* Cleans variables for use in queries.<br />
* If cleaning an integer, use intval($post->clean_var($var)); to be sure that it is in the correct format.
*
* @name clean_var
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @param string Content to Clean
* @return string
*
**/
function clean_var($content,$allowhtml = false) {
if(get_magic_quotes_gpc()) {
$content = stripslashes($content);
}
$content = (!$allowhtml) ? htmlentities($content,ENT_QUOTES) : $content;
$content = str_replace("--", "-", $content);
return $content;
}
/**
* Returns Post Date in md5.<br />
* This is the Post's unique hash, and is used for security purposes.
*
* @name makehash
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @param string Date to Encode
* @return string
*
**/
function makehash($date) {
$hash = md5($date);
return $hash;
}
/**
* Check E-Mail.<br />
* Makes sure that the E-Mail address is in a valid format, i.e. hide@address.com
*
* @name check_email
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @param string Address to Check.
* @return boolean
*
**/
function check_email($address) {
// check an email address is possibly valid
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address)) {
return true;
}
else {
return false;
}
}
/**
* Kill teh swear words!
*
* @name badwords
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @param string Content to Clean Up.
* @return string
*
**/
function badwords($content) {
global $db, $q;
$badwords = $db->get_results($q->badwords());
foreach($badwords as $bw) {
$content = str_replace($bw->badword, $bw->replacement, "$content");
}
return $content;
}
/**
* Check that the user hasn't been banned
*
* @name isbanned
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @param string IP Address.
* @param string E-Mail Address
* @return boolean
*
**/
function isbanned($ip,$email) {
global $book,$db,$q;
//Check IP and E-Mail against DB for matches.
$banned = $db->get_var($q->isbanned($email,$ip));
//Check for Global Ban
$gban = $db->get_var($q->gban($email,$ip));
echo $gban;
//If they're banned, return true.
if($banned == $book || $gban == 1) {
return true;
}
//Otherwise, false.
else {
return false;
}
}
/**
* Return HTML Entities to their corresponding symbols.<br />
* i.e. < -> '<', etc.
* @name undohtmlentities
* @author Dennis Pedrie
* @version 1.0 BUILD 1000
* @param string Content to Convert.
* @return string $content
* @since 1.0
**/
function undohtmlentities($content) {
$content = html_entity_decode($content);
return $content;
}
}
?>