IPB UPGRADE LOADER
| > Script written by Matt Mecham
| > Date started: 21st April 2004
| > Interesting fact: Radiohead rock (still)
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_IPB' ) )
{
print "
Некорректный адрес
Вы не имеете доступа к этому файлу напрямую. Если вы недавно обновляли форум, вы должны обновить все соответствующие файлы.";
exit();
}
class core_functions
{
/*-------------------------------------------------------------------------*/
// CONSTRUCTOR
/*-------------------------------------------------------------------------*/
function core_functions()
{
}
/*-------------------------------------------------------------------------*/
// FINISH _EVERYTHING_
/*-------------------------------------------------------------------------*/
function upgrade_complete()
{
$this->ipsclass->template->content .= "
Обновление IPB завершено!
Ваш форум успешно обновлен!
Вы должны отключить права на выполнение скрипта /upgrade/index.php или переименовать директорию /upgrade/. Иначе у вас могут быть проблемы с безопасностью.
";
$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']}", "Перестройка кеша для стиля «{$r['set_name']}»
{$extra}
Далее переходим к следующему стилю..." );
}
else
{
$this->ipsclass->core->redirect( "index.php?act=finish&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}", "Нет больше стилей для перестройки..." );
}
}
/*-------------------------------------------------------------------------*/
// 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("Ошибка в файле ipb_templates.xml невозможно выполнить этот XML файл");
}
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']}", "Перестройка мастер шаблонов, далее перестройка обычных шаблонов..." );
}
/*-------------------------------------------------------------------------*/
// 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']}", "Кеши перестроены, далее перестройка шаблонов..." );
}
/*-------------------------------------------------------------------------*/
// 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[] = "Шаблоны компонентов обновлены...";
}
//--------------------------------
// 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 ) . "
Обновление модуля завершено, перемещаемся к обновлению следующего модуля...." );
}
else
{
$this->ipsclass->template->content .= "
Обновление IPB завершено
".implode( "
", $message ) . "
Ваш форум был успешно обновлен с {$this->ipsclass->versions[$this->ipsclass->current_version]} до {$this->ipsclass->versions[$this->ipsclass->current_upgrade]}
Следующие финальные этапы проверят на обновления настройки и перестроят ваши кеш данные (форумы, группы, модераторы и т.д.), а также перестроят ваши мастер шаблоны...
";
$this->ipsclass->template->output();
}
}
/*-------------------------------------------------------------------------*/
// Redirect
/*-------------------------------------------------------------------------*/
function redirect($url, $text, $time=2)
{
$this->ipsclass->template->content .= "
";
$this->ipsclass->template->output("Переадресация...");
}
/*-------------------------------------------------------------------------*/
// SHOW LOG IN SCREEN
/*-------------------------------------------------------------------------*/
function login_screen($msg='')
{
if ( ! file_exists( ROOT_PATH.'ipb_templates.xml' ) )
{
$alert .= "Невозможно найти XML шаблоны
Они должны находиться в «ipb_templates.xml» пожалуйста проверьте, чтобы этот файл был загружен. Без него продолжение невозможно.
Если вы не загрузите этот файл, то ваши шаблоны не будут обновлены!
";
}
if ( ! is_writeable( CACHE_PATH . 'cache/skin_cache' ) )
{
$alert .= "ВНИМАНИЕ: Папка cache/skin_cache недоступна для записи
Пожалуйста, проверьте CHMOD для этой папки. Если вы проигнорируете это предупреждение, то файлы стилей
могут некорректно установиться.
";
}
if ( $alert )
{
$this->ipsclass->template->content .= "{$alert}";
$this->ipsclass->template->output("ВНИМАНИЕ");
exit();
}
if ( $msg != "" )
{
$msg = "$msg
";
}
$this->ipsclass->template->content .= "
";
$this->ipsclass->template->output("Войти");
}
/*-------------------------------------------------------------------------*/
// 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;
}
}
}
?>