Welcome

BoltWire is a content management system developed by Dan Vis.

Welcome Tour
Documentation
Mailing List



Popular Posts

Version 5.11 Released
May 26, 2016

Big Changes Coming Soon...
April 28, 2016

Catching Up
April 6, 2016



Other Sites

Here's some other sites by Dan Vis:

Alexa Echoes
Join my adventures developing for Amazons exciting new voice platform.

Firefly Spot
Personal rambling about new gadgets, technology news, and space travel.

FAST Missions
My ministry hub, with news and updates about our online school.

You can follow him at www.danvis.info.

Engine

Documentation > Concepts > Engine

Here is BoltWire's full initialization routine. It is found in engine.php.


Here is the BoltWire code for the initialization routine:
## THIS IS THE SCRIPT THAT CALLS ALL THE OTHER SCRIPTS AND CREATES OUTPUT
define('BOLTWIRE','5.11'); // version number
if (substr(PHP_VERSION, 0, 1) < 5) exit('PHP 5.0+ required. Please upgrade.');
if (isset($BOLTstopWatch))     BOLTstopWatch('Initialization begun');  // Stopwatch is used to benchmark performance

## FIRST, LOAD THE SYSTEM SCRIPTS
if (! isset($boltwire)) $boltwire = '../boltwire';  // change in index.php if non-standard installation
if (! isset($BOLTscripts)) $BOLTscripts = Array('library', 'variables', 'markups', 'functions', 'conditions', 'commands'); // can customize $BOLTscripts in index.php
foreach ($BOLTscripts as $script) {
     if (file_exists("$boltwire/scripts/$script.php")) include_once("$boltwire/scripts/$script.php");
     else exit("Script //$script// not found...");
     }
BOLTprocess('startup'); // run array of custom functions before initializing system

## NEXT TAKE CARE OF A FEW INTERNAL DETAILS
if (isset($errorReporting)) {
     if ($errorReporting == true) error_reporting(E_ALL ^ E_NOTICE); // Turn on in index.php
     else error_reporting($errorReporting);
     }
else error_reporting(0);

if (! file_exists('stamps')) {  // sets up key directories for first time run...
     BOLTfixdir('pages');
     BOLTfixdir('config');
     BOLTfixdir('files', false);
     BOLTfixdir('stamps');
     if (! file_exists('favicon.ico')) copy("$boltwire/shared/img/favicon.ico", "favicon.ico");
     copy("$boltwire/shared/img/boltwire.gif", "files/boltwire.gif");
     }

// Cleans up php security weaknesses. Deprecated in php6
if (ini_get('register_globals')) {
     foreach($_REQUEST as $k => $v) {
          if (preg_match('/^(GLOBALS|_SERVER|_COOKIE|_POST|_FILES|_ENV|_REQUEST|_SESSION)$/i', $k)) exit();  // _GET ommitted
          unset(${$k});
          }
     }

// Elininate slashes if php has magic quotes turned on
if (get_magic_quotes_gpc() == 1) {
     foreach($_GET as $field => $value) $_GET[$field] = stripslashes($value);
     foreach($_POST as $field => $value) {
          if (is_array($value)) $_POST[$field] = array_map(stripslashes, $value);
          else $_POST[$field] = stripslashes($value);
          }
     }

## LOAD CONFIG VALUES FROM SITE.CONFIG PAGE AND DETERMINE PLUGINS TO BE ENABLED
if ($sitePages == '') $sitePages = 'pages';
$config = file_get_contents("$sitePages/site.config");
if ($config == '') $config = file_get_contents("$boltwire/system/site.config");
preg_match_all('/^(enable([-\w]+)\:?|(([-\w]*)\: )?)(.*)?$/m', $config, $m);
foreach ($m[5] as $i => $v) {
     if ($m[4][$i] != '') $BOLTconfig[strtolower($m[4][$i])] = trim($v); // config values
     if ($m[2][$i] != '') $BOLTplugins[strtolower($m[2][$i])] = trim($v); // plugins
     }

## SETUP TIME, LANGUAGE & UTF VARIABLES
$BOLTtime = time() + BOLTconfig('localTime', 0) * 3600;
$BOLTvar['now'] = $BOLTtime;
$BOLTvar['language'] = BOLTconfig('language');
$BOLTutfEscapeChars = Array('%','<','>','/','\\','*',':',',','~','@','+','^','!','#','&','$',';','=','?',"\n",'{','}','"','\'');
foreach ($BOLTutfEscapeChars as $char) {
     $code = urlencode($char);
     $BOLTutfEscape[$code] = $char;
     $BOLTutfEscape[strtolower($code)] = $char;
     }
if (BOLTconfig('skinMobile', 'false') == 'true') {
     $mobilePat = BOLTconfig('mobilepat', '/(iphone|ipod|android|webos|iemobile|kindle|blackberry)/i');
     if (preg_match($mobilePat, $_SERVER['HTTP_USER_AGENT']) > 0) $BOLTmobile = 'true';
     }

## INITIALIZE SESSION
global $BOLTsession;
session_start();
$BOLTsession = $_SESSION[$BOLTfield];

## SETUP MEMBER/GROUP AUTHENTICATION FROM SESSION
if (isset($BOLTsession['ID'])) {  // If logged in.
     $BOLTid = $BOLTsession['ID']['id'];
     $BOLTvar['id'] = $BOLTid;
     $BOLTmember = $BOLTsession['ID']['member'];
     $BOLTvar['member'] = $BOLTmember;
     $BOLTgroups = $BOLTsession['ID']['groups'];
     $BOLTvar['groups'] = $BOLTgroups;
     }
else {  // If not logged in.
     $BOLTmember = BOLTconfig('guestname', 'Guest');
     $BOLTgroups = 'guest';
     }

## CLEANUP PAGELINK (FROM UTF) AND CREATE PAGEARRAY VAR
if ($_GET['p'] == '') {
     if ($BOLTmobile) $pageLink = BOLTconfig('homeMobile', 'main');
     else $pageLink = BOLTconfig('homePage', 'main');
     }
else $pageLink = $_GET['p'];
$pageLink = str_replace('/', '.', $pageLink);
$pageLink = strtolower(trim($pageLink, '.'));
$pageLink = BOLTutf2url($pageLink);
if (preg_match('/^[-_a-zA-Z0-9\.%]+$/', $pageLink) == 0) exit("Invalid page name.");
$pageArray = explode(".", $pageLink);
$BOLTindexPages = Array();
if (BOLTconfig('cleanurls') == 'true') $cleanURL = BOLTinit("$fieldURL/", $cleanURL);
//$BOLTvar['url'] = BOLTFgeturl($pageLink);

## LOAD LOCAL CONFIG.PHP AND ENABLED PLUGINS
if (file_exists("config/config.php")) include_once("config/config.php");
if (file_exists("$pluginPath/config.php")) include_once("$pluginPath/config.php");
if (is_array($BOLTplugins)) {
     foreach($BOLTplugins as $plugin => $check) {
          if (! BOLTpageCheck($check)) continue;
          if (file_exists("config/$plugin.php")) {
               include_once("config/$plugin.php");
               $BOLTvar['plugins'] .= ",$plugin";
               }
          elseif (file_exists("$pluginPath/$plugin.php")) {
               include_once("$pluginPath/$plugin.php");
               $BOLTvar['plugins'] .= ",$plugin";
               }
          }
     $BOLTvar['plugins'] = ltrim($BOLTvar['plugins'], ",");
     }

## MANAGES IMPORT REQUESTS AND LOGINS VIA A GET[LOGIN] FIELD WITH AN ID:PASS VALUE
if ($_GET['importcode'] != '') {
     if ($_GET['importcode'] == BOLTconfig('exportCode')) {
          print_r(BOLTescape(BOLTdomarkup(BOLTloadpage($pageLink)), false));
          }
     die();
     }
if ($_GET['id'] != '' && $_GET['pass'] != '') BOLTFlogin();
BOLTpageShow();  // sets action vars if action page required.

BOLTprocess('pre');
if (isset($BOLTstopWatch)) {
     BOLTstopWatch('Initialization complete');
     BOLTstopWatch('Page construction begun');
     }

## RUN FORMS PROCESSOR IF NEEDED, PREPARE PAGE FOR DISPLAY, RUN BACKGROUND FUNCTIONS
if (isset($_POST['boltkey'])) BOLTexecute(BOLTsecure());  // Validates form and executes commands
unset($BOLTsession['KEY']);  // Expires all old keys

## THIS SECTION DETERMINES SKIN
if (! isset($BOLTskin)) $BOLTskin == '';
if (function_exists('myBOLTchooseSkin')) $skin = myBOLTchooseSkin();  // Hook for custom function. Must set gobal $BOLTskin...
else {
     if ($BOLTskin == '') $BOLTskin = BOLTconfig('skin', BOLTinit('default', $BOLTdefaultSkin));
     if ($_GET['action'] == 'print' && BOLTconfig('printSkin', 'print') !== 'false') $BOLTskin = BOLTinit(BOLTconfig('printSkin', 'print'), $BOLTdefaultPrintSkin);
     if ($BOLTmobile == 'true' && BOLTconfig('mobileSkin', 'mobile') !== 'false') $BOLTskin = BOLTinit(BOLTconfig('mobileSkin', 'mobile'), $BOLTdefaultMobileSkin);
     $skin = "code.skin.$BOLTskin.html";
     }
$out = BOLTloadskin('html');
if ($out == '') {
     if (BOLTingroup('admin', $BOLTid)) BOLTmessage("skin_missing::$BOLTskin");
     $BOLTskin = 'default';
     $skin = 'code.skin.default.html';
     $out = BOLTloadskin('html');
     }
$BOLTvar['skin'] = "$skinPath/$BOLTskin/";  // Useful for skin graphics, css, and similar files
$BOLTvar['skinname'] = $BOLTskin;

## THIS SECTION CREATES PAGE OUTPUT
if (function_exists('myBOLTmakePage')) $out = myBOLTmakePage($out);  // Hook for custom function
else {
     BOLTstopWatch('Skin creation begun');
     $out = preg_replace_callback('/\<\<([-_a-z0-9\.]+)\>\>/i', function($m) { return BOLTloadskin($m[1]); }, $out);  // Code zone--like <<css>>
     $out = preg_replace_callback('/\=\=(.*?)\=\=/', function($m, $pageLink) use ($pageLink) { return BOLTdomarkup($m[1], $pageLink, 'SKIN'); }, $out);  // Put markup in skin directly--like ==[(function)]==
     $out = preg_replace_callback('/\{([-_a-z0-9:]+)\}/i', function($m) { return BOLTskinSettings($m[1]); }, $out);  // Inserts {vars} from code.settings page
     preg_match_all('/\[\[([-_a-z0-9]+)\]\]/i', $out, $matches);  // identify zones
     $BOLTvar['zones'] = strtolower(implode(',', $matches[1]));
     foreach($matches[1] as $zone) {
          $p = BOLTgetlink($zone);
          if ($zone == 'main' && ! BOLTexists($p)) $BOLTvar["zone_$zone"] = BOLTgetlink('missing', 'action');
          else $BOLTvar["zone_$zone"] = $p;
          }
     foreach($matches[1] as $zone) {
          BOLTstopWatch("Zone $zone begun");
          $out = str_replace("[[$zone]]", BOLTgetzones($zone), $out);  // Do each zone
          BOLTstopWatch("Zone $zone complete");
          }
     $out = BOLTescape($out, false);  // Undo escaped content
     $out = preg_replace_callback('/\[messages( ([-_,a-zA-Z0-9=]+))?\]/i', function($m) { return BOLTmessageDisplay($m[1]); }, $out);  // Display messages
     BOLTstopWatch('Skin creation complete');
     if (BOLTconfig('robotBlock') != '') {  // can turn specific pages off for robots. Use site*,test.block
          if (BOLTpageCheck(BOLTconfig('robotBlock'))) {
               $BOLTreplaceHTML['find'][] = '</head>';
               $BOLTreplaceHTML['replace'][] = "<meta name='robots' content='noindex'>\n</head>";
               }
          }
     if (is_array($BOLTreplaceHTML)) $out = str_replace($BOLTreplaceHTML['find'], $BOLTreplaceHTML['replace'], $out);  // Any custom code replacements
     if (is_array($BOLTserverHeaders)) { foreach($BOLTserverHeaders as $h) header($h); } // Add custom headers
     }

## CLEAR OLD SESSION INFO AND SAVE NEW
if (isset($BOLTformKeys)) $keys = implode(',', $BOLTformKeys);  // current forms needed on next page
foreach($BOLTsession as $i => $data) {  
     if (is_number($i) && ! inlist($i, $keys)) {  // Delete the rest
          unset($BOLTsession['']);
          unset($BOLTsession[$i]);
          unset($BOLTsession['KEY'][$i]);
          }
     }
unset($BOLTsession['MSG']);  // from last page for this page
unset($BOLTsession['PASSFORM']);

session_start();
$_SESSION = Array();
$_SESSION[$BOLTfield] = $BOLTsession;
session_write_close();

if (isset($BOLTstopWatch)) {
     BOLTstopWatch('Page construction complete');
     if (inlist('admin', $BOLTgroups)) $out = str_replace("<body>", "<body><div class='stopwatch'>$BOLTstopWatchMsg</div>", $out);
     }

//p('end');p($BOLTfield);p($BOLTsession); $debug = true;

## OUTPUT PAGE AND RELEASE BROWSER TO ALLOW BACKGROUND PROCESSES
if (isset($debug)) { print_r($out); die(); } // set in index.php for, well, debugging!
BOLToutputPage($out);

To leave a comment, please login using your Facebook account: