예제 #1
0
<?php

/**
 * This is a Anax pagecontroller.
 *
 */
// Get environment & autoloader.
require __DIR__ . '/config_with_app.php';
// Demonstration of application specific module CDice
$dice = new \Mos\Dice\CDice();
// Check how many rolls to do
$roll = isset($_GET['roll']) && is_numeric($_GET['roll']) ? $_GET['roll'] : 0;
if ($roll > 100) {
    throw new Exception("To many rolls on the dice. Not allowed.");
}
// Make roll and prepare reply
$html = null;
if ($roll) {
    $dice->roll($roll);
    $html = "<p>You made {$roll} roll(s) and you got this serie.</p>\n<ul class='dice'>";
    foreach ($dice->getResults() as $val) {
        $html .= "\n<li class='dice-{$val}'></li>";
    }
    $html .= "\n</ul>\n";
    $html .= "<p>You got " . $dice->getTotal() . " as a total.</p>";
}
// Prepare the page content
$app->theme->addStylesheet("css/dice.css")->setVariable('title', "Throw a dice")->setVariable('main', "\n    <h1>Throw a dice</h1>\n    <p>This is a sample pagecontroller showing how to use <i>application specific modules</i> in a pagecontroller.</p>\n    <p>How many rolls do you want to do, <a href='?roll=1'>1 roll</a>, <a href='?roll=3'>3 rolls</a> or <a href='?roll=6'>6 rolls</a>? </p>\n    {$html}\n");
// Render the response using theme engine.
$app->theme->render();
예제 #2
0
 *
 */
// Get environment & autoloader.
require __DIR__ . '/config_with_app.php';
// Add extra assets
$app->theme->addStylesheet('css/dice.css');
// Home route
$app->router->add('', function () use($app) {
    $app->views->add('welcome/index');
    $app->theme->setTitle("Welcome to Anax");
});
// Route to show welcome to dice
$app->router->add('dice', function () use($app) {
    $app->views->add('dice/index');
    $app->theme->setTitle("Roll a dice");
});
// Route to roll dice and show results
$app->router->add('dice/roll', function () use($app) {
    // Check how many rolls to do
    $roll = $app->request->getGet('roll', 1);
    $app->validate->check($roll, ['int', 'range' => [1, 100]]) or die("Roll out of bounds");
    // Make roll and prepare reply
    $dice = new \Mos\Dice\CDice();
    $dice->roll($roll);
    $app->views->add('dice/index', ['roll' => $dice->getNumOfRolls(), 'results' => $dice->getResults(), 'total' => $dice->getTotal()]);
    $app->theme->setTitle("Rolled a dice");
});
// Check for matching routes and dispatch to controller/handler of route
$app->router->handle();
// Render the page
$app->theme->render();
예제 #3
0
    $content = $app->fileContent->get('about.md');
    $content = $app->textFilter->doFilter($content, 'shortcode, markdown, nl2br');
    $byline = $app->fileContent->get('byline.md');
    $byline = $app->textFilter->doFilter($byline, 'shortcode, markdown');
    $app->views->add('me/page', ['content' => $content, 'byline' => $byline]);
});
$app->router->add('source', function () use($app) {
    $app->theme->addStylesheet('css/source.css');
    $app->theme->setTitle("Source code");
    $source = new \Me\Source\CSource(['secure_dir' => '..', 'base_dir' => '..', 'add_ignore' => ['.htaccess']]);
    $app->views->add('me/source', ['content' => $source->View()]);
});
$app->router->add('dice', function () use($app) {
    $app->theme->setTitle('Spela tärning');
    $app->theme->addStylesheet('css/dice.css');
    $die = new \Mos\Dice\CDice();
    $results = null;
    $total = null;
    $roll = null;
    if (isset($_GET['roll']) && $_GET['roll'] > 0 && $_GET['roll'] < 7) {
        $die->roll($_GET['roll']);
        $roll = filter_var($_GET['roll'], FILTER_SANITIZE_NUMBER_INT);
        $results = $die->getResults();
        $total = $die->getTotal();
    }
    $app->views->add('dice/index', ['roll' => $roll, 'results' => $results, 'total' => $total]);
});
$app->router->add('presentation/kmom01', function () use($app) {
    $app->theme->setVariable('title', "Kmom01");
    $content = $app->fileContent->get('presentation/kmom01.md');
    $content = $app->textFilter->doFilter($content, 'shortcode, markdown, nl2br');