<commit_before><?php

/**************************************************************************

File: mapprservice.api.class.php

Description: Extends MAPPR class and produces maps from API call.

Developer: <NAME>
Email: <EMAIL>

Copyright (C) 2010  <NAME>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

**************************************************************************/

require_once('../config/conf.php');
require_once ('mapprservice.class.php');
require_once ('georss/rss_fetch.inc');

class MAPPRAPI extends MAPPR {

  private $_file;
  private $_data;
  private $_coord_cols;

  /**
  * Override method in parent class
  */
  public function get_request() {
    //ping API to return JSON
    $this->ping             = $this->load_param('ping', false);
    if($this->ping) {
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Cache-Control: private",false);
      header("Content-Type: application/json");
      $output = array("status" => "ok");
      echo json_encode($output);
      exit();
    }

    $this->method           = $_SERVER['REQUEST_METHOD'];

    $this->download         = true;
    $this->watermark        = true;
    $this->options          = array();
    $this->legend           = array();

    $this->url              = false;
    $url                    = urldecode($this->load_param('url', false));

    if($this->method == "POST" && $_FILES) {
      try {
        $file = $this->moveFile();
      } catch (Exception $e) {
        $output = array(
          'error' => "An error occurred:" . $e->getMessage()
        );
        echo json_encode($output);
        exit();
      }
    } else {
      $file = urldecode($this->load_param('file', false));
    }

    $georss                 = urldecode($this->load_param('georss', false));

    if($georss) { $this->url = $georss; }
    if($url)    { $this->url = $url; }
    if($file)   { $this->url = $file; }

    $this->points           = $this->load_param('point', array());
    $this->shape            = (is_array($this->load_param('shape', array()))) ? $this->load_param('shape', array()) : array($this->load_param('shape', array()));
    $this->size             = (is_array($this->load_param('size', array()))) ? $this->load_param('size', array()) : array($this->load_param('size', array()));
    $this->color            = (is_array($this->load_param('color', array()))) ? $this->load_param('color', array()) : array($this->load_param('color', array()));

    $this->outlinecolor     = $this->load_param('outlinecolor', null);
    $this->border_thickness = (float)$this->load_param('thickness', 1.25);

    $shaded = $this->load_param('shade', array());
    $this->regions = array(
      'data' => (array_key_exists('places', $shaded)) ? $shaded['places'] : "",
      'title' => (array_key_exists('title', $shaded)) ? $shaded['title'] : "",
      'color' => (array_key_exists('color', $shaded)) ? str_replace(",", " ",$shaded['color']) : "120 120 120"
    );

    $this->output           = $this->load_param('output','pnga');
    $this->projection       = $this->load_param('projection', 'epsg:4326');
    $this->projection_map   = $this->projection;

    $this->bbox_map         = $this->load_param('bbox', '-180,-90,180,90');
    $this->zoom             = (int)$this->load_param('zoom', false);

    //convert layers as comma-separated values to an array
    $_layers                = explode(',', $this->load_param('layers', ''));
    $layers = array();
    foreach($_layers as $_layer) {
      if($_layer) { $layers[trim($_layer)] = trim($_layer); }
    }
    $this->layers           = $layers;
    $this->graticules       = $this->load_param('graticules', false);
    $this->gridspace        = $this->load_param('spacing', false);
    $this->gridlabel        = $this->load_param('gridlabel', "true");

    if($this->load_param('border', false)) { $this->options['border'] = true; }
    if($this->load_param('legend', false)) { $this->options['legend'] = true; }
    if($this->load_param('scalebar', false)) { $this->options['scalebar'] = true; }

    //set the image size from width & height to array(width, height)
    $this->width            = (float)$this->load_param('width', 800);
    $this->height           = (float)$this->load_param('height', (isset($_GET['width']) && !isset($_GET['height'])) ? $this->width/2 : 400);
    if($this->width == 0 || $this->height == 0) { $this->width = 800; $this->height = 400; }
    $this->image_size       = array($this->width, $this->height);

    return $this;
  }
  
  /**
  * Override method in parent class
  */ 
  public function add_coordinates() {
    if($this->url || $this->points) {

      if($this->url) {
        if (strstr($this->url, MAPPR_UPLOAD_DIRECTORY)) {
          $this->parseFile();
        } else {
          $headers = get_headers($this->url, 1);<commit_msg>Remove file from API immediately after parsing<commit_after><?php

/**************************************************************************

File: mapprservice.api.class.php

Description: Extends MAPPR class and produces maps from API call.

Developer: <NAME>
Email: <EMAIL>

Copyright (C) 2010  <NAME>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

**************************************************************************/

require_once('../config/conf.php');
require_once ('mapprservice.class.php');
require_once ('georss/rss_fetch.inc');

class MAPPRAPI extends MAPPR {

  private $_file;
  private $_data;
  private $_coord_cols;

  /**
  * Override method in parent class
  */
  public function get_request() {
    //ping API to return JSON
    $this->ping             = $this->load_param('ping', false);
    if($this->ping) {
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Cache-Control: private",false);
      header("Content-Type: application/json");
      $output = array("status" => "ok");
      echo json_encode($output);
      exit();
    }

    $this->method           = $_SERVER['REQUEST_METHOD'];

    $this->download         = true;
    $this->watermark        = true;
    $this->options          = array();
    $this->legend           = array();

    $this->url              = false;
    $url                    = urldecode($this->load_param('url', false));

    if($this->method == "POST" && $_FILES) {
      try {
        $file = $this->moveFile();
      } catch (Exception $e) {
        $output = array(
          'error' => "An error occurred:" . $e->getMessage()
        );
        echo json_encode($output);
        exit();
      }
    } else {
      $file = urldecode($this->load_param('file', false));
    }

    $georss                 = urldecode($this->load_param('georss', false));

    if($georss) { $this->url = $georss; }
    if($url)    { $this->url = $url; }
    if($file)   { $this->url = $file; }

    $this->points           = $this->load_param('point', array());
    $this->shape            = (is_array($this->load_param('shape', array()))) ? $this->load_param('shape', array()) : array($this->load_param('shape', array()));
    $this->size             = (is_array($this->load_param('size', array()))) ? $this->load_param('size', array()) : array($this->load_param('size', array()));
    $this->color            = (is_array($this->load_param('color', array()))) ? $this->load_param('color', array()) : array($this->load_param('color', array()));

    $this->outlinecolor     = $this->load_param('outlinecolor', null);
    $this->border_thickness = (float)$this->load_param('thickness', 1.25);

    $shaded = $this->load_param('shade', array());
    $this->regions = array(
      'data' => (array_key_exists('places', $shaded)) ? $shaded['places'] : "",
      'title' => (array_key_exists('title', $shaded)) ? $shaded['title'] : "",
      'color' => (array_key_exists('color', $shaded)) ? str_replace(",", " ",$shaded['color']) : "120 120 120"
    );

    $this->output           = $this->load_param('output','pnga');
    $this->projection       = $this->load_param('projection', 'epsg:4326');
    $this->projection_map   = $this->projection;

    $this->bbox_map         = $this->load_param('bbox', '-180,-90,180,90');
    $this->zoom             = (int)$this->load_param('zoom', false);

    //convert layers as comma-separated values to an array
    $_layers                = explode(',', $this->load_param('layers', ''));
    $layers = array();
    foreach($_layers as $_layer) {
      if($_layer) { $layers[trim($_layer)] = trim($_layer); }
    }
    $this->layers           = $layers;
    $this->graticules       = $this->load_param('graticules', false);
    $this->gridspace        = $this->load_param('spacing', false);
    $this->gridlabel        = $this->load_param('gridlabel', "true");

    if($this->load_param('border', false)) { $this->options['border'] = true; }
    if($this->load_param('legend', false)) { $this->options['legend'] = true; }
    if($this->load_param('scalebar', false)) { $this->options['scalebar'] = true; }

    //set the image size from width & height to array(width, height)
    $this->width            = (float)$this->load_param('width', 800);
    $this->height           = (float)$this->load_param('height', (isset($_GET['width']) && !isset($_GET['height'])) ? $this->width/2 : 400);
    if($this->width == 0 || $this->height == 0) { $this->width = 800; $this->height = 400; }
    $this->image_size       = array($this->width, $this->height);

    return $this;
  }
  
  /**
  * Override method in parent class
  */ 
  public function add_coordinates() {
    if($this->url || $this->points) {

      if($this->url) {
        if (strstr($this->url, MAPPR_UPLOAD_DIRECTORY)) {
          $this->parseFile();
          unlink($this->url);
        } else {
          $headers = get_headers($this->url, 1);
{'fraction_non_alphanumeric': 0.20413274890419536, 'fraction_numerical': 0.010913319617139278, 'mean_word_length': 3.0877513711151736, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 180, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6062264', 'n_tokens_mistral': 3535, 'n_tokens_neox': 3355, 'n_words': 788}