<?php if (!defined('PmWiki')) exit();

$RecipeInfo['ProgressBar']['Version'] = '20191121';

/*
	Progress Bar for PmWiki	
	Copyright 2006 Mateusz Czaplinski (mateusz@czaplinski.pl)

	This file is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published
	by the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	---- Usage Information: ----

	* Put this file in 'cookbook/' directory of your PmWiki installation
	* In your 'local/config.php' file add the following line:

		include_once("$FarmD/cookbook/progressbar.php");

	* This enables additional markup in your wiki - example usage:

		(:progress 30:)
		- creates a progress bar filled in 30%

		(:progress 3/4:)
		- creates a progress bar filled in 3 quarters (75%)


	---- Comments and More Information: ----

		http://pmwiki.org/wiki/Cookbook/ProgressBar

	---- History: ----

	* 2006-12-06 - v1.0 - initial release
        * 20191121 updated for PHP 5.5 - 7.2 by Petko Yotov pmwiki.org/petko
*/

## Styles based on:
## http://www.davidanaxagoras.com/2005/04/16/track-your-progress-or-lack-thereof/
## http://cssplay.co.uk/boxes/krazy.html (A must-see CSS site!)

## Possible usage (all examples equal 30%):
## (:progress 30:)
## (:progress 3/10:)
## Not yet implemented:
## (:progress 30%:)
## (:progress +3 -7:)

Markup( 'progress', 'directives',
	"/\\(:progress(.*?):\\)/",
	"ProgressBar"
	);

function ProgressBar($m) {
	$args = ParseArgs($m[1]);
	$perc = $args[''];
	$perc = $perc[0];

	if( ($pos = strpos($perc,'/')) !== false )
		$perc = (int)( 100.0 * substr($perc,0,$pos) / substr($perc,$pos+1) );

	return Keep(
"<b class='progress-bar'>
<b class='pb1'></b><b class='pb2'></b><b class='pb3'></b>
<b class='pb4'><b class='pb5'>
<b class='bar' style='width:{$perc}%'></b>
</b></b>
<b class='pb3'></b><b class='pb2'></b><b class='pb1'></b>
</b>" );
}

$HTMLStylesFmt[] = '
.progress-bar {
	display: block;
	background: transparent; 
	width: 205px;
	font-size: 1px; /* for IE */
	margin: 2px 0;
}

.progress-bar .pb1, .progress-bar .pb2, .progress-bar .pb3, .progress-bar .pb4 {
	display: block; 
	background: #fff; 
	border-left:  1px solid #999; 
	border-right: 1px solid #999;

	overflow: hidden; 
	height: 1px; 
}
.progress-bar .pb1 { margin: 0 4px; background: #999;}
.progress-bar .pb2 { margin: 0 2px; border-width: 0 2px; }
.progress-bar .pb3 { margin: 0 1px; }
.progress-bar .pb4 { height: 11px; padding: 0 3px; }
.progress-bar .pb5 { display: block; background: #eeeeef; overflow:hidden; }

.progress-bar .bar {
	display: block;
	background: #a5bbd8;
	height: 11px;
	padding: 0;
}
';