/** * Process bbcode inside a string * @since Version 3.10.0 * @param string|DOMDocument $string The HTML or text block to process * @return DOMDocument */ public static function Process($string, $doBbcode = true) { if (!$doBbcode) { return $string; } $timer = Debug::getTimer(); /** * Pre-process the string before we send it through the BBCode parser */ $string = self::preProcessBBCodeUIDs($string); $parser = new Decoda($string); $parser->addPath(__DIR__ . DIRECTORY_SEPARATOR . 'BbcodeEtc' . DIRECTORY_SEPARATOR); $emoticonConfig = ['path' => '//static.railpage.com.au/images/smiles/', 'extension' => 'gif']; $engine = new DecodaPhpEngine(); $engine->addPath(__DIR__ . DIRECTORY_SEPARATOR . 'BbcodeEtc' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR); $parser->setEngine($engine); $parser->defaults(); $parser->setStrict(false); $parser->setLineBreaks(false); $parser->removeHook('Emoticon'); $parser->addFilter(new RailpageImageFilter()); $string = $parser->parse(); $string = html_entity_decode($string); // Fix: if I set escapeHtml in the Decoda options, it fails to auto linkify links //$string = wpautop($string); Debug::LogEvent(__METHOD__, $timer); return $string; }
/** * 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); }
/** * Process emoticons inside a string * @since Version 3.10.0 * @param string|DOMDocument $string The HTML or text block to process * @param boolean $doEmoticons Boolean flag for processing or skipping emoticons * @return DOMDocument */ public static function Process($string, $doEmoticons = true) { if (!$doEmoticons) { return $string; } $emojiOne = new EmojioneClient(new EmoticonsRuleset()); $emojiOne->ascii = true; $string = $emojiOne->toImage($string); $attr = "data-sceditor-emoticon"; $timer = Debug::getTimer(); if (is_string($string)) { $string = phpQuery::newDocumentHTML($string); } //phpQuery::selectDocument($doc); // Remove #tinymce and .mceContentBody tags foreach (pq('img') as $e) { if (pq($e)->attr($attr)) { $emoticon = pq($e)->attr($attr); if (strlen($emoticon) > 0) { pq($e)->replaceWith(str_replace('\\"', "", $emoticon)); } } } Debug::LogEvent(__METHOD__, $timer); return $string; }
/** * 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; }
/** * 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); }
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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Strip headers from within a block of text * @param string|DOMDocument $string * @return DOMDocument */ public static function removeHeaders($string) { $timer = Debug::getTimer(); if (is_string($string)) { $string = phpQuery::newDocumentHTML($string); } foreach (pq('h1') as $e) { pq($e)->replaceWith("<p><strong>" . pq($e)->text() . "</strong></p>"); } foreach (pq('h2') as $e) { pq($e)->replaceWith("<p><strong>" . pq($e)->text() . "</strong></p>"); } foreach (pq('h3') as $e) { pq($e)->replaceWith("<p><strong>" . pq($e)->text() . "</strong></p>"); } Debug::LogEvent(__METHOD__, $timer); return $string; }
/** * 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.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); }
/** * 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; }
/** * Populate the user object * @since Version 3.0.1 * @version 3.0.1 * @return boolean * * @param int $userId */ public function load($userId = false) { if (filter_var($userId, FILTER_VALIDATE_INT)) { $this->id = $userId; } // Get out early if (!filter_var($this->id, FILTER_VALIDATE_INT)) { return false; } $timer = Debug::getTimer(); $this->createUrls(); Debug::logEvent(__METHOD__ . " - createUrls() completed", $timer); $this->mckey = sprintf("railpage:user_id=%d", $this->id); $cached = false; $timer = Debug::getTimer(); /** * Load the User data from Redis first */ if ($data = $this->Redis->fetch($this->mckey)) { $cached = true; Debug::logEvent(__METHOD__ . "(" . $this->id . ") loaded via Redis", $timer); } /** * I f****d up before, so validate the redis data before we continue... */ if (!is_array($data) || empty($data) || count($data) === 1) { $timer = Debug::getTimer(); $data = Utility\UserUtility::fetchFromDatabase($this); Debug::logEvent(__METHOD__ . "(" . $this->id . ") loaded via ZendDB", $timer); } /** * Process some of the returned values */ $data = Utility\UserUtility::normaliseAvatarPath($data); $data = Utility\UserUtility::setDefaults($data, $this); /** * Start setting the class vars */ $this->getGroups(); $this->provider = $data['provider']; $this->preferences = json_decode($data['user_opts']); $this->guest = false; $this->theme = $data['theme']; $this->rank_id = $data['user_rank']; $this->rank_text = $data['rank_title']; $this->timezone = $data['timezone']; $this->website = $data['user_website']; $this->hide = $data['user_allow_viewonline']; $this->meta = json_decode($data['meta'], true); if (json_last_error() != JSON_ERROR_NONE || !is_array($this->meta)) { $this->meta = array(); } if (isset($data['password_new'])) { $this->password_new = $data['password_new']; } $this->session_last_nice = date($this->date_format, $this->lastvisit); $this->contact_email_public = (bool) $this->contact_email_public ? $this->contact_email : $data['femail']; $this->reputation = '100% (+' . $this->wheat . '/' . $this->chaff . '-)'; if (intval($this->wheat) > 0) { $this->reputation = number_format($this->chaff / $this->wheat / 2 * 100, 1) . '% (+' . $this->wheat . '/' . $this->chaff . '-)'; } /** * Map database fields to class vars */ $fields = Utility\UserUtility::getColumnMapping(); foreach ($fields as $key => $var) { $this->{$var} = $data[$key]; } /** * Update the user registration date if required */ Utility\UserMaintenance::checkUserRegdate($data); $this->RegistrationDate = new DateTime($data['user_regdate_nice']); /** * Fetch the last IP address from the login logs */ $this->getLogins(1); $this->warning_level_colour = Utility\UserUtility::getWarningBarColour($this->warning_level); if (isset($data['oauth_key']) && isset($data['oauth_secret'])) { $this->oauth_key = $data['oauth_key']; $this->oauth_secret = $data['oauth_secret']; } $this->oauth_id = $data['oauth_consumer_id']; // Bugfix for REALLY old accounts with a NULL user_level if (!filter_var($this->level, FILTER_VALIDATE_INT) && $this->active == 1) { $this->level = 1; } $this->verifyAPI(); /** * Set some default values for $this->preferences */ $this->preferences = json_decode(json_encode($this->getPreferences())); if (!$cached) { $this->Redis->save($this->mckey, $data, strtotime("+6 hours")); } return true; }
/** * 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); }
/** * 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); }
/** * 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.8.7 * * @param int $id * @param int $option */ public function __construct($id = null, $option = null) { parent::__construct(); $timer = Debug::getTimer(); $this->GuzzleClient = new Client(); $this->Module = new Module("images"); if ($this->id = filter_var($id, FILTER_VALIDATE_INT)) { $this->load($option); } Debug::logEvent(__METHOD__, $timer); }
/** * 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); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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; }