|
// +---------------------------------------------------------------------------+
/**
* 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 ='
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; } } ?>