/** * Return a news article * @since Version 3.9.1 * @return \Railpage\News\Article * @param int|string $id */ public static function CreateArticle($id) { $Redis = AppCore::getRedis(); $Memcached = AppCore::getMemcached(); $Registry = Registry::getInstance(); /** * Lookup article slug-to-ID first */ if (!filter_var($id, FILTER_VALIDATE_INT)) { $mckey = sprintf("railpage:news.article_slug=%s", $id); if (!($article_id = $Memcached->fetch($mckey))) { $Database = AppCore::getDatabase(); $article_id = $Database->fetchOne("SELECT sid FROM nuke_stories WHERE slug = ?", $id); } if (!filter_var($article_id, FILTER_VALIDATE_INT)) { throw new Exception("Could not find an article ID matching URL slug " . $id); } $id = $article_id; } /** * We have an integer article ID, so go ahead and load it */ $regkey = sprintf(Article::REGISTRY_KEY, $id); try { $Article = $Registry->get($regkey); } catch (Exception $e) { if ($Article = $Redis->fetch($regkey)) { $Article->Memcached = $Memcached; $Article->Redis = $Redis; $Database = AppCore::getDatabase(); $Article->setDatabaseConnection($Database)->setDatabaseReadOnlyConnection($Database); } else { $Article = new Article($id); $Redis->save($regkey, $Article); } $Registry->set($regkey, $Article); } return $Article; }
/** * Get last newsletter dispatch date * @since Version 3.10.0 * @param \Railpage\Users\User $User * @return \DateTime */ public static function lastWeeklyDispatchDate(User $User) { $query = "SELECT newsletter_weekly_last FROM nuke_users_flags WHERE user_id = ?"; $date = AppCore::getDatabase()->fetchOne($query, $User->id); if ($date) { return new DateTime($date); } return false; }