Topic: Looking for some validation help

This is my mod active topics and for the life of me I can't get it to validate. Can someone please lend a hand. I've been trying for hours now and with no success. Here is the code below as well as the link to show what is being displayed.

http://validator.w3.org/check?uri=http% … Findex.php

<?php
/*

PunBB Active Topics

Copyright 2004-2005 Alex King, http://www.alexking.org/

This is a mod for PunBB, http://www.punbb.org/
PunBB is Copyright (C) 2002, 2003, 2004  Rickard Andersson (rickard@punbb.org)

This file is based on the viewtopic.php file in PunBB.

-------------------------------
*/

$ak_limit = 10; // change this to the number of active topics you want to display.

$result = $db->query('
    SELECT p.poster_id AS has_posted, t.* 
    FROM '.$db->prefix.'topics AS t 

LEFT JOIN '.$db->prefix.'posts AS p ON p.id=p.topic_id AND p.poster_id='.$pun_user['id'].' 
    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='.$pun_user['g_id'].'
    ) 
    WHERE (
        fp.read_forum IS NULL 
        OR fp.read_forum=1
    ) 
    GROUP BY t.id
    ORDER BY t.last_post DESC
    LIMIT '.$ak_limit
) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

$new_topics = get_all_new_topics();

?>

<div id="vf" class="blocktable">
    <h2><span>Latest Active Topics</span></h2>


    <div class="box">
        <div class="inbox">
            <table cellspacing="0">
            <thead>
                <tr><th style="border-left: 0px;" class="tc0"> </th>
                    <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
                    <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
                    <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
                    <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
                </tr>
            </thead>
            <tbody>
<?php

// If there are topics in this forum.
if ($db->num_rows($result))
{
// added for forum row differnetial colors
$alt = true;
// added for forum row differnetial colors

    while ($cur_topic = $db->fetch_assoc($result))
    {
// added for forum row differnetial colors
    $alt = !$alt;
// added for forum row differnetial colors

        $icon_text = $lang_common['Normal icon'];
        $item_status = '';
        $icon_type = 'icon';

        if ($cur_topic['moved_to'] == null)
            $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <br /><span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']).'</span>';
        else
            $last_post = ' ';

        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);

        if ($cur_topic['moved_to'] != 0) {
            $item_status .= 'imoved';
            $icon_type = 'icon imoved';
            $subject = $lang_forum['Moved'].': <a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <br /><span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
}
        else if ($cur_topic['closed'] == '0')
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class=""><br />'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
        else
        {
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <br /><span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
            $icon_text = $lang_common['Closed icon'];
            $item_status = 'iclosed';
        }
                            // gleek edit
                        if ($cur_topic['num_replies'] >= $pun_config['o_hot_count'])
                        {
                                $item_status .= 'ihot';
                                $icon_type = 'icon ihot';
                        }
        if (!$pun_user['is_guest'] && topic_is_new($cur_topic['id'], $id,  $cur_topic['last_post']) && $cur_topic['moved_to'] == null)
        {
            $icon_text .= ' '.$lang_common['New icon'];
            $item_status .= ' inew';
            $icon_type = 'icon inew';
            $subject = '<strong>'.$subject.'</strong>';
            $subject_new_posts = '<span class="newtext">[<a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a>]</span>';
        }
        else
            $subject_new_posts = null;

        // Should we display the dot or not? :)
        if (!$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1')
        {
            if ($cur_topic['has_posted'] == $pun_user['id'])
                $subject = '<img src="img/'.$pun_user['style'].'/buttons/btn_just_posted.png" title="'.$lang_forum['User has just posted'].'" alt="'.$lang_forum['User has just posted'].'" /> '.$subject;
            else
                $subject = '  '.$subject;
        }

        if ($cur_topic['sticky'] == '1')
        {
            $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
            $item_status .= ' isticky';
            $icon_text .= ' '.$lang_forum['Sticky'];
        }

        $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);

        if ($num_pages_topic > 1)
            $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
        else
            $subject_multipage = null;

        // Should we show the "New posts" and/or the multipage links?
        if (!empty($subject_new_posts) || !empty($subject_multipage))
        {
            $subject .= '  '.(!empty($subject_new_posts) ? $subject_new_posts : '');
            $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
        }
// added for forum row differnetial colors
if ($alt)
{
    $item_status .= 'alt';
}
// added for forum row differnetial colors
?>
                <tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
            <td style="border-left: 0;" class="tc0"><div class="<?php echo $icon_type ?>"> </div></td>
                    <td class="tc1"><?php echo $subject."\n" ?> </td>


                    <td class="tc2"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_replies'] : ' ' ?></td>
                    <td class="tc3"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_views'] : ' ' ?></td>


<?php
        if ($cur_topic['moved_to'] != 0) {
            $item_status .= 'imoved';
            $icon_type = 'icon imoved';
            echo '<td class="tcr"><img src="'.$pun_config['o_base_url'].'/img/topic_moved.gif" alt="Topic Moved" title="Topic Moved" /> Topic Moved</td>';
}else {


?>


                    <td class="tcr"><?php echo $last_post ?></td>
                </tr>
<?php
}
    }
}
else
{

?>
                <tr>
                    <td class="tcl" colspan="5"><?php echo $lang_forum['Empty forum'] ?></td>
                </tr>
<?php

}

?>
            </tbody>
            </table>
        </div>
    </div>
</div>

Thanks in advance.

2 (edited by MattF 2008-01-21 02:49)

Re: Looking for some validation help

Edit: Scrub that reply. Tab the code to indent it. You'll probably have one of the braces out of place. The layout makes it nigh on impossible to see offhand, however.

Re: Looking for some validation help

I tried that but it is required or else it doesn't work.

4 (edited by bingiman 2008-01-21 02:51)

Re: Looking for some validation help

This area seems to be causing the problem Matt. If I remove it and curly bracket, all the errors go away. I am lost.


<?php
        if ($cur_topic['moved_to'] != 0) {
            $item_status .= 'imoved';
            $icon_type = 'icon imoved';
            echo '<td class="tcr"><img src="'.$pun_config['o_base_url'].'/img/topic_moved.gif" alt="Topic Moved" title="Topic Moved" /> Topic Moved</td>';
}else {


?>

5

Re: Looking for some validation help

bingiman wrote:

I tried that but it is required or else it doesn't work.

That's why I edited my post. big_smile It would have thrown a parsing error if that were the case. Get the code indented, and it'll be far easier to check.

6

Re: Looking for some validation help

Give this a try. Change this:

?>


                    <td class="tcr"><?php echo $last_post ?></td>
                </tr>
<?php
}
    }
}
else

to this:

?>


                    <td class="tcr"><?php echo $last_post ?></td>
<?php
        }
?>
                </tr>
<?php
    }
}
else

Re: Looking for some validation help

Thank you mat once again. That solved the problem. big_smile

Cheers mate.

Re: Looking for some validation help

Sorry to bug you guys again but I have one last file that I can't validate. I managed to validate all the others so far but online.php I can't seem to get. I followed other files with a similar layout but this just never seems to validate. Here is the code if anyone can help me.

<?php
define('PUN_ALT4',1);
define ('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

if ($pun_user['is_guest'] && $pun_user['g_read_board'] == '0')
        message($lang_common['No permission']);


// Load the userlist.php language file

require PUN_ROOT.'lang/'.$pun_user['language'].'/userlist.php';
// Load the online.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/online.php';

$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_online['Online List'];
require PUN_ROOT.'header.php';
?>
<div class="blocktable">
    <h2><span><?echo $lang_online['Online List']?></span></h2>
    <div class="box">
        <div class="inbox">
            <table cellspacing="0">
            <tr>
                <th class="tcr" style="text-align: center; border-left: 0px;" scope="col"><?php echo $lang_common['Username'] ?></th>
                <th class="tcr" style="text-align: center; border-left: 0px;" scope="col"><?php echo $lang_online['Last action'] ?></th>
                <th class="tcr" style="text-align: center; border-left: 0px;" scope="col"><?php echo $lang_online['Time'] ?></th>
                <?if($pun_user['g_id'] <= PUN_MOD):?>
                <th style="text-align: center; border-left: 0px;" class="tcr" scope="col"><?php echo $lang_online['IP'] ?></th><?echo"\n";endif?>
            
            

<?php


// Grab the users
$result = $db->query('SELECT * FROM '.$db->prefix.'online WHERE user_id > 0 AND idle=0 ORDER BY ident') or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
$num_users_page = $db->num_rows($result);

if ($num_users_page) {
  while ($num_users_page--) {
   $user_data = $db->fetch_assoc($result);
    if ($user_data['current_page']) {
        echo"\t\t\t\t".'<tr>'."\n";
        
    if ($user_data['user_id'] > 1) 
          echo "\t\t\t\t\t".'<td style="text-align: center; border-left: 0px;"><a href="'.PUN_ROOT.'profile.php?id='.$user_data['user_id'].'">'.$user_data['ident'].'</a></td>'."\n";
    else 
        echo "\t\t\t\t\t".'<td style="text-align: center; border-left: 0px;">'.$lang_online['Guest'].'</td>'."\n";

$pathinfo = pathinfo($user_data['current_page']);
$current_page = $pathinfo['basename'];

if ($user_data['current_page_id'] > 0) {
    if ($current_page == "viewtopic.php" || $current_page == "post.php") { $current_page_name = $db->query('SELECT subject FROM '.$db->prefix.'topics WHERE id=\''.$user_data['current_page_id'].'\'') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); }
    if ($current_page == "viewforum.php") { $current_page_name = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id=\''.$user_data['current_page_id'].'\'') or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error()); }
    if ($current_page == "profile.php") { $current_page_name = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id=\''.$user_data['current_page_id'].'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error()); }
    if ($current_page == "post.php" || $current_page == "edit.php") { echo"\t\t\t\t\t".'<td>'.$lang_online[$user_data['current_page']].': <b><a href="'.PUN_ROOT.'viewtopic.php?id='.$user_data['current_page_id'].'">'.$db->result($current_page_name, 0).'</a></b></td>'."\n";}
    else { echo"\t\t\t\t\t".'<td style="text-align: left;">'.$lang_online[$user_data['current_page']].': <b><a href="'.$user_data['current_page'].'?id='.$user_data['current_page_id'].'">'.$db->result($current_page_name, 0).'</a></b></td>'."\n";}

}else if ((@$lang_online[$user_data['current_page']]) == '')
        echo"\t\t\t\t\t".'<td style="text-align: left;">'.$lang_online['Hiding Somewhere'].'</td>'."\n";
    else
        echo"\t\t\t\t\t".'<td style="text-align: left;"><a href="'.$user_data['current_page'].'">'.$lang_online[$user_data['current_page']].'</a></td>'."\n";    


echo"\t\t\t\t\t".'<td style="text-align: center;">'.format_time($user_data['logged']).'</td>'."\n";

if ($pun_user['g_id'] <= PUN_MOD) echo"\t\t\t\t\t".'<td style="text-align: center;"><a href="'.PUN_ROOT.'admin_users.php?show_users='.$user_data['current_ip'].'">'.$user_data['current_ip'].'</a></td>'."\n";
echo"\t\t\t\t".'</tr>'."\n";
} } }
else { echo "\t\t\t\t".'<tr><td colspan="4">'.$lang_online['No users'].'</td>'."\n\t\t\t\t".'</tr>'."\n"; }
?>
                        </table>
        </div>
    </div>
</div>

<?php
require PUN_ROOT.'footer.php';

Thanks
Bingiman

Re: Looking for some validation help

Anyone?

10

Re: Looking for some validation help

Compare it against mine, (which is valid). It'll be the closing tag placement within the loop, I would guess:

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

Re: Looking for some validation help

Yours is completely different to mine Matt. I can't even begin to compare them. big_smile

12 (edited by MattF 2008-01-22 21:50)

Re: Looking for some validation help

It's the same file, in it's base form. big_smile Mine has just been tidied up, (both cosmetically and codewise), and then just has minor alterations/additions. Have a look. You'll see that most of it, (other than the altered lang_file syntax), is the same.

Re: Looking for some validation help

MattF wrote:

Mine has just been tidied up, (both cosmetically and codewise)

Erm... you sure about that...

You have more { } than I have ever seen in one file tongue

Re: Looking for some validation help

Well, I figured it out..finally... I did a file comparison with Matt's file and it was a missing </tr> in this littel area of code.

<?php 
        echo "\n";
    }
?>
    </tr>

Finally it validates.

Thanks a lot guys. smile

15

Re: Looking for some validation help

StevenBullen wrote:

Erm... you sure about that...

You have more { } than I have ever seen in one file tongue

Ah, but is it highly readable and can you understand where each clause begins and ends without any head scratching? big_smile The curly braces improve both readibility and prevent any 'unexpected' issues due to code placement.

It's a carry over from shell scripting, which is, (still, I suppose), my preferred choice. The braces prevent child processes being spawned. (If I remember correctly. It has been a while since I last did any indepth shell work). Again, it also keep the readability and operation sane. (In my opinion).

Re: Looking for some validation help

I was only playing anyway... smile

17

Re: Looking for some validation help

StevenBullen wrote:

I was only playing anyway... smile

I know. big_smile