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

Revision 6806, 4.2 KB checked in by nikrou, 9 years ago (diff)

Add permissions on add tags widget
Use default theme jquery library
Add help

Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Tags  - 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 t4u_Content
23{
24  public function __construct($config) {
25    $this->plugin_config = $config;
26
27    if (preg_match('!/t4u_addtags.*!', $_SERVER['QUERY_STRING']) 
28        && !empty($_POST['tags'])
29        && hasPermission('add')) {
30      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
31
32      $tag_ids = get_fckb_tag_ids($_POST['tags']);
33      set_tags($tag_ids, $_POST['image_id']);
34      redirect(get_absolute_root_url().$_POST['referer']);
35    }
36
37    if (preg_match('!/t4u_gettags.*!', $_SERVER['QUERY_STRING'])
38        && hasPermission('add')) {
39      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
40
41      $query = '
42SELECT
43    id AS tag_id,
44    name AS tag_name
45  FROM '.TAGS_TABLE.'
46;';
47      echo json_encode(get_fckb_taglist($query));
48      exit();
49    }
50  }
51
52  public function render_element_content($content, $picture) {
53    global $template;
54
55    if (!$this->hasPermission('add')) {
56      return false;
57    }
58
59    $template->func_known_script(array('id' => 'jquery',
60                                       'src' => get_root_url().'themes/default/js/jquery.packed.js'
61                                       ),
62                                 $template->smarty
63                                 );
64
65    $template->assign('T4U_JS', T4U_JS);
66    $template->assign('T4U_CSS', T4U_CSS);
67    $template->assign('T4U_IMGS', T4U_IMGS);
68    $template->assign('T4U_ADD_SCRIPT', $this->public_addtags_url());
69    $template->assign('T4U_GET_SCRIPT', $this->public_gettags_url());
70    $template->assign('T4U_IMAGE_ID', $picture['id']);
71    $template->assign('T4U_REFERER', htmlentities($picture['url']));
72    $template->assign('T4U_PERMISSION_DELETE', $this->hasPermission('delete'));
73
74    $related_tags = array();
75    if (!empty($template->smarty->_tpl_vars['related_tags'])) {
76      foreach ($template->smarty->_tpl_vars['related_tags'] as $id => $tag_infos) {
77        $related_tags['~~'.$tag_infos['id'].'~~'] = $tag_infos['name']; 
78      }
79    }
80    $template->assign('T4U_RELATED_TAGS', $related_tags);
81
82    $template->set_filename('add_tags', T4U_TEMPLATE.'/add_tags.tpl');
83    $template->assign_var_from_handle('PLUGIN_PICTURE_BEFORE', 'add_tags');
84  }   
85
86  private function public_addtags_url() {
87    $url = get_root_url().'index';
88    if ($GLOBALS['conf']['php_extension_in_urls']) {
89      $url .= '.php';
90    }
91    if ($GLOBALS['conf']['question_mark_in_urls']) {
92      $url .= '?';
93    }
94    $url .= '/t4u_addtags';
95    return $url;
96  }
97
98  private function public_gettags_url() {
99    $url = get_root_url().'index';
100    if ($GLOBALS['conf']['php_extension_in_urls']) {
101      $url .= '.php';
102    }
103    if ($GLOBALS['conf']['question_mark_in_urls']) {
104      $url .= '?';
105    }
106    $url .= '/t4u_gettags';
107    return $url;
108  }
109
110  private function hasPermission($permission='add') {
111    return 
112      (($this->plugin_config->getPermission($permission)!='')
113       and is_autorize_status(get_access_type_status($this->plugin_config->getPermission($permission))));
114  }
115}
116?>
Note: See TracBrowser for help on using the repository browser.