Completed
Push — master ( e91126...cc5cb8 )
by Gino
03:37
created

TDMCreateLogo::createLogo()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 47
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 47
rs 6.7272
cc 7
eloc 27
nc 6
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 29 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * modules class.
15
 *
16
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.7
20
 *
21
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
22
 *
23
 * @version         $Id: 1.91 logo.php 13040 2015-04-25 15:12:12Z timgno $
24
 */
25
include __DIR__.'/autoload.php';
26
/**
27
 * Class TDMCreateLogo
28
 */
29
class TDMCreateLogo
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
30
{    
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
31
    /*
32
    *  @static function &getInstance
33
    *  @param null
34
    */
35
    /**
36
     * @return TDMCreateModules
37
     */
38
    public static function &getInstance()
39
    {
40
        static $instance = false;
41
        if (!$instance) {
42
            $instance = new self();
43
        }
44
45
        return $instance;
46
    }
47
    	
48
	/*
49
    *  @private static function createLogo
50
    *  @param mixed $logoIcon
51
    *  @param string $moduleDirname
52
    */
53
    /**
54
     * @param $logoIcon
55
     * @param $moduleDirname
56
     *
57
     * @return bool|string
58
     */
59
    /*private static function createLogo($logoIcon, $moduleDirname)
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
    {
61
        if (!extension_loaded('gd')) {
62
            return false;
63
        } else {
64
            $requiredFunctions = array('imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate');
65
            foreach ($requiredFunctions as $func) {
66
                if (!function_exists($func)) {
67
                    return false;
68
                }
69
            }
70
        }
71
        if (!file_exists($imageBase = TDMC_IMAGES_LOGOS_PATH.'/empty.png') ||
72
            !file_exists($font = TDMC_FONTS_PATH.'/VeraBd.ttf') ||
73
            !file_exists($iconFile = XOOPS_ICONS32_PATH.'/'.basename($logoIcon))
74
        ) {
75
            return false;
76
        }
77
        $imageModule = imagecreatefrompng($imageBase);
78
        $imageIcon = imagecreatefrompng($iconFile);
79
        // Write text
80
        $textColor = imagecolorallocate($imageModule, 0, 0, 0);
81
        $spaceBorder = (92 - strlen($moduleDirname) * 7.5) / 2;
82
        imagefttext($imageModule, 8.5, 0, $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), array());
83
        imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
84
        $logoImg = '/'.$moduleDirname.'_logo.png';
85
        imagepng($imageModule, TDMC_UPLOAD_IMGMOD_PATH.$logoImg);
86
        imagedestroy($imageModule);
87
        imagedestroy($imageIcon);
88
89
        return TDMC_UPLOAD_IMGMOD_URL.$logoImg;
90
	}*/
91
		/**
92
     * @param $logoIcon
93
     * @param $moduleDirname
94
     *
95
     * @return bool|string
96
     */
97
    public static function createLogo($logoIcon, $moduleDirname)
98
    {
99
        if (!extension_loaded('gd')) {
100
            return false;
101
        } else {
102
            $requiredFunctions = array('imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate');
103
            foreach ($requiredFunctions as $func) {
104
                if (!function_exists($func)) {
105
                    return false;
106
                }
107
            }
108
        }
109
110
        $dirname = 'tdmcreate';
111
        $iconFileName = XOOPS_ROOT_PATH.'/Frameworks/moduleclasses/icons/32/'.basename($logoIcon);
112
113
        //$dirFonts = TDMC_PATH . "/assets/fonts";
114
        //$dirLogos = TDMC_PATH . "/assets/images/logos";
115
        $dirFonts = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/assets/fonts';
116
        $dirLogos = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/assets/images/logos';
117
118
        if (!file_exists($imageBase = $dirLogos.'/empty.png') ||
119
            !file_exists($font = $dirFonts.'/VeraBd.ttf') ||
120
            !file_exists($iconFile = $iconFileName)) {
121
            return false;
122
        }
123
124
        $imageModule = imagecreatefrompng($imageBase);
125
        $imageIcon = imagecreatefrompng($iconFile);
126
127
        // Write text
128
        $textColor = imagecolorallocate($imageModule, 0, 0, 0);
129
        $spaceToBorder = (92 - strlen($moduleDirname) * 7.5) / 2;
130
        imagefttext($imageModule, 8.5, 0, $spaceToBorder, 45, $textColor, $font, ucfirst($moduleDirname), array());
131
132
        imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
133
134
        //$targetImage = TDMC_UPLOAD_IMGMOD_URL . "/" . $moduleDirname . "_logo.png";
135
        $targetImage = '/uploads/'.$dirname.'/images/modules/'.$moduleDirname.'_logo.png';
136
137
        imagepng($imageModule, XOOPS_ROOT_PATH.$targetImage);
138
139
        imagedestroy($imageModule);
140
        imagedestroy($imageIcon);
141
142
        return XOOPS_URL.$targetImage;
143
    }       
144
}