47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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;
 | |
| }
 |