Use global assigns for headers/footers and to avoid duplication
Use global assigns for headers/footers and to avoid duplication

--- a/include/display.git_blob.php
+++ b/include/display.git_blob.php
@@ -23,9 +23,7 @@
 	if (!isset($hash) && isset($file))
 		$hash = git_get_hash_by_path($projectroot . $project, $hashbase,$file,"blob");
 	$catout = git_cat_file($projectroot . $project, $hash);
-	$tpl->clear_all_assign();
 	$tpl->assign("hash",$hash);
-	$tpl->assign("project",$project);
 	$tpl->assign("hashbase",$hashbase);
 	if ($co = git_read_commit($projectroot . $project, $hashbase)) {
 		$tpl->assign("fullnav",TRUE);

--- a/include/display.git_blobdiff.php
+++ b/include/display.git_blobdiff.php
@@ -21,11 +21,9 @@
 		echo $ret;
 		return;
 	}
-	$tpl->clear_all_assign();
 	$tpl->assign("hash",$hash);
 	$tpl->assign("hashparent",$hashparent);
 	$tpl->assign("hashbase",$hashbase);
-	$tpl->assign("project",$project);
 	if (isset($file))
 		$tpl->assign("file",$file);
 	if ($co = git_read_commit($projectroot . $project, $hashbase)) {

--- a/include/display.git_commit.php
+++ b/include/display.git_commit.php
@@ -28,8 +28,6 @@
 	}
 	$diffout = git_diff_tree($projectroot . $project, $root . " " . $parent . " " . $hash, TRUE);
 	$difftree = explode("\n",$diffout);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("tree",$co['tree']);
 	if (isset($co['parent']))

--- a/include/display.git_commitdiff.php
+++ b/include/display.git_commitdiff.php
@@ -28,8 +28,6 @@
 	$diffout = git_diff_tree($projectroot . $project, $hash_parent . " " . $hash);
 	$difftree = explode("\n",$diffout);
 	$refs = read_info_ref($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("tree",$co['tree']);
 	$tpl->assign("hashparent",$hash_parent);

--- a/include/display.git_commitdiff_plain.php
+++ b/include/display.git_commitdiff_plain.php
@@ -42,7 +42,6 @@
 	header("Content-type: text/plain; charset=UTF-8");
 	header("Content-disposition: inline; filename=\"git-" . $hash . ".patch\"");
 	$ad = date_str($co['author_epoch'],$co['author_tz']);
-	$tpl->clear_all_assign();
 	$tpl->assign("from",$co['author']);
 	$tpl->assign("date",$ad['rfc2822']);
 	$tpl->assign("subject",$co['title']);

--- a/include/display.git_heads.php
+++ b/include/display.git_heads.php
@@ -14,8 +14,6 @@
 {
 	global $tpl;
 	$head = git_read_head($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("head",$head);
 	$headlist = git_read_refs($projectroot, $project, "refs/heads");
 	$tpl->assign("headlist",$headlist);

--- a/include/display.git_history.php
+++ b/include/display.git_history.php
@@ -21,8 +21,6 @@
 		$hash = git_read_head($projectroot . $project);
 	$co = git_read_commit($projectroot . $project, $hash);
 	$refs = read_info_ref($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	if (isset($refs[$hash]))
 		$tpl->assign("hashbaseref",$refs[$hash]);

--- a/include/display.git_log.php
+++ b/include/display.git_log.php
@@ -22,8 +22,6 @@
 	if (!isset($page))
 		$page = 0;
 	$refs = read_info_ref($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("head",$head);
 

--- a/include/display.git_message.php
+++ b/include/display.git_message.php
@@ -10,7 +10,6 @@
 function git_message($message, $error = FALSE)
 {
 	global $tpl;
-	$tpl->clear_all_assign();
 	$tpl->assign("message",$message);
 	if ($error)
 		$tpl->assign("error", TRUE);

--- a/include/display.git_opml.php
+++ b/include/display.git_opml.php
@@ -15,7 +15,6 @@
 	global $tpl,$gitphp_conf;
 	$projlist = git_read_projects($projectroot,$projectlist);
 	header("Content-type: text/xml; charset=UTF-8");
-	$tpl->clear_all_assign();
 	$tpl->assign("title",$gitphp_conf['title']);
 	$tpl->assign("self",script_url());
 	$opmllist = array();

--- a/include/display.git_project_list.php
+++ b/include/display.git_project_list.php
@@ -19,7 +19,6 @@
 	$projects = git_read_projects($projectroot,$projectlist, TRUE);
 	if (is_array($projects)) {
 		if (count($projects) > 0) {
-			$tpl->clear_all_assign();
 			if ($order)
 				$tpl->assign("order",$order);
 			if (!isset($git_projects)) {

--- a/include/display.git_rss.php
+++ b/include/display.git_rss.php
@@ -21,9 +21,7 @@
 	$head = git_read_head($projectroot . $project);
 	$revlist = git_read_revlist($projectroot . $project, $head, GITPHP_RSS_ITEMS);
 	header("Content-type: text/xml; charset=UTF-8");
-	$tpl->clear_all_assign();
 	$tpl->assign("self",script_url());
-	$tpl->assign("project",$project);
 
 	$commitlines = array();
 	for ($i = 0; $i <= count($revlist); $i++) {

--- a/include/display.git_search.php
+++ b/include/display.git_search.php
@@ -16,7 +16,6 @@
 {
 	global $tpl,$gitphp_conf;
 
-	$tpl->clear_all_assign();
 	if (!$gitphp_conf['search']) {
 		$tpl->assign("message","Search has been disabled");
 		$tpl->display("message.tpl");
@@ -43,7 +42,6 @@
 		return;
 	}
 
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("treehash",$co['tree']);
 

--- a/include/display.git_search_files.php
+++ b/include/display.git_search_files.php
@@ -16,7 +16,6 @@
 {
 	global $tpl,$gitphp_conf;
 
-	$tpl->clear_all_assign();
 	if (!($gitphp_conf['search'] && $gitphp_conf['filesearch'])) {
 		$tpl->assign("message","File search has been disabled");
 		$tpl->display("message.tpl");
@@ -44,7 +43,6 @@
 		return;
 	}
 
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("treehash",$co['tree']);
 

--- a/include/display.git_shortlog.php
+++ b/include/display.git_shortlog.php
@@ -22,8 +22,6 @@
 	if (!isset($page))
 		$page = 0;
 	$refs = read_info_ref($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("head",$head);
 

--- a/include/display.git_summary.php
+++ b/include/display.git_summary.php
@@ -25,8 +25,6 @@
 	$commitdate = date_str($commit['committer_epoch'],$commit['committer_tz']);
 	$owner = git_project_owner($projectroot,$project);
 	$refs = read_info_ref($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("head",$head);
 	$tpl->assign("description",$descr);
 	$tpl->assign("owner",$owner);

--- a/include/display.git_tag.php
+++ b/include/display.git_tag.php
@@ -16,8 +16,6 @@
 	global $tpl;
 
 	$head = git_read_head($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("head",$head);
 	$tpl->assign("hash", $hash);
 

--- a/include/display.git_tags.php
+++ b/include/display.git_tags.php
@@ -14,8 +14,6 @@
 {
 	global $tpl;
 	$head = git_read_head($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("head",$head);
 	$taglist = git_read_refs($projectroot, $project, "refs/tags");
 	if (isset($taglist) && (count($taglist) > 0)) {

--- a/include/display.git_tree.php
+++ b/include/display.git_tree.php
@@ -27,8 +27,6 @@
 	}
 	$lsout = git_ls_tree($projectroot . $project, $hash, TRUE);
 	$refs = read_info_ref($projectroot . $project);
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	if (isset($hashbase))
 		$tpl->assign("hashbase",$hashbase);

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -45,8 +45,35 @@
 	$tpl->load_filter('output','trimwhitespace');
 }
 
-
- $rss_link = FALSE;
+/*
+ * Setup global assigns used everywhere (such as header/footer)
+ */
+ $tpl->assign("stylesheet",$gitphp_conf['stylesheet']);
+ $tpl->assign("version",$gitphp_version);
+ $tpl->assign("pagetitle",$gitphp_conf['title']);
+ if (isset($_GET['p'])) {
+	$tpl->assign("validproject",TRUE);
+	$tpl->assign("project",$_GET['p']);
+	require_once('include/gitutil.git_project_descr.php');
+	$tpl->assign("projectdescription",git_project_descr($gitphp_conf['projectroot'],$_GET['p']));
+	if (isset($_GET['a']))
+		$tpl->assign("action",$_GET['a']);
+ }
+ if (isset($_GET['st']))
+ 	$tpl->assign("currentsearchtype",$_GET['st']);
+ else
+	$tpl->assign("currentsearchtype","commit");
+if (isset($_GET['s']))
+	$tpl->assign("currentsearch",$_GET['s']);
+if (isset($_GET['hb']))
+	$tpl->assign("currentsearchhash",$_GET['hb']);
+else if (isset($_GET['h']))
+	$tpl->assign("currentsearchhash",$_GET['h']);
+if ($gitphp_conf['search'])
+	$tpl->assign("enablesearch",TRUE);
+if ($gitphp_conf['filesearch'])
+	$tpl->assign("filesearch",TRUE);
+
  $suppress_headers = FALSE;
 
  ob_start();
@@ -60,13 +87,14 @@
 	git_project_index($gitphp_conf['projectroot'],$git_projects);
  } else if (isset($_GET['p'])) {
  	if (!is_dir($gitphp_conf['projectroot'] . $_GET['p'])) {
+		$tpl->assign("validproject",FALSE);
 		require_once('include/display.git_message.php');
 		git_message("No such directory",TRUE);
 	} else if (!is_file($gitphp_conf['projectroot'] . $_GET['p'] . "/HEAD")) {
+		$tpl->assign("validproject",FALSE);
 		require_once('include/display.git_message.php');
 		git_message("No such project",TRUE);
 	} else {
-		$rss_link = TRUE;
 		if (!isset($_GET['a'])) {
 			require_once('include/display.git_summary.php');
 			git_summary($gitphp_conf['projectroot'],$_GET['p']);
@@ -170,45 +198,12 @@
  ob_end_clean();
 
  if (!$suppress_headers) {
-	 $tpl->clear_all_assign();
-	 $tpl->assign("stylesheet",$gitphp_conf['stylesheet']);
-	 $tpl->assign("version",$gitphp_version);
-	 $title = $gitphp_conf['title'];
-	 if ($rss_link) {
-		$tpl->assign("rss_link",TRUE);
-		$tpl->assign("project",$_GET['p']);
-		$title .= " :: " . $_GET['p'];
-		if (isset($_GET['a'])) {
-			$tpl->assign("action",$_GET['a']);
-			$title .= "/" . $_GET['a'];
-		}
-	 }
-	 $tpl->assign("title",$title);
-	 if (isset($_GET['st']))
-	 	$tpl->assign("searchtype",$_GET['st']);
-	else
-		$tpl->assign("searchtype","commit");
-	if (isset($_GET['s']))
-		$tpl->assign("search",$_GET['s']);
-	if (isset($_GET['hb']))
-		$tpl->assign("hash",$_GET['hb']);
-	else if (isset($_GET['h']))
-		$tpl->assign("hash",$_GET['h']);
-	if ($gitphp_conf['search'])
-		$tpl->assign("enablesearch",TRUE);
-	if ($gitphp_conf['filesearch'])
-		$tpl->assign("filesearch",TRUE);
 	 $tpl->display("header.tpl");
  }
 
  echo $main;
 
  if (!$suppress_headers) {
-	 if ($rss_link) {
-		$tpl->assign("project",$_GET['p']);
-		require_once('include/gitutil.git_project_descr.php');
-		$tpl->assign("descr",git_project_descr($gitphp_conf['projectroot'],$_GET['p']));
-	 }
 	 $tpl->display("footer.tpl");
  }
 

--- a/templates/footer.tpl
+++ b/templates/footer.tpl
@@ -7,10 +7,12 @@
  *}
     <div class="page_footer">
       {if $project}
-        {if $descr}
-          <div class="page_footer_text">{$descr}</div>
+        {if $projectdescription}
+          <div class="page_footer_text">{$projectdescription}</div>
         {/if}
-        <a href="{$SCRIPT_NAME}?p={$project}&a=rss" class="rss_logo">RSS</a>
+	{if $validproject}
+          <a href="{$SCRIPT_NAME}?p={$project}&a=rss" class="rss_logo">RSS</a>
+	{/if}
       {else}
         <a href="{$SCRIPT_NAME}?a=opml" class="rss_logo">OPML</a>
         <a href="{$SCRIPT_NAME}?a=project_index" class="rss_logo">TXT</a>

--- a/templates/header.tpl
+++ b/templates/header.tpl
@@ -12,8 +12,8 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <!-- gitphp web interface {$version}, (C) 2006 Christopher Han <xiphux@gmail.com> -->
   <head>
-    <title>{$title}</title>
-    {if $rss_link}
+    <title>{$pagetitle}{if $project && $validproject} :: {$project}{if $action}/{$action}{/if}{/if}</title>
+    {if $validproject}
       <link rel="alternate" title="{$project} log" href="{$SCRIPT_NAME}?p={$project}&a=rss" type="application/rss+xml" />
     {/if}
     <link rel="stylesheet" href="{$stylesheet}" type="text/css" />
@@ -25,7 +25,7 @@
         <img src="git-logo.png" width="72" height="27" alt="git" class="logo" />
       </a>
       <a href="index.php">projects</a> / 
-      {if $project}
+      {if $project && $validproject}
         <a href="{$SCRIPT_NAME}?p={$project}&a=summary">{$project}</a>
         {if $action}
            / {$action}
@@ -35,15 +35,15 @@
             <div class="search">
               <input type="hidden" name="p" value="{$project}" />
               <input type="hidden" name="a" value="search" />
-              <input type ="hidden" name="h" value="{if $hash}{$hash}{else}HEAD{/if}" />
+              <input type ="hidden" name="h" value="{if $currentsearchhash}{$currentsearchhash}{else}HEAD{/if}" />
               <select name="st">
-                <option {if $searchtype == 'commit'}selected="selected"{/if} value="commit">commit</option>
-                <option {if $searchtype == 'author'}selected="selected"{/if} value="author">author</option>
-                <option {if $searchtype == 'committer'}selected="selected"{/if} value="committer">committer</option>
+                <option {if $currentsearchtype == 'commit'}selected="selected"{/if} value="commit">commit</option>
+                <option {if $currentsearchtype == 'author'}selected="selected"{/if} value="author">author</option>
+                <option {if $currentsearchtype == 'committer'}selected="selected"{/if} value="committer">committer</option>
                 {if $filesearch}
-                  <option {if $searchtype == 'file'}selected="selected"{/if} value="file">file</option>
+                  <option {if $currentsearchtype == 'file'}selected="selected"{/if} value="file">file</option>
                 {/if}
-              </select> search: <input type="text" name="s" {if $search}value="{$search}"{/if} />
+              </select> search: <input type="text" name="s" {if $currentsearch}value="{$currentsearch}"{/if} />
             </div>
           </form>
         {/if}

comments