Make trim length a constant
Make trim length a constant

--- /dev/null
+++ b/include/defs.constants.php
@@ -1,1 +1,13 @@
+<?php
+/*
+ *  defs.constants.php
+ *  gitphp: A PHP git repository browser
+ *  Component: Definitions - constants
+ *
+ *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
+ */
 
+define("GITPHP_TRIM_LENGTH", 50);
+
+?>
+

--- a/include/display.git_search.php
+++ b/include/display.git_search.php
@@ -7,6 +7,7 @@
  *  Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  */
 
+include_once('defs.constants.php');
 include_once('gitutil.git_read_commit.php');
 include_once('gitutil.git_rev_list.php');
 
@@ -91,11 +92,10 @@
 			$matches = array();
 			foreach ($co2['comment'] as $comline) {
 				if (eregi("(.*)(" . quotemeta($search) . ")(.*)",$comline,$regs)) {
-					$maxlen = 50;
 					$linelen = strlen($regs[0]);
-					if ($linelen > $maxlen) {
+					if ($linelen > GITPHP_TRIM_LENGTH) {
 						$matchlen = strlen($regs[2]);
-						$remain = floor(($maxlen - $matchlen) / 2);
+						$remain = floor((GITPHP_TRIM_LENGTH - $matchlen) / 2);
 						$leftlen = strlen($regs[1]);
 						$rightlen = strlen($regs[3]);
 						if ($leftlen > $remain) {

--- a/include/gitutil.git_project_descr.php
+++ b/include/gitutil.git_project_descr.php
@@ -7,11 +7,13 @@
  *  Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
  */
 
+include_once('defs.constants.php');
+
 function git_project_descr($projectroot,$project,$trim = FALSE)
 {
 	$desc = file_get_contents($projectroot . $project . "/description");
-	if ($trim && (strlen($desc) > 50))
-		$desc = substr($desc,0,50) . " ...";
+	if ($trim && (strlen($desc) > GITPHP_TRIM_LENGTH))
+		$desc = substr($desc,0, GITPHP_TRIM_LENGTH) . "...";
 	return $desc;
 }
 

--- a/include/gitutil.git_read_commit.php
+++ b/include/gitutil.git_read_commit.php
@@ -7,6 +7,7 @@
  *  Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
  */
 
+ include_once('defs.constants.php');
  include_once('util.age_string.php');
  include_once('gitutil.git_rev_list.php');
 
@@ -51,8 +52,8 @@
 			if ((strlen($trimmed) > 0) && !ereg("^[0-9a-fA-F]{40}",$trimmed) && !ereg("^parent [0-9a-fA-F]{40}",$trimmed)) {
 				if (!isset($commit['title'])) {
 					$commit['title'] = $trimmed;
-					if (strlen($trimmed) > 50)
-						$commit['title_short'] = substr($trimmed,0,50) . " ...";
+					if (strlen($trimmed) > GITPHP_TRIM_LENGTH)
+						$commit['title_short'] = substr($trimmed,0,GITPHP_TRIM_LENGTH) . "...";
 					else
 						$commit['title_short'] = $trimmed;
 				}

comments