if (!isset($_GET['debug'])) { header("Content-type: image/png"); } // Read session data if (!isset($_SESSION['data'])) { exit; } $data = $_SESSION['data']; $color = isset($_SESSION['color']) ? $_SESSION['color'] : 0; $triangles = isset($_SESSION['triangles']) ? $_SESSION['triangles'] : FALSE; $antialias = isset($_SESSION['antialias']) ? $_SESSION['antialias'] : 0; $autosub = isset($_SESSION['autosub']) ? $_SESSION['autosub'] : 0; $font = isset($_SESSION['font']) ? $_SESSION['font'] : 'Vera.ttf'; $fontsize = isset($_SESSION['fontsize']) ? $_SESSION['fontsize'] : 8; // Validate the phrase and draw the tree $sp = new CStringParser($data); if (!$sp->Validate()) { // Display an error if the phrase doesn't validate. // Right now that only means the brackets didn't // match up. More tests could be added in the future. // It would also be a good idea to make this error // image creation a standalone class or something. $im = imagecreate(350, 20); $col_bg = imagecolorallocate($im, 255, 255, 255); $col_fg = imagecolorallocate($im, 255, 0, 0); imagestring($im, 3, 5, 3, "Sentence brackets don't match up...", $col_fg); imagepng($im); } else { // If all is well, go ahead and draw the graph ... $sp->Parse(); if ($autosub) {
function parseTriggerExpressions($expressions, $askData = false) { static $scparser, $triggersData; global $triggerExpressionRules; if (!$scparser) { $scparser = new CStringParser($triggerExpressionRules); } if (!is_array($expressions)) { $expressions = array($expressions); } $data = array(); $noErrors = true; foreach ($expressions as $key => $str) { if (!isset($triggersData[$str])) { $tmp_expr = $str; //SDI($tmp_expr); if ($scparser->parse($tmp_expr)) { $triggersData[$str]['expressions'] = $scparser->getElements('expression'); $triggersData[$str]['hosts'] = $scparser->getElements('server'); $triggersData[$str]['keys'] = $scparser->getElements('keyName'); $triggersData[$str]['keysParams'] = $scparser->getElements('keyParams'); $triggersData[$str]['keysFunctions'] = $scparser->getElements('keyFunctionName'); $triggersData[$str]['macros'] = array_merge($scparser->getElements('macro'), $scparser->getElements('macroNum'), $scparser->getElements('customMacro')); $triggersData[$str]['customMacros'] = $scparser->getElements('customMacro'); $triggersData[$str]['allMacros'] = array_merge($triggersData[$str]['expressions'], $triggersData[$str]['macros']); $triggersData[$str]['tree'] = $scparser->getTree(); } else { $triggersData[$str]['errors'] = $scparser->getErrors(); $noErrors = false; } } $data[$str] =& $triggersData[$str]; } return $askData ? $data : $noErrors; }