Created
October 26, 2017 05:26
-
-
Save iamstoick/e53d5d58a05889be300198b1a71577fa to your computer and use it in GitHub Desktop.
Drupal
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
$modules = array(); | |
$status = array('rc', 'dev', 'alpha', 'beta',); | |
foreach (system_rebuild_module_data() as $module) { | |
// We deal only with enabled modules. | |
if ($module->status != 1) { | |
continue; | |
} | |
// We deal only with contrib modules. | |
if (strpos($module->uri, 'sites/all/modules/contrib/') !== 0) { | |
continue; | |
} | |
// Get the release status. | |
$key = 'stable'; | |
foreach ($status as $s) { | |
if (strpos($module->info['version'], '-' . $s)) { | |
$key = $s; | |
break; | |
} | |
} | |
// Get the module name from the directory. | |
// It avoids multiple entries for sub-modules. | |
$name = explode('/', $module->uri)[4]; | |
$modules[$key][$name] = $module; | |
} | |
echo '<table>'; | |
foreach ($modules as $status => $smodules) { | |
if ($status == 'stable') { | |
continue; | |
} | |
foreach ($smodules as $name => $module) { | |
// Get the number of download for this module from d.o. | |
$cache = cache_get('count_' . $name); | |
if (empty($cache)) { | |
$count = '???'; | |
if (($html = file_get_contents('https://drupal.org/project/' . $name)) !== FALSE) { | |
preg_match_all('#<li>Reported installs: <strong>(\d+[\,]{1}\d+)+<#', $html, $matches); | |
if (isset($matches[1][0])) { | |
cache_set('count_' . $name, $matches[1][0]); | |
$count = $matches[1][0]; | |
} | |
} | |
} | |
else { | |
$count = $cache->data; | |
} | |
// Get the latest release number from d.o. | |
$cache = cache_get('latest_release_' . $name); | |
if (empty($cache)) { | |
$result = drupal_http_request('https://updates.drupal.org/release-history/' . $name . '/7.x'); | |
$xml = simplexml_load_string($result->data); | |
$release = (string) @$xml->xpath("/project/releases/release[status='published']")[0]->version; | |
cache_set('latest_release_' . $name, $release); | |
} | |
else { | |
$release = $cache->data; | |
} | |
echo '<tr><td>' . $name .'</td><td>' . $module->info['version'] . '</td><td>' . $release . '</td><td>' . $count . '</td></tr>'; | |
} | |
} | |
echo '</table>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment