Post by bthirsk » Fri Oct 17, 2008 7:29 pm

    I have a serious issue when displaying trunctuated text such as product description in Featured, Latest, Specials.
When truncating by word count or character count, the results can be disastrous.
    If you chop the text between Strong tags, all following on the page text becomes bold. If you use something like color and text is chopped between oping and closing span tags, your page is broken. I have been having this occur because my Latest products occurs before Special priced products, which is in a right column. When this occurs, the complete right column is relocated with the top being located inline with the last line in the offending Latest products display.

This is some code I came up with that will correct the problem. I am going to include somewhere so it will be available anywhere in the catalog. I think it show be a call in locator with the php file somewhere in library. Maybe someone with more experience could offer some suggestions.

This is my fix.


Reduce Text Display



S55-55-675 Cleveland
Outside Lock-up (OLU) : 3.219”
Inside Lock-up (ILU) : 2.380”
Cup Diameter (CD) : 1.063”
Cup Diameter (CD) : 1.125”
Round Cups
Grease-able U-Joint';


$lines = 3; // set $lines for number of complete lines to display
  // This function return specified number of lines to display without splitting lines.
  // It should handle any formated text. Line count is determined by Line feed tags

  // echo formatedstring($test, $lines);  // This is call to function, $test is sourcestring, $ lines is number of lines to display
  // Will display one line with no trailing dots, more than one includes dots ...(more to come)
function formatedstring ($sourcestring, $lines)
{
if (strpos($sourcestring,'')) {$short = substr($sourcestring,strpos($sourcestring,'')+3,strpos($sourcestring,'')-3);}
else {$short = $sourcestring;}
$short.= '
';
$short = implode('
',array_slice(preg_split('##',$short),0,$lines));
if ($lines > 1){
   if (strlen($short) tag is removed
  if (strpos($desc,'')) {$desc = substr($desc,0,strpos($desc,''));}           // closeing tag removed
  if (strlen($desc)



Brent
Last edited by Anonymous on Sat Oct 18, 2008 12:24 am, edited 1 time in total.

Brent


Active Member

Posts

Joined
Wed Sep 03, 2008 11:33 am
Location - Canada

Post by bruce » Sat Oct 18, 2008 9:46 pm

The most general solution would be to
  • count the characters in the actual text without any formatting
  • reducing html special characters to count as one
  • close all open html tags from the point of truncation
by this time you are almost down to writing an html parser... but you did ask.  :)

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by bthirsk » Sun Oct 19, 2008 12:15 am

Actually, the function formatedstring ($sourcestring, $lines) does all that.
I have it working with Featured/latest/specials right now.
I was just asking the proper procedure to include in open cart.
Right now, I just have a require_once in each of the module files.
Brent

Brent


Active Member

Posts

Joined
Wed Sep 03, 2008 11:33 am
Location - Canada

Post by bruce » Sun Oct 19, 2008 7:13 am

:-[ That will teach me to read more carefully.

I suspect that you are only going to call these functions from within template code so you could put them all into library\template\template.php.

I won't tell you how to set them up as you clearly know PHP quite well.

cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by bthirsk » Sun Oct 19, 2008 10:04 am

Wrong again. I have no idea what I'm doing.
I just do what I need out of necessity.
6 months ago, I never heard of PHP.
Anyway, It appears most changes in contribs happen in controller.?

Brent


Active Member

Posts

Joined
Wed Sep 03, 2008 11:33 am
Location - Canada

Post by bruce » Sun Oct 19, 2008 8:54 pm

Well done then...

The location for code depends on where and how it is used. So, if you put a function in library\template\template.php then it will be visible in the .tpl files by name but also accessable from controllers.

eg:

Code: Select all

function fred(){...}
in template.php which returns a string value.

is accessed as

Code: Select all

<?php echo fred($product_description); ?>
or from a controller as follows:

Code: Select all

	$template =& $this->locator->get('template');

	$new_description = $template->fred($current_description);


Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm
Who is online

Users browsing this forum: No registered users and 1 guest