Skip to content

Commit

Permalink
Move templates into html directory. Add directory for rss templates. …
Browse files Browse the repository at this point in the history
…Get RSS feed of latest packages working.
  • Loading branch information
saltybeagle committed Mar 30, 2010
1 parent dd85bec commit ff75a77
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 10 deletions.
6 changes: 4 additions & 2 deletions package.xml
Expand Up @@ -29,8 +29,8 @@ a fully customized PEAR channel.
<email>saltybeagle@php.net</email>
<active>yes</active>
</lead>
<date>2009-12-20</date>
<time>12:21:21</time>
<date>2010-03-29</date>
<time>16:13:46</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
Expand Down Expand Up @@ -61,6 +61,7 @@ Package PEAR2_SimpleChannelFrontend API release notes for version 0.1.0.</notes>
<file role="php" name="Package.php"/>
<file role="php" name="PackageList.php"/>
<file role="php" name="PackageRelease.php"/>
<file role="php" name="Search.php"/>
<file role="php" name="Support.php"/>
<file role="php" name="TemplateMapper.php"/>
<file role="php" name="UnregisteredViewException.php"/>
Expand All @@ -85,6 +86,7 @@ Package PEAR2_SimpleChannelFrontend API release notes for version 0.1.0.</notes>
<file role="www" name="Package.tpl.php"/>
<file role="www" name="PackageList.tpl.php"/>
<file role="www" name="PackageRelease.tpl.php"/>
<file role="www" name="Search.tpl.php"/>
<file role="www" name="Support.tpl.php"/>
<file role="www" name="UnregisteredViewException.tpl.php"/>
</dir>
Expand Down
8 changes: 6 additions & 2 deletions package_compatible.xml
Expand Up @@ -29,8 +29,8 @@ a fully customized PEAR channel.
<email>saltybeagle@php.net</email>
<active>yes</active>
</lead>
<date>2009-12-20</date>
<time>12:21:21</time>
<date>2010-03-29</date>
<time>16:13:46</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
Expand All @@ -53,6 +53,7 @@ Package PEAR2_SimpleChannelFrontend API release notes for version 0.1.0.</notes>
<dir name="/">
<file role="www" name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/UnregisteredViewException.tpl.php"/>
<file role="www" name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/Support.tpl.php"/>
<file role="www" name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/Search.tpl.php"/>
<file role="www" name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/PackageRelease.tpl.php"/>
<file role="www" name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/PackageList.tpl.php"/>
<file role="www" name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/Package.tpl.php"/>
Expand All @@ -72,6 +73,7 @@ Package PEAR2_SimpleChannelFrontend API release notes for version 0.1.0.</notes>
<file role="php" name="php/pear2/SimpleChannelFrontend/UnregisteredViewException.php"/>
<file role="php" name="php/pear2/SimpleChannelFrontend/TemplateMapper.php"/>
<file role="php" name="php/pear2/SimpleChannelFrontend/Support.php"/>
<file role="php" name="php/pear2/SimpleChannelFrontend/Search.php"/>
<file role="php" name="php/pear2/SimpleChannelFrontend/PackageRelease.php"/>
<file role="php" name="php/pear2/SimpleChannelFrontend/PackageList.php"/>
<file role="php" name="php/pear2/SimpleChannelFrontend/Package.php"/>
Expand Down Expand Up @@ -102,6 +104,7 @@ Package PEAR2_SimpleChannelFrontend API release notes for version 0.1.0.</notes>
<install name="php/pear2/SimpleChannelFrontend/Package.php" as="pear2/SimpleChannelFrontend/Package.php"/>
<install name="php/pear2/SimpleChannelFrontend/PackageList.php" as="pear2/SimpleChannelFrontend/PackageList.php"/>
<install name="php/pear2/SimpleChannelFrontend/PackageRelease.php" as="pear2/SimpleChannelFrontend/PackageRelease.php"/>
<install name="php/pear2/SimpleChannelFrontend/Search.php" as="pear2/SimpleChannelFrontend/Search.php"/>
<install name="php/pear2/SimpleChannelFrontend/Support.php" as="pear2/SimpleChannelFrontend/Support.php"/>
<install name="php/pear2/SimpleChannelFrontend/TemplateMapper.php" as="pear2/SimpleChannelFrontend/TemplateMapper.php"/>
<install name="php/pear2/SimpleChannelFrontend/UnregisteredViewException.php" as="pear2/SimpleChannelFrontend/UnregisteredViewException.php"/>
Expand All @@ -121,6 +124,7 @@ Package PEAR2_SimpleChannelFrontend API release notes for version 0.1.0.</notes>
<install name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/Package.tpl.php" as="pear2.php.net/templates/templates/Package.tpl.php"/>
<install name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/PackageList.tpl.php" as="pear2.php.net/templates/templates/PackageList.tpl.php"/>
<install name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/PackageRelease.tpl.php" as="pear2.php.net/templates/templates/PackageRelease.tpl.php"/>
<install name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/Search.tpl.php" as="pear2.php.net/templates/templates/Search.tpl.php"/>
<install name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/Support.tpl.php" as="pear2.php.net/templates/templates/Support.tpl.php"/>
<install name="www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/templates/UnregisteredViewException.tpl.php" as="pear2.php.net/templates/templates/UnregisteredViewException.tpl.php"/>
</filelist>
Expand Down
19 changes: 17 additions & 2 deletions src/SimpleChannelFrontend/Main.php
Expand Up @@ -36,7 +36,8 @@ class Main

public $page_content;

protected $options = array('view' => 'news');
public $options = array('view' => 'news',
'format' => 'html');

protected static $view_map = array('news' => 'pear2\SimpleChannelFrontend\News',
'packages' => 'pear2\SimpleChannelFrontend\PackageList',
Expand All @@ -59,13 +60,27 @@ function __construct(\pear2\Pyrus\ChannelFileInterface $channel, $options = arra
{
static::setChannel($channel);
$this->options = array_merge($this->options, $options);
$this->preRun();
try {
$this->run();
} catch(Exception $e) {
$this->page_content = $e;
}
}


function preRun()
{
switch ($this->options['format']) {
case 'rss':
header('Content-type:text/xml');
break;
case 'html':
default:
header('Content-Type:text/html; charset=UTF-8');
break;
}
}

/**
* Set the channel file for this frontend.
*
Expand Down
4 changes: 2 additions & 2 deletions src/SimpleChannelFrontend/TemplateMapper.php
Expand Up @@ -10,10 +10,10 @@ function __construct()
// running from svn, or extracted from archive
if (strpos(__FILE__, 'trunk/src/SimpleChannelFrontend')) {
// running from svn
self::$templatePath = __DIR__ . '/../../www/templates/';
self::$templatePath = __DIR__ . '/../../www/templates/html';
} else {
// running from extracted archive
self::$templatePath = __DIR__ . '/../../../www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/';
self::$templatePath = __DIR__ . '/../../../www/PEAR2_SimpleChannelFrontend/pear2.php.net/templates/html';
}
}
static::$classname_replacement = 'pear2\\SimpleChannelFrontend\\';
Expand Down
10 changes: 9 additions & 1 deletion www/index.php
Expand Up @@ -27,7 +27,15 @@

$savant = new pear2\Templates\Savant\Main();
$savant->setClassToTemplateMapper(new pear2\SimpleChannelFrontend\TemplateMapper);
$savant->setTemplatePath(array(__DIR__ . '/templates'));
$savant->setTemplatePath(array(__DIR__ . '/templates/html'));

switch($frontend->options['format']) {
case 'rss':
$savant->addTemplatePath(__DIR__.'/templates/'.$frontend->options['format']);
break;
}


$savant->setEscape('htmlspecialchars');
$savant->addFilters(array($frontend, 'postRender'));
echo $savant->render($frontend);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="search" title="search packages" type="application/opensearchdescription+xml" href="?view=searchdefinition">
<link rel="alternate" title="My Channel Latest Releases" type="application/atom+xml" href="?view=latest" />
<link rel="alternate" title="My Channel Latest Releases" type="application/rss+xml" href="?view=latest&amp;format=rss" />
<link rel="stylesheet" href="<?php echo pear2\SimpleChannelFrontend\Main::getURL(); ?>css/all.css" />
<title><?php echo $context->page_title; ?></title>
</head>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions www/templates/rss/LatestReleases.tpl.php
@@ -0,0 +1,10 @@
<?php foreach($context as $package): ?>
<item rdf:about="<?php echo pear2\SimpleChannelFrontend\Main::getURL().$package->name.'-'.$package->version['release']; ?>">
<title><?php echo $package->name.' '.$package->version['release']; ?></title>
<link><?php echo pear2\SimpleChannelFrontend\Main::getURL().$package->name.'-'.$package->version['release']; ?></link>
<content:encoded>
<?php echo htmlspecialchars(nl2br($package->notes)); ?>
</content:encoded>
<dc:date><?php echo date('c', strtotime($package->date.' '.$package->time)); ?></dc:date>
</item>
<?php endforeach; ?>
17 changes: 17 additions & 0 deletions www/templates/rss/Main.tpl.php
@@ -0,0 +1,17 @@
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; ?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel rdf:about="<?php echo pear2\SimpleChannelFrontend\Main::getURL(); ?>">
<link><?php echo pear2\SimpleChannelFrontend\Main::getURL(); ?></link>
<dc:creator>pear-webmaster@lists.php.net</dc:creator>
<dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
<dc:language>en-us</dc:language>
<title><?php echo pear2\SimpleChannelFrontend\Main::$channel->summary; ?>: Latest releases</title>
<description>The latest releases for <?php echo pear2\SimpleChannelFrontend\Main::$channel->summary; ?>.</description>
</channel>
<?php echo $savant->render($context->page_content); ?>
</rdf:RDF>

0 comments on commit ff75a77

Please sign in to comment.