.
*/
/**
* bbcode_format()
*
* Modified public domain code from www.phpit.net
*
* @param mixed $str
* @return
*/
function bbcode_format ($str)
{
$str = htmlentities($str);
$str = strip_tags($str);
$str = wordwrap($str,100,"\n",true);
$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[hr\]/is',
'/\[pi\](.*?)\[\/pi\]/is',
'/\[center\](.*?)\[\/center\]/is',
'/\[title\](.*?)\[\/title\]/is',
'/\[article\](.*?)\[\/article\]/is',
'/\[section\](.*?)\[\/section\]/is',
'/\[code\](.*?)\[\/code\]/is',
'/\[quote\](.*?)\[\/quote\]/is',
'/\[quote\=(.*?)\](.*?)\[\/quote\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[align\=(.*?)\](.*?)\[\/align\]/is',
'/\[size\=(.*?)\](.*?)\[\/size\]/is',
'/\[img\=(.*?)\](.*?)\[\/img\]/is'
);
$simple_replace = array(
'$1',
'$1',
'$1',
'
',
'$1
',
'$1',
'$1
',
'$1
',
'$1
',
'$1
',
'$1
',
'$1 wrote:
$2
',
'$2',
'$2',
'$2',
'
'
);
$order = array("\r\n", "\n", "\r");
$replace = "\n
";
$str = preg_replace ($simple_search, $simple_replace, $str);
$str = str_ireplace($order,$replace,$str);
return $str;
}
//BBcode 2 HTML was written by WAY2WEB.net
function BBCode($Text)
{
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// Convert new line chars to html
tags
$Text = nl2br($Text);
// Set up the parameters for a URL search string
$URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";
// Perform URL Search
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '$1', $Text);
$Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '$2', $Text);
//$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '$2', $Text);
// Perform MAIL Search
$Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '$1', $Text);
$Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '$2', $Text);
// Check for bold text
$Text = preg_replace("(\[b\](.+?)\[\/b])is",'$1',$Text);
// Check for Italics text
$Text = preg_replace("(\[i\](.+?)\[\/i\])is",'$1',$Text);
// Check for Underline text
$Text = preg_replace("(\[u\](.+?)\[\/u\])is",'$1',$Text);
// Check for strike-through text
$Text = preg_replace("(\[s\](.+?)\[\/s\])is",'$1',$Text);
// Check for over-line text
$Text = preg_replace("(\[o\](.+?)\[\/o\])is",'$1',$Text);
// Check for colored text
$Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","$2",$Text);
// Check for sized text
$Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","$2",$Text);
// Check for list text
$Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '' ,$Text);
$Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '' ,$Text);
$Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '' ,$Text);
$Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '' ,$Text);
$Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '' ,$Text);
$Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '' ,$Text);
$Text = str_replace("[*]", "", $Text);
// Check for font change text
$Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","$2",$Text);
// Declare the format for [code] layout
$CodeLayout = '';
// Check for [code] text
$Text = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $Text);
// Declare the format for [php] layout
$phpLayout = '';
// Check for [php] text
$Text = preg_replace("/\[php\](.+?)\[\/php\]/is",$phpLayout, $Text);
// Declare the format for [quote] layout
$QuoteLayout = '';
// Check for [quote] text
$Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $Text);
// Images
// [img]pathtoimage[/img]
$Text = preg_replace("/\[img\](.+?)\[\/img\]/", '
', $Text);
//[img=align]image source[/img]
$Text = preg_replace("(\[img align\=(.+?)\](.+?)\[\/img\])is","
",$Text);
// [img=widthxheight]image source[/img]
$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '
', $Text);
// Alignment
// [align=type]text[/align]
$Text = preg_replace("(\[align=(.+?)\](.+?)\[\/align\])is","$2
",$Text);
return $Text;
}
function articleHeading($text){
// Set the content-type
header('Content-type: image/png');
//$text = $_GET['text'];
$im = imagecreatefrompng('images/news_header.png'); // open image
imagealphablending($im, true); // setting alpha blending on
imagesavealpha($im, true); // save alphablending setting (important)
// Create some colors
$black = imagecolorallocate($im, 0, 0, 0);
// Replace path by your own font path
//$font = 'TrajanPro-Regular.otf';
//$font = 'TrajanPro-Bold.otf';
$font = 'BrushScriptStd.otf';
//$font = 'TRATS__.TTF';
//$text = strtoupper($text);
// Add the text
imagettftext($im, 18, 0, 0, 17, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
}
function LinkList($array)
{
if(!is_array($array))
{
ReportError("List was not an array");
return;
}
echo "";
foreach($array as $text => $link)
{
echo "- $text
";
}
echo "
";
}
/**
* LinkModule()
*
* Helper function to link to Bayonet modules.
*
* @param mixed $module_name
* @param mixed $link_name
* @return
*/
function LinkModule($module_name,$args = NULL,$link_name)
{
return "{$link_name}";
}
/**
* LinkPage()
*
* Helper function to link to Bayonet pages.
*
* @param mixed $page_id
* @param mixed $page_name
* @return
*/
function LinkPage($page_id,$page_name)
{
return "{$page_name}";
}
/**
* LinkInternal()
*
* Helper function to link to a relative Bayonet path.
*
* @param mixed $name
* @param string $rel_path
* @param string $file
* @return
*/
function LinkInternal($name,$file,$rel_path = "./")
{
return "{$name}";
}
if(!defined("CALLED_FROM_ADMIN"))
{
/**
* OpenTable()
*
* Begins a Bayonet site table.
*
* @return
*/
function OpenTable($width = "100%")
{
//width="100%" is important. Otherwise all of our tables will be text width.
echo "\n";
}
/**
* CloseTable()
*
* Closes a Bayonet site table.
*
* @return
*/
function CloseTable()
{
echo "
";
}
}
function OpenBlock($title = 'New Block')
{
OpenTable();
echo "{$title}
";
echo "";
}
function CloseBlock()
{
echo "
";
CloseTable();
}
/**
* ReportError()
*
* This function should be called in the event that an error has occured.
*
* @param mixed $message - automatically logged
* @return
*/
function ReportError($message)
{
//WriteLog($message,BAYONET_LOG_ERROR);
OpenTable();
echo "Error Message |
---|
{$message} |
";
CloseTable();
}
/**
* ReportHack()
*
* This function should be called in the event that we are confirming
* a hacking attempt.
*
* @param mixed $message - automatically logged
* @return void
*/
function ReportHack($message)
{
//WriteLog($message,BAYONET_LOG_HACK);
OpenTable();
echo "Hack Attempt |
---|
{$message} |
";
CloseTable();
}
/**
* array_dump()
*
* Useful against $_POST and $_GET variables, for dumping data to
* a log file, or to stdout. The return value is a single string,
* with each array key => value pair delimited by a character.
* The default character is a pipe -> '|'. It is assumed that if
* wanted to have a newline character inserted, just replace $spacer
* with '\n'.
*
* @param mixed $array
* @param string $spacer
* @return
*/
function array_dump($array, $spacer = '|')
{
$retval = NULL;
foreach($array as $challenge => $answer)
{
$retval .= " $challenge => $answer " . $spacer;
}
return $retval;
}
/**
* WriteLog()
*
* This function can be accessed directly, however, anything that is
* passed to ReportError() or ReportHack(), or decho() will be logged in their
* appropriate log file.
*
* Change made: added checks to see if the log files exist before opening
*
* @param mixed $message
* @param mixed $flag
* @return
*/
define('BAYONET_LOG_HACK','bayonet_log_hack');
define('BAYONET_LOG_ERROR','bayonet_log_error');
define('BAYONET_LOG_WARN','bayonet_log_warn');
define('BAYONET_LOG_INFO','bayonet_log_info');
function WriteLog($message,$flag)
{
global $config;
$enabled = $config['logs']['enabled'];
if(!$enabled)
{
return false;
}
$dir = $config['logs']['dir'];
date_default_timezone_set($config['logs']['timezone']);
$varstr = array_dump($_GET);
$type = NULL;
$ip = $_SERVER['REMOTE_ADDR'];
$hostname = gethostbyaddr($ip);
$executed = $_SERVER['PHP_SELF'];
$timestamp = date('Y-M-d H:i:s T');
$message = str_replace("\n",'',$message);
$message = str_replace("
",'',$message);
switch($flag)
{
case BAYONET_LOG_HACK:
if(!file_exists($dir.'hacks.log')){
break;
}
$fp = fopen($dir.'hacks.log','a');
$type = 'HACK';
$full_message = "TIMESTAMP: {$timestamp}\n\t\tIP: {$ip}\n\t\tHOSTNAME: {$hostname}\n\t\tACTION: {$type} of {$executed}\n\t\tDEFERRAL: {$message}\n\t\tVAR: ({$varstr})\n\n";
break;
case BAYONET_LOG_ERROR:
if(!file_exists($dir.'error.log')){
break;
}
$fp = fopen($dir.'error.log','a');
$type = 'ERROR';
$full_message = "({$timestamp}) - {$type} - {$message} - ({$varstr})\n";
break;
case BAYONET_LOG_WARN:
if(!file_exists($dir.'warn.log')){
break;
}
$fp = fopen($dir.'warn.log','a');
$type = 'WARN';
$full_message = "({$timestamp}) - {$type} - {$message} - ({$varstr})\n";
break;
case BAYONET_LOG_INFO:
if(!file_exists($dir.'info.log')){
break;
}
$fp = fopen($dir.'info.log','a');
$type = 'INFO';
$full_message = "({$timestamp}) - {$type} - {$message}\n";
break;
default:
echo 'To log something, you need to define a log to write to.
';
return;
}
if(file_exists($fp)){
fwrite($fp,$full_message);
fclose($fp);
}else{
//echo "could not write to file because file does not exist.
";
}
}
/**
* UnderConstruction()
*
* Displays a site-wide message across the page header.
*
* @param mixed $message
* @param mixed $flag Acceptable flags are BAYONET_SITE, and BAYONET_SECTION
* @return
*/
define('BAYONET_SITE','bayonet_site');
define('BAYONET_SECTION','bayonet_section');
function UnderConstruction($message = NULL, $flag = BAYONET_SITE)
{
$timestamp = date("Y-M-d h:m:s");
OpenTable();
switch($flag)
{
case BAYONET_SITE:
echo "Site is currently under construction : $timestamp |
";
break;
case BAYONET_SECTION:
echo "Section currently under construction : $timestamp |
";
}
if(!is_null($message))
{
echo "$message |
";
}
CloseTable();
echo "
";
}
/**
* GetBlocks()
*
* Includes all directories listed in blocks/ and uses the bayonet_blocks
* MySQL table to determine the order of the blocks displayed.
*
* @return
*/
define('BLOCK_LEFT',false);
define('BLOCK_RIGHT',false);
function GetBlocks($position = BLOCK_LEFT)
{
global $config;
/**
* I had to reconnect to the database for some fucking reason at this point.
* I have no idea why, but I was recieving errors telling me that $db was no longer
* an object. This is/was bullshit.
*/
$db = new Bayonet_SQL();
$db->Connect(
$config['sql']['hostname'],
$config['sql']['username'],
$config['sql']['password']
);
$db->Select_db($config['sql']['database']);
$result = $db->Query("SELECT * FROM `bayonet_blocks` ORDER BY weight, position");
$blocks = $db->Fetch($result);
foreach($blocks as $block)
{
if($block['position'] == $position && $block['active'] == true)
{
$load = 'blocks/'.$block['dir_name'].'/index.php';
if(file_exists($load))
{
OpenBlock($block['title']);
include $load;
CloseBlock();
}
else
{
ReportError("Failed to load block, '{$block['dir_name']}'. Check block config.");
}
if($config['blocks']['spacer']) echo "
";
}
}
}
/**
* PageRedirect()
*
* performs an http redirect
*
* @param $delay
* @param $link
*/
function PageRedirect($delay, $link)
{
echo "";
}
?>