add plugin category display support to the website

This commit is contained in:
Jon Atkins 2013-06-08 19:18:33 +01:00
parent 4073e56856
commit 362406f529
2 changed files with 62 additions and 18 deletions

View File

@ -3,3 +3,7 @@ body {
background: url('../img/bg.jpg'); background: url('../img/bg.jpg');
} }
table tr.category_header {
background: #ddd;
}

View File

@ -16,8 +16,37 @@ function iitcDesktopDownload ( $build )
function iitcDesktopPluginDownloadTable ( $build ) function iitcDesktopPluginDownloadTable ( $build )
{ {
$categories = Array (
'Info' => "",
'Keys' => "Key management",
'Controls' => "Map controls",
'Highlighter' => "Portal highliters",
'Layer' => "Additional map layers",
'Map Tiles' => "Alternative map layers",
'Tweaks' => "Adjust IITC settings",
'Misc' => "Unclassified plugins",
);
$plugins = Array();
foreach ( glob ( "$build/plugins/*.user.js" ) as $path )
{
$basename = basename ( $path, ".user.js" );
$details = loadUserScriptHeader ( $path );
$plugins[$basename] = $details;
$category = array_key_exists('@category',$details) ? $details['@category'] : 'Misc';
if ( !array_key_exists($category,$categories) )
{
# add missing categories
$categories[$category] = '';
}
}
?> ?>
<table class="table table-condensed table-hover"> <table class="table table-condensed">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@ -29,30 +58,41 @@ function iitcDesktopPluginDownloadTable ( $build )
<tbody> <tbody>
<?php <?php
foreach ( glob ( "$build/plugins/*.user.js" ) as $path ) foreach ( $categories as $category => $category_desc )
{ {
$basename = basename ( $path, ".user.js" ); print "<tr class=\"category_header\"><th colspan=\"2\">Category: $category</th><td colspan=\"2\">$category_desc</td></tr>\n";
$details = loadUserScriptHeader ( $path ); $empty = True;
foreach ( $plugins as $basename => $details )
{
$this_category = array_key_exists('@category',$details) ? $details['@category'] : 'Misc';
print "<tr id=\"plugin-$basename\">\n"; if ( $category != $this_category )
continue;
# remove 'IITC Plugin: ' prefix if it's there, for neatness $empty = False;
$name = preg_replace ( '/^IITC plugin: /i', '', $details['@name'] );
# format extended version info in less prominant font print "<tr id=\"plugin-$basename\">\n";
$version = preg_replace ( '/^(\d+\.\d+\.\d+)\.(\d{8}\.\d{6})/', '\1<small class="muted">.\2</small>', $details['@version'] );
# remove unneeded prefix from description # remove 'IITC Plugin: ' prefix if it's there, for neatness
$description = preg_replace ( '/^\[[^]]*\] */', '', $details['@description'] ); $name = preg_replace ( '/^IITC plugin: /i', '', $details['@name'] );
print "<td>$name</td>"; # format extended version info in less prominant font
print "<td>$basename<br />$version</td>"; $version = preg_replace ( '/^(\d+\.\d+\.\d+)\.(\d{8}\.\d{6})/', '\1<small class="muted">.\2</small>', $details['@version'] );
print "<td>$description</td>";
print "<td><a onclick=\"if(track){track('desktop','iitc-plugin-$basename','$build');}\" href=\"$path\" class=\"btn btn-small btn-primary\">Download</a></td>";
print "</tr>\n";
}
# remove unneeded prefix from description
$description = preg_replace ( '/^\[[^]]*\] */', '', $details['@description'] );
print "<td>$name</td>";
print "<td>$basename<br />$version</td>";
print "<td>$description</td>";
print "<td><a onclick=\"if(track){track('desktop','iitc-plugin-$basename','$build');}\" href=\"$path\" class=\"btn btn-small btn-primary\">Download</a></td>";
print "</tr>\n";
}
if ( $empty )
print "<tr><td colspan=\"4\">(no plugins in this category)</td></tr>\n";
}
?> ?>
</tbody> </tbody>
</table> </table>