| // +---------------------------------------------------------------------------+ /** * Provides various static methods required for install routine. * @package Install */ class SGL_Install_Common { function errorPush($error) { if (!isset($GLOBALS['_SGL'])) { $GLOBALS['_SGL'] = array(); } if (!isset($_SESSION['ERRORS'])) { $_SESSION['ERRORS'] = array(); } array_push($_SESSION['ERRORS'], $error); } function errorCheck(&$page) { if (SGL_Install_Common::errorsExist()) { foreach ($_SESSION['ERRORS'] as $oError) { $out = $oError->getMessage() . '
'; $out .= $oError->getUserInfo(); $page->addElement('static', 'errors', 'Errors:', $out); } $_SESSION['ERRORS'] = array(); } } function errorsExist() { return @count($_SESSION['ERRORS']); } function errorPrint() { foreach ($_SESSION['ERRORS'] as $oError) { $msg = SGL_Error::toString($oError); if (stristr($msg, "%e")) { $msg = str_replace("%e", SGL_VAR_DIR, $msg); } $html ='
Error
' . $msg . '
'; print $html; } } /** * Returns a string indicating the framework version. * * @return string */ function getFrameworkVersion() { $version = file_get_contents(SGL_PATH . '/VERSION.txt'); return $version; } function ensureWebrootSet() { if (!defined('SGL_BASE_URL')) { if (@preg_match('/^(.*)\/.*\.php$/', $_SERVER['SCRIPT_NAME'], $aMatches)) { define('SGL_BASE_URL', $aMatches[1]); } else { die('Could not set webroot'); } } } /** * Returns html head section of page, only used for 'enter passwd for * access setup' screen * * @param string $title * * @see QuickFormOverride.php for header html used in QuickForm install wizard */ function printHeader($title = '') { if (SGL::runningFromCli() || defined('SGL_ADMIN_REBUILD')) { return false; } SGL_Install_Common::ensureWebrootSet(); $baseUrl = SGL_BASE_URL; $html = << Seagull Framework :: Installation

$title

HTML; print $html; } function printFooter() { if (SGL::runningFromCli() || defined('SGL_ADMIN_REBUILD')) { return false; } $html = << Powered by Seagull PHP Framework
HTML; print $html; } function printLoginForm() { $message = !empty($_SESSION['message']) ? $_SESSION['message'] : ''; $_SESSION = array(); $html = <<

 

 

 

Authorisation Required
$message
Password

HTML; print $html; } /** * Returns an array of modules scanned from filesystem. * * @return array */ function getModuleList() { $dir = SGL_MOD_DIR; $fileList = array(); $stack[] = $dir; while ($stack) { $currentDir = array_pop($stack); if ($dh = opendir($currentDir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' && $file !== '..' && $file !== '.svn') { $currentFile = "{$currentDir}/{$file}"; if (is_dir($currentFile)) { $fileList[] = "{$file}"; } } } } } sort($fileList); return $fileList; } function getMinimumModuleList() { return array('block', 'default', 'navigation', 'user'); } /** * This adds default values for the installer form, based on a ini file. * * @return array */ function overrideDefaultInstallSettings($aData = array()) { // flatten module array if exists if (array_key_exists('aModuleList', $aData)) { $aData['aModuleList'] = implode(',', $aData['aModuleList']); } // read in custom install defaults $customConfig = SGL_PATH . '/etc/customInstallDefaults.ini'; if (file_exists($customConfig)) { $aOverrideData = parse_ini_file($customConfig, true); } else { $aOverrideData = array(); } // override data passed as arg with custom data $aRet = array_merge($aData, $aOverrideData); // explode module data back to array if (!empty($aRet['aModuleList'])) { $aRet['aModuleList'] = explode(',', $aRet['aModuleList']); } return $aRet; } } if (!(function_exists('file_put_contents'))) { function file_put_contents($location, $data) { if (is_file($location)) { unlink($location); } $fileHandler = fopen ($location, "w"); fwrite ($fileHandler, $data); fclose ($fileHandler); return true; } } ?>