Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: can somebody explain the %d parts in pics_on_page part  (Read 1844 times)

0 Members and 1 Guest are viewing this topic.

xplicit

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 214
can somebody explain the %d parts in pics_on_page part
« on: July 16, 2006, 07:48:48 pm »

Hi all!

I thought I understood coppermine perfectly and have codes several functions but there is just one part in the theme.inc.php I just canīt fully understand.

Itīs this part.

Code: [Select]
  if ($mode == 'thumb') {
        $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $aid == 'lastalb' ? $lang_album_list['album_on_page'] : $lang_thumb_view['pic_on_page']));
        $theme_thumb_tab_tmpl['inactive_tab'] = strtr($theme_thumb_tab_tmpl['inactive_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . $uid_link . '&page=%d'));
        $theme_thumb_tab_tmpl['inactive_next_tab'] = strtr($theme_thumb_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . $uid_link . '&page=%d'));
        $theme_thumb_tab_tmpl['inactive_prev_tab'] = strtr($theme_thumb_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'thumbnails.php?album=' . $aid . $cat_link . $uid_link . '&page=%d'));
    } else {
        $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $lang_thumb_view['user_on_page']));
        $theme_thumb_tab_tmpl['inactive_tab'] = strtr($theme_thumb_tab_tmpl['inactive_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
        $theme_thumb_tab_tmpl['inactive_next_tab'] = strtr($theme_thumb_tab_tmpl['inactive_next_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
        $theme_thumb_tab_tmpl['inactive_prev_tab'] = strtr($theme_thumb_tab_tmpl['inactive_prev_tab'], array('{LINK}' => 'index.php?cat=' . $cat . '&page=%d'));
    }

which uses

Code: [Select]
$lang_thumb_view = array(
 'pic_on_page' => '%d files ON %d page(s)',
 'user_on_page' => '%d users ON %d pages(s)',
);

But how and where are these %d and the other %d determined?  I played a bit with it but it seems I can not use these %d things in bolean equations... I wanted to determine if the %d of the pages was equal to 1 and than output page instead of page(s). I can put the %d things in variables but no matter what the number is it always sais the if statement is false and executes the else part all the time.. When I use them like this:

Code: [Select]
$theme_thumb_tab_tmpl = $template_tab_display;
 if ($mode == 'thumb') {
 $photopart = "%d";
 $pagespart = "%d";
 if ($pagespart == 1) {
  $pagespart = $pagespart." PAGE";
 } else {
  $pagespart = $pagespart." PAGES";
 }

What's up with these magic things?

Strangest part is that if I use the $pagespart and photopart is gives the numbers correctly... but it seems like these are not normal numbers since I cant compare with them...
« Last Edit: July 18, 2006, 06:52:27 am by GauGau »
Logged
Don't ask me: Can you do this .... or Give me that...or I need Quick help in PM's. I'm not Santaclaus so post your questions on the board so it will be in the benefit for everyone.

Nibbler

  • Guest
Re: can somebody explain the %d parts in pics_on_page part
« Reply #1 on: July 16, 2006, 07:54:30 pm »

http://php.net/sprintf

You can't add new logic there, you need to add it where the string is actually evaluated.
Logged

xplicit

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 214
Re: can somebody explain the %d parts in pics_on_page part
« Reply #2 on: July 17, 2006, 11:28:30 pm »

Ahh thanx!

And I was stupid... the answer was there all along just in the start of the function...

It now displays correctly 1 photo on 1 page or for instance 2 fotos on 5 pages :)

So topic can be closed.

To make this topic not completly useless I will post my piece of code.

Note that this is purely written to display photos and nothing else like movies, docs etc so I hardcoded it as photo

Code: [Select]
  if ($mode == 'thumb') {

 if ($nbThumb == 1) {
  $photopart = $nbThumb." PHOTO ON ";
 } else {
  $photopart = $nbThumb." PHOTOS ON ";
 }

 if ($total_pages == 1) {
  $pagespart = $total_pages." PAGE";
 } else {
  $pagespart = $total_pages." PAGES";
 }

  $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $photopart.$pagespart));

etc.....

Similar thing can be codes for the usermgr with some adjustments and moving pieces of code
« Last Edit: July 18, 2006, 12:11:02 am by xplicit »
Logged
Don't ask me: Can you do this .... or Give me that...or I need Quick help in PM's. I'm not Santaclaus so post your questions on the board so it will be in the benefit for everyone.
Pages: [1]   Go Up
 

Page created in 0.013 seconds with 15 queries.