plugins/comment-feed: CommentFeed.jplug.php

File CommentFeed.jplug.php, 4.8 KB (added by robertb, 3 years ago)

Plugin Version 1.5, arbeitet jetzt auch mit CommentModeration.jplug zusammen

Line 
1<?php
2/**
3 * @name:       CommentFeed <http://jeenaparadies.net/projects/jlog/wiki/plugins/comment-feed>
4 * @author:     Robert Bienert <robertbienert at gmx dot net>
5 * @version:    1.5
6 * @date:       2009-01-14
7 */
8
9define('COMMENTFEED_VERSION', '1.5');
10
11/* This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
24 */
25
26class CommentFeed extends JlogPlugin {
27        /* XXX Von der Funktion her zurueck zu den Wurzeln, aber ich
28         * weiss jetzt auch warum newComment nicht funktioniert: Ich
29         * habe in diesem Hook keinen Zugriff auf die noch nicht
30         * vorhandene mysql_insert_id. Also bleibt es bei onUpdate, auch
31         * wenn das vom Aufwand her vielleicht "overkill" sein mag.
32         */
33        function hook_onUpdate($form) {
34                global $l;              // Sprachtabelle
35                global $bbcode;         // BBCode-Parser
36
37                // nur zwei Abkuerzungen fuer Datenbank-Tabellen:
38                $pm = JLOG_DB_COMMENTS;
39                $pn = JLOG_DB_CONTENT;
40
41                /* Jlog speichert datetime-Typen, wir brauchen fuer
42                 * date() am Besten Timestamps. Ausserdem entfernt MySQL
43                 * den Tabellennamen, weshalb wir zwischen comments.date
44                 * und content.date unterscheiden muessen.
45                 */
46                # XXX Aktuell wird die Anzahl der eingestellten
47                # Subcurrent-Eintraege als Limit genommen, evtl.
48                # andere/eigene Konfiguration waehlen?
49                # XXX Weiterer fuer Konfiguration: Beruecksichtigung von
50                # Pingbacks?
51                $q = new Query("SELECT $pm.name, " .
52                        "UNIX_TIMESTAMP($pm.date) AS com_date, " .
53                        "$pm.content, $pm.id, $pn.url, " .
54                        "UNIX_TIMESTAMP($pn.date) AS con_date, " .
55                        "$pn.topic " .
56                        "FROM $pm, $pn " .
57                        "WHERE $pm.reference = $pn.id AND " .
58                        "($pm.type = '' OR $pm.type = 'pingback') " .
59                        "ORDER BY $pm.date DESC LIMIT 0," .
60                                JLOG_SUB_CURRENT);
61                $item = NULL;
62
63                // Es gibt nichts zu tun
64                # FIXME keine Fehlermeldung
65                if ($q->error())
66                        return $form;
67
68                /* Seit Version 1.1 ist Jlog in UTF-8 und die Konstante
69                 * JLOG_VERSION ist nicht mehr definiert.
70                 */
71                $enc = 'ISO-8859-1';
72
73                if (defined('JLOG_INSTALLED_VERSION')) {
74                        $enc = 'utf-8';
75
76                        if (! defined('JLOG_VERSION'))
77                                define('JLOG_VERSION',
78                                        JLOG_INSTALLED_VERSION);
79                }
80
81                // Zusammenbau des Feeds
82                $feed = '<?xml version="1.0" ' .
83                        "encoding=\"$enc\" ?>\n" .
84                        '<rss version="2.0" ' .
85                        'xmlns:dc="http://purl.org/dc/elements/1.1/" ' .
86                        'xmlns:content="http://purl.org/rss/1.0/modules/content/">' .
87                        '<channel>' .
88                        '<title>Kommentare zu '.htmlspecialchars(JLOG_WEBSITE).'</title>' .
89                        '<link>'.htmlspecialchars(JLOG_PATH).'</link>' .
90                        '<description>'.htmlspecialchars(JLOG_DESCRIPTION).'</description>' .
91                        '<language>'.$l['language'].'</language>' .
92                        '<lastBuildDate>'.date('r').'</lastBuildDate>' .
93                        '<docs>http://blogs.law.harvard.edu/tech/rss</docs>' .
94                        '<generator>&lt;a href=&quot;http://jeenaparadies.net/webdesign/jlog/&quot;&gt;Jlog v'.JLOG_VERSION.'&lt;/a&gt; with &lt;a href=&quot;http://jeenaparadies.net/projects/jlog/wiki/plugins/comment-feed&quot;&gt;CommentsFeed v'.COMMENTFEED_VERSION.'&lt;/a&gt;</generator>' .
95                        '<managingEditor>'.htmlspecialchars(JLOG_PUBLISHER).' '.htmlspecialchars(JLOG_EMAIL).'</managingEditor>' .
96                        '<copyright>&#169;'.date('Y').' by '.htmlspecialchars(JLOG_PUBLISHER)."</copyright>\n";
97
98                while (($item = $q->fetch())) {
99                        $author = htmlspecialchars($item['name']);
100                        $url = blog($item['con_date'], $item['url']) .
101                                "#c{$item['id']}";
102
103                        $feed .= '<item>' .
104                                "<title>$author zu ".htmlspecialchars($item['topic']).'</title>' .
105                                "<guid isPermaLink=\"true\">$url</guid>" .
106                                "<dc:creator>$author</dc:creator>" .
107                                '<pubDate>'.date('r', $item['com_date']).'</pubDate>' .
108                                "<link>$url</link>" .
109                                '<description>'.htmlspecialchars($bbcode->parse($item['content'])).'</description>' .
110                                "</item>\n";
111                }
112
113                $feed .= "\n</channel></rss>";
114                $feedPath = JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR.
115                                        'rss-comments.xml';
116
117                // Speichern der beiden Feeds
118                $mask = umask(0);
119                # FIXME Schnittstelle fuer error handling waere praktisch
120                if (($fh = @fopen($feedPath, 'wb'))) {
121                        @fwrite($fh, $feed);
122                        @fclose($fh);
123                }
124                // Bug behoben: zlib sollte vorhanden sein
125                if (function_exists('gzopen') &&
126                        ($fh = @gzopen($feedPath.'.gz', 'wb')))
127                {
128                        @gzwrite($fh, $feed, strlen($feed));
129                        @gzclose($fh);
130                }
131                umask($mask);
132
133                return $form;
134        }
135}
136?>