Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. // Example version.php file
  4.  
  5. $text = '
  6.  
  7. This is a version.php file with its contents, friends
  8. and other variables. Let\'s see how we do parse it
  9.  
  10. defined(\'MOODLE_INTERNAL\') || die();
  11.  
  12. $plugin->version  = 2010073100;
  13. $plugin->requires = 2010090501;   // Requires this Moodle version
  14. $plugin->dependencies = array(
  15.    \'mod_quiz\' => 2011090100,
  16.    \'qtype_pmatch\' => ANY_VERSION);
  17. ';
  18.  
  19. // Very basic implementation ;-) Tons of checks/cleanup needed (empties, bad formed, injected...)
  20.  
  21. preg_match('/\$plugin\->dependencies\s*=\s*array\s*\((.*)\)/s', $text, $matches);
  22. if (isset($matches[1])) {
  23.     $ofinterest = preg_replace('/[ \t\']+/s', '', trim($matches[1])); // Whitespace, comma cleanup
  24.     $ofinterest = preg_replace('/[\n\r]+/s', '\n', $ofinterest);      // CRLF cleanup
  25.     $ofinterestarr = explode('\n', $ofinterest);
  26.     foreach ($ofinterestarr as $dependency) {
  27.         if (strpos($dependency, '=>') !== false) {
  28.             $dependencyarr = explode('=>', $dependency);
  29.             $dependencies[$dependencyarr[0]] = $dependencyarr[1];
  30.         } else {
  31.             die('wrong dependency spec');
  32.         }
  33.     }
  34.     var_dump($dependencies);
  35. } else {
  36.     die('not dependencies found');
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement