Example #1
0
 function delete()
 {
     $this->load->model('snippets_model');
     if ($this->input->post('selected')) {
         $selected = $this->input->post('selected');
     } else {
         $selected = (array) $this->uri->segment(5);
     }
     $Snippets = new Snippets_model();
     $Snippets->where_in('id', $selected)->get();
     if ($Snippets->exists()) {
         foreach ($Snippets as $Snippet) {
             // Delete revisions
             $Revisions = $Snippet->get_revisions();
             $Revisions->delete_all();
             // Delete snippet
             $Snippet->delete();
         }
         // Clear cache
         $this->load->library('cache');
         $this->cache->delete_all('snippets');
         $message = '<p class="success">The selected items were successfully deleted.</p>';
         $this->session->set_flashdata('message', $message);
     }
     redirect(ADMIN_PATH . '/content/snippets');
 }
Example #2
0
<?php

require 'config.php';
require_once __DIR__ . '/../vendor/autoload.php';
include 'models/snippets.class.php';
$snippets_model = new Snippets_model($pdo);
$app = new Silex\Application();
$app['debug'] = true;
// Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Used for requests
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app->before(function () use($app, $snippets_model) {
    $categories = $snippets_model->get_categories();
    $app["twig"]->addGlobal("categories", $categories);
});
$app->get('/', function ($page) use($app, $snippets_model) {
    $snippets = $snippets_model->get_all();
    $pages = $snippets_model->get_pages_all();
    $app["twig"]->addGlobal("actualPage", array("page" => "home", "category" => "all"));
    return $app['twig']->render('snippets.twig', array('snippets' => $snippets, "pages" => $pages));
})->value('page', 1)->bind('home');
$app->get('/category/{category}/{page}', function ($category = "all", $page = 1) use($app, $snippets_model) {
    if ($category == "all") {
        $snippets = $snippets_model->get_all($page);
        $pages = $snippets_model->get_pages_all($page);
        $cat_details = array('slug' => 'all', 'title' => 'All', 'count' => $snippets_model->get_snippets_count());
    } else {
        $cat_details = $snippets_model->get_cat_details($category);