UserHeader::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Tdmcreate\Files\User;
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: user_header.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class UserHeader.
30
 */
31
class UserHeader 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 UserHeader
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 mixed $table
61
     *  @param array $tables
62
     *  @param string $filename
63
     */
64
    public function write($module, $table, $tables, $filename)
65
    {
66
        $this->setModule($module);
67
        $this->setTable($table);
68
        $this->setTables($tables);
69
        $this->setFileName($filename);
70
    }
71
72
    /**
73
     *  @private function getUserHeader
74
     *  @param $moduleDirname
75
     *
76
     *  @return string
77
     */
78
    private function getUserHeader($moduleDirname)
79
    {
80
        $stuModuleDirname = mb_strtoupper($moduleDirname);
81
        $ucfModuleDirname = ucfirst($moduleDirname);
0 ignored issues
show
Unused Code introduced by
The assignment to $ucfModuleDirname is dead and can be removed.
Loading history...
82
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
83
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
84
        $uc = UserXoopsCode::getInstance();
85
        $ret = $pc->getPhpCodeIncludeDir('dirname(dirname(__DIR__))', 'mainfile');
86
        $ret .= $pc->getPhpCodeIncludeDir('__DIR__', 'include/common');
87
        $ret .= $xc->getXcEqualsOperator('$dirname', 'basename(__DIR__)');
88
        $language = $this->getLanguage($moduleDirname, 'MA');
89
        $ret .= $uc->getUserBreadcrumbsHeaderFile($moduleDirname, $language);
90
91
        $table = $this->getTable();
92
        $tables = $this->getTables();
93
        if (is_object($table) && '' != $table->getVar('table_name')) {
94
            $ret .= $xc->getXoopsHandlerInstance($moduleDirname);
95
        }
96
        if (is_array($tables)) {
97
            foreach (array_keys($tables) as $i) {
98
                $tableName = $tables[$i]->getVar('table_name');
99
                $ret .= $xc->getXoopsHandlerLine($moduleDirname, $tableName);
100
            }
101
        }
102
        $ret .= $pc->getPhpCodeCommentLine('Permission');
103
        $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
104
        $ret .= $xc->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", null, true);
105
106
        $condIf = $xc->getXcEqualsOperator('$groups ', '$xoopsUser->getGroups()', null, false, "\t");
107
        $condElse = $xc->getXcEqualsOperator('$groups ', 'XOOPS_GROUP_ANONYMOUS', null, false, "\t");
108
109
        $ret .= $pc->getPhpCodeConditions('is_object($xoopsUser)', '', '', $condIf, $condElse);
110
        $ret .= $pc->getPhpCodeCommentLine();
111
        $ret .= $xc->getXcEqualsOperator('$myts', 'MyTextSanitizer::getInstance()', null, true);
112
        $ret .= $pc->getPhpCodeCommentLine('Default Css Style');
113
        $ret .= $xc->getXcEqualsOperator('$style', "{$stuModuleDirname}_URL . '/assets/css/style.css'");
114
        $ret .= $pc->getPhpCodeConditions('!file_exists($style)', '', '', "\treturn false;\n");
115
        $ret .= $pc->getPhpCodeCommentLine('Smarty Default');
116
        $ret .= $xc->getXcGetInfo('sysPathIcon16', 'sysicons16');
117
        $ret .= $xc->getXcGetInfo('sysPathIcon32', 'sysicons32');
118
        $ret .= $xc->getXcGetInfo('pathModuleAdmin', 'dirmoduleadmin');
119
        $ret .= $xc->getXcGetInfo('modPathIcon16', 'modicons16');
120
        $ret .= $xc->getXcGetInfo('modPathIcon32', 'modicons16');
121
        $ret .= $pc->getPhpCodeCommentLine('Load Languages');
122
        $ret .= $xc->getXcLoadLanguage('main');
123
        $ret .= $xc->getXcLoadLanguage('modinfo');
124
125
        return $ret;
126
    }
127
128
    /**
129
     *  @public function render
130
     *  @param null
131
     * @return bool|string
132
     */
133
    public function render()
134
    {
135
        $module = $this->getModule();
136
        $moduleDirname = $module->getVar('mod_dirname');
137
        $filename = $this->getFileName();
138
        $content = $this->getHeaderFilesComments($module, $filename);
139
        $content .= $this->getUserHeader($moduleDirname);
140
141
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
142
143
        return $this->renderFile();
144
    }
145
}
146