*/ require_once('prolog_tag.php'); class AttributeOptions extends PrologTag { var $name = 'options'; var $allowedOptions = array('debug', 'files', 'source'); var $authorizedOption = null; /** * Constructor */ function AttributeOptions() { $this->setAttributePattern($this->name); } /** * Reads the option from the options attribute * @param string $optionsValue the value from attribute options * @return array $options array with options */ function getOptions($optionsValue) { $options = array(); $exValues = explode(',', $optionsValue); foreach($exValues as $option) { $option = trim($option); if(!empty($option)) array_push($options, $option); } return $options; } /** * Checks the option permission to be operate * @param string $option * @return bool */ function isAuthorizedOption($option) { if($this->authorizedOption == $option) return true; else return false; } /** * Gives permission to the option to be operate * @param string $option */ function authorizeOption($option) { if($this->isAllowedOption($option)) $this->authorizedOption = $option; else $this->authorizedOption = null; } /** * Checks if a particular option is allowed * @param string $option * @return bool */ function isAllowedOption($option) { if(in_array($option, $this->allowedOptions)) return true; else return false; } /** * Handles the "files" option * @param array $files files paths list * @return string $filesList formatted files list to display */ function handleOptionFiles($files = array()) { if(!$this->isAuthorizedOption('files')) return; $filesList = '
Prolog plug-in - option files'; return $filesList; } /** * Handles the "source" option * @param string $sourceCode prolog source code * @return string $source formatted prolog source code to display */ function handleOptionSource($sourceCode = null) { if(!$this->isAuthorizedOption('source')) return; $source = '
Included files:
'; if(count($files)) foreach($files as $file) $filesList .= $file.'
'; $filesList .= wikiFN(getID()).'
'; $filesList .= '
Prolog plug-in - option source'; return $source; } /** * Handles the "debug" option * @param string $errors output from errors pipe from prolog interpreter * @return string $debug formatted prolog errors pipe content to display */ function handleOptionDebug($errors = null) { if(!$this->isAuthorizedOption('debug')) return; $debug = '
Source code:
'; $source .= $sourceCode; $source .= '
Prolog plug-in - option debug'; return $debug; } } ?>
Compilation results:
'; $debug .= $errors; $debug .= '