|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xhelp; |
|
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
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
17
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
|
18
|
|
|
* @author XOOPS Development Team |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
if (!\defined('XHELP_CLASS_PATH')) { |
|
22
|
|
|
exit(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// require_once XHELP_CLASS_PATH . '/faq.php'; |
|
26
|
|
|
|
|
27
|
|
|
\define('XHELP_FAQ_CATEGORY_SING', 0); |
|
28
|
|
|
\define('XHELP_FAQ_CATEGORY_MULTI', 1); |
|
29
|
|
|
\define('XHELP_FAQ_CATEGORY_NONE', 2); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* class FaqAdapterAbstract |
|
33
|
|
|
*/ |
|
34
|
|
|
abstract class FaqAdapterAbstract implements FaqAdapterInterface |
|
35
|
|
|
{ |
|
36
|
|
|
public $categoryType = \XHELP_FAQ_CATEGORY_SING; |
|
37
|
|
|
/** |
|
38
|
|
|
* Adapter Details |
|
39
|
|
|
* Required Values: |
|
40
|
|
|
* name - name of adapter |
|
41
|
|
|
* author - who wrote the plugin |
|
42
|
|
|
* author_email - contact email |
|
43
|
|
|
* version - version of this plugin |
|
44
|
|
|
* tested_versions - supported application versions |
|
45
|
|
|
* url - support url for plugin |
|
46
|
|
|
* module_dir - module directory name (not needed if class overloads the isActive() function from FaqAdapterAbstract) |
|
47
|
|
|
*/ |
|
48
|
|
|
public $meta = [ |
|
49
|
|
|
'name' => '', |
|
50
|
|
|
'author' => '', |
|
51
|
|
|
'author_email' => '', |
|
52
|
|
|
'version' => '', |
|
53
|
|
|
'tested_versions' => '', |
|
54
|
|
|
'url' => '', |
|
55
|
|
|
'module_dir' => '', |
|
56
|
|
|
]; |
|
57
|
|
|
public $modname; |
|
58
|
|
|
public $module; |
|
59
|
|
|
public $helper; |
|
60
|
|
|
public $dirname = ''; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Perform any initilization needed |
|
64
|
|
|
*/ |
|
65
|
|
|
public function init() |
|
66
|
|
|
{ |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Stub function (does nothing) |
|
71
|
|
|
*/ |
|
72
|
|
|
public function &getCategories() |
|
73
|
|
|
{ |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return bool true (success)/false (failure) |
|
78
|
|
|
*/ |
|
79
|
|
|
public function storeFaq(): bool |
|
80
|
|
|
{ |
|
81
|
|
|
// Store a Faq |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return Faq object |
|
87
|
|
|
*/ |
|
88
|
|
|
public function createFaq(): Faq |
|
89
|
|
|
{ |
|
90
|
|
|
// Create an faq |
|
91
|
|
|
$faq = new Faq(); |
|
92
|
|
|
|
|
93
|
|
|
return $faq; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return bool true (success) / false (failure) |
|
98
|
|
|
*/ |
|
99
|
|
|
public function isActive(): bool |
|
100
|
|
|
{ |
|
101
|
|
|
$module_dir = $this->meta['module_dir']; |
|
102
|
|
|
$module_name = $this->meta['name']; |
|
103
|
|
|
|
|
104
|
|
|
if ('' === $module_dir || '' == $module_name) { // Sanity check |
|
105
|
|
|
return false; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
// Make sure that module is active |
|
109
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
|
110
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
|
111
|
|
|
$mod = $moduleHandler->getByDirname($module_dir); |
|
112
|
|
|
|
|
113
|
|
|
if (\is_object($mod)) { |
|
114
|
|
|
if ($mod->getVar('isactive')) { // Module active? |
|
115
|
|
|
$activeAdapter = Utility::getMeta('faq_adapter'); //TODO use this one or the one below? |
|
116
|
|
|
// $activeAdapter = $module_name; |
|
117
|
|
|
if ($activeAdapter) { |
|
118
|
|
|
return true; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return false; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return false; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return false; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Create the url going to the Faq article |
|
132
|
|
|
* |
|
133
|
|
|
* @param \XoopsModules\Xhelp\Faq $faq |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function makeFaqUrl(\XoopsModules\Xhelp\Faq $faq): string |
|
137
|
|
|
{ |
|
138
|
|
|
} |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: