public static function handleRequest() { if (extension_loaded('newrelic')) { newrelic_disable_autorum(); } if (!Site::getConfig('inheritance_key')) { Site::respondUnauthorized('Remote emergence access is disabled'); } elseif (empty($_REQUEST['accessKey']) || $_REQUEST['accessKey'] != Site::getConfig('inheritance_key')) { // attempt to authenticate via developer session if (!UserSession::getFromRequest()->hasAccountLevel('Developer')) { Site::respondUnauthorized('Remote emergence access denied'); } } if ($_REQUEST['remote'] == 'parent') { set_time_limit(1800); $remoteParams = array(); if (!empty($_REQUEST['exclude'])) { $remoteParams['exclude'] = $_REQUEST['exclude']; } HttpProxy::relayRequest(array('url' => static::buildUrl(Site::$pathStack, $remoteParams), 'autoAppend' => false, 'autoQuery' => false, 'timeout' => 500)); } if (empty(Site::$pathStack[0])) { return static::handleTreeRequest(); } elseif ($node = Site::resolvePath(Site::$pathStack)) { if (method_exists($node, 'outputAsResponse')) { $node->outputAsResponse(true); } elseif (is_a($node, 'SiteCollection')) { return static::handleTreeRequest($node); } else { Site::respondBadRequest(); } } else { header('HTTP/1.0 404 Not Found'); die('File not found'); } }
public static function executeScript(SiteFile $_SCRIPT_NODE, $_SCRIPT_EXIT = true) { // create session if (empty($GLOBALS['Session']) && static::$autoCreateSession && !in_array(implode('/', static::$resolvedPath), static::$skipSessionPaths)) { $GLOBALS['Session'] = UserSession::getFromRequest(); } if (is_callable(static::$onBeforeScriptExecute)) { call_user_func(static::$onBeforeScriptExecute, $_SCRIPT_NODE); } require $_SCRIPT_NODE->RealPath; if ($_SCRIPT_EXIT) { exit; } }
public static function executeScript(SiteFile $_SCRIPT_NODE, $_SCRIPT_EXIT = true) { // create session if (empty($GLOBALS['Session']) && static::$autoCreateSession && !in_array(implode('/', static::$resolvedPath), static::$skipSessionPaths)) { $GLOBALS['Session'] = UserSession::getFromRequest(); } if (extension_loaded('newrelic')) { if (!empty($GLOBALS['Session'])) { newrelic_add_custom_parameter('session_id', $GLOBALS['Session']->Handle); newrelic_add_custom_parameter('person_id', $GLOBALS['Session']->PersonID); } newrelic_add_custom_parameter('script_path', $_SCRIPT_NODE->FullPath); } if (is_callable(static::$onBeforeScriptExecute)) { call_user_func(static::$onBeforeScriptExecute, $_SCRIPT_NODE); } if (class_exists('Emergence\\EventBus')) { Emergence\EventBus::fireEvent('beforeScriptExecute', 'Site', array('node' => $_SCRIPT_NODE, 'exit' => $_SCRIPT_EXIT)); } require $_SCRIPT_NODE->RealPath; if ($_SCRIPT_EXIT) { exit; } }
public static function handleRequest() { // TODO: try global handle lookup? // resolve URL in root $resolvedNode = false; $rootNode = static::getRootCollection('site-root'); // handle root request - default page if (empty(static::$pathStack[0]) && static::$defaultPage) { static::$pathStack[0] = static::$defaultPage; } // route request if (static::$pathStack[0] == 'emergence') { array_shift(static::$pathStack); return Emergence::handleRequest(); } elseif (static::$pathStack[0] == 'parent-refresh' && $_REQUEST['key'] == static::$controlKey) { DB::nonQuery('DELETE FROM `%s` WHERE CollectionID IN (SELECT ID FROM `%s` WHERE SiteID != %u)', array(SiteFile::$tableName, SiteCollection::$tableName, Site::getSiteID())); die('Cleared ' . DB::affectedRows() . ' cached files'); } else { $resolvedNode = $rootNode; $resolvedPath = array(); while ($handle = array_shift(static::$pathStack)) { $scriptHandle = substr($handle, -4) == '.php' ? $handle : $handle . '.php'; //printf('%s: (%s)/(%s) - %s<br>', $resolvedNode->Handle, $handle, implode('/',static::$pathStack), $scriptHandle); if ($resolvedNode && method_exists($resolvedNode, 'getChild') && (($childNode = $resolvedNode->getChild($handle)) || $scriptHandle && ($childNode = $resolvedNode->getChild($scriptHandle))) || ($childNode = Emergence::resolveFileFromParent('site-root', array_merge($resolvedPath, array($handle)))) || $scriptHandle && ($childNode = Emergence::resolveFileFromParent('site-root', array_merge($resolvedPath, array($scriptHandle))))) { $resolvedNode = $childNode; if (is_a($resolvedNode, 'SiteFile')) { break; } } else { $resolvedNode = false; //break; } $resolvedPath[] = $handle; } } if ($resolvedNode) { // create session if (static::$autoCreateSession && $resolvedNode->MIMEType == 'application/php') { $GLOBALS['Session'] = UserSession::getFromRequest(); } if (is_callable(static::$onRequestMapped)) { call_user_func(static::$onRequestMapped, $resolvedNode); } if ($resolvedNode->MIMEType == 'application/php') { require $resolvedNode->RealPath; exit; } elseif (!is_callable(array($resolvedNode, 'outputAsResponse'))) { //throw new Exception('Node does not support rendering'); static::respondNotFound(); } else { $resolvedNode->outputAsResponse(); } } else { static::respondNotFound(); } }
public static function executeScript(SiteFile $_SCRIPT_NODE, $_SCRIPT_EXIT = true) { // create session if (empty($GLOBALS['Session']) && static::$autoCreateSession && !in_array(implode('/', static::$resolvedPath), static::$skipSessionPaths)) { $GLOBALS['Session'] = UserSession::getFromRequest(); } if (is_callable(static::$onBeforeScriptExecute)) { call_user_func(static::$onBeforeScriptExecute, $_SCRIPT_NODE); } if (class_exists('Emergence\\EventBus')) { Emergence\EventBus::fireEvent('beforeScriptExecute', 'Site', array('node' => $_SCRIPT_NODE, 'exit' => $_SCRIPT_EXIT)); } require $_SCRIPT_NODE->RealPath; if ($_SCRIPT_EXIT) { exit; } }