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

Last change on this file since 6852 was 6852, checked in by nikrou, 14 years ago

Updated german, thanks to duke
Updated spanish, thanks to jpr928
Remove configuration when plugin is uninstalled.
Add indexes in languages directories.
Update Free Software Foundation address

File size: 7.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | akBookStyle  - a plugin for Piwigo                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2009-2010 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., 51 Franklin Street, Fifth Floor, Boston,            |
20// | MA 02110-1301 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    $this->applicable = false;
37
38    $this->picture_pattern_format = '`^%s/(?:start\-\d+/)?picture/(\d+)$`';
39  }
40
41  public function page_force() {
42    global $page;
43
44    if (!empty($page['category'])) {
45      if (in_array($page['category']['id'], $this->plugin_config->ak_categories))
46      {
47        $this->applicable = true;
48        $page['nb_image_page'] = $this->plugin_config->ak_by_page;
49        $GLOBALS['user']['nb_image_page'] = $this->plugin_config->ak_by_page;
50      }
51      else
52      {
53        $this->applicable = false;
54      }     
55    }
56  }
57
58  public function loc_begin_index_thumbnails($images) {
59    global $template;
60   
61    if (!$this->applicable) {
62      return;
63    }
64
65    $this->category_url = make_index_url(array('section' => 'category',
66                                               'category' => $GLOBALS['page']['category'],
67                                               'start' => $GLOBALS['page']['start']
68                                               ) 
69                                         );
70    $this->picture_pattern = sprintf($this->picture_pattern_format,
71                                     str_replace('?', '\?', $this->category_url)
72                                     );
73                                     
74    $this->current_picture = $this->getPictureId($images);
75    $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl'));
76    $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS);
77    $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS);
78
79    $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail');
80    $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']);
81    $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line);
82    $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event);
83    $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size);
84    $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl');
85    $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl');
86    $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl');
87    $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); 
88    $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture]));
89
90    $template->assign('AK_NEXT', $this->getNextPicture($this->current_picture, $images));
91    $template->assign('AK_PREVIOUS', $this->getPreviousPicture($this->current_picture, $images));
92    if (empty($_SESSION['ak_previous_image'])) {
93      $_SESSION['ak_previous_image'] = $images[$this->current_picture]['id'];
94    }
95  }
96   
97  public function loc_end_index_thumbnails($tpl_vars, $images) {
98    if (!$this->applicable) {
99      return $tpl_vars;
100    }
101
102    $selected_one = false;
103    foreach ($tpl_vars as &$tpl_var) {
104      list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']);
105      $thumbnail_x_center = $thumbnail_width/2;
106      $thumbnail_y_center = $thumbnail_height/2;
107      $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2);
108      $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2);
109      $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2);
110      $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2);
111
112      if (!empty($_SESSION['ak_previous_image'])
113          && ($tpl_var['ID']==$_SESSION['ak_previous_image'])) {
114        $tpl_var['SELECTED'] = true;
115        $selected_one  =true;
116      }
117      if (!$selected_one) {
118        $tpl_vars[0]['SELECTED'] = true;
119      }
120    }
121
122    return $tpl_vars;
123  }
124
125  public function loc_end_picture() {
126    if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) 
127        && ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')) {     
128
129      $response = array();
130      $tpl_vars = $GLOBALS['template']->smarty->_tpl_vars;
131      $response['AK_PIC_SRC'] = $tpl_vars['SRC_IMG'];
132      $response['AK_PIC_ALT'] = $tpl_vars['ALT_IMG'];
133      if (isset($tpl_vars['ALT_IMG'])) {
134        $response['AK_PIC_TITLE'] = $tpl_vars['ALT_IMG'];
135      } else {
136        $response['AK_PIC_TITLE'] = '';
137      }
138
139      if (isset($tpl_vars['previous'])) {
140        $response['AK_PREVIOUS'] = $tpl_vars['previous']['url'];
141      }
142      if (isset($tpl_vars['next'])) {
143        $response['AK_NEXT'] = $tpl_vars['next']['url'];
144      }
145      $_SESSION['ak_previous_image'] = $tpl_vars['current']['id'];
146      header("Content-Type: application/json");
147      echo json_encode($response);
148      exit();
149
150    }
151  }
152
153  /*** privates methods ***/
154  private function makeAkUrl($image) {
155    return duplicate_picture_url(array('image_id' => $image['id'],
156                                       'image_file' => $image['file']
157                                       ),
158                                 array('start')
159                                 );
160  }
161
162  private function getPictureId($images) {
163    if ($GLOBALS['conf']['question_mark_in_urls']==false and
164      isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) {
165      $rewritten = $_SERVER["PATH_INFO"];
166      $rewritten = str_replace('//', '/', $rewritten);
167    } else {
168      $rewritten = '';
169      foreach (array_keys($_GET) as $keynum => $key) {
170        $rewritten = $key;
171        break;
172      }
173    }
174    $rewritten = make_index_url().$rewritten;
175
176    if (preg_match($this->picture_pattern, $rewritten, $matches)) {
177      foreach ($images as $index => $image) {
178        if ($image['id']==$matches[1]) {
179          return $index;
180        }
181      }
182      return false;
183    } else {
184      return false;
185    }
186  }
187
188  private function getPreviousPicture($current, $images) {
189    $previous = $current-1;
190    if ($previous>0) {
191      return $this->makeAkUrl($images[$previous]);
192    } else {
193      return null;
194    }
195  }
196
197  private function getNextPicture($current, $images) {
198    $next = $current+1;
199    if ($next<count($images)) {
200      return $this->makeAkUrl($images[$next]);
201    } else {
202      return null;
203    }
204  }
205}
206?>
Note: See TracBrowser for help on using the repository browser.