SET search_path = public, pg_catalog;
 
 --
--- TOC entry 198 (OID 14911565)
+-- TOC entry 201 (OID 14911565)
 -- Name: plpgsql_call_handler(); Type: FUNC PROCEDURAL LANGUAGE; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 119 (OID 14911566)
+-- TOC entry 122 (OID 14911566)
 -- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: public; Owner: 
 --
 
 
 
 --
--- TOC entry 120 (OID 11524574)
+-- TOC entry 123 (OID 11524574)
 -- Name: lexize(oid, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 121 (OID 11524575)
+-- TOC entry 124 (OID 11524575)
 -- Name: lexize(text, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 122 (OID 11524576)
+-- TOC entry 125 (OID 11524576)
 -- Name: lexize(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 123 (OID 11524577)
+-- TOC entry 126 (OID 11524577)
 -- Name: set_curdict(integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 124 (OID 11524578)
+-- TOC entry 127 (OID 11524578)
 -- Name: set_curdict(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 125 (OID 11524579)
+-- TOC entry 128 (OID 11524579)
 -- Name: dex_init(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 126 (OID 11524580)
+-- TOC entry 129 (OID 11524580)
 -- Name: dex_lexize(internal, internal, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 127 (OID 11524582)
+-- TOC entry 130 (OID 11524582)
 -- Name: snb_en_init(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 128 (OID 11524583)
+-- TOC entry 131 (OID 11524583)
 -- Name: snb_lexize(internal, internal, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 129 (OID 11524585)
+-- TOC entry 132 (OID 11524585)
 -- Name: snb_ru_init(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 130 (OID 11524587)
+-- TOC entry 133 (OID 11524587)
 -- Name: spell_init(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 131 (OID 11524588)
+-- TOC entry 134 (OID 11524588)
 -- Name: spell_lexize(internal, internal, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 132 (OID 11524590)
+-- TOC entry 135 (OID 11524590)
 -- Name: syn_init(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 133 (OID 11524591)
+-- TOC entry 136 (OID 11524591)
 -- Name: syn_lexize(internal, internal, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 134 (OID 11524602)
+-- TOC entry 137 (OID 11524602)
 -- Name: token_type(integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 135 (OID 11524603)
+-- TOC entry 138 (OID 11524603)
 -- Name: token_type(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 136 (OID 11524604)
+-- TOC entry 139 (OID 11524604)
 -- Name: token_type(); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 137 (OID 11524605)
+-- TOC entry 140 (OID 11524605)
 -- Name: set_curprs(integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 138 (OID 11524606)
+-- TOC entry 141 (OID 11524606)
 -- Name: set_curprs(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 139 (OID 11524609)
+-- TOC entry 142 (OID 11524609)
 -- Name: parse(oid, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 140 (OID 11524610)
+-- TOC entry 143 (OID 11524610)
 -- Name: parse(text, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 141 (OID 11524611)
+-- TOC entry 144 (OID 11524611)
 -- Name: parse(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 142 (OID 11524612)
+-- TOC entry 145 (OID 11524612)
 -- Name: prsd_start(internal, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 143 (OID 11524613)
+-- TOC entry 146 (OID 11524613)
 -- Name: prsd_getlexeme(internal, internal, internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 144 (OID 11524614)
+-- TOC entry 147 (OID 11524614)
 -- Name: prsd_end(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 145 (OID 11524615)
+-- TOC entry 148 (OID 11524615)
 -- Name: prsd_lextype(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 146 (OID 11524616)
+-- TOC entry 149 (OID 11524616)
 -- Name: prsd_headline(internal, internal, internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 147 (OID 11524632)
+-- TOC entry 150 (OID 11524632)
 -- Name: set_curcfg(integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 148 (OID 11524633)
+-- TOC entry 151 (OID 11524633)
 -- Name: set_curcfg(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 149 (OID 11524634)
+-- TOC entry 152 (OID 11524634)
 -- Name: show_curcfg(); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 150 (OID 11524696)
+-- TOC entry 153 (OID 11524696)
 -- Name: tsvector_in(cstring); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 151 (OID 11524697)
+-- TOC entry 154 (OID 11524697)
 -- Name: tsvector_out(tsvector); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 152 (OID 11524699)
+-- TOC entry 155 (OID 11524699)
 -- Name: length(tsvector); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 153 (OID 11524700)
+-- TOC entry 156 (OID 11524700)
 -- Name: to_tsvector(oid, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 154 (OID 11524701)
+-- TOC entry 157 (OID 11524701)
 -- Name: to_tsvector(text, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 155 (OID 11524702)
+-- TOC entry 158 (OID 11524702)
 -- Name: to_tsvector(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 156 (OID 11524703)
+-- TOC entry 159 (OID 11524703)
 -- Name: strip(tsvector); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 157 (OID 11524704)
+-- TOC entry 160 (OID 11524704)
 -- Name: setweight(tsvector, "char"); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 158 (OID 11524705)
+-- TOC entry 161 (OID 11524705)
 -- Name: concat(tsvector, tsvector); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 200 (OID 11524706)
+-- TOC entry 203 (OID 11524706)
 -- Name: ||; Type: OPERATOR; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 159 (OID 11524708)
+-- TOC entry 162 (OID 11524708)
 -- Name: tsquery_in(cstring); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 160 (OID 11524709)
+-- TOC entry 163 (OID 11524709)
 -- Name: tsquery_out(tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 161 (OID 11524711)
+-- TOC entry 164 (OID 11524711)
 -- Name: querytree(tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 162 (OID 11524712)
+-- TOC entry 165 (OID 11524712)
 -- Name: to_tsquery(oid, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 163 (OID 11524713)
+-- TOC entry 166 (OID 11524713)
 -- Name: to_tsquery(text, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 164 (OID 11524714)
+-- TOC entry 167 (OID 11524714)
 -- Name: to_tsquery(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 165 (OID 11524715)
+-- TOC entry 168 (OID 11524715)
 -- Name: exectsq(tsvector, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 167 (OID 11524716)
+-- TOC entry 170 (OID 11524716)
 -- Name: rexectsq(tsquery, tsvector); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 202 (OID 11524717)
+-- TOC entry 205 (OID 11524717)
 -- Name: @@; Type: OPERATOR; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 201 (OID 11524718)
+-- TOC entry 204 (OID 11524718)
 -- Name: @@; Type: OPERATOR; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 169 (OID 11524719)
+-- TOC entry 172 (OID 11524719)
 -- Name: tsearch2(); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 170 (OID 11524720)
+-- TOC entry 173 (OID 11524720)
 -- Name: rank(real[], tsvector, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 171 (OID 11524721)
+-- TOC entry 174 (OID 11524721)
 -- Name: rank(real[], tsvector, tsquery, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 172 (OID 11524722)
+-- TOC entry 175 (OID 11524722)
 -- Name: rank(tsvector, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 173 (OID 11524723)
+-- TOC entry 176 (OID 11524723)
 -- Name: rank(tsvector, tsquery, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 174 (OID 11524724)
+-- TOC entry 177 (OID 11524724)
 -- Name: rank_cd(integer, tsvector, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 175 (OID 11524725)
+-- TOC entry 178 (OID 11524725)
 -- Name: rank_cd(integer, tsvector, tsquery, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 176 (OID 11524726)
+-- TOC entry 179 (OID 11524726)
 -- Name: rank_cd(tsvector, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 177 (OID 11524727)
+-- TOC entry 180 (OID 11524727)
 -- Name: rank_cd(tsvector, tsquery, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 178 (OID 11524728)
+-- TOC entry 181 (OID 11524728)
 -- Name: headline(oid, text, tsquery, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 179 (OID 11524729)
+-- TOC entry 182 (OID 11524729)
 -- Name: headline(oid, text, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 180 (OID 11524730)
+-- TOC entry 183 (OID 11524730)
 -- Name: headline(text, text, tsquery, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 181 (OID 11524731)
+-- TOC entry 184 (OID 11524731)
 -- Name: headline(text, text, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 182 (OID 11524732)
+-- TOC entry 185 (OID 11524732)
 -- Name: headline(text, tsquery, text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 183 (OID 11524733)
+-- TOC entry 186 (OID 11524733)
 -- Name: headline(text, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 184 (OID 11524735)
+-- TOC entry 187 (OID 11524735)
 -- Name: gtsvector_in(cstring); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 185 (OID 11524736)
+-- TOC entry 188 (OID 11524736)
 -- Name: gtsvector_out(gtsvector); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 186 (OID 11524738)
+-- TOC entry 189 (OID 11524738)
 -- Name: gtsvector_consistent(gtsvector, internal, integer); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 187 (OID 11524739)
+-- TOC entry 190 (OID 11524739)
 -- Name: gtsvector_compress(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 188 (OID 11524740)
+-- TOC entry 191 (OID 11524740)
 -- Name: gtsvector_decompress(internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 189 (OID 11524741)
+-- TOC entry 192 (OID 11524741)
 -- Name: gtsvector_penalty(internal, internal, internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 190 (OID 11524742)
+-- TOC entry 193 (OID 11524742)
 -- Name: gtsvector_picksplit(internal, internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 191 (OID 11524743)
+-- TOC entry 194 (OID 11524743)
 -- Name: gtsvector_union(bytea, internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 192 (OID 11524744)
+-- TOC entry 195 (OID 11524744)
 -- Name: gtsvector_same(gtsvector, gtsvector, internal); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 203 (OID 11524745)
+-- TOC entry 206 (OID 11524745)
 -- Name: gist_tsvector_ops; Type: OPERATOR CLASS; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 193 (OID 11524748)
+-- TOC entry 196 (OID 11524748)
 -- Name: stat(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 194 (OID 11524749)
+-- TOC entry 197 (OID 11524749)
 -- Name: reset_tsearch(); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 195 (OID 11524750)
+-- TOC entry 198 (OID 11524750)
 -- Name: get_covers(tsvector, tsquery); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 196 (OID 11524753)
+-- TOC entry 199 (OID 11524753)
 -- Name: _get_parser_from_curcfg(); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 197 (OID 11524754)
+-- TOC entry 200 (OID 11524754)
 -- Name: ts_debug(text); Type: FUNCTION; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 67 (OID 11524757)
+-- TOC entry 69 (OID 11524757)
 -- Name: pages_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 68 (OID 11524767)
+-- TOC entry 70 (OID 11524767)
 -- Name: contents_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
     ie_imagetoolbar_no boolean DEFAULT false NOT NULL,
     global_noodp boolean DEFAULT false NOT NULL,
     ie6_fixes_css text,
-    ie7_fixes_css text
+    ie7_fixes_css text,
+    enable_rss_func boolean DEFAULT false NOT NULL
 );
 
 
 
 
 --
--- TOC entry 69 (OID 11524775)
+-- TOC entry 71 (OID 11524775)
 -- Name: hosts_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 70 (OID 11524795)
+-- TOC entry 72 (OID 11524795)
 -- Name: images_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 71 (OID 11524804)
+-- TOC entry 73 (OID 11524804)
 -- Name: files_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 72 (OID 11524813)
+-- TOC entry 74 (OID 11524813)
 -- Name: users_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 73 (OID 11524840)
+-- TOC entry 75 (OID 11524840)
 -- Name: contacts_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 74 (OID 11524882)
+-- TOC entry 76 (OID 11524882)
 -- Name: templates_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 75 (OID 11524896)
+-- TOC entry 77 (OID 11524896)
 -- Name: messages_id_seq; Type: ACL; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 199 (OID 14911567)
+-- TOC entry 202 (OID 14911567)
 -- Name: contents_jsgo_check_tg(); Type: FUNCTION; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 90 (OID 11576669)
+-- TOC entry 67 (OID 14972886)
+-- Name: rss_cache; Type: TABLE; Schema: public; Owner: rich
+--
+
+CREATE TABLE rss_cache (
+    url text NOT NULL,
+    t timestamp without time zone DEFAULT ('now'::text)::timestamp(6) with time zone NOT NULL,
+    rss text NOT NULL
+);
+
+
+--
+-- TOC entry 68 (OID 14972886)
+-- Name: rss_cache; Type: ACL; Schema: public; Owner: rich
+--
+
+REVOKE ALL ON TABLE rss_cache FROM PUBLIC;
+GRANT ALL ON TABLE rss_cache TO "www-data";
+
+
+--
+-- TOC entry 92 (OID 11576669)
 -- Name: hostnames_hostid_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 85 (OID 11576670)
+-- TOC entry 87 (OID 11576670)
 -- Name: pages_url_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 92 (OID 11576671)
+-- TOC entry 94 (OID 11576671)
 -- Name: images_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 94 (OID 11576672)
+-- TOC entry 96 (OID 11576672)
 -- Name: files_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 97 (OID 11576673)
+-- TOC entry 99 (OID 11576673)
 -- Name: users_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 96 (OID 11576674)
+-- TOC entry 98 (OID 11576674)
 -- Name: users_id_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 100 (OID 11576675)
+-- TOC entry 102 (OID 11576675)
 -- Name: sitemenu_ordering_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 101 (OID 11576676)
+-- TOC entry 103 (OID 11576676)
 -- Name: sitemenu_url_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 104 (OID 11576677)
+-- TOC entry 106 (OID 11576677)
 -- Name: contact_emails_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 105 (OID 11576678)
+-- TOC entry 107 (OID 11576678)
 -- Name: themes_theme_css_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 106 (OID 11576679)
+-- TOC entry 108 (OID 11576679)
 -- Name: page_emails_email_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 107 (OID 11576680)
+-- TOC entry 109 (OID 11576680)
 -- Name: mailing_lists_email_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 102 (OID 11576681)
+-- TOC entry 104 (OID 11576681)
 -- Name: contacts_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 108 (OID 11576682)
+-- TOC entry 110 (OID 11576682)
 -- Name: links_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 109 (OID 11576683)
+-- TOC entry 111 (OID 11576683)
 -- Name: templates_ext_ord_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 111 (OID 11576684)
+-- TOC entry 113 (OID 11576684)
 -- Name: templates_title_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 112 (OID 11576685)
+-- TOC entry 114 (OID 11576685)
 -- Name: templates_url_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 113 (OID 11576686)
+-- TOC entry 115 (OID 11576686)
 -- Name: recently_visited_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 114 (OID 11576687)
+-- TOC entry 116 (OID 11576687)
 -- Name: messages_inet_message_id_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 84 (OID 11576688)
+-- TOC entry 86 (OID 11576688)
 -- Name: pages_url_ix; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 83 (OID 11576689)
+-- TOC entry 85 (OID 11576689)
 -- Name: pages_redirect_ix; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 80 (OID 11576690)
+-- TOC entry 82 (OID 11576690)
 -- Name: pages_fti_idx; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 86 (OID 11576691)
+-- TOC entry 88 (OID 11576691)
 -- Name: contents_fti_idx; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 87 (OID 11576692)
+-- TOC entry 89 (OID 11576692)
 -- Name: contents_pageid_idx; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 91 (OID 11576693)
+-- TOC entry 93 (OID 11576693)
 -- Name: hostnames_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 99 (OID 11576694)
+-- TOC entry 101 (OID 11576694)
 -- Name: usercookies_cookie_idx; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 81 (OID 11576695)
+-- TOC entry 83 (OID 11576695)
 -- Name: pages_lc_title; Type: INDEX; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 76 (OID 11524572)
+-- TOC entry 78 (OID 11524572)
 -- Name: pg_ts_dict_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 77 (OID 11524598)
+-- TOC entry 79 (OID 11524598)
 -- Name: pg_ts_parser_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 78 (OID 11524623)
+-- TOC entry 80 (OID 11524623)
 -- Name: pg_ts_cfg_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 79 (OID 11524630)
+-- TOC entry 81 (OID 11524630)
 -- Name: pg_ts_cfgmap_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 82 (OID 11576696)
+-- TOC entry 84 (OID 11576696)
 -- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 88 (OID 11576698)
+-- TOC entry 90 (OID 11576698)
 -- Name: contents_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 89 (OID 11576700)
+-- TOC entry 91 (OID 11576700)
 -- Name: hosts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 93 (OID 11576702)
+-- TOC entry 95 (OID 11576702)
 -- Name: images_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 95 (OID 11576704)
+-- TOC entry 97 (OID 11576704)
 -- Name: files_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 98 (OID 11576706)
+-- TOC entry 100 (OID 11576706)
 -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 103 (OID 11576708)
+-- TOC entry 105 (OID 11576708)
 -- Name: contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 110 (OID 11576710)
+-- TOC entry 112 (OID 11576710)
 -- Name: templates_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 115 (OID 11576712)
+-- TOC entry 117 (OID 11576712)
 -- Name: messages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 116 (OID 11576714)
+-- TOC entry 118 (OID 11576714)
 -- Name: powered_by_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 117 (OID 11576716)
+-- TOC entry 119 (OID 11576716)
 -- Name: pending_email_changes_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 118 (OID 14911934)
+-- TOC entry 120 (OID 14911934)
 -- Name: macros_hostid_key; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 208 (OID 11576718)
+-- TOC entry 121 (OID 14972892)
+-- Name: rss_cache_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
+--
+
+ALTER TABLE ONLY rss_cache
+    ADD CONSTRAINT rss_cache_pkey PRIMARY KEY (url);
+
+
+--
+-- TOC entry 211 (OID 11576718)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 212 (OID 11576722)
+-- TOC entry 215 (OID 11576722)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 209 (OID 11576726)
+-- TOC entry 212 (OID 11576726)
 -- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 204 (OID 11576730)
+-- TOC entry 207 (OID 11576730)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 213 (OID 11576734)
+-- TOC entry 216 (OID 11576734)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 214 (OID 11576738)
+-- TOC entry 217 (OID 11576738)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 205 (OID 11576742)
+-- TOC entry 208 (OID 11576742)
 -- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 215 (OID 11576746)
+-- TOC entry 218 (OID 11576746)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 216 (OID 11576750)
+-- TOC entry 219 (OID 11576750)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 206 (OID 11576754)
+-- TOC entry 209 (OID 11576754)
 -- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 207 (OID 11576758)
+-- TOC entry 210 (OID 11576758)
 -- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 217 (OID 11576762)
+-- TOC entry 220 (OID 11576762)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 218 (OID 11576766)
+-- TOC entry 221 (OID 11576766)
 -- Name: sitemenu_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 219 (OID 11576770)
+-- TOC entry 222 (OID 11576770)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 220 (OID 11576774)
+-- TOC entry 223 (OID 11576774)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 210 (OID 11576778)
+-- TOC entry 213 (OID 11576778)
 -- Name: hosts_theme_css_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 221 (OID 11576782)
+-- TOC entry 224 (OID 11576782)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 222 (OID 11576786)
+-- TOC entry 225 (OID 11576786)
 -- Name: page_emails_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 223 (OID 11576790)
+-- TOC entry 226 (OID 11576790)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 224 (OID 11576794)
+-- TOC entry 227 (OID 11576794)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 225 (OID 11576798)
+-- TOC entry 228 (OID 11576798)
 -- Name: links_from_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 226 (OID 11576802)
+-- TOC entry 229 (OID 11576802)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 227 (OID 11576806)
+-- TOC entry 230 (OID 11576806)
 -- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 228 (OID 11576810)
+-- TOC entry 231 (OID 11576810)
 -- Name: recently_visited_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 229 (OID 11576814)
+-- TOC entry 232 (OID 11576814)
 -- Name: recently_visited_userid_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 231 (OID 11576818)
+-- TOC entry 234 (OID 11576818)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 230 (OID 11576822)
+-- TOC entry 233 (OID 11576822)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 211 (OID 11576826)
+-- TOC entry 214 (OID 11576826)
 -- Name: hosts_powered_by_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 232 (OID 11576830)
+-- TOC entry 235 (OID 11576830)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 233 (OID 14911936)
+-- TOC entry 236 (OID 14911936)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 234 (OID 11576834)
+-- TOC entry 237 (OID 11576834)
 -- Name: pages_fti_tr; Type: TRIGGER; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 235 (OID 11576835)
+-- TOC entry 238 (OID 11576835)
 -- Name: contents_fti_tr; Type: TRIGGER; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 236 (OID 14911568)
+-- TOC entry 239 (OID 14911568)
 -- Name: contents_jsgo_check_tg; Type: TRIGGER; Schema: public; Owner: rich
 --
 
 
 
 --
--- TOC entry 166 (OID 11524715)
+-- TOC entry 169 (OID 11524715)
 -- Name: FUNCTION exectsq(tsvector, tsquery); Type: COMMENT; Schema: public; Owner: postgres
 --
 
 
 
 --
--- TOC entry 168 (OID 11524716)
+-- TOC entry 171 (OID 11524716)
 -- Name: FUNCTION rexectsq(tsquery, tsvector); Type: COMMENT; Schema: public; Owner: postgres
 --
 
 
--- /dev/null
+(* An RSS feed reader function.
+ * $Id: cocanwiki_func_rss.ml,v 1.1 2006/12/07 17:05:47 rich Exp $
+ *)
+
+open Printf
+open ExtString
+open ExtList
+
+open Rss
+
+open Cocanwiki_extensions
+open Cocanwiki_template
+
+(* Argument is a whitespace-separated list of key=value pairs.
+ *
+ * Example:
+ *   {{rss:url=http://blog.merjis.com/feed/ max_items=3 refresh=daily}}
+ *
+ * The keys are:
+ *   url       The URL of the RSS feed (required).
+ *   show      What to show.  A comma-separated list of:
+ *                 title            Blog title
+ *                 link             Blog link
+ *                 description      Blog description
+ *                 items            Items in the feed
+ *                 item_title       Title of items
+ *                 item_link        Link to items
+ *                 item_description Description of items
+ *               Default is everything.
+ *   max_items Maximum number of items to show.
+ *   refresh   How often to recheck feed: hourly, daily, weekly,
+ *               <nn>h, or <nn>d.
+ *               Default is daily.  Warning: we only check the
+ *               feed when the page is loaded, so making this
+ *               too frequent will slow page loading.
+ *)
+let ws_re = Pcre.regexp "\\s+"
+let key_re = Pcre.regexp "^(\\w+)=(.*)$"
+let refresh_re = Pcre.regexp "^(\\d+)(h|d)$"
+
+(* This exception is thrown if there is an error during processing.  The
+ * string is an error message.
+ *)
+exception Error of string
+
+type show = Title | Link | Description
+         | Items | Item_title | Item_link | Item_description
+let default_show = [ Title; Link; Description;
+                    Items; Item_title; Item_link; Item_description ]
+
+let event_system = Unixqueue.create_unix_event_system ()
+let connection =
+  let connection = new Http_client.pipeline in
+  connection#set_event_system event_system;
+  connection
+
+let fetch_url url =
+  prerr_endline ("fetching URL: " ^ url);
+  try
+    let msg = new Http_client.get url in
+    connection#add msg;
+    connection#run ();
+    msg#get_resp_body ()
+  with
+  | Http_client.Http_protocol exn
+  | exn ->
+      (* Log the real exception in the logfile, for security. *)
+      prerr_endline (Printexc.to_string exn);
+      raise (Error ("error fetching url; " ^
+                     "note that for security reasons " ^
+                     "the real error is only written to error_log"))
+
+(* OCamlRSS uses its own date format. *)
+let printable_date { year = year; month = month; day = day;
+                    hour = hour; minute = minute; second = second } =
+  let date = Calendar.lmake ~year ~month ~day ~hour ~minute ~second () in
+  Cocanwiki_date.printable_date_time date
+
+let rss r dbh hostid arg =
+  let template = _get_template "cocanwiki_func_rss.html" in
+
+  try
+    (* Is RSS enabled for this host?  This is a safety feature to ensure
+     * that people only turn this feature on if they really mean to.
+     *)
+    let rows =
+      PGSQL(dbh) "select enable_rss_func from hosts where id = $hostid" in
+    if rows <> [Some true] then
+      raise (Error "RSS is disabled on this host.  You have to enable it manually by setting enable_rss_func for the relevant row in the hosts table.  RSS introduces a potential security hole (cross-site scripting) and should not be used where you have untrusted editors or with untrusted RSS feeds.");
+
+    let arg = match arg with
+      | None -> raise (Error ("missing url: try {{rss:url=http://....}}"))
+      | Some arg -> arg in
+
+    (* Parse the argument. *)
+    let args = Pcre.split ~rex:ws_re arg in
+    let args = List.map (
+      fun arg ->
+       try
+         let subs = Pcre.exec ~rex:key_re arg in
+         let key = Pcre.get_substring subs 1 in
+         let value = Pcre.get_substring subs 2 in
+         key, value
+       with
+         Not_found ->
+           raise (Error ("invalid argument: " ^ arg))
+    ) args in
+
+    (* Get known arguments or their defaults. *)
+    let url =
+      try List.assoc "url" args
+      with Not_found ->
+       raise (Error "missing url: try {{rss:url=http://....}}") in
+
+    let max_items =
+      try
+       let n = List.assoc "max_items" args in
+       let n = int_of_string n in
+       Some n
+      with
+      | Not_found -> None
+      | Failure "int_of_string" ->
+         raise (Error "max_items is not a number") in
+
+    let refresh =
+      try
+       let p = List.assoc "refresh" args in
+       match p with
+       | "hourly" -> Calendar.Period.hour 1
+       | "daily" -> Calendar.Period.day 1
+       | "weekly" -> Calendar.Period.week 1
+       | str ->
+           try
+             let subs = Pcre.exec ~rex:refresh_re str in
+             let n = int_of_string (Pcre.get_substring subs 1) in
+             match Pcre.get_substring subs 2 with
+             | "h" -> Calendar.Period.hour n
+             | "d" -> Calendar.Period.day n
+             | _ -> assert false
+           with
+             Not_found ->
+               raise (Error "refresh is hourly|daily|weekly|<nn>h|<nn>d")
+      with
+       Not_found ->
+         Calendar.Period.day 1 in
+
+    let show =
+      try
+       let xs = List.assoc "show" args in
+       let xs = String.nsplit xs "," in
+       let xs = List.map (
+          function
+          | "title" -> Title
+         | "link" -> Link
+         | "description" -> Description
+         | "items" -> Items
+         | "item_title" -> Item_title
+         | "item_link" -> Item_link
+         | "item_description" -> Item_description
+         | str ->
+             raise (Error ("show: invalid item: " ^ str))
+        ) xs in
+       xs
+      with
+       Not_found -> default_show in
+
+    (* Process the show parameter into template conditionals. *)
+    template#conditional "show_title" false;
+    template#conditional "show_link" false;
+    template#conditional "show_description" false;
+    template#conditional "show_items" false;
+    template#conditional "show_item_title" false;
+    template#conditional "show_item_link" false;
+    template#conditional "show_item_description" false;
+    List.iter (
+      function
+      | Title -> template#conditional "show_title" true
+      | Link -> template#conditional "show_link" true
+      | Description -> template#conditional "show_description" true
+      | Items -> template#conditional "show_items" true
+      | Item_title -> template#conditional "show_item_title" true
+      | Item_link -> template#conditional "show_item_link" true
+      | Item_description -> template#conditional "show_item_description" true
+    ) show;
+
+    (* Grab the RSS from our database cache.  If it's too old
+     * or we don't have it cached, grab it from the server.
+     *)
+    let rss =
+      let rows =
+       PGSQL(dbh)
+         "select t, rss from rss_cache where url = $url" in
+      let need_to_fetch, rss =
+       match rows with
+       | [] -> true, "" (* not in cache, so have to fetch URL *)
+       | (t, rss) :: _ ->
+           if Calendar.compare
+             (Calendar.add t refresh) (Calendar.now ()) < 0 then
+             true, ""
+           else
+             false, rss in
+      if need_to_fetch then (
+       let rss = fetch_url url in
+       (* This lock is OK - refetches are supposed to be infrequent. *)
+       PGSQL(dbh) "lock table rss_cache in share mode";
+       PGSQL(dbh) "delete from rss_cache where url = $url";
+       PGSQL(dbh) "insert into rss_cache (url, rss) values ($url, $rss)";
+       PGOCaml.commit dbh; (* XXX How to avoid? *)
+       PGOCaml.begin_work dbh;
+       rss
+      ) else
+       rss in
+
+    (* Try to parse the RSS. *)
+    let channel =
+      try
+       channel_of_string rss
+      with
+      | Xml.Error err ->
+         raise (Error ("error parsing feed: XML: " ^ Xml.error err))
+      | Failure err ->
+         raise (Error ("error parsing feed: RSS: " ^ err)) in
+
+    (* Generate some XML. *)
+    template#set "title" channel.ch_title;
+    template#set "link" channel.ch_link;
+    template#set "description" channel.ch_desc;
+
+    let items = channel.ch_items in
+    let items =
+      match max_items with
+      | None -> items
+      | Some n -> List.take n items in
+    let items = List.map (
+      fun item ->
+       [ "title", Template.VarString (Option.default "" item.item_title);
+         "link", Template.VarString (Option.default "" item.item_link);
+         "description",
+           Template.VarString (Option.default "" item.item_desc);
+         "date",
+           Template.VarString (Option.map_default
+                                 printable_date "" item.item_pubdate); ]
+    ) items in
+    template#table "items" items;
+
+    template#to_string
+  with
+    Error msg ->
+      "rss: " ^ Cgi_escape.escape_html msg
+
+(* Register function. *)
+let () =
+  external_functions := ("rss", rss) :: !external_functions