1 # ===================================================================== 2 # blogger.getRecentPosts: BloggerAPI method and MetaWeblog API. 3 # 4 # Copyright (c) 2007,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 # ===================================================================== 22 # Local variables and functions 23 # ===================================================================== 24 25 cgi.group = () 26 cgi.group.literal = () 27 cgi.numposts = $TNS_RECENT_PAGES_NUM # Default. 28 cgi.numeric = () 29 30 # ===================================================================== 31 # Main program 32 # ===================================================================== 33 34 csaGetArgs POST 35 36 . $CSA_ROOT/lib/group-stuff.rc 37 38 . $CSA_ROOT/lib/group-editor.rc 39 40 # Policy checks done after the inclusion of group meta-data. 41 ~ ,$TNS_AUTH_GRP, *,editor,* || csaExit.needauth 42 43 # Create target table if it does not yet exist. 44 if (!csaIsFullPath --exists --quiet $tw_gstem/page+dat) { 45 46 # Set Principal Lock Semaphore(s) (PLS). 47 csaLock $tw_gstem/page+dat || csaExit.fault 48 49 # Test again, to account for races. 50 if (!csaIsFullPath --exists --quiet $tw_gstem/page+dat) { 51 maketable --input \ 52 $CSA_ROOT/lib/page.xrf > $tw_gstem/page+dat || 53 csaExit.fault 0003 maketable 54 } 55 } 56 57 csaMkTemp tpl.include.tw.rpc 58 59 switch ($CSA_PGM($#CSA_PGM)) { 60 case metaWeblog.*; csaAwkCmd mwRecentPosts.awk 61 case mt.*; csaAwkCmd mtRecentPostTitles.awk 62 #case wp.*; csaAwkCmd wpPageList.awk 63 case *; csaAwkCmd bloggerRecentPosts.awk 64 } 65 66 awktable -i $tw_gstem/page+dat -- 'BEGIN { 67 print "\001k_page\t\001p_ctime\t\001p_name\t\001p_creau" \ 68 "\t\001p_uri\t\001p_descr\t\001p_vtime\t\001p_modau" \ 69 "\t\001p_tags\t\001p_allow\t\001k_node\t\001p_link\t\001p_store" 70 } 71 72 # Handle page expiration dates, accounting for older 73 # versions of page+dat which may lack that field. 74 p_etime/=1 { 75 # Set default expiration date. 76 if ($p_etime == "") $p_etime = "9999-12-31 23:59:59" 77 if ("'$CSA_TIME_ISO'" >= $p_etime && \ 78 $p_descr !~ /^ *-/) $p_descr = "-" $p_descr 79 } 80 81 # Exclude redirected pages if non-editor. Note: most (all ?) API methods 82 # only make sense if the user is an editor and they are currently 83 # unavailable to others, so tests like the following ones never match. 84 $p_descr ~ /\(:redirect / && ENVIRON["TNS_AUTH_GRP"] !~ /,editor,/{next} 85 86 # Unconditionally exclude hidden pages with no title, as they are 87 # to be considered logically deleted and the editor will only be 88 # able to edit them through the RESTful interface. 89 $p_descr ~ /^ *-[- ]*$/ {next} 90 91 # Exclude hidden pages (with non-empty title) if non-editor. 92 $p_descr ~ /^ *-[- ]*[^- ]/ && ENVIRON["TNS_AUTH_GRP"] !~ /,editor,/{next} 93 94 # Exclude restricted pages unless authorized user or editor. 95 { auth_ = "(,editor,|," $p_allow ",)" } 96 $p_allow != "" && ENVIRON["TNS_AUTH_GRP"] !~ auth_ {next} 97 98 # Honour explicit exclusions if non-editor. 99 $p_descr ~ /^ *!/ && ENVIRON["TNS_AUTH_GRP"] !~ /,editor,/{next} 100 101 {print $k_page,$p_ctime,$p_name,$p_creau,$p_uri,$p_descr,\ 102 $p_vtime,$p_modau,$p_tags,$p_allow,$k_node,$p_link,$p_store}' | 103 sorttable -r p_ctime | head -n $'cgi.numposts' | 104 $CSA_RESULT > $'tpl.include.tw.rpc' 105 106 # It looks like that GNU sort(1) traps SIGPIPE, and returns 2 on both 107 # SIGPIPE and EPIPE. This does not stand for an error, because it 108 # is due to head(1) closing the pipeline after the specified number 109 # of lines have been read. Furthermore, it does not always happen, 110 # possibly depending on the size of the input data, on the machine 111 # load and on other momentary factors. Ignoring error code 2 seems 112 # to fix that. 113 114 csaStatus sigpipe 2 || csaExit.fault 0003 awktable/sorttable/head/AWK 115 116 #if (~ $tpl_name tw-*) { 117 # 118 # # Page names beginning with tw-* are reserved for TW use, and usually 119 # # refer to views that do not correspond to actual pages on disk, so 120 # # we need to toggle unapplicable sections in templates. 121 # 122 # tpl.if.tw.ispage = '(::DEL:)' 123 # tpl.fi.tw.ispage = '(:DEL::)' 124 # tpl.if.tw.editor = '(::DEL:)' 125 # tpl.fi.tw.editor = '(:DEL::)' 126 #} 127 128 # Make sure no-replace mode is used on the page body by prepending 129 # its name with '-', or any user-supplied CSA tags in the text will 130 # be happily parsed by _envtoxml() !! 131 132 #~ $REMOTE_ADDR 192.168.1.2 && cp $'tpl.include.tw.rpc' /tmp/aaa 133 134 tpl.include.tw.rpc = -$'tpl.include.tw.rpc' 135 136 csaExit.ok 137 138 # End of program.