diff --git a/web/plugins/addonrepository/addonrepository.php b/web/plugins/addonrepository/addonrepository.php
index 856d0188b2..33f231b5bf 100644
--- a/web/plugins/addonrepository/addonrepository.php
+++ b/web/plugins/addonrepository/addonrepository.php
@@ -24,6 +24,8 @@
includeGuard('AddonRepositoryPlugin');
+require_once('addonsparser.class.php');
+
class AddonRepositoryPlugin extends Plugin implements Actioner, RequestInterpreter
{
public static $name = 'addonrepository';
@@ -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');
@@ -77,6 +109,8 @@ public function outputAddonList(&$addons)
foreach($addons as $addon)
{
+ if(!$this->addonSupportsGameMode($addon, $gameModes)) continue;
+
?>
|
|
|
@@ -88,58 +122,12 @@ 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'=>'Unzip 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'=>'Move 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'=>'Move 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'=>'Move 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'=>'Move 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'=>'Move 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'=>'Move 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'=>'Move 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'=>'Move 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'=>'Move 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);
@@ -147,19 +135,22 @@ public function generateHTML()
The following add-ons are for use with DOOM, DOOM2, Ultimate DOOM and Final DOOM (TNT/Plutonia). Some of which may even be used with the shareware version of DOOM (check the Notes).
outputAddonList($doomAddons);
+ $doomGames = array('doom1', 'doom1-ultimate', 'doom1-share', 'doom2', 'doom2-plut', 'doom2-tnt');
+ $this->outputAddonList($addons, $doomGames);
?>jHeretic
The following add-ons are for use with Heretic and Heretic: Shadow of the Serpent Riders . Some of which may even be used with the shareware version of Heretic (check the Notes).
outputAddonList($hereticAddons);
+ $hereticGames = array('heretic', 'heretic-share', 'heretic-ext');
+ $this->outputAddonList($addons, $hereticGames);
?>jHexen
The following add-ons are for use with Hexen and Hexen:Deathkings of the Dark Citadel. Some of which may even be used with the shareware version of Hexen (check the Notes).
outputAddonList($hexenAddons);
+ $hexenGames = array('hexen', 'hexen-dk', 'hexen-demo');
+ $this->outputAddonList($addons, $hexenGames);
includeHTML('instructions', self::$name);
}
diff --git a/web/plugins/addonrepository/addons.xml b/web/plugins/addonrepository/addons.xml
new file mode 100644
index 0000000000..2b99b2251d
--- /dev/null
+++ b/web/plugins/addonrepository/addons.xml
@@ -0,0 +1,137 @@
+
+
+
+ http://files.dengine.net/tracker/torrents/jdrp-packaged-20070404.zip.torrent
+ jDRP v1.01 (packaged)
+ DOOM Resource Pack
+ Unzip this pack into the Snowberry addon folder]]>
+
+ doom1
+ doom1-share
+ doom1-ultimate
+ doom2
+ doom2-plut
+ doom2-tnt
+
+
+
+ http://files.dengine.net/tracker/torrents/jdmu-doom-classic-20080930.pk3.torrent
+ DOOM Classic Music
+ DOOM Music Recorded from a genuine Roland Sound Canvas SC-155
+ Move this pack into the Snowberry addon folder]]>
+
+ doom1
+ doom1-share
+ doom1-ultimate
+
+
+
+ http://files.dengine.net/tracker/torrents/jdmu-doom2-classic-20080930.pk3.torrent
+ DOOM2 Classic Music
+ DOOM2 Music Recorded from a genuine Roland Sound Canvas SC-155
+ Move this pack into the Snowberry addon folder]]>
+
+ doom2
+
+
+
+ http://files.dengine.net/tracker/torrents/tnt-remix-lorcan-20071225.pk3.torrent
+ TNT Lorcan Remix
+ TNT Music Remixed by Lorcan
+ Move this pack into the Snowberry addon folder]]>
+
+ doom2-tnt
+
+
+
+ http://files.dengine.net/tracker/torrents/jdmu-all-remix-Sycraft-v4.pk3.torrent
+ Sycraft Remixes
+ DOOM, DOOMII and Final DOOM music remastered by Sycraft
+ Move this pack into the Snowberry addon folder]]>
+
+ doom1
+ doom1-share
+ doom1-ultimate
+ doom2
+ doom2-plut
+ doom2-tnt
+
+
+
+ http://dhtp.freelanzer.com/
+ DOOM High-resolution Texture Project
+ DOOM high resolution textures
+
+ doom1
+ doom1-share
+ doom1-ultimate
+ doom2
+ doom2-plut
+ doom2-tnt
+
+
+
+ http://files.dengine.net/tracker/torrents/jdui-all-20120223.pk3.torrent
+ DOOM High-resolution User interface Pack
+ DOOM High-resolution User interface Pack
+ Move this pack into the Snowberry addon folder]]>
+
+ doom1
+ doom1-share
+ doom1-ultimate
+ doom2
+ doom2-plut
+ doom2-tnt
+
+
+
+ http://files.dengine.net/tracker/torrents/pk-doom-sfx-20100109.pk3.torrent
+ DOOM High-quality sound pack
+ Compiled by Per Kristian Risvik
+ Move this pack into the Snowberry addon folder]]>
+
+ doom1
+ doom1-share
+ doom1-ultimate
+ doom2
+ doom2-plut
+ doom2-tnt
+
+
+
+ http://files.dengine.net/tracker/torrents/slide-skyboxes.torrent
+ Slide's Skyboxes
+ Created by slide for all the DOOM games
+ Move these packs into the Snowberry addon folder]]>
+
+ doom1
+ doom1-share
+ doom1-ultimate
+ doom2
+ doom2-plut
+ doom2-tnt
+
+
+
+ http://torrage.com/torrent/584A6DDB49940C73753CB6B425B4301E6137E945.torrent
+ jHRP 2009.07.03 (packaged)
+ 3D Models, hi-res interface elements and textures
+ Move this pack into the Snowberry addon folder]]>
+
+ heretic
+ heretic-share
+ heretic-ext
+
+
+
+ http://files.dengine.net/tracker/torrents/xhtp-20100714.pk3.torrent
+ xHTP 2010.07.14 (packaged)
+ High resolution texture pack
+ Move this pack into the Snowberry addon folder]]>
+
+ hexen
+ hexen-dk
+ hexen-demo
+
+
+
diff --git a/web/plugins/addonrepository/addonsparser.class.php b/web/plugins/addonrepository/addonsparser.class.php
new file mode 100644
index 0000000000..9f6fe624b9
--- /dev/null
+++ b/web/plugins/addonrepository/addonsparser.class.php
@@ -0,0 +1,170 @@
+
+ */
+
+includeGuard('AddonsParser');
+
+class AddonsParser
+{
+ public static function parse($xmlAddonList, &$addons)
+ {
+ if(!is_array($addons))
+ throw new Exception('Invalid addons argument, array expected');
+
+ $listDom = self::constructSimpleXmlElementTree($xmlAddonList);
+ if($listDom == FALSE)
+ throw new Exception('Failed constructing XML DOM');
+
+ if(!self::parseAddonListDOM($listDom, $addons))
+ throw new Exception('Failed parsing XML DOM');
+
+ return TRUE;
+ }
+
+ /**
+ * Transform the raw XML data into a SimpleXMLElement node tree.
+ *
+ * @param $raw_XML XML data to be parsed (scheme independent).
+ * @return (Object) Root element of a SimpleXMLElement tree if successfull
+ * (Boolean) @c FALSE otherwise.
+ */
+ private static function constructSimpleXmlElementTree($xmlData)
+ {
+ libxml_use_internal_errors(TRUE);
+ try
+ {
+ $xmlTree = new SimpleXMLElement($xmlData);
+ }
+ catch(Exception $e)
+ {
+ $errorMsg = '';
+ foreach(libxml_get_errors() as $libXmlError)
+ {
+ $errorMsg .= "\t" . $libXmlError->message;
+ }
+ trigger_error($errorMsg);
+ return FALSE;
+ }
+ return $xmlTree;
+ }
+
+ /**
+ * Parse the specified addon list, constructing from it a collection
+ * of Addon objects representing the addons.
+ *
+ * @param list (Object) Root element of a SimpleXMLElement DOM
+ * @param addons (Array) Addons collection to be populated.
+ * @return (Boolean) @c TRUE iff parse completed successfully.
+ */
+ private static function parseAddonListDOM(&$list, &$addons)
+ {
+ if(!($list instanceof SimpleXMLElement))
+ throw new Exception('Received invalid addon list');
+
+ // For each addon.
+ foreach($list->children() as $list_addon)
+ {
+ try
+ {
+ $addon = self::parseAddon($list_addon);
+
+ foreach($list_addon->children() as $child)
+ {
+ switch($child->getName())
+ {
+ case 'games':
+ try
+ {
+ $addon['games'] = self::parseGames($child);
+ }
+ catch(Exception $e)
+ {
+ /// \todo Log exception.
+ }
+ break;
+
+ default: break;
+ }
+ }
+
+ // Add this new Addon to the collection.
+ $addons[] = $addon;
+ }
+ catch(Exception $e)
+ {
+ /// \todo Log exception.
+ }
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Parse the list of games from a SimpleXMLElement.
+ *
+ * @param $list_game (Object) SimpleXMLElement node to be "parsed".
+ * @return (Array) Resultant GameList record.
+ */
+ private static function parseGames(&$list_games)
+ {
+ if(!($list_games instanceof SimpleXMLElement))
+ throw new Exception('Received invalid list_games');
+
+ $games = array();
+ foreach($list_games->children() as $child)
+ {
+ if($child->getName() !== 'game') continue;
+
+ $name = strtolower(clean_text((string)$child));
+ $games[$name] = (boolean)TRUE;
+ }
+
+ return $games;
+ }
+
+ /**
+ * Parse a new Addon from a SimpleXMLElement.
+ *
+ * @param $list_game (Object) SimpleXMLElement node to be "parsed".
+ * @return (object) Resultant Addon object.
+ */
+ private static function parseAddon(&$list_addon)
+ {
+ if(!($list_addon instanceof SimpleXMLElement))
+ throw new Exception('Received invalid list_addon');
+
+ $downloadUri = safe_url($list_addon->downloadUri);
+ $title = clean_text($list_addon->title);
+ $description = clean_text($list_addon->description);
+ $notes = clean_text($list_addon->notes);
+
+ $addon = array('downloadUri'=>$downloadUri,
+ 'title'=>$title,
+ 'description'=>$description,
+ 'notes'=>$notes);
+ return $addon;
+ }
+}