[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements support functions for the installer 4 * 5 * b2evolution - {@link http://b2evolution.net/} 6 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html} 7 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 8 * 9 * @package install 10 */ 11 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 12 13 14 /** 15 * This will offer other display methods in the future 16 */ 17 function task_begin( $title ) 18 { 19 echo $title; 20 } 21 22 23 /** 24 * This will offer other display methods in the future 25 */ 26 function task_end() 27 { 28 echo "OK.<br />\n"; 29 flush(); 30 } 31 32 33 34 /** 35 * check_db_version(-) 36 * 37 * Note: version number 8000 once meant 0.8.00.0, but I decided to switch to sequential 38 * increments of 10 (in case we ever need to introduce intermediate versions for intermediate 39 * bug fixes...) 40 */ 41 function check_db_version() 42 { 43 global $DB, $old_db_version, $new_db_version; 44 45 echo '<p>'.T_('Checking DB schema version...').' '; 46 47 if( db_col_exists( 'T_settings', 'set_name' ) ) 48 { // we have new table format (since 0.9) 49 $old_db_version = $DB->get_var( 'SELECT set_value FROM T_settings WHERE set_name = "db_version"' ); 50 } 51 else 52 { 53 $old_db_version = $DB->get_var( 'SELECT db_version FROM T_settings' ); 54 } 55 56 if( empty($old_db_version) ) debug_die( T_('NOT FOUND! This is not a b2evolution database.') ); 57 58 echo $old_db_version, ' : '; 59 60 if( $old_db_version < 8000 ) debug_die( T_('This version is too old!') ); 61 if( $old_db_version > $new_db_version ) debug_die( T_('This version is too recent! We cannot downgrade to it!') ); 62 echo "OK.<br />\n"; 63 } 64 65 66 /** 67 * Clean up extra quotes in posts 68 */ 69 function cleanup_post_quotes( $col_ID = 'ID' ) 70 { 71 global $DB; 72 73 echo "Checking for extra quote escaping in posts... "; 74 $query = "SELECT $col_ID, post_title, post_content 75 FROM T_items__item 76 WHERE post_title LIKE '%\\\\\\\\\'%' 77 OR post_title LIKE '%\\\\\\\\\"%' 78 OR post_content LIKE '%\\\\\\\\\'%' 79 OR post_content LIKE '%\\\\\\\\\"%' "; 80 /* FP: the above looks overkill, but MySQL is really full of surprises... 81 tested on 4.0.14-nt */ 82 // echo $query; 83 $rows = $DB->get_results( $query, ARRAY_A ); 84 if( $DB->num_rows ) 85 { 86 echo 'Updating '.$DB->num_rows.' posts... '; 87 foreach( $rows as $row ) 88 { 89 // echo '<br />'.$row['post_title']; 90 $query = "UPDATE T_items__item 91 SET post_title = ".$DB->quote( stripslashes( $row['post_title'] ) ).", 92 post_content = ".$DB->quote( stripslashes( $row['post_content'] ) )." 93 WHERE $col_ID = ".$row[$col_ID]; 94 // echo '<br />'.$query; 95 $DB->query( $query ); 96 } 97 } 98 echo "OK.<br />\n"; 99 100 } 101 102 /** 103 * Clean up extra quotes in comments 104 */ 105 function cleanup_comment_quotes() 106 { 107 global $DB; 108 109 echo "Checking for extra quote escaping in comments... "; 110 $query = "SELECT comment_ID, comment_content 111 FROM T_comments 112 WHERE comment_content LIKE '%\\\\\\\\\'%' 113 OR comment_content LIKE '%\\\\\\\\\"%' "; 114 /* FP: the above looks overkill, but MySQL is really full of surprises... 115 tested on 4.0.14-nt */ 116 // echo $query; 117 $rows = $DB->get_results( $query, ARRAY_A ); 118 if( $DB->num_rows ) 119 { 120 echo 'Updating '.$DB->num_rows.' comments... '; 121 foreach( $rows as $row ) 122 { 123 $query = "UPDATE T_comments 124 SET comment_content = ".$DB->quote( stripslashes( $row['comment_content'] ) )." 125 WHERE comment_ID = ".$row['comment_ID']; 126 // echo '<br />'.$query; 127 $DB->query( $query ); 128 } 129 } 130 echo "OK.<br />\n"; 131 132 } 133 134 135 /** 136 * Validate install requirements. 137 * 138 * @return array List of errors, empty array if ok. 139 */ 140 function install_validate_requirements() 141 { 142 $errors = array(); 143 144 return $errors; 145 } 146 147 148 /** 149 * Insert default settings into T_settings. 150 * 151 * It only writes those to DB, that get overridden (passed as array), or have 152 * no default in {@link _generalsettings.class.php} / {@link GeneralSettings::default}. 153 * 154 * @param array associative array (settings name => value to use), allows 155 * overriding of defaults 156 */ 157 function create_default_settings( $override = array() ) 158 { 159 global $DB, $new_db_version, $default_locale, $Group_Users; 160 161 $defaults = array( 162 'db_version' => $new_db_version, 163 'default_locale' => $default_locale, 164 'newusers_grp_ID' => $Group_Users->ID, 165 ); 166 167 $settings = array_merge( array_keys($defaults), array_keys($override) ); 168 $settings = array_unique( $settings ); 169 $insertvalues = array(); 170 foreach( $settings as $name ) 171 { 172 if( isset($override[$name]) ) 173 { 174 $insertvalues[] = '('.$DB->quote($name).', '.$DB->quote($override[$name]).')'; 175 } 176 else 177 { 178 $insertvalues[] = '('.$DB->quote($name).', '.$DB->quote($defaults[$name]).')'; 179 } 180 } 181 182 echo 'Creating default settings'.( count($override) ? ' (with '.count($override).' existing values)' : '' ).'... '; 183 $DB->query( 184 "INSERT INTO T_settings (set_name, set_value) 185 VALUES ".implode( ', ', $insertvalues ) ); 186 echo "OK.<br />\n"; 187 } 188 189 190 /** 191 * Install basic skins. 192 */ 193 function install_basic_skins() 194 { 195 load_class( 'skins/model/_skin.class.php' ); 196 197 echo 'Installing default skins... '; 198 199 // Note: Skin #1 will we used by default by auto-installed blogs. 200 $Skin = new Skin(); 201 $Skin->install( 'evopress' ); 202 203 $Skin = new Skin(); 204 $Skin->install( 'asevo' ); 205 206 $Skin = new Skin(); 207 $Skin->install( 'custom' ); 208 209 $Skin = new Skin(); 210 $Skin->install( 'evocamp' ); 211 212 $Skin = new Skin(); 213 $Skin->install( 'natural_pink' ); 214 215 $Skin = new Skin(); 216 $Skin->install( 'nifty_corners' ); 217 218 $Skin = new Skin(); 219 $Skin->install( 'photoblog' ); 220 221 222 $Skin = new Skin(); 223 $Skin->install( '_atom', 'Atom' ); 224 225 $Skin = new Skin(); 226 $Skin->install( '_rss2', 'RSS 2.0' ); 227 228 echo "OK.<br />\n"; 229 } 230 231 232 /** 233 * Install basic plugins. 234 * 235 * This gets called separately on fresh installs. 236 * 237 * {@internal 238 * NOTE: this won't call the "AfterInstall" method on the plugin nor install its DB schema. 239 * This get done in the plugins controller, on manually installing a plugin. 240 * 241 * If you change the number of plugins here, please also adjust {@link InstallUnitTestCase::nr_of_basic_plugins}. 242 * }} 243 * 244 * @param integer Old DB version, so that only new plugins gets installed 245 */ 246 function install_basic_plugins( $old_db_version = 0 ) 247 { 248 $Plugins_admin = & get_Cache('Plugins_admin'); 249 250 if( $old_db_version < 9100 ) 251 { 252 echo 'Installing default plugins... '; 253 // Toolbars: 254 $Plugins_admin->install( 'quicktags_plugin' ); 255 // Renderers: 256 $Plugins_admin->install( 'auto_p_plugin' ); 257 $Plugins_admin->install( 'autolinks_plugin' ); 258 $Plugins_admin->install( 'texturize_plugin' ); 259 $Plugins_admin->install( 'smilies_plugin' ); 260 $Plugins_admin->install( 'code_highlight_plugin' ); 261 $Plugins_admin->install( 'videoplug_plugin' ); 262 // SkinTags: 263 $Plugins_admin->install( 'calendar_plugin' ); 264 $Plugins_admin->install( 'archives_plugin' ); 265 echo "OK.<br />\n"; 266 } 267 268 if( $old_db_version < 9330 ) 269 { // Upgrade to 1.9-beta 270 echo 'Installing default ping plugins... '; 271 $Plugins_admin->install( 'ping_b2evonet_plugin' ); 272 $Plugins_admin->install( 'ping_pingomatic_plugin' ); 273 echo "OK.<br />\n"; 274 } 275 } 276 277 278 /** 279 * Install basic widgets. 280 */ 281 function install_basic_widgets() 282 { 283 global $DB; 284 285 echo 'Installing default widgets... '; 286 287 // Add nlog list to all blog Page Tops: 288 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 289 SELECT blog_ID, "Page Top", 1, "core", "colls_list_public" 290 FROM T_blogs' ); 291 292 // Add title to all blog Headers: 293 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 294 SELECT blog_ID, "Header", 1, "core", "coll_title" 295 FROM T_blogs' ); 296 // Add tagline to all blogs Headers: 297 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 298 SELECT blog_ID, "Header", 2, "core", "coll_tagline" 299 FROM T_blogs' ); 300 301 // Add home link to all blogs Menus: 302 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params ) 303 SELECT blog_ID, "Menu", 1, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'home'))).'" 304 FROM T_blogs' ); 305 // Add info pages to all blogs Menus: 306 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 307 SELECT blog_ID, "Menu", 2, "core", "coll_page_list" 308 FROM T_blogs' ); 309 // Add contact link to all blogs Menus: 310 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params ) 311 SELECT blog_ID, "Menu", 3, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'ownercontact'))).'" 312 FROM T_blogs' ); 313 // Add login link to all blogs Menus: 314 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code, wi_params ) 315 SELECT blog_ID, "Menu", 4, "core", "menu_link", "'.$DB->escape(serialize(array('link_type'=>'login'))).'" 316 FROM T_blogs' ); 317 318 // Add Calendar plugin to all blog Sidebars: 319 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 320 SELECT blog_ID, "Sidebar", 1, "plugin", "evo_Calr" 321 FROM T_blogs' ); 322 // Add title to all blog Sidebars: 323 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 324 SELECT blog_ID, "Sidebar", 2, "core", "coll_title" 325 FROM T_blogs' ); 326 // Add longdesc to all blogs Sidebars: 327 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 328 SELECT blog_ID, "Sidebar", 3, "core", "coll_longdesc" 329 FROM T_blogs' ); 330 // Add common links to all blogs Sidebars: 331 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 332 SELECT blog_ID, "Sidebar", 4, "core", "coll_common_links" 333 FROM T_blogs' ); 334 // Add search form to all blogs Sidebars: 335 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 336 SELECT blog_ID, "Sidebar", 5, "core", "coll_search_form" 337 FROM T_blogs' ); 338 // Add categories list to all blog Sidebars: 339 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 340 SELECT blog_ID, "Sidebar", 6, "core", "coll_category_list" 341 FROM T_blogs' ); 342 // Add XML feeds to all blogs Sidebars: 343 $DB->query( 'INSERT INTO T_widget( wi_coll_ID, wi_sco_name, wi_order, wi_type, wi_code ) 344 SELECT blog_ID, "Sidebar", 7, "core", "coll_xml_feeds" 345 FROM T_blogs' ); 346 347 echo "OK.<br />\n"; 348 } 349 350 351 352 function advanced_properties() 353 { 354 /* 355 // file_path needs to be case sensitive on unix 356 // Note: it should be ok on windows too if we take care of updating the db on case renames 357 ALTER TABLE `T_files` CHANGE `file_path` `file_path` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL 358 or 359 ALTER TABLE `T_files` CHANGE `file_path` `file_path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL 360 */ 361 } 362 363 364 /** 365 * Create relations 366 * 367 * @todo NOT UP TO DATE AT ALL :( -- update field names before activating this 368 */ 369 function create_relations() 370 { 371 global $DB, $db_use_fkeys; 372 373 if( !$db_use_fkeys ) 374 return false; 375 376 echo 'Creating relations... '; 377 378 $DB->query( 'alter table T_coll_user_perms 379 add constraint FK_bloguser_blog_ID 380 foreign key (bloguser_blog_ID) 381 references T_blogs (blog_ID) 382 on delete restrict 383 on update restrict' ); 384 385 $DB->query( 'alter table T_coll_user_perms 386 add constraint FK_bloguser_user_ID 387 foreign key (bloguser_user_ID) 388 references T_users (user_ID) 389 on delete restrict 390 on update restrict' ); 391 392 $DB->query( 'alter table T_categories 393 add constraint FK_cat_blog_ID 394 foreign key (cat_blog_ID) 395 references T_blogs (blog_ID) 396 on delete restrict 397 on update restrict, 398 add constraint FK_cat_parent_ID 399 foreign key (cat_parent_ID) 400 references T_categories (cat_ID) 401 on delete restrict 402 on update restrict' ); 403 404 $DB->query( 'alter table T_comments 405 add constraint FK_comment_post_ID 406 foreign key (comment_post_ID) 407 references T_items__item (post_ID) 408 on delete restrict 409 on update restrict' ); 410 411 $DB->query( 'alter table T_postcats 412 add constraint FK_postcat_cat_ID 413 foreign key (postcat_cat_ID) 414 references T_categories (cat_ID) 415 on delete restrict 416 on update restrict, 417 add constraint FK_postcat_post_ID 418 foreign key (postcat_post_ID) 419 references T_items__item (post_ID) 420 on delete restrict 421 on update restrict' ); 422 423 $DB->query( 'alter table T_items__item 424 add constraint FK_post_assigned_user_ID 425 foreign key (post_assigned_user_ID) 426 references T_users (user_ID) 427 on delete restrict 428 on update restrict, 429 add constraint FK_post_lastedit_user_ID 430 foreign key (post_lastedit_user_ID) 431 references T_users (user_ID) 432 on delete restrict 433 on update restrict, 434 add constraint FK_post_creator_user_ID 435 foreign key (post_creator_user_ID) 436 references T_users (user_ID) 437 on delete restrict 438 on update restrict, 439 add constraint FK_post_main_cat_ID 440 foreign key (post_main_cat_ID) 441 references T_categories (cat_ID) 442 on delete restrict 443 on update restrict, 444 add constraint FK_post_parent_ID 445 foreign key (post_parent_ID) 446 references T_items__item (post_ID) 447 on delete restrict 448 on update restrict, 449 add constraint FK_post_pst_ID 450 foreign key (post_pst_ID) 451 references T_items__status (pst_ID) 452 on delete restrict 453 on update restrict, 454 add constraint FK_post_ptyp_ID 455 foreign key (post_ptyp_ID) 456 references T_items__type (ptyp_ID) 457 on delete restrict 458 on update restrict' ); 459 460 $DB->query( 'alter table T_links 461 add constraint FK_link_creator_user_ID 462 foreign key (link_creator_user_ID) 463 references T_users (user_ID) 464 on delete restrict 465 on update restrict' ); 466 $DB->query( 'alter table T_links 467 add constraint FK_link_lastedit_user_ID 468 foreign key (link_lastedit_user_ID) 469 references T_users (user_ID) 470 on delete restrict 471 on update restrict' ); 472 $DB->query( 'alter table T_links 473 add constraint FK_link_dest_itm_ID 474 foreign key (link_dest_itm_ID) 475 references T_items__item (post_ID) 476 on delete restrict 477 on update restrict' ); 478 $DB->query( 'alter table T_links 479 add constraint FK_link_file_ID 480 foreign key (link_file_ID) 481 references T_files (file_ID) 482 on delete restrict 483 on update restrict' ); 484 $DB->query( 'alter table T_links 485 add constraint FK_link_itm_ID 486 foreign key (link_itm_ID) 487 references T_items__item (post_ID) 488 on delete restrict 489 on update restrict' ); 490 491 $DB->query( 'alter table T_pluginsettings 492 add constraint FK_pset_plug_ID 493 foreign key (pset_plug_ID) 494 references T_plugins (plug_ID) 495 on delete restrict 496 on update restrict' ); 497 498 $DB->query( 'alter table T_pluginusersettings 499 add constraint FK_puset_plug_ID 500 foreign key (puset_plug_ID) 501 references T_plugins (plug_ID) 502 on delete restrict 503 on update restrict' ); 504 505 $DB->query( 'alter table T_pluginevents 506 add constraint FK_pevt_plug_ID 507 foreign key (pevt_plug_ID) 508 references T_plugins (plug_ID) 509 on delete restrict 510 on update restrict' ); 511 512 $DB->query( 'alter table T_users 513 add constraint FK_user_grp_ID 514 foreign key (user_grp_ID) 515 references T_groups (grp_ID) 516 on delete restrict 517 on update restrict' ); 518 519 $DB->query( 'alter table T_usersettings 520 add constraint FK_uset_user_ID 521 foreign key (uset_user_ID) 522 references T_users (user_ID) 523 on delete restrict 524 on update restrict' ); 525 526 $DB->query( 'alter table T_subscriptions 527 add constraint FK_sub_coll_ID 528 foreign key (sub_coll_ID) 529 references T_blogs (blog_ID) 530 on delete restrict 531 on update restrict' ); 532 533 $DB->query( 'alter table T_subscriptions 534 add constraint FK_sub_user_ID 535 foreign key (sub_user_ID) 536 references T_users (user_ID) 537 on delete restrict 538 on update restrict' ); 539 540 echo "OK.<br />\n"; 541 } 542 543 544 /* 545 * $Log: _functions_install.php,v $ 546 * Revision 1.38 2007/10/08 21:30:19 fplanque 547 * evocamp skin 548 * 549 * Revision 1.37 2007/10/08 08:32:56 fplanque 550 * widget fixes 551 * 552 * Revision 1.36 2007/10/01 01:06:31 fplanque 553 * Skin/template functions cleanup. 554 * 555 * Revision 1.35 2007/09/28 02:17:48 fplanque 556 * Menu widgets 557 * 558 * Revision 1.34 2007/09/19 02:54:16 fplanque 559 * bullet proof upgrade 560 * 561 * Revision 1.33 2007/09/08 23:46:38 fplanque 562 * made evopress the new default skin 563 * 564 * Revision 1.32 2007/09/03 16:46:58 fplanque 565 * minor 566 * 567 * Revision 1.31 2007/08/21 22:32:31 blueyed 568 * Use get_Cache() for singleton $Plugins_admin instance. This fixes at least the installation of flickr_plugin. 569 * 570 * Revision 1.30 2007/07/01 18:49:40 fplanque 571 * evopress skin (tentative) 572 * 573 * Revision 1.29 2007/07/01 03:55:04 fplanque 574 * category plugin replaced by widget 575 * 576 * Revision 1.28 2007/06/25 11:02:30 fplanque 577 * MODULES (refactored MVC) 578 * 579 * Revision 1.27 2007/06/24 18:28:55 fplanque 580 * refactored skin install 581 * 582 * Revision 1.26 2007/05/14 02:43:06 fplanque 583 * Started renaming tables. There probably won't be a better time than 2.0. 584 * 585 * Revision 1.25 2007/05/13 20:44:52 fplanque 586 * more pages support 587 * 588 * Revision 1.24 2007/05/09 01:58:57 fplanque 589 * Widget to display other blogs from same owner 590 * 591 * Revision 1.23 2007/05/08 19:36:06 fplanque 592 * automatic install of public blog list widget on new blogs 593 * 594 * Revision 1.22 2007/05/07 23:26:19 fplanque 595 * public blog list as a widget 596 * 597 * Revision 1.21 2007/04/26 00:11:10 fplanque 598 * (c) 2007 599 * 600 * Revision 1.20 2007/04/20 02:31:06 fplanque 601 * more default plugins 602 * 603 * Revision 1.19 2007/01/19 09:31:04 fplanque 604 * Provision for case sensitive file meta data handling 605 * 606 * Revision 1.18 2007/01/15 19:10:29 fplanque 607 * install refactoring 608 * 609 * Revision 1.17 2006/11/17 01:46:16 fplanque 610 * Fixed broken upgrade path. 611 * 612 * Revision 1.16 2006/11/01 00:24:07 blueyed 613 * Fixed cafelog upgrade 614 * 615 * Revision 1.15 2006/09/08 15:35:36 blueyed 616 * Completely nuked tokenizer dependency - removed commented out block 617 * 618 * Revision 1.14 2006/08/20 20:54:31 blueyed 619 * Removed dependency on tokenizer. Quite a few people don't have it.. see http://forums.b2evolution.net//viewtopic.php?t=8664 620 * 621 * Revision 1.13 2006/07/04 17:32:30 fplanque 622 * no message 623 * 624 * Revision 1.12 2006/06/19 20:59:38 fplanque 625 * noone should die anonymously... 626 * 627 * Revision 1.11 2006/04/06 08:52:27 blueyed 628 * Validate install "misc" requirements ("tokenizer" support for now) 629 * 630 * Revision 1.10 2005/12/30 18:08:24 fplanque 631 * no message 632 * 633 */ 634 ?>
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 |
![]() |