/usr
/web
/cmcCMS-dev
/app
/controllers
/Page
/Node.php
error_log('Malformed node request');
}
$category = $pageCategoryModel->FindByName($category);
$page = $pageCategoryModel->GetNodePage($category);
$requestIsSecure = $this->request->isSecure();
if (!$requestIsSecure) {
$correctProtocol = $this->configuration->get(
'paths.baseUrls'
);
return $response->redirect(
$correctProtocol.$this->request->url,
301
);
}
$node = $this->mediaMapper->byId($nodeId);
if (!$node) {
throw new NotFound('Article not found', 404);
}
if ($node->published != 1) {
throw new NotFound('Article not found', 404);
}
$document = $documentFactory->newDocument($this->request->format);
$response->setDocument($document);
$content = $pageModel->GetContent($page);
$category = $pageModel->GetCategory($page);
$pageSet = $pageModel->GetPageSet($page);
if ($page->version == 1) {
$layout = $layoutFactory->create($page->layout);
} else {
$layout = $layoutFactory->create($page->layoutRegionOptions);
}
$pageTitle = trim($page->pageTitle);
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
$obj = $this->dependencyBuilder->make($handler);
$response = call_user_func_array(array($obj, $action), $arguments);
}
if (!($response instanceof iResponse)) {
throw new \LogicException('Invalid controller return, no response object');
}
//die('about to return response from dispatcher');
return $response;
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
$obj = $this->dependencyBuilder->make($handler);
$response = call_user_func_array(array($obj, $action), $arguments);
}
if (!($response instanceof iResponse)) {
throw new \LogicException('Invalid controller return, no response object');
}
//die('about to return response from dispatcher');
return $response;
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/TheatreEventAliasRoutes.php
class TheatreEventAliasRoutes implements iMiddleware {
private $db = null;
private $config = null;
public function __construct(
iConfiguration $config,
\App\Models\Content\Mapper $contentMapper,
\App\Models\Event\Mapper $eventMapper,
\App\Models\EventDate\Mapper $eventDateMapper
) {
$this->config = $config;
$this->contentMapper = $contentMapper;
$this->eventDateMapper = $eventDateMapper;
$this->eventMapper = $eventMapper;
}
public function handle(iRequest $request, \Closure $next) {
$requestPath = $request->path;
if (in_array('event', $requestPath) === false) {
return $next($request);
}
array_shift($requestPath); // "event"
$alias = array_shift($requestPath); // the alias we want
$event = $this->eventMapper
->where('urlAlias', '=', $alias)
->andWhere('status', '=', 'published')
->orderBy('id', 'desc')
->one()
;
if (!$event) {
return $next($request);
}
$dates = $this->eventDateMapper
->where('eventId', '=', $event->id)
->andWhere('status', '!=', 'deleted')
->andWhere('access', '=', 'public')
->andWhere('showOnCalendar', '=', '1')
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/QuickProfile.php
}
public function handle(iRequest $request, \Closure $next) {
if (
($request->get('_profile') === '1' && DEVELOPMENT === true) ||
PROFILE === true
){
$pqp = realpath(CMCCMS_LIBRARY_PATH.'..'.DIRECTORY_SEPARATOR.'pqp');
require_once($pqp.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.'PhpQuickProfiler.php');
$profiler = new \PhpQuickProfiler\PhpQuickProfiler(\PhpQuickProfiler\PhpQuickProfiler::getMicroTime(), '/../vendor/pqp/');
$this->db->setLogging(true);
\PhpQuickProfiler\Console::logMemory();
\PhpQuickProfiler\Console::logSpeed();
register_shutdown_function(function () use ($profiler) {
\cmcCMS\profileMessage('PQP Shutdown', 'memory');
\cmcCMS\profileMessage('PQP Shutdown', 'speed');
$profiler->display($this->db);
});
}
return $next($request);
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/DonationCampaignAliasIdFinder.php
<?php
namespace App\Middleware;
use cmcCMS\Middleware\iMiddleware;
use cmcCMS\Request\iRequest;
use cmcCMS\Routing\iRouter;
use cmcCMS\DataAccess\iDataAccess;
class DonationCampaignAliasIdFinder implements iMiddleware {
private $db = null;
public function __construct(
iDataAccess $db,
\App\Models\CampaignEvent\Model $campaignEventModel
) {
$this->db = $db;
$this->campaignEventModel = $campaignEventModel;
}
public function handle(iRequest $request, \Closure $next) {
$requestPath = $request->path;
if (in_array('donate', $requestPath) === false) {
return $next($request);
}
array_shift($requestPath); // "donate"
$alias = array_shift($requestPath); // the alias we want
$campaignEvent = $this->campaignEventModel
->where('urlAlias', '=', $alias)
->orderBy('id', 'desc')
->one()
;
if (!$campaignEvent) {
return $next($request);
}
if (
$campaignEvent->type == 'event' &&
($campaignEvent->start > time() || $campaignEvent->end < time())
) {
// event is over or hasn't started, find website capture from same campaign
$capturingCampaignEvent = $this->campaignEventModel
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/CsrfCheck.php
) {
$response = new \cmcCMS\Response\Response();
$document = $this->documentFactory->newDocument($request->format);
$response->setDocument($document);
if($request->format == 'json') {
$document->addData('ok', false);
$document->addData('$passedToken', $passedToken);
$document->addData('message', 'Security error, please contact us.');
} else {
$response->redirect('/error?error=400');
}
$response->send($request->format);
die();
}
unset($_POST['_token']);
unset($_GET['_token']);
$request->removeFromPost('_token');
}
$response = $next($request);
$document = $response->getDocument();
if (!$document) {
return $response;
}
$document->addMeta('_token', $currentToken);
return $response;
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/DebuggerTrace.php
<?php
namespace App\Middleware;
use cmcCMS\Middleware\iMiddleware;
use cmcCMS\Request\iRequest;
class DebuggerTrace implements iMiddleware {
public function __construct(
\cmcCMS\CurrentUser\iCurrentUser $currentUser
) {
$this->currentUser = $currentUser;
}
public function handle(iRequest $request, \Closure $next) {
$response = $next($request);
$document = $response->getDocument();
if (!$document)
return $response;
$trace = $this->currentUser->getVar('debuggerTrace');
if (is_array($trace) === false || count($trace) < 1)
return $response;
$this->currentUser->setVar('debuggerTrace', array());
while (count($trace) > 0) {
$thisTrace = array_shift($trace);
$document->addData('debug'.\cmcCMS\randomString(4), $thisTrace);
}
return $response;
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/AliasRoutes.php
implode('/', $pathParts)
);
$sql = '
SELECT
url
FROM
'.$this->db->getTableAlias('cmcCMS').'.urlAliases
WHERE
alias IN (
:'.implode(',:', array_keys($aliasCheckUrls)).'
) AND
active = 1
ORDER BY LENGTH(alias) DESC
LIMIT 1
';
$alias = $this->db->field($sql, $aliasCheckUrls);
if (!$alias) {
return $next($request);
}
if (strpos($alias, '://') !== false) {
header('location: '.$alias);
die();
}
$alias = (substr($alias, 0, 1) === '/' ? substr($alias, 1) : $alias);
$request->setRequestUrl($alias);
return $next($request);
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/AppendMessage.php
<?php
namespace App\Middleware;
use cmcCMS\Middleware\iMiddleware;
use cmcCMS\Request\iRequest;
class AppendMessage implements iMiddleware {
public function __construct(
\cmcCMS\CurrentUser\iCurrentUser $currentUser
) {
$this->currentUser = $currentUser;
}
public function handle(iRequest $request, \Closure $next) {
$notifications = $this->currentUser->getNotifications();
//\cmcCMS\print_p($notifications);
//\cmcCMS\print_p($_SESSION);
$this->currentUser->clearNotifications();
$response = $next($request);
$document = $response->getDocument();
if (!$document) {
return $response;
}
if ($request->isAjax() === true) {
$document->addData('_cmsNotifications', $notifications);
return $response;
}
foreach ($notifications as $notification) {
$document->prependBody(
'<div class="system-message alert-box '.($notification['error'] === false ? 'success' : 'alert').'">'.$notification['message'].'</div>'
);
}
return $response;
}
}
?>
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/AddFacebookAppToDocument.php
<?php
namespace App\Middleware;
use cmcCMS\Middleware\iMiddleware;
use cmcCMS\Request\iRequest;
class AddFacebookAppToDocument implements iMiddleware {
public function __construct(\cmcCMS\Core\iConfiguration $configuration) {
$this->configuration = $configuration;
}
public function handle(iRequest $request, \Closure $next) {
/* @var $response \cmcCMS\Response\Response */
$response = $next($request);
$document = $response->getDocument();
if (!$document)
return $response;
if (
in_array($this->configuration->get('routing.apiNamespace'), $request->path)
){
return $response;
}
$document->prependBody('
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId='.$this->configuration->get('thirdPartyApis.facebook.appId').'&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));</script>
');
$document->appendBody('
<script>
var fbInitInterval = false;
function fbInitCheck() {
if (typeof FB == "undefined" || typeof FB.init == "undefined") {
return true;
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
array $middlewareStack = array()
){
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
/usr
/web
/cmcCMS-dev
/app
/middleware
/AddGoogleAnalyticsToDocument.php
<?php
namespace App\Middleware;
use cmcCMS\Middleware\iMiddleware;
use cmcCMS\Request\iRequest;
class AddGoogleAnalyticsToDocument implements iMiddleware {
public function __construct(\cmcCMS\Core\iConfiguration $configuration) {
$this->configuration = $configuration;
}
public function handle(iRequest $request, \Closure $next) {
/* @var $response \cmcCMS\Response\Response */
$response = $next($request);
$document = $response->getDocument();
if (!$document)
return $response;
if (
in_array($this->configuration->get('routing.apiNamespace'), $request->path)
){
return $response;
}
$document->appendBody('
<script type="text/javascript">
Application.ready(function () {
// set up Google analytics
(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');
$(document).ready(function () {
ga(\'create\', \''.$this->configuration->get('thirdPartyApis.googleAnalytics.trackingId').'\', \'auto\');
ga(\'send\', \'pageview\');
});
});
</script>
');
return $response;
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Middleware
/MiddlewareCollector.php
if (is_array($arg)) {
$namespace = $arg[0];
$arg = $arg[1];
}
if (file_exists($arg) === true && is_dir($arg) === false) {
print 'middleware collector file';
continue;
}
if (file_exists($arg) === true && is_dir($arg) === true) {
$directory = new \DirectoryIterator($arg);
foreach ($directory as $file) {
if ($file->isDir() || $file->isLink() || $file->isDot()) {
continue;
} elseif (substr($file->getFilename(), -4) === '.php') {
$className = $namespace.'\\'.$file->getBasename('.php');
array_push($this->collection, function (\cmcCMS\Request\iRequest $request, \Closure $next) use ($className, $injector) {
$obj = $injector->make($className);
return $obj->handle($request, $next);
});
}
}
continue;
}
if (class_exists($arg)) {
print 'middleware collector classname';
continue;
}
$argParts = explode('@', $arg);
if (class_exists($argParts[0])) {
print 'middleware collector classname + methodname';
continue;
}
throw new \InvalidArgumentException('MiddlewareCollector: invalid middleware "'.$arg.'""');
}
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Dispatcher
/Dispatcher.php
$route = $this->router->match($request);
if (!$route || !($route instanceof iRoute)) {
throw new \RuntimeException('Route not found');
}
//\cmcCMS\trace('in dispather pre middleware check');
if (count($middlewareStack) > 0) {
$dispatcher = $this;
/* @var $thisMiddleware \Closure */
$thisMiddleware = array_shift($middlewareStack);
if (is_callable($thisMiddleware) === false) {
throw new \LogicException('Dispatcher: invalid middleware in stack');
}
//\cmcCMS\trace('above next');
$next = function (iRequest $request) use ($dispatcher, $response, $middlewareStack) {
//\cmcCMS\trace('in next');
return $dispatcher->handle($request, $response, $middlewareStack);
};
$response = $thisMiddleware($request, $next);
if (!$response instanceof iResponse) {
throw new \LogicException('Dispatcher: middleware failed to return a response object');
}
//\cmcCMS\trace('return response');
return $response;
}
$handler = $route->getHandler();
$action = $route->getAction();
$arguments = $route->getArguments();
$arguments[':response'] = $response;
if (is_string($handler) === false) {
$response = $this->dependencyBuilder->execute(
$handler,
$arguments
);
} else {
/usr
/web
/cmcCMS-dev
/vendor
/cmcCMS
/Core
/Application.php
// create the router and import routes from app/routes.php
$router = $this->make('Routing\Router');
$router->importFromFile(APPLICATION_BASE_PATH.'app/routes.php', $this->getConfig());
$dispatcher = $this->make('Dispatcher\Dispatcher', array(
':router'=>$router
));
$MiddlewareCollector = $this->make('Middleware\MiddlewareCollector');
// todo: implement a path-to-namespace conversion instead of passing it?
$MiddlewareCollector->collect(
array('App\Middleware', APPLICATION_BASE_PATH.'app'.DIRECTORY_SEPARATOR.'middleware')
);
return $dispatcher->handle(
$this->make('Request\RequestHttp'),
$this->prepareResponse(),
$MiddlewareCollector->getCollection()
);
/*
if (PROFILE){ Console::logSpeed(); Console::logMemory(); }
// prepare the respone, then dispatch the route
$response = $app->component('response');
$response->setSecure($request->isSecure());
$dispatcher = $app->component('dispatcher');
$tc = 0;
while ($route->complete() != true) {
$tc++;
try {
$dispatcher->dispatch($route, $request, $response, $app);
} catch (Exception $e) {
$route->setError($e);
$route->routeToError(500);
break;
}
if ($tc > 10)
/usr
/web
/cmcCMS-dev
/public
/index.php
<?php
$settingsFile = include('../settingsFile.php');
require_once('../vendor/cmcCMS/bootstrap.php');
//Prevents javascript XSS attacks aimed to steal the session ID
ini_set('session.cookie_httponly', 1);
// Uses a secure connection (HTTPS)
ini_set('session.cookie_secure', 1);
// Prevent Session ID from being passed through URLs
ini_set('session.use_only_cookies', 1);
$app = \cmcCMS\bootstrap(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR, $settingsFile);
$request = $app->make('Request\RequestHttp');
$response = $app->run();
$response->send($request->format);
\cmcCMS\profileMessage('Response sent', 'memory');
\cmcCMS\profileMessage('Response sent', 'speed');
?>