]> git.mxchange.org Git - friendica-addons.git/blob - twitter/twitter_sync.php
Replace and/AND and or/OR by && and ||
[friendica-addons.git] / twitter / twitter_sync.php
1 <?php
2
3 use Friendica\App;
4
5 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
6         $directory = dirname($_SERVER["argv"][0]);
7
8         if (substr($directory, 0, 1) != "/")
9                 $directory = $_SERVER["PWD"]."/".$directory;
10
11         $directory = realpath($directory."/..");
12
13         chdir($directory);
14 }
15
16 require_once("boot.php");
17
18
19 function twitter_sync_run($argv, $argc){
20         global $a, $db;
21
22         if (is_null($a)) {
23                 $a = new App;
24         }
25
26         if (is_null($db)) {
27                 @include(".htconfig.php");
28                 require_once("include/dba.php");
29                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
30                 unset($db_host, $db_user, $db_pass, $db_data);
31         };
32
33         require_once("addon/twitter/twitter.php");
34         require_once("include/pidfile.php");
35
36         $maxsysload = intval(get_config('system','maxloadavg'));
37         if ($maxsysload < 1) {
38                 $maxsysload = 50;
39         }
40         if (function_exists('sys_getloadavg')) {
41                 $load = sys_getloadavg();
42                 if (intval($load[0]) > $maxsysload) {
43                         logger('system: load ' . $load[0] . ' too high. Twitter sync deferred to next scheduled run.');
44                         return;
45                 }
46         }
47
48         if ($argc < 3) {
49                 return;
50         }
51
52         $mode = intval($argv[1]);
53         $uid = intval($argv[2]);
54
55         // This is deprecated with the worker
56         if (function_exists("get_lockpath")) {
57                 $lockpath = get_lockpath();
58                 if ($lockpath != '') {
59                         $pidfile = new pidfile($lockpath, 'twitter_sync-'.$mode.'-'.$uid);
60                         if ($pidfile->is_already_running()) {
61                                 logger("Already running");
62                                 if ($pidfile->running_time() > 9*60) {
63                                         $pidfile->kill();
64                                         logger("killed stale process");
65                                         // Calling a new instance
66                                         proc_run('php','addon/twitter/twitter_sync.php', $mode, $uid);
67                                 }
68                                 exit;
69                         }
70                 }
71         }
72
73         if ($mode == 1) {
74                 twitter_fetchtimeline($a, $uid);
75         } elseif ($mode == 2) {
76                 twitter_fetchhometimeline($a, $uid);
77         }
78 }
79
80 if (array_search(__file__,get_included_files())===0){
81         twitter_sync_run($_SERVER["argv"],$_SERVER["argc"]);
82         killme();
83 }
84 ?>