mirror of
https://github.com/php/web-php.git
synced 2026-03-23 23:02:13 +01:00
Create phpweb\News\NewsHandler class to handle pregen-news.inc (#1288)
This commit is contained in:
committed by
GitHub
parent
a3cac2b411
commit
35d6a900ac
@@ -2,6 +2,7 @@
|
||||
|
||||
use phpweb\I18n\Languages;
|
||||
use phpweb\Navigation\NavItem;
|
||||
use phpweb\News\NewsHandler;
|
||||
|
||||
$_SERVER['STATIC_ROOT'] = $MYSITE;
|
||||
$_SERVER['MYSITE'] = $MYSITE;
|
||||
@@ -346,7 +347,7 @@ function news_archive_sidebar(): void
|
||||
}
|
||||
|
||||
// Print news
|
||||
function print_news($news, $dog, $max = 5, $onlyyear = null, $return = false) {
|
||||
function print_news($news, $dog, $max = 5, $return = false) {
|
||||
$retval = [];
|
||||
$count = 0;
|
||||
$news = $news ?: []; // default to empty array (if no news)
|
||||
@@ -391,10 +392,6 @@ function print_news($news, $dog, $max = 5, $onlyyear = null, $return = false) {
|
||||
$published = substr($item["published"], 0, 10);
|
||||
$nixtimestamp = strtotime($published);
|
||||
$newsdate = date("d M Y", $nixtimestamp);
|
||||
if ($onlyyear && date("Y", $nixtimestamp) != $onlyyear) {
|
||||
$count--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($return) {
|
||||
$retval[] = [
|
||||
@@ -518,8 +515,12 @@ function get_nav_items(): array {
|
||||
|
||||
function get_news_changes()
|
||||
{
|
||||
include __DIR__ . "/pregen-news.inc";
|
||||
$date = date_create($NEWS_ENTRIES[0]["updated"]);
|
||||
$lastNews = (new NewsHandler())->getLastestNews();
|
||||
if ($lastNews === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$date = date_create($lastNews["updated"]);
|
||||
if (isset($_COOKIE["LAST_NEWS"]) && $_COOKIE["LAST_NEWS"] >= $date->getTimestamp()) {
|
||||
return false;
|
||||
}
|
||||
@@ -534,8 +535,8 @@ function get_news_changes()
|
||||
|
||||
$date->modify("+1 week");
|
||||
if ($date->getTimestamp() > $_SERVER["REQUEST_TIME"]) {
|
||||
$link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '/', $NEWS_ENTRIES[0]["link"][0]["href"]);
|
||||
$title = $NEWS_ENTRIES[0]["title"];
|
||||
$link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '/', $lastNews["link"][0]["href"]);
|
||||
$title = $lastNews["title"];
|
||||
return "<a href='{$link}'>{$title}</a>";
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user