Beispiel #1
0
 /**
  * Constructor
  * @param string $country
  * @param string $region
  */
 public function __construct($country, $region = false)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     /**
      * Start the debug timer
      */
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     if ($region == false && !preg_match("@[a-zA-Z]+@", $country)) {
         // Assume a WOE ID
         $woe = Place::getWOEData($country);
     } else {
         $woe = Place::getWOEData($region . ", " . strtoupper($country));
     }
     /**
      * End the debug timer
      */
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : fetched WOE data from Yahoo in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
     if (isset($woe['places']['place'][0]['name'])) {
         $row = $woe['places']['place'][0];
         $this->slug = $region;
         $this->Country = new Country($country);
     } elseif (isset($woe['place'])) {
         $row = $woe['place'];
         $this->slug = $this->makeRegionSlug($row['name']);
     }
     if (isset($row)) {
         if (empty($this->Country->name) && !preg_match("@[a-zA-Z]+@", $country) && isset($row['country'])) {
             $this->Country = new Country($row['country']);
         }
         $this->name = $row['name'];
         $this->url = $this->Country->url . "/" . $this->slug;
         $this->centre = new stdClass();
         $this->centre->lat = $row['centroid']['latitude'];
         $this->centre->lon = $row['centroid']['longitude'];
         $this->boundingBox = new stdClass();
         $this->boundingBox->northEast = new stdClass();
         $this->boundingBox->northEast->lat = $row['boundingBox']['northEast']['latitude'];
         $this->boundingBox->northEast->lon = $row['boundingBox']['northEast']['longitude'];
         $this->boundingBox->southWest = new stdClass();
         $this->boundingBox->southWest->lat = $row['boundingBox']['southWest']['latitude'];
         $this->boundingBox->southWest->lon = $row['boundingBox']['southWest']['longitude'];
         if (isset($row['timezone'])) {
             $this->timezone = $row['timezone'];
         }
     }
 }
Beispiel #2
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     debug_recordInstance(__CLASS__);
 }
Beispiel #3
0
 /**
  * Constructor
  * @since Version 3.4
  */
 public function __construct()
 {
     // Placeholder - do nothing for now
     /**
      * Record this in the debug log
      */
     debug_recordInstance(__CLASS__);
 }
 /**
  * Constructor
  */
 public function construct()
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
 }
Beispiel #5
0
 /**
  * Constructor
  * @since Version 3.6
  * @param int $event_id
  */
 public function __construct($event_id = false)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     debug_recordInstance(__CLASS__);
     if ($event_id) {
         $this->id = $event_id;
         $this->fetch();
     }
 }
Beispiel #6
0
 /**
  * Constructor
  * @param string $code
  */
 public function __construct($code)
 {
     parent::__construct();
     $this->code = $code;
     $this->url = "/locations/" . strtolower($this->code);
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     /**
      * Start the debug timer
      */
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     $woe = Place::getWOEData(strtoupper($code));
     /**
      * End the debug timer
      */
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : fetched WOE data from Yahoo in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
     if (isset($woe['places']['place'][0]['name'])) {
         $woe = $woe['places']['place'][0];
         $this->name = $woe['name'];
         if (isset($woe['country attrs'])) {
             $this->code = $woe['country attrs']['code'];
             $this->url = "/locations/" . strtolower($this->code);
         }
         $this->centre = new stdClass();
         $this->centre->lat = $woe['centroid']['latitude'];
         $this->centre->lon = $woe['centroid']['longitude'];
         $this->boundingBox = new stdClass();
         $this->boundingBox->northEast = new stdClass();
         $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude'];
         $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude'];
         $this->boundingBox->southWest = new stdClass();
         $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude'];
         $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude'];
         if (isset($woe['timezone'])) {
             $this->timezone = $woe['timezone'];
         }
     }
 }
Beispiel #7
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     /**
      * Load the Module object
      */
     $this->Module = new Module("glossary");
 }
Beispiel #8
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id The ID of the event
  * @uses \Railpage\Events\EventCategory The category which this event is filed under
  * @uses \Railpage\Organisations\Organisation The organisation associated with this event
  * @uses \Railpage\Place The geographic place (latitude & longitude) of this event
  */
 public function __construct($id = false)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     $this->Module = new Module("events");
     $this->namespace = $this->Module->namespace;
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $query = "SELECT * FROM event WHERE id = ?";
         $this->mckey = sprintf("railpage:events.event=%d", $id);
     } elseif (is_string($id) && strlen($id) > 2) {
         $query = "SELECT * FROM event WHERE slug = ?";
         $this->mckey = getMemcacheObject(sprintf("railpage:events.event=%s", $id));
     }
     if (empty($this->mckey) || $this->mckey === false || !($row = getMemcacheObject($this->mckey))) {
         if (isset($query)) {
             $row = $this->db->fetchRow($query, $id);
             $this->mckey = sprintf("railpage:events.event=%d", $row['id']);
             setMemcacheObject($this->mckey, $row);
             setMemcacheObject(sprintf("railpage:events.event=%s", $row['slug']), $row['id']);
         }
     }
     if (isset($row) && is_array($row)) {
         $this->id = $row['id'];
         $this->title = $row['title'];
         $this->desc = $row['description'];
         $this->meta = json_decode($row['meta'], true);
         $this->slug = $row['slug'];
         $this->flickr_tag = "railpage:event=" . $this->id;
         if (filter_var($row['category_id'], FILTER_VALIDATE_INT)) {
             $this->Category = new EventCategory($row['category_id']);
         }
         if (filter_var($row['organisation_id'], FILTER_VALIDATE_INT)) {
             $this->Organisation = new Organisation($row['organisation_id']);
         }
         if (round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") {
             $this->Place = new Place($row['lat'], $row['lon']);
         }
         $this->createUrls();
         $this->Templates = new stdClass();
         $this->Templates->view = sprintf("%s/event.tpl", $this->Module->Paths->html);
     }
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __METHOD__ . " completed in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
 }
 /**
  * Constructor
  * @since Version 3.2
  * @param int $id
  * @param int|string $class_id_or_slug
  * @param string $number
  */
 public function __construct($id = NULL, $class_id_or_slug = NULL, $number = NULL)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     $this->namespace = sprintf("%s.%s", $this->Module->namespace, "loco");
     /**
      * List of templates
      */
     $this->Templates = new stdClass();
     $this->Templates->view = "loco";
     $this->Templates->edit = "loco.edit";
     $this->Templates->sightings = "loco.sightings";
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
     }
     if ((is_null($id) || $id == false) && !is_null($number)) {
         if (!filter_var($class_id_or_slug, FILTER_VALIDATE_INT) && is_string($class_id_or_slug)) {
             // Assume Zend_DB
             $class_id_or_slug = $this->db->fetchOne("SELECT id FROM loco_class WHERE slug = ?", $class_id_or_slug);
         }
         // We are searching by loco number - we need to find it first
         if ($this->db instanceof \sql_db) {
             $query = "SELECT loco_id FROM loco_unit WHERE class_id = " . $this->db->real_escape_string($class_id_or_slug) . " AND loco_num = '" . $this->db->real_escape_string($number) . "'";
             if ($rs = $this->db->query($query)) {
                 $row = $rs->fetch_assoc();
                 $this->id = $row['loco_id'];
             }
         } else {
             $this->id = $this->db->fetchOne("SELECT loco_id FROM loco_unit WHERE class_id = ? AND loco_num = ?", array($class_id_or_slug, $number));
         }
     } else {
         $this->id = $id;
     }
     // Load the loco object
     if (!empty($this->id)) {
         $this->fetch();
     }
 }
Beispiel #10
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id
  */
 public function __construct($id = NULL)
 {
     parent::__construct();
     $this->Module = new Module("images");
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         /**
          * Record this in the debug log
          */
         debug_recordInstance(__CLASS__);
         $this->mckey = sprintf("railpage:image=%d", $id);
         if (!($row = getMemcacheObject($this->mckey))) {
             $query = "SELECT i.id, i.provider, i.photo_id, i.modified, i.meta, i.lat, i.lon FROM image AS i WHERE i.id = ?";
             $row = $this->db->fetchRow($query, $id);
             $row['meta'] = json_decode($row['meta'], true);
             setMemcacheObject($this->mckey, $row, strtotime("+24 hours"));
         }
         $this->id = $id;
         $this->provider = $row['provider'];
         $this->photo_id = $row['photo_id'];
         $this->Date = new DateTime($row['modified']);
         $this->title = !empty($row['meta']['title']) ? format_topictitle($row['meta']['title']) : "Untitled";
         $this->description = $row['meta']['description'];
         $this->sizes = $row['meta']['sizes'];
         $this->links = $row['meta']['links'];
         $this->meta = $row['meta']['data'];
         $this->url = new Url("/image?id=" . $this->id);
         if ($this->provider == "rpoldgallery") {
             $GalleryImage = new \Railpage\Gallery\Image($this->photo_id);
             $this->url->source = $GalleryImage->url->url;
             if (empty($this->meta['source'])) {
                 $this->meta['source'] = $this->url->source;
             }
         }
         /**
          * Normalize some sizes
          */
         if (count($this->sizes)) {
             if (!isset($this->sizes['thumb'])) {
                 foreach ($this->sizes as $size) {
                     if ($size['width'] >= 280 && $size['height'] >= 150) {
                         $this->sizes['thumb'] = $size;
                         break;
                     }
                 }
             }
             if (!isset($this->sizes['small'])) {
                 foreach ($this->sizes as $size) {
                     if ($size['width'] >= 500 && $size['height'] >= 281) {
                         $this->sizes['small'] = $size;
                         break;
                     }
                 }
             }
             $width = 0;
             foreach ($this->sizes as $size) {
                 if ($size['width'] > $width) {
                     $this->sizes['largest'] = $size;
                     $width = $size['width'];
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] >= 1920) {
                     $this->sizes['fullscreen'] = $size;
                     break;
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] > 1024 && $size['width'] <= 1920) {
                     $this->sizes['larger'] = $size;
                     break;
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] == 1024) {
                     $this->sizes['large'] = $size;
                     break;
                 }
             }
             foreach ($this->sizes as $size) {
                 if ($size['width'] == 800) {
                     $this->sizes['medium'] = $size;
                     break;
                 }
             }
         }
         if (isset($row['meta']['author'])) {
             $this->author = json_decode(json_encode($row['meta']['author']));
             if (isset($this->author->railpage_id)) {
                 $this->author->User = new User($this->author->railpage_id);
             }
         } else {
             $this->populate(true);
         }
         if (round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") {
             try {
                 $this->Place = new Place($row['lat'], $row['lon']);
             } catch (Exception $e) {
                 // Throw it away. Don't care.
             }
         }
         /**
          * Set the source URL
          */
         if (isset($this->meta['source'])) {
             $this->source = $this->meta['source'];
         } else {
             switch ($this->provider) {
                 case "flickr":
                     $this->source = "https://flic.kr/p/" . base58_encode($this->photo_id);
             }
         }
         $this->getJSON();
     }
 }
Beispiel #11
0
 /**
  * Constructor
  * @param float $lat
  * @param float $lon
  * @param float $radius
  */
 public function __construct($lat, $lon, $radius = 0.1)
 {
     parent::__construct();
     $this->lat = $lat;
     $this->lon = $lon;
     $this->radius = $radius;
     $this->url = sprintf("/place?lat=%s&lon=%s", $this->lat, $this->lon);
     /**
      * Start the debug timer
      */
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     $woe = $this->getWOEData($this->lat . "," . $this->lon);
     if (!isset($woe['places']['place'][0])) {
         #printArray($woe);die;
         throw new Exception("Could not find a place matching coordinates " . $this->lat . "," . $this->lon);
     }
     /**
      * End the debug timer
      */
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : fetched WOE data from Yahoo in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
     /**
      * Simple enough - create the country object
      */
     $this->Country = new Country($woe['places']['place'][0]['country']);
     /**
      * Bit trickier - find the region, ie, the next geographical location down from a country
      */
     foreach ($woe['places']['place'][0] as $key => $val) {
         if (isset($val['type']) && strtolower($val['type']) != "country") {
             $this->Region = new Region($val['woeid']);
             break;
         }
     }
     /**
      * Set the place name
      */
     if (empty($this->name)) {
         $this->name = $woe['places']['place'][0]['locality1'];
     }
     /**
      * Set the bounding box
      */
     $this->boundingBox = new stdClass();
     $this->boundingBox->northEast = new stdClass();
     $this->boundingBox->northEast->lat = floatval($woe['places']['place'][0]['boundingBox']['northEast']['latitude']);
     $this->boundingBox->northEast->lon = floatval($woe['places']['place'][0]['boundingBox']['northEast']['longitude']);
     $this->boundingBox->southWest = new stdClass();
     $this->boundingBox->southWest->lat = floatval($woe['places']['place'][0]['boundingBox']['southWest']['latitude']);
     $this->boundingBox->southWest->lon = floatval($woe['places']['place'][0]['boundingBox']['southWest']['longitude']);
 }
Beispiel #12
0
 /**
  * Constructor
  * @since Version 3.0
  * @version 3.0
  * @param object $db
  * @param array $preferences
  */
 public function __construct()
 {
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     debug_recordInstance(__CLASS__);
     parent::__construct();
     $this->guest();
     $this->Module = new Module("users");
     foreach (func_get_args() as $arg) {
         if (filter_var($arg, FILTER_VALIDATE_INT)) {
             $this->id = $arg;
             $this->load();
         } elseif (is_string($arg) && strlen($arg) > 1) {
             $query = "SELECT user_id FROM nuke_users WHERE username = ?";
             $this->id = $this->db->fetchOne($query, $arg);
             if (filter_var($this->id, FILTER_VALIDATE_INT)) {
                 $this->load();
             }
         }
     }
     if (RP_DEBUG) {
         $site_debug[] = "Railpage: " . __CLASS__ . "(" . $this->id . ") instantiated in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
 }
Beispiel #13
0
 /**
  * Constructor
  * @since Version 3.2
  * @param int|string $id_or_slug
  * @param boolean $recurse
  */
 public function __construct($id_or_slug = false, $recurse = true)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     $this->Templates = new stdClass();
     $this->Templates->view = "class";
     $this->Templates->sightings = "loco.sightings";
     $this->Templates->bulkedit = "class.bulkedit";
     $this->Templates->bulkedit_operators = "class.bulkedit.operators";
     $this->Templates->bulkedit_buildersnumbers = "class.bulkedit.buildersnumbers";
     $this->Templates->bulkedit_status = "class.bulkedit.status";
     $this->Templates->bulkedit_gauge = "class.bulkedit.gauge";
     $this->namespace = sprintf("%s.%s", $this->Module->namespace, "class");
     // Set the ID
     if (filter_var($id_or_slug, FILTER_VALIDATE_INT) || is_string($id_or_slug)) {
         $this->id = $id_or_slug;
         $this->fetch($recurse);
     }
 }