Esempio n. 1
2
require 'lib/http.php';
require 'lib/site.php';
define('DATA_DIR', '../data/');
define('LOG_DIR', '../logs/');
define('CACHE_DIR', '../cache/');
define('DEBUG', getenv('APPLICATION_ENV'));
TwigView::$twigDirectory = 'vendor/Twig';
$twigview = new TwigView();
$app = new Slim(array('templates.path' => '../views', 'debug' => true, 'view' => $twigview));
// Add some functions that will be usable inside Twig
twig_add_function(array($twigview, 'is_float', 'var_dump'));
$app->get('/', function () use($app) {
    $data['url'] = 'http://' . get_random_url();
    $data['check_url'] = "http://{$_SERVER['SERVER_NAME']}/check?url=";
    $data['show_try'] = true;
    $app->render('index.twig', $data);
});
$app->get('/sms', function () use($app) {
    $data['url'] = 'http://' . get_random_url();
    $data['check_url'] = "http://{$_SERVER['SERVER_NAME']}/check?url=";
    $data['show_try'] = true;
    $app->render('sms.twig', $data);
});
$app->get('/check', function () use($app) {
    $url = trim($app->request()->params('url'));
    if ($url === 'random') {
        $url = get_random_url();
    }
    // Normalize URL to include "http://" prefix.
    $url2 = parse_url($url);
    if (!isset($url2['scheme'])) {
Esempio n. 2
2
        $app->response()->header('HTTP/1.1 401 Unauthorized', '');
        $app->response()->body('<h1>Please enter valid administration credentials</h1>');
        $app->response()->send();
        exit;
    }
};
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('log/your.log', Logger::WARNING));
// add records to the log
$log->addWarning('Foo');
$log->addError('Bar');
// Blog Home.
$app->get('/', function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    return $app->render('blog_home.html', array('articles' => $articles));
});
// Blog View.
$app->get('/view/(:id)', function ($id) use($app) {
    $article = Model::factory('Article')->find_one($id);
    if (!$article instanceof Article) {
        $app->notFound();
    }
    return $app->render('blog_detail.html', array('article' => $article));
});
// Admin Home.
$app->get('/admin', $authCheck, function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    return $app->render('admin_home.html', array('articles' => $articles));
});
// Admin Add.
Esempio n. 3
2
 /**
  * Test render with template and data and status
  */
 public function testRenderTemplateWithDataAndStatus()
 {
     $s = new Slim(array('templates.path' => dirname(__FILE__) . '/templates'));
     $s->get('/bar', function () use($s) {
         $s->render('test.php', array('foo' => 'bar'), 500);
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals(500, $status);
     $this->assertEquals('test output bar', $body);
 }
Esempio n. 4
2
 /**
  * Render template
  */
 function render($template)
 {
     $this->slim->render($template, $this->viewData());
 }
Esempio n. 5
1
<?php

require 'Slim/Slim.php';
//With custom settings
$app = new Slim();
//Mailchimp help route
$app->get('/mailchimp', function () use($app) {
    $app->render('mailchimp.php');
});
//Mailchimp webhook
$app->post('/mailchimp', function () use($app) {
    require_once 'MCAPI.class.php';
    $emailField = $app->request()->get('email');
    $listId = $app->request()->get('listid');
    $apiKey = $app->request()->get('apikey');
    //Make sure we have required data.
    if (empty($emailField) || empty($listId) || empty($apiKey)) {
        $app->halt(500, 'Your hook is missing required GET parameters.');
    }
    $email = $app->request()->post($emailField);
    $forename = $app->request()->post($app->request()->get('forename'));
    $surname = $app->request()->post($app->request()->get('surname'));
    $rid = $app->request()->post('id');
    //Make sure we have required data.
    if (empty($email)) {
        $app->halt(500, 'Your hook is missing email address.');
    }
    //If double opt in parameter is present, subscribe with double opt-in.
    $doubleOptIn = false;
    if (!is_null($app->request()->get('doubleoptin'))) {
        $doubleOptIn = true;
Esempio n. 6
1
<?php

require 'Slim/Slim.php';
require 'Views/TwigView.php';
$app = new Slim(array('view' => new TwigView(), 'templates.path' => 'templates'));
$app->get('/', function () use($app) {
    $app->render('index.html');
});
$app->run();
Esempio n. 7
1
 /**
  * Test Slim::render
  *
  * Pre-conditions:
  * You have initialized a Slim app and render an existing
  * template. No Exceptions or Errors are thrown.
  *
  * Post-conditions:
  * The response status is 404;
  * The View data is set correctly;
  * The response status code is set correctly
  */
 public function testSlimRenderSetsResponseStatusOk(){
     $data = array('foo' => 'bar');
     Slim::init();
     Slim::render('test.php', $data, 404);
     $this->assertEquals(Slim::response()->status(), 404);
     $this->assertEquals($data, Slim::view()->getData());
     $this->assertEquals(Slim::response()->status(), 404);
 }
Esempio n. 8
1
 /**
  * Render template
  *
  * @param string $template template file to be rendered
  */
 public function render($template)
 {
     $this->slim->render($template, $this->getViewData());
 }
Esempio n. 9
0
 /**
  * Render view for specific action
  * @param  string $dir  directory name that contains the view files
  * @param  string $view view file
  * @return void
  */
 public function renderView($dir, $view)
 {
     $templatePath = $this->app->config->get('app.settings.renderer.template_path');
     $templateExt = $this->app->config->get('app.settings.renderer.template_ext');
     $file = $templatePath . DS . $dir . DS . $view . $templateExt;
     ob_start();
     if (isset($this->viewData)) {
         extract($this->viewData);
     }
     require $file;
     $content = ob_get_clean();
     // Store slim app to pass it to the view
     $app = $this->app;
     // Append data to view
     $this->app->view->appendData(compact('app', 'content'));
     $this->app->render($this->layout);
 }
Esempio n. 10
0
 /**
  * Test Slim sets custom status code
  *
  * Pre-conditions:
  * You have initialized a Slim app and render a template while
  * specifying a non-200 status code.
  *
  * Post-conditions:
  * The HTTP response status code is set correctly.
  */
 public function testSlimRenderSetsStatusCode()
 {
     Slim::init();
     $data = array('foo' => 'bar');
     Slim::render('test.php', $data, 400);
     $this->assertEquals(Slim::response()->status(), 400);
 }
Esempio n. 11
0
<?php

if (isset($_GET['debug'])) {
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
    // System Start Time
    define('START_TIME', microtime(true));
    // System Start Memory
    define('START_MEMORY_USAGE', memory_get_usage());
}
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/', function () use($app) {
    $app->render('helloworld.php');
});
$app->run();
$xhprof_data = xhprof_disable();
if (!isset($_GET['debug'])) {
    die;
}
echo "Page rendered in <b>" . round(microtime(true) - START_TIME, 5) * 1000 . " ms</b>, taking <b>" . round((memory_get_usage() - START_MEMORY_USAGE) / 1024, 2) . " KB</b>";
$f = get_included_files();
echo ", include files: " . count($f);
$XHPROF_ROOT = realpath(dirname(__FILE__) . '/..');
include_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_foo"
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
echo ", xhprof <a href=\"http://xhprof.pfb.example.com/xhprof_html/index.php?run={$run_id}&source=xhprof_foo\">url</a>";
Esempio n. 12
0
    $isLoginned = User::isLoginned();
    if ($isLoginned) {
        return $app->redirect('/newtest/user/' . $_COOKIE['login']);
    } else {
        return $app->redirect('/newtest/feed');
    }
});
// Blog Feed.
$app->get('/feed', function () use($app) {
    $articles = Model::factory('Article')->order_by_desc('timestamp')->find_many();
    $isLoginned = User::isLoginned();
    $user_name = '';
    if ($isLoginned) {
        $user_name = $_COOKIE['login'];
    }
    return $app->render('blog_home.html', array('articles' => $articles, 'isLoginned' => $isLoginned, 'B_author' => 'People', 'User_name' => $user_name));
});
// Blog View.
$app->get('/posts/view/(:id)', function ($id) use($app) {
    $article = Model::factory('Article')->find_one($id);
    if (!$article instanceof Article) {
        $app->notFound();
    }
    $isLoginned = User::isLoginned();
    $user_name = '';
    if ($isLoginned) {
        $user_name = $_COOKIE['login'];
    }
    //$app->response()->header('Content-Type', 'application/json');
    //echo json_encode($article->as_array());
    return $app->render('blog_detail.html', array('article' => $article, 'isLoginned' => $isLoginned, 'User_name' => $user_name));
Esempio n. 13
0
<?php

require_once 'Views/Twig/Autoloader.php';
Twig_Autoloader::register();
require 'Slim/Slim.php';
require 'Views/TwigView.php';
require 'lib/database.php';
$app = new Slim(array('view' => 'TwigView', 'http.version' => '1.0'));
$app->get('/', function () use($app) {
    $app->redirect('wishlist');
});
$app->get('/wishlist(/:order)', function ($order = 'year') use($app) {
    $app->etag('wishlist');
    $albums = Database::getAlbums('wishlist', $order);
    $data = array('albums' => $albums, 'page' => 'wishlist', 'order' => $order);
    $app->render('index.html', $data);
});
$app->get('/coleccao(/:order)', function ($order = 'year') use($app) {
    $app->etag('coleccao');
    $albums = Database::getAlbums('collection', $order);
    $data = array('albums' => $albums, 'page' => 'coleccao', 'order' => $order);
    $app->render('index.html', $data);
});
$app->run();
<?php

require 'libs/php/Slim/Slim.php';
$app = new Slim(array('templates.path' => 'src/php/views'));
$app->get('/', function () use($app) {
    $app->render('main.php');
});
$app->get('/todos', function () use($app) {
    $data = array(array("label" => "Task 1", "order" => 1, "completed" => false), array("label" => "Task 3", "order" => 3, "completed" => true), array("label" => "Task 2", "order" => 2, "completed" => false));
    $response = $app->response();
    $response->header('Cache-Control', 'no-cache, must-revalidate');
    $response->header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
    $response->header('Content-type', 'application/json');
    echo json_encode($data);
});
$app->run();
Esempio n. 15
0
 * Step 2: Instantiate the Slim application
 *
 * Here we instantiate the Slim application with its default settings.
 * However, we could also pass a key-value array of settings.
 * Refer to the online documentation for available settings.
 */
$app = new Slim(array('view' => new TwigView()));
////////////////////////////////////////////////////////////////////////////////
//--Routes--////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/* purpose: main page show normal fizbuz and the structure / forms for the rest of the roots.
 * 
 */
$app->get('/', function () use($app) {
    $args = array('numbers' => getNumberArray(1, 100));
    $app->render('index.twig', $args);
});
$app->get('/:num', function ($pNumber) use($app) {
    $args = array('number' => new FizBuzNumber($pNumber));
    $app->render('single.twig', $args);
});
//->conditions(array('num'=> 'd+'));
$app->get('/list/(:start-):end', function ($start = 1, $end) use($app) {
    if ($start >= $end) {
        $app->flash("error start has to be greater than end");
        //--TODO--/ redirect to first page.
    }
    $args = array('start' => $start, 'end' => $end, 'numbers' => getNumberArray($start, $end));
    $app->render('list.twig', $args);
});
/**
Esempio n. 16
0
*/
//Register an "after" callback for PHP >=5.3
Slim::after(function () {
    Slim::response()->write('<p>After!</p>');
});
//Register an "after" callback for PHP <5.3
/*
Slim::after('example_after');
function example_after() {
	Slim::response()->write('After!');
}
*/
/*** ROUTES ***/
//Sample GET route for PHP >=5.3
Slim::get('/', function () {
    Slim::render('index.php');
});
//Sample GET route for PHP <5.3
/*
Slim::get('/', 'get_example');
function get_example() {
	Slim::render('index.php');
}
*/
//Sample POST route for PHP >=5.3
Slim::post('/post', function () {
    echo '<p>Here are the details about your POST request:</p>';
    print_r(Slim::request());
});
//Sample POST route for PHP <5.3
/*
Esempio n. 17
0
 * ==============================================*/
$app->map('/', function () use($app) {
    if ($app->request()->isPost() && sizeof($app->request()->post()) == 2) {
        // if valid login, set auth cookie and redirect
        $testp = sha1('uAX8+Tdv23/3YQ==');
        $post = (object) $app->request()->post();
        if (isset($post->username) && isset($post->password) && sha1($post->password) == $testp && $post->username == 'bppenne') {
            //$app->setEncryptedCookie('bppasscook', $post->password, 0);
            $app->setCookie('user_cook', $post->username, 0);
            $app->setCookie('pass_cook', $post->password, 0);
            $app->redirect('./review');
        } else {
            $app->redirect('.');
        }
    }
    $app->render('login.html');
})->via('GET', 'POST')->name('login');
$authUser = function ($role = 'member') use($app) {
    return function () use($role) {
        $app = Slim::getInstance();
        // Check for password in the cookie
        if ($app->getCookie('pass_cook') != 'uAX8+Tdv23/3YQ==' || $app->getCookie('user_cook') != 'bppenne') {
            //if ( $app->getEncryptedCookie('bppasscook', false) != 'uAX8+Tdv23/3YQ==') {
            $app->redirect('..');
            //$app->redirect('review');
        }
    };
};
$app->get('/review/', $authUser('review'), function () use($app) {
    $json_data = file_get_contents('./data/bp_review.json');
    $data = json_decode($json_data, true);
Esempio n. 18
0
<?php

// TODO:: ajax refresh middle list section after create/delete
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/', function () use($app) {
    $repo_list = get_repo_list();
    $vars = compact('repo_list');
    $app->render('index.tpl.php', $vars);
});
$app->post('/create', function () use($app) {
    $repo_name = $app->request()->post('repo_name');
    if (substr($repo_name, -4) != '.git') {
        $repo_name .= '.git';
    }
    $repo_list = get_repo_list();
    if (in_array($repo_name, $repo_list)) {
        die(json_encode(array('status' => 'fail', 'msg' => 'The repository name already exists!')));
    }
    `./gitinit {$repo_name}`;
    // TODO:: check if the repo is successfully created.
    die(json_encode(array('status' => 'ok', 'msg' => 'Repository successfully created!')));
});
$app->post('/delete', function () use($app) {
    $repo_name = $app->request()->post('repo_name');
    $repo_list = get_repo_list();
    if (!in_array($repo_name, $repo_list)) {
        die(json_encode(array('status' => 'fail', 'msg' => 'No such repository!')));
    }
    `rm -rf ../{$repo_name}`;
    die(json_encode(array('status' => 'ok', 'msg' => 'Repository successfully deleted!')));
Esempio n. 19
0
    if (!App::user()) {
        $app->redirect("/connect/");
    }
}
//## ROUTES ##//
$app->get('/', function () use($app) {
    $params = App::start();
    $params['title'] = "Home";
    $params['page'] = "home";
    if (!App::user()) {
        $params['button'] = "Connect";
    } else {
        $params['button'] = "Logout";
    }
    $params['errors'] = array();
    $app->render('static.tpl', $params);
});
$app->map('/connect/', function () use($app) {
    $params = App::start();
    $params['title'] = "Connect";
    $params['page'] = "connect";
    $params['errors'] = array();
    # This user already has an active session
    if (App::user()) {
        $user = App::getUser();
        $params['user_email'] = $user->email;
        $params['user_name'] = $user->first_name . ' ' . $user->last_name;
        $params['button'] = "Logout";
    } else {
        # This user is not yet authenticated
        #  (it is their first visit, or they were redirected here after logout)
Esempio n. 20
0
File: index.php Progetto: stojg/puny
 * This is a Slim middleware route that prevents non logged in visitors to
 * access that route
 */
$locked = function () use($app) {
    return function () use($app) {
        if (!puny\User::is_logged_in()) {
            $app->redirect($app->urlFor('login'));
        }
    };
};
/**
 * This is the index page
 */
$app->get('/', function () use($app) {
    $posts = puny\Blog::get_posts(5);
    $app->render('home.php', array('posts' => $posts));
})->name('index');
/**
 * Show a single post
 */
$app->get('/blog/:url', function ($url) use($app) {
    $blog = new puny\Blog('posts/');
    $post = $blog->getPost($url);
    if (!$post->exists()) {
        $app->notFound();
        return;
    }
    $app->render('single_post.php', array('post' => $post, 'title' => $post->getTitle()));
})->name('single_post');
/**
 * A list of all the posts that has been made
Esempio n. 21
0
<?php

require 'Slim/Slim.php';
require 'vendor/ActiveRecord.php';
// initialize ActiveRecord
// change the connection settings to whatever is appropriate for your mysql server
ActiveRecord\Config::initialize(function ($cfg) {
    $cfg->set_model_directory('models');
    $cfg->set_connections(array('development' => 'mysql://*****:*****@127.0.0.1/test'));
});
$app = new Slim();
$app->get('/', function () use($app) {
    $data['tasks'] = Task::find('all');
    $app->render('task/index.php', $data);
})->name('tasks');
$app->post('/task/new/', function () use($app) {
    $task = new Task();
    $task->name = "My New Task";
    $task->done = 0;
    $task->save();
    if ($task->id > 0) {
        $app->redirect($app->urlFor('tasks'));
    }
})->name('task_new');
$app->get('/task/:id/edit', function ($id) use($app) {
    $data['task'] = Task::find($id);
    $app->render('task/edit.php', $data);
})->name('task_edit');
$app->post('/task/:id/edit', function ($id) use($app) {
    $task = Task::find($id);
    $task->name = $app->request()->post('name');
Esempio n. 22
0
<?php

// require stuffs
require 'vendors/Slim/Slim/Slim.php';
require 'vendors/Slim-Extras/Views/MustacheView.php';
require 'vendors/couchsimple.php';
// set up the app
MustacheView::$mustacheDirectory = 'vendors';
$app = new Slim(array('view' => 'MustacheView'));
$env = $app->environment();
$app->view()->appendData(array('app_title' => 'Couchbase Beers', 'base_url' => $env['SCRIPT_NAME'], 'current_url' => $env['PATH_INFO']));
// Setup Couchbase connected objects
try {
    $cb = new Couchbase("127.0.0.1:9000", "Administrator", "asdasd", "beer-sample");
} catch (ErrorException $e) {
    die($e->getMessage());
}
$cbv = new CouchSimple(array('host' => '127.0.0.1', 'port' => 9500));
// openbeers application goodness
// GET route
$app->get('/', function () use($app) {
    $content = $app->view()->render('index.mustache');
    $app->render('layout.mustache', compact('content'));
});
// beer routes
require_once 'beers.php';
// brewery routes
require_once 'breweries.php';
// run, Slim, run
$app->run();
Esempio n. 23
0
include_once './libs/Slim/Slim.php';
require_once './classes/dbHelper.php';
$app = new Slim();
$db = new dbHelper();
$app->get('/getperguntas/:idpalestra', function ($idpalestra) use($app) {
    global $db;
    $stmt = $db->selectperguntas("perguntaspalestras", "id,pergunta,nomeusuario", " idpalestra = '{$idpalestra}'");
    echo json_encode($stmt);
});
$app->post('/avaliarpalestra', function () use($app) {
    global $db;
    $idpalestra = "palestra01";
    $nota = 3;
    $email = "*****@*****.**";
    $db->insert("avaliacao", array("idpalestra" => $idpalestra, "email" => $email, "nota" => $nota));
});
$app->post('/cadastrapergunta', function () use($app) {
    global $db;
    $postvalores = $app->request()->post();
    $idpalestra = $postvalores['idpalestra'];
    $pergunta = $postvalores['pergunta'];
    $nomeusuario = $postvalores['nomeusuario'];
    $db->insert("perguntaspalestras", array("idpalestra" => $idpalestra, "pergunta" => $pergunta, "nomeusuario" => $nomeusuario));
});
$app->get('/', function () use($app) {
    $app->render('home.php');
});
$app->get('/iframe', function () use($app) {
    $app->render('iframe.php');
});
$app->run();
Esempio n. 24
0
 /**
  * Test Slim rendering
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Render an existing template with custom data;
  *
  * Post-conditions:
  * The response body is correct;
  */
 public function testSlimRender()
 {
     $this->expectOutputString('test output bar');
     $app = new Slim(array('templates.path' => dirname(__FILE__) . '/templates'));
     $app->render('test.php', array('foo' => 'bar'));
 }
Esempio n. 25
0
// Some global template variables
Data::$data['title'] = $app->config('title');
Data::$data['logged_in'] = User::is_logged_in() ? true : false;
Data::$data['subtitle'] = $app->config('subtitle');
Data::$data['next_page'] = 0;
// Blog index
$app->get('/', function () use($app) {
    Data::$data['posts_all'] = R::find('post', '1 ORDER BY id DESC ');
    $count = count(Data::$data['posts_all']);
    if ($count) {
        Data::$data['posts'] = array(Data::$data['posts_all'][key(Data::$data['posts_all'])]);
    }
    if ($count > 1) {
        Data::$data['next_page'] = 1;
    }
    $app->render('index.php', Data::$data);
});
// Blog Admin Login
$app->get('/login', function () use($app) {
    $data['title'] = $app->config('title');
    $app->render('login.php', $data);
});
// Blog Admin Post
$app->post('/login', function () use($app) {
    $username = $app->request()->post('username');
    $password = $app->request()->post('password');
    if (authenticate($app, $username, $password)) {
        $_SESSION['logged_in'] = true;
        $app->redirect('/');
    }
    $app->redirect('/login');
Esempio n. 26
0
<?php

require 'Slim/Slim.php';
require 'config.inc';
require 'ideal.inc';
if (SECRETS_FILE) {
    require SECRETS_FILE;
}
$app = new Slim(array('templates.path' => './templates'));
$app->add(new Slim_Middleware_SessionCookie(array('expires' => '20 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'slim_session', 'secret' => 'CHANGE_ME', 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC)));
$app->get('/', function () use($app) {
    $app->render('_head.inc');
    $app->render('landing.php', array('default_amount' => DEFAULT_AMOUNT));
    $app->render('_footer.inc');
});
$app->post('/pirate', function () use($app) {
    $pirate = $app->request()->params();
    $pirate["status"] = "pending";
    // @TODO: append messages somehow. Now only first error is returned.
    if (!valid($app, 'initials', FALSE, '', 'Voorletters zijn vereist') || !valid($app, 'name', FALSE, '', 'Naam is vereist') || !valid($app, 'email', FALSE, '/.+@.+\\..+/', 'E-mailadres is niet correct') || !valid($app, 'address', FALSE, '', 'Adres is vereist') || !valid($app, 'city', FALSE, '', 'Stad is vereist')) {
        $app->redirect("/");
    }
    $pirate = write_pirate($pirate);
    write_mail($pirate);
    // @TODO: if pirate['id'] is not set, writing to database failed. Redirect to error in that case.
    //Prepare form for payment
    $ideal = new Ideal(MERCHANT_ID, SUB_ID, HASH_KEY, AQUIRER_NAME, AQUIRER_URL);
    $ideal->order_id = $pirate["id"];
    $ideal->amount = (double) DEFAULT_AMOUNT;
    $ideal->order_description = "Piratenpartij lidmaatschap";
    $base = $app->request()->getUrl();
Esempio n. 27
0
    return $posts;
};
// ----------------------------------------------------------
// ------------------------ ROUTES --------------------------
// home page
$blog->get('/', function () use($blog, $getMarkdownPosts) {
    // get our posts
    $posts = $getMarkdownPosts($blog->config('posts.path'));
    // limit our posts to pagination
    $posts_limit = array_slice($posts, 0, $blog->config('pagination'));
    // get the total number of posts
    $posts_count = count($posts);
    // calculate the number of page
    $pages_number = ceil($posts_count / $blog->config('pagination'));
    // render the main page
    $blog->render('index.html', array('posts' => $posts_limit, 'page_current' => 1, 'page_count' => $pages_number));
});
// about page
$blog->get('/about', function () use($blog) {
    // render the about page
    $blog->render('about.html');
});
// projects page
$blog->get('/projects', function () use($blog) {
    // render the blog page
    $blog->render('projects.html');
});
// redirect blog/page1 to root index
$blog->get('/blog/1', function () use($blog) {
    $blog->redirect('/');
});
Esempio n. 28
-1
 public function run()
 {
     $that = $this;
     $app = new \Slim(array('view' => 'rg\\broker\\web\\View', 'templates.path' => './src/rg/broker/web/templates'));
     $this->app = $app;
     $app->get('/', function () use($app, $that) {
         /** @var \Slim $app */
         /** @var Application $that  */
         $mdParser = new \dflydev\markdown\MarkdownParser();
         $content = $mdParser->transformMarkdown(file_get_contents(ROOT . '/README.md'));
         $app->render('home.php', array('repositories' => $that->getRepositories(), 'content' => $content));
     });
     $app->get('/repositories/:repositoryName/', function ($repositoryName) use($app, $that) {
         /** @var \Slim $app */
         /** @var Application $that  */
         $app->render('repository.php', array('repositories' => $that->getRepositories(), 'currentRepository' => $that->getRepository($repositoryName)));
     });
     $app->get('/repositories/:repositoryName/package/:packageName', function ($repositoryName, $packageName) use($app, $that) {
         /** @var \Slim $app */
         /** @var Application $that  */
         $packageName = urldecode($packageName);
         $app->render('package.php', array('repositories' => $that->getRepositories(), 'currentRepository' => $that->getRepository($repositoryName), 'package' => $that->getPackage($repositoryName, $packageName)));
     });
     $app->run();
 }
Esempio n. 29
-1
<?php

ob_start("ob_gzhandler");
header('Content-type: application/json');
require_once "../include_me.php";
require 'Slim/Slim.php';
$app = new Slim();
/**
 * Set Custom 404 page when an API method is not found
 */
$app->notFound(function () use($app) {
    $app->render("api404.html");
});
/**
 * Set Custom Error Page. No sensetive information should be displayed to the user
 */
$app->error(function () use($app) {
    // log error
    //$app -> render("apiError.html");
});
/**
 * REST Methods
 */
$app->get('/teacher/', function () use($teacherModel) {
    $result = $teacherModel->get();
    echo json_encode($result);
});
$app->get('/course/', function () use($courseModel) {
    $result = $courseModel->get();
    echo json_encode($result);
});
 /**
  * Renders output with given template
  *
  * @param string $template Name of the template to be rendererd
  * @param array  $args     Args for view
  */
 protected function render($template, $args = array())
 {
     if (!is_null($this->renderTemplateSuffix) && !preg_match('/\\.' . $this->renderTemplateSuffix . '$/', $template)) {
         $template .= '.' . $this->renderTemplateSuffix;
     }
     $this->app->render($template, $args);
 }