]> git.mxchange.org Git - friendica.git/blob - src/Worker/SpoolPost.php
API: fix sender/recipient of PMs: check api_user before get user info.
[friendica.git] / src / Worker / SpoolPost.php
1 <?php
2 /**
3  * @file src/Worker/SpoolPost.php
4  * @brief Posts items that wer spooled because they couldn't be posted.
5  */
6 namespace Friendica\Worker;
7
8 use Friendica\Model\Item;
9 use Friendica\Core\Config;
10
11 require_once("include/items.php");
12
13 class SpoolPost {
14         public static function execute() {
15                 $path = get_spoolpath();
16
17                 if (($path != '') && is_writable($path)){
18                         if ($dh = opendir($path)) {
19                                 while (($file = readdir($dh)) !== false) {
20
21                                         // It is not named like a spool file, so we don't care.
22                                         if (substr($file, 0, 5) != "item-") {
23                                                 continue;
24                                         }
25
26                                         $fullfile = $path."/".$file;
27
28                                         // We don't care about directories either
29                                         if (filetype($fullfile) != "file") {
30                                                 continue;
31                                         }
32
33                                         // We can't read or write the file? So we don't care about it.
34                                         if (!is_writable($fullfile) || !is_readable($fullfile)) {
35                                                 continue;
36                                         }
37
38                                         $arr = json_decode(file_get_contents($fullfile), true);
39
40                                         // If it isn't an array then it is no spool file
41                                         if (!is_array($arr)) {
42                                                 continue;
43                                         }
44
45                                         // Skip if it doesn't seem to be an item array
46                                         if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
47                                                 continue;
48                                         }
49
50                                         $result = Item::insert($arr);
51
52                                         logger("Spool file ".$file." stored: ".$result, LOGGER_DEBUG);
53                                         unlink($fullfile);
54                                 }
55                                 closedir($dh);
56                         }
57                 }
58         }
59 }