]> git.mxchange.org Git - friendica.git/blob - include/spool_post.php
36bcab2a5570d865a851b84283b6abbe42990132
[friendica.git] / include / spool_post.php
1 <?php
2 /**
3  * @file include/spool_post.php
4  * @brief Posts items that wer spooled because they couldn't be posted.
5  */
6
7 use \Friendica\Core\Config;
8
9 require_once("boot.php");
10 require_once("include/items.php");
11
12 function spool_post_run($argv, $argc) {
13         global $a, $db;
14
15         if (is_null($a)) {
16                 $a = new App;
17         }
18
19         if (is_null($db)) {
20                 @include(".htconfig.php");
21                 require_once("include/dba.php");
22                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
23                 unset($db_host, $db_user, $db_pass, $db_data);
24         }
25
26         Config::load();
27
28         $path = get_spoolpath();
29
30         if (is_writable($path)){
31                 if ($dh = opendir($path)) {
32                         while (($file = readdir($dh)) !== false) {
33
34                                 // It is not named like a spool file, so we don't care.
35                                 if (substr($file, 0, 5) != "item-") {
36                                         continue;
37                                 }
38
39                                 $fullfile = $path."/".$file;
40
41                                 // We don't care about directories either
42                                 if (filetype($fullfile) != "file") {
43                                         continue;
44                                 }
45
46                                 // We can't read or write the file? So we don't care about it.
47                                 if (!is_writable($fullfile) OR !is_readable($fullfile)) {
48                                         continue;
49                                 }
50
51                                 $arr = json_decode(file_get_contents($fullfile), true);
52
53                                 // If it isn't an array then it is no spool file
54                                 if (!is_array($arr)) {
55                                         continue;
56                                 }
57
58                                 // Skip if it doesn't seem to be an item array
59                                 if (!isset($arr['uid']) AND !isset($arr['uri']) AND !isset($arr['network'])) {
60                                         continue;
61                                 }
62
63                                 $result = item_store($arr);
64
65                                 logger("Spool file ".$file." stored: ".$result, LOGGER_DEBUG);
66                                 unlink($fullfile);
67                         }
68                         closedir($dh);
69                 }
70         }
71 }
72
73 if (array_search(__file__, get_included_files()) === 0) {
74         spool_post_run($_SERVER["argv"], $_SERVER["argc"]);
75         killme();
76 }
77 ?>