Created
April 29, 2013 19:14
-
-
Save joshmiller83/5483972 to your computer and use it in GitHub Desktop.
Random Community Stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # of new committers | |
$commerce_module = "http://drupal.org/node/605898/committers"; | |
echo return_new_committer_ul($commerce_module,'<a href="http://drupal.org/node/605898/committers">Drupal Commerce</a>'); | |
$commerce_module = "http://drupal.org/node/1079066/committers"; | |
echo return_new_committer_ul($commerce_module,'<a href="http://drupal.org/node/1079066/committers">Drupal Commerce Kickstart</a>'); | |
function return_new_committer_ul ($url,$module) { | |
$doc = new DOMDocument(); | |
$doc->loadHTMLFile($url); | |
$table = parseTable($doc->saveHTML()); | |
$newcommitters = array(); | |
foreach ($table as $row) { | |
$first_commit = strtotime($row['First commit']); | |
if ($first_commit > strtotime("-20 days")) { | |
$newcommitters[$first_commit][] = $row['User']; | |
} | |
} | |
ksort($newcommitters); | |
$return = ""; | |
if ($newcommitters) { | |
$return = "<p><strong>Committers for ".$module."</strong></p><ul>"; | |
$ul = array(); | |
foreach ($newcommitters as $commitdate => $users) { | |
$date = date("W",$commitdate); | |
foreach ($users as $user){ | |
$ul[$date][] = $user; | |
} | |
} | |
foreach ($ul as $date => $users) { | |
$return .= "<li>".date('m-d', strtotime(date("Y")."W".$date."1"))." - ".count($users)." committers</li>"; | |
} | |
return $return."</ul>"; | |
} else { | |
$return = "<p><strong>Committers for ".$module."</strong></p>"; | |
return $return."<p><em>No one new in the last 20 days.</em></p>"; | |
} | |
} | |
function parseTable($html) | |
{ | |
// Find the table | |
preg_match("/<table.*?>.*?<\/[\s]*table>/s", $html, $table_html); | |
// Get title for each row | |
preg_match_all("/<th.*?>(.*?)<\/[\s]*th>/", $table_html[0], $matches); | |
$row_headers = $matches[1]; | |
// Iterate each row | |
preg_match_all("/<tr.*?>(.*?)<\/[\s]*tr>/s", $table_html[0], $matches); | |
$table = array(); | |
foreach($matches[1] as $row_html) | |
{ | |
preg_match_all("/<td.*?>(.*?)<\/[\s]*td>/", $row_html, $td_matches); | |
$row = array(); | |
for($i=0; $i<count($td_matches[1]); $i++) | |
{ | |
$td = strip_tags(html_entity_decode($td_matches[1][$i])); | |
$row[strip_tags($row_headers[$i])] = $td; | |
} | |
if(count($row) > 0) | |
$table[] = $row; | |
} | |
return $table; | |
} | |
function parseTable_noheader($html) | |
{ | |
// Iterate each row | |
preg_match_all("/<tr.*?>(.*?)<\/[\s]*tr>/s", $html, $matches); | |
$table = array(); | |
foreach($matches[0] as $row_html) | |
{ | |
preg_match_all("/<td.*?>(.*?)<\/[\s]*td>/", $row_html, $td_matches); | |
$row = array(); | |
for($i=0; $i<count($td_matches[1]); $i++) | |
{ | |
$td = strip_tags(html_entity_decode($td_matches[1][$i])); | |
$row[$i] = $td; | |
} | |
if(count($row) > 0) | |
$table[] = $row; | |
} | |
return $table; | |
} | |
// Vimeo | |
echo "<p><strong>Vimeo Stats</strong></p>"; | |
$plays = 0; | |
$url = "https://vimeo.com/channels/commerceguys/videos/sort:plays/format:detail"; | |
$page1 = totalplays($url); | |
if ($page1 != "Couldn't load page") { $plays += intval($page1); } | |
echo "<ul><li>Page 1 = $page1</li>"; | |
$url = "https://vimeo.com/channels/commerceguys/videos/page:2/sort:plays/format:detail"; | |
$page2 = totalplays($url); | |
if ($page2 != "Couldn't load page") { $plays += intval($page2); } | |
echo "<li>Page 2 = $page2</li>"; | |
$url = "https://vimeo.com/channels/commerceguys/videos/page:3/sort:plays/format:detail"; | |
$page3 = totalplays($url); | |
if ($page3 != "Couldn't load page") { $plays += intval($page3); } | |
echo "<li>Page 3 = $page3</li>"; | |
$url = "https://vimeo.com/channels/commerceguys/videos/page:4/sort:plays/format:detail"; | |
$page4 = totalplays($url); | |
if ($page4 != "Couldn't load page") { $plays += intval($page4); } | |
echo "<li>Page 4 = $page4</li>"; | |
$url = "https://vimeo.com/channels/commerceguys/videos/page:5/sort:plays/format:detail"; | |
$page5 = totalplays($url); | |
if ($page5 != "Couldn't load page") { $plays += intval($page5); } | |
echo "<li>Page 5 = $page5</li></ul>"; | |
function totalplays($url) { | |
$doc = new DOMDocument(); | |
$doc->loadHTMLFile($url); | |
$html = $doc->saveHTML(); | |
if (trim(strip_tags($html))) { | |
preg_match_all("/<span class=\"plays\".*?>.*?<\/[\s]*span>/s", $html, $span); | |
$plays = 0; | |
foreach ($span[0] as $single) { | |
$text = explode(" ",strip_tags($single)); | |
$text = str_replace(',','',$text[0]); | |
$plays = $plays + $text; | |
} | |
return $plays; | |
} else { return "Couldn't load page"; } | |
} | |
echo $plays." Video Plays on Vimeo"; | |
//var_dump($ul); | |
$url = "http://drupalcode.org/project/commerce.git/shortlog/refs/heads/7.x-1.x"; | |
echo return_new_commits_ul($url,'<a href="http://drupalcode.org/project/commerce.git/shortlog/refs/heads/7.x-1.x">Drupal Commerce</a>'); | |
$url = "http://drupalcode.org/project/commerce_kickstart.git/shortlog/refs/heads/7.x-1.x"; | |
echo return_new_commits_ul($url,'<a href="http://drupalcode.org/project/commerce_kickstart.git/shortlog/refs/heads/7.x-1.x">Commerce Kickstart</a>'); | |
$url = "http://drupalcode.org/project/commerce_kickstart.git/shortlog/refs/heads/7.x-2.x"; | |
echo return_new_commits_ul($url,'<a href="http://drupalcode.org/project/commerce_kickstart.git/shortlog/refs/heads/7.x-2.x">Commerce Kickstart v2</a>'); | |
function return_new_commits_ul ($url,$module) { | |
$doc = new DOMDocument(); | |
$doc->loadHTMLFile($url); | |
$html = $doc->saveHTML(); | |
$table = parseTable_noheader($html); | |
$newcommitters = array(); | |
foreach ($table as $row) { | |
$first_commit = strtotime($row[0]); | |
if ($first_commit > strtotime("-20 days")) { | |
$newcommitters[$first_commit][] = $row[1]; | |
} | |
} | |
ksort($newcommitters); | |
$return = ""; | |
if ($newcommitters) { | |
$return = "<p><strong>Commits for ".$module."</strong></p><ul>"; | |
$ul = array(); | |
foreach ($newcommitters as $commitdate => $users) { | |
$date = date("W",$commitdate); | |
foreach ($users as $user){ | |
$ul[$date][] = $user; | |
} | |
} | |
foreach ($ul as $date => $users) { | |
$return .= "<li>".date('m-d', strtotime(date("Y")."W".$date."1"))." - ".count($users)." commits</li>"; | |
} | |
return $return."</ul>"; | |
} | |
return "No New commits available for $module<br />"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment