getdata.php 1.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
require_once(dirname(__DIR__) . '/config.php');

// Initialize database
$dbh = new PDO('mysql:dbname='.DBNAME.';host='.DBHOST, DBUSER, DBPASS);

// Calculate start and end date (monthly stats only)
$start_date = '2006-09-01';
$end_date = date('Y-m-01', strtotime('-1 month'));

// Get statistics from Sourceforge
$url = "http://sourceforge.net/projects/civicrm/files/stats/json?start_date=$start_date&end_date=$end_date";
$result = json_decode(file_get_contents($url));
//print_r($result);

// by country
$dbh->query("DELETE FROM sourceforge_download WHERE type='C'");
$query = "INSERT INTO sourceforge_download (type, label, value) VALUES ";
foreach ($result->countries as $stat) {
  $query .= "('C', \"$stat[0]\", $stat[1]),";
}
$dbh->query(substr($query,0,-1));

// by month
$dbh->query("DELETE FROM sourceforge_download WHERE type='M'");
$query = "INSERT INTO sourceforge_download (type, label, value) VALUES ";
foreach ($result->downloads as $stat) {
28 29 30 31 32
  // Workaround for sf.net adding extra 0 values in their stats
  if (substr($stat[0], -8) == '00:00:00') {
    $stat[0] = substr($stat[0], 0, 7); // keep only month part of string
    $query .= "('M', '$stat[0]', $stat[1]),";
  }
33 34
}
$dbh->query(substr($query,0,-1));