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

Revision 6798, 3.9 KB checked in by nikrou, 10 years ago (diff)

First public release User Tags

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