示例#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();
 }
示例#2
0
文件: File.php 项目: moiseh/metapages
 public function prettySize()
 {
     return \Meta\Core\FileSystem::prettySize($this->getSize());
 }
示例#3
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;
});
示例#4
0
    print_footer();
    ?>
    <?php 
});
// edit/manage page route
route_add('builder/page/*', function ($path) {
    $pages = \Meta\Builder::read('pages');
    $pageArray = $pages[$path];
    // check write permissions
    if (!is_writable(\Meta\Builder::pageFile())) {
        $cmd = 'sudo chmod 666 ' . \Meta\Builder::pageFile();
        \Meta\Core\Flash::error(t('The file <b>' . basename(\Meta\Builder::pageFile()) . '</b> is not writable! To set correct permission, type: <br/><b>' . $cmd . '</b>'));
    }
    // file perms
    if (!\Meta\Core\FileSystem::isDirWritable()) {
        $cmd = 'sudo chmod 666 ' . \Meta\Core\FileSystem::getFilesPath() . ' -R';
        \Meta\Core\Flash::error(t('The files directory is not writable! To set correct permission, type: <br/><b>' . $cmd . '</b>'));
    }
    set_page_title(t("Page: {$pageArray['label']}"));
    // form
    \Meta\Core\Form::validateRequired('name');
    \Meta\Core\Form::validateRequired('label');
    $new_name = \Meta\Core\Form::value('name');
    // page rename action detect
    $renamed = false;
    if (is_post() && $new_name != $path) {
        $renamed = true;
        // validate page exists
        if (isset($pages[$new_name])) {
            \Meta\Core\Form::addError(t('This page already exists'));
        }