Advertisement:

Author Topic: Trim description on main and search...  (Read 2188 times)

code monkey

  • Full Member
  • ***
  • Posts: 204
Trim description on main and search...
« on: March 18, 2011, 03:03:12 am »
Problem: when user posts a long description, it will spam the main page and search results.
Let's trim it at two lines (about 190 characters).
Also, this will add strip_tag to main, which doesn't have it currently.


/oc-includes/osclass/helpers/hItems.php

After...
Code: [Select]
    function osc_item_description($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_item_field("s_description", $locale) ;
    }

Add...
Code: [Select]
function osc_item_description_extract($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
$extract = strip_tags(osc_item_field("s_description", $locale)) ;
if ( strlen($extract) > 193 )
$extract = substr($extract, 0, 190) . '...';
return $extract;
}


/oc-content/themes/modern/main.php

Around line 103, find...
Code: [Select]
<p><?php echo osc_item_description() ; ?></p>
Replace with...
Code: [Select]
<p><?php echo osc_item_description_extract(); ?></p>

/oc-content/themes/modern/search-list.php and
/oc-content/themes/modern/search-gallery.php

Around line 52, find...
Code: [Select]
<p><?php echo osc_highlightstrip_tagsosc_item_description() ) ); ?></p>
Replace with...
Code: [Select]
<p><?php echo osc_highlightosc_item_description_extract() ); ?></p>

Now a long description will be trimmed at two lines instead of taking up the whole page.

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Trim description on main and search...
« Reply #1 on: March 18, 2011, 12:01:31 pm »

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: Trim description on main and search...
« Reply #2 on: March 25, 2011, 05:20:03 pm »
Have you seen this function?

hUtils.php - line 116
function osc_highlight($txt, $len = 300, $start_tag = '<strong>', $end_tag = '</strong>')