putxml.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright 2021, 2024 5 Mode
  4. *
  5. * This file is part of MacSwap.
  6. *
  7. * SnipSwap is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * SnipSwap is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with SnipSwap. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * putxml.php
  21. *
  22. * Write an xml file in the data folder.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2016, 2024, 5 Mode
  26. */
  27. //
  28. // VARIABLES AND FUNCTIONS DECLARATIONS
  29. //
  30. //
  31. // PARAMETER VALIDATION
  32. //
  33. $filename = filter_input(INPUT_POST, "f");
  34. $filename2 = $filename . ".xml";
  35. $xmlStr = filter_input(INPUT_POST, "xml");
  36. // if the snip data folder doesn'exist I create it
  37. // with all the subfolders..
  38. if (!is_readable(APP_DATA_PATH . PHP_SLASH . $filename)) {
  39. mkdir(APP_DATA_PATH . PHP_SLASH . $filename);
  40. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data");
  41. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "title");
  42. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "desc");
  43. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "code");
  44. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "cats");
  45. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "tags");
  46. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "label");
  47. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "link");
  48. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "email");
  49. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "guid");
  50. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "password");
  51. }
  52. // Saving the XML file..
  53. $filepath = APP_DATA_PATH . PHP_SLASH . $filename . PHP_SLASH . $filename2;
  54. file_put_contents($filepath, $xmlStr);
  55. // Saving filesystem version of the data..
  56. $details = new SimpleXMLElement($xmlStr);
  57. storeFSData($details, $filename, "title");
  58. storeFSData($details, $filename, "desc");
  59. storeFSData($details, $filename, "code");
  60. storeFSData($details, $filename, "cats");
  61. storeFSData($details, $filename, "tags");
  62. storeFSData($details, $filename, "label");
  63. storeFSData($details, $filename, "link");
  64. storeFSData($details, $filename, "email");
  65. storeFSData($details, $filename, "guid");
  66. storeFSData($details, $filename, "password");
  67. echo json_encode([200, 'OK']);