1 # ===================================================================== 2 # rssFeed: provide an RSS export of certain TW listings. 3 # 4 # Copyright (c) 2007-2011 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # Local variables and functions 23 # ===================================================================== 24 25 cgi.group = () 26 cgi.group.literal = () 27 cgi.page = () 28 cgi.subcat = () 29 cgi.tw.page = tw-recent-changes # default listing. 30 cgi.page.literal = () 31 32 # ===================================================================== 33 # Main program 34 # ===================================================================== 35 36 # Load call arguments. 37 csaGetArgs GET 38 39 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 40 41 . $CSA_ROOT/lib/group-stuff.rc 42 43 # Check the most important arg if needed by the requested view. 44 if (~ $'cgi.what' *-recent-headlines) { 45 ~ $'cgi.page' () && csaExit.fault 1001 46 tw_pstem = $tw_gstem/$'cgi.page' 47 ~ $'cgi.page.literal' () && csaExit.fault 0041 cgi.page.literal 48 tbl_group.p_name = $'cgi.page.literal' 49 tpl.var.tw.page.unx = $'cgi.page' 50 } 51 52 . $CSA_ROOT/lib/group-editor.rc 53 54 cgi.tw.page.url = $'cgi.tw.page' # default 55 56 # Add more listing types as needed. 57 58 switch ($'cgi.tw.page') { 59 60 case tw-recent-changes 61 # Force the blog-style on this view. 62 #TNS_TW_STYLE = blog 63 awktable -i $tw_gstem/page+dat -- \ 64 'BEGIN{print "\001p_uri\t\001p_mtime" \ 65 "\t\001p_name\t\001p_modau\t\001p_descr" 66 } 67 # Explicit exclusions from static views apply also to RSS feeds. 68 $p_descr ~ /^ *!/ {next} 69 # Exclude hidden/redirected pages from output. Redirections which 70 # are NOT to be excluded must be *immediately* preceeded by "+" . 71 {sub(/\+\(:redirect /,"(:+redirect ",$p_descr)} 72 $p_descr !~ /(^ *-|\(:redirect )/ { 73 sub(/\(:\+redirect /,"(:redirect ",$p_descr) 74 print $p_uri,$p_mtime,$p_name,$p_modau,$p_descr 75 }' | sorttable -r p_mtime | 76 head -n $TNS_RECENT_CHANGES_NUM > $tmp1 77 78 case tw-recent-pages 79 # Force the blog-style on this view. 80 #TNS_TW_STYLE = blog 81 awktable -i $tw_gstem/page+dat -- \ 82 'BEGIN{print "\001p_uri\t\001p_vtime" \ 83 "\t\001p_name\t\001p_modau\t\001p_descr\t\001k_page" 84 } 85 # Explicit exclusions from static views apply also to RSS feeds. 86 $p_descr ~ /^ *!/ {next} 87 # Exclude hidden/redirected pages from output. Redirections which 88 # are NOT to be excluded must be *immediately* preceeded by "+" . 89 {sub(/\+\(:redirect /,"(:+redirect ",$p_descr)} 90 $p_descr !~ /(^ *-|\(:redirect )/ { 91 sub(/\(:\+redirect /,"(:redirect ",$p_descr) 92 print $p_uri,$p_vtime,$p_name,$p_modau,$p_descr,$k_page 93 }' | sorttable -r p_vtime | 94 head -n $TNS_RECENT_PAGES_NUM > $tmp1 95 96 case tw-recent-headlines 97 # Force the blog-style on this view. 98 #TNS_TW_STYLE = blog 99 if (~ $'cgi.subcat' [a-z]*) { 100 cgi.tw.page.url = tw-$'cgi.subcat'-recent-headlines 101 keysearch --partial $'cgi.subcat'. $tw_gstem/page+dat | 102 awktable -- 'BEGIN{print "\001p_uri\t\001p_vtime" \ 103 "\t\001p_name\t\001p_modau\t\001p_descr" 104 } 105 # Explicit exclusions from static views apply also to RSS feeds. 106 $p_descr ~ /^ *!/ {next} 107 # Exclude hidden/redirected pages from output. Redirections which 108 # are NOT to be excluded must be *immediately* preceeded by "+" . 109 {sub(/\+\(:redirect /,"(:+redirect ",$p_descr)} 110 $p_descr !~ /(^ *-|\(:redirect )/ { 111 sub(/\(:\+redirect /,"(:redirect ",$p_descr) 112 print $p_uri,$p_vtime,$p_name,$p_modau,$p_descr 113 }' | sorttable -r p_vtime | 114 head -n $TNS_RECENT_HEADLINES_NUM > $tmp1 115 } else { 116 awktable -i $tw_gstem/page+dat -- \ 117 'BEGIN{print "\001p_uri\t\001p_vtime" \ 118 "\t\001p_name\t\001p_modau\t\001p_descr" 119 } 120 # Explicit exclusions from static views apply also to RSS feeds. 121 $p_descr ~ /^ *!/ {next} 122 # Exclude hidden/redirected pages from output. Redirections which 123 # are NOT to be excluded must be *immediately* preceeded by "+" . 124 {sub(/\+\(:redirect /,"(:+redirect ",$p_descr)} 125 $p_descr !~ /(^ *-|\(:redirect )/ { 126 sub(/\(:\+redirect /,"(:redirect ",$p_descr) 127 print $p_uri,$p_vtime,$p_name,$p_modau,$p_descr 128 }' | sorttable -r p_vtime | 129 head -n $TNS_RECENT_HEADLINES_NUM > $tmp1 130 } 131 132 case tw-page-trackbacks 133 # Force the blog-style on this view. 134 #TNS_TW_STYLE = blog 135 ~ $'cgi.page' () && csaExit.fault 0038 136 getcolumn --input $tw_gstem/$'cgi.page'+tbk \ 137 k_tbkurl t_^(ctime title blog descr) | 138 sorttable -r t_ctime > $tmp1 139 140 case * 141 csaExit.fault 0038 142 } 143 144 # The recent-headlines listing uses the tw-recent-pages. 145 ~ $'cgi.tw.page' tw-recent-headlines && cgi.tw.page = tw-recent-pages 146 147 # This is mainly to set the "Print" action, and possibly other 148 # page-level functions, to something sensible even when in virtual 149 # views (i.e. tw-*). 150 151 ~ $'tpl.var.tw.page' () && tpl.var.tw.page = $TNS_GROUP_HOME(1) 152 153 # Set template vars to their final values. 154 tpl.var.html.title = $'tpl.var.tw.group'/$'cgi.tw.page' 155 tpl.var.tw.page.object = $'tpl.var.tw.page' 156 157 # Note: response templates are not really used for the final RSS output, 158 # where everything is delivered through the RDF page head section, but 159 # I leave them defined nevertheless, which will not hurt. 160 161 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/$'cgi.tw.page'.txt) { 162 # custom special-page display template. 163 tpl.include.html.body = $CSA_TPL_ROOT/$'cgi.tw.page'.txt 164 } else { 165 # default special-page display template. 166 tpl.include.html.body = $tw_dstem/$'cgi.tw.page'.txt 167 } 168 169 # Use a minimal template for feeds, or it may not validate. 170 # Tested with http://feedvalidator.org/ . 171 172 if (!csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-rss10.xml) { 173 tpl_file = (--file-root $tw_dstem tw-rss10.xml) 174 } else tpl_file = tw-rss10.xml 175 176 CSA_RPC_FMT = rss # override any different specs. 177 178 # Setting the correct namespace is mandatory, or the response will 179 # not be detected as a live feed by Firefox 2.0 , even if it has the 180 # correct Content-Type header. 181 182 CSA_XMLNS_DEFAULT = http://purl.org/rss/1.0/ 183 184 # Use alternate opts for response, if defined. 185 ~ $SWU_AWK_OPTS2 () || SWU_AWK_OPTS = $SWU_AWK_OPTS2 186 187 csaExit.ok --table $tmp1 $tpl_file 188 189 # End of program.