add popularity column to plugin list on website. sort so the most popular plugins are at the top of each category
This commit is contained in:
parent
a172abd061
commit
d3f23df82e
@ -13,6 +13,32 @@ function iitcDesktopDownload ( $build )
|
|||||||
print "<a class=\"btn btn-large btn-primary\" onclick=\"if(track){track('desktop','iitc','$build');}\" href=\"$build/total-conversion-build.user.js\">Download</a>\n";
|
print "<a class=\"btn btn-large btn-primary\" onclick=\"if(track){track('desktop','iitc','$build');}\" href=\"$build/total-conversion-build.user.js\">Download</a>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadPopularity()
|
||||||
|
{
|
||||||
|
$popularity = Array();
|
||||||
|
|
||||||
|
$pop_file = getcwd() . "/popularity.txt";
|
||||||
|
|
||||||
|
if ( file_exists($pop_file) )
|
||||||
|
{
|
||||||
|
foreach ( file($pop_file,FILE_IGNORE_NEW_LINES) as $line )
|
||||||
|
{
|
||||||
|
$items = explode ( ' ', $line );
|
||||||
|
$popularity[$items[0]] = (int)$items[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $popularity;
|
||||||
|
}
|
||||||
|
|
||||||
|
function popularity_cmp ( $a, $b )
|
||||||
|
{
|
||||||
|
if ( $a['popularity'] == $b['popularity'] )
|
||||||
|
return 0;
|
||||||
|
// sort from highest to lowest
|
||||||
|
return ($a['popularity'] > $b['popularity']) ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function iitcDesktopPluginDownloadTable ( $build )
|
function iitcDesktopPluginDownloadTable ( $build )
|
||||||
{
|
{
|
||||||
@ -28,6 +54,8 @@ function iitcDesktopPluginDownloadTable ( $build )
|
|||||||
'Misc' => "Unclassified plugins",
|
'Misc' => "Unclassified plugins",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$popularity = loadPopularity();
|
||||||
|
|
||||||
$plugins = Array();
|
$plugins = Array();
|
||||||
|
|
||||||
foreach ( glob ( "$build/plugins/*.user.js" ) as $path )
|
foreach ( glob ( "$build/plugins/*.user.js" ) as $path )
|
||||||
@ -35,6 +63,11 @@ function iitcDesktopPluginDownloadTable ( $build )
|
|||||||
$basename = basename ( $path, ".user.js" );
|
$basename = basename ( $path, ".user.js" );
|
||||||
$details = loadUserScriptHeader ( $path );
|
$details = loadUserScriptHeader ( $path );
|
||||||
|
|
||||||
|
if ( array_key_exists('total-conversion-build',$popularity) && array_key_exists('plugins/'.$basename, $popularity) )
|
||||||
|
{
|
||||||
|
$details['popularity'] = $popularity['plugins/'.$basename] / $popularity['total-conversion-build'];
|
||||||
|
}
|
||||||
|
|
||||||
$plugins[$basename] = $details;
|
$plugins[$basename] = $details;
|
||||||
|
|
||||||
$category = array_key_exists('@category',$details) ? $details['@category'] : 'Misc';
|
$category = array_key_exists('@category',$details) ? $details['@category'] : 'Misc';
|
||||||
@ -47,15 +80,19 @@ function iitcDesktopPluginDownloadTable ( $build )
|
|||||||
}
|
}
|
||||||
|
|
||||||
ksort ( $plugins );
|
ksort ( $plugins );
|
||||||
|
uasort ( $plugins, 'popularity_cmp' );
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<table class="table table-condensed">
|
<table class="table table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>ID / Version</th>
|
<th>Popularity</th>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Version</th>
|
||||||
|
<!--
|
||||||
<th>Description</th>
|
<th>Description</th>
|
||||||
|
-->
|
||||||
<th>Download</th>
|
<th>Download</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -64,7 +101,7 @@ function iitcDesktopPluginDownloadTable ( $build )
|
|||||||
<?php
|
<?php
|
||||||
foreach ( $categories as $category => $category_desc )
|
foreach ( $categories as $category => $category_desc )
|
||||||
{
|
{
|
||||||
print "<tr class=\"category_header\"><th colspan=\"2\">Category: $category</th><td colspan=\"2\">$category_desc</td></tr>\n";
|
print "<tr class=\"category_header\"><th colspan=\"1\">Category: $category</th><td colspan=\"4\">$category_desc</td></tr>\n";
|
||||||
|
|
||||||
$empty = True;
|
$empty = True;
|
||||||
foreach ( $plugins as $basename => $details )
|
foreach ( $plugins as $basename => $details )
|
||||||
@ -89,11 +126,22 @@ function iitcDesktopPluginDownloadTable ( $build )
|
|||||||
# remove unneeded prefix from description
|
# remove unneeded prefix from description
|
||||||
$description = preg_replace ( '/^\[[^]]*\] */', '', $details['@description'] );
|
$description = preg_replace ( '/^\[[^]]*\] */', '', $details['@description'] );
|
||||||
|
|
||||||
|
$plugin_users = "-";
|
||||||
|
if ( array_key_exists('popularity',$details) )
|
||||||
|
{
|
||||||
|
$plugin_users = (int)($details['popularity']*1000)/10 . "%";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
print "<td>$name</td>";
|
print "<td>$name</td>";
|
||||||
print "<td>$basename<br />$version</td>";
|
print "<td>$plugin_users</td>";
|
||||||
print "<td>$description</td>";
|
print "<td>$basename</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 "<td>$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\" title=\"Download\"><i class=\"icon-download icon-white\"></i></a></td>";
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
print "<tr><td colspan=\"4\" style=\"border-top: none; padding-top: 0; padding-bottom: 0.5em\">$description</td></tr>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
if ( $empty )
|
if ( $empty )
|
||||||
print "<tr><td colspan=\"4\">(no plugins in this category)</td></tr>\n";
|
print "<tr><td colspan=\"4\">(no plugins in this category)</td></tr>\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user