
Untitled
By: a guest on
Sep 22nd, 2011 | syntax:
PHP | size: 1.21 KB | hits: 86 | expires: Never
<?php
// Example version.php file
$text = '
This is a version.php file with its contents, friends
and other variables. Let\'s see how we do parse it
defined(\'MOODLE_INTERNAL\') || die();
$plugin->version = 2010073100;
$plugin->requires = 2010090501; // Requires this Moodle version
$plugin->dependencies = array(
\'mod_quiz\' => 2011090100,
\'qtype_pmatch\' => ANY_VERSION);
';
// Very basic implementation ;-) Tons of checks/cleanup needed (empties, bad formed, injected...)
preg_match('/\$plugin\->dependencies\s*=\s*array\s*\((.*)\)/s', $text, $matches);
if (isset($matches[1])) {
$ofinterest = preg_replace('/[ \t\']+/s', '', trim($matches[1])); // Whitespace, comma cleanup
$ofinterest = preg_replace('/[\n\r]+/s', '\n', $ofinterest); // CRLF cleanup
$ofinterestarr = explode('\n', $ofinterest);
foreach ($ofinterestarr as $dependency) {
if (strpos($dependency, '=>') !== false) {
$dependencyarr = explode('=>', $dependency);
$dependencies[$dependencyarr[0]] = $dependencyarr[1];
} else {
die('wrong dependency spec');
}
}
var_dump($dependencies);
} else {
die('not dependencies found');
}