| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | class FuseboxPlugin { |
|---|
| 53 | |
|---|
| 54 | var $name; |
|---|
| 55 | var $fuseboxApplication; |
|---|
| 56 | var $phase; |
|---|
| 57 | var $path; |
|---|
| 58 | var $template; |
|---|
| 59 | var $rootPath; |
|---|
| 60 | var $parameters; |
|---|
| 61 | var $paramVerbs; |
|---|
| 62 | |
|---|
| 63 | function FuseboxPlugin ( |
|---|
| 64 | $phase, |
|---|
| 65 | $pluginXML, |
|---|
| 66 | &$fbApp |
|---|
| 67 | ) { |
|---|
| 68 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 69 | |
|---|
| 70 | $i = 0; |
|---|
| 71 | $n = count($pluginXML['xmlChildren']); |
|---|
| 72 | $attr = 0; |
|---|
| 73 | $nAttrs = 2; |
|---|
| 74 | $verbChildren = array(); |
|---|
| 75 | $factory =& $fbApp->getFuseactionFactory(); |
|---|
| 76 | $ext = "." . $fbApp->scriptFileDelimiter; |
|---|
| 77 | |
|---|
| 78 | if ( !array_key_exists("name",$pluginXML['xmlAttributes']) ) { |
|---|
| 79 | __cfthrow(array( 'type'=>"fusebox.badGrammar.requiredAttributeMissing", |
|---|
| 80 | 'message'=>"Required attribute is missing", |
|---|
| 81 | 'detail'=>"The attribute 'name' is required, for a '$phase' plugin declaration in fusebox.xml." |
|---|
| 82 | )); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | $this->name = $pluginXML['xmlAttributes']['name']; |
|---|
| 86 | $this->fuseboxApplication =& $fbApp; |
|---|
| 87 | |
|---|
| 88 | if ( !array_key_exists("template",$pluginXML['xmlAttributes']) ) { |
|---|
| 89 | __cfthrow(array( 'type'=>"fusebox.badGrammar.requiredAttributeMissing", |
|---|
| 90 | 'message'=>"Required attribute is missing", |
|---|
| 91 | 'detail'=>"The attribute 'template' is required, for the '".$this->getName()."' plugin declaration in fusebox.xml." |
|---|
| 92 | )); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | $this->phase = $phase; |
|---|
| 96 | if ( $pluginXML['xmlName'] == "plugin" ) { |
|---|
| 97 | $this->path = $fbApp->getPluginsPath(); |
|---|
| 98 | if ( array_key_exists("path",$pluginXML['xmlAttributes']) ) { |
|---|
| 99 | $this->path .= str_replace("\\","/",$pluginXML['xmlAttributes']['path']); |
|---|
| 100 | $nAttrs = 3; |
|---|
| 101 | } |
|---|
| 102 | if ( substr($this->path,-1) != "/" ) { |
|---|
| 103 | $this->path .= "/"; |
|---|
| 104 | } |
|---|
| 105 | $this->template = $pluginXML['xmlAttributes']['template']; |
|---|
| 106 | if ( strlen($this->template) > 4 || substr($this->template,-4) != $ext ) { |
|---|
| 107 | $this->template .= $ext; |
|---|
| 108 | } |
|---|
| 109 | $this->rootpath = |
|---|
| 110 | $fbApp->relativePath($fbApp->getApplicationRoot() . |
|---|
| 111 | $this->path,$fbApp->getApplicationRoot()); |
|---|
| 112 | |
|---|
| 113 | while ( strpos($this->rootpath,'/../') !== false ) { |
|---|
| 114 | $this->rootpath = ereg_replace("[^\\.:/]*/\\.\\./","",$this->rootpath); |
|---|
| 115 | } |
|---|
| 116 | if ( $fbApp->strictMode && count($pluginXML['xmlAttributes']) != $nAttrs ) { |
|---|
| 117 | __cfthrow(array( 'type'=>"fusebox.badGrammar.unexpectedAttributes", |
|---|
| 118 | 'message'=>"Unexpected attributes", |
|---|
| 119 | 'detail'=>"Unexpected attributes were found in the '".$this->getName()."' plugin declaration in fusebox.xml." |
|---|
| 120 | )); |
|---|
| 121 | } |
|---|
| 122 | $this->parameters = $pluginXML['xmlChildren']; |
|---|
| 123 | $this->paramVerbs = array(); |
|---|
| 124 | for ( $i = 0 ; $i < $n ; $i++ ) { |
|---|
| 125 | if ( !array_key_exists("name",$this->parameters[$i]['xmlAttributes']) ) { |
|---|
| 126 | __cfthrow(array( 'type'=>"fusebox.badGrammar.requiredAttributeMissing", |
|---|
| 127 | 'message'=>"Required attribute is missing", |
|---|
| 128 | 'detail'=>"The attribute 'name' is required, for a 'parameter' to the '".$this->getName()."' plugin declaration in fusebox.xml." |
|---|
| 129 | )); |
|---|
| 130 | } |
|---|
| 131 | if ( !array_key_exists("value",$this->parameters[$i]['xmlAttributes']) ) { |
|---|
| 132 | __cfthrow(array( 'type'=>"fusebox.badGrammar.requiredAttributeMissing", |
|---|
| 133 | 'message'=>"Required attribute is missing", |
|---|
| 134 | 'detail'=>"The attribute 'value' is required, for a 'parameter' to the '".$this->getName()."' plugin declaration in fusebox.xml." |
|---|
| 135 | )); |
|---|
| 136 | } |
|---|
| 137 | if ( $fbApp->strictMode && count($this->parameters[$i].xmlAttributes) != 2 ) { |
|---|
| 138 | __cfthrow(array( 'type'=>"fusebox.badGrammar.unexpectedAttributes", |
|---|
| 139 | 'message'=>"Unexpected attributes", |
|---|
| 140 | 'detail'=>"Unexpected attributes were found in the '".$this->parameters[$i]['xmlAttributes']['name']."' parameter of the '$this->getName()' plugin declaration in fusebox.xml." |
|---|
| 141 | )); |
|---|
| 142 | } |
|---|
| 143 | $attr = array(); |
|---|
| 144 | $attr['name'] = 'myFusebox->plugins["'.$this->getName().'"]["parameters"]["'.$this->parameters[$i]['xmlAttributes']['name'].'"]'; |
|---|
| 145 | $attr['value'] = $this->parameters[$i]['xmlAttributes']['value']; |
|---|
| 146 | $this->paramVerbs[$i] = $factory->create("set",$this,$attr,$verbChildren); |
|---|
| 147 | } |
|---|
| 148 | } else { |
|---|
| 149 | __cfthrow(array( 'type'=>"fusebox.badGrammar.illegalDeclaration", |
|---|
| 150 | 'message'=>"Illegal declaration", |
|---|
| 151 | 'detail'=>"The XML entity '{$pluginXML['xmlName']}' was found where a plugin declaration was expected in fusebox.xml." |
|---|
| 152 | )); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 156 | return $this; |
|---|
| 157 | |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | function compile ( |
|---|
| 161 | &$writer |
|---|
| 162 | ) { |
|---|
| 163 | |
|---|
| 164 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 165 | $i = 0; |
|---|
| 166 | $n = count($this->paramVerbs); |
|---|
| 167 | $file = ""; |
|---|
| 168 | $p = ""; |
|---|
| 169 | |
|---|
| 170 | if ( $_REQUEST['__fusebox']['SuppressPlugins'] ) { |
|---|
| 171 | return; |
|---|
| 172 | } |
|---|
| 173 | switch ( $this->phase ) { |
|---|
| 174 | case 'processError' : |
|---|
| 175 | case 'fuseactionException' : |
|---|
| 176 | $fplFilename = $this->fuseboxApplication->getApplicationRoot().$this->path.$this->template; |
|---|
| 177 | $fpl = fopen($fplFilename,'r'); |
|---|
| 178 | $file = fread($fpl,filesize($fplFilename)); |
|---|
| 179 | fclose($fpl); |
|---|
| 180 | $writer->rawPrintln($file); |
|---|
| 181 | break; |
|---|
| 182 | default : |
|---|
| 183 | for ( $i = 0 ; $i < $n ; $i++ ) { |
|---|
| 184 | $this->paramVerbs[$i]->compile($writer); |
|---|
| 185 | } |
|---|
| 186 | $p = $writer->setPhase($this->phase); |
|---|
| 187 | $writer->println('$myFusebox->thisPlugin = "'.$this->getName().'";'); |
|---|
| 188 | $writer->_print('include('); |
|---|
| 189 | $writer->_print('$application[$FUSEBOX_APPLICATION_KEY]->WebRootPathToappRoot."'.$this->path.$this->template); |
|---|
| 190 | $writer->println('");'); |
|---|
| 191 | $writer->setPhase($p); |
|---|
| 192 | break; |
|---|
| 193 | } |
|---|
| 194 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 195 | |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | function getName() { |
|---|
| 199 | |
|---|
| 200 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 201 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 202 | return $this->name; |
|---|
| 203 | |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | function &getCircuit() { |
|---|
| 207 | |
|---|
| 208 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '<ul><li>Starting $'.__CLASS__.'->'.__FUNCTION__.'()'; |
|---|
| 209 | if ( isset($GLOBALS['attributes']['fusebox.debug']) && $GLOBALS['attributes']['fusebox.debug'] == 'true' ) echo '</li><li>Ending $'.__CLASS__.'->'.__FUNCTION__.'()</li></ul>'; |
|---|
| 210 | return $this->fuseboxApplication; |
|---|
| 211 | |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | } |
|---|
| 215 | ?> |
|---|