wgfilemanagerMetaDescription()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
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
 * wgFileManager module for xoops
17
 *
18
 * @copyright    2021 XOOPS Project (https://xoops.org)
19
 * @license      GPL 2.0 or later
20
 * @package      wgfilemanager
21
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
22
 */
23
24
/**
25
 * function add selected cats to block
26
 *
27
 * @param  $cats
28
 * @return string
29
 */
30
function wgfilemanager_block_addCatSelect($cats)
31
{
32
    $cat_sql = '(';
33
    if (\is_array($cats)) {
34
        $cat_sql .= current($cats);
35
        array_shift($cats);
36
        foreach ($cats as $cat) {
37
            $cat_sql .= ',' . $cat;
38
        }
39
    }
40
    $cat_sql .= ')';
41
    return $cat_sql;
42
}
43
44
/**
45
 * Get the permissions ids
46
 *
47
 * @param  $permtype
48
 * @param  $dirname
49
 * @return mixed $itemIds
50
 */
51
function wgfilemanagerGetMyItemIds($permtype, $dirname)
52
{
53
    global $xoopsUser;
54
    static $permissions = [];
55
    if (\is_array($permissions) && \array_key_exists($permtype, $permissions)) {
56
        return $permissions[$permtype];
57
    }
58
    $moduleHandler = \xoops_getHandler('module');
59
    $wgfilemanagerModule = $moduleHandler->getByDirname($dirname);
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

59
    /** @scrutinizer ignore-call */ 
60
    $wgfilemanagerModule = $moduleHandler->getByDirname($dirname);
Loading history...
60
    $groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : \XOOPS_GROUP_ANONYMOUS;
61
    $grouppermHandler = \xoops_getHandler('groupperm');
62
    return $grouppermHandler->getItemIds($permtype, $groups, $wgfilemanagerModule->getVar('mid'));
0 ignored issues
show
Bug introduced by
The method getItemIds() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

62
    return $grouppermHandler->/** @scrutinizer ignore-call */ getItemIds($permtype, $groups, $wgfilemanagerModule->getVar('mid'));
Loading history...
63
}
64
65
/**
66
 * Add content as meta tag to template
67
 * @param $content
68
 * @return void
69
 */
70
71
function wgfilemanagerMetaKeywords($content)
72
{
73
    global $xoopsTpl, $xoTheme;
74
    $myts = MyTextSanitizer::getInstance();
75
    $content= $myts->undoHtmlSpecialChars($myts->displayTarea($content));
76
    if(isset($xoTheme) && \is_object($xoTheme)) {
77
        $xoTheme->addMeta( 'meta', 'keywords', \strip_tags($content));
78
    } else {    // Compatibility for old Xoops versions
79
        $xoopsTpl->assign('xoops_meta_keywords', \strip_tags($content));
80
    }
81
}
82
83
/**
84
 * Add content as meta description to template
85
 * @param $content
86
 * @return void
87
 */
88
 
89
function wgfilemanagerMetaDescription($content)
90
{
91
    global $xoopsTpl, $xoTheme;
92
    $myts = MyTextSanitizer::getInstance();
93
    $content = $myts->undoHtmlSpecialChars($myts->displayTarea($content));
94
    if(isset($xoTheme) && \is_object($xoTheme)) {
95
        $xoTheme->addMeta( 'meta', 'description', \strip_tags($content));
96
    } else {    // Compatibility for old Xoops versions
97
        $xoopsTpl->assign('xoops_meta_description', \strip_tags($content));
98
    }
99
}
100
101
/**
102
 * Rewrite all url
103
 *
104
 * @param string  $module  module name
105
 * @param array   $array   array
106
 * @param string  $type    type
107
 * @return null|string $type    string replacement for any blank case
108
 */
109
function wgfilemanager_RewriteUrl($module, $array, $type = 'content')
110
{
111
    $comment = '';
112
    $helper = \XoopsModules\Wgfilemanager\Helper::getInstance();
113
    //$fileHandler = $helper->getHandler('file');
114
    $lenght_id = $helper->getConfig('lenght_id');
115
    $rewrite_url = $helper->getConfig('rewrite_url');
116
117
    if (0 != $lenght_id) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $lenght_id of type mixed|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
118
        $id = $array['content_id'];
119
        while (\strlen($id) < $lenght_id) {
120
            $id = '0' . $id;
121
        }
122
    } else {
123
        $id = $array['content_id'];
124
    }
125
126
    if (isset($array['topic_alias']) && $array['topic_alias']) {
127
        $topic_name = $array['topic_alias'];
128
    } else {
129
        $topic_name = wgfilemanager_Filter(xoops_getModuleOption('static_name', $module));
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

129
        $topic_name = wgfilemanager_Filter(/** @scrutinizer ignore-deprecated */ xoops_getModuleOption('static_name', $module));
Loading history...
130
    }
131
132
    switch ($rewrite_url) {
133
134
        case 'none':
135
            if($topic_name) {
136
                 $topic_name = 'topic=' . $topic_name . '&amp;';
137
            }
138
            $rewrite_base = '/modules/';
139
            $page = 'page=' . $array['content_alias'];
140
            return \XOOPS_URL . $rewrite_base . $module . '/' . $type . '.php?' . $topic_name . 'id=' . $id . '&amp;' . $page . $comment;
141
142
        case 'rewrite':
143
            if($topic_name) {
144
                $topic_name .= '/';
145
            }
146
            $rewrite_base = xoops_getModuleOption('rewrite_mode', $module);
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

146
            $rewrite_base = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_mode', $module);
Loading history...
147
            $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module);
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

147
            $rewrite_ext = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_ext', $module);
Loading history...
148
            $module_name = '';
149
            if(xoops_getModuleOption('rewrite_name', $module)) {
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

149
            if(/** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_name', $module)) {
Loading history...
150
                $module_name = xoops_getModuleOption('rewrite_name', $module) . '/';
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

150
                $module_name = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_name', $module) . '/';
Loading history...
151
            }
152
            $page = $array['content_alias'];
153
            $type .= '/';
154
            $id .= '/';
155
            if ('content/' === $type) {
156
                $type = '';
157
            }
158
            if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) {
159
                return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/';
160
            }
161
162
            return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name  . $id . $page . $rewrite_ext;
163
164
        case 'short':
165
            if($topic_name) {
166
                $topic_name .= '/';
167
            }
168
            $rewrite_base = xoops_getModuleOption('rewrite_mode', $module);
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

168
            $rewrite_base = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_mode', $module);
Loading history...
169
            $rewrite_ext = xoops_getModuleOption('rewrite_ext', $module);
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

169
            $rewrite_ext = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_ext', $module);
Loading history...
170
            $module_name = '';
171
            if(xoops_getModuleOption('rewrite_name', $module)) {
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

171
            if(/** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_name', $module)) {
Loading history...
172
                $module_name = xoops_getModuleOption('rewrite_name', $module) . '/';
0 ignored issues
show
Deprecated Code introduced by
The function xoops_getModuleOption() has been deprecated. ( Ignorable by Annotation )

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

172
                $module_name = /** @scrutinizer ignore-deprecated */ xoops_getModuleOption('rewrite_name', $module) . '/';
Loading history...
173
            }
174
            $page = $array['content_alias'];
175
            $type .= '/';
176
            if ('content/' === $type) {
177
                $type = '';
178
            }
179
            if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) {
180
                return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/';
181
            }
182
183
            return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $page . $rewrite_ext;
184
    }
185
    return null;
186
}
187
/**
188
 * Replace all escape, character, ... for display a correct url
189
 *
190
 * @param string $url      string to transform
191
 * @param string $type     string replacement for any blank case
192
 * @return string $url
193
 */
194
function wgfilemanager_Filter($url, $type = '') {
195
196
    // Get regular expression from module setting. default setting is : `[^a-z0-9]`i
197
    $helper = \XoopsModules\Wgfilemanager\Helper::getInstance();
198
    //$fileHandler = $helper->getHandler('file');
199
    $regular_expression = $helper->getConfig('regular_expression');
200
201
    $url = \strip_tags($url);
202
    $url .= \preg_replace('`\[.*\]`U', '', $url);
203
    $url .= \preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '-', $url);
204
    $url .= \htmlentities($url, ENT_COMPAT, 'utf-8');
205
    $url .= \preg_replace('`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', "\1", $url);
206
    $url .= \preg_replace([$regular_expression, '`[-]+`'], '-', $url);
207
    return ('' == $url) ? $type : \strtolower(\trim($url, '-'));
208
}