function timeago_get_version in Timeago 7.2
Gets the version information from a file.
Parameters
$path: The path of the file to check.
$options: (Optional) An associative array containing any of the following keys:
- pattern: A string containing a regular expression (PCRE) to match the library version. Defaults to '@version\s+([0-9a-zA-Z\.-]+)@'.
- lines: The maximum number of lines in which to search for the pattern. Defaults to 20.
Return value
A string containing the version of a file, or FALSE if no version is detected or file fails to open.
See also
1 call to timeago_get_version()
- timeago_requirements in ./
timeago.install - Implements hook_requirements().
File
- ./
timeago.install, line 97 - (Un)installs the Timeago module.
Code
function timeago_get_version($path, $options = array()) {
// Provide defaults.
$options += array(
'pattern' => '@version\\s+([0-9a-zA-Z\\.-]+)@',
'lines' => 20,
);
$file = drupal_http_request(file_create_url($path))->data;
if ($file) {
foreach (preg_split("/((\r?\n)|(\r\n?))/", $file) as $line) {
if ($options['lines']-- && $line && preg_match($options['pattern'], $line, $matches)) {
return $matches[1];
}
}
}
return FALSE;
}