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

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

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