1 (edited by cuteseal 2004-06-24 00:36)

Topic: PunNewz

Hi,

I was looking for a simple solution for displaying forum posts on the front page of a site - nothing bloated like bolting on a CMS - but despite searching through the forums, I was unsuccessful.  As a result, I decided to hack the extern.php to do this.

It works pretty much the same way as extern.php works:
- just drop externnews.php into our forum directory, and include (as per extern.php)
- use action=new or active (but it would probably make sense to only use new)
- use fid to limit to one forum only
- Displays first paragraph of text only
- Does parsing of bbcode in text
- uses <div class="..."></div> CSS styles to display different sections.  Define these in your stylesheets to format them the way you want.

newsdateheader = date header for grouping posts by date
newsheading = news heading
newstext = actual post text
newstagline = the poster name and time of post

Todo:
- RSS part doesn't work, I've only done the HTML display at the moment
- Perhaps display posts from multiple forums (category maybe??)
- Improve db queries (I copied and pasted form viewtopic.php)
- Parsing of smilies doesn't quite work - image location is wrong //** Edit This can be fixed by copying the /forums/img/ directory to wherever you plan to use this script


Anyway, let me know how you go with this one.  I'm by no means a php programmer, and as I said before, this is just a hack I put together.  Please feel free to share your knowledge and improve on it (especially the RSS and smilies bit)...


Demo at: http://shuttertalk.com
Download from: http://shuttertalk.com/externnews.zip

Version history:
- 2004-06-02: changed display of posts, and added number of replies
- 2004-06-23: fixed "order by" bug on line 266

Enjoy!
Jules

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

Re: PunNewz

A great idea! I'll check it out tonight.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3 (edited by cuteseal 2004-06-02 00:47)

Re: PunNewz

Ev!L-E!NsTe!N wrote:

I like this moddification a lot btw.. but how can i display the text instead of only the first paragraph?

Hey Evil Einstein, thanks for the comments.

If you want to turn off the one-paragraph truncation, comment out the following block of code in externnews.php: (~line 269)

    // Display first paragraph only
    $paragraph = preg_split("/\s*\n+/", $cur_post['message']);
    if ($paragraph[1]) {
        $paragraph[0] .= "...";
    }

Cheers,
Julian

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

4 (edited by cuteseal 2004-06-02 23:40)

Re: PunNewz

Oops, sorry.. my bad!  Serves me right for releasing untested code.

I've uploaded a new version, please use this one and follow the instructions below:
http://www.shuttertalk.com/externnews.zip

To turn off the paragraph truncation feature:

Comment out the following code (~269):

// Display first paragraph only (comment out next four lines to turn off)
//$paragraph = preg_split("/\s*\n+/", $cur_post['message']);
//if ($paragraph[1]) {
//    $cur_post['message'] = $paragraph[0] . "...";
//}

Let me know how you go!

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

Re: PunNewz

Ok, number of posts added.

Changed line 243 (add t.num_replies to DB query)
and line 278 (to display $cur_topic['num_replies'])

I've updated the zip file if you're interested.

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

Re: PunNewz

I've changed it like it works as a function : pun_extern($action, $fid, $show, $type)
It will be more useful when you make a front page. I added "array" type to the last variable $type. see the example 3

this is the code : http://jacobswell.nared.net/upload/punbb_extern.zip

example 1:

<?php
$pun_root = './punbb/';

include $pun_root."punbb_extern.php";

?>
<table cellpadding=1 cellspacing=0 border=0 width=95%><tr><td bgcolor=#A57121>
<table cellpadding=5 cellspacing=1 border=0 width=100%>
<tr>
<td bgcolor=white><?php echo pun_extern('new'); ?></td>
</tr>
<tr>
<td bgcolor=white><?php echo pun_extern('active', 1, 5); ?></td>
</tr>
<tr>
<td bgcolor=white><?php echo pun_extern('stats'); ?></td>
</tr>
</table>
</td></tr></table>

example 2:

<?php
$pun_root = './punbb/';

include $pun_root."punbb_extern.php";
// pun_extern('action','fid','show',type')

exit(pun_extern('active','','','RSS'));
?>

exaple 3: this just shows the array result.

<?php
$pun_root = './punbb/';

include "array_dump.class.php";
$arr_dump = new array_dump;

include $pun_root."punbb_extern.php";
// pun_extern('action','fid','show',type')

?>
<table cellpadding=1 cellspacing=0 border=0 ><tr><td bgcolor=#A57121>
<table cellpadding=5 cellspacing=1 border=0 width=100%>
<td bgcolor=#F7DFAD align=center>Test for pun_extern('new','','','array')</td>
</tr>
<tr>
<td bgcolor=white>
<?php 
$r = pun_extern('new','','','array');
$arr_dump->max_length(150);
echo $arr_dump->dump($r); ?>
</td>
</tr>
<tr>
<td bgcolor=#F7DFAD align=center>Test for pun_extern('active','','5','array')</td>
</tr>
<tr>
<td bgcolor=white>
<?php 
$r = pun_extern('active', '', 5,'array');
$arr_dump->max_length(150);
echo $arr_dump->dump($r); ?>
</td>
</tr>
<tr>
<td bgcolor=#F7DFAD align=center>Test for pun_extern('active','1','1','array')</td>
</tr>
<tr>
<td bgcolor=white>
<?php
$r = pun_extern('active','1','1','array');
$arr_dump->max_length(150);
echo $arr_dump->dump($r); ?>
</td>
</tr>
<tr>
<td bgcolor=#F7DFAD align=center>Test for pun_extern('stats','','','array')</td>
</tr>
<tr>
<td bgcolor=white>
<?php
$r = pun_extern('stats','','','array');
$arr_dump->max_length(150);
echo $arr_dump->dump($r); ?>
</td>
</tr>
</table>
</td></tr></table>

you can see the result of last example here

Re: PunNewz

Interesting... good stuff!

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

Re: PunNewz

Hey,

     I think ya'll have done a great job with this mod; however, I am having trouble with what I want to do.  I am trying to make it so that I have a list of recent topics in the forum like in the regular extern.php and a section of news like on the externnews.php.  I want both of these segments on the main page of my site.  I don't know a lot about php, but I formatted the extern.php and the externnews.php to work with my site.  My intention is to allow admins in the forum to post to a certain admin only forum and that would be the news on the front page.  I am having trouble including extern and externnews becausee it says I can't call the same funcions in functions.php and etc.  I tried just taking out the functions include, but there are other things that get used twice as well.

Does anyone have any suggestions for me?
I would be most appreciative.

Re: PunNewz

Hey lemmage, thanks smile

I'm using both externnews.php and extern.php on the front page of my site http://www.shuttertalk.com without any problems.  However, I'm using the original version - not the version that jacobswell has modded.

Like you, I've set one forum to be the "admin only" forum, and used the "Reply Only" mod so that only admins and mods can start new topics in that forum.

lemmage wrote:

I am having trouble including extern and externnews becausee it says I can't call the same funcions in functions.php and etc.  I tried just taking out the functions include, but there are other things that get used twice as well.

Are you able to use just extern.php on its own?  If that works, then maybe try using my original version of the mod.

If that doesn't work then perhaps post the code that you use to call the extern.php and externnews.php, then maybe we could take a look at it.

Jules

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

Re: PunNewz

Thanks cuteseal...

I did try to use both extern.php and your original externnews.php.  I've also been trying to directly put the php code into my main page, but when I do that, nothing is showing up.  I have to edit the code to only display what I want ex (preset the action, show, fid variables).  It's kinda wierd ... I must be doing something wrong and I'm probably going to kick myself later, but since I'm not too affluent with php, I'm not sure what it is.

Once I get to a good spot I'll post my code....

Thanks

Re: PunNewz

Oh I finally got it to work .. and it was a stupid mistake... my news was not showing up because I made the news forum an "Admin/Mod" only forum....

I appreciate the comments though...

Re: PunNewz

heheh no worries.  use the reply-only mod for that - instead of the admin/mod only forum. big_smile

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

13 (edited by jacobswell 2004-06-19 15:11)

Re: PunNewz

lemmage wrote:

My intention is to allow admins in the forum to post to
a certain admin only forum and that would be the news on the front page.

in extern.php you can see like this code:

$result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, f.id AS fid, 
f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f 
ON t.forum_id=f.id WHERE t.moved_to IS NULL AND '.$forum_sql.'f.admmod_only=0 
ORDER BY '.$order_by.' DESC LIMIT 15') 
or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

if you change "f.admmod_only=0" to "f.admmod_only=1", it will display what you want.

Re: PunNewz

Thanks jacobswell and cuteseal.....
I really appreciate all the help!

I have installed the Reply Only Mod and it works great.....

I'll give that code sample that Jacobswell submitted a try too...

Re: PunNewz

I don't get it... I'm a noob in this things.

How can I just let the 'news' display on a page?
What do I have to do then.
I have to create a new file? And what should I put in it...

Re: PunNewz

Ok after some searching I found out. Didn't read the first post well here.

But another question. How do I put that news in a layout? with tables and that stuff.

17 (edited by cuteseal 2004-06-23 12:21)

Re: PunNewz

Hey Crissipos,

The idea is to create your page layout, and then "call" this externnews script where you want the news to appear in your page.

The script outputs <div> tags with css classes as described in the first post, so you'll need to define your style sheet entries to format the headings, text, etc.  For example, here's what I use:

.newssection  {
    border-color: solid #000000;
    border-width: 0px;
    padding: 5px;
}

.newsdateheader  {
    color: #FFFFFF;
    font-size: 12pt;
    font-weight: bold;
    background-color: #CCCC99;
    padding: 5px;
    margin-bottom: 2px;
}

.newsheading  {
    font-size: 12pt;
    font-weight: bold;
    padding-left: 10px;
}

.newstagline  {
    color: #333333;
    font-size: 8pt;
    padding-bottom: 10px;
    padding-left: 10px;
}

.newstext  {
    font-size: 10pt;
    padding-left: 10px;
}

Hope that comes across ok... let me know if you need more info.

Regards,
Julian

Digital photography news, reviews, discussions and more!
http://www.shuttertalk.com

The online bible for all
http://www.publicbible.com

Re: PunNewz

Thank you very much!!!
Everything works fine. I tested your stylesheet.

And the newssystem is integrated on a page. Only thing left changing the layout a bit smile

Re: PunNewz

I still have a little problem....

My newssystem takes the topics from a forum with 'post only'

The news shows up the content of that first post in a topic then. ok... still good.
But when someone replies in that topic, the news shows up that reply and not the first post!
This must be changed smile

20

Re: PunNewz

Hi Crissipos,

I found the same thing - see my post at http://punbb.org/forums/viewtopic.php?id=3818&p=2 where you'll find a fix to add to line 266.  Basically you want to add a "ORDER BY posted" to the SQL so that you get the first post in the thread.

Hope this helps.

Paul.

Re: PunNewz

Hey pgregg.

I see... Well I'll add that 'ORDER BY' if I know how smile

22

Re: PunNewz

Oh, ok... smile

 Make Line 266:
$msg = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.status, u.registered, u.admin_note, p.id, p.poster, p.poster_id, p.poster_ip, p.poster_email, p.message, p.smilies, p.posted, p.edited, p.edited_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id WHERE p.topic_id='.$id.' ORDER BY posted LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

All on one line (if the above code isn't).

Re: PunNewz

lol thanks smile

24

Re: PunNewz

Is there any way to customize the appearance ?

eg: adding background colors to the title etc etc ?

25

Re: PunNewz

simmo wrote:

Is there any way to customize the appearance ?

eg: adding background colors to the title etc etc ?

Um, re-read this thread again... cuteseal already posted the CSS that does this.