示例#1
0
    /**
     * Be careful to never throw exceptions from here if we're already
     * on the Error500Page. e.g. if content of FooPage is empty, this throws
     * an exception but then index.php instantiates a new page (Error500Page),
     * which does have content. So any exception thrown from here (either directly
     * or indirectly from an Action class), should either be caught or made sure
     * that it doesn't occurr for a Error500Page).
     */
    public function output()
    {
        $this->execute();
        if (!$this->getContent()) {
            throw new SwarmException("Page `content` must not be empty.");
        }
        if (!$this->getTitle()) {
            throw new SwarmException("Page `title` must not be empty.");
        }
        if (headers_sent($filename, $linenum)) {
            throw new SwarmException("Headers already sent in `{$filename}` on line {$linenum}.");
        }
        header("Content-Type: text/html; charset=utf-8");
        $request = $this->getContext()->getRequest();
        // ProjectsAction could throw an exception, which needs to be caught here,
        // since Error500Page (exception handler) also uses Page::output() eventually.
        // @todo: Find a cleaner way to deal with exceptions in the final page out,
        // because page output is also used on the Error500Page.
        $projects = array();
        if (!isset($this->exceptionObj)) {
            try {
                $projectsActionContext = $this->getContext()->createDerivedRequestContext(array("action" => "projects", "sort" => "name", "sort_oder" => "asc"));
                $projectsAction = ProjectsAction::newFromContext($projectsActionContext);
                $projectsAction->doAction();
                $projects = $projectsAction->getData();
            } catch (Exception $e) {
                $pageObj = Error500Page::newFromContext($this->getContext());
                $pageObj->setExceptionObj($e);
                $pageObj->output();
                exit;
            }
        }
        ?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<?php 
        foreach ($this->metaTags as $metaTag) {
            echo "\t" . html_tag("meta", $metaTag) . "\n";
        }
        $subTitleSuffix = $this->getSubTitle() ? ": {$this->getSubTitle()}" : "";
        $htmlTitle = $this->getTitle() . $subTitleSuffix . " - " . $this->getContext()->getConf()->web->title;
        $displayTitleHtml = $this->getDisplayTitleHtml();
        ?>
	<title><?php 
        echo htmlentities($htmlTitle);
        ?>
</title>
	<link rel="stylesheet" href="<?php 
        echo swarmpath("css/bootstrap.min.css");
        ?>
">
	<link rel="stylesheet" href="<?php 
        echo swarmpath("css/testswarm.css");
        ?>
">
	<script src="<?php 
        echo swarmpath("js/jquery.js");
        ?>
"></script>
	<script src="<?php 
        echo swarmpath("js/bootstrap-dropdown.js");
        ?>
"></script>
	<script>window.SWARM = <?php 
        $infoAction = InfoAction::newFromContext($this->getContext());
        $infoAction->doAction();
        echo json_encode($infoAction->getData());
        ?>
;</script><?php 
        foreach ($this->styleSheets as $styleSheet) {
            echo "\n\t" . html_tag("link", array("rel" => "stylesheet", "href" => $styleSheet));
        }
        foreach ($this->headScripts as $headScript) {
            echo "\n\t" . html_tag("script", array("src" => $headScript));
        }
        ?>
</head>
<body>
	<div class="navbar navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<a class="brand" href="<?php 
        echo swarmpath("");
        ?>
"><?php 
        echo htmlspecialchars($this->getContext()->getConf()->web->title);
        ?>
</a>
				<div class="nav-collapse">
					<ul class="nav">
						<li><a href="<?php 
        echo swarmpath("");
        ?>
">Home</a></li>
						<li class="dropdown" id="swarm-projectsmenu">
							<a href="<?php 
        echo swarmpath("projects");
        ?>
" class="dropdown-toggle" data-toggle="dropdown" data-target="#swarm-projectsmenu">
								Projects
								<b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<li><a href="<?php 
        echo swarmpath("projects");
        ?>
">All projects</a></li>
								<li class="divider"></li>
								<li class="nav-header">Projects</li>
<?php 
        foreach ($projects as $project) {
            ?>
								<li><a href="<?php 
            echo htmlspecialchars(swarmpath("user/{$project["name"]}"));
            ?>
"><?php 
            echo htmlspecialchars($project["name"]);
            ?>
</a></li>
<?php 
        }
        ?>
							</ul>
						</li>
						<li><a href="<?php 
        echo swarmpath("scores");
        ?>
">Scores</a></li>
						<li><a href="<?php 
        echo swarmpath("about");
        ?>
">About</a></li>
					</ul>
					<ul class="nav pull-right">
<?php 
        if ($request->getSessionData("username") && $request->getSessionData("auth") == "yes") {
            $username = htmlspecialchars($request->getSessionData("username"));
            ?>
						<li><a href="<?php 
            echo swarmpath("user/{$username}");
            ?>
">Hello, <?php 
            echo $username;
            ?>
!</a></li>
						<li><a href="<?php 
            echo swarmpath("run/{$username}");
            ?>
">Join the Swarm</a></li>
						<li><a href="<?php 
            echo swarmpath("logout");
            ?>
">Logout</a></li>
<?php 
        } else {
            ?>
						<li><a href="<?php 
            echo swarmpath("login");
            ?>
">Login</a></li>
						<li><a href="<?php 
            echo swarmpath("signup");
            ?>
">Signup</a></li>
<?php 
        }
        ?>
					</ul>
				</div><!--/.nav-collapse -->
			</div>
		</div>
	</div>

	<div class="container">
		<div class="hero-unit">
			<h1><?php 
        echo $displayTitleHtml;
        ?>
</h1>
		</div>
<?php 
        echo $this->getContent();
        ?>

		<hr>
		<footer class="swarm-page-footer">
			<p>Powered by <a href="//github.com/jquery/testswarm">TestSwarm</a>:
			<a href="//github.com/jquery/testswarm">Source Code</a>
			| <a href="//github.com/jquery/testswarm/issues">Issue Tracker</a>
			| <a href="//github.com/jquery/testswarm/wiki">About</a>
			| <a href="//twitter.com/testswarm">Twitter</a>
			</p>
		</footer>
	</div>
	<script src="<?php 
        echo swarmpath("js/pretty.js");
        ?>
"></script>
	<script src="<?php 
        echo swarmpath("js/testswarm.js");
        ?>
"></script><?php 
        foreach ($this->bodyScripts as $bodyScript) {
            echo "\n\t" . html_tag("script", array("src" => $bodyScript));
        }
        if ($this->getContext()->getConf()->debug->dbLogQueries) {
            $queryLog = $this->getContext()->getDB()->getQueryLog();
            $queryLogHtml = '<hr><h3>Database query log</h3><div class="well"><ul class="unstyled">';
            foreach ($queryLog as $i => $queryInfo) {
                if ($i !== 0) {
                    $queryLogHtml .= '<hr>';
                }
                $queryLogHtml .= '<li>' . '<pre>' . htmlspecialchars($queryInfo["sql"]) . '</pre>' . '<table class="table table-bordered table-condensed"><tbody><tr>' . '<td>Caller: <code>' . htmlspecialchars($queryInfo["caller"]) . '</code></td>' . '<td>Num rows: <code>' . htmlspecialchars($queryInfo["numRows"]) . '</code></td>' . '<td>Insert ID: <code>' . htmlspecialchars($queryInfo["insertId"]) . '</code></td>' . '<td>Affected rows: <code>' . htmlspecialchars($queryInfo["affectedRows"]) . '</code></td>' . '<td>Query time: <code>' . htmlspecialchars(substr($queryInfo["queryTime"], 0, 8)) . '</code></td>' . '</tr></table>' . '</li>';
            }
            $queryLogHtml .= '</ul>';
            echo $queryLogHtml;
        }
        ?>
</body>
</html>
<?php 
        // End of Page::output
    }
示例#2
0
<?php

/**
 * This is the main front-end entry point for TestSwarm.
 *
 * All HTML-based views served to web browsers start here.
 * The recommended configuration will have web requests
 * rewritten from a path to a query string calling index.php
 *
 * @author Timo Tijhof, 2012
 * @since 0.1.0
 * @package TestSwarm
 */
// Valid entry point
define('SWARM_ENTRY', 'INDEX');
require_once __DIR__ . '/inc/init.php';
session_start();
$pageObj = $swarmContext->getRequest()->getPageInstance();
if ($pageObj instanceof Page) {
    try {
        $pageObj->output();
    } catch (Exception $e) {
        $pageObj = Error500Page::newFromContext($swarmContext);
        $pageObj->setExceptionObj($e);
        $pageObj->output();
    }
} else {
    $pageObj = Error404Page::newFromContext($swarmContext);
    $pageObj->output();
}
exit;
示例#3
0
    /**
     * Be careful to never throw exceptions from here if we're already
     * on the Error500Page. e.g. if content of FooPage is empty, this throws
     * an exception but then index.php instantiates a new page (Error500Page),
     * which does have content. So any exception thrown from here (either directly
     * or indirectly from an Action class), should either be caught or made sure
     * that it doesn't occurr for a Error500Page).
     */
    public function output()
    {
        $this->execute();
        if (!$this->getContent()) {
            throw new SwarmException('Page `content` must not be empty.');
        }
        if (!$this->getTitle()) {
            throw new SwarmException('Page `title` must not be empty.');
        }
        if (headers_sent($filename, $linenum)) {
            throw new SwarmException("Headers already sent in `{$filename}` on line {$linenum}.");
        }
        header('Content-Type: text/html; charset=UTF-8');
        $frameOptions = $this->getFrameOptions();
        if ($frameOptions) {
            header('X-Frame-Options: ' . $frameOptions, true);
        }
        $context = $this->getContext();
        $request = $context->getRequest();
        $auth = $context->getAuth();
        // ProjectsAction could throw an exception, which needs to be caught here,
        // since Error500Page (exception handler) also uses Page::output() eventually.
        // @todo: Find a cleaner way to deal with exceptions in the final page out,
        // because page output is also used on the Error500Page.
        $projects = array();
        if (!isset($this->exceptionObj)) {
            try {
                $projectsAction = ProjectsAction::newFromContext($context);
                $projectsAction->doAction();
                $projects = $projectsAction->getData();
            } catch (Exception $e) {
                $pageObj = Error500Page::newFromContext($context);
                $pageObj->setExceptionObj($e);
                $pageObj->output();
                exit;
            }
        }
        ?>
<!DOCTYPE html>
<html lang="en" dir="ltr" class="no-js">
<head>
<?php 
        foreach ($this->metaTags as $metaTag) {
            echo "\t" . html_tag('meta', $metaTag) . "\n";
        }
        $subTitleSuffix = $this->getSubTitle() ? ": {$this->getSubTitle()}" : "";
        $htmlTitle = $this->getTitle() . $subTitleSuffix . ' - ' . $context->getConf()->web->title;
        $displayTitleHtml = $this->getDisplayTitleHtml();
        ?>
	<title><?php 
        echo htmlentities($htmlTitle);
        ?>
</title>
	<link rel="stylesheet" href="<?php 
        echo swarmpath('external/bootstrap/css/bootstrap.css');
        ?>
">
	<link rel="stylesheet" href="<?php 
        echo swarmpath('external/bootstrap/css/bootstrap-responsive.css');
        ?>
">
	<link rel="stylesheet" href="<?php 
        echo swarmpath('css/testswarm.css');
        ?>
">
	<script>
	(function (h) { h.className = h.className.replace(/\bno-js\b/,'js')})(document.documentElement);
	SWARM = <?php 
        $infoAction = InfoAction::newFromContext($context);
        $infoAction->doAction();
        echo json_encode2($infoAction->getData());
        ?>
;
	SWARM.auth = <?php 
        echo json_encode2($auth);
        ?>
;
	</script>
<?php 
        foreach ($this->styleSheets as $styleSheet) {
            echo "\t" . html_tag('link', array('rel' => 'stylesheet', 'href' => $styleSheet)) . "\n";
        }
        foreach ($this->headScripts as $headScript) {
            echo "\t" . html_tag('script', array('src' => $headScript)) . "\n";
        }
        ?>
</head>
<body>
	<div class="navbar navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<a class="brand" href="<?php 
        echo swarmpath('');
        ?>
"><?php 
        echo htmlspecialchars($context->getConf()->web->title);
        ?>
</a>
				<ul class="nav">
					<?php 
        echo $this->getPageLink('home', 'Home');
        ?>
					<li class="dropdown<?php 
        if (strpos($this->getSelfPath(), 'projects') === 0) {
            echo ' active';
        }
        ?>
">
						<a href="<?php 
        echo swarmpath('projects');
        ?>
" class="dropdown-toggle" data-toggle="dropdown">
							Projects
							<b class="caret"></b>
						</a>
						<ul class="dropdown-menu">
							<?php 
        echo $this->getPageLink('projects', 'All projects');
        ?>
							<li class="divider"></li>
							<li class="nav-header">Projects</li>
<?php 
        foreach ($projects as $project) {
            echo $this->getPageLink("project/{$project['id']}", $project['displayTitle']);
        }
        ?>
						</ul>
					</li>
					<?php 
        echo $this->getPageLink('clients', 'Clients');
        ?>
					<?php 
        echo $this->getPageLink('info', 'Info');
        ?>
				</ul>
				<ul class="nav pull-right">
<?php 
        if ($auth) {
            ?>
					<li><a href="<?php 
            echo htmlspecialchars(swarmpath("project/{$auth->project->id}"));
            ?>
"><?php 
            echo htmlspecialchars($auth->project->display_title);
            ?>
</a></li>
					<li><a href="<?php 
            echo swarmpath("addjob");
            ?>
">Add job</a></li>
					<li><a href="<?php 
            echo swarmpath('logout');
            ?>
" class="swarm-logout-link">Logout</a></li>
<?php 
        } else {
            echo $this->getPageLink('login', 'Login');
        }
        ?>
				</ul>
			</div>
		</div>
	</div>

	<div class="container">
		<div class="hero-unit">
			<h1><?php 
        echo $displayTitleHtml;
        ?>
</h1>
		</div>
<?php 
        echo $this->getContent();
        ?>

		<hr>
		<footer class="swarm-page-footer">
			<p>Powered by <a href="https://github.com/jquery/testswarm">TestSwarm</a>:
			<a href="https://github.com/jquery/testswarm">Source Code</a>
			| <a href="https://github.com/jquery/testswarm/issues">Issue Tracker</a>
			| <a href="https://github.com/jquery/testswarm/wiki">About</a>
			| <a href="https://twitter.com/testswarm">Twitter</a>
			</p>
		</footer>
	</div>
	<script src="<?php 
        echo swarmpath('external/jquery/jquery.js');
        ?>
"></script>
	<script src="<?php 
        echo swarmpath('external/bootstrap/js/bootstrap-dropdown.js');
        ?>
"></script>
	<script src="<?php 
        echo swarmpath('js/pretty.js');
        ?>
"></script>
	<script src="<?php 
        echo swarmpath('js/testswarm.js');
        ?>
"></script><?php 
        foreach ($this->bodyScripts as $bodyScript) {
            echo "\n\t" . html_tag('script', array('src' => $bodyScript));
        }
        if ($context->getConf()->debug->dbLogQueries) {
            $queryLog = $context->getDB()->getQueryLog();
            $queryLogHtml = '<hr><h3>Database query log</h3><div class="well"><ul class="unstyled">';
            foreach ($queryLog as $i => $queryInfo) {
                if ($i !== 0) {
                    $queryLogHtml .= '<hr>';
                }
                $queryLogHtml .= '<li>' . '<pre>' . htmlspecialchars($queryInfo["sql"]) . '</pre>' . '<table class="table table-bordered table-condensed"><tbody><tr>' . '<td>Caller: <code>' . htmlspecialchars($queryInfo['caller']) . '</code></td>' . '<td>Num rows: <code>' . htmlspecialchars($queryInfo['numRows']) . '</code></td>' . '<td>Insert ID: <code>' . htmlspecialchars($queryInfo['insertId']) . '</code></td>' . '<td>Affected rows: <code>' . htmlspecialchars($queryInfo['affectedRows']) . '</code></td>' . '<td>Query time: <code>' . htmlspecialchars(substr($queryInfo['queryTime'], 0, 8)) . '</code></td>' . '</tr></table>' . '</li>';
            }
            $queryLogHtml .= '</ul>';
            echo $queryLogHtml;
        }
        ?>
</body>
</html>
<?php 
        // End of Page::output
    }