Welcome to Geeklog, Anonymous Monday, December 09 2024 @ 11:58 pm EST
Geeklog Forums
Special BBCode system - non standard
Status: offline
TheRaftGuy
Forum User
Newbie
Registered: 05/04/03
Posts: 6
Here is a simple bbcode system for articles, static pages and blocks. The code is not perfect, so feel free to clean it up. I wouldn't mind if changes were sent directly to me (but all at once!)
These funtions go in lib-custom.php and then they get called to change tags in lib-common.php, and the index.php for staticpages and also story admin.
Do a search in the relevent files for 'introtext', 'bodytext', 'blockcontent' and 'sp_content' to find where you should call the function from.
The first function gets called after saving articles/blocks/static pages, and the second when displaying data. In the first function, [s=12345678] becomes [sl=12345678]The title of the story[/sl] - Obviously changes to the story title are not reflected in the admin bbcode, but it avoids the overhead of extra database calls when displaying the story. You can skip the first function if you don't want it.
[image=fred] is replaced with fred.gif from images folder (good for bullets etc)
The short story tag [ss=222] needs a file shortstorytext.thtml in the theme folder. (see eg below) and is great for embedding the intro into another story.function AdminBB ($text) // Called when saving story by admin code - picks up titles automatically
{
global $_CONF, $_TABLES, $_FM_TABLES;
$BB_StoryTag = "#[s=([0-9s]+)]#si";
$BB_DownloadTag = "#[d=([0-9s]+)]#si";
while (preg_match($BB_StoryTag, $text, $resultA))
{
$sid = $resultA[1];
$sresult = DB_query("SELECT title FROM {$_TABLES['stories']} WHERE sid = '$sid'"
$AL = DB_fetchArray($sresult);
$title = $AL['title'];
$text = str_replace($resultA[0],'[sl='.$sid.']'.$title.'[/sl]',$text);
}
while (preg_match($BB_DownloadTag, $text, $resultA))
{
$sid = $resultA[1];
$sresult = DB_query("SELECT title FROM {$_FM_TABLES['filemgmt_filedetail']} WHERE lid = '$sid'"
$AL = DB_fetchArray($sresult);
$title = $AL['title'];
$text = str_replace($resultA[0],'[dl='.$sid.']'.$title.'[/dl]',$text);
}
return $text;
}
function UseMacros ($ToScan, $MacroList)
{
foreach ($MacroList as $Macro)
{
$Find = strtoupper($Macro[0]);
$Find = $Macro[0];
$Repl = $Macro[1];
$ToScan = str_replace($Find,$Repl,$ToScan);
$Find = strtolower($Macro[0]);
$ToScan = str_replace($Find,$Repl,$ToScan);
}
return $ToScan;
}
function BB2HTML ($text) // Called from when displaying
{
global $_CONF, $_TABLES;
// Most tags are self explanatory. Try these
// [border][caption][image1_r]caption here[/caption][/border]
[table]column 1 text[gutter]column 2 text[/table]
$MacroList = array
(
array ("[BR]", "<BR>",
array ("", "<B>",
array ("", "</B>",
array ("", "<I>",
array ("", "</I>",
array ("", "<U>",
array ("", "</U>",
array ("[BI]", "<B><I>",
array ("[/BI]", "</I></B>",
array ("[RED]", "<font color=#FF0000>",
array ("[/RED]", "</font>",
array ("[BORDER]", "<table bgcolor=#000000 align=right width=150 cellpadding=1 cellspacing=0><TR><TD>",
array ("[/BORDER]", "</TD></TR></TABLE>",
array ("[CAPTION]", "<table bgcolor=#FFCC00 width=100% cellpadding=0 cellspacing=2><TR><TD>",
array ("[/CAPTION]", "</TD></TR></TABLE>",
array ("[BAR]", "<table bgcolor=#CCCCCC width=100% cellpadding=0 cellspacing=3><TR><TD>",
array ("[/BAR]", "</TD></TR></TABLE>",
array ("[TABLE]", "<table cellpadding=0 cellspacing=0><TR valign=top><TD width=49%>",
array ("[/TABLE]", "</TD></TR></TABLE>",
array ("[GUTTER]", "</TD><TD width=10> </TD><TD width=49%>",
array ("[LI]", "<LI>",
array ("[/LI]", "</LI>",
array ("[_]", " "
);
$text = UseMacros($text, $MacroList);
$BB_StoryLinkTag = "#[sl=([0-9s]+)](.*?)[/sl]#si";
$BB_DownloadLinkTag = "#[dl=([0-9s]+)](.*?)[/dl]#si";
$BB_PHPTag = "#[php](.*?)[/php]#si";
$BB_ImageTag = "#[i=([a-z0-9s]+)]#si";
$BB_ShortStoryTag = "#[ss=([0-9s]+)]#si";
$BB_FrameTag = "#[frame=([a-z0-9s]+)](.*?)[/frame]#si";
$BB_BlockTag = "#[block=(.*?)](.*?)[/block]#si";
// *************************************************
// TODO - Implement the STYLE option for links, as well as POPUP and CHOP
while (preg_match($BB_StoryLinkTag, $text, $resultA))
{
$sid = $resultA[1];
$title = $resultA[2];
$text = str_replace($resultA[0],'<a href="'. $_CONF['site_url'] . '/article.php?story='
.$sid.'">'.$title.'</a>',$text);
}
while (preg_match($BB_ShortStoryTag, $text, $resultA))
{
$sid = $resultA[1];
$result = DB_query("SELECT *,unix_timestamp(date) AS day FROM {$_TABLES['stories']} WHERE sid = '$sid'"
$A = DB_fetchArray($result);
$articleHTML = COM_article( $A, '', 'shortstorytext.thtml' );
$text = str_replace($resultA[0],$articleHTML,$text);
}
while (preg_match($BB_DownloadLinkTag, $text, $resultA))
{
$sid = $resultA[1];
$title = $resultA[2];
$text = str_replace($resultA[0],'<a href="'. $_CONF['site_url'] . '/filemgmt/visit.php?lid='
.$sid.'">'.$title.'</a>',$text);
}
while (preg_match($BB_ImageTag, $text, $resultA))
{
$imagename = $resultA[1];
$text = str_replace($resultA[0],'<img src="'. $_CONF['layout_url']
. '/images/'.$imagename.'.gif" align=left>',$text);
}
while (preg_match($BB_FrameTag, $text, $resultA))
{
$color = $resultA[1];
$content = $resultA[2];
$text = str_replace($resultA[0],"<table bgcolor=#000000 cellpadding=1 cellspacing=0><tr><td>"
."<table bgcolor=#".$color." cellpadding=4 cellspacing=0><tr><td>".$content
."<td></tr></table><td></tr></table>"
,$text);
}
while (preg_match($BB_BlockTag, $text, $resultA))
{
$title = $resultA[1];
$content = $resultA[2];
$text = str_replace($resultA[0],COM_startBlock($title).$content.COM_endBlock(),$text);
}
while (preg_match($BB_PHPTag, $text, $resultA))
{
$phpcode = stripslashes($resultA[1]);
$text = str_replace($resultA[0],eval($phpcode),$text);
}
return $text;
}
---
shortstorytext.thtml example:
<!-- ARTICLE START -->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="storytitle"><b><u>{story_title}</u></b></td>
</tr>
<tr>
<td><div align=justify>
{story_introtext}
{start_readmore_anchortag}[Full Story...]{end_readmore_anchortag}{edit_link}
</div></td>
</tr>
</table>
<!-- ARTICLE END -->
14
16
Quote
Anonymous
Anonymous
I am busy expanding the BBcode system, and have also added quite a
few other features to Geeklog. Right now it is very useful as a newspaper
or magazine style website, but is quite a long way from the original
Geeklog - it should probably be a new project. (we use it for an
environmental news service)
Some of the new features:
1. Selectable styles for blocks (in the admin section) & parameters field
2. More fields in the story table (issue no, story template, search
keywords, linked stories)
3. A very powerful newsletter manager and builder plugin which I
currently use to manage about 20 subscription only and free newsletters.
4. A campaign manager to organisations that would like to lobby
government/business etc
Right now I was wondering if anyone else is using the BBcode stuff, or
would like to work with on this.
The Raft Guy
11
12
Quote
All times are EST. The time is now 11:58 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content