| <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php"); $App = new App(); $Nav = new Nav(); $Menu = new Menu(); include($App->getProjectCommon()); # All on the same line to unclutter the user's desktop' | |
| #***************************************************************************** | |
| # | |
| # functions.php | |
| # | |
| # Author: Yossi Mesika, Stefan Edlund | |
| # Date: 2009-07-19 | |
| # | |
| # Description: Common functions for STEM web page | |
| # | |
| #**************************************************************************** | |
| # | |
| # Begin: page-specific settings. Change these. | |
| function getFeedContents($rssUrl, $cacheFile) | |
| { | |
| # $cacheFile = $_SERVER['DOCUMENT_ROOT'] . "/stem/data/rss_cache.xml"; | |
| # $rssUrl = "http://www.eclipse.org/forums/rdf.php?mode=m&l=1&basic=1&frm=72&n=5"; | |
| $rssData = ""; | |
| # if (file_exists($cacheFile) && @filemtime($cacheFile) + 86400 > time()) { | |
| # $rssData = @file_get_contents($cacheFile); | |
| # } else { | |
| $rssData = @file_get_contents($rssUrl); | |
| if (!empty($rssData)) { | |
| @file_put_contents($cacheFile, $rssData); | |
| } else { | |
| // If we have a failed retrieve, set cache file mod time to 12 hours behind current epoch. | |
| // This will delay cache timeout for another 12 hours. Fail safe to prevent | |
| // latency on _all_ page reloads in the event of infrastructure problems. | |
| @touch($cacheFile, time() - 43200); | |
| } | |
| # } | |
| return $rssData; | |
| } | |
| function getRssFeed($rssUrl, $cacheFile) | |
| { | |
| //$rssFilePath = $_SERVER['DOCUMENT_ROOT'] . "/stem/feeds/news.xml"; | |
| $xmlData = getFeedContents($rssUrl, $cacheFile); | |
| if (empty($xmlData)) { | |
| return; | |
| } | |
| $xmlResult = new SimpleXMLElement($xmlData); | |
| $rssResults = $xmlResult->item; | |
| $rssMaxResults = 5; | |
| if (sizeof($rssResults) > 0) { | |
| $rssCount = 0; | |
| foreach ($rssResults as $rssResult) { | |
| if ($rssCount >= $rssMaxResults) { | |
| break; | |
| } | |
| $title = $rssResult->title; | |
| $url = $rssResult->link; | |
| $ns_dc = $rssResult->children("http://purl.org/dc/elements/1.1/"); | |
| $date = strtotime($ns_dc->date); | |
| if (!$date || $date === -1) { | |
| $date = time(); | |
| } | |
| $formattedDate = date('d-M y', $date); | |
| echo "<img src=\"images/arrow.jpg\" width=\"11\" height=\"10\" alt=\"\" border=\"0\"> " .$formattedDate . ": <a href=\"". $url ."\" target=\"_blank\">". $title ."</a><br />"; | |
| $rssCount++; | |
| } | |
| } | |
| } | |
| function getData($file, $maxresults, $icon) | |
| { | |
| $filePath = $_SERVER['DOCUMENT_ROOT'] . $file; | |
| $xmlData = file_get_contents($filePath); | |
| $xmlResult = new SimpleXMLElement($xmlData); | |
| $results = $xmlResult->item; | |
| echo $results; | |
| if (sizeof($results) > 0) { | |
| $count = 0; | |
| foreach ($results as $result) { | |
| if ($maxresults != -1 && $count >= $maxresults) { | |
| break; | |
| } | |
| $title = $result->title; | |
| $url = $result->link; | |
| $authors = $result->authors; | |
| $source = $result->source; | |
| $other = $result->other; | |
| $image = $result->image; | |
| $markup = ""; | |
| if(!empty($image)) { | |
| $markup = $markup. "<img src=\"". $image ."\" style=\"float: left;width:150px;\"/>"; | |
| } | |
| if(!empty($authors)) | |
| $markup = $markup. $authors. " "; | |
| if(!empty($url)) { | |
| $markup = $markup. "<a href=\"". $url ."\" target=\"_blank\">"; | |
| if(!empty($icon)) $markup = $markup. "<img border=0 src=\"". $icon . "\"> "; | |
| } | |
| if(!empty($title)) | |
| $markup = $markup. $title."</a> "; | |
| if(!empty($source)) | |
| $markup = $markup. "<div style=\"font-style: italic;\">".$source."</div>"; | |
| if(!empty($other)) | |
| $markup = $markup. " " . $other; | |
| $markup = $markup . "<br/>"; | |
| echo $markup; | |
| $count++; | |
| } | |
| } | |
| } | |
| ?> |