|
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 Brian Wahoff <[email protected]> |
|
17
|
|
|
* @author Eric Juden <[email protected]> |
|
18
|
|
|
* @author XOOPS Development Team |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace XoopsModules\Xhelp\Faq; |
|
22
|
|
|
|
|
23
|
|
|
use XoopsModules\Xhelp; |
|
24
|
|
|
use XoopsModules\Smartsection\Helper as AdapterHelper; |
|
|
|
|
|
|
25
|
|
|
use XoopsModules\Smartsection\Constants as AdapterConstants; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
//Sanity Check: make sure that file is not being accessed directly |
|
28
|
|
|
if (!\defined('XHELP_CLASS_PATH')) { |
|
29
|
|
|
exit(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// ** Define any site specific variables here ** |
|
33
|
|
|
//\define('XHELP_SSECTION_PATH', XOOPS_ROOT_PATH . '/modules/smartsection'); |
|
34
|
|
|
//\define('XHELP_SSECTION_URL', \XHELP_SITE_URL . '/modules/smartsection'); |
|
35
|
|
|
// ** End site specific variables ** |
|
36
|
|
|
|
|
37
|
|
|
// What features should be enabled for new smartsection items |
|
38
|
|
|
//\define('XHELP_SSECTION_DOHTML', 0); |
|
39
|
|
|
//\define('XHELP_SSECTION_DOSMILEY', 1); |
|
40
|
|
|
//\define('XHELP_SSECTION_DOBBCODE', 1); |
|
41
|
|
|
//\define('XHELP_SSECTION_DOIMAGE', 0); |
|
42
|
|
|
//\define('XHELP_SSECTION_DOBR', 1); |
|
43
|
|
|
//\define('XHELP_SSECTION_NOTIFYPUB', 1); |
|
44
|
|
|
//\define('XHELP_SSECTION_FORCEAPPROVAL', 0); //Should articles be reviewed prior to submission (0 = Always No, 1 = Always Yes, 2 = Follow Module Config |
|
45
|
|
|
|
|
46
|
|
|
// @todo - can this declaration be moved into the initialization sequence so |
|
47
|
|
|
// that each class does not need to include its interface? |
|
48
|
|
|
//Include the base faqAdapter interface (required) |
|
49
|
|
|
// require_once XHELP_CLASS_PATH . '/faqAdapter.php'; |
|
50
|
|
|
|
|
51
|
|
|
//These functions are required to work with the smartsection application directly |
|
52
|
|
|
//@require \XHELP_SSECTION_PATH . '/include/functions.php'; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* class Smartsection |
|
56
|
|
|
*/ |
|
57
|
|
|
class Smartsection extends Xhelp\FaqAdapterAbstract |
|
58
|
|
|
{ |
|
59
|
|
|
/** |
|
60
|
|
|
* Does application support categories? |
|
61
|
|
|
* Possible Values: |
|
62
|
|
|
* XHELP_FAQ_CATEGORY_SING - entries can be in 1 category |
|
63
|
|
|
* XHELP_FAQ_CATEGORY_MULTI - entries can be in more than 1 category |
|
64
|
|
|
* XHELP_FAQ_CATEGORY_NONE - No category support |
|
65
|
|
|
*/ |
|
66
|
|
|
public $categoryType = \XHELP_FAQ_CATEGORY_SING; |
|
67
|
|
|
/** |
|
68
|
|
|
* Adapter Details |
|
69
|
|
|
* Required Values: |
|
70
|
|
|
* name - name of adapter |
|
71
|
|
|
* author - who wrote the plugin |
|
72
|
|
|
* author_email - contact email |
|
73
|
|
|
* version - version of this plugin |
|
74
|
|
|
* tested_versions - supported application versions |
|
75
|
|
|
* url - support url for plugin |
|
76
|
|
|
* module_dir - module directory name (not needed if class overloads the isActive() function from Xhelp\FaqAdapterAbstract) |
|
77
|
|
|
*/ |
|
78
|
|
|
public $meta = [ |
|
79
|
|
|
'name' => 'SmartSection', |
|
80
|
|
|
'author' => 'Brian Wahoff', |
|
81
|
|
|
'author_email' => '[email protected]', |
|
82
|
|
|
'description' => 'Create SmartSection pages from xHelp helpdesk tickets', |
|
83
|
|
|
'version' => '1.0', |
|
84
|
|
|
'tested_versions' => '1.05 Beta 1', |
|
85
|
|
|
'url' => 'https://www.smartfactory.ca/', |
|
86
|
|
|
'module_dir' => 'smartsection', |
|
87
|
|
|
]; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Class Constructor (Required) |
|
91
|
|
|
*/ |
|
92
|
|
|
public function __construct() |
|
93
|
|
|
{ |
|
94
|
|
|
if (\class_exists(AdapterHelper::class)) { |
|
95
|
|
|
$this->helper = AdapterHelper::getInstance(); |
|
96
|
|
|
$this->dirname = $this->helper->dirname(); |
|
97
|
|
|
} |
|
98
|
|
|
// Every class should call parent::init() to ensure that all class level |
|
99
|
|
|
// variables are initialized properly. |
|
100
|
|
|
$this->init(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* getCategories: retrieve the categories for the module |
|
105
|
|
|
* @return array|bool Array of Xhelp\FaqCategory |
|
106
|
|
|
*/ |
|
107
|
|
|
public function &getCategories() |
|
108
|
|
|
{ |
|
109
|
|
|
$ret = false; |
|
110
|
|
|
// if (!\class_exists('XoopsModules\Smartsection\Helper')) { |
|
111
|
|
|
// return false; |
|
112
|
|
|
// } |
|
113
|
|
|
if (null === $this->helper) { |
|
114
|
|
|
return $ret; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$ret = []; |
|
118
|
|
|
$helper = Xhelp\Helper::getInstance(); |
|
119
|
|
|
// Create an instance of the Xhelp\FaqCategoryHandler |
|
120
|
|
|
$faqCategoryHandler = $helper->getHandler('FaqCategory'); |
|
121
|
|
|
|
|
122
|
|
|
// Get all the categories for the application |
|
123
|
|
|
$smartsectionCategoryHandler = $this->helper->getHandler('Category'); |
|
124
|
|
|
$categories = $smartsectionCategoryHandler->getCategories(0, 0, -1); |
|
125
|
|
|
|
|
126
|
|
|
//Convert the module specific category to the |
|
127
|
|
|
//Xhelp\FaqCategory object for standarization |
|
128
|
|
|
foreach ($categories as $category) { |
|
129
|
|
|
$faqcat = $faqCategoryHandler->create(); |
|
130
|
|
|
$faqcat->setVar('id', $category->getVar('categoryid')); |
|
131
|
|
|
$faqcat->setVar('parent', $category->getVar('parentid')); |
|
132
|
|
|
$faqcat->setVar('name', $category->getVar('name')); |
|
133
|
|
|
$ret[] = $faqcat; |
|
134
|
|
|
} |
|
135
|
|
|
unset($categories); |
|
136
|
|
|
\ksort($ret); |
|
137
|
|
|
|
|
138
|
|
|
return $ret; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* storeFaq: store the FAQ in the application's specific database (required) |
|
143
|
|
|
* @param Xhelp\Faq|null $faq The faq to add |
|
144
|
|
|
* @return bool true (success) / false (failure) |
|
145
|
|
|
*/ |
|
146
|
|
|
public function storeFaq(Xhelp\Faq $faq = null): bool |
|
147
|
|
|
{ |
|
148
|
|
|
global $xoopsUser, $smartsection_itemHandler; |
|
149
|
|
|
|
|
150
|
|
|
$uid = $xoopsUser->getVar('uid'); |
|
151
|
|
|
|
|
152
|
|
|
if (!\class_exists('XoopsModules\Smartsection\Helper')) { |
|
153
|
|
|
return false; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
//fix for smartsectionItem::store assuming that smartsection handlers are globalized |
|
157
|
|
|
$GLOBALS['smartsection_itemHandler'] = AdapterHelper::getInstance() |
|
158
|
|
|
->getHandler('Item'); |
|
159
|
|
|
$GLOBALS['smartsection_categoryHandler'] = AdapterHelper::getInstance() |
|
160
|
|
|
->getHandler('Category'); |
|
161
|
|
|
|
|
162
|
|
|
// $ssConfig = XoopsModules\Smartsection\Utility::getModuleConfig(); |
|
163
|
|
|
|
|
164
|
|
|
// Create page in smartsection from Xhelp\Faq object |
|
165
|
|
|
$smartsectionItemHandler = AdapterHelper::getInstance() |
|
166
|
|
|
->getHandler('Item'); |
|
167
|
|
|
$itemObj = $smartsectionItemHandler->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', AdapterConstants::SMARTSECTION_STATUS_SUBMITTED); |
|
193
|
|
|
} else { |
|
194
|
|
|
$itemObj->setVar('status', AdapterConstants::SMARTSECTION_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([AdapterConstants::SMARTSECTION_NOT_ITEM_SUBMITTED]); |
|
212
|
|
|
} else { |
|
213
|
|
|
// Send notifications |
|
214
|
|
|
$itemObj->sendNotifications([AdapterConstants::SMARTSECTION_NOT_ITEM_PUBLISHED]); |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
return $ret; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Create the url going to the faq article |
|
223
|
|
|
* |
|
224
|
|
|
* @param \XoopsModules\Xhelp\Faq $faq object |
|
225
|
|
|
* @return string |
|
226
|
|
|
*/ |
|
227
|
|
|
public function makeFaqUrl(\XoopsModules\Xhelp\Faq $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
|
|
|
$smartsectionHelper = AdapterHelper::getInstance(); |
|
238
|
|
|
return (\XHELP_SSECTION_FORCEAPPROVAL == 2 && 0 === $smartsectionHelper->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