/** * set default timezone (date_default_timezone) */ public static function setTimezone() { // if no user timezone if (!conf::getMainIni('date_default_timezone')) { conf::setMainIni('date_default_timezone', 'Europe/Copenhagen'); } date_default_timezone_set(conf::getMainIni('date_default_timezone')); }
/** * Do this after the commandline options has been parsed. * Examine the --domain flag and the --verbose flag * @param type $result */ public static function afterParse($result) { $verbose = $result->options['verbose']; conf::setMainIni('verbose', $verbose); // Check if other domain than default is being used $domain = $result->options['domain']; conf::setMainIni('domain', $domain); if ($domain != 'default' || empty($domain)) { $domain_ini = conf::pathBase() . "/config/multi/{$domain}/config.ini"; if (!file_exists($domain_ini)) { common::abort("No such domain - no configuration found: '{$domain_ini}'"); } else { // If domain is used - Load domain specific configuration conf::loadMainCli(); } } }
/** * Sets a flag which indicate the usage of SSL */ public static function setUseSSL() { conf::setMainIni('a2_use_ssl', true); }
/** * Run the system */ public function run() { // Register an autoloader for loading modules from mopdules dir $m = new modules(); $m->autoloadRegister(); // define HTML constants common::defineConstants(); // define global constants - based on base path conf::defineCommon(); // set include paths conf::setIncludePath(); // load config file conf::load(); if (conf::getMainIni('debug')) { log::enableDebug(); } // set public file folder in file class file::$basePath = conf::getFullFilesPath(); // utf-8 ini_set('default_charset', 'UTF-8'); // load config/config.ini // check if there exists a shared ini file // shared ini is used if we want to enable settings between hosts // which share same code base. // e.g. when updating all sites, it is a good idea to set the following flag // site_update = 1 // this flag will send correct 503 headers, when we are updating our site. // if site is being updaing we send temporarily headers // and display an error message if (conf::getMainIni('site_update')) { http::temporarilyUnavailable(); } // set a unified server_name if not set in config file. $server_name = conf::getMainIni('server_name'); if (!$server_name) { conf::setMainIni('server_name', $_SERVER['SERVER_NAME']); } // redirect to uniform server name is set in config.ini // e.g. www.testsite.com => testsite.com $server_redirect = conf::getMainIni('server_redirect'); if (isset($server_redirect)) { http::redirectHeaders($server_redirect); } // redirect to https is set in config.ini // force anything into ssl mode $server_force_ssl = conf::getMainIni('server_force_ssl'); if (isset($server_force_ssl)) { http::sslHeaders(); } // catch all output ob_start(); // Create a db connection $db_conn = array('url' => conf::getMainIni('url'), 'username' => conf::getMainIni('username'), 'password' => conf::getMainIni('password'), 'db_init' => conf::getMainIni('db_init')); // Other options // db_dont_persist = 0 // dont_die = 0 // Set to one and the connection don't die because of // e.g. no database etc. This will return NO_DB_CONN as string //$url = conf::getMainIni('url'); connect::connect($db_conn); // init module loader. $ml = new moduleloader(); // initiate uri uri::getInstance(); // runlevel 1: merge db config $ml->runLevel(1); // select all db settings and merge them with ini file settings $db_Settings = []; if (moduleloader::moduleExists('settings')) { $db_settings = q::select('settings')->filter('id =', 1)->fetchSingle(); } // merge db settings with config/config.ini settings // db settings override ini file settings conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings); // run level 2: set locales $ml->runLevel(2); // set locales intl::setLocale(); // set default timezone intl::setTimezone(); // runlevel 3 - init session $ml->runLevel(3); // start session session::initSession(); // Se if user is logged in with SESSION if (!session::isUser()) { // If not logged in check system cookie // This will start the session, if an appropiate cookie exists session::checkSystemCookie(); } // Check account $res = session::checkAccount(); if (!$res) { // Redirect to main page if user is not allowed // With current SESSION or COOKIE http::locationHeader('/'); } // set account timezone if enabled - can only be done after session // as user needs to be logged in intl::setAccountTimezone(); // run level 4 - load language $ml->runLevel(4); // load all language files $l = new lang(); $base = conf::pathBase(); $htdocs = conf::pathHtdocs(); $l->setDirsInsideDir("{$base}/modules/"); $l->setDirsInsideDir("{$htdocs}/templates/"); $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes"); $l->setSingleDir("{$base}/vendor/diversen/simple-pager"); $l->loadLanguage(conf::getMainIni('lang')); // runlevel 5 $ml->runLevel(5); // load routes if any dispatch::setDbRoutes(); // check db routes or load defaults $db_route = dispatch::getMatchRoutes(); if (!$db_route) { $ml->setModuleInfo(); $ml->initModule(); } else { dispatch::includeModule($db_route['method']); } // After module has been loaded. // You can e.g. override module ini settings $ml->runLevel(6); // Init layout. Sets template name // load correct CSS. St menus if any. Etc. $layout = new layout(); // we first load menus here so we can se what happened when we // init our module. In case of a 404 not found error we don't want // to load module menus $layout->loadMenus(); // init blocks $layout->initBlocks(); // if any matching route was found we check for a method or function if ($db_route) { $str = dispatch::call($db_route['method']); } else { // or we use default module parsing $str = $ml->getParsedModule(); } // set view vars $vars['content'] = $str; // run level 7 $ml->runLevel(7); // echo module content echo $str = \mainTemplate::view($vars); conf::$vars['final_output'] = ob_get_contents(); ob_end_clean(); // Last divine intervention // e.g. Dom or Tidy $ml->runLevel(8); echo conf::$vars['final_output']; }
<?php include_once "vendor/autoload.php"; use diversen\mycurl; use diversen\conf; conf::setMainIni('base_path', realpath('.')); $c = new mycurl('http://coscms/account/login/index'); $fields = array('email' => 'test', 'password' => 'test', 'submit_account_login' => 'Send'); $c->setPost($fields); $c->createCurl(); echo $c->getWebPage();
/** * notification flag to other functions * @param type $options */ function cos_phar_files($options = array()) { conf::setMainIni('phar_files', 1); }
// Accept no time limit and ignore user abort set_time_limit(0); ignore_user_abort(true); // set a base path and include autoloader // include autoload if (file_exists('vendor')) { $path = dirname(__FILE__); include 'vendor/autoload.php'; } else { $path = dirname(__FILE__) . '/..'; include '../vendor/autoload.php'; } use diversen\conf; use diversen\alias; // set base_path in conf conf::setMainIni('base_path', $path); // set alias. common defines. Load config. Set include paths alias::set(); conf::defineCommon(); conf::loadMain(); conf::setIncludePath(); // include som install helpers $vendor = 'vendor/diversen/simple-php-classes/src'; include_once $vendor . "/shell/common.php"; include_once $vendor . "/shell/profile.php"; include_once $vendor . "/install/common.php"; // check if system is sane if (!isset($_GET['ignore'])) { cos_check_version(); cos_check_pdo_mysql(); cos_check_magic_gpc();
/** * function for doing a prompt install from shell mode * is a wrapper around other shell functions. */ function prompt_install() { common::echoMessage('Pick a version to install:', 'y'); $tags = git::getTagsInstallLatest() . PHP_EOL; $tags .= "master"; common::echoMessage($tags); $tag = common::readSingleline("Enter tag (version) to use:"); common::execCommand("git checkout {$tag}"); // Which profile to install $profiles = file::getFileList('profiles', array('dir_only' => true)); if (count($profiles) == 1) { $profile = array_pop($profiles); } else { common::echoMessage("List of profiles: "); foreach ($profiles as $val) { common::echoMessage("\t" . $val); } // select profile and load it $profile = common::readSingleline('Enter profile, and hit return: '); } common::echoMessage("Loading the profile '{$profile}'", 'y'); load_profile(array('profile' => $profile, 'config_only' => true)); common::echoMessage("Main configuration (placed in config/config.ini) for '{$profile}' is loaded", 'y'); // Keep base path. Ortherwise we will lose it when loading profile $base_path = conf::pathBase(); // Load the default config.ini settings as a skeleton conf::$vars['coscms_main'] = conf::getIniFileArray($base_path . '/config/config.ini', true); // Reset base path conf::setMainIni('base_path', $base_path); conf::defineCommon(); common::echoMessage("Enter MySQL credentials", 'y'); // Get configuration info $host = common::readSingleline('Enter your MySQL host: '); $database = common::readSingleline('Enter database name: '); $username = common::readSingleline('Enter database user: '******'Enter database users password: '******'Enter server host name: '); common::echoMessage("Writing database connection info to main configuration"); // Assemble configuration info conf::$vars['coscms_main']['url'] = "mysql:dbname={$database};host={$host};charset=utf8"; conf::$vars['coscms_main']['username'] = $username; conf::$vars['coscms_main']['password'] = $password; conf::$vars['coscms_main']['server_name'] = $server_name; // Write it to ini file $content = conf::arrayToIniFile(conf::$vars['coscms_main'], false); $path = conf::pathBase() . "/config/config.ini"; file_put_contents($path, $content); common::echoMessage("Your can also always change the config/config.ini file manually"); $options = array(); $options['profile'] = $profile; if ($tag == 'master') { $options['master'] = true; } common::echoMessage("Will now clone and install all modules", 'y'); cos_install($options); common::echoMessage("Create a super user", 'y'); useradd_add(); $login = "******"; common::echoMessage("If there was no errors you will be able to login at {$login}"); common::echoMessage("Remember to change file permissions. This will require super user"); common::echoMessage("E.g. like this:"); common::echoMessage("sudo ./coscli.sh file --chmod-files"); }
/** * cli call function is --master is set then master will be used instead of * normal tag * * @param array $options */ function cos_install_use_master($options) { conf::setMainIni('git_use_master', 1); }
public function run() { // Register an autoloader for loading modules from mopdules dir $m = new modules(); $m->autoloadRegister(); // define HTML constants common::defineConstants(); // define global constants - based on base path conf::defineCommon(); // set include paths conf::setIncludePath(); // load config file conf::load(); // set log level - based on config.ini log::setLogLevel(); // utf-8 ini_set('default_charset', 'UTF-8'); // load config/config.ini // check if there exists a shared ini file // shared ini is used if we want to enable settings between hosts // which share same code base. // e.g. when updating all sites, it is a good idea to set the following flag // site_update = 1 // this flag will send correct 503 headers, when we are updating our site. // if site is being updaing we send temporarily headers // and display an error message if (conf::getMainIni('site_update')) { http::temporarilyUnavailable(); } // set a unified server_name if not set in config file. $server_name = conf::getMainIni('server_name'); if (!$server_name) { conf::setMainIni('server_name', $_SERVER['SERVER_NAME']); } // redirect to uniform server name is set in config.ini // e.g. www.testsite.com => testsite.com $server_redirect = conf::getMainIni('server_redirect'); if (isset($server_redirect)) { http::redirectHeaders($server_redirect); } // redirect to https is set in config.ini // force anything into ssl mode $server_force_ssl = conf::getMainIni('server_force_ssl'); if (isset($server_force_ssl)) { http::sslHeaders(); } // catch all output ob_start(); // Create a db connection $db = new db(); // init module loader. $ml = new moduleloader(); // initiate uri uri::getInstance(); // runlevel 1: merge db config $ml->runLevel(1); // select all db settings and merge them with ini file settings $db_settings = $db->selectOne('settings', 'id', 1); // merge db settings with config/config.ini settings // db settings override ini file settings conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings); // run level 2: set locales $ml->runLevel(2); // set locales intl::setLocale(); // set default timezone intl::setTimezone(); // runlevel 3 - init session $ml->runLevel(3); // start session session::initSession(); $res = session::checkAccount(); if (!$res) { // To prevent http::locationHeader('/'); } // set account timezone if enabled - can only be done after session // as user needs to be logged in intl::setAccountTimezone(); // run level 4 - load language $ml->runLevel(4); // load all language files $l = new lang(); $base = conf::pathBase(); $htdocs = conf::pathHtdocs(); $l->setDirsInsideDir("{$base}/modules/"); $l->setDirsInsideDir("{$htdocs}/templates/"); $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes"); $l->setSingleDir("{$base}/vendor/diversen/simple-pager"); $l->loadLanguage(conf::getMainIni('language')); // runlevel 5 $ml->runLevel(5); // load routes if any dispatch::setDbRoutes(); // runlevel 6 $ml->runLevel(6); // check db routes or load by defaults $db_route = dispatch::getMatchRoutes(); if (!$db_route) { $ml->setModuleInfo(); $ml->initModule(); } // Init layout. Sets template name // load correct CSS. St menus if any. Etc. $layout = new layout(); // we first load menus here so we can se what happened when we // init our module. In case of a 404 not found error we don't want // to load module menus $layout->loadMenus(); // init blocks $layout->initBlocks(); // if any matching route was found we check for a method or function if ($db_route) { $str = dispatch::call($db_route['method']); } else { // or we use default module parsing $str = $ml->getParsedModule(); } // set view vars $vars['content'] = $str; // run level 7 $ml->runLevel(7); // echo module content echo $str = \mainTemplate::view($vars); conf::$vars['final_output'] = ob_get_contents(); ob_end_clean(); // Last divine intervention // e.g. Dom or Tidy $ml->runLevel(8); echo conf::$vars['final_output']; }