test
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • librandi Friend
    #202328

    hello,
    in the russian version, although the intro text is set to 50 characters in some of the articles is not true look at the screen shot


    1. Cattura
    jooservices Friend
    #553789

    Hi there,
    I have just checked but your site display as well.
    And please note it’s 50 characters not words 🙂

    Thank you,
    Viet Vu

    librandi Friend
    #553792

    did you see the screen shoot?

    jooservices Friend
    #553873

    Hi there,
    Yes. It’ not much clearly your issue. Would you mind provide some note.

    Thank you,
    Viet Vu

    librandi Friend
    #554082

    I’m sorry, look this please


    1. Cattura
    librandi Friend
    #554253

    can anyone help me?

    jooservices Friend
    #554272

    Hi there,
    Let me check your site. Please wait for moment.

    Thank you,
    Viet Vu

    jooservices Friend
    #554277

    Hi there,


    /**
    * Method to truncate introtext
    *
    * The goal is to get the proper length plain text string with as much of
    * the html intact as possible with all tags properly closed.
    *
    * @param string $html The content of the introtext to be truncated
    * @param integer $maxLength The maximum number of charactes to render
    *
    * @return string The truncated string
    */
    public static function truncate($html, $maxLength = 0)
    {
    $baseLength = strlen($html);

    // First get the plain text string. This is the rendered text we want to end up with.
    $ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit = true, $allowHtml = false);

    for ($maxLength; $maxLength < $baseLength;)
    {
    // Now get the string if we allow html.
    $htmlString = JHtml::_('string.truncate', $html, $maxLength, $noSplit = true, $allowHtml = true);

    // Now get the plain text from the html string.
    $htmlStringToPtString = JHtml::_('string.truncate', $htmlString, $maxLength, $noSplit = true, $allowHtml = false);

    // If the new plain text string matches the original plain text string we are done.
    if ($ptString == $htmlStringToPtString)
    {
    return $htmlString;
    }

    // Get the number of html tag characters in the first $maxlength characters
    $diffLength = strlen($ptString) - strlen($htmlStringToPtString);

    // Set new $maxlength that adjusts for the html tags
    $maxLength += $diffLength;

    if ($baseLength <= $maxLength || $diffLength <= 0)
    {
    return $htmlString;
    }
    }

    return $html;
    }

    These code would cause little bit trouble with UTF-8 characters 🙂

    Thank you,
    Viet Vu

    librandi Friend
    #554307

    thank you,
    … and what can I do?

    Ninja Lead Moderator
    #554339

    <em>@librandi 451854 wrote:</em><blockquote>thank you,
    … and what can I do?</blockquote>

    This belongs to mod_articles_category – default module of Joomla, you will need to hack in code to achieve that. Try with my tweak as below:

    – Open modules/mod_articles_category/helper.php file

    – Find and change


    public static function truncate($html, $maxLength = 0)
    {
    $baseLength = strlen($html);

    // First get the plain text string. This is the rendered text we want to end up with.
    $ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit = true, $allowHtml = false);

    for ($maxLength; $maxLength < $baseLength;)
    {
    // Now get the string if we allow html.
    $htmlString = JHtml::_('string.truncate', $html, $maxLength, $noSplit = true, $allowHtml = true);

    // Now get the plain text from the html string.
    $htmlStringToPtString = JHtml::_('string.truncate', $htmlString, $maxLength, $noSplit = true, $allowHtml = false);

    // If the new plain text string matches the original plain text string we are done.
    if ($ptString == $htmlStringToPtString)
    {
    return $htmlString;
    }

    // Get the number of html tag characters in the first $maxlength characters
    $diffLength = strlen($ptString) - strlen($htmlStringToPtString);

    // Set new $maxlength that adjusts for the html tags
    $maxLength += $diffLength;

    if ($baseLength <= $maxLength || $diffLength <= 0)
    {
    return $htmlString;
    }
    }

    return $html;
    }

    To

    public static function truncate($html, $maxLength = 0)
    {
    $baseLength = mb_strlen($html);

    // First get the plain text string. This is the rendered text we want to end up with.
    $ptString = JHtml::_('string.truncate', $html, $maxLength, $noSplit = true, $allowHtml = false);

    for ($maxLength; $maxLength < $baseLength;)
    {
    // Now get the string if we allow html.
    $htmlString = JHtml::_('string.truncate', $html, $maxLength, $noSplit = true, $allowHtml = true);

    // Now get the plain text from the html string.
    $htmlStringToPtString = JHtml::_('string.truncate', $htmlString, $maxLength, $noSplit = true, $allowHtml = false);

    // If the new plain text string matches the original plain text string we are done.
    if ($ptString == $htmlStringToPtString)
    {
    return $htmlString;
    }

    // Get the number of html tag characters in the first $maxlength characters
    $diffLength = mb_strlen($ptString) - mb_strlen($htmlStringToPtString);

    // Set new $maxlength that adjusts for the html tags
    $maxLength += $diffLength;

    if ($baseLength <= $maxLength || $diffLength <= 0)
    {
    return $htmlString;
    }
    }

    return $html;
    }

    Please note that this change is applied directly to core module of Joomla so you should consider to take a backup of this change when update new Joomla version.

    Let me know if it helps

    librandi Friend
    #554631

    thanks, now it works perfectly
    great!!!

Viewing 11 posts - 1 through 11 (of 11 total)

This topic contains 11 replies, has 3 voices, and was last updated by  librandi 10 years, 1 month ago.

We moved to new unified forum. Please post all new support queries in our New Forum