We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25799
    • 9 Posts
    First of all hi! I’m quietly using modX for a few month now and loving it. I’m quite a n00bish at php/mysql but in order to learn php a re-done an old "get-topics" script. (some like phpBB fetchall - basic). it’s quite in development right now and I’m testing new things every day. But before i go any further i would like some feedback of things i could do better. if you have some ideas (which a php n00b can do/learn) please add them. Also i have not much clue if it’s save enough to use in a live site.


    description:
    phpBB Snippet v0.001 is udate 1 a very simple "get topic" script for modX. It works with phpBB 2.X. phpBB 3.0 support will be added later on (at least i hope tongue ). Please make sure you fill in all items in the ’config’ section. A side note: you mySQL tables has to have the standard prefix: "phpbb_" if this is not the case edit the 3 SQL connection (example: if your prefix is forum_ change phpbb_users to forum_users. )



    For the people don’t know how to find the id of a certain forum: follow the link of the forum you want to include, then look at the url: http://crea-design.nl/test/viewforum.php?f=1 f=1 so id=1 and so on.



    Params:

    &forumid --> ID of the forum (in phpBB) in which you want to fetch the post (default=1).
    &numberoftopics --> Number of posts you want to include.(default=5)
    &maxchar --> Max number of characters (don’t call it for full article)
    &language --> The language of the snippet (support for Dutch and English only at this time)

    Example call:

    [[phpbb? &forumid=`1` &numberoftopics=`1` &maxchar=`100` &language=`nl` ]]

    [[phpbb? &forumid=`12` &numberoftopics=`6` &language=`en` ]]


    Script in action:

    basic phpBB forum: http://crea-design.nl/test/
    modx page with snippet: http://crea-design.nl/phpBB_snippet_test.html

    (oh don’t mind the rest of the site still dev. )
    (I’m quite rubish at languages, i can’t even spell in my own language so plz don’t mind my bad english)


    Update 1! added the code Doze (where for tnx) and some moer placeholders in.



    snippet.txt:


      <?php
     /*
     
    ---------------------------------------------------------------------
           phpBB snippet v0.001 upadte 1
    ---------------------------------------------------------------------
     
     Original code (tnx for letting me using it) by: 
        *  Cyst 
    	*  ColdIce aka Furiouz (http://clan12.com)
    
     
     Ported / re-coding for modX:
        *  RWQ (http://crea-design.nl  - htpp://sesil.nl }
     
     Also many many tnx to:
        *  Doze - for making the placeholders and adding the TPL and CSS params
      
    oh before i forgot please don't mind my bad english 
    ---------------------------------------------------------------------
    //   Docu: 
    ---------------------------------------------------------------------
    
    phpBB Snippet v0.001 is a very simpel "get topic" script for modX. It works with phpBB 2.X. phpBB 3.0 support will be added later on (at least i hope :P ). Please make sure you fill in all items in the 'config' section. A side note: you mySQL tables has to have the standard prefix: "phpbb_" if this is not the case edit the 3 SQL connection (example: if your prefix is forum_ change phpbb_topic to forum_topic. 
    
      Functions:
       *  Gets a x number of topics from a forum
       *  Max char. to display
       *  Template system
       *  Select the language of the script (otherwise would the list be so short :P)
       
      For the peaple don't know how to find the id of a certain forum: follow the link of the forum you want to include, then look at the url: http://crea-design.nl/test/viewforum.php?f=1 f=1 so id=1 and so on.
    
      
     
     Params:
     
     &forumid    --> ID of the forum (in phpBB) in wich you want to fetch the post (default=1).
     &numberoftopics    --> Number of posts you want to include.(default=5)
     &maxchar    --> Max number of characters (leave empty for full article)
     &cssTpl     --> Css path (default: assets/snippets/phpbb/css.css)
     &topicTpl   --> path to yout TPL file (defaulr assets/snippets/phpbb/topicTpl.html
    
     Example call:
     
     [[phpbb? &forumid=`1` &numberoftopics=`1` &maxchar=`100`  ]]
     
     [[phpbb? &forumid=`12` &numberoftopics=`6`  ]]
     
    [[phpbb? &forumid=`7` &numberoftopics=`3` &maxchar=`350` &topicTpl=`assets/snippets/phpbb/test.html` &cssTpl='assets/snippets/phpbb/style.css` ]]
     
     
     There is one Tpl file called topicTpl.html, you can edit it or create a new one. list of placeholders:
     
      [+userAvatar+] --> containing the link to the ava of a user
      [+topicUrl+]   --> containing a link to the topic
      [+topicPoster+]--> The topic poster 
      [+topicTitle+] --> Topic Title
      [+topicDate+]  --> Date of publishing the topic
      [+postContent+]--> The topic text
      [+replyCount+] --> The number of replies
      [+userRank+]   --> The rank of a user
      [+userEmail+]  --> User Email (in text so make link with html command mailto) 
      [+userSig+]    --> User Signature 
      
      Then the language placeholders:
      
      [+lang.writtenby+]
      [+lang.on+]
      [+lang.replytxt+]
     
    
    
     Things that will be added later on (al least i hope):
     
      * support for UserGroups (example: a members list) 
      * more place holders
     
     
    ---------------------------------------------------------------------
    //  Config section :    
    -------------------------------------------------------------------*/ 
      
    $forumpath="http://www.crea-design.nl/test/"; // path to your phpbb2 install   
    
    $dbname= 'DBname';    // Database Name
    $dbuser= 'DBuser';     // Your MySQL username
    $dbpass='pass';         // Your MySQ password
    $dbhost= 'localhost';      // MySQL host (mostly: localhost) 
    
    $date='%d-%m-%y'; // Time and Ddte default:  Days - Month - Year
    
    
    // Language:
    
    $phpbb_lang['writtenby']='written by:';
    $phpbb_lang['gototopic']='go to topic';
    $phpbb_lang['quote']='Quote:';
    $phpbb_lang['code']='Code:'; 
    $phpbb_lang['replytxt']=' replies'; 
    $phpbb_lang['by']='Quote By:';
    $phpbb_lang['on']='On:';
    $phpbb_lang['gototopiclink']='<i>... <b><a href=[+topicUrl+] target=_blank>[+lang.gototopic+]</a></b></i>';
    
    
    /* -------------------------------------------------------------
    // End config start code - if you know even less of php/mySQL then I do don't mess around alot :P. 
    --------------------------------------------------------------*/ 
    
    
    // param list:
    $forumid=(isset($forumid))? $forumid: 1;
    $numberoftopics=(isset($numberoftopics))? $numberoftopics: 5;
    $maxchar=(isset($maxchar))? $maxchar: true; 
    $cssTpl=(isset($cssTpl))? $cssTpl: 'assets/snippets/phpbb/css.css'; // template css
    $topicTpl=(isset($topicTpl))? $topicTpl: 'assets/snippets/phpbb/topicTpl.html'; // template chunk 
    
    // TPL code
    
    if(!function_exists(phpbbGetTemplate)) {
    	function phpbbGetTemplate($tpl){
    		global $modx;
    		$template = "";
    		if ($modx->getChunk($tpl) != "") {
    			$template = $modx->getChunk($tpl);
    		} else if(is_file($tpl)) {
    			$template = file_get_contents($tpl);
    		} else {
    			$template = $tpl;
    		}
    		return $template;
    	}
    }
    
    // css code:
    
    if ($cssTpl != "") {
    	if ($modx->getChunk($cssTpl) != "") {
    		$modx->regClientCSS($modx->getChunk($cssTpl));
    	} else if (file_exists($modx->config['base_path'].$cssTpl)) {
    		$modx->regClientCSS('<link rel="stylesheet" href="'. $modx->config['base_url'].$cssTpl.'" type="text/css" media="screen" />');
    	} else {	
    		$modx->regClientCSS($cssTpl);
    	}
    }
    
    
    
     // Create a SQL connection
     
    		mysql_connect("$dbhost", "$dbuser","$dbpass"); 
    		mysql_select_db ("$dbname");
    
     // Result 1. ( get topic info)
     
    		$result = mysql_query("SELECT topic_id,topic_title,topic_poster,topic_time,topic_replies,topic_first_post_id FROM phpbb_topics WHERE forum_id='$forumid' ORDER BY topic_id DESC LIMIT $numberoftopics ");
    		while(list($topic_id,$topic_title,$topic_poster,$topic_time,$topic_replies,$topic_first_post_id) = mysql_fetch_array($result))
    		{
    
     // Result 2. ( get user info (inc ava)
     
    		$result2 = mysql_query("SELECT username,user_avatar,user_email,user_sig,user_rank FROM phpbb_users WHERE user_id='$topic_poster'");
    		list($topic_poster_name,$user_avatar,$user_email,$user_sig,$user_rank) = mysql_fetch_array($result2);
    
     // Result 3. ( get topic text and BB code )
    
    		$result3 = mysql_query("SELECT bbcode_uid,post_text FROM phpbb_posts_text WHERE post_id='$topic_first_post_id'");
    		list($bbcode_uid,$post_content) = mysql_fetch_array($result3);
    
    		
    		
    		
    		
    // Replace BB code with (x)HTML code
    		
    		$post_content = preg_replace("/\\n/",'<br>', $post_content);
            $post_content = str_replace("[quote:$bbcode_uid]", "<div class='quote'>$quote <br />", $post_content);
            $post_content = str_replace("[/quote:$bbcode_uid]", "</div>", $post_content);
            $post_content = str_replace("[code:1:$bbcode_uid]", "<div class='code'>$code
    ", $post_content);
    $post_content = str_replace("[/code:1:$bbcode_uid]", "</div>", $post_content); $post_content = preg_replace("#\[quote=\\\"(.*?)\\\":$bbcode_uid\]#si", "$by" , $post_content); $post_content = str_replace("[list:$bbcode_uid]", "<ul>", $post_content); $post_content = str_replace("[*:$bbcode_uid]", "<li>", $post_content); $post_content = str_replace("[/list:u:$bbcode_uid]", "</ul>", $post_content); $post_content = str_replace("[/list:o:$bbcode_uid]", "</ol>", $post_content); $post_content = preg_replace("/\[list=([a1]):$bbcode_uid\]/si", "<ol type=\\1>", $post_content); $post_content = str_replace("[b:$bbcode_uid]", "<b>", $post_content); $post_content = str_replace("[/b:$bbcode_uid]", "</b>", $post_content); $post_content = str_replace("[i:$bbcode_uid]", "<i>", $post_content); $post_content = str_replace("[/i:$bbcode_uid]", "</i>", $post_content); $post_content = str_replace("[u:$bbcode_uid]", "<u>", $post_content); $post_content = str_replace("[/u:$bbcode_uid]", "</u>", $post_content); $post_content = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$bbcode_uid\]/si", "<font color=\\1>", $post_content); $post_content = str_replace("[/color:$bbcode_uid]", "</font>", $post_content); $post_content = preg_replace("/\[size=([1-2]?[0-9]):$bbcode_uid\]/si", "<font size=\\1>", $post_content); $post_content = str_replace("[/size:$bbcode_uid]", "</font>", $post_content); $post_content = str_replace("[img:$bbcode_uid]", "<img src=", $post_content); $post_content = str_replace("[/img:$bbcode_uid]", " ' alt='' />", $post_content); // date and stuff. $datum = strftime ("$date",$topic_time + $timeadjust); // Getting the smilies (the basic ones that come with the first install. Edit/Add the lines below for costum images) $post_content = str_replace (":oops:","<img src=$forumpath/images/smiles/icon_redface.gif alt= border=0 />", $post_content); $post_content = str_replace (":?:","<img src=$forumpath/images/smiles/icon_question.gif alt= border=0 />", $post_content); $post_content = str_replace (":D","<img src=$forumpath/images/smiles/icon_biggrin.gif alt= border=0 />", $post_content); $post_content = str_replace (":)","<img src=$forumpath/images/smiles/icon_smile.gif alt= border=0 />", $post_content); $post_content = str_replace (":(","<img src=$forumpath/images/smiles/icon_sad.gif alt= border=0 />", $post_content); $post_content = str_replace (":o","<img src=$forumpath/images/smiles/icon_surprised.gif alt= border=0 />", $post_content); $post_content = str_replace (":shock:","<img src=$forumpath/images/smiles/icon_eek.gif alt= border=0 />", $post_content); $post_content = str_replace (":?","<img src=$forumpath/images/smiles/icon_confused.gif alt= border=0 />", $post_content); $post_content = str_replace ("8)","<img src=$forumpath/images/smiles/icon_cool.gif alt= border=0 />", $post_content); $post_content = str_replace (":lol:","<img src=$forumpath/images/smiles/icon_lol.gif alt= border=0 />", $post_content); $post_content = str_replace (":x","<img src=$forumpath/images/smiles/icon_mad.gif alt= border=0 />", $post_content); $post_content = str_replace (":P","<img src=$forumpath/images/smiles/icon_razz.gif alt= border=0 />", $post_content); $post_content = str_replace (":cry:","<img src=$forumpath/images/smiles/icon_cry.gif alt= border=0 />", $post_content); $post_content = str_replace (":evil:","<img src=$forumpath/images/smiles/icon_evil.gif alt= border=0 />", $post_content); $post_content = str_replace (":twisted:","<img src=$forumpath/images/smiles/icon_twisted.gif alt= border=0 />", $post_content); $post_content = str_replace (":roll:","<img src=$forumpath/images/smiles/icon_rolleyes.gif alt= border=0 />", $post_content); $post_content = str_replace (":wink:","<img src=$forumpath/images/smiles/icon_wink.gif alt= border=0 />", $post_content); $post_content = str_replace (":!:","<img src=$forumpath/images/smiles/icon_exclaim.gif alt= border=0 />", $post_content); $post_content = str_replace (":idea:","<img src=$forumpath/images/smiles/icon_idea.gif alt= border=0 />", $post_content); $post_content = str_replace (":arrow:","<img src=$forumpath/images/smiles/icon_arrow.gif alt= border=0 />", $post_content); // Max char. code : if( strlen($post_content)>$maxchar ) { $post_content = substr($post_content, 0, $maxchar) . "[+lang.gototopiclink+]"; } //get template $template = phpbbGetTemplate($topicTpl); //replace language placeholders foreach ($phpbb_lang as $key => $value) { $template = str_replace('[+lang.'.$key.'+]', $value, $template); } //replace content placeholders and append to $output $placeholders = array('[+userAvatar+]', '[+topicUrl+]', '[+topicTitle+]', '[+topicPoster+]', '[+topicDate+]', '[+postContent+]', '[+replyCount+]', '[+userRank+]', '[+userEmail+]', '[+userSig+]'); $phContent = array($user_avatar, $forumpath.'/viewtopic.php?t='.$topic_id, $topic_title, $topic_poster_name, $datum, $post_content, $topic_replies, $user_email, $user_sig, $user_rank); $output .= str_replace($placeholders, $phContent, $template); } // output for modX return $output; ?>



    the attachment is v0.001 upadte 1 (so the latest vesrion)
      • 7923
      • 4,213 Posts
      Looks really nice, good job! I would like to see a possibility to use a chunk as a template for the output format, Eg. make placeholders for the topic_id, topic_title, topic_poster, topic_time, topic_replies, topic_first_post_id fields (example here).. so something like:

      Add snippet parameters:
      <?php
      $cssTpl=(isset($cssTpl))? $cssTpl: 'assets/snippets/phpbb/css.css'; //to make possible define css chunk, file, string in snippet param
      $topicTpl=(isset($topicTpl))? $topicTpl: 'assets/snippets/phpbb/topicTpl.html'; //template chunk for the topic/post items
      ?>
      


      Add function to get template contents, gets from chunk, file or as string:
      <?php
      if(!function_exists(phpbbGetTemplate)) {
      	function phpbbGetTemplate($tpl){
      		global $modx;
      		$template = "";
      		if ($modx->getChunk($tpl) != "") {
      			$template = $modx->getChunk($tpl);
      		} else if(is_file($tpl)) {
      			$template = file_get_contents($tpl);
      		} else {
      			$template = $tpl;
      		}
      		return $template;
      	}
      }
      ?>


      Remove the current hardcoded $css_link parameter and the $modx->regClientCSS call for it and put this after the parameters
      <?php
      if ($cssTpl != "") {
      	if ($modx->getChunk($cssTpl) != "") {
      		$modx->regClientCSS($modx->getChunk($cssTpl));
      	} else if (file_exists($modx->config['base_path'].$cssTpl)) {
      		$modx->regClientCSS('<link rel="stylesheet" href="'. $modx->config['base_url'].$cssTpl.'" type="text/css" media="screen" />');
      	} else {	
      		$modx->regClientCSS($cssTpl);
      	}
      }
      ?>


      Do the language strings in a single array (and later below make them also available as placeholders):
      <?php
      $phpbb_lang['writtenby']='written by:';
      $phpbb_lang['gototopic']='go to topic';
      $phpbb_lang['quote']='Quote:';
      $phpbb_lang['code']='Code:'; 
      $phpbb_lang['replytxt']=' replies'; 
      $phpbb_lang['by']='Quote By:';
      $phpbb_lang['on']='On:';
      $phpbb_lang['gototopiclink']='<i>... <b><a href=[+topicUrl+] target=_blank>[+lang.gototopic+]</a></b></i>';
      ?>


      Instead of using this:
      <?php
      if( strlen($post_content)>$maxchar )
      	$post_content = substr($post_content, 0, $maxchar) . "<i>... <b><a href=$forumpath/viewtopic.php?t=$topic_id  target=_blank>$gototopic</a></b></i>";
      
      echo "
      
      <div class='postbase'>
      <div class='top'>
      <div class='topleft'><img src=$user_avatar alt=''/></div>
      <div class='topright'>
      <a href=$forumpath/viewtopic.php?t=$topic_id target=_blank><h3 class='toph3'>$topic_title</h3></a>
      $writtenby <b>$topic_poster_name</b> <br />$on $datum				
      </div>
      </div>
      
      <div class='contentphpbb'>
      $post_content 
      <br />
      <p align='right'><a href=$forumpath/viewtopic.php?t=$topic_id target=_blank>$topic_replies  $replytxt</a></p>
      <br />
      </div>	
      
      </div>
      
      
      
      			";
      ?>


      Use this:
      <?php
      //add link if needed
      if( strlen($post_content)>$maxchar ) {
      	$post_content = substr($post_content, 0, $maxchar) . "[+lang.gototopiclink+]";
      }
      //get template
      $template = phpbbGetTemplate($topicTpl);
      //replace language placeholders
      foreach ($phpbb_lang as $key => $value) {
      	$template = str_replace('[+lang.'.$key.'+]', $value, $template);
      }
      //replace content placeholders and append to $output
      $placeholders = array('[+userAvatar+]', '[+topicUrl+]', '[+topicTitle+]', '[+topicPoster+]', '[+topicDate+]', '[+postContent+]', '[+replyCount+]');
      $phContent = array($user_avatar, $forumpath.'/viewtopic.php?t='.$topic_id, $topic_title, $topic_poster_name, $datum, $post_content, $topic_replies);
      $output .= str_replace($placeholders, $phContent, $template);
      ?>
      


      And to the default template (assets/snippets/phpbb/topicTpl.html) put the following:
      <div class='postbase'>
      	<div class='top'>
      		<div class='topleft'><img src=[+user_avatar+] alt=''/></div>
      		<div class='topright'>
      			<a href=[+topicUrl+] target=_blank><h3 class='toph3'>[+topicTitle+]</h3></a>
      			[+lang.writtenby+] <b>[+topicPoster+]</b> <br />[+lang.on+] [+topicDate+]
      		</div>
      	</div>
      	<div class='contentphpbb'>
      		[+postContent+]
      		<br />
      		<p align='right'><a href=[+topicUrl+] target=_blank>[+replyCount+] [+lang.replytxt+]</a></p>
      		<br />
      	</div>	
      </div>
      


      And in the section that converts phpbb tags to html, replace $quote, $code and $by with [+lang.quote+], [+lang.code+] and [+lang.by+]

      That should be all, I think. To make the snippet even better, see the Creating Snippets page in MODx wiki..

      Good stuff! Keep it up! grin


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 25799
        • 9 Posts
        thnx Doze for all those tips, i now understands placeholders and so on. Added some more: like signature support, Topic Poster Email and Poster Rank. the next update will be a bit bigger with hopefully the support of usergroups.

        updated the first post, with the latest version.
          • 7923
          • 4,213 Posts
          Good job!

          Have you tested that new code? I see that at least on these parts, the old language tags are not replaced:

          <?php
          $post_content = str_replace("[quote:$bbcode_uid]", "<div class='quote'>$quote <br />", $post_content);
          
          $post_content = str_replace("[code:1:$bbcode_uid]", "<div class='code'>$code
          ", $post_content);

          $post_content = preg_replace("#\
          #si", "$by" , $post_content);
          ?>
          <br /><br />Should be:<br />

          <?php
          $post_content = str_replace("
          ", "<div class='quote'>$phpbb_lang['quote']
          ", $post_content);

          $post_content = str_replace("[code:1:$bbcode_uid]", "<div class='code'>$phpbb_lang['code']<br />", $post_content); $post_content = preg_replace("#\[quote=\\\"(.*?)\\\":$bbcode_uid\]#si", "$phpbb_lang['by']" , $post_content); ?>


          I also suggest to make language snippet parameter and include the language from separate file.. like:

          <?php
          // snippet parameter
          $lang = (isset($lang)) ? $lang : "en"; // default language english
          
          $langfile = $modx->config['base_path'].'assets/snippets/phpbb/lang_'.$lang.'.php';
          if(file_exists($langfile)){
          	include($langfile);
          } else {
          	return 'phpbb snippet error: language file is missing!';
          }
          ?>
          


          Then you can create language files like lang_en.php, lang_nl.php, etc..

          Keep up the good work!


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 25799
            • 9 Posts
            whoops if you haven’t said it i wouldn’t have noticed.... stupid of me to froget. But have to go now I’ll update it tomorrow.
              • 11429
              • 90 Posts
              under the database config in the snippet which one do we put the modx or the phpbb ?
              i’m having databse errors no matter which database details i put
                • 24530
                • 100 Posts
                Hi doze!
                Yesterday I was trying to do a snippet which supports placeholders/templates ... it took me way to much time and had no result ;-( but your description in this thread really helps!
                If you do some small changes to your post it could serve as a really cool "placeholders/templates tutorial" for the wiki?
                  my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
                  • 7923
                  • 4,213 Posts
                  Yeah, feel free to create that wiki tutorial, it would be great!


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 24530
                    • 100 Posts
                    I know, I should spend the time to write it up ... but I have to learn (about php and the English language) a little bit more before I can do it ... if nobody else does it, I will – but not right now ...
                      my newest webpage [url=http://gitarren.zucali.at]Meisterwerkstatt f
                      • 10815
                      • 1 Posts
                      Hey there!

                      I modified the snippet by RWQ a little bit. It now works for my phpbb3 installation. If anyone has time to test it for downwards compatibility feel free to do so. It would be interesting tif it still works with phpbb 2.x.

                      <?php
                      /** 
                       * ======================================================================================
                       * !!! IMPORTANT !!!
                       * ======================================================================================
                       *
                       * I had to change a line in the modx file "includes/document.parser.class.inc.php" 
                       * in order to get this thing to work.
                       * 
                       * Change 
                       *   $ds= @mysql_query($sql);
                       * to
                       *   $ds= $this->dbQuery($sql);
                       *
                       * See http://modxcms.com/bugs/task/866
                       *
                       * Have fun with the script!
                       * Gigi
                       * 
                       * ======================================================================================
                       * ======================================================================================
                       *
                       *
                       * ---------------------------------------------------------------------
                       *  phpBB snippet v0.0.2
                       * ---------------------------------------------------------------------
                       *
                       * Original code (tnx for letting me using it) by: 
                       *  - Cyst 
                       *  - ColdIce aka Furiouz (http://clan12.com)
                       *
                       * 
                       * Ported / re-coding for modX:
                       *  - RWQ (http://crea-design.nl  - htpp://sesil.nl }
                       * 
                       * Also many many tnx to:
                       *  - Doze - for making the placeholders and adding the TPL and CSS params
                       *
                       * Modifications for PHPBB3:
                       *  - Christoph 'Gigi' Fuchs (http://cgf.at, gigi33 [at] gmx _dot_ at)
                       *  
                       *
                       * ---------------------------------------------------------------------
                       *  Documentation:
                       * ---------------------------------------------------------------------
                       *
                       *
                       *  Functions:
                       *   - Gets a x number of topics from a forum
                       *   - Max char. to display
                       *   - Template system
                       *   - Select the language of the script (otherwise would the list be so short :P)
                       *   
                       *  For everyone who doesn't know how to find the ID of a certain forum: 
                       *  Follow the link of the forum you want to include, then look at the url: 'http://www.example.com/forum/viewforum.php?f=1' f=1 so id=1.
                       *
                       * 
                       * Params:
                       * 
                       * &forumid          ID of the forum (in phpBB) in wich you want to fetch the post (default=1).
                       * &numberoftopics   Number of posts you want to include.(default=5)
                       * &maxchar          Max number of characters (leave empty for full article)
                       * &cssTpl           Css path (default: assets/snippets/phpbb/style.css)
                       * &topicTpl         path to yout TPL file (defaulr assets/snippets/phpbb/chunk.topic.tpl
                       *
                       * 
                       * Example calls:
                       * 
                       * [[phpbb? &forumid=`1` &numberoftopics=`1` &maxchar=`100`  ]]
                       * [[phpbb? &forumid=`12` &numberoftopics=`6`  ]]
                       * [[phpbb? &forumid=`7` &numberoftopics=`3` &maxchar=`350` &topicTpl=`assets/snippets/phpbb/chunk.topic.tpl` &cssTpl='assets/snippets/phpbb/style.css` ]]
                       * 
                       * 
                       * There is one Tpl file called chunk.topic.tpl, you can edit it or create a new one. list of placeholders:
                       * 
                       * [+userAvatar+] --> containing the link to the ava of a user
                       * [+topicUrl+]   --> containing a link to the topic
                       * [+topicPoster+]--> The topic poster 
                       * [+topicTitle+] --> Topic Title
                       * [+topicDate+]  --> Date of publishing the topic
                       * [+postContent+]--> The topic text
                       * [+replyCount+] --> The number of replies
                       * [+userRank+]   --> The rank of a user
                       * [+userEmail+]  --> User Email (in text so make link with html command mailto) 
                       * [+userSig+]    --> User Signature 
                       *  
                       * Language specific placeholders:
                       *  
                       * [+lang.writtenby+]
                       * [+lang.on+]
                       * [+lang.replytxt+]
                       *
                       */ 
                       
                      /** -------------------------------------------------------------------
                       *  Configuration
                       */ 
                      
                      
                      $forumpath = 'forum';        // path to your phpbb3 install (do not at a trailing slash)
                      $snipdir =   'assets/snippets/phpbb'; // path to your phpbb snippet (do not add a trailing slash)
                      
                      
                      $dbname =    'dbname';       // Database Name
                      $dbuser =    'dbuser';       // Your MySQL username
                      $dbpass =    '*********';    // Your MySQ password
                      $dbhost =    'localhost';    // MySQL host (mostly: localhost) 
                      
                      $date =      '%d.%m.%Y';     // Time and Ddte default:  Days - Month - Year 
                                                   //   (see http://php.net/date for formating strings)
                      $lang =      'de';           // Language (available: en, de)
                      
                      
                      
                      /** ------------------------------------------------------------------- 
                       * End of configuration
                       * Don't change the following code if you don't know what you're doing.
                       */
                      
                      // Language:
                      $languagefile = $snipdir . '/' . $lang . '.lang.inc.php';
                      if (!file_exists($languagefile)) {
                      	return "<strong>[PHPBB Snippet] Error:</strong> Language file '$languagefile' not found. Language: '$lang'.<br />";
                      }
                      
                      include_once($languagefile);
                      $phpbb_lang['gototopiclink']='<i>... <b><a href=[+topicUrl+] target=_blank>[+lang.gototopic+]</a></b></i>';
                      
                      // param list:
                      $forumid = (isset($forumid)) ? $forumid : 1;
                      $numberoftopics = (isset($numberoftopics)) ? $numberoftopics : 5;
                      $maxchar = (isset($maxchar)) ? $maxchar : true; 
                      $cssTpl = (isset($cssTpl)) ? $cssTpl : $snipdir . '/style.css'; // template css
                      $topicTpl = (isset($topicTpl)) ? $topicTpl : $snipdir . '/chunk.topic.tpl'; // template chunk 
                      
                      // TPL code
                      if(!function_exists(phpbbGetTemplate)) {
                      	function phpbbGetTemplate($tpl){
                      		global $modx;
                      		$template = "";
                      		if ($modx->getChunk($tpl) != "") {
                      			$template = $modx->getChunk($tpl);
                      		} else if(is_file($tpl)) {
                      			$template = file_get_contents($tpl);
                      		} else {
                      			$template = $tpl;
                      		}
                      		return $template;
                      	}
                      }
                      
                      // css code:
                      if ($cssTpl != "") {
                      	if ($modx->getChunk($cssTpl) != "") {
                      		$modx->regClientCSS($modx->getChunk($cssTpl));
                      	} else if (file_exists($modx->config['base_path'].$cssTpl)) {
                      		$modx->regClientCSS('<link rel="stylesheet" href="'. $modx->config['base_url'].$cssTpl.'" type="text/css" media="screen" />');
                      	} else {	
                      		$modx->regClientCSS($cssTpl);
                      	}
                      }
                      
                      // Create a mySQL connection 
                      mysql_connect("$dbhost", "$dbuser","$dbpass"); 
                      mysql_select_db("$dbname");
                      
                      // Result 1. ( get topic info )
                      $result = mysql_query("SELECT topic_id,topic_title,topic_poster,topic_time,topic_replies,topic_first_post_id FROM phpbb_topics WHERE forum_id='$forumid' ORDER BY topic_id DESC LIMIT $numberoftopics ");
                      
                      while(list($topic_id,$topic_title,$topic_poster,$topic_time,$topic_replies,$topic_first_post_id) = mysql_fetch_array($result))	{
                      
                      	// Result 2. ( get user info (incl. avatar) )
                      	$result2 = mysql_query("SELECT username,user_avatar,user_email,user_sig,user_rank FROM phpbb_users WHERE user_id='$topic_poster'");
                      	list($topic_poster_name,$user_avatar,$user_email,$user_sig,$user_rank) = mysql_fetch_array($result2);
                      	
                      	// Result 3. ( get topic text and BB code )
                      	$result3 = mysql_query("SELECT bbcode_uid,post_text FROM phpbb_posts WHERE post_id='$topic_first_post_id'");
                      	list($bbcode_uid,$post_content) = mysql_fetch_array($result3);
                      
                      	$post_content = str_replace("{SMILIES_PATH}", "$forumpath/images/smilies", $post_content);
                      			
                      	// Replace BB code with (x)HTML code
                      	$post_content = preg_replace("/\\n/",'<br />', $post_content);
                      	$post_content = str_replace("[quote:$bbcode_uid]", "<div class='quote'>$quote <br />", $post_content);
                      	$post_content = str_replace("[/quote:$bbcode_uid]", "</div>", $post_content);
                      	$post_content = str_replace("[code:1:$bbcode_uid]", "<div class='code'>$code
                      ", $post_content);
                      $post_content = str_replace("[/code:1:$bbcode_uid]", "</div>", $post_content); $post_content = preg_replace("#\[quote=\\\"(.*?)\\\":$bbcode_uid\]#si", "$by" , $post_content); $post_content = str_replace("[list:$bbcode_uid]", "<ul>", $post_content); $post_content = str_replace("[*:$bbcode_uid]", "<li>", $post_content); $post_content = str_replace("[/list:u:$bbcode_uid]", "</ul>", $post_content); $post_content = str_replace("[/list:o:$bbcode_uid]", "</ol>", $post_content); $post_content = preg_replace("/\[list=([a1]):$bbcode_uid\]/si", "<ol type=\\1>", $post_content); $post_content = str_replace("[b:$bbcode_uid]", "<strong>", $post_content); $post_content = str_replace("[/b:$bbcode_uid]", "</strong>", $post_content); $post_content = str_replace("[i:$bbcode_uid]", "<i>", $post_content); $post_content = str_replace("[/i:$bbcode_uid]", "</i>", $post_content); $post_content = str_replace("[u:$bbcode_uid]", "<u>", $post_content); $post_content = str_replace("[/u:$bbcode_uid]", "</u>", $post_content); $post_content = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$bbcode_uid\]/si", "<font color=\\1>", $post_content); $post_content = str_replace("[/color:$bbcode_uid]", "</font>", $post_content); $post_content = preg_replace("/\[size=([1-2]?[0-9]):$bbcode_uid\]/si", "<font size=\\1>", $post_content); $post_content = str_replace("[/size:$bbcode_uid]", "</font>", $post_content); $post_content = str_replace("[img:$bbcode_uid]", "<img src=", $post_content); $post_content = str_replace("[/img:$bbcode_uid]", " ' alt='' />", $post_content); $post_content = preg_replace("/\[url=(.*):$bbcode_uid\](.*)\[\/url:$bbcode_uid\]/Usi", "<a href='\\1'>\\2</a>", $post_content); $post_content = preg_replace("/\[url:$bbcode_uid\](.*)\[\/url:$bbcode_uid\]/Usi", "<a href='\\1'>\\1</a>", $post_content); $user_avatar = "$forumpath/download.php?avatar=" . $user_avatar; // date and stuff. $datum = strftime ("$date", $topic_time + $timeadjust); // Max char. code : if( strlen($post_content)>$maxchar ) { $post_content = substr($post_content, 0, $maxchar) . "[+lang.gototopiclink+]"; } //get template $template = phpbbGetTemplate($topicTpl); //replace language placeholders foreach ($phpbb_lang as $key => $value) { $template = str_replace('[+lang.'.$key.'+]', $value, $template); } //replace content placeholders and append to $output $placeholders = array('[+userAvatar+]', '[+topicUrl+]', '[+topicTitle+]', '[+topicPoster+]', '[+topicDate+]', '[+postContent+]', '[+replyCount+]', '[+userRank+]', '[+userEmail+]', '[+userSig+]'); $phpbbContent = array($user_avatar, $forumpath.'/viewtopic.php?t='.$topic_id, $topic_title, $topic_poster_name, $datum, $post_content, $topic_replies, $user_email, $user_sig, $user_rank); $output .= str_replace($placeholders, $phpbbContent, $template); } // output for modX return $output; ?>


                      I am by no means actively working on this snippet but any comments are appreciated.

                      Edit: Removed my database username and password from the snippet rolleyes

                      Cheers,
                      Gigi