PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/phpmyfaq/admin/meta.php

http://github.com/thorsten/phpMyFAQ
PHP | 189 lines | 156 code | 18 blank | 15 comment | 9 complexity | 2c4dfcbba5c65dd771797b60bfa07965 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * The meta data administration frontend.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public License,
  6. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. * obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. * @category phpMyFAQ
  10. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  11. * @copyright 2018-2021 phpMyFAQ Team
  12. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  13. * @link https://www.phpmyfaq.de
  14. * @since 2018-08-10
  15. */
  16. use phpMyFAQ\Entity\MetaEntity;
  17. use phpMyFAQ\Filter;
  18. use phpMyFAQ\Meta;
  19. if (!defined('IS_VALID_PHPMYFAQ')) {
  20. http_response_code(400);
  21. exit();
  22. }
  23. $defaultMetaAction = 'list';
  24. $metaAction = Filter::filterInput(INPUT_GET, 'meta_action', FILTER_UNSAFE_RAW, $defaultMetaAction);
  25. $csrfToken = Filter::filterInput(INPUT_POST, 'csrf', FILTER_UNSAFE_RAW);
  26. $metaId = Filter::filterInput(INPUT_POST, 'meta_id', FILTER_VALIDATE_INT);
  27. ?>
  28. <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  29. <h1 class="h2">
  30. <i aria-hidden="true" class="fa fa-code"></i>
  31. <?= $PMF_LANG['ad_menu_meta'] ?>
  32. </h1>
  33. <div class="btn-toolbar mb-2 mb-md-0">
  34. <div class="btn-group mr-2">
  35. <button class="btn btn-sm btn-success" data-toggle="modal" data-target="#addMetaModal">
  36. <i aria-hidden="true" class="fa fa-plus"></i>
  37. <?= $PMF_LANG['ad_meta_add'] ?>
  38. </button>
  39. </div>
  40. </div>
  41. </div>
  42. <?php
  43. if (!$user->perm->hasPermission($user->getUserId(), 'editconfig')) {
  44. echo $PMF_LANG['err_NotAuth'];
  45. }
  46. $meta = new Meta($faqConfig);
  47. // Update meta data
  48. if ('meta.update' === $action && is_integer($metaId)) {
  49. if (!isset($_SESSION['phpmyfaq_csrf_token']) || $_SESSION['phpmyfaq_csrf_token'] !== $csrfToken) {
  50. echo $PMF_LANG['err_NotAuth'];
  51. } else {
  52. $entity = new MetaEntity();
  53. $entity
  54. ->setPageId(Filter::filterInput(INPUT_POST, 'page_id', FILTER_UNSAFE_RAW))
  55. ->setType(Filter::filterInput(INPUT_POST, 'type', FILTER_UNSAFE_RAW))
  56. ->setContent(Filter::filterInput(INPUT_POST, 'content', FILTER_SANITIZE_SPECIAL_CHARS));
  57. if ($meta->update($metaId, $entity)) {
  58. printf(
  59. '<p class="alert alert-success">%s%s</p>',
  60. '<a class="close" data-dismiss="alert" href="#">&times;</a>',
  61. $PMF_LANG['ad_config_saved']
  62. );
  63. } else {
  64. printf(
  65. '<p class="alert alert-danger">%s%s<br/>%s</p>',
  66. '<a class="close" data-dismiss="alert" href="#">&times;</a>',
  67. $PMF_LANG['ad_entryins_fail'],
  68. $faqConfig->getDb()->error()
  69. );
  70. }
  71. }
  72. }
  73. $metaData = $meta->getAll();
  74. ?>
  75. <table class="table table-striped">
  76. <thead class="thead-dark">
  77. <tr>
  78. <th>#</th>
  79. <th><?= $PMF_LANG['ad_meta_page_id'] ?></th>
  80. <th><?= $PMF_LANG['ad_meta_type'] ?></th>
  81. <th colspan="2"><?= $PMF_LANG['ad_meta_content'] ?></th>
  82. </tr>
  83. </thead>
  84. <tbody>
  85. <?php foreach ($metaData as $data) : ?>
  86. <tr id="row-meta-<?= $data->getId() ?>">
  87. <td><?= $data->getId() ?></td>
  88. <td><?= $data->getPageId() ?></td>
  89. <td><?= $data->getType() ?></td>
  90. <td><?= $data->getContent() ?></td>
  91. <td class="text-right">
  92. <a href="?action=meta.edit&id=<?= $data->getId() ?>" class="btn btn-success">
  93. <i aria-hidden="true" class="fa fa-pencil"></i>
  94. </a>
  95. <a href="#" id="delete-meta-<?= $data->getId() ?>" class="btn btn-danger pmf-meta-delete"
  96. data-csrf="<?= $user->getCsrfTokenFromSession() ?>">
  97. <i aria-hidden="true" class="fa fa-trash"></i>
  98. </a>
  99. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#codeModal"
  100. data-code-snippet="<?= $data->getPageId() ?>">
  101. <i aria-hidden="true" class="fa fa-code"></i>
  102. </button>
  103. </td>
  104. </tr>
  105. <?php endforeach; ?>
  106. </tbody>
  107. </table>
  108. <!-- Modal to add new meta data -->
  109. <div class="modal fade" id="addMetaModal" tabindex="-1" role="dialog" aria-labelledby="addMetaModalLabel"
  110. aria-hidden="true">
  111. <div class="modal-dialog" role="document">
  112. <div class="modal-content">
  113. <div class="modal-header">
  114. <h5 class="modal-title" id="addMetaModalLabel"><?= $PMF_LANG['ad_meta_add'] ?></h5>
  115. <button type="button" class="close" data-dismiss="modal" aria-label="<?= $PMF_LANG['ad_att_close'] ?>">
  116. <span aria-hidden="true">&times;</span>
  117. </button>
  118. </div>
  119. <div class="modal-body">
  120. <form action="#" method="post" accept-charset="utf-8">
  121. <input type="hidden" name="csrf" id="csrf" value="<?= $user->getCsrfTokenFromSession() ?>">
  122. <div class="form-group row">
  123. <label for="page_id" class="col-sm-2 col-form-label"><?= $PMF_LANG['ad_meta_page_id'] ?></label>
  124. <div class="col-sm-10">
  125. <input type="text" class="form-control" id="page_id" required>
  126. </div>
  127. </div>
  128. <div class="form-group row">
  129. <label for="type" class="col-sm-2 col-form-label"><?= $PMF_LANG['ad_meta_type'] ?></label>
  130. <div class="col-sm-10">
  131. <select class="form-control" id="type" required>
  132. <option value="text">Text</option>
  133. <option value="html">HTML</option>
  134. </select>
  135. </div>
  136. </div>
  137. <div class="form-group row">
  138. <label for="meta-content" class="col-sm-2 col-form-label"><?= $PMF_LANG['ad_meta_content'] ?></label>
  139. <div class="col-sm-10">
  140. <textarea class="form-control" id="meta-content" rows="5" required></textarea>
  141. </div>
  142. </div>
  143. </form>
  144. </div>
  145. <div class="modal-footer">
  146. <button type="button" class="btn btn-primary pmf-meta-add"><?= $PMF_LANG['msgSave'] ?></button>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. <!-- Modal to copy meta data code snippet -->
  152. <div class="modal fade" id="codeModal" tabindex="-1" role="dialog" aria-labelledby="codeModalLabel" aria-hidden="true">
  153. <div class="modal-dialog" role="document">
  154. <div class="modal-content">
  155. <div class="modal-header">
  156. <h5 class="modal-title" id="codeModalLabel"><?= $PMF_LANG['ad_meta_copy_snippet'] ?></h5>
  157. <button type="button" class="close" data-dismiss="modal" aria-label="<?= $PMF_LANG['ad_att_close'] ?>">
  158. <span aria-hidden="true">&times;</span>
  159. </button>
  160. </div>
  161. <div class="modal-body">
  162. <label class="sr-only" for="copy-code-snippet"><?= $PMF_LANG['ad_meta_copy_snippet'] ?></label>
  163. <textarea class="form-control" id="copy-code-snippet"></textarea>
  164. </div>
  165. <div class="modal-footer">
  166. <button type="button" class="btn btn-primary" data-dismiss="modal"><?= $PMF_LANG['ad_att_close'] ?></button>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. <script src="assets/js/meta.js"></script>