Ejemplo n.º 1
0
<?php

namespace Plugins;

use Verbier\Application;
Application::registerPlugin('Hello', function ($app) {
    $app->helper('hello', function () use($app) {
        return 'Hello World';
    });
});
Ejemplo n.º 2
0
<?php

namespace Plugins;

use Verbier\Application;
Application::registerPlugin('Flash', function ($app) {
    $app->flash = new FlashMessages();
    $app->helper('flash', function ($name, $message = null) use($app) {
        if ($message === null) {
            return $app->flash->get($name);
        }
        $app->flash->set($name, $message);
    });
});
class FlashMessages
{
    protected $messages = array();
    public function __construct()
    {
        session_start();
        if (!empty($_SESSION['flashMessages'])) {
            $this->messages = $_SESSION['flashMessages'];
        }
        $_SESSION['flashMessages'] = array();
    }
    public function set($name, $message)
    {
        $_SESSION['flashMessages'][$name] = $message;
    }
    public function get($name)
    {
Ejemplo n.º 3
0
<?php

use Verbier\Application;
Application::registerPlugin('Markdown', function ($app) {
    $app->helper('markdown', function ($text) {
        $parser = new Markdown_Parser();
        return $parser->transform($text);
    });
});
define('MARKDOWN_VERSION', "1.0.1n");
define('MARKDOWN_EMPTY_ELEMENT_SUFFIX', " />");
define('MARKDOWN_TAB_WIDTH', 4);
class Markdown_Parser
{
    # Regex to match balanced [brackets].
    # Needed to insert a maximum bracked depth while converting to PHP.
    var $nested_brackets_depth = 6;
    var $nested_brackets_re;
    var $nested_url_parenthesis_depth = 4;
    var $nested_url_parenthesis_re;
    # Table of hash values for escaped characters:
    var $escape_chars = '\\`*_{}[]()>#+-.!';
    var $escape_chars_re;
    # Change to ">" for HTML output.
    var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX;
    var $tab_width = MARKDOWN_TAB_WIDTH;
    # Change to `true` to disallow markup or entities.
    var $no_markup = false;
    var $no_entities = false;
    # Predefined urls and titles for reference links and images.
    var $predef_urls = array();
Ejemplo n.º 4
0
<?php

use Verbier\Application;
Application::registerPlugin('Auth', function ($app) {
    $app->helper('ensure_user_is_logged_in', function () use($app) {
        if ($app->request->env('PHP_AUTH_USER') === null) {
            authenticate();
        } else {
            if ($app->request->env('PHP_AUTH_USER') !== ADMIN_EMAIL || $app->request->env('PHP_AUTH_PW') !== ADMIN_PASSWORD) {
                authenticate();
            }
        }
        return true;
    });
    $app->helper('authenticate', function () use($app) {
        $app->response->setHeader('WWW-Authenticate: Basic realm="Verbier Auth"');
        $app->response->setHeader('HTTP/1.1 401 Unauthorized');
        $app->response->setContent('Authentication required');
        $app->response->finish();
    });
});