|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use phpweb\News\ConferenceSchedule; |
3 | 4 | use phpweb\News\NewsHandler; |
4 | 5 |
|
5 | 6 | $_SERVER['BASE_PAGE'] = 'conferences/index.php'; |
|
14 | 15 | 'css' => ['home.css'], |
15 | 16 | ]); |
16 | 17 |
|
17 | | -$content = "<div class='home-content'>"; |
18 | | -$panels = '<p class="prepend"><a href="https://wiki.php.net/conferences">Want to see your conference appear here?</a></p>'; |
| 18 | +$today = gmdate('Y-m-d'); |
| 19 | +$schedule = new ConferenceSchedule((new NewsHandler())->getConferences(), $today); |
| 20 | + |
| 21 | +// The page has two views, switched via ?view=: the default view, which lists |
| 22 | +// conferences only (targeted at attendees/sponsors), and the call-for-papers |
| 23 | +// view, which lists CFPs only, split into open and closed (targeting speakers). |
| 24 | +$view = ($_GET['view'] ?? null) === 'cfps' ? 'cfps' : 'conferences'; |
| 25 | + |
| 26 | +// Build nav for switching between views |
| 27 | +$viewLinks = [ |
| 28 | + 'conferences' => ['label' => 'Conferences', 'href' => '/conferences/'], |
| 29 | + 'cfps' => ['label' => 'Calls for papers', 'href' => '/conferences/?view=cfps'], |
| 30 | +]; |
| 31 | + |
| 32 | +$viewSwitcher = '<nav class="conference-views" aria-label="Conference views">'; |
| 33 | +foreach ($viewLinks as $key => $viewLink) { |
| 34 | + $isActive = $key === $view; |
| 35 | + $viewSwitcher .= sprintf( |
| 36 | + '<a class="conference-view%s" href="%s"%s>%s</a>', |
| 37 | + $isActive ? ' is-active' : '', |
| 38 | + $viewLink['href'], |
| 39 | + $isActive ? ' aria-current="page"' : '', |
| 40 | + $viewLink['label'], |
| 41 | + ); |
| 42 | +} |
| 43 | +$viewSwitcher .= '</nav>'; |
19 | 44 |
|
20 | | -foreach ((new NewsHandler())->getConferences() as $entry) { |
| 45 | +$renderEntry = static function (array $entry) use ($MYSITE, $today): string { |
21 | 46 | $link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '', $entry["id"]); |
22 | 47 | $id = parse_url($entry["id"], PHP_URL_FRAGMENT); |
23 | | - $date = date_format(date_create($entry["updated"] ?? $entry["published"]), 'Y-m-d'); |
24 | | - $content .= '<div class="newsentry">'; |
25 | | - $content .= '<h3 class="newstitle title"><a href="' . $MYSITE . $link . '" id="' . $id . '">' . $entry["title"] . '</a></h3>'; |
26 | | - $content .= '<div class="newsimage">'; |
| 48 | + |
| 49 | + $html = '<div class="newsentry">'; |
| 50 | + $html .= '<h3 class="newstitle title"><a href="' . $MYSITE . $link . '" id="' . $id . '">' . $entry["title"] . '</a></h3>'; |
| 51 | + |
| 52 | + if (isset($entry["finalTeaserDate"])) { |
| 53 | + $isPast = $entry["finalTeaserDate"] < $today; |
| 54 | + if (ConferenceSchedule::termFor($entry) === 'cfp') { |
| 55 | + $label = $isPast ? 'CFP closed' : 'CFP closes'; |
| 56 | + } else { |
| 57 | + $label = $isPast ? 'Started' : 'Starts'; |
| 58 | + } |
| 59 | + $html .= '<p class="newsdate">' . $label . ' <time datetime="' . $entry["finalTeaserDate"] . '">' . date_format(date_create($entry["finalTeaserDate"]), 'd M Y') . '</time></p>'; |
| 60 | + } |
| 61 | + |
| 62 | + $html .= '<div class="newsimage">'; |
27 | 63 |
|
28 | 64 | if (isset($entry["newsImage"])) { |
29 | | - $content .= sprintf('<a href="%s"><img src="/images/news/%s"></a>', $entry["newsImage"]["link"], $entry["newsImage"]["content"]); |
| 65 | + $html .= sprintf('<a href="%s"><img src="/images/news/%s"></a>', $entry["newsImage"]["link"], $entry["newsImage"]["content"]); |
30 | 66 | } |
31 | 67 |
|
32 | | - $content .= '</div>'; |
33 | | - $content .= '<div class="newscontent">'; |
34 | | - $content .= $entry["content"]; |
35 | | - $content .= '</div>'; |
36 | | - $content .= '</div>'; |
| 68 | + $html .= '</div>'; |
| 69 | + $html .= '<div class="newscontent">'; |
| 70 | + $html .= $entry["content"]; |
| 71 | + $html .= '</div>'; |
| 72 | + $html .= '</div>'; |
| 73 | + |
| 74 | + return $html; |
| 75 | +}; |
| 76 | + |
| 77 | +$content = "<div class='home-content'>"; |
| 78 | +$content .= $viewSwitcher; |
| 79 | + |
| 80 | +if ($view === 'cfps') { |
| 81 | + $content .= '<h2>Open calls for papers</h2>'; |
| 82 | + |
| 83 | + if ($schedule->openCallsForPapers === []) { |
| 84 | + $content .= '<p>No open calls for papers right now.</p>'; |
| 85 | + } else { |
| 86 | + foreach ($schedule->openCallsForPapers as $entry) { |
| 87 | + $content .= $renderEntry($entry); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + if ($schedule->closedCallsForPapers !== []) { |
| 92 | + $content .= '<h2 class="conferences-divider">Closed calls for papers</h2>'; |
| 93 | + |
| 94 | + foreach ($schedule->closedCallsForPapers as $entry) { |
| 95 | + $content .= $renderEntry($entry); |
| 96 | + } |
| 97 | + } |
| 98 | +} else { |
| 99 | + $content .= '<h2>Upcoming conferences</h2>'; |
37 | 100 |
|
38 | | - $panels .= sprintf('<p class="panel"><a href="%s">%s</a></p>', $entry["newsImage"]["link"] ?? $link, $entry["title"]); |
| 101 | + if ($schedule->upcomingConferences === []) { |
| 102 | + $content .= '<p>No upcoming conferences right now.</p>'; |
| 103 | + } else { |
| 104 | + foreach ($schedule->upcomingConferences as $entry) { |
| 105 | + $content .= $renderEntry($entry); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + if ($schedule->pastConferences !== []) { |
| 110 | + $content .= '<h2 class="conferences-divider">Past conferences</h2>'; |
| 111 | + |
| 112 | + foreach ($schedule->pastConferences as $entry) { |
| 113 | + $content .= $renderEntry($entry); |
| 114 | + } |
| 115 | + } |
39 | 116 | } |
| 117 | + |
40 | 118 | $content .= "</div>"; |
41 | 119 |
|
42 | 120 | echo $content; |
43 | 121 |
|
| 122 | +// Build sidebar mirroring the active view: conferences grouped into upcoming/past, or CFPs into open/closed. |
| 123 | +$panels = '<p class="prepend"><a href="https://wiki.php.net/conferences">Want to see your conference appear here?</a></p>'; |
| 124 | + |
| 125 | +$renderPanels = static function (array $entries): string { |
| 126 | + $html = ''; |
| 127 | + foreach ($entries as $entry) { |
| 128 | + $link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '', $entry["id"]); |
| 129 | + $html .= sprintf('<p class="panel"><a href="%s">%s</a></p>', $entry["newsImage"]["link"] ?? $link, $entry["title"]); |
| 130 | + } |
| 131 | + |
| 132 | + return $html; |
| 133 | +}; |
| 134 | + |
| 135 | +if ($view === 'cfps') { |
| 136 | + if ($schedule->openCallsForPapers !== []) { |
| 137 | + $panels .= '<h3>Open</h3>' . $renderPanels($schedule->openCallsForPapers); |
| 138 | + } |
| 139 | + |
| 140 | + if ($schedule->closedCallsForPapers !== []) { |
| 141 | + $panels .= '<h3>Closed</h3>' . $renderPanels($schedule->closedCallsForPapers); |
| 142 | + } |
| 143 | +} else { |
| 144 | + if ($schedule->upcomingConferences !== []) { |
| 145 | + $panels .= '<h3>Upcoming</h3>' . $renderPanels($schedule->upcomingConferences); |
| 146 | + } |
| 147 | + |
| 148 | + if ($schedule->pastConferences !== []) { |
| 149 | + $panels .= '<h3>Past</h3>' . $renderPanels($schedule->pastConferences); |
| 150 | + } |
| 151 | +} |
| 152 | + |
44 | 153 | site_footer([ |
45 | 154 | "atom" => "/feed.atom", |
46 | 155 | "elephpants" => true, |
|
0 commit comments