editlink.inc.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2022 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 = array();
  29. $formData = array();
  30. # very simple security check.
  31. # can/should be extended in the future.
  32. Summoner::simpleAuth();
  33. $_id = '';
  34. if(isset($_GET['id']) && !empty($_GET['id'])) {
  35. $_id = trim($_GET['id']);
  36. $_id = Summoner::validate($_id,'nospace') ? $_id : '';
  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 = '';
  45. if(isset($_GET['m']) && !empty($_GET['m'])) {
  46. $_requestMode = trim($_GET['m']);
  47. $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : '';
  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. if($_isAwm === true) {
  56. $submitFeedback['message'] = $T->t('edit.link.accept.new.link');
  57. $submitFeedback['status'] = 'success';
  58. }
  59. if($_requestMode == "export") {
  60. $linkObj->load($_id);
  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'] = $T->t('edit.link.export.fail');
  74. $submitFeedback['status'] = 'error';
  75. }
  76. }
  77. else {
  78. $submitFeedback['message'] = $T->t('edit.link.export.data.fail');
  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['snapshot'] = false;
  93. if(isset($fData['snapshot'])) {
  94. $formData['snapshot'] = true;
  95. }
  96. $formData['pagescreenshot'] = false;
  97. if(isset($fData['pagescreenshot'])) {
  98. $formData['pagescreenshot'] = true;
  99. }
  100. $formData['description'] = trim($fData['description']);
  101. $formData['title'] = trim($fData['title']);
  102. $formData['image'] = trim($fData['image']);
  103. $formData['category'] = trim($fData['category']);
  104. $formData['tag'] = trim($fData['tag']);
  105. if(!empty($formData['title'])) {
  106. $linkObj->load($_id);
  107. $update = $linkObj->update($formData);
  108. if($update === true) {
  109. $submitFeedback['message'] = $T->t('edit.link.updated');
  110. $submitFeedback['status'] = 'success';
  111. // update link info
  112. $linkObj->reload();
  113. $linkData = $linkObj->getData();
  114. }
  115. else {
  116. $submitFeedback['message'] = $T->t('edit.link.update.failed');
  117. $submitFeedback['status'] = 'error';
  118. }
  119. }
  120. else {
  121. $submitFeedback['message'] = $T->t('edit.link.update.title.missing');
  122. $submitFeedback['status'] = 'error';
  123. }
  124. }
  125. elseif(isset($_POST['refreshlink'])) {
  126. $linkInfo = Summoner::gatherInfoFromURL($linkData['link']);
  127. if(!empty($linkInfo)) {
  128. if(isset($linkInfo['description'])) {
  129. $linkData['description'] = $linkInfo['description'];
  130. }
  131. if(isset($linkInfo['title'])) {
  132. $linkData['title'] = $linkInfo['title'];
  133. }
  134. if(isset($linkInfo['image'])) {
  135. $linkData['image'] = $linkInfo['image'];
  136. }
  137. }
  138. }
  139. elseif(isset($_POST['deleteLink'])) {
  140. $fData = $_POST['data'];
  141. if(isset($fData['delete'])) {
  142. $do = $Management->deleteLink($_id);
  143. if($do === true) {
  144. if($_isAwm === true) {
  145. header('Location: index.php?p=overview&m=awm');
  146. }
  147. else {
  148. header('Location: index.php');
  149. }
  150. exit();
  151. }
  152. }
  153. }
  154. $formData = $linkData;
  155. $existingCategories = $Management->categories();
  156. $existingTags = $Management->tags();