Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2KB

  1. <?php
  2. /**
  3. * @file include/spool_post.php
  4. * @brief Posts items that wer spooled because they couldn't be posted.
  5. */
  6. use \Friendica\Core\Config;
  7. require_once("include/items.php");
  8. function spool_post_run($argv, $argc) {
  9. global $a;
  10. $path = get_spoolpath();
  11. if (($path != '') AND is_writable($path)){
  12. if ($dh = opendir($path)) {
  13. while (($file = readdir($dh)) !== false) {
  14. // It is not named like a spool file, so we don't care.
  15. if (substr($file, 0, 5) != "item-") {
  16. continue;
  17. }
  18. $fullfile = $path."/".$file;
  19. // We don't care about directories either
  20. if (filetype($fullfile) != "file") {
  21. continue;
  22. }
  23. // We can't read or write the file? So we don't care about it.
  24. if (!is_writable($fullfile) OR !is_readable($fullfile)) {
  25. continue;
  26. }
  27. $arr = json_decode(file_get_contents($fullfile), true);
  28. // If it isn't an array then it is no spool file
  29. if (!is_array($arr)) {
  30. continue;
  31. }
  32. // Skip if it doesn't seem to be an item array
  33. if (!isset($arr['uid']) AND !isset($arr['uri']) AND !isset($arr['network'])) {
  34. continue;
  35. }
  36. $result = item_store($arr);
  37. logger("Spool file ".$file." stored: ".$result, LOGGER_DEBUG);
  38. unlink($fullfile);
  39. }
  40. closedir($dh);
  41. }
  42. }
  43. }