1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Wggithub;
|
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
|
|
|
* wgGitHub module for xoops
|
17
|
|
|
*
|
18
|
|
|
* @copyright 2020 XOOPS Project (https://xooops.org)
|
19
|
|
|
* @license GPL 2.0 or later
|
20
|
|
|
* @package wggithub
|
21
|
|
|
* @since 1.0
|
22
|
|
|
* @min_xoops 2.5.10
|
23
|
|
|
* @author Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
|
24
|
|
|
*/
|
25
|
|
|
|
26
|
|
|
use XoopsModules\Wggithub;
|
27
|
|
|
use XoopsModules\Wggithub\MDParser;
|
28
|
|
|
|
29
|
|
|
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
|
30
|
|
|
|
31
|
|
|
/**
|
32
|
|
|
* Class Object Readmes
|
33
|
|
|
*/
|
34
|
|
|
class Readmes extends \XoopsObject
|
|
|
|
|
35
|
|
|
{
|
36
|
|
|
/**
|
37
|
|
|
* Constructor
|
38
|
|
|
*
|
39
|
|
|
* @param null
|
40
|
|
|
*/
|
41
|
|
|
public function __construct()
|
42
|
|
|
{
|
43
|
|
|
$this->initVar('rm_id', \XOBJ_DTYPE_INT);
|
|
|
|
|
44
|
|
|
$this->initVar('rm_repoid', \XOBJ_DTYPE_INT);
|
45
|
|
|
$this->initVar('rm_name', \XOBJ_DTYPE_TXTBOX);
|
|
|
|
|
46
|
|
|
$this->initVar('rm_type', \XOBJ_DTYPE_TXTBOX);
|
47
|
|
|
$this->initVar('rm_content', \XOBJ_DTYPE_TXTAREA);
|
|
|
|
|
48
|
|
|
$this->initVar('rm_encoding', \XOBJ_DTYPE_TXTBOX);
|
49
|
|
|
$this->initVar('rm_downloadurl', \XOBJ_DTYPE_TXTBOX);
|
50
|
|
|
$this->initVar('rm_baseurl', \XOBJ_DTYPE_TXTBOX);
|
51
|
|
|
$this->initVar('rm_datecreated', \XOBJ_DTYPE_INT);
|
52
|
|
|
$this->initVar('rm_submitter', \XOBJ_DTYPE_INT);
|
53
|
|
|
}
|
54
|
|
|
|
55
|
|
|
/**
|
56
|
|
|
* @static function &getInstance
|
57
|
|
|
*
|
58
|
|
|
* @param null
|
59
|
|
|
*/
|
60
|
|
|
public static function getInstance()
|
61
|
|
|
{
|
62
|
|
|
static $instance = false;
|
63
|
|
|
if (!$instance) {
|
64
|
|
|
$instance = new self();
|
65
|
|
|
}
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
/**
|
69
|
|
|
* The new inserted $Id
|
70
|
|
|
* @return inserted id
|
|
|
|
|
71
|
|
|
*/
|
72
|
|
|
public function getNewInsertedIdReadmes()
|
73
|
|
|
{
|
74
|
|
|
$newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
|
75
|
|
|
return $newInsertedId;
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* @public function getForm
|
80
|
|
|
* @param bool $action
|
81
|
|
|
* @param int $start
|
82
|
|
|
* @param int $limit
|
83
|
|
|
* @return \XoopsThemeForm
|
84
|
|
|
*/
|
85
|
|
|
public function getFormReadmes($action = false, $start = 0, $limit = 0)
|
86
|
|
|
{
|
87
|
|
|
$helper = \XoopsModules\Wggithub\Helper::getInstance();
|
88
|
|
|
if (!$action) {
|
89
|
|
|
$action = $_SERVER['REQUEST_URI'];
|
90
|
|
|
}
|
91
|
|
|
|
92
|
|
|
// Get Theme Form
|
93
|
|
|
\xoops_load('XoopsFormLoader');
|
|
|
|
|
94
|
|
|
$form = new \XoopsThemeForm(\_AM_WGGITHUB_README_EDIT, 'form', $action, 'post', true);
|
|
|
|
|
95
|
|
|
$form->setExtra('enctype="multipart/form-data"');
|
96
|
|
|
// Form Table repositories
|
97
|
|
|
$repositoriesHandler = $helper->getHandler('Repositories');
|
98
|
|
|
$rmRepoidSelect = new \XoopsFormSelect(\_AM_WGGITHUB_README_REPOID, 'rm_repoid', $this->getVar('rm_repoid'));
|
|
|
|
|
99
|
|
|
$rmRepoidSelect->addOptionArray($repositoriesHandler->getList());
|
100
|
|
|
$form->addElement($rmRepoidSelect);
|
101
|
|
|
// Form Text rmName
|
102
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGGITHUB_README_NAME, 'rm_name', 50, 255, $this->getVar('rm_name')));
|
|
|
|
|
103
|
|
|
// Form Text rmType
|
104
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGGITHUB_README_TYPE, 'rm_type', 50, 255, $this->getVar('rm_type')));
|
105
|
|
|
// Form Editor TextArea rmContent
|
106
|
|
|
$form->addElement(new \XoopsFormTextArea(\_AM_WGGITHUB_README_CONTENT, 'rm_content', $this->getVar('rm_content', 'e'), 4, 47));
|
|
|
|
|
107
|
|
|
// Form Text rmEncoding
|
108
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGGITHUB_README_ENCODING, 'rm_encoding', 50, 255, $this->getVar('rm_encoding')));
|
109
|
|
|
// Form Text rmDownloadurl
|
110
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGGITHUB_README_DOWNLOADURL, 'rm_downloadurl', 50, 255, $this->getVar('rm_downloadurl')));
|
111
|
|
|
// Form Text rmBaseurl
|
112
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGGITHUB_README_BASEURL, 'rm_baseurl', 50, 255, $this->getVar('rm_baseurl')));
|
113
|
|
|
// Form Text Date Select rmDatecreated
|
114
|
|
|
$rmDatecreated = $this->isNew() ?: $this->getVar('rm_datecreated');
|
115
|
|
|
$form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_README_DATECREATED, 'rm_datecreated', '', $rmDatecreated));
|
|
|
|
|
116
|
|
|
// Form Select User rmSubmitter
|
117
|
|
|
$form->addElement(new \XoopsFormSelectUser(\_AM_WGGITHUB_README_SUBMITTER, 'rm_submitter', false, $this->getVar('rm_submitter')));
|
|
|
|
|
118
|
|
|
// To Save
|
119
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save'));
|
|
|
|
|
120
|
|
|
$form->addElement(new \XoopsFormHidden('start', $start));
|
121
|
|
|
$form->addElement(new \XoopsFormHidden('limit', $limit));
|
122
|
|
|
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
|
|
|
|
|
123
|
|
|
return $form;
|
124
|
|
|
}
|
125
|
|
|
|
126
|
|
|
/**
|
127
|
|
|
* Get Values
|
128
|
|
|
* @param null $keys
|
|
|
|
|
129
|
|
|
* @param null $format
|
|
|
|
|
130
|
|
|
* @param null $maxDepth
|
|
|
|
|
131
|
|
|
* @return array
|
132
|
|
|
*/
|
133
|
|
|
public function getValuesReadmes($keys = null, $format = null, $maxDepth = null)
|
134
|
|
|
{
|
135
|
|
|
$helper = \XoopsModules\Wggithub\Helper::getInstance();
|
136
|
|
|
$utility = new \XoopsModules\Wggithub\Utility();
|
137
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth);
|
138
|
|
|
$ret['id'] = $this->getVar('rm_id');
|
139
|
|
|
$repositoriesHandler = $helper->getHandler('Repositories');
|
140
|
|
|
$repositoriesObj = $repositoriesHandler->get($this->getVar('rm_repoid'));
|
141
|
|
|
$repoName = '*****missing repo_name*****';
|
142
|
|
|
if (\is_object($repositoriesObj)) {
|
143
|
|
|
$repoName = $repositoriesObj->getVar('repo_name');
|
144
|
|
|
}
|
145
|
|
|
$ret['repoid'] = $repoName;
|
146
|
|
|
$rmName = $this->getVar('rm_name');
|
147
|
|
|
$ret['name'] = $rmName;
|
148
|
|
|
$ret['type'] = $this->getVar('rm_type');
|
149
|
|
|
$baseUrl = $this->getVar('rm_baseurl');
|
150
|
|
|
$ret['baseurl'] = $baseUrl;
|
151
|
|
|
$ret['content'] = $this->getVar('rm_content', 'e');
|
152
|
|
|
$contentDecoded = base64_decode($this->getVar('rm_content', 'n'));
|
153
|
|
|
if ('.MD' == \substr(strtoupper($rmName), -3)) {
|
154
|
|
|
$Parsedown = new MDParser\Parsedown();
|
155
|
|
|
$contentEncoded = $Parsedown->text($contentDecoded);
|
156
|
|
|
$baseUrl = \str_replace('/blob/', '/raw/', $baseUrl);
|
157
|
|
|
$contentClean = $this->cleaningMD($contentEncoded, $baseUrl);
|
158
|
|
|
} else {
|
159
|
|
|
$contentClean = $contentDecoded;
|
160
|
|
|
}
|
161
|
|
|
$ret['content_clean'] = $contentClean;
|
162
|
|
|
$editorMaxchar = $helper->getConfig('editor_maxchar');
|
163
|
|
|
$ret['content_short'] = $utility::truncateHtml($ret['content'], $editorMaxchar);
|
164
|
|
|
$ret['encoding'] = $this->getVar('rm_encoding');
|
165
|
|
|
$ret['downloadurl'] = $this->getVar('rm_downloadurl');
|
166
|
|
|
$ret['datecreated'] = \formatTimestamp($this->getVar('rm_datecreated'), 'm');
|
|
|
|
|
167
|
|
|
$ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('rm_submitter'));
|
|
|
|
|
168
|
|
|
$ret['gitbook_link'] = '';
|
169
|
|
|
if (\strpos($ret['downloadurl'], 'XoopsDoc') > 0) {
|
170
|
|
|
$ret['gitbook_link'] = 'https://xoops.gitbook.io/' . $repoName . '/';
|
171
|
|
|
}
|
172
|
|
|
return $ret;
|
173
|
|
|
}
|
174
|
|
|
|
175
|
|
|
/**
|
176
|
|
|
* Returns an array representation of the object
|
177
|
|
|
*
|
178
|
|
|
* @return array
|
179
|
|
|
*/
|
180
|
|
|
public function toArrayReadmes()
|
181
|
|
|
{
|
182
|
|
|
$ret = [];
|
183
|
|
|
$vars = $this->getVars();
|
184
|
|
|
foreach (\array_keys($vars) as $var) {
|
185
|
|
|
$ret[$var] = $this->getVar('"{$var}"');
|
186
|
|
|
}
|
187
|
|
|
return $ret;
|
188
|
|
|
}
|
189
|
|
|
/**
|
190
|
|
|
* Returns an array representation of the object
|
191
|
|
|
* @param $textMD
|
192
|
|
|
* @param $baseUrl
|
193
|
|
|
* @return string
|
194
|
|
|
*/
|
195
|
|
|
private function cleaningMD($textMD, $baseUrl)
|
196
|
|
|
{
|
197
|
|
|
$baseUrl = \str_replace('/blob/', '/raw/', $baseUrl);
|
198
|
|
|
|
199
|
|
|
$contentClean = \str_replace('http://', 'https://', $textMD);
|
200
|
|
|
|
201
|
|
|
//replace image links
|
202
|
|
|
$arrSearch = [
|
203
|
|
|
'src="https://xoops.org/images/logoXoopsPhp8_400.png',
|
204
|
|
|
"src='https://xoops.org/images/logoXoopsPhp8_400.png",
|
205
|
|
|
'src=".gitbook/assets/',
|
206
|
|
|
"src='.gitbook/assets/",
|
207
|
|
|
'src="en/assets/',
|
208
|
|
|
"src='en/assets/",
|
209
|
|
|
'src="assets/',
|
210
|
|
|
"src='assets/"
|
211
|
|
|
];
|
212
|
|
|
$arrReplace = [
|
213
|
|
|
'src="https://xoops.org/images/logoXoopsPhp8.png',
|
214
|
|
|
"src='https://xoops.org/images/logoXoopsPhp8.png",
|
215
|
|
|
'src="' . $baseUrl . '.gitbook/assets/',
|
216
|
|
|
"src='" . $baseUrl . '.gitbook/assets/',
|
217
|
|
|
'src="' . $baseUrl . 'en/assets/',
|
218
|
|
|
"src='" . $baseUrl . 'en/assets/',
|
219
|
|
|
'src="' . $baseUrl . 'assets/',
|
220
|
|
|
"src='" . $baseUrl . 'assets/'
|
221
|
|
|
];
|
222
|
|
|
$contentClean = \str_replace($arrSearch, $arrReplace, $contentClean);
|
223
|
|
|
|
224
|
|
|
//replace known missing images
|
225
|
|
|
$arrSearch = [
|
226
|
|
|
'src="' . \XOOPS_URL . '/screenshot.jpg',
|
|
|
|
|
227
|
|
|
'src="' . \XOOPS_URL . '/sd-099-theme-surprice.gif',
|
228
|
|
|
'src="' . \XOOPS_URL . '/shot.gif',
|
229
|
|
|
'src="' . \XOOPS_URL . '/shot.jpg',
|
230
|
|
|
'src="' . \XOOPS_URL . '/theme_preview.png',
|
231
|
|
|
'src="https://github.com/xoops/newbb-tutorial/tree/54ef6104e66b74e8c6dea683d3cce70ceafdd739/assets/image001.jpg',
|
232
|
|
|
'src="https://github.com/xoops/repairshop-tutorial/tree/719d6d32dea221b3e980fd3d6222f179ac898394/en/assets/img_2.jpg',
|
233
|
|
|
'src="https://github.com/xoops/xoops-mylinks-tutorial/tree/d30c30645d48c5ead51399ff711c25935cbd0495/en/assets/forkit.png',
|
234
|
|
|
'src="https://github.com/xoops/xoopspartners-tutorial/tree/f41bf73b884ccd906dc6a8323363b9b1aa3f8d02/en/assets/forkit.png',
|
235
|
|
|
'src="https://github.com/XoopsDocs/adslight-tutorial/raw/master/en/assets/image001.png',
|
236
|
|
|
'src="https://github.com/XoopsDocs/avaman-tutorial/raw/master/en/assets/image001.png',
|
237
|
|
|
'src="https://github.com/XoopsDocs/extgallery-tutorial/raw/master/en/assets/forkit.png',
|
238
|
|
|
'src="https://github.com/XoopsDocs/extgallery-tutorial/raw/master/en/assets/image001.png',
|
239
|
|
|
'src="https://github.com/XoopsDocs/presenter-tutorial/raw/master/en/assets/image001.png',
|
240
|
|
|
'src="https://github.com/XoopsDocs/smartpartner-tutorial/raw/master/en/assets/image001.png',
|
241
|
|
|
'src="https://github.com/XoopsDocs/tag-tutorial/raw/master/en/assets/image001.png',
|
242
|
|
|
'src="https://github.com/XoopsDocs/wfdownloads-tutorial/raw/master/en/assets/forkit.png',
|
243
|
|
|
'src="https://github.com/XoopsDocs/wfdownloads-tutorial/raw/master/en/assets/image001.png',
|
244
|
|
|
'src="https://github.com/XoopsDocs/xasset-tutorial/tree/9b95bc0ae0219c95a8cf16e77b9cd2175d856e89/en/assets/image001.png',
|
245
|
|
|
'src="https://github.com/XoopsDocs/xoops_codex/raw/master/en/assets/image001.png',
|
246
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/adslight.svg?style=flat',
|
247
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/avaman.svg?style=flat',
|
248
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/extcal.svg?style=flat',
|
249
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/extgallery.svg?style=flat',
|
250
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/gbook.svg?style=flat',
|
251
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/marquee.svg?style=flat',
|
252
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/mastopgo2.svg?style=flat',
|
253
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/moduleinstaller.svg?style=flat',
|
254
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/myconference.svg?style=flat',
|
255
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/newbb.svg?style=flat',
|
256
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/planet.svg?style=flat',
|
257
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/publisher.svg?style=flat',
|
258
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/randomquote.svg?style=flat',
|
259
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/references/.svg?style=flat',
|
260
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/smartfaq.svg?style=flat',
|
261
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/smartpartner.svg?style=flat',
|
262
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/suico.svg?style=flat',
|
263
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/tdmpicture.svg?style=flat',
|
264
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/waiting.svg?style=flat',
|
265
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/wflinks.svg?style=flat',
|
266
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/xfaq.svg?style=flat',
|
267
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/xoopsheadline.svg?style=flat',
|
268
|
|
|
'src="https://img.shields.io/codeclimate/github/mambax7/xoopspoll.svg?style=flat',
|
269
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/about.svg?style=flat',
|
270
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/adminer.svg?style=flat',
|
271
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/contact.svg?style=flat',
|
272
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/content.svg?style=flat',
|
273
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/cssholmes.svg?style=flat',
|
274
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/lexikon.svg?style=flat',
|
275
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/myiframe.svg?style=flat',
|
276
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/mylinks.svg?style=flat',
|
277
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/mymenus.svg?style=flat',
|
278
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/news.svg?style=flat',
|
279
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/smallworld.svg?style=flat',
|
280
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/soapbox.svg?style=flat',
|
281
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/tag.svg?style=flat',
|
282
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/tdmdownloads.svg?style=flat',
|
283
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/userlog.svg?style=flat',
|
284
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xbssacc.svg?style=flat',
|
285
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xbstags.svg?style=flat',
|
286
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xbsvat.svg?style=flat',
|
287
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xfguestbook.svg?style=flat',
|
288
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xlanguage.svg?style=flat',
|
289
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xmfdemo.svg?style=flat',
|
290
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xoopsfaq.svg?style=flat',
|
291
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xoopshp.svg?style=flat',
|
292
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xoopsinfo.svg?style=flat',
|
293
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xoopspartners.svg?style=flat',
|
294
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xoopstube.svg?style=flat',
|
295
|
|
|
'src="https://img.shields.io/codeclimate/github/XoopsModules25x/xsitemap.svg?style=flat',
|
296
|
|
|
'src="https://img.shields.io/github/release/mambax7/references/.svg?style=flat',
|
297
|
|
|
'src="https://img.shields.io/github/tag/mambax7/references/.svg?style=flat',
|
298
|
|
|
'src="https://insight.sensiolabs.com/projects/7ada0220-a68e-4369-aef0-950172630ff8/mini.png',
|
299
|
|
|
'src="https://xoops.org/images/translations-github-blue.svg',
|
300
|
|
|
];
|
301
|
|
|
$contentClean = \str_replace($arrSearch, 'src="' . \WGGITHUB_IMAGE_URL . '/blank.gif', $contentClean);
|
302
|
|
|
|
303
|
|
|
return $contentClean;
|
304
|
|
|
}
|
305
|
|
|
}
|
306
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths