coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: will on October 27, 2007, 12:37:56 AM

Title: Divider In Total Files In Gallery
Post by: will on October 27, 2007, 12:37:56 AM
Hi

I just wanted to show total files like this 100,522 instead of 100522

And the same for total files in each category on the index page.

Any help would be good couldn't work out how to do it myself

Thanks 8)
Title: Re: Divider In Total Files In Gallery
Post by: Stramm on October 27, 2007, 08:43:24 AM
there's a thread in the german support board...
http://forum.coppermine-gallery.net/index.php?topic=47755.0

This is not a copy/paste ready to go solution. The function is able to add the 'divider' if you pass the data to it. GauGau's first post tells where to add code to call the function (index.php).
Title: Re: Divider In Total Files In Gallery
Post by: Joachim Müller on October 27, 2007, 10:47:37 AM
You can use the function I provided in the thread Stramm refered to for your issue as well. The default separator is a dot, but you can override it as second parameter. Here's the function from that other thread:function float2decSeparated($string, $separator = '.') {
  $remainder = floor($string);
  $counter=0;
  $return = '';

  //loop through the string and chop into triplets
  while ($remainder >= 1) {
      $number = $remainder - (floor($remainder/pow(10,3)) * pow(10,3));
      $return = $number . $separator . $return;
      //$number = sprintf ("%'{$fill}{$fit}s", $number); // fill the chop with leading zeros if needed
      $remainder = floor($remainder/pow(10,3));
      $counter++;
  }
  // chop the trailing separator
  $return = rtrim($return, $separator);
  return $return;
}


For your purposes, call the function with the second parameter that specifies "," as separator like this:float2decSeparated($string, ',')

The function is not fool-proof (yet), as it doesn't take into account floats (instead, they just get cut off, converting the number to integer), but it's a start, nor is it fail-proof against large numbers nor alphanumeric strings.

Title: Re: Divider In Total Files In Gallery
Post by: Stramm on October 27, 2007, 10:58:34 AM
the php function number_format() should do too
Title: Re: Divider In Total Files In Gallery
Post by: Joachim Müller on October 27, 2007, 11:06:56 AM
Oh, I wasn't aware of that function. Link to docs: http://www.php.net/manual/en/function.number-format.php
@Stramm: please take a look at http://forum.coppermine-gallery.net/index.php?topic=47854.0
Title: Re: Divider In Total Files In Gallery
Post by: will on October 27, 2007, 01:11:58 PM
Does it matter where I put the code in index.php
Title: Re: Divider In Total Files In Gallery
Post by: Joachim Müller on October 28, 2007, 10:36:26 AM
The function definition should reside at the start of the PHP section. Exact location doesn't matter though.
Title: Re: Divider In Total Files In Gallery
Post by: will on November 06, 2007, 04:51:22 PM
Thanks for this and I changed the separator but it doesn't work ???
Title: Re: Divider In Total Files In Gallery
Post by: Stramm on November 06, 2007, 05:32:06 PM
http://forum.coppermine-gallery.net/index.php?topic=47755.msg229109#msg229109

in index.php find
            $statistics = strtr($lang_list_categories['stat1'], array('[pictures]' => $picture_count,
                    '[albums]' => $album_count,
                    '[cat]' => $cat_count,
                    '[comments]' => $comment_count,
                    '[views]' => $hit_count));


and replace with
            $statistics = strtr($lang_list_categories['stat1'], array('[pictures]' => number_format($picture_count, 0, ',', '.'),
                    '[albums]' => number_format($album_count, 0, ',', '.'),
                    '[cat]' => number_format($cat_count, 0, ',', '.'),
                    '[comments]' => number_format($comment_count, 0, ',', '.'),
                    '[views]' => number_format($hit_count, 0, ',', '.')));
Title: Re: Divider In Total Files In Gallery
Post by: will on November 07, 2007, 04:51:35 PM
Thank you stramm, spot on don't know why GauGau gave me that code didn't need it to work, is there anyway of making the total files in each category look the same ;)
Title: Re: Divider In Total Files In Gallery
Post by: Joachim Müller on November 08, 2007, 07:26:00 AM
Quote from: will on November 07, 2007, 04:51:35 PM
don't know why GauGau gave me that code didn't need it to work
I already said that I wasn't aware of that PHP function. Read up what I wrote.
What you you expect: apologies for this? Your reply is just lame imo.