commit 6b5e7a3c7cc56a5428cd900bb526d37b2c0f5d47 Author: Tim Schumacher Date: Thu Sep 15 12:54:40 2011 +0200 Initial commit diff --git a/README b/README new file mode 100644 index 0000000..7d7f9cd --- /dev/null +++ b/README @@ -0,0 +1,27 @@ +whoisinyourhackspace Plugin for DokuWiki + +Displays if someone is in your hackspace + +All documentation for this plugin can be found at +http://hackspace-jena.de/ + +If you install this plugin manually, make sure it is installed in +lib/plugins/whoisinyourhackspace/ - if the folder is called different it +will not work! + +Please refer to http://www.dokuwiki.org/plugins for additional info +on how to install plugins in DokuWiki. + +---- +Copyright (C) Tim Schumacher + +This program 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; version 2 of the License + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See the COPYING file in your DokuWiki folder for details diff --git a/conf/default.php b/conf/default.php new file mode 100644 index 0000000..70be168 --- /dev/null +++ b/conf/default.php @@ -0,0 +1,8 @@ + + */ + +$conf['leasefile'] = '/tmp/leasefile'; diff --git a/conf/metadata.php b/conf/metadata.php new file mode 100644 index 0000000..5ded4ff --- /dev/null +++ b/conf/metadata.php @@ -0,0 +1,10 @@ + + */ + + +$meta['leasefile'] = array('the place where the leasefile resides'); + diff --git a/lang/en/lang.php b/lang/en/lang.php new file mode 100644 index 0000000..7852d97 --- /dev/null +++ b/lang/en/lang.php @@ -0,0 +1,16 @@ + + */ + +// menu entry for admin plugins +// $lang['menu'] = 'Your menu entry'; + +// custom language strings for the plugin +// $lang['fixme'] = 'FIXME'; + + + +//Setup VIM: ex: et ts=4 : diff --git a/lang/en/settings.php b/lang/en/settings.php new file mode 100644 index 0000000..ba28e57 --- /dev/null +++ b/lang/en/settings.php @@ -0,0 +1,13 @@ + + */ + +// keys need to match the config setting name +// $lang['fixme'] = 'FIXME'; + + + +//Setup VIM: ex: et ts=4 : diff --git a/plugin.info.txt b/plugin.info.txt new file mode 100644 index 0000000..a161516 --- /dev/null +++ b/plugin.info.txt @@ -0,0 +1,7 @@ +base whoisinyourhackspace +author Tim Schumacher +email tim.daniel.schumacher@gmail.com +date 2011-09-09 +name whoisinyourhackspace plugin +desc Displays if someone is in your hackspace +url http://hackspace-jena.de/ diff --git a/style.css b/style.css new file mode 100644 index 0000000..991a80d --- /dev/null +++ b/style.css @@ -0,0 +1,18 @@ +.ample { + display: block; + width: 200px; + height: 100px; + font-size: 24px; + font-weight: bold; + padding: 5px; +} + +.available { + background-color: green; + color: white; +} + +.not-available { + background-color: red; + color: white; +} \ No newline at end of file diff --git a/syntax.php b/syntax.php new file mode 100644 index 0000000..5f7b65b --- /dev/null +++ b/syntax.php @@ -0,0 +1,88 @@ + + */ + +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); + +if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); +if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); +if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); + +require_once DOKU_PLUGIN.'syntax.php'; + +class syntax_plugin_whoisinyourhackspace extends DokuWiki_Syntax_Plugin { + /** + * Check if a given option has been given, and remove it from the initial string + * @param string $match The string match by the plugin + * @param string $pattern The pattern which activate the option + * @param $varAffected The variable which will memorise the option + * @param $valIfFound the value affected to the previous variable if the option is found + */ + private function _checkOption(&$match, $pattern, &$varAffected, $valIfFound){ + if ( preg_match($pattern, $match, $found) ){ + $varAffected = $valIfFound; + $match = str_replace($found[0], '', $match); + } + } // _checkOption + + public function getType() { + return 'substition'; + } + + public function getPType() { + return 'block'; + } + + public function getSort() { + return 0; + } + + + public function connectTo($mode) { + $this->Lexer->addSpecialPattern(']*>',$mode,'plugin_whoisinyourhackspace'); + } + + public function handle($match, $state, $pos, &$handler){ + $return = array( + 'ample' => true + ); + + $this->_checkOption($match, "/-ample/i", $return['ample'], true); + return $return; + } + + public function render($mode, &$renderer, $data) { + global $conf; + + if($mode != 'xhtml') return false; + $leasefile_path = $this->getConf('leasefile'); + if (file_exists($leasefile_path)) { + $leasefile = file_get_contents($leasefile_path); + $count = preg_match_all('/(([0-9a-f]*):([0-9a-f]*):([0-9a-f]*):([0-9a-f]*):([0-9a-f]*):([0-9a-f]*))/i',$leasefile,$matches); + $class = ''; + if ($count > 0) { + $class = ""; + } else { + $class = "not-available"; + } + if ($count > 1) { + $renderer->doc .= sprintf('

Es sind %s Personen im Hackspace :)

', $count); + } else if ($count == 1) { + $renderer->doc .= sprintf('

Es ist %s Person im Hackspace :)

', $count); + } else { + $renderer->doc .= sprintf('

Es sind keine Personen im Hackspace :(

',$class, $count); + } + + } else { + $renderer->doc .= '

No leasefile found

'; + } + return true; + } +} + +// vim:ts=4:sw=4:et: