Exemplo n.º 1
0
 function display_json($array)
 {
     $data = json_indent($array);
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     header('Content-type: application/json');
     echo $data;
 }
Exemplo n.º 2
0
 function dimensions($type)
 {
     $data = array();
     switch ($type) {
         case 'usa-states':
             $data = $this->GeoData->getUSACoords();
             $this->output->set_content_type('application/json')->set_output(json_indent($data));
             break;
     }
 }
Exemplo n.º 3
0
 function sample()
 {
     $data = array();
     for ($i = 0; $i < 12; $i++) {
         $x = rand(20, 550);
         $y = rand(30, 800);
         $value = rand(2, 100);
         $this->cluster->addNode($x, $y, $value);
     }
     $this->output->set_content_type('application/json')->set_output(json_indent($data));
 }
Exemplo n.º 4
0
/**
 * Smarty encode modifier plugin
 *
 * Type:     function<br>
 * Name:     jsonencode<br>
 * Purpose:  Encode a variable with the specified encoding format
 * @author   James Baicoianu
 * @param var
 * @return string
 */
function smarty_function_jsonencode($args, $smarty)
{
    $ret = "null";
    if (isset($args["var"])) {
        $ret = !empty($args["indent"]) ? json_indent(json_encode($args["var"]), $args["indent"]) : json_encode($args["var"]);
    }
    switch ($args["escape"]) {
        case 'html':
            $ret = htmlspecialchars($ret);
            break;
        case 'js':
            $ret = addslashes($ret);
    }
    return $ret;
}
        echo chr(255) . chr(254) . mb_convert_encoding(array2csv($logs['logs']), 'UTF-16LE', 'UTF-8');
        break;
    case 'XML':
        header('Content-type: application/xml', true);
        $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
        $xml .= '<pml>';
        $xml .= generate_xml_from_array($logs, 'log');
        $xml .= '</pml>';
        echo $xml;
        break;
    case 'JSONPR':
        header('Content-type: application/json', true);
        if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
            echo json_encode($logs, JSON_PRETTY_PRINT);
        } else {
            echo json_indent(json_encode($logs));
        }
        break;
    case 'JSONP':
        header('Content-type: application/javascript', true);
        echo isset($_GET['callback']) ? $_GET['callback'] : '?';
        echo '(';
        echo json_encode($logs);
        echo ')';
        break;
    case 'JSON':
    default:
        header('Content-type: application/json', true);
        echo json_encode($logs);
        break;
}
Exemplo n.º 6
0
 function Generate()
 {
     if (!empty($this->classes)) {
         $data = DataManager::singleton();
         foreach ($this->classes as $cls => $classcfg) {
             $primary = array();
             $keys = array();
             if (!empty($classcfg->keys)) {
                 foreach ($classcfg->keys as $k => $v) {
                     $columns = explode(",", $v);
                     foreach ($columns as $c) {
                         if ($k == "primary") {
                             $primary[] = trim($c);
                         } else {
                             $keys[trim($c)][] = $k;
                         }
                     }
                 }
             }
             $result = $data->Query("db." . $classcfg->table . ".schema:nocache", "show columns from " . $classcfg->table);
             foreach ($result->rows as $row) {
                 $rowargs = array();
                 if ($row->key == "PRI" || in_array($row->field, $primary)) {
                     $rowargs["pk"] = true;
                 }
                 if ($row->null == "NO") {
                     $rowargs["notnull"] = true;
                 }
                 if (preg_match("/^(.*?)\\(([\\d\\.,]+)\\)(?:\\s+(.*))?\$/", $row->type, $m)) {
                     $rowtype = $m[1];
                     $rowargs["length"] = $m[2];
                     if (!empty($m[3])) {
                         $rowargs[$m[3]] = true;
                     }
                 } else {
                     $rowtype = $row->type;
                 }
                 if (isset($row->default) && $row->default !== "") {
                     $rowargs["default"] = $row->default;
                 }
                 if (isset($keys[$row->field])) {
                     $rowargs["keys"] = implode(",", $keys[$row->field]);
                 }
                 $this->classes->{$cls}->props[$row->field] = array($row->field, $rowtype);
                 if (!empty($rowargs)) {
                     $this->classes->{$cls}->props[$row->field][] = $rowargs;
                 }
             }
         }
     }
     return json_indent(json_encode($this), 5);
     //return json_encode($this);
 }
Exemplo n.º 7
0
}
unset($_SESSION['reg_key']);
unset($_SESSION['reg_password']);
$_SESSION['reg_key'] = $reg_key;
$_SESSION['reg_password'] = $reg_password;
togglePre("Registration Request", htmlent_utf8($body));
$more_headers = array();
if ($lti_message_type == "ToolProxyReregistrationRequest") {
    $more_headers[] = 'VND-IMS-CONFIRM-URL: ' . $cur_base . 'tp_commit.php?correlation=49201-48842';
}
$response = sendOAuthBody("POST", $register_url, $reg_key, $reg_password, "application/vnd.ims.lti.v2.toolproxy+json", $body, $more_headers);
togglePre("Registration Request Headers", htmlent_utf8(get_body_sent_debug()));
global $LastOAuthBodyBaseString;
togglePre("Registration Request Base String", $LastOAuthBodyBaseString);
togglePre("Registration Response Headers", htmlent_utf8(get_body_received_debug()));
togglePre("Registration Response", htmlent_utf8(json_indent($response)));
$tc_half_shared_secret = false;
if ($last_http_response == 201 || $last_http_response == 200) {
    if ($oauth_splitsecret && $tp_half_shared_secret) {
        $responseObject = json_decode($response);
        if (isset($responseObject->tc_half_shared_secret)) {
            $tc_half_shared_secret = $responseObject->tc_half_shared_secret;
            echo "<p>tc_half_shared_secret: " . $tc_half_shared_secret . "</p>\n";
            if (strlen($tc_half_shared_secret) != 128) {
                echo '<p style="color: red">Warning secret length of ' . strlen($tc_half_shared_secret) . " should be 128</p>\n";
            }
            $split_secret = $tc_half_shared_secret . $tp_half_shared_secret;
            $_SESSION['split_secret'] = $split_secret;
            echo "<p>Split Secret: " . $split_secret . "</p>\n";
        } else {
            echo "<p>Error: Tool Consumer did not provide oauth_splitsecret</p>\n";
Exemplo n.º 8
0
 function getOutput($type)
 {
     $ret = array("text/html", NULL);
     $tplmgr = TemplateManager::singleton();
     switch ($type) {
         case 'ajax':
             $ret = array("application/xml", $tplmgr->GenerateXML($this->data));
             break;
         case 'json':
         case 'jsonp':
             $jsonp = any($_REQUEST["jsonp"], "elation.ajax.processResponse");
             //$ret = array("application/javascript", $jsonp . "(" . json_encode($this->data) . ");");
             $ret = array("application/javascript", $tplmgr->GenerateJavascript($this->data, $jsonp));
             break;
         case 'js':
             $ret = array("application/javascript", @json_encode($this) . "\n");
             break;
         case 'jsi':
             $ret = array("application/javascript", json_indent(@json_encode($this)) . "\n");
             break;
         case 'txt':
             $ret = array("text/plain", $tplmgr->GenerateHTML($tplmgr->GetTemplate($this->template, NULL, $this->data)));
             break;
         case 'xml':
             $ret = array("application/xml", object_to_xml($this, "response"));
             break;
         case 'data':
             $ret = array("", $this->data);
             break;
         case 'componentresponse':
             $ret = array("", $this);
             break;
         case 'popup':
             // Popup is same as HTML, but we only use the bare-minimum html.page frame
             $vars["content"] = $this;
             $ret = array("text/html", ComponentManager::fetch("html.page", $vars, "inline"));
             break;
         case 'snip':
         case 'inline':
         case 'commandline':
             $ret = array("text/html", $tplmgr->GetTemplate($this->template, NULL, $this->data));
             break;
         case 'html':
         case 'fhtml':
         default:
             $cfg = ConfigManager::singleton();
             $framecomponent = any(ConfigManager::get("page.frame"), array_get($cfg->servers, "page.frame"), "html.page");
             // If framecomponent is false/0, just return the raw content
             $ret = array("text/html", empty($framecomponent) ? $this->data["content"] : ComponentManager::fetch($framecomponent, array("content" => $this), "inline"));
             //$ret = array("text/html", $tplmgr->GetTemplate($this->template, NULL, $this->data));
             break;
     }
     if (!empty($this->prefix)) {
         $ret[1] = $this->prefix . $ret[1];
     }
     return $ret;
 }
Exemplo n.º 9
0
 public function procesos($proceso_id = null, $recurso = null)
 {
     $api_token = $this->input->get('token');
     $cuenta = Cuenta::cuentaSegunDominio();
     if (!$cuenta->api_token) {
         show_404();
     }
     if ($cuenta->api_token != $api_token) {
         show_error('No tiene permisos para acceder a este recurso.', 401);
     }
     if ($proceso_id) {
         $proceso = Doctrine::getTable('Proceso')->find($proceso_id);
         if (!$proceso) {
             show_404();
         }
         if ($proceso->Cuenta != $cuenta) {
             show_error('No tiene permisos para acceder a este recurso.', 401);
         }
         if ($recurso == 'tramites') {
             $offset = $this->input->get('pageToken') ? 1 * base64_decode(urldecode($this->input->get('pageToken'))) : null;
             $limit = $this->input->get('maxResults') && $this->input->get('maxResults') <= 20 ? 1 * $this->input->get('maxResults') : 10;
             $query = Doctrine_Query::create()->from('Tramite t, t.Proceso p')->where('p.id = ?', array($proceso->id))->orderBy('id desc');
             if ($offset) {
                 $query->andWhere('id < ?', $offset);
             }
             $ntramites_restantes = $query->count() - $limit;
             $query->limit($limit);
             $tramites = $query->execute();
             $nextPageToken = null;
             if ($ntramites_restantes > 0) {
                 $nextPageToken = urlencode(base64_encode($tramites[count($tramites) - 1]->id));
             }
             $respuesta = new stdClass();
             $respuesta->tramites->titulo = 'Listado de Trámites';
             $respuesta->tramites->tipo = '#tramitesFeed';
             $respuesta->tramites->nextPageToken = $nextPageToken;
             $respuesta->tramites->items = null;
             foreach ($tramites as $t) {
                 $respuesta->tramites->items[] = $t->toPublicArray();
             }
         } else {
             $respuesta = new stdClass();
             $respuesta->proceso = $proceso->toPublicArray();
         }
     } else {
         $procesos = Doctrine::getTable('Proceso')->findByCuentaId($cuenta->id);
         $respuesta = new stdClass();
         $respuesta->procesos->titulo = 'Listado de Procesos';
         $respuesta->procesos->tipo = '#procesosFeed';
         $respuesta->procesos->items = null;
         foreach ($procesos as $t) {
             $respuesta->procesos->items[] = $t->toPublicArray();
         }
     }
     header('Content-type: application/json');
     echo json_indent(json_encode($respuesta));
 }
Exemplo n.º 10
0
        foreach ($iface_refs as $iface_ref) {
            $iface_name = $iface_ref->getAttribute('client_id');
            $interfaces[] = $iface_name;
            if (array_key_exists($iface_name, $component_info_per_interface)) {
                $component_info = $component_info_per_interface[$iface_name];
                $am_name = $component_info['am_name'];
                $x = $component_info['x'];
                $y = $component_info['y'];
                $link_points[] = array($x, $y);
            }
        }
        $link_feature = array("geometry" => array("type" => "LineString", "coordinates" => $link_points), "type" => "Feature", "properties" => array("type" => "Link", "name" => $link_id, "interfaces" => $interfaces));
        //    error_log("C(LF) = " . count($link_points) . " " . print_r($link_feature, true));
        $link_features[] = $link_feature;
    }
}
// Above we need to keep a mapping of interfaces to coordinates
// Then we go through the links and get the interface refs, lookup
// the interfaces and corresponding coordinates
// and add a line segment (OpenLayers.Geometry.LineString) between these
// points
//
// Eventually, try to avoid drawing the same line twice(A -> B, B -> A)
//error_log("NODE_FEATURES = " . print_r($node_features, true));
//error_log("LINK_FEATURES = " . print_r($link_features, true));
$slice_info = array("type" => "FeatureCollection", "features" => array_merge($node_features, $link_features));
header("Cache-Control: public");
header("Content-Type: application/json");
$slice_info_json = json_encode($slice_info);
print json_indent($slice_info_json);
Exemplo n.º 11
0
#!/usr/bin/env php
<?php 
print json_indent(file_get_contents('php://stdin')) . PHP_EOL;
/**
 * pretty print JSON string
 * based on http://php.net/manual/en/function.json-encode.php#92539
 * by damon1977@gmail.com
 */
function json_indent($json)
{
    $json = json_encode(json_decode($json));
    //remove formatting hack
    $tabcount = 0;
    $result = '';
    $inquote = false;
    $ignorenext = false;
    $tab = "  ";
    for ($i = 0; $i < strlen($json); $i++) {
        $char = $json[$i];
        if ($ignorenext) {
            $result .= $char;
            $ignorenext = false;
        } else {
            switch ($char) {
                case '{':
                case '[':
                    $tabcount++;
                    $result .= $char . PHP_EOL . str_repeat($tab, $tabcount);
                    break;
                case '}':
                case ']':
Exemplo n.º 12
0
    }
} else {
    $msg = $retVal;
}
$success = $obj[0];
$fail = $obj[1];
if (count($success)) {
    if (count($am_urls) == 1) {
        log_event($log_url, $user, "Renewed resources from slice " . $slice_name . " at " . $AM_name, $log_attributes);
    } else {
        log_event($log_url, $user, "Renewed resources from slice " . $slice_name, $log_attributes);
    }
}
//if terminated obj[1] is failed nodes; so on terminated want to append the AM to $obj[1]
//error_log("RenewSliver msg = " . $msg . " obj " . print_r($obj, true));
if (preg_match("/" . AM_CLIENT_TIMED_OUT_MSG . "/", $msg) == 1) {
    $rrht = $obj[1];
    $rrht[] = am_name($am_url);
    $obj[1] = $rrht;
}
// Set headers for download
header("Cache-Control: public");
header("Content-Type: application/json");
/* json_encode accepts JSON_PRETTY_PRINT in PHP 5.4, but
 * we've got 5.3. Use a third-party utility instead.
 */
if ($obj != "") {
    print json_indent(json_encode($obj));
} else {
    print json_indent($msg);
}
Exemplo n.º 13
0
        $slice_name = "";
    }
    $_SESSION['lasterror'] = "Slice " . $slice_name . " is expired.";
    relative_redirect('dashboard.php#slices');
}
if (!$user->isAllowed(SA_ACTION::LOOKUP_SLICE, CS_CONTEXT_TYPE::SLICE, $slice_id)) {
    relative_redirect('home.php');
}
if (!isset($ams) or is_null($ams)) {
    $ams = array();
}
// Look up the sliverstatus...
$statRet = query_sliverstatus($user, $ams, $sa_url, $slice, $slice_id);
$msg = $statRet[0];
$obj = $statRet[1];
if (!$obj) {
    relative_redirect("slice.php?slice_id={$slice_id}");
}
/* Construct a filename like "raw-sliverstatus.json" */
//$filename = "geni-" . str_replace(' ', '', $user->prettyName()) . ".pem";
$filename = "raw-sliverstatus.json";
// Set headers for download
header("Cache-Control: public");
//header("Content-Description: File Transfer");
//header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/json");
/* json_encode accepts JSON_PRETTY_PRINT in PHP 5.4, but
 * we've got 5.3. Use a third-party utility instead.
 */
print json_indent(json_encode($obj)) . "\n";
Exemplo n.º 14
0
/**
 * Equivalent of serilize function but output pretty printed 
 * json format to make it possible to edit the output manually.
 * 
 * @param array $data
 * 
 * @return string
 */
function serialize_json($data)
{
    $data = json_encode($data);
    return json_indent($data);
}