|
1
|
|
|
<?php namespace XoopsModules\Modulebuilder; |
|
2
|
|
|
|
|
3
|
|
|
use XoopsModules\Modulebuilder; |
|
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
|
|
|
* modulebuilder module. |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
18
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
19
|
|
|
* |
|
20
|
|
|
* @since 2.5.0 |
|
21
|
|
|
* |
|
22
|
|
|
* @author Xoops Team Developement Modules - https://xoops.org |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
require_once \dirname(__DIR__, 3) . '/mainfile.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $val |
|
29
|
|
|
*/ |
|
30
|
|
|
function phpFunction($val = '') |
|
31
|
|
|
{ // create php function here |
|
32
|
|
|
echo $val; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$myfunction = '\\XoopsModules\\Modulebuilder\\' . $_GET['f']; |
|
36
|
|
|
|
|
37
|
|
|
if (\function_exists($myfunction)) { |
|
38
|
|
|
$ret = \XoopsModules\Modulebuilder\LogoGenerator::createLogo($_GET['iconName'], $_GET['caption']); |
|
39
|
|
|
phpFunction($ret); |
|
|
|
|
|
|
40
|
|
|
} else { |
|
41
|
|
|
echo 'Method Not Exist'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Class LogoGenerator. |
|
46
|
|
|
*/ |
|
47
|
|
|
class LogoGenerator |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @param $logoIcon |
|
51
|
|
|
* @param $moduleName |
|
52
|
|
|
* |
|
53
|
|
|
* @return bool|string |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function createLogo($logoIcon, $moduleName) |
|
56
|
|
|
{ |
|
57
|
|
|
if (!\extension_loaded('gd')) { |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
$requiredFunctions = ['imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate']; |
|
61
|
|
|
foreach ($requiredFunctions as $func) { |
|
62
|
|
|
if (!\function_exists($func)) { |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$dirname = 'modulebuilder'; |
|
68
|
|
|
$iconFileName = \XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32/' . \basename($logoIcon); |
|
69
|
|
|
|
|
70
|
|
|
//$dirFonts = TDMC_PATH . "/assets/fonts"; |
|
71
|
|
|
//$dirLogos = TDMC_PATH . "/assets/images/logos"; |
|
72
|
|
|
$dirFonts = \XOOPS_ROOT_PATH . '/modules/' . $dirname . '/assets/fonts'; |
|
73
|
|
|
$dirLogos = \XOOPS_ROOT_PATH . '/modules/' . $dirname . '/assets/images/logos'; |
|
74
|
|
|
|
|
75
|
|
|
if (!\file_exists($imageBase = $dirLogos . '/empty.png') |
|
76
|
|
|
|| !\file_exists($font = $dirFonts . '/VeraBd.ttf') |
|
77
|
|
|
|| !\file_exists($iconFile = $iconFileName)) { |
|
78
|
|
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$imageModule = \imagecreatefrompng($imageBase); |
|
82
|
|
|
$imageIcon = \imagecreatefrompng($iconFile); |
|
83
|
|
|
|
|
84
|
|
|
// Write text |
|
85
|
|
|
$textColor = imagecolorallocate($imageModule, 0, 0, 0); |
|
86
|
|
|
$spaceToBorder = (92 - mb_strlen($moduleName) * 7.5) / 2; |
|
87
|
|
|
imagefttext($imageModule, 8.5, 0, $spaceToBorder, 45, $textColor, $font, $moduleName, []); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32); |
|
90
|
|
|
|
|
91
|
|
|
//$targetImage = TDMC_UPLOAD_IMGMOD_URL . "/" . $moduleName . "_logo.png"; |
|
92
|
|
|
$targetImage = '/uploads/' . $dirname . '/images/modules/' . $moduleName . '_logo.png'; |
|
93
|
|
|
|
|
94
|
|
|
\imagepng($imageModule, \XOOPS_ROOT_PATH . $targetImage); |
|
95
|
|
|
|
|
96
|
|
|
\imagedestroy($imageModule); |
|
97
|
|
|
\imagedestroy($imageIcon); |
|
98
|
|
|
|
|
99
|
|
|
return \XOOPS_URL . $targetImage; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|