1 # ===================================================================== 2 # mwRecentPosts.awk: MetaWeblog API 3 # 4 # Copyright (c) 2008,2009.2010 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 BEGIN { 22 23 i=j=0; delete a; delete b; delete c 24 25 url = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/" 26 27 page_dir = _rcget("tw_gstem") 28 29 # I use the unixified group name as a URI here, so that 30 # blogger.getRecentPosts does not need to read the actual group 31 # record into memory. Fortunately the TW design provides enough 32 # flexibility :-) 33 34 g_name = _rcget("cgi.group") 35 36 printf("\n") 37 } 38 39 /^\001/ { next } # skip table header, if any. 40 41 { 42 # Process each input record in turn. 43 44 # k_page,p_ctime,p_name,p_creau,p_uri,\ 45 # p_descr,p_vtime,p_modau,p_tags,p_allow,k_node,p_link 46 47 split($0,a,"\t") # split each record into fields. 48 49 split(a[3],c,".") # page category, if any. 50 51 if (a[4] == _NULL) a[4] = _nlsmap(_NULL,"anonymous") 52 53 # Fix 'ctime' to meet XML-RPC specs. 54 gsub(/-/,"",a[2]); sub(/ /,"T",a[2]) 55 56 page = page_dir "/" a[1] "+wki" 57 58 # Load each page body in turn. 59 value = _NULL 60 while (getline tmp1 < page > 0) value = value tmp1; close(page) 61 62 # Skip empty pages, as they are to be considered as logically deleted. 63 # This test should now be obsolete, but I'll leave it in place still 64 # for a while, as it does not cost much anyway since this program 65 # needs lo load the page bodies also for other reasons, see below. 66 67 if (value !~ /(>[^<>]+|[^<>]+<)/) next 68 69 # CSA tag markers must be escaped, or _envtoxml() will happily 70 # interpret anything typed by the user into the file !! 71 72 gsub(/\$\[/,"\\$[",value) 73 74 # Retain only page abstracts/intros, if defined, depending also on 75 # whether the output is to have a blog- or a wiki-style respectively. 76 # See also the call to _wikicpi() further down. 77 78 if (_rcget("TNS_TW_STYLE",1) != "blog") { 79 sub(/.*\(::ab:\)/,"",value) 80 sub(/\(:ab::\).*/,"",value) 81 82 sub(/\(:i:\).*/,_NULL,value) 83 } 84 85 #tmp = "/,"?",b[j]) 141 } 142 143 144 # This is to make sure hyperlinks do not contain blanks, 145 # or the W3C validator may complain. 146 147 tmp1 = b[j] 148 sub(/['"].*/,_NULL,tmp1) 149 sub(/[^'"]+/,_NULL,b[j]) 150 gsub(/ /,"+",tmp1) 151 b[j] = tmp1 b[j] 152 153 # Now spot external links and label them as such. 154 155 b[j] = "href=" b[j] 156 sub(/=/,"='",b[j]) # leading quote. 157 b[j] = extLink("\n" \ 165 "\n" \ 166 "categories\n" \ 167 "\n" \ 168 "" _xmlencode(c[1]) \ 169 "\n" \ 170 "\n" \ 171 "" 172 173 # Perform Wiki parsing at this stage. 174 175 # If the invoking user is an editor we have no other choice but assume 176 # that she wants to edit entries, including any embedded user-level 177 # CPI's, otherwise the latter will be parsed for display. If an editor 178 # wants to rather pull the rendered page over RPC then she will have 179 # to log-out and log-in again with an unprivileged account. Given the 180 # limited capabilities of the Blogger API compared with the full-blown 181 # TW Web API, it looks like this is the only sensible behaviour. 182 # Note: most (all ?) API methods only make sense if the user is an 183 # editor, so they are currently unavailable to others and therefore 184 # tests like the following never match. 185 186 if ("," ENVIRON["TNS_AUTH_GRP"] "," !~ /,editor,/) 187 value = _wikicpi(value) 188 189 if (_rcget("cgi.numeric",1) == _NULL) 190 id = "" ENVIRON["CSA_LANG"] "/" g_name "/" a[1] "" 191 else id = "" a[11] "" 192 193 # Honour the Title-API flag. 194 if (_rcget("TNS_API_PROP",2) == "t") 195 tmp = a[3] "|" a[6] "|" a[7] "|" a[8] "|" a[9] "|" a[10] "|" a[12] 196 else tmp = a[3] 197 198 print "\n" \ 199 "title\n" \ 200 "" _xmlencode(tmp) "\n" \ 201 "\n" \ 202 "\n" \ 203 "description\n" \ 204 "" _xmlencode(value) "\n" \ 205 "\n" \ 206 "\n" \ 207 "userId\n" \ 208 "" a[4] "\n" \ 209 "\n" \ 210 "\n" \ 211 "postId\n" \ 212 "" id "\n" \ 213 "\n" \ 214 "\n" \ 215 "dateCreated\n" \ 216 "" a[2] "\n" \ 217 "" 218 219 printf("") 220 221 } 222 223 END { 224 225 print "\n\n" 226 } 227 228 # EOF