File:  [mozdev] / seb / www / functions.php
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Mon Aug 4 16:11:05 2003 UTC (16 years, 10 months ago) by tsn
Branches: MAIN
CVS tags: HEAD
relative to project's repos dir

    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.6 2003/08/04 16:11:05 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:         if ( $dir == $downloads ) {
   56: 			$ret .= printCVSFileSize("downloads/". $filename);
   57:         } else {
   58:             $ret .= sizeUnit(@filesize($dir.$filename));
   59:         }
   60:         $res .= "</td>\n"."            </tr>\n";
   61: 
   62: 		echo $ret;
   63: 	}
   64: 
   65: 	Function tmpl_table_error() { // table (basic) error template
   66: 		$ret = "            <tr>\n".
   67: 			'              <td style="width:620px;">'.
   68: 			"Sorry, couldn't list files</td>\n".
   69: 			"            </tr>\n";
   70: 
   71: 		echo $ret;
   72: 	}
   73: 
   74: 	Function files($title, $type, $eval, $tmpl, $dir) { // list files from a given pattern
   75: 		global $file;
   76: 		$tmp = '';
   77: 		if (is_array($file)) {
   78: 			eval ("\$eval(\$file);");
   79: 			reset($file);
   80: 			$filecount = 0;
   81: 			while (list (,$filename) = each($file)) {
   82: 				if (preg_match($type, substr($filename, 0, -2))) { // strip the ",v"
   83: 					eval('tmpl_'.$tmpl."(\$filename,\$title,\$dir);");
   84: 					$filecount++;
   85: 				}
   86: 			}
   87: 			if ($filecount == 0) {
   88: 				eval("tmpl_".$tmpl."_error();");
   89: 			}
   90: 		} else {
   91: 			eval("tmpl_".$tmpl."_error();");
   92: 		}
   93: 	}
   94: 
   95: 	Function listFiles($dir) { // generate the file array used in listings
   96: 		global $file;
   97: 		if ($dir = @opendir($dir)) {
   98: 			if (!isset ($file)) 
   99: 				$file = array();
  100: 			while ($file[] = @readdir($dir)) ;
  101: 			@closedir($dir);
  102: 		} else
  103: 			$file = FALSE;
  104: 	}
  105: 
  106: 	Function CVSId($Id) { // Grabs the CVS Id from each PHP file.
  107: 		global $cvs;
  108: 
  109: 		if (!isset ($cvs))
  110: 			$cvs = array();
  111: 
  112: 		$tmp = explode(' ', substr($Id, 5, -6));
  113: 		$tmp[0] = substr($tmp[0], 0, -2);
  114: 		$cvs[] = $tmp;
  115: 	}
  116: 
  117: 	Function getRevFromFile($file) { // gets the cvs version number of $file
  118: 		global $cvs;
  119: 		
  120: 		for ($i=0; $i < count($cvs); $i++) {
  121: 			if ($cvs[$i][0] == $file)
  122: 				return $cvs[$i][1];
  123: 		}
  124: 	}
  125: 
  126: 	Function setMimeType($http='HTTP_ACCEPT',$type='application/xhtml+xml',
  127: 		$default='text/html') { // some browsers support xhtml mime type. Use it!
  128: 
  129: 		if (isset ($_SERVER[$http])) {
  130: 			if (stristr($_SERVER[$http], $type))
  131: 				header('Content-type: '.$type);
  132: 			else
  133: 				header('Content-type: '.$default);
  134: 		}
  135: 	}
  136: 
  137: ?>

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