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

Last change on this file since 7830 was 7385, checked in by plg, 13 years ago

bug 1932: use core functions to create URLs.

Make the use of query_string more explicit (show_xml_list)

Warning: PhotoWidget currently doesn't work with $confquestion_mark_in_urls = false

File size: 4.8 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 $show_xml_list = false, $applicable = false;
25 
26  public function __construct($config) {
27    $this->plugin_config = $config;
28  }
29
30  public function loc_begin_index() {
31    global $page;
32
33    $this->applicable = false;
34   
35    if (!empty($page['category'])) {
36      if ($this->plugin_config->pw_all_categories==1 or
37          (is_array($this->plugin_config->pw_categories) &&
38           in_array($page['category']['id'], $this->plugin_config->pw_categories)))
39      {
40        $this->applicable = true;
41      }
42    }
43
44    $match_content = $_SERVER['QUERY_STRING'];
45    if (PHPWG_ROOT_PATH != $page['root_path']) {
46      $match_content = $_SERVER['PATH_INFO'];
47    }
48
49    $xml_pattern = '#/pw\.xml$#';
50    if (preg_match($xml_pattern, $match_content)) {
51      $this->show_xml_list = true;
52    }
53  }
54
55  public function loc_begin_index_thumbnails($images) {
56    global $template, $page;
57   
58    if (!$this->applicable) {
59      return;
60    }
61
62    if ($this->show_xml_list)
63    {
64      foreach ($images as &$image) {
65        $image['url'] = duplicate_picture_url(
66          array('image_id' => $image['id'],
67                'image_file' => $image['file']
68            ),
69          array('start')
70          );
71      }
72      $this->pw_xml($images);
73    }
74
75    $template->set_filename('index_thumbnails', PW_TEMPLATE . '/animation.tpl');
76    $template->assign('PW_XML', $this->getXmlPath($page['category']));
77    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
78    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
79    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
80    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
81  }
82
83  public function loc_begin_index_category_thumbnails($categories) {
84    global $template, $page;
85   
86    if (!$this->applicable) {
87      return;
88    }
89
90    if ($this->show_xml_list)
91    {
92      $image_ids = array();
93      foreach ($categories as $category) {
94        $image_ids[] = $category['representative_picture_id'];
95      }
96      $thumbnail_src_of = array();
97     
98      $query = '
99SELECT id, path, tn_ext
100  FROM '.IMAGES_TABLE.'
101  WHERE id IN ('.implode(',', $image_ids).')
102;';
103      $result = pwg_query($query);
104      while ($row = pwg_db_fetch_assoc($result)) {
105        $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
106      }
107
108      foreach ($categories as &$category) {
109        $category['url'] = make_index_url(array('category' => $category));
110        $category['path'] = $thumbnail_src_of[$category['representative_picture_id']];
111      }
112      $this->pw_xml($categories);
113    }
114   
115    $template->set_filename('index_category_thumbnails', PW_TEMPLATE . '/animation.tpl');
116    $template->assign('PW_XML', $this->getXmlPath($page['category']));
117    $template->assign('PW_BGCOLOR', $this->plugin_config->pw_bgcolor);
118    $template->assign('PW_WIDTH', $this->plugin_config->pw_width);
119    $template->assign('PW_HEIGHT', $this->plugin_config->pw_height);
120    $template->assign('PW_SWF_ANIMATION', PW_SWF . '/photowidget.swf');
121  }
122
123  private function getXmlPath($category) {
124    global $page;
125
126    return sprintf(
127      '%s/pw.xml',
128      make_index_url(
129        array(
130          'section' => 'categories',
131          'category' => $page['category']
132          )
133        )
134      );
135  }
136
137  private function pw_xml($images) {
138    include PW_TEMPLATE . '/liste.xml';
139    exit();
140  }
141}
142?>
Note: See TracBrowser for help on using the repository browser.