Skip to content

Commit

Permalink
Homepage|Addon Repository: Dynamically construct the addon lists from…
Browse files Browse the repository at this point in the history
… an XML file

The Add-ons page is now dynamically built by parsing an XML document
and constructing from it a collection of Addon record objects.
  • Loading branch information
danij-deng committed Feb 23, 2012
1 parent 5dc6056 commit 7018458
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 56 deletions.
103 changes: 47 additions & 56 deletions web/plugins/addonrepository/addonrepository.php
Expand Up @@ -24,6 +24,8 @@

includeGuard('AddonRepositoryPlugin');

require_once('addonsparser.class.php');

class AddonRepositoryPlugin extends Plugin implements Actioner, RequestInterpreter
{
public static $name = 'addonrepository';
Expand Down Expand Up @@ -67,7 +69,37 @@ public function InterpretRequest($request)
return false; // Not for us.
}

public function outputAddonList(&$addons)
/**
* Does the addon support any of these game modes?
*
* @param addon (Array) Addon record object.
* @param gameModes (Array) Associative array containing the list of
* game modes to look for (the needles).
*/
private function addonSupportsGameMode(&$addon, &$gameModes)
{
if(!is_array($addon))
throw new Exception('Invalid addon argument, array expected');

if(!isset($addon['games'])) return true;
if(!is_array($gameModes)) return false;

$supportedModes = &$addon['games'];
foreach($gameModes as $mode)
{
if(isset($supportedModes[$mode])) return true;
}

return false;
}

/**
* Output an HTML list of addons to the output stream
*
* @param addons (Array) Collection of Addon records to process.
* @param gameModes (Array) Game modes to filter the addon list by.
*/
private function outputAddonList(&$addons, &$gameModes)
{
if(!is_array($addons))
throw new Exception('Invalid addons argument, array expected');
Expand All @@ -77,6 +109,8 @@ public function outputAddonList(&$addons)

foreach($addons as $addon)
{
if(!$this->addonSupportsGameMode($addon, $gameModes)) continue;

?><tr><td><a href="<?php echo $addon['downloadUri']; ?>" title="Download <?php echo $addon['title']; ?>"><?php echo htmlspecialchars($addon['title']); ?></a></td>
<td><?php echo htmlspecialchars($addon['description']); ?></td>
<td><?php echo $addon['notes']; ?></td></tr><?
Expand All @@ -88,78 +122,35 @@ public function outputAddonList(&$addons)

public function generateHTML()
{
$doomAddons = array(
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/jdrp-packaged-20070404.zip.torrent',
'title'=>'jDRP v1.01 (packaged)',
'description'=>'DOOM Resource Pack',
'notes'=>'<em>Unzip</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/jdmu-doom-classic-20080930.pk3.torrent',
'title'=>'DOOM Classic Music',
'description'=>'DOOM Music Recorded from a genuine Roland Sound Canvas SC-155',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/jdmu-doom2-classic-20080930.pk3.torrent',
'title'=>'DOOM2 Classic Music',
'description'=>'DOOM2 Music Recorded from a genuine Roland Sound Canvas SC-155',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/tnt-remix-lorcan-20071225.pk3.torrent',
'title'=>'TNT Lorcan Remix',
'description'=>'TNT Music Remixed by Lorcan',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/jdmu-all-remix-Sycraft-v4.pk3.torrent',
'title'=>'Sycraft Remixes',
'description'=>'DOOM, DOOMII and Final DOOM music remastered by Sycraft',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://dhtp.freelanzer.com/',
'title'=>'DOOM High-resolution Texture Project',
'description'=>'DOOM high resolution textures',
'notes'=>''),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/jdui-all-20120223.pk3.torrent',
'title'=>'DOOM High-resolution User interface Pack',
'description'=>'DOOM High-resolution User interface Pack',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/pk-doom-sfx-20100109.pk3.torrent',
'title'=>'DOOM High-quality sound pack',
'description'=>'Compiled by Per Kristian Risvik',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder'),
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/slide-skyboxes.torrent',
'title'=>'Slide\'s Skyboxes',
'description'=>'Created by slide for all the DOOM games',
'notes'=>'<em>Move</em> these packs into the Snowberry addon folder')
);

$hereticAddons = array(
array('downloadUri'=>'http://torrage.com/torrent/584A6DDB49940C73753CB6B425B4301E6137E945.torrent',
'title'=>'jHRP 2009.07.03 (packaged)',
'description'=>'3D Models, hi-res interface elements and textures',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder')
);

$hexenAddons = array(
array('downloadUri'=>'http://files.dengine.net/tracker/torrents/xhtp-20100714.pk3.torrent',
'title'=>'xHTP 2010.07.14 (packaged)',
'description'=>'High resolution texture pack',
'notes'=>'<em>Move</em> this pack into the Snowberry addon folder')
);
global $FrontController;

$addonListXml = file_get_contents(FrontController::nativePath("plugins/addonrepository/addons.xml"));

$addons = array();
AddonsParser::parse($addonListXml, $addons);

includeHTML('overview', self::$name);

?><h3>jDoom</h3>
<p>The following add-ons are for use with <strong>DOOM</strong>, <strong>DOOM2</strong>, <strong>Ultimate DOOM</strong> and <strong>Final DOOM (TNT/Plutonia)</strong>. Some of which may even be used with the shareware version of DOOM (check the <em>Notes</em>).</p>
<?php

$this->outputAddonList($doomAddons);
$doomGames = array('doom1', 'doom1-ultimate', 'doom1-share', 'doom2', 'doom2-plut', 'doom2-tnt');
$this->outputAddonList($addons, $doomGames);

?><h3>jHeretic</h3>
<p>The following add-ons are for use with <strong>Heretic</strong> and <strong>Heretic: Shadow of the Serpent Riders </strong>. Some of which may even be used with the shareware version of Heretic (check the <em>Notes</em>).</p>
<?php

$this->outputAddonList($hereticAddons);
$hereticGames = array('heretic', 'heretic-share', 'heretic-ext');
$this->outputAddonList($addons, $hereticGames);

?><h3>jHexen</h3>
<p>The following add-ons are for use with <strong>Hexen</strong> and <strong>Hexen:Deathkings of the Dark Citadel</strong>. Some of which may even be used with the shareware version of Hexen (check the <em>Notes</em>).</p>
<?php

$this->outputAddonList($hexenAddons);
$hexenGames = array('hexen', 'hexen-dk', 'hexen-demo');
$this->outputAddonList($addons, $hexenGames);

includeHTML('instructions', self::$name);
}
Expand Down
137 changes: 137 additions & 0 deletions web/plugins/addonrepository/addons.xml
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<addons>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/jdrp-packaged-20070404.zip.torrent</downloadUri>
<title>jDRP v1.01 (packaged)</title>
<description>DOOM Resource Pack</description>
<notes><![CDATA[<em>Unzip</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
<game>doom2</game>
<game>doom2-plut</game>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/jdmu-doom-classic-20080930.pk3.torrent</downloadUri>
<title>DOOM Classic Music</title>
<description>DOOM Music Recorded from a genuine Roland Sound Canvas SC-155</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/jdmu-doom2-classic-20080930.pk3.torrent</downloadUri>
<title>DOOM2 Classic Music</title>
<description>DOOM2 Music Recorded from a genuine Roland Sound Canvas SC-155</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom2</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/tnt-remix-lorcan-20071225.pk3.torrent</downloadUri>
<title>TNT Lorcan Remix</title>
<description>TNT Music Remixed by Lorcan</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/jdmu-all-remix-Sycraft-v4.pk3.torrent</downloadUri>
<title>Sycraft Remixes</title>
<description>DOOM, DOOMII and Final DOOM music remastered by Sycraft</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
<game>doom2</game>
<game>doom2-plut</game>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://dhtp.freelanzer.com/</downloadUri>
<title>DOOM High-resolution Texture Project</title>
<description>DOOM high resolution textures</description>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
<game>doom2</game>
<game>doom2-plut</game>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/jdui-all-20120223.pk3.torrent</downloadUri>
<title>DOOM High-resolution User interface Pack</title>
<description>DOOM High-resolution User interface Pack</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
<game>doom2</game>
<game>doom2-plut</game>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/pk-doom-sfx-20100109.pk3.torrent</downloadUri>
<title>DOOM High-quality sound pack</title>
<description>Compiled by Per Kristian Risvik</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
<game>doom2</game>
<game>doom2-plut</game>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/slide-skyboxes.torrent</downloadUri>
<title>Slide's Skyboxes</title>
<description>Created by slide for all the DOOM games</description>
<notes><![CDATA[<em>Move</em> these packs into the Snowberry addon folder]]></notes>
<games>
<game>doom1</game>
<game>doom1-share</game>
<game>doom1-ultimate</game>
<game>doom2</game>
<game>doom2-plut</game>
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<downloadUri>http://torrage.com/torrent/584A6DDB49940C73753CB6B425B4301E6137E945.torrent</downloadUri>
<title>jHRP 2009.07.03 (packaged)</title>
<description>3D Models, hi-res interface elements and textures</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>heretic</game>
<game>heretic-share</game>
<game>heretic-ext</game>
</games>
</addon>
<addon>
<downloadUri>http://files.dengine.net/tracker/torrents/xhtp-20100714.pk3.torrent</downloadUri>
<title>xHTP 2010.07.14 (packaged)</title>
<description>High resolution texture pack</description>
<notes><![CDATA[<em>Move</em> this pack into the Snowberry addon folder]]></notes>
<games>
<game>hexen</game>
<game>hexen-dk</game>
<game>hexen-demo</game>
</games>
</addon>
</addons>

0 comments on commit 7018458

Please sign in to comment.