function announcements_feed_is_relevant_item
Check whether the version given is relevant to the Drupal version used.
Parameters
string $version: Version to check.
Return value
bool Return TRUE if the version matches Drupal version.
2 calls to announcements_feed_is_relevant_item()
- AnnounceFeedTestRelevantVersion::testIsRelevantItem in modules/
announcements_feed/ tests/ announce_feed_test.test - Test for validating the announcements_feed_is_relevant_item function.
- announcements_feed_filter_announcements in modules/
announcements_feed/ announcements_feed.inc - Filter the announcements relevant to the Drupal version used with valid URL controlled by drupal.org.
File
-
modules/
announcements_feed/ announcements_feed.inc, line 178
Code
function announcements_feed_is_relevant_item($version) {
if ($version == '*') {
return TRUE;
}
// Split the version if received in || formats.
$version_patterns = '/\\|\\|/';
$all_versions = preg_split($version_patterns, $version);
// The operation is optional and defaults to equals.
$p_op = '(?P<operation>!=|\\^|==|=|<|<=|>|>=|<>)?';
$operations = '=';
// Extracts major version from version string like 7, 8, 9.
$p_major = '(?P<major>\\d+)';
// Extracts minor version from version string.
$p_minor = '(?P<minor>(?:\\d+|x)(?:-[A-Za-z]+\\d+)?)';
foreach ($all_versions as $version) {
if (preg_match("/^\\s*{$p_op}\\s*{$p_major}(\\.{$p_minor})?/", $version, $matches)) {
$feed_version = $matches['major'];
if (!empty($matches['minor'])) {
$feed_version = $matches['major'] . '.' . $matches['minor'];
}
if (!empty($matches['operation'])) {
$operations = $matches['operation'];
if ($operations == '^') {
$operations = '>=';
}
}
if (isset($operations) && version_compare(VERSION, $feed_version, $operations)) {
return TRUE;
}
}
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.