]> git.mxchange.org Git - friendica.git/blob - src/Worker/Directory.php
634c5a5ec513479a9bce8066dcd7967e4e15e703
[friendica.git] / src / Worker / Directory.php
1 <?php
2 /**
3  * @file src/Worker/Directory.php
4  * @brief Sends updated profile data to the directory
5  */
6
7 namespace Friendica\Worker;
8
9 use Friendica\Core\Addon;
10 use Friendica\Core\Config;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBM;
13 use Friendica\Util\Network;
14
15 class Directory {
16         public static function execute($url = '') {
17                 $dir = Config::get('system', 'directory');
18
19                 if (!strlen($dir)) {
20                         return;
21                 }
22
23                 if ($url == '') {
24                         self::updateAll();
25                         return;
26                 }
27
28                 $dir .= "/submit";
29
30                 $arr = ['url' => $url];
31
32                 Addon::callHooks('globaldir_update', $arr);
33
34                 logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG);
35                 if (strlen($arr['url'])) {
36                         Network::fetchURL($dir . '?url=' . bin2hex($arr['url']));
37                 }
38
39                 return;
40         }
41
42         private static function updateAll() {
43                 $r = q("SELECT `url` FROM `contact`
44                         INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
45                         INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
46                                 WHERE `contact`.`self` AND `profile`.`net-publish` AND `profile`.`is-default` AND
47                                         NOT `user`.`account_expired` AND `user`.`verified`");
48
49                 if (DBM::is_result($r)) {
50                         foreach ($r AS $user) {
51                                 Worker::add(PRIORITY_LOW, 'Directory', $user['url']);
52                         }
53                 }
54         }
55 }