Unify search templates
Unify search templates

--- a/include/display.git_search.php
+++ b/include/display.git_search.php
@@ -16,15 +16,14 @@
 {
 	global $tpl,$gitphp_conf;
 
+	$tpl->clear_all_assign();
 	if (!$gitphp_conf['search']) {
-		$tpl->clear_all_assign();
 		$tpl->assign("message","Search has been disabled");
 		$tpl->display("message.tpl");
 		return;
 	}
 
 	if (!isset($search) || (strlen($search) < 2)) {
-		$tpl->clear_all_assign();
 		$tpl->assign("error",TRUE);
 		$tpl->assign("message","You must enter search text of at least 2 characters");
 		$tpl->display("message.tpl");
@@ -39,77 +38,51 @@
 
 	$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->clear_all_assign();
 		$tpl->assign("message","No matches for '" . $search . "'.");
 		$tpl->display("message.tpl");
 		return;
 	}
 
-	$tpl->clear_all_assign();
 	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("treehash",$co['tree']);
-	$tpl->display("search_nav.tpl");
 
 	$tpl->assign("search",$search);
 	$tpl->assign("searchtype",$searchtype);
-	if ($page > 0) {
-		$tpl->assign("firstlink",TRUE);
-		$tpl->assign("prevlink",TRUE);
-		if ($page > 1)
-			$tpl->assign("prevpage",$page-1);
-	}
-	if (count($revlist) > 100) {
-		$tpl->assign("nextlink",TRUE);
-		$tpl->assign("nextpage",$page+1);
-	}
-	$tpl->display("search_pagenav.tpl");
+	$tpl->assign("page",$page);
+	$revlistcount = count($revlist);
+	$tpl->assign("revlistcount",$revlistcount);
 
 	$tpl->assign("title",$co['title']);
-	$tpl->display("search_header.tpl");
 
-	$alternate = FALSE;
-	$commitcount = min(100,count($revlist));
+	$commitlines = array();
+	$commitcount = min(100,$revlistcount);
 	for ($i = 0; $i < $commitcount; $i++) {
-		$tpl->clear_all_assign();
 		$commit = $revlist[$i];
 		if (strlen(trim($commit)) > 0) {
+			$commitline = array();
 			$co2 = git_read_commit($projectroot . $project, $commit);
-			if ($alternate)
-				$tpl->assign("class","dark");
-			else
-				$tpl->assign("class","light");
-			$alternate = !$alternate;
-			$tpl->assign("project",$project);
-			$tpl->assign("commit",$commit);
-			$tpl->assign("agestringage",$co2['age_string_age']);
-			$tpl->assign("agestringdate",$co2['age_string_date']);
-			$tpl->assign("authorname",$co2['author_name']);
-			$tpl->assign("title_short",$co2['title_short']);
+			$commitline["commit"] = $commit;
+			$commitline["agestringage"] = $co2['age_string_age'];
+			$commitline["agestringdate"] = $co2['age_string_date'];
+			$commitline["authorname"] = $co2['author_name'];
+			$commitline["title_short"] = $co2['title_short'];
 			if (strlen($co2['title_short']) < strlen($co2['title']))
-				$tpl->assign("title",$co2['title']);
-			$tpl->assign("committree",$co2['tree']);
+				$commitline["title"] = $co2['title'];
+			$commitline["committree"] = $co2['tree'];
 			$matches = array();
 			foreach ($co2['comment'] as $comline) {
 				$hl = highlight($comline, $search, "searchmatch", GITPHP_TRIM_LENGTH);
 				if ($hl && (strlen($hl) > 0))
 					$matches[] = $hl;
 			}
-			$tpl->assign("matches",$matches);
-			$tpl->display("search_item.tpl");
+			$commitline["matches"] = $matches;
+			$commitlines[] = $commitline;
 		}
 	}
-
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
-	$tpl->assign("hash",$hash);
-	$tpl->assign("search",$search);
-	$tpl->assign("searchtype",$searchtype);
-	if (count($revlist) > 100) {
-		$tpl->assign("nextlink",TRUE);
-		$tpl->assign("nextpage",$page+1);
-	}
-	$tpl->display("search_footer.tpl");
+	
+	$tpl->assign("commitlines",$commitlines);
+	$tpl->display("search.tpl");
 }
 
 ?>

--- a/include/display.git_search_files.php
+++ b/include/display.git_search_files.php
@@ -16,15 +16,14 @@
 {
 	global $tpl,$gitphp_conf;
 
+	$tpl->clear_all_assign();
 	if (!($gitphp_conf['search'] && $gitphp_conf['filesearch'])) {
-		$tpl->clear_all_assign();
 		$tpl->assign("message","File search has been disabled");
 		$tpl->display("message.tpl");
 		return;
 	}
 
 	if (!isset($search) || (strlen($search) < 2)) {
-		$tpl->clear_all_assign();
 		$tpl->assign("error",TRUE);
 		$tpl->assign("message","You must enter search text of at least 2 characters");
 		$tpl->display("message.tpl");
@@ -40,47 +39,28 @@
 	$filesearch = git_filesearch($projectroot . $project, $hash, $search, false, ($page * 100), 101);
 
 	if (count($filesearch) < 1) {
-		$tpl->clear_all_assign();
 		$tpl->assign("message","No matches for '" . $search . "'.");
 		$tpl->display("message.tpl");
 		return;
 	}
 
-	$tpl->clear_all_assign();
 	$tpl->assign("project",$project);
 	$tpl->assign("hash",$hash);
 	$tpl->assign("treehash",$co['tree']);
-	$tpl->display("search_nav.tpl");
 
 	$tpl->assign("search",$search);
 	$tpl->assign("searchtype","file");
-	if ($page > 0) {
-		$tpl->assign("firstlink",TRUE);
-		$tpl->assign("prevlink",TRUE);
-		if ($page > 1)
-			$tpl->assign("prevpage",$page-1);
-	}
-	if (count($filesearch) > 100) {
-		$tpl->assign("nextlink",TRUE);
-		$tpl->assign("nextpage",$page+1);
-	}
-	$tpl->display("search_pagenav.tpl");
+	$tpl->assign("page",$page);
+	$filesearchcount = count($filesearch);
+	$tpl->assign("filesearchcount",$filesearchcount);
 
 	$tpl->assign("title",$co['title']);
-	$tpl->display("search_header.tpl");
 
-	$alternate = FALSE;
+	$filesearchlines = array();
 	$i = 0;
 	foreach ($filesearch as $file => $data) {
-		$tpl->clear_all_assign();
-		if ($alternate)
-			$tpl->assign("class","dark");
-		else
-			$tpl->assign("class","light");
-		$alternate = !$alternate;
-		$tpl->assign("project",$project);
-		$tpl->assign("hashbase",$hash);
-		$tpl->assign("file",$file);
+		$filesearchline = array();
+		$filesearchline["file"] = $file;
 		if (strpos($file,"/") !== false) {
 			$f = basename($file);
 			$d = dirname($file);
@@ -92,12 +72,12 @@
 		} else
 			$hlt = highlight($file, $search, "searchmatch");
 		if ($hlt)
-			$tpl->assign("filename",$hlt);
+			$filesearchline["filename"] = $hlt;
 		else
-			$tpl->assign("filename",$file);
-		$tpl->assign("hash",$data['hash']);
+			$filesearchline["filename"] = $file;
+		$filesearchline["hash"] = $data['hash'];
 		if ($data['type'] == "tree")
-			$tpl->assign("tree",TRUE);
+			$filesearchline["tree"] = TRUE;
 		if (isset($data['lines'])) {
 			$matches = array();
 			foreach ($data['lines'] as $line) {
@@ -106,24 +86,15 @@
 					$matches[] = $hlt;
 			}
 			if (count($matches) > 0)
-				$tpl->assign("matches",$matches);
+				$filesearchline["matches"] = $matches;
 		}
-		$tpl->display("search_fileitem.tpl");
+		$filesearchlines[] = $filesearchline;
 		$i++;
 		if ($i >= 100)
 			break;
 	}
-
-	$tpl->clear_all_assign();
-	$tpl->assign("project",$project);
-	$tpl->assign("hash",$hash);
-	$tpl->assign("search",$search);
-	$tpl->assign("searchtype","file");
-	if (count($filesearch) > 100) {
-		$tpl->assign("nextlink",TRUE);
-		$tpl->assign("nextpage",$page+1);
-	}
-	$tpl->display("search_footer.tpl");
+	$tpl->assign("filesearchlines",$filesearchlines);
+	$tpl->display("searchfiles.tpl");
 }
 
 ?>

--- /dev/null
+++ b/templates/search.tpl
@@ -1,1 +1,55 @@
+{*
+ *  search.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Search view template
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ *}
+<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>
+  <br />
+  {if $page > 0}
+    <a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}">first</a>
+  {else}
+    first
+  {/if}
+    &sdot; 
+  {if $page > 0}
+    <a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}{if $page > 1}&pg={$page-1}{/if}" accesskey="p" title="Alt-p">prev</a>
+  {else}
+    prev
+  {/if}
+    &sdot; 
+  {if $revlistcount > 100}
+    <a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}&pg={$page+1}" accesskey="n" title="Alt-n">next</a>
+  {else}
+    next
+  {/if}
+  <br />
+</div>
+<div>
+  <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}" class="title">{$title}</a>
+</div>
+<table cellspacing="0">
 
+  {section name=match loop=$commitlines}
+    <tr class="{cycle values="light,dark"}">
+      <td title="{$commitlines[match].agestringage}"><i>{$commitlines[match].agestringdate}</i></td>
+      <td><i>{$commitlines[match].authorname}</i></td>
+      <td><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$commitlines[match].commit}" class="list" {if $title}title="{$commitlines[match].title}"{/if}><b>{$commitlines[match].title_short}</b>
+        {foreach from=$commitlines[match].matches item=line name=match}
+          {if $smarty.foreach.match.first}<br />{/if}{$line}<br />
+        {/foreach}
+      </td>
+      <td class="link"><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$commitlines[match].commit}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$commitlines[match].commit}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$commitlines[match].committree}&hb={$commitlines[match].commit}">tree</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=snapshot&h={$commitlines[match].commit}">snapshot</a>
+      </td>
+    </tr>
+  {/section}
+
+  {if $revlistcount > 100}
+    <tr>
+      <td><a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}&pg={$page+1}" title="Alt-n">next</a></td>
+    </tr>
+  {/if}
+</table>
+

--- a/templates/search_fileitem.tpl
+++ /dev/null
@@ -1,21 +1,1 @@
-{*
- *  search_fileitem.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Search file item template
- *
- *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
- *}
-<tr class="{$class}">
-<td>
-{if $tree}
-<a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$hash}&hb={$hashbase}&f={$file}" class="list"><b>{$filename}</b></a>
-{else}
-<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hash}&hb={$hashbase}&f={$file}" class="list"><b>{$filename}</b></a>
-{foreach from=$matches item=line name=match}
-{if $smarty.foreach.match.first}<br />{/if}<span class="respectwhitespace">{$line}</span><br />
-{/foreach}
-{/if}
-</td>
-<td class="link">{if $tree}<a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$hash}&hb={$hashbase}&f={$file}">tree</a>{else}<a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$hash}&hb={$hashbase}&f={$file}">blob</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=history&h={$hashbase}&f={$file}">history</a>{/if}</td>
-</tr>
 

--- a/templates/search_footer.tpl
+++ /dev/null
@@ -1,12 +1,1 @@
-{*
- *  search_footer.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Search view footer template
- *
- *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
- *}
- {if $nextlink}
- <tr><td><a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}&pg={$nextpage}" title="Alt-n">next</a></td></tr>
- {/if}
- </table>
 

--- a/templates/search_header.tpl
+++ /dev/null
@@ -1,12 +1,1 @@
-{*
- *  search_header.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Search header template
- *
- *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
- *}
-<div>
-<a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}" class="title">{$title}</a>
-</div>
-<table cellspacing="0">
 

--- a/templates/search_item.tpl
+++ /dev/null
@@ -1,19 +1,1 @@
-{*
- *  search_item.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Search view item template
- *
- *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
- *}
-<tr class="{$class}">
-<td title="{$agestringage}"><i>{$agestringdate}</i></td>
-<td><i>{$authorname}</i></td>
-<td><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$commit}" class="list" {if $title}title="{$title}"{/if}><b>{$title_short}</b>
-{foreach from=$matches item=line name=match}
-{if $smarty.foreach.match.first}<br />{/if}{$line}<br />
-{/foreach}
-</td>
-<td class="link"><a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$commit}">commit</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=commitdiff&h={$commit}">commitdiff</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$committree}&hb={$commit}">tree</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=snapshot&h={$commit}">snapshot</a>
-</td>
-</tr>
 

--- a/templates/search_nav.tpl
+++ /dev/null
@@ -1,11 +1,1 @@
-{*
- *  search_nav.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Search view nav template
- *
- *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
- *}
-<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>
-<br />
 

--- a/templates/search_pagenav.tpl
+++ /dev/null
@@ -1,11 +1,1 @@
-{*
- *  search_pagenav.tpl
- *  gitphp: A PHP git repository browser
- *  Component: Log view page nav template
- *
- *  Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
- *}
- {if $firstlink}<a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}">{/if}first{if $firstlink}</a>{/if} &sdot; {if $prevlink}<a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}{if $prevpage}&pg={$prevpage}{/if}" accesskey="p" title="Alt-p">{/if}prev{if $prevlink}</a>{/if} &sdot; {if $nextlink}<a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}&pg={$nextpage}" accesskey="n" title="Alt-n">{/if}next{if $nextlink}</a>{/if}
- <br />
- </div>
 

--- /dev/null
+++ b/templates/searchfiles.tpl
@@ -1,1 +1,63 @@
+{*
+ *  searchfiles.tpl
+ *  gitphp: A PHP git repository browser
+ *  Component: Search files template
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ *}
+<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>
+  <br />
+  {if $page > 0}
+    <a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}">first</a>
+  {else}
+    first
+  {/if}
+    &sdot; 
+  {if $page > 0}
+    <a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}{if $page > 1}&pg={$page-1}{/if}" accesskey="p" title="Alt-p">prev</a>
+  {else}
+    prev
+  {/if}
+    &sdot; 
+  {if $filesearchcount > 100}
+    <a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}&pg={$page+1}" accesskey="n" title="Alt-n">next</a>
+  {else}
+    next
+  {/if}
+  <br />
+</div>
+<div>
+  <a href="{$SCRIPT_NAME}?p={$project}&a=commit&h={$hash}" class="title">{$title}</a>
+</div>
+<table cellspacing="0">
 
+  {section name=match loop=$filesearchlines}
+    <tr class="{cycle values="light,dark"}">
+      <td>
+        {if $filesearchlines[match].tree}
+          <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$filesearchlines[match].hash}&hb={$hash}&f={$filesearchlines[match].file}" class="list"><b>{$filesearchlines[match].filename}</b></a>
+        {else}
+          <a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$filesearchlines[match].hash}&hb={$hash}&f={$filesearchlines[match].file}" class="list"><b>{$filesearchlines[match].filename}</b></a>
+          {foreach from=$filesearchlines[match].matches item=line name=match}
+            {if $smarty.foreach.match.first}<br />{/if}<span class="respectwhitespace">{$line}</span><br />
+          {/foreach}
+        {/if}
+      </td>
+      <td class="link">
+        {if $filesearchlines[match].tree}
+          <a href="{$SCRIPT_NAME}?p={$project}&a=tree&h={$filesearchlines[match].hash}&hb={$hash}&f={$filesearchlines[match].file}">tree</a>
+        {else}
+          <a href="{$SCRIPT_NAME}?p={$project}&a=blob&h={$filesearchlines[match].hash}&hb={$hash}&f={$filesearchlines[match].file}">blob</a> | <a href="{$SCRIPT_NAME}?p={$project}&a=history&h={$hash}&f={$filesearchlines[match].file}">history</a>
+        {/if}
+      </td>
+    </tr>
+  {/section}
+
+  {if $filesearchcount > 100}
+    <tr>
+      <td><a href="{$SCRIPT_NAME}?p={$project}&a=search&h={$hash}&s={$search}&st={$searchtype}&pg={$page+1}" title="Alt-n">next</a></td>
+    </tr>
+  {/if}
+</table>
+

comments