function testLoadModule() { $m = databaseLoadModule('NOTEXISTINGMODULE'); $this->assertEquals(new Error('DATABASEMANAGER_MODULE_DOES_NOT_EXITS', 'NOTEXISTINGMODULE'), $m); $m = databaseLoadModule('MySQL'); $newMySQL = new mysqlDatabaseActions(); $this->assertEquals($newMySQL, $m); }
function setUp($moduleName) { //parent::__construct (); $this->_moduleName = $moduleName; $this->_module = databaseLoadModule($this->_moduleName); $a = $this->connect(); if ($a === false) { return; } }
function loadModuleFromConfig($module, $config) { $mod = databaseLoadModule($module); if (isError($mod)) { return $mod; } $mOpts = $config[$module]; $a = $mod->connect($mOpts['Host'], $mOpts['User'], $mOpts['Password'], $mOpts['DatabaseName']); if (isError($a)) { return $a; } $mod->setPrefix($mOpts['Prefix']); return $mod; }
function setUp() { $this->_dbModule = databaseLoadModule('XML'); $this->_dbModule->connect('core/tests', 'nathan', 'nopass'); $this->_dbModule->selectDatabase('test'); }
function installConfigAndDatabase($siteName, $siteDefaultLanguage, $databaseModule, $databaseHost, $databaseUser, $databasePassword, $databaseName, $databasePrefix, $adminLogin, $adminPassword, $adminMail) { $dbModule = databaseLoadModule($databaseModule); if (!isError($dbModule)) { $dbModule->connect($databaseHost, $databaseUser, $databasePassword, $databaseName); $dbModule->setPrefix($databasePrefix); $pluginManager = new pluginManager($this->_pluginAPI); $pluginManager->findAllPlugins('interface/core-plugins/'); // an hack for viewPage to be first $foundPlugins = array_reverse($pluginManager->getAllFoundPlugins()); foreach ($foundPlugins as $plugin) { if (is_a($plugin, 'InstallablePlugin')) { $a = $plugin->install($this->_pluginAPI, $dbModule, $siteDefaultLanguage); if (isError($a)) { var_dump($a); die('Something went wrong'); } } } $userM = new userManager($dbModule); $admin = $userM->newUser(); $a = $admin->initFromArray(array('login' => $adminLogin, 'password' => md5($adminPassword), 'email' => $adminMail)); $userM->addUserToDatabase($admin); $group = $userM->newGroup(); $group->initFromArray(array('generic_name' => 'administrator', 'generic_description' => 'The admin users')); $userM->addGroupToDatabase($group); $group->assignPermission('edit_admin', true); $admin->addToGroup($group); $group = $userM->newGroup(); $group->initFromArray(array('generic_name' => 'normaluser', 'generic_description' => 'All users')); $userM->addGroupToDatabase($group); $group->assignPermission('edit_admin', false); $admin->addToGroup($group); $group = $userM->newGroup(); $group->initFromArray(array('generic_name' => 'anonymous', 'generic_description' => 'Not logged in')); $userM->addGroupToDatabase($group); $group->assignPermission('edit_admin', false); $configContents = '<?php' . PHP_NL . PHP_NL; $configContents .= '$configItems[\'/databases/module\']=\'' . $databaseModule . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/host\']=\'' . $databaseHost . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/password\']=\'' . $databasePassword . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/user\']=\'' . $databaseUser . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/database\']=\'' . $databaseName . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/table_prefix\']=\'' . $databasePrefix . '\';' . PHP_NL . PHP_NL; $configContents .= '$configItems[\'/site/title\']=\'' . $siteName . '\';' . PHP_NL; $configContents .= '$configItems[\'/site/default_language\']=\'' . $siteDefaultLanguage . '\';' . PHP_NL; $configContents .= '$configItems[\'/site/enableUsers\']=true;' . PHP_NL; $configContents .= '$configItems[\'/languages/' . $siteDefaultLanguage . '\']=\'' . $siteDefaultLanguage . '\';' . PHP_NL; $configContents .= '?>'; $c = @fopen('config.php', 'w'); if ($c !== false) { fwrite($c, $configContents); fclose($c); header('Location: index.php'); } else { $sm =& $this->_pluginAPI->getSmarty(); $sm->assign('CONFIG_CONTENT', htmlspecialchars($configContents)); $sm->display('installer/save_config_manual.tpl'); } } else { var_dump($dbModule); } }
/** * Init the system. * @public */ function init() { parent::init(); $this->_pluginAPI = new PluginAPI($this); $this->_dbModule = databaseLoadModule($this->_configManager->getStringItem('/databases/module')); $e = $this->_dbModule->connect($this->_configManager->getStringItem('/databases/host'), $this->_configManager->getStringItem('/databases/user'), $this->_configManager->getStringItem('/databases/password'), $this->_configManager->getStringItem('/databases/database')); if (isError($e)) { $this->_pageManager = new PageManager($this->_dbDriver); $this->_userManager = new UserManager($this->_dbDriver); $this->loadPluginAPI(); $this->loadUserSettings(); $this->error($e); } $this->_dbModule->setPrefix($this->_configManager->getStringItem('/databases/table_prefix')); $this->_pageManager = new PageManager($this->_dbModule); $this->_userManager = new UserManager($this->_dbModule); $this->_pluginManager->findAllPlugins('interface/core-plugins'); $this->loadPluginAPI(); $this->loadUserSettings(); }
$c->loadConfigFile('config.php'); $_POST['action'] = 'installerInstall'; $_POST['siteName'] = $c->getStringItem('/site/title'); $_POST['siteDefaultLanguage'] = $c->getStringItem('/site/default_language'); $_POST['databaseModule'] = $c->getStringItem('/databases/module'); $_POST['databaseHost'] = $c->getStringItem('/databases/host'); $_POST['databaseUser'] = $c->getStringItem('/databases/user'); $_POST['databasePassword'] = $c->getStringItem('/databases/password'); $_POST['databaseName'] = $c->getStringItem('/databases/database'); $_POST['databasePrefix'] = $c->getStringItem('/databases/table_prefix'); $_POST['adminLogin'] = '******'; $_POST['adminPassword1'] = 'test'; $_POST['adminPassword2'] = 'test'; $_POST['adminMail'] = '*****@*****.**'; // lets hack some more $_SERVER['REQUEST_METHOD'] = 'POST'; $dbDriver = databaseLoadModule($_POST['databaseModule']); $dbDriver->connect($_POST['databaseHost'], $_POST['databaseUser'], $_POST['databasePassword'], $_POST['databaseName']); foreach ($dbDriver->getAllTables() as $t) { if (ereg('^' . $_POST['databasePrefix'], $t)) { $sql = "DROP TABLE {$t}"; $dbDriver->query($sql); } } $morgos = new BaseMorgos(); $morgos->run(); header('Location: index.php'); // header to index.php even if config.php is unwritable } else { die('config.php not found'); }
function installConfigAndDatabase($siteName, $databaseModule, $databaseHost, $databaseUser, $databasePassword, $databaseName, $databasePrefix, $adminLogin, $adminPassword, $adminMail) { $dbModule = databaseLoadModule($databaseModule); if (!isError($dbModule)) { $dbModule->connect($databaseHost, $databaseUser, $databasePassword); $dbModule->selectDatabase($databaseName); $dbModule->setPrefix($databasePrefix); $dbModule->queryFile('interface/installer/base-plugin/sqlCode.sql'); //var_dump ($dbModule); //die ('End'); $userM = new userManager($dbModule); $admin = $userM->newUser(); $a = $admin->initFromArray(array('login' => $adminLogin, 'password' => md5($adminPassword), 'email' => $adminMail)); $userM->addUserToDatabase($admin); $group = $userM->newGroup(); $group->initFromArray(array('genericName' => 'administrator', 'genericDescription' => 'The admin users')); $userM->addGroupToDatabase($group); $group->assignPermission('edit_admin', true); $admin->addToGroup($group); $group = $userM->newGroup(); $group->initFromArray(array('genericName' => 'normaluser', 'genericDescription' => 'All users')); $userM->addGroupToDatabase($group); $group->assignPermission('edit_admin', false); $admin->addToGroup($group); $group = $userM->newGroup(); $group->initFromArray(array('genericName' => 'anonymous', 'genericDescription' => 'Not logged in')); $userM->addGroupToDatabase($group); $group->assignPermission('edit_admin', false); $pageM = new pageManager($dbModule); $site = $pageM->newPage(); $admin = $pageM->newPage(); $home = $pageM->newPage(); $ahome = $pageM->newPage(); $pman = $pageM->newPage(); $pluman = $pageM->newPage(); $regform = $pageM->newPage(); $adminLogout = $pageM->newPage(); $adminUser = $pageM->newPage(); $site->initFromArray(array('name' => 'site', 'parentPageID' => 0, 'placeInMenu' => 0)); $admin->initFromArray(array('name' => 'admin', 'parentPageID' => 0, 'placeInMenu' => 0)); $pageM->addPageToDatabase($site); $pageM->addPageToDatabase($admin); $home->initFromArray(array('name' => 'MorgOS_Home', 'parentPageID' => $site->getID())); $ahome->initFromArray(array('name' => 'MorgOS_Admin_Home', 'parentPageID' => $admin->getID())); $pman->initFromArray(array('name' => 'MorgOS_Admin_PageManager', 'parentPageID' => $admin->getID(), 'action' => 'adminPageManager')); $pluman->initFromArray(array('name' => 'MorgOS_Admin_PluginManager', 'parentPageID' => $admin->getID(), 'action' => 'adminPluginManager')); $regform->initFromArray(array('name' => 'MorgOS_RegisterForm', 'parentPageID' => $site->getID(), 'action' => 'userRegisterForm', 'placeInMenu' => 0)); $adminLogout->initFromArray(array('name' => 'MorgOS_Admin_Logout', 'parentPageID' => $admin->getID(), 'action' => 'adminLogout')); $adminUser->initFromArray(array('name' => 'MorgOS_Admin_UserManager', 'parentPageID' => $admin->getID(), 'action' => 'adminUserManager')); $pageM->addPageToDatabase($home); $pageM->addPageToDatabase($ahome); $pageM->addPageToDatabase($pman); $pageM->addPageToDatabase($adminUser); $pageM->addPageToDatabase($pluman); $pageM->addPageToDatabase($regform); $pageM->addPageToDatabase($adminLogout); $tHome = $pageM->newTranslatedPage(); $tAHome = $pageM->newTranslatedPage(); $tPMan = $pageM->newTranslatedPage(); $tRegForm = $pageM->newTranslatedPage(); $tPlugMan = $pageM->newTranslatedPage(); $tALogout = $pageM->newTranslatedPage(); $tAdminUser = $pageM->newTranslatedPage(); $t =& $this->_pluginAPI->getI18NManager(); $tHome->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('Home'), 'translatedContent' => $t->translate('This is the homepage.'))); $tAHome->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('Admin'), 'translatedContent' => $t->translate('This is the admin. Here you can configure the site, add/remove and edit pages, or ban users.'))); $tPMan->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('Page Manager'), 'translatedContent' => $t->translate('Edit pages here.'))); $tRegForm->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('Registration'), 'translatedContent' => $t->translate('Give up all your user details in order to registrate to this site.'))); $tPlugMan->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('Plugin Manager'), 'translatedContent' => $t->translate('Enable/disable plugins.'))); $tALogout->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('Logout'), 'translatedContent' => $t->translate('Logout'))); $tAdminUser->initFromArray(array('languageCode' => 'en_UK', 'translatedTitle' => $t->translate('User manager'), 'translatedContent' => $t->translate('Manage users here, remove/add them from administrators list.'))); $home->addTranslation($tHome); $ahome->addTranslation($tAHome); $pman->addTranslation($tPMan); $regform->addTranslation($tRegForm); $pluman->addTranslation($tPlugMan); $adminLogout->addTranslation($tALogout); $adminUser->addTranslation($tAdminUser); $configContents = '<?php' . PHP_NL . PHP_NL; $configContents .= '$configItems[\'/databases/host\']=\'' . $databaseHost . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/password\']=\'' . $databasePassword . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/user\']=\'' . $databaseUser . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/database\']=\'' . $databaseName . '\';' . PHP_NL; $configContents .= '$configItems[\'/databases/table_prefix\']=\'' . $databasePrefix . '\';' . PHP_NL . PHP_NL; $configContents .= '$configItems[\'/site/title\']=\'' . $siteName . '\';' . PHP_NL; $configContents .= '?>'; $c = @fopen('config.php', 'w'); if ($c !== false) { fwrite($c, $configContents); fclose($c); header('Location: index.php'); } else { echo $configContents; } } else { var_dump($dbModule); } }
function setUp() { global $dbModule; include_once 'core/varia.functions.php'; include_once 'core/databasemanager.functions.php'; $testerOptions = parse_ini_file('core/tests/options.ini'); $dbModule = databaseLoadModule($testerOptions['dbModule']); if (isError($dbModule)) { die('Can\'t load database module, check your settings.'); } $r = $dbModule->connect($testerOptions['dbHost'], $testerOptions['dbUser'], $testerOptions['dbPass']); if (isError($r)) { die('Can\' connect to database, check your settings.'); } $r = $dbModule->selectDatabase($testerOptions['dbDatabaseName']); if (isError($r)) { die('Wrong databasename, check your settings.'); } foreach ($dbModule->getAllTables() as $tableName) { $r = $dbModule->query("DROP TABLE {$tableName}"); if (isError($r)) { var_dump($r); exit; } } $queries = file_get_contents("core/tests/database.sql"); $queries = str_replace('{prefix}', $testerOptions['dbPrefix'], $queries); $dbModule->setPrefix($testerOptions['dbPrefix']); $a = split(';', $queries); foreach ($a as $sql) { if (trim($sql) != '') { $r = $dbModule->query($sql); if (isError($r)) { var_dump($r); var_dump($sql); exit; } } } global $avModules; $availableModulesINI = explode(',', $testerOptions['dbAvailableModules']); foreach ($availableModulesINI as $value) { $value = trim($value); $avModules[$value] = null; } include_once 'core/user/usermanager.class.php'; global $u; $u = new userManager($dbModule); $this->setName('MorgOS automated Tester: results'); global $php; if ($php == "4") { include_once 'core/tests/databasemanager.functions.test.php'; include_once 'core/tests/config.class.test.php'; include_once 'core/tests/usermanager.class.test.php'; include_once 'core/tests/varia.functions.test.php'; include_once 'core/tests/compatible.functions.test.php'; include_once 'core/tests/pagemanager.class.test.php'; //include_once ('core/tests/xmlsql.class.test.php'); } elseif ($php == "5") { $this->addTestFile('core/tests/databasemanager.functions.test.php'); $this->addTestFile('core/tests/config.class.test.php'); $this->addTestFile('core/tests/usermanager.class.test.php'); $this->addTestFile('core/tests/varia.functions.test.php'); $this->addTestFile('core/tests/compatible.functions.test.php'); $this->addTestFile('core/tests/pagemanager.class.test.php'); $this->addTestFile('core/tests/xmlsql.class.test.php'); } $this->result = new TestResult(); if ($php == "5") { $this->result->addListener(new SimpleTestListener()); } $this->dbModule = $dbModule; }
/** * Init the system (if possible otherwise try a tinyInit). * @public */ function init() { $this->checkSmartyDirs(); if ($this->isInstalled()) { ob_start(); $this->_eventManager = new eventManager(); $this->_configManager = new configurator(); $this->_configManager->loadConfigFile('config.php'); $this->_i18nManager = new localizer(); $this->_i18nManager->loadLanguage('nl_NL', 'i18n'); $this->setDefaultErrors(); $this->_dbModule = databaseLoadModule('MySQL'); $a = $this->_dbModule->connect($this->_configManager->getStringItem('/databases/host'), $this->_configManager->getStringItem('/databases/user'), $this->_configManager->getStringItem('/databases/password')); $this->_dbModule->selectDatabase($this->_configManager->getStringItem('/databases/database')); $this->_dbModule->setPrefix($this->_configManager->getStringItem('/databases/table_prefix')); $this->_userManager = new userManager($this->_dbModule); $this->_pageManager = new pageManager($this->_dbModule); $this->_actionManager = new actionManager(); $this->_smarty = new ExtendedSmarty(); //$this->_smarty->debugging = true; $this->_pluginAPI = new pluginAPI($this); $this->_pluginAPI->setEventManager($this->_eventManager); $this->_pluginAPI->setUserManager($this->_userManager); $this->_pluginAPI->setDBModule($this->_dbModule); $this->_pluginAPI->setConfigManager($this->_configManager); $this->_pluginAPI->setActionManager($this->_actionManager); $this->_pluginAPI->setPageManager($this->_pageManager); $this->_pluginAPI->setSmarty($this->_smarty); $this->_pluginAPI->setI18NManager($this->_i18nManager); $this->_pluginManager = new pluginManager($this->_pluginAPI); $this->_pluginAPI->setPluginManager($this->_pluginManager); // Hardcoded for the moment $this->_skinManager = new skinManager($this->_pluginAPI); $this->_pluginAPI->setSkinManager($this->_skinManager); $this->_skinManager->findAllSkins('skins/'); //$this->_skinManager->loadSkin (MORGOS_DEFAULTSKIN_ID); $this->_skinManager->loadSkin('{0abf1469-d312-40b9-ad3a-3cb28b4c204e}'); //$this->_skinManager->loadSkin ('{c11681a8-5889-41cd-8fe1-d6fba2978804}'); $this->_smarty->plugins_dir[] = 'interface/smarty-plugins/'; $this->_smarty->assign_by_ref('t', $this->_i18nManager); $this->_pluginManager->findAllPlugins('interface/core-plugins'); // hardcore loading of core plugins $a = $this->_pluginManager->setPluginToLoad(MORGOS_VIEWPAGE_PLUGINID); $a = $this->_pluginManager->setPluginToLoad(MORGOS_USER_PLUGINID); $a = $this->_pluginManager->setPluginToLoad(MORGOS_ADMIN_PLUGINID); if (isError($a)) { var_dump($a); } $a = $this->_pluginManager->loadPlugins(); if (isError($a)) { var_dump($a); } $this->_pluginManager->findAllPlugins('plugins'); $allExternalPlugins = $this->_configManager->getArrayItem('/extplugs'); foreach ($allExternalPlugins as $pID => $item) { if ($item->getCurrentValue() == true) { $this->_pluginManager->setPluginToLoad($pID); } } $this->_pluginManager->loadPlugins(); } else { $this->tinyInit(); $this->loadInstaller(); //$this->error (new Error ('MORGOS_NOT_INSTALLED'), true); } }