Example #1
0
 /**
  * Remove an object from the registry
  * @since Version 3.9.1
  * @param string $key Name of the object to remove
  * @return \Railpage\Registry;
  */
 public function remove($key)
 {
     if (isset($this->registry[strtolower($key)])) {
         unset($this->registry[strtolower($key)]);
     }
     Debug::logEvent(__METHOD__ . "(" . $key . ")");
     return $this;
 }
Example #2
0
 /**
  * Constructor
  * @since Version 3.2
  * @version 3.2
  * @param int $operator_id
  */
 public function __construct($operator_id = false)
 {
     $timer = Debug::getTimer();
     parent::__construct();
     if (filter_var($operator_id, FILTER_VALIDATE_INT)) {
         $this->fetch($operator_id);
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #3
0
 public function testAdd()
 {
     if (!defined("RP_DEBUG")) {
         define("RP_DEBUG", true);
     }
     $timer = Debug::getTimer();
     Debug::logEvent("testing", $timer);
     Debug::getLog();
     Debug::printPretty();
     //Debug::SaveError(new Exception("zomg this is shit"));
     Debug::printArray("asdafd");
 }
 /**
  * Constructor
  * @since Version 3.8.7
  * @var int|string $id
  */
 public function __construct($id = NULL)
 {
     $timer = Debug::getTimer();
     parent::__construct();
     if (!is_null($id)) {
         if (filter_var($id, FILTER_VALIDATE_INT)) {
             $row = $this->db->fetchRow("SELECT * FROM wheel_arrangements WHERE id = ?", $id);
         } elseif (is_string($id)) {
             $row = $this->db->fetchRow("SELECT * FROM wheel_arrangements WHERE slug = ?", $id);
         }
         $this->load($row);
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #5
0
 /**
  * Constructor
  * @since Version 3.9.1
  * @param int|string $id
  */
 public function __construct($id = false)
 {
     $timer = Debug::getTimer();
     parent::__construct();
     $this->Module = new Module("locos");
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
     } elseif (is_string($id) && !empty($id)) {
         $query = "SELECT gauge_id FROM loco_gauge WHERE slug = ?";
         $this->id = $this->db->fetchOne($query, $id);
     }
     $this->populate();
     Debug::logEvent(__METHOD__, $timer);
 }
Example #6
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @var int|string $id
  */
 public function __construct($id = NULL)
 {
     $timer = Debug::getTimer();
     parent::__construct();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $row = $this->db->fetchRow("SELECT * FROM loco_type WHERE id = ?", $id);
         $this->load($row);
     }
     $id = filter_var($id, FILTER_SANITIZE_STRING);
     if (!is_null($id)) {
         $row = $this->db->fetchRow("SELECT * FROM loco_type WHERE slug = ?", $id);
         $this->load($row);
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #7
0
 /**
  * Constructor
  *
  * @since Version 3.8.7
  *
  * @param string $default_url
  */
 public function __construct($default_url = false)
 {
     Debug::RecordInstance();
     $timer = Debug::getTimer();
     if ($default_url !== false) {
         $this->url = $default_url;
         $fwlink = new fwlink($this->url);
         $this->short = $fwlink->url_short;
         /**
          * Create the canonical link
          */
         $rp_host = defined("RP_HOST") ? RP_HOST : "www.railpage.com.au";
         $rp_root = defined("RP_WEB_ROOT") ? RP_WEB_ROOT : "";
         if (substr($this->url, 0, 4) == "http") {
             $this->canonical = $this->url;
         } else {
             $this->canonical = sprintf("http://%s%s%s", $rp_host, $rp_root, $this->url);
         }
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #8
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $categoryId
  */
 public function __construct($categoryId = NULL)
 {
     parent::__construct();
     $timer = Debug::getTimer();
     $this->Module = new Module("events");
     $this->namespace = $this->Module->namespace;
     if (filter_var($categoryId, FILTER_VALIDATE_INT)) {
         $query = "SELECT * FROM event_categories WHERE id = ?";
     } elseif (is_string($categoryId) && strlen($categoryId) > 1) {
         $query = "SELECT * FROM event_categories WHERE slug = ?";
     }
     if (isset($query)) {
         if ($row = $this->db->fetchRow($query, $categoryId)) {
             $this->id = $row['id'];
             $this->name = $row['title'];
             $this->desc = $row['description'];
             $this->slug = $row['slug'];
             $this->createUrls();
         }
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #9
0
 /**
  * Constructor
  * @since Version 3.8.7
  *
  * @param int|string $id
  */
 public function __construct($id = NULL)
 {
     $timer = Debug::getTimer();
     parent::__construct();
     if (!is_null($id)) {
         if (filter_var($id, FILTER_VALIDATE_INT)) {
             $query = "SELECT * FROM loco_manufacturer WHERE manufacturer_id = ?";
             $row = $this->db->fetchRow($query, $id);
         } elseif (is_string($id)) {
             $query = "SELECT * FROM loco_manufacturer WHERE slug = ?";
             $row = $this->db->fetchRow($query, $id);
         }
         if (isset($row) && count($row)) {
             $this->id = $row['manufacturer_id'];
             $this->name = $row['manufacturer_name'];
             $this->desc = $row['manufacturer_desc'];
             $this->slug = $row['slug'];
             if (empty($this->slug)) {
                 $proposal = ContentUtility::generateUrlSlug($this->name, 30);
                 $query = "SELECT manufacturer_id FROM loco_manufacturer WHERE slug = ?";
                 $result = $this->db->fetchAll($query, $proposal);
                 if (count($result)) {
                     $proposal = $proposal . count($result);
                 }
                 $this->slug = $proposal;
                 $this->commit();
             }
             $this->url = new Url(sprintf("/locos/builder/%s", $this->slug));
         }
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #10
0
 /**
  * Commit changes to database
  * @since Version 3.2
  * @version 3.8.7
  * @return boolean
  */
 public function commit()
 {
     $timer = Debug::getTimer();
     $this->validate();
     $data = Utility\LocomotiveUtility::getSubmitData($this);
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         $rs = $this->db->insert("loco_unit", $data);
         $this->id = $this->db->lastInsertId();
         $verb = "Insert";
     } else {
         $this->Memcached->delete($this->mckey);
         $this->Redis->delete($this->mckey);
         $where = array("loco_id = ?" => $this->id);
         $verb = "Update";
         $rs = $this->db->update("loco_unit", $data, $where);
     }
     // Update the registry
     $Registry = Registry::getInstance();
     $regkey = sprintf(self::REGISTRY_KEY, $this->id);
     $Registry->remove($regkey)->set($regkey, $this);
     $this->Memcached->delete(sprintf(self::CACHE_KEY_DESC, $this->id));
     Debug::logEvent("Zend_DB: commit loco ID " . $this->id, $timer);
     $this->makeLinks();
     return true;
 }
Example #11
0
 /**
  * Set last session activity
  * @since   Version 3.0
  * @version 3.10.0
  * @return boolean
  *
  * @param string $remoteAddr
  */
 public function updateSessionTime($remoteAddr = null)
 {
     $timer = Debug::GetTimer();
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         return $this;
     }
     if ($this->session_time >= time() - 300) {
         return $this;
     }
     $this->session_time = time();
     if (is_null($remoteAddr)) {
         $this->session_ip = $remoteAddr;
     }
     $this->commit();
     Debug::logEvent("Zend_DB: Update user session time for user ID " . $this->id, $timer);
     return $this;
 }
Example #12
0
 /**
  * Populate this object
  * @since Version 3.9.1
  * @return void
  */
 private function populate()
 {
     $timer = Debug::getTimer();
     $this->mckey = sprintf("railpage:organisations.organisation=%d", $this->id);
     if (!($row = $this->Memcached->fetch($this->mckey))) {
         $query = "SELECT o.* FROM organisation AS o WHERE organisation_id = ?";
         $row = $this->db->fetchRow($query, $this->id);
         $this->Memcached->save($this->mckey, $row);
     }
     $lookup = ["name" => "organisation_name", "desc" => "organisation_desc", "created" => "organisation_dateadded", "owner" => "organisation_owner", "contact_website" => "organisation_website", "contact_phone" => "organisation_phone", "contact_fax" => "organisation_fax", "contact_email" => "organisation_email", "loco" => "organisation_logo", "flickr_photo_id" => "flickr_photo_id", "slug" => "organisation_slug"];
     foreach ($lookup as $var => $val) {
         $this->{$var} = $row[$val];
     }
     /*
     $this->name     = $row['organisation_name'];
     $this->desc     = $row['organisation_desc'];
     $this->created  = $row['organisation_dateadded'];
     $this->owner    = $row['organisation_owner'];
     $this->contact_website  = $row['organisation_website'];
     $this->contact_phone    = $row['organisation_phone'];
     $this->contact_fax      = $row['organisation_fax'];
     $this->contact_email    = $row['organisation_email'];
     
     $this->logo = $row['organisation_logo']; 
     $this->flickr_photo_id = $row['flickr_photo_id'];
     
     $this->slug = $row['organisation_slug']; 
     */
     if (empty($this->slug)) {
         $this->slug = parent::createSlug();
     }
     $this->url = parent::makePermaLink($this->slug);
     $this->loadRoles();
     Debug::logEvent(__METHOD__, $timer);
 }
Example #13
0
 /**
  * Update the geoplace reference for this image
  *
  * @since Version 3.9.1
  * @return void
  */
 public function updateGeoPlace()
 {
     if (!filter_var($this->lat, FILTER_VALIDATE_FLOAT) || !filter_var($this->lat, FILTER_VALIDATE_FLOAT)) {
         return;
     }
     $timer = microtime(true);
     $GeoPlaceID = PlaceUtility::findGeoPlaceID($this->lat, $this->lon);
     #var_dump($GeoPlaceID);die;
     $data = ["geoplace" => $GeoPlaceID];
     $where = ["id = ?" => $this->id];
     $this->db->update("image", $data, $where);
     $this->Memcached->delete($this->mckey);
     $this->Redis->delete($this->mckey);
     Debug::logEvent(__METHOD__, $timer);
     Debug::LogCLI(__METHOD__, $timer);
     return;
 }
Example #14
0
 /**
  * Constructor
  * @param float $lat
  * @param float $lon
  * @param float $radius
  */
 public function __construct($lat = false, $lon = false, $radius = 0.1)
 {
     parent::__construct();
     $timer = Debug::getTimer();
     Debug::RecordInstance();
     $this->GuzzleClient = new Client();
     if (filter_var($lat, FILTER_VALIDATE_FLOAT) && filter_var($lon, FILTER_VALIDATE_FLOAT)) {
         $this->lat = $lat;
         $this->lon = $lon;
         $this->radius = $radius;
         $this->url = sprintf("/place?lat=%s&lon=%s", $this->lat, $this->lon);
         $this->load();
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #15
0
 /**
  * Constructor
  *
  * @param int $id
  */
 public function __construct($id = null)
 {
     $timer = Debug::getTimer();
     parent::__construct();
     if ($id = filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->populate();
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #16
0
 /**
  * Find events where key = x and optionally value = y
  * @since Version 3.6
  * @param mixed $keys
  * @param mixed $value
  * @param int $limit
  * @return array
  */
 public function find($keys = false, $value = false, $limit = 25)
 {
     $timer = Debug::getTimer();
     if (!$keys) {
         throw new Exception("Cannot find events - \$keys cannot be empty");
         return false;
     }
     $clause = array();
     $where = array();
     if (is_array($keys)) {
         $clause[] = "`key` IN ('" . implode("','", $keys) . "')";
     } elseif (is_string($keys)) {
         $clause[] = $this->db instanceof sql_db ? " `key` = '" . $this->db->real_escape_string($keys) . "'" : " `key` = ?";
         $where[] = $keys;
     }
     if ($value) {
         $clause[] = $this->db instanceof sql_db ? " `value` = '" . $this->db->real_escape_string($value) . "'" : " `value` = ?";
         $where[] = $value;
     }
     if (count($clause)) {
         $sql_where = "WHERE " . implode(" AND ", $clause);
     }
     $query = "SELECT e.id, e.user_id, u.username, e.timestamp, e.title, e.args, e.key, e.value FROM log_general AS e INNER JOIN nuke_users AS u ON u.user_id = e.user_id " . $sql_where . " ORDER BY e.timestamp DESC LIMIT 0, ?";
     $where[] = $limit;
     $return = array();
     foreach ($this->db->fetchAll($query, $where) as $row) {
         $row['timestamp'] = new DateTime($row['timestamp']);
         $row['args'] = json_decode($row['args'], true);
         $return[$row['id']] = $row;
     }
     Debug::logEvent(__METHOD__, $timer);
     return $return;
 }
Example #17
0
 /**
  * Load this object
  * @since Version 3.9.1
  * @return array
  * @param int|string $id
  */
 private function load($id)
 {
     if (!filter_var($id, FILTER_VALIDATE_INT)) {
         $id = $this->db->fetchOne("SELECT id FROM event WHERE slug = ?", $id);
     }
     if (!($id = filter_var($id, FILTER_VALIDATE_INT))) {
         return;
     }
     $this->id = $id;
     $this->mckey = sprintf("railpage:events.event=%d", $this->id);
     $query = "SELECT * FROM event WHERE id = ?";
     if (!($row = $this->Memcached->fetch($this->mckey))) {
         $row = $this->db->fetchRow($query, $this->id);
         Debug::logEvent(__METHOD__ . " - fetched from SQL");
         $this->Memcached->save($this->mckey, $row);
     }
     return $row;
 }
Example #18
0
 /**
  * Commit changes to the database
  * @since Version 3.2
  * @version 3.8.7
  * @return boolean
  */
 public function commit()
 {
     $this->validate();
     $timer = Debug::getTimer();
     $this->flushMemcached();
     $data = array("name" => $this->name, "desc" => $this->desc, "introduced" => $this->introduced, "wheel_arrangement_id" => $this->wheel_arrangement_id, "loco_type_id" => $this->type_id, "manufacturer_id" => $this->manufacturer_id, "flickr_tag" => $this->flickr_tag, "flickr_image_id" => $this->flickr_image_id, "length" => $this->length, "weight" => $this->weight, "axle_load" => $this->axle_load, "tractive_effort" => $this->tractive_effort, "model" => $this->model, "download_id" => empty($this->download_id) ? 0 : $this->download_id, "slug" => empty($this->slug) ? "" : $this->slug, "meta" => json_encode(isset($this->meta) && is_array($this->meta) ? $this->meta : array()));
     if (empty($this->date_added)) {
         $data['date_added'] = time();
     }
     if (!empty($this->date_added)) {
         $data['date_modified'] = time();
     }
     if ($this->Asset instanceof Asset) {
         $data['asset_id'] = $this->Asset->id;
     }
     foreach ($data as $key => $val) {
         if (is_null($val)) {
             $data[$key] = "";
         }
     }
     // Update
     if (filter_var($this->id, FILTER_VALIDATE_INT)) {
         // Update
         $where = array("id = ?" => $this->id);
         $this->db->update("loco_class", $data, $where);
         $verb = "Update";
     }
     // Insert
     if (!filter_var($this->id, FILTER_VALIDATE_INT)) {
         $this->db->insert("loco_class", $data);
         $this->id = intval($this->db->lastInsertId());
         $this->createSlug();
         $this->commit();
         $this->url = new Url($this->makeClassURL($this->slug));
         $this->url->edit = sprintf("%s?mode=class.edit&id=%d", $this->Module->url, $this->id);
         $this->url->addLoco = sprintf("%s?mode=loco.edit&class_id=%d", $this->Module->url, $this->id);
         $verb = "Insert";
     }
     // Update the registry
     $Registry = Registry::getInstance();
     $regkey = sprintf(self::REGISTRY_KEY, $this->id);
     $Registry->set($regkey, $this);
     Debug::logEvent(__METHOD__ . " :: ID " . $this->id, $timer);
     $this->Memcached->delete("railpage:loco.class.bytype=all");
     return true;
 }
Example #19
0
 /**
  * Constructor
  * @since Version 3.2
  * @param int $id
  * @param boolean $recurse
  */
 public function __construct($id = false, $recurse = true)
 {
     parent::__construct();
     $timer = Debug::getTimer();
     Debug::RecordInstance();
     $this->namespace = "railpage.locos.liveries.livery";
     // Fetch any child objects
     $this->recurse = $recurse;
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->url = new Url("/photos/search?livery_id=" . $this->id);
         $this->fetch();
     }
     Debug::logEvent(__METHOD__, $timer);
 }
Example #20
0
 /**
  * Check if a user is a member of this group
  * @since Version 3.7.5
  * @paran int $userId
  * @return boolean
  */
 public function userInGroup($userId = null)
 {
     if ($userId instanceof User) {
         $userId = $userId->id;
     }
     if (!filter_var($userId, FILTER_VALIDATE_INT)) {
         return false;
     }
     $mckey = sprintf("railpage:group=%d.user_id=%d", $this->id, $userId);
     $timer = Debug::getTimer();
     $result = false;
     if (!($result = $this->Redis->fetch($mckey))) {
         $query = "SELECT user_id FROM nuke_bbuser_group WHERE group_id = ? AND user_id = ? AND user_pending = 0";
         $params = [$this->id, $userId];
         $id = $this->db->fetchOne($query, $params);
         if (filter_var($id, FILTER_VALIDATE_INT)) {
             $this->Redis->save($mckey, "yes", strtotime("+1 day"));
             Debug::logEvent(__METHOD__ . " found user ID " . $userId . " in group ID " . $this->id, $timer);
             return true;
         }
     }
     Debug::logEvent(__METHOD__ . " did not find ID " . $userId . " in group ID " . $this->id, $timer);
     return (bool) $result;
 }
Example #21
0
 /**
  * Format an avatar
  * @since Version 3.9.1
  * @return string
  * @param string $userAvatar
  * @param int $width
  * @param width $height
  */
 public static function format($userAvatar = null, $width = 100, $height = 100)
 {
     if (is_null($userAvatar)) {
         return false;
     }
     $cacheHandler = AppCore::getMemcached();
     $timer = Debug::getTimer();
     if ($userAvatar == "http://www.railpage.com.au/modules/Forums/images/avatars/https://static.railpage.com.au/image_resize") {
         $userAvatar = self::DEFAULT_AVATAR;
     }
     if (empty($userAvatar) || stristr($userAvatar, "blank.gif") || stristr($userAvatar, "blank.png")) {
         $userAvatar = self::DEFAULT_AVATAR;
         return $userAvatar;
     }
     $parts = parse_url($userAvatar);
     if (isset($parts['host']) && $parts['host'] == "static.railpage.com.au" && isset($parts['query'])) {
         parse_str($parts['query'], $query);
         if (isset($query['w']) && isset($query['h']) && isset($query['image'])) {
             if ($query['w'] == $width && $query['h'] == $height) {
                 return $userAvatar;
             }
             return sprintf("http://static.railpage.com.au/image_resize.php?w=%d&h=%d&image=%s", $width, $height, $query['image']);
         }
     }
     if (isset($parts['host']) && $parts['host'] == "www.gravatar.com" && isset($parts['query'])) {
         parse_str($parts['query'], $query);
         $query['s'] = $width;
         $bits = array();
         foreach ($query as $key => $val) {
             $bits[] = sprintf("%s=%s", $key, $val);
         }
         $userAvatar = sprintf("%s://%s%s?%s", $parts['scheme'], $parts['host'], $parts['path'], implode("&", $bits));
         return self::GravatarHTTPS($userAvatar);
     }
     $mckey = sprintf("railpage.user:avatar=%s;width=%s;height=%s", $userAvatar, $width, $height);
     /**
      * Check if this shit is in Memcache first
      */
     if ($result = $cacheHandler->fetch($mckey)) {
         return self::GravatarHTTPS($result);
     }
     /**
      * It's not in Memcached, so let's process and cache it
      */
     parse_str(parse_url($userAvatar, PHP_URL_QUERY), $args);
     if (isset($args['base64_args'])) {
         if (!@unserialize(base64_decode($args['base64_args']))) {
             // Malformed string!
             $userAvatar = self::DEFAULT_AVATAR;
         } else {
             // Do other stuff...
             $base64 = unserialize(base64_decode($args['base64_args']));
         }
     }
     if (preg_match("@modules/Forums/images/avatars/(http\\:\\/\\/|https\\:\\/\\/)@", $userAvatar)) {
         $userAvatar = self::DEFAULT_AVATAR;
     }
     if (!preg_match("@(http\\:\\/\\/|https\\:\\/\\/)@", $userAvatar)) {
         $userAvatar = "http://static.railpage.com.au/modules/Forums/images/avatars/" . $userAvatar;
     }
     if (!ContentUtility::url_exists($userAvatar)) {
         $userAvatar = self::DEFAULT_AVATAR;
     }
     if ($width && !$height) {
         $height = $width;
     }
     // Is this an anigif?
     if (substr($userAvatar, -4, 4) == ".gif") {
         // Fetch the dimensions
         $mckey = "railpage:avatar.size=" . md5($userAvatar);
         if ($dimensions = $cacheHandler->fetch($mckey)) {
             // Do nothing
         } else {
             $dimensions = @getimagesize($userAvatar);
             $cacheHandler->save($mckey, $dimensions);
         }
         if (isset($dimensions['mime']) && $dimensions['mime'] == "image/gif") {
             // Great, it's a gif
             if ($width && $height) {
                 if ($dimensions[0] <= $width && $dimensions[1] <= $height) {
                     // It fits within the width and height - return it as-is
                     return self::GravatarHTTPS($userAvatar);
                 }
             }
         }
     }
     // Assume that all avatars created on dev.railpage.com.au are shit and should be re-directed to static.railpage.com.au
     $userAvatar = str_replace("dev.railpage.com.au", "static.railpage.com.au", $userAvatar);
     if ($width && $height) {
         $args['width'] = $width;
         $args['height'] = $height;
         $args['url'] = $userAvatar;
         if (empty($userAvatar)) {
             $args['url'] = self::DEFAULT_AVATAR;
         }
         #$userAvatar = "https://static.railpage.com.au/image_resize.php?base64_args=".base64_encode(serialize($args));
         $userAvatar = sprintf("https://static.railpage.com.au/image_resize.php?w=%d&h=%d&image=%s", $args['width'], $args['height'], $args['url']);
         if ($width == $height) {
             $userAvatar .= "&square=true";
         }
     }
     $cacheHandler->save($mckey, $userAvatar, 0);
     Debug::logEvent(__METHOD__, $timer);
     return self::GravatarHTTPS($userAvatar);
 }
Example #22
0
 /**
  * Format a title
  * @since Version 3.9.1
  * @param string $text
  * @return $text
  */
 public static function FormatTitle($text = NULL)
 {
     if (is_null($text)) {
         return $text;
     }
     $timer = Debug::getTimer();
     Debug::RecordInstance();
     $text = htmlentities($text, ENT_COMPAT, "UTF-8");
     $text = str_replace("&trade;&trade;", "&trade;", $text);
     if (function_exists("html_entity_decode_utf8")) {
         $text = html_entity_decode_utf8($text);
     }
     $text = stripslashes($text);
     if (substr($text, 0, 4) == "Re: ") {
         $text = substr($text, 4, strlen($text));
     }
     if (substr($text, -1) == ".") {
         $text = substr($text, 0, -1);
     }
     Debug::logEvent(__METHOD__, $timer);
     return $text;
 }
Example #23
0
 /**
  * Get an instance of Memcache for legacy code
  * @since Version 3.9.1
  * @return object
  * @param boolean $reload Don't fetch the cache handler from the registry and instead create a new instance
  */
 public static function getMemcache($reload = false)
 {
     if (!extension_loaded("memcache") || defined("PHPUNIT_RAILPAGE_TESTSUITE")) {
         return new NullCacheDriver();
     }
     $Registry = Registry::getInstance();
     if ($reload) {
         $Registry->remove("memcache");
     }
     try {
         $memcache = $Registry->get("memcache");
     } catch (Exception $e) {
         $memcache = false;
         Debug::logEvent(__METHOD__ . " -- Looking for memcache.php");
         if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . "memcache.php")) {
             require __DIR__ . DIRECTORY_SEPARATOR . "memcache.php";
         }
         $Registry->set("memcache", $memcache);
     }
     return $memcache;
 }
 /**
  * Get the ID of the locomotive class slug
  * @since Version 3.9.1
  * @param string $slug
  * @return int
  */
 public static function getClassId($slug)
 {
     $Memcached = AppCore::getMemcached();
     $Database = (new AppCore())->getDatabaseConnection();
     $timer = Debug::getTimer();
     $slugkey = sprintf("railpage:locos.class.id;fromslug=%s", $slug);
     if (!($id = $Memcached->fetch($slugkey))) {
         $id = $Database->fetchOne("SELECT id FROM loco_class WHERE slug = ?", $slug);
         $Memcached->save($slugkey, $id, strtotime("+1 year"));
     }
     Debug::logEvent(__METHOD__, $timer);
     return $id;
 }