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

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

Add config values.
'ak_by_page' is operational. (bug 1162)
'ak_categories' is not active currently.

File size: 5.9 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    $this->next_picture = null;
35    $this->previous_picture = null;
36  }
37
38  public function user_force() {
39    $GLOBALS['user']['nb_image_page'] = $this->plugin_config->ak_by_page;
40  }
41
42  public function loc_begin_index_thumbnails($images) {
43    global $template;
44    $this->category_url = make_index_url(array('section' => 'category',
45                 'category' => $GLOBALS['page']['category'],
46                 'start' => $GLOBALS['page']['start']
47                 ) 
48           );
49    $this->current_picture = $this->getPictureId($images);
50
51    $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl'));
52    $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS);
53    $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS);
54
55    $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail');
56    $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']);
57    $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line);
58    $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event);
59    $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size);
60    $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl');
61    $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl');
62    $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl');
63    $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); 
64    $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture]));
65
66    $template->assign('AK_NEXT', $this->getNextPicture($this->current_picture, $images));
67    $template->assign('AK_PREVIOUS', $this->getPreviousPicture($this->current_picture, $images));
68  }
69
70  public function loc_end_index_thumbnails($tpl_vars, $images) {
71    foreach ($tpl_vars as &$tpl_var) {
72      $tpl_var['AK_URL'] = $this->makeAkUrl($tpl_var);
73
74      list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']);
75      $thumbnail_x_center = $thumbnail_width/2;
76      $thumbnail_y_center = $thumbnail_height/2;
77      $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2);
78      $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2);
79      $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2);
80      $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2);
81    }
82
83    return $tpl_vars;
84  }
85
86  /*** privates methods ***/
87  private function makeAkUrl($image) {
88    return sprintf('%s/picture/%d', $this->category_url, $image['ID']);
89
90  }
91
92  private function getPictureId($images) {
93    if ($GLOBALS['conf']['question_mark_in_urls']==false and
94      isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) {
95      $rewritten = $_SERVER["PATH_INFO"];
96      $rewritten = str_replace('//', '/', $rewritten);
97    } else {
98      $rewritten = '';
99      foreach (array_keys($_GET) as $keynum => $key) {
100        $rewritten = $key;
101        break;
102      }
103    }
104    $rewritten = make_index_url().$rewritten;
105    $pattern = sprintf('`^%s/(?:start\-\d+/)?picture/(\d+)$`',
106           str_replace('?', '\?', $this->category_url)
107           );
108
109    if (preg_match($pattern, $rewritten, $matches)) {
110      foreach ($images as $index => $image) {
111        if ($image['id']==$matches[1]) {
112          return $index;
113        }
114      }
115      return false;
116    } else {
117      return false;
118    }
119  }
120
121  private function getPreviousPicture($current, $images) {
122    $previous = $current--;
123    if ($previous>0) {
124      return $this->makeAkUrl(array('ID' => $images[$previous]['id']));
125    } else {
126      return null;
127    }
128  }
129
130  private function getNextPicture($current, $images) {
131    $index_current = null;
132    foreach ($images as $index => $image) {
133      if ($image['id']==$current) {
134        $index_current = $index;
135        break;
136      }
137    }
138
139    $next = $index_current+1;
140    if ($next<count($images)) {
141      return $this->makeAkUrl(array('ID' => $images[$next]['id']));
142    } else {
143      return null;
144    }
145  }
146}
147?>
Note: See TracBrowser for help on using the repository browser.