1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Helper class for phpMyFAQ FAQs. |
5
|
|
|
* |
6
|
|
|
* PHP Version 5.5 |
7
|
|
|
* |
8
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License, |
9
|
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can |
10
|
|
|
* obtain one at http://mozilla.org/MPL/2.0/. |
11
|
|
|
* |
12
|
|
|
* @category phpMyFAQ |
13
|
|
|
* @author Thorsten Rinne <[email protected]> |
14
|
|
|
* @copyright 2010-2016 phpMyFAQ Team |
15
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
16
|
|
|
* @link http://www.phpmyfaq.de |
17
|
|
|
* @since 2010-11-12 |
18
|
|
|
*/ |
19
|
|
|
if (!defined('IS_VALID_PHPMYFAQ')) { |
20
|
|
|
exit(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* PMF_Helper_Faq. |
25
|
|
|
* |
26
|
|
|
* @category phpMyFAQ |
27
|
|
|
* @author Thorsten Rinne <[email protected]> |
28
|
|
|
* @copyright 2010-2016 phpMyFAQ Team |
29
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
30
|
|
|
* @link http://www.phpmyfaq.de |
31
|
|
|
* @since 2010-11-12 |
32
|
|
|
*/ |
33
|
|
|
class PMF_Helper_Faq extends PMF_Helper |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* SSL enabled. |
37
|
|
|
* |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $ssl = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor. |
44
|
|
|
* |
45
|
|
|
* @param PMF_Configuration $config |
46
|
|
|
* |
47
|
|
|
* @return PMF_Helper_Faq |
48
|
|
|
*/ |
49
|
|
|
public function __construct(PMF_Configuration $config) |
50
|
|
|
{ |
51
|
|
|
$this->_config = $config; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sets SSL mode. |
56
|
|
|
* |
57
|
|
|
* @param bool $ssl |
58
|
|
|
*/ |
59
|
|
|
public function setSsl($ssl) |
60
|
|
|
{ |
61
|
|
|
$this->ssl = $ssl; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns current SSL mode. |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function getSsl() |
70
|
|
|
{ |
71
|
|
|
return $this->ssl; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Renders a Facebook Like button. |
76
|
|
|
* |
77
|
|
|
* @param string $url |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function renderFacebookLikeButton($url) |
82
|
|
|
{ |
83
|
|
|
if (empty($url) || $this->_config->get('socialnetworks.enableFacebookSupport') == false) { |
84
|
|
|
return ''; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if ($this->ssl) { |
88
|
|
|
$http = 'https://'; |
89
|
|
|
} else { |
90
|
|
|
$http = 'http://'; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return sprintf( |
94
|
|
|
'<iframe src="%sfacebook.com/plugins/like.php?href=%s&layout=standard&show_faces=true&width=250&action=like&font=arial&colorscheme=light&height=30" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:30px;" allowTransparency="true"></iframe>', |
95
|
|
|
$http, |
96
|
|
|
urlencode($url) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Renders a Share on Facebook link. |
102
|
|
|
* |
103
|
|
|
* @param string $url |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function renderFacebookShareLink($url) |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
if (empty($url) || $this->_config->get('socialnetworks.disableAll') === true) { |
110
|
|
|
return ''; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$icon = '<span class="fa-stack fa-lg"> |
114
|
|
|
<i class="fa fa-square-o fa-stack-2x"></i> |
115
|
|
|
<i class="fa fa-facebook fa-stack-1x"></i> |
116
|
|
|
</span>'; |
117
|
|
|
|
118
|
|
|
return sprintf( |
119
|
|
|
'<a href="%s" target="_blank">%s</a>', |
120
|
|
|
$url, |
121
|
|
|
$icon |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Renders a Share on Twitter link. |
127
|
|
|
* |
128
|
|
|
* @param string $url |
129
|
|
|
* |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
View Code Duplication |
public function renderTwitterShareLink($url) |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
if (empty($url) || $this->_config->get('socialnetworks.disableAll') === true) { |
135
|
|
|
return ''; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$icon = '<span class="fa-stack fa-lg"> |
139
|
|
|
<i class="fa fa-square-o fa-stack-2x"></i> |
140
|
|
|
<i class="fa fa-twitter fa-stack-1x"></i> |
141
|
|
|
</span>'; |
142
|
|
|
|
143
|
|
|
return sprintf( |
144
|
|
|
'<a href="%s" target="_blank">%s</a>', |
145
|
|
|
$url, |
146
|
|
|
$icon |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Renders a select box with all translations of a FAQ. |
152
|
|
|
* |
153
|
|
|
* @param PMF_Faq $faq |
154
|
|
|
* @param int $categoryId |
155
|
|
|
* |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
public function renderChangeLanguageSelector(PMF_Faq $faq, $categoryId) |
159
|
|
|
{ |
160
|
|
|
global $languageCodes; |
161
|
|
|
|
162
|
|
|
$html = ''; |
163
|
|
|
$faqUrl = sprintf( |
164
|
|
|
'?action=artikel&cat=%d&id=%d&artlang=%%s', |
165
|
|
|
$categoryId, |
166
|
|
|
$faq->faqRecord['id'] |
167
|
|
|
); |
168
|
|
|
|
169
|
|
|
$oLink = new PMF_Link(PMF_Link::getSystemRelativeUri().$faqUrl, $this->_config); |
170
|
|
|
$oLink->itemTitle = $faq->faqRecord['title']; |
171
|
|
|
$availableLanguages = $this->_config->getLanguage()->languageAvailable($faq->faqRecord['id']); |
172
|
|
|
|
173
|
|
|
if (count($availableLanguages) > 1) { |
174
|
|
|
$html = '<form method="post">'; |
175
|
|
|
$html .= '<select name="language" onchange="top.location.href = this.options[this.selectedIndex].value;">'; |
176
|
|
|
|
177
|
|
|
foreach ($availableLanguages as $language) { |
178
|
|
|
$html .= sprintf('<option value="%s"', sprintf($oLink->toString(), $language)); |
179
|
|
|
$html .= ($faq->faqRecord['lang'] === $language ? ' selected' : ''); |
180
|
|
|
$html .= sprintf('>%s</option>', $languageCodes[strtoupper($language)]); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$html .= '</select></form>'; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return $html; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Renders a preview of the answer. |
191
|
|
|
* |
192
|
|
|
* @param string $answer |
193
|
|
|
* @param integer $numWords |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
|
|
public function renderAnswerPreview($answer, $numWords) |
197
|
|
|
{ |
198
|
|
|
if ($this->_config->get('main.enableMarkdownEditor')) { |
199
|
|
|
$parseDown = new ParsedownExtra(); |
200
|
|
|
return PMF_Utils::chopString(strip_tags($parseDown->text($answer)), $numWords); |
201
|
|
|
} else { |
202
|
|
|
return PMF_Utils::chopString(strip_tags($answer), $numWords); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Creates an overview with all categories with their FAQs. |
208
|
|
|
* |
209
|
|
|
* @param PMF_Category $category |
210
|
|
|
* @param PMF_Faq $faq |
211
|
|
|
* @param string $language |
212
|
|
|
* |
213
|
|
|
* @return array |
214
|
|
|
*/ |
215
|
|
|
public function createOverview(PMF_Category $category, PMF_Faq $faq, $language = '') |
216
|
|
|
{ |
217
|
|
|
global $PMF_LANG; |
218
|
|
|
|
219
|
|
|
$output = ''; |
220
|
|
|
|
221
|
|
|
// Initialize categories |
222
|
|
|
$category->transform(0); |
223
|
|
|
|
224
|
|
|
// Get all FAQs |
225
|
|
|
$faqData = $faq->get(FAQ_QUERY_TYPE_EXPORT_XHTML, 0, true, $language); |
226
|
|
|
|
227
|
|
|
if (count($faqData)) { |
228
|
|
|
$lastCategory = 0; |
229
|
|
|
foreach ($faqData as $data) { |
230
|
|
|
if ($data['category_id'] !== $lastCategory) { |
231
|
|
|
$output .= sprintf('<h3>%s</h3>', $category->getPath($data['category_id'], ' » ')); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
$output .= sprintf('<h4>%s</h4>', strip_tags($data['topic'])); |
235
|
|
|
$output .= sprintf('<article>%s</article>', $data['content']); |
236
|
|
|
$output .= sprintf('<p>%s: %s<br>%s', |
237
|
|
|
$PMF_LANG['msgAuthor'], |
238
|
|
|
$data['author_name'], |
239
|
|
|
$PMF_LANG['msgLastUpdateArticle'].PMF_Date::createIsoDate($data['lastmodified']) |
240
|
|
|
); |
241
|
|
|
$output .= '<hr>'; |
242
|
|
|
|
243
|
|
|
$lastCategory = $data['category_id']; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return $output; |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.