source: extensions/photoWidget/include/photoWidgetContent.class.php @ 7315

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

Fix issue 1932 : photoWidget is not compatible with id-name category url style

File size: 4.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | photoWidget  - a plugin for Piwigo                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010 Nicolas Roudaire             http://www.nikrou.net  |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,            |
19// | MA 02110-1301 USA.                                                    |
20// +-----------------------------------------------------------------------+
21
22class photoWidgetContent
23{
24  private $query_string = null, $applicable = false;
25 
26  public function __construct($config) {
27    $this->plugin_config = $config;
28
29    $this->fmt_xml = make_index_url() . '/category/%s/pw.xml';
30    $xml_pattern = '`category/([^/]*)/pw\.xml$`';
31   
32    if (preg_match($xml_pattern, $_SERVER['QUERY_STRING'], $matches)) {
33      $this->query_string = $matches[1];
34    }
35  }
36
37  public function loc_begin_index() {
38    global $page;
39
40    $this->applicable = false;
41   
42    if (!empty($page['category'])) {
43      if ($this->plugin_config->pw_all_categories==1 or
44          (is_array($this->plugin_config->pw_categories) &&
45           in_array($page['category']['id'], $this->plugin_config->pw_categories)))
46      {
47        $this->applicable = true;
48      }
49    }
50  }
51
52  public function loc_begin_index_thumbnails($images) {
53    global $template, $page;
54   
55    if (!$this->applicable) {
56      return;
57    }
58
59    if ($this->query_string!=null)
60    {
61      foreach ($images as &$image) {
62        $image['url'] = duplicate_picture_url(
63          array('image_id' => $image['id'],
64                'image_file' => $image['file']
65            ),
66          array('start')
67          );
68      }
69      $this->pw_xml($images);
70    }
71
72    $template->set_filename('index_thumbnails', PW_TEMPLATE . '/animation.tpl');
73    $template->assign('PW_XML', $this->getXmlPath($page['category']));
74    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
75    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
76    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
77    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
78  }
79
80  public function loc_begin_index_category_thumbnails($categories) {
81    global $template, $page;
82   
83    if (!$this->applicable) {
84      return;
85    }
86
87    if ($this->query_string!=null)
88    {
89      $image_ids = array();
90      foreach ($categories as $category) {
91        $image_ids[] = $category['representative_picture_id'];
92      }
93      $thumbnail_src_of = array();
94     
95      $query = '
96SELECT id, path, tn_ext
97  FROM '.IMAGES_TABLE.'
98  WHERE id IN ('.implode(',', $image_ids).')
99;';
100      $result = pwg_query($query);
101      while ($row = pwg_db_fetch_assoc($result)) {
102        $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
103      }
104
105      foreach ($categories as &$category) {
106        $category['url'] = make_index_url(array('category' => $category));
107        $category['path'] = $thumbnail_src_of[$category['representative_picture_id']];
108      }
109      $this->pw_xml($categories);
110    }
111   
112    $template->set_filename('index_category_thumbnails', PW_TEMPLATE . '/animation.tpl');
113    $template->assign('PW_XML', $this->getXmlPath($page['category']));
114    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
115    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
116    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
117    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
118  }
119
120  private function getXmlPath($category) {
121    if (!empty($category['permalink'])) {
122      return sprintf($this->fmt_xml, $category['permalink']);
123    } elseif ( $GLOBALS['conf']['category_url_style']=='id-name' ) {
124      $id_name = $category['id'] . '-' . str2url($category['name']);
125      return sprintf($this->fmt_xml, $id_name);
126    } else {
127      return sprintf($this->fmt_xml, $category['id']);
128    }   
129  }
130
131  private function pw_xml($images) {
132    include PW_TEMPLATE . '/liste.xml';
133    exit();
134  }
135}
136?>
Note: See TracBrowser for help on using the repository browser.