| 1 |
<?php |
| 2 |
|
| 3 |
class Drupal { |
| 4 |
|
| 5 |
/** |
| 6 |
* search for a drupal in that folder. |
| 7 |
* if this class think that a drupal is here, returns the version number, normalized. |
| 8 |
*/ |
| 9 |
function search($root) { |
| 10 |
|
| 11 |
if (is_file($root."/index.php") && is_dir($root."/modules") && is_dir($root."/sites")) { |
| 12 |
// detect 3 different drupal version spans |
| 13 |
// 5/6/7: |
| 14 |
if (is_file($root."/modules/block/block.info")) { |
| 15 |
$f=fopen($root."/modules/block/block.info","rb"); |
| 16 |
if (!$f) return false; |
| 17 |
while($s=fgets($f,1024)) { |
| 18 |
if (preg_match('#version\s+=\s+[\'"](.*)[\'"]#',$s,$mat)) { |
| 19 |
fclose($f); |
| 20 |
return $mat[1]; |
| 21 |
} |
| 22 |
} |
| 23 |
fclose($f); |
| 24 |
} |
| 25 |
// 8/9/10 |
| 26 |
if (is_file($root."/composer.lock") && filesize($root."/composer.lock")<1048576) { |
| 27 |
$f=json_decode(file_get_contents($root."/composer.lock"),true); |
| 28 |
if (!$f) return false; |
| 29 |
foreach($f["packages"] as $one) { |
| 30 |
if ($one["name"]=="drupal/core") |
| 31 |
return $one["version"]; |
| 32 |
} |
| 33 |
} |
| 34 |
// 4 |
| 35 |
if (is_file($root."/CHANGELOG.txt")) { |
| 36 |
$f=fopen($root."/CHANGELOG.txt","rb"); |
| 37 |
if (!$f) return false; |
| 38 |
$s=fgets($f,1024); |
| 39 |
if (preg_match('#^Drupal ([^,]+),#',$s,$mat)) { |
| 40 |
return $mat[1]; |
| 41 |
} |
| 42 |
} |
| 43 |
return false; // no case found :/ TODO: spit out a warning? |
| 44 |
} else { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
} // search |
| 49 |
|
| 50 |
} // class Drupal |