source: extensions/akBookStyle/trunk/include/akContent.class.php @ 3829

Last change on this file since 3829 was 3829, checked in by vdigital, 15 years ago

Partial thumbnail navigation

File size: 5.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | akBookStyle  - a plugin for Piwigo                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2009      Nicolas Roudaire        http://www.nikrou.net  |
6// | Copyright(C) 2009      vdigital                                       |
7// +-----------------------------------------------------------------------+
8// | This program is free software; you can redistribute it and/or modify  |
9// | it under the terms of the GNU General Public License as published by  |
10// | the Free Software Foundation                                          |
11// |                                                                       |
12// | This program is distributed in the hope that it will be useful, but   |
13// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
14// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
15// | General Public License for more details.                              |
16// |                                                                       |
17// | You should have received a copy of the GNU General Public License     |
18// | along with this program; if not, write to the Free Software           |
19// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20// | USA.                                                                  |
21// +-----------------------------------------------------------------------+
22
23if (!defined('PHPWG_ROOT_PATH')) {
24  die('Hacking attempt!');
25}
26
27include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
28
29class akContent
30{
31  public function __construct($config) {
32    $this->plugin_config = $config;
33    $this->current_picture = 0;
34  }
35
36  public function loc_begin_index_thumbnails($images) {
37    global $template, $page;
38
39    $this->category_url = make_index_url(array('section' => 'category',
40                 'category' => $GLOBALS['page']['category'],
41                 'start' => $GLOBALS['page']['start']
42                 ) 
43           );
44    $this->current_picture = $this->getPictureId($images);
45
46    $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl'));
47    $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS);
48    $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS);
49
50    $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail');
51    $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']);
52    $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture]));
53    $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line);
54    $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event);
55    $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size);
56    $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl');
57    $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl');
58    $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl');
59    $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); 
60                /* Thumbnail Nav */
61                if (isset($page['navigation_bar'])) {
62                        $nav = explode(' | ', $page['navigation_bar']);
63                        if (substr($nav[1],0,2)=='<a') {
64                                $this->navbar['URL_PREV'] = substr($nav[1],9,stripos($nav[1],'" rel="'));
65                        }
66                        if (substr($nav[3],0,2)=='<a') {
67                                $this->navbar['URL_NEXT'] = substr($nav[3],9,stripos($nav[3],'" rel="'));
68                        }
69                        $template->assign('navbar', $this->navbar); 
70                }
71}
72
73  public function loc_end_index_thumbnails($tpl_vars, $images) {
74    foreach ($tpl_vars as &$tpl_var) {
75      $tpl_var['AK_URL'] = $this->makeAkUrl($tpl_var);
76
77      list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']);
78      $thumbnail_x_center = $thumbnail_width/2;
79      $thumbnail_y_center = $thumbnail_height/2;
80      $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2);
81      $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2);
82      $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2);
83      $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2);
84    }
85
86    return $tpl_vars;
87  }
88
89  /*** privates methods ***/
90  private function makeAkUrl($image) {
91    return sprintf('%s/picture/%d', $this->category_url, $image['ID']);
92
93  }
94
95  private function getPictureId($images) {
96    if ($GLOBALS['conf']['question_mark_in_urls']==false and
97      isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) {
98      $rewritten = $_SERVER["PATH_INFO"];
99      $rewritten = str_replace('//', '/', $rewritten);
100    } else {
101      $rewritten = '';
102      foreach (array_keys($_GET) as $keynum => $key) {
103        $rewritten = $key;
104        break;
105      }
106    }
107    $rewritten = make_index_url().$rewritten;
108    $pattern = sprintf('`^%s/(?:start\-\d+/)?picture/(\d+)$`',
109           str_replace('?', '\?', $this->category_url)
110           );
111
112    if (preg_match($pattern, $rewritten, $matches)) {
113      foreach ($images as $index => $image) {
114        if ($image['id']==$matches[1]) {
115          return $index;
116        }
117      }
118      return false;
119    } else {
120      return false;
121    }
122  }
123}
124?>
Note: See TracBrowser for help on using the repository browser.