Location: PHPKode > scripts > Yet Another Link Directory > yald2/install/upgrade.php
<?php
/******************************************************************************
* This file is part of Yet Another Link Directory.                            *
*                                                                             *
* Yet Another Link Directory is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or           *
* (at your option) any later version.                                         *
*                                                                             *
* Yet Another Link Directory is distributed in the hope that it will be       *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of      *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
* GNU General Public License for more details.                                *
*                                                                             *
* You should have received a copy of the GNU General Public License           *
* along with Yet Another Link Directory; if not, write to the Free Software   *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
******************************************************************************/

require('../inc/config.php');
require('../inc/functions.php');
require('../inc/version.php');
mysql_connect($mysql['host'],$mysql['username'],$mysql['password']) or die('Could not connect to MySQL. Make sure your MySQL settings are correct.');
mysql_select_db($mysql['db']) or die('Could not select MySQL database');

$template = file_get_contents('template.html');
$yald_body = '<b>Upgrade YALD</b><br />';

function gen_output(){
	global $yald_head, $yald_body, $template;
	$template = str_replace(array('@INSTALL_ACTIVE@','@UPGRADE_ACTIVE@'),array('','class="active"'),$template);
	$template = str_replace('@YALD_BODY@',$yald_body,$template);
	die($template);
}


// set all vars to empty array
$changedfiles = array();
$extrafields = array();
$changedfiles_a = array();

$this_update_build = 14;

/*----------------Initial checks---------------------*/
// we need to get the settings from the database if the version is greater than 2.3.1
if($yald_build_number > 12){
	$settings = getSettings();
}

// the updater is not compatible with versions older than 2.3
if($yald_build_number < 11){
	$yald_body = 'You must be using version 2.3 or greater for this updater to work. Manually update to 2.3 then update to this version.';
	gen_output();
}

if($yald_build_number == $this_update_build){
	$yald_body = 'As far as I can tell (based on version.php) you are running the version this updater is for.';
	gen_output();
}


/*-----------------Version specifics---------------*/
// version 2.3 specifics
if($yald_build_number == 11){
	$changedfiles[] = 'admin/stats.php';
}

// version 2.3.1 specifics
if($yald_build_number <= 12){

	if(!isset($_POST['settings_table_name'])){
		$_POST['settings_table_name'] = '';
	}

	$extrafields[] = 'What do you want the settings table to be called? If you are not sure, leave the default. <input type="text" name="settings_table_name" value="settings" />';

	$changedfiles[] = 'admin/approve.php';
	$changedfiles[] = 'admin/backup.php';
	$changedfiles[] = 'admin/categories.php';
	$changedfiles[] = 'admin/edit.php';
	$changedfiles[] = 'admin/login.php';
	$changedfiles[] = 'admin/new.php';
	$changedfiles[] = 'admin/prune.php';
	$changedfiles[] = 'admin/stats.php';
	$changedfiles[] = 'admin/submitmap.php';
	$changedfiles[] = 'admin/template.html';
	$changedfiles[] = 'admin/editconfig.php  [New file]';
	$changedfiles[] = 'templates/classic/footer.html';
	$changedfiles[] = 'templates/classic/header.html';
	$changedfiles[] = 'templates/classic/directory.html';
	$changedfiles[] = 'inc/functions.php';
	$changedfiles[] = 'inc/pages.class.php';
	$changedfiles_a[] = 'inc/config.php  [Needs Modification]';
	$changedfiles_a[] = 'inc/version.php';
	$changedfiles[] = 'directory.php';
	$changedfiles[] = 'sitemap.php';
	$changedfiles[] = 'suggest.php';
	$changedfiles[] = 'search_info.php  [New File]';

	$query[] = 'ALTER TABLE `'.$settings['categories_table'].'` ADD `path` TEXT NULL ;';
	$query[] = 'ALTER TABLE `'.$settings['links_table'].'` CHANGE `description` `description` TEXT NOT NULL';
	$query[] = 'CREATE TABLE `'.$_POST['settings_table_name'].'` (
  `id` int(4) NOT NULL auto_increment,
  `setting` varchar(50) NOT NULL,
  `value` tinytext,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;';
	$query[] = 'ALTER TABLE `'.$settings['links_table'].'` ADD FULLTEXT(`url`, `name`, `description`);';

	$query[] = "INSERT INTO `{$_POST['settings_table_name']}` (`id`, `setting`, `value`) VALUES
(1, 'site_title', '".serialize($settings['site_title'])."'),
(2, 'jump_links', '".serialize($settings['jump_links'])."'),
(3, 'max_url_length', '".serialize($settings['max_url_length'])."'),
(4, 'max_title_length', '".serialize($settings['max_title_length'])."'),
(5, 'max_description_length', '".serialize($settings['max_description_length'])."'),
(6, 'index_file', '".serialize($settings['index_file'])."'),
(7, 'display_admin_link', '".serialize($settings['display_admin_link'])."'),
(8, 'home_link', '".serialize($settings['home_link'])."'),
(9, 'show_num_subs', '".serialize($settings['show_num_subs'])."'),
(10, 'use_captcha', '".serialize($settings['use_captcha'])."'),
(11, 'check_links', '".serialize($settings['check_links'])."'),
(12, 'list_type', '".serialize($settings['list_type'])."'),
(13, 'url_type', '".serialize($settings['url_type'])."'),
(14, 'mod_rewrite_url', '".serialize($settings['mod_rewrite_url'])."'),
(15, 'admin_user', '".$settings['admin_user']."'),
(16, 'admin_pass', '".$settings['admin_pass']."'),
(17, 'template_dir', '".serialize($settings['template_dir'])."'),
(18, 'template_c_dir', '".serialize($settings['template_c_dir'])."'),
(19, 'default_template', '".serialize($settings['default_template'])."'),
(20, 'recursive_counts', '".serialize($settings['recursive_counts'])."'),
(21, 'count_refresh_time', '".serialize($settings['count_refresh_time'])."'),
(22, 'use_pagination', '".serialize($settings['use_pagination'])."'),
(23, 'links_per_page', '".serialize($settings['links_per_page'])."'),
(24, 'disp_latest', '".serialize($settings['disp_latest'])."'),
(25, 'num_latest_links', '".serialize($settings['num_latest_links'])."');";

}

//2.4 specifics
if($yald_build_number <= 13){
	
	$query[] = 'ALTER TABLE `'.$settings['categories_table'].'` ADD INDEX ( `parent`,`name` )';
	$query[] = 'ALTER TABLE `'.$settings['categories_table'].'` ADD INDEX ( `lft` , `rgt` )';
	$query[] = 'ALTER TABLE `'.$settings['links_table'].'` ADD INDEX ( `category` , `approved` )';
	$query[] = 'UPDATE `'.$settings['settings_table'].'` SET `value`="'.sha1($settings['admin_pass']).'" WHERE `setting`="admin_pass"';
	
	$changedfiles[] = 'inc/functions.php';
	$changedfiles[] = 'templates/classic/header.html';
	$changedfiles_a[] = 'inc/version.php';
	
	
}

$changedfiles = array_unique($changedfiles);
$changedfiles_a = array_unique($changedfiles_a);

if(!isset($_GET['step'])){

	$yald_body .= "<html><head><title>Upgrade YALD</title><body>The following files have changed since version {$yald_version_number}. Follow the upgrade instructions carefully to make sure there are no problems. First, make a BACKUP of your database and config.php! Then, replace these files on your server with the corresponding files from this package. Alternatively, you may replace all files but you MUST NOT overwrite version.php or config.php until the update is complete. When you are done, click next.<br /><div style=\"border:1px solid #000; padding: 10px;\">";
	if(!empty($changedfiles)){
		foreach($changedfiles as $file){
			$yald_body .= "$file<br />";
		}
	} else {
		$yald_body .= "No changed files";
	}
	$yald_body .= '</div><br />It is suggested that you do a database backup before clicking next!<br /><form action="'.$_SERVER['PHP_SELF'].'?step=2" method="post"><input type="submit" name="submit" value="Next &gt;&gt;" /></form></body></html>';

} elseif($_GET['step'] == '2'){

	if(isset($extrafields)){
		$yald_body .= "Some settings have been added since the previous version. Please specify what you would like them to be set to.<br /><br />";
		$yald_body .= '<form action="'.$_SERVER['PHP_SELF'].'?step=3" method="post" />';
		foreach($extrafields as $field){
			$yald_body .= $field.'<br />';
		}
		$yald_body .= '<br /><input type="submit" name="" value="Next &gt;&gt;" /></form>';
	} else {
		header('Location: '.$_SERVER['PHP_SELF'].'?step=3');
		exit;
	}

} elseif($_GET['step'] == '3'){

	foreach($query as $q){
		mysql_query($q) or die(htmlentities($q).' failed. MySQL said '.mysql_error());
	}

	// additonal operations based on version
	if($yald_build_number <= '12'){
		updateDbPath('1',true);
	}

	$yald_body .= "Database update was successful! To complete the update, replace the following files on your server with the ones contained in the downloaded package.<br /><br />";
	foreach($changedfiles_a as $file){
		$yald_body .= "$file<br />";
	}
	$yald_body .= "<br />Login to your admin panel to make sure all settings are correct.";

}

gen_output();

?>
Return current item: Yet Another Link Directory