Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2007
    Posts
    12
    Plugin Contributions
    0

    bug [Not a Bug] Bug in zen_truncate_paragraph function

    I'm using V1.3.7.1 and notice a bug in the zen_truncate_paragraph() function. This can be found in includes\functions\functions_general.php

    The symptom of this bug is that meta tag descriptions are not shorten. For example;
    MAX_META_TAG_DESCRIPTION_LENGTH=120 and the string to be shorten equals 250 characters. This function will return the total string (250 characters) and not the shorten string. The reason being is that the function compares the number of words to the numbers of characters which creates this bug. Near line 1329 and 1330, you find this;
    PHP Code:
        if ($zv_total $size) {
          for (
    $x=0$x $size$x++) { 
    $sv_total is the number of words and $size is the maximum number of characters. One is comparing apples with oranges, so to say.

    Fix
    Replace this function with the following code;

    PHP Code:
      function zen_truncate_paragraph($paragraph$size 100) {
        
    $zv_paragraph trim($paragraph);

        
    // if it's less than the size given, then return it
        
    if (strlen($zv_paragraph) <= $size) return $zv_paragraph;

        
    // backtrack to find the end of the last complete word
        
    $len $size;
        while (
    $zv_paragraph[$len] != ' ' && $len) --$len;
        return (
    $len)? substr($zv_paragraph0$len) : substr($zv_paragraph0$size);


  2. #2
    Join Date
    Jan 2004
    Posts
    66,447
    Plugin Contributions
    81

    Default Re: Bug in zen_truncate_paragraph function

    I gather you were interpreting that the zen_truncate_paragraph() function was supposed to truncate to a certain number of characters?

    It's actually intended to truncate at a certain number of words.
    ... in which case, it's correct and there's no bug.

    Note the description for MAX_META_TAG_DESCRIPTION_LENGTH:
    Meta Tags Generated Description Maximum Length?
    Set Generated Meta Tag Description Maximum Length to (words)
    Default: 50
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Nov 2007
    Posts
    12
    Plugin Contributions
    0

    Default Re: [Not a Bug] Bug in zen_truncate_paragraph function

    , did not notice the description for MAX_META_TAG_DESCRIPTION_LENGTH. Thanks for that DrByte. I kind of assumed from the define label that the word DESCRIPTION_LENGTH would normally be the number of characters. A better define might be MAX_META_TAG_NUMBER_WORDS, but as a programmer I know how it goes.

    Functionally I believe that it would be better to have the maximum number characters (and where the last word is a complete word and not truncated) since it seems as though search engines are interested in maximum number of characters for the description (even though it seems difficult to tell which search engines use this or not). I have a multi-language site and 50 words in one language could be 30% longer or more in another language.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,447
    Plugin Contributions
    81

    Default Re: [Not a Bug] Bug in zen_truncate_paragraph function

    If you want to limit to characters, then change the module to use zen_truncate_string instead of zen_truncate_paragraph
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v151 [NOT A BUG] SSL in function zen_draw_form wrong code
    By truonghoang in forum Bug Reports
    Replies: 6
    Last Post: 15 Apr 2014, 10:26 PM
  2. Replies: 4
    Last Post: 24 Jul 2010, 01:06 PM
  3. [NOT A BUG] Minor bug in account edit template
    By jdcncsolutions in forum Bug Reports
    Replies: 3
    Last Post: 2 May 2010, 01:37 AM
  4. Replies: 7
    Last Post: 23 Jul 2009, 08:51 PM
  5. [Not a Bug] EZ-Page Links IE bug when first clicking
    By NamSingh in forum Bug Reports
    Replies: 11
    Last Post: 25 Dec 2006, 03:40 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