IPB UPGRADE LOADER
| > Script written by Matt Mecham
| > Date started: 21st April 2004
| > Interesting fact: Radiohead rock (still)
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_IPB' ) )
{
print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
exit();
}
class core_functions
{
/*-------------------------------------------------------------------------*/
// CONSTRUCTOR
/*-------------------------------------------------------------------------*/
function core_functions()
{
}
/*-------------------------------------------------------------------------*/
// FINISH _EVERYTHING_
/*-------------------------------------------------------------------------*/
function upgrade_complete()
{
$this->ipsclass->template->content .= "
IPB Upgrade Complete!
You have now been upgraded!
You may want to disable permissions on the script 'upgrade/index.php' to increase security or rename the 'upgrade' directory.
";
$this->ipsclass->template->output();
}
/*-------------------------------------------------------------------------*/
// REBUILD TEMPLATES
/*-------------------------------------------------------------------------*/
function rebuild_templates_cache()
{
//-----------------------------------
// Get ACP library
//-----------------------------------
require_once( ROOT_PATH.'sources/lib/admin_cache_functions.php' );
$acp = new admin_cache_functions();
$acp->ipsclass =& $this->ipsclass;
$justdone = intval($this->ipsclass->input['justdone']);
$justdone = $justdone ? $justdone : 1;
//-----------------------------------
// Get skins
//-----------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*',
'from' => 'skin_sets',
'where' => 'set_skin_set_id > '.$justdone,
'order' => 'set_skin_set_id',
'limit' => array( 0, 1 )
) );
$this->ipsclass->DB->simple_exec();
//-----------------------------------
// Got a biggun?
//-----------------------------------
$r = $this->ipsclass->DB->fetch_row();
if ( $r['set_skin_set_id'] )
{
$acp->_rebuild_all_caches( array($r['set_skin_set_id']) );
$extra = implode( "
", $acp->messages );
$this->ipsclass->core->redirect( "index.php?act=templatescache&justdone={$r['set_skin_set_id']}&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}", "Rebuild cache for skin set {$r['set_name']}
{$extra}
Proceeding to the next skin..." );
}
else
{
$this->ipsclass->core->redirect( "index.php?act=finish&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}", "No more skins to rebuild..." );
}
}
/*-------------------------------------------------------------------------*/
// REBUILD TEMPLATES
/*-------------------------------------------------------------------------*/
function rebuild_templates()
{
//-----------------------------------
// Get XML
//-----------------------------------
require_once( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
$xml->lite_parser = 1;
//-----------------------------------
// Get XML file (TEMPLATES)
//-----------------------------------
$xmlfile = ROOT_PATH.'ipb_templates.xml';
$setting_content = implode( "", file($xmlfile) );
//-------------------------------
// Unpack the datafile (TEMPLATES)
//-------------------------------
$xml->xml_parse_document( $setting_content );
//-------------------------------
// (TEMPLATES)
//-------------------------------
if ( ! is_array( $xml->xml_array['templateexport']['templategroup']['template'] ) )
{
install_error("Error with ipb_templates.xml - could not process XML properly");
}
foreach( $xml->xml_array['templateexport']['templategroup']['template'] as $id => $entry )
{
$row = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'suid',
'from' => 'skin_templates',
'where' => "group_name='{$entry[ 'group_name' ]['VALUE']}' AND func_name='{$entry[ 'func_name' ]['VALUE']}' and set_id=1"
) );
if ( $row['suid'] )
{
$this->ipsclass->DB->do_update( 'skin_templates', array( 'func_data' => $entry[ 'func_data' ]['VALUE'],
'section_content' => $entry[ 'section_content' ]['VALUE'],
'updated' => time()
)
, 'suid='.$row['suid'] );
}
else
{
$this->ipsclass->DB->do_insert( 'skin_templates', array( 'func_data' => $entry[ 'func_data' ]['VALUE'],
'func_name' => $entry[ 'func_name' ]['VALUE'],
'section_content' => $entry[ 'section_content' ]['VALUE'],
'group_name' => $entry[ 'group_name' ]['VALUE'],
'updated' => time(),
'set_id' => 1
) );
}
}
//-----------------------------------
// Boink..
//-----------------------------------
$this->ipsclass->core->redirect( "index.php?act=templatescache&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}", "Master templates rebuilt, proceeding to recache templates..." );
}
/*-------------------------------------------------------------------------*/
// REBUILD CACHES
/*-------------------------------------------------------------------------*/
function rebuild_caches()
{
//-------------------------------------------------------------
// BBCODE
//-------------------------------------------------------------
$this->ipsclass->cache['bbcode'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'custom_bbcode' ) );
$bbcode = $this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row($bbcode) )
{
$this->ipsclass->cache['bbcode'][] = $r;
}
$this->ipsclass->update_cache( array( 'name' => 'bbcode', 'array' => 1, 'deletefirst' => 1 ) );
//-------------------------------------------------------------
// Forum cache
//-------------------------------------------------------------
$this->ipsclass->update_forum_cache();
//-------------------------------------------------------------
// Group Cache
//-------------------------------------------------------------
$this->ipsclass->cache['group_cache'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => "*",
'from' => 'groups'
) );
$this->ipsclass->DB->simple_exec();
while ( $i = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->cache['group_cache'][ $i['g_id'] ] = $i;
}
$this->ipsclass->update_cache( array( 'name' => 'group_cache', 'array' => 1, 'deletefirst' => 1 ) );
//-------------------------------------------------------------
// Systemvars
//-------------------------------------------------------------
$this->ipsclass->cache['systemvars'] = array();
$result = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'count(*) as cnt', 'from' => 'mail_queue' ) );
$this->ipsclass->cache['systemvars']['mail_queue'] = intval( $result['cnt'] );
$this->ipsclass->cache['systemvars']['task_next_run'] = time() + 3600;
$this->ipsclass->update_cache( array( 'name' => 'systemvars', 'array' => 1, 'deletefirst' => 1 ) );
//-----------------------------------------
// Moderators
//-----------------------------------------
$this->ipsclass->cache['moderators'] = array();
require_once( ROOT_PATH.'sources/action_admin/moderator.php' );
$mod = new ad_moderator();
$mod->ipsclass =& $this->ipsclass;
$mod->rebuild_moderator_cache();
//-----------------------------------------
// Cal events / Birthdays
//-----------------------------------------
require_once( ROOT_PATH . 'sources/action_admin/calendars.php' );
$calendars = new ad_calendars();
$calendars->ipsclass =& $this->ipsclass;
$calendars->calendar_rebuildcache( 0 );
//-------------------------------------------------------------
// Ranks
//-------------------------------------------------------------
$this->ipsclass->cache['ranks'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => 'id, title, pips, posts',
'from' => 'titles',
'order' => "posts DESC",
) );
$this->ipsclass->DB->simple_exec();
while ($i = $this->ipsclass->DB->fetch_row())
{
$this->ipsclass->cache['ranks'][ $i['id'] ] = array(
'TITLE' => $i['title'],
'PIPS' => $i['pips'],
'POSTS' => $i['posts'],
);
}
$this->ipsclass->update_cache( array( 'name' => 'ranks', 'array' => 1, 'deletefirst' => 1 ) );
//-------------------------------------------------------------
// SETTINGS
//-------------------------------------------------------------
require_once( ROOT_PATH . 'sources/action_admin/settings.php' );
$settings = new ad_settings();
$settings->ipsclass =& $this->ipsclass;
$settings->setting_rebuildcache();
//-------------------------------------------------------------
// EMOTICONS
//-------------------------------------------------------------
$this->ipsclass->cache['emoticons'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => 'typed,image,clickable,emo_set', 'from' => 'emoticons' ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->cache['emoticons'][] = $r;
}
$this->ipsclass->update_cache( array( 'name' => 'emoticons', 'array' => 1, 'deletefirst' => 1 ) );
//-------------------------------------------------------------
// LANGUAGES
//-------------------------------------------------------------
$this->ipsclass->cache['languages'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => 'ldir,lname', 'from' => 'languages' ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->cache['languages'][] = $r;
}
$this->ipsclass->update_cache( array( 'name' => 'languages', 'array' => 1, 'deletefirst' => 1 ) );
//-------------------------------------------------------------
// ATTACHMENT TYPES
//-------------------------------------------------------------
$this->ipsclass->cache['attachtypes'] = array();
$this->ipsclass->DB->simple_construct( array( 'select' => 'atype_extension,atype_mimetype,atype_post,atype_photo,atype_img', 'from' => 'attachments_type', 'where' => "atype_photo=1 OR atype_post=1" ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->cache['attachtypes'][ $r['atype_extension'] ] = $r;
}
$this->ipsclass->update_cache( array( 'name' => 'attachtypes', 'array' => 1, 'deletefirst' => 1 ) );
$this->ipsclass->core->redirect( "index.php?act=templates&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}", "Caches rebuilt, proceeding to rebuild templates..." );
}
/*-------------------------------------------------------------------------*/
// MODULE RUN - Look for next, or finish up...
/*-------------------------------------------------------------------------*/
function module_complete()
{
$message = array();
//--------------------------------
// Upgrade templates
//--------------------------------
if ( @file_exists( THIS_PATH.'upg_'.$this->ipsclass->current_upgrade.'/components.php' ) )
{
require_once( THIS_PATH.'upg_'.$this->ipsclass->current_upgrade.'/components.php' );
$this->ipsclass->DB->do_update( 'skin_sets', array( 'set_css' => $CSS,
'set_cache_css' => $CSS,
'set_wrapper' => $WRAPPER,
'set_cache_wrapper' => $WRAPPER,
), 'set_skin_set_id=1' );
$message[] = "Template components updated...";
}
//--------------------------------
// ACP Perms
//--------------------------------
if ( @file_exists( THIS_PATH.'upg_'.$this->ipsclass->current_upgrade.'/ipb_acpperms.xml' ) )
{
//-------------------------------
// Load module...
//-------------------------------
require_once( ROOT_PATH . 'sources/action_admin/acppermissions.php' );
$settings = new ad_acppermissions();
$settings->ipsclass =& $this->ipsclass;
//-------------------------------
// Set location
//-------------------------------
$this->ipsclass->input['file_location'] = UPGRADE_DIR.'/upg_'.$this->ipsclass->current_upgrade.'/ipb_acpperms.xml';
//-------------------------------
// Run it
//-------------------------------
$settings->acpperms_xml_import( 1 );
$message[] = $this->ipsclass->main_msg;
}
//--------------------------------
// Settings
//--------------------------------
if ( @file_exists( THIS_PATH.'upg_'.$this->ipsclass->current_upgrade.'/ipb_settings_partial.xml' ) )
{
//-------------------------------
// Load module...
//-------------------------------
require_once( ROOT_PATH . 'sources/action_admin/settings.php' );
$settings = new ad_settings();
$settings->ipsclass =& $this->ipsclass;
//-------------------------------
// Set location
//-------------------------------
$this->ipsclass->input['file_location'] = UPGRADE_DIR.'/upg_'.$this->ipsclass->current_upgrade.'/ipb_settings_partial.xml';
//-------------------------------
// Run it
//-------------------------------
$settings->settings_do_import( 1 );
$message[] = $this->ipsclass->main_msg;
}
//------------------------------------------
// Update DB
//------------------------------------------
$this->ipsclass->DB->do_insert( 'upgrade_history', array( 'upgrade_version_id' => $this->ipsclass->current_upgrade,
'upgrade_version_human' => $this->ipsclass->versions[ $this->ipsclass->current_upgrade ],
'upgrade_date' => time(),
'upgrade_mid' => $this->ipsclass->input['mid']
) );
//------------------------------------------
// Anymore to run?
//------------------------------------------
if ( $this->ipsclass->last_poss_id != $this->ipsclass->current_upgrade )
{
$this->ipsclass->core->redirect( "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}",
implode( "
", $message ) . "
Upgrade module complete, moving on to the next upgrade module...." );
}
else
{
$this->ipsclass->template->content .= "
IPB Upgrade Complete
".implode( "
", $message ) . "
You have now been upgraded from {$this->ipsclass->versions[$this->ipsclass->current_version]} to {$this->ipsclass->versions[$this->ipsclass->current_upgrade]}
The next few final steps will check for updated settings and recache your cached data (forums, groups, moderators, etc) and rebuild your master templates to ensure
that all the template additions and modifications are updated.
";
$this->ipsclass->template->output();
}
}
/*-------------------------------------------------------------------------*/
// Redirect
/*-------------------------------------------------------------------------*/
function redirect($url, $text, $time=2)
{
$this->ipsclass->template->content .= "
";
$this->ipsclass->template->output("Redirecting...");
}
/*-------------------------------------------------------------------------*/
// SHOW LOG IN SCREEN
/*-------------------------------------------------------------------------*/
function login_screen($msg='')
{
if ( ! file_exists( ROOT_PATH.'ipb_templates.xml' ) )
{
$alert .= "Cannot locate XML templates
This should be located in 'ipb_templates.xml' please ensure this file is uploaded (recreating the file structure if needed) before continuing.
Failure to upload this file will mean that your templates will not be updated.
";
}
if ( ! is_writeable( CACHE_PATH . 'cache/skin_cache' ) )
{
$alert .= "WARNING: cache/skin_cache is not writeable
Please check the CHMOD value on this folder before continuing. Failure to do so could mean that
your skin files will not be installed correctly.
";
}
if ( $alert )
{
$this->ipsclass->template->content .= "{$alert}";
$this->ipsclass->template->output("WARNING");
exit();
}
if ( $msg != "" )
{
$msg = "$msg
";
}
$this->ipsclass->template->content .= "
";
$this->ipsclass->template->output("Log In");
}
/*-------------------------------------------------------------------------*/
// Authorise da membah
/*-------------------------------------------------------------------------*/
function get_member()
{
$member = array( 'id' => 0 );
$this->ipsclass->loginkey = $this->check_md5( $this->ipsclass->input['loginkey'] );
$this->ipsclass->securekey = $this->check_md5( $this->ipsclass->input['securekey'] );
$this->ipsclass->member_id = trim(intval($this->ipsclass->input['mid'] ) );
if ( ! $this->ipsclass->loginkey or ! $this->ipsclass->securekey )
{
return $member;
}
$this->ipsclass->DB->query( "SELECT m.*, g.* FROM ibf_members m
LEFT JOIN ibf_groups g ON ( m.mgroup=g.g_id )
WHERE member_login_key='{$this->ipsclass->loginkey}' and id='{$this->ipsclass->member_id}'" );
$member = $this->ipsclass->DB->fetch_row();
return $member;
}
/*-------------------------------------------------------------------------*/
// Get the current version and the next version to upgrade to..
/*-------------------------------------------------------------------------*/
function get_version_latest()
{
$this->ipsclass->current_version = '';
$this->ipsclass->current_upgrade = '';
//------------------------------------------
// Copy & pop DB array and get next
// upgrade script
//------------------------------------------
$tmp = $this->ipsclass->db_contents;
$this->ipsclass->current_version = array_pop( $tmp );
//------------------------------------------
// Get the next upgrade script
//------------------------------------------
ksort( $this->ipsclass->dir_contents );
foreach( $this->ipsclass->dir_contents as $i => $a )
{
if ( $a > $this->ipsclass->current_version )
{
if ( ! $this->ipsclass->current_upgrade )
{
$this->ipsclass->current_upgrade = $a;
}
$this->ipsclass->modules_to_run[] = $this->ipsclass->versions[ $a ];
}
}
}
/*-------------------------------------------------------------------------*/
// GET INFO FROM THE DERTABASTIC
/*-------------------------------------------------------------------------*/
function get_db_structure()
{
$vers = array();
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'upgrade_history', 'order' => 'upgrade_version_id ASC' ) );
$this->ipsclass->DB->simple_exec();
while( $r = $this->ipsclass->DB->fetch_row() )
{
$vers[ $r['upgrade_version_id'] ] = $r['upgrade_version_id'];
}
return $vers;
}
/*-------------------------------------------------------------------------*/
// Get dir structure..
/*-------------------------------------------------------------------------*/
function get_dir_structure()
{
$return = array();
//------------------------------------------
// Get the folder names
//------------------------------------------
$dh = opendir( THIS_PATH );
while ( $file = readdir( $dh ) )
{
if ( is_dir( THIS_PATH."/".$file ) )
{
if ( $file != "." && $file != ".." )
{
if ( strstr( $file, 'upg_' ) )
{
$tmp = str_replace( "upg_", "", $file );
$return[ $tmp ] = $tmp;
}
}
}
}
closedir( $dh );
sort($return);
return $return;
}
/*-------------------------------------------------------------------------*/
// Check to see if its a 'real' MD5
/*-------------------------------------------------------------------------*/
function check_md5($t)
{
$t = preg_replace( "#[^a-z0-9]#", "", trim($t) );
if ( strlen($t) != 32 )
{
return '';
}
else
{
return $t;
}
}
}
?>