Commit 480dbf10 authored by bgm's avatar bgm

Merge branch 'stats' into 'master'

Fix scraping drupal.org for project stats

See merge request marketing/civicrm-website!1
parents 5eab9962 0eb6868c
...@@ -51,11 +51,10 @@ class civicrm_org_stats_drupal extends civicrm_org_stats { ...@@ -51,11 +51,10 @@ class civicrm_org_stats_drupal extends civicrm_org_stats {
if ($html === FALSE) { if ($html === FALSE) {
return FALSE; return FALSE;
} }
$html = strstr($html, '</strong>', TRUE); $html = stristr($html, 'project information</h3>');
$html = strstr($html, 'Reported installs'); $matches = [];
$html = strstr($html, '>'); preg_match('#<strong>([0-9,]+)</strong>#', $html, $matches);
$html = str_replace(array('>', ','), '', $html); return !empty($matches[1]) ? str_replace(',', '', $matches[1]) : FALSE;
return is_numeric($html) ? $html : FALSE;
} }
...@@ -67,8 +66,7 @@ class civicrm_org_stats_drupal extends civicrm_org_stats { ...@@ -67,8 +66,7 @@ class civicrm_org_stats_drupal extends civicrm_org_stats {
private function fetch($name) { private function fetch($name) {
$returnedRawValues = drupal_http_request(self::URL . $name); $returnedRawValues = drupal_http_request(self::URL . $name);
if (empty($returnedRawValues->error) && !empty($returnedRawValues->data)) { if (empty($returnedRawValues->error) && !empty($returnedRawValues->data)) {
$html = strstr($returnedRawValues->data, '<h3>Project Information</h3>'); return $returnedRawValues->data;
return $html;
} }
return FALSE; return FALSE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment