File:  [mozdev] / seb / www / functions.php
Revision 1.15: download - view: text, annotated - select for diffs - revision graph
Thu Aug 7 21:47:32 2003 UTC (16 years, 9 months ago) by seb
Branches: MAIN
CVS tags: HEAD
oops

    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.15 2003/08/07 21:47:32 seb 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: 	Function getCVSFileSize($aFileName) {
   21: 		global $project;
   22: 		$f_current = LXR_PATH.$project.'/'.$aFileName;
   23: 
   24: 		$rv = 0;
   25: 		if (@file_exists($f_current))
   26: 			$rv = @filesize($f_current);
   27: 
   28: 		return $rv;
   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: 			echo "            <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: 		echo "            <tr>\n".'              <td><a href="'.
   62: 			'http://'.$path.substr($filename, 0, -2).'">'. //strip the ,v (again)
   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:         if ( $dir == $downloads ) {
   67:             echo sizeUnit(getCVSFileSize('downloads/'.substr($filename, 0, -2)));
   68:         } else {
   69:             echo sizeUnit(@filesize($dir.$filename));
   70:         }
   71:         echo "</td>\n"."            </tr>\n";
   72: 
   73: 		echo $ret;
   74: 	}
   75: 
   76: 	Function tmpl_table_error() { // table (basic) error template
   77: 		$ret = "            <tr>\n".
   78: 			'              <td colspan="3" style="width:620px;">'.
   79: 			"Sorry, couldn't list files</td>\n".
   80: 			"            </tr>\n";
   81: 
   82: 		echo $ret;
   83: 	}
   84: 
   85: 	Function files($title, $type, $eval, $tmpl, $dir) { // list files from a given pattern
   86: 		global $file;
   87: 		$tmp = '';
   88: 		if (is_array($file)) {
   89: 			eval ("\$eval(\$file);");
   90: 			reset($file);
   91: 			$filecount = 0;
   92: 			while (list (,$filename) = each($file)) {
   93: 				if (preg_match($type, substr($filename, 0, -2))) { // strip the ",v"
   94: 					eval('tmpl_'.$tmpl."(\$filename,\$title,\$dir);");
   95: 					$filecount++;
   96: 				}
   97: 			}
   98: 			if ($filecount == 0) {
   99: 				eval("tmpl_".$tmpl."_error();");
  100: 			}
  101: 		} else {
  102: 			eval("tmpl_".$tmpl."_error();");
  103: 		}
  104: 	}
  105: 
  106: 	Function listFiles($dir) { // generate the file array used in listings
  107: 		global $file;
  108: 		if ($dir = @opendir($dir)) {
  109: 			if (!isset ($file)) 
  110: 				$file = array();
  111: 			while ($file[] = @readdir($dir)) ;
  112: 			@closedir($dir);
  113: 		} else
  114: 			$file = FALSE;
  115: 	}
  116: 
  117: 	Function CVSId($Id) { // Grabs the CVS Id from each PHP file.
  118: 		global $cvs;
  119: 
  120: 		if (!isset ($cvs))
  121: 			$cvs = array();
  122: 
  123: 		$tmp = explode(' ', substr($Id, 5, -6));
  124: 		$tmp[0] = substr($tmp[0], 0, -2);
  125: 		$cvs[] = $tmp;
  126: 	}
  127: 
  128: 	Function getRevFromFile($file) { // gets the cvs version number of $file
  129: 		global $cvs;
  130: 		
  131: 		for ($i=0; $i < count($cvs); $i++) {
  132: 			if ($cvs[$i][0] == $file)
  133: 				return $cvs[$i][1];
  134: 		}
  135: 	}
  136: 
  137: 	Function setMimeType($http='HTTP_ACCEPT',$type='application/xhtml+xml',
  138: 		$default='text/html') { // some browsers support xhtml mime type. Use it!
  139: 
  140: 		if (isset ($_SERVER[$http])) {
  141: 			if (stristr($_SERVER[$http], $type))
  142: 				header('Content-type: '.$type);
  143: 			else
  144: 				header('Content-type: '.$default);
  145: 		}
  146: 	}
  147: 
  148: ?>

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