/** * Constructor */ public function __construct() { parent::__construct(); Debug::RecordInstance(); /** * Load the Module object */ $this->Module = new Module("glossary"); }
/** * Constructor * * @param string|null $country * @param string|bool $region */ public function __construct($country = null, $region = false) { Debug::RecordInstance(); $timer = Debug::GetTimer(); if (is_null($country)) { throw new InvalidArgumentException("No country was specified"); } parent::__construct(); $this->load($country, $region); Debug::LogEvent(__METHOD__, $timer); }
/** * 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(); if ($event_id) { $this->id = $event_id; $this->fetch(); } }
/** * 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); }
/** * Constructor * * @param string $code */ public function __construct($code) { parent::__construct(); $this->code = $code; $this->url = new Url("/locations/" . strtolower($this->code)); $countries = ISO_3166::get_countries(); if (strlen($this->code) == 2) { $this->name = $countries[$code]['name']; } else { foreach ($countries as $cc => $data) { if (strtolower($data['name']) == strtolower($this->code)) { $this->code = $cc; $this->url = new Url("/locations/" . strtolower($this->code)); $this->name = $data['name']; } } } Debug::RecordInstance(); $timer = Debug::GetTimer(); if (!$this->loadFromCache() || empty($this->name)) { $woe = Place::getWOEData(strtoupper($code)); if (isset($woe['places']['place'][0]['name'])) { $woe = $woe['places']['place'][0]; $data = ["point" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['centroid']['latitude'], $woe['centroid']['longitude'])), "bb_southwest" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['southWest']['latitude'], $woe['boundingBox']['southWest']['longitude'])), "bb_northeast" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['northEast']['latitude'], $woe['boundingBox']['northEast']['longitude'])), "country_code" => $woe['country attrs']['code'], "country_name" => $woe['name'], "timezone" => isset($woe['timezone']) ? $woe['timezone'] : ""]; $this->db->insert("geoplace", $data); $this->name = $woe['name']; $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']; } } /** * Fetch the WOE (Where On Earth) data from Yahoo */ Debug::LogEvent(__METHOD__, $timer); }
/** * 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); }
/** * Constructor * @since Version 3.4 */ public function __construct() { // Placeholder - do nothing for now Debug::RecordInstance(); }
/** * Constructor * @since Version 3.2 * @param int $id * @param int|string $classIdOrSlug * @param string $number */ public function __construct($id = NULL, $classIdOrSlug = NULL, $number = NULL) { parent::__construct(); $timer = Debug::getTimer(); /** * Record this in the debug log */ Debug::RecordInstance(NULL, $id); $this->bootstrap(); if (filter_var($id, FILTER_VALIDATE_INT)) { $this->id = filter_var($id, FILTER_VALIDATE_INT); } else { $this->id = Utility\LocomotiveUtility::getLocoId($classIdOrSlug, $number); } // Load the loco object if (filter_var($this->id, FILTER_VALIDATE_INT)) { $this->fetch(); } $this->id = intval($this->id); Debug::logEvent(sprintf("%s(%d)", __METHOD__, $this->id), $timer); }
/** * Constructor * @since Version 3.0 * @version 3.10.0 */ public function __construct() { $timer = Debug::getTimer(); Debug::RecordInstance(); 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(); } } } Debug::LogEvent(__METHOD__ . "(" . $this->id . ")", $timer); }
/** * Build the Forums ACL * @since Version 3.8.7 * @param boolean $force Force an update of the ACL * @todo Finish this shit */ public function buildACL($force = false) { $Registry = Registry::getInstance(); try { $ForumsACL = $Registry->get("forumsacl"); $this->ZendACL = $ForumsACL; return; } catch (Exception $e) { // F**k it } Debug::RecordInstance(__METHOD__); $timer = Debug::getTimer(); $acl = $Registry->get("acl"); if (!$this->User instanceof User) { throw new Exception("A valid user must be set before the ACL can be built"); } $mckey = "railpage.forums.list"; if ($force || !($forums = $this->Memcached->fetch($mckey))) { $query = "SELECT forum_id FROM nuke_bbforums"; $forums = $this->db->fetchAll($query); $this->Memcached->save($mckey, $forums); } $acl_forums = array(); /** * Add all the forums to the ACL */ foreach ($forums as $row) { $acl_forum_name = sprintf("railpage.forums.forum:%d", $row['forum_id']); $acl_forums[$row['forum_id']] = $acl_forum_name; try { $acl->get($acl_forum_name); } catch (Exception $e) { $acl->addResource(new Zend_Acl_Resource($acl_forum_name)); } } /** * Get the forum permissions from the database */ $a_sql = array("auth_view", "auth_read", "auth_post", "auth_reply", "auth_edit", "auth_delete", "auth_sticky", "auth_announce", "auth_vote", "auth_pollcreate"); $auth_fields = array('auth_view', 'auth_read', 'auth_post', 'auth_reply', 'auth_edit', 'auth_delete', 'auth_sticky', 'auth_announce', 'auth_vote', 'auth_pollcreate'); $query = "SELECT forum_id, " . implode(", ", $a_sql) . ", " . self::AUTH_ACL . " AS auth_mod FROM nuke_bbforums"; $db_acl = array(); foreach ($this->db->fetchAll($query) as $row) { $db_acl[$row['forum_id']] = $row; } /** * Get the group permissions for this user */ $query = "SELECT a.* FROM nuke_bbauth_access AS a WHERE a.group_id IN (SELECT group_id FROM nuke_bbuser_group WHERE user_id = ? AND user_pending = 0)"; $gperms = array(); foreach ($this->db->fetchAll($query, $this->User->id) as $perm) { $forum_id = $perm['forum_id']; $group_id = $perm['group_id']; unset($perm['forum_id']); unset($perm['group_id']); $gperms[$forum_id][$group_id] = $perm; } /** * Guest details */ $guestfucknamingthis = [self::AUTH_MOD => $this->User->inGroup(RP_GROUP_MODERATORS), self::AUTH_ADMIN => $this->User->inGroup(RP_GROUP_ADMINS)]; /** * Add the forum permissions to Zend_ACL */ foreach ($db_acl as $forum_id => $permissions) { $allowed = array(); $denied = array(); unset($permissions['forum_id']); $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_ALL)); if (!$this->User->guest) { $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_REG)); } if ($guestfucknamingthis[self::AUTH_MOD]) { $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_MOD)); } if ($guestfucknamingthis[self::AUTH_ADMIN]) { $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_ADMIN)); } $perms_acl = array_keys($permissions, self::AUTH_ACL); if (count($perms_acl)) { if (isset($gperms[$forum_id])) { foreach ($gperms[$forum_id] as $group) { foreach ($group as $gitem => $gval) { $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_REG)); if ($guestfucknamingthis[self::AUTH_MOD]) { $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_MOD)); } if ($guestfucknamingthis[self::AUTH_ADMIN]) { $allowed = array_merge($allowed, array_keys($permissions, self::AUTH_ADMIN)); } } } } } $allowed = array_unique($allowed); #continue; /* foreach ($permissions as $item => $value) { switch ($value) { case self::AUTH_ACL . "zzz" : if (isset($gperms[$forum_id])) { foreach ($gperms[$forum_id] as $group) { foreach ($group as $gitem => $gval) { switch ($gval) { case self::AUTH_REG : $allowed[] = $item; break; case self::AUTH_ACL : // Inception break; case self::AUTH_MOD : if ($this->User->inGroup(RP_GROUP_MODERATORS)) { $allowed[] = $gitem; } break; case self::AUTH_ADMIN : if ($this->User->inGroup(RP_GROUP_ADMINS)) { $allowed[] = $gitem; } break; } } } } break; case self::AUTH_MOD . "zzz": if ($this->User->inGroup(RP_GROUP_MODERATORS)) { $allowed[] = $item; } break; case self::AUTH_ADMIN . "zzz" : if ($this->User->inGroup(RP_GROUP_ADMINS)) { $allowed[] = $item; } break; } } */ foreach ($permissions as $item => $value) { if (!in_array($item, $allowed)) { $denied[] = $item; } } #$allowed = array_unique($allowed); #$denied = array_unique($denied); $acl->allow("forums_viewer", sprintf("railpage.forums.forum:%d", $forum_id), $allowed); $acl->deny("forums_viewer", sprintf("railpage.forums.forum:%d", $forum_id), $denied); } $Registry->set("acl", $acl); $Registry->set("forumsacl", $acl); $this->ZendACL = $acl; Debug::LogEvent(__METHOD__, $timer); return; }
/** * Populate this image object * * @since Version 3.9.1 * @return void * * @param int $option */ private function load($option = null) { Debug::RecordInstance(); $this->mckey = sprintf("railpage:image=%d", $this->id); if (defined("NOREDIS") && NOREDIS == true || !($row = $this->Redis->fetch($this->mckey))) { Debug::LogCLI("Fetching data for " . $this->id . " from database"); $query = "SELECT i.title, i.description, i.id, i.provider, i.photo_id, i.modified, i.meta, i.lat, i.lon, i.user_id, i.geoplace, i.captured FROM image AS i WHERE i.id = ?"; $row = $this->db->fetchRow($query, $this->id); $row['meta'] = json_decode($row['meta'], true); $this->Redis->save($this->mckey, $row, strtotime("+24 hours")); } $this->populateFromArray($row); 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; } } if (!isset($row['user_id'])) { $row['user_id'] = 0; } /** * Update the database row */ if ((!isset($row['title']) || empty($row['title']) || is_null($row['title'])) && !empty($this->title) || (!isset($row['description']) || empty($row['description']) || is_null($row['description'])) && !empty($this->description)) { $row['title'] = $this->title; $row['description'] = $this->description; $this->Redis->save($this->mckey, $row, strtotime("+24 hours")); $this->commit(); } /** * Load the author. If we don't know who it is, attempt to re-populate the data */ if (isset($row['meta']['author'])) { $this->author = json_decode(json_encode($row['meta']['author'])); if (isset($this->author->railpage_id) && $row['user_id'] === 0) { $row['user_id'] == $this->author->railpage_id; } if (filter_var($row['user_id'], FILTER_VALIDATE_INT)) { $this->author->User = UserFactory::CreateUser($row['user_id']); } } else { Debug::LogCLI("No author found in local cache - refreshing from " . $this->provider); Debug::LogEvent("No author found in local cache - refreshing from " . $this->provider); $this->populate(true, $option); } /** * Unless otherwise instructed load the places object if lat/lng are present */ if ($option != Images::OPT_NOPLACE && round($row['lat'], 3) != "0.000" && round($row['lon'], 3) != "0.000") { try { $this->Place = Place::Factory($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": if (function_exists("base58_encode")) { $this->source = "https://flic.kr/p/" . base58_encode($this->photo_id); } } } /** * Create an array/JSON object */ $this->getJSON(); }
/** * 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("™™", "™", $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; }
/** * 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 = null) { parent::__construct(); Debug::RecordInstance(); $timer = Debug::getTimer(); $this->Module = new Module("events"); $this->namespace = $this->Module->namespace; if ($id != null) { $this->populate($id); } Debug::logEvent(__METHOD__, $timer); }
/** * Constructor * @since Version 3.2 * @param int|string $idOrSlug * @param boolean $recurse */ public function __construct($idOrSlug = null, $recurse = null) { parent::__construct(); $timer = Debug::getTimer(); /** * Record this in the debug log */ Debug::RecordInstance(); $this->getTemplates(); $this->namespace = sprintf("%s.%s", $this->Module->namespace, "class"); if ($recurse == null) { $recurse = false; } // Set the ID if (filter_var($idOrSlug, FILTER_VALIDATE_INT) || $idOrSlug != null) { $this->id = $idOrSlug; $this->fetch($recurse); } Debug::logEvent(__METHOD__, $timer); }
/** * 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); }