Contribute to JEvents

Minor bug with "ellipsisification": some titles made longer

We are looking for developers, forum moderators and translators for this project.

If you would like to help out then please add a message in this forum.

Postby kriegj » Sat Feb 06, 2010 1:02 pm

Hi all,

I am an experienced web developer (several years of Perl, PHP and Java experience) but relatively new to Joomla and JEvents. It's all been a fairly good experience so far. This is my first bug report; the bug applies to JEvents v1.5.3 (and possibly earlier versions).

Executive summary (detailed description below):

In the various calendar_cell.php view scripts, suggest replacing:

Code: Select all
                if( JString::strlen( $this->title ) >= $cfg->get('com_calCutTitle',50)){
                        $tmpTitle = JString::substr( $this->title, 0, $cfg->get('com_calCutTitle',50) ) . ' ...';
                }


...with:

Code: Select all
// Fix #1
                if( JString::strlen( $this->title ) > $cfg->get('com_calCutTitle',50) ){
                        $tmpTitle = JString::substr( $this->title, 0, $cfg->get('com_calCutTitle',50) - 3 ) . ' ...';
                }


...or:

Code: Select all
// Fix #2
                if( JString::strlen( $this->title ) > $cfg->get('com_calCutTitle',50) + 3 ){
                        $tmpTitle = JString::substr( $this->title, 0, $cfg->get('com_calCutTitle',50) ) . ' ...';
                }


Similar bug (& fix) applies for helpers/defaultvieweventrownew.php. (With so many files affected, perhaps there is also a case here for factoring this code out into a subroutine in a utility package. Maybe this could go in the Joomla core somewhere? This is probably the sort of function that is likely to be useful to other Joomla component developers. Anyway, this is probably an issue that can be dealt with separately.)

Detailed bug description follows.

One of the things that I noticed with the monthly view of the Calendar is that it had a nifty trick of truncating the titles and replacing the chopped text with an ellipsis ("..."). I have called this "ellipsisification", for lack of a better word. This does a pretty good job of saving space in a cluttered display with long titles.

However, I noted that while the idea is a good one, there seems to be a minor quirk with the implementation. I had titles that were displayed complete (no truncation) and yet they still had an ellipsis appended to them.

Suspecting that this was an easy bug to fix I dug into the PHP code and found the following offending lines in the various implementations of calendar_cell.php:

Code: Select all
                if( JString::strlen( $this->title ) >= $cfg->get('com_calCutTitle',50)){
                        $tmpTitle = JString::substr( $this->title, 0, $cfg->get('com_calCutTitle',50) ) . ' ...';
                }
 


One solution to the problem was simply to replace the ">=" in the conditional with a ">". This fixed my problem but on closer inspection I realised that there could be other, similar quirks. For example, if the "cut title" length was 50 characters and I had a title that was 51 characters long, then my title would first be truncated to 50 characters and then have an additional three characters appended to it ("..."), for a total of 53 characters - two characters longer than the original title. So not only is the "ellipsisification" making the title slightly more difficult to read (and slightly more ugly), it is also actually making the title longer than it was originally (and thus being counter-productive as to what it was intended).

So my potential revised solutions are as per the beginning of this post - basically, to take the additional length of the ellipsis into account when deciding when to "ellipsisify". The difference is that the first one actually adheres to specs and keeps the displayed title length strictly <= to the specified number of characters, however there is a minor risk of having unpredictable behaviour if the "cut title" parameter is set to a value < 3 (this could be worked around with suitable defensive programming & parameter input validation). The second one, while not strictly adhering to the spec (ie, it will cut title lengths to (cut_title + 3) chars rather than to cut title chars), avoids the potential for the above bug. (It should be pointed out that the drawback of the second fix (ie, making titles slightly longer than specified) actually applies to the existing implementation also, so at least this would be backwards compatible.) Both fixes achieve the desired goal of only "ellipsisifying" if the ellipsisified title is actually shorter than the un-ellipsisified title.

I have already implemented the first fix in my local copy of JEvents. I will leave it to the JEvents developer community to decide which (if any) of the two suggested fixes it decides to incorporate into the next version of JEvents.

Regards,

-Jeremy
kriegj
 
Posts: 2
Joined: Sat Feb 06, 2010 11:01 am

Postby Geraint » Sun Feb 07, 2010 10:48 am

WOW what a detailed bug report :D .

This is a good point and I'll look to incorporate this into JEvents 1.5.5

Geraint
JEvents Club members can get priority forum support at the Support Forum. As well as access to a variety of custom JEvents addons and benefits. Join the JEvents club today!
User avatar
Geraint
 
Posts: 42795
Joined: Fri Feb 15, 2008 6:14 pm

Postby kriegj » Wed Feb 10, 2010 8:09 am

Oops, I just realised that the suffix is four characters (' ...'), not three ('...'), so that + 3/- 3 in my proposed fix needed to be a +/- 4.

And I think I posted this in the wrong forum, did I? Should have been in the JEvents 1.5 forum?
kriegj
 
Posts: 2
Joined: Sat Feb 06, 2010 11:01 am


Return to Contribute to JEvents

  • Who is online
  • View new posts
  • View unanswered posts
  • In total there are 0 users online :: 0 registered and 0 hidden (based on users active over the past 5 minutes)
  • Most users ever online was 94 on Tue Sep 01, 2009 12:33 am
  • Users browsing this forum: No registered users