Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 07:00 am EDT

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'"Wink; $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'"Wink; $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>"Wink, array ("", "<B>"Wink, array ("", "</B>"Wink, array ("", "<I>"Wink, array ("", "</I>"Wink, array ("", "<U>"Wink, array ("", "</U>"Wink, array ("[BI]", "<B><I>"Wink, array ("[/BI]", "</I></B>"Wink, array ("[RED]", "<font color=#FF0000>"Wink, array ("[/RED]", "</font>"Wink, array ("[BORDER]", "<table bgcolor=#000000 align=right width=150 cellpadding=1 cellspacing=0><TR><TD>"Wink, array ("[/BORDER]", "</TD></TR></TABLE>"Wink, array ("[CAPTION]", "<table bgcolor=#FFCC00 width=100% cellpadding=0 cellspacing=2><TR><TD>"Wink, array ("[/CAPTION]", "</TD></TR></TABLE>"Wink, array ("[BAR]", "<table bgcolor=#CCCCCC width=100% cellpadding=0 cellspacing=3><TR><TD>"Wink, array ("[/BAR]", "</TD></TR></TABLE>"Wink, array ("[TABLE]", "<table cellpadding=0 cellspacing=0><TR valign=top><TD width=49%>"Wink, array ("[/TABLE]", "</TD></TR></TABLE>"Wink, array ("[GUTTER]", "</TD><TD width=10>&nbsp;</TD><TD width=49%>"Wink, array ("[LI]", "<LI>"Wink, array ("[/LI]", "</LI>"Wink, array ("[_]", "&nbsp;"Wink ); &#36;text = UseMacros(&#36;text, &#36;MacroList); &#36;BB_StoryLinkTag = "#[sl=([0-9s]+)](.*?)[/sl]#si"; &#36;BB_DownloadLinkTag = "#[dl=([0-9s]+)](.*?)[/dl]#si"; &#36;BB_PHPTag = "#[php](.*?)[/php]#si"; &#36;BB_ImageTag = "#[i=([a-z0-9s]+)]#si"; &#36;BB_ShortStoryTag = "#[ss=([0-9s]+)]#si"; &#36;BB_FrameTag = "#[frame=([a-z0-9s]+)](.*?)[/frame]#si"; &#36;BB_BlockTag = "#[block=(.*?)](.*?)[/block]#si"; // ************************************************* // TODO - Implement the STYLE option for links, as well as POPUP and CHOP while (preg_match(&#36;BB_StoryLinkTag, &#36;text, &#36;resultA)) &#123; &#36;sid = &#36;resultA[1]; &#36;title = &#36;resultA[2]; &#36;text = str_replace(&#36;resultA[0],'<a href="'. &#36;_CONF['site_url'] . '/article.php?story=' .&#36;sid.'">'.&#36;title.'</a>',&#36;text); &#125; while (preg_match(&#36;BB_ShortStoryTag, &#36;text, &#36;resultA)) &#123; &#36;sid = &#36;resultA[1]; &#36;result = DB_query("SELECT *,unix_timestamp(date) AS day FROM &#123;&#36;_TABLES['stories']&#125; WHERE sid = '&#36;sid'"Wink; &#36;A = DB_fetchArray(&#36;result); &#36;articleHTML = COM_article( &#36;A, '', 'shortstorytext.thtml' ); &#36;text = str_replace(&#36;resultA[0],&#36;articleHTML,&#36;text); &#125; while (preg_match(&#36;BB_DownloadLinkTag, &#36;text, &#36;resultA)) &#123; &#36;sid = &#36;resultA[1]; &#36;title = &#36;resultA[2]; &#36;text = str_replace(&#36;resultA[0],'<a href="'. &#36;_CONF['site_url'] . '/filemgmt/visit.php?lid=' .&#36;sid.'">'.&#36;title.'</a>',&#36;text); &#125; while (preg_match(&#36;BB_ImageTag, &#36;text, &#36;resultA)) &#123; &#36;imagename = &#36;resultA[1]; &#36;text = str_replace(&#36;resultA[0],'<img src="'. &#36;_CONF['layout_url'] . '/images/'.&#36;imagename.'.gif" align=left>',&#36;text); &#125; while (preg_match(&#36;BB_FrameTag, &#36;text, &#36;resultA)) &#123; &#36;color = &#36;resultA[1]; &#36;content = &#36;resultA[2]; &#36;text = str_replace(&#36;resultA[0],"<table bgcolor=#000000 cellpadding=1 cellspacing=0><tr><td>" ."<table bgcolor=#".&#36;color." cellpadding=4 cellspacing=0><tr><td>".&#36;content ."<td></tr></table><td></tr></table>" ,&#36;text); &#125; while (preg_match(&#36;BB_BlockTag, &#36;text, &#36;resultA)) &#123; &#36;title = &#36;resultA[1]; &#36;content = &#36;resultA[2]; &#36;text = str_replace(&#36;resultA[0],COM_startBlock(&#36;title).&#36;content.COM_endBlock(),&#36;text); &#125; while (preg_match(&#36;BB_PHPTag, &#36;text, &#36;resultA)) &#123; &#36;phpcode = stripslashes(&#36;resultA[1]); &#36;text = str_replace(&#36;resultA[0],eval(&#36;phpcode),&#36;text); &#125; return &#36;text; &#125; --- shortstorytext.thtml example: <!-- ARTICLE START --> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td class="storytitle"><b><u>&#123;story_title&#125;</u></b></td> </tr> <tr> <td><div align=justify> &#123;story_introtext&#125; &#123;start_readmore_anchortag&#125;[Full Story...]&#123;end_readmore_anchortag&#125;&#123;edit_link&#125; </div></td> </tr> </table> <!-- ARTICLE END -->
 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
 Quote

All times are EDT. The time is now 07:00 am.

  • 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