コード例 #1
0
 /**
  * Store a key/value pair in the cache
  * @param $key string The key to store as
  * @param $value object The value to store
  * @param $expire int The number of seconds to expire in, 0 for forever
  * @return TRUE on success and FALSE on failure
  */
 public function set($key, $value, $expire = 0)
 {
     if (!$this->isEnabled()) {
         return false;
     }
     if (!$this->attemptedConnection) {
         $this->connect();
     }
     // Check for flags
     if ($expire == CACHE_UNTIL_NEXT_GRAPH) {
         $expire = strtotime('+30 minutes', getLastGraphEpoch());
     }
     $this->handle->set($key, gzencode($value));
     if ($expire > 0) {
         $this->handle->expireat($key, $expire);
     }
     return true;
 }
コード例 #2
0
 /**
  * Generates graph data
  *
  * @static
  * @param $graph Graph
  * @param $columnID int The column ID to generate data for if applicable. Not required for Pie graphs
  * @return array
  */
 public static function generateCustomChartData($graph, $columnID = -1, $hours = 372)
 {
     $_cacheid = 'CustomChart/' . $graph->getID() . '/' . $columnID . '/' . $graph->getType() . '/' . $hours;
     // Check the cache
     // if ($data = $graph->getPlugin()->cacheGet($_cacheid)) {
     //     return json_decode($data);
     //}
     $generatedData = array();
     // calculate the minimum
     $baseEpoch = getLastGraphEpoch();
     $minimum = strtotime('-' . $hours . ' hours', $baseEpoch);
     $maximum = $baseEpoch;
     if ($graph->getType() == GraphType::Pie) {
         // the amounts for each column
         $columnAmounts = array();
         foreach ($graph->getColumns() as $id => $columnName) {
             $columnAmounts[$columnName] = $graph->getPlugin()->getTimelineCustomLast($id, $graph);
         }
         // Now begin our magic
         asort($columnAmounts);
         // Sum all of the points
         $data_sum = array_sum($columnAmounts);
         // remove low outlier data on large datasets
         if ($data_sum > 1000) {
             foreach ($columnAmounts as $columnName => $amount) {
                 if ($amount <= 5) {
                     unset($columnAmounts[$columnName]);
                 }
             }
             // recalculate the data summages
             $data_sum = array_sum($columnAmounts);
         }
         $count = count($columnAmounts);
         if ($count >= MINIMUM_FOR_OTHERS) {
             $others_total = 0;
             foreach ($columnAmounts as $columnName => $amount) {
                 if ($count <= MINIMUM_FOR_OTHERS) {
                     break;
                 }
                 $count--;
                 $others_total += $amount;
                 unset($columnAmounts[$columnName]);
             }
             // Set the 'Others' stat
             $columnAmounts['Others'] = $others_total;
             // Sort again
             arsort($columnAmounts);
         }
         // Now convert it to %
         foreach ($columnAmounts as $columnName => $dataPoint) {
             $percent = round($dataPoint / $data_sum * 100, 2);
             // Leave out 0%s !
             if ($percent == 0) {
                 continue;
             }
             if (is_numeric($columnName) || is_double($columnName)) {
                 // $columnName = "\0" . $columnName;
             }
             $generatedData[] = array($columnName . ' (' . $dataPoint . ')', $percent);
         }
         if (count($generatedData) == 0) {
             $generatedData[] = array('NO DATA', 100);
         }
     } else {
         if ($graph->getType() == GraphType::Donut) {
             // the amounts for each column
             $columnAmounts = array();
             foreach ($graph->getColumns() as $id => $columnName) {
                 $columnAmounts[$columnName] = $graph->getPlugin()->getTimelineCustomLast($id, $graph);
             }
             // Now begin our magic
             asort($columnAmounts);
             // Sum all of the points
             $data_sum = array_sum($columnAmounts);
             // remove low outlier data on large datasets
             if ($data_sum > 1000) {
                 foreach ($columnAmounts as $columnName => $amount) {
                     $percent = round($amount / $data_sum * 100, 2);
                     if ($percent <= 0.25) {
                         $expl = explode('~=~', $columnName);
                         unset($columnAmounts[$columnName]);
                         $otherName = $expl[0] . '~=~Others';
                         if (!isset($columnAmounts[$otherName])) {
                             $columnAmounts[$otherName] = 0;
                         } else {
                             $columnAmounts[$otherName] += round($percent * $data_sum / 100);
                         }
                     }
                 }
                 // recalculate the data summages
                 $data_sum = array_sum($columnAmounts);
                 asort($columnAmounts);
             }
             // Now convert it to %
             $amountsInner = array();
             foreach ($columnAmounts as $columnName => $dataPoint) {
                 $percent = round($dataPoint / $data_sum * 100, 2);
                 // Leave out 0%s !
                 if ($percent == 0) {
                     continue;
                 }
                 if (is_numeric($columnName) || is_double($columnName)) {
                     // $columnName = "\0" . $columnName;
                 }
                 // explode the string on the delimiter
                 $expl = explode('~=~', $columnName);
                 $innerName = $expl[0];
                 $outerName = $expl[1];
                 $amountsInner[$innerName] += $dataPoint;
                 $generatedData[$innerName][] = array("name" => $outerName . ' (' . $dataPoint . ')', "y" => $percent);
             }
             foreach ($amountsInner as $innerName => $amount) {
                 $generatedData[$innerName . '<br/>(' . $amount . ')'] = $generatedData[$innerName];
                 unset($generatedData[$innerName]);
             }
         } else {
             // Get all of the custom data points
             $dataPoints = $graph->getPlugin()->getTimelineCustom($columnID, $minimum, $graph);
             // Add all of them to the array
             foreach ($dataPoints as $epoch => $dataPoint) {
                 if ($dataPoint == 0) {
                     continue;
                 }
                 $generatedData[] = array($epoch * 1000, $dataPoint);
             }
         }
     }
     // Cache it
     // $graph->getPlugin()->cacheSet($_cacheid, json_encode($generatedData));
     return $generatedData;
 }
コード例 #3
0
ファイル: privacy.php プロジェクト: willies952002/mcstats.org
<?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';
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', getLastGraphEpoch()) . ' GMT');
/// Templating
$page_title = 'MCStats :: Privacy Policy';
// $container_class = 'container';
send_header();
echo <<<END

<div class="row-fluid" style="margin-left: 25%; text-align: center;">
    <div class="span6" style="width: 50%;">
        <h1 style="margin-bottom:30px; font-size:40px;">
            Privacy Policy
        </h1>
    </div>
</div>

<div class="row-fluid" style="margin-left: 25%; text-align: center;">
    <div class="span6" style="width: 50%;">
        <p>
            All plugins that use MCStats will send data to a central server (http://mcstats.org)
        </p>
    </div>
</div>

<div class="row-fluid" style="margin-left: 30%;">
コード例 #4
0
ファイル: func.php プロジェクト: willies952002/mcstats.org
function insert_cache_headers()
{
    global $config;
    header('X-MCStats-Cache: no');
    // if (true) return;
    header("Cache-Control: must-revalidate");
    // header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', getLastGraphEpoch() + (60 * $config['graph']['interval'])));
    header('Expires: -1');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', getLastGraphEpoch()));
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= getLastGraphEpoch() && graph_generator_percentage() === null) {
            header('HTTP/1.1 304 Not Modified');
            header('X-MCStats-Cache: yes (not modified)');
            exit;
        }
    }
}
コード例 #5
0
 /**
  * Gets the last set of country timelines
  * @param $minEpoch int
  * @param $maxEpoch int
  * @return array keyed by the epoch
  */
 function getTimelineCountryLast()
 {
     $db_handle = get_slave_db_handle();
     $ret = array();
     $epoch = getLastGraphEpoch();
     $statement = $db_handle->prepare('SELECT Country, Servers FROM CountryTimeline WHERE Plugin = ? AND Epoch = ?');
     $statement->execute(array($this->id, $epoch));
     while ($row = $statement->fetch()) {
         $country = $row['Country'];
         $servers = $row['Servers'];
         $ret[$epoch][$country] = $servers;
     }
     return $ret;
 }