1 # ===================================================================== 2 # bloggerRecentPosts.awk: Blogger API 1.0 3 # 4 # Copyright (c) 2007,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 # Load each page in turn, showing links to nonexistent wiki pages 43 # within the same group. 44 45 # k_page,p_ctime,p_name,p_creau,p_uri,\ 46 # p_descr,p_vtime,p_modau,p_tags,p_allow,k_node,p_link,p_store 47 48 split($0,a,"\t") # split each record into fields. 49 50 split(a[3],c,".") # page category, if any. 51 52 if (a[4] == _NULL) a[4] = _nlsmap(_NULL,"anonymous") 53 54 # Fix 'ctime' to meet XML-RPC specs. 55 gsub(/-/,"",a[2]); sub(/ /,"T",a[2]) 56 57 page = page_dir "/" a[1] "+wki" 58 59 # Load each page body in turn. 60 61 value = _NULL 62 while (getline tmp1 < page > 0) value = value tmp1; close(page) 63 64 # Skip empty pages, as they are to be considered as logically deleted. 65 # This test should now be obsolete, but I'll leave it in place still 66 # for a while, as it does not cost much anyway since this program 67 # needs lo load the page bodies also for other reasons, see below. 68 69 if (value !~ /(>[^<>]+|[^<>]+<)/) next 70 71 # CSA tag markers must be escaped, or _envtoxml() will happily 72 # interpret anything typed by the user into the file !! 73 74 gsub(/\$\[/,"\\$[",value) 75 76 # If this group style is "wiki" then retain only the page abstract, 77 # if present. Otherwise, if either no abstract can be isolated or 78 # the group has been given a "blog" style, then the actual page body 79 # will be used. See also the call to _wikicpi() further down. 80 81 # Retain only page abstracts, if defined. 82 83 if (_rcget("TNS_TW_STYLE",1) != "blog") { 84 sub(/.*\(::ab:\)/,"",value) 85 sub(/\(:ab::\).*/,"",value) 86 87 sub(/\(:i:\).*/,_NULL,value) 88 } 89 90 #tmp = "/,"?",b[j]) 146 } 147 148 149 # This is to make sure hyperlinks do not contain blanks, 150 # or the W3C validator may complain. 151 152 tmp1 = b[j] 153 sub(/['"].*/,_NULL,tmp1) 154 sub(/[^'"]+/,_NULL,b[j]) 155 gsub(/ /,"+",tmp1) 156 b[j] = tmp1 b[j] 157 158 # Now spot external links and label them as such. 159 160 b[j] = "href=" b[j] 161 sub(/=/,"='",b[j]) # leading quote. 162 b[j] = extLink("\n" \ 168 "\n" \ 169 "content" 170 171 printf("%s",_xmlencode("" a[3])) 172 173 # Honour the Title-API flag. 174 if (_rcget("TNS_API_PROP",2) == "t") 175 printf("%s",_xmlencode("|" a[6] "|" a[7] "|" a[8] \ 176 "|" a[9] "|" a[10] "|" a[12] "|" a[13])) 177 178 printf(_xmlencode("")) 179 180 if (c[2] != _NULL) 181 printf("%s",_xmlencode("" c[1] "")) 182 183 # If the invoking user is an editor we have no other choice but assume 184 # that she wants to edit entries, including any embedded user-level 185 # CPI's, otherwise the latter will be parsed for display. If an editor 186 # wants to rather pull the rendered page over RPC then she will have 187 # to log-out and log-in again with an unprivileged account. Given the 188 # limited capabilities of the Blogger API compared with the full-blown 189 # TW Web API, it looks like this is the only sensible behaviour. 190 # Note: most (all ?) API methods only make sense if the user is an 191 # editor, so they are currently unavailable to others and therefore 192 # tests like the following never match. 193 194 # Perform Wiki parsing at this stage. 195 if ("," ENVIRON["TNS_AUTH_GRP"] "," !~ /,editor,/) 196 value = _wikicpi(value) 197 198 if (_rcget("cgi.numeric",1) == _NULL) 199 id = "" ENVIRON["CSA_LANG"] "/" g_name "/" a[1] "" 200 else id = "" a[11] "" 201 202 print _xmlencode(value) "\n" \ 203 "\n" \ 204 "\n" \ 205 "userId\n" \ 206 "" a[4] "\n" \ 207 "\n" \ 208 "\n" \ 209 "postId\n" \ 210 "" id "\n" \ 211 "\n" \ 212 "\n" \ 213 "dateCreated\n" \ 214 "" a[2] "\n" \ 215 "" 216 217 printf("") 218 219 } 220 221 END { 222 223 print "\n\n" 224 } 225 226 # EOF