1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Tdmdownloads\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|null $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(__DIR__)); |
33
|
|
|
if (null === $module) { |
34
|
|
|
$module = \XoopsModule::getByDirname($moduleDirName); |
35
|
|
|
} |
36
|
|
|
xoops_loadLanguage('admin', $moduleDirName); |
37
|
|
|
|
38
|
|
|
//check for minimum XOOPS version |
39
|
|
|
$currentVer = mb_substr(XOOPS_VERSION, 6); // get the numeric part of string |
40
|
|
|
if (null === $requiredVer) { |
41
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
|
|
|
42
|
|
|
} |
43
|
|
|
$success = true; |
44
|
|
|
|
45
|
|
|
if (version_compare($currentVer, $requiredVer, '<')) { |
46
|
|
|
$success = false; |
47
|
|
|
$module->setErrors(sprintf(_AM_WFL_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $success; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Verifies PHP version meets minimum requirements for this module |
55
|
|
|
* @static |
56
|
|
|
* @param \XoopsModule $module |
57
|
|
|
* |
58
|
|
|
* @return bool true if meets requirements, false if not |
59
|
|
|
*/ |
60
|
|
|
public static function checkVerPhp(\XoopsModule $module) |
61
|
|
|
{ |
62
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
63
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
|
|
|
|
64
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
|
|
|
|
65
|
|
|
// check for minimum PHP version |
66
|
|
|
$success = true; |
67
|
|
|
$verNum = PHP_VERSION; |
68
|
|
|
$reqVer = $module->getInfo('min_php'); |
69
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
70
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
|
|
|
|
71
|
|
|
$module->setErrors(sprintf(_AM_WFL_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
|
|
|
72
|
|
|
$success = false; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $success; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* |
81
|
|
|
* compares current module version with latest GitHub release |
82
|
|
|
* @static |
83
|
|
|
* @param \Xmf\Module\Helper $helper |
84
|
|
|
* @param string $location |
85
|
|
|
* @param string $default |
86
|
|
|
* |
87
|
|
|
* @return string link to the latest module version, if newer |
88
|
|
|
*/ |
89
|
|
|
|
90
|
|
|
public static function checkVerModule($helper, $location = 'github', $default = 'master') |
91
|
|
|
{ |
92
|
|
|
$moduleDirName = basename(dirname(dirname(__DIR__))); |
93
|
|
|
$update = ''; |
94
|
|
|
$repository = 'XoopsModules25x/' . $moduleDirName; |
95
|
|
|
// $repository = 'XoopsModules25x/publisher'; //uncomment for testing |
96
|
|
|
$ret = ''; |
97
|
|
|
|
98
|
|
|
if ('github' === $location) { |
99
|
|
|
$file = @json_decode(@file_get_contents("https://api.github.com/repos/$repository/releases", false, stream_context_create(['http' => ['header' => "User-Agent:Publisher\r\n"]]))); |
100
|
|
|
$latestReleaseLink = sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->tag_name : $default); |
101
|
|
|
$latestRelease = substr(strrchr($latestReleaseLink, "/"), 1, -4); |
102
|
|
|
if ('master' !== $latestRelease) { |
103
|
|
|
$update = '<span><strong> Latest Release: </strong>' . ' <a href="' . $latestReleaseLink . '">' . $latestRelease . '</a> </span><br><br>'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$moduleVersion = round($helper->getConfig('version') / 100, 2); |
107
|
|
|
// $moduleVersion = '3.0'; //uncomment for testing |
108
|
|
|
|
109
|
|
|
$ret .= "<div align='center'>"; |
110
|
|
|
|
111
|
|
|
// $ret .= "<a href='https://xoops.org/'><img src='../assets/images/icons/32/xoopsmicrobutton.gif'></a><br>"; |
112
|
|
|
if (version_compare($moduleVersion, $latestRelease, '<')) { |
113
|
|
|
// $ret .= "| "; |
114
|
|
|
$ret .= " <span style='color: #FF0000; font-size:11px' " . 'Latest Release: </span>' . $update . "<a href='https://github.com/XoopsModules25x/$moduleDirName/releases/'>"; |
115
|
|
|
$ret .= "<img src='https://img.shields.io/github/release/XoopsModules25x/$moduleDirName.svg?style=flat'></a>"; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
$GLOBALS['xoopsTpl']->assign('latestModRelease', $ret); |
119
|
|
|
return $ret; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|