title = trim(fgets($fd, 512)); $this->content = ''; while (!feof($fd)) { $this->content .= fread($fd, 8192); } $this->date = $mtime; fclose($fd); $this->category = array_filter(split('/', $filename)); } function getDate() { return $this->date; } function getTitle() { return $this->title; } function getURL() { $fullcat = $_SERVER['SCRIPT_NAME']."/"; foreach ($this->category as $cat) { $fullcat .= "$cat/"; } return 'http://'.$_SERVER['SERVER_NAME'].$fullcat; } function getCategory() { return $this->category; } function categoryMatches($category) { $count = count($category); return array_slice($this->category, 0, $count) == $category; } function getContent($absolute = false) { global $root; $content = $this->content; $content = preg_replace('/\$root\/?/', ($absolute ? 'http://'.$_SERVER['SERVER_NAME'] : '') .$root, $content); $content = preg_replace('/\$url\/?/', $this->getURL(), $content); return $content; } function toHTML() { $str = ""; $str .= "
"; $str .= "

"; $str .= $this->title; $str .= "

"; $str .= "
"; $str .= strftime('%d/%m/%Y', $this->date).', [ '; $fullcat = $_SERVER['SCRIPT_NAME']."/"; foreach ($this->category as $cat) { $fullcat .= "$cat/"; if (strstr($cat, '.diary')) { $str .= " ] [ link ]"; } else { $str .= "$cat / "; } } $str .= "
"; $str .= "
"; $str .= $this->getContent(); $str .= "
"; $str .= "
"; return $str; } function toRSSItem($doc) { $itemnode = $doc->createElement("item"); $node = $doc->createElement("title"); $node->appendChild($doc->createTextNode( htmlspecialchars($this->title))); $itemnode->appendChild($node); $fullcat = $_SERVER['SCRIPT_NAME']."/"; foreach ($this->category as $cat) { $fullcat .= "$cat/"; } $node = $doc->createElement("pubDate"); $node->appendChild($doc->createTextNode( strftime('%a, %d %b %Y %H:%M:%S %z', $this->date))); $itemnode->appendChild($node); $node = $doc->createElement("link"); $node->appendChild($doc->createTextNode($this->getURL())); $itemnode->appendChild($node); $node = $doc->createElement("description"); $cdata = $doc->createCDATASection($this->getContent(true)); $node->appendChild($cdata); $itemnode->appendChild($node); return $itemnode; } } krsort($files); $outputentries = array(); foreach ($files as $tag => $entry) { $mtime = $entry['mtime']; $file = $entry['file']; $entry = new Entry($file, $mtime); if ($entry == null) { continue; } $outputentries[] = $entry; if (count($outputentries) > $defaultentries) { break; } } if (count($outputentries) == 1) { $title = strip_tags($outputentries[0]->getTitle()); } if ($_GET['t'] == 'rss') { $doc = new DOMDocument(); $channode = initRSSDoc($doc); foreach ($outputentries as $entry) { $channode->appendChild($entry->toRSSItem($doc)); } header("Content-Type: text/xml"); print $doc->saveXML(); } else { $rssurl = $_SERVER['SCRIPT_NAME'].'?t=rss'; $headers = array( sprintf('', $rssurl)); printheader($title, $headers); print('

diary

'); printf('

' .'rss feed

', $rssurl); foreach ($outputentries as $entry) { print $entry->toHTML(); } // print('
'.$disclaimer.'
') printfooter(); } function initRSSDoc($doc) { $rssnode = $doc->createElement("rss"); $rssnode->setAttribute("version", 0.91); $doc->appendChild($rssnode); $channode = $doc->createElement("channel"); $rssnode->appendChild($channode); $node = $doc->createElement("title"); $node->appendChild($doc->createTextNode("jk")); $channode->appendChild($node); $node = $doc->createElement("link"); $node->appendChild($doc->createTextNode("http://". $_SERVER['SERVER_NAME']. $_SERVER['SCRIPT_NAME'])); $channode->appendChild($node); $node = $doc->createElement("description"); $node->appendChild($doc->createTextNode("jeremy's blog")); $channode->appendChild($node); $node = $doc->createElement("language"); $node->appendChild($doc->createTextNode("en")); $channode->appendChild($node); return $channode; } ?>