Topic: Some advice on my modded Latest Topics

I am no coder but I managed to whip this Latest Topics up using various code. I am not sure if it is correct but it does work. I would just like someone to tell me if everything in here is required or not. I have no clue what the censoring area of the code does. I am assuming that if censoring is turned on in the admin panel the results are shown here. One thing I do not understand is why I need to set the make topics displayed to (6) in order to show (5). However, if I remove the censoring code then a setting of (5) is (5). Anyway, just need someone to pick out the code that I need in here:


<?php

showRecent(); // Set amount of posts to be displayed here

function showRecent($show=10) {
    global $lang_common, $db, $pun_config, $pun_user, $db_prefix;
    $max_subject_length = 20;

    $order_by = 't.last_post';
    $forum_sql = '';



    $show = intval($show);
    if ($show < 1 || $show > $show_max_topics)
    $show = 6;
// Fetch $show topics
    $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND 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) ) return $output;
    while ( ($show_count < $show) && ($cur_topic = $db->fetch_assoc($result)) ) {
        $temp = '';

            while ($cur_topic = $db->fetch_assoc($result)) {
        if ($pun_config['o_censoring'] == '1')
     $cur_topic['subject'] = censor_words($cur_topic['subject']);
    $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);
 
        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'];


    echo '<div class="l_icon"><strong><a class="l_icon_padding" href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.pun_htmlspecialchars($subject_truncated).'</a></strong></div><br /><div style="padding-left: 12px; font-size: 9px; font-family: Tahoma, Arial, Verdana; text-align: left;">by: '.pun_htmlspecialchars($cur_topic['poster']).'<br />'.format_time($cur_topic['last_post']).'</div><br />'."\n";
    }
    return;
    }
}

Thanks big_smile
Bingiman.

Re: Some advice on my modded Latest Topics

I am just asking for your opinion on the code above. I am not asking for any coding help. big_smile

Re: Some advice on my modded Latest Topics

Thank you for the overwhelming response I got here on this matter.

Re: Some advice on my modded Latest Topics

bing, post the code at my site and get a faster result....


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: Some advice on my modded Latest Topics

I will do that.. thanks Scot

6

Re: Some advice on my modded Latest Topics

bingiman wrote:

Thank you for the overwhelming response I got here on this matter.

Bingiman, no disrespect intended, but one does have to understand that people do have lives of their own. The forum is not a persons personal programming crew at their beck and call.

7

Re: Some advice on my modded Latest Topics

quaker wrote:

bing, post the code at my site and get a faster result....


Q

Why should posting on your site yield a faster answer? Unless I'm mistaken, all of your dev team are either members or Mods on here or Punres. Unless you have created an unknown agreement to divert quetsions that way by not helping on here, (which I find hard to believe judging by the helpful attitude displayed by those persons upto just), what would asking on your site achieve that it cannot on here? Surely, they would still be as busy if the question was asked upon your site?

8

Re: Some advice on my modded Latest Topics

Try this. It's had a quick once over, and is totally untested, but should be fine. Have removed all code which appeared to be excess baggage.

http://outgoing.bauchan.org/unix/bingfile.txt

9 (edited by bingiman 2007-11-04 03:08)

Re: Some advice on my modded Latest Topics

Hi Matt,

I tried the code but it didn't work. It shows nothing at all.

As for my sarcasm in my previous post. It was merely a way of getting someones attention. As a webmaster of a website with over 34,000 members. Trust me, I know what it is like to be bogged down with support questions and people wanting an immediate response. On the other hand, I do understand that people have lives. I unfortunately have none because this is all I do as far as my http://phpfusion-themes.com site is concerned. Sad but true.

Anyway, if I offended anyone then I apologize. big_smile

Bingiman

10

Re: Some advice on my modded Latest Topics

bingiman wrote:

I tried the code but it didn't work. It shows nothing at all.

What error does it show in the logs?


bingiman wrote:

As for my sarcasm in my previous post. It was merely a way of getting someones attention. As a webmaster of a website with over 34,000 members. Trust me, I know what it is like to be bogged down with support questions and people wanting an immediate response. On the other hand, I do understand that people have lives. I unfortunately have none because this is all I do as far as my http://phpfusion-themes.com site is concerned. Sad but true.

Anyway, if I offended anyone then I apologize. big_smile

No offence taken. Just trying to remind people that even sad gits like I do have external interests, and have to work. big_smile big_smile

Re: Some advice on my modded Latest Topics

It just show nothing. There is just white space and nothing else.

12

Re: Some advice on my modded Latest Topics

So the page loads okay, but there's no output from the lookup, or the page doesn't show at all, i.e: white screen?

Re: Some advice on my modded Latest Topics

yes, just a white screen.

Re: Some advice on my modded Latest Topics

I modified it a bit to get it to work and this is the end result:

<?php

LatestPosts(); 

function LatestPosts() {
global $lang_common, $db, $pun_config, $pun_user, $db_prefix;

    $max_subject_length = 20;         // Set amount of words to be displayed before truncation.
    $show = 10;                 // Set amount of posts to be displayed here.
    $order_by = 't.last_post';
    $forum_sql = '';



if ($show > '0')
    {
// Fetch $show topics
        $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND 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());

        if ($db->num_rows($result))
        {
            while($cur_topic = $db->fetch_assoc($result))
            {
                if ($pun_config['o_censoring'] == '1')
                {
                    $cur_topic['subject'] = censor_words($cur_topic['subject']);
                }

                if (pun_strlen($cur_topic['subject']) > $max_subject_length)
                {
                    $subject = trim(substr($cur_topic['subject'], 0, ($max_subject_length-5))).' ...';
                }
                else
                {
                    $subject = $cur_topic['subject'];
                }

                echo '<div class="l_icon"><strong><a class="l_icon_padding" href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($subject).'">'.pun_htmlspecialchars($subject).'</a></strong></div><br /><div style="padding-left: 12px; font-size: 9px; font-family: Tahoma, Arial, Verdana; text-align: left;">by: '.pun_htmlspecialchars($cur_topic['poster']).'<br />'.format_time($cur_topic['last_post']).'</div><br />'."\n";

                return;
            }
        }
    }
}

I don't know if it is correct.

15 (edited by MattF 2007-11-04 03:31)

Re: Some advice on my modded Latest Topics

You're calling the function from the script itself, and not from another script/page?

If so, just add:

showRecent(); to the top of that script I posted, just under the

<?php

tag.

16

Re: Some advice on my modded Latest Topics

I've just updated the script on the server. Try it now. smile

Re: Some advice on my modded Latest Topics

I get the following:

Warning: Missing argument 1 for showrecent() in c:\punbb\include\user\latestposts.php on line 7

Re: Some advice on my modded Latest Topics

I had to add $show to this line: showRecent(---inside here---);

19

Re: Some advice on my modded Latest Topics

Updated it again. big_smile

20

Re: Some advice on my modded Latest Topics

bingiman wrote:

I had to add $show to this line: showRecent(---inside here---);

Aye. I'd just updated it again with that. Bloody functions. big_smile big_smile

21

Re: Some advice on my modded Latest Topics

Btw, with regards to your censoring question earlier in the thread. That just checks against the censor words list in the admin panel and works on whichever words are defined by the admin.

Re: Some advice on my modded Latest Topics

It works great now. Thanks Matt.

23

Re: Some advice on my modded Latest Topics

No probs. Glad it's sorted. smile

Re: Some advice on my modded Latest Topics

Hi Matt,

I only had one post on my test site last night and your mod did display it. However, it only shows that 1 even though I have it set to 10. So something is wrong somewhere with the code.

Bingiman

25

Re: Some advice on my modded Latest Topics

Download it again and try it now. smile