示例#1
0
 public function GetReviewsArticlesMain()
 {
     $file = "reviews/open";
     $json = read_json($file);
     if ($json) {
         if (time() - $json->time < 60 * 5) {
             return $json->articles;
         }
     }
     $articles = $this->GetReviewsArticlesMainFn();
     $data = array('time' => time(), 'articles' => $articles);
     write_json($file, $data);
     return $articles;
 }
示例#2
0
function main($query, $type, $reversed, $key)
{
    $line = get_bus_line($key);
    if (count($line) == 0) {
        write_error($GLOBALS['ERR_NOT_BUS']);
    } else {
        if ($type == 'text') {
            write_text($query, $reversed, $line);
        } elseif ($type == 'json') {
            write_json($query, $reversed, $line);
        } else {
            write_error($GLOBALS['ERR_PARAMS_TYPE']);
        }
    }
}
示例#3
0
 public function getTagArticles($tag = 0)
 {
     $file = "tags/tag-{$tag}";
     $json = read_json($file);
     if ($json) {
         if (time() - $json->time < 60 * 5) {
             return $json->articles;
         }
     }
     /*AND C.id_categoria_raiz IN (1,2,3,4,5,6,67,120)*/
     $sql = "SELECT C.id, C.titulo_home as title, C.copete_home as subtitle, C.fecha as date, C.hora as hour,\n    C.id_categoria_raiz as category, advf.advLink AS picture\n    FROM contenidos C\n    INNER JOIN contenidos_tags CT ON C.id = CT.id_contenido\n    LEFT JOIN advf ON advf.advID = C.fotohome\n    WHERE C.id \n    AND CT.id_tag = '{$tag}' AND C.estado = 'A' AND C.activo = 'S'\n    ORDER BY C.fecha DESC, C.hora DESC, C.id DESC\n    LIMIT 0, 9";
     $result = $this->db->query($sql)->result();
     $articles = array();
     foreach ($result as $article) {
         $articles[] = $this->Data->DataArticlePrep($article);
     }
     $data = array('time' => time(), 'articles' => $articles);
     write_json($file, $data);
     return $articles;
 }
示例#4
0
 public function GetSectionArticlesMainSubportal($section = 0)
 {
     $file = "section/open-{$section}";
     $json = read_json($file);
     if ($json) {
         if (time() - $json->time < 60 * 5) {
             return $json->articles;
         }
     }
     $articles = array();
     $articlesSub = $this->GetSectionArticlesSubportal($section);
     foreach ($articlesSub as $article) {
         if (count($articles) >= 4) {
             break;
         }
         $article = $this->Data->DataArticleBasic($article->id);
         if ($article && $article->active) {
             $articles[] = $article->id;
         }
     }
     $data = array('time' => time(), 'articles' => $articles);
     write_json($file, $data);
     return $articles;
 }
示例#5
0
        return null;
    }
    return $basepath . "/" . $path . ".json";
}
/*
 * load_json(path)
 *
 * Loads a file and returns it
 *
 */
function load_json($path)
{
    global $content_base_path;
    $clean_path = cleanup_path($content_base_path, $path);
    echo file_get_contents($clean_path);
}
/*
 * AJAX content provider
 *
 */
switch ($_GET["hycms_cmd"]) {
    case "get_content":
        load_json($_GET["hycms_path"]);
        break;
    case "set_content":
        write_json($_GET["hycms_path"], $_POST["hycms_data"]);
        break;
}
?>

$data = substr($x, $pos, $pos2 - $pos);
$list = [];
$rows = explode("\n", $data);
for ($i = 0; $i < count($rows); $i++) {
    if (!$rows[$i] || $rows[$i] == '|-' || $rows[$i] == '|') {
        continue;
    }
    $country = cleanText($rows[$i++]);
    $country = mapCountry($country);
    $codes = extractLinks($rows[$i++]);
    $timezone = $rows[$i++];
    foreach ($codes as $c) {
        $code = getRightSideOfMediawikiTag($c);
        $code = str_replace(' ', '', $code);
        $code = str_replace('+', '', $code);
        $codes2 = explode(',', $code);
        foreach ($codes2 as $code2) {
            if (!is_numeric($code2)) {
                echo "Skipping " . $code2 . "\n";
                continue;
            }
            $o = new \MartinLindhe\Data\CallingCodes\CallingCode();
            $o->country = $country;
            $o->code = $code2;
            $list[] = $o;
        }
    }
}
write_csv(__DIR__ . '/../data/calling_codes.csv', $list);
write_json(__DIR__ . '/../data/calling_codes.json', $list);
示例#7
0
 public function balotaje_2015_finish()
 {
     header('Content-Type: application/json');
     $this->load->library('Session');
     $session = round($this->session->userdata('balotaje_2015'));
     if ($session >= 200) {
         echo json_encode(array('result' => true, 'description' => 'limit'));
         return;
     } else {
         if (!is_numeric($this->input->post('v1')) && !is_numeric($this->input->post('v2')) && !is_numeric($this->input->post('p1')) && !is_numeric($this->input->post('p2'))) {
             echo json_encode(array('result' => true, 'description' => 'data'));
             return;
         } else {
             if ($this->input->post('p1') + $this->input->post('p2') > 100) {
                 echo json_encode(array('result' => true, 'description' => 'total'));
                 return;
             }
         }
     }
     $session++;
     $this->session->set_userdata('balotaje_2015', $session);
     $json = array();
     $json['v1'] = $this->input->post('v1');
     $json['v2'] = $this->input->post('v2');
     $json['p1'] = $this->input->post('p1');
     $json['p2'] = $this->input->post('p2');
     $this->load->helper('string');
     $file = random_string('alnum', 16);
     write_json('widgets/balotaje-2015/' . $file, json_encode($json));
     $folder = APPPATH . 'layout/widgets/balotaje-2015/';
     $canvas = imagecreatetruecolor(699, 367);
     $base = imagecreatefrompng($folder . 'img/bg-share.png');
     imagecopy($canvas, $base, 0, 0, 0, 0, 700, 368);
     $color = imagecolorallocate($canvas, 255, 255, 255);
     $font_regular = APPPATH . 'layout/fonts/raleway-regular-webfont.ttf';
     $font_bold = APPPATH . 'layout/fonts/raleway-bold-webfont.ttf';
     // $pos1 = array(0, 165, 330, 490);
     // $pos2 = array(0, 265, 330, 490);
     $candidato1 = imagecreatefrompng($folder . 'img/scioli.png');
     $candidato2 = imagecreatefrompng($folder . 'img/macri.png');
     imagettftext($canvas, 16, 0, 330, 75, $color, $font_regular, 'Daniel Scioli');
     imagettftext($canvas, 50, 0, 323, 135, $color, $font_bold, $json['p1'] . '%');
     imagecopy($canvas, $candidato1, 310, 145, 0, 0, 163, 154);
     imagettftext($canvas, 12, 0, 340, 315, $color, $font_regular, number_format($json['v1'], 0, '.', '.') . ' votos');
     imagettftext($canvas, 16, 0, 527, 75, $color, $font_regular, 'Mauricio Macri');
     imagettftext($canvas, 50, 0, 523, 135, $color, $font_bold, $json['p2'] . '%');
     imagecopy($canvas, $candidato2, 510, 145, 0, 0, 163, 154);
     imagettftext($canvas, 12, 0, 540, 315, $color, $font_regular, number_format($json['v2'], 0, '.', '.') . ' votos');
     imagepng($canvas, $folder . 'placas/' . $file . '.png');
     $retfile = layout() . 'widgets/balotaje-2015/placas/' . $file . '.png';
     echo json_encode(array('result' => true, 'url' => $retfile, 'file' => $file));
 }
示例#8
0
function write_worksheet($in, $file, $options = array())
{
    $ext = pathinfo($file, PATHINFO_EXTENSION);
    if (isset($options["write"])) {
        if ($ext != "" && $options["write"] != $ext) {
            fputs(STDERR, "Warning: Ignored the extension to adopt {$options["write"]}.\n");
        }
        $ext = $options["write"];
    }
    switch (strtolower($ext)) {
        case "raw":
            $out = fopen($file, "w");
            while (($line = fgets($in)) !== false) {
                fputs($out, $line);
            }
            fclose($out);
            break;
        case "csv":
            $options["delimiter"] = ",";
            write_csv($in, $file, $options);
            break;
        case "tsv":
            $options["delimiter"] = "\t";
            write_csv($in, $file, $options);
            break;
        case "xlsx":
            write_excel($in, $file, $options);
            break;
        case "json":
            write_json($in, $file, $options);
            break;
        case "yml":
        case "yaml":
            write_yaml($in, $file, $options);
            break;
        case "xml":
            write_xml($in, $file, $options);
            break;
        case "htm":
        case "html":
            // a write only converter
            write_html($in, $file, $options);
            break;
        case "tex":
            // a write only converter
            write_tex($in, $file, $options);
            break;
        case "sql":
            // a write only converter
            write_sql($in, $file, $options);
            break;
        default:
            fputs(STDERR, "Error[{$ext}]: No writer is available.\n");
            break;
    }
    return;
}
    $o->name = trim($name);
    // HACK
    $cols[4] = str_replace('[[Caribbean Netherlands]] (BQ - Bonaire, Sint Eustatius and Saba)', 'Caribbean Netherlands', $cols[4]);
    $countries = [];
    foreach (explode(', ', $cols[4]) as $c) {
        $c = \MartinLindhe\MediawikiClient\Client::stripMediawikiLinks($c);
        $c = trim(getRightSideOfMediawikiTag($c));
        if (!$c) {
            continue;
        }
        $code = countryCodeFromName($c, $allCountries);
        if (!$code) {
            err("WARNING: didn't find country code to " . $c);
        } else {
            $countries[] = $code;
        }
    }
    $o->countries = $countries;
    $list[] = $o;
}
if (!isAlpha3InList('BTC', $list)) {
    $o = new MartinLindhe\Data\Currencies\Currency();
    $o->alpha3 = 'BTC';
    $o->name = 'Bitcoin';
    $o->number = '000';
    $o->decimals = 2;
    $list[] = $o;
}
write_csv(__DIR__ . '/../data/currencies.csv', $list);
write_json(__DIR__ . '/../data/currencies.json', $list);
        $i++;
        $rows[$i] = cleanText($rows[$i]);
        $cols = explode('||', $rows[$i]);
    }
    $o = new \MartinLindhe\Data\Countries\Country();
    $o->alpha2 = getRightSideOfMediawikiTag($cols[0]);
    $o->alpha3 = getRightSideOfMediawikiTag($cols[1]);
    $o->number = getRightSideOfMediawikiTag($cols[2]);
    $name = cleanText($name);
    $name = getRightSideOfMediawikiTag(\MartinLindhe\MediawikiClient\Client::stripMediawikiLinks($name));
    $pos = mb_strpos($name, '/');
    if ($pos !== false) {
        $name = mb_substr($name, 0, $pos);
    }
    $pos = mb_strpos($name, '|');
    if ($pos !== false) {
        $name = mb_substr($name, $pos + 1);
    }
    $o->name = trim(translateName($name));
    $list[] = $o;
}
// aug 2015: Kosovo has a temporary "XK" code since 2010
$o = new \MartinLindhe\Data\Countries\Country();
$o->alpha2 = 'XK';
$o->alpha3 = 'XKO';
$o->number = '';
$o->name = 'Kosovo';
$list[] = $o;
write_csv(__DIR__ . '/../data/countries.csv', $list);
write_json(__DIR__ . '/../data/countries.json', $list);
示例#11
0
 public function json_trending_todoshow()
 {
     $this->load->helper('date');
     $this->load->model('DataModel', 'Data');
     $this->load->model('TrendingModel', 'TrendingM');
     $return = array();
     $file = "trending/todoshow-global";
     $articles = $return[] = $this->TrendingM->GetTrending(false, 67);
     write_json($file, $articles);
     $file = "trending/todoshow-comments";
     $articles = $return[] = $this->TrendingM->GetTrending('comments', 67);
     write_json($file, $articles);
     $file = "trending/todoshow-visits";
     $articles = $return[] = $this->TrendingM->GetTrending('visits', 67);
     write_json($file, $articles);
     $file = "trending/todoshow-shares";
     $articles = $return[] = $this->TrendingM->GetTrending('shares', 67);
     write_json($file, $articles);
     die(print_r($return));
 }
示例#12
0
 public function GetLastVideos($section = 0)
 {
     $file = "videos/section-infonews";
     $where = "";
     if (!$this->clientID && $section) {
         $where = "v.id_categoria = '{$section}' AND ";
         $file = "videos/section-{$section}";
     }
     $json = read_json($file);
     if ($json) {
         if (time() - $json->time < 60 * 5) {
             return $json->videos;
         }
     }
     $sql = "select v.id, v.id_categoria as category, v.titulo as title, v.copete as subtitle, v.codigo as code, v.fecha as date, v.hora as hour\n    from videos v \n    where {$where} v.activo = 'S' and v.estado = 'A'\n    order by v.fecha desc\n    Limit 0,3";
     $result = $this->db->query($sql)->result();
     $videos = array();
     foreach ($result as $video) {
         $videos[] = $this->Data->DataVideoPrep($video);
     }
     $data = array('time' => time(), 'videos' => $videos);
     write_json($file, $data);
     return $videos;
 }