File:  [mozdev] / seb / www / functions.php
Revision 1.23: download - view: text, annotated - select for diffs - revision graph
Thu Aug 7 23:49:58 2003 UTC (16 years, 9 months ago) by seb
Branches: MAIN
CVS tags: HEAD
improve it bit by bit

    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.23 2003/08/07 23:49:58 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: 	$defined_title = array(); // used in files templates
   22: 
   23: 	Function tmpl_table($filename,$title,$dir) { // table (basic) template
   24: 		global $defined_title, $downloads, $normal, $type;
   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: 			echo "            <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: 		echo "            <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:             printCVSFileSize("downloads/". substr($filename, 0, -2));
   57:         } else {
   58:             echo sizeUnit(@filesize($dir.$filename));
   59:         }
   60:                                                 
   61:         echo "</td>\n            </tr>\n";
   62: 
   63: 	}
   64: 
   65: 	Function tmpl_table_error() { // table (basic) error template
   66: 		$ret = "            <tr>\n".
   67: 			'              <td colspan="3" 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>