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
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
15
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
16
|
|
|
* @author XOOPS Development Team |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace XoopsModules\Xhelp\Faq; |
20
|
|
|
|
21
|
|
|
use XoopsModules\Publisher\Helper as AdapterHelper; |
|
|
|
|
22
|
|
|
use XoopsModules\Publisher\Constants; |
|
|
|
|
23
|
|
|
use XoopsModules\Xhelp; |
24
|
|
|
|
25
|
|
|
//Sanity Check: make sure that file is not being accessed directly |
26
|
|
|
if (!\defined('XHELP_CLASS_PATH')) { |
27
|
|
|
exit(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// ** Define any site specific variables here ** |
31
|
|
|
\define('XHELP_SSECTION_PATH', XOOPS_ROOT_PATH . '/modules/publisher'); |
32
|
|
|
\define('XHELP_SSECTION_URL', \XHELP_SITE_URL . '/modules/publisher'); |
33
|
|
|
// ** End site specific variables ** |
34
|
|
|
|
35
|
|
|
// What features should be enabled for new publisher items |
36
|
|
|
\define('XHELP_SSECTION_DOHTML', 0); |
37
|
|
|
\define('XHELP_SSECTION_DOSMILEY', 1); |
38
|
|
|
\define('XHELP_SSECTION_DOBBCODE', 1); |
39
|
|
|
\define('XHELP_SSECTION_DOIMAGE', 0); |
40
|
|
|
\define('XHELP_SSECTION_DOBR', 1); |
41
|
|
|
\define('XHELP_SSECTION_NOTIFYPUB', 1); |
42
|
|
|
\define('XHELP_SSECTION_FORCEAPPROVAL', 0); //Should articles be reviewed prior to submission (0 = Always No, 1 = Always Yes, 2 = Follow Module Config |
43
|
|
|
|
44
|
|
|
// @todo - can this declaration be moved into the initialization sequence so |
45
|
|
|
// that each class does not need to include its interface? |
46
|
|
|
//Include the base faqAdapter interface (required) |
47
|
|
|
// require_once XHELP_CLASS_PATH . '/faqAdapter.php'; |
48
|
|
|
|
49
|
|
|
//These functions are required to work with the publisher application directly |
50
|
|
|
//@require \XHELP_SSECTION_PATH . '/include/functions.php'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* class Publisher |
54
|
|
|
*/ |
55
|
|
|
class Publisher extends Xhelp\FaqAdapterAbstract |
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* Does application support categories? |
59
|
|
|
* Possible Values: |
60
|
|
|
* XHELP_FAQ_CATEGORY_SING - entries can be in 1 category |
61
|
|
|
* XHELP_FAQ_CATEGORY_MULTI - entries can be in more than 1 category |
62
|
|
|
* XHELP_FAQ_CATEGORY_NONE - No category support |
63
|
|
|
*/ |
64
|
|
|
public $categoryType = \XHELP_FAQ_CATEGORY_SING; |
65
|
|
|
/** |
66
|
|
|
* Adapter Details |
67
|
|
|
* Required Values: |
68
|
|
|
* name - name of adapter |
69
|
|
|
* author - who wrote the plugin |
70
|
|
|
* author_email - contact email |
71
|
|
|
* version - version of this plugin |
72
|
|
|
* tested_versions - supported application versions |
73
|
|
|
* url - support url for plugin |
74
|
|
|
* module_dir - module directory name (not needed if class overloads the isActive() function from Xhelp\FaqAdapterAbstract) |
75
|
|
|
*/ |
76
|
|
|
public $meta = [ |
77
|
|
|
'name' => 'Publisher', |
78
|
|
|
'author' => 'Brian Wahoff, Michael Beck', |
79
|
|
|
'author_email' => '[email protected]', |
80
|
|
|
'description' => 'Create Publisher pages from xHelp helpdesk tickets', |
81
|
|
|
'version' => '1.0', |
82
|
|
|
'tested_versions' => '1.05 Beta 1', |
83
|
|
|
'url' => 'https://xoops.org/', |
84
|
|
|
'module_dir' => 'publisher', |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Class Constructor (Required) |
89
|
|
|
*/ |
90
|
|
|
public function __construct() |
91
|
|
|
{ |
92
|
|
|
if (\class_exists(AdapterHelper::class)) { |
93
|
|
|
$this->helper = AdapterHelper::getInstance(); |
94
|
|
|
$this->dirname = $this->helper->dirname(); |
95
|
|
|
} |
96
|
|
|
// Every class should call parent::init() to ensure that all class level |
97
|
|
|
// variables are initialized properly. |
98
|
|
|
$this->init(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* getCategories: retrieve the categories for the module |
103
|
|
|
* @return array|bool Array of Xhelp\FaqCategory |
104
|
|
|
*/ |
105
|
|
|
public function &getCategories() |
106
|
|
|
{ |
107
|
|
|
$ret = false; |
108
|
|
|
// if (!\class_exists('XoopsModules\Publisher\Helper')) { |
109
|
|
|
// return false; |
110
|
|
|
// } |
111
|
|
|
if (null === $this->helper) { |
112
|
|
|
return $ret; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$ret = []; |
116
|
|
|
$helper = Xhelp\Helper::getInstance(); |
117
|
|
|
// Create an instance of the Xhelp\FaqCategoryHandler |
118
|
|
|
$faqCategoryHandler = $helper->getHandler('FaqCategory'); |
119
|
|
|
|
120
|
|
|
// Get all the categories for the application |
121
|
|
|
$publisherCategoryHandler = $this->helper->getHandler('Category'); |
122
|
|
|
$categories = $publisherCategoryHandler->getCategories(0, 0, -1); |
123
|
|
|
|
124
|
|
|
//Convert the module specific category to the |
125
|
|
|
//Xhelp\FaqCategory object for standarization |
126
|
|
|
foreach ($categories as $category) { |
127
|
|
|
$faqcat = $faqCategoryHandler->create(); |
128
|
|
|
$faqcat->setVar('id', $category->getVar('categoryid')); |
129
|
|
|
$faqcat->setVar('parent', $category->getVar('parentid')); |
130
|
|
|
$faqcat->setVar('name', $category->getVar('name')); |
131
|
|
|
$ret[] = $faqcat; |
132
|
|
|
} |
133
|
|
|
unset($categories); |
134
|
|
|
\ksort($ret); |
135
|
|
|
|
136
|
|
|
return $ret; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* storeFaq: store the FAQ in the application's specific database (required) |
141
|
|
|
* @param Xhelp\Faq|null $faq The faq to add |
142
|
|
|
* @return bool true (success) / false (failure) |
143
|
|
|
*/ |
144
|
|
|
public function storeFaq(Xhelp\Faq $faq = null): bool |
145
|
|
|
{ |
146
|
|
|
global $xoopsUser, $publisher_itemHandler; |
147
|
|
|
|
148
|
|
|
$uid = $xoopsUser->getVar('uid'); |
149
|
|
|
|
150
|
|
|
// if (!\class_exists('XoopsModules\Publisher\Helper')) { |
151
|
|
|
// return false; |
152
|
|
|
// } |
153
|
|
|
if (null === $this->helper) { |
154
|
|
|
return false; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->helper->loadLanguage('admin'); |
158
|
|
|
|
159
|
|
|
//fix for publisherItem::store assuming that publisher handlers are globalized //TODO MB adjust for Publisher |
160
|
|
|
$publisherItemHandler = $this->helper->getHandler('Item'); |
161
|
|
|
$publisherCategoryHandler = $this->helper->getHandler('Category'); |
|
|
|
|
162
|
|
|
|
163
|
|
|
// $ssConfig = XoopsModules\Publisher\Utility::getModuleConfig(); |
164
|
|
|
|
165
|
|
|
// Create page in publisher from Xhelp\Faq object |
166
|
|
|
/** @var \XoopsModules\Publisher\Item $itemObj */ |
167
|
|
|
$itemObj = $publisherItemHandler->create(); |
168
|
|
|
|
169
|
|
|
//$faq->getVar('categories') is an array. If your application |
170
|
|
|
//only supports single categories use the first element |
171
|
|
|
//in the array |
172
|
|
|
$categories = $faq->getVar('categories'); |
|
|
|
|
173
|
|
|
$categories = (int)$categories[0]; // Change array of categories to 1 category |
174
|
|
|
|
175
|
|
|
// Putting the values about the ITEM in the ITEM object |
176
|
|
|
$itemObj->setVar('categoryid', $categories); |
177
|
|
|
$itemObj->setVar('title', $faq->getVar('subject', 'e')); |
178
|
|
|
$itemObj->setVar('summary', '[b]' . \ucfirst(\_XHELP_TEXT_PROBLEM) . "[/b]\r\n" . $faq->getVar('problem', 'e')); |
179
|
|
|
$itemObj->setVar('body', '[b]' . \ucfirst(\_XHELP_TEXT_SOLUTION) . "[/b]\r\n" . $faq->getVar('solution', 'e')); |
180
|
|
|
|
181
|
|
|
$itemObj->setVar('dohtml', \XHELP_SSECTION_DOHTML); |
182
|
|
|
$itemObj->setVar('dosmiley', \XHELP_SSECTION_DOSMILEY); |
183
|
|
|
$itemObj->setVar('doxcode', \XHELP_SSECTION_DOBBCODE); |
184
|
|
|
$itemObj->setVar('doimage', \XHELP_SSECTION_DOIMAGE); |
185
|
|
|
$itemObj->setVar('dobr', \XHELP_SSECTION_DOBR); |
186
|
|
|
$itemObj->setVar('notifypub', \XHELP_SSECTION_NOTIFYPUB); |
187
|
|
|
$itemObj->setVar('uid', $uid); |
188
|
|
|
$itemObj->setVar('datesub', \time()); |
189
|
|
|
|
190
|
|
|
// Setting the status of the item |
191
|
|
|
if ($this->articleNeedsApproval()) { |
192
|
|
|
$itemObj->setVar('status', Constants::PUBLISHER_STATUS_SUBMITTED); |
193
|
|
|
} else { |
194
|
|
|
$itemObj->setVar('status', Constants::PUBLISHER_STATUS_PUBLISHED); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
// Storing the item object in the database |
198
|
|
|
$ret = $itemObj->store(); |
199
|
|
|
if ($ret && null !== $faq) { |
200
|
|
|
$faq->setVar('id', $itemObj->getVar('itemid')); |
201
|
|
|
$faq->setVar('url', $this->makeFaqUrl($faq)); |
202
|
|
|
|
203
|
|
|
if ($this->articleNeedsApproval()) { |
204
|
|
|
if (\XHELP_SSECTION_NOTIFYPUB) { |
205
|
|
|
require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
206
|
|
|
/** @var \XoopsNotificationHandler $notificationHandler */ |
207
|
|
|
$notificationHandler = \xoops_getHandler('notification'); |
208
|
|
|
$notificationHandler->subscribe('item', $itemObj->itemid(), 'approved', \XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
209
|
|
|
} |
210
|
|
|
// Send notifications |
211
|
|
|
$itemObj->sendNotifications([\_AM_PUBLISHER_NOITEMS_SUBMITTED]); |
|
|
|
|
212
|
|
|
} else { |
213
|
|
|
// Send notifications |
214
|
|
|
$itemObj->sendNotifications([\_AM_PUBLISHER_NOITEMS]); |
|
|
|
|
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
return $ret; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Create the url going to the faq article |
223
|
|
|
* |
224
|
|
|
* @param \XoopsModules\Xhelp\Xhelp\Faq $faq |
|
|
|
|
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function makeFaqUrl($faq): string |
228
|
|
|
{ |
229
|
|
|
return \XHELP_SSECTION_URL . '/item.php?itemid=' . $faq->getVar('id'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return bool |
234
|
|
|
*/ |
235
|
|
|
private function articleNeedsApproval(): bool |
236
|
|
|
{ |
237
|
|
|
// $publisherHelper = XoopsModules\Publisher\Helper::getInstance(); |
238
|
|
|
return (\XHELP_SSECTION_FORCEAPPROVAL == 2 && 0 === $this->helper->getConfig('perm_autoapprove')) |
239
|
|
|
|| \XHELP_SSECTION_FORCEAPPROVAL == 1; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
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