smartified upgrader.inc

This commit is contained in:
Ian 2012-02-28 20:06:20 +01:00
parent 60f2535597
commit 3e192b0edd
2 changed files with 261 additions and 140 deletions

View File

@ -0,0 +1,147 @@
{if $task_function}
{'Calling %s ...<br />'|sprintf:(is_array($task['function']) ? $task['function'][0] . '::'. $task['function'][1] : $task['function'])}
{/if}
{if $errors}
{$CONST.DIAGNOSTIC_ERROR}<br /><br />
<div class="serendipityAdminMsgError">- <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="{serendipity_getFile file='admin/img/admin_msg_error.png'}" alt="" />{foreach $errors AS $implode_err}{$implode_err}{if (count($errors) > 1) && !$implode_err@last}<br /> {/if}{/foreach}</div><br /><br />
{/if}
{if ($smarty.get.action == 'ignore')}
{* Todo: Don't know what to put here? *}
{elseif ($smarty.get.action == 'upgrade')}
{foreach $call_tasks AS $ctask}
{if $is_callable_task}
{'Calling %s ...<br />'|sprintf:( is_array($ctask.function) ? "{$ctask.function.0} :: {$ctask.function.1}" : "$ctask.function" )}
{/if}
{/foreach}
{if $errors}
{$CONST.DIAGNOSTIC_ERROR}<br /><br />
<div class="serendipityAdminMsgError">- <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="{serendipity_getFile file='admin/img/admin_msg_error.png'}" alt="" />{foreach $errors AS $implode_err}{$implode_err}{if (count($errors) > 1) && !$implode_err@last}<br /> {/if}{/foreach}</div><br /><br />
{/if}
{/if}
{if (($showAbort && $smarty.get.action == 'ignore') || $smarty.get.action == 'upgrade')}
{if $smarty.get.action == 'ignore'}
{$CONST.SERENDIPITY_UPGRADER_YOU_HAVE_IGNORED}
{elseif $smarty.get.action == 'upgrade'}
<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="{serendipity_getFile file='admin/img/admin_msg_success.png'}" alt="" />{$CONST.SERENDIPITY_UPGRADER_NOW_UPGRADED|sprintf:$s9y_version}</div>
{/if}
<br />
<div align="center">{$CONST.SERENDIPITY_UPGRADER_RETURN_HERE|sprintf:'<a href="{$serendipityHTTPPath}">':'</a>'}</div>
{else}
<h2>{$CONST.SERENDIPITY_UPGRADER_WELCOME}</h2>
{$CONST.SERENDIPITY_UPGRADER_PURPOSE|sprintf:$s9y_version_installed}<br />
{$CONST.SERENDIPITY_UPGRADER_WHY|sprintf:$s9y_version}
<br />{$CONST.FIRST_WE_TAKE_A_LOOK}.
<br /><br />
<div align="center">{$result_diagnose}.<br />
<div align="center">
<table class="serendipity_admin_list_item serendipity_admin_list_item_even" width="90%" align="center">
{if $checksums}
<tr>
<td colspan="2" style="font-weight: bold">{$CONST.INTEGRITY}</td>
</tr>
{** upgraderResultDiagnoseX looks like <span class="serendipityAdminMsgSuccessInstall" style="color: green/orange/red; font-weight: bold">'. $s .'</span> **}
{** if known, class name color will be added for the inline style into php file **}
<tr>
<td width="200">
{foreach $upgraderResultDiagnose1 AS $urd1}
{$urd1}
{/foreach}
</td>
</tr>
{/if}
<tr>
<td colspan="2" style="font-weight: bold">{$CONST.PERMISSIONS}</td>
</tr>
<tr>
<td>{$basedir}</td>
<td width="200">
{foreach $upgraderResultDiagnose2 AS $urd2}
{$urd2}
{/foreach}
</td>
</tr>
<tr>
<td>{$basedir}{$CONST.PATH_SMARTY_COMPILE}</td>
<td width="200">
{foreach $upgraderResultDiagnose3 AS $urd3}
{$urd3}
{/foreach}
</td>
</tr>
{if $isdir_uploadpath}
<tr>
<td>{$basedir}{$uploadHTTPPath}</td>
<td width="200">
{foreach $upgraderResultDiagnose4 AS $urd4}
{$urd4}
{/foreach}
</td>
</tr>
{/if}
</table>
</div>
{if $showWritableNote}
<div class="serendipityAdminMsgNote"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="{serendipity_getFile file='admin/img/admin_msg_note.png'}" alt="" />{$CONST.PROBLEM_PERMISSIONS_HOWTO|sprintf:'chmod 1777'}</div>
{/if}
{if ($errorCount > 0)}
<div align="center">
<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="{serendipity_getFile file='admin/img/admin_msg_error.png'}" alt="" />{$CONST.PROBLEM_DIAGNOSTIC}</div>
<h2><a href="serendipity_admin.php">{$CONST.RECHECK_INSTALLATION}</a></h2>
</div>
{/if}
</div>
{if ($errorCount < 1)}
{if (sizeof($sqlfiles) > 0)}
<br />
<h3>{$database_update_types}:</h3>
{$CONST.SERENDIPITY_UPGRADER_FOUND_SQL_FILES}:<br />
{if is_array($sqlfiles) && !empty($sqlfiles)}
{foreach $sqlfiles as $sqlfile}
<div style="padding-left: 5px"><strong>{$sqlfile}</strong></div>
{/foreach}
{/if}
{/if}
<br />
<h3>{$CONST.SERENDIPITY_UPGRADER_VERSION_SPECIFIC}:</h3>
{if is_array($tasks) && !empty($tasks)}
{foreach $tasks as $task}
<div><strong>{$task.version} - {$task.title}</strong></div>
<div style="padding-left: 5px">{$task.desc|nl2br}</div><br />
{/foreach}
{if}
{if ($taskCount == 0)}
{$CONST.SERENDIPITY_UPGRADER_NO_VERSION_SPECIFIC}
{/if}
<br /><br />
<hr noshade="noshade">
{if (($taskCount > 0) || (sizeof($sqlfiles) > 0))}
<strong>{$CONST.SERENDIPITY_UPGRADER_PROCEED_QUESTION}</strong>
<br /><br /><a href="{$upgradeLoc}" class="serendipityPrettyButton input_button">{$CONST.SERENDIPITY_UPGRADER_PROCEED_DOIT}</a> {if $showAbort}<a href="{$abortLoc}" class="serendipityPrettyButton">{$CONST.SERENDIPITY_UPGRADER_PROCEED_ABORT}</a>{/if}
{else}
<strong>{$CONST.SERENDIPITY_UPGRADER_NO_UPGRADES}</strong>
<br /><br /><a href="{$upgradeLoc}" class="serendipityPrettyButton input_button">{$CONST.SERENDIPITY_UPGRADER_CONSIDER_DONE}</a>
{/if}
{/if}
{/if}{* showAbort else end *}

View File

@ -1,6 +1,4 @@
<?php # $Id$
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
if (IN_serendipity !== true) {
die ('Don\'t hack!');
@ -28,27 +26,41 @@ function serendipity_upgraderResultDiagnose($result, $s) {
global $errorCount;
if ( $result === S9Y_U_SUCCESS ) {
$data['u_success'] = true;
return '<span class="serendipityAdminMsgSuccessInstall" style="color: green; font-weight: bold">'. $s .'</span>';
}
if ( $result === S9Y_U_WARNING ) {
$data['u_warning'] = true;
return '<span class="serendipityAdminMsgWarningInstall" style="color: orange; font-weight: bold">'. $s .'</span>';
}
if ( $result === S9Y_U_ERROR ) {
$errorCount++;
$data['u_error'] = true;
return '<span class="serendipityAdminMsgErrorInstall" style="color: red; font-weight: bold">'. $s .'</span>';
}
}
/* shall we add the function to smarty ?? */
/*
function serendipity_smarty_backend_upgraderResultDiagnose($params, $smarty) {
$ssb_URD = serendipity_upgraderResultDiagnose($params[0], $params[1]);
$smarty->assign($ssb_URD);
}
*/
// Setting this value to 'FALSE' is recommended only for SHARED BLOG INSTALLATIONS. This enforces all shared blogs with a common
// codebase to only allow upgrading, no bypassing and thus causing instabilities.
// This variable can also be set as $serendipity['UpgraderShowAbort'] inside serendipity_config_local.inc.php to prevent
// your setting being changed when updating serendipity in first place.
$showAbort = (isset($serendipity['UpgraderShowAbort']) ? $serendipity['UpgraderShowAbort'] : true);
$data['showAbort'] = $showAbort;
$abortLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=ignore';
$upgradeLoc = $serendipity['serendipityHTTPPath'] . 'serendipity_admin.php?serendipity[action]=upgrade';
$data['abortLoc'] = $abortLoc;
$data['upgradeLoc'] = $upgradeLoc;
/* Functions which needs to be run if installed version is equal or lower */
$tasks = array(array('version' => '0.5.1',
@ -197,10 +209,12 @@ if ($serendipity['GET']['action'] == 'ignore') {
}
/* Call functions */
$data['call_tasks'] = array():
foreach ($tasks as $task) {
if (!empty($task['function']) && version_compare($serendipity['versionInstalled'], $task['version'], '<') ) {
if (is_callable($task['function'])) {
echo sprintf('Calling %s ...<br />', (is_array($task['function']) ? $task['function'][0] . '::'. $task['function'][1] : $task['function']));;
$data['is_callable_task'] = true;
$data['call_tasks'][] = $task;
if (empty($task['arguments'])) {
call_user_func($task['function']);
@ -214,8 +228,7 @@ if ($serendipity['GET']['action'] == 'ignore') {
}
if (sizeof($errors)) {
echo DIAGNOSTIC_ERROR . '<br /><br />';
echo '<div class="serendipityAdminMsgError">- <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . implode('<br />', $errors) . '</div><br /><br />';
$data['errors'] = $errors;
}
/* I don't care what you told me, I will always nuke Smarty cache */
@ -223,6 +236,9 @@ if ($serendipity['GET']['action'] == 'ignore') {
}
$data['s9y_version'] = $serendipity['version'];
$data['s9y_version_installed'] = $serendipity['versionInstalled'];
if (($showAbort && $serendipity['GET']['action'] == 'ignore') || $serendipity['GET']['action'] == 'upgrade') {
$privateVariables = array();
if (isset($serendipity['UpgraderShowAbort'])) {
@ -241,159 +257,117 @@ if (($showAbort && $serendipity['GET']['action'] == 'ignore') || $serendipity['G
);
if ($serendipity['GET']['action'] == 'ignore') {
echo SERENDIPITY_UPGRADER_YOU_HAVE_IGNORED;
$data['ignore'] = true;
} elseif ($serendipity['GET']['action'] == 'upgrade') {
printf('<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . SERENDIPITY_UPGRADER_NOW_UPGRADED .'</div>', $serendipity['version']);
// void
}
echo '<br />';
printf('<div align="center">'. SERENDIPITY_UPGRADER_RETURN_HERE .'</div>', '<a href="'. $serendipity['serendipityHTTPPath'] .'">', '</a>');
$data['return_here'] = true;
$_SESSION['serendipityAuthedUser'] = false;
@session_destroy();
} else {
echo '<h2>' . SERENDIPITY_UPGRADER_WELCOME . '</h2>';
printf(SERENDIPITY_UPGRADER_PURPOSE . '<br />', $serendipity['versionInstalled']);
printf(SERENDIPITY_UPGRADER_WHY . '.', $serendipity['version']);
echo '<br />' . FIRST_WE_TAKE_A_LOOK . '.';
?>
<br /><br />
<div align="center"><?php printf(ERRORS_ARE_DISPLAYED_IN, serendipity_upgraderResultDiagnose(S9Y_U_ERROR, RED), serendipity_upgraderResultDiagnose(S9Y_U_WARNING, YELLOW), serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, GREEN)); ?>.<br />
<?php
$data['upgrade'] = true;
$data['result_diagnose'] = sprintf(ERRORS_ARE_DISPLAYED_IN, serendipity_upgraderResultDiagnose(S9Y_U_ERROR, RED), serendipity_upgraderResultDiagnose(S9Y_U_WARNING, YELLOW), serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, GREEN));
$errorCount = 0;
$showWritableNote = false;
$basedir = $serendipity['serendipityPath'];
?>
<div align="center">
<table class="serendipity_admin_list_item serendipity_admin_list_item_even" width="90%" align="center">
<?php if (is_readable($basedir . 'checksums.inc.php')) {
$badsums = serendipity_verifyFTPChecksums();
?>
<tr>
<td colspan="2" style="font-weight: bold"><?php echo INTEGRITY ?></td>
</tr>
<tr>
<td width="200"><?php
if ( empty($badsums) ) {
echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, CHECKSUMS_PASS);
} else {
foreach ($badsums as $rfile => $sum) {
echo serendipity_upgraderResultDiagnose(S9Y_U_WARNING, sprintf(CHECKSUM_FAILED, $rfile)) . "<br />\n";
}
}
?></td>
</tr>
<?php } // End if checksums
?>
<tr>
<td colspan="2" style="font-weight: bold"><?php echo PERMISSIONS ?></td>
</tr>
<tr>
<td><?php echo $basedir ?></td>
<td width="200"><?php
if ( is_writable($basedir) ) {
echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
} else {
$showWritableNote = false;
#Figure out if we're set up a little more securely
#PATH_SMARTY_COMPILE/
#uploads/
#archives/
#.htaccess
#serendipity_config_local.inc.php
# For completeness we could test to make sure the directories
# really are directories, but that's probably overkill
foreach (array('archives/', PATH_SMARTY_COMPILE . '/', 'uploads/', '.htaccess', 'serendipity_config_local.inc.php') as $path) {
if (!is_writeable($basedir . $path)) {
echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
$showWritableNote = true;
break;
}
}
$data['basedir'] = $basedir;
$data['upgraderResultDiagnose1'] = array();
if (is_readable($basedir . 'checksums.inc.php')) {
$data['checksums'] = true;
$badsums = serendipity_verifyFTPChecksums();
if (!$showWritableNote) {
echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
}
}
?></td>
</tr>
<tr>
<td><?php echo $basedir . PATH_SMARTY_COMPILE?></td>
<td width="200"><?php
if ( is_writable($basedir . PATH_SMARTY_COMPILE) ) {
echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
} else {
echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
$showWritableNote = true;
}
?></td>
</tr>
<?php if (is_dir($basedir . $serendipity['uploadHTTPPath'])) { ?>
<tr>
<td><?php echo $basedir . $serendipity['uploadHTTPPath']; ?></td>
<td width="200"><?php
if (is_writable($basedir . $serendipity['uploadHTTPPath'])) {
echo serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
} else {
echo serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
$showWritableNote = true;
}
?></td>
</tr>
<?php } ?>
</table>
</div>
<?php if ($showWritableNote === true) { ?>
<div class="serendipityAdminMsgNote"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_note.png'); ?>" alt="" /><?php echo sprintf(PROBLEM_PERMISSIONS_HOWTO, 'chmod 1777') ?></div>
<?php }
if ($errorCount > 0) { ?>
<div align="center">
<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_error.png'); ?>" alt="" />
<?php echo PROBLEM_DIAGNOSTIC ?></div>
<h2><a href="serendipity_admin.php"><?php echo RECHECK_INSTALLATION ?></a></h2>
</div>
<?php }
?>
</div>
<?php
if ($errorCount < 1) {
if (sizeof($sqlfiles) > 0) { ?>
<br />
<h3><?php printf(SERENDIPITY_UPGRADER_DATABASE_UPDATES, $serendipity['dbType']) ?>:</h3>
<?php echo SERENDIPITY_UPGRADER_FOUND_SQL_FILES ?>:<br />
<?php
foreach ($sqlfiles as $sqlfile) {
echo '<div style="padding-left: 5px"><strong>'. $sqlfile .'</strong></div>';
if ( empty($badsums) ) {
$data['upgraderResultDiagnose1'][] = serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, CHECKSUMS_PASS);
} else {
foreach ($badsums as $rfile => $sum) {
$data['upgraderResultDiagnose1'][] = serendipity_upgraderResultDiagnose(S9Y_U_WARNING, sprintf(CHECKSUM_FAILED, $rfile));
}
}
?>
<br />
} // End if checksums
$data['upgraderResultDiagnose2'] = array();
if ( is_writable($basedir) ) {
$data['upgraderResultDiagnose2'][] = serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
} else {
$showWritableNote = false;
#Figure out if we're set up a little more securely
#PATH_SMARTY_COMPILE/
#uploads/
#archives/
#.htaccess
#serendipity_config_local.inc.php
# For completeness we could test to make sure the directories
# really are directories, but that's probably overkill
foreach (array('archives/', PATH_SMARTY_COMPILE . '/', 'uploads/', '.htaccess', 'serendipity_config_local.inc.php') as $path) {
if (!is_writeable($basedir . $path)) {
$data['upgraderResultDiagnose2'][] = serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
$showWritableNote = true;
break;
}
}
if (!$showWritableNote) {
$data['upgraderResultDiagnose2'][] = serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
}
}
$data['upgraderResultDiagnose3'] = array();
if ( is_writable($basedir . PATH_SMARTY_COMPILE) ) {
$data['upgraderResultDiagnose3'][] = serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
} else {
$data['upgraderResultDiagnose3'][] = serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
$showWritableNote = true;
}
$data['upgraderResultDiagnose4'] = array();
if (is_dir($basedir . $serendipity['uploadHTTPPath'])) {
$data['isdir_uploadpath'] = is_dir($basedir . $serendipity['uploadHTTPPath']);
if (is_writable($basedir . $serendipity['uploadHTTPPath'])) {
$data['upgraderResultDiagnose4'][] = serendipity_upgraderResultDiagnose(S9Y_U_SUCCESS, WRITABLE);
} else {
$data['upgraderResultDiagnose4'][] = serendipity_upgraderResultDiagnose(S9Y_U_ERROR, NOT_WRITABLE);
$showWritableNote = true;
}
}
$data['showWritableNote'] = $showWritableNote;
$data['errorCount'] = $errorCount;
if ($errorCount < 1) {
if (sizeof($sqlfiles) > 0) {
$data['database_update_types'] = sprintf(SERENDIPITY_UPGRADER_DATABASE_UPDATES, $serendipity['dbType']);
$data['sqlfiles'] = $sqlfiles;
}
<h3><?php echo SERENDIPITY_UPGRADER_VERSION_SPECIFIC ?>:</h3>
<?php
$taskCount = 0;
$data['tasks'] = array();
foreach ( $tasks as $task ) {
if (version_compare($serendipity['versionInstalled'], $task['version'], '<')) {
echo '<div><strong>'. $task['version'] .' - '. $task['title'] .'</strong></div>';
echo '<div style="padding-left: 5px">'. nl2br($task['desc']) .'</div><br />';
$data['tasks'][] = $task;
$taskCount++;
}
}
if ($taskCount == 0) {
echo SERENDIPITY_UPGRADER_NO_VERSION_SPECIFIC;
}
?>
<br /><br />
<hr noshade="noshade">
<?php if ($taskCount > 0 || sizeof($sqlfiles) > 0) { ?>
<strong><?php echo SERENDIPITY_UPGRADER_PROCEED_QUESTION ?></strong>
<br /><br /><a href="<?php echo $upgradeLoc; ?>" class="serendipityPrettyButton input_button"><?php echo SERENDIPITY_UPGRADER_PROCEED_DOIT ?></a> <?php if ($showAbort) { ?><a href="<?php echo $abortLoc; ?>" class="serendipityPrettyButton"><?php echo SERENDIPITY_UPGRADER_PROCEED_ABORT ?></a><?php } ?>
<?php } else { ?>
<strong><?php echo SERENDIPITY_UPGRADER_NO_UPGRADES ?></strong>
<br /><br /><a href="<?php echo $upgradeLoc; ?>" class="serendipityPrettyButton input_button"><?php echo SERENDIPITY_UPGRADER_CONSIDER_DONE ?></a>
<?php }
$data['taskCount'] = $taskCount;
}
}
if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
/* see on top */
#$serendipity['smarty']->registerPlugin('function', 'serendipity_upgraderResultDiagnose', 'serendipity_smarty_backend_upgraderResultDiagnose');
$serendipity['smarty']->assign($data);
$tfile = dirname(__FILE__) . "/tpl/upgrader.inc.tpl";
$content = $serendipity['smarty']->fetch('file:'. $tfile); // short notation with Smarty3 in S9y 1.7 and up
echo $content;
/* vim: set sts=4 ts=4 expandtab : */