Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,826
    Plugin Contributions
    31

    Default [Not a ZC bug] Truncated product description may fail HTML validation

    I would not really class this as bug but in the interests of 100% validation...

    If the product description starts with a <p> tag and the truncated text loses the closing </p> it will fail validation.

    I added an extra function into function zen_trunc_string to check for unbalanced p tags and add one on the end if necessary which seems to be working ok.

    (Why do I have a p tag in the product description anyway? - I use <p class... to style the first paragraph differently,)

    Steve

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Truncated product description may fail validation

    Care to share the extra code you added?
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  3. #3
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,826
    Plugin Contributions
    31

    Default Re: Truncated product description may fail validation

    WHAT! My hacks in public!
    Well, in the interests of someone doing it better...

    In/functions/functions_general.php:
    in function zen_trunc_string (around line 1036),
    I edited it to call a new function in
    /extra_functions/my_new_functions.php just before returning the truncated string:

    Code:
     function zen_trunc_string($str = "", $len = 150, $more = 'true') {
      //echo '$str = '.$str.'&nbsp;&nbsp;$len = '.$len.'&nbsp;&nbsp;$more = '.$more.'<br />';//check
        if ($str == "") return $str;
        if (is_array($str)) return $str;
        $str = trim($str);//strips whitespace from either end
        // if it's less than the size given, then return it
        if (strlen($str) <= $len) return $str;
        // else get that size of text
        $str = substr($str, 0, $len);//strips string to required length
        // backtrack to the end of a word
        if ($str != "") {
          // check to see if there are any spaces left
          if (!substr_count($str , " ")) {
            if ($more == 'true') $str .= "...";
    	$str = check_for_p($str);//check for unclosed paragraph tags
            return $str;
          }
          // backtrack
          while(strlen($str) && ($str[strlen($str)-1] != " ")) {
            $str = substr($str, 0, -1);
          }
          $str = substr($str, 0, -1);
    	  
          if ($more == 'true') $str .= "...";
    	  if ($more != 'true' and $more != 'false') $str .= $more;
    	$str = check_for_p($str);//steve check for unclosed paragraph tags
        }
        return $str;
      }
    and the new function:
    PHP Code:
    function check_for_p ($str) {
          
    $needle '<p';
          
    $opened_p substr_count($str,$needle);
          
    $needle '</p>';
          
    $closed_p substr_count($str,$needle);
          if (
    $opened_p != $closed_p) {$str $str.'</p>';} 
          return 
    $str;


  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Truncated product description may fail validation

    Where are you seeing that if using:
    <p>long description here</p>
    that this isn't getting stripped on the Listings?

    What version Zen Cart?

    What happens if you switch to the Classic Template?

    So far, I am not reproducing this ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Truncated product description may fail validation

    What you see is
    <p>long description
    which flags as invalid code, significant because Google appears to now take this into account and in extreme examples can even break the structure of a page.

    torvista, that's a move in the right direction but a bit too specific. It will only deal with the problem of a missing paragraph closing tag. But other HTML elements that might be used in product descriptions and can get broken include DIVs, ULs, OLs, LIs and all the table elements. And even if its possible numberically to work out what's missing, they need to be closed in the right order.

    I suspect that a more robust route approach (at least in PHP 5) would be to use DOMDocument::loadHTML or DOMDocument::loadXML, to create a complete structure based on the truncated string, but there may be some gotchas lurking in there.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  6. #6
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Truncated product description may fail HTML validation

    Hmmm. Torvista. Where are you actually seeing this manifest and what in what version of Zen Cart?
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  7. #7
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,826
    Plugin Contributions
    31

    Default Re: Truncated product description may fail HTML validation

    Stand down...false alarm. I should have posted this in the Bug Reports-for-my-shop section.
    I did not have a vanilla install available to check this at the time...and thought I understood what I was looking at.

    Zen Cart 139d already deals with this issue by stripping html from the truncated text in the listings so there are no problems with unclosed tags.

    I use the Boilerplate Text mod and Single Listing Template and other mods in my product listings which has given rise to this fault, not sure yet exactly which mod code or my implementation is at fault but thats not relevant to this thread. Added those some time ago when I knew nothing as opposed to almost nothing.

    Sorry for the time wasted,
    regards
    Steve

  8. #8
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Truncated product description may fail HTML validation

    LOL. I had a quick chat with Ajeh and we'd come to much the same conclusion. Glad you got in there first!
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  9. #9
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Truncated product description may fail HTML validation

    That is a warning I generally give when discussing how to have HTML in the product listing - you need to make sure you either don't truncate the descriptions at all, or keep HTML tag sets inside or outside the truncation point, not crossing it.

 

 

Similar Threads

  1. v153 Product Description HTML Validation
    By lloyd_borrett in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 4 Aug 2014, 08:51 PM
  2. Replies: 2
    Last Post: 11 Aug 2013, 04:09 PM
  3. Replies: 3
    Last Post: 10 Aug 2011, 06:21 AM
  4. product description truncated
    By thefuss in forum Setting Up Categories, Products, Attributes
    Replies: 8
    Last Post: 3 Mar 2011, 09:45 PM
  5. Add more info link to product listing description when description is truncated
    By MaureenT in forum Templates, Stylesheets, Page Layout
    Replies: 11
    Last Post: 16 Sep 2010, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg