File:  [mozdev] / seb / www / functions.php
Revision 1.35: download - view: text, annotated - select for diffs - revision graph
Fri Aug 8 11:38:26 2003 UTC (16 years, 8 months ago) by seb
Branches: MAIN
CVS tags: HEAD
trying something better

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

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