1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Extgallery\Common; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
17
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
18
|
|
|
* @author mamba <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
trait VersionChecks |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Verifies XOOPS version meets minimum requirements for this module |
24
|
|
|
* @static |
25
|
|
|
* @param \XoopsModule $module |
26
|
|
|
* |
27
|
|
|
* @param null|string $requiredVer |
28
|
|
|
* @return bool true if meets requirements, false if not |
29
|
|
|
*/ |
30
|
|
|
public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
31
|
|
|
{ |
32
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
33
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
34
|
|
|
if (null === $module) { |
35
|
|
|
$module = \XoopsModule::getByDirname($moduleDirName); |
36
|
|
|
} |
37
|
|
|
xoops_loadLanguage('admin', $moduleDirName); |
38
|
|
|
|
39
|
|
|
//check for minimum XOOPS version |
40
|
|
|
$currentVer = mb_substr(XOOPS_VERSION, 6); // get the numeric part of string |
41
|
|
|
if (null === $requiredVer) { |
42
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
|
|
|
43
|
|
|
} |
44
|
|
|
$success = true; |
45
|
|
|
|
46
|
|
|
if (version_compare($currentVer, $requiredVer, '<')) { |
47
|
|
|
$success = false; |
48
|
|
|
$module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $success; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Verifies PHP version meets minimum requirements for this module |
56
|
|
|
* @static |
57
|
|
|
* @param \XoopsModule|null $module |
58
|
|
|
* |
59
|
|
|
* @return bool true if meets requirements, false if not |
60
|
|
|
*/ |
61
|
|
|
public static function checkVerPhp(\XoopsModule $module = null) |
62
|
|
|
{ |
63
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
64
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
65
|
|
|
if (null === $module) { |
66
|
|
|
$module = \XoopsModule::getByDirname($moduleDirName); |
67
|
|
|
} |
68
|
|
|
xoops_loadLanguage('admin', $moduleDirName); |
69
|
|
|
// check for minimum PHP version |
70
|
|
|
$success = true; |
71
|
|
|
|
72
|
|
|
$verNum = PHP_VERSION; |
73
|
|
|
$reqVer = &$module->getInfo('min_php'); |
74
|
|
|
|
75
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
76
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
|
|
|
|
77
|
|
|
$module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
|
|
|
78
|
|
|
$success = false; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $success; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
* compares current module version with latest GitHub release |
88
|
|
|
* @static |
89
|
|
|
* @param \Xmf\Module\Helper $helper |
90
|
|
|
* @param string|null $source |
91
|
|
|
* @param string|null $default |
92
|
|
|
* |
93
|
|
|
* @return string|array info about the latest module version, if newer |
94
|
|
|
*/ |
95
|
|
|
|
96
|
|
|
public static function checkVerModule($helper, $source = 'github', $default = 'master') |
97
|
|
|
{ |
98
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
99
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
100
|
|
|
$update = ''; |
101
|
|
|
$repository = 'XoopsModules25x/' . $moduleDirName; |
102
|
|
|
// $repository = 'XoopsModules25x/publisher'; //for testing only |
103
|
|
|
$ret = ''; |
104
|
|
|
$infoReleasesUrl = "https://api.github.com/repos/$repository/releases"; |
105
|
|
|
if ('github' === $source) { |
106
|
|
|
if (function_exists('curl_init') && false !== ($curlHandle = curl_init())) { |
107
|
|
|
curl_setopt($curlHandle, CURLOPT_URL, $infoReleasesUrl); |
108
|
|
|
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); |
109
|
|
|
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); |
110
|
|
|
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]); |
111
|
|
|
$curlReturn = curl_exec($curlHandle); |
112
|
|
|
if (false === $curlReturn) { |
113
|
|
|
trigger_error(curl_error($curlHandle)); |
114
|
|
|
} elseif (false !== strpos($curlReturn, 'Not Found')) { |
115
|
|
|
trigger_error('Repository Not Found: ' . $infoReleasesUrl); |
116
|
|
|
} else { |
117
|
|
|
$file = json_decode($curlReturn, false); |
118
|
|
|
$latestVersionLink = sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->tag_name : $default); |
119
|
|
|
$latestVersion = $file[0]->tag_name; |
120
|
|
|
$prerelease = $file[0]->prerelease; |
121
|
|
|
if ('master' !== $latestVersionLink) { |
122
|
|
|
$update = constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion; |
123
|
|
|
} |
124
|
|
|
//"PHP-standardized" version |
125
|
|
|
$latestVersion = mb_strtolower($latestVersion); |
126
|
|
|
if (false !== mb_strpos($latestVersion, 'final')) { |
127
|
|
|
$latestVersion = str_replace('_', '', mb_strtolower($latestVersion)); |
128
|
|
|
$latestVersion = str_replace('final', '', mb_strtolower($latestVersion)); |
129
|
|
|
} |
130
|
|
|
$moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status')); |
|
|
|
|
131
|
|
|
//"PHP-standardized" version |
132
|
|
|
$moduleVersion = str_replace(' ', '', mb_strtolower($moduleVersion)); |
133
|
|
|
// $moduleVersion = '1.0'; //for testing only |
134
|
|
|
// $moduleDirName = 'publisher'; //for testing only |
135
|
|
|
if (!$prerelease && version_compare($moduleVersion, $latestVersion, '<')) { |
136
|
|
|
$ret = []; |
137
|
|
|
$ret[] = $update; |
138
|
|
|
$ret[] = $latestVersionLink; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
curl_close($curlHandle); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
return $ret; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|