1
|
|
|
<?php
|
2
|
|
|
/*
|
3
|
|
|
You may not change or alter any portion of this comment or credits
|
4
|
|
|
of supporting developers from this source code or any supporting source code
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors.
|
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful,
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
/**
|
13
|
|
|
* wgGitHub module for xoops
|
14
|
|
|
*
|
15
|
|
|
* @copyright 2020 XOOPS Project (https://xooops.org)
|
16
|
|
|
* @license GPL 2.0 or later
|
17
|
|
|
* @package wggithub
|
18
|
|
|
* @since 1.0
|
19
|
|
|
* @min_xoops 2.5.10
|
20
|
|
|
* @author Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
|
21
|
|
|
*/
|
22
|
|
|
|
23
|
|
|
/**
|
24
|
|
|
* function add selected cats to block
|
25
|
|
|
*
|
26
|
|
|
* @param $cats
|
27
|
|
|
* @return string
|
28
|
|
|
*/
|
29
|
|
|
function wggithub_block_addCatSelect($cats)
|
30
|
|
|
{
|
31
|
|
|
$cat_sql = '(';
|
32
|
|
|
if (\is_array($cats)) {
|
33
|
|
|
$cat_sql .= current($cats);
|
34
|
|
|
\array_shift($cats);
|
35
|
|
|
foreach ($cats as $cat) {
|
36
|
|
|
$cat_sql .= ',' . $cat;
|
37
|
|
|
}
|
38
|
|
|
}
|
39
|
|
|
$cat_sql .= ')';
|
40
|
|
|
return $cat_sql;
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* Get the permissions ids
|
45
|
|
|
*
|
46
|
|
|
* @param $permtype
|
47
|
|
|
* @param $dirname
|
48
|
|
|
* @return mixed $itemIds
|
49
|
|
|
*/
|
50
|
|
|
function wggithubGetMyItemIds($permtype, $dirname)
|
51
|
|
|
{
|
52
|
|
|
global $xoopsUser;
|
53
|
|
|
static $permissions = [];
|
54
|
|
|
if (\is_array($permissions) && \array_key_exists($permtype, $permissions)) {
|
55
|
|
|
return $permissions[$permtype];
|
56
|
|
|
}
|
57
|
|
|
$moduleHandler = \xoops_getHandler('module');
|
|
|
|
|
58
|
|
|
$wggithubModule = $moduleHandler->getByDirname($dirname);
|
59
|
|
|
$groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : \XOOPS_GROUP_ANONYMOUS;
|
|
|
|
|
60
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm');
|
61
|
|
|
$itemIds = $grouppermHandler->getItemIds($permtype, $groups, $wggithubModule->getVar('mid'));
|
62
|
|
|
return $itemIds;
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
/**
|
66
|
|
|
* Add content as meta tag to template
|
67
|
|
|
* @param $content
|
68
|
|
|
* @return void
|
69
|
|
|
*/
|
70
|
|
|
|
71
|
|
|
function wggithubMetaKeywords($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 wggithubMetaDescription($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 wggithub_RewriteUrl($module, $array, $type = 'content')
|
110
|
|
|
{
|
111
|
|
|
$comment = '';
|
112
|
|
|
$helper = \XoopsModules\Wggithub\Helper::getInstance();
|
113
|
|
|
//$readmesHandler = $helper->getHandler('readmes');
|
114
|
|
|
$lenght_id = $helper->getConfig('lenght_id');
|
115
|
|
|
$rewrite_url = $helper->getConfig('rewrite_url');
|
116
|
|
|
|
117
|
|
|
if (0 != $lenght_id) {
|
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 = wggithub_Filter(xoops_getModuleOption('static_name', $module));
|
|
|
|
|
130
|
|
|
}
|
131
|
|
|
|
132
|
|
|
switch ($rewrite_url) {
|
133
|
|
|
|
134
|
|
|
case 'none':
|
135
|
|
|
if($topic_name) {
|
136
|
|
|
$topic_name = 'topic=' . $topic_name . '&';
|
137
|
|
|
}
|
138
|
|
|
$rewrite_base = '/modules/';
|
139
|
|
|
$page = 'page=' . $array['content_alias'];
|
140
|
|
|
return \XOOPS_URL . $rewrite_base . $module . '/' . $type . '.php?' . $topic_name . 'id=' . $id . '&' . $page . $comment;
|
|
|
|
|
141
|
|
|
break;
|
|
|
|
|
142
|
|
|
|
143
|
|
|
case 'rewrite':
|
144
|
|
|
if($topic_name) {
|
145
|
|
|
$topic_name .= '/';
|
146
|
|
|
}
|
147
|
|
|
$rewrite_base = xoops_getModuleOption('rewrite_mode', $module);
|
148
|
|
|
$rewrite_ext = xoops_getModuleOption('rewrite_ext', $module);
|
149
|
|
|
$module_name = '';
|
150
|
|
|
if(xoops_getModuleOption('rewrite_name', $module)) {
|
151
|
|
|
$module_name = xoops_getModuleOption('rewrite_name', $module) . '/';
|
152
|
|
|
}
|
153
|
|
|
$page = $array['content_alias'];
|
154
|
|
|
$type .= '/';
|
155
|
|
|
$id .= '/';
|
156
|
|
|
if ('content/' === $type) {
|
157
|
|
|
$type = '';
|
158
|
|
|
}
|
159
|
|
|
if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) {
|
160
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/';
|
161
|
|
|
}
|
162
|
|
|
|
163
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $id . $page . $rewrite_ext;
|
164
|
|
|
break;
|
165
|
|
|
|
166
|
|
|
case 'short':
|
167
|
|
|
if($topic_name) {
|
168
|
|
|
$topic_name .= '/';
|
169
|
|
|
}
|
170
|
|
|
$rewrite_base = xoops_getModuleOption('rewrite_mode', $module);
|
171
|
|
|
$rewrite_ext = xoops_getModuleOption('rewrite_ext', $module);
|
172
|
|
|
$module_name = '';
|
173
|
|
|
if(xoops_getModuleOption('rewrite_name', $module)) {
|
174
|
|
|
$module_name = xoops_getModuleOption('rewrite_name', $module) . '/';
|
175
|
|
|
}
|
176
|
|
|
$page = $array['content_alias'];
|
177
|
|
|
$type .= '/';
|
178
|
|
|
if ('content/' === $type) {
|
179
|
|
|
$type = '';
|
180
|
|
|
}
|
181
|
|
|
if ('comment-edit/' === $type || 'comment-reply/' === $type || 'comment-delete/' === $type) {
|
182
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $id . '/';
|
183
|
|
|
}
|
184
|
|
|
|
185
|
|
|
return \XOOPS_URL . $rewrite_base . $module_name . $type . $topic_name . $page . $rewrite_ext;
|
186
|
|
|
break;
|
187
|
|
|
}
|
188
|
|
|
return null;
|
189
|
|
|
}
|
190
|
|
|
/**
|
191
|
|
|
* Replace all escape, character, ... for display a correct url
|
192
|
|
|
*
|
193
|
|
|
* @param string $url string to transform
|
194
|
|
|
* @param string $type string replacement for any blank case
|
195
|
|
|
* @return string $url
|
196
|
|
|
*/
|
197
|
|
|
function wggithub_Filter($url, $type = '') {
|
198
|
|
|
|
199
|
|
|
// Get regular expression from module setting. default setting is : `[^a-z0-9]`i
|
200
|
|
|
$helper = \XoopsModules\Wggithub\Helper::getInstance();
|
201
|
|
|
$regular_expression = $helper->getConfig('regular_expression');
|
202
|
|
|
|
203
|
|
|
$url = \strip_tags($url);
|
204
|
|
|
$url .= \preg_replace("`\[.*\]`U", '', $url);
|
205
|
|
|
$url .= \preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '-', $url);
|
206
|
|
|
$url .= htmlentities($url, ENT_COMPAT, 'utf-8');
|
207
|
|
|
$url .= \preg_replace('`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', "\1", $url);
|
208
|
|
|
$url .= \preg_replace([$regular_expression, '`[-]+`'], '-', $url);
|
209
|
|
|
$url = ($url == '') ? $type : strtolower(\trim($url, '-'));
|
210
|
|
|
return $url;
|
211
|
|
|
} |