68 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
|   /**
 | |
|    * Plugin Now: Inserts a timestamp.
 | |
|    * 
 | |
|    * @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();
 | |
| 
 | |
| /**
 | |
|  * All DokuWiki plugins to extend the parser/rendering mechanism
 | |
|  * need to inherit from this class
 | |
|  */
 | |
| class syntax_plugin_brmburo extends DokuWiki_Syntax_Plugin {
 | |
| 
 | |
|   public function getType() { return 'substition'; }
 | |
|   public function getSort() { return 32; }
 | |
| 
 | |
|   public function connectTo($mode) {
 | |
|     $this->Lexer->addSpecialPattern('\[BRMDOOR\]',$mode,'plugin_brmburo');
 | |
|   }
 | |
| 
 | |
|   public function handle($match, $state, $pos, Doku_Handler $handler) {
 | |
|     return array($match, $state, $pos);
 | |
|   }
 | |
| 
 | |
|   public function render($mode, Doku_Renderer $renderer, $data) {
 | |
|     // $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'];
 | |
| 	  $assetsdir = DOKU_BASE . "lib/plugins/brmburo/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>';
 | |
| 	  }
 | |
| 	}
 | |
|       }
 | |
|       $renderer->doc .= $status;
 | |
|       return true;
 | |
|     }
 | |
|     return false;
 | |
|   }
 | |
| }
 |