phpBB recent posts widget

On a language website that I maintain I recently switched to a full-fledged phpBB forum from a previous solution that included a comment box on every page, provided by the online service Disqus.

phpBB is the classical choice for forum software, it is open source, based on php (as the name suggests), well supported, with a lot of information scattered around on the internet, with many useful extensions and a bewildering amount of parameters to be configured.

Here are some of the pros/cons of phpBB that I noticed in comparison to the previous set-up I used:
+ More control over the content, the comments are now stored on my server
+ Better organization of topics, possibility to move messages from one thread to another, the accumulated threads serve as some sort of knowledge-base
+ More fine-grained user permissions and moderating options. While this is useful, I would be happier with some sane defaults, as it takes quite a lot of time to play around with all these settings, to little visible benefit to the users.
+ Better integration: I can customize phpBB to closely match the looks of my site, more so than with the widgets I used previously
+ Users can create user accounts within my site
+ Since phpBB has been around for ages, most people are comfortable using it
A lot of time wasted setting up, configuring, customizing, upgrading, etc. the software
A lot of time wasted fighting spam. While there are many half-solutions available, in this regard running your own forum is clearly inferior to a centralized service like Disqus
The look and feel of the forum is slightly heavy-weight and outdated (not too web2.0-y). This is not a big problem, as it is familiar even to non-technical people.
Higher threshold for commenting. Although I tried to keep registration requirements, rules, captcha’s to a minimum, the number of messages written is somewhat smaller than in the previous system. However, the posts are longer, usually more substantial and better organized, so this is actually a +.

All in all I am quite happy with phpBB, even though it is not nearly as minimalistic as I would prefer it to be. One thing, however, that I was still missing from the Disqus days is a recent posts widget. This would be embedded on a different page than the actual forum (for example on the front page) and it would show the most recent 5-10 posts that were written in the forum. As I found no obvious ready-made solution, I wrote my own, which was not very difficult, as the database structure of the forums is quite straightforward.

You can download it below, with some explanation on how to install it. Let me know if you find it useful, or if you make any improvements to it. I spent about as much time putting it together, as it took me to write this post, so it is really nothing fancy. It is released under the WTFPL license, which means that you can … well, you know.

Installation

Put the following line in the web page where you want the recent comments to appear:

<div id="recent-widget"></div>

And somewhere later in the same file (preferably just before the closing </body> tag):

<script type="text/javascript">
httpRequest("recent-widget.php", showrecent);
function showrecent(WIDGET){
 d = document.getElementById('recent-widget');
 d.innerHTML = WIDGET;
}

function httpRequest(url, callback) {
  var httpObj = false;
  if (typeof XMLHttpRequest != 'undefined') {
    httpObj = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try{
      httpObj = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
      try{
        httpObj = new ActiveXObject('iMicrosoft.XMLHTTP');
      } catch(e) {}
    }
  }
  if (!httpObj) return;
  httpObj.onreadystatechange = function() {
    if (httpObj.readyState == 4) { // when request is complete
      callback(httpObj.responseText);
    }
  };
  httpObj.open('GET', url, true);
  httpObj.send(null);
}
</script>

This will load the recent-widget.php file that writes the actual widget and put the output into the HTML file. Upload this on your server, so that it is accessible from your main page. The only advantage to this javascript-loader is that you can easily display the same widget on many different HTML pages. Otherwise you could simply put the stuff from recent-widget.php into your own php files.

Here is the recent-widget.php

Before you upload it, you have to modify some things in it that are about the access to the forum database and links to the forum itself and you can modify other things, like the actual layout, colors used, number of posts, etc. See the TODO comments in the file for more information. This assumes that you are running phpBB with MySQL, but if you run some other database, such as SQLite, it should still be easy to modify. Obviously, this whole widget is nothing too complicated, so even if you never programmed in php, or seen an SQL query before, it is still a decent way to learn if you tweak it to work.

Note: this widget is provided without any guarantee – unfortunately, due to lack of time, I am unable to provide support for it. You might find some useful information in the comments below.

77 comments ↓

#1 Sean on 07.07.11 at 10:12 am

Thanks for the widget! It works great.

I have one question–the widget can’t parse emoticons, it returns this:

s:? –> (broken image) s:? –>

Any thoughts? I’m fine with it not being able to display the emoticons themselves, but it would be nice to just not display anything.

#2 lkozma on 07.09.11 at 8:37 pm

I made some small changes now, cleaning up a small portion of the code (the whole thing could use a rewrite), so now the part that removes the BBCode formatting are the lines starting with $ppost = …

After the last such line, you can add further commands if some unwanted stuff still remains in the text (such as the smiley you mention).

For example, for removing s:? you can add:
$ppost = str_replace(“s:?”, “”, $ppost);

There’s probably a systematic way of removing all BBCode smileys, if someone contributes, I’ll be happy to add it.

I didn’t get the broken image part. Is it written like this in words, or a broken image icon appears in the widget or you just mean that the smiley icon is missing?

#3 Sean on 07.26.11 at 6:46 am

I’m getting an actual broken image, not the words (broken image).

I’ll test out your new version now. Thanks so much for the response!

#4 Sean on 07.26.11 at 7:30 am

Thanks man, the cleaned up code works awesome! Here’s what I used to clean up all of my errant smilies and broken images:

$ppost = str_replace(“”, “”, $ppost);
$smilies = array(“s:D”, “s:)”, “s;)”, “s:(“, “s:P”);
$ppost = str_replace($smilies, “”, $ppost);
$ppost = preg_replace(“”,””,$ppost);

Just added all of the offending smilies to an array and removed them with an str_replace in the next line.

Also used a preg_replace to kill the broken images.

Works great!

#5 Johnny Hastings on 08.08.11 at 7:20 pm

Thanks very much for posting this! I was able to use it as a very solid starting point for a recent posts widget on my site. Much appreciated.

#6 Bethany on 09.20.11 at 3:45 pm

Can anyone help me out with this? I really like what this script can do, but I don’t like that one topic name could potentially be returned so many times while a thread is popular. Is there any way to make it so that a thread only appears once on the list, and is just bumped to the top when someone posts on it again? Does that make sense?

#7 lkozma on 09.22.11 at 9:27 pm

@Bethany: good idea, makes a lot of sense.

A quick & dirty solution is the following:

in the long line that starts with “$result = ”

insert ” group by tid ” (without quotes) just before “order”.

So you will have something like:
…user_id group by tid order by post_time…

Hope it works…

#8 Bethany on 09.23.11 at 10:20 am

Works perfectly. Thanks for your response and time. Very helpful. ;D

#9 Jim on 09.24.11 at 9:06 pm

Any way to link directly to the post, instead of linking to the thread?

#10 Jim on 09.24.11 at 9:38 pm

Also, I tried your group by fix, and it now only returns one post/topic.

Query: select phpbb_posts.post_time as post_time, phpbb_posts.post_text as post_text, phpbb_posts.topic_id as tid, phpbb_posts.forum_id as fid, phpbb_topics.topic_title as topic_title, phpbb_users.username as username, phpbb_posts.post_username as anon from phpbb_posts, phpbb_topics, phpbb_users where phpbb_posts.forum_id != 14 and phpbb_posts.forum_id != 15 and phpbb_posts.forum_id != 30 and post_approved=1 and phpbb_posts.topic_id=phpbb_topics.topic_id and phpbb_posts.poster_id=phpbb_users.user_id group by tid order by post_time desc limit 8;

#11 Bethany on 10.01.11 at 3:26 pm

I swear it was working fine for me before… but that’s impossible. o_O I’m really confused. Because now I’m having an issue where… let’s see. I THINK it’s showing the most recent CREATED threads, but not the most recent posted in threads?

Sorry to be a bother, but do you have any thoughts on this?

#12 Rune on 10.03.11 at 3:18 pm

Looks like this one doesn’t take permissions into matter. At least I still can see the officers posts when I’m logged out.

Can you confirm/deny this please?

Else, thanks for a great widget! :)

#13 Jim on 10.04.11 at 7:55 pm

@rune, I dont think it is possible to hide specific user group’s posts, but you can hide posts in a particular forum. Just add this to your WHERE clause:

phpbb_posts.forum_id != 14

so WHERE phpbb_posts.forum_id != 14 AND phpbb_posts.forum_id != 15

#14 lkozma on 10.09.11 at 6:32 pm

@Rune:
indeed, the widget as it is now ignores permissions.

@Jim:
Thanks for the workaround.

The description of the phpbb tables structure can be found at http://www.phpbbdoctor.com/doc_tables.php so other smaller modifications should not be too difficult.

#15 lkozma on 10.10.11 at 7:42 pm

@Bethany:

Yes, the simple change that I sent earlier did not show the most recent post from threads but _any_ post from the most recently modified threads. I know this is not the best, so I added the query now which should do exactly what you want, i.e. show the five most recent posts from the five most recently edited threads (one post from each thread).

I added the line to the recent-widget.php, but I copy it here as well (this should replace the quoted part in the line starting with $result=…)

“select phpbb_posts.post_time as post_time, phpbb_posts.post_text as post_text, phpbb_posts.topic_id as tid, phpbb_posts.forum_id as fid, phpbb_topics.topic_title as topic_title, phpbb_users.username as username, phpbb_posts.post_username as anon from phpbb_posts, phpbb_topics, phpbb_users where post_id IN (select * from (select max(post_id) as mpt from phpbb_posts group by topic_id order by mpt desc limit 5) alias ) AND post_approved=1 and phpbb_posts.topic_id=phpbb_topics.topic_id and phpbb_posts.poster_id=phpbb_users.user_id order by post_time desc;”

Note that the “limit 5″ is now towards the middle of the query, rather than the end, so if you want to change it to show, say, 10 newest posts, change it there.

Aside: before some MySQL expert jumps at me that this is inefficient because of the triply nested “select”, let me say that this query actually seems to be faster than the previous one, which makes sense if you think a bit about what might happen behind the scenes.

#16 Bethany on 10.11.11 at 9:29 am

I’m sorry to be a bother. Thanks so much for your help. It’s been invaluable. <3

#17 Søren on 06.23.12 at 10:26 am

How do i target the smilie folder, so i don’t get the broken image?

#18 Brandon on 11.01.12 at 8:32 pm

@Jim (if you’re still around) or anyone that can help me.

I seen his post about hiding certain forums but I am pretty new to coding. I’m not sure where to add the lines to hide certain forums.

phpbb_posts.forum_id != 14 AND phpbb_posts.forum_id != 41

Those are the 2 forums I want to exclude from the list. Where exactly in the PHP do I add those?

I tried a few places but it didn’t work.

If anyone could direct me in the right direction to where to place those, it would be great.

Thanks,
Brandon

#19 lkozma on 11.01.12 at 9:05 pm

Dear Brandon,

you can add such code for excluding certain forums in the line containing the SQL query. In the code I provided, that is the line starting with $result = mysql_query(” …

Towards the middle of that line there is a “where”, and after that a list of conditions, such as

post_approved=1 and (another condition) and (yet another condition) …

add your two new conditions after the last condition, that is right before the “order by” part.

Hope this helps.

#20 Brandon on 11.01.12 at 11:46 pm

@ikozma, thank you very much for the help!

I got the coding to actually work but when I put the code Jim told someone else to use to exlude forums from the list, it actually only included them instead.

Here is what I have.

where post_approved=1 and phpbb_posts.topic_id=phpbb_topics.topic_id and phpbb_posts.poster_id=phpbb_users.user_id group by tid and phpbb_posts.forum_id != 14 and phpbb_posts.forum_id != 41 order by

The last 2 (id = 14 and 41). Is the coding wrong for them?

Thanks again!

#21 Brandon on 11.02.12 at 12:27 am

Sorry, I would edit my last post but I can’t.

From what I actually see is that when I add that code in, all the forums disappear from the list. Almost as if it excluded everything.

#22 lkozma on 11.02.12 at 7:36 am

Try it with <> instead of !=.

#23 Rob on 01.10.13 at 7:54 am

I made a long post and it wouldn’t send, so I am testing with a short one

#24 Rob on 01.10.13 at 7:55 am

Here’s my problem – The recent-widget is pulling in the entire page that it’s on, from Logo to Footer!! No sign of anything from the Forum.

I’ve gone wrong somewhere, hope someone can help?
I can access both databases in PhpMyAdmin
The PHPBB forum is in a Folder on my WordPress site
Wordpress is in the root folder http://www.mydomain.com
The Forum url is http://www.mydomain.com/Forum

#25 Rob on 01.10.13 at 7:56 am

Part Two –
I have given the Id ‘recent-widget’ a height , a border and overflow:scroll and put the div in the actual wordpress page. Before that I had the div in the page template and the page was broken and looked crazy.

The script is in a special page template ‘frontpage’ and I added it to the php file after ” and before the next container “”

I have filled in the six TODO’s and put the ‘recent-widget’ file in the same folder as the pages.

I replaced nebulo.ro on the 5th TODO to
a href=’http://americancarclubcairns.com/Forum/viewtopic.php…..etc

I can’t code in PHP, v good in HTML and CSS.
I have edited a lot of JS and PHP by copying etc.

Where did I go wrong???

Rob

#26 lkozma on 01.10.13 at 8:28 pm

@Rob: The problem is probably with the access path to the recent-widget.php file. After you filled in the TODOs, you need to upload it onto your site, and if it is not in the root folder, you need to put the correct path in the HTML file in the line:
httpRequest(“recent-widget.php”, showrecent);

Currently if I try to access it under http://americancarclubcairns.com/recent-widget.php
I get the wordpress error page, which is probably what appeared instead of the widget.

#27 Rob on 01.11.13 at 2:07 am

Thanks for the fast reply, much appreciated.
FYI – I am building a new theme so when not working on the website, I reactivate the old theme. When I’m working on it, the website is hidden by a maintenance page.
I have now uploaded recent-widget.php to the root and received this error message-
DB selection error

Here are the 4 TODO’s
$db_host = ‘localhost'; // TODO: put here your database host name
$db_user = ‘american_phpb945′; // TODO: put here your database user name
$db_pwd = ‘xzxzxzxzxzz'; // TODO: put here your database password
$database = ‘phpbb_forums'; // TODO: change here if your forum database name is something else than phpbb_forum
In the phpbb config file the forum name and the user are the same –
$dbms = ‘mysql';
$dbhost = ‘localhost';
$dbport = ”;
$dbname = ‘american_phpb945′;
$dbuser = ‘american_phpb945′;
$dbpasswd = ‘xzxzxzxzxz';
$table_prefix = ‘phpbb_';
$acm_type = ‘file';
$load_extensions = ”;

(I’ve changed the password of course)

For the 4th TODO I changed that to ‘phpbb_forums’ plural, because that’s what I see in PhpMyAdmin- but no luck, same error message with forum or forums.

I think I’m nearly there – what have I got wrong?

#28 Rob on 01.11.13 at 2:14 am

FIXED!!

I changed the 4th TODO phpbb_forums to $database = ‘american_phpb945′; and I have forum posts showing

THANK YOU very much for writing this script. I had tried a wordpress plugin but was unable to get it to work.

Rob, from
Cairns
Australia

#29 Rob on 01.14.13 at 3:15 am

Something weird happening with IE !!
The recent posts show on first load, but there’s just a vacant space when refreshing ALT+5F or coming back from a different page. Using IE9 – haven’t checked other versions
It shows in Chrome, FF, and Opera- refresh etc all OK

I had made some changes, so I uploaded the original,’recent-widget.php’, filled in the passwords etc and checked, still not displaying in IE

This is an up to date WordPress installation.
I created a special page for it – frontpage.php which was a copy of page.php with the addition of the script at the beginning, but there’s no head it’s all body.
and the is the first thing to display after the content area starts –

etc

IE doesn’t like something – could it be the script in the body ?
Any suggestions?

#30 Rob on 01.14.13 at 3:19 am

There are some words missing from my post above – after ‘no head it’s all body’- next lines should be –
and the recent posts div is the first thing to display after the content area starts –

etc’

#31 lkozma on 01.15.13 at 8:01 pm

@Rob: I think I see what is the problem. When IE tries inserting the widget using the script, the page is not completely loaded yet. I’m not sure why this only affects IE and why not on the first load as well, but I think the following should fix it:

try putting the part starting with < script… more towards the end of your HTML file, preferably right before the closing …/body > . Since you use WordPress, this might be tricky, depending on the theme and configuration. You could try putting it on the sidebar, using an invisible Text widget. Just configure it somehow, so that it appears only on the front page.

Otherwise try to find a way to put the code in the footer.
There might be a clearer way, but what probably works is simply editing the footer.php file of your template. Then again you should ensure that the code is run only on the front page and not on every page containing the footer. You can do that as follows. Write (somewhere in footer.php):

<? if (is_home()) { ?>

…the part with <script… until …/script>

<? } ?>

Let me know if it works.

#32 lkozma on 01.15.13 at 8:06 pm

@Rob: Just to clarify, only the script part ( <script…. /script> ) should go either into the sidebar or the footer, the <div id=… part can stay where it is.

#33 Ron on 01.21.13 at 11:04 am

Hi, Is it in any way possible to get this great widget to work for every forum seperate?
Now it shows the latest posts over the whole board/forum, but I have different forum subject and would like each forum subject to have it own recent post list. Simular as is possible with the forum rules.

#34 Ron on 01.21.13 at 11:21 pm

Hi again,

I solved my above question (for my needs anyway).
I replace

viewtopic.php?f=”.$row[‘fid’].”&t

with e.g.

viewtopic.php?f=2&t

and then do the exclude forum(s) (basically is all other forums, except id=2), as mentioned above somewhere, in the

$result = mysql_query

Then I have made different recent-widget.php(s),
e.g. recent1.php, recent2.php and so on.
Now I just directly link to the recent1.php (target blank) and get the recent posts ONLY from forum-id-2 IF excluded ALL other forum in the $result = mysql_query.

Just put some html in the recent.php(s) to have it look like a real page. Like this I can pull 25-50 most recent posts per forum, which is what I needed anyway, so for me it is a great solution.
You can create a dropdown menu for it or whatever.
You do NOT need the script anymore,
just the recent-widget.php

#35 Ron on 01.21.13 at 11:38 pm

Continue from above.

A question:

Is it somehow possible to exclude a bunch of forums with a string of using only the numbers/ids (after something else),
so now it is like
phpbb_posts.forum_id != 3 and phpbb_posts.forum_id != 4 and phpbb…..

Could it be somehow phpbb_posts.forum_id != 3+4+5+6 ?

Question2:

in the $result = mysql_query (I use the first string) is it possible to have the POST name subject and not the TOPIC name subject. Now if someone did 2 replies they both show the topic name subject even if for a reply the subject was changed (normal would be Re: ….), but I my forum setup, people would actually chance the subject in a reply.

Hope someone can help, especially question 2.
Although I “solved” my very first question, these other 2 questions are way above my capabilities.

Thanks, Ron

PS. Sorry I can not give the URL to the forum. It is part of a very large project, that needs to stay as much as possible invisible until it is ready for launch (eta April 2013).
After the launch I will be happy to post the URL here.

#36 Ron on 01.22.13 at 12:13 am

OK, 1 more remark for noobs like me,

The above mention replacements for images, smilies strange letter/number combinations is (for me) not working.

Just found out that just use the 2 strings that are already in the php

$ppost = str_replace(“”, “”, $ppost);

and if you have an image and get:

ai0 imagename.jpg ai0

just add a line like
$ppost = str_replace(“ai0″, “”, $ppost);

and you just get imagename.jpg

also works for smilies

#37 lkozma on 01.22.13 at 12:20 am

@Ron: thanks for the comments and suggestions, I’m sure it will be helpful for others who are modifying the script. As for the yet unsolved questions:

Q1: if it is contiguous numbers that you want to exclude, you can write something like:
( (phpbb_posts.forum_id < 3) OR (phpbb_posts.forum_id > 6) )

#38 lkozma on 01.22.13 at 12:38 am

@Ron:
Q2:
the field name that you are looking for is
phpbb_posts.post_subject

A quick and dirty solution is to change the following in the query string that you use:
replace
“phpbb_topics.topic_title as topic_title” with
“phpbb_posts.post_subject as topic_title”.
This has to be changed in one place only. Let me know whether it works.

#39 Ron on 01.22.13 at 1:29 am

Thanks lkozma,

Q2 works like a charm, excellent, thanks.

Q1 not sure have not tried it yet, because need to create a few more test forums for it, to try it.
But for example:
If I want the recent posts to show from forum number/id=10,
I need to exclude everything 10, which are contiguous numbers, so would it be:

( (phpbb_posts.forum_id 10) )

Since you put a BIG CAPITAL OR, my guess is either one or the other, or not? Does it need to be between the ( (… or …) ), so exactly as you posted?

Yes, sorry a question 3, as mentioned in the beginning of the comments, broken images “image” I just noticed:
In FireFox no problem, in Chrome and IE I get the broken image symbol (from smilies), normal attachments are OK.

I tried the $ppost = preg_replace(“”,””,$ppost); as Sean mentioned, but that just gives an error:
Warning: preg_replace() [function.preg-replace]: Empty regular expression in home/………. on line 97 (is the preg_replace line)

Thanks again.
It is amazing the support you give here!

#40 Ron on 01.22.13 at 1:34 am

In the above message, code got deleted, so for Q1, a bit simpler without code.
I need recent post from forum id=10
so need to exclude all below id=10 and all above id=10

#41 lkozma on 01.22.13 at 9:25 am

@Ron:

if you want to exclude a single forum, you can use the line you wrote earlier, something like:
phpbb_posts.forum_id != 3
if you want to exclude multiple forums, you can put all of them, separated by AND’s, as in:
(phpbb_posts.forum_id != 3) AND (phpbb_posts.forum_id != 4) …

if you want to exclude multiple forums with continuous id’s, you can use my earlier solution with OR, the idea is that if the id is not allowed to be 3,4,5,6, then it is either below 3 OR above 6.

#42 lkozma on 01.22.13 at 9:47 am

@Ron:
I think in Sean’s solution above some of the code disappeared from the comment.
In preg_replace and str_replace as it is above, you should put in the first string what you want to remove. However, str_replace is for exactly matching strings and preg_replace is for regex patterns.

If you want to remove all filenames ending in .jpg, you can use something like:

$ppost = preg_replace(“/[\w\-]+\.jpg/”, “”, $ppost);

This should replace all filenames ending in .jpg, but I haven’t really tested it. Also it doesn’t bother with path names, so it might need some more tweaking.

#43 Ron on 01.22.13 at 12:11 pm

Thanks lkozma,

Your code to remove image filenames works, so now all mention to any images are gone.

I only still had the broken image from smilies in Chrome and IE (as mentioned FireFox did not have it).

I found the solution for that also. Got to love Firebug sometimes to get 100% clear what is in the code.

Anyway, I got rid of the broken images symbol by doing a simple replace, (hope the code stays, if not maybe this stays:
{SMILIES_PATH}/ )

$ppost = str_replace(“{SMILIES_PATH}/”, “”, $ppost);

Will get back to the forum id exclude later.

Thanks again, Ron

#44 Ron on 01.22.13 at 12:15 pm

PS. Also maybe a note for noobs.
Any code posted here will have the ” ” in italic, be sure to remove/replace does with non italic

#45 Ron on 01.22.13 at 12:25 pm

OOPS, correction,

$ppost = str_replace(“{SMILIES_PATH}/”, “”, $ppost);

works for Chrome browser
NOT for IExplorer, so guess I am half a smiley now.
I wish people would stop using IE anyway, it is the worst browser ever.

No idea what it does with Safari of course or Opera.

and of course IE does not have Firebug.

#46 lkozma on 01.22.13 at 12:33 pm

@Ron:

note that the php code runs on the server, so it produces the same output regardless of the browser. What might differ is how each browser renders this output. What you can do to debug is to open just the recent-widget.php file in the browser, by typing the correct url in the browser, and then look at the HTML source of the page. There you will see what is the data that is actually being displayed, and whether there is some artifact that causes the broken image symbol. It could be for example, that there is some “<img src=… ” HTML stuff that is still there, and you might try to clear that up also with str_replace.

#47 Ron on 01.22.13 at 12:47 pm

Yes, I just wanted to post this, but IE keeps having problems, clear in the source code.
This is what is left of the smiley code:

“”

I tried to remove also img src and others, but either error or still a broken image in IE.

I think the prolem is the “” that needs to be removed, but that creates a php error, if I put those in a replace code, since the replace code uses them itself.

Very Happy would then of course the a wildcard in any code, which might get rid of the rest.

#48 Ron on 01.22.13 at 12:48 pm

img src=”” alt=”” title=”Very Happy” /

and then in between the url arrows

#49 Ron on 01.22.13 at 1:02 pm

As soon as I do a replace with img src, yes the broken image is gone, but then in ALL browsers it shows:

=”” alt=”” title=”Very Happy” /
and then in between the url arrows

So how to remove everything, with Very Happy being a wildcard, because that changes per smiley

#50 lkozma on 01.22.13 at 1:02 pm

If you want to replace something that has double-quotes (“) in it, you can put the whole thing in single quotes (‘) to avoid clashes. So, say you want to replace:
img src=”” alt=””
then the command is:

$ppost = str_replace(‘img src=”” alt=””‘, ”, $ppost);

This should work, but please look up this kind of stuff in the php documentation on different functions and/or sites like stackoverflow.

#51 lkozma on 01.22.13 at 1:08 pm

For the wildcard thing you need preg_replace, and the first string should be something like:
$ppost = preg_replace(‘/<img.*src=”(.*?)”.*?>/’,””,$ppost); (watch out that all the quotes are right)

Actually this is the only thing you should do and not the previous jpg-stuff, this replaces all “img src” stuff with filename and all.

For your own good, please look into regex and preg_replace documentation, it will help you in the future.

#52 lkozma on 01.22.13 at 1:32 pm

for your previous question, to replace <img src=”” alt=”” title=”wildcard”>
try:
$ppost = preg_replace(‘/<img src=”” alt=”” title=”[^”]*”>/’,””,$ppost);
(watch out that all the quotes are right)

the part [^”]* means “anything but quotes”

#53 Ron on 01.22.13 at 1:41 pm

OK, I will give that a try.

I have been Googling, that is why I got as far as I am now and thanks to you of course, mostly.

This is my first time ever with these codes in php and looked like abadacrabra to me at first, but it is all pure logic and learning.

Any way I now have another replace done, which just shows the smilies in the recent posts.

$ppost = str_replace(“{SMILIES_PATH}/”, “http://domain.com/images/smilies/”, $ppost);

a disadvantage with this is, I can not use the replace for gif images, so I will have to look into what you posted above.

#54 Ron on 01.23.13 at 4:11 am

Hi lkozma,

New day, new hope and problems.

I tried your idea for excluding forums (3,4,5,6), is not working.

I now created 8 forums, ID’s 2-3-4-5-6-7-8-9
I tried to get only forum id=7 to show with your OR code.

I tried maybe 10-15 different possibilities with/without () and more, but all either have 1 of 3 results:

1. Most common, I get ONLY forum id=9 to show and it shows 25 times the same post (I set the results to 25 not 5), which is the last post made.

2. No error, but also no recent posts. Yes there is a topic in forum id=7

3. Plain DB error

Now I have the simple WORKING way:

and phpbb_posts.forum_id != 2
and phpbb_posts.forum_id != 3
and phpbb_posts.forum_id != 4
and phpbb_posts.forum_id != 5
and phpbb_posts.forum_id != 6
and phpbb_posts.forum_id != 8
and phpbb_posts.forum_id != 9

Just happy the string allows a new line for easy editing.

Unless you have an other solution, I will stick to the above one, but I think the board will have about 30 forums, so a clean shorter code might be needed.

#55 Ron on 01.23.13 at 4:27 am

New question,

Since I use the first string for the DB query and now also have it show the post name instead of the topic name thanks to you,

Is it possible to have the postname link go directly to the post and not the topic?
Like viewtopic.php?f=9&t=21#p33

I tried to add a little to the URL in the recent.php, but am unable to get the post number (p33) in the link.
My idea was:
&t=”.$row[‘tid’].”#p=”.$row[‘pid’].”
and a few variaties, but no luck yet

#56 Ron on 01.23.13 at 4:38 am

Since I now have the smilies in my recent posts, is it somehow possible to also exclude gif images from being mentioned, because smilies are gif.

A dirty way is to redo all smilies and rename them as giff,
I tried it with a smiley and works.

But maybe you know an official clean solution.

#57 lkozma on 01.23.13 at 8:41 am

@Ron: if you want to remove .gif images, you can do it the same way as earlier with the .jpg images, just change jpg into gif.

For the sql question, if you want to select a single forum_id, just write:
and phpbb_posts.forum_id = 7.

For your last question, the direction is good, but this way of course it doesn’t work, if there is no “pid” field in the query. To make it work, you need to add to the query, in the first part, where different fields are listed separated by comma, the following:
phpbb_posts.post_id as pid

As much as I’d like to further help, I’m afraid that we are getting further away from simple bugfixing in the widget code and this comment box does not allow for detailed discussion.

I really suggest you to look into some simple sql tutorial or book, besides some php material, as it will speed up the development. Cheers, Laszlo.

#58 Ron on 01.23.13 at 9:04 am

As a closing then, I would like to thank you very very much for all your help. Your recent-widget.php added so much to the project I am working on.

The single forum phpbb_posts.forum_id = 7 works great.

The phpbb_posts.post_id as pid also works great and goes straight to the post.

I know how to solve the images/smilies problem.

So basically I am ready with your “script”.

After the project is finished (eta April 2013) I would like to send you the domain (actually 11 domains), so you can see what I was doing and how I use your great “script”.

Also, the idea is that this project will make (loads of) money in time and then I will probably need an experienced programmer/script/php person who can do stuff for a fee/payment.

If you are interested in something like that, let me know and send me an email. Not sure if you can see my email address in this comment box. (rjsticky (at) gmail.com)

Again, many, many thanks and hope to hear from you again.

Ron

#59 George on 02.19.13 at 4:24 pm

Hi,
I am trying to add the forum name to the recent post, so it also shows from which forum the post comes. Like time and poster.
I added to the mysql_query
phpbb_posts.forum_name as forum_name

I added the forum name row in the code (probably wrong ??)

// Forumname
$pforum = ($row[‘forum_name’]);

and added “.$pforum.” to the echo line

I get a DB query error. Honestly I do not really know what I am doing, so a little help is welcome.

#60 lkozma on 02.20.13 at 9:12 am

@George:

1. change “phpbb_posts.forum_name as forum_name” to “phpbb_forums.forum_name as forum_name”

2. add phpbb_forums to the list of tables separated by comma (after “from phpbb_posts, phpbb_topics, phpbb_users” here comes ,phpbb_forums …)

3. to the list of conditions after “where”, that are separated by “and”s, but before the “order by” part, add the following: … and phpbb_forums.forumid = phpbb_posts.forum_id … (without the dot-dot-dot).

Should do the trick.

#61 George on 02.22.13 at 11:18 pm

Thanks for that. I got that working now.
Only number 3 should be:

and phpbb_forums.forum_id=phpbb_posts.forum_id

guess that was just a typo errors you overlooked.

#62 George on 02.26.13 at 2:00 am

Hi Ikozma,

I have one more thing. It is not really a problem, but if it can be easily fixed, it would be nice.

My server is located in the USA, but the forum is not USA based. Therefore the forum time is set to local time, but I noticed that the recent-widget.php puts the server time as timestamp.

Is it possible to have the forum time also as the recent-widget.php time, so that the most recent posts show the local (forum) time and not the USA-server time?

#63 lkozma on 02.26.13 at 8:38 am

@George: This conversion is not hard to do, please Google “php convert timezones”.

#64 George on 03.12.13 at 5:08 am

Thank, that was easy, now I know what to look for.

// Time of post
ini_set( ‘date.timezone’, ‘Asia/Bangkok’ );
$ptime = strftime(‘%A, %d %B %Y at %H:%M:%S’, $row[‘post_time’]);

#65 Paul on 03.19.13 at 2:16 pm

Thanks a lot for the widget, I’ve been looking for a script like this till I found your blog. I have implemented your widget on my site and it works great, there is only a minor problem i encounter the widget don’t show up in IE7 and IE6 but works great on other browser.

#66 Finn on 05.23.13 at 2:51 pm

Thank you for the great widget. I’ve been tweaking things and almost have it to where I want it.

One question. I’m using the 5 most recent topics option, drawn from just one forum. But It’s only displaying the most recent 2 topics.

I suspect that it’s actually posting the 5 most recent created topics, but excluding of those 3 topics because they are in another forum.

Is there a way to have it display the 5 most recent topics from my forum(s) of interest?

#67 Will on 07.17.13 at 11:02 pm

Is everything that you helped people with uploaded as a whole? If so could you make it user friendly by adding a Backend of sorts? I know its completely unnecessary but that would help people like myself who have no experience with php.

#68 [phpBB] Como Mostrar Postagens Recentes No Index ∗ Mario Júnior [Leptossomico] on 08.14.13 at 5:06 pm

[…] procurar, encontrei uma solução simples e realmente eficaz, para qualquer versão do phpBB no blog do programador László […]

#69 Marius on 08.20.13 at 12:50 pm

Hi there,

I get DB selection error. I think I filled in all the names and passwords in correctly.

Do you have any advice?

#70 mathew on 08.27.13 at 6:47 am

Thanks a lot for the code brother. very much useful

#71 Adrian on 09.17.13 at 12:59 pm

Any ideea how to display an exact number of topics/posts? I want to have 15 last topics. Is this possible? Complete noobe at php! Please help.

BTW, the script works like a charm! :)

#72 oSe-Creation on 12.15.13 at 1:04 am

@ lkozma
Really good work thank ya soooo mutch !!!
Well After playing a bit with your code i get the result I wanted !!

Q.

Do you maybe have a little add for this script to give the opportunity to logged user to quick reply to one of the comments !!

I saw that you wasn’t hier since end of february 2013 !! I really hope to read from ya soon cus i just don’t find the write code on myself thank you sooo mutch
Kind Regard oSe !!!

#73 oSe-Creation on 12.15.13 at 2:22 am

@ lkozma

Well about include a quick reply to the right topic under your script i need no more help i finally find the good code on my self but now i still have one probleme …

Q

How do i only shows the topics from a single Forum somrthing like …. where forum_id=17 ????
I try and try again but no way to make it …

#74 oSe-Creation on 12.15.13 at 2:33 am

Well done !!!

So for each of you who need it here it is

Shows only one forum and add quick reply
___________________________________

in file ” recent-widget.php” change the $Result :

$result = mysql_query( “select ose_posts.post_time as post_time,
ose_posts.post_text as post_text,
ose_posts.topic_id as tid,
ose_posts.forum_id as fid,
ose_topics.topic_title as topic_title,
ose_users.username as username,
ose_posts.post_username as anon from ose_posts,
ose_topics,
ose_users where post_approved=1 and ose_posts.forum_id=17 and ose_posts.topic_id=ose_topics.topic_id and ose_posts.poster_id=ose_users.user_id order by post_time desc limit 10;”);

and then go to your page wher you want it to appear and add just under the :

the following code:

//

Quick Reply

Subject:

 
 

of course you will need to change a few lines of the code like those who specifie where your forum is located …

Hope i could help anyone …

#75 oSe-Creation on 12.15.13 at 2:34 am

oh shit the code wasn’t post in the message well who needs help can write me @ script@06rz.com ….

#76 Heidi on 12.29.13 at 9:18 am

Can this be added to the overall header of the forum?

#77 Jay on 01.07.14 at 5:24 am

I am running the bbphp3.012. I installed the files, changed the TODOs to all the right settings. I am getting a “DB Query Error”. After testing it it seems to be at $results, line 36.

My DB info is all accurate:
$db_host = ‘localhost'; 
$db_user = ‘skyforum1′;  
$db_pwd = ‘XXXXXXXX’;   
$database = ‘solutiod_v1’;

The only changes I have made are to the TODOs