1<?php 2 3/** 4 * JSON, XML, HTML5 and PDF export - streamer page. 5 * 6 * This Source Code Form is subject to the terms of the Mozilla Public License, 7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can 8 * obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * @package phpMyFAQ 11 * @author Matteo Scaramuccia <matteo@scaramuccia.com> 12 * @author Thorsten Rinne <thorsten@phpmyfaq.de> 13 * @copyright 2005-2020 phpMyFAQ Team 14 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 15 * @link https://www.phpmyfaq.de 16 * @since 2005-11-02 17 */ 18 19use phpMyFAQ\Category; 20use phpMyFAQ\Export; 21use phpMyFAQ\Faq; 22use phpMyFAQ\Filter; 23use phpMyFAQ\HttpStreamer; 24use phpMyFAQ\Tags; 25 26if (!defined('IS_VALID_PHPMYFAQ')) { 27 http_response_code(400); 28 exit(); 29} 30 31if ($user->perm->checkRight($user->getUserId(), 'export')) { 32 $categoryId = Filter::filterInput(INPUT_POST, 'catid', FILTER_VALIDATE_INT); 33 $downwards = Filter::filterInput(INPUT_POST, 'downwards', FILTER_VALIDATE_BOOLEAN, false); 34 $inlineDisposition = Filter::filterInput(INPUT_POST, 'dispos', FILTER_SANITIZE_STRING); 35 $type = Filter::filterInput(INPUT_POST, 'export-type', FILTER_SANITIZE_STRING, 'none'); 36 37 $faq = new Faq($faqConfig); 38 $tags = new Tags($faqConfig); 39 $category = new Category($faqConfig, [], false); 40 $category->buildTree($categoryId); 41 42 try { 43 $export = Export::create($faq, $category, $faqConfig, $type); 44 } catch (Exception $e) { 45 // handle exception 46 } 47 $content = $export->generate($categoryId, $downwards, $faqConfig->getLanguage()->getLanguage()); 48 49 // Stream the file content 50 $httpStreamer = new HttpStreamer($type, $content); 51 if ('inline' === $inlineDisposition) { 52 $httpStreamer->send(HttpStreamer::EXPORT_DISPOSITION_INLINE); 53 } else { 54 $httpStreamer->send(HttpStreamer::EXPORT_DISPOSITION_ATTACHMENT); 55 } 56} else { 57 echo $PMF_LANG['err_noArticles']; 58} 59