PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyfaq/pdf.php

https://github.com/cyrke/phpMyFAQ
PHP | 153 lines | 99 code | 23 blank | 31 comment | 26 complexity | 87eb6140b45834ca0416e7e2604ea33f MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * PDF export
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Frontend
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @author Peter Beauvain <pbeauvain@web.de>
  15. * @author Olivier Plathey <olivier@fpdf.org>
  16. * @author Krzysztof Kruszynski <thywolf@wolf.homelinux.net>
  17. * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
  18. * @copyright 2003-2012 phpMyFAQ Team
  19. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  20. * @link http://www.phpmyfaq.de
  21. * @since 2003-02-12
  22. */
  23. define('IS_VALID_PHPMYFAQ', null);
  24. require_once 'inc/Bootstrap.php';
  25. PMF_Init::cleanRequest();
  26. session_name(PMF_Session::PMF_COOKIE_NAME_AUTH);
  27. session_start();
  28. // get language (default: english)
  29. $Language = new PMF_Language($faqConfig);
  30. $LANGCODE = $Language->setLanguage($faqConfig->get('main.languageDetection'), $faqConfig->get('main.language'));
  31. $faqConfig->setLanguage($Language);
  32. // Found an article language?
  33. $lang = PMF_Filter::filterInput(INPUT_POST, 'artlang', FILTER_SANITIZE_STRING);
  34. if (is_null($lang) && !PMF_Language::isASupportedLanguage($lang) ) {
  35. $lang = PMF_Filter::filterInput(INPUT_GET, 'artlang', FILTER_SANITIZE_STRING);
  36. if (is_null($lang) && !PMF_Language::isASupportedLanguage($lang) ) {
  37. $lang = $LANGCODE;
  38. }
  39. }
  40. if (isset($lang) && PMF_Language::isASupportedLanguage($lang)) {
  41. require_once "lang/language_".$lang.".php";
  42. } else {
  43. $lang = "en";
  44. require_once "lang/language_en.php";
  45. }
  46. //
  47. // Initalizing static string wrapper
  48. //
  49. PMF_String::init($LANGCODE);
  50. // authenticate with session information
  51. $user = PMF_User_CurrentUser::getFromSession($faqConfig);
  52. if ($user) {
  53. $auth = true;
  54. } else {
  55. $user = null;
  56. }
  57. // Get current user rights
  58. $permission = array();
  59. if (isset($auth)) {
  60. // read all rights, set them FALSE
  61. $allRights = $user->perm->getAllRightsData();
  62. foreach ($allRights as $right) {
  63. $permission[$right['name']] = false;
  64. }
  65. // check user rights, set them TRUE
  66. $allUserRights = $user->perm->getAllUserRights($user->getUserId());
  67. foreach ($allRights as $right) {
  68. if (in_array($right['right_id'], $allUserRights))
  69. $permission[$right['name']] = true;
  70. }
  71. }
  72. // Get current user and group id - default: -1
  73. if (!is_null($user) && $user instanceof PMF_User_CurrentUser) {
  74. $current_user = $user->getUserId();
  75. if ($user->perm instanceof PMF_Perm_Medium) {
  76. $current_groups = $user->perm->getUserGroups($current_user);
  77. } else {
  78. $current_groups = array(-1);
  79. }
  80. if (0 == count($current_groups)) {
  81. $current_groups = array(-1);
  82. }
  83. } else {
  84. $current_user = -1;
  85. $current_groups = array(-1);
  86. }
  87. $currentCategory = PMF_Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT);
  88. $id = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  89. $getAll = PMF_Filter::filterInput(INPUT_GET, 'getAll', FILTER_VALIDATE_BOOLEAN, false);
  90. $faq = new PMF_Faq($faqConfig);
  91. $faq->setUser($current_user);
  92. $faq->setGroups($current_groups);
  93. $category = new PMF_Category($faqConfig);
  94. $category->setUser($current_user);
  95. $category->setGroups($current_groups);
  96. $pdf = new PMF_Export_Pdf($faq, $category, $faqConfig);
  97. $http = new PMF_Helper_Http();
  98. if (true === $getAll) {
  99. $category->buildTree();
  100. }
  101. $tags = new PMF_Tags($faqConfig);
  102. session_cache_limiter('private');
  103. $headers = array(
  104. "Pragma: public",
  105. "Expires: 0",
  106. "Cache-Control: must-revalidate, post-check=0, pre-check=0",
  107. );
  108. if (true === $getAll && $permission['export']) {
  109. $filename = 'FAQs.pdf';
  110. $pdfFile = $pdf->generate(0, true, $lang);
  111. } else {
  112. if (is_null($currentCategory) || is_null($id)) {
  113. $headers[] = 'HTTP/1.1 403 Forbidden';
  114. $payload = 'Wrong HTTP GET parameters values.';
  115. $http->sendWithHeaders($payload, $headers);
  116. exit();
  117. }
  118. $faq->getRecord($id);
  119. $faq->faqRecord['category_id'] = $currentCategory;
  120. $filename = 'FAQ-' . $id . '-' . $lang . '.pdf';
  121. $pdfFile = $pdf->generateFile($faq->faqRecord, $filename);
  122. }
  123. if (preg_match("/MSIE/i", $_SERVER["HTTP_USER_AGENT"])) {
  124. $headers[] = "Content-type: application/pdf";
  125. $headers[] = "Content-Transfer-Encoding: binary";
  126. $headers[] = "Content-Disposition: attachment; filename=" . $filename;
  127. } else {
  128. $headers[] = "Content-Type: application/pdf";
  129. }
  130. $http->sendWithHeaders($pdfFile, $headers);