can somebody explain the %d parts in pics_on_page part can somebody explain the %d parts in pics_on_page part
 

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]

Main Menu

can somebody explain the %d parts in pics_on_page part

Started by xplicit, July 16, 2006, 07:48:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xplicit

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.

  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

$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:

$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...
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

http://php.net/sprintf

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

xplicit

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

  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
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.