1<?php 2 3/* vim: ft=php 4 This code is used to pregenerate the conference teaser array displayed 5 on the PHP.net homepage. It gets the filename 6 of the RSS where the info is already fetched, and generates the 7 PHP code ready to be included to $outfile 8*/ 9 10function pregenerate_conf_teaser($rssfile, $outfile) 11{ 12 // Try to open output file for reading 13 $out = @fopen("$outfile~", "w"); 14 if (!$out) { die("unable to pregenerate conference teaser to '$outfile~'"); } 15 16 // Load the RSS file and register used namespaces 17 $sxe = new SimpleXMLElement($rssfile, $GLOBALS["XML_OPTIONS"], true); 18 $sxe->registerXPathNamespace("php", "http://php.net/ns/news"); 19 20 // Loop over the items and store them in a array 21 $STORE = []; 22 foreach($sxe->entry as $item) { 23 $url = (string)$item->link["href"]; 24 $subject = (string)$item->category["term"]; 25 if($subject == "conferences") { 26 $subject = "conference"; 27 } 28 elseif($subject != "cfp") { 29 // This is neither a conf announcement nor cfp, skip it 30 continue; 31 } 32 $title = (string)$item->title; 33 $lastDate = current($item->xpath("php:finalTeaserDate")); 34 if(strtotime($lastDate) < strtotime("tomorrow")) { 35 // finalTeaserDate has passed, skip it 36 continue; 37 } 38 $STORE[$subject][$url] = $title; 39 } 40 41 // Create PHP readable array 42 $write = '$CONF_TEASER = ' .var_export($STORE, true); 43 44 // Write & close 45 fwrite($out, "<?php\n$write\n?>"); 46 fclose($out); 47 48 // If we don't have new data, delete file 49 if (!@filesize("$outfile~")) { 50 echo "'$outfile~' was empty, skipping\n"; 51 unlink("$outfile~"); 52 return; 53 } 54 55 // Replace real file with temporary file 56 return rename("$outfile~", $outfile); 57} 58 59