Файл: upgrade/index.php
Строк: 300
<?php
define('_PEEP_', true);
define('DS', DIRECTORY_SEPARATOR);
define('PEEP_DIR_ROOT', dirname(dirname(__FILE__)) . DS);
define('UPDATE_DIR_ROOT', PEEP_DIR_ROOT . 'upgrade' . DS);
require_once PEEP_DIR_ROOT . 'includes/config.php';
require_once PEEP_DIR_ROOT . 'includes/define.php';
require_once PEEP_DIR_UTIL . 'debug.php';
require_once PEEP_DIR_UTIL . 'string.php';
require_once PEEP_DIR_UTIL . 'file.php';
require_once UPDATE_DIR_ROOT . 'classes' . DS . 'autoload.php';
require_once UPDATE_DIR_ROOT . 'classes' . DS . 'error_manager.php';
require_once UPDATE_DIR_ROOT . 'classes' . DS . 'updater.php';
require_once PEEP_DIR_CORE . 'peep.php';
require_once PEEP_DIR_CORE . 'plugin.php';
spl_autoload_register(array('UPDATE_Autoload', 'autoload'));
UPDATE_ErrorManager::getInstance(true);
$autoloader = UPDATE_Autoload::getInstance();
$autoloader->addPackagePointer('BOL', PEEP_DIR_SYSTEM_PLUGIN . 'base' . DS . 'bol' . DS);
$autoloader->addPackagePointer('PEEP', PEEP_DIR_CORE);
$autoloader->addPackagePointer('UTIL', PEEP_DIR_UTIL);
$autoloader->addPackagePointer('UPDATE', UPDATE_DIR_ROOT . 'classes' . DS);
$db = Updater::getDbo();
PEEP_Auth::getInstance()->setAuthenticator(new PEEP_SessionAuthenticator());
/* ------------------- CORE UPDATE ------------------------ */
$currentBuild = (int) $db->queryForColumn("SELECT `value` FROM `" . PEEP_DB_PREFIX . "base_config` WHERE `key` = 'base' AND `name` = 'soft_build'");
$currentXmlInfo = (array) simplexml_load_file(PEEP_DIR_ROOT . 'soft-version.xml');
if ( (int) $currentXmlInfo['build'] > $currentBuild )
{
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 1 WHERE `key` = 'base' AND `name` = 'maintenance'");
$peeppUpdateDir = UPDATE_DIR_ROOT . 'updates' . DS;
$updateDirList = array();
$handle = opendir($peeppUpdateDir);
while ( ($item = readdir($handle)) !== false )
{
if ( $item === '.' || $item === '..' )
{
continue;
}
$dirPath = $peeppUpdateDir . ((int) $item);
if ( file_exists($dirPath) && is_dir($dirPath) )
{
$updateDirList[] = (int) $item;
}
}
sort($updateDirList);
foreach ( $updateDirList as $item )
{
if ( $item > $currentBuild )
{
include($peeppUpdateDir . $item . DS . 'update.php');
}
$updateXmlInfo = (array) simplexml_load_file($peeppUpdateDir . $item . DS . 'update.xml');
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = :build WHERE `key` = 'base' AND `name` = 'soft_build'", array('build' => $currentXmlInfo['build']));
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = :version WHERE `key` = 'base' AND `name` = 'soft_version'", array('version' => $currentXmlInfo['version']));
}
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 0 WHERE `key` = 'base' AND `name` = 'update_soft'");
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 0 WHERE `key` = 'base' AND `name` = 'maintenance'");
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 1 WHERE `key` = 'base' AND `name` = 'dev_mode'");
$entries = UPDATER::getLogger()->getEntries();
if ( !empty($entries) )
{
$query = "INSERT INTO `" . PEEP_DB_PREFIX . "base_log` (`message`, `type`, `key`, `timeStamp`) VALUES (:message, 'peep_update', 'core', :time)";
try
{
$db->query($query, array('message' => json_encode($entries), 'time' => time()));
}
catch ( Exception $e )
{
}
}
}
/* ----------------- CORE UPDATE END ------------------------ */
/* ----------------- PLUGIN UPDATE ------------------------ */
if ( !empty($_GET['plugin']) )
{
$query = "SELECT * FROM `" . PEEP_DB_PREFIX . "base_plugin` WHERE `key` = :key";
$result = $db->queryForRow($query, array('key' => trim($_GET['plugin'])));
// plugin not found
if ( empty($result) )
{
$mode = 'plugin_empty';
$hcMessage = "Error! Plugin '<b>" . htmlspecialchars($_GET['plugin']) . "</b>' not found.";
}
else
{
$xmlInfoArray = (array) simplexml_load_file(PEEP_DIR_ROOT . 'plugins' . DS . $result['module'] . DS . 'plugin.xml');
if ( (int) $xmlInfoArray['build'] > (int) $result['build'] )
{
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 1 WHERE `key` = 'base' AND `name` = 'maintenance'");
$peeppUpdateDir = PEEP_DIR_ROOT . 'plugins' . DS . $result['module'] . DS . 'update' . DS;
$updateDirList = array();
if ( file_exists($peeppUpdateDir) )
{
$handle = opendir($peeppUpdateDir);
while ( ($item = readdir($handle)) !== false )
{
if ( $item === '.' || $item === '..' )
{
continue;
}
if ( file_exists($peeppUpdateDir . ((int) $item)) && is_dir($peeppUpdateDir . ((int) $item)) )
{
$updateDirList[] = (int) $item;
}
}
sort($updateDirList);
foreach ( $updateDirList as $item )
{
if ( (int) $item > (int) $result['build'] )
{
include($peeppUpdateDir . $item . DS . 'update.php');
$query = "UPDATE `" . PEEP_DB_PREFIX . "base_plugin` SET `build` = :build, `update` = 0 WHERE `key` = :key";
$db->query($query, array('build' => (int) $item, 'key' => $result['key']));
}
}
}
$entries = UPDATER::getLogger()->getEntries();
if ( !empty($entries) )
{
$query = "INSERT INTO `" . PEEP_DB_PREFIX . "base_log` (`message`, `type`, `key`, `timeStamp`) VALUES (:message, 'peep_update', :key, :time)";
try
{
$db->query($query, array('message' => json_encode($entries), 'key' => $result['key'], 'time' => time()));
}
catch ( Exception $e )
{
}
}
$query = "UPDATE `" . PEEP_DB_PREFIX . "base_plugin` SET `build` = :build, `update` = 0, `title` = :title, `description` = :desc WHERE `key` = :key";
$db->query($query, array('build' => (int) $xmlInfoArray['build'], 'key' => $result['key'], 'title' => $xmlInfoArray['name'], 'desc' => $xmlInfoArray['description']));
$mode = 'plugin_update_success';
$hcMessage = "Update Complete! Plugin '<b>" . $result['key'] . "</b>' successfully updated.";
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 0 WHERE `key` = 'base' AND `name` = 'maintenance'");
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 1 WHERE `key` = 'base' AND `name` = 'dev_mode'");
}
else
{
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_plugin` SET `update` = 0 WHERE `key` = :key", array('key' => $result['key']));
$mode = 'plugin_up_to_date';
$hcMessage = "Error! Plugin '<b>" . $result['key'] . "</b>' is up to date.";
}
}
// update result actions
if ( !empty($_GET['back-uri']) )
{
$url = build_url_query_string(PEEP_URL_HOME . urldecode($_GET['back-uri']), array('plugin' => $_GET['plugin'], 'mode' => $mode));
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: " . $url);
exit;
}
else
{
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upgrader</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font:18px Tahoma;">
<div style="width:400px;margin:300px auto 0;font:14px Tahoma;">
<h3 style="color:#CF3513;font:bold 20px Tahoma;">Update Request</h3>
' . $hcMessage . ' <br />
Go to <a style="color:#3366CC;" href="' . PEEP_URL_HOME . '">Index Page</a> or <a style="color:#3366CC;" href="' . PEEP_URL_HOME . 'admin-board">Admin Board</a>
</div>
</body>
</html>
';
exit;
}
}
/* ------------------ PLUGIN UPDATE END -------------------- */
/* ----------------- THEME UPDATE ------------------------ */
if ( !empty($_GET['theme']) )
{
$query = "SELECT * FROM `" . PEEP_DB_PREFIX . "base_theme` WHERE `name` = :name";
$result = $db->queryForRow($query, array('name' => trim($_GET['theme'])));
// theme not found
if ( empty($result) )
{
$mode = 'theme_empty';
$hcMessage = "Error! Theme '<b>" . htmlspecialchars($_GET['theme']) . "</b>' not found.";
}
else
{
$xmlInfoArray = (array) simplexml_load_file(PEEP_DIR_ROOT . 'themes' . DS . $result['name'] . DS . 'theme.xml');
if ( (int) $xmlInfoArray['build'] > (int) $result['build'] )
{
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 1 WHERE `key` = 'base' AND `name` = 'maintenance'");
$entries = UPDATER::getLogger()->getEntries();
if ( !empty($entries) )
{
$query = "INSERT INTO `" . PEEP_DB_PREFIX . "base_log` (`message`, `type`, `key`, `timeStamp`) VALUES (:message, 'peep_update', :key, :time)";
try
{
$db->query($query, array('message' => json_encode($entries), 'key' => $result['name'], 'time' => time()));
}
catch ( Exception $e )
{
}
}
$query = "UPDATE `" . PEEP_DB_PREFIX . "base_theme` SET `update` = 0 WHERE `name` = :name";
$db->query($query, array('name' => $result['name']));
BOL_ThemeService::getInstance()->updateThemeInfo($result['name'], true);
$mode = 'theme_update_success';
$hcMessage = "Update Complete! Theme '<b>" . $result['title'] . "</b>' successfully updated.";
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 0 WHERE `key` = 'base' AND `name` = 'maintenance'");
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_config` SET `value` = 1 WHERE `key` = 'base' AND `name` = 'dev_mode'");
}
else
{
$db->query("UPDATE `" . PEEP_DB_PREFIX . "base_theme` SET `update` = 0 WHERE `name` = :name", array('name' => $result['name']));
$mode = 'theme_up_to_date';
$hcMessage = "Error! Theme '<b>" . $result['title'] . "</b>' is up to date.";
}
}
// update result actions
if ( !empty($_GET['back-uri']) )
{
$url = build_url_query_string(PEEP_URL_HOME . urldecode($_GET['back-uri']), array('theme' => $_GET['theme'], 'mode' => $mode));
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: " . $url);
exit;
}
else
{
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upgrader</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font:18px Tahoma;">
<div style="width:400px;margin:300px auto 0;font:14px Tahoma;">
<h3 style="color:#CF3513;font:bold 20px Tahoma;">Update Request</h3>
' . $hcMessage . ' <br />
Go to <a style="color:#3366CC;" href="' . PEEP_URL_HOME . '">Index Page</a> or <a style="color:#3366CC;" href="' . PEEP_URL_HOME . 'admin-board">Admin Board</a>
</div>
</body>
</html>
';
exit;
}
}
/* ------------------ THEME UPDATE END -------------------- */
if ( !empty($peeppUpdateDir) )
{
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Peepmatches Upgrader</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div style="width:400px;margin:100px auto 0;font:16px Tahoma; background:#cdcdcd; padding:20px; border-radius:8px;">
<h3 style="color:#777;font:bold 20px Tahoma;">Upgrade Process Completed</h3>
Your site has been successfully upgraded to <b>' . $currentXmlInfo['version'] . '</b>!<br />
Go to <a style="color:#3366CC;" href="' . PEEP_URL_HOME . '">Index Page</a> or <a style="color:#3366CC;" href="' . PEEP_URL_HOME . 'admin-board">Admin Board</a>
</div>
</body>
</html>
';
}
else
{
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Peepmatches Upgrader</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font:18px Tahoma;">
<div style="width:400px;margin:100px auto 0;font:16px Tahoma; background:#cdcdcd; padding:20px; border-radius:8px;">
<h3 style="color:#777;font:bold 20px Tahoma;">Peepmatches Upgrade</h3>
Your site is already up to date to latest peepmatches version. <br /><br /><br />
Go to <a style="color:#3366CC;" href="' . PEEP_URL_HOME . '">Front site</a> or <a style="color:#3366CC;" href="' . PEEP_URL_HOME . 'admin-board">Admin Board</a>
</div>
</body>
</html>
';
}
/* ------------------- CORE UPDATE END ------------------------ */
/* functions */
function build_url_query_string( $url, array $paramsToUpdate = array(), $anchor = null )
{
$requestUrlArray = parse_url($url);
$currentParams = array();
if ( isset($requestUrlArray['query']) )
{
parse_str($requestUrlArray['query'], $currentParams);
}
$currentParams = array_merge($currentParams, $paramsToUpdate);
return $requestUrlArray['scheme'] . '://' . $requestUrlArray['host'] . $requestUrlArray['path'] . '?' . http_build_query($currentParams) . ( $anchor === null ? '' : '#' . trim($anchor) );
}
function printVar( $var )
{
UTIL_Debug::varDump($var);
}