Changeset 6151
- Timestamp:
- 11/23/07 18:35:29 (6 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtjs2Plugin/trunk/config/config.php
r6147 r6151 1 1 <?php 2 2 sfConfig::set('sf_extjs2_version', 'v0.23'); 3 4 # 5 # array values that don't need quotes 6 # 7 $quoteExcept = array('value' => array('true', 'false', 'new Ext.', 'function', 'Ext.'), 8 'key' => array('renderer', 'store', 'defaults', 'plugins', 'cm', 'ds', 'view', 'tbar', 'bbar')); 9 sfConfig::set('sf_extjs2_quote_except', $quoteExcept); 10 3 11 # 4 12 # adapters … … 12 20 'adapter/jquery/ext-jquery-adapter.js' 13 21 ), 14 'prototype' => array(22 'prototype' => array( 15 23 'adapter/prototype/prototype.js', 16 24 'adapter/prototype/scriptaculous.js?load=effects.js', 17 25 'adapter/prototype/ext-prototype-adapter.js' 18 ),19 'yui' => array(26 ), 27 'yui' => array( 20 28 'adapter/yui/yui-utilities.js', 21 29 'adapter/yui/ext-yui-adapter.js' 22 30 ), 23 'ext' => array(31 'ext' => array( 24 32 'adapter/ext/ext-base.js' 25 33 ) 26 34 ) 27 35 ); 36 28 37 # 29 38 # themes … … 36 45 ) 37 46 ); 47 38 48 # 39 49 # base directories … … 42 52 sfConfig::set('sf_extjs2_css_dir', '/sfExtjs2Plugin/resources/css/'); 43 53 sfConfig::set('sf_extjs2_images_dir', '/sfExtjs2Plugin/resources/images/'); 54 44 55 # 45 56 # spacer gif 46 57 # 47 58 sfConfig::set('sf_extjs2_spacer', '/sfExtjs2Plugin/resources/images/default/s.gif'); 59 48 60 # 49 61 # attributes which must handled as array 50 62 # 51 sfConfig::set('sf_extjs2_list_attributes', array('items', 'tbar', 'buttons')); 52 # 53 # mapping plugin method against class 63 sfConfig::set('sf_extjs2_list_attributes', array('items', 'tbar', 'buttons', 'defaults', 'plugins', 'cm', 'ds', 'view', 'tbar', 'bbar')); 64 65 # 66 # mapping plugin method against class 54 67 # 55 68 sfConfig::set('classes', 56 69 array( 57 70 // data 58 'JsonReader' => 'Ext.data.JsonReader', 59 'Store' => 'Ext.data.Store', 60 'HttpProxy' => 'Ext.data.HttpProxy', 71 'JsonReader' => 'Ext.data.JsonReader', 72 'Store' => 'Ext.data.Store', 73 'HttpProxy' => 'Ext.data.HttpProxy', 74 61 75 // widgets 62 76 'BoxComponent' => 'Ext.BoxComponent', 63 77 'Button' => 'Ext.Button', 64 'GridPanel' => 'Ext.grid.GridPanel',65 'ColumnModel' => 'Ext.grid.ColumnModel',78 'GridPanel' => 'Ext.grid.GridPanel', 79 'ColumnModel' => 'Ext.grid.ColumnModel', 66 80 'Panel' => 'Ext.Panel', 67 81 'TabPanel' => 'Ext.TabPanel', … … 73 87 'TimeField' => 'Ext.form.TimeField', 74 88 'HtmlEditor' => 'Ext.form.HtmlEditor', 75 'Menu' => 'Ext.menu.Menu',76 'Item' => 'Ext.menu.Item'89 'Menu' => 'Ext.menu.Menu', 90 'Item' => 'Ext.menu.Item' 77 91 ) 78 92 ); … … 178 192 ); 179 193 180 181 194 sfConfig::set('Ext.FormPanel', 182 195 array( plugins/sfExtjs2Plugin/trunk/lib/helper/sfExtjs2Helper.php
r6147 r6151 7 7 * @version 0.0.23 8 8 * @last modified 11.22.2007 Kubens: 9 * - Added parameter support for custom methods10 * - Added features to create application11 * - Added parameter support for Ext.object constructors12 * 11.17.2007 Kubens:13 * - Added features to create custom classes and custom methods14 * 11.12.2007 Kubens:15 * - Fixed loading order of adapters. If adapters are used then it is important to load16 * adapters and coresponding files before ext-all.js17 * - Overworked: load method. Adapters and themes are setuped in config.php18 * - Overworked: constructor. If no adapter or theme is passed then default19 * settings from config.php will used20 * 11.07.2007 KRavEN:21 * - Fixed the adapter includes to load all required files in the correct order9 * - Added parameter support for custom methods 10 * - Added features to create application 11 * - Added parameter support for Ext.object constructors 12 * 11.17.2007 Kubens: 13 * - Added features to create custom classes and custom methods 14 * 11.12.2007 Kubens: 15 * - Fixed loading order of adapters. If adapters are used then it is important to load 16 * adapters and coresponding files before ext-all.js 17 * - Overworked: load method. Adapters and themes are setuped in config.php 18 * - Overworked: constructor. If no adapter or theme is passed then default 19 * settings from config.php will used 20 * 11.07.2007 KRavEN: 21 * - Fixed the adapter includes to load all required files in the correct order 22 22 * moved ext-base into adapters, pass ext as adapter for standalone 23 23 * changed all javascript to load first so they will come before files specified in view.yml 24 * 07.15.2007 Kubens: 25 * - created24 * 07.15.2007 Kubens: 25 * - created 26 26 */ 27 27 class sfExtjs2Plugin { … … 48 48 { 49 49 $object = sfConfig::get($classes[$class]); 50 return sfExtjs2Plugin::getExtObject($object['class'], $parameters[0]);50 return sfExtjs2Plugin::getExtObject($object['class'], $parameters[0]); 51 51 } 52 52 } … … 55 55 * Renders javascript source for Ext.Object 56 56 * Example usage: 57 * 57 * 58 58 * Syntax A = short form without any options 59 59 * … … 74 74 * ( 75 75 * 'name' => 'string', // option to render Javascript variable 76 * 'attributes' => array // attributes for Ext constructor76 * 'attributes' => array // attributes for Ext constructor 77 77 * ( 78 78 * 'id' => 'id', … … 84 84 * ) 85 85 * ) 86 * 'parameters' => array87 * (88 * 'parameter1',89 * 'parameter2'90 * )86 * 'parameters' => array 87 * ( 88 * 'parameter1', 89 * 'parameter2' 90 * ) 91 91 * ); 92 92 * … … 96 96 * 97 97 */ 98 public static function getExtObject($class, $attrib utes = array())99 { 98 public static function getExtObject($class, $attribs = array()) 99 { 100 100 # parameters for constructor 101 101 $parameters = array(); 102 if (is_array($attributes) && array_key_exists('parameters', $attributes)) 103 { 104 $parameters = $attributes['parameters']; 105 unset($attributes['parameters']); 106 } 107 102 if (is_array($attribs) && array_key_exists('parameters', $attribs)) 103 { 104 $parameters = $attribs['parameters']; 105 unset($attribs['parameters']); 106 } 107 108 #make it easier on us so not so much escaping in the attibutes setup 109 foreach ($attribs as $key => $value) 110 { 111 #enables us to have empty keys removed 112 if(is_null($value)) continue; 113 114 #quotes everything not in the quote_except value list 115 if(!is_array($value)) 116 { 117 $attributes[$key] = (sfExtjs2Plugin::quote_except($key, $value) ? '\''.$value.'\'' : $value); 118 } 119 else 120 { 121 $attributes[$key] = $value; 122 } 123 } 124 108 125 # syntax A is a shortform of syntax B 109 126 # if syntax A is used then convert syntax A to syntax B … … 121 138 if (is_array($attributes) && array_key_exists($attribute, $attributes['attributes'])) 122 139 { 123 $attributes['attributes'][$attribute] = sprintf('[%s]', implode(',',$attributes['attributes'][$attribute])); 140 $attStr = implode(',',$attributes['attributes'][$attribute]); 141 $attributes['attributes'][$attribute] = (sfExtjs2Plugin::quote_except($attribute, null) ? '['.$attStr.']' : '{'.$attStr.'}'); 142 //$attributes['attributes'][$attribute] = sprintf('[%s]', implode(',',$attributes['attributes'][$attribute])); 124 143 } 125 144 } … … 127 146 // get source of component 128 147 $source = call_user_func(array('sfExtjs2Plugin', 'getExtObjectComponent'), $attributes['attributes'], sfConfig::get($class), $parameters); 129 148 130 149 // if 'name' is assigned then we must render 131 150 // either a Javascript variable or an attribute of this … … 153 172 * @param array attributes 154 173 * @param array config 155 * @param array parameters 174 * @param array parameters 156 175 * @return string source of Ext component 157 176 * … … 161 180 $attributes = sfExtjs2Plugin::_build_attributes($attributes, $config['attributes']); 162 181 $attributes = sprintf('%s', $attributes != '' ? '{'.$attributes.'}' : ''); 163 182 164 183 $parameters = implode(',', $parameters); 165 184 $parameters = sprintf('%s%s', $attributes != '' && $parameters != '' ? ',' : '', $parameters); 166 185 167 186 $source = sprintf( 168 'new %s (%s%s)', 169 $config['class'], 170 $attributes, 187 'new %s (%s%s)', 188 $config['class'], 189 $attributes, 171 190 $parameters 172 );191 ); 173 192 174 193 return $source; … … 176 195 177 196 /** 178 * add sources for css and js 197 * add sources for css and js 179 198 * files to response 180 199 * … … 183 202 { 184 203 $response = sfContext::getInstance()->getResponse(); 185 204 186 205 // add javascript sources for adapter 187 $adapters = sfConfig::get('sf_extjs2_adapters', array()); 206 $adapters = sfConfig::get('sf_extjs2_adapters', array()); 188 207 foreach ($adapters[$this->adapter] as $file) 189 208 { … … 192 211 193 212 // add javascript sources for ext all 194 $response->addJavascript(sfConfig::get('sf_extjs2_js_dir'). 'ext-all.js', ' last');195 213 $response->addJavascript(sfConfig::get('sf_extjs2_js_dir'). 'ext-all.js', 'first'); 214 196 215 // add css sources for ext all 197 $response->addStylesheet(sfConfig::get('sf_extjs2_css_dir'). 'ext-all.css', ' last');216 $response->addStylesheet(sfConfig::get('sf_extjs2_css_dir'). 'ext-all.css', 'first'); 198 217 199 218 // add css sources for theme 200 $themes = sfConfig::get('sf_extjs2_themes', array()); 219 $themes = sfConfig::get('sf_extjs2_themes', array()); 201 220 foreach ($themes[$this->theme] as $file) 202 221 { 203 $response->addStylesheet(sfConfig::get('sf_extjs2_css_dir'). $file, ' last');222 $response->addStylesheet(sfConfig::get('sf_extjs2_css_dir'). $file, 'first'); 204 223 } 205 224 } … … 233 252 * writes opening class tag 234 253 * 235 * @param string namespace 254 * @param string namespace 236 255 * @param string classname 237 256 * @param string extend … … 243 262 $source = ''; 244 263 245 // write namespace directive 246 // prevent double output of namespace directive 264 // write namespace directive 265 // prevent double output of namespace directive 247 266 if ($this->namespace !== $namespace) 248 267 { … … 250 269 $source .= sprintf("Ext.namespace('%s')%s", $namespace, sfExtjs2Plugin::LBR_SM); 251 270 } 252 271 253 272 // write class tag 254 273 $source .= sprintf("%s.%s = Ext.extend(%s, {%s", $namespace, $classname, $extend, sfExtjs2Plugin::LBR); … … 267 286 /** 268 287 * writes closing class tag 269 * 288 * 270 289 * @return source 271 290 */ … … 274 293 $source = ''; 275 294 $source .= sprintf("})%s", sfExtjs2Plugin::LBR_SM); 276 295 277 296 echo $source; 278 297 } … … 280 299 /** 281 300 * writes begining application tag 282 * 301 * 283 302 * @param attributes['name'] 284 303 * @param attributes['private'] 285 304 * @param attributes['public'] 286 * @return source 305 * @return source 287 306 */ 288 307 public function beginApplication($attributes = array()) … … 295 314 { 296 315 $sourcePrivate .= sprintf('%svar %s = %s;', sfExtjs2Plugin::LBR, $key, $value); 297 } 316 } 298 317 } 299 318 … … 308 327 $sourcePublic .= sprintf('%s%s: %s%s', sfExtjs2Plugin::LBR, $key, $value, $i < count($attributes['public']) ? ',' : '' ); 309 328 } 310 } 311 329 } 330 312 331 // write application syntax 313 332 $source = ''; 314 333 $source = sprintf( 315 'var %s = function() { %s%sreturn {%s %s', 316 $attributes['name'], 334 'var %s = function() { %s%sreturn {%s %s', 335 $attributes['name'], 317 336 $sourcePrivate, 318 337 $sourcePrivate != '' ? sfExtjs2Plugin::LBR : '', … … 320 339 $sourcePublic != '' ? sfExtjs2Plugin::LBR : '' 321 340 ); 322 323 echo $source; 324 } 325 341 342 echo $source; 343 } 344 326 345 /** 327 346 * writes closing application tag 328 * 347 * 329 348 * @return source 330 */ 349 */ 331 350 public function endApplication() 332 351 { 333 352 $source = ''; 334 353 $source .= sprintf("}}()%s", sfExtjs2Plugin::LBR_SM); 335 336 echo $source; 337 } 338 354 355 echo $source; 356 } 357 339 358 /** 340 359 * returns output of evaled php code 341 * 360 * 342 361 * @param array matches 343 362 * @return string source … … 345 364 public static function methodEvalPHP ($matches) 346 365 { 347 $source = str_replace( array('<?php', '<?', '?>'), '', $matches[0]); 366 $source = str_replace( array('<?php', '<?', '?>'), '', $matches[0]); 348 367 ob_start(); 349 368 eval($source); … … 363 382 { 364 383 $source = is_array($attributes) && array_key_exists('source', $attributes) ? $attributes['source'] : $attributes; 365 $source = preg_replace_callback( 366 '/(\<\?php)(.*?)(\?>)/si', 367 array('self', 'methodEvalPHP'), 384 $source = preg_replace_callback( 385 '/(\<\?php)(.*?)(\?>)/si', 386 array('self', 'methodEvalPHP'), 368 387 $source 369 388 ); 370 389 $source = sprintf("function (%s) { %s }", is_array($attributes) && array_key_exists('parameters', $attributes) ? $attributes['parameters'] : '', $source); 371 372 return $source; 373 } 374 375 /** 376 * returns source of custom class 390 391 return $source; 392 } 393 394 /** 395 * returns source of custom class 377 396 * 378 397 * @param string classname … … 419 438 return $attributes; 420 439 } 421 440 441 private static function quote_except($key, $value) 442 { 443 $quoteExcept = sfConfig::get('sf_extjs2_quote_except'); 444 445 if (is_int($key)) 446 { 447 return false; 448 } 449 else 450 { 451 foreach ($quoteExcept['key'] as $except) 452 { 453 if ($key == $except) 454 { 455 return false; 456 } 457 } 458 } 459 460 if (is_int($value)) 461 { 462 return false; 463 } 464 else 465 { 466 foreach ($quoteExcept['value'] as $except) 467 { 468 if (substr($value, 0, strlen($except)) == $except) 469 { 470 return false; 471 } 472 } 473 } 474 475 return true; 476 } 477 422 478 } 423 479