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

Last change on this file since 6430 was 5647, checked in by nikrou, 15 years ago
  • Improve categories selections in admin
  • Fix some mispelling language keys
File size: 4.5 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | 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/%d/pw.xml';
30    $xml_pattern = '`category/(\d*)/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', sprintf($this->fmt_xml, $page['category']['id']));
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      {
103        $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
104      }
105
106      foreach ($categories as &$category) {
107        $category['url'] = make_index_url(array('category' => $category));
108        $category['path'] = $thumbnail_src_of[$category['representative_picture_id']];
109      }
110      $this->pw_xml($categories);
111    }
112   
113    $template->set_filename('index_category_thumbnails', PW_TEMPLATE . '/animation.tpl');
114    $template->assign('PW_XML', sprintf($this->fmt_xml, $page['category']['id']));
115    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
116    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
117    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
118    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
119  }
120
121  private function pw_xml($images) {
122    include PW_TEMPLATE . '/liste.xml';
123    exit();
124  }
125}
126?>
Note: See TracBrowser for help on using the repository browser.