aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-05-24 16:36:55 -0700
committerredmatrix <git@macgirvin.com>2016-05-24 16:36:55 -0700
commit84ba6393ad32406a9875044aef2d031c7d0d7a46 (patch)
treee1d82b53030df491cea67407526aa5f1a1d0a521 /Zotlabs
parent29ba8918093166ac32ef9a727a9b71ba8e01a402 (diff)
downloadvolse-hubzilla-84ba6393ad32406a9875044aef2d031c7d0d7a46.tar.gz
volse-hubzilla-84ba6393ad32406a9875044aef2d031c7d0d7a46.tar.bz2
volse-hubzilla-84ba6393ad32406a9875044aef2d031c7d0d7a46.zip
relocate index and db
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Module/Setup.php26
-rw-r--r--Zotlabs/Web/WebServer.php191
2 files changed, 205 insertions, 12 deletions
diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php
index 462ccced6..b913190b1 100644
--- a/Zotlabs/Module/Setup.php
+++ b/Zotlabs/Module/Setup.php
@@ -82,11 +82,11 @@ class Setup extends \Zotlabs\Web\Controller {
$siteurl = rtrim($siteurl,'/');
require_once('include/dba/dba_driver.php');
- unset($db);
- $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
+
+ $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
- if(! $db->connected) {
- echo 'Database Connect failed: ' . $db->error;
+ if(! \DBA::$dba->connected) {
+ echo 'Database Connect failed: ' . DBA::$dba->error;
killme();
\App::$data['db_conn_failed']=true;
}
@@ -138,10 +138,12 @@ class Setup extends \Zotlabs\Web\Controller {
}
}
- // connect to db
- $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
-
- if(! $db->connected) {
+ if(! \DBA::$dba->connected) {
+ // connect to db
+ $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true);
+ }
+
+ if(! \DBA::$dba->connected) {
echo 'CRITICAL: DB not connected.';
killme();
}
@@ -228,7 +230,7 @@ class Setup extends \Zotlabs\Web\Controller {
$txt .= "<pre>".\App::$data['db_failed'] . "</pre>". EOL ;
$db_return_text .= $txt;
}
- if($db && $db->connected) {
+ if(\DBA::$dba && \DBA::$dba->connected) {
$r = q("SELECT COUNT(*) as `total` FROM `account`");
if($r && count($r) && $r[0]['total']) {
$tpl = get_markup_template('install.tpl');
@@ -598,7 +600,7 @@ class Setup extends \Zotlabs\Web\Controller {
if(! is_writable(TEMPLATE_BUILD_PATH) ) {
$status = false;
$help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
- $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the Red top level folder.'), TEMPLATE_BUILD_PATH) . EOL;
+ $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the top level web folder.'), TEMPLATE_BUILD_PATH) . EOL;
$help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
$help .= sprintf( t('Note: as a security measure, you should give the web server write access to %s only--not the template files (.tpl) that it contains.'), TEMPLATE_BUILD_PATH) . EOL;
}
@@ -698,12 +700,12 @@ class Setup extends \Zotlabs\Web\Controller {
function load_database($db) {
- $str = file_get_contents($db->get_install_script());
+ $str = file_get_contents(\DBA::$dba->get_install_script());
$arr = explode(';',$str);
$errors = false;
foreach($arr as $a) {
if(strlen(trim($a))) {
- $r = @$db->q(trim($a));
+ $r = dbq(trim($a));
if(! $r) {
$errors .= t('Errors encountered creating database tables.') . $a . EOL;
}
diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php
new file mode 100644
index 000000000..98bf62c9a
--- /dev/null
+++ b/Zotlabs/Web/WebServer.php
@@ -0,0 +1,191 @@
+<?php /** @file */
+
+class WebServer {
+
+ public function run() {
+
+ global $db;
+
+ /*
+ * Bootstrap the application, load configuration, load modules, load theme, etc.
+ */
+
+ /*
+ * bootstrap the application
+ */
+
+ require_once('boot.php');
+
+ if(file_exists('.htsite.php'))
+ include('.htsite.php');
+
+
+ // miniApp is a conversion object from old style .htconfig.php files
+
+ $a = new \miniApp;
+
+ // our central App object
+
+ \App::init();
+
+ /*
+ * Load the configuration file which contains our DB credentials.
+ * Ignore errors. If the file doesn't exist or is empty, we are running in
+ * installation mode.
+ */
+
+ \App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
+
+ @include('.htconfig.php');
+
+ if(! defined('UNO'))
+ define('UNO', 0);
+
+ $a->convert();
+
+ \App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
+ date_default_timezone_set(\App::$timezone);
+
+
+ /*
+ * Try to open the database;
+ */
+
+ require_once('include/dba/dba_driver.php');
+
+ if(! \App::$install) {
+ $db = DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, \App::$install);
+ if(! $db->connected) {
+ system_unavailable();
+ }
+
+ unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
+
+ /**
+ * Load configs from db. Overwrite configs from .htconfig.php
+ */
+
+ load_config('config');
+ load_config('system');
+ load_config('feature');
+
+ \App::$session = new Zotlabs\Web\Session();
+ \App::$session->init();
+ load_hooks();
+ call_hooks('init_1');
+
+ }
+
+
+ \App::$language = get_best_language();
+ load_translation_table(\App::$language,\App::$install);
+
+
+ /**
+ *
+ * Important stuff we always need to do.
+ *
+ * The order of these may be important so use caution if you think they're all
+ * intertwingled with no logical order and decide to sort it out. Some of the
+ * dependencies have changed, but at least at one time in the recent past - the
+ * order was critical to everything working properly
+ *
+ */
+
+ if(\App::$session) {
+ \App::$session->start();
+ }
+ else {
+ session_start();
+ register_shutdown_function('session_write_close');
+ }
+
+ /**
+ * Language was set earlier, but we can over-ride it in the session.
+ * We have to do it here because the session was just now opened.
+ */
+
+ if(array_key_exists('system_language',$_POST)) {
+ if(strlen($_POST['system_language']))
+ $_SESSION['language'] = $_POST['system_language'];
+ else
+ unset($_SESSION['language']);
+ }
+ if((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) {
+ \App::$language = $_SESSION['language'];
+ load_translation_table(\App::$language);
+ }
+
+ if((x($_GET,'zid')) && (! \App::$install)) {
+ \App::$query_string = strip_zids(\App::$query_string);
+ if(! local_channel()) {
+ $_SESSION['my_address'] = $_GET['zid'];
+ zid_init($a);
+ }
+ }
+
+ if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (\App::$module === 'login'))
+ require('include/auth.php');
+
+ if(! x($_SESSION, 'sysmsg'))
+ $_SESSION['sysmsg'] = array();
+
+ if(! x($_SESSION, 'sysmsg_info'))
+ $_SESSION['sysmsg_info'] = array();
+
+ /*
+ * check_config() is responsible for running update scripts. These automatically
+ * update the DB schema whenever we push a new one out. It also checks to see if
+ * any plugins have been added or removed and reacts accordingly.
+ */
+
+
+ if(\App::$install) {
+ /* Allow an exception for the view module so that pcss will be interpreted during installation */
+ if(\App::$module != 'view')
+ \App::$module = 'setup';
+ }
+ else
+ check_config($a);
+
+ nav_set_selected('nothing');
+
+ $Router = new Zotlabs\Web\Router($a);
+
+ /* initialise content region */
+
+ if(! x(\App::$page, 'content'))
+ \App::$page['content'] = '';
+
+ call_hooks('page_content_top', \App::$page['content']);
+
+
+ $Router->Dispatch($a);
+
+
+ // If you're just visiting, let javascript take you home
+
+ if(x($_SESSION, 'visitor_home')) {
+ $homebase = $_SESSION['visitor_home'];
+ } elseif(local_channel()) {
+ $homebase = z_root() . '/channel/' . \App::$channel['channel_address'];
+ }
+
+ if(isset($homebase)) {
+ \App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>';
+ }
+
+ // now that we've been through the module content, see if the page reported
+ // a permission problem and if so, a 403 response would seem to be in order.
+
+ if(stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
+ header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
+ }
+
+ call_hooks('page_end', \App::$page['content']);
+
+ construct_page($a);
+
+ killme();
+ }
+} \ No newline at end of file