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

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

Add IT thanks to sergix
Add CZ thanks to webprostor-hosting
Bug fix : Flash animation didn't work when category used a permanink.
Update FSF address
Remove configuration when plugin is uninstalled.

File size: 4.7 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    if (!empty($page['category']['permalink'])) {
74      $template->assign('PW_XML', sprintf($this->fmt_xml, $page['category']['permalink']));
75    } else {
76      $template->assign('PW_XML', sprintf($this->fmt_xml, $page['category']['id']));
77    }
78    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
79    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
80    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
81    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
82  }
83
84  public function loc_begin_index_category_thumbnails($categories) {
85    global $template, $page;
86   
87    if (!$this->applicable) {
88      return;
89    }
90
91    if ($this->query_string!=null)
92    {
93      $image_ids = array();
94      foreach ($categories as $category) {
95        $image_ids[] = $category['representative_picture_id'];
96      }
97      $thumbnail_src_of = array();
98     
99      $query = '
100SELECT id, path, tn_ext
101  FROM '.IMAGES_TABLE.'
102  WHERE id IN ('.implode(',', $image_ids).')
103;';
104      $result = pwg_query($query);
105      while ($row = pwg_db_fetch_assoc($result))
106      {
107        $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
108      }
109
110      foreach ($categories as &$category) {
111        $category['url'] = make_index_url(array('category' => $category));
112        $category['path'] = $thumbnail_src_of[$category['representative_picture_id']];
113      }
114      $this->pw_xml($categories);
115    }
116   
117    $template->set_filename('index_category_thumbnails', PW_TEMPLATE . '/animation.tpl');
118    $template->assign('PW_XML', sprintf($this->fmt_xml, $page['category']['id']));
119    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
120    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
121    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
122    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
123  }
124
125  private function pw_xml($images) {
126    include PW_TEMPLATE . '/liste.xml';
127    exit();
128  }
129}
130?>
Note: See TracBrowser for help on using the repository browser.