b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: install ] [ index: install ] [ all elements ]

Source for file _functions_install.php

Documentation is available at _functions_install.php

  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-2010 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.  * Open a block
  15.  */
  16. function block_open()
  17. {
  18.     global $block_status;
  19.     ifisset($block_status&& $block_status == 'open' )
  20.     {
  21.         return;
  22.     }
  23.     $block_status 'open';
  24.     echo '<div class="block1"><div class="block2"><div class="block3">';
  25. }
  26.  
  27. /**
  28.  * Close a block
  29.  */
  30. function block_close()
  31. {
  32.     global $block_status;
  33.     if!isset($block_status|| $block_status == 'closed' )
  34.     {
  35.         return;
  36.     }
  37.     $block_status 'closed';
  38.     echo '</div></div></div>';
  39. }
  40.  
  41. /**
  42.  * Language selector
  43.  */
  44. {
  45.     global $locales$default_locale$action;
  46.  
  47.     static $selector_already_displayed false;
  48.  
  49.     if$selector_already_displayed )
  50.     {
  51.         return;
  52.     }
  53.     $selector_already_displayed true;
  54.     block_open();
  55.     ?>
  56.     <h2><?php echo T_('Language / Locale')?></h2>
  57.     <form action="index.php" method="get">
  58.     <?php
  59.     echo '<div class="floatright"><a href="index.php?action=localeinfo&amp;locale='.$default_locale.'">'.T_('More languages').' &raquo;</a></div>';
  60.  
  61.     locale_flag$default_locale'w16px''flag'''true/* Do not rely on $baseurl/$rsc_url here: */ '../rsc/flags' );
  62.     echo '<select name="locale" onchange="this.form.submit()">';
  63.     foreach$locales as $lkey => $lvalue )
  64.     {
  65.         echo '<option';
  66.         if$default_locale == $lkey echo ' selected="selected"';
  67.         echo ' value="'.$lkey.'">';
  68.         echo T_$lvalue['name');
  69.         echo '</option>';
  70.     }
  71.     ?>
  72.     </select>
  73.     <noscript>
  74.         <input type="submit" value="<?php echo T_('Select as default language/locale')?>" />
  75.     </noscript>
  76.     </form>
  77.     <?php
  78.     block_close();
  79. }
  80.  
  81. /**
  82.  * Base config recap
  83.  */
  84. {
  85.     global $default_locale$conf_db_user$conf_db_password$conf_db_name$conf_db_host$db_config$tableprefix$baseurl$admin_email;
  86.  
  87.     static $base_config_recap_already_displayed false;
  88.  
  89.     if$base_config_recap_already_displayed )
  90.     {
  91.         return;
  92.     }
  93.     $base_config_recap_already_displayed true;
  94.  
  95.     block_open();
  96.     ?>
  97.     <h2><?php echo T_('Base config recap...')?></h2>
  98.  
  99.     <p><?php printfT_('If you don\'t see correct settings here, STOP before going any further, and <a %s>update your base configuration</a>.')'href="index.php?action=start&amp;locale='.$default_locale.'"' ?></p>
  100.  
  101.     <?php
  102.     if!isset($conf_db_user) ) $conf_db_user $db_config['user'];
  103.     if!isset($conf_db_password) ) $conf_db_password $db_config['password'];
  104.     if!isset($conf_db_name) ) $conf_db_name $db_config['name'];
  105.     if!isset($conf_db_host) ) $conf_db_host $db_config['host'];
  106.  
  107.     echo '<pre>',
  108.     T_('MySQL Username').': '.$conf_db_user."\n".
  109.     T_('MySQL Password').': '.(($conf_db_password != 'demopass' T_('(Set, but not shown for security reasons)''demopass') )."\n".
  110.     T_('MySQL Database name').': '.$conf_db_name."\n".
  111.     T_('MySQL Host/Server').': '.$conf_db_host."\n".
  112.     T_('MySQL tables prefix').': '.$tableprefix."\n\n".
  113.     T_('Base URL').': '.$baseurl."\n\n".
  114.     T_('Admin email').': '.$admin_email.
  115.     '</pre>';
  116.     block_close();
  117. }
  118.  
  119.  
  120. /**
  121.  * Install new DB.
  122.  */
  123. function install_newdb()
  124. {
  125.     global $new_db_version$admin_url$random_password;
  126.  
  127.     /*
  128.      * -----------------------------------------------------------------------------------
  129.      * NEW DB: Create a plain new db structure + sample contents
  130.      * -----------------------------------------------------------------------------------
  131.      */
  132.     require_once dirname(__FILE__).'/_functions_create.php';
  133.  
  134.     if$old_db_version get_db_version() )
  135.     {
  136.         echo '<p><strong>'.T_('OOPS! It seems b2evolution is already installed!').'</strong></p>';
  137.  
  138.         if$old_db_version $new_db_version )
  139.         {
  140.             echo '<p>'.sprintfT_('Would you like to <a %s>upgrade your existing installation now</a>?')'href="?action=evoupgrade"' ).'</p>';
  141.         }
  142.  
  143.         return;
  144.     }
  145.  
  146.     $installer_version param'installer_version''integer');
  147.     if$installer_version >= 10 )
  148.     {
  149.         $create_sample_contents param'create_sample_contents''integer');
  150.     }
  151.     else
  152.     {    // OLD INSTALLER call. Probably an automated script calling.
  153.         // Let's force the sample contents since they haven't been explicitely disabled
  154.         $create_sample_contents 1;
  155.     }
  156.  
  157.     echo '<h2>'.T_('Creating b2evolution tables...').'</h2>';
  158.     flush();
  159.     create_tables();
  160.  
  161.     echo '<h2>'.T_('Creating minimum default data...').'</h2>';
  162.     flush();
  163.  
  164.     if$create_sample_contents )
  165.     {
  166.         global $Settings;
  167.  
  168.         echo '<h2>'.T_('Installing sample contents...').'</h2>';
  169.         flush();
  170.  
  171.         // We're gonna need some environment in order to create the demo contents...
  172.         load_class'settings/model/_generalsettings.class.php''GeneralSettings' );
  173.         load_class'users/model/_usersettings.class.php''UserSettings' );
  174.         /**
  175.          * @var GeneralSettings
  176.          */
  177.         $Settings new GeneralSettings();
  178.  
  179.         /**
  180.          * @var UserCache
  181.          */
  182.         $UserCache get_UserCache();
  183.         // Create $current_User object.
  184.         // (Assigning by reference does not work with "global" keyword (PHP 5.2.8))
  185.         $GLOBALS['current_User'$UserCache->get_by_ID);
  186.  
  187.         create_demo_contents();
  188.     }
  189.  
  190.     echo '<h2>'.T_('Installation successful!').'</h2>';
  191.  
  192.     echo '<p><strong>';
  193.     printfT_('Now you can <a %s>log in</a> with the following credentials:')'href="'.$admin_url.'"' );
  194.     echo '</strong></p>';
  195.  
  196.     echo '<table>';
  197.     echo '<tr><td>'T_'Login' )': &nbsp;</td><td><strong><evo:password>admin</evo:password></strong></td></tr>';
  198.     printf'<tr><td>%s: &nbsp;</td><td><strong><evo:password>%s</evo:password></strong></td></tr>'T_'Password' )$random_password );
  199.     echo '</table>';
  200.  
  201.     echo '<p>'.T_('Note that password carefully! It is a <em>random</em> password that is given to you when you install b2evolution. If you lose it, you will have to delete the database tables and re-install anew.').'</p>';
  202. }
  203.  
  204.  
  205. /**
  206.  * Begin install task.
  207.  * This will offer other display methods in the future
  208.  */
  209. function task_begin$title )
  210. {
  211.     echo $title;
  212. }
  213.  
  214.  
  215. /**
  216.  * End install task.
  217.  * This will offer other display methods in the future
  218.  */
  219. function task_end()
  220. {
  221.     echo "OK.<br />\n";
  222.     flush();
  223. }
  224.  
  225.  
  226. function get_db_version()
  227. {
  228.     global $DB;
  229.  
  230.     $DB->save_error_state();
  231.     $DB->halt_on_error false;
  232.     $DB->show_errors false;
  233.     $DB->log_errors false;
  234.  
  235.     $r NULL;
  236.  
  237.     ifdb_col_exists'T_settings''set_name' ) )
  238.     // we have new table format (since 0.9)
  239.         $r $DB->get_var'SELECT set_value FROM T_settings WHERE set_name = "db_version"' );
  240.     }
  241.     else
  242.     {
  243.         $r $DB->get_var'SELECT db_version FROM T_settings' );
  244.     }
  245.  
  246.     $DB->restore_error_state();
  247.  
  248.     return $r;
  249. }
  250.  
  251.  
  252. /**
  253.  * @return boolean Does a given column name exist in DB?
  254.  */
  255. function db_col_exists$table$col_name )
  256. {
  257.     global $DB;
  258.  
  259.     $col_name strtolower($col_name);
  260.  
  261.     $r false;
  262.     $DB->save_error_state();
  263.     foreach$DB->get_results('SHOW COLUMNS FROM '.$tableas $row )
  264.     {
  265.         ifstrtolower($row->Field== $col_name )
  266.         {
  267.             $r true;
  268.             break;
  269.         }
  270.     }
  271.     $DB->restore_error_state();
  272.  
  273.     return $r;
  274. }
  275.  
  276.  
  277. /**
  278.  * Clean up extra quotes in comments
  279.  */
  280. {
  281.   global $DB;
  282.  
  283.     echo "Checking for extra quote escaping in comments... ";
  284.     $query "SELECT comment_ID, comment_content
  285.                             FROM T_comments
  286.                          WHERE comment_content LIKE '%\\\\\\\\\'%'
  287.                                  OR comment_content LIKE '%\\\\\\\\\"%' ";
  288.     /* FP: the above looks overkill, but MySQL is really full of surprises...
  289.                     tested on 4.0.14-nt */
  290.     // echo $query;
  291.     $rows $DB->get_results$queryARRAY_A );
  292.     if$DB->num_rows )
  293.     {
  294.         echo 'Updating '.$DB->num_rows.' comments... ';
  295.         foreach$rows as $row )
  296.         {
  297.             $query "UPDATE T_comments
  298.                                 SET comment_content = ".$DB->quotestripslashes$row['comment_content') )."
  299.                                 WHERE comment_ID = ".$row['comment_ID'];
  300.             // echo '<br />'.$query;
  301.             $DB->query$query );
  302.         }
  303.     }
  304.     echo "OK.<br />\n";
  305.  
  306. }
  307.  
  308.  
  309. /**
  310.  * Validate install requirements.
  311.  *
  312.  * @return array List of errors, empty array if ok.
  313.  */
  314. {
  315.     $errors array();
  316.  
  317.     return $errors;
  318. }
  319.  
  320.  
  321. /**
  322.  * Insert default settings into T_settings.
  323.  *
  324.  * It only writes those to DB, that get overridden (passed as array), or have
  325.  * no default in {@link _generalsettings.class.php} / {@link GeneralSettings::default}.
  326.  *
  327.  * @param array associative array (settings name => value to use), allows
  328.  *               overriding of defaults
  329.  */
  330. function create_default_settings$override array() )
  331. {
  332.     global $DB$new_db_version$default_locale$Group_Users;
  333.  
  334.     $defaults array(
  335.         'db_version' => $new_db_version,
  336.         'default_locale' => $default_locale,
  337.         'newusers_grp_ID' => $Group_Users->ID,
  338.         'default_blog_ID' => 1,
  339.     );
  340.  
  341.     $settings array_mergearray_keys($defaults)array_keys($override) );
  342.     $settings array_unique$settings );
  343.     $insertvalues array();
  344.     foreach$settings as $name )
  345.     {
  346.         ifisset($override[$name]) )
  347.         {
  348.             $insertvalues['('.$DB->quote($name).', '.$DB->quote($override[$name]).')';
  349.         }
  350.         else
  351.         {
  352.             $insertvalues['('.$DB->quote($name).', '.$DB->quote($defaults[$name]).')';
  353.         }
  354.     }
  355.  
  356.     echo 'Creating default settings'.count($override' (with '.count($override).' existing values)' '' ).'... ';
  357.     $DB->query(
  358.         "INSERT INTO T_settings (set_name, set_value)
  359.         VALUES ".implode', '$insertvalues ) );
  360.     echo "OK.<br />\n";
  361. }
  362.  
  363.  
  364. /**
  365.  * Install basic skins.
  366.  */
  367. {
  368.     load_funcs'skins/_skin.funcs.php' );
  369.  
  370.     echo 'Installing default skins... ';
  371.  
  372.     // Note: Skin #1 will we used by Blog A
  373.     skin_install'evopress' );
  374.  
  375.     // Note: Skin #2 will we used by Blog B
  376.     skin_install'evocamp' );
  377.  
  378.     // Note: Skin #3 will we used by Linkblog
  379.     skin_install'miami_blue' );
  380.  
  381.     // Note: Skin #4 will we used by Photoblog
  382.     skin_install'photoblog' );
  383.  
  384.     skin_install'asevo' );
  385.     skin_install'custom' );
  386.     skin_install'glossyblue' );
  387.     skin_install'intense' );
  388.     skin_install'natural_pink' );
  389.     skin_install'nifty_corners' );
  390.     skin_install'pixelgreen' );
  391.     skin_install'pluralism' );
  392.     skin_install'terrafirma' );
  393.     skin_install'vastitude' );
  394.     skin_install'_atom' );
  395.     skin_install'_rss2' );
  396.  
  397.     echo "OK.<br />\n";
  398. }
  399.  
  400.  
  401. /**
  402.  * Install basic plugins.
  403.  *
  404.  * This gets called separately on fresh installs.
  405.  *
  406.  * {@internal 
  407.  * NOTE: this won't call the "AfterInstall" method on the plugin nor install its DB schema.
  408.  *       This get done in the plugins controller, on manually installing a plugin.
  409.  *
  410.  * If you change the plugins here, please also adjust {@link InstallUnitTestCase::basic_plugins}.
  411.  * }}}
  412.  *
  413.  * @param integer Old DB version, so that only new plugins gets installed
  414.  */
  415. function install_basic_plugins$old_db_version )
  416. {
  417.     /**
  418.      * @var Plugins_admin
  419.      */
  420.     global $Plugins_admin;
  421.  
  422.     $Plugins_admin get_Plugins_admin();
  423.  
  424.     // Create global $Plugins instance, which is required during installation of basic plugins,
  425.     // not only for the ones getting installed, but also during e.g. count_regs(), which instantiates
  426.     // each plugin (which may then use (User)Settings in PluginInit (through Plugin::__get)).
  427.     $GLOBALS['Plugins'$Plugins_admin;
  428.  
  429.     if$old_db_version 9100 )
  430.     {
  431.         // Toolbars:
  432.         install_plugin'quicktags_plugin' );
  433.         // Renderers:
  434.         install_plugin'auto_p_plugin' );
  435.         install_plugin'autolinks_plugin' );
  436.         install_plugin'texturize_plugin' );
  437.         install_plugin'smilies_plugin' );
  438.         install_plugin'videoplug_plugin' );
  439.         // SkinTags:
  440.         install_plugin'calendar_plugin' );
  441.         install_plugin'archives_plugin' );
  442.     }
  443.  
  444.     if$old_db_version 9330 )
  445.     // Upgrade to 1.9-beta
  446.         install_plugin'ping_b2evonet_plugin' );
  447.         install_plugin'ping_pingomatic_plugin' );
  448.     }
  449.  
  450.     if$old_db_version 9930 )
  451.     // Upgrade to 3.1.0
  452.         install_plugin'tinymce_plugin' );
  453.     }
  454.  
  455.     if$old_db_version 9940 )
  456.     // Upgrade to 3.2.0
  457.         install_plugin'twitter_plugin' );
  458.     }
  459. }
  460.  
  461.  
  462. /**
  463.  * @return true on success
  464.  */
  465. function install_plugin$plugin )
  466. {
  467.     /**
  468.      * @var Plugins_admin
  469.      */
  470.     global $Plugins_admin;
  471.  
  472.     echo 'Installing plugin: '.$plugin.'... ';
  473.     $edit_Plugin $Plugins_admin->install$plugin'broken' )// "broken" by default, gets adjusted later
  474.     ifis_a$edit_Plugin'Plugin' ) )
  475.     {
  476.         echo $edit_Plugin."<br />\n";
  477.         return false;
  478.     }
  479.  
  480.     // install_plugin_db_schema_action()
  481.  
  482.     // Try to enable plugin:
  483.     $enable_return $edit_Plugin->BeforeEnable();
  484.     if$enable_return !== true )
  485.     {
  486.         $Plugins_admin->set_Plugin_status$edit_Plugin'disabled' )// does not unregister it
  487.         echo $enable_return."<br />\n";
  488.         return false;
  489.     }
  490.  
  491.     $Plugins_admin->set_Plugin_status$edit_Plugin'enabled' );
  492.  
  493.     echo "OK.<br />\n";
  494.     return true;
  495. }
  496.  
  497.  
  498. /**
  499.  * Install basic widgets.
  500.  */
  501. {
  502.     load_funcs'widgets/_widgets.funcs.php' );
  503.  
  504.     echo 'Installing default widgets... ';
  505.  
  506.  
  507.     echo "OK.<br />\n";
  508. }
  509.  
  510.  
  511.  
  512. {
  513.     /*
  514. // file_path needs to be case sensitive on unix
  515. // Note: it should be ok on windows too if we take care of updating the db on case renames
  516. ALTER TABLE `T_files` CHANGE `file_path` `file_path` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL
  517. or
  518. ALTER TABLE `T_files` CHANGE `file_path` `file_path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
  519.     */
  520. }
  521.  
  522.  
  523. /**
  524.  * Create relations
  525.  *
  526.  * @todo NOT UP TO DATE AT ALL :( -- update field names before activating this
  527.  */
  528. function create_relations()
  529. {
  530.     global $DB;
  531.  
  532.     echo 'Creating relations... ';
  533.  
  534.     $DB->query'alter table T_coll_user_perms
  535.                                 add constraint FK_bloguser_blog_ID
  536.                                             foreign key (bloguser_blog_ID)
  537.                                             references T_blogs (blog_ID)
  538.                                             on delete restrict
  539.                                             on update restrict' );
  540.  
  541.     $DB->query'alter table T_coll_user_perms
  542.                                 add constraint FK_bloguser_user_ID
  543.                                             foreign key (bloguser_user_ID)
  544.                                             references T_users (user_ID)
  545.                                             on delete restrict
  546.                                             on update restrict' );
  547.  
  548.     $DB->query'alter table T_categories
  549.                                 add constraint FK_cat_blog_ID
  550.                                             foreign key (cat_blog_ID)
  551.                                             references T_blogs (blog_ID)
  552.                                             on delete restrict
  553.                                             on update restrict,
  554.                                 add constraint FK_cat_parent_ID
  555.                                             foreign key (cat_parent_ID)
  556.                                             references T_categories (cat_ID)
  557.                                             on delete restrict
  558.                                             on update restrict' );
  559.  
  560.     $DB->query'alter table T_comments
  561.                                 add constraint FK_comment_post_ID
  562.                                             foreign key (comment_post_ID)
  563.                                             references T_items__item (post_ID)
  564.                                             on delete restrict
  565.                                             on update restrict' );
  566.  
  567.     $DB->query'alter table T_postcats
  568.                                 add constraint FK_postcat_cat_ID
  569.                                             foreign key (postcat_cat_ID)
  570.                                             references T_categories (cat_ID)
  571.                                             on delete restrict
  572.                                             on update restrict,
  573.                                 add constraint FK_postcat_post_ID
  574.                                             foreign key (postcat_post_ID)
  575.                                             references T_items__item (post_ID)
  576.                                             on delete restrict
  577.                                             on update restrict' );
  578.  
  579.     $DB->query'alter table T_items__item
  580.                                 add constraint FK_post_assigned_user_ID
  581.                                             foreign key (post_assigned_user_ID)
  582.                                             references T_users (user_ID)
  583.                                             on delete restrict
  584.                                             on update restrict,
  585.                                 add constraint FK_post_lastedit_user_ID
  586.                                             foreign key (post_lastedit_user_ID)
  587.                                             references T_users (user_ID)
  588.                                             on delete restrict
  589.                                             on update restrict,
  590.                                 add constraint FK_post_creator_user_ID
  591.                                             foreign key (post_creator_user_ID)
  592.                                             references T_users (user_ID)
  593.                                             on delete restrict
  594.                                             on update restrict,
  595.                                 add constraint FK_post_main_cat_ID
  596.                                             foreign key (post_main_cat_ID)
  597.                                             references T_categories (cat_ID)
  598.                                             on delete restrict
  599.                                             on update restrict,
  600.                                 add constraint FK_post_parent_ID
  601.                                             foreign key (post_parent_ID)
  602.                                             references T_items__item (post_ID)
  603.                                             on delete restrict
  604.                                             on update restrict,
  605.                                 add constraint FK_post_pst_ID
  606.                                             foreign key (post_pst_ID)
  607.                                             references T_items__status (pst_ID)
  608.                                             on delete restrict
  609.                                             on update restrict,
  610.                                 add constraint FK_post_ptyp_ID
  611.                                             foreign key (post_ptyp_ID)
  612.                                             references T_items__type (ptyp_ID)
  613.                                             on delete restrict
  614.                                             on update restrict' );
  615.  
  616.     $DB->query'alter table T_links
  617.                                 add constraint FK_link_creator_user_ID
  618.                                             foreign key (link_creator_user_ID)
  619.                                             references T_users (user_ID)
  620.                                             on delete restrict
  621.                                             on update restrict' );
  622.     $DB->query'alter table T_links
  623.                                 add constraint FK_link_lastedit_user_ID
  624.                                             foreign key (link_lastedit_user_ID)
  625.                                             references T_users (user_ID)
  626.                                             on delete restrict
  627.                                             on update restrict' );
  628.     $DB->query'alter table T_links
  629.                                 add constraint FK_link_dest_itm_ID
  630.                                             foreign key (link_dest_itm_ID)
  631.                                             references T_items__item (post_ID)
  632.                                             on delete restrict
  633.                                             on update restrict' );
  634.     $DB->query'alter table T_links
  635.                                 add constraint FK_link_file_ID
  636.                                             foreign key (link_file_ID)
  637.                                             references T_files (file_ID)
  638.                                             on delete restrict
  639.                                             on update restrict' );
  640.     $DB->query'alter table T_links
  641.                                 add constraint FK_link_itm_ID
  642.                                             foreign key (link_itm_ID)
  643.                                             references T_items__item (post_ID)
  644.                                             on delete restrict
  645.                                             on update restrict' );
  646.  
  647.     $DB->query'alter table T_pluginsettings
  648.                   add constraint FK_pset_plug_ID
  649.                         foreign key (pset_plug_ID)
  650.                         references T_plugins (plug_ID)
  651.                         on delete restrict
  652.                         on update restrict' );
  653.  
  654.     $DB->query'alter table T_pluginusersettings
  655.                   add constraint FK_puset_plug_ID
  656.                         foreign key (puset_plug_ID)
  657.                         references T_plugins (plug_ID)
  658.                         on delete restrict
  659.                         on update restrict' );
  660.  
  661.     $DB->query'alter table T_pluginevents
  662.                   add constraint FK_pevt_plug_ID
  663.                         foreign key (pevt_plug_ID)
  664.                         references T_plugins (plug_ID)
  665.                         on delete restrict
  666.                         on update restrict' );
  667.  
  668.     $DB->query'alter table T_users
  669.                                 add constraint FK_user_grp_ID
  670.                                             foreign key (user_grp_ID)
  671.                                             references T_groups (grp_ID)
  672.                                             on delete restrict
  673.                                             on update restrict' );
  674.  
  675.     $DB->query'alter table T_users__usersettings
  676.                                 add constraint FK_uset_user_ID
  677.                                             foreign key (uset_user_ID)
  678.                                             references T_users (user_ID)
  679.                                             on delete restrict
  680.                                             on update restrict' );
  681.  
  682.     $DB->query'alter table T_subscriptions
  683.                                 add constraint FK_sub_coll_ID
  684.                                             foreign key (sub_coll_ID)
  685.                                             references T_blogs (blog_ID)
  686.                                             on delete restrict
  687.                                             on update restrict' );
  688.  
  689.     $DB->query'alter table T_subscriptions
  690.                                 add constraint FK_sub_user_ID
  691.                                             foreign key (sub_user_ID)
  692.                                             references T_users (user_ID)
  693.                                             on delete restrict
  694.                                             on update restrict' );
  695.  
  696.     echo "OK.<br />\n";
  697. }
  698.  
  699.  
  700. /**
  701.  * Loads the b2evo database scheme.
  702.  *
  703.  * This gets updated through {@link db_delta()} which generates the queries needed to get
  704.  * to this scheme.
  705.  *
  706.  * Please see {@link db_delta()} for things to take care of.
  707.  */
  708. function load_db_schema()
  709. {
  710.     global $schema_queries;
  711.     global $modules$inc_path;
  712.  
  713.     global $db_storage_charset$DB;
  714.     ifempty($db_storage_charset) )
  715.     {    // If no specific charset has been requested for datstorage, use the one of the current connection (optimize for speed - no conversions)
  716.         $db_storage_charset $DB->connection_charset;
  717.     }
  718.     //pre_dump( 'db_storage_charset', $db_storage_charset );
  719.  
  720.     // Load modules:
  721.     foreach$modules as $module )
  722.     {
  723.         echo 'Loading module: '.$module.'/model/_'.$module.'.install.php<br />';
  724.         require_once $inc_path.$module.'/model/_'.$module.'.install.php';
  725.     }
  726.  
  727. }
  728.  
  729.  
  730. /**
  731.  * Install htaccess: Check if it works with the webserver, then install it for real.
  732.  *
  733.  * @return string error message
  734.  */
  735. function install_htaccess$upgrade false )
  736. {
  737.     echo '<p>Preparing to install .htaccess ... ';
  738.  
  739.     $error_message do_install_htaccess$upgrade );
  740.  
  741.     if$error_message)
  742.     {
  743.         echo 'ERROR!<br/><b>'.$error_message.'</b><br />';
  744.         printfT_('Everything should still work, but for optimization you should follow <a %s>these instructions</a>.'.'</p>')'href="http://manual.b2evolution.net/Tricky_stuff" target="_blank"');
  745.     }
  746. }
  747.  
  748. /**
  749.  * This does the actual file manipulations for installing .htaccess
  750.  *
  751.  * @param boolean are we upgrading (vs installing)?
  752.  * @return mixed 
  753.  */
  754. function do_install_htaccess$upgrade false )
  755. {
  756.     global $baseurl;
  757.     global $basepath;
  758.  
  759.     if@file_exists($basepath.'.htaccess') )
  760.     {
  761.         if$upgrade )
  762.         {
  763.             echo 'Already installed.';
  764.             return ''// all is well :)
  765.         }
  766.         return 'You already have a file named .htaccess in your your base url folder.';
  767.     }
  768.  
  769.     // Make sure we have a sample file to start with:
  770.     if@file_exists($basepath.'sample.htaccess') )
  771.     {
  772.         return 'Can not find file [ sample.htaccess ] in your base url folder.';
  773.     }
  774.  
  775.     // Try to copy that file to the test folder:
  776.     if@copy$basepath.'sample.htaccess'$basepath.'install/test/.htaccess' ) )
  777.     {
  778.         return 'Failed to copy files!';
  779.     }
  780.  
  781.     // Make sure .htaccess does not crash in the test folder:
  782.     load_funcs('_core/_url.funcs.php');
  783.     $info array();
  784.     if$remote_page fetch_remote_page$baseurl.'install/test/'$info ) )
  785.     {
  786.         return $info[error];
  787.     }
  788.     if$remote_page != 'Test successful.' )
  789.     {
  790.         return 'install/test/index.html was not found as expected.';
  791.     }
  792.  
  793.     // Now we consider it's safe, copy .htaccess to its real location:
  794.     if@copy$basepath.'sample.htaccess'$basepath.'.htaccess' ) )
  795.     {
  796.         return 'Test was successful, but failed to copy .htaccess into baseurl directory!';
  797.     }
  798.  
  799.     echo 'Install successful.';
  800.     return '';
  801. }
  802.  
  803.  
  804. /**
  805.  * Return antispam SQL query.
  806.  * This is obfuscated because some hosting companies prevent uploading PHP files
  807.  * containing "spam" strings.
  808.  *
  809.  * @return string; 
  810.  */
  811. function get_antispam_query()
  812. {
  813.     //used base64_encode() for getting this code
  814.     $r base64_decode('SU5TRVJUIElOVE8gVF9hbnRpc3BhbShhc3BtX3N0cmluZykgVkFMVUVTICgnb25saW5lLWNhc2lubycpLCAoJ3BlbmlzLWVubGFyZ2VtZW50JyksICgnb3JkZXItdmlhZ3JhJyksICgnb3JkZXItcGhlbnRlcm1pbmUnKSwgKCdvcmRlci14ZW5pY2FsJyksICgnb3JkZXItcHJvcGhlY2lhJyksICgnc2V4eS1saW5nZXJpZScpLCAoJy1wb3JuLScpLCAoJy1hZHVsdC0nKSwgKCctdGl0cy0nKSwgKCdidXktcGhlbnRlcm1pbmUnKSwgKCdvcmRlci1jaGVhcC1waWxscycpLCAoJ2J1eS14ZW5hZHJpbmUnKSwJKCd4eHgnKSwgKCdwYXJpcy1oaWx0b24nKSwgKCdwYXJpc2hpbHRvbicpLCAoJ2NhbWdpcmxzJyksICgnYWR1bHQtbW9kZWxzJyk=');
  815.     // pre_dump($r);
  816.     return $r;
  817. }
  818.  
  819. /*
  820.  * $Log: _functions_install.php,v $
  821.  * Revision 1.90  2010/03/04 18:02:50  fplanque
  822.  * Cleaned up .htaccess install
  823.  *
  824.  * Revision 1.89  2010/03/03 18:56:50  fplanque
  825.  * minor
  826.  *
  827.  * Revision 1.88  2010/02/18 06:59:37  efy-yury
  828.  * localization of widgets create code
  829.  *
  830.  * Revision 1.87  2010/02/13 13:42:26  efy-yury
  831.  * move get_antispam_query()
  832.  *
  833.  * Revision 1.86  2010/02/08 17:55:38  efy-yury
  834.  * copyright 2009 -> 2010
  835.  *
  836.  * Revision 1.85  2010/02/06 23:10:50  sam2kb
  837.  * minor
  838.  *
  839.  * Revision 1.84  2010/01/25 18:18:21  efy-asimo
  840.  * .htaccess automatic install
  841.  *
  842.  * Revision 1.83  2009/12/20 21:05:08  fplanque
  843.  * New default widget styles
  844.  *
  845.  * Revision 1.82  2009/12/14 03:59:51  fplanque
  846.  * added 2 new skins
  847.  *
  848.  * Revision 1.81  2009/12/10 20:13:25  blueyed
  849.  * Add log_errors property to DB and set it to false in get_db_version to not
  850.  * log SQL errors which are expected during install.
  851.  *
  852.  * Revision 1.80  2009/10/17 16:31:33  efy-maxim
  853.  * Renamed: T_groupsettings to T_groups__groupsettings, T_usersettings to T_users__usersettings
  854.  *
  855.  * Revision 1.79  2009/10/04 18:27:34  blueyed
  856.  * Changed nb_of_basic_plugins to list of plugins (basic_plugins), and tell about differences on failure.
  857.  *
  858.  * Revision 1.78  2009/10/04 18:05:24  blueyed
  859.  * rename nr_ to nb_
  860.  *
  861.  * Revision 1.77  2009/09/26 12:00:44  tblue246
  862.  * Minor/coding style
  863.  *
  864.  * Revision 1.76  2009/09/25 07:33:31  efy-cantor
  865.  * replace get_cache to get_*cache
  866.  *
  867.  * Revision 1.75  2009/09/20 00:33:59  blueyed
  868.  * Add widget to display avatar of collection/blog owner. Install it for all new blogs by default.
  869.  *
  870.  * Revision 1.74  2009/09/14 14:10:14  efy-arrin
  871.  * Included the ClassName in load_class() call with proper UpperCase
  872.  *
  873.  * Revision 1.73  2009/09/13 22:34:59  blueyed
  874.  * doc
  875.  *
  876.  * Revision 1.71  2009/07/19 21:00:19  fplanque
  877.  * minor
  878.  *
  879.  * Revision 1.70  2009/07/16 21:36:26  blueyed
  880.  * Comment debug code(?!)
  881.  * fp> No, it makes sense to show what modules are being installed.
  882.  * dh> I've seen it being displayed in (non-install) tests and thought that it should not get displayed there.
  883.  *
  884.  * Revision 1.69  2009/07/12 22:22:26  tblue246
  885.  * Translation bugfix
  886.  *
  887.  * Revision 1.68  2009/07/12 18:41:58  fplanque
  888.  * doc / help
  889.  *
  890.  * Revision 1.67  2009/07/10 19:48:02  fplanque
  891.  * clean up a little bit
  892.  *
  893.  * Revision 1.66  2009/07/10 18:41:34  fplanque
  894.  * do NOT hide password warning from developers.
  895.  * They need to know what teh rest of the world sees.
  896.  *
  897.  * Revision 1.65  2009/07/10 06:48:46  sam2kb
  898.  * Don't show the message about random password if $install_password is set.
  899.  *
  900.  * Revision 1.64  2009/07/07 23:17:31  sam2kb
  901.  * Rolled back translation in serialized strings
  902.  *
  903.  * Revision 1.63  2009/07/07 04:52:54  sam2kb
  904.  * Made some strings translatable
  905.  *
  906.  * Revision 1.62  2009/07/02 13:35:19  fplanque
  907.  * Improved installer -- language/locale selection moved to a place where it's visible!
  908.  *
  909.  * Revision 1.61  2009/05/26 17:00:04  fplanque
  910.  * added twitter plugin + better auto-install code for plugins in general
  911.  *
  912.  * Revision 1.60  2009/05/23 20:20:18  fplanque
  913.  * Skins can now have a _skin.class.php file to override default Skin behaviour. Currently only the default name but can/will be extended.
  914.  *
  915.  * Revision 1.59  2009/03/24 23:57:07  blueyed
  916.  * Fix error in PHP5 during upgrade, when existing plugins are using Plugin(User)Settings in PluginInit. This needs a global Plugins instance, which is a reference to Plugins_admin during installation now.
  917.  *
  918.  * Revision 1.58  2009/03/21 22:55:15  fplanque
  919.  * Adding TinyMCE -- lowfat version
  920.  *
  921.  * Revision 1.57  2009/03/15 22:48:16  fplanque
  922.  * refactoring... final step :)
  923.  *
  924.  * Revision 1.56  2009/03/08 23:57:47  fplanque
  925.  * 2009
  926.  *
  927.  * Revision 1.55  2009/01/22 23:26:45  blueyed
  928.  * Fix install-myself test (and stuff around it). Move 'newdb' action from install/index.php to functions_install.php to call it the same as during real install.
  929.  *
  930.  * Revision 1.54  2008/09/24 10:39:42  fplanque
  931.  * no message
  932.  *
  933.  * Revision 1.53  2008/09/24 10:36:32  fplanque
  934.  * create some imagy widgets
  935.  *
  936.  * Revision 1.52  2008/09/22 20:06:13  blueyed
  937.  * doc
  938.  *
  939.  * Revision 1.51  2008/05/26 19:15:32  fplanque
  940.  * glossyblue skin
  941.  *
  942.  * Revision 1.50  2008/04/27 02:33:43  fplanque
  943.  * skins
  944.  *
  945.  * Revision 1.49  2008/04/15 20:30:48  fplanque
  946.  * terrafirma minor
  947.  *
  948.  * Revision 1.48  2008/04/06 19:19:30  fplanque
  949.  * Started moving some intelligence to the Modules.
  950.  * 1) Moved menu structure out of the AdminUI class.
  951.  * It is part of the app structure, not the UI. Up to this point at least.
  952.  * Note: individual Admin skins can still override the whole menu.
  953.  * 2) Moved DB schema to the modules. This will be reused outside
  954.  * of install for integrity checks and backup.
  955.  * 3) cleaned up config files
  956.  *
  957.  * Revision 1.47  2008/04/04 17:02:22  fplanque
  958.  * cleanup of global settings
  959.  *
  960.  * Revision 1.46  2008/02/07 00:35:52  fplanque
  961.  * cleaned up install
  962.  *
  963.  * Revision 1.45  2008/01/21 17:56:34  fplanque
  964.  * no more code plugin by default
  965.  *
  966.  * Revision 1.44  2008/01/21 09:35:38  fplanque
  967.  * (c) 2008
  968.  *
  969.  * Revision 1.43  2008/01/12 19:25:58  blueyed
  970.  * - Fix install from < 0.8: Make function "cleanup_post_quotes" inline and fix table name
  971.  * - Only check max_execution_time when > 0 (not disabled)
  972.  *
  973.  * Revision 1.42  2008/01/07 03:00:52  fplanque
  974.  * minor
  975.  *
  976.  * Revision 1.41  2007/12/28 00:13:02  fplanque
  977.  * no message
  978.  *
  979.  * Revision 1.40  2007/12/27 23:56:07  fplanque
  980.  * Better out of the box experience
  981.  *
  982.  * Revision 1.39  2007/12/22 16:59:41  fplanque
  983.  * Miami blue 2.x
  984.  *
  985.  * Revision 1.38  2007/10/08 21:30:19  fplanque
  986.  * evocamp skin
  987.  *
  988.  * Revision 1.37  2007/10/08 08:32:56  fplanque
  989.  * widget fixes
  990.  *
  991.  * Revision 1.36  2007/10/01 01:06:31  fplanque
  992.  * Skin/template functions cleanup.
  993.  *
  994.  * Revision 1.35  2007/09/28 02:17:48  fplanque
  995.  * Menu widgets
  996.  *
  997.  * Revision 1.34  2007/09/19 02:54:16  fplanque
  998.  * bullet proof upgrade
  999.  *
  1000.  * Revision 1.33  2007/09/08 23:46:38  fplanque
  1001.  * made evopress the new default skin
  1002.  *
  1003.  * Revision 1.32  2007/09/03 16:46:58  fplanque
  1004.  * minor
  1005.  *
  1006.  * Revision 1.31  2007/08/21 22:32:31  blueyed
  1007.  * Use get_Cache() for singleton $Plugins_admin instance. This fixes at least the installation of flickr_plugin.
  1008.  *
  1009.  * Revision 1.30  2007/07/01 18:49:40  fplanque
  1010.  * evopress skin (tentative)
  1011.  *
  1012.  * Revision 1.29  2007/07/01 03:55:04  fplanque
  1013.  * category plugin replaced by widget
  1014.  *
  1015.  * Revision 1.28  2007/06/25 11:02:30  fplanque
  1016.  * MODULES (refactored MVC)
  1017.  *
  1018.  * Revision 1.27  2007/06/24 18:28:55  fplanque
  1019.  * refactored skin install
  1020.  *
  1021.  * Revision 1.26  2007/05/14 02:43:06  fplanque
  1022.  * Started renaming tables. There probably won't be a better time than 2.0.
  1023.  *
  1024.  * Revision 1.25  2007/05/13 20:44:52  fplanque
  1025.  * more pages support
  1026.  *
  1027.  * Revision 1.24  2007/05/09 01:58:57  fplanque
  1028.  * Widget to display other blogs from same owner
  1029.  *
  1030.  * Revision 1.23  2007/05/08 19:36:06  fplanque
  1031.  * automatic install of public blog list widget on new blogs
  1032.  *
  1033.  * Revision 1.22  2007/05/07 23:26:19  fplanque
  1034.  * public blog list as a widget
  1035.  *
  1036.  * Revision 1.21  2007/04/26 00:11:10  fplanque
  1037.  * (c) 2007
  1038.  *
  1039.  * Revision 1.20  2007/04/20 02:31:06  fplanque
  1040.  * more default plugins
  1041.  *
  1042.  * Revision 1.19  2007/01/19 09:31:04  fplanque
  1043.  * Provision for case sensitive file meta data handling
  1044.  *
  1045.  * Revision 1.18  2007/01/15 19:10:29  fplanque
  1046.  * install refactoring
  1047.  *
  1048.  * Revision 1.17  2006/11/17 01:46:16  fplanque
  1049.  * Fixed broken upgrade path.
  1050.  *
  1051.  * Revision 1.16  2006/11/01 00:24:07  blueyed
  1052.  * Fixed cafelog upgrade
  1053.  *
  1054.  * Revision 1.15  2006/09/08 15:35:36  blueyed
  1055.  * Completely nuked tokenizer dependency - removed commented out block
  1056.  *
  1057.  * Revision 1.14  2006/08/20 20:54:31  blueyed
  1058.  * Removed dependency on tokenizer. Quite a few people don't have it.. see http://forums.b2evolution.net//viewtopic.php?t=8664
  1059.  *
  1060.  * Revision 1.13  2006/07/04 17:32:30  fplanque
  1061.  * no message
  1062.  *
  1063.  * Revision 1.12  2006/06/19 20:59:38  fplanque
  1064.  * noone should die anonymously...
  1065.  *
  1066.  * Revision 1.11  2006/04/06 08:52:27  blueyed
  1067.  * Validate install "misc" requirements ("tokenizer" support for now)
  1068.  *
  1069.  * Revision 1.10  2005/12/30 18:08:24  fplanque
  1070.  * no message
  1071.  *
  1072.  */
  1073. ?>

Documentation generated on Sat, 06 Mar 2010 04:11:28 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).