Exemplo n.º 1
0
 /**
  * Constructor
  * @since Version 3.9.1
  * @param int $correction_id
  */
 public function __construct($correction_id = false)
 {
     parent::__construct();
     if ($this->id = filter_var($correction_id, FILTER_VALIDATE_INT)) {
         $this->populate();
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param string $type
  */
 public function __construct($type = null)
 {
     parent::__construct();
     $this->Module = new Module("glossary");
     if ($type == null) {
         return $this;
     }
     $this->url = new Url(sprintf("%s?mode=type&type=%s", $this->Module->url, $type));
     $this->id = $type;
     switch ($type) {
         case "code":
         case "acronym":
         case "station":
             $this->name = ucfirst($type . "s");
             break;
         case "slang":
         case "general":
             $this->name = ucfirst($type);
             break;
         case "term":
             $this->name = "Terminology";
             break;
         default:
             $this->name = "General";
             break;
     }
 }
Exemplo n.º 3
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     $this->Module = new Module("glossary");
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->mckey = sprintf("%s.entry=%d", $this->Module->namespace, $this->id);
         deleteMemcacheObject($this->mckey);
         if ($row = getMemcacheObject($this->mckey)) {
         } else {
             $query = "SELECT type, short, full, example, date, author FROM glossary WHERE id = ?";
             $row = $this->db->fetchRow($query, $this->id);
             setMemcacheObject($this->mckey, $row);
         }
         if (isset($row) && is_array($row)) {
             $this->name = $row['short'];
             $this->text = $row['full'];
             $this->example = $row['example'];
             $this->Type = new Type($row['type']);
             $this->url = sprintf("%s?mode=entry&id=%d", $this->Module->url, $this->id);
             if ($row['date'] == "0000-00-00 00:00:00") {
                 $this->Date = new DateTime();
                 $this->commit();
             } else {
                 $this->Date = new DateTime($row['date']);
             }
             $this->Author = new User($row['author']);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Return a locomotive
  *
  * @since Version 3.9.1
  * @return \Railpage\Locos\Locomotive
  *
  * @param int|bool    $id
  * @param string|bool $class
  * @param string|bool $number
  */
 public static function CreateLocomotive($id = false, $class = false, $number = false)
 {
     $Redis = AppCore::getRedis();
     $Registry = Registry::getInstance();
     if (!filter_var($id, FILTER_VALIDATE_INT)) {
         $id = Utility\LocomotiveUtility::getLocoId($class, $number);
     }
     if ($id = filter_var($id, FILTER_VALIDATE_INT)) {
         $regkey = sprintf(Locomotive::REGISTRY_KEY, $id);
         try {
             $Loco = $Registry->get($regkey);
         } catch (Exception $e) {
             $cachekey = sprintf(Locomotive::CACHE_KEY, $id);
             if (!self::USE_REDIS || !($Loco = $Redis->fetch($cachekey))) {
                 $Loco = new Locomotive($id);
                 if (self::USE_REDIS) {
                     $Redis->save($cachekey, $Loco);
                 }
             }
             $Registry->set($regkey, $Loco);
         }
         return $Loco;
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * Constructor
  * @param string $slug
  */
 public function __construct($slug)
 {
     $Database = AppCore::GetDatabase();
     $Cache = AppCore::GetMemcached();
     $mckey = "railpage:news.article_slug=" . $slug;
     $loaded = false;
     if ($story_id = $Cache->fetch($mckey)) {
         try {
             parent::__construct($story_id);
             $loaded = true;
         } catch (Exception $e) {
         }
     }
     /**
      * Fall back to a database query if we can't load the news article from Memcached
      */
     if (!$loaded) {
         $story_id = $Database->fetchOne("SELECT sid FROM nuke_stories WHERE slug = ?", $slug);
         if (filter_var($story_id, FILTER_VALIDATE_INT)) {
             $Cache->save($mckey, $story_id, strtotime("+6 months"));
             parent::__construct($story_id);
         } else {
             throw new Exception("Could not find a story matching URL slug " . $slug);
             return false;
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param string $type
  */
 public function __construct($type = false)
 {
     parent::__construct();
     $this->Module = new Module("glossary");
     if ($type) {
         $this->url = sprintf("%s?mode=type&type=%s", $this->Module->url, $type);
         $this->id = $type;
         switch ($type) {
             case "code":
                 $this->name = "Codes";
                 break;
             case "term":
                 $this->name = "Terminology";
                 break;
             case "acronym":
                 $this->name = "Acronyms";
                 break;
             case "station":
                 $this->name = "Stations";
                 break;
             case "slang":
                 $this->name = "Slang";
                 break;
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Return an event
  * @since Version 3.9.1
  * @return \Railpage\Organisations\Organisation
  * @param int|string $id
  */
 public static function CreateOrganisation($id = false)
 {
     $Memcached = AppCore::getMemcached();
     $Redis = AppCore::getRedis();
     $Registry = Registry::getInstance();
     if (!filter_var($id, FILTER_VALIDATE_INT)) {
         $slugkey = sprintf(Organisation::REGISTRY_KEY, $id);
         try {
             $id = $Registry->get($slugkey);
         } catch (Exception $e) {
             $Database = (new AppCore())->getDatabaseConnection();
             $id = $Database->fetchOne("SELECT organisation_id FROM organisation WHERE organisation_slug = ?", $id);
             $Registry->set($slugkey, $id);
         }
     }
     $regkey = sprintf(Organisation::REGISTRY_KEY, $id);
     try {
         $Organisation = $Registry->get($regkey);
     } catch (Exception $e) {
         $cachekey = sprintf(Organisation::CACHE_KEY, $id);
         if (!self::USE_REDIS || !($Organisation = $Redis->fetch($cachekey))) {
             $Organisation = new Organisation($id);
             if (self::USE_REDIS) {
                 $Redis->save($cachekey, $Organisation);
             }
         }
         $Registry->set($regkey, $Organisation);
     }
     return $Organisation;
 }
Exemplo n.º 8
0
 /**
  * Constructor
  * @since Version 3.8.6
  * @param int|string $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if ($id) {
         $mckey = "railpage:fwlink=" . md5($id);
         if ($row = getMemcacheObject($mckey)) {
             $this->id = $row['id'];
             $this->url = $row['url'];
             $this->title = $row['title'];
         } else {
             if (filter_var($id, FILTER_VALIDATE_INT)) {
                 $query = "SELECT * FROM fwlink WHERE id = ?";
             } else {
                 $query = "SELECT * FROM fwlink WHERE url = ?";
             }
             if ($row = $this->db->fetchRow($query, $id)) {
                 $this->id = $row['id'];
                 $this->url = $row['url'];
                 $this->title = $row['title'];
                 setMemcacheObject($mckey, $row, strtotime("+1 month"));
             }
         }
         if (!empty($this->url)) {
             $this->url_canonical = sprintf("http://%s%s", RP_HOST, $this->url);
             $this->url_short = sprintf("http://%s/fwlink?id=%d", RP_HOST, $this->id);
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Get the cover image of the supplied object
  * @since Version 3.9.1
  * @param object $Object
  * @return array
  */
 public static function getCoverImageOfObject($Object)
 {
     if (!self::hasCoverImage($Object)) {
         return false;
     }
     $cachekey = sprintf("railpage:%s=%d;coverimage", $Object->namespace, $Object->id);
     $Memcached = AppCore::getMemcached();
     $Redis = AppCore::GetRedis();
     #printArray($cachekey);die;
     if ($result = $Memcached->fetch($cachekey)) {
         return $result;
     }
     if ($result = $Redis->fetch($cachekey)) {
         return $result;
     }
     $photoidvar = isset($Object->flickr_image_id) ? "flickr_image_id" : "photo_id";
     if (isset($Object->meta['coverimage'])) {
         $Image = ImageFactory::CreateImage($Object->meta['coverimage']['id']);
     } elseif ($Object->Asset instanceof Asset) {
         $Image = $Object->Asset;
     } elseif (isset($Object->{$photoidvar}) && filter_var($Object->{$photoidvar}, FILTER_VALIDATE_INT) && $Object->{$photoidvar} > 0) {
         $Image = ImageFactory::CreateImage($Object->{$photoidvar}, "flickr");
     }
     $return = array("type" => "image", "provider" => $Image instanceof Image ? $Image->provider : "", "title" => $Image instanceof Image ? $Image->title : $Asset->meta['title'], "author" => array("id" => "", "username" => "", "realname" => "", "url" => ""));
     if ($Image instanceof Image) {
         $return = array_merge($return, array("author" => array("id" => $Image->author->id, "username" => $Image->author->username, "realname" => isset($Image->author->realname) ? $Image->author->realname : $Image->author->username, "url" => $Image->author->url), "image" => array("id" => $Image->id), "sizes" => $Image->sizes, "url" => $Image->url->getURLs()));
     }
     if ($Object->Asset instanceof Asset) {
         $return = array_merge($return, array("sizes" => array("large" => array("source" => $Asset->meta['image']), "original" => array("source" => $Asset->meta['original'])), "url" => array("url" => $Asset['meta']['image'])));
     }
     $Memcached->save($cachekey, $return, strtotime("+1 hour"));
     $Redis->save($cachekey, $return, strtotime("+1 hour"));
     return $return;
 }
Exemplo n.º 10
0
 /**
  * Constructor
  *
  * @since Version 3.8.7
  *
  * @param string $module
  */
 public function __construct($module)
 {
     parent::__construct();
     if (!is_string($module)) {
         return;
     }
     $this->Colours = new stdClass();
     $this->Colours->primary = "#666";
     $this->Colours->accent = "#ddd";
     $this->Colours->inverse = "#333";
     $module = self::getModuleAlternateName($module);
     $this->name = ucwords($module);
     $this->url = self::getModuleUrl($module);
     if (self::getModuleId($module)) {
         $this->id = self::getModuleId($module);
     }
     switch (strtolower($module)) {
         case "images.competitions":
             $this->name = "Photo competitions";
             $this->namespace = "railpage.images.competitions";
             break;
         case "locations":
             $this->Colours->primary = "#116416";
             $this->Colours->accent = "#54A759";
             $this->Colours->inverse = "#004304";
             break;
         case "locos":
             $this->Colours->primary = "#3D0CE8";
             $this->Colours->accent = "#576BFF";
             $this->Colours->inverse = "#1B054E";
             break;
         case "news":
             $this->Colours->primary = "#8A2E60";
             $this->Colours->accent = "#CE8AAF";
             $this->Colours->inverse = "#450026";
             break;
         case "privatemessages":
             $this->name = "Private Messages";
             break;
     }
     /**
      * Lazy populate the namespace
      */
     if (empty($this->namespace) && !empty($this->name)) {
         $this->namespace = sprintf("railpage.%s", strtolower($this->name));
     }
     /**
      * Lazy populate the URL
      */
     if (empty($this->url) && !empty($this->name)) {
         $this->url = sprintf("modules.php?name=%s", $this->name);
     }
     /**
      * Create and populate the filesystem paths
      */
     $this->Paths = new stdClass();
     $this->Paths->module = sprintf("%s/modules/%s", RP_SITE_ROOT, $this->name);
     $this->Paths->html = sprintf("%s/modules/%s/html", RP_SITE_ROOT, $this->name);
 }
Exemplo n.º 11
0
 /**
  * Constructor
  * @since Version 3.10.0
  * @return \Railpage\Railcams\Storage
  */
 public function __construct($id = null)
 {
     $this->db = AppCore::GetDatabase();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->getConfig();
     }
 }
Exemplo n.º 12
0
 /**
  * Constructor
  * @since Version 3.9.1
  * @param string $url
  */
 public function __construct($url = false)
 {
     parent::__construct();
     $this->GuzzleClient = new Client();
     if ($url) {
         $this->addFeed($url);
     }
 }
Exemplo n.º 13
0
 /**
  * Constructor
  * @since Version 3.9
  */
 public function __construct()
 {
     parent::__construct();
     $this->Module = new Module("timetables");
     $this->url = new Url($this->Module->url);
     $this->url->import = sprintf("%s?mode=import", $this->url->url);
     $this->url->location = sprintf("%s?mode=location", $this->url->url);
 }
Exemplo n.º 14
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     debug_recordInstance(__CLASS__);
 }
Exemplo n.º 15
0
 /**
  * Constructor
  * @since Version 3.2
  * @param string $dir The download directory to use. If null we'll use the preset one. 
  */
 public function __construct($dir = null)
 {
     parent::__construct();
     $this->Module = new Module("Downloads");
     if ($dir == null) {
         $dir = RP_DOWNLOAD_DIR;
     }
     $this->dir = $dir;
 }
Exemplo n.º 16
0
 /**
  * Constructor
  * @since Version 3.10.0
  * @param \Railpage\Railcams\Camera $cameraObject
  * @param int|null $id
  */
 public function __construct(Camera $cameraObject, $id = null)
 {
     $this->setCamera($cameraObject);
     $this->db = AppCore::GetDatabase();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->getFootage();
     }
 }
Exemplo n.º 17
0
 public function __construct()
 {
     $host = "cache.railpage.com.au";
     $port = 6379;
     $this->Cache = new Redis();
     $this->Cache->connect($host, $port);
     $Smarty = AppCore::GetSmarty();
     $Smarty->caching_type = "redis";
 }
Exemplo n.º 18
0
 /**
  *
  * Constructor
  * @param object $db 
  * @param int $db
  * @since Version 3.0
  * @version 3.0
  *
  */
 public function __construct()
 {
     parent::__construct();
     foreach (func_get_args() as $arg) {
         if (filter_var($arg, FILTER_VALIDATE_INT)) {
             $this->id = $arg;
         }
     }
 }
Exemplo n.º 19
0
 /**
  * Constructor
  */
 public function construct()
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
 }
Exemplo n.º 20
0
 /**
  * Constructor
  * @since Version 3.2
  * @param string $dir The download directory to use. If null we'll use the preset one. 
  */
 public function __construct($dir = NULL)
 {
     parent::__construct();
     if (is_null($dir)) {
         // Try to set the directory
         $this->dir = RP_DOWNLOAD_DIR;
     } else {
         $this->dir = $dir;
     }
 }
Exemplo n.º 21
0
 /**
  * Constructor
  * @since Version 3.9.1
  * @param int $status_id
  * @return void
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if ($id = filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->mckey = sprintf("railpage:locos.status=%d", $this->id);
         $this->populate();
     }
     return;
 }
Exemplo n.º 22
0
 /**
  * Constructor
  * @since Version 3.3
  * @param object $db
  */
 public function __construct($db = false, $user = false)
 {
     parent::__construct();
     $this->Module = new Module("privatemessages");
     foreach (func_get_args() as $arg) {
         if ($arg instanceof User) {
             $this->setUser($arg);
         }
     }
 }
 public function __construct()
 {
     //$this->Cache = AppCore::getMemcached();
     $host = defined("RP_MEMCACHE_HOST") ? RP_MEMCACHE_HOST : "cache.railpage.com.au";
     $port = defined("RP_MEMCACHE_PORT") ? RP_MEMCACHE_PORT : 11211;
     $this->Cache = new PhpMemcached();
     $this->Cache->addServer($host, $port);
     $Smarty = AppCore::GetSmarty();
     $Smarty->caching_type = "memcached";
 }
Exemplo n.º 24
0
 /**
  * Constructor
  * @since Version 3.9
  * @param string $url
  */
 public function __construct($url = false, $provider = "Railway Gazette")
 {
     parent::__construct();
     $this->Module = new Module("news");
     if (is_string($url)) {
         $this->feed = $url;
     }
     if (is_string($provider)) {
         $this->provider = $provider;
     }
 }
Exemplo n.º 25
0
 /**
  * Get most recent push notification for a given user
  * @since Version 3.10.0
  * @param \Railpage\Users\User|int $User
  * @return array
  */
 public static function getCurrentNotification($User)
 {
     if ($User instanceof User) {
         $User = $User->id;
     }
     $query = "SELECT n.* FROM notifications AS n LEFT JOIN notifications_recipients AS nr ON n.id = nr.notification_id WHERE nr.user_id = ? AND n.transport = ? ORDER BY n.date_sent DESC LIMIT 1";
     $params = [$User, Notifications::TRANSPORT_PUSH];
     $result = AppCore::GetDatabase()->FetchRow($query, $params);
     $result['meta'] = json_decode($result['meta'], true);
     return $result;
 }
Exemplo n.º 26
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param string $target
  */
 public function __construct($target = false)
 {
     parent::__construct();
     if (function_exists("getRailpageConfig")) {
         $this->Config = getRailpageConfig();
     }
     if ($target) {
         $this->target = $target;
     }
     $this->format = "json";
 }
Exemplo n.º 27
0
 /**
  * Constructor
  * @since Version 3.9.1
  * @param int|string $id
  */
 public function __construct($id = null)
 {
     parent::__construct();
     $this->namespace = "railpage.images.collection";
     if (!filter_var($id, FILTER_VALIDATE_INT)) {
         $id = $this->getIdFromSlug($id);
     }
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->load();
     }
 }
Exemplo n.º 28
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->Module = new Module("chronicle");
     $this->url = new Url(sprintf("%s/chronicle", RP_WEB_ROOT));
     $this->url->newest = sprintf("%s?mode=newest", $this->url->url);
     $this->url->year = sprintf("%s?mode=year", $this->url->url);
     $this->url->today = sprintf("%s?mode=today", $this->url->url);
     $this->url->thisweek = sprintf("%s?mode=thisweek", $this->url->url);
     $this->url->thismonth = sprintf("%s?mode=thismonth", $this->url->url);
     $this->SubQuery_AllAreas = "SELECT 'locos' AS module, CONCAT(l.loco_num, ': ', dt.loco_date_text) AS title, d.text AS text, timestamp AS `date` FROM loco_unit_date AS d LEFT JOIN loco_unit AS l ON l.loco_id = d.loco_unit_id LEFT JOIN loco_date_type AS dt ON dt.loco_date_id = d.loco_date_id \r\n                UNION SELECT 'locations' AS module, dt.name AS title, d.text, d.date FROM location_date AS d LEFT JOIN location_datetypes AS dt ON d.type_id = dt.id \r\n                UNION SELECT 'events' AS module, e.title, e.description AS text, ed.date FROM event_dates AS ed LEFT JOIN event AS e ON ed.event_id = e.id";
 }
Exemplo n.º 29
0
 /**
  * Get a location ID from a URL slug
  * @since Version 3.10.0
  * @param string $slug
  * @return int
  */
 public static function getLocationId($slug)
 {
     $Redis = AppCore::GetRedis();
     $Memcached = AppCore::GetMemcached();
     $Database = (new AppCore())->getDatabaseConnection();
     $key = sprintf("railpage:locations.slug=%s", $slug);
     if (!($id = $Memcached->fetch($key))) {
         $id = $Database->fetchOne("SELECT id FROM location WHERE slug = ?", $slug);
         $Memcached->save($key, $id, 0);
     }
     return $id;
 }
Exemplo n.º 30
0
 /**
  * Get a phpBB config item
  * @since Version 3.10.0
  * @param string $key
  * @return mixed
  */
 public static function getPhpBB($key = null)
 {
     $Memcached = AppCore::GetMemcached();
     $cachekey = sprintf("railpage:config_phpbb:%s", $key);
     if ($rs = $Memcached->fetch($cachekey)) {
         return $rs;
     }
     $Database = AppCore::GetDatabase();
     $query = "SELECT config_value FROM nuke_bbconfig WHERE config_name = 'allow_html_tags'";
     $rs = $Database->fetchOne($query);
     $Memcached->save($cachekey, $rs, strtotime("+1 month"));
     return $rs;
 }