Work on shared spaceapi module.
This commit is contained in:
parent
df1c590afc
commit
b89b4e3147
2 changed files with 5 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Now: Inserts a timestamp.
|
||||
* Plugin HackerBase: Inserts SpaceAPI-based open/closed info
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Dominik Pantůček <dominik.pantucek@trustica.cz>
|
||||
|
@ -9,6 +9,8 @@
|
|||
// must be run within DokuWiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
require_once("common.php"):
|
||||
|
||||
/**
|
||||
* All DokuWiki plugins to extend the parser/rendering mechanism
|
||||
* need to inherit from this class
|
||||
|
@ -30,39 +32,7 @@ class syntax_plugin_hackerbase extends DokuWiki_Syntax_Plugin {
|
|||
// $data is what the function handle return'ed.
|
||||
if($mode == 'xhtml'){
|
||||
$spaceapi_status_json = $this->getConf("spaceapijson");
|
||||
$str = file_get_contents($spaceapi_status_json);
|
||||
/** @var Doku_Renderer_xhtml $renderer */
|
||||
$status = "UNKNOWN";
|
||||
if ($str == FALSE) {
|
||||
$status = "ERROR:FILE";
|
||||
} else {
|
||||
$json = json_decode($str, true);
|
||||
if ($json == NULL) {
|
||||
$status = "ERROR:JSON";
|
||||
} else {
|
||||
$opened = $json['state']['open'];
|
||||
$lastchange = $json['state']['lastchange'];
|
||||
$myfile = __FILE__;
|
||||
$mydir = dirname($myfile);
|
||||
$mydirname = basename($mydir);
|
||||
$assetsdir = DOKU_BASE . "lib/plugins/" . $mydirname . "/assets";
|
||||
if ($opened == TRUE) {
|
||||
$status =
|
||||
'<p><img src="' . $assetsdir . '/open-sun.png"></p>' .
|
||||
'<h3>OPEN</h3>';
|
||||
} elseif ($opened == FALSE) {
|
||||
$status =
|
||||
'<p><img src="' . $assetsdir . '/closed-moon.png"></p>' .
|
||||
'<h3>CLOSED</h3>';
|
||||
} else {
|
||||
$status = "ERROR:DECODE";
|
||||
}
|
||||
if ($lastchange) {
|
||||
$str_date = strftime('%Y-%m-%d %H:%M', $lastchange);
|
||||
$status .= '<p>Last changed: ' . $str_date . '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$status = hackerbase_spaceapi_html_snippet($spaceapi_status_json);
|
||||
$renderer->doc .= $status;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue