示例#1
0
 public function testRenderTemplateWithLayoutUsingPHTMLConvenience()
 {
     phtml()->title = "Test";
     ob_start();
     phtml('for_layout', 'layout')->render();
     $out = ob_get_clean();
     $this->assertContains('<!DOCTYPE html>', $out);
     $this->assertContains('<h1>Test</h1>', $out);
     $this->assertContains('<title>Test</title>', $out);
 }
示例#2
0
function phtml($__n, $__v = [], $__l = 'layout')
{
    # if we have templates set, use it as view base path
    if (($__d = config('templates')) !== null) {
        $__n = "{$__d}/{$__n}";
    }
    # extract locals (__v), require template (__n)
    extract($__v, EXTR_SKIP);
    ob_start();
    require "{$__n}.phtml";
    $__b = ob_get_clean();
    # if we have a layout file, render it
    if (!empty($__l) && is_string($__l)) {
        $__b = phtml($__l, ['body' => $__b] + $__v, null);
    }
    return $__b;
}
示例#3
0
$app_base_url = strlen($app_base) ? "/{$app_base}" : $app_base;
config('url', $app_base_url);
config('templates', 'views');
require APP_DIR . 'functions.php';
if (!session('user_uid')) {
    if (isset($_POST['email']) && isset($_POST['password'])) {
        $users = jdb_select('.users', ['email' => trim($_POST['email'])]);
        if (count($users)) {
            $user = $users[0];
            if ($user['hash'] === hash('sha256', trim($_POST['password']))) {
                session('user_uid', $user['_uid']);
                redirect($_SERVER['REQUEST_URI']);
            } else {
                alerts('error', 'Wrong email or password!');
            }
        } else {
            alerts('error', 'Wrong email or password!');
        }
    }
    echo phtml('login', [], false);
    exit;
}
stash('user', jdb_select('.users', session('user_uid'))[0]);
if (flash('info')) {
    alerts('info', flash('info'));
}
require 'routes/routes.main.php';
require 'routes/routes.users.php';
require 'routes/routes.settings.php';
require 'routes/routes.collections.php';
dispatch();
示例#4
0
<?php

map('GET', '/', function ($db) {
    echo phtml('index');
});
示例#5
0
/**
*
* @package hackslash
* @version GIT: $Id$ Rewrite Imminent 
* @copyright (c) 2015 rage28 (rage28@gmail.com) & Xubz (me@xubz.com)
*
*/
function render_page($title, $inner_layout, $script_path)
{
    print phtml('layout', ['title' => $title, 'body' => $inner_layout, 'script_path' => $script_path], false);
}
示例#6
0
    if (!preg_match('/^\\S+@\\S+$/', $email)) {
        alerts('error', 'Email must have format: abc@xyz.com.');
    }
    if (stash('user')['email'] !== $email) {
        $users = jdb_select('.users', ['email' => $email]);
        if (count($users) > 0) {
            alerts('error', 'User with same email alredy exists.');
        }
    }
    if ($new_password !== '') {
        if (stash('user')['hash'] !== hash('sha256', $password)) {
            alerts('error', 'Wrong password.');
        }
        if (!preg_match('/.{6}/', $new_password)) {
            alerts('error', 'New password must containt minimum 6 characters.');
        }
    }
    if (count(alerts('error')) === 0) {
        $update = ['login' => $login, 'email' => $email];
        if ($new_password) {
            $update['hash'] = hash('sha256', $new_password);
        }
        if (jdb_update('.users', $update, stash('user')['_uid'])) {
            alerts('info', 'User updated.');
            stash('user', jdb_select('.users', stash('user')['_uid'])[0]);
        } else {
            alerts('error', 'Something was wrong, user not updated.');
        }
    }
    echo phtml('user');
});
示例#7
0
 public function testDispatchWithRequestObject()
 {
     $r = new ApplicationTestWrapper();
     $r->get('/person/:name/:id', function () {
         return '/person';
     });
     $r->get('/', function () {
         phtml()->title = "test";
         return phtml('view');
     });
     ob_start();
     $request = new vicious\Request('/person/bob/55', 'GET');
     $r->dispatch($request);
     $o = ob_get_clean();
     $this->assertEquals('/person', $o);
     ob_start();
     $request = new vicious\Request('/', 'GET');
     $r->dispatch($request);
     $o = ob_get_clean();
     $this->assertEquals('<!DOCTYPE html><html><head><title>test</title></head><body><h1>test</h1></body></html>', $o);
 }
示例#8
0
        $posts .= phtml('post', ['post' => unserialize(trim($post))], false);
    }
    print phtml('index', ['posts' => $posts]);
});
# show a post
map('GET', '/posts/<id>', function ($args, $db) {
    foreach (file($db) as $post) {
        $post = unserialize($post);
        if ($post['id'] != $args['id']) {
            continue;
        }
        print phtml('post', ['post' => $post]);
    }
});
# new post form
map('GET', '/submit', function () {
    print phtml('submit', blanks('title', 'body'));
});
# create a new post
map('POST', '/create', function ($db) {
    $post = $_POST['post'];
    $post['id'] = time();
    file_put_contents($db, serialize($post) . "\n", FILE_APPEND);
    return redirect('/index');
});
# load contents of config.ini
config(parse_ini_file(__DIR__ . '/config.ini'));
# prep the db
!file_exists($db = __DIR__ . '/posts.txt') && touch($db);
# pass along our data store
dispatch($db);
        $collection = ['name' => $name, 'slug' => $slug, 'fields' => isset($_POST['fields']) ? $_POST['fields'] : null];
        if (!$collection['fields']) {
            alerts('error', 'Collection must have fields.');
        } else {
            $names = [];
            foreach ($collection['fields'] as $n => $field) {
                $field['name'] = trim($field['name']);
                if ($field['name'] === '') {
                    alerts('error', 'Enter field name (' . ($n + 1) . ')');
                } elseif (in_array($field['name'], $names)) {
                    alerts('error', 'Field with same name aready exist (' . ($n + 1) . ')');
                } else {
                    $names[] = $field['name'];
                }
                if ($field['type'] === 'select' && trim($field['options']) === '') {
                    alerts('error', 'Field with type `select` must have options (' . ($n + 1) . ')');
                }
                $collection['fields'][$n] = ['name' => trim($field['name']), 'type' => $field['type'], 'label' => $field['label'], 'default' => $field['default_value'], 'required' => isset($field['required']) ? true : false, 'options' => $field['options']];
            }
        }
        if (count(alerts('error')) === 0) {
            if (jdb_update('collections', $collection, $uid)) {
                flash('info', 'Collection updated successfuly.');
                redirect(site() . 'collections/collection/' . $uid);
            } else {
                alerts('error', 'Something was wron, collection do not created.');
            }
        }
    }
    echo phtml('collection', ['collection' => $collection]);
});
示例#10
0
            if (!isset($_SESSION['hs_ch_complete'])) {
                $_SESSION['hs_ch_complete'] = false;
            }
            if ($_SESSION['hs_ch_complete']) {
                render_page('Challenge ' . $current_challenge, phtml('challenge-success', ['session' => $_SESSION, 'ext' => $_ext, 'script_path' => $script_path], false), $script_path);
                unset($_SESSION['hs_used_clue']);
                unset($_SESSION['hs_challocatedpts']);
                unset($_SESSION['hs_ch_complete']);
            } else {
                if ($redtime < 5) {
                    $challenge_layout = 'challenge-red';
                } else {
                    $challenge_layout = 'challenge-normal';
                }
                $challenge_statement = get_challenge_data_2($current_challenge);
                $clue = '';
                if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['btnChClue'])) {
                    if (isset($_SESSION['hs_challocatedpts']) && !isset($_SESSION['hs_used_clue'])) {
                        $_SESSION['hs_challocatedpts'] -= $current_challenge;
                    }
                    $clue = get_challenge_clue($current_challenge);
                }
                render_page('Challenge ' . $current_challenge, phtml($challenge_layout, ['current_challenge' => $current_challenge, 'challenge_statement' => $challenge_statement, 'clue' => $clue, 'timeleft' => $timeleft, 'script_path' => $script_path, 'ext' => $_ext], false), $script_path);
            }
        }
    } else {
        return redirect($script_path);
    }
});
config(parse_ini_file(__DIR__ . '/config.ini'));
dispatch($conn);
示例#11
0
function view($template, $data = false, $layout = false)
{
    /*{{{*/
    config('templates', 'views');
    echo phtml($template, $data, $layout);
}
示例#12
0
function page($path, array $vars = [])
{
    return function () use($path, $vars) {
        return response(phtml($path, $vars));
    };
}
示例#13
0
}
# invalid data
try {
    config(require __DIR__ . '/fixtures/settings-invalid.php');
} catch (Exception $e) {
    assert($e instanceof InvalidArgumentException);
}
# ent() and url()
assert(ent('john & marsha') === 'john &amp; marsha');
assert(url('=') === '%3D');
# bare phtml()
assert('<h1>dispatch</h1>' === trim(phtml(__DIR__ . '/fixtures/template', ['name' => 'dispatch'], null)));
# load views config
config(parse_ini_file(__DIR__ . '/fixtures/templates.ini'));
# test page rendering using layout and dispatch.views
assert('<h1>dispatch</h1>' === trim(phtml('template', ['name' => 'dispatch'])));
# form blanks
assert(['name' => '', 'email' => ''] === blanks('name', 'email'));
# ip() - least priority first
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
assert(ip() === $_SERVER['REMOTE_ADDR']);
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.2';
assert(ip() === $_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['HTTP_CLIENT_IP'] = '127.0.0.3';
assert(ip() === $_SERVER['HTTP_CLIENT_IP']);
# stash tests
stash('name', 'dispatch');
assert(stash('name') === 'dispatch');
stash('name', null);
assert(stash('name') === null);
stash('name', 'dispatch');
示例#14
0
<?php

map('GET', '/settings', function () {
    echo phtml('settings');
});