2018-11-12 03:08:33 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Directory\Models;
|
|
|
|
|
2018-11-13 03:49:49 +01:00
|
|
|
use Friendica\Directory\Utils\Network;
|
|
|
|
|
2018-11-12 03:08:33 +01:00
|
|
|
/**
|
2020-06-13 19:15:53 +02:00
|
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
2018-11-12 03:08:33 +01:00
|
|
|
*/
|
|
|
|
class ProfilePollQueue extends \Friendica\Directory\Model
|
|
|
|
{
|
2018-11-14 04:00:07 +01:00
|
|
|
const EMPTY_URL = 1;
|
|
|
|
const MISSING_HOST = 2;
|
|
|
|
const PRIVATE_HOST = 3;
|
|
|
|
const ALREADY_EXISTS = 4;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $profile_url
|
|
|
|
* @return int 0 on success or error code
|
|
|
|
*/
|
|
|
|
public function add(string $profile_url): int
|
2018-11-12 03:08:33 +01:00
|
|
|
{
|
|
|
|
$url = trim($profile_url);
|
|
|
|
|
|
|
|
if (!$url) {
|
2018-11-14 04:00:07 +01:00
|
|
|
return self::EMPTY_URL;
|
2018-11-12 03:08:33 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 03:49:49 +01:00
|
|
|
$host = parse_url($url, PHP_URL_HOST);
|
|
|
|
if (!$host) {
|
2018-11-14 04:00:07 +01:00
|
|
|
return self::MISSING_HOST;
|
2018-11-13 03:49:49 +01:00
|
|
|
}
|
|
|
|
|
2018-11-14 04:00:29 +01:00
|
|
|
if (!Network::isPublicHost($host)) {
|
2018-11-14 04:00:07 +01:00
|
|
|
return self::PRIVATE_HOST;
|
2018-11-13 03:49:49 +01:00
|
|
|
}
|
|
|
|
|
2018-11-14 04:00:07 +01:00
|
|
|
$affected = $this->atlas->fetchAffected(
|
2018-11-12 03:08:33 +01:00
|
|
|
'INSERT IGNORE INTO `profile_poll_queue` SET `profile_url` = :profile_url',
|
|
|
|
['profile_url' => $url]
|
|
|
|
);
|
|
|
|
|
2018-11-14 04:00:07 +01:00
|
|
|
return ($affected == 1 ? 0 : self::ALREADY_EXISTS);
|
2018-11-12 03:08:33 +01:00
|
|
|
}
|
|
|
|
}
|