* @license MIT */ if (!defined('DOKU_INC')) die(); /** * Implements rrd class plugin's syntax plugin. * */ class syntax_plugin_rrdgraph extends DokuWiki_Syntax_Plugin { /** Constant that indicates that a recipe is used for cerating graphs. */ const RT_GRAPH = 0; /** Constant that indicates that a recipe is used for inclusion in other recipes. */ const RT_TEMPLATE = 1; /** Constant that indicates that a recipe is used for bound svg graphics. */ const RT_BOUNDSVG = 2; /** Array index of the graph type within the parsed recipe. */ const R_TYPE = 'type'; /** Array index of the graph name within the parsed recipe. */ const R_NAME = 'name'; /** Array index of a flag that indicates if the results of this recipe should be included within the generated xhtml output. */ const R_SHOW = 'show'; /** Array index of the recipe data within the parsed recipe. */ const R_DATA = 'data'; /** Array index of the ganged flag within the parsed recipe. */ const R_GANGED = 'ganged'; /** Array index of the name of the bound svg file if the parsed recipe is of type RT_BOUNDSVG. */ const R_BSOURCE = 'bsource'; /** * Stores the rrd recipe while it's parsed. This variable is reset every time a new recipe starts. * @var Array */ private $rrdRecipe; /** * Returns the syntax mode of this plugin. * @return String Syntax mode type */ public function getType() { return 'substition'; } /** * Returns the paragraph type of this plugin. * @return String Paragraph type */ public function getPType() { return array (); } /** * Returns the sort order for this plugin. * @return Integer Sort order - Low numbers go before high numbers */ public function getSort() { return 320; } /** * Connect lookup pattern to lexer. * * @param string $mode Parser mode */ public function connectTo($mode) { $this->Lexer->addEntryPattern('(?=.*?)', $mode, 'plugin_rrdgraph'); } /** * Adds some patterns after the start pattern was found. */ public function postConnect() { $this->Lexer->addPattern('\n[ \t]*(?:[a-z0-9,<>=&|]+\?)?[A-Z0-9]+:[^\n]+', 'plugin_rrdgraph'); //TODO: Parser Regex mit der weiter untern verschmelzen und in eine Konstante packen! $this->Lexer->addExitPattern('', 'plugin_rrdgraph'); } /** * Parses the given string as a boolean value. * @param String $value String to be parsed. * @return boolean If the string is "yes", "on" or "true" true is returned. If the stirng is anything else, false is returned. */ private function parseBoolean($value) { $value = strtolower(trim($value)); if (is_numeric($value)) return (intval($value) > 0); switch ($value) { case 'yes' : case 'on' : case 'true' : return true; default : return false; } } /** * Extracts the range tags from a given recipe. * @param Array $recipe The rrd recipe that should be parsed. * @return Array An array of arrays is returned. For each RANGE tag an array is created containing three values: (0) The range name, (1) the start time, (2) the end time. */ private function getRanges($recipe) { $ranges = array (); foreach ($recipe as $option) { list ($condition, $key, $value) = $option; switch ($key) { case "RANGE" : $range = explode(":", $value, 3); if (count($range) == 3) $ranges[] = $range; break; } } return $ranges; } /** * Generates the XHTML markup for the tabs based on a range definition generated by getRanges(). * @param Array $ranges The range definition generated by getRanges(). * @param Integer $selectedTab The number of the selected tab. (zero based). * @param String $graphId The id-value (hex-hash) of the graph this tab markup is generated for. * @param Boolean $initiallyGanged If the "ganged" checkbox shlould be initially ticked. * @return String Returns the XHTML markup that should be inserted into the page.. */ private function generateTabs($ranges, $selectedTab, $graphId, $initiallyGanged) { //-- Define the tabs for bigger streen resolutions... $xhtml = '