1 # ===================================================================== 2 # mwGetCategories.awk: MetaWeblog API. 3 # 4 # Copyright (c) 2007,2008 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 delete a; delete b; delete c 24 25 # I use the unixified group name as a URI here, so that 26 # blogger.getRecentPosts or anyone else using the output 27 # from this program will not need to read the actual group 28 # record into memory. Fortunately the TW design provides 29 # enough flexibility :-) 30 31 g_name = _rcget("cgi.group") 32 33 url = ENVIRON["CSA_RPC_URI"] "/" ENVIRON["CSA_LANG"] "/" g_name 34 35 printf("\n") 36 } 37 38 /^\001/ { next } # skip table header, if any. 39 40 { 41 # k_page, p_name, p_descr 42 43 split($0,a,"\t") # split each record into fields. 44 45 split(a[2],b,".") # page category name, if any. 46 47 split(a[1],c,".") # page category URI, if any. 48 49 # Note that we do not need to test for redirected/hidden/restricted 50 # pages here, and possibly skip them, because categories exist regardless 51 # of what the pages belonging into them may contain. Also note that 52 # the MetaWeblog API specs are debatable regarding the getCategories 53 # method, as reported in many places, among which: 54 # 55 # http://www.truerwords.net/articles/web-tech/metaweblog.getrecentposts.html 56 # http://roy.tabulas.com/2008/04/02/xml-rpc-interfaces-and-standards-oh-yeah/ 57 # 58 # I am currently sticking to the widely adopted interpretation of 59 # returning an array of structs as the result, but the original specs 60 # (which nobody seems to implement except maybe Userland's Radio), say 61 # that a struct of structs should be returned. See the specs at 62 # http://www.xmlrpc.com/metaWeblogApi . 63 # 64 # OTOH, even if one wanted to stick to the specs and return a struct of 65 # structs, it is not at all clear how this could possibly be accomplished, 66 # since a struct is an unordered list of name/value pairs, and the specs 67 # do not tell what names should be used in the outer struct. 68 69 print "\n\n" \ 70 "\n" \ 71 "description\n" \ 72 "" _xmlencode(b[1]) "\n" \ 73 "\n" \ 74 "\n" \ 75 "htmlUrl\n" \ 76 "" url "/" c[1] "-recent-headlines\n" \ 77 "\n" \ 78 "\n" \ 79 "rssUrl\n" \ 80 "\n" \ 81 url "/tw-" c[1] "-recent-headlines/style/rss\n" \ 82 "" 83 84 printf("") 85 86 } 87 88 END { 89 90 print "\n\n" 91 } 92 93 # EOF