editlink.inc.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2019 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. $linkData = $Management->loadLink($_id);
  45. if(empty($linkData)) {
  46. header("HTTP/1.0 404 Not Found");
  47. exit();
  48. }
  49. $linkObj = new Link($DB);
  50. $linkObj->load($_id);
  51. if($_isAwm === true) {
  52. $submitFeedback['message'] = 'To accept this link (link has moderation status), just save it. Otherwise just delete.';
  53. $submitFeedback['status'] = 'success';
  54. }
  55. if(isset($_POST['data']) && !empty($_POST['data']) && isset($_POST['editlink'])) {
  56. $fData = $_POST['data'];
  57. $formData['private'] = 2;
  58. if(isset($fData['private'])) {
  59. $formData['private'] = 1;
  60. }
  61. $formData['localImage'] = false;
  62. if(isset($fData['localImage'])) {
  63. $formData['localImage'] = true;
  64. }
  65. $formData['description'] = trim($fData['description']);
  66. $formData['title'] = trim($fData['title']);
  67. $formData['image'] = trim($fData['image']);
  68. $formData['category'] = trim($fData['category']);
  69. $formData['tag'] = trim($fData['tag']);
  70. if(!empty($formData['title'])) {
  71. $update = $linkObj->update($formData);
  72. if($update === true) {
  73. $submitFeedback['message'] = 'Link updated successfully.';
  74. $submitFeedback['status'] = 'success';
  75. // update link info
  76. $linkObj->reload();
  77. $linkData = $linkObj->getData();
  78. }
  79. else {
  80. $submitFeedback['message'] = 'Something went wrong...';
  81. $submitFeedback['status'] = 'error';
  82. }
  83. }
  84. else {
  85. $submitFeedback['message'] = 'Please provide a title.';
  86. $submitFeedback['status'] = 'error';
  87. }
  88. }
  89. elseif(isset($_POST['refreshlink'])) {
  90. $linkInfo = Summoner::gatherInfoFromURL($linkData['link']);
  91. if(!empty($linkInfo)) {
  92. if(isset($linkInfo['description'])) {
  93. $linkData['description'] = $linkInfo['description'];
  94. }
  95. if(isset($linkInfo['title'])) {
  96. $linkData['title'] = $linkInfo['title'];
  97. }
  98. if(isset($linkInfo['image'])) {
  99. $linkData['image'] = $linkInfo['image'];
  100. }
  101. }
  102. }
  103. elseif(isset($_POST['deleteLink'])) {
  104. $fData = $_POST['data'];
  105. if(isset($fData['delete'])) {
  106. $do = $Management->deleteLink($_id);
  107. if($do === true) {
  108. if($_isAwm === true) {
  109. header('Location: index.php?p=overview&m=awm');
  110. }
  111. else {
  112. header('Location: index.php');
  113. }
  114. exit();
  115. }
  116. }
  117. }
  118. $formData = $linkData;
  119. # prepare the tag string
  120. $formData['tag'] = '';
  121. if(!empty($linkData['tags'])) {
  122. foreach($linkData['tags'] as $k=>$v) {
  123. $formData['tag'] .= $v.',';
  124. }
  125. $formData['tag'] = trim($formData['tag']," ,");
  126. }
  127. # prepare the category string
  128. $formData['category'] = '';
  129. if(!empty($linkData['categories'])) {
  130. foreach($linkData['categories'] as $k=>$v) {
  131. $formData['category'] .= $v.',';
  132. }
  133. $formData['category'] = trim($formData['category']," ,");
  134. }
  135. $existingCategories = $Management->categories();
  136. $existingTags = $Management->tags();