From a582bf5866c8dbb6d497c0f860475a6eeb73b096 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Tue, 7 Jun 2011 15:22:41 +1000 Subject: [PATCH] "rrdtool" theme for graphing basic stats in development --- templates/themes/rrdtool/cron.php | 12 ++++++ templates/themes/rrdtool/info.php | 37 ++++++++++++++++++ templates/themes/rrdtool/theme.php | 59 +++++++++++++++++++++++++++++ templates/themes/rrdtool/thumb.png | Bin 0 -> 2967 bytes 4 files changed, 108 insertions(+) create mode 100644 templates/themes/rrdtool/cron.php create mode 100644 templates/themes/rrdtool/info.php create mode 100644 templates/themes/rrdtool/theme.php create mode 100644 templates/themes/rrdtool/thumb.png diff --git a/templates/themes/rrdtool/cron.php b/templates/themes/rrdtool/cron.php new file mode 100644 index 00000000..4608e959 --- /dev/null +++ b/templates/themes/rrdtool/cron.php @@ -0,0 +1,12 @@ + '', 'HTTP_HOST' => '', 'SCRIPT_FILENAME' => ''); + chdir('/var/www'); + + require 'inc/functions.php'; + require 'inc/display.php'; + require 'inc/template.php'; + require 'inc/database.php'; + + require 'theme.php'; + rebuildTheme('rrdtool', 'cron'); +?> \ No newline at end of file diff --git a/templates/themes/rrdtool/info.php b/templates/themes/rrdtool/info.php new file mode 100644 index 00000000..fa1844e9 --- /dev/null +++ b/templates/themes/rrdtool/info.php @@ -0,0 +1,37 @@ + 'Path', + 'name' => 'path', + 'type' => 'text', + 'default' => str_replace('\\', '/', dirname(__FILE__)) . '/data', + '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) + ); + + // Unique function name for building everything + $theme['build_function'] = 'rrdtool_build'; +?> \ No newline at end of file diff --git a/templates/themes/rrdtool/theme.php b/templates/themes/rrdtool/theme.php new file mode 100644 index 00000000..0482c688 --- /dev/null +++ b/templates/themes/rrdtool/theme.php @@ -0,0 +1,59 @@ +build($action, $settings); + } + + // Wrap functions in a class so they don't interfere with normal Tinyboard operations + class TB_RRDTool { + public function build($action, $settings) { + global $config, $_theme; + + $this->boards = explode(' ', $settings['boards']); + $this->interval = 60; + + if($action == 'cron') { + if(!file_exists($settings['path'])) + mkdir($settings['path']); + + foreach($this->boards as &$board) { + $file = $settings['path'] . '/' . $board . '.rrd'; + + if(!file_exists($file)) { + // Create graph + if(!rrd_create($file, Array( + '-s ' . $this->interval, + 'DS:posts:ABSOLUTE:120:0:100000000', + 'RRA:AVERAGE:0.5:1:2880', + 'RRA:AVERAGE:0.5:30:672', + 'RRA:AVERAGE:0.5:120:732', + 'RRA:AVERAGE:0.5:720:1460'))) + error('RRDtool failed: ' . htmlentities(rrd_error())); + } + + if($action == 'cron') { + $query = prepare(sprintf("SELECT COUNT(*) AS `count` FROM `posts_%s` WHERE `time` >= :time", $board)); + $query->bindValue(':time', time() - $this->interval, PDO::PARAM_INT): + $query->exeucte() or error(db_error($query)); + $query->fetch(); + + if(!rrd_update($file, Array( + '-t', + 'posts', + 'N:'))) + error('RRDtool failed: ' . htmlentities(rrd_error())); + } + } + } + } + }; + +?> \ No newline at end of file diff --git a/templates/themes/rrdtool/thumb.png b/templates/themes/rrdtool/thumb.png new file mode 100644 index 0000000000000000000000000000000000000000..d4e48a0d5a85839db4edb425cddbe54c8e63e0e5 GIT binary patch literal 2967 zcmeAS@N?(olHy`uVBq!ia0y~yVA#vRz!1X0%)r3#!0DI=0|PTdfKQ04mX=oi{Qv*| z|37>7tdWtCqN1X>xcH78J3Ku-BO@b!{P^+q?c00z?oFRQ-NM2mIXRh~ojp4{d+pk_ z`}gm+b_@{|6pSrcb@b@bl9H0N+5_F)-9bS?O-)Tz(?4c6pN+|1HfPS9@QgV@iG6l% zG0T=MtEs7Ra&oGf{oUNgt90U1-{@w2Ba5Qm`*|H#eIo01boCv*lAk|+?iE&f_3G8c zvMsuLMj&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