Debian Codegraph @

src/softs/Joomla.php

raw
1 <?php
2
3 class Joomla {
4
5 /**
6 * search for a joomla in that folder.
7 * if this class think that a joomla is here, returns the version number, normalized.
8 */
9 function search($root) {
10
11 if (is_file($root."/includes/version.php")) {
12 $v=$this->parseversion($root."/includes/version.php");
13 if ($v) return $v;
14 }
15 if (is_file($root."/libraries/joomla/version.php")) {
16 $v=$this->parseversion($root."/libraries/joomla/version.php");
17 if ($v) return $v;
18 }
19 if (is_file($root."/libraries/cms/version/version.php")) {
20 $v=$this->parseversion($root."/libraries/cms/version/version.php");
21 if ($v) return $v;
22 }
23
24 if (is_file($root."/libraries/src/Version.php")) {
25 $version=false; $minor=false; $patch=false;
26 $f=fopen($root."/libraries/src/Version.php","rb");
27 if (!$f) return false;
28 while($s=fgets($f,1024)) {
29 if (preg_match('#const\s+MAJOR_VERSION\s+=\s+([0-9]+);#',$s,$mat)) {
30 $version=$mat[1];
31 }
32 if (preg_match('#const\s+MINOR_VERSION\s+=\s+([0-9]+);#',$s,$mat)) {
33 $minor=$mat[1];
34 }
35 if (preg_match('#const\s+PATCH_VERSION\s+=\s+([0-9]+);#',$s,$mat)) {
36 $patch=$mat[1];
37 }
38
39 }
40 fclose($f);
41 if ($version && $minor && $patch) return $version.".".$minor.".".$patch;
42 }
43
44 return false;
45
46 } // search
47
48
49 function parseversion($file) {
50 $version=false; $patch=false;
51 $f=fopen($file,"rb");
52 if (!$f) return false;
53 while($s=fgets($f,1024)) {
54 if (preg_match('#var\s+\$RELEASE\s+=\s+\'([^\']+)\';#',$s,$mat)) {
55 $version=$mat[1];
56 }
57 if (preg_match('#var\s+\$DEV_LEVEL\s+=\s+\'([^\']+)\';#',$s,$mat)) {
58 $patch=$mat[1];
59 }
60 }
61 fclose($f);
62 if ($version && $patch) return $version.".".$patch;
63 return false;
64 }
65
66 } // class Joomla