| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the Skin class. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}. 10 * 11 * {@internal License choice 12 * - If you have received this file as part of a package, please find the license.txt file in 13 * the same folder or the closest folder above for complete license terms. 14 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 15 * then you must choose one of the following licenses before using the file: 16 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 17 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 18 * }} 19 * 20 * @package evocore 21 * 22 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 23 * @author fplanque: Francois PLANQUE. 24 * 25 * @version $Id: _skin.class.php,v 1.6 2007/10/08 08:32:56 fplanque Exp $ 26 */ 27 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 28 29 /** 30 * Skin Class 31 * 32 * @package evocore 33 */ 34 class Skin extends DataObject 35 { 36 var $name; 37 var $folder; 38 var $type; 39 40 /** 41 * Lazy filled. 42 * @var array 43 */ 44 var $container_list = NULL; 45 46 47 /** 48 * Constructor 49 * 50 * @param table Database row 51 */ 52 function Skin( $db_row = NULL ) 53 { 54 // Call parent constructor: 55 parent::DataObject( 'T_skins__skin', 'skin_', 'skin_ID' ); 56 57 $this->delete_restrictions = array( 58 array( 'table'=>'T_blogs', 'fk'=>'blog_skin_ID', 'msg'=>T_('%d blogs using this skin') ), 59 ); 60 61 $this->delete_cascades = array( 62 array( 'table'=>'T_skins__container', 'fk'=>'sco_skin_ID', 'msg'=>T_('%d linked containers') ), 63 ); 64 65 if( is_null($db_row) ) 66 { // We are creating an object here: 67 $this->type = 'normal'; 68 } 69 else 70 { // Wa are loading an object: 71 $this->ID = $db_row->skin_ID; 72 $this->name = $db_row->skin_name; 73 $this->folder = $db_row->skin_folder; 74 $this->type = $db_row->skin_type; 75 } 76 } 77 78 79 /** 80 * Install a skin 81 * 82 * @todo do not install if skin doesn't exist. Important for upgrade. Need to NOT fail if ZERO skins installed though :/ 83 * 84 * @param string 85 * @param string NULL for default 86 */ 87 function install( $skin_folder, $name = NULL ) 88 { 89 $this->set( 'name', empty( $name) ? $skin_folder : $name ); 90 $this->set( 'folder', $skin_folder ); 91 $this->set( 'type', substr($skin_folder,0,1) == '_' ? 'feed' : 'normal' ); 92 93 // Look for containers in skin file: 94 $this->discover_containers(); 95 96 // INSERT NEW SKIN INTO DB: 97 $this->dbinsert(); 98 } 99 100 101 /** 102 * 103 */ 104 function get_name() 105 { 106 return $this->name; 107 } 108 109 /** 110 * Load data from Request form fields. 111 * 112 * @return boolean true if loaded data seems valid. 113 */ 114 function load_from_Request() 115 { 116 // Name 117 param_string_not_empty( 'skin_name', T_('Please enter a name.') ); 118 $this->set_from_Request( 'name' ); 119 120 // Skin type 121 param( 'skin_type', 'string' ); 122 $this->set_from_Request( 'type' ); 123 124 return ! param_errors_detected(); 125 } 126 127 128 /** 129 * Display a container 130 * 131 * @todo fp> if it doesn't get any skin specific, move it outta here! :P 132 * fp> Do we need Skin objects in the frontoffice at all? -- Do we want to include the dispatcher into the Skin object? WARNING: globals 133 * fp> We might want to customize the container defaults. -- Per blog or per skin? 134 * 135 * @param string 136 * @param array 137 */ 138 function container( $sco_name, $params = array() ) 139 { 140 /** 141 * Blog currently displayed 142 * @var Blog 143 */ 144 global $Blog; 145 146 // echo '<div>Debug: container: '.$sco_name.'</div>'; 147 148 /** 149 * @var WidgetCache 150 */ 151 $WidgetCache = & get_Cache( 'WidgetCache' ); 152 $Widget_array = & $WidgetCache->get_by_coll_container( $Blog->ID, $sco_name ); 153 154 if( !empty($Widget_array) ) 155 { 156 foreach( $Widget_array as $ComponentWidget ) 157 { 158 // Let the Widget display itself (with contextual params): 159 $ComponentWidget->display( $params ); 160 } 161 } 162 } 163 164 165 /** 166 * Discover containers included in skin file 167 * @todo browse all *.tpl.php 168 */ 169 function discover_containers() 170 { 171 global $skins_path, $Messages; 172 173 $this->container_list = array(); 174 175 if( ! $dir = @opendir($skins_path.$this->folder) ) 176 { 177 $Messages->add( 'Cannot open skin directory.', 'error' ); // No trans 178 return false; 179 } 180 181 while( ( $file = readdir($dir) ) !== false ) 182 { 183 $rf_main_subpath = $this->folder.'/'.$file; 184 $af_main_path = $skins_path.$rf_main_subpath; 185 186 if( !is_file( $af_main_path ) || ! preg_match( '¤\.php$¤', $file ) ) 187 { // Not a php template file 188 continue; 189 } 190 191 if( ! is_readable($af_main_path) ) 192 { 193 $Messages->add( sprintf( T_('Cannot read skin file «%s»!'), $rf_main_subpath ), 'error' ); 194 continue; 195 } 196 197 $file_contents = @file_get_contents( $af_main_path ); 198 if( ! is_string($file_contents) ) 199 { 200 $Messages->add( sprintf( T_('Cannot read skin file «%s»!'), $rf_main_subpath ), 'error' ); 201 continue; 202 } 203 204 205 // if( ! preg_match_all( '~ \$Skin->container\( .*? (\' (.+?) \' )|(" (.+?) ") ~xmi', $file_contents, $matches ) ) 206 if( ! preg_match_all( '~ (\$Skin->|skin_)container\( .*? ((\' (.+?) \')|(" (.+?) ")) ~xmi', $file_contents, $matches ) ) 207 { // No containers in this file 208 continue; 209 } 210 211 // Merge matches from the two regexp parts (due to regexp "|" ) 212 $container_list = array_merge( $matches[4], $matches[6] ); 213 214 $c = 0; 215 foreach( $container_list as $container ) 216 { 217 if( empty($container) ) 218 { // regexp empty match 219 continue; 220 } 221 222 $c++; 223 224 if( in_array( $container, $this->container_list ) ) 225 { // we already have that one 226 continue; 227 } 228 229 $this->container_list[] = $container; 230 } 231 232 if( $c ) 233 { 234 $Messages->add( sprintf( T_('%d containers have been found in skin template «%s».'), $c, $rf_main_subpath ), 'success' ); 235 } 236 } 237 238 // pre_dump( $this->container_list ); 239 240 if( empty($this->container_list) ) 241 { 242 $Messages->add( T_('No containers found in this skin!'), 'error' ); 243 return false; 244 } 245 246 return true; 247 } 248 249 /** 250 * @return array 251 */ 252 function get_containers() 253 { 254 /** 255 * @var DB 256 */ 257 global $DB; 258 259 if( is_null( $this->container_list ) ) 260 { 261 $this->container_list = $DB->get_col( 262 'SELECT sco_name 263 FROM T_skins__container 264 WHERE sco_skin_ID = '.$this->ID, 0, 'get list of containers for skin' ); 265 } 266 267 return $this->container_list; 268 } 269 270 /** 271 * Update the DB based on previously recorded changes 272 * 273 * @return boolean true 274 */ 275 function dbupdate() 276 { 277 global $DB; 278 279 $DB->begin(); 280 281 if( parent::dbupdate() !== false ) 282 { // Skin updated, also save containers: 283 $this->db_save_containers(); 284 } 285 286 $DB->commit(); 287 288 return true; 289 } 290 291 292 /** 293 * Insert object into DB based on previously recorded changes. 294 * 295 * @return boolean true 296 */ 297 function dbinsert() 298 { 299 global $DB; 300 301 $DB->begin(); 302 303 if( parent::dbinsert() ) 304 { // Skin saved, also save containers: 305 $this->db_save_containers(); 306 } 307 308 $DB->commit(); 309 310 return true; 311 } 312 313 314 /** 315 * Save containers 316 * 317 * to be called by dbinsert / dbupdate 318 */ 319 function db_save_containers() 320 { 321 global $DB; 322 323 if( empty( $this->container_list ) ) 324 { 325 return false; 326 } 327 328 $values = array(); 329 foreach( $this->container_list as $container_name ) 330 { 331 $values [] = '( '.$this->ID.', '.$DB->quote($container_name).' )'; 332 } 333 334 $DB->query( 'REPLACE INTO T_skins__container( sco_skin_ID, sco_name ) 335 VALUES '.implode( ',', $values ), 'Insert containers' ); 336 337 return true; 338 } 339 340 341 /** 342 * Display skinshot for skin folder in various places. 343 * 344 * Including for NON installed skins. 345 * 346 * @static 347 */ 348 function disp_skinshot( $skin_folder, $function = NULL, $selected = false, $select_url = NULL, $function_url = NULL ) 349 { 350 global $skins_path, $skins_url; 351 352 if( !empty($select_url) ) 353 { 354 $select_a_begin = '<a href="'.$select_url.'" title="'.T_('Select this skin!').'">'; 355 $select_a_end = '</a>'; 356 } 357 else 358 { 359 $select_a_begin = '<a href="'.$function_url.'" title="'.T_('Install NOW!').'">'; 360 $select_a_end = '</a>'; 361 } 362 363 echo '<div class="skinshot">'; 364 echo '<div class="skinshot_placeholder'; 365 if( $selected ) 366 { 367 echo ' current'; 368 } 369 echo '">'; 370 if( file_exists( $skins_path.$skin_folder.'/skinshot.png' ) ) 371 { 372 echo $select_a_begin; 373 echo '<img src="'.$skins_url.$skin_folder.'/skinshot.png" width="240" height="180" alt="'.$skin_folder.'" />'; 374 echo $select_a_end; 375 } 376 elseif( file_exists( $skins_path.$skin_folder.'/skinshot.jpg' ) ) 377 { 378 echo $select_a_begin; 379 echo '<img src="'.$skins_url.$skin_folder.'/skinshot.jpg" width="240" height="180" alt="'.$skin_folder.'" />'; 380 echo $select_a_end; 381 } 382 elseif( file_exists( $skins_path.$skin_folder.'/skinshot.gif' ) ) 383 { 384 echo $select_a_begin; 385 echo '<img src="'.$skins_url.$skin_folder.'/skinshot.gif" width="240" height="180" alt="'.$skin_folder.'" />'; 386 echo $select_a_end; 387 } 388 else 389 { 390 echo '<div class="skinshot_noshot">'.T_('No skinshot available for').'</div>'; 391 echo '<div class="skinshot_name">'.$select_a_begin.$skin_folder.$select_a_end.'</div>'; 392 } 393 echo '</div>'; 394 echo '<div class="legend">'; 395 if( !empty( $function) ) 396 { 397 echo '<div class="actions">'; 398 switch( $function ) 399 { 400 case 'install': 401 echo '<a href="'.$function_url.'" title="'.T_('Install NOW!').'">'; 402 echo T_('Install NOW!').'</a>'; 403 break; 404 405 case 'select': 406 echo '<a href="'.$function_url.'" target="_blank" title="'.T_('Preview blog with this skin in a new window').'">'; 407 echo T_('Preview').'</a>'; 408 break; 409 } 410 echo '</div>'; 411 } 412 echo '<strong>'.$skin_folder.'</strong>'; 413 echo '</div>'; 414 echo '</div>'; 415 } 416 417 418 } 419 420 421 /* 422 * $Log: _skin.class.php,v $ 423 * Revision 1.6 2007/10/08 08:32:56 fplanque 424 * widget fixes 425 * 426 * Revision 1.5 2007/09/29 03:42:12 fplanque 427 * skin install UI improvements 428 * 429 * Revision 1.4 2007/09/12 01:18:32 fplanque 430 * translation updates 431 * 432 * Revision 1.3 2007/07/09 19:49:29 fplanque 433 * Look for containers in all skin templates. 434 * 435 * Revision 1.2 2007/06/27 02:23:24 fplanque 436 * new default template for skins named index.main.php 437 * 438 * Revision 1.1 2007/06/25 11:01:32 fplanque 439 * MODULES (refactored MVC) 440 * 441 * Revision 1.21 2007/06/24 18:28:55 fplanque 442 * refactored skin install 443 * 444 * Revision 1.20 2007/06/20 21:42:13 fplanque 445 * implemented working widget/plugin params 446 * 447 * Revision 1.19 2007/05/28 01:36:24 fplanque 448 * enhanced blog list widget 449 * 450 * Revision 1.18 2007/05/08 00:42:07 fplanque 451 * public blog list as a widget 452 * 453 * Revision 1.17 2007/05/07 23:26:19 fplanque 454 * public blog list as a widget 455 * 456 * Revision 1.16 2007/05/07 18:59:45 fplanque 457 * renamed skin .page.php files to .tpl.php 458 * 459 * Revision 1.15 2007/04/26 00:11:12 fplanque 460 * (c) 2007 461 * 462 * Revision 1.14 2007/03/19 21:21:00 blueyed 463 * fixed typo 464 * 465 * Revision 1.13 2007/03/18 01:39:54 fplanque 466 * renamed _main.php to main.page.php to comply with 2.0 naming scheme. 467 * (more to come) 468 * 469 * Revision 1.12 2007/02/05 00:35:43 fplanque 470 * small adjustments 471 * 472 * Revision 1.11 2007/01/23 21:45:25 fplanque 473 * "enforce" foreign keys 474 * 475 * Revision 1.10 2007/01/14 00:45:13 fplanque 476 * bugfix 477 * 478 * Revision 1.9 2007/01/13 18:37:29 fplanque 479 * doc 480 * 481 * Revision 1.8 2007/01/12 02:40:26 fplanque 482 * widget default params proof of concept 483 * (param customization to be done) 484 * 485 * Revision 1.7 2007/01/12 00:39:11 fplanque 486 * bugfix 487 * 488 * Revision 1.6 2007/01/11 20:44:19 fplanque 489 * skin containers proof of concept 490 * (no params handling yet though) 491 * 492 * Revision 1.5 2007/01/08 02:11:56 fplanque 493 * Blogs now make use of installed skins 494 * next step: make use of widgets inside of skins 495 * 496 * Revision 1.4 2007/01/07 23:38:20 fplanque 497 * discovery of skin containers 498 * 499 * Revision 1.3 2007/01/07 19:40:18 fplanque 500 * discover skin containers 501 * 502 * Revision 1.2 2007/01/07 05:32:11 fplanque 503 * added some more DB skin handling (install+uninstall+edit properties ok) 504 * still useless though :P 505 * next step: discover containers in installed skins 506 * 507 * Revision 1.1 2006/12/29 01:10:06 fplanque 508 * basic skin registering 509 * 510 */ 511 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
|