|
|
|
@ -16,19 +16,6 @@ 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';
|
|
|
|
@ -42,46 +29,71 @@ class syntax_plugin_whoisinyourhackspace extends DokuWiki_Syntax_Plugin {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function connectTo($mode) {
|
|
|
|
|
$this->Lexer->addSpecialPattern('\[wiyh\]',$mode,'plugin_whoisinyourhackspace');
|
|
|
|
|
$this->Lexer->addSpecialPattern("(?:\[wiyh '.*?'\]|\[wiyh\])", $mode,'plugin_whoisinyourhackspace');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render($mode, &$renderer, $data) {
|
|
|
|
|
global $conf;
|
|
|
|
|
public function handle($match, $state, $pos, Doku_Handler $handler)
|
|
|
|
|
{
|
|
|
|
|
if (DOKU_LEXER_SPECIAL !== $state) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($mode != 'xhtml') return false;
|
|
|
|
|
$matches = [];
|
|
|
|
|
|
|
|
|
|
$api_path = $this->getConf('api_path');
|
|
|
|
|
if (false !== preg_match("/wiyh '(.*?)'/", $match, $matches)) {
|
|
|
|
|
return [$state, $match, $matches[1] ?? null];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file = file_get_contents($api_path);
|
|
|
|
|
return [$state, $match];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$api = json_decode($file);
|
|
|
|
|
public function render($format, Doku_Renderer $renderer, $data) {
|
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
|
|
$content = '';
|
|
|
|
|
$content .= '<div class="leinelab-state">';
|
|
|
|
|
$content .= "<h3>" . $this->getLang('wiyh_heading') . "</h3>";
|
|
|
|
|
[$state, $match, $url] = $data;
|
|
|
|
|
|
|
|
|
|
if ($api->state->open) {
|
|
|
|
|
$content .= "<img class=\"icon\" src=\"{$api->state->icon->open}\" alt=\"{$api->space} ist besetzt.\" title=\"{$api->space} ist besetzt.\" />";
|
|
|
|
|
$content .= "<p class=\"text\">{$api->space} " . $this->getLang('wiyh_open') . "</p>";
|
|
|
|
|
} else {
|
|
|
|
|
$content .= "<img class=\"icon\" src=\"{$api->state->icon->closed}\" alt=\"{$api->space} ist geschlossen.\" title=\"{$api->space} ist geschlossen.\" />";
|
|
|
|
|
$content .= "<p class=\"text\">{$api->space} " . $this->getLang('wiyh_closed') . "</p>";
|
|
|
|
|
}
|
|
|
|
|
if($format != 'xhtml') return false;
|
|
|
|
|
|
|
|
|
|
$date = new DateTime();
|
|
|
|
|
$date->setTimeStamp($api->lastchange);
|
|
|
|
|
$content .= "<p class=\"text\"> seit " . $date->format('d.m.Y H:i') . " Uhr</p>";
|
|
|
|
|
$api_path = $url ?: $this->getConf('api_path');
|
|
|
|
|
|
|
|
|
|
$content .= '<hr />';
|
|
|
|
|
if (empty ($api_path)) {
|
|
|
|
|
$renderer->doc .= "<div>{$this->getLang('wiyh_no_api_path')}</div>";
|
|
|
|
|
|
|
|
|
|
$content .= sprintf('<p><a href="http://spaceapi-stats.n39.eu/#%s">'.$this->getLang('wiyh_stats').'</a></p>',strtolower($api->space));
|
|
|
|
|
$content .= '</div>';
|
|
|
|
|
|
|
|
|
|
$renderer->doc .= $content;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (false === $file = file_get_contents($api_path)) {
|
|
|
|
|
$renderer->doc .= "<div>{$this->getLang('wiyh_fetch_error')}</div>";
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$api = json_decode($file);
|
|
|
|
|
|
|
|
|
|
$content = '';
|
|
|
|
|
$content .= '<div class="hackerspace-room-state">';
|
|
|
|
|
$content .= "<h3>" . $this->getLang('wiyh_heading') . "</h3>";
|
|
|
|
|
|
|
|
|
|
if ($api->state->open) {
|
|
|
|
|
$content .= $api->state->icon->open ? "<img class=\"icon\" src=\"{$api->state->icon->open}\" alt=\"{$api->space} ist besetzt.\" title=\"{$api->space} ist besetzt.\" />" : '';
|
|
|
|
|
$content .= "<p class=\"text\">{$api->space} " . $this->getLang('wiyh_open') . "</p>";
|
|
|
|
|
} else {
|
|
|
|
|
$content .= $api->state->icon->open ? "<img class=\"icon\" src=\"{$api->state->icon->closed}\" alt=\"{$api->space} ist geschlossen.\" title=\"{$api->space} ist geschlossen.\" />" : '';
|
|
|
|
|
$content .= "<p class=\"text\">{$api->space} " . $this->getLang('wiyh_closed') . "</p>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$date = new DateTime();
|
|
|
|
|
$date->setTimeStamp($api->state->lastchange);
|
|
|
|
|
$content .= "<p class=\"text\"> seit " . $date->format('d.m.Y H:i') . " Uhr</p>";
|
|
|
|
|
|
|
|
|
|
$content .= '<hr />';
|
|
|
|
|
$content .= '</div>';
|
|
|
|
|
|
|
|
|
|
$renderer->doc .= $content;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// vim:ts=4:sw=4:et:
|
|
|
|
|