root/branches/multiuser/plugins/delicious.php

Revision 1606, 3.6 kB (checked in by mdodoo, 2 years ago)

This was really annoying, and took more time than the previous commit. For some reason, "svn diff" does not work correctly on my machine.

  • Property svn:keywords set to Rev
Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003, 2004 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
28
29/// Name: del.icio.us Tags
30/// Author: Marco Bonetti
31/// Description: Fetches tag suggestions from del.icio.us
32/// Version: 0.5
33
34
35function __delicious_js_register($js) {
36        $js[] = getPath(). RSS_PLUGINS_DIR . "/delicious.php?deljs";
37        return $js;
38}
39
40if (isset($_REQUEST['deljs'])) {
41        require_once('../core.php');
42        rss_bootstrap(false,'$Revision$',24);
43        require_once('../init.php');
44?>
45function get_from_delicious(id) {
46 x___exp__getFromDelicious(id,getFromDelicious_cb);
47}
48
49function getFromDelicious_cb(ret) {
50 data=ret.split(',');
51 id=data[0];
52 tags=data[1].split(' ');
53 var span=document.getElementById('dt'+id);
54 html = '';
55 for(i=0;i<tags.length;i++) {
56  if (tags[i] != '') {
57    html += "<a href=\"#\" onclick=\"addToTags(" + id +",'"
58    +tags[i]
59    +"'); return false;\">"+tags[i]+"</a>"
60    if(i<tags.length -1) { html += "&nbsp;"; }
61  }
62 }
63 if (html == '') {
64  html = '<?php echo  __('no suggestions') ?>';
65 }
66 span.innerHTML = '(' + html + ')';
67}
68
69function addToTags(id,tag) {
70 var fld = document.getElementById("tfield" + id);
71 fld.value=fld.value+ " " + tag;
72}
73
74<?php                   
75        flush();
76        exit();
77}
78
79function __delicious_appendAJAXfunction($exp) {
80        $exp[]='__exp__getFromDelicious';
81        return $exp;
82}
83
84function __exp__getFromDelicious($id) {
85    list($url)= rss_fetch_row(
86       rss_query('select url from '  . getTable('item')  ." where id=$id"));
87    $ret = array();
88    $durl = "http://del.icio.us/url/" . md5($url)."?settagview=list";
89    $bfr = getUrl($durl,3000);
90    if ($bfr) {
91                        define ('DLSRX','|<a href="/tag/([^"]+)".*>\\1</a>|U');
92                        if ($bfr && preg_match_all(DLSRX,$bfr,$hits,PREG_SET_ORDER)) {
93                                        $hits=array_slice($hits,0,MAX_TAGS_PER_ITEM);
94                                        foreach($hits as $hit) {
95                                                $ret[] = $hit[1];
96                                        }
97                                }
98        }
99   return "$id," .implode(" ",$ret);
100}
101
102function __delicious_edittag_js($dummy) {
103?>
104        // get tag suggestions from del.icio.us
105        newspan = document.createElement("span");
106        newspan.setAttribute("id","dt" + id);
107        newspan.style.margin="0 0 0 0.5em";
108        newspan.innerHTML = "<?php echo  __('suggestions') ?>: (...) ]";
109        actionSpan.appendChild(newspan);
110        get_from_delicious(id);
111<?php
112        return null;
113}
114
115
116rss_set_hook('rss.plugins.javascript','__delicious_js_register');
117rss_set_hook('rss.plugins.ajax.exports','__delicious_appendAJAXfunction');
118rss_set_hook('rss.plugins.ajax.extrajs.edittag','__delicious_edittag_js');
119?>
Note: See TracBrowser for help on using the browser.