1 # ===================================================================== 2 # tpl-stuff.rc: W-TW template finder. 3 # 4 # Copyright (c) 2009,2010,2011,2021 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 tpl_name = tw # default template. 26 27 switch ($'cgi.style') { 28 case p print 29 tpl_name = tp 30 } 31 32 # Look into the group-level attachment directory first, to see if 33 # there's a Blogger template that needs to be rebuilt. I cannot rely 34 # on the fact that it was uploaded with blogger.setTemplate, as not 35 # many blogging clients support that method, so in most cases it 36 # will have been uploaded by the user with putAttachment. 37 38 tw_stem = $CSA_DOCROOT/$CSA_LANG/$TNS_ATTACH_PUBDIR/$'cgi.group' 39 40 # If tb.html exists then rebuild the associated .tw.html if appropriate, 41 # otherwise remove the previous .tw.html . This is necessary or the 42 # user will not be able to delete the latter, because she is not 43 # allowed to upload/remove hidden files (see putAttachment). Do NOT 44 # EVER look for a user-uploaded tw.html in the public attachment 45 # directory, or we will be effectively granting webmaster privileges 46 # to editors! While we should not inadvertently let editors become 47 # webmasters, the latters are always allowed to include editor-uploaded 48 # stuff in FTP-managed templates by referencing them with the associated 49 # filesystem path, i.e. $[./path/to/upload/dir/somefile.txt:c] . 50 # 51 # Note that while a newly uploaded tb.html becomes immediately 52 # effective to display a single page, it will be used with static 53 # views (recent pages/headlines) only when they are re-built, i.e. 54 # upon the next page editing. 55 56 if (csaIsFullPath --exists --quiet $tw_stem/tb.$CSA_TPLEXT) { 57 if (!csaIsFullPath --exists --quiet $tw_stem/.tw.$CSA_TPLEXT || 58 test $tw_stem/tb.$CSA_TPLEXT -nt $tw_stem/.tw.$CSA_TPLEXT) { 59 60 # No TPC really needed here, also because the two associated *.fmt 61 # files are currently created directly by bloggerSetTemplate.awk 62 # and to apply TPC I would need to use temporary files instead. 63 # If anything fails then the operation can simply be repeated 64 # until the target files are re-created correctly. 65 66 csaAwkCmd bloggerSetTemplate.awk 67 68 $CSA_RESULT < $tw_stem/tb.$CSA_TPLEXT \ 69 > $tw_stem/.tw.$CSA_TPLEXT || 70 csaExit.fault 0009 $tw_stem/.tw.$CSA_TPLEXT 71 72 sed 's,\$\[tpl\.include\.html\.body:c\],
$[CSA_MSG_TEXT:x]
\ 73
$[tpl.include.nav.next:c]
,' \ 74 $tw_stem/.tw.$CSA_TPLEXT > $tw_stem/.tw.msg || 75 csaExit.fault 0009 $tw_stem/.tw.msg 76 77 tpl.include.tw.tpl.ok = $tw_stem/.tw.msg 78 tpl.include.tw.tpl.fault = $tw_stem/.tw.msg 79 } 80 81 TNS_TW_STYLE = blog # this seems logical to me. 82 83 } else { 84 85 # Remove any local templates as well as any custom tw-...fmt files 86 # that were created by the '' template directive. 87 rm -f $tw_stem/.tw.* $tw_stem/tw-* 88 89 # Restore default values. 90 tpl.include.tw.tpl.ok = $CSA_INSTALL/lib/csaOk.html 91 tpl.include.tw.tpl.fault = $CSA_INSTALL/lib/csaError.html 92 } 93 94 # Look for a node-specific custom Blogger template next. Note that 95 # rather than looking for a unixified page name we use the page 96 # node ID instead, as it is easier to handle over having to unixify 97 # the page name portion of the template name, which could be any 98 # string in the name of the template file uploaded by the editor. 99 # A file name like tb.12345.html is probably also easier for the 100 # editor to create too. 101 102 if (!~ $'tpl.var.tw.node' () && csaIsFullPath --exists --quiet \ 103 $tw_stem/tb.$'tpl.var.tw.node'.$CSA_TPLEXT) { 104 if (!csaIsFullPath --exists --quiet \ 105 $tw_stem/.tw.$'tpl.var.tw.node'.$CSA_TPLEXT || 106 test $tw_stem/tb.$'tpl.var.tw.node'.$CSA_TPLEXT -nt \ 107 $tw_stem/.tw.$'tpl.var.tw.node'.$CSA_TPLEXT) { 108 109 # No TPC really needed here, also because the two associated *.fmt 110 # files are currently created directly by bloggerSetTemplate.awk 111 # and to apply TPC I would need to use temporary files instead. 112 # If anything fails then the operation can simply be repeated 113 # until the target files are re-created correctly. 114 115 csaAwkCmd bloggerSetTemplate.awk 116 117 # Custom format files are disallowed inside per-page custom 118 # Blogger templates or they would apply to the whole site 119 # and not just to the specific page. 120 121 sed 's,\(<\)\(/\?BlogTemplates\)\(>\),\1!-- \2 --\3,g' \ 122 $tw_stem/tb.$'tpl.var.tw.node'.$CSA_TPLEXT | 123 $CSA_RESULT > $tw_stem/.tw.$'tpl.var.tw.node'.$CSA_TPLEXT || 124 csaExit.fault 0009 $tw_stem/.tw.$'tpl.var.tw.node'.$CSA_TPLEXT 125 126 sed 's,\$\[tpl\.include\.html\.body:c\],
$[CSA_MSG_TEXT:x]
\ 127
$[tpl.include.nav.next:c]
,' \ 128 $tw_stem/.tw.$'tpl.var.tw.node'.$CSA_TPLEXT \ 129 > $tw_stem/.tw.$'tpl.var.tw.node'.msg || 130 csaExit.fault 0009 $tw_stem/.tw.$'tpl.var.tw.node'.msg 131 132 tpl.include.tw.tpl.ok = $tw_stem/.tw.$'tpl.var.tw.node'.msg 133 tpl.include.tw.tpl.fault = $tw_stem/.tw.$'tpl.var.tw.node'.msg 134 } 135 136 TNS_TW_STYLE = blog # this seems logical to me. 137 138 } else { 139 140 rm -f $tw_stem/.tw.$'tpl.var.tw.node'.* 141 142 # Restore default values. 143 tpl.include.tw.tpl.ok = $CSA_INSTALL/lib/csaOk.html 144 tpl.include.tw.tpl.fault = $CSA_INSTALL/lib/csaError.html 145 } 146 147 # Note that the .tp.[node|page.]html template will also be sought for in 148 # the group-level attachment directory, but it will never be found there 149 # because "rpclib/putAttachment" refuses the upload of hidden files, so 150 # the search will fall-back to either the customized or the stock one. 151 # Therefore, the print-style template is currently not customizable by 152 # editors, and neither are the per-page, per-subcat or per-group-and-subcat 153 # templates, but given the limited scope of the customization mechanism 154 # exposed to editors this provides enough flexibility, at least for now. 155 156 # Per-pagenode template. 157 if (!~ $'tpl.var.tw.node' () && csaIsFullPath --exists --quiet \ 158 $tw_stem/.$tpl_name.$'tpl.var.tw.node'.$CSA_TPLEXT) { 159 tpl_file = (--file-root $tw_stem .$tpl_name.$'tpl.var.tw.node'.$CSA_TPLEXT) 160 161 } else { 162 163 # Per-pagename template. Note how in the following code the syntax used 164 # to identify a page-specific template is virtually indistinguishable 165 # from the one used to identify a subcat-specific template. That is 166 # intentional, because it would be rather peculiar if a page named "goofy" 167 # and a page named "goofy.mickey" needed *not* to use the same per- 168 # subcat template (unless a page-specific "tw.goofy.mickey.html" exists, 169 # of course). 170 171 if (!~ $'tpl.var.tw.page.unx' () && csaIsFullPath --exists \ 172 --quiet $CSA_TPL_ROOT/$tpl_name.$'tpl.var.tw.page.unx'.$CSA_TPLEXT) { 173 tpl_file = $tpl_name.$'tpl.var.tw.page.unx'.$CSA_TPLEXT 174 175 } else { 176 177 # Per-group custom template. 178 if (csaIsFullPath --exists --quiet $tw_stem/.$tpl_name.$CSA_TPLEXT) { 179 tpl_file = (--file-root $tw_stem .$tpl_name.$CSA_TPLEXT) 180 181 } else { 182 183 # If a per-subcat template exists then use the latter, otherwise 184 # use default (either per-language if available, or global 185 # otherwise). Note that the per-subcat template is not sought for 186 # if the subcat token is to be interpreted as a search pattern. 187 # See also 'rpclib/groupPageMap' . 188 189 if (~ $'cgi.subcat' [a-z]* && !~ $'cgi.scope' f* F* && 190 csaIsFullPath --exists --quiet \ 191 $CSA_TPL_ROOT/$tpl_name.$'cgi.subcat'.$CSA_TPLEXT) { 192 tpl_file = $tpl_name.$'cgi.subcat'.$CSA_TPLEXT 193 } else { 194 if (csaIsFullPath --exists --quiet \ 195 $CSA_TPL_ROOT/$tpl_name.$CSA_TPLEXT) { 196 tpl_file = $tpl_name.$CSA_TPLEXT 197 } else { 198 if (csaIsFullPath --exists --quiet \ 199 $tw_dstem/i18n/$CSA_LANG/$tpl_name.$CSA_TPLEXT) { 200 tpl_file = (--file-root $tw_dstem/i18n/$CSA_LANG 201 $tpl_name.$CSA_TPLEXT) 202 } else tpl_file = (--file-root $tw_dstem $tpl_name.$CSA_TPLEXT) 203 } 204 } 205 } 206 } 207 } 208 209 # Handle any user-defined name/value pairs. 210 211 if (csaIsFullPath --exists --quiet $tw_stem/tv.xml && 212 test $tw_stem/tv.xml -nt $tw_gstem+rc) { 213 214 # Let's do without TPC for the moment. 215 #csaOpen --fast --relaxed $tw_gstem+rc || csaExit.fault 216 #uservar_out = $CSA_RESULT 217 218 csaAwkCmd groupUserVars.awk 219 220 $CSA_RESULT < $tw_stem/tv.xml > $tw_gstem+rc || 221 csaExit.fault 0009 $tw_gstem+rc 222 223 . $tw_gstem+rc # load the new defs right away. 224 } 225 226 # As a further level of customization, if a tw-..html template 227 # exists then it will take over (where "group" is an authorization group, 228 # not a page group of course). If the user belongs into multiple groups 229 # then only the last group-specific template will take over. This behavior 230 # is currently experimental and it does not currently support per-subcat 231 # local templates (see above). 232 233 if (!~ $'tpl.var.tw.page.unx' () && !~ $TNS_AUTH_GRP ()) { 234 * = ``,{echo -n $TNS_AUTH_GRP} 235 while (!~ $1 ()) { 236 csaIsFullPath --exists --quiet \ 237 $CSA_TPL_ROOT/$tpl_name-$1.$'tpl.var.tw.page.unx'.$CSA_TPLEXT && 238 tpl_file = $tpl_name-$1.$'tpl.var.tw.page.unx'.$CSA_TPLEXT 239 shift 240 } 241 } 242 243 #EOF