Frio - bugfix - don't show new event button if the button isn't available
[friendica.git/.git] / src / Worker / GProbe.php
1 <?php
2 /**
3  * @file src/Worker/GProbe.php
4  */
5
6 namespace Friendica\Worker;
7
8 use Friendica\Core\Cache;
9 use Friendica\Core\Protocol;
10 use Friendica\Database\DBA;
11 use Friendica\Model\GContact;
12 use Friendica\Network\Probe;
13 use Friendica\Protocol\PortableContact;
14
15 class GProbe {
16         public static function execute($url = '')
17         {
18                 if (empty($url)) {
19                         return;
20                 }
21
22                 $r = q(
23                         "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
24                         DBA::escape(normalise_link($url))
25                 );
26
27                 logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
28
29                 if (!DBA::isResult($r)) {
30                         // Is it a DDoS attempt?
31                         $urlparts = parse_url($url);
32
33                         $result = Cache::get("gprobe:".$urlparts["host"]);
34                         if (!is_null($result)) {
35                                 if (in_array($result["network"], [Protocol::FEED, Protocol::PHANTOM])) {
36                                         logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
37                                         return;
38                                 }
39                         }
40
41                         $arr = Probe::uri($url);
42
43                         if (is_null($result)) {
44                                 Cache::set("gprobe:".$urlparts["host"], $arr);
45                         }
46
47                         if (!in_array($arr["network"], [Protocol::FEED, Protocol::PHANTOM])) {
48                                 GContact::update($arr);
49                         }
50
51                         $r = q(
52                                 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
53                                 DBA::escape(normalise_link($url))
54                         );
55                 }
56                 if (DBA::isResult($r)) {
57                         // Check for accessibility and do a poco discovery
58                         if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == Protocol::DFRN)) {
59                                 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
60                         }
61                 }
62
63                 logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
64                 return;
65         }
66 }