[RC] Display posts anywhere 1.2.0RC5

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Ideas Centre
ddeg10
Registered User
Posts: 180
Joined: Mon Oct 21, 2002 8:24 am

Re: [BETA] Display posts anywhere

Post by ddeg10 » Tue Jul 10, 2007 9:57 pm

I really wish this had better instructions :roll:

User avatar
nickvergessen
Former Team Member
Posts: 4397
Joined: Mon Apr 30, 2007 5:33 pm
Location: Stuttgart, Germany
Name: Joas Schilling
Contact:

Re: [BETA] Display posts anywhere

Post by nickvergessen » Wed Jul 25, 2007 12:13 am

I took the IDea and made it work for the first post of all topics of a choosable forum...
I also got all variables of the viewtopic working,
if you are interested i can show it to you @GroovePlugs
No Support via PM

Wickedlad
Registered User
Posts: 40
Joined: Tue Jun 19, 2007 12:05 pm

Re: [BETA] Display posts anywhere

Post by Wickedlad » Mon Aug 20, 2007 3:09 pm

I need it. Be waiting...

User avatar
nickvergessen
Former Team Member
Posts: 4397
Joined: Mon Apr 30, 2007 5:33 pm
Location: Stuttgart, Germany
Name: Joas Schilling
Contact:

Re: [BETA] Display posts anywhere

Post by nickvergessen » Mon Aug 20, 2007 4:16 pm

I think, I'll take up that work
No Support via PM

Tona
Registered User
Posts: 23
Joined: Sat Apr 16, 2005 4:45 pm
Contact:

Re: [BETA] Display posts anywhere

Post by Tona » Mon Aug 20, 2007 4:41 pm

Hi -- First off, I really appreciate this mod. Thanks for making it available! I'm implementing it on my site now. Everything works great, but I could just use a little help with a finishing detail. This is probably just a general php question, but I'm sure it would be useful to others using this mod. So here's the deal. This is how my forum posts currently display on my website:
Image
As you can see, I needed the links to fit into a small space, so I removed some of the code from the "fancy schmancy table" in my news.php file so that only the topic title and a link to the full post remain (I was trying the approximate the old "topics anywhere" mod from phpBB2). In order to customize the look just a bit more, I created a little bullet image (would replace the "--" at the beginning of each post title) and a little clickable button that says "view" (would replace the clickable text that says "read").

Here is the chunk of code that I modified. It's from the very bottom of the "news.php" file that I created from the code posted in this thread:

Code: Select all

              //echo out the news in a fancy schmancy table
             echo "<br />";
//  I would like to include this image here: http://www.blamesociety.net/forum/bullet.jpg
             echo "-- <font size=1.7><b>" . $current_subject . "</b></font> - ";
             echo " <a href=\"/" . $forumpath . "/viewtopic.php?f=1&t=" . $current_topic . "\"> read </a>";
// In the line above, I would like to replace the text "read" with this button image: http://www.blamesociety.net/forum/view.jpg
              //Time to make sure that the amount of news posts to be displayed will be reached.
              $one++;
So..... Does anyone know what I would need to do to make my images display as described in my annotations in the code? I know it's got to be a simple solution, but it's been driving me mad trying to figure it out!

Thanks in advance for your help.

xxxgamer
Registered User
Posts: 574
Joined: Mon Jul 16, 2007 11:25 pm

Re: [BETA] Display posts anywhere

Post by xxxgamer » Mon Aug 20, 2007 6:15 pm

Id love to use this mod and need to use it on my site but i seriously dont understand the installation instructions :( any chance anyone could enlighten me?

Tona
Registered User
Posts: 23
Joined: Sat Apr 16, 2005 4:45 pm
Contact:

Re: [BETA] Display posts anywhere

Post by Tona » Mon Aug 20, 2007 7:11 pm

Well, I'll describe what I did. There are tons of different possible implementations of this code, so this was just my process --- several of my steps are unique to my situation and may not apply to others. Also, there may be even more streamlined ways to do some of these things; since I don't work with .php code a lot, I just kept troubleshooting until I found something that worked.

1. I took this chunk of code and pasted it into a new blank document, which I named "news.php" and saved at the root level of my forum. (Note: the code below is the code pasted at the top of this thread, so you may want to change it if some time has passed and a newer version comes out)

Code: Select all

[b]<?php
  //----------------------------------------------------------------------------//
  // PHPBB3 News Mod V.1.2                                                      //
  //                                                                            //
  // Tested and working on PHPBB3 RC3 and RC4                                   //
  //                                                                            //
  // MOD Made by Cruddpuppet (http://www.uranet.net/) (http://www.n-etwork.net) //
  //                                                                            //
  // replace_bb_code() function from bizzar.ssi                                 //
  //                                                                            //
  // Free for editing, but not distribution! If you have any questions on this, //
  // feel free to email me at cruddpuppet@gmail.com !                          //
  //----------------------------------------------------------------------------//
 
  //mysql information, must be correct in order to get news
  //this information can be found in your config.php in the root forum directory.
  $dbms = 'mysql';
  $dbhost = 'localhost';
  $dbport = '';
  $dbname = 'put your forum database name here';
  $dbuser = 'put the user name for your database/website here';
  $dbpasswd = 'put your password here';
 
  //table prefix, came from when you installed phpbb3. phpbb3_ is the default.
  //Also can be found in config.php
  $table_prefix = 'phpbb3_';
 
  //Relative path to your forum
  //NO BACK/FRONT SLASHES, PLEASE
  $forumpath = "nforum";
 
  $acm_type = 'file';
  $load_extensions = '';
 
  //Forum ID from where to grab the news
  $forum_id = "1";
 
  //Be careful, checking connection
  $db = mysql_connect($dbserver, $dbuser, $dbpasswd) or die('Could not connect to DB server!');
 
  //uh-oh
  mysql_select_db($dbname) or die("Could not connect to database: " . mysql_error());
 
  //Grab news posts with SQL query
  $query = "SELECT * FROM " . $table_prefix . "posts WHERE forum_id='" . $forum_id . "' ORDER BY topic_id DESC, post_id;";
  $result = mysql_query($query);
  $num = mysql_num_rows($result);
 
  //following function from bizzar.ssi
  // Find BB code, and replace with desired text. Supported so far: B, I, U, S, URL, IMG, COLOR, QUOTE, CODE
 
  function replace_bb_code($text)
  {
      $text = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $text);
      $text = preg_replace("#\[b\](.+?)\[/b\]#is", "<b>\\1</b>", $text);
      $text = preg_replace("#\[i\](.+?)\[/i\]#is", "<i>\\1</i>", $text);
      $text = preg_replace("#\[u\](.+?)\[/u\]#is", "<u>\\1</u>", $text);
      $text = preg_replace("#\[s\](.+?)\[/s\]#is", "<s>\\1</s>", $text);
      $text = eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $text);
      $text = eregi_replace("\\[url=([^\\[]+)\\]([^\\[]*)\\[/url\\]", "<a href=\"\\1\" target=\"_blank\">\\2</a>", $text);
      $text = eregi_replace("\\[img\\]([^\\[]*)\\[/img\\]", "<img src=\"\\1\">", $text);
      $text = eregi_replace("\\[color=([^\\[]+)\\]([^\\[]*)\\[/color\\]", "<font color=\"\\1\">\\2</font>", $text);
      $text = eregi_replace("\\[quote\\]([^\\[]*)\\[/quote\\]", "<br><br><strong>Quote:</strong><table width='80%' border='0' cellspacing='0' cellpadding='3'><tr><td bgcolor='#EFEFEF'><font color='#000000' size='-2'>\\1</font></td></tr></table><br>", $text);
      $text = eregi_replace("\\[code\\]([^\\[]*)\\[/code\\]", "<br><br><strong>Code:</strong><table width='80%' border='0' cellpadding='3' cellspacing='0' bgcolor='#FFFFFF' style='border:1px solid gray;'><tr><td bgcolor='#FFFFFF'><font color='#009900' size='-2'>\\1</font></td></tr></table><br>", $text);
      return $text;
  }
 
  //Array to store the news
  $newsitems = array();
  $one = "1";
 
  //How many posts do you want?
  $newsdisplay = "10";
 
  //Time to get the posts
  while ($row = mysql_fetch_array($result)) {
      //Has the amount of posts to be displayed been reached?
      if ($one <= $newsdisplay) {
          //Set some variables for future reference
          $current_topic = $row['topic_id'];
          $current_post_id = $row['post_id'];
          $current_subject = $row['post_subject'];
         
          //Query the database for the username from the user id
          $useridquery = "SELECT * FROM " . $table_prefix . "users WHERE user_id='" . $row['poster_id'] . "';";
          $useridresults = mysql_query($useridquery);
          $useridrow = mysql_fetch_object($useridresults);
         
          //Has the subject already been posted?
          //If so, do nothing
          //The first post is the original, so we have nothing to worry about
          if (in_array($current_topic, $newsitems)) {
              echo "";
              echo "";
          } else {
              //Hmm... It's not in the array, so we'll put it there so it's not repeated
              array_push($newsitems, $row['topic_id']);
             
              //Extra parsing where bbcode function doesn't parse
              $message = str_replace("\n", '<br />', replace_bb_code($row['post_text']));
              $message = str_replace("[size=", "<font size=\"", $message);
              $message = str_replace("[url=", "<a href=\"", $message);
              $message = str_replace("[/size]", "</font>", $message);
              $message = str_replace("[/url]", "</a>", $message);
              $message = str_replace("[marquee]", "<marquee>", $message);
              $message = str_replace("[/marquee]", "</marquee>", $message);
              $message = str_replace("]", "\">", $message);
              $message = str_replace("jpg\">", "jpg\" alt=\"\" />", $message);
             
              //echo out the news in a fancy schmancy table
              echo "<hr /><table><tr><td valign=\"top\">";
              echo "" . $current_subject . "</td><td rowspan=\"2\"></td></tr><tr><td valign=\"top\">Posted by <a href=\"/" . $forumpath . "/memberlist.php?mode=viewprofile&u=" . $row['poster_id'] . "\">" . $useridrow->username . "</a> on " . date('l dS \of F Y h:i:s A', $row['post_time']) . "</td></tr>";
              echo "<tr><td colspan=\"2\"><hr />" . $message . "</td></tr></table>";
              echo "<hr width=\"100%\"/><br />";
              echo "<div align=\"right\"><a href=\"/" . $forumpath . "/posting.php?mode=reply&f=1&t=" . $current_topic . "\">Reply</a> || <a href=\"/" . $forumpath . "/viewtopic.php?f=1&t=" . $current_topic . "\">Replies/Comments</a></div>";
              echo "<br /><br />";
              //Time to make sure that the amount of news posts to be displayed will be reached.
              $one++;
          }
      }
  }
//credits (You are welcome to take this line out, but I would rather you didn't, so more people can find this mod)
echo('PHPBB3 MOD by <a href="http://www.uranet.net/">cruddpuppet</a> of <a href="http://www.n-etwork.com/">N-etwork</a>');
?>
I modified this part of file, and replaced it with the corresponding chunk of code in the config.php file in the root level of my forum:

Code: Select all

  $dbms = 'mysql';
  $dbhost = 'localhost';
  $dbport = '';
  $dbname = 'put your forum database name here';
  $dbuser = 'put the user name for your database/website here';
  $dbpasswd = 'put your password here';
2. After that, I actually had to convert my entire website to .php, since it had been using only .html files. This was pretty simple, though. I just replaced each of my .html and .htm extensions with .php, and then, to preserve all the incoming links to my site, I added this line of code to the .htaccess file in the root level of my website, so that every time someone tries to load one of my old .html files, they'll automatically get the .php version:

Code: Select all

RedirectMatch permanent ^(.*)\.htm(l?)$ $1.php
Note: if you don't already have a file called .htaccess on your server, you can just create one in a plain text editor and upload it to your server. There is no code required within the .htaccess file, just add the specific lines that you need.

3. Then I was ready to add the php insert to my web pages. I added this code to my template file, so that in my website the forum news links appear on every page, but you can just add it wherever. So insert this where you want the news links to show up:

Code: Select all

  <?PHP 
  include("http://www.blamesociety.net/forum/news.php");
  ?>
Note: obviously, replace blamesociety.net/forum/ with the actual path to the news.php file on your server.

4. Because on my site I don't want to display the entire text of each post, I made a modification to the news.php file so that only the topic title and a link to each post would appear on my web pages. Also, I didn't need the table formatting, since I inserted the php include within an existing style sheet style on my website. This is the part of the code that I modified:

Code: Select all

              //echo out the news in a fancy schmancy table
              echo "<hr /><table><tr><td valign=\"top\">";
              echo "" . $current_subject . "</td><td rowspan=\"2\"></td></tr><tr><td valign=\"top\">Posted by <a href=\"/" . $forumpath . "/memberlist.php?mode=viewprofile&u=" . $row['poster_id'] . "\">" . $useridrow->username . "</a> on " . date('l dS \of F Y h:i:s A', $row['post_time']) . "</td></tr>";
              echo "<tr><td colspan=\"2\"><hr />" . $message . "</td></tr></table>";
              echo "<hr width=\"100%\"/><br />";
              echo "<div align=\"right\"><a href=\"/" . $forumpath . "/posting.php?mode=reply&f=1&t=" . $current_topic . "\">Reply</a> || <a href=\"/" . $forumpath . "/viewtopic.php?f=1&t=" . $current_topic . "\">Replies/Comments</a></div>";
              echo "<br /><br />";
              //Time to make sure that the amount of news posts to be displayed will be reached.
              $one++;
See my post above to see how I changed this code for my site.

5. Finally, in my case my website is mirrored on two separate servers, with my forum on one of those servers. So I added another line of code to the .htaccess file at the root level of the server that doesn't have the forum on it. This is a workaround, to get the automatically-generated topic links to switch servers so that they link up to the forum properly. If you're putting the php insert code on a different server than where your forum resides, you'll want to do this (or some other workaround or code rewrite), and instead of blamesociety.net/forum you'll put the address of your own forum:

Code: Select all

redirect /forum http://www.blamesociety.net/forum
I hope this is helpful.

xxxgamer
Registered User
Posts: 574
Joined: Mon Jul 16, 2007 11:25 pm

Re: [BETA] Display posts anywhere

Post by xxxgamer » Mon Aug 20, 2007 7:57 pm

hey thanks for posting your way of doing it!
I followed your instructions very closely and went over it again and again to see if i have any mistakes but i get these errors when i look at my page then:

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource 
and:

Code: Select all

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource 
anyone know how to fix this issue?

Tona
Registered User
Posts: 23
Joined: Sat Apr 16, 2005 4:45 pm
Contact:

Re: [BETA] Display posts anywhere

Post by Tona » Mon Aug 20, 2007 11:11 pm

Hm, well I just realized there was another part of the news.php file that I edited:

Code: Select all

 //table prefix, came from when you installed phpbb3. phpbb3_ is the default.
  //Also can be found in config.php
  $table_prefix = 'phpbb3_';
 
  //Relative path to your forum
  //NO BACK/FRONT SLASHES, PLEASE
  $forumpath = "forum";
 
  $acm_type = 'file';
  $load_extensions = '';
 
  //Forum ID from where to grab the news
  $forum_id = "1";
You'll need to customize some of those variables for your website/database as necessary. If you haven't done that already, maybe that's the source of the error, because it's not communicating with the database properly?

xxxgamer
Registered User
Posts: 574
Joined: Mon Jul 16, 2007 11:25 pm

Re: [BETA] Display posts anywhere

Post by xxxgamer » Mon Aug 20, 2007 11:31 pm

no i definitly took all the right information and filled it in from the config! hmm..maybe the author of this can help me a little?

xxxgamer
Registered User
Posts: 574
Joined: Mon Jul 16, 2007 11:25 pm

Re: [BETA] Display posts anywhere

Post by xxxgamer » Tue Aug 21, 2007 2:41 pm

tona did you change anything with the actuall sql database?

Tona
Registered User
Posts: 23
Joined: Sat Apr 16, 2005 4:45 pm
Contact:

Re: [BETA] Display posts anywhere

Post by Tona » Tue Aug 21, 2007 4:17 pm

Nope, nothing. .... just upgraded it to phpbb3 when I installed the 3.0 release of the forum. But that was before doing anything with this mod.

User avatar
Handyman`
Former Team Member
Posts: 1751
Joined: Thu Feb 03, 2005 8:44 pm
Contact:

Re: [BETA] Display posts anywhere

Post by Handyman` » Tue Aug 21, 2007 9:08 pm

xxxgamer wrote:no i definitly took all the right information and filled it in from the config! hmm..maybe the author of this can help me a little?
I'm not sure what exactly you are trying to do, but my script definitely doesn't use mysql specific functions… it uses the dbal.
http://startrekguide.com My Mod Queue || 1/16/10 Display Posts Anywhere 1.2.0 RC5, Cash MOD 1.0.0 b1, MOD Version Check, AJAX Chat, SEO MOD, AJAX QR, Photo Gallery
MOD Development Manager (version 0.2.0-dev with MODX Generator)

xxxgamer
Registered User
Posts: 574
Joined: Mon Jul 16, 2007 11:25 pm

Re: [BETA] Display posts anywhere

Post by xxxgamer » Wed Aug 22, 2007 12:00 am

well do you know what could be giving me those errors?
Thanks for reading

User avatar
Handyman`
Former Team Member
Posts: 1751
Joined: Thu Feb 03, 2005 8:44 pm
Contact:

Re: [BETA] Display posts anywhere

Post by Handyman` » Wed Aug 22, 2007 2:50 am

xxxgamer wrote:well do you know what could be giving me those errors?
Thanks for reading
I have no idea… it's not from my script.
http://startrekguide.com My Mod Queue || 1/16/10 Display Posts Anywhere 1.2.0 RC5, Cash MOD 1.0.0 b1, MOD Version Check, AJAX Chat, SEO MOD, AJAX QR, Photo Gallery
MOD Development Manager (version 0.2.0-dev with MODX Generator)

Locked

Return to “[3.0.x] MODs in Development”