jDownloadsownloads.com


Author Topic: three blank lines in each file listing  (Read 4990 times)

0 Members and 1 Guest are viewing this topic.

Offline ColinM

  • jD Tester
  • *
  • Posts: 3.666
three blank lines in each file listing
« on: 03.12.2013 10:16:30 »
This is a minor bug.  When the download files in a category is shown then there are  three blank lines following the description.  This causes entries to be spaced out which is annoying , especially on a small screen.  This happens if you do not have mp3 player selected.  jDownloads correctly removes the {mp3_player} and {mp3_id3_tag} layout 'globals' but in the original there are three <br /> elements introduced.  The problem occurs around line 813 in jdownloads.html.php.  As a quick cure which solved my problem I changed code from
           $html_file = str_replace('{mp3_player}', '', $html_file);
                $html_file = str_replace('{mp3_id3_tag}', '', $html_file);


by adding a line to give

$html_file = str_replace('{mp3_player}', '', $html_file);
                $html_file = str_replace('{mp3_id3_tag}', '', $html_file);
//cam remove the 3 <br /> introduced by mp3 codeas well
                $html_file = str_replace('<br /><br /><br />', '', $html_file);

The above is just a simple fix and it could be better by adjusting the find strings.

As a thought having line spacing between entries as a controllable facility would be most useful.

Colin

Offline Arno

  • Administrator
  • ***
  • Posts: 12.290
    • jDownloads.com
Re: three blank lines in each file listing
« Reply #1 on: 04.12.2013 11:45:48 »
Hi Colin,
many thanks for your post.
But have you tried before to use the option 'remove empty html tags' ?
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline ColinM

  • jD Tester
  • *
  • Posts: 3.666
Re: three blank lines in each file listing
« Reply #2 on: 06.12.2013 17:42:06 »
Yes I had that option selected - it was my first resort.  Attached is a png file taken from the 'view source' screen.  Actually as I thought about it one would not want <br /> tags removed as they are used naturally, such as in the created, size and downloads fields.   Also if one were pedantic <br /> is a complete open and close tag in itself so technically it is always 'empty' but it is a special case.

I am by no means an expert on regular expressions but I think the removeEmptyTags just removes stuff like <> or </> which are really empty tags but I could well be wrong!
function removeEmptyTags($html){
    $pattern = "/<[^\/>]*>([\s]?)*<\/[^>]*>/";
    return preg_replace($pattern, '', $html);
}

Colin

[gelöscht durch Administrator]

Offline Arno

  • Administrator
  • ***
  • Posts: 12.290
    • jDownloads.com
Re: three blank lines in each file listing
« Reply #3 on: 07.12.2013 01:07:58 »
Hi Colin,
the prior used regex was not the best, this is correct. But i have found a better way for the new 2.5 version. Please replace the old with the new one:

Code: [Select]
   /**
    *  Remove all defined 'empty' html tags from a text.
    *
    * @param string     $string
    * @result string    cleaned text
    */
    function removeEmptyTags($string)
    {
        // define which tags shall be checked
        $tags = array('p', 'strong', 'b', 'tr', 'td', 'div', 'span', 'small', 'br' );
        
        if (!is_string ($string) || trim ($string) == '')
            return $string;
        
        $p_o_tag = '<('.implode('|', $tags).')(?:\s[^>]*[^\/])?';
        $p_o_tag_short_tag = '\/>';
        $p_o_tag_long_tag = '>';
        $p_empty = '(?:&nbsp;|\x00|\xa0|\s)*';
        $p_cl_tag = '<\/\\1>';
        $pattern =
            $p_o_tag
            .'(?:'.$p_o_tag_short_tag
            .'|'.$p_o_tag_long_tag.$p_empty.$p_cl_tag.')';
        while ( $string != ($val = preg_replace('/'.$pattern.'/iS', '', $string)) && is_string($val)) {
                $string = $val;
        }
        return $string;
    }

You can change the checked html tags in this line (but for me works it fine):
$tags = array('p', 'strong', 'b', 'tr', 'td', 'div', 'span', 'small', 'br' );

See also the pic and read the new option description.

By the way, the old regex had also destroyed the ajax vote function for downloads.  :-\

[gelöscht durch Administrator]
« Last Edit: 07.12.2013 01:14:47 by Arno »
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline ColinM

  • jD Tester
  • *
  • Posts: 3.666
Re: three blank lines in each file listing
« Reply #4 on: 07.12.2013 17:41:58 »
Arno
That is a much better solution than the old removeEmptyTags function.  In the special case of <br /> tags however it does not seem to resolve that issue.  I think this is because the
 <br /> tag is unlike the others and is not a pair with a start tag and an end tag.   Also we need to keep <br /> in the text stream as it gets used to layout the create date, file size and number of downloads fields.

Just to clarify. The removeEmptyTags function will treat html code like  <p></p> and <p>&nbsp;</p>  as an empty pair of tags.  That is  if the only content between a tag and its tagend is zero or more &nbsp; characters then they are treated as  being empty.  Note that the numeric equivalent of &nbsp; is &#160; so that if you want to keep the effect of empty tags, say for spacing out items, then use &#160; as those tag pairs will not be removed.

Could I suggest the wording in the Remove Empty HTML tag option is perhaps
"If set to yes then all empty front end tags are removed.  This is useful when you are not outputting all possible fields in the layout.  It is also useful for the "Remove Title when no value" option above is in use.  Tags are treated as being empty if the the only content between the tag start and its mating tag end is zero or multiple &nbsp; characters. Tip: if you need to include non breaking spaces then use the direct numerical equivalent &#160; instead."
 Colin
PS Just as a thought for the upcoming 2.5 release I would gladly revise the UK English file if that would help.  Personally I rather like your English as it gives the software some personal 'flavour' but maybe it might help other language translators.
C

Offline Arno

  • Administrator
  • ***
  • Posts: 12.290
    • jDownloads.com
Re: three blank lines in each file listing
« Reply #5 on: 09.12.2013 10:07:25 »
Hi Colin,
when you will correct the englih language files, you are welcome. So i have your added to the transalation team (see new forums category). (I see that you are always a member from testing team. )
Wide parts from the current language files are from myself written. But my english is bad, i know it.  :-\  

All language files are managed by transifex.com here. But it is the best, when you start your correction work with the new v2.5 language files in the next year. Then i hope i can published the new language files at the end from this year.

Back again to the clearing function: I shall use your reworked description above for it? I have just changed it. ;)

Many thanks for your help.  8)
« Last Edit: 09.12.2013 10:19:41 by Arno »
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline ColinM

  • jD Tester
  • *
  • Posts: 3.666
Re: three blank lines in each file listing
« Reply #6 on: 09.12.2013 21:39:00 »
Arno
Would be delighted to assist this way. Starting in New Year on 2.5 version is sensible way forward.
Have looked at Transifex and created an a/c.  See that you and ep98 are the maintainers.  There is of course no en-gb to en-gb.  What is most convenient way for you when I do an english/english translation?

Colin

Offline Arno

  • Administrator
  • ***
  • Posts: 12.290
    • jDownloads.com
Re: three blank lines in each file listing
« Reply #7 on: 11.12.2013 12:52:21 »
Hi Colin,
you have right, in this case is transifex maybe not the best solution.
I will send it your in the next weeks, when it is nearly ready.  ;)
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline ColinM

  • jD Tester
  • *
  • Posts: 3.666
Re: three blank lines in each file listing
« Reply #8 on: 12.12.2013 00:20:44 »
AOK - new years gift!

Offline Arno

  • Administrator
  • ***
  • Posts: 12.290
    • jDownloads.com
Re: three blank lines in each file listing
« Reply #9 on: 20.01.2014 14:59:37 »
Hi Colin,
can i send your in the next days the english language files for your corrections?  ;D
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!