| 1 |
<?php |
| 2 |
|
| 3 |
class Prestashop { |
| 4 |
|
| 5 |
/** |
| 6 |
* search for a prestashop in that folder. |
| 7 |
* if this class think that a prestashop is here, returns the version number, normalized. |
| 8 |
*/ |
| 9 |
function search($root) { |
| 10 |
|
| 11 |
if (is_dir($root."/modules") && is_dir($root."/override") && is_dir($root."/pdf")) { |
| 12 |
// >=8 |
| 13 |
if (is_file($root."/app/metadata.json") && filesize($root."/app/metadata.json")<1048576) { |
| 14 |
$f=json_decode(file_get_contents($root."/app/metadata.json"),true); |
| 15 |
if (isset($f["version"])) |
| 16 |
return $f["version"]; |
| 17 |
} |
| 18 |
// <8 |
| 19 |
if (is_file($root."/app/AppKernel.php")) { |
| 20 |
$f=fopen($root."/app/AppKernel.php","rb"); |
| 21 |
if (!$f) return false; |
| 22 |
while($s=fgets($f,1024)) { |
| 23 |
if (preg_match('#const VERSION\s*=\s*[\'"](.*)[\'"];#',$s,$mat)) { |
| 24 |
fclose($f); |
| 25 |
return $mat[1]; |
| 26 |
} |
| 27 |
} |
| 28 |
fclose($f); |
| 29 |
} |
| 30 |
// VERY old ~1.6.1.9 |
| 31 |
if (is_file($root."/install/install_version.php")) { |
| 32 |
$f=fopen($root."/install/install_version.php","rb"); |
| 33 |
if (!$f) return false; |
| 34 |
while($s=fgets($f,1024)) { |
| 35 |
if (preg_match('#define\(\'_PS_INSTALL_VERSION_\',\s*[\'"](.*)[\'"]\);#',$s,$mat)) { |
| 36 |
fclose($f); |
| 37 |
return $mat[1]; |
| 38 |
} |
| 39 |
} |
| 40 |
fclose($f); |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
return false; |
| 45 |
} // search |
| 46 |
|
| 47 |
} // class Prestashop |