File:  [mozdev] / seb / www / functions.php
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Mon Aug 4 16:06:19 2003 UTC (16 years, 6 months ago) by tsn
Branches: MAIN
CVS tags: HEAD
The function only works with relative paths.
Lets try it that way then,

Sorry for the CVS spam. But this seems to be the only way of testing how it works

<?php

	if (isset ($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'source') {
		show_source(basename(__FILE__));
		exit;
	}

	CVSId('$Id: functions.php,v 1.5 2003/08/04 16:06:19 tsn Exp $');

	Function sizeUnit($fileSize) {
		if ($fileSize >= 1048576)
			$fileSize = (round($fileSize / 1048576 * 100) / 100).' MB'; 
		elseif ($fileSize >= 1024)
			$fileSize = (round($fileSize / 1024 * 100) / 100).' KB'; 
		else 
			$fileSize = $fileSize.' B'; 
		return $fileSize;
	}

	$defined_title = array(); // used in files templates

	Function tmpl_table($filename,$title,$dir) { // table (basic) template
		global $defined_title, $downloads, $normal, $type;
		$ret = '';

		if ($dir == $downloads) {
			$path = 'downloads.mozdev.org/seb/';
		} else {
			$path = 'seb.mozdev.org/'.$type.'/';
		}

		if (!isset ($defined_title['table_'.$title])) {
			$ret .= "            <tr>\n".
				'              <td colspan="3" style="text-decoration:underline;'.
				'text-align:center;font-style:italic;width:620px;">'.
				$title.
				"</td>\n".
				"            </tr>\n".
				"            <tr>\n".
				'              <td style="width:270px;font-weight:bold;">Filename'.
				"</td>\n".
				'              <td style="width:270px;font-weight:bold;">Date'.
				"</td>\n".
				'              <td style="width:80px;font-weight:bold;">Size'.
				"</td>\n".
				"            </tr>\n";
			$defined_title['table_'.$title] = $title;
		}

		$ret .= "            <tr>\n".'              <td><a href="'.
			'http://'.$path.substr($filename, 0, -2).'">'. //strip the ,v (again)
			substr($filename, 0, -2)."</a></td>\n".'              <td>'.
			date("Y/m/d - H:i:s", filemtime($dir.$filename))."</td>\n".
			'              <td>'.
			printCVSFileSize("../../downloads/". $filename)."</td>\n"."            </tr>\n";

		echo $ret;
	}

	Function tmpl_table_error() { // table (basic) error template
		$ret = "            <tr>\n".
			'              <td style="width:620px;">'.
			"Sorry, couldn't list files</td>\n".
			"            </tr>\n";

		echo $ret;
	}

	Function files($title, $type, $eval, $tmpl, $dir) { // list files from a given pattern
		global $file;
		$tmp = '';
		if (is_array($file)) {
			eval ("\$eval(\$file);");
			reset($file);
			$filecount = 0;
			while (list (,$filename) = each($file)) {
				if (preg_match($type, substr($filename, 0, -2))) { // strip the ",v"
					eval('tmpl_'.$tmpl."(\$filename,\$title,\$dir);");
					$filecount++;
				}
			}
			if ($filecount == 0) {
				eval("tmpl_".$tmpl."_error();");
			}
		} else {
			eval("tmpl_".$tmpl."_error();");
		}
	}

	Function listFiles($dir) { // generate the file array used in listings
		global $file;
		if ($dir = @opendir($dir)) {
			if (!isset ($file)) 
				$file = array();
			while ($file[] = @readdir($dir)) ;
			@closedir($dir);
		} else
			$file = FALSE;
	}

	Function CVSId($Id) { // Grabs the CVS Id from each PHP file.
		global $cvs;

		if (!isset ($cvs))
			$cvs = array();

		$tmp = explode(' ', substr($Id, 5, -6));
		$tmp[0] = substr($tmp[0], 0, -2);
		$cvs[] = $tmp;
	}

	Function getRevFromFile($file) { // gets the cvs version number of $file
		global $cvs;
		
		for ($i=0; $i < count($cvs); $i++) {
			if ($cvs[$i][0] == $file)
				return $cvs[$i][1];
		}
	}

	Function setMimeType($http='HTTP_ACCEPT',$type='application/xhtml+xml',
		$default='text/html') { // some browsers support xhtml mime type. Use it!

		if (isset ($_SERVER[$http])) {
			if (stristr($_SERVER[$http], $type))
				header('Content-type: '.$type);
			else
				header('Content-type: '.$default);
		}
	}

?>

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