+ public static function getTargetType(string $url, bool $fetch = true)
+ {
+ $target = null;
+
+ if (empty($url)) {
+ return $target;
+ }
+
+ $tag = DBA::selectFirst('tag', ['url', 'type'], ['url' => $url]);
+ if (!empty($tag['type'])) {
+ $target = $tag['type'];
+ if ($target != self::GENERAL_COLLECTION) {
+ Logger::debug('Found existing type', ['type' => $tag['type'], 'url' => $url]);
+ return $target;
+ }
+ }
+
+ if ($url == ActivityPub::PUBLIC_COLLECTION) {
+ $target = self::PUBLIC_COLLECTION;
+ Logger::debug('Public collection', ['url' => $url]);
+ } else {
+ if (DBA::exists('apcontact', ['followers' => $url])) {
+ $target = self::FOLLOWER_COLLECTION;
+ Logger::debug('Found collection via existing apcontact', ['url' => $url]);
+ } elseif (Contact::getIdForURL($url, 0, $fetch ? null : false)) {
+ $target = self::ACCOUNT;
+ Logger::debug('URL is an account', ['url' => $url]);
+ } elseif ($fetch && ($target != self::GENERAL_COLLECTION)) {
+ $content = ActivityPub::fetchContent($url);
+ if (!empty($content['type']) && ($content['type'] == 'OrderedCollection')) {
+ $target = self::GENERAL_COLLECTION;
+ Logger::debug('URL is an ordered collection', ['url' => $url]);
+ }
+ }
+ }
+
+ if (!empty($target) && !empty($tag['url']) && ($tag['type'] != $target)) {
+ DBA::update('tag', ['type' => $target], ['url' => $url]);
+ }
+
+ if (empty($target)) {
+ Logger::debug('No type could be detected', ['url' => $url]);
+ }
+
+ return $target;
+ }
+
+ /**
+ * Get a tag id for a given tag name and URL
+ *
+ * @param string $name Name of tag
+ * @param string $url
+ * @param int $type Type of tag
+ * @return int Tag id
+ */
+ public static function getID(string $name, string $url = '', int $type = null): int