public function _updateSavedStats() { global $conf; $dir = $conf['metadir'] . '/'; // Return the files in the directory /data/meta $files = $this->_getChangeLogs($dir); // Read saved data from JSON file $sd = authorstatsReadJSON(); // Get last change $lastchange = empty($sd) ? -1 * PHP_INT_MAX - 1 : (int) $sd["lastchange"]; $newlast = $lastchange; foreach ($files as $file) { $file_contents = array_reverse(file($file)); foreach ($file_contents as $line) { $r = $this->_parseChange($line); if ($r["timestamp"] <= $lastchange) { break; } // Update the last if there is a more recent change $newlast = max($newlast, $r["timestamp"]); // If the author is not in the array, initialize his stats if (!isset($sd["authors"][$r["author"]])) { $sd["authors"][$r["author"]]["C"] = 0; $sd["authors"][$r["author"]]["E"] = 0; $sd["authors"][$r["author"]]["e"] = 0; $sd["authors"][$r["author"]]["D"] = 0; $sd["authors"][$r["author"]]["R"] = 0; $sd["authors"][$r["author"]]["pm"] = array(); } else { // Initialize month if doesn't exist // else increment it if (!isset($sd["authors"][$r["author"]]["pm"][$r["date"]])) { $sd["authors"][$r["author"]]["pm"][$r["date"]] = 1; } else { $sd["authors"][$r["author"]]["pm"][$r["date"]]++; } } $sd["authors"][$r["author"]][$r["type"]]++; } } $sd["lastchange"] = $newlast; authorstatsSaveJSON($sd); }
function _getMonthlyStatsTable($months) { $output = "<h3>Contribution in the last " . $months . " months</h3><table class=\"authorstats-table\"><tr><th>Name</th><th>Contrib</th></tr>"; $authors = authorstatsReadJSON(); $authors = $authors["authors"]; if (!$authors) { return "There are no stats to output!"; } foreach ($authors as $name => $author) { $authors[$name]['lmc'] = $this->_getLastMonthsContrib($author, $months); } uasort($authors, array($this, '_sortByLastMonthsContrib')); foreach ($authors as $name => $author) { if ($authors[$name]['lmc'] > 0) { $output .= "<tr><th>" . $name . "</th><td>" . strval($authors[$name]['lmc']) . "</td></tr>"; } } $output .= "</table>"; return $output; }