1

Topic: Extern validation issue...

I have added a modification to the extern.php file to show news that is posted in my punbb news forum on my frontpage of my website.

The problem I am having is that the output is causing the site to no longer comply to XHTML 1.0 W3C standards.

Can anyone take a look and see what they think can be done to remedy this problem?

Here is the added code to extern.php:

//
// 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\"><h2><b><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a></b></h2></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>) <br /><hr /></p> \n";                
                }
                echo "</div>"; // end newsblock div
                $show_count++;
            }
        }
    }
}
else
    exit('Bad request');

Thanks!

2

Re: Extern validation issue...

This is certainly wrong

 echo "<p class=\"newstitle\"><h2><b><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a></b></h2></p> \n

You can't nest block level elements inside paragraphs. In any case, the <p> and <b> tags are surplus to requirements, just the <h2> would be sufficient.

I also noticed this bit

                     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";

If that results in a <p> being nested inside another <p> that will will also fail validation.

3 (edited by Notch 2006-02-25 21:49)

Re: Extern validation issue...

Those two things were causing a few of the validation errors, but I still have a ton left over from what appears to be the output of the extern file...

This is a sample of the 90 errors returned... all from the output of the script to display the news thread on the main page:

# Error  Line 56 column 60: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified.

...ock"><p class="newstitle"><b><a href=http://www.uscivilwaronline.com/forums/v

?
# Error Line 56 column 66: NET-enabling start-tag not immediately followed by null end-tag.

...p class="newstitle"><b><a href=http://www.uscivilwaronline.com/forums/viewtop

This error may occur when there is a mistake in how a self-closing tag is closed, e.g '.../ >'. The proper syntax is '... />' (note the position of the space).

?
# Error Line 56 column 181: end tag for element "a" which is not open.

...ntally Plow Civil War-Era Cemetery</a></b></p> 

The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

If this error occured in a script section of your document, you should probably read this FAQ entry.

For example, this part of the script:

echo "<p class=\"newstitle\"><b><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a></b></p> \n";

returns this in the source view (hence what the validator sees):

<p class="newstitle"><b><a href=http://www.uscivilwaronline.com/forums/viewtopic.php?id=55>Plantation Workers Accidentally Plow Civil War-Era Cemetery</a></b></p>

and obviously the lack of quotes (") enclosing the URL.


Any thoughts?

Re: Extern validation issue...

Notch wrote:
echo "<p class=\"newstitle\"><b><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a></b></p> \n";

returns this in the source view (hence what the validator sees):

<p class="newstitle"><b><a href=http://www.uscivilwaronline.com/forums/viewtopic.php?id=55>Plantation Workers Accidentally Plow Civil War-Era Cemetery</a></b></p>

and obviously the lack of quotes (") enclosing the URL.


Any thoughts?

You are talking about this hunk from your first post correct...

else
{
  // DISPLAY FOR TITLE OF NEWS
  echo "<p class=\"newstitle\"><h2><b><a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">$subject_truncated</a></b></h2></p> \n";

Why not just change it to...

else
{
  // DISPLAY FOR TITLE OF NEWS
  echo '<p class="newstitle"><h2><b><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'">'.$subject_truncated."</a></b></h2></p> \n";

5

Re: Extern validation issue...

That would still be invalid wouldn't it but only because of the nesting of the <p> and <h2> tags. It would solve the unquoted href problem.

I'm moving this to integration as this is a modified version of extern and thats where the post announcing the original release is situated.

6 (edited by Notch 2006-02-26 03:57)

Re: Extern validation issue...

Well I did it without the <h2> tag and then made the changes suggested and that cleared up half the errors...

The next line causing the remainder appears to be this line:

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

I tried making similar changes as the bit mentioned before but I end up with parse errors...

7 (edited by Paul 2006-02-26 04:09)

Re: Extern validation issue...

First, you should have left the <h2> and removed the <p> and <b> tags as its clearly a heading.

I think the line should be

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

But then my php isn't upto much.

8

Re: Extern validation issue...

This is getting me so close... it's also greatly appreciated too...

I have tried messing with the last bit thats left but I cannot seem to grasp where to add and remove the ' and ".

This is what I think is left to be altered:

echo "<p class=\"newstext\">$message";
                    if ($truncate == 1) { echo "<a href=".$pun_config['o_base_url']."/viewtopic.php?id=".$cur_topic['id'].">Read More...</a>"; }
                    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>) <br /><hr /></p> \n";

Re: Extern validation issue...

Paul wrote:

That would still be invalid wouldn't it but only because of the nesting of the <p> and <h2> tags. It would solve the unquoted href problem.

Since you explained a few posts back about the problems with having h2 in the p I didn't think it nessary to rehash the details. I just wanted to offer a hand with the unquoted href. smile

Mark

10

Re: Extern validation issue...

Something like this I think

echo '<p class="newstext">'.$message;
                    if ($truncate == 1) { echo '<a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'">Read More...</a>'; }
                    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>) <br /><hr /></p>'."\n";

11

Re: Extern validation issue...

CableGuy wrote:
Paul wrote:

That would still be invalid wouldn't it but only because of the nesting of the <p> and <h2> tags. It would solve the unquoted href problem.

Since you explained a few posts back about the problems with having h2 in the p I didn't think it nessary to rehash the details. I just wanted to offer a hand with the unquoted href. smile

Mark

I just wanted to make sure Notch knew that he had to fix both problems i.e. they weren't alternative solutions.

12

Re: Extern validation issue...

Thanks guys... learning a lot from this... I think... LOL.... I have it down from the initial 119 problems to 5... some were easy to figure out some (like what I posted here) I had trouble grasping.

The last 5 appear to be related to this (I think):

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

Somewhere an extra <p> is being inserted after < class='newstext'>

Re: Extern validation issue...

Notch, could you post the page source that is being generated. Just the problem part. I can't see your forums from your main site anymore. From the Civil War link I get a nothing page.

14

Re: Extern validation issue...

$message is always wrapped in a paragraph which is inserted by parser.php. You just need to change <p class="newstext"> to <div class="newstext"> making sure you also change the closing </p> to </div>.

15

Re: Extern validation issue...

Page now passes XHTML 1.0 validation!

Thanks Paul and CableGuy for your efforts!

cool

16

Re: Extern validation issue...

Notch, can you post the complete code here?

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 !!!