Skip to content

Create phpweb\News\NewsHandler class to handle pregen-news.inc #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion archive/2013.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

$_SERVER['BASE_PAGE'] = 'archive/2013.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2013", ["cache" => true]);
?>
Expand Down
1 change: 0 additions & 1 deletion archive/2014.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

$_SERVER['BASE_PAGE'] = 'archive/2014.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2014", ["cache" => true]);
?>
Expand Down
5 changes: 3 additions & 2 deletions archive/2015.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2015.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2015");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, ["conferences", "cfp", "frontpage", "nofrontpage"], 500, 2015);
print_news((new NewsHandler())->getNewsByYear(2015), ["conferences", "cfp", "frontpage", "nofrontpage"], 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2016.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2016.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2016");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, ["conferences", "cfp", "frontpage", "nofrontpage"], 500, 2016);
print_news((new NewsHandler())->getNewsByYear(2016), ["conferences", "cfp", "frontpage", "nofrontpage"], 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2017.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2017.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2017");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2017);
print_news((new NewsHandler())->getNewsByYear(2017), null, 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2018.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2018.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2018");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2018);
print_news((new NewsHandler())->getNewsByYear(2018), null, 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2019.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2019.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2019");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2019);
print_news((new NewsHandler())->getNewsByYear(2019), null, 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2020.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2020.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2020");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2020);
print_news((new NewsHandler())->getNewsByYear(2020), null, 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2021.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2021.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2021");
?>
Expand All @@ -17,7 +18,7 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2021);
print_news((new NewsHandler())->getNewsByYear(2021), null, 500);

/* %s/<a href="\(.*\)"><img src="\/images\/news\/\(.*\)" alt="\(.*\)" width.*><\/a>/<?php news_image("\1", "\2", "\3"); ?>/g */
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2022.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2022.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2022");
?>
Expand All @@ -17,5 +18,5 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2022);
print_news((new NewsHandler())->getNewsByYear(2022), null, 500);
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2023.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2023.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2023");
?>
Expand All @@ -17,5 +18,5 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2023);
print_news((new NewsHandler())->getNewsByYear(2023), null, 500);
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2024.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2024.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2024");
?>
Expand All @@ -17,5 +18,5 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2024);
print_news((new NewsHandler())->getNewsByYear(2024), null, 500);
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
5 changes: 3 additions & 2 deletions archive/2025.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'archive/2025.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';
news_archive_sidebar();
site_header("News Archive - 2025");
?>
Expand All @@ -17,5 +18,5 @@

<?php

print_news($NEWS_ENTRIES, null, 500, 2025);
print_news((new NewsHandler())->getNewsByYear(2025), null, 500);
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);
18 changes: 3 additions & 15 deletions conferences/index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use phpweb\News\NewsHandler;

$_SERVER['BASE_PAGE'] = 'conferences/index.php';
include_once __DIR__ . '/../include/prepend.inc';
include_once __DIR__ . '/../include/pregen-news.inc';

mirror_setcookie("LAST_NEWS", $_SERVER["REQUEST_TIME"], 60 * 60 * 24 * 365);
site_header("PHP Conferences around the world", [
Expand All @@ -12,22 +13,9 @@
]);

$content = "<div class='home-content'>";
$frontpage = [];
foreach ($NEWS_ENTRIES as $entry) {
foreach ($entry["category"] as $category) {
if ($category["term"] == "cfp") {
$frontpage[] = $entry;
break;
}
if ($category["term"] == "conferences") {
$frontpage[] = $entry;
break;
}
}
}
$panels = '<p class="prepend"><a href="https://wiki.php.net/conferences">Want to see your conference appear here?</a></p>';

foreach ($frontpage as $entry) {
foreach ((new NewsHandler())->getConferences() as $entry) {
$link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '', $entry["id"]);
$id = parse_url($entry["id"], PHP_URL_FRAGMENT);
$date = date_format(date_create($entry["updated"]), 'Y-m-d');
Expand Down
19 changes: 10 additions & 9 deletions include/layout.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use phpweb\I18n\Languages;
use phpweb\Navigation\NavItem;
use phpweb\News\NewsHandler;

$_SERVER['STATIC_ROOT'] = $MYSITE;
$_SERVER['MYSITE'] = $MYSITE;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
16 changes: 3 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use phpweb\News\NewsHandler;

(function ($uri): void {
// Special redirect cases not able to be captured in error.php
$shortcuts = [
Expand Down Expand Up @@ -51,24 +53,12 @@
include_once 'include/prepend.inc';
include_once 'include/branches.inc';
include_once 'include/pregen-confs.inc';
include_once 'include/pregen-news.inc';
include_once 'include/version.inc';

mirror_setcookie("LAST_NEWS", $_SERVER["REQUEST_TIME"], 60 * 60 * 24 * 365);

$content = "<div class='home-content'>";
$frontpage = [];
foreach ($NEWS_ENTRIES as $entry) {
foreach ($entry["category"] as $category) {
if ($category["term"] == "frontpage") {
$frontpage[] = $entry;
if (count($frontpage) >= 25) {
break 2;
}
}
}
}
foreach ($frontpage as $entry) {
foreach ((new NewsHandler())->getFrontPageNews() as $entry) {
$link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '', $entry["id"]);
$id = parse_url($entry["id"], PHP_URL_FRAGMENT);
$date = date_create($entry['updated']);
Expand Down
Loading