Include header and footer into each template rather than displaying them out of order and rearranging
Include header and footer into each template rather than displaying them out of order and rearranging

--- a/include/display.git_message.php
+++ b/include/display.git_message.php
@@ -7,12 +7,14 @@
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  */
 
-function git_message($message, $error = FALSE)
+function git_message($message, $error = FALSE, $standalone = TRUE)
 {
 	global $tpl;
 	$tpl->assign("message",$message);
 	if ($error)
 		$tpl->assign("error", TRUE);
+	if ($standalone)
+		$tpl->assign("standalone", TRUE);
 	$tpl->display("message.tpl");
 }
 

--- a/include/display.git_search.php
+++ b/include/display.git_search.php
@@ -11,21 +11,19 @@
 require_once('util.highlight.php');
 require_once('gitutil.git_read_commit.php');
 require_once('gitutil.git_rev_list.php');
+require_once('display.git_message.php');
 
 function git_search($projectroot, $project, $hash, $search, $searchtype, $page = 0)
 {
 	global $tpl,$gitphp_conf;
 
 	if (!$gitphp_conf['search']) {
-		$tpl->assign("message","Search has been disabled");
-		$tpl->display("message.tpl");
+		git_message("Search has been disabled", TRUE, TRUE);
 		return;
 	}
 
 	if (!isset($search) || (strlen($search) < 2)) {
-		$tpl->assign("error",TRUE);
-		$tpl->assign("message","You must enter search text of at least 2 characters");
-		$tpl->display("message.tpl");
+		git_message("You must enter search text of at least 2 characters", TRUE, TRUE);
 		return;
 	}
 	if (!isset($hash)) {
@@ -37,8 +35,7 @@
 
 	$revlist = explode("\n",trim(git_rev_list($projectroot . $project, $hash, 101, ($page * 100), FALSE, FALSE, $searchtype, $search)));
 	if (count($revlist) < 1 || (strlen($revlist[0]) < 1)) {
-		$tpl->assign("message","No matches for '" . $search . "'.");
-		$tpl->display("message.tpl");
+		git_message("No matches for '" . $search . "'.", FALSE, TRUE);
 		return;
 	}
 

--- a/include/display.git_search_files.php
+++ b/include/display.git_search_files.php
@@ -11,21 +11,19 @@
 require_once('util.highlight.php');
 require_once('gitutil.git_filesearch.php');
 require_once('gitutil.git_read_commit.php');
+require_once('display.git_message.php');
 
 function git_search_files($projectroot, $project, $hash, $search, $page = 0)
 {
 	global $tpl,$gitphp_conf;
 
 	if (!($gitphp_conf['search'] && $gitphp_conf['filesearch'])) {
-		$tpl->assign("message","File search has been disabled");
-		$tpl->display("message.tpl");
+		git_message("File search has been disabled", TRUE, TRUE);
 		return;
 	}
 
 	if (!isset($search) || (strlen($search) < 2)) {
-		$tpl->assign("error",TRUE);
-		$tpl->assign("message","You must enter search text of at least 2 characters");
-		$tpl->display("message.tpl");
+		git_message("You must enter search text of at least 2 characters", TRUE, TRUE);
 		return;
 	}
 	if (!isset($hash)) {
@@ -38,8 +36,7 @@
 	$filesearch = git_filesearch($projectroot . $project, $hash, $search, false, ($page * 100), 101);
 
 	if (count($filesearch) < 1) {
-		$tpl->assign("message","No matches for '" . $search . "'.");
-		$tpl->display("message.tpl");
+		git_message("No matches for '" . $search . "'.", FALSE, TRUE);
 		return;
 	}
 

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -74,15 +74,11 @@
 if ($gitphp_conf['filesearch'])
 	$tpl->assign("filesearch",TRUE);
 
- $suppress_headers = FALSE;
 
- ob_start();
  if (isset($_GET['a']) && $_GET['a'] == "opml") {
-	$suppress_headers = TRUE;
 	require_once('include/display.git_opml.php');
 	git_opml($gitphp_conf['projectroot'],$git_projects);
  } else if (isset($_GET['a']) && $_GET['a'] == "project_index") {
-	$suppress_headers = TRUE;
 	require_once('include/display.git_project_index.php');
 	git_project_index($gitphp_conf['projectroot'],$git_projects);
  } else if (isset($_GET['p'])) {
@@ -125,7 +121,6 @@
 					git_commitdiff($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'], (isset($_GET['hp']) ? $_GET['hp'] : NULL));
 					break;
 				case "commitdiff_plain":
-					$suppress_headers = TRUE;
 					require_once('include/display.git_commitdiff_plain.php');
 					git_commitdiff_plain($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],(isset($_GET['hp']) ? $_GET['hp'] : NULL));
 					break;
@@ -138,7 +133,6 @@
 					git_tags($gitphp_conf['projectroot'],$_GET['p']);
 					break;
 				case "rss":
-					$suppress_headers = TRUE;
 					require_once('include/display.git_rss.php');
 					git_rss($gitphp_conf['projectroot'],$_GET['p']);
 					break;
@@ -147,7 +141,6 @@
 					git_blob($gitphp_conf['projectroot'],$_GET['p'], (isset($_GET['h']) ? $_GET['h'] : NULL), (isset($_GET['f']) ? $_GET['f'] : NULL), (isset($_GET['hb']) ? $_GET['hb'] : NULL));
 					break;
 				case "blob_plain":
-					$suppress_headers = TRUE;
 					require_once('include/display.git_blob_plain.php');
 					git_blob_plain($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],(isset($_GET['f']) ? $_GET['f'] : NULL));
 					break;
@@ -156,12 +149,10 @@
 					git_blobdiff($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],$_GET['hb'],$_GET['hp'],(isset($_GET['f']) ? $_GET['f'] : NULL));
 					break;
 				case "blobdiff_plain":
-					$suppress_headers = TRUE;
 					require_once('include/display.git_blobdiff_plain.php');
 					git_blobdiff_plain($gitphp_conf['projectroot'],$_GET['p'],$_GET['h'],$_GET['hb'],$_GET['hp'], (isset($_GET['f']) ? $_GET['f'] : NULL));
 					break;
 				case "snapshot":
-					$suppress_headers = TRUE;
 					require_once('include/display.git_snapshot.php');
 					git_snapshot($gitphp_conf['projectroot'],$_GET['p'], (isset($_GET['h']) ? $_GET['h'] : NULL));
 					break;
@@ -190,21 +181,8 @@
 		}
 	}
  } else {
- 	$tpl->display("hometext.tpl");
 	require_once('include/display.git_project_list.php');
  	git_project_list($gitphp_conf['projectroot'],$git_projects,(isset($_GET['o']) ? $_GET['o'] : "project"));
- }
- $main = ob_get_contents();
- ob_end_clean();
-
- if (!$suppress_headers) {
-	 $tpl->display("header.tpl");
- }
-
- echo $main;
-
- if (!$suppress_headers) {
-	 $tpl->display("footer.tpl");
  }
 
  if ($gitphp_conf['debug'])

--- a/templates/blob.tpl
+++ b/templates/blob.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* If we managed to look up commit info, we have enough info to display the full header - othewise just use a simple header *}
  <div class="page_nav">
    {if $fullnav}
@@ -63,3 +66,5 @@
    {/if}
  </div>
 
+ {include file='footer.tpl'}
+

--- a/templates/blobdiff.tpl
+++ b/templates/blobdiff.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* If we managed to look up commit info, we have enough info to display the full header - othewise just use a simple header *}
  <div class="page_nav">
    {if $fullnav}
@@ -48,3 +51,6 @@
    {include file='filediff.tpl'}
  </div>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/commit.tpl
+++ b/templates/commit.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  <div class="page_nav">
    {* Nav *}
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog&h={$hash}">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log&h={$hash}">log</a> | commit | {if $parent}<a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hash}">commitdiff</a> | {/if}<a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hash}">tree</a>
@@ -103,3 +106,6 @@
    {/section}
  </table>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/commitdiff.tpl
+++ b/templates/commitdiff.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog&h={$hash}">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log&h={$hash}">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}">commit</a> | commitdiff | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hash}">tree</a><br /><a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff_plain&h={$hash}&hp={$hashparent}">plain</a>
@@ -41,3 +44,6 @@
    {/section}
  </div>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/heads.tpl
+++ b/templates/heads.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$head}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$head}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$head}">tree</a>
@@ -24,3 +27,6 @@
    {/foreach}
  </table>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/history.tpl
+++ b/templates/history.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Page header *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hash}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$tree}&hb={$hash}">tree</a>
@@ -43,3 +46,6 @@
    {/section}
  </table>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/log.tpl
+++ b/templates/log.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog&h={$hash}">shortlog</a> | log | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hash}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$hash}&hb={$hash}">tree</a>
@@ -63,3 +66,6 @@
    </div>
  {/section}
 
+ {include file='footer.tpl'}
+
+

--- a/templates/message.tpl
+++ b/templates/message.tpl
@@ -5,5 +5,14 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+{if $standalone}
+  {include file='header.tpl'}
+{/if}
+
 <div class="message {if $error}error{/if}">{$message}</div>
 
+{if $standalone}
+  {include file='footer.tpl'}
+{/if}
+

--- a/templates/project.tpl
+++ b/templates/project.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    summary | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$head}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$head}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree">tree</a>
@@ -92,3 +95,6 @@
    </table>
  {/if}
 
+ {include file='footer.tpl'}
+
+

--- a/templates/projectlist.tpl
+++ b/templates/projectlist.tpl
@@ -5,6 +5,11 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+{include file='header.tpl'}
+
+{include file='hometext.tpl'}
+
 {if $message}
   {* Something is wrong; display an error message instead of trying to list *}
   {include file='message.tpl'}
@@ -97,3 +102,6 @@
   </table>
 {/if}
 
+{include file='footer.tpl'}
+
+

--- a/templates/search.tpl
+++ b/templates/search.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+{include file='header.tpl'}
+
 {* Nav *}
 <div class="page_nav">
   <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog&h={$hash}">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log&h={$hash}">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hash}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$treehash}&hb={$hash}">tree</a>
@@ -54,3 +57,6 @@
   {/if}
 </table>
 
+{include file='footer.tpl'}
+
+

--- a/templates/searchfiles.tpl
+++ b/templates/searchfiles.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+{include file='header.tpl'}
+
 {* Nav *}
 <div class="page_nav">
   <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog&h={$hash}">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log&h={$hash}">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hash}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$treehash}&hb={$hash}">tree</a>
@@ -62,3 +65,6 @@
   {/if}
 </table>
 
+{include file='footer.tpl'}
+
+

--- a/templates/shortlog.tpl
+++ b/templates/shortlog.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | shortlog | <a href="{$SCRIPT_NAME}?p={$project}&a=log&h={$hash}">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$hash}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$hash}&hb={$hash}">tree</a>
@@ -56,3 +59,6 @@
    {/if}
  </table>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/tag.tpl
+++ b/templates/tag.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$head}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$head}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$head}">tree</a>
@@ -40,3 +43,6 @@
    {/foreach}
  </div>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/tags.tpl
+++ b/templates/tags.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  <div class="page_nav">
    <a href="{$SCRIPT_NAME}?p={$project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$head}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$head}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&hb={$head}">tree</a>
@@ -37,3 +40,6 @@
    {/section}
  </table>
 
+ {include file='footer.tpl'}
+
+

--- a/templates/tree.tpl
+++ b/templates/tree.tpl
@@ -5,6 +5,9 @@
  *
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  *}
+
+ {include file='header.tpl'}
+
  {* Nav *}
  {if $fullnav}
    <div class="page_nav">
@@ -56,3 +59,6 @@
    </table>
  </div>
 
+ {include file='footer.tpl'}
+
+

comments