Пример #1
0
 public function after($controller, $metadata, &$data)
 {
     if ($metadata->map && $metadata->item && isset($data[$metadata->item])) {
         switch ($_SERVER['HTTP_ACCEPT']) {
             case 'application/xml':
             case 'text/xml':
                 content_type('application/xml');
                 echo Serializer::SerializeObject($data[$metadata->item], Serializer::FORMAT_XML, null, $metadata->map);
                 die;
                 break;
             case 'application/json':
             case 'text/json':
             case '*/*, application/json':
                 content_type('text/json');
                 $response = Serializer::SerializeObject($data[$metadata->item], Serializer::FORMAT_JSON, null, $metadata->map);
                 header("X-JSON:{$response}");
                 echo $response;
                 die;
                 break;
             case 'text/yaml':
                 content_type('text/yaml');
                 echo Serializer::SerializeObject($data[$metadata->item], Serializer::FORMAT_YAML, null, $metadata->map);
                 die;
                 break;
         }
     }
 }
Пример #2
0
function try_file($path)
{
    if (!file_exists($path)) {
        header("HTTP/1.0 404 Not Found");
        error_log("Pas trouvé : " . $path);
        return;
    }
    $info = pathinfo($path);
    $ext = @$info['extension'] ?: null;
    header('Content-Type: ' . content_type($ext));
    readfile($path);
}
Пример #3
0
    $logs = get_log($advertiser_id);
    foreach ($reports as $ad_id => $report) {
        $log = fetch($logs, $ad_id, []);
        $report['clicks'] = count($log);
        $breakdown = array('gender' => (object) [], 'agents' => (object) [], 'generations' => (object) []);
        foreach ($log as $click) {
            incr_hash($breakdown['gender'], $click['gender']);
            incr_hash($breakdown['agents'], $click['agent']);
            if (isset($click['age']) && !empty($click['age'])) {
                $generation = intval($click['age'] / 10);
            } else {
                $generation = 'unknown';
            }
            incr_hash($breakdown['generations'], $generation);
        }
        $report['breakdown'] = $breakdown;
        $reports[$ad_id] = $report;
    }
    return json((object) $reports);
});
dispatch_post('/initialize', function () {
    $redis = option('redis');
    $keys = $redis->keys('isu4:*');
    foreach ($keys as $key) {
        $redis->del($key);
    }
    array_map('unlink', glob(get_dir('log') . '/*'));
    content_type('text/plain');
    return 'OK';
});
run();
Пример #4
0
<?php

set_include_path(implode(PATH_SEPARATOR, array('../../lib/', get_include_path())));
require 'Verbier.php';
set('app_file', __FILE__);
set('root', __DIR__);
before(function () {
    content_type('text/html');
});
get('/', function () {
    return 'Hello World';
});
get('/:name', function ($self, $name) {
    return "Hello {$name}";
});
run();
Пример #5
0
 public static function download()
 {
     if (!($test = self::test())) {
         return false;
     }
     function content_type($filename)
     {
         $mime_types = array('txt' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', 'php' => 'text/html', 'css' => 'text/css', 'js' => 'application/javascript', 'json' => 'application/json', 'xml' => 'application/xml', 'swf' => 'application/x-shockwave-flash', 'flv' => 'video/x-flv', 'png' => 'image/png', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'bmp' => 'image/bmp', 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', 'zip' => 'application/zip', 'rar' => 'application/x-rar-compressed', 'exe' => 'application/x-msdownload', 'msi' => 'application/x-msdownload', 'cab' => 'application/vnd.ms-cab-compressed', 'mp3' => 'audio/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'pdf' => 'application/pdf', 'psd' => 'image/vnd.adobe.photoshop', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'doc' => 'application/msword', 'rtf' => 'application/rtf', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'odt' => 'application/vnd.oasis.opendocument.text', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet');
         $ext = pathinfo($filename);
         if (array_key_exists($ext['extension'], $mime_types)) {
             return $mime_types[$ext['extension']];
         } else {
             return 'application/octet-stream';
         }
     }
     if (is_file(self::$current)) {
         $name = basename(self::$current);
         $poids = filesize(self::$current);
         header('Content-Type:' . content_type($name));
         header('Content-Length:' . $poids);
         header('Content-disposition: attachment; filename=' . $name);
         $handle = fopen(self::$current, 'r');
         fpassthru($handle);
         exit;
     } else {
         return false;
     }
 }
Пример #6
0
 public function __construct()
 {
     content_type('text/javascript');
 }