function collectHourStat($store = false) { $stats = new stdClass(); $stats->time = gmdate("Y-m-d H:00:00", time()); $stats->duration = "hour"; $database = new DatabaseManager(); //Addons! $addons = new stdClass(); $addonArray = AddonManager::getAll(); $addons->count = sizeof($addonArray); $addons->cumulative_downloads = array(); $addons->usage = array(); $addons->usage_total = array(); foreach ($addonArray as $addon) { $downloadData = new stdClass(); // TODO we need to go back. I dont want total downloads, I want individual //$downloadData->web = //$downloadData->ingame = //$downloadData->update = $addons->cumulative_downloads[$addon->getId()] = $downloadData; $res = $database->query("SELECT `version` FROM `stats_usage` WHERE `aid`='" . $addon->getId() . "' AND `reported` > now() - INTERVAL 1 HOUR"); $ret = $res->fetch_object(); $usage = array(); $total = 0; while ($obj = $res->fetch_object()) { $total++; if (!isset($usage[$obj->version])) { $usage[$obj->version] = 1; } else { $usage[$obj->version]++; } } $addons->usage[$addon->getId()] = $usage; $addons->usage_total[$addon->getId()] = $total; } $stats->addons = $addons; //Builds $builds = new stdClass(); $buildArray = BuildManager::getAll(); $builds->count = sizeof($buildArray); $builds->cumulative_downloads = array(); foreach ($buildArray as $build) { // TODO this isn't done either... //$builds->cumulative_downloads[$build->getId()] = $build->getDownloads(); } $stats->builds = $builds; //Master Server $stats->master = new stdClass(); $master = CronStatManager::getMasterServerStats(); $stats->master->users = $master[0]; $stats->master->servers = $master[1]; if ($store) { CronStatManager::verifyTable($database); $database->query("INSERT INTO `cron_statistics` (`time` , `duration` , `data`) VALUES ('" . $stats->time . "', 'hour', '" . $database->sanitize(json_encode($stats)) . "')"); } return $stats; }
public static function getUnapproved() { $ret = array(); foreach (AddonManager::getAll() as $addon) { if ($addon->isDeleted() || $addon->getFile($addon->getLatestBranch())->getMalicious() == 2) { continue; } $info = json_decode($addon->getApprovalInfo()); if (isset($info->format) && $info->format == 2) { if (sizeof($info->reports) < 5) { $ret[] = $addon; } } else { if ($info == null) { $ret[] = $addon; } } } return $ret; }
function collectHourStat($store = false) { $stats = new stdClass(); $stats->time = gmdate("Y-m-d H:00:00", time()); $stats->duration = "hour"; //Addons! $addons = new stdClass(); $addonArray = AddonManager::getAll(); $addons->count = sizeof($addonArray); $addons->cumulative_downloads = array(); foreach ($addonArray as $addon) { $downloadData = new stdClass(); // TODO we need to go back. I dont want total downloads, I want individual //$downloadData->web = //$downloadData->ingame = //$downloadData->update = $addons->cumulative_downloads[$addon->getId()] = $downloadData; } $stats->addons = $addons; //Builds $builds = new stdClass(); $buildArray = BuildManager::getAll(); $builds->count = sizeof($buildArray); $builds->cumulative_downloads = array(); foreach ($buildArray as $build) { // TODO this isn't done either... //$builds->cumulative_downloads[$build->getId()] = $build->getDownloads(); } $stats->builds = $builds; //Master Server $stats->master = new stdClass(); $master = CronStatManager::getMasterServerStats(); $stats->master->users = $master[0]; $stats->master->servers = $master[1]; if ($store) { $database = new DatabaseManager(); CronStatManager::verifyTable($database); $database->query("INSERT INTO `cron_statistics` (`time` , `duration` , `data`) VALUES ('" . $stats->time . "', 'hour', '" . $database->sanitize(json_encode($stats)) . "')"); } return $stats; }
public static function checkUpstreamRepos() { $channelId[1] = "stable"; $channelId[2] = "unstable"; $channelId[3] = "development"; $addons = AddonManager::getAll(); foreach ($addons as $addon) { $versionInfo = $addon->getVersionInfo(); if (isset($versionInfo->upstream)) { $upstream = $versionInfo->upstream; //For consistency I like using echo() with parenthesis and sticking with 'ID' instead of 'Id' echo $addon->getId() . "\n"; $url = $upstream->url; if (isset($upstream->mod)) { $url .= "?mods=" . $upstream->mod; } if (strpos($url, "http") !== 0) { $url = "http://" . $url; } $opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\n" . "User-Agent: Torque/1.3\r\n")); $context = stream_context_create($opts); $response = file_get_contents($url, false, $context); if ($response !== false) { if (($res = json_decode($response)) !== null) { $a = "add-ons"; foreach ($res->{$a} as $ad) { if ($ad->name == $addon->getFilename()) { foreach ($ad->channels as $channel => $info) { if (in_array($channel, $upstream->branch)) { $localBranchId = array_search($channel, $upstream->branch); echo "remote [{$channel}]:" . $info->version . "\n"; echo "local [{$localBranchId}]:" . $addon->getBranchInfo($localBranchId)->version . "\n"; if ($info->version !== $addon->getBranchInfo($localBranchId)->version) { AddonManager::doUpstreamUpdate($addon->getId(), $localBranchId, $info->file, $info->version); } } } } } } else { echo $response; $lines = explode("\n", $response); //basically we're going to construct a fake json response foreach ($lines as $line) { $line = trim($line); if (!isset($res)) { if (strpos($line, "<addon:") === 0) { $ad = substr($line, 7, strlen($line) - 8); $res = new stdClass(); $res->name = "{$ad}.zip"; } } else { if (strpos($line, "</addon>") === 0) { break; } if (!isset($currentChannel)) { if (strpos($line, "<channel:") === 0) { $ch = substr($line, 9, strlen($line) - 10); $currentChannel = new stdClass(); $currentChannel->name = $ch; } } else { if (strpos($line, "</channel>") === 0) { $res->channels[$currentChannel->name] = $currentChannel; unset($currentChannel); } if (strpos($line, "<version:") === 0) { $ch = substr($line, 9, strlen($line) - 10); $currentChannel->version = $ch; } if (strpos($line, "<file:") === 0) { $file = substr($line, 6, strlen($line) - 7); $currentChannel->file = $file; } } } } if (isset($res)) { foreach ($res->channels as $channel => $info) { $arr = (array) $upstream->branch; if (in_array($channel, $arr)) { $localBranchId = array_search($channel, $arr); echo "remote [{$channel}]:" . $info->version . "\n"; echo "local [{$localBranchId}]:" . $addon->getBranchInfo($localBranchId)->version . "\n"; //if($info->version !== $addon->getBranchInfo($localBranchId)->version) { AddonManager::doUpstreamUpdate($addon->getId(), $localBranchId, $info->file, $info->version); //} } } } } } else { } } } }
$_PAGETITLE = "Glass | Update List"; include realpath(dirname(__DIR__) . "/../private/header.php"); include realpath(dirname(__DIR__) . "/../private/navigationbar.php"); require_once realpath(dirname(__DIR__) . "/../private/class/AddonManager.php"); require_once realpath(dirname(__DIR__) . "/../private/class/UserManager.php"); ?> <div class="maincontainer"> <table style="width: 100%"> <thead> <tr><th>Add-On</th><th>Branch</th><th>Version</th></tr> </thead> <tbody> <?php // this is going to be INCREDIBLY inefficent, i'll take another pass later $list = AddonManager::getAll(); foreach ($list as $addon) { $manager = UserManager::getFromBLID($addon->getManagerBLID()); if (is_object($manager)) { $name = $manager->getName(); } else { $name = $addon->getManagerBLID(); } $versionInfo = $addon->getVersionInfo(); foreach ($versionInfo as $branch => $dat) { if (isset($dat->pending)) { echo "<tr>"; echo "<td>"; echo $name; echo "</td>"; echo "<td>";