source: extensions/user_tags/include/t4u_content.class.php

Last change on this file was 25653, checked in by nikrou, 10 years ago

small issue with paramter called by value

File size: 3.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Tags  - a plugin for Piwigo                                      |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010-2013 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 version 2 as     |
9// | published by 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 t4u_Content
23{
24  public function __construct($config) {
25    $this->plugin_config = &$config;
26  }
27
28  public function render_element_content($content, $picture) {
29    global $template;
30
31    $template->set_prefilter('picture', array(__CLASS__, 'picture_prefilter'));
32
33    if ($this->plugin_config->hasPermission('add')) {
34      load_language('plugin.lang', T4U_PLUGIN_LANG);
35
36      $template->assign('T4U_JS', T4U_JS);
37      $template->assign('T4U_CSS', T4U_CSS);
38      $template->assign('T4U_IMGS', T4U_IMGS);
39      $template->assign('T4U_PERMISSION_DELETE', $this->plugin_config->hasPermission('delete'));
40      $template->assign('T4U_UPDATE_SCRIPT', get_root_url().'ws.php?format=json&method='.T4U_WS.'update');
41      $template->assign('T4U_UPDATE_METHOD', T4U_WS.'update');
42      $template->assign('T4U_LIST_SCRIPT', get_root_url().'ws.php?format=json&method='.T4U_WS.'list');
43      $template->assign('T4U_IMAGE_ID', $picture['id']);
44      $template->assign('T4U_REFERER', urlencode($picture['url']));
45      $template->assign('T4U_PERMISSION_DELETE', $this->plugin_config->hasPermission('delete'));
46      if ($this->plugin_config->hasPermission('existing_tags_only')) {
47        $template->assign('T4U_ALLOW_CREATION', 'false');
48      } else {
49        $template->assign('T4U_ALLOW_CREATION', 'true');
50      }
51     
52      $related_tags = array();
53      $_tpl_vars = $template->get_template_vars('related_tags');
54      if (!empty($_tpl_vars)) {
55        foreach ($_tpl_vars as $id => $tag_infos) {
56          $related_tags['~~'.$tag_infos['id'].'~~'] = $tag_infos['name']; 
57        }
58        $template->assign('T4U_RELATED_TAGS', $related_tags);
59      }
60
61      $template->set_filename('add_tags', T4U_TEMPLATE.'/add_tags.tpl');
62      $template->assign_var_from_handle('PLUGIN_PICTURE_AFTER', 'add_tags');
63    }
64
65    return $content;
66  }
67
68  public static function picture_prefilter($source, $smarty) {
69    $pattern = '{if $display_info.tags and isset($related_tags)}';
70    $replace = '{if $display_info.tags}';
71   
72    return str_replace($pattern, $replace, $source);
73  }
74}
Note: See TracBrowser for help on using the repository browser.