File:  [mozdev] / seb / www / functions.php
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Mon Aug 4 15:56:22 2003 UTC (16 years, 8 months ago) by tsn
Branches: MAIN
CVS tags: HEAD
Attemping to use printCVSFileSize(), recommeded by pete@mozdev.org

    1: <?php
    2: 
    3: 	if (isset ($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'source') {
    4: 		show_source(basename(__FILE__));
    5: 		exit;
    6: 	}
    7: 
    8: 	CVSId('$Id: functions.php,v 1.4 2003/08/04 15:56:22 tsn Exp $');
    9: 
   10: 	Function sizeUnit($fileSize) {
   11: 		if ($fileSize >= 1048576)
   12: 			$fileSize = (round($fileSize / 1048576 * 100) / 100).' MB'; 
   13: 		elseif ($fileSize >= 1024)
   14: 			$fileSize = (round($fileSize / 1024 * 100) / 100).' KB'; 
   15: 		else 
   16: 			$fileSize = $fileSize.' B'; 
   17: 		return $fileSize;
   18: 	}
   19: 
   20: 	$defined_title = array(); // used in files templates
   21: 
   22: 	Function tmpl_table($filename,$title,$dir) { // table (basic) template
   23: 		global $defined_title, $downloads, $normal, $type;
   24: 		$ret = '';
   25: 
   26: 		if ($dir == $downloads) {
   27: 			$path = 'downloads.mozdev.org/seb/';
   28: 		} else {
   29: 			$path = 'seb.mozdev.org/'.$type.'/';
   30: 		}
   31: 
   32: 		if (!isset ($defined_title['table_'.$title])) {
   33: 			$ret .= "            <tr>\n".
   34: 				'              <td colspan="3" style="text-decoration:underline;'.
   35: 				'text-align:center;font-style:italic;width:620px;">'.
   36: 				$title.
   37: 				"</td>\n".
   38: 				"            </tr>\n".
   39: 				"            <tr>\n".
   40: 				'              <td style="width:270px;font-weight:bold;">Filename'.
   41: 				"</td>\n".
   42: 				'              <td style="width:270px;font-weight:bold;">Date'.
   43: 				"</td>\n".
   44: 				'              <td style="width:80px;font-weight:bold;">Size'.
   45: 				"</td>\n".
   46: 				"            </tr>\n";
   47: 			$defined_title['table_'.$title] = $title;
   48: 		}
   49: 
   50: 		$ret .= "            <tr>\n".'              <td><a href="'.
   51: 			'http://'.$path.substr($filename, 0, -2).'">'. //strip the ,v (again)
   52: 			substr($filename, 0, -2)."</a></td>\n".'              <td>'.
   53: 			date("Y/m/d - H:i:s", filemtime($dir.$filename))."</td>\n".
   54: 			'              <td>'.
   55: 			printCVSFileSize($dir.$filename)."</td>\n"."            </tr>\n";
   56: 
   57: 		echo $ret;
   58: 	}
   59: 
   60: 	Function tmpl_table_error() { // table (basic) error template
   61: 		$ret = "            <tr>\n".
   62: 			'              <td style="width:620px;">'.
   63: 			"Sorry, couldn't list files</td>\n".
   64: 			"            </tr>\n";
   65: 
   66: 		echo $ret;
   67: 	}
   68: 
   69: 	Function files($title, $type, $eval, $tmpl, $dir) { // list files from a given pattern
   70: 		global $file;
   71: 		$tmp = '';
   72: 		if (is_array($file)) {
   73: 			eval ("\$eval(\$file);");
   74: 			reset($file);
   75: 			$filecount = 0;
   76: 			while (list (,$filename) = each($file)) {
   77: 				if (preg_match($type, substr($filename, 0, -2))) { // strip the ",v"
   78: 					eval('tmpl_'.$tmpl."(\$filename,\$title,\$dir);");
   79: 					$filecount++;
   80: 				}
   81: 			}
   82: 			if ($filecount == 0) {
   83: 				eval("tmpl_".$tmpl."_error();");
   84: 			}
   85: 		} else {
   86: 			eval("tmpl_".$tmpl."_error();");
   87: 		}
   88: 	}
   89: 
   90: 	Function listFiles($dir) { // generate the file array used in listings
   91: 		global $file;
   92: 		if ($dir = @opendir($dir)) {
   93: 			if (!isset ($file)) 
   94: 				$file = array();
   95: 			while ($file[] = @readdir($dir)) ;
   96: 			@closedir($dir);
   97: 		} else
   98: 			$file = FALSE;
   99: 	}
  100: 
  101: 	Function CVSId($Id) { // Grabs the CVS Id from each PHP file.
  102: 		global $cvs;
  103: 
  104: 		if (!isset ($cvs))
  105: 			$cvs = array();
  106: 
  107: 		$tmp = explode(' ', substr($Id, 5, -6));
  108: 		$tmp[0] = substr($tmp[0], 0, -2);
  109: 		$cvs[] = $tmp;
  110: 	}
  111: 
  112: 	Function getRevFromFile($file) { // gets the cvs version number of $file
  113: 		global $cvs;
  114: 		
  115: 		for ($i=0; $i < count($cvs); $i++) {
  116: 			if ($cvs[$i][0] == $file)
  117: 				return $cvs[$i][1];
  118: 		}
  119: 	}
  120: 
  121: 	Function setMimeType($http='HTTP_ACCEPT',$type='application/xhtml+xml',
  122: 		$default='text/html') { // some browsers support xhtml mime type. Use it!
  123: 
  124: 		if (isset ($_SERVER[$http])) {
  125: 			if (stristr($_SERVER[$http], $type))
  126: 				header('Content-type: '.$type);
  127: 			else
  128: 				header('Content-type: '.$default);
  129: 		}
  130: 	}
  131: 
  132: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>