Example #1
0
 /**
  * Initialize builder
  */
 public static function init()
 {
     require_once abspath('app/overrides.php');
     // Loop all pages to add the routes
     foreach (\Meta\Builder::read('pages') as $path => $page) {
         route_add($path, function () use($path, $page) {
             $pg = new \Meta\Builder\Page($path, $page, true);
             echo $pg->render();
         });
     }
     // file
     \Meta\Core\FileSystem::createDownloadRoute();
 }
Example #2
0
    return $page;
});
Page::beforeRender('frame-user-groups', function ($page) {
    // modify $page array here
    // prevent unauthorized actions
    if (is_demo() && isset($_REQUEST['action']) && isset($_REQUEST['id'])) {
        if (is_post() || $_REQUEST['action'] == 'delete') {
            $user_id = \Meta\Core\Db::query('SELECT user_id FROM user_groups WHERE id = ?', array($_REQUEST['id']))->fetchColumn();
            if ($user_id == 1) {
                \Meta\Core\Flash::error(t('Sorry, but you cannot modify the Admin user in demo mode'));
                header("Location: " . urldecode($_GET['url_from']));
                exit;
            }
        }
    }
    return $page;
});
Page::beforeRender('manage-files', function ($page) {
    // scan all files. if the number is different than the table, then re populate all entirely table
    $files = \Meta\Core\FileSystem::listAll();
    $dbCountFiles = \Meta\Core\Db::query('SELECT COUNT(*) FROM files')->fetchColumn();
    if (count($files) > 0 && count($files) != $dbCountFiles) {
        // delete all and insert files list
        \Meta\Core\Db::execute('DELETE FROM files');
        foreach ($files as $file) {
            \Meta\Core\Db::save('files', array('name' => basename($file), 'size' => filesize($file)));
        }
        \Meta\Core\Flash::info(t('The files base was been updated'));
    }
    return $page;
});
Example #3
0
<?php

use Meta\Core\Flash;
use Meta\Core\Form;
use Meta\Core\User;
use Meta\Builder\Page;
route_add('user-login', function () {
    set_page_title('User authentication');
    Form::validateRequired('username');
    Form::validateRequired('password');
    if (Form::hasValidated()) {
        if (User::authenticate($_POST['username'], $_POST['password'])) {
            if (isset($_GET['back_to'])) {
                redirect(urldecode($_GET['back_to']));
            } else {
                redirect(PAGE_HOME);
            }
        } else {
            Flash::error(t('Invalid username or password!'));
        }
    }
    echo Page::renderLayout(array('content' => render('user-login.php')));
});
route_add('user-logout', function () {
    User::logout();
    redirect(PAGE_HOME);
});
Example #4
0
 protected function blockAccess()
 {
     echo \Meta\Builder\Page::renderDenied();
     exit;
     return true;
 }
Example #5
0
<?php

// this is an example of how use the API for generate pages with View and Form components
use Meta\Builder\Page;
use Meta\Builder\Object;
use Meta\Builder\Column;
use Meta\Builder\Field;
use Meta\Builder\Formatter;
use Meta\Builder\Command;
use Meta\Builder\Condition;
use Meta\Builder\Validation;
use Meta\Builder\Object\View;
use Meta\Builder\Object\Form;
route_add('page-sample', function () {
    // page
    $page = new Page('page-sample', array('label' => 'My test page'));
    // listing
    $view = $page->objects[] = new View();
    $view->templateFile = 'builder-view-table.php';
    $view->paginate = true;
    $view->query = array('select' => '*', 'from' => 'users');
    $view->columns[] = new Column(array('id' => 'login', 'label' => 'Login'));
    $view->columns[] = new Column(array('id' => 'name', 'label' => 'Name', 'sortable' => true));
    $view->columns['id'] = new Column(array('id' => 'id', 'label' => 'action'));
    $view->columns['id']->formatters[] = new Formatter(array('command' => 'linkSimple', 'paramValues' => array('edit', '?action=edit&id=[id]')));
    // form edit
    $form = $page->objects[] = new Form(array('label' => 'Edit form'));
    $form->rules[] = new Condition(array('command' => 'parameterHasValue', 'paramValues' => array('action', 'edit')));
    $form->onLoad[] = new Command(array('command' => 'fetchFromTable', 'paramValues' => array('users')));
    $form->fields['id'] = new Field(array('name' => 'id', 'label' => 'ID', 'type' => 'pkeyfield'));
    $form->fields['name'] = new Field(array('name' => 'name', 'label' => 'Name', 'type' => 'text', 'isRequired' => true));