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: [Code Sample] Prev / Next image on tab  (Read 18520 times)

0 Members and 1 Guest are viewing this topic.

djpushplay

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 3
[Code Sample] Prev / Next image on tab
« on: October 15, 2006, 12:47:42 am »

Did a quick search and hopefully, this is not a repeat.  Newbie on this board but decided to give back to this great community.  A while back, I saw in the existing 1.4.9 code stubs for "Prev" and "Next" in the image tab so I took a shot at coding it.  So far it seems to work but I'm not positive it's gold.  I'm sure somebody on here will fix it if it's not.

The code will make the tab look like this:
<Prev 1 ... 5 6 7 8 9 10 ... 320 Next>

theme.php
Code: [Select]
function theme_create_tabs($items, $curr_page, $total_pages, $template)
{
global $CONFIG, $lang_create_tabs;

    $maxTab = $CONFIG['max_tabs'];

    $tabs = sprintf($template['left_text'], $items, $total_pages);
    if (($total_pages == 1))
    return $tabs;

    $tabs .= $template['tab_header'];
   
//start
$prev = $curr_page - 1;
$p = array('{PREV}' => $lang_create_tabs['previous']);
if ($prev < 1)
$tabs .= strtr( sprintf($template['active_prev_tab']), $p);
else
$tabs .= strtr( sprintf($template['inactive_prev_tab'],$prev), $p);
//end

    if ($curr_page == 1) {
        $tabs .= sprintf($template['active_tab'], 1);
    } else {
        $tabs .= sprintf($template['inactive_tab'], 1, 1);
        if ($curr_page - floor($maxTab / 2) >= 2) //
        $tabs .= $template['dotdotdot']; //
    }

    if ($total_pages > $maxTab){
        $start = max(2, $curr_page - floor(($maxTab - 2) / 2));
        $start = min($start, $total_pages - $maxTab + 2);
        $end = $start + $maxTab - 3;
    } else {
        $start = 2;
        $end = $total_pages - 1;
    }

    for ($page = $start; $page <= $end; $page++) {
        if ($page == $curr_page) {
$tabs .= sprintf($template['active_tab'], $page);
        } else {
$tabs .= sprintf($template['inactive_tab'], $page, $page);
        }
    }

    if ($total_pages > 1) {
if ($curr_page == $total_pages) {
$tabs .= sprintf($template['active_tab'], $total_pages);

} else {
if ($curr_page + ($maxTab / 2) <= $total_pages) //
        $tabs .= $template['dotdotdot']; //
$tabs .= sprintf($template['inactive_tab'], $total_pages, $total_pages);
}
    }

//start
$next = $curr_page + 1;
$n = array('{NEXT}' => $lang_create_tabs['next']);
if ($next > $total_pages)
$tabs .= strtr( sprintf($template['active_next_tab']), $n);
else
$tabs .= strtr( sprintf($template['inactive_next_tab'],$next), $n);
//end

    return $tabs . $template['tab_trailer'];
}

And the tab definitions are:
Code: [Select]
$template_tab_display = array(
'left_text' => '<td align="left" valign="middle" class="tableh1_compact" style="white-space: nowrap"><b>{LEFT_TEXT}</b></td>' . "\n",
    'tab_header' => '',
    'tab_trailer' => '',
    'dotdotdot' => '<td align="center" valign="middle">...</td>',
    'active_tab' => '<td align="center" valign="middle" class="navmenu_active">%d</td>',
    'inactive_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>%d</b></a></td>' . "\n",
    'active_prev_tab' => '<td align="center" valign="middle" class="navmenu_active">{PREV}</td>' . "\n",
    'inactive_prev_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>{PREV}</b></a></td>' . "\n",
    'active_next_tab' => '<td align="center" valign="middle" class="navmenu_active">{NEXT}</td>' . "\n",
    'inactive_next_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>{NEXT}</b></a></td>' . "\n",
);

english.php
Code: [Select]
$lang_create_tabs = array(
  'previous' => '&lt;Prev', //cpg1.4 //
  'next' => 'Next&gt;', //cpg1.4 //
);

If you're wondering why I removed the comments from the code above, it's because this is a family board and I tend to write odd comments in my code.

If I forgot to include something here, let me know.  I wrote this a while ago so it's not so fresh in my memory anymore.

Also, I moved the navigation tabs to the top instead of the bottom.  This way, a user can keep his/her cursor on the "Next" and keep clicking without having to move the cursor each time.  Less work for the user.
« Last Edit: October 15, 2006, 01:53:59 pm by GauGau »
Logged

benj_gos

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • My Myspace Page
Re: [Code Sample] Prev / Next image on tab
« Reply #1 on: November 12, 2006, 03:04:36 pm »

This is really great  :D, thank you!!

1 question.
I always have the dotdotdot, even if the number of pages is same or higher then what's defined as max pages.
example - album has 5 pages i have set to show 10 pages and i see "1 2 3 4 ... 5".
How would i go about making sure that it shows only when it's above the set limit?

Thanks,
Benji
Logged

Hein Traag

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: nl
  • Offline Offline
  • Gender: Male
  • Posts: 2166
  • A, B, Cpg
    • Personal website - Spintires.nl
Re: [Code Sample] Prev / Next image on tab
« Reply #2 on: November 17, 2006, 11:09:35 am »

Added this mod to my CPG. So far so good. It adds a nice set of tabs to the thumbnail screen. Tested with two pages of thumbs.. adding more pictures to see if the same problem arises as benj_gos.

Cheers!
Hein
Logged

Gephri

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 235
Re: [Code Sample] Prev / Next image on tab
« Reply #3 on: January 17, 2007, 08:53:40 pm »

Installed the mod easily enough, but now I don't have the ... in pages with lots of tabs.
For examples 1,2,3,4,5,6,7,8,9,10,324
Should be 1,2,3,4,5,6,7,8,9,10,...324

Can anyone point me towards the code that controls this?
Logged

ppFreddy

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: [Code Sample] Prev / Next image on tab
« Reply #4 on: February 26, 2007, 02:00:41 am »

Got it working on my testserver, nice and easy mod.

Modded a few things so that if you are on page 1, there is no "previous", and if you are on the last page, ther is nog "next"

Only: on the index, if your albums in your categories are tabbed too, the link you get is just "{LINK}"
The numbered ones are correct though.

(http://users.telenet.be/welvaert/dump/bleh.JPG)
Logged

skidpics

  • Coppermine frequent poster
  • ***
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 223
Re: [Code Sample] Prev / Next image on tab
« Reply #5 on: March 10, 2007, 01:26:55 pm »

Awesome Mod!  ONly problem is that it is showing at the bottom of the page, not the top as described in the first post.  What do I change to place it at the top of the thumb view?

-- Skidpics
Logged

dke

  • Guest
Re: [Code Sample] Prev / Next image on tab
« Reply #6 on: June 24, 2007, 12:50:36 pm »

really great mod! but i have the same problem aswell, the tabs displaying at the bottom insted of the top left corner, would be sweet not having to move the cursor :) anyway great mod thanks!
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 20 queries.