|
1
|
|
|
<?php declare(strict_types=1); |
|
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
|
|
|
* wgEvents module for xoops |
|
15
|
|
|
* |
|
16
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @license GPL 2.0 or later |
|
18
|
|
|
* @package wgevents |
|
19
|
|
|
* @since 1.0.0 |
|
20
|
|
|
* @min_xoops 2.5.11 Beta1 |
|
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 wgevents_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 wgeventsGetMyItemIds($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
|
|
|
$wgeventsModule = $moduleHandler->getByDirname($dirname); |
|
|
|
|
|
|
60
|
|
|
$groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : \XOOPS_GROUP_ANONYMOUS; |
|
61
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
|
62
|
|
|
return $grouppermHandler->getItemIds($permtype, $groups, $wgeventsModule->getVar('mid')); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Add content as meta tag to template |
|
67
|
|
|
* @param $content |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
|
|
71
|
|
|
function wgeventsMetaKeywords($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 wgeventsMetaDescription($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 wgevents_RewriteUrl($module, $array, $type = 'content') |
|
110
|
|
|
{ |
|
111
|
|
|
$comment = ''; |
|
112
|
|
|
$helper = \XoopsModules\Wgevents\Helper::getInstance(); |
|
113
|
|
|
$textblockHandler = $helper->getHandler('textblocks'); |
|
|
|
|
|
|
114
|
|
|
$length_id = (int)$helper->getConfig('length_id'); |
|
115
|
|
|
$rewrite_url = $helper->getConfig('rewrite_url'); |
|
116
|
|
|
|
|
117
|
|
|
$id = $array['content_id']; |
|
118
|
|
|
if (0 !== $length_id) { |
|
119
|
|
|
while (\strlen($id) < $length_id) { |
|
120
|
|
|
$id = '0' . $id; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
if (isset($array['topic_alias']) && $array['topic_alias']) { |
|
125
|
|
|
$topic_name = $array['topic_alias']; |
|
126
|
|
|
} else { |
|
127
|
|
|
$topic_name = wgevents_Filter(xoops_getModuleOption('static_name', $module)); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
switch ($rewrite_url) { |
|
131
|
|
|
|
|
132
|
|
|
case 'none': |
|
133
|
|
|
if($topic_name) { |
|
134
|
|
|
$topic_name = 'topic=' . $topic_name . '&'; |
|
135
|
|
|
} |
|
136
|
|
|
$rewrite_base = '/modules/'; |
|
137
|
|
|
$page = 'page=' . $array['content_alias']; |
|
138
|
|
|
return \XOOPS_URL . $rewrite_base . $module . '/' . $type . '.php?' . $topic_name . 'id=' . $id . '&' . $page . $comment; |
|
139
|
|
|
|
|
140
|
|
|
case 'rewrite': |
|
141
|
|
|
if($topic_name) { |
|
142
|
|
|
$topic_name .= '/'; |
|
143
|
|
|
} |
|
144
|
|
|
$rewrite_base = xoops_getModuleOption('rewrite_mode', $module); |
|
|
|
|
|
|
145
|
|
|
$rewrite_ext = xoops_getModuleOption('rewrite_ext', $module); |
|
|
|
|
|
|
146
|
|
|
$module_name = ''; |
|
147
|
|
|
if(xoops_getModuleOption('rewrite_name', $module)) { |
|
|
|
|
|
|
148
|
|
|
$module_name = xoops_getModuleOption('rewrite_name', $module) . '/'; |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
$page = $array['content_alias']; |
|
151
|
|
|
$type .= '/'; |
|
152
|
|
|
$id .= '/'; |
|
153
|
|
|
if ('content/' === $type) { |
|
154
|
|
|
$type = ''; |
|
155
|
|
|
} |
|
156
|
|
|
if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) { |
|
157
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $id . $page . $rewrite_ext; |
|
161
|
|
|
|
|
162
|
|
|
case 'short': |
|
163
|
|
|
if($topic_name) { |
|
164
|
|
|
$topic_name .= '/'; |
|
165
|
|
|
} |
|
166
|
|
|
$rewrite_base = xoops_getModuleOption('rewrite_mode', $module); |
|
|
|
|
|
|
167
|
|
|
$rewrite_ext = xoops_getModuleOption('rewrite_ext', $module); |
|
|
|
|
|
|
168
|
|
|
$module_name = ''; |
|
169
|
|
|
if(xoops_getModuleOption('rewrite_name', $module)) { |
|
|
|
|
|
|
170
|
|
|
$module_name = xoops_getModuleOption('rewrite_name', $module) . '/'; |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
$page = $array['content_alias']; |
|
173
|
|
|
$type .= '/'; |
|
174
|
|
|
if ('content/' === $type) { |
|
175
|
|
|
$type = ''; |
|
176
|
|
|
} |
|
177
|
|
|
if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) { |
|
178
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/'; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $page . $rewrite_ext; |
|
182
|
|
|
} |
|
183
|
|
|
return null; |
|
184
|
|
|
} |
|
185
|
|
|
/** |
|
186
|
|
|
* Replace all escape, character, ... for display a correct url |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $url string to transform |
|
189
|
|
|
* @param string $type string replacement for any blank case |
|
190
|
|
|
* @return string $url |
|
191
|
|
|
*/ |
|
192
|
|
|
function wgevents_Filter($url, $type = '') { |
|
193
|
|
|
|
|
194
|
|
|
// Get regular expression from module setting. default setting is : `[^a-z0-9]`i |
|
195
|
|
|
$helper = \XoopsModules\Wgevents\Helper::getInstance(); |
|
196
|
|
|
$textblockHandler = $helper->getHandler('textblocks'); |
|
|
|
|
|
|
197
|
|
|
$regular_expression = $helper->getConfig('regular_expression'); |
|
198
|
|
|
|
|
199
|
|
|
$url = \strip_tags($url); |
|
200
|
|
|
$url .= \preg_replace('`\[.*\]`U', '', $url); |
|
201
|
|
|
$url .= \preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '-', $url); |
|
202
|
|
|
$url .= \htmlentities($url, ENT_COMPAT, 'utf-8'); |
|
203
|
|
|
$url .= \preg_replace('`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', "\1", $url); |
|
204
|
|
|
$url .= \preg_replace([$regular_expression, '`[-]+`'], '-', $url); |
|
205
|
|
|
return ('' == $url) ? $type : \strtolower(\trim($url, '-')); |
|
206
|
|
|
} |