putxml.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 . "beauty");
  50. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "guid");
  51. mkdir(APP_DATA_PATH . PHP_SLASH . $filename. PHP_SLASH . "data". PHP_SLASH . "password");
  52. }
  53. // Saving the XML file..
  54. $filepath = APP_DATA_PATH . PHP_SLASH . $filename . PHP_SLASH . $filename2;
  55. file_put_contents($filepath, $xmlStr);
  56. // Saving filesystem version of the data..
  57. $details = new SimpleXMLElement($xmlStr);
  58. storeFSData($details, $filename, "title");
  59. storeFSData($details, $filename, "desc");
  60. storeFSData($details, $filename, "code");
  61. storeFSData($details, $filename, "cats");
  62. storeFSData($details, $filename, "tags");
  63. storeFSData($details, $filename, "label");
  64. storeFSData($details, $filename, "link");
  65. storeFSData($details, $filename, "email");
  66. storeFSData($details, $filename, "beauty");
  67. storeFSData($details, $filename, "guid");
  68. storeFSData($details, $filename, "password");
  69. echo json_encode([200, 'OK']);