Example #1
0
 protected function fetchData(Request $request)
 {
     $country = strtoupper($request->getCountry());
     $lang = strtoupper($request->getLang());
     $stations = array();
     $count = 0;
     $pre = "";
     //yes, I hate this dirty hack. It's here to provide for the iRail client as well as for the API.
     //It needs to disapear if we rewrite the mobile client
     if (sizeof(explode("api", $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"])) > 1) {
         $pre = "../";
     }
     $file = $pre . "stationlists/" . $country . ".csv";
     if (!file_exists($file)) {
         $file = $pre . "stationlists/" . $country . "_EN.csv";
     }
     if (($handle = fopen($file, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
             if (isset($data[4])) {
                 $stations[$count] = new Station($data[1], $data[3], $data[2], $data[0], $data[4]);
             } else {
                 $stations[$count] = new Station($data[1], $data[3], $data[2], $data[0]);
             }
             $count++;
         }
         fclose($handle);
     }
     return $stations;
 }
Example #2
0
 protected function fetchData(Request $request)
 {
     $this->request = $request;
     include "getUA.php";
     $request_options = array("referer" => "http://api.irail.be/", "timeout" => "30", "useragent" => $irailAgent);
     $id = preg_replace("/.*?(\\d.*)/smi", "\\1", $request->getVehicleId());
     $this->scrapeURL .= "?l=" . $request->getLang() . "&s=1&tid=" . $id . "&da=D&p=2";
     $post = http_post_data($this->scrapeURL, "", $request_options) or die("");
     $body = http_parse_message($post)->body;
     return $body;
 }
 function Lang()
 {
     $c = new Cookie(COOKIE_NAME_VIEW);
     // look if reload lang file
     $this->fileAdress = INCLUDE_PATH . "/config/lang_available.php";
     if (!file_exists($this->fileAdress)) {
         $this->reloadLangFile();
     } else {
         require $this->fileAdress;
         if (!isset($langAvailable)) {
             print "There is a problem with the /config/lang_available.php file.";
             $langAvailableFile = INCLUDE_PATH . "/config/lang_available.php";
             if (!unlink($langAvailableFile)) {
                 print "Error when trying to delete {$langAvailableFile}. You have to delete the file {$langAvailableFile} manually.";
             }
             print "<br>Please refresh this page";
             exit;
         }
         $this->langAvailable = $langAvailable;
     }
     $langRequest = Request::getLang();
     if (!file_exists(LANGS_PATH . "/" . $langRequest)) {
         // cookie ?
         if (($langRequest = $c->getVar('lang')) && file_exists(LANGS_PATH . "/" . $langRequest)) {
             $this->file = $langRequest;
         } else {
             // default lang?
             if (defined('INTERFACE_DEFAULT_LANG') && file_exists(LANGS_PATH . "/" . INTERFACE_DEFAULT_LANG)) {
                 $this->file = INTERFACE_DEFAULT_LANG;
             }
         }
     } else {
         $this->file = $langRequest;
     }
     // if lang not found in REQUEST + COOKIE + not set with INTERFACE_DEFAULT_LANG
     // then we try to choose the better lang
     if (!isset($this->file) || !strpos($this->file, 'utf-8.php') || strpos($this->file, '..') !== FALSE) {
         $this->file = $this->getNearestLang();
     }
     $this->setLang();
     // cookie
     $c->setVar('lang', $this->file);
     $c->save();
     //print($c->toString());
     //print($this->file);
 }
Example #4
0
 protected function fetchData(Request $request)
 {
     include "getUA.php";
     $this->request = $request;
     $scrapeUrl = "http://www.railtime.be/mobile/SearchStation.aspx";
     $request_options = array("referer" => "http://api.irail.be/", "timeout" => "30", "useragent" => $irailAgent);
     $stationname = strtoupper($request->getStation());
     include "includes/railtimeids.php";
     if (array_key_exists($stationname, $railtimeids)) {
         $rtid = $railtimeids[$stationname];
     } else {
         throw new Exception("Station not available for liveboard", 3);
     }
     $this->arrdep = $request->getArrdep();
     $this->name = $request->getStation();
     $scrapeUrl .= "?l=" . $request->getLang() . "&s=1&sid=" . $rtid . "&da=" . substr($request->getArrdep(), 0, 1) . "&p=2";
     $post = http_post_data($scrapeUrl, "", $request_options) or die("");
     $body = http_parse_message($post)->body;
     return $body;
 }
Example #5
0
    /**
     * This function will get the data from nmbs we need.
     * @param Request $request
     * @return <type>
     */
    protected function fetchData(Request $request)
    {
        $this->request = $request;
        include "getUA.php";
        $url = "http://hari.b-rail.be/Hafas/bin/extxml.exe";
        $request_options = array("referer" => "http://api.irail.be/", "timeout" => "30", "useragent" => $irailAgent);
        //first request: Getting the id of the right stations
        $postdata = '<?xml version="1.0 encoding="iso-8859-1"?>
<ReqC ver="1.1" prod="iRail API v1.0" lang="EN">
<LocValReq id="from" maxNr="1">
<ReqLoc match="' . $request->getFrom() . '" type="ST"/>
</LocValReq>
<LocValReq id="to" maxNr="1">
<ReqLoc match="' . $request->getTo() . '" type="ST"/>
</LocValReq>
</ReqC>';
        $post = http_post_data($url, $postdata, $request_options) or die("");
        $idbody = http_parse_message($post)->body;
        preg_match_all("/externalId=\"(.*?)\"/si", $idbody, $matches);
        $idfrom = $matches[1][0];
        $idto = $matches[1][1];
        //for now
        $trainsonly = "1111111111111111";
        $timeSel = 0;
        if ($request->getTimeSel() == "depart") {
            $timeSel = 0;
        } else {
            if (strcmp($request->getTimeSel(), "arrive") == 0) {
                $timeSel = 1;
            }
        }
        //now we're going to get the real data
        $postdata = '<?xml version="1.0 encoding="iso-8859-1"?>
<ReqC ver="1.1" prod="irail" lang="' . $request->getLang() . '">
<ConReq>
<Start min="0">
<Station externalId="' . $idfrom . '" distance="0">
</Station>
<Prod prod="' . $trainsonly . '">
</Prod>
</Start>
<Dest min="0">
<Station externalId="' . $idto . '" distance="0">
</Station>
</Dest>
<Via>
</Via>
<ReqT time="' . $request->getTime() . '" date="' . $request->getDate() . '" a="' . $timeSel . '">
</ReqT>
<RFlags b="' . $request->getResults() * $timeSel . '" f="' . $request->getResults() * -($timeSel - 1) . '">
</RFlags>
<GISParameters>
<Front>
</Front>
<Back>
</Back>
</GISParameters>
</ConReq>
</ReqC>';
        $post = http_post_data($url, $postdata, $request_options) or die("<br />NMBS/SNCB website timeout. Please <a href='..'>refresh</a>.");
        return http_parse_message($post)->body;
    }
Example #6
0
 /**
  * Loads and renders the view containing a list of recent changes in the vocabulary.
  * @param Request $request
  */
 public function invokeChangeList($request, $prop = 'dc:created')
 {
     // set language parameters for gettext
     $this->setLanguageProperties($request->getLang());
     $vocab = $request->getVocab();
     $offset = $request->getQueryParam('offset') && is_numeric($request->getQueryParam('offset')) && $request->getQueryParam('offset') >= 0 ? $request->getQueryParam('offset') : 0;
     $changeList = $vocab->getChangeList($prop, $request->getContentLang(), $request->getLang(), $offset);
     // load template
     $template = $this->twig->loadTemplate('changes.twig');
     // render template
     echo $template->render(array('vocab' => $vocab, 'languages' => $this->languages, 'request' => $request, 'changeList' => $changeList));
 }
Example #7
0
 /**
  * Used for querying narrower relations for a concept in the hierarchy view.
  * @param Request $request
  * @return object json-ld wrapped hierarchical concept uris and labels.
  */
 public function related($request)
 {
     $results = array();
     $related = $request->getVocab()->getConceptRelateds($request->getUri(), $request->getLang());
     if ($related === null) {
         return $this->returnError('404', 'Not Found', "Could not find concept <{$request->getUri()}>");
     }
     foreach ($related as $uri => $vals) {
         $results[] = array('uri' => $uri, 'prefLabel' => $vals['label']);
     }
     $ret = array_merge_recursive($this->context, array('@context' => array('prefLabel' => 'skos:prefLabel', 'related' => 'skos:related', '@language' => $request->getLang()), 'uri' => $uri, 'related' => $results));
     return $this->returnJson($ret);
 }