1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* JSON Export class for phpMyFAQ. |
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 2015 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 2015-12-29 |
18
|
|
|
*/ |
19
|
|
|
if (!defined('IS_VALID_PHPMYFAQ')) { |
20
|
|
|
exit(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* PMF_Export_Xml. |
25
|
|
|
* |
26
|
|
|
* @category phpMyFAQ |
27
|
|
|
* @author Thorsten Rinne <[email protected]> |
28
|
|
|
* @copyright 2015 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 2015-12-29 |
32
|
|
|
*/ |
33
|
|
|
class PMF_Export_Json extends PMF_Export |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Constructor. |
37
|
|
|
* |
38
|
|
|
* @param PMF_Faq $faq Faq object |
39
|
|
|
* @param PMF_Category $category Category object |
40
|
|
|
* @param PMF_Configuration $config Configuration |
41
|
|
|
* |
42
|
|
|
* return PMF_Export_Json |
43
|
|
|
*/ |
44
|
|
|
public function __construct(PMF_Faq $faq, PMF_Category $category, PMF_Configuration $config) |
45
|
|
|
{ |
46
|
|
|
$this->faq = $faq; |
47
|
|
|
$this->category = $category; |
48
|
|
|
$this->_config = $config; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Generates the export. |
53
|
|
|
* |
54
|
|
|
* @param int $categoryId Category Id |
55
|
|
|
* @param bool $downwards If true, downwards, otherwise upward ordering |
56
|
|
|
* @param string $language Language |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function generate($categoryId = 0, $downwards = true, $language = '') |
61
|
|
|
{ |
62
|
|
|
$generated = []; |
63
|
|
|
|
64
|
|
|
// Initialize categories |
65
|
|
|
$this->category->transform($categoryId); |
66
|
|
|
|
67
|
|
|
$faqdata = $this->faq->get(FAQ_QUERY_TYPE_EXPORT_XML, $categoryId, $downwards, $language); |
68
|
|
|
|
69
|
|
|
if (count($faqdata)) { |
70
|
|
|
foreach ($faqdata as $data) { |
71
|
|
|
|
72
|
|
|
$generated[] = [ |
73
|
|
|
'faq' => [ |
74
|
|
|
'id' => $data['id'], |
75
|
|
|
'language' => $data['lang'], |
76
|
|
|
'category' => $this->category->getPath($data['category_id'], ' >> '), |
77
|
|
|
'keywords' => $data['keywords'], |
78
|
|
|
'question' => strip_tags($data['topic']), |
79
|
|
|
'answer' => PMF_String::htmlspecialchars($data['content']), |
80
|
|
|
'author' => $data['author_name'], |
81
|
|
|
'last_modified' => PMF_Date::createIsoDate($data['lastmodified']) |
82
|
|
|
] |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
header('Content-type: application/json'); |
88
|
|
|
|
89
|
|
|
return json_encode($generated); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|