tlayout.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2004 Patrick R. Michaud (pmichaud@pobox.com)
  3. This file is part of PmWiki; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version. See pmwiki.php for full details.
  7. This module sets the values of $PageStartFmt and $PageEndFmt,
  8. used by various modules to generate output pages. The general
  9. mechanism for page output is that a function such as HandleBrowse
  10. or HandleEdit will output the value of $PageStartFmt, followed
  11. by the action-specific content, followed by $PageEndFmt. The
  12. HTML comment <!--PageText--> in the template file denotes the
  13. location where $PageStart ends and $PageEnd begins. The
  14. HTML comment <!--HeaderText--> denotes where the contents of
  15. $HTMLHeaderFmt should be generated.
  16. The template file may also contain HTML comments of the form
  17. <!--PageHeaderFmt-->, <!--PageFooterFmt-->, etc. These
  18. have the side effect of putting the strings that follow into
  19. the variables $PageHeaderFmt, $PageFooterFmt, etc. and then
  20. placing references to those variables into $PageStartFmt or
  21. $PageEndFmt. This allows HandleBrowse and other functions to
  22. selectively disable headers and footers by setting the corresponding
  23. variable to the empty string.
  24. Versions 0.6.1 and 0.6.2 made use of an $HTMLHeaders variable
  25. that is now deprecated, use <!--HeaderText--> and $HTMLHeaderFmt
  26. instead.
  27. */
  28. SDV($FarmPubDirUrl,$PubDirUrl);
  29. SDV($PageTemplateFmt,"$FarmD/pub/skins/pmwiki/pmwiki.tmpl");
  30. SDV($PageLogoUrl,"$FarmPubDirUrl/skins/pmwiki/pmwiki-32.gif");
  31. SDV($PageLogoFmt,"<div id='wikilogo'><a href='$ScriptUrl'><img
  32. src='$PageLogoUrl' alt='$WikiTitle' border='0' /></a></div>");
  33. SDV($PageCSSListFmt,array(
  34. 'pub/css/local.css' => '$PubDirUrl/css/local.css',
  35. 'pub/css/$Group.css' => '$PubDirUrl/css/$Group.css',
  36. 'pub/css/$Group.$Title_.css' => '$PubDirUrl/css/$Group.$Title_.css'));
  37. foreach((array)$PageCSSListFmt as $k=>$v)
  38. if (file_exists(FmtPageName($k,$pagename)))
  39. $HTMLHeaderFmt[] = "<link rel='stylesheet' type='text/css' href='$v' />\n";
  40. if ($PageTemplateFmt) LoadPageTemplate($PageTemplateFmt);
  41. function LoadPageTemplate($tfilefmt) {
  42. global $PageStartFmt,$PageEndFmt,$BasicLayoutVars,$HTMLHeaderFmt;
  43. SDV($BasicLayoutVars,array('HeaderText','PageHeaderFmt','PageLeftFmt',
  44. 'PageTitleFmt', 'PageText','PageRightFmt','PageFooterFmt'));
  45. $k = str_replace('$HTMLHeaders','<!--HeaderText-->', # deprecated
  46. implode('',file(FmtPageName($tfilefmt,$pagename))));
  47. $sect = preg_split('#[[<]!--(/?Page[A-Za-z]+Fmt|PageText|HeaderText)--[]>]#',
  48. $k,0,PREG_SPLIT_DELIM_CAPTURE);
  49. $PageStartFmt = array_merge(array('headers:'),
  50. preg_split('/[[<]!--((?:wiki|file|function):.*?)--[]>]/',array_shift($sect),
  51. 0,PREG_SPLIT_DELIM_CAPTURE));
  52. $PageEndFmt = array();
  53. $ps = 'PageStartFmt';
  54. while (count($sect)>0) {
  55. $k = array_shift($sect);
  56. $v = preg_split('/[[<]!--((?:wiki|file|function):.*?)--[]>]/',
  57. array_shift($sect),0,PREG_SPLIT_DELIM_CAPTURE);
  58. if (substr($k,0,1)=='/') {
  59. $GLOBALS[$ps][] = "<!--$k-->";
  60. $GLOBALS[$ps][] = (count($v)>1) ? $v : $v[0];
  61. continue;
  62. }
  63. $GLOBALS[$k] = (count($v)>1) ? $v : $v[0];
  64. if (in_array($k,$BasicLayoutVars)) {
  65. $GLOBALS[$ps][] = "<!--$k-->";
  66. if ($k=='PageText') { $ps = 'PageEndFmt'; }
  67. if ($k=='HeaderText') $GLOBALS[$ps][] = &$HTMLHeaderFmt;
  68. $GLOBALS[$ps][] =& $GLOBALS[$k];
  69. }
  70. }
  71. array_push($PageStartFmt,"\n<div id='wikitext'>\n");
  72. array_unshift($PageEndFmt,'</div>');
  73. }
  74. ?>