function count_servers($plugins, $min_epoch, $matches_required = -1) { $plugin_ids = array(); foreach ($plugins as $plugin) { $plugin_ids[] = $plugin->getID(); } if ($matches_required == -1) { $statement = get_slave_db_handle()->prepare(' select count(*) from ( select 1 from ServerPlugin where Plugin IN ( ' . implode(',', $plugin_ids) . ' ) AND Updated >= ? group by Server ) V'); $statement->execute(array($min_epoch)); } else { $statement = get_slave_db_handle()->prepare(' select count(*) from ( select 1 from ServerPlugin where Plugin IN ( ' . implode(',', $plugin_ids) . ' ) AND Updated >= ? group by Server having count(Plugin) = ? ) V'); $statement->execute(array($min_epoch, $matches_required)); } $row = $statement->fetch(); return $row != null ? $row[0] : 0; }
/** * Get or create a custom column and return the id * * @param $columnName string * @return int * @deprecated */ public function getCustomColumnID($columnName, $attemptedToCreate = false) { global $master_db_handle; // Execute the query $statement = get_slave_db_handle()->prepare('SELECT ID FROM CustomColumn WHERE Name = ?'); $statement->execute(array($columnName)); // Did we get it? if ($row = $statement->fetch()) { return $row['ID']; } if ($attemptedToCreate) { error_fquit("Failed to create custom column: {$columnName}"); } // Nope... $statement = $master_db_handle->prepare('INSERT INTO CustomColumn (Plugin, Name) VALUES (:Plugin, :Name)'); $statement->execute(array(':Plugin' => $this->plugin, ':Name' => $columnName)); return $this->getCustomColumnID($columnName, true); }
$dataSet->SetSerieName('Players', 'Serie1'); $dataSet->SetSerieName('Servers', 'Serie2'); $dataSet->SetYAxisName(''); // Add all of the series $dataSet->AddAllSeries(); // Set us up the bomb $graph = new pChart(REAL_IMAGE_WIDTH, REAL_IMAGE_HEIGHT); $graph->setFontProperties('tahoma.ttf', 8); $graph->setGraphArea(60, 30, REAL_IMAGE_WIDTH - 20, REAL_IMAGE_HEIGHT - 30); $graph->drawFilledRoundedRectangle(7, 7, REAL_IMAGE_WIDTH - 7, REAL_IMAGE_HEIGHT - 7, 5, 240, 240, 240); $graph->drawRoundedRectangle(5, 5, REAL_IMAGE_WIDTH - 5, REAL_IMAGE_HEIGHT - 5, 5, 230, 230, 230); $graph->drawGraphArea(250, 250, 250, true); $graph->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, true, 0, 0); // $graph->drawGrid(4, true, 230, 230, 230, 100); if ($plugin->getID() == GLOBAL_PLUGIN_ID) { $statement = get_slave_db_handle()->prepare('SELECT Sum(GlobalHits) FROM Plugin'); $statement->execute(); $serverStarts = $statement->fetch()[0]; $serversLast24Hours = $plugin->countServersLastUpdated(time() - SECONDS_IN_DAY); } else { $serverStarts = $plugin->getGlobalHits(); $serversLast24Hours = $plugin->countServersLastUpdated(time() - SECONDS_IN_DAY); } // Draw the footer $graph->setFontProperties('pf_arma_five.ttf', 6); $footer = sprintf('%s servers in the last 24 hours with %s all-time server startups ', number_format($serversLast24Hours), number_format($serverStarts)); $graph->drawTextBox(60, REAL_IMAGE_HEIGHT - 25, REAL_IMAGE_WIDTH - 20, REAL_IMAGE_HEIGHT - 7, $footer, 0, 255, 255, 255, ALIGN_RIGHT, true, 0, 0, 0, 30); // Draw the data $graph->drawFilledLineGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 75, true); // Draw legend $graph->drawLegend(65, 35, $dataSet->GetDataDescription(), 255, 255, 255);
$rank_class = 'sparkline_line_neutral'; $rank_change = '±0'; $rank_graph = '4,4,4,4,4,4,4,4'; } } $servers_graph = array(); $players_graph = array(); // $global_stats = $plugin->getGraphByName('Global Statistics'); if ($global_stats == null) { err('No graphs have yet been generated for your plugin.'); exit; } $servers_column = $global_stats->getColumnID('Servers'); $players_column = $global_stats->getColumnID('Players'); $statement = get_slave_db_handle()->prepare('select ColumnID, Sum from GraphData where Plugin = ? AND (ColumnID = ? OR ColumnID = ?) AND Epoch >= ? order by Epoch DESC limit 10'); $cursor = $m_graphdata->find(array('plugin' => intval($plugin->getID()), 'graph' => intval($global_stats->getID()), 'epoch' => array('$gte' => intval(time() - SECONDS_IN_DAY * 5))))->limit(10)->sort(array('epoch' => -1)); foreach ($cursor as $doc) { if (isset($doc['data'][$servers_column])) { $servers_graph[] = $doc['data'][$servers_column]['sum']; } if (isset($doc['data'][$players_column])) { $players_graph[] = $doc['data'][$players_column]['sum']; } } $servers_count = count($servers_graph); if ($servers_count > 2) { $servers_class = $servers_graph[0] > $servers_graph[1] ? 'sparkline_line_good' : 'sparkline_line_bad'; $servers_diff = $servers_graph[0] - $servers_graph[1]; $players_count = count($players_graph); $players_class = $players_graph[0] > $players_graph[1] ? 'sparkline_line_good' : 'sparkline_line_bad';
/** * Load a plugin using its internal ID * * @param $plugin integer * @return Plugin if it exists otherwise NULL */ function loadPluginByID($id) { global $cachedPlugins; if (isset($cachedPlugins[$id])) { return $cachedPlugins[$id]; } $statement = get_slave_db_handle()->prepare('SELECT ID, Parent, Name, Author, Hidden, GlobalHits, Created, Rank, LastRank, LastRankChange, LastUpdated, ServerCount30 FROM Plugin WHERE ID = :ID'); $statement->execute(array(':ID' => $id)); if ($row = $statement->fetch()) { $cachedPlugins[$id] = resolvePlugin($row); return $cachedPlugins[$id]; } return null; }
/** * Load the columns for this graph * @param $limit_results Only show the most used results, mainly just for displaying in /plugin/ */ public function loadColumns($limit_results = false) { $this->columns = array(); $statement = get_slave_db_handle()->prepare('SELECT ID, Name FROM CustomColumn WHERE Plugin = ? AND Graph = ? order by ID ASC'); $statement->execute(array($this->plugin->getID(), $this->id)); while (($row = $statement->fetch()) != null) { $id = $row['ID']; $name = $row['Name']; $this->columns[$id] = $name; } }
$authorID = $row['AuthorID']; $authorName = $row['AuthorName']; $email = $row['Email']; $dbo = $row['DBO']; $created = $row['RequestCreated']; // resolve the plugin $plugin = resolvePlugin($row); if (strstr($dbo, 'http') !== false || strstr($dbo, 'com') !== false || strstr($dbo, 'org')) { $dbo_link = '<a href="' . htmlentities($dbo) . '" target="_blank">' . htmlentities($dbo) . '</a>'; } else { $dbo_link = htmlentities($dbo); } $authorsStatement = get_slave_db_handle()->prepare('SELECT COUNT(*) FROM AuthorACL WHERE Plugin = ? AND Pending = 0'); $authorsStatement->execute(array($plugin->getID())); $existingAuthors = $authorsStatement->fetch()[0]; $authorsStatement = get_slave_db_handle()->prepare('SELECT COUNT(*) FROM AuthorACL WHERE Author = ? AND Pending = 0'); $authorsStatement->execute(array($authorID)); $existingOwnedPlugins = $authorsStatement->fetch()[0]; echo ' <tr> <td> ' . htmlentities($authorName) . ' (' . $authorID . ') (' . $existingOwnedPlugins . ') </td> <td> ' . htmlentities($plugin->getName()) . ' (' . $plugin->getID() . ') (' . $existingAuthors . ') </td> <td> ' . $dbo_link . ' </td> <td> ' . htmlentities($email) . '
} else { if ($hasPlugin && $plugin->getPendingAccess() !== true) { err(sprintf('You already own the plugin <b>%s</b>!', htmlentities($plugin->getName()))); send_add_plugin(htmlentities($plugin->getName()), htmlentities($email), $dbo); } else { $uid = $_SESSION['uid']; $statement = get_slave_db_handle()->prepare('SELECT Created FROM PluginRequest WHERE Author = ? AND Plugin = ? AND Complete = 0'); $statement->execute(array($uid, $plugin->getID())); if ($row = $statement->fetch()) { $created = $row['Created']; err(sprintf('Your ownership request for <b>%s</b> is still pending approval, which was submitted at <b>%s</b>', htmlentities($plugin->getName()), date('H:i T D, F d', $created))); send_add_plugin(htmlentities($plugin->getName()), htmlentities($email), htmlentities($dbo)); } else { // Consider auto approval // Calculate the delta on the database so we can ignore timezones $statement = get_slave_db_handle()->prepare('SELECT UNIX_TIMESTAMP() - Created AS delta FROM Plugin where ID = ?'); $statement->execute(array($plugin->getID())); $delta = $statement->fetch()['delta']; $auto_approved = false; if ($delta < 86400) { $auto_approved = true; } // Auto deny if they have too many plugins if (count($accessible) > 10) { $auto_approved = false; } if ($auto_approved) { $statement = $master_db_handle->prepare('INSERT INTO PluginRequest (Author, Plugin, Email, DBO, Created, Complete) VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), 1)'); $statement->execute(array($uid, $plugin->getID(), $email, $dbo)); $statement = $master_db_handle->prepare('INSERT INTO AuthorACL (Author, Plugin, Pending) VALUES (?, ?, 0)'); $statement->execute(array($uid, $plugin->getID()));
<?php define('ROOT', '../../'); header('Access-Control-Allow-Origin: *'); header('Content-type: application/json'); require_once ROOT . '../private_html/config.php'; require_once ROOT . '../private_html/includes/database.php'; require_once ROOT . '../private_html/includes/func.php'; cacheCurrentPage(); // Our json encoded response $response = array(); if (!isset($_REQUEST['q'])) { $response['msg'] = 'No query provided'; $response['status'] = 'err'; exit(json_encode($response)); } $query = $_REQUEST['q']; $statement = get_slave_db_handle()->prepare('SELECT Name FROM Plugin WHERE Name LIKE ?'); $statement->execute(array('%' . $query . '%')); $matchness = array(); while ($row = $statement->fetch()) { $name = $row['Name']; $matchness[$name] = levenshtein($query, $name); } asort($matchness); $matchness = array_slice($matchness, 0, 10); foreach ($matchness as $name => $lev) { $response[] = $name; } echo json_encode($response);
<?php define('ROOT', './'); session_start(); require_once ROOT . '../private_html/config.php'; require_once ROOT . '../private_html/includes/database.php'; require_once ROOT . '../private_html/includes/func.php'; /// Templating $page_title = 'MCStats :: Homepage'; $container_class = 'container'; send_header(); $plugin = loadPluginByID(GLOBAL_PLUGIN_ID); $graph = $plugin->getOrCreateGraph('Global Statistics'); $serverCount = number_format($plugin->getTimelineCustomLast($graph->getColumnID('Servers'), $graph)); $playerCount = number_format($plugin->getTimelineCustomLast($graph->getColumnID('Players'), $graph)); $statement = get_slave_db_handle()->prepare('SELECT COUNT(*) FROM Plugin where LastUpdated >= ?'); $statement->execute(array(normalizeTime() - SECONDS_IN_DAY)); $row = $statement->fetch(); $pluginCount = $row ? $row[0] : 0; echo <<<END <script type="text/javascript"> \$(document).ready(function() { \$("#players-popover").popover(); }); </script> <div class="row-fluid"> <div class="col-xs-12"> <h1 style="margin-bottom:10px; font-size:57px;">Glorious plugin stats!</h1>
/** * Get the amount of servers that used a given version between the given epochs * @param $minEpoch int * @param $maxEpoch int * @return array keyed by the epoch */ function getTimelineVersion($versionID, $minEpoch, $maxEpoch = -1) { $db_handle = get_slave_db_handle(); // use time() if $max is -1 if ($maxEpoch == -1) { $maxEpoch = time(); } $ret = array(); $statement = $db_handle->prepare('SELECT Count, Epoch FROM VersionTimeline WHERE Plugin = ? AND Version = ? AND Epoch >= ? AND Epoch <= ? ORDER BY Epoch ASC'); $statement->execute(array($this->id, $versionID, $minEpoch, $maxEpoch)); while ($row = $statement->fetch()) { $ret[$row['Epoch']] = $row['Count']; } return $ret; }
$query->execute(array($server['GUID'])); $pluginCount = 0; $pluginsHTML = ''; while ($row = $query->fetch()) { $safeName = htmlentities($row['Name']); $safeUrlName = urlencode($safeName); $pluginCount++; $pluginsHTML .= '<tr> <td> <a href="/plugin/' . $safeUrlName . '">' . $safeName . '</a> </td> <td> ' . $row['Version'] . ' </td> <td> ' . $row['Revision'] . ' </td> <td> ' . epochToHumanString($row['LastSent']) . ' ago </td> </tr> '; } $query = get_slave_db_handle()->prepare(' SELECT Plugin.Name, CustomColumn.ID, Graph.Name as GraphName, CustomColumn.Name as ColumnName, CustomData.DataPoint, (UNIX_TIMESTAMP()-ServerPlugin.Updated) as LastSent FROM CustomData LEFT OUTER JOIN Plugin on Plugin.ID = CustomData.Plugin LEFT OUTER JOIN CustomColumn ON CustomColumn.ID = CustomData.ColumnID LEFT OUTER JOIN Graph ON Graph.ID = CustomColumn.Graph LEFT OUTER JOIN Server on Server.ID = CustomData.Server LEFT OUTER JOIN ServerPlugin ON Server.ID = ServerPlugin.Server WHERE Server.GUID = ? group by CustomColumn.ID order by Plugin.Name asc, LastSent asc limit 1000 '); $query->execute(array($server['GUID'])); $customDataHTML = ''; $c = 0; while ($row = $query->fetch()) { $safeName = htmlentities($row['Name']); $safeUrlName = urlencode($safeName); $customDataHTML .= '<tr> <td> <a href="/plugin/' . $safeUrlName . '">' . $safeName . '</a> </td>