Exemple #1
0
    //login::customerLogado('user_logado',$app);
    //$customer = customers::where('name',$_SESSION['name']);
    $categories = \app\models\categories::listar();
    $dados = array('categories' => $categories, 'customer' => $customer);
    $template = $twig->loadTemplate('contato.html');
    $template->display($dados);
});
$app->get('/:slug', function ($slug) use($app, $twig) {
    $logado = login::customerLogado('user_logado', $app);
    if ($logado) {
        $customer = customers::where('name', $_SESSION['name']);
    } else {
        $customer = null;
    }
    $categories = \app\models\categories::listar();
    $category = \app\models\categories::where('slug', $slug);
    $id = $category->id;
    $albums = \app\models\albums::where('category_id', $id, 'all');
    $dados = array('categories' => $categories, 'category' => $category, 'albums' => $albums, 'customer' => $customer);
    $template = $twig->loadTemplate('album.html');
    $template->display($dados);
});
$app->get('/:slug/:album', function ($slug, $album) use($app, $twig) {
    $logado = login::customerLogado('user_logado', $app);
    if ($logado) {
        $customer = customers::where('name', $_SESSION['name']);
    } else {
        $customer = null;
    }
    $categories = \app\models\categories::listar();
    $album = \app\models\albums::where('slug', $album);
        $app->flash('sucesso', 'Categoria alterada com sucesso !');
        $app->redirect('/admin/categories');
    }
});
$app->post('/admin/categories/cover/:id', function () use($app) {
    $id = $app->request()->post('category-id');
    $foto = $_FILES['foto']['name'];
    $temp_foto = $_FILES['foto']['tmp_name'];
    $extensoes_permitidas = array('jpg', 'jpeg', 'png');
    if (empty($foto)) {
        $app->flash('mensagem', '<div class="alert alert-danger">Escolha uma foto.</div>');
        $app->redirect('/admin/categories');
    } else {
        $isImage = imagem::isImage($foto);
        if ($isImage) {
            $coverAdd = categories::where('id', $id);
            if (empty($coverAdd->cover)) {
                $wide = \WideImage\WideImage::load($temp_foto);
                $imagem = new imagem();
                $novoNome = $imagem->renomear($foto);
                $imagem->upload($wide, 'img/category_cover', 1000, 1000);
                $attributes = array('cover' => $novoNome);
                categories::atualizar($id, $attributes);
                $app->flash('mensagem', '<div class="alert alert-success">Foto Cadastrada.</div>');
                $app->redirect('/admin/categories');
            } else {
                imagem::deletar($coverAdd->cover);
                $wide = \WideImage\WideImage::load($temp_foto);
                $imagem = new imagem();
                $novoNome = $imagem->renomear($foto);
                $imagem->upload($wide, 'img/category_cover', 1000, 1000);