Scripts

ToolBox v1.0.0

Hoe dikwijls kom je het niet tegen dat je een geweldige tool hebt maar die dan in de vergeethoek geraakt? Met dit script kan je uw tools ordenen en benaderen via één webpagina. Wat moet je doen? Ergens zet je een map /tool neer. In die map zet je dit script met de naam tool.php. Dan maak je voor elke tool een folder met daarin je tool en nog twee (of drie) extra dingen. Een about.ini bestand waar informatie over de tool in staat. Een form.php bestand dat html weergeeft en dient om je parameters op te vragen die je wilt meegeven aan je tool. En eventueel een aparte bestand dat de formulier gegevens daadwerkelijk koppelt aan je tool. Ik heb van elk er één toegevoegd als voorbeeld. Je mapstructuur is dus: tool/ tool/greattoolone/ tool/greattoolone/about.ini tool/greattoolone/form.php tool/greattoolone/api.php tool/greattoolone/class.greattoolone.php tool/nxtgreattool/ ... tool/tool.php voorbeeld about.ini: name = 'Scan for class definitions' version = '0.0.2' description = 'With this tool you get a list of all the class and interface definitions that are present in the given file or directory.' voorbeeld form.php:   Scan for class and interface definitions.   A scan will be done of the c:/xampp/htdocs directory and shown on screen.   Yes, do it  |  No, return to main tool menu. Have fun Marc

toolbox-v100
<?php
/* ******************************************************************
 * Main: API
 * ****************************************************************** */

// get a new instance
$page = new THF_Admin_Tool_ToolBox(); // See at the bottom.

// Read all the data from the tools
$page->readAllIniFiles();

// Echo the heading of the webpage.
echo $page->htmlHeading();

// Dit we select a valid tool or nothing at all?
$tool = $page->readUri();

// Switch for the content depending on the $tool variable
if( NULL === $tool )
{
	// startpage
	echo $page->htmlToolTable();
}
elseif( FALSE === $tool )
{
	// Impossible or bad people?
	echo '<br /><h3 style="color:red">Invalid tool request.</h3><br />';
	echo $page->htmlToolTable();
}
else
{
	// Show the form connected to the tool.
	$page->invokeTool($tool);
}

echo $page->htmlFooter();



/* ******************************************************************
 *
 * Class for easy handling this tool page.
 *
 * ****************************************************************** */

class THF_Admin_Tool_ToolBox
{
	// Holds all the info about every tool
	private $_about;

	public function __construct()
	{
		$this->_about = array();
	}

	public function readAllIniFiles()
	{
		$this->_about = array();
		$dir = new DirectoryIterator('./');
		foreach( $dir as $subdir )
		{
			if( $subdir->isDir() AND ! $subdir->isDot() )
			{
				$inipath = $subdir->getPathname() . DIRECTORY_SEPARATOR . 'about.ini';
				$content = parse_ini_file($inipath);
				$content = array($subdir->getBasename() => $content);
				$this->_about = array_merge($this->_about, $content);
			}
		}
	}

	public function htmlToolTable()
	{
		$html  = '<table border="1" cellpadding="5">';
		$html .= '<tr><th align="left">tool</th><th align="left">description</th></tr>';
		foreach( $this->_about as $tool => $data )
		{
			$html .= '<tr><td align="left"><a href="?tool='.$tool.'">'.$data['name'].'</a><br />'.$data['version'].'</td><td align="left" style="vertical-align:text-top">'.$data['description'].'</td></tr>';
		}
		$html .= '</table>';
		return $html;
	}

	public function invokeTool($tool)
	{
		$path = './'.$tool.'/form.php';
		include $path;
	}

	public function readUri()
	{
		if( ! isset($_REQUEST['tool']) )
				return NULL;

		$tool = $_REQUEST['tool'];
		if( ! array_key_exists($tool, $this->_about) )
				return FALSE;

		return $tool;
	}

	public function htmlHeading()
	{
		$out  = '<h1>Toolbox</h1>';
		$out .= '<a href="?">hoofdmenu toolbox</a>';
		$out .= '<hr /><br />';
		return $out;
	}

	public function htmlFooter()
	{
		$out  = '<br /><hr />';
		$out .= '<a href="?">hoofdmenu toolbox</a>';
		$out .= '&nbsp;&nbsp;&nbsp;&nbsp;<span>'.date('d M Y').'</span>';
		return $out;
	}

}
?>

Reacties

0
Nog geen reacties.