<?php

include("eff_setup2.php");

$smarty = new EFFSmarty;

$smarty->assign('title','WIPO Resources');
$smarty->caching = true;
$smarty->assign('breadcrumb','true');
$issue = array("IP" => "/IP/", "WIPO" => "/IP/WIPO/");
$smarty->assign('issue',$issue);

$content  = '
<div id="featuretext">
';

$filename = isset($_GET['f']) ? basename($_GET['f']) : 'index.html';
if (substr($filename, -4) != "html") { $content .= "<pre>\n"; }
  $isfeed = true;
  require_once '/www/www.eff.org/docs/magpie/rss_fetch.inc';
  $url = 'http://www.eff.org/deeplinks/cat-wipo.xml';
  $num_items = 5;
  $rss = fetch_rss($url);
  
  $items = array_slice($rss->items, 0, $num_items);
  
  $prefeed = '';
  foreach ($items as $item ) {
    $title = $item['title'];
    $url   = $item['link'];
    $date = $item['dc']['date']; 
    $desc = $item['description'];
    $prefeed = "$prefeed \n  <p><i style=\"font-size:10px;\">$date</i><br /><b style=\"font-size:12px;\"><a href=$url>$title</a></b> <br />\n$desc [<a href=$url>Read more</a>]</p>";
  }
//}

$content .= implode('', file($filename));

// get title
preg_match("/(title.*>)(.*?)(<\/title)/i",$content, $title);
if ($title[2]) { $smarty->assign('title',$title[2]); } 

// remove title
$tag = "title";
$content = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$content);

// add feed
if (isset($isfeed)) {
$feed = '<div class="blogfeed">
<h2>WIPO-related Posts from <a href="/deeplinks/">DeepLinks</a></h2>
<p>'.$prefeed.'</p>
<p align="right"><a href="/deeplinks/archives/cat_wipo.php">All WIPO posts from DeepLinks &raquo;</a></p>
</div>';

  $content = preg_replace("/<!--feed-->/",$feed,$content);
}

if (substr($filename, -4) != "html") { $content .= "</pre>\n"; }

$content .= '</div>';

global $REQUEST_URI;
$smarty->assign('content',$content);
if (isset($isfeed)) {
  $smarty->display('no-sidebar.tpl',$REQUEST_URI);
} else {
  $smarty->display('generic.tpl',$REQUEST_URI);
}
?>
