root/trunk/gregarius/admin/tags.php

Revision 1741, 7.8 kB (checked in by mbonetti, 16 months ago)

we only want actual item tags, no categories, thank you

Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003 - 2006 Marco Bonetti
5#
6###############################################################################
7# This program is free software and open source software; you can redistribute
8# it and/or modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the License,
10# or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE.      See the GNU General Public License for
15# more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
20# http://www.gnu.org/licenses/gpl.html
21#
22###############################################################################
23# E-mail:          mbonetti at gmail dot com
24# Web page:      http://gregarius.net/
25#
26###############################################################################
27
28function tags_admin(){
29        return CST_ADMIN_DOMAIN_TAGS;
30}
31
32function tags(){
33
34        // Fix for #16: Admin (et al.) should not rely on l10n labels for actions:
35        // Look for a meta-action first, which should be the (untranslated) *name* of
36        // the (translated) action constant.
37
38        // Fixme: should replace 'action's with a constant
39        if (array_key_exists(CST_ADMIN_METAACTION,$_REQUEST)) {
40                $__action__ = $_REQUEST[CST_ADMIN_METAACTION];
41        } elseif (array_key_exists('action',$_REQUEST)) {
42                $__action__ = $_REQUEST['action'];
43        } else {
44                $__action__ = "";
45        }
46
47        if (isset($_REQUEST['id'])) {
48                $tid = sanitize($_REQUEST['id'],RSS_SANITIZER_NUMERIC);
49        }
50
51        $ret__ = CST_ADMIN_DOMAIN_TAGS;
52        switch ($__action__) {
53
54        case CST_ADMIN_EDIT_ACTION:
55                tag_edit($tid);
56                $ret__ = CST_ADMIN_DOMAIN_NONE;
57                break;
58
59        case CST_ADMIN_DELETE_ACTION:
60                if (array_key_exists(CST_ADMIN_CONFIRMED,$_POST) && $_POST[CST_ADMIN_CONFIRMED] == __('Yes')) {
61                        $sql = "delete from " . getTable("tag") ." where id=$tid";
62                        rss_query($sql);
63                        $sql = "delete from " . getTable("metatag") ." where tid=$tid";
64                        rss_query($sql);
65                        rss_invalidate_cache();
66                } elseif (array_key_exists(CST_ADMIN_CONFIRMED,$_REQUEST) && $_REQUEST[CST_ADMIN_CONFIRMED] == __('No')) {
67                        // nop;
68                } elseif (array_key_exists('me_delete', $_REQUEST)) {
69                        if(array_key_exists('me_do_delete', $_REQUEST) && "1" == $_REQUEST['me_do_delete']) {
70                                $ids = array();
71                                foreach($_REQUEST as $key => $val) {
72                                        if(preg_match('/^tcb([0-9]+)$/', $key, $match)) {
73                                                if(($id = (int) $_REQUEST[$key]) > 0) {
74                                                        $ids[] = $id;
75                                                }
76                                        }
77                                }
78
79                                if(count($ids) > 0)  {
80                                        $sql = "delete from " . getTable("tag") . " where id in (".implode(',', $ids) . ")";
81                                        rss_query($sql);
82                                        $sql = "delete from " . getTable("metatag") . " where tid in (".implode(',', $ids) . ")";
83                                        rss_query($sql);
84                                        rss_invalidate_cache();
85                                }
86                        }
87                } else {
88
89                        list($tname) = rss_fetch_row(rss_query("select tag from " .getTable("tag") ." where id = $tid"));
90
91                        echo "<form class=\"box\" method=\"post\" action=\"" .$_SERVER['PHP_SELF'] ."\">\n"
92                        ."<p class=\"error\">";
93                        printf(__("Are you sure you wish to delete '%s'?"),$tname);
94                        echo "</p>\n"
95                        ."<p><input type=\"submit\" name=\"".CST_ADMIN_CONFIRMED."\" value=\"". __('No') ."\"/>\n"
96                        ."<input type=\"submit\" name=\"".CST_ADMIN_CONFIRMED."\" value=\"". __('Yes') ."\"/>\n"
97                        ."<input type=\"hidden\" name=\"id\" value=\"$tid\"/>\n"
98                        ."<input type=\"hidden\" name=\"".CST_ADMIN_DOMAIN."\" value=\"".CST_ADMIN_DOMAIN_TAGS."\"/>\n"
99                        ."<input type=\"hidden\" name=\"action\" value=\"". CST_ADMIN_DELETE_ACTION ."\"/>\n"
100                        ."</p>\n</form>\n";
101                        $ret__ = CST_ADMIN_DOMAIN_NONE;
102                }
103                break;
104        case CST_ADMIN_SUBMIT_EDIT:
105                // TBD
106                $new_label = preg_replace(ALLOWED_TAGS_REGEXP,'', $_REQUEST['t_name']);
107                // also replace whitespaces
108                $new_label = str_replace(' ','',$new_label);
109                if (is_numeric($tid) && strlen($new_label) > 0) {
110                        $res = rss_query("select count(*) as cnt from " . getTable("tag") ." where binary tag='".rss_real_escape_string($new_label)."'");
111                        list($cnt) = rss_fetch_row($res);
112                        if ($cnt > 0) {
113                                rss_error(sprintf(__("You can't rename this item '%s' because such an item already exists."),$new_label), RSS_ERROR_ERROR,true);
114                                break;
115                        }
116                        rss_query("update " .getTable("tag") ." set tag='".rss_real_escape_string($new_label)."' where id=$tid");
117                        rss_invalidate_cache();
118                }
119                break;
120        default:
121                break;
122        }
123  echo "<script type=\"text/javascript\">\n"
124    ."//<!--\n"
125    ."function cbtoggle() {\n"
126    ."var c=document.getElementById('mastercb').checked;\n"
127    ."var cs=document.getElementById('tagtable').getElementsByTagName('input');\n"
128    ."for(i=0;i<cs.length;i++) {\n"
129    ."if (cs[i].type == 'checkbox') cs[i].checked = c;\n"
130    ."}\n" 
131    ."}\n" 
132                ."</script>\n";
133
134        echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n"
135        ."<h2 class=\"trigger\">".__('Tags')."</h2>\n"
136        ."<div id=\"admin_tags\" class=\"trigger\">"
137        ."<table id=\"tagtable\">\n"
138        ."<tr>\n"
139  ."\t<th><input type=\"checkbox\" id=\"mastercb\" onclick=\"cbtoggle();\" /></th>\n"
140        ."\t<th class=\"cntr\">". __('Tags') ."</th>\n"
141        ."\t<th>". __('Action') ."</th>\n"
142        ."</tr>\n";
143
144        $sql = sprintf("select id, tag from %s t left join %s m on (t.id = m.tid) where m.ttype = 'item'", getTable("tag"), getTable("metatag"));
145        $res = rss_query($sql);
146        $cntr = 0;
147        while (list($id, $tag) = rss_fetch_row($res)) {
148                $class_ = (($cntr++ % 2 == 0)?"even":"odd");
149                echo "<tr class=\"$class_\">\n"
150    ."\t<td><input type=\"checkbox\" name=\"tcb$id\" value=\"$id\" id=\"scb_$id\" /></td>\n"
151                ."\t<td><label for=\"scb_$id\">".htmlspecialchars($tag)."</label></td>\n"
152                ."\t<td><a href=\"".$_SERVER['PHP_SELF']. "?".CST_ADMIN_DOMAIN."=". CST_ADMIN_DOMAIN_TAGS
153                ."&amp;action=". CST_ADMIN_EDIT_ACTION. "&amp;id=$id\">" . __('edit')
154                ."</a>\n"
155                ."|<a href=\"".$_SERVER['PHP_SELF']. "?".CST_ADMIN_DOMAIN."=". CST_ADMIN_DOMAIN_TAGS
156                ."&amp;action=". CST_ADMIN_DELETE_ACTION ."&amp;id=$id\">" . __('delete') ."</a>\n"
157                ."|<a href=\"".getPath('tag/'.htmlspecialchars($tag))."\">" . __('view') ."</a>\n"             
158                ."</td>\n"
159                ."</tr>\n";
160        }
161        echo "</table>\n";
162        echo "<fieldset>\n"
163        ."<legend>".__('Selected')."...</legend>\n"
164        ."<p>\n"
165        ."<input type=\"submit\" id=\"me_delete\" name=\"me_delete\" value=\"".__('Delete')."\" />\n"
166        ."<input type=\"checkbox\" name=\"me_do_delete\" id=\"me_do_delete\" value=\"1\" />\n"
167        ."<label for=\"me_do_delete\">".__("I'm sure!")."</label>\n"
168        ."<input type=\"hidden\" name=\"action\" value=\"".CST_ADMIN_DELETE_ACTION."\" />\n"
169        ."<input type=\"hidden\" name=\"".CST_ADMIN_DOMAIN."\" value=\"".CST_ADMIN_DOMAIN_TAGS."\" />\n"
170        ."</fieldset>\n"
171        ."</form>\n"
172        ."</div>\n";
173}
174
175function tag_edit($tid){
176        $sql = "select id, tag from " . getTable("tag") ." where id=$tid";
177        $res = rss_query($sql);
178        list ($id, $tag) = rss_fetch_row($res);
179
180        echo "<div>\n"
181        ."<h2>".ucfirst(__('edit'))." '$tag'</h2>\n"
182        ."<form method=\"post\" action=\"" .$_SERVER['PHP_SELF'] ."\" id=\"tagedit\">\n"
183
184        ."<div style=\"inline\"><input type=\"hidden\" name=\"".CST_ADMIN_DOMAIN."\" value=\"". CST_ADMIN_DOMAIN_TAGS."\"/>\n"
185        ."<input type=\"hidden\" name=\"action\" value=\"".CST_ADMIN_SUBMIT_EDIT."\"/>\n"
186        ."<input type=\"hidden\" name=\"id\" value=\"$tid\"/>\n"
187        ."<label for=\"t_name\">". __('Rename to...') ."</label>\n"
188        ."<input type=\"text\" id=\"t_name\" name=\"t_name\" value=\"$tag\"/>\n"
189        ."<input type=\"submit\" name=\"action_\" value=\"". __('Submit Changes') ."\"/></div>"
190        ."</form></div>\n";
191}
Note: See TracBrowser for help on using the browser.