summaryrefslogtreecommitdiff
path: root/templates/themes/rrdtool/info.php
blob: 4655d5bf5da00131cb88a3f7c8ee17cc1770aa3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
	$theme = Array();
	
	// Theme name
	$theme['name'] = 'RRDtool';
	// Description (you can use Tinyboard markup here)
	$theme['description'] = 'Graph basic statistics using the PHP RRDtool extension.';
	$theme['version'] = 'v0.1';
	
	// Theme configuration	
	$theme['config'] = Array();
	
	$theme['config'][] = Array(
		'title' => 'Path',
		'name' => 'path',
		'type' => 'text',
		'default' => str_replace('\\', '/', dirname(__FILE__)) . '/data',
		'size' => '50'
	);
	
	$theme['config'][] = Array(
		'title' => 'Images path',
		'name' => 'images',
		'type' => 'text',
		'default' => str_replace('\\', '/', dirname(__FILE__)) . '/images',
		'size' => '50'
	);
	
	$__boards = listBoards();
	$__default_boards = Array();
	foreach($__boards as $__board)
		$__default_boards[] = $__board['uri'];
	
	$theme['config'][] = Array(
		'title' => 'Boards',
		'name' => 'boards',
		'type' => 'text',
		'comment' => '(boards to graph; space seperated)',
		'size' => 24,
		'default' => implode(' ', $__default_boards)
	);
	
	$theme['install_callback'] = 'rrdtool_install';
	if(!function_exists('rrdtool_install')) {
		function rrdtool_install($settings) {
			global $config;
			
			$job = '*/2 * * * * php -q ' . str_replace('\\', '/', dirname(__FILE__)) . '/cron.php' . PHP_EOL;
			
			if(function_exists('system')) {
				$crontab = tempnam($config['tmp'], 'tinyboard-rrdtool');
				file_write($crontab, $job);
				@system('crontab ' . escapeshellarg($crontab), $ret);
				unlink($crontab);
				
				if($ret === 0)
					return ''; // it seems to install okay?
			}
			
			return '<h2>I couldn\'t install the crontab!</h2>' . 
				'In order to use this plugin, you must add the following crontab entry:' . 
				'<pre>' . $job . '</pre>';
		}
	}
	
	// Unique function name for building everything
	$theme['build_function'] = 'rrdtool_build';
?>