コード例 #1
0
ファイル: MapImage.php プロジェクト: railpage/railpagecore
 /**
  * Constructor
  * @since Version 3.8.7
  * @param double $lat
  * @param double $lon
  */
 public function __construct($lat = NULL, $lon = NULL)
 {
     parent::__construct();
     $Config = AppCore::GetConfig();
     if ($lat != NULL && $lon != NULL) {
         $this->Place = new Place($lat, $lon);
         $urlstring = "http://maps.googleapis.com/maps/api/staticmap?key=%s&center=%s,%s&zoom=%d&size=%dx%d&maptype=roadmap&markers=color:red%%7C%s,%s";
         $this->sizes = array("thumb" => array("width" => 300, "height" => 150, "zoom" => 14), "small" => array("width" => 500, "height" => 281, "zoom" => 14), "largest" => array("width" => 800, "height" => 600, "zoom" => 12));
         foreach ($this->sizes as $size => $row) {
             $this->sizes[$size]['source'] = sprintf($urlstring, $Config->Google->API_Key, $this->Place->lat, $this->Place->lon, $row['zoom'], $row['width'], $row['height'], $this->Place->lat, $this->Place->lon);
         }
     }
 }
コード例 #2
0
ファイル: Railcams.php プロジェクト: railpage/railpagecore
 /**
  * Get photos tagged with locomotives
  * @since Version 3.9
  * @return array
  * @param boolean|\DateTime $DateFrom
  * @param boolean|\DateTime $DateTo
  */
 public function getTaggedPhotos($DateFrom = false, $DateTo = false)
 {
     $Config = AppCore::GetConfig();
     $SphinxPDO_New = new PDO("mysql:host=" . $Config->Sphinx->Host . ";port=9312");
     $lookup = $SphinxPDO_New->prepare("SELECT * FROM idx_sightings WHERE meta.source = :source ORDER BY date_unix DESC LIMIT 0, 25");
     $lookup->bindValue(":source", "railcam", PDO::PARAM_STR);
     $lookup->execute();
     $result = $lookup->fetchAll(PDO::FETCH_ASSOC);
     foreach ($result as $key => $val) {
         $result[$key]['loco_ids'] = json_decode($val['loco_ids'], true);
         $result[$key]['meta'] = json_decode($val['meta'], true);
     }
     return $result;
     $Sphinx = $this->getSphinx();
     $query = $Sphinx->select("*")->from("idx_railcam_locos")->orderBy("id", "DESC");
     if ($DateFrom instanceof DateTime) {
         $query->where("date", ">=", $DateFrom->format(DateTime::ISO8601));
     }
     if ($DateTo instanceof DateTime) {
         $query->where("date", "<=", $DateTo->format(DateTime::ISO8601));
     }
     $locos = $query->execute();
     return $locos;
 }
コード例 #3
0
ファイル: Sightings.php プロジェクト: railpage/railpagecore
 /**
  * Get sightings for a locomotive
  * @since Version 3.10.0
  * @param \Railpage\Locos\Locomotive $Loco
  * @return array
  */
 public static function getLocoSightings(Locomotive $Loco)
 {
     $Config = AppCore::GetConfig();
     $SphinxPDO = new PDO("mysql:host=" . $Config->Sphinx->Host . ";port=9312");
     $stmt = $SphinxPDO->prepare("SELECT *, IN(loco_ids, :loco_id) AS p FROM idx_sightings WHERE p = 1 ORDER BY date_unix DESC");
     $stmt->bindParam(":loco_id", $Loco->id, PDO::PARAM_INT);
     $stmt->execute();
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $sightings = array();
     foreach ($rs as $row) {
         $Sighting = new Sighting($row['id']);
         $sightings[] = $Sighting->getArray();
     }
     return $sightings;
 }
コード例 #4
0
ファイル: Photo.php プロジェクト: railpage/railpagecore
 /**
  * Tag a locomotive in this photo
  * @since Version 3.9
  * @return \Railpage\Railcams\Photo
  * @throws \Exception if the supplied $Loco object does not have an ID
  * @param \Railpage\Locos\Locomotive $Loco
  */
 public function tagLoco(Locomotive $Loco)
 {
     if (!filter_var($Loco->id, FILTER_VALIDATE_INT)) {
         throw new Exception("An invalid instance of Railpage\\Locos\\Locomotive was supplied");
     }
     /**
      * Lookup this sighting in Sphinx first
      */
     $Config = AppCore::GetConfig();
     $SphinxPDO_New = new PDO("mysql:host=" . $Config->Sphinx->Host . ";port=9312");
     $lookup = $SphinxPDO_New->prepare("SELECT * FROM idx_sightings WHERE meta.source = :source AND meta.photo_id = :photo_id");
     $lookup->bindValue(":source", "railcam", PDO::PARAM_STR);
     $lookup->bindValue(":photo_id", intval($this->id), PDO::PARAM_INT);
     $lookup->execute();
     $id = 0;
     $loco_ids = [];
     $meta = [];
     /**
      * If it's in Sphinx then we need to adjust some insert values
      */
     if ($lookup->rowCount() > 0) {
         $row = $lookup->fetchAll(PDO::FETCH_ASSOC);
         $id = $row[0]['id'];
         $loco_ids = json_decode($row[0]['loco_ids'], true);
         $meta = json_decode($row[0]['meta'], true);
     }
     if (!in_array($Loco->id, $loco_ids)) {
         $loco_ids[] = $Loco->id;
     }
     $meta['source'] = "railcam";
     $meta['railcam_id'] = intval($this->Camera->id);
     $meta['photo_id'] = intval($this->id);
     /**
      * Prepare the insert
      */
     $data = ["timezone" => $this->Camera->timezone, "date" => $this->dates['taken']->format("Y-m-d H:i:s"), "date_added" => new Zend_Db_Expr("NOW()"), "lat" => $this->Camera->lat, "lon" => $this->Camera->lon, "text" => $this->text, "user_id" => $this->User->id, "loco_ids" => json_encode($loco_ids), "meta" => json_encode($meta)];
     /**
      * Guess the train code
      */
     if (preg_match("/([0-9]{1})([a-zA-Z]{2})([0-9]{1})/", $this->title, $matches)) {
         $data['traincode'] = sprintf("%s%s%s", $matches[1], $matches[2], $matches[3]);
     }
     #printArray($data); printArray($id); die;
     /**
      * Insert / update
      */
     if ($id > 0) {
         $where = ["id = ?" => $id];
         $this->db->update("sighting", $data, $where);
     } else {
         $this->db->insert("sighting", $data);
     }
     return $this;
     $data = array("id" => (int) str_replace(".", "", microtime(true)), "railcam_id" => (int) $this->Camera->id, "loco_id" => (int) $Loco->id, "date" => $this->dates['taken']->format(DateTime::ISO8601), "photo_id" => (int) $this->id);
     #printArray($data);die;
     $Sphinx = $this->getSphinx();
     $Insert = $Sphinx->insert()->into("idx_railcam_locos");
     $Insert->set($data);
     $Insert->execute();
     return $this;
 }
コード例 #5
0
    /**
     * Convert a Google Maps link into embedded content
     * @since Version 3.10.0
     * @param \DOMElement $e
     * @return \DOMElement
     */
    public static function EmbedGoogleMap(DOMElement $e)
    {
        $timer = Debug::GetTimer();
        $Config = AppCore::GetConfig();
        $lookup = pq($e)->attr("href");
        // Prevent this from f*****g with links in the middle of sentences
        if (pq($e)->text() != $lookup) {
            return $e;
        }
        if (!preg_match("#google.com(.au)?/maps/(.*)\\@([0-9\\-.]{8,13}),([0-9\\-.]{8,13})#", $lookup, $matches[0]) && !preg_match("#goo.gl/maps/([a-zA-Z0-9]{10,13})#", $lookup, $matches[1])) {
            return $e;
        }
        $basehtml = '<iframe width="%s" height="%s" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/view?key=%s
&zoom=%d&maptype=%s&center=%s" allowfullscreen>
</iframe>';
        $params = ["100%", 600, $Config->Google->API_Key, 15, "satellite"];
        foreach ($matches as $val) {
            if (!count($val)) {
                continue;
            }
            // Co-ordinates known, great
            if (count($val) === 5) {
                $params[] = $val[3] . "," . $val[4];
                continue;
            }
            // Co-ordinates not known. Shit. Better look 'em up
            if (count($val) !== 2) {
                continue;
            }
            $Memcached = AppCore::GetMemcached();
            $cachekey = sprintf("google:url.shortner=%s", $val[1]);
            if (!($return = $Memcached->fetch($cachekey))) {
                $GuzzleClient = new Client();
                $url = sprintf("https://www.googleapis.com/urlshortener/v1/url?shortUrl=%s&key=%s", $lookup, "AIzaSyC1lUe1h-gwmFqj9xDTDYI9HYVTUxNscCA");
                $response = $GuzzleClient->get($url);
                // F****d it
                if ($response->getStatusCode() != 200) {
                    return $e;
                }
                $return = json_decode($response->getBody(), true);
                $Memcached->save($cachekey, $return);
            }
            // Get out if it looks problematic
            if ($return['status'] != "OK") {
                return $e;
            }
            pq($e)->attr("href", $return['longUrl'])->text($return['longUrl']);
            return self::EmbedGoogleMap($e);
            continue;
        }
        pq($e)->replaceWith(vsprintf($basehtml, $params));
        Debug::LogEvent(__METHOD__, $timer);
        return $e;
    }
コード例 #6
0
 /**
  * Return an instance of an image provider from the name of the provider
  * @since Version 3.10.0
  * @param string $provider
  * @param array $options An array of options for creating the provider
  * @return object
  */
 public static function CreateImageProvider($provider, $options = [])
 {
     $Config = AppCore::GetConfig();
     $imageprovider = __NAMESPACE__ . "\\Provider\\" . ucfirst($provider);
     $params = array();
     switch ($provider) {
         case "smugmug":
             $imageprovider = __NAMESPACE__ . "\\Provider\\SmugMug";
             break;
         case "picasaweb":
             $imageprovider = __NAMESPACE__ . "\\Provider\\PicasaWeb";
             break;
         case "rpoldgallery":
             $imageprovider = __NAMESPACE__ . "\\Provider\\RPOldGallery";
             break;
         case "fivehundredpx":
             $imageprovider = __NAMESPACE__ . "\\Provider\\FiveHundredPx";
             break;
         case "flickr":
             $params = array_merge(array("oauth_token" => "", "oauth_secret" => ""), $options);
             if (isset($Config->Flickr->APIKey)) {
                 $params['api_key'] = $Config->Flickr->APIKey;
             }
             break;
     }
     $imageprovider = str_replace("\\Utility\\", "\\", $imageprovider);
     return new $imageprovider($params);
 }
コード例 #7
0
ファイル: Finder.php プロジェクト: railpage/railpagecore
 /**
  * Process the photo array
  * @since Version 3.9.1
  * @param array $data
  * @return array
  */
 private static function ProcessPhoto($data)
 {
     $Config = AppCore::GetConfig();
     $data['meta'] = json_decode($data['meta'], true);
     $data['meta']['sizes'] = Images::NormaliseSizes($data['meta']['sizes']);
     if (!empty($data['country_code'])) {
         $urlstring = "http://maps.googleapis.com/maps/api/staticmap?key=%s&center=%s,%s&zoom=%d&size=%dx%d&maptype=roadmap&markers=color:red%%7C%s,%s";
         $data['geoplace_image'] = sprintf($urlstring, $Config->Google->API_Key, $data['geoplace_lat'], $data['geoplace_lon'], 12, 800, 600, $data['geoplace_lat'], $data['geoplace_lon']);
         $data['geoplace_photo'] = isset($data['meta']['sizes']['small']) ? $data['meta']['sizes']['small']['source'] : NULL;
     }
     return $data;
 }
コード例 #8
0
 /**
  * Constructor
  * @since Version 3.9
  */
 public function __construct()
 {
     $this->Config = AppCore::GetConfig();
     $this->adapter = new Adapter(array("driver" => "Mysqli", "database" => $this->Config->GTFS->PTV->db_name, "username" => $this->Config->GTFS->PTV->db_user, "password" => $this->Config->GTFS->PTV->db_pass, "host" => $this->Config->GTFS->PTV->db_host));
     $this->db = new Sql($this->adapter);
 }