示例#1
0
 public static function respond($TemplatePath, $responseData = array(), $responseMode = false)
 {
     if (!headers_sent()) {
         header('X-TemplatePath: ' . $TemplatePath);
         header('Content-Type: text/html; charset=utf-8');
     }
     switch ($responseMode ? $responseMode : static::$responseMode) {
         case 'json':
             JSON::translateAndRespond($responseData);
         case 'jsonp':
             JSONP::translateAndRespond($responseData);
         case 'text':
             header('Content-Type: text/plain');
         case 'html':
             if (!file_exists($TemplatePath)) {
                 throw new \Exception($TemplatePath . ' not found.');
             }
             if (!is_readable($TemplatePath)) {
                 throw new \Exception($TemplatePath . ' is not readable.');
             }
             include $TemplatePath;
         case 'dwoo':
             $dwoo = new \Divergence\Templates\Engines\Dwoo();
             $data = array('responseID' => $responseID, 'data' => $responseData);
             if (is_array(static::$injectableData)) {
                 $data = array_merge($data, static::$injectableData);
             }
             if (function_exists('fastcgi_finish_request')) {
                 while (@ob_end_flush()) {
                 }
             }
             $dwoo->setTemplateDir(App::$ApplicationPath . '/views/');
             echo $dwoo->get($TemplatePath, $data);
             if (function_exists('fastcgi_finish_request')) {
                 fastcgi_finish_request();
             }
             exit;
         case 'return':
             return array('TemplatePath' => ${$TemplatePath}, 'data' => $data);
         default:
             die('Invalid response mode');
     }
 }
示例#2
0
}
function validateHexColor($hex)
{
    $hex = substr($hex, 0, 1) == '#' ? $hex : '#' . $hex;
    if (preg_match('/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $hex)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
session_start();
if (isset($_GET['expected'])) {
    if ($_GET['expected'] == $_SESSION['expected']) {
        JSONP::output(TRUE);
    } else {
        JSONP::output(FALSE);
    }
} else {
    // Background color
    if (isset($_GET['bg']) && validateHexColor($_GET['bg'])) {
        $bgc = hex2rgb($_GET['bg']);
    } else {
        $bgc = hex2rgb('#fff');
    }
    // Foreground color
    if (isset($_GET['fg']) && validateHexColor($_GET['fg'])) {
        $fgc = hex2rgb($_GET['fg']);
    } else {
        $fgc = hex2rgb('#000');
    }
    // Font