Skip to content

Instantly share code, notes, and snippets.

@goldbattle
Last active December 21, 2015 05:48
Show Gist options
  • Save goldbattle/6259204 to your computer and use it in GitHub Desktop.
Save goldbattle/6259204 to your computer and use it in GitHub Desktop.
JSTR Mod Table Display
<?php
// Data/Constants/Finals
$COL_MASTER = "580";
$COL_MODS = "406";
$COL_VERSION = "130";
$COL_DOWNLOAD = "100";
// Json url location
$branch_location="http://files.jslegacy.com/texture-patcher/data/branch.json";
// Retrieve master data
$contents = file_get_contents($branch_location);
$json_master = json_decode($contents, true);
// Loop through and display tables
foreach($json_master["branches"] as $branch){
displayTable($branch["name"], $branch["url"]);
}
// Main function called to display a table based on a .json
function displayTable($table_name, $json_table_url) {
// Data
global $COL_MASTER, $COL_MODS, $COL_VERSION, $COL_DOWNLOAD;
// Get Json
$contents = file_get_contents($json_table_url);
$json_table = json_decode($contents, true);
// Find zip location
$zip_location = $json_table["options"]["zipsurl"];
// Find mods
$json_mod_data = $json_table["mods"];
// Make table/columns
echo '<h2>Mod List ('.$table_name.')';
echo '<table border="1" width="'.$COL_MASTER.'">';
// Set column widths
echo '<col width="'.$COL_MODS.'">';
echo '<col width="'.$COL_VERSION.'">';
echo '<col width="'.$COL_DOWNLOAD.'">';
echo '<tbody>';
echo '<tr><th>Mod Name</th><th>Mod Version</th><th>Download</th></tr>';
// Add rows/mods
$mod_names = array_keys($json_mod_data);
foreach($mod_names as &$mod) {
echo '<tr>';
echo '<td>'.$mod.'</td>';
echo '<td>'.$json_mod_data[$mod]["version"].'</td>';
// Create url for download
$mod_zip = str_replace(' ', '_', $mod);
$mod_zip = $zip_location.$mod_zip.".zip";
echo '<td><a href="'.$mod_zip.'">Download</a></td>';
echo '</tr>';
}
// End table
echo '</tbody>';
echo '</table>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment