FaRe-Ed wrote:

hi all,

i know this is quite an old topic but i hope you guys can help me out.

This mod only display 1 paragraph, how to change it  to show any desirable numbers of paragraph?

Thanks again!

Not sure if you still need this, but you'd change this code:

                    $truncate = isset($_GET['summary']) ? 1 : 0;
                    if ($truncate == 1)
                    {
                        $paragraph = preg_split("/\s*\n+/", $cur_post['message']);
                        if (isset($paragraph[1])) 
                        {
                            $cur_post['message'] = $paragraph[0] . "...";
                        }
                    }

To something like...

                    $truncate = isset($_GET['summary']) ? $_GET['summary'] : 0;
                    for($truncate > 0)
                    {
                        $result = preg_split("/\s*\n+/", $cur_post['message']);

                        if (count($result) > $truncate) 
                        {
                            $result = array_slice($result, 0, $truncate);
                            $cur_post['message'] = implode('\n\n', $result) . "...";
                        }
                    }

Then in your URL rather than
www.yourhost.com/forums/extern.php?action=news&fid=1,4,5&summary=yes

You'd have
www.yourhost.com/forums/extern.php?action=news&fid=1,4,5&summary=NUMBER_OF_PARAGRAPHS


I haven't tested this, but it should work.

This sort of sat doing nothing for a while and then all of a sudden people are using it! cool smile

Connorhd wrote:

the reason the mini portal does not just edit extern.php and include it is lots of people have problems including html via php because of their hosting settings, anyway good work might be worth adding to the punres wiki smile

Ah, I see. Actually, I have this problem in my local editting environment.. what setting is it that causes this?

Hi, I just installed PunBB today and I'm going to be using it to build a community website. I just finished part one of the development phase, which was to use a forum in PunBB to be able to post news from. I looked around at some of the current solutions and found none of them to be "just right" for what I wanted to do.

This first release currently:
* Automatically pulls news from 1 or more forums
* Allows you to limit the number of articles pulled
* Allows you to select how to order them (last commented on or date posted)
* Displays the number of comments and (expanded) views each news item has had.
* Allows you to summarise the message body, only displaying the first paragraph of each post.
* Allows the concept of HEADLINES: latest/top news item has message text and full news details, the rest are just headlines.

Files modified: extern.php

In EXTERN.PHP

Copy and paste this to the bottom of the file BEFORE

else
    exit('Bad request');

##############################

//
// Use this to display 'news' - the recent topics from a specific forum
// expanded to include the first post text, posters, comments, etc.
//

else if ($_GET['action'] == 'news')
{
    $order_by = ($_GET['action'] == 'active') ? 't.last_post' : 't.posted';
    $forum_sql = '';

    // Get the forum id(s) you'd like to post news from
    if (isset($_GET['fid']) && $_GET['fid'] != '')
    {
        $fids = explode(',', trim($_GET['fid']));
        $fids = array_map('intval', $fids);

        if (!empty($fids))
            $forum_sql = ' AND f.id IN('.implode(',', $fids).')';
    }

    // RSS support not implemented, if anyone wants to do it, feel free..
    if (isset($_GET['type']) && strtoupper($_GET['type']) == 'RSS')
    {    
    }
    // Regular HTML output
    else
    {
        $show = isset($_GET['show']) ? intval($_GET['show']) : $show_default_topics;
        if ($show < 1 || $show > $show_max_topics)
            $show = $show_default_topics;        

        $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.num_replies, t.num_views, 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 '.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show.' ') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
        $show_count = 0;

        if(!$db->num_rows($result))
        {
            echo "No news to display";
        }
        else
        {

            while ( ($show_count < $show) && ($cur_topic = $db->fetch_assoc($result)) ) 
            {
                echo "<div class=newsblock>";
                $temp = '';
                if ($pun_config['o_censoring'] == '1')
                    $cur_topic['subject'] = censor_words($cur_topic['subject']);
                if (pun_strlen($cur_topic['subject']) > $max_subject_length)
                    $subject_truncated = trim(substr($cur_topic['subject'], 0, ($max_subject_length-5))).' ...';
                else
                    $subject_truncated = $cur_topic['subject'];

                // Simplify frequently required display information
                $thisdate = date('l, d F Y', $cur_topic['posted']);
                $poster = $cur_topic['poster'];
                $comments = $cur_topic['num_replies'];
                $views = $cur_topic['num_views'];

                // If using headlines, then after first item only show headlines...
                if(isset($_GET['headlines']) && $show_count > 0)
                {
                    echo "<p class=\"newsheadline\"><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a> ($comments)</p> \n";
                }
                else
                {
                    // DISPLAY FOR TITLE OF NEWS
                    echo "<p class=\"newstitle\"><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a></p> \n";

                    $id = $cur_topic['id'];
                    $msg = $db->query('SELECT id, poster, poster_id, poster_ip, poster_email, message, posted, edited, edited_by FROM '.$db_prefix.'posts WHERE topic_id='.$id.' LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
                    if ( !$db->num_rows($msg) ) continue;

                    $cur_post = $db->fetch_assoc($msg);
                    $posterid = $cur_post['poster_id'];    

                    // DISPLAY FOR "Posted on DATE by POSTER"
                    echo "<p class=\"newsdetails\">Posted on $thisdate by <a href=".$pun_config['o_base_url']."/profile.php?id=$posterid>$poster</a></p> \n";

                    $truncate = isset($_GET['summary']) ? 1 : 0;
                    if ($truncate == 1)
                    {
                        $paragraph = preg_split("/\s*\n+/", $cur_post['message']);
                        if (isset($paragraph[1])) 
                        {
                            $cur_post['message'] = $paragraph[0] . "...";
                        }
                    }

                    $message = parse_message($cur_post['message'], 0);            
                    echo "<p class=\"newstext\">$message";
                    if ($truncate == 1) { echo "<p><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">Read More...</a></p>"; }
                    echo "</p> \n";

                    echo "<p class=\"newsextra\">Comments(<a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$comments</a>) | Views (<a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$views</a>) </p> \n";                
                }
                echo "</div>"; // end newsblock div
                $show_count++;
            }
        }
    }
}

THEN

Find the following code:
######################
define('PUN_ROOT', './');
@include PUN_ROOT.'config.php';

Add this line afterwards:
#######################
require PUN_ROOT.'include/parser.php';

FINALLY:

Find the following code:
########################
// The length at which topic subjects will be truncated (for HTML output)
$max_subject_length = 30;

Add the following code:
########################
// If you exceed max number of allowed topics, how many to display?
$show_default_topics = 10;

HOW TO USE IT
######################

Using PHP includes:(default sorting order is by date posted)

include('http://www.yourhost.com/forums/extern.php?action=news')
This displays the latest $show_default_topics (default value: 10) topics posted in your messageboard as news items.

include('http://www.yourhost.com/forums/extern.php?action=news&fid=1,4,5')
Displays the latest $show_default_topics topics posted in forums 1,4 and 5 as news items.

include('http://www.yourhost.com/forums/extern.php?action=news&fid=1,4,5&summary=yes')
Displays the latest $show_default_topics topics posted in forums 1,4 and 5 as news items. Summarises the news text so that only the first paragraph is shown with a "Read More..." link replacing the rest.

Example: http://www.mesaverde.co.uk/forums/example.php

include('http://www.yourhost.com/forums/extern.php?action=news&fid=1,4,5&summary=yes&show=5')
Displays the latest 5 topics posted in forums 1,4 and 5 as news items. Summarises the news text so that only the first paragraph is shown with a "Read More..." link replacing the rest.

include('http://www.yourhost.com/forums/extern.php?action=news&fid=1,4,5&summary=yes&show=5&headlines=yes')
Fully displays the first news item from forums 1,4 and 5, summarising the text. The other news items (4) are shown as headlines.

Example; http://www.mesaverde.co.uk/forums/example2.php

THE PRESENTATION

<div id=newsblock>
    <p class=newstitle> Subject Title </p>
    <p class=newsdetails> Posted on DATE by POSTER</p>
    <p class=newstext> Message Text </p>
    <p class=newsextra> Comments(# of comments) | Views (# of views) </p>
</div>
<div id=newsblock>
    <p class=newstitle> Subject Title (# of comments) </p>
    ...
</div>

OR:
<div id=newsblock>
    <p class=newstitle> Subject Title </p>
    <p class=newsdetails> Posted on DATE by POSTER</p>
    <p class=newstext> Message Text </p>
    <p class=newsextra> Comments(# of comments) | Views (# of views) </p>
</div>
<div id=newsblock>
    <p class=newstitle> Subject Title (# of comments) </p>
</div>
...

This was mostly based on the tutorial at http://nupusi.net/punbb:tutorials:miniportal except it is not a function and has some added bits here and there. The fact that it is in extern.php almost makes it much easier to use (imo).

If you try it and get it working or run into problems, please let me know. Also if anyone has ideas to improve it or sees stupid mistakes, etc. then go ahead and fix it!

Thanks,
David