CVS update: /cowiki/htdocs/setup/
[email protected] 2 Aug 2005 22:13:31 -0000
| Newsgroups | gmane.comp.php.cowiki.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: dgorski Date: 2005/08/02 15:13:31 Modified: cowiki/htdocs/setup/installer.php Log: Introduction a proxy script File Changes: Directory: /cowiki/htdocs/setup/ ================================ File [changed]: installer.php Url: http://cowiki.tigris.org/source/browse/cowiki/htdocs/setup/installer.php?r1=1.6&r2=1.7 Delta lines: +12 -471 ---------------------- --- installer.php 26 May 2005 20:37:30 -0000 1.6 +++ installer.php 2 Aug 2005 22:13:28 -0000 1.7 @@ -2,7 +2,7 @@ /** * - * $Id: installer.php,v 1.6 2005/05/26 20:37:30 dgorski Exp $ + * $Id: installer.php,v 1.7 2005/08/02 22:13:28 dgorski Exp $ * * This file is part of coWiki. coWiki is free software under the terms of * the GNU General Public License (GPL). Read the LICENSE file. If you did @@ -17,19 +17,13 @@ * @author Daniel T. Gorski, <[email protected]> * @copyright (C) Daniel T. Gorski, {@link http://www.develnet.org} * @license http://www.gnu.org/licenses/gpl.html - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * */ - // This installer controller is a bit weird in its flow. Is is not - // nice, but pragmatic solution. Be careful if you change it, please. - - // If you change something please make sure, that the forward/backward - // navigation won't break, even if there are task blocks, that are - // defined to be skipped or need validation. - - error_reporting(E_ALL | E_STRICT); - set_magic_quotes_runtime(0); +// ------------------------------------------------------------------------ +// ATTENTION: THIS SCRIPT HAVE TO WORK WITHOUT DEPENDENCIES WITH PHP4! +// ------------------------------------------------------------------------ header('Expires: Sat, 05 Aug 2000 22:27:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); @@ -38,471 +32,18 @@ header('Cache-Control: post-check=0, pre-check=0'); header('Vary: Accept-Encoding, User-Agent'); - define('SETUP_PATH', dirname($_SERVER['SCRIPT_FILENAME'])); - - define('SETUP_FIELDSET_SEPARATOR', - '<table style="margin:5px 0px 5px 0px" width="100%" - cellpadding="0" cellspacing="0" border="0"> - <tr> - <td bgcolor="#CCCCCC"><img src="img/0.gif" width="1" - height="1" alt="" border="0"/></td> - </tr> - <tr> - <td bgcolor="#FFFFFF"><img src="img/0.gif" width="1" - height="1" alt="" border="0"/></td> - </tr> - </table>' - ); - // -------------------------------------------------------------------- - // Start the main controller - try { - main(); - - } catch (Exception $e) { - - echo $e->getName() .' in '.$e->getFile().' in line '.$e->getLine(); - echo '<br />'; - echo $e->getMessage(); - echo '<pre>'; - echo $e->getTraceAsString(); - echo '</pre>'; - exit; - } - - // -------------------------------------------------------------------- - - function main() { - - // Init StateHolder (session) - $StateHolder = StateHolder::getInstance(); - - // ---------------------------------------------------------------- - - // Do not care about send data if a Location-redirection is - // required. - ob_start(); - - // Trim all posted data - // Working with escaped values is annoying and confusing - foreach($_POST as $k => $v) { - if (ini_get('magic_quotes_gpc')) { - $_POST[$k] = stripslashes(trim($v)); - } else { - $_POST[$k] = trim($v); - } - } - - // ---------------------------------------------------------------- + $sPath = dirname($_SERVER['SCRIPT_FILENAME']); // Include and init required files - include SETUP_PATH.'/function.php'; - include SETUP_PATH.'/../version.php'; - - // Check if valid installer id and direction parameters are given - $sInstId = 'invitator'; - if (isset($_REQUEST['id'])) { - $sInstId = preg_replace('#[^a-z_-]#i', '', $_REQUEST['id']); - } - - $sDir = ''; - if (isset($_REQUEST['dir'])) { - $sDir = preg_replace('#[^a-z]#', '', $_REQUEST['dir']); - } - - // ---------------------------------------------------------------- - - // This script has been called with a reference, where we need to - // return after we are finished or cancelled? - if (isset($_REQUEST['ref'])) { - $StateHolder->setReturnReferenceScript($_REQUEST['ref']); - } - - // Check if "Cancel" or "Finish" has been triggered, leave script - if (isset($_POST['submit'])) { - - if ($_POST['submit'] == 'Cancel' - || $_POST['submit'] == 'Finish') { - - // Check if we have a non-standard return target. E.g. if - // the installer has been called from the administration - // area. - if ($StateHolder->getReturnReferenceScript() != '') { - redirectTo('../'.$StateHolder->getReturnReferenceScript()); - } else { - redirectTo('../'); - } - } - } - - // ---------------------------------------------------------------- - - // Get flow definition from flow.xml file - $DomDoc = new DOMDocument(); - - if (!@$DomDoc->load(SETUP_PATH.'/flow.xml')) { - // FIX: better message/behaviour - die(SETUP_PATH.'/flow.xml not found or not readable.'); - } - - // Init XPath - $XPath = new DOMXPath($DomDoc); - - // ---------------------------------------------------------------- - - // Get all installer steps (the complete flow definition) - $FlowList = $XPath->query('/setup/flow/installer'); - - // Get installer element defined by the current installer id - $InstList = $XPath->query('/setup/flow/installer[@id="'.$sInstId.'"]'); - - // Check if we got a DOM NodeList returned - if (!is_object($InstList->item(0))) { - // FIX: better message/behaviour - die('Installer with id "'.$sInstId.'" not found in - flow.xml definition.'); - } - - // ---------------------------------------------------------------- - - // Get id of the target to jump to if a task is not required - $sSkipTargetId = $InstList->item(0)->getAttribute('skip_id'); - - // Get the name of the installer task class - $sInstClass = $InstList->item(0) - ->getElementsByTagName('class')->item(0)->nodeValue; - - // Get the label of the installer task - $sInstLabel = $InstList->item(0) - ->getElementsByTagName('label')->item(0)->nodeValue; - - // Get the label of the installer task - $sInstTitle = $InstList->item(0) - ->getElementsByTagName('title')->item(0)->nodeValue; - - // Get button definitions - $ButList = $XPath->query('button', $InstList->item(0)); - - // ---------------------------------------------------------------- - - // Init HTML template processor - $Tpl = new InstallerTemplateProcessor(); - - // Set window title - $Tpl->assign('TPL_WINDOW_TITLE', $sInstTitle); - - // Set software version and stuff - $Tpl->assign('TPL_SOFTWARE_VERSION', COWIKI_FULL_NAME); - $Tpl->assign('TPL_SOFTWARE_RELEASE', COWIKI_RELEASE); - $Tpl->assign('TPL_SOFTWARE_HOME', COWIKI_HOME); - - $Tpl->assign('TPL_CURRENT_YEAR', date('Y')); - - // Set formular data - $Tpl->assign('TPL_FORM_ACTION', $_SERVER['PHP_SELF']); - - $sStr = '<input type="hidden" name="id" value="'.$sInstId.'">'; - $Tpl->assign('TPL_FORM_DATA', $sStr); - - // ---------------------------------------------------------------- - - // Fetch and generate setup step-by-step progress list - - $aRow = array(); - $bAfterCurrent = false; - $bResetCurrent = false; - - for ($i=0, $n=$FlowList->length; $i<$n; $i++) { - - $sId = $FlowList->item($i)->getAttribute('id'); - $sLabel = $FlowList->item($i)->getElementsByTagName('label') - ->item(0)->nodeValue; - - $aArr = array(); - $aArr['id'] = $sId; - $aArr['label'] = trim($sLabel); - $aArr['status'] = $bAfterCurrent ? 'incomplete' : 'complete'; - - if ($aArr['id'] == $sInstId) { - $aArr['status'] = 'current'; - $bAfterCurrent = true; - } - - if ($aArr['label'] == '') { - if ($bAfterCurrent && $aArr['id'] == $sInstId) { - if (!$bResetCurrent) { - $aRow[sizeof($aRow)-1]['status'] = 'current'; - $bResetCurrent = true; - } - } - continue; - } - - $aRow[] = $aArr; - } - - // --- - - $sStr = '<table cellpadding="0" cellspacing="0" border="0">'; - - foreach ($aRow as $v) { - - $sStyle = ''; - $sIcon = '0.gif'; - - switch ($v['status']) { - case 'complete': - $sIcon = 'icon.true.gif'; - break; - - case 'current': - $sStyle = 'background-color:#E8E8E8'; - $sIcon = 'icon.current.gif'; - break; + include $sPath . '/../version.php'; - case 'incomplete': - $sIcon = 'icon.false.gif'; - break; - } - - $sStr .= '<tr>'; - $sStr .= '<td style="'.$sStyle.'">'; - $sStr .= '<img src="img/'.$sIcon.'" width="16" height="16"'; - $sStr .= ' alt="" border="0">'; - $sStr .= '</td>'; - $sStr .= '<td style="'.$sStyle.'"> </td>'; - $sStr .= '<td width="100%"'; - $sStr .= ' style="padding-right:3px;'.$sStyle.'" nowrap>'; - - if ($v['status'] == 'complete') { - $sStr .= '<a href="installer.php?id='.$v['id'].'">'; - $sStr .= @$v['label']; - $sStr .= '</a>'; - } else { - $sStr .= @$v['label']; - } - - $sStr .= '</td>'; - $sStr .= '</tr>'; - } - - $sStr .= '</table>'; - - $Tpl->assign('TPL_SETUP_PROGRESS', $sStr); - - // ---------------------------------------------------------------- - - // Generate buttons - $sStr = '<table width="100%" cellpadding="8" cellspacing="0"'; - $sStr .= ' border="0">'; - $sStr .= '<tr>'; - - $bFlag = false; - - for ($i=0, $n=$ButList->length; $i<$n; $i++) { - - if ($ButList->item($i)->getAttribute('align') == 'right' - && !$bFlag) { - - $sStr .= '<td width="100%"> </td>'; - $bFlag = true; - } - - $sVal = htmlentities(trim($ButList->item($i)->nodeValue)); - - $sStr .= '<td>'; - $sStr .= '<input class="submit" type="submit" name="submit"'; - $sStr .= ' value="'.$sVal.'">'; - $sStr .= '</td>'; - } - - $sStr .= '<td>'; - $sStr .= '<input class="submit" type="submit" name="submit"'; - $sStr .= ' value="Cancel"'; - - if ($sInstId == 'finish') { - $sStr .= ' disabled="true"'; - } - - $sStr .= '>'; - $sStr .= '</td>'; - - $sStr .= '</tr>'; - $sStr .= '</table>'; - - $Tpl->assign('BUTTONS', $sStr); - - // ---------------------------------------------------------------- - - // Instantiate task processor class - $Task = new $sInstClass($Tpl); - - // Check if it is required to execute the task. If not, go to the - // next task in the flow definition. If we are moving backwards in - // the wizard, go to the previous task. - if (!$Task->isRequired()) { - - // We are not moving backwards, skip this task - if ($sDir != 'backward') { - redirectToController('id='.$sSkipTargetId); - } - - // We are moving backwards, get the button target id of the - // button that points backwards. - for ($i=0, $n=$ButList->length; $i<$n; $i++) { - if ($ButList->item($i)->getAttribute('dir') == 'backward') { - $sTargetId = $ButList->item($i)->getAttribute('target_id'); - - redirectToController('id='.$sTargetId.'&dir=backward'); - } - } - } - - // ---------------------------------------------------------------- - - // If data has been posted, check if we need to validate it. If the - // validation fails redisplay the task. If everything is ok, go - // further to the next task. - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - - $Button = null; - - // Get the XML definition of the button that has been pressed - // and submitted. This is a simple string comparison as all - // buttons need to have different labels. - for ($i=0, $n=$ButList->length; $i<$n; $i++) { - - if ($_POST['submit'] == trim($ButList->item($i)->nodeValue)) { - $Button = $ButList->item($i); - break; - } - } - - // If a button is defined in the XML flow file, react on its - // invocation. - if (is_object($Button)) { - $sTargetId = $Button->getAttribute('target_id'); - - // If direction (dir) attribute for the button is 'forward', - // we need to tell the Task class to validate its data. - if ($Button->getAttribute('dir') == 'forward') { - - // Fall through if validation fails - if ($Task->validate()) { - redirectToController('id='.$sTargetId); - } - } - - // If direction (dir) attribute for the button is 'backward', - // no validation need to be performed. - if ($Button->getAttribute('dir') == 'backward') { - redirectToController('id='.$sTargetId.'&dir=backward'); - } - } - - // If no button definition was found in the XML flow file, but - // we've received a POST submission though, it means that a - // task-class wants probably to validate its values itself. - // In this case we call the validate() method, but do not care - // what the class is going to do with its data. No redirection - // will be triggered. - if (!is_object($Button)) { - $Task->validate(); - } - } - - // ---------------------------------------------------------------- - - // Render the installer task 'window' - $Task->render(); - - } // of main() - - - // === HELPER FUNCTIONS =============================================== - - /** - * Class autoloader for the installer/setup classes. If all include - * paths are set properly, this loader will also invoke the ClassLoader - * of the main application itself. - * - * @author Daniel T. Gorski, <[email protected]> - * @since coWiki 0.4.0 - */ - function __autoload($sClass) { - static $aPaths = null; - - if (!$aPaths) { - $sDir = SETUP_PATH . '/class/'; - if (!is_dir($sDir)) { - echo 'Classpath error'; // FIX - } - $aPaths = getClassPaths($sDir); - } - - // If the requested class is an installer class, load it. If not, - // try the ClassLoader (if it exists) of the application. - if (!@include_once $aPaths[$sClass]) { - if (class_exists('ClassLoader')) { - ClassLoader::getInstance()->load($sClass); - } - } - } + // Compares the version and emmit an error in browser if neccessary. + include $sPath . '/../version.compare.php'; // -------------------------------------------------------------------- - /** - * Helper function for __autoload() (local class loader) - * - * @author Daniel T. Gorski, <[email protected]> - * @since coWiki 0.4.0 - */ - function &getClassPaths($sDir) { - static $aArr = array(); - - $rDir = @opendir($sDir); - - while ($sFileName = @readdir($rDir)) { - switch ($sFileName) { - case '.': - case '..': - case 'CVS': - continue 2; - } - - if (is_dir($sDir . $sFileName)) { - getClassPaths($sDir . $sFileName . '/'); - } else { - $aParts = explode('.', $sFileName); - $aArr[$aParts[1]] = $sDir . $sFileName; - } - } - - closedir($rDir); - return $aArr; - } - -/* - Don't quiver little boy, your daddy's with you now - It won't be long anyhow - It's just around the corner - The destiny that I embrace with you - - Don't get too close to my fantasy - Don't be afraid to clutch the hand of your creator - Stare into the lion's eyes and if you taste the candy - You'll get to the surprise - - Stay calm little dreamer and drift off into dreams - The gentle kiss of night is better than it seems - It's just around the corner - Close your eyes and soon you'll be with me - - Don't get too close to my fantasy - Don't be afraid to clutch the hand of your creator - Stare into the lion's eyes and if you taste the candy - You'll get to the surprise -*/ + include 'installer.proxy.php'; ?>