<?php
/***************************
* PonPublish *
* Written By: Pongles *
* Website: pongles.com *
* Licence: GPL *
****************************/
// main defines
define( "PONPUBLISH_VERSION", "0.1" );
// error defines
define( "ERROR_NOMODULES", 1 );
define( "ERROR_MISSINGDATA", 2 );
// purpose: converts BBCode to HTML
// returns: text
function BBCodeToHTML( $strText )
{
$strText = str_replace( "[sub]", "<sub>", $strText );
$strText = str_replace( "[/sub]", "</sub>", $strText );
$strText = str_replace( "[sup]", "<sup>", $strText );
$strText = str_replace( "[/sup]", "</sup>", $strText );
$strText = str_replace( "[s]", "<s>",$strText );
$strText = str_replace( "[/s]", "</s>",$strText );
$strText = str_replace( "[b]", "<b>",$strText );
$strText = str_replace( "[/b]", "</b>",$strText );
$strText = str_replace( "[i]", "<i>",$strText );
$strText = str_replace( "[/i]", "</i>",$strText );
$strText = str_replace( "[u]", "<u>",$strText );
$strText = str_replace( "[/u]", "</u>",$strText );
$strText = str_replace( "[*]", "<li>",$strText );
$strText = str_replace( "[list]", "<ul>",$strText );
$strText = str_replace( "[/list]", "</ul>",$strText );
$strText = str_replace( "[code]", "<table border=\"0\" align=\"center\" width=\"95%\" cellpadding=\"3\" cellspacing=\"1\"><tr><td id=\"smallcode\">CODE</td></tr><tr><td id=\"code\"><br>", $strText );
$strText = str_replace( "[/code]", "</td></tr></table>", $strText );
$strText = str_replace( "[center]", "<center>", $strText );
$strText = str_replace( "[/center]", "</center>", $strText );
$strText = eregi_replace( "\\[img]([^\\[]*)\\[/img\\]","<img src=\"\\1\">", $strText );
$strText = eregi_replace( "\\[rimg]([^\\[]*)\\[/rimg\\]","<img src=\"\\1\" align=\"right\" hspace=\"10\">", $strText );
$strText = eregi_replace( "\\[cimg]([^\\[]*)\\[/cimg\\]","<center><img src=\"\\1\" hspace=\"10\"></center>", $strText );
$strText = eregi_replace( "\\[limg]([^\\[]*)\\[/limg\\]","<img src=\"\\1\" align=\"left\" hspace=\"10\">", $strText );
$strText = eregi_replace( "\\[email\\]([^\\[]*)\\[/email\\]", "<a href=\"mailto:\\1\">\\1</a>", $strText );
$strText = eregi_replace( "\\[email=([^\\[]*)\\]([^\\[]*)\\[/email\\]", "<a href=\"mailto:\\1\">\\2</a>", $strText );
$strText = eregi_replace( "\\[url\\]www.([^\\[]*)\\[/url\\]", "<a href=\"http://www.\\1\" target=\"_blank\">\\1</a>", $strText );
$strText = eregi_replace( "\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\1</a>", $strText );
$strText = eregi_replace( "\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>", $strText );
return $strText;
}
// purpose: find substring
// returns: bool
function FindSubString( &$strResult, $strHaystack, $strPrefix, $strSuffix )
{
$iPrefixLength = strlen( $strPrefix );
$iPos = strpos( $strHaystack, $strPrefix );
if( $iPos == 0 )
return false;
$iPos += $iPrefixLength;
$iEndPos = strpos( $strHaystack, $strSuffix, $iPos );
$strResult = substr( $strHaystack, $iPos, $iEndPos - $iPos );
return true;
}
// purpose: useful string encoding function
// returns: string
function EncodeString( $strString )
{
return urlencode( stripslashes( $strString ) );
}
// purpose: abstract base class for modules for easy access
class CPublishBase
{
// purpose: parse the BB code into the generic PonPublish BBCode into what the module needs
// returns: bool
function ParseBBCode( $strText ) { }
// purpose: publish a module
// returns: bool
function Publish( $strSubject, $iDate, $strBody ) { }
}
// purpose: adds a module to the submit list
// returns: none
function CreateModule( $strName, $Module )
{
global $g_rgModules;
$g_rgModules[] = array( "name" => $strName, "module" => $Module );
}
// purpose: main access to the publisher
class CPonPubisher
{
// purpose: get the version number
// returns: int
function GetVersion( )
{
return PONPUBLISH_VERSION;
}
// purpose: returns "powered by" string
// returns: string
function GetPowered( )
{
return "Powered By PonPublish " . $this->GetVersion();
}
// purpose: load a module
// returns: bool
function LoadModule( $strName )
{
$strPath = dirname( __FILE__ ) . "/modules/" . $strName . ".php";
if( !file_exists( $strPath ) )
return false;
require( $strPath );
return true;
}
// purpose: set the subject of the post
// returns: none
function SetSubject( $strSubject )
{
$this->m_strSubject = $strSubject;
}
// purpose: set the date of the post
// returns: none
function SetDate( $iDate )
{
$this->m_iDate = $iDate;
}
// purpose: set the body of the post
// returns: none
function SetBody( $strBody )
{
$this->m_strBody = $strBody;
}
// purpose: publish the blog
// returns: int (anything but 0 is an error)
function Publish( &$rgOutput )
{
global $g_rgModules;
if( empty( $g_rgModules ) )
return ERROR_NOMODULES;
if( empty( $this->m_strSubject ) || empty( $this->m_strBody ) )
return ERROR_MISSINGDATA;
if( $this->m_iDate == 0 )
$this->m_iDate = time();
foreach( $g_rgModules as $rgModule )
{
$Return = $rgModule[ "module" ]->Publish( $this->m_strSubject, $this->m_iDate, $this->m_strBody );
$rgOutput[] = array( "name" => $rgModule[ "name" ], "return" => ( $Return === true ), "output" => $Return );
}
return 0;
}
var $m_strSubject;
var $m_strBody;
var $m_iDate;
}
?>