IncludeCommon::getCommonDefines()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Tdmcreate\Files\Includes;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tdmcreate module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: IncludeCommon.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class IncludeCommon.
30
 */
31
class IncludeCommon extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /**
43
     *  @static function getInstance
44
     *  @param null
45
     * @return IncludeCommon
46
     */
47
    public static function getInstance()
48
    {
49
        static $instance = false;
50
        if (!$instance) {
51
            $instance = new self();
52
        }
53
54
        return $instance;
55
    }
56
57
    /**
58
     *  @public function write
59
     *  @param string $module
60
     *  @param object $table
61
     *  @param string $filename
62
     */
63
    public function write($module, $table, $filename)
64
    {
65
        $this->setModule($module);
66
        $this->setTable($table);
67
        $this->setFileName($filename);
68
    }
69
70
    /**
71
     * @param $modDirname
72
     * @param $const
73
     * @param $desc
74
     * @return string
75
     */
76
    private function getCommonDefines($modDirname, $const, $desc)
77
    {
78
        $stuModDirname = mb_strtoupper($modDirname);
79
80
        return "define('{$stuModDirname}_{$const}', {$desc});\n";
81
    }
82
83
    /**
84
     *  @private function getCommonCode
85
     *  @param \XoopsObject $module
86
     * @return string
87
     */
88
    private function getCommonCode($module)
89
    {
90
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
91
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
92
        $table = $this->getTable();
93
        $moduleDirname = $module->getVar('mod_dirname');
94
        $stuModuleDirname = mb_strtoupper($moduleDirname);
0 ignored issues
show
Bug introduced by
It seems like $moduleDirname can also be of type array and array; however, parameter $str of mb_strtoupper() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
        $stuModuleDirname = mb_strtoupper(/** @scrutinizer ignore-type */ $moduleDirname);
Loading history...
95
        $moduleAuthor = $module->getVar('mod_author');
96
        $moduleAuthorWebsiteName = $module->getVar('mod_author_website_name');
97
        $moduleAuthorWebsiteUrl = $module->getVar('mod_author_website_url');
98
        $moduleAuthorImage = str_replace(' ', '', mb_strtolower($moduleAuthor));
0 ignored issues
show
Bug introduced by
It seems like $moduleAuthor can also be of type array and array; however, parameter $str of mb_strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

98
        $moduleAuthorImage = str_replace(' ', '', mb_strtolower(/** @scrutinizer ignore-type */ $moduleAuthor));
Loading history...
99
        $ret = <<<'EOT'
100
if (!defined('XOOPS_ICONS32_PATH')) {
101
    define('XOOPS_ICONS32_PATH', XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32');
102
}
103
if (!defined('XOOPS_ICONS32_URL')) {
104
    define('XOOPS_ICONS32_URL', XOOPS_URL . '/Frameworks/moduleclasses/icons/32');
105
}
106
107
EOT;
108
        $ret .= $this->getCommonDefines($moduleDirname, 'DIRNAME', "'{$moduleDirname}'");
109
        $ret .= $this->getCommonDefines($moduleDirname, 'PATH', "XOOPS_ROOT_PATH.'/modules/'.{$stuModuleDirname}_DIRNAME");
110
        $ret .= $this->getCommonDefines($moduleDirname, 'URL', "XOOPS_URL.'/modules/'.{$stuModuleDirname}_DIRNAME");
111
        $ret .= $this->getCommonDefines($moduleDirname, 'ICONS_PATH', "{$stuModuleDirname}_PATH.'/assets/icons'");
112
        $ret .= $this->getCommonDefines($moduleDirname, 'ICONS_URL', "{$stuModuleDirname}_URL.'/assets/icons'");
113
        $ret .= $this->getCommonDefines($moduleDirname, 'IMAGE_PATH', "{$stuModuleDirname}_PATH.'/assets/images'");
114
        $ret .= $this->getCommonDefines($moduleDirname, 'IMAGE_URL', "{$stuModuleDirname}_URL.'/assets/images'");
115
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_PATH', "XOOPS_UPLOAD_PATH.'/'.{$stuModuleDirname}_DIRNAME");
116
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_URL', "XOOPS_UPLOAD_URL.'/'.{$stuModuleDirname}_DIRNAME");
117
118
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
119
        $fieldElement = [];
120
        foreach (array_keys($fields) as $f) {
121
            $fieldElement[] = $fields[$f]->getVar('field_element');
122
        }
123
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_FILES_PATH', "{$stuModuleDirname}_UPLOAD_PATH.'/files'");
124
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_FILES_URL', "{$stuModuleDirname}_UPLOAD_URL.'/files'");
125
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_IMAGE_PATH', "{$stuModuleDirname}_UPLOAD_PATH.'/images'");
126
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_IMAGE_URL', "{$stuModuleDirname}_UPLOAD_URL.'/images'");
127
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_SHOTS_PATH', "{$stuModuleDirname}_UPLOAD_PATH.'/images/shots'");
128
        $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_SHOTS_URL', "{$stuModuleDirname}_UPLOAD_URL.'/images/shots'");
129
        $ret .= $this->getCommonDefines($moduleDirname, 'ADMIN', "{$stuModuleDirname}_URL . '/admin/index.php'");
130
        $ret .= $xc->getXcEqualsOperator('$localLogo', "{$stuModuleDirname}_IMAGE_URL . '/{$moduleAuthorImage}_logo.png'");
131
        $ret .= $pc->getPhpCodeCommentLine('Module Information');
132
        $htmlCode = Tdmcreate\Files\CreateHtmlCode::getInstance();
133
        $img = $htmlCode->getHtmlImage('".$localLogo."', $moduleAuthorWebsiteName);
0 ignored issues
show
Bug introduced by
It seems like $moduleAuthorWebsiteName can also be of type array and array; however, parameter $alt of XoopsModules\Tdmcreate\F...tmlCode::getHtmlImage() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

133
        $img = $htmlCode->getHtmlImage('".$localLogo."', /** @scrutinizer ignore-type */ $moduleAuthorWebsiteName);
Loading history...
134
        $anchor = $htmlCode->getHtmlAnchor($moduleAuthorWebsiteUrl, $img, $moduleAuthorWebsiteName, '_blank');
0 ignored issues
show
Bug introduced by
It seems like $moduleAuthorWebsiteUrl can also be of type array and array; however, parameter $url of XoopsModules\Tdmcreate\F...mlCode::getHtmlAnchor() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
        $anchor = $htmlCode->getHtmlAnchor(/** @scrutinizer ignore-type */ $moduleAuthorWebsiteUrl, $img, $moduleAuthorWebsiteName, '_blank');
Loading history...
Bug introduced by
It seems like $moduleAuthorWebsiteName can also be of type array and array; however, parameter $title of XoopsModules\Tdmcreate\F...mlCode::getHtmlAnchor() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
        $anchor = $htmlCode->getHtmlAnchor($moduleAuthorWebsiteUrl, $img, /** @scrutinizer ignore-type */ $moduleAuthorWebsiteName, '_blank');
Loading history...
135
        $replace = $xc->getXcEqualsOperator('$copyright', '"' . $anchor . '"');
136
        $ret .= str_replace("\n", '', $replace) . PHP_EOL;
137
        $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsrequest', true);
138
        $ret .= $pc->getPhpCodeIncludeDir("{$stuModuleDirname}_PATH", 'class/helper', true);
139
        $ret .= $pc->getPhpCodeIncludeDir("{$stuModuleDirname}_PATH", 'include/functions', true);
140
141
        return $ret;
142
    }
143
144
    /**
145
     *  @public function render
146
     *  @param null
147
     * @return bool|string
148
     */
149
    public function render()
150
    {
151
        $module = $this->getModule();
152
        $moduleDirname = $module->getVar('mod_dirname');
153
        $filename = $this->getFileName();
154
        $content = $this->getHeaderFilesComments($module, $filename);
155
        $content .= $this->getCommonCode($module);
156
        $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
157
158
        return $this->renderFile();
159
    }
160
}
161