File:  [mozdev] / seb / www / functions.php
Revision 1.36: download - view: text, annotated - select for diffs - revision graph
Fri Aug 8 11:40:44 2003 UTC (16 years, 7 months ago) by seb
Branches: MAIN
CVS tags: HEAD
should work fine now

    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.36 2003/08/08 11:40:44 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: 		} else {
   40: 			$path = 'seb.mozdev.org/'.$type.'/';
   41: 		}
   42: 
   43: 		if (!isset ($defined_title['table_'.$title])) {
   44: 			$ret .= "            <tr>\n".
   45: 				'              <td colspan="3" style="text-decoration:underline;'.
   46: 				'text-align:center;font-style:italic;width:620px;">'.
   47: 				$title.
   48: 				"</td>\n".
   49: 				"            </tr>\n".
   50: 				"            <tr>\n".
   51: 				'              <td style="width:270px;font-weight:bold;">Filename'.
   52: 				"</td>\n".
   53: 				'              <td style="width:270px;font-weight:bold;">Date'.
   54: 				"</td>\n".
   55: 				'              <td style="width:80px;font-weight:bold;">Size'.
   56: 				"</td>\n".
   57: 				"            </tr>\n";
   58: 			$defined_title['table_'.$title] = $title;
   59: 		}
   60: 
   61: 		$ret .= "            <tr>\n".'              <td><a href="'.
   62: 			'http://'.$path.substr($filename, 0, -2).'">'. //strip the ,v
   63: 			substr($filename, 0, -2)."</a></td>\n".'              <td>'.
   64: 			date("Y/m/d - H:i:s", filemtime($dir.$filename))."</td>\n".
   65: 			'              <td>'.
   66: 			sizeUnit(getFileSize(str_replace('/cvs/seb/', '', $dir).
   67: 			substr($filename, 0, -2)))."</td>\n            </tr>\n";
   68: 
   69: 		echo $ret;
   70: 	}
   71: 
   72: 	Function tmpl_table_error() { // table (basic) error template
   73: 		$ret = "            <tr>\n".
   74: 			'              <td colspan="3" style="width:620px;">'.
   75: 			"Sorry, couldn't list files</td>\n".
   76: 			"            </tr>\n";
   77: 
   78: 		echo $ret;
   79: 	}
   80: 
   81: 	Function files($title, $type, $eval, $tmpl, $dir) { // list files from a given pattern
   82: 		global $file;
   83: 		$tmp = '';
   84: 		if (is_array($file)) {
   85: 			eval ("\$eval(\$file);");
   86: 			reset($file);
   87: 			$filecount = 0;
   88: 			while (list (,$filename) = each($file)) {
   89: 				if (preg_match($type, substr($filename, 0, -2))) { // strip the ",v"
   90: 					eval('tmpl_'.$tmpl."(\$filename,\$title,\$dir);");
   91: 					$filecount++;
   92: 				}
   93: 			}
   94: 			if ($filecount == 0) {
   95: 				eval("tmpl_".$tmpl."_error();");
   96: 			}
   97: 		} else {
   98: 			eval("tmpl_".$tmpl."_error();");
   99: 		}
  100: 	}
  101: 
  102: 	Function listFiles($dir) { // generate the file array used in listings
  103: 		global $file;
  104: 		if ($dir = @opendir($dir)) {
  105: 			if (!isset ($file)) 
  106: 				$file = array();
  107: 			while ($file[] = @readdir($dir)) ;
  108: 			@closedir($dir);
  109: 		} else
  110: 			$file = FALSE;
  111: 	}
  112: 
  113: 	Function CVSId($Id) { // Grabs the CVS Id from each PHP file.
  114: 		global $cvs;
  115: 
  116: 		if (!isset ($cvs))
  117: 			$cvs = array();
  118: 
  119: 		$tmp = explode(' ', substr($Id, 5, -6));
  120: 		$tmp[0] = substr($tmp[0], 0, -2);
  121: 		$cvs[] = $tmp;
  122: 	}
  123: 
  124: 	Function getRevFromFile($file) { // gets the cvs version number of $file
  125: 		global $cvs;
  126: 		
  127: 		for ($i=0; $i < count($cvs); $i++) {
  128: 			if ($cvs[$i][0] == $file)
  129: 				return $cvs[$i][1];
  130: 		}
  131: 	}
  132: 
  133: 	Function setMimeType($http='HTTP_ACCEPT',$type='application/xhtml+xml',
  134: 		$default='text/html') { // some browsers support xhtml mime type. Use it!
  135: 
  136: 		if (isset ($_SERVER[$http])) {
  137: 			if (stristr($_SERVER[$http], $type))
  138: 				header('Content-type: '.$type);
  139: 			else
  140: 				header('Content-type: '.$default);
  141: 		}
  142: 	}
  143: 
  144: ?>

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