Beispiel #1
0
function response_json($value)
{
    $response = raw_json_encode($value);
    debug_log("Response: " . $response);
    header('Content-Type: application/json');
    // 古いIEがおかしいMIMEタイプ判定をしてXSSの原因になる問題を避けるための呪符
    header('X-Content-Type-Options: nosniff');
    echo $response;
}
Beispiel #2
0
 public function getJson($id = '1')
 {
     $searchPhrase = isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase']) ? $_POST['searchPhrase'] : '';
     //get query parameters
     $sort = isset($_POST['sort']) && !empty($_POST['sort']) ? $_POST['sort'] : array();
     $rowCount = isset($_POST['rowCount']) && !empty($_POST['rowCount']) ? $_POST['rowCount'] : 0;
     $current = isset($_POST['current']) && !empty($_POST['current']) ? $_POST['current'] - 1 : 0;
     //order by clause
     $orderClause = '';
     $i = 0;
     if (count($sort) > 0) {
         foreach ($sort as $field => $order) {
             $orderClause .= ($i++ > 0 ? ',' : '') . $field . ' ' . $order;
         }
     }
     //filter condition
     $conditions = '';
     if (!empty($searchPhrase)) {
         $conditions .= $this->getSearchField() . ' LIKE "%' . addslashes($searchPhrase) . '%"';
     }
     $parameters = array('select' => empty($this->fields) ? '*' : join($this->fields, ','), 'conditions' => array($this->getPK() . ' >= ?' . (empty($conditions) ? '' : ' and (' . $conditions . ')'), $id), 'order' => $orderClause);
     $allRecords = $this::all($parameters);
     if ($rowCount > 0) {
         $parameters['limit'] = $rowCount;
         $parameters['offset'] = $current * $rowCount;
     }
     $records = $this::all($parameters);
     $totalRows = count($allRecords);
     $rows = array();
     foreach ($records as $s) {
         array_push($rows, $s->attributes());
     }
     return '{
                 "current": ' . ($current + 1) . ',
                 "rowCount": ' . $rowCount . ',
             "rows":' . raw_json_encode($rows) . ',
                 "total": ' . $totalRows . '
             }';
 }
 public function get_summary($content, $status)
 {
     $sentences_dic = $this->get_sentences_ranks($content, $status);
     $paragraphs = $this->split_content_to_paragraphs($content);
     $c = count($paragraphs);
     //	if($status==true)
     //		$rawData['paragraphs']=$paragraphs;
     $this->original = $content;
     $summary = array();
     $z = 0;
     foreach ($paragraphs as $p) {
         //	for($i=0; $i<$c; $i++){
         //print_r($p."<br><br>");
         $sentence = $this->get_best_sentence($p);
         if (!empty($sentence)) {
             $summary[$z++] = $sentence;
         }
     }
     //	}
     $this->summary = implode("\$\$\$", $summary);
     $this->summary = preg_replace("/\\.+/", ".", $this->summary);
     $this->summary = explode("\$\$\$", $this->summary);
     if ($status == true) {
         $rawData['total_sentences'] = $this->n;
         $intersection = $this->values;
         $rawData['intersection'] = array();
         for ($i = 0; $i < count($intersection); $i++) {
             $midintersection = array();
             for ($j = 0; $j < count($intersection[$i]); $j++) {
                 $midintersection[" " . $j . " "] = $intersection[$i][$j];
             }
             $rawData["intersection"][" " . $i . " "] = $midintersection;
         }
         $rawData['sentences_dic'] = $sentences_dic;
         $rawData['summary'] = array();
         for ($i = 0; $i < count($this->summary); $i++) {
             $tempinfo = array();
             $paraToSentWithScore = array();
             $tempParaSent = $this->split_content_to_sentences($paragraphs[$i]);
             $tempinfo["para"] = array();
             for ($j = 0; $j < count($tempParaSent); $j++) {
                 $sent = $tempParaSent[$j];
                 $score = $sentences_dic[$this->format_sentence($sent)];
                 $tempinfo["para"][$j] = array($sent, $score);
             }
             $tempinfo["pickedLine"] = $this->summary[$i];
             array_push($rawData['summary'], $tempinfo);
         }
         echo raw_json_encode($rawData);
     }
     return $this->summary;
 }
$st = new Summarizer();
$sums = $st->get_summary($para, false);
$response["eng"]["summarized__smart"] = $sums;
$response["hin"]["summarized__smart"] = TranslateArray($sums);
if (isset($_GET["lcount"])) {
    $lcount = $_GET["lcount"];
    $lines = explode(',', $lcount);
    for ($i = 0; $i < count($lines); $i++) {
        if ($i > 2) {
            $response["exception"] = "Max line count exceeded";
            break;
        }
        $para = break_string($finalhtml, $lines[$i]);
        $st = new Summarizer();
        $sums = $st->get_summary($para, false);
        $response["eng"]["summarized__" . $lines[$i] . "_lines"] = $sums;
        $response["hin"]["summarized__" . $lines[$i] . "_lines"] = TranslateArray($sums);
    }
}
$response["vid"] = $urlYoutube;
$response["meta"]["originalLength"] = strlen($finalhtml);
$response["meta"]["summaryLength"] = strlen(implode("", $sums));
$response["meta"]["summaryRatio"] = 100 - 100 * $response["meta"]["summaryLength"] / $response["meta"]["originalLength"];
$response["meta"]["source_text"] = "wikihow";
$response["meta"]["source_video"] = "youtube";
$response["meta"]["queryTime"] = microtime(true) - $start;
$response["meta"]["graphRef"] = "http://nikunj.freakengineers.com/agro-api/showdata.php?total=" . ($response["meta"]["originalLength"] - $response["meta"]["summaryLength"]) . "&summr=" . $response["meta"]["summaryLength"] . "&st=" . rand(8000, 9000) / 1000 . "&myst=" . $response["meta"]["queryTime"] . "&nost=" . rand(1000, 2000) / 1000;
$response["meta"]["rawRef"] = "http://nikunj.freakengineers.com/agro-api/showraw.php?query=" . urlencode($query);
$response["meta"]["devRef"] = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
echo raw_json_encode($response);
Beispiel #5
0
<?php

header('Content-type: text/json; charset=UTF-8');
require_once "../include/global.include.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $returnArr = array('code' => 200, 'data' => array());
    if (!check_session()) {
        responseJSON('session expired', 440);
    }
    extract($_POST);
    if (!isset($media_id)) {
        responseJSON('invalid request');
    }
    try {
        $result = $wechat->dropMedia($media_id);
        if ($result['hasError']) {
            responseJSON($result['err']);
        }
        $bindArr = array($media_id);
        $query = "UPDATE media_news SET deleted = 1 WHERE media_id = ?";
        if (!$mysql->execute($query, $bindArr)) {
            throw new Exception($mysql->error);
        }
    } catch (Exception $ex) {
        # log the exception
        log_error('media_news: drop', raw_json_encode($media_id), $ex->getMessage());
        $returnArr = array('hasError' => true, 'err' => $ex->getMessage());
    }
    responseJSON($returnArr);
}
$id_experiencia = $_REQUEST['codexp'];
$conexion = dbConectarMySQL($config_host_bd, $config_usuario_bd, $config_password_bd, $config_bd);
$array_experiencias_gemelas = dbObtenerArrayExperienciasGemelas($id_experiencia, $conexion);
$nro_exp_gemelas = count($array_experiencias_gemelas);
$array_id_experiencias_gemelas = array();
for ($i = 0; $i < $nro_exp_gemelas; $i++) {
    array_push($array_id_experiencias_gemelas, $array_experiencias_gemelas[$i]['ed_id_experiencia']);
}
$array_mensajes_experiencias_gemelas = dbObtenerMensajesBitacoraExperiencias($array_id_experiencias_gemelas, $conexion);
$string_mensajes_experiencias_gemelas = implode(' ', $array_mensajes_experiencias_gemelas);
$ruta_archivo = "historial_mensajes_exp" . $id_experiencia . ".txt";
$archivo_mensajes = fopen($ruta_archivo, "w+") or die($lang_obtiene_frec_palabras_error);
fwrite($archivo_mensajes, $string_mensajes_experiencias_gemelas);
fclose($archivo_mensajes);
$resultado = exec("python " . $config_ruta_servidor . "dataviz/wordcloud/obtiene_frecuencia_palabras.py " . $ruta_archivo, $output);
$array_frecuencia_palabras = array();
for ($i = 0; $i < sizeof($output); $i++) {
    $palabra_frecuencia = $output[$i];
    //echo $palabra_frecuencia.'</br>';
    $array_palabra_frecuencia = explode(",", $palabra_frecuencia);
    $array_palabra_frecuencia = array_map(utf8_encode, $array_palabra_frecuencia);
    $palabra = $array_palabra_frecuencia[0];
    $frecuencia = $array_palabra_frecuencia[1];
    $objeto_json = new FrecuenciaPalabras();
    $objeto_json->text = $palabra;
    $objeto_json->size = $frecuencia;
    array_push($array_frecuencia_palabras, $objeto_json);
}
$json_data = array("frecuencia_palabras" => $array_frecuencia_palabras);
echo raw_json_encode($json_data);
 public function to_s()
 {
     return raw_json_encode(self::$include_root ? array(strtolower(get_class($this->model)) => $this->to_a()) : $this->to_a());
 }
<?php

header('Content-Type: text/html; charset=utf-8');
require_once 'config.php';
function raw_json_encode($input)
{
    return preg_replace_callback('/\\\\u([0-9a-zA-Z]{4})/', function ($matches) {
        return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
    }, json_encode($input));
}
$query = "SELECT road_name FROM tbl_roads";
$result = mysqli_query($con, $query);
if (!$result) {
    die('Error : ' . mysql_error());
} else {
    $id = array();
    while ($row = mysqli_fetch_assoc($result)) {
        if (!empty($row['road_name'])) {
            array_push($id, $row['road_name']);
        }
    }
    $roads = array();
    foreach (array_unique($id) as $road) {
        array_push($roads, $road);
    }
    echo raw_json_encode($roads, JSON_UNESCAPED_UNICODE);
}