Small XHTML Validation Problem with 5.3.3.1

Permalink
when using the header include statement in my template

<?php Loader::element('header_required'); ?>

Among other things it produces the following code ...

<script type="text/javascript" src="/demo/concrete/js/jquery.js"></script>
<script type="text/javascript" src="/demo/concrete/js/ccm.base.js"></script>
<style> 
</style>


... the last two <style></style> tags are failing xhtml validation... these tags are definitely being inserted by the loader::element .... I've looked thru the header_required.php file but can't find whats producing these empty style tags.... any ideas...??

...I've looked on a couple of other peoples 5.3.3.1 sites and they have the same issue !!
JimboJetset
View Replies:
JimboJetset replied on at Permalink Reply
JimboJetset
I'm pulling my hair out with this... my client demands XHTML Validation which I can't deliver since upgrading to 5.3.3.1 and I have no idea what's generating these empty style tags...
synlag replied on at Permalink Reply
synlag
can you pastie your header_required.php
JimboJetset replied on at Permalink Reply
JimboJetset
pastie ??
synlag replied on at Permalink Reply
synlag
put your code in and post the link to it
synlag replied on at Permalink Reply
synlag
seems like one of the core block has a design attached.
mine looks like this:
...
<script type="text/javascript" src="/c5loc/concrete/js/jquery.ui.js"></script>
<script type="text/javascript" src="/c5loc/concrete/js/ccm.base.js"></script>
<style> 
#blockStyles1 {} 
</style>
<link rel="stylesheet" type="text/css" href="/c5loc/blocks/form/view.css" />
...
synlag replied on at Permalink Reply
synlag
...of how the designer for blocks adds the styles to the headerItems[]. i would prefer if the current collection is checked for blocks and the related stylesheets are in seperate css files at concrete/css/ and included if a block of a specific type exists in the collection..
JimboJetset replied on at Permalink Reply
JimboJetset
I've searched everywhere... :-(
JimboJetset replied on at Permalink Reply
JimboJetset
The empty style tags are generated by the block_styles.php file in the concrete/models folder.

Line 58

$v->addHeaderItem("<style> \r\n".$blockStyleHeader.'<style>', 'CONTROLLER');


...it seems this line outputs any block style headers into the page header. Unfortunately there is no check to see if the $blockStyleHeader variable actually contains data before writing to the header. In my case this means that empty tags are produced which then fails XHTML validation.

my solution was to wrap lines 58 & 59 with an 'if' statement.

if($blockStylesHeader != '') {
   $v->addHeaderItem("<style> \r\n".$blockStyleHeader.'<style>', 'CONTROLLER');
   self::$headerStylesAdded=1;
}


maybe this could be incorporated into a future release.
mobius2000 replied on at Permalink Reply
Hi JimboJetset,

I tried to use your fix however I get a error like this:

Parse error: syntax error, unexpected T_PROTECTED in /home/myserver/public_html/testclient/models/block_styles.php on line 64

I have no doubt at all that I am putting this in wrong... New to PHP!

I have placed the following:

56./ //add to header
57./ $v = View::getInstance();
58./ if($blockStylesHeader != '') {
59./ $v->addHeaderItem("<style> \r\n".$blockStyleHeader.'<style>', 'CONTROLLER'); self::$headerStylesAdded=1;
60./ }

in block_styles.php, the if($blo.... added to line 58.

Any pointers for a lost and confused little boy? hehehe
edbeeny replied on at Permalink Reply
JimboJetset

Worked perfectly, Thanks
tallacman replied on at Permalink Reply
tallacman
I tried this on my localhost with Blog and eCommerce installed and the page fails to load.
riotaj replied on at Permalink Reply
riotaj
Firstly, I found Jimbo's comment very helpful; however, I think his instructions could be clarified a bit for us non-php guru's.

I fixed the validation error by modifying block_styles.php and uploading the file attached below to my server. Here's what I did:

1. In your block_styles.php file, highlight lines 55-60.

2. Replace lines 55-60 with the following code:

?> <?php
      //add to header
      $v = View::getInstance();
        if($blockStylesHeader != '') {
   $v->addHeaderItem("<style> \r\n".$blockStyleHeader.'<style>', 'CONTROLLER');
   self::$headerStylesAdded=1;
} ?> <?php
   }


3. Save the file and upload it to its original location:
\concrete\models\block_styles.php



This is how I fixed the validation issue. THAT SAID, I know *very little* about php and can almost guarantee that the manner by which I did this is incorrect when speaking of semantic php. If anyone would like to attach their block_styles.php code that does it the right way, then please do so. In either case, if you use the provided code, it works to fix the style type validation issue.

An additional note: If you use this method to validate your page, you cannot put styles in via the C5 interface. It will break your page should you try it.

Happy Validating.
ringo replied on at Permalink Reply
Any easy way of fixing this would also be to replace the ...

<style>

with...

<style type='text/css'>

Works for me.
Remo replied on at Permalink Reply
Remo
kind of.. The patch above also makes sure there's not style tag if it doesn't have any content.

This is not only about validation, also about removing useless code...
riotaj replied on at Permalink Reply
riotaj
Congrats ringo, that was totally the way to fix that issue.

I had originally tried to fix it by using that method; however I used a double quote (") instead of a single quote ('). The double quotes--what's traditionally round on type declarations--returned a php error whilst your single quotes validate perfectly.

@Remo: If we use jimboJetset's code, users are unable to insert custom styles via the "Design" button when you are logged in and click on a block. Concrete tries to insert your custom CSS into the head without any surrounding style tags and then it totally breaks the page (page turns white, in turn you have to completely delete it and then re-make the page). Yikes!

That said, if you don't have to insert any styles via the interface, Jimbo's way likely would be the way to go.

Thanks for the help guys!
Remo replied on at Permalink Reply
Remo
are you sure you merged it the right way? Try the patch otherwise..

I just tested it and it works fine for me!
riotaj replied on at Permalink Reply
riotaj
Aha, well, if you got it to go, then probably not. I am not php savvy so it's highly likely that I did botch it somehow.

By patch are you referring to Jimbo's or something else altogether?

Cheers Remo, and nice blog! Lots of helpful stuff on there.
gewoonbiel replied on at Permalink Reply
gewoonbiel
And how is this solved in 5.4??