Skip to content

Commit

Permalink
Homepage|Add-on Repository: Add-ons can now be marked "featured"
Browse files Browse the repository at this point in the history
Presently it makes no difference whether an add-on is marked with
the featured flag. Eventually this will be used as a filter in a
more dynamic and user-friendly interface.
  • Loading branch information
danij-deng committed Feb 24, 2012
1 parent 66c5442 commit 36a2cfb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
90 changes: 62 additions & 28 deletions web/plugins/addonrepository/addonrepository.php
Expand Up @@ -74,15 +74,17 @@ public function InterpretRequest($request)
*
* @param addon (Array) Addon record object.
* @param gameModes (Array) Associative array containing the list of
* game modes to look for (the needles).
* game modes to look for (the needles). If none are
* specified; assume this addon supports it.
* @return (Boolean)
*/
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;
if(!is_array($gameModes)) return true;

$supportedModes = &$addon['games'];
foreach($gameModes as $mode)
Expand All @@ -93,46 +95,78 @@ private function addonSupportsGameMode(&$addon, &$gameModes)
return false;
}

/**
* @return (Boolean) @c true if this addon is marked 'featured'.
*/
private function addonHasFeatured(&$addon)
{
if(!is_array($addon))
throw new Exception('Invalid addon argument, array expected');

if(!is_array($addon['attributes'])) return false;

$attribs = &$addon['attributes'];
return isset($attribs['featured']) && (boolean)$attribs['featured'];
}

private function outputAddonListElement(&$addon)
{
if(!is_array($addon))
throw new Exception('Invalid addon argument, array expected');

$addonFullTitle = $addon['title'];
if(isset($addon['version']))
$addonFullTitle .= ' '. $addon['version'];

?><tr><td><?php

if(isset($addon['downloadUri']))
{
?><a href="<?php echo $addon['downloadUri']; ?>" title="Download <?php echo $addonFullTitle; ?>" rel="nofollow"><?php echo $addonFullTitle; ?></a><?php
}
else if(isset($addon['homepageUri']))
{
?><a href="<?php echo $addon['homepageUri']; ?>" title="Visit homepage for <?php echo $addonFullTitle; ?>" rel="nofollow"><?php echo $addonFullTitle; ?></a><?php
}
else
{
echo $addonFullTitle;
}

?></td>
<td><?php if(isset($addon['description'])) echo $addon['description']; ?></td>
<td><?php if(isset($addon['notes'])) echo $addon['notes']; ?></td></tr><?
}

/**
* 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.
* @param filter_gameModes (Array) Game modes to filter the addon list by.
* @param filter_featured (Mixed) @c < 0 no filter
* = 0 not featured
* = 1 featured
*/
private function outputAddonList(&$addons, &$gameModes)
private function outputAddonList(&$addons, $filter_gameModes, $filter_featured=-1)
{
if(!is_array($addons))
throw new Exception('Invalid addons argument, array expected');

// Sanitize filter arguments.
$filter_featured = intval($filter_featured);
if($filter_featured < 0) $filter_featured = -1; // Any.
else $filter_featured = $filter_featured? 1 : 0;

// Output the table.
?><table class="directory">
<tr><th>Name</th><th>Description</th><th>Notes</th></tr><?php

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

$addonFullTitle = $addon['title'];
if(isset($addon['version']))
$addonFullTitle .= ' '. $addon['version'];

?><tr><td><?php
if($filter_featured != -1 && (boolean)$filter_featured != $this->addonHasFeatured($addon)) continue;
if(!$this->addonSupportsGameMode($addon, $filter_gameModes)) continue;

if(isset($addon['downloadUri']))
{
?><a href="<?php echo $addon['downloadUri']; ?>" title="Download <?php echo $addonFullTitle; ?>" rel="nofollow"><?php echo $addonFullTitle; ?></a><?php
}
else if(isset($addon['homepageUri']))
{
?><a href="<?php echo $addon['homepageUri']; ?>" title="Visit homepage for <?php echo $addonFullTitle; ?>" rel="nofollow"><?php echo $addonFullTitle; ?></a><?php
}
else
{
echo $addonFullTitle;
}

?></td>
<td><?php echo $addon['description']; ?></td>
<td><?php echo $addon['notes']; ?></td></tr><?
$this->outputAddonListElement($addon);
}

?></table><?php
Expand Down
6 changes: 3 additions & 3 deletions web/plugins/addonrepository/addons.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<addons>
<addon>
<addon featured="true">
<downloadUri>http://files.dengine.net/tracker/torrents/jdrp-packaged-20070404.zip.torrent</downloadUri>
<title>jDRP (packaged)</title>
<version>1.01</version>
Expand Down Expand Up @@ -58,7 +58,7 @@
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<addon featured="true">
<homepageUri>http://dhtp.freelanzer.com/</homepageUri>
<title>DOOM High-resolution Texture Project</title>
<description>DOOM high resolution textures</description>
Expand All @@ -85,7 +85,7 @@
<game>doom2-tnt</game>
</games>
</addon>
<addon>
<addon featured="true">
<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>
Expand Down
13 changes: 13 additions & 0 deletions web/plugins/addonrepository/addonsparser.class.php
Expand Up @@ -173,6 +173,19 @@ private static function parseAddon(&$list_addon)
if(!empty($list_addon->notes))
$addon['notes'] = clean_text($list_addon->notes);

$attribs = array();
foreach($list_addon->attributes() as $key => $value)
{
$attrib = clean_text($key);
if(strcasecmp($attrib, 'featured') == 0)
{
$value = clean_text($value);
$attribs[strtolower($attrib)] = (integer)eval('return ('.$value.');');
}
}

$addon['attributes'] = $attribs;

return $addon;
}
}

0 comments on commit 36a2cfb

Please sign in to comment.