Hi Rob,
An idea of the merged file installer.php
<?php
/**
* Generic Installer
*
* Database install script for contributions
* Dependencies - installer_class.php
*
* @package Generic Installer
* @link http://www.fwrmedia.co.uk
* @copyright Copyright ©2008, Robert Fisher, FWR Media
* @author Robert Fisher, FWR Media, http://www.fwrmedia.co.uk
* @lastdev $Author:: Rob $: Author of last commit
* @lastmod $Date:: 2009-11-29 21:55:09 +0000 (Sun, 29 Nov 2009) $: Date of last commit
* @version $Rev:: 117 $: Revision of last commit
* @Id $Id:: installer.php 117 2009-11-29 21:55:09Z Rob $: Full Details
* @filesource
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
// Initial set up
// set the level of error reporting
error_reporting( ( E_ALL & ~E_NOTICE ) & ~E_DEPRECATED );
date_default_timezone_set("EUROPE/LONDON");
session_start();
require_once( 'includes/configure.php' );
require_once( 'includes/database_tables.php' );
define( 'FWR_INSTALLER', 1 );
require_once( 'installer_class.php' );
$installer = new installer_class;
$installer->showHeader();
$error = '';
$required_version = '5.1.4';
if ( PHP_VERSION < $required_version ) {
$error .= '<div class="error">You cannot install this script as your PHP version ("' . PHP_VERSION . '") is too low. The required version is ' . $required_version . '+</div>' . PHP_EOL;
}
if ( false === function_exists( 'filter_var' ) ) {
$error .= '<div class="error">You cannot install this script as the function filter_var() does not exist in your PHP set up</div>' . PHP_EOL;
}
if ( false === function_exists( 'gzinflate' ) ) {
$error .= '<div class="error">You cannot install this script as the Zlib functions gzinflate()/gzdeflate() do not exist in your PHP set up</div>' . PHP_EOL;
}
if ( false === class_exists( 'SplFileInfo' ) ) {
$error .= '<div class="error">You cannot install this script as the SPL (standard PHP Library) does not exist in your PHP set up</div>' . PHP_EOL;
}
if ( false === class_exists( 'DirectoryIterator' ) ) {
$error .= '<div class="error">You cannot install this script as the class DirectoryIterator does not exist in your PHP set up</div>' . PHP_EOL;
}
if ( !empty($error) ) {
echo $error;
$installer->showFooter();
exit;
}
/**
* Build your install using the arrays below
*
* @param $config_inserts - configuration group install
* plus configuration being an array of related configuration install values
* @param $tables_to_add - array of tables to be created
* @param $tables_to_alter - array tables we are going to alter
* @param $fields_to_add - array of fields we are going to add to specific tables
* @param $fields_to_alter - array of fields we are going to alter
*/
################## START USER DEFINED INSTALL ARRAYS #####################
$config_inserts = array('group' => array(
array( 'configuration_group_title' => 'Seo Urls 5',
'configuration_group_description' => 'Options for ULTIMATE Seo Urls 5 by FWR Media',
'sort_order' => '99',
'visible' => '1',
'configuration' => array(
array( 'configuration_title' => 'Enable SEO URLs 5?',
'configuration_key' => 'SEO_URLS_ENABLED',
'configuration_value' => 'true',
'configuration_description' => 'Turn Seo Urls 5 on',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Add cPath to product URLs?',
'configuration_key' => 'SEO_URLS_ADD_CPATH_TO_PRODUCT_URLS',
'configuration_value' => 'false',
'configuration_description' => 'This setting will append the cPath to the end of product URLs (i.e. - some-product-p-1.html?cPath=xx).',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Add category parent to beginning of URLs?',
'configuration_key' => 'SEO_URLS_ADD_CAT_PARENT',
'configuration_value' => 'true',
'configuration_description' => 'This setting will add the category parent name to the beginning of the category URLs (i.e. - parent-category-c-1.html).',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Filter Short Words',
'configuration_key' => 'SEO_URLS_FILTER_SHORT_WORDS',
'configuration_value' => '1',
'configuration_description' => '<b>This setting will filter words.</b><br>1 = Remove words of 1 letter<br>2 = Remove words of 2 letters or less<br>3 = Remove words of 3 letters or less<br>',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''1'', ''2'', ''3''), " ),
array( 'configuration_title' => 'Output W3C valid URLs?',
'configuration_key' => 'SEO_URLS_USE_W3C_VALID',
'configuration_value' => 'true',
'configuration_description' => 'This setting will output W3C valid URLs.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Choose URL Rewrite Type',
'configuration_key' => 'SEO_URLS_TYPE',
'configuration_value' => 'standard',
'configuration_description' => 'Choose SEO URL format:<br><b>rewrite</b><br>mysite.com/great-product-p-3.html<br><b>standard</b><br>mysite.com/product_info.php/great-product-p-3<p><i>Note: mod_rewrite has to be enabled for the rewrite option and AllowOveride set to all.</i></p>',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''rewrite'', ''standard''), " ),
array( 'configuration_title' => 'Enter special character conversions. (Better to use the file based character conversions.See extras/character_conversion_pack/instructions.txt)',
'configuration_key' => 'SEO_URLS_CHAR_CONVERT_SET',
'configuration_value' => '',
'configuration_description' => 'This setting will convert characters.<br><br>The format <b>MUST</b> be in the form: <b>char=>conv,char2=>conv2</b>',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => NULL ),
array( 'configuration_title' => 'Remove all non-alphanumeric characters?',
'configuration_key' => 'SEO_URLS_REMOVE_ALL_SPEC_CHARS',
'configuration_value' => 'true',
'configuration_description' => 'This will remove all non-letters and non-numbers. If your language has special characters then you will need to use the character conversion system.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Set the number of days to store the cache.',
'configuration_key' => 'SEO_URLS_CACHE_DAYS',
'configuration_value' => '7',
'configuration_description' => 'Set the number of days you wish to retain cached data, after this the cache will auto reset.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => NULL ),
array( 'configuration_title' => 'Reset SEO URLs Cache',
'configuration_key' => 'SEO_URLS_CACHE_RESET',
'configuration_value' => 'false',
'configuration_description' => 'This will reset the cache data for SEO',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => 'tep_reset_cache_data_seo_urls',
'set_function' => "tep_cfg_select_option(array(''reset'', ''false''), " ),
array( 'configuration_title' => 'Turn debug reporting on true/false.',
'configuration_key' => 'SEO_URLS_OUPUT_PERFORMANCE',
'configuration_value' => 'false',
'configuration_description' => '<span style="color: red;">Debug reporting should <b>NOT</b> be set to ON on a live site</span><br>It is for dev reporting re: performance and queries.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Select caching system.',
'configuration_key' => 'SEO_URLS_CACHE_SYSTEM',
'configuration_value' => 'FileSystem',
'configuration_description' => '<b>Filesystem:</b><br>Zero queries after cache load.<br><b>Database:</b><br>One query after cache load<br><b>Memcached:</b><br>Requires memcached in apache and php.ini.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''FileSystem'', ''Database'', ''Memcached''), " )
)
)
));
$tables_to_add = array( 'usu_cache' => "CREATE TABLE `usu_cache` (
`cache_name` varchar(32) NOT NULL,
`cache_data` mediumtext NOT NULL,
`cache_date` datetime NOT NULL,
PRIMARY KEY (`cache_name`)
) ENGINE=MyISAM;" );
$tables_to_alter = array();
$fields_to_add = array();
$fields_to_alter = array();
################### END USER DEFINED INSTALL ARRAYS ######################
/**
* Stage 1 - Check all database alterations for current existence
*/
$errors = false;
if( $installer->stage == '1' ) {
echo ' <div id="messages_container">' . "\n";
echo ' <ul>' . "\n";
// Check config inserts
if( !empty($config_inserts) ){
if( $installer->configExists( $config_inserts ) ) {
echo ' <li class="error">At least one of the configuration values already exists!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">All configuration values look good.</li>' . "\n";
if( false !== $installer->autoIncrement ) {
echo ' <li class="success">Configuration Group auto increment to start at ' . $installer->autoIncrement . '</li>' . "\n";
}
}
} else {
echo ' <li class="dormant">No configuration values to install it seems.</li>' . "\n";
}
// Check tables to add
if( !empty( $tables_to_add ) ) {
if( $installer->tablesExist( $tables_to_add ) ) {
echo ' <li class="error">At least one of the tables to insert already exists!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Tables look good to insert.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No tables to insert it seems.</li>' . "\n";
}
// Check tables to add
if( !empty( $tables_to_alter ) ) {
if( !$installer->tablesExist( $tables_to_alter ) ) {
echo ' <li class="error">At least one of the tables to alter does not exist!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Tables to alter look good.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No tables to alter it seems.</li>' . "\n";
}
// Check fields to add
if( !empty( $fields_to_add ) ) {
if( $installer->fields_exist( $fields_to_add ) ) {
echo ' <li class="error">At least one of the fields to insert already exists!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Fields look good to insert.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No fields to insert it seems.</li>' . "\n";
}
// Check fields to alter
if( !empty( $fields_to_alter ) ) {
if( !$installer->fields_exist( $fields_to_alter ) ) {
echo ' <li class="error">At least one of the fields to alter does not exist!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Fields to alter look good.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No fields to alter it seems.</li>' . "\n";
}
echo ' </ul>' . "\n";
echo ' </div>' . "\n";
$installer->showStatus( $errors );
} elseif( $installer->stage == '2' ) { // Stage 2 - Install
$installer->implementInstall( $config_inserts, $tables_to_add, $tables_to_alter, $fields_to_add, $fields_to_alter );
if( empty( $installer->install['error'] ) ) {
$installer->outputInstallSuccess();
$installer_class = str_replace( 'installer.php', '', __FILE__ ) . 'installer_class.php';
@unlink( $installer_class );
@unlink( __FILE__ );
echo '<div style="padding: 0.5em; margin-top: 3em;">' . ( ( !file_exists( __FILE__ ) && !file_exists( $installer_class ) ) ? '<b style="color: green;">This file has self deleted!<b>' : '<b style="color: red;">installer.php and installer_class.php file MUST be deleted!<b>' ) . '</div>' . PHP_EOL;
} else {
$installer->outputErrors();
}
}
if( false === $errors ) {
$_SESSION['stage'] = 1;
$_SESSION['token'] = $installer->token;
if( $installer->stage == '1' ) {
$installer->drawPostForm( 'Install Database Settings' );
}
}
$installer->showFooter();
$installer->db->close();
### KissMT DB Installer ###
################## START USER DEFINED INSTALL ARRAYS #####################
$config_inserts = array('group' => array(
array( 'configuration_group_title' => 'KissMT Meta Tags',
'configuration_group_description' => 'Options for KissMT Dynamic Seo Meta Tags by FWR Media',
'sort_order' => '99',
'visible' => '1',
'configuration' => array(
array( 'configuration_title' => 'Turn on the KissMT cache?',
'configuration_key' => 'KISSMT_CACHE_ON',
'configuration_value' => 'true',
'configuration_description' => '<b>Recommended:</b><br>This setting will turn on the KissMT cache feature.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'The separator for words in the title bar.',
'configuration_key' => 'KISSMT_TITLE_SEPARATOR',
'configuration_value' => '-',
'configuration_description' => 'The way words are separated in the browser title bar like .. My - Shop',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => NULL ),
array( 'configuration_title' => 'Output tags in XHTML?',
'configuration_key' => 'KISSMT_XHTML_OUTPUT',
'configuration_value' => 'false',
'configuration_description' => 'Outputs tags in XHTML if set to true',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Output KissMT performance data',
'configuration_key' => 'KISSMT_PERFORMANCE_OUTPUT',
'configuration_value' => 'false',
'configuration_description' => '<b>Dev only</b> This setting will output performance data at the bottom of the page.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'This setting will output KissMT class properties.',
'configuration_key' => 'KISSMT_CLASS_OUTPUT',
'configuration_value' => 'false',
'configuration_description' => '<b>Dev only</b> This will output the KissMT class properties at the bottom of the page<br><b>Output KissMT performance data</b> must be set to true also.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Output canonical tags for SEO',
'configuration_key' => 'KISSMT_CANONICAL_ON',
'configuration_value' => 'true',
'configuration_description' => '<b>Recommended:</b><br>Output canonical tags removing osCsid from search engine indexes and preventing duplicate content.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Set a limit for products/categories',
'configuration_key' => 'KISSMT_CATEGORIES_PRODUCTS_LIMIT',
'configuration_value' => '30',
'configuration_description' => 'This will set a limit for the number of categories/products extracted from the database for description and keywords.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => NULL ),
array( 'configuration_title' => 'Enable Categories/Manufacturers descriptions extension.',
'configuration_key' => 'KISSMT_DESCRIPTIONS_EXTENSION_ENABLE',
'configuration_value' => 'false',
'configuration_description' => 'Enable the extension for categories/manufacturers descriptions.<br><span style="color: red;">Have you installed the extension?</span>',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''true'', ''false''), " ),
array( 'configuration_title' => 'Reset KissMT Cache',
'configuration_key' => 'KISSMT_CACHE_RESET',
'configuration_value' => 'false',
'configuration_description' => 'This will reset the cache data for KissMT. Actions on the next page load of the front end.',
'configuration_group_id' => '',
'sort_order' => '99',
'last_modified' => date( "Y-m-d H:i:s" ),
'date_added' => date( "Y-m-d H:i:s" ),
'use_function' => NULL,
'set_function' => "tep_cfg_select_option(array(''reset'', ''false''), " )
)
)
));
$tables_to_add = array();
/*
$tables_to_add = array( 'usu_cache' => "CREATE TABLE `usu_cache` (
`cache_name` varchar(32) NOT NULL,
`cache_data` mediumtext NOT NULL,
`cache_date` datetime NOT NULL,
PRIMARY KEY (`cache_name`)
) ENGINE=MyISAM;" );
*/
$tables_to_alter = array();
$fields_to_add = array( TABLE_CATEGORIES_DESCRIPTION =>
array( 'kissmt_categories_description' => "ALTER TABLE `categories_description` ADD COLUMN kissmt_categories_description TEXT DEFAULT NULL" ),
TABLE_MANUFACTURERS_INFO =>
array( 'kissmt_manufacturers_description' => "ALTER TABLE `manufacturers_info` ADD COLUMN kissmt_manufacturers_description TEXT DEFAULT NULL") );
$fields_to_alter = array();
################### END USER DEFINED INSTALL ARRAYS ######################
/**
* Stage 1 - Check all database alterations for current existence
*/
$errors = false;
if( $installer->stage == '1' ) {
echo ' <div id="messages_container">' . "\n";
echo ' <ul>' . "\n";
// Check config inserts
if( !empty($config_inserts) ){
if( $installer->configExists( $config_inserts ) ) {
echo ' <li class="error">At least one of the configuration values already exists!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">All configuration values look good.</li>' . "\n";
if( false !== $installer->autoIncrement ) {
echo ' <li class="success">Configuration Group auto increment to start at ' . $installer->autoIncrement . '</li>' . "\n";
}
}
} else {
echo ' <li class="dormant">No configuration values to install it seems.</li>' . "\n";
}
// Check tables to add
if( !empty( $tables_to_add ) ) {
if( $installer->tablesExist( $tables_to_add ) ) {
echo ' <li class="error">At least one of the tables to insert already exists!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Tables look good to insert.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No tables to insert it seems.</li>' . "\n";
}
// Check tables to add
if( !empty( $tables_to_alter ) ) {
if( !$installer->tablesExist( $tables_to_alter ) ) {
echo ' <li class="error">At least one of the tables to alter does not exist!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Tables to alter look good.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No tables to alter it seems.</li>' . "\n";
}
// Check fields to add
if( !empty( $fields_to_add ) ) {
if( !$installer->fields_exist( $fields_to_add ) ) {
echo ' <li class="error">At least one of the fields to insert already exists!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Fields look good to insert.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No fields to insert it seems.</li>' . "\n";
}
// Check fields to alter
if( !empty( $fields_to_alter ) ) {
if( !$installer->fields_exist( $fields_to_alter ) ) {
echo ' <li class="error">At least one of the fields to alter does not exist!</li>' . "\n";
$errors = true;
} else {
echo ' <li class="success">Fields to alter look good.</li>' . "\n";
}
} else {
echo ' <li class="dormant">No fields to alter it seems.</li>' . "\n";
}
echo ' </ul>' . "\n";
echo ' </div>' . "\n";
$installer->showStatus( $errors );
} elseif( $installer->stage == '2' ) { // Stage 2 - Install
$installer->implementInstall( $config_inserts, $tables_to_add, $tables_to_alter, $fields_to_add, $fields_to_alter );
if( empty( $installer->install['error'] ) ) {
$installer->outputInstallSuccess();
$installer_class = str_replace( 'installer.php', '', __FILE__ ) . 'installer_class.php';
@unlink( $installer_class );
@unlink( __FILE__ );
echo '<div style="padding: 0.5em; margin-top: 3em;">' . ( ( !file_exists( __FILE__ ) && !file_exists( $installer_class ) ) ? '<b style="color: green;">This file has self deleted!<b>' : '<b style="color: red;">installer.php and installer_class.php file MUST be deleted!<b>' ) . '</div>' . PHP_EOL;
} else {
$installer->outputErrors();
}
}
if( false === $errors ) {
$_SESSION['stage'] = 1;
$_SESSION['token'] = $installer->token;
if( $installer->stage == '1' ) {
$installer->drawPostForm( 'Install Database Settings' );
}
}
$installer->showFooter();
$installer->db->close();
?>
There are two instances of this
$installer->showFooter();
$installer->db->close();
Shall I remove any duplicates for the code to work or are they ok as they are..
Cheers Fab