Add the common module.
This commit is contained in:
parent
b89b4e3147
commit
5fb5e6dbf6
1 changed files with 47 additions and 0 deletions
47
dokuwiki/common.php
Normal file
47
dokuwiki/common.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin HackerBase: Common functions
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Dominik Pantůček <dominik.pantucek@trustica.cz>
|
||||
*/
|
||||
|
||||
// must be run within DokuWiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
function hackerbase_spaceapi_html_snippet($spaceapi_status_json) {
|
||||
$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>';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue