2011-09-15 12:54:40 +02:00
< ? php
/**
* DokuWiki Plugin whoisinyourhackspace ( Syntax Component )
*
* @ license GPL 2 http :// www . gnu . org / licenses / gpl - 2.0 . html
* @ author Tim Schumacher < tim . daniel . schumacher @ gmail . com >
*/
// must be run within Dokuwiki
if ( ! defined ( 'DOKU_INC' )) die ();
if ( ! defined ( 'DOKU_LF' )) define ( 'DOKU_LF' , " \n " );
if ( ! defined ( 'DOKU_TAB' )) define ( 'DOKU_TAB' , " \t " );
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' ;
}
public function getPType () {
return 'block' ;
}
public function getSort () {
return 0 ;
}
public function connectTo ( $mode ) {
2015-02-03 21:16:12 +01:00
$this -> Lexer -> addSpecialPattern ( '\[wiyh\]' , $mode , 'plugin_whoisinyourhackspace' );
2011-09-15 12:54:40 +02:00
}
public function render ( $mode , & $renderer , $data ) {
global $conf ;
if ( $mode != 'xhtml' ) return false ;
2014-06-03 21:13:40 +02:00
$api_path = $this -> getConf ( 'api_path' );
$file = file_get_contents ( $api_path );
$api = json_decode ( $file );
2014-06-30 23:00:01 +02:00
$content = '' ;
$content .= '<div class="hackerspace-room-state">' ;
2015-02-03 21:16:12 +01:00
$content .= " <h3> " . $this -> getLang ( 'wiyh_heading' ) . " </h3> " ;
2014-06-30 23:00:01 +02:00
2014-06-03 21:13:40 +02:00
if ( $api -> state -> open ) {
2014-06-30 23:00:01 +02:00
$content .= " <img class= \" icon \" src= \" { $api -> state -> icon -> open } \" alt= \" { $api -> space } ist besetzt. \" title= \" { $api -> space } ist besetzt. \" /> " ;
2015-02-03 21:16:12 +01:00
$content .= " <p class= \" text \" > { $api -> space } " . $this -> getLang ( 'wiyh_open' ) . " </p> " ;
2014-06-03 21:13:40 +02:00
} else {
2014-06-30 23:00:01 +02:00
$content .= " <img class= \" icon \" src= \" { $api -> state -> icon -> closed } \" alt= \" { $api -> space } ist geschlossen. \" title= \" { $api -> space } ist geschlossen. \" /> " ;
2015-02-03 21:16:12 +01:00
$content .= " <p class= \" text \" > { $api -> space } " . $this -> getLang ( 'wiyh_closed' ) . " </p> " ;
2014-06-03 21:13:40 +02:00
}
2014-06-30 23:00:01 +02:00
$content .= '<hr />' ;
2015-02-03 21:16:12 +01:00
$content .= sprintf ( '<p><a href="http://spaceapi-stats.n39.eu/#%s">' . $this -> getLang ( 'wiyh_stats' ) . '</a></p>' , strtolower ( $api -> space ));
2014-06-30 23:00:01 +02:00
$content .= '</div>' ;
2014-06-03 22:01:09 +02:00
2014-06-30 23:00:01 +02:00
$renderer -> doc .= $content ;
2011-09-15 12:54:40 +02:00
return true ;
}
}
// vim:ts=4:sw=4:et: