Example #1
0
 public static function createDownloadRoute()
 {
     route_add('getfile/*', function ($name) {
         if (isset($_SESSION['allowed_files']) && in_array($name, $_SESSION['allowed_files'])) {
             // send download
         } else {
             echo t("You don't have access to download this file.");
             exit;
         }
     });
 }
Example #2
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 #3
0
        header('Location: ' . $url_home . '/search/' . urlencode($_POST['q']));
        exit;
    } else {
        header('Location: ' . $url_home);
        exit;
    }
});
// Search Page => `search/search-query`, `search/search-query/1`
route_add(array('search/(:any)', 'search/(:any)/(:num)'), function ($query = "", $offset = 1) use($url_home) {
    $title = 'Search Page';
    $query = urldecode($query);
    template_create('search', array('title' => 'Search Page', 'query' => urldecode($query)));
});
// Static Page
route_add('(:any)', function ($slug = "") use($url_home) {
    if (file_exists('pages/' . $slug . '.txt')) {
        template_create('page', array('title' => 'Static Page', 'slug' => $slug, 'content' => file_get_contents('pages/' . $slug . '.txt')));
    } else {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
        template_create('404', array('title' => '404 Not Found', 'content' => '<p>Page not found.</p>'));
    }
});
// Home Page => `/`
route_add('/', function () use($url_home) {
    template_create('home', array('title' => 'Home Page'));
});
// Do Routing
route_execute();
// Fallback to 404 Page if Nothing Matched
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
template_create('404', array('title' => '404 Not Found', 'content' => '<p>Page not found.</p>'));
Example #4
0
    $pages = \Meta\Builder::read('pages');
    $page = new \Meta\Builder\Page($path, $pages[$path]);
    $object = $page->objects[$oid];
    echo json_encode($object);
});
route_add('builder/analizesql/*/*', function ($pname, $oid) {
    $errors = array();
    $cols = array();
    $sql = \Meta\Builder::replaceSQL(\Meta\Core\Db::sqlNormalize($_REQUEST['query']));
    $statement = \Meta\Core\Db::getPDO()->prepare($sql);
    if ($statement->execute()) {
        for ($i = 0; $i < $statement->columnCount(); $i++) {
            $meta = $statement->getColumnMeta($i);
            //            $cols[$meta['name']] = $meta['native_type'];
            $cols[$meta['name']] = $meta['name'];
        }
    } else {
        $errors = $statement->errorInfo();
    }
    // ataualiza colunas do SQL na base (array)
    $pages = \Meta\Builder::read('pages');
    $pages[$pname]['objects'][$oid]['sqlCols'] = $cols;
    \Meta\Builder::write('pages', $pages);
    echo json_encode(array('errors' => $errors, 'sql_cols' => $cols));
});
route_add('builder/print-metadata/*', function ($pname) {
    $pages = \Meta\Builder::read('pages');
    print_header();
    highlight_string("<?php\n" . var_export($pages[$pname], true));
    print_footer();
});
Example #5
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 #6
0
    exit;
}
if (isset($_GET["new-route-js"])) {
    route_add_js();
    exit;
}
if (isset($_GET["route-delete-js"])) {
    route_delete_js();
    exit;
}
if (isset($_GET["search"])) {
    search();
    exit;
}
if (isset($_GET["new-route-popup"])) {
    route_add();
    exit;
}
if (isset($_POST["ip"])) {
    route_add_save();
    exit;
}
if (isset($_GET["popup"])) {
    popup();
    exit;
}
if (isset($_GET["list"])) {
    echo popup_list();
    exit;
}
if (isset($_POST["delete"])) {
Example #7
0
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));
    $form->fields['submit'] = new Field(array('name' => 'submit', 'label' => 'Save', 'type' => 'btn_validated'));
    $form->fields['submit']->commands[] = new Command(array('command' => 'saveRecordInTable', 'paramValues' => array('users')));
    $form->fields['submit']->commands[] = new Command(array('command' => 'messageAlert', 'paramValues' => array('Form submitted!')));
    $form->fields['submit']->commands[] = new Command(array('command' => 'redirectToCurrentPath'));
    // if any errors occurrs, an Exception will raised
    $page->checkErrors();
    //    echo '<pre>' . var_export($page->toArray(), true) . '</pre>';
    echo $page->render();
});