Example #1
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;
});