/**
  * Test Expires
  */
 public function testExpiresAsInteger()
 {
     \Slim\Environment::mock(array('SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar'));
     $fiveDaysFromNow = time() + 60 * 60 * 24 * 5;
     $expectedDate = gmdate('D, d M Y H:i:s T', $fiveDaysFromNow);
     $s = new \Slim\Slim();
     $s->get('/bar', function () use($s, $fiveDaysFromNow) {
         $s->expires($fiveDaysFromNow);
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertTrue(isset($header['Expires']));
     $this->assertEquals($header['Expires'], $expectedDate);
 }
Exemple #2
0
}
$config = array();
include_once "config/config.php";
$app = new \Slim\Slim();
$app->config('debug', $config['debug']);
$db = new RedMap\Drivers\MySQLiDriver('UTF8');
$db->connect($config['db_user'], $config['db_password'], $config['db_name']);
$users = new Users($db);
$bidders = new Bidders($db, $users);
$publishers = new Publishers($db, $users);
$stats = new Stats($db);
$gitkitClient = Gitkit_Client::createFromFile('config/gitkit-server-config.json');
$app->get('/bidders/', function () use($app, $bidders) {
    $uiFormat = $app->request()->get('format') === 'ui';
    if (!$uiFormat) {
        $app->expires('+3 hour');
    }
    displayResultJson($app, $bidders->getAll($app, $uiFormat));
});
$app->get('/bidders/:id', function ($id) use($app, $bidders) {
    $uiFormat = $app->request()->get('format') === 'ui';
    if (!$uiFormat) {
        $app->expires('+3 hour');
    }
    displayResultJson($app, $bidders->get($app, $id, $uiFormat));
});
$app->delete('/bidders/:id', function ($id) use($app, $bidders, $users, $gitkitClient) {
    $userId = validateUserForBidder($app, $users, $gitkitClient, $id);
    $bidders->delete($app, $userId, $id);
});
$app->put('/bidders/:id', function ($id) use($app, $bidders, $users, $gitkitClient) {
Exemple #3
0
    $response = $session->getUser()->getTestResult();
    Helpers::sendJson($response);
});
$app->delete('/result', function () use($session) {
    if (!checkAuth()) {
        return;
    }
    $status = $session->getUser()->resetTestResult();
    Helpers::sendJson(array('status' => $status));
});
$app->get('/groups', function () use($app) {
    if (!checkAdminAuth()) {
        return;
    }
    $app->etag('groups');
    $app->expires('+15 minutes');
    Helpers::sendJson(AdminHelpers::getGroups());
});
$app->get('/admin/results', function () use($app) {
    if (!checkAdminAuth()) {
        return;
    }
    $filters = $app->request()->get();
    $response = AdminHelpers::getResults($filters);
    Helpers::sendJson($response);
});
$app->get('/admin/result/:studentId', function ($studentId) {
    if (!checkAdminAuth()) {
        return;
    }
    $response = User::findByStudentId($studentId)->getTestResult();
<?php

require '../Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->contentType('application/json');
$app->expires('-1000000');
$db = new PDO('sqlite:db.sqlite3');
function getTitleFromUrl($url)
{
    preg_match('/<title>(.+)<\\/title>/', file_get_contents($url), $matches);
    return mb_convert_encoding($matches[1], 'UTF-8', 'UTF-8');
}
function getFaviconFromUrl($url)
{
    $url = parse_url($url);
    $url = urlencode(sprintf('%s://%s', isset($url['scheme']) ? $url['scheme'] : 'http', isset($url['host']) ? $url['host'] : strtolower($url['path'])));
    return "http://g.etfv.co/{$url}";
}
function saveFavicon($url, $id)
{
    file_put_contents("../icons/{$id}.ico", file_get_contents(getFaviconFromUrl($url)));
}
function returnResult($action, $success = true, $id = 0)
{
    echo json_encode(['action' => $action, 'success' => $success, 'id' => intval($id)]);
}
$app->get('/bookmark', function () use($db, $app) {
    $sth = $db->query('SELECT * FROM bookmark;');
    echo json_encode($sth->fetchAll(PDO::FETCH_CLASS));
});
Exemple #5
0
    $app->get('', 'getSettings');
    $app->get('/:value', 'getSetting');
});
require "routes/users.php";
$app->group('/users', function () use($app) {
    $app->get('', 'getUsers');
    $app->get('/search/:query', 'getUserSearch');
    $app->post('/login', 'login');
    $app->get('/logout', 'logout');
    $app->get('/isLoggedIn', 'isLoggedIn');
    $app->post('/register', 'register');
});
require "routes/updates.php";
$app->group('/updates', function () use($app) {
    $app->get('', 'getUserUpdates');
    $app->post('', 'insertUpdate');
    $app->delete('/:update_id', 'deleteUpdate');
});
/* Slim Framework settings */
$app->contentType('application/json');
//make sure browsers don't cache the json content
$app->expires('-1 hour');
$app->notFound(function () {
    echo '{"error":{"message":"404 Page Not Found"}}';
});
$app->run();
function getBody()
{
    global $body;
    return $body;
}
Exemple #6
0
<?php

require '../vendor/autoload.php';
require '../app/config.php';
$app = new \Slim\Slim(array('log.level' => 4, 'log.enabled' => true, 'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(array('path' => '../var/logs', 'name_format' => 'y-m-d'))));
$app->contentType('application/json; charset=utf-8');
$app->expires('+1 month');
foreach ($active_services as $service) {
    include_once '../app/srv_' . $service . '.php';
}
$app->notFound(function () use($app, $service_doc) {
    $req = $app->request();
    if ($req->isGet()) {
        echo json_encode(array('description' => array('en' => "REST services to query for Peru's UBIGEO (geographical location code)", 'es' => "Servicios REST para buscar los códigos de UBIGEO Peruanos"), 'services' => $service_doc));
    } else {
        $app->halt(405);
    }
});
try {
    $app->run();
} catch (Slim_Exception_Stop $e) {
    // do nothing
}