editlink.inc.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2020 Johannes Keßler
  7. *
  8. * Development starting from 2011: Johannes Keßler
  9. * https://www.bananas-playground.net/projekt/insipid/
  10. *
  11. * creator:
  12. * Luke Reeves <luke@neuro-tech.net>
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  26. *
  27. */
  28. $submitFeedback = false;
  29. $formData = false;
  30. # very simple security check.
  31. # can/should be extended in the future.
  32. Summoner::simpleAuth();
  33. $_id = false;
  34. if(isset($_GET['id']) && !empty($_GET['id'])) {
  35. $_id = trim($_GET['id']);
  36. $_id = Summoner::validate($_id,'nospace') ? $_id : false;
  37. }
  38. $_isAwm = false;
  39. if(isset($_GET['awm']) && !empty($_GET['awm'])) {
  40. $_isAwm = trim($_GET['awm']);
  41. $_isAwm = Summoner::validate($_isAwm,'digit') ? true : false;
  42. $Management->setShowAwm($_isAwm);
  43. }
  44. $_requestMode = false;
  45. if(isset($_GET['m']) && !empty($_GET['m'])) {
  46. $_requestMode = trim($_GET['m']);
  47. $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : false;
  48. }
  49. $linkData = $Management->loadLink($_id);
  50. if(empty($linkData)) {
  51. header("HTTP/1.0 404 Not Found");
  52. exit();
  53. }
  54. $linkObj = new Link($DB);
  55. $linkObj->load($_id);
  56. if($_isAwm === true) {
  57. $submitFeedback['message'] = 'To accept this link (link has moderation status), just save it. Otherwise just delete.';
  58. $submitFeedback['status'] = 'success';
  59. }
  60. if($_requestMode && $_requestMode == "export") {
  61. $_i = $linkObj->getData('id');
  62. if(!empty($_i)) {
  63. $exportFilename = 'inspid-single-export-'.$_i.'.xml';
  64. $exportData = $Management->exportLinkData(false, $linkObj);
  65. if (!empty($exportData)) {
  66. header('Content-Type: text/xml');
  67. header("Content-Transfer-Encoding: Binary");
  68. header("Content-disposition: attachment; filename=$exportFilename");
  69. echo($exportData);
  70. exit();
  71. }
  72. else {
  73. $submitFeedback['message'] = 'Export could not generated.';
  74. $submitFeedback['status'] = 'error';
  75. }
  76. }
  77. else {
  78. $submitFeedback['message'] = 'Required data for export could not be loaded.';
  79. $submitFeedback['status'] = 'error';
  80. }
  81. }
  82. if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) {
  83. $fData = $_POST['data'];
  84. $formData['private'] = 2;
  85. if(isset($fData['private'])) {
  86. $formData['private'] = 1;
  87. }
  88. $formData['localImage'] = false;
  89. if(isset($fData['localImage'])) {
  90. $formData['localImage'] = true;
  91. }
  92. $formData['description'] = trim($fData['description']);
  93. $formData['title'] = trim($fData['title']);
  94. $formData['image'] = trim($fData['image']);
  95. $formData['category'] = trim($fData['category']);
  96. $formData['tag'] = trim($fData['tag']);
  97. if(!empty($formData['title'])) {
  98. $update = $linkObj->update($formData);
  99. if($update === true) {
  100. $submitFeedback['message'] = 'Link updated successfully.';
  101. $submitFeedback['status'] = 'success';
  102. // update link info
  103. $linkObj->reload();
  104. $linkData = $linkObj->getData();
  105. }
  106. else {
  107. $submitFeedback['message'] = 'Something went wrong...';
  108. $submitFeedback['status'] = 'error';
  109. }
  110. }
  111. else {
  112. $submitFeedback['message'] = 'Please provide a title.';
  113. $submitFeedback['status'] = 'error';
  114. }
  115. }
  116. elseif(isset($_POST['refreshlink'])) {
  117. $linkInfo = Summoner::gatherInfoFromURL($linkData['link']);
  118. if(!empty($linkInfo)) {
  119. if(isset($linkInfo['description'])) {
  120. $linkData['description'] = $linkInfo['description'];
  121. }
  122. if(isset($linkInfo['title'])) {
  123. $linkData['title'] = $linkInfo['title'];
  124. }
  125. if(isset($linkInfo['image'])) {
  126. $linkData['image'] = $linkInfo['image'];
  127. }
  128. }
  129. }
  130. elseif(isset($_POST['deleteLink'])) {
  131. $fData = $_POST['data'];
  132. if(isset($fData['delete'])) {
  133. $do = $Management->deleteLink($_id);
  134. if($do === true) {
  135. if($_isAwm === true) {
  136. header('Location: index.php?p=overview&m=awm');
  137. }
  138. else {
  139. header('Location: index.php');
  140. }
  141. exit();
  142. }
  143. }
  144. }
  145. $formData = $linkData;
  146. $existingCategories = $Management->categories();
  147. $existingTags = $Management->tags();