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

Last change on this file since 3876 was 3876, checked in by nikrou, 15 years ago

Bug 1159: fix
Medium image are loaded in ajax mode.

File size: 6.9 KB
RevLine 
[3761]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
[3764]23if (!defined('PHPWG_ROOT_PATH')) {
24  die('Hacking attempt!');
25}
[3770]26
[3787]27include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
28
[3770]29class akContent
30{
31  public function __construct($config) {
32    $this->plugin_config = $config;
[3787]33    $this->current_picture = 0;
[3838]34    $this->next_picture = null;
35    $this->previous_picture = null;
[3843]36    $this->applicable = false;
[3876]37
38    $this->picture_pattern_format = '`^%s/(?:start\-\d+/)?picture/(\d+)$`';
[3770]39  }
40
[3843]41  public function page_force() {
42    global $page;
[3876]43
44    if (isset($page['category'])) {
[3843]45      $cat_filter = $this->plugin_config->ak_categories;
[3844]46      $this->applicable = (stripos($page['category']['name'], $cat_filter) === false) ? false:true;
[3843]47      if ( $this->applicable ) { 
48        $page['nb_image_page'] = $this->plugin_config->ak_by_page;
49      }
50    }
[3842]51  }
52
[3787]53  public function loc_begin_index_thumbnails($images) {
[3842]54    global $template;
[3876]55
[3843]56    if ($this->applicable === false) return;
[3787]57    $this->category_url = make_index_url(array('section' => 'category',
[3876]58                                               'category' => $GLOBALS['page']['category'],
59                                               'start' => $GLOBALS['page']['start']
60                                               ) 
61                                         );
62    $this->picture_pattern = sprintf($this->picture_pattern_format,
63                                     str_replace('?', '\?', $this->category_url)
64                                     );
65                                     
[3787]66    $this->current_picture = $this->getPictureId($images);
67
[3770]68    $template->set_filenames(array('index_thumbnails'=> AK_PLUGIN_TEMPLATE . '/ak_thumbnails.tpl'));
[3791]69    $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS);
70    $template->assign('AK_PLUGIN_JS', AK_PLUGIN_JS);
71
[3792]72    $template->assign('AK_DIR_THUMBNAIL', isset($GLOBALS['conf']['dir_thumbnail'])?$GLOBALS['conf']['dir_thumbnail']:'thumbnail');
[3791]73    $template->assign('AK_PREFIX_THUMBNAIL', $GLOBALS['conf']['prefix_thumbnail']);
74    $template->assign('AK_BY_LINE', $this->plugin_config->ak_by_line);
[3806]75    $template->assign('AK_MOUSE_EVENT', $this->plugin_config->ak_mouse_event);
[3792]76    $template->assign('AK_THUMBNAIL_SIZE', $this->plugin_config->ak_thumbnail_size);
[3770]77    $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl');
[3806]78    $template->assign('AK_VERTICAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_vertical.tpl');
[3807]79    $template->assign('AK_HORIZONTAL_TPL', AK_PLUGIN_TEMPLATE. '/ak_horizontal.tpl');
[3804]80    $template->assign('AK_THUMBNAILS_LOC', $this->plugin_config->ak_thumbnails_loc); 
[3838]81    $template->assign('AK_PIC_SRC', get_image_url($images[$this->current_picture]));
[3787]82
[3838]83    $template->assign('AK_NEXT', $this->getNextPicture($this->current_picture, $images));
84    $template->assign('AK_PREVIOUS', $this->getPreviousPicture($this->current_picture, $images));
85  }
86
[3787]87  public function loc_end_index_thumbnails($tpl_vars, $images) {
[3843]88    if ($this->applicable === false) return $tpl_vars;
[3787]89    foreach ($tpl_vars as &$tpl_var) {
[3792]90      list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']);
91      $thumbnail_x_center = $thumbnail_width/2;
92      $thumbnail_y_center = $thumbnail_height/2;
93      $tpl_var['CLIP_TOP'] = round($thumbnail_y_center - $this->plugin_config->ak_thumbnail_size/2);
94      $tpl_var['CLIP_RIGHT'] = round($thumbnail_x_center + $this->plugin_config->ak_thumbnail_size/2);
95      $tpl_var['CLIP_BOTTOM'] = round($thumbnail_y_center + $this->plugin_config->ak_thumbnail_size/2);
96      $tpl_var['CLIP_LEFT'] = round($thumbnail_x_center - $this->plugin_config->ak_thumbnail_size/2);
[3787]97    }
98
99    return $tpl_vars;
100  }
101
[3876]102  public function loc_end_picture() {
103    if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) 
104        && ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')) {     
105      header("Content-Type: application/json");
106
107      $response = array();
108      $tpl_vars = $GLOBALS['template']->smarty->_tpl_vars;
109      $response['AK_PIC_SRC'] = $tpl_vars['SRC_IMG'];
110      $response['AK_PIC_ALT'] = $tpl_vars['ALT_IMG'];
111      if (isset($tpl_vars['ALT_IMG'])) {
112        $response['AK_PIC_TITLE'] = $tpl_vars['ALT_IMG'];
113      } else {
114        $response['AK_PIC_TITLE'] = '';
115      }
116
117      if (isset($tpl_vars['previous'])) {
118        $response['AK_PREVIOUS'] = $tpl_vars['previous']['url'];
119      }
120      if (isset($tpl_vars['next'])) {
121        $response['AK_NEXT'] = $tpl_vars['next']['url'];
122      }
123      echo json_encode($response);
124      exit();
125
126    }
127  }
128
[3787]129  /*** privates methods ***/
130  private function makeAkUrl($image) {
131    return sprintf('%s/picture/%d', $this->category_url, $image['ID']);
132  }
133
134  private function getPictureId($images) {
135    if ($GLOBALS['conf']['question_mark_in_urls']==false and
[3829]136      isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) {
[3787]137      $rewritten = $_SERVER["PATH_INFO"];
138      $rewritten = str_replace('//', '/', $rewritten);
139    } else {
140      $rewritten = '';
141      foreach (array_keys($_GET) as $keynum => $key) {
[3829]142        $rewritten = $key;
143        break;
[3787]144      }
145    }
146    $rewritten = make_index_url().$rewritten;
147
[3876]148    if (preg_match($this->picture_pattern, $rewritten, $matches)) {
[3787]149      foreach ($images as $index => $image) {
[3829]150        if ($image['id']==$matches[1]) {
151          return $index;
152        }
[3787]153      }
154      return false;
155    } else {
156      return false;
157    }
158  }
[3838]159
160  private function getPreviousPicture($current, $images) {
[3876]161    $previous = $current-1;
[3838]162    if ($previous>0) {
163      return $this->makeAkUrl(array('ID' => $images[$previous]['id']));
164    } else {
165      return null;
166    }
167  }
168
169  private function getNextPicture($current, $images) {
[3876]170    $next = $current+1;
[3838]171    if ($next<count($images)) {
172      return $this->makeAkUrl(array('ID' => $images[$next]['id']));
173    } else {
174      return null;
175    }
176  }
[3770]177}
[3761]178?>
Note: See TracBrowser for help on using the repository browser.