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

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

fonctionnement sans javascript

File size: 3.6 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;
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_PIC_SRC', get_image_url($images[$this->current_picture]));
48    $template->assign('AK_BY_LINE', 3);
49    $template->assign('AK_RELOADED_IMAGE_TPL', AK_PLUGIN_TEMPLATE. '/ak_reloaded_image.tpl');
50    $template->assign('AK_PLUGIN_CSS', AK_PLUGIN_CSS);
51  }
52
53
54  public function loc_end_index_thumbnails($tpl_vars, $images) {
55    foreach ($tpl_vars as &$tpl_var) {
56
57      $tpl_var['AK_URL'] = $this->makeAkUrl($tpl_var);
58    }
59
60    return $tpl_vars;
61  }
62
63  /*** privates methods ***/
64  private function makeAkUrl($image) {
65    return sprintf('%s/picture/%d', $this->category_url, $image['ID']);
66
67  }
68
69  private function getPictureId($images) {
70    if ($GLOBALS['conf']['question_mark_in_urls']==false and
71        isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) {
72      $rewritten = $_SERVER["PATH_INFO"];
73      $rewritten = str_replace('//', '/', $rewritten);
74    } else {
75      $rewritten = '';
76      foreach (array_keys($_GET) as $keynum => $key) {
77        $rewritten = $key;
78        break;
79      }
80    }
81    $rewritten = make_index_url().$rewritten;
82    $pattern = sprintf('`^%s/(?:start\-\d+/)?picture/(\d+)$`',
83                       str_replace('?', '\?', $this->category_url)
84                       );
85
86    if (preg_match($pattern, $rewritten, $matches)) {
87      foreach ($images as $index => $image) {
88        if ($image['id']==$matches[1]) {
89          return $index;
90        }
91      }
92      return false;
93    } else {
94      return false;
95    }
96  }
97}
98?>
Note: See TracBrowser for help on using the repository browser.