1<?php 2 3(function ($uri): void { 4 // Special redirect cases not able to be captured in error.php 5 $shortcuts = [ 6 '/?:' => '/language.operators.comparison#language.operators.comparison.ternary', 7 '/??' => '/language.operators.comparison#language.operators.comparison.coalesce', 8 '/??=' => '/language.operators.assignment#language.operators.assignment.other', 9 ]; 10 if (isset($shortcuts[$uri])) { 11 header("Location: {$shortcuts[$uri]}"); 12 exit; 13 } 14})($_SERVER['REQUEST_URI'] ?? ''); 15 16// Get the modification date of this PHP file 17$timestamps = [@getlastmod()]; 18 19/* 20 The date of prepend.inc represents the age of ALL 21 included files. Please touch it if you modify any 22 other include file (and the modification affects 23 the display of the index page). The cost of stat'ing 24 them all is prohibitive. 25*/ 26$timestamps[] = @filemtime("include/prepend.inc"); 27 28// These are the only dynamic parts of the frontpage 29$timestamps[] = @filemtime("include/pregen-confs.inc"); 30$timestamps[] = @filemtime("include/pregen-news.inc"); 31$timestamps[] = @filemtime("include/version.inc"); 32$timestamps[] = @filemtime("js/common.js"); 33 34// The latest of these modification dates is our real Last-Modified date 35$timestamp = max($timestamps); 36 37// Note that this is not a RFC 822 date (the tz is always GMT) 38$tsstring = gmdate("D, d M Y H:i:s ", $timestamp) . "GMT"; 39 40// Check if the client has the same page cached 41if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && 42 ($_SERVER["HTTP_IF_MODIFIED_SINCE"] == $tsstring)) { 43 header("HTTP/1.1 304 Not Modified"); 44 exit(); 45} 46 47// Inform the user agent what is our last modification date 48header("Last-Modified: " . $tsstring); 49 50$_SERVER['BASE_PAGE'] = 'index.php'; 51include_once 'include/prepend.inc'; 52include_once 'include/branches.inc'; 53include_once 'include/pregen-confs.inc'; 54include_once 'include/pregen-news.inc'; 55include_once 'include/version.inc'; 56 57mirror_setcookie("LAST_NEWS", $_SERVER["REQUEST_TIME"], 60 * 60 * 24 * 365); 58 59$content = "<div class='home-content'>"; 60$frontpage = []; 61foreach ($NEWS_ENTRIES as $entry) { 62 foreach ($entry["category"] as $category) { 63 if ($category["term"] == "frontpage") { 64 $frontpage[] = $entry; 65 if (count($frontpage) >= 25) { 66 break 2; 67 } 68 } 69 } 70} 71foreach ($frontpage as $entry) { 72 $link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '', $entry["id"]); 73 $id = parse_url($entry["id"], PHP_URL_FRAGMENT); 74 $date = date_create($entry['updated']); 75 $date_human = date_format($date, 'd M Y'); 76 $date_w3c = date_format($date, DATE_W3C); 77 $content .= <<<NEWSENTRY 78<article class="newsentry"> 79 <header class="title"> 80 <time datetime="$date_w3c">$date_human</time> 81 <h2 class="newstitle"> 82 <a href="{$MYSITE}{$link}" id="{$id}">{$entry["title"]}</a> 83 </h2> 84 </header> 85 <div class="newscontent"> 86 {$entry["content"]} 87 </div> 88</article> 89NEWSENTRY; 90} 91$content .= '<p class="archive"><a href="/archive/">Older News Entries</a></p>'; 92$content .= "</div>"; 93 94$intro = <<<EOF 95 <div class="hero"> 96 <img class="hero__logo" src="/images/logos/php-logo-white.svg" alt="php" width="240" height="120"> 97 <p class="hero__text">A <strong>popular general-purpose scripting language</strong> that is especially suited to web development.<br />Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.</p> 98 <div class="hero__actions"> 99 <a href="/releases/8.4/index.php" class="hero__btn hero__btn--primary">What's new in 8.4</a> 100 <a href="/downloads.php" class="hero__btn hero__btn--secondary">Download</a> 101 </div> 102EOF; 103 104$intro .= "<ul class='hero__versions'>\n"; 105$active_branches = get_active_branches(); 106krsort($active_branches); 107foreach ($active_branches as $major => $releases) { 108 krsort($releases); 109 foreach ((array)$releases as $release) { 110 $version = $release['version']; 111 [$major, $minor, $_] = explode('.', $version); 112 $intro .= " 113 <li class='hero__version'><a class='hero__version-link' href='/downloads.php#v$version'>$version</a> · <a class='notes' href='/ChangeLog-$major.php#$version'>Changelog</a> · <a class='notes' href='/migration$major$minor'>Upgrading</a></li>\n"; 114 } 115} 116$intro .= "</ul>\n"; 117$intro .= <<<EOF 118 </div> 119EOF; 120 121site_header("Hypertext Preprocessor", 122 [ 123 'current' => 'home', 124 'headtags' => [ 125 '<link rel="alternate" type="application/atom+xml" title="PHP: Hypertext Preprocessor" href="' . $MYSITE . 'feed.atom">', 126 '<script>', 127 "function okc(f){var c=[38,38,40,40,37,39,37,39,66,65,13],x=function(){x.c=x.c||Array.apply({},c);x.r=function(){x.c=null};return x.c},h=function(e){if(x()[0]==(e||window.event).keyCode){x().shift();if(!x().length){x.r();f()}}else{x.r()}};window.addEventListener?window.addEventListener('keydown',h,false):document.attachEvent('onkeydown',h)}", 128 "okc(function(){if(document.getElementById){i=document.getElementById('phplogo');i.src='" . $MYSITE . "images/php_konami.gif'}});", 129 '</script>', 130 ], 131 'link' => [ 132 [ 133 "rel" => "search", 134 "type" => "application/opensearchdescription+xml", 135 "href" => $MYSITE . "phpnetimprovedsearch.src", 136 "title" => "Add PHP.net search", 137 ], 138 [ 139 "rel" => "alternate", 140 "type" => "application/atom+xml", 141 "href" => $MYSITE . "releases/feed.php", 142 "title" => "PHP Release feed", 143 ], 144 145 ], 146 'css' => ['home.css'], 147 'intro' => $intro, 148 ], 149); 150 151// Print body of home page. 152echo $content; 153 154// Prepare announcements. 155if (is_array($CONF_TEASER)) { 156 $conftype = [ 157 'conference' => 'Upcoming conferences', 158 'cfp' => 'Conferences calling for papers', 159 ]; 160 $announcements = ""; 161 foreach ($CONF_TEASER as $category => $entries) { 162 if ($entries) { 163 $announcements .= '<div class="panel">'; 164 $announcements .= ' <a href="/conferences" class="headline" title="' . $conftype[$category] . '">' . $conftype[$category] . '</a>'; 165 $announcements .= '<div class="body"><ul>'; 166 foreach (array_slice($entries, 0, 4) as $url => $title) { 167 $title = preg_replace("'([A-Za-z0-9])([\s:\-,]*?)call for(.*?)$'i", "$1", $title); 168 $announcements .= "<li><a href='$url' title='$title'>$title</a></li>"; 169 } 170 $announcements .= '</ul></div>'; 171 $announcements .= '</div>'; 172 } 173 } 174} else { 175 $announcements = ''; 176} 177 178$SIDEBAR = <<<SIDEBAR_DATA 179 180 <div class='panel'> 181 <a href='https://thephp.foundation/' class='headline'>The PHP Foundation</a> 182 <div class='body'> 183 <p>The PHP Foundation is a collective of people and organizations, united in the mission to ensure the long-term prosperity of the PHP language. 184 <p><a href='https://thephp.foundation/donate/' class='btn btn-primary'>Donate</a></p> 185 </div> 186 </div> 187$announcements 188 <p class='panel'><a href='/cal.php'>User Group Events</a></p> 189 <p class='panel'><a href='/thanks.php'>Special Thanks</a></p> 190 <div class='panel social-media'> 191 <span class='headline'>Social media</span> 192 <div class='body'> 193 <ul> 194 <li> 195 <a href="https://twitter.com/official_php"> 196 <i class="icon-x-twitter"></i> 197 @official_php 198 </a> 199 </li> 200 <li> 201 <a href="https://fosstodon.org/@php"> 202 <i class="icon-mastodon"></i> 203 @php@fosstodon.org 204 </a> 205 </li> 206 </ul> 207 </div> 208 </div> 209 210SIDEBAR_DATA; 211 212// Print the common footer. 213site_footer([ 214 "atom" => "/feed.atom", // Add a link to the feed at the bottom 215 'elephpants' => true, 216 'sidebar' => $SIDEBAR, 217]); 218