+ /**
+ * Webfinger matches: @user@example.com or even @user--one.george_orwell@1984.biz
+ *
+ * @return array The matching IDs (without @ or acct:) and each respective position in the given string.
+ */
+ static function extractWebfingerIds($text)
+ {
+ $wmatches = array();
+ // Maybe this should harmonize with lib/nickname.php and Nickname::WEBFINGER_FMT
+ $result = preg_match_all('/(?<!\S)@((?:\w+[\w\-\_\.]*)?\w+@'.URL_REGEX_DOMAIN_NAME.')/',
+ $text,
+ $wmatches,
+ PREG_OFFSET_CAPTURE);
+ if ($result === false) {
+ common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
+ } else {
+ common_debug(sprintf('Found %i matches for WebFinger IDs: %s', count($wmatches), _ve($wmatches)));
+ }
+ return $wmatches[1];
+ }
+
+ /**
+ * Profile URL matches: @example.com/mublog/user
+ *
+ * @return array The matching URLs (without @ or acct:) and each respective position in the given string.
+ */
+ static function extractUrlMentions($text)
+ {
+ $wmatches = array();
+ // In the regexp below we need to match / _before_ URL_REGEX_VALID_PATH_CHARS because it otherwise gets merged
+ // with the TLD before (but / is in URL_REGEX_VALID_PATH_CHARS anyway, it's just its positioning that is important)
+ $result = preg_match_all('/(?:^|\s+)@('.URL_REGEX_DOMAIN_NAME.'(?:\/['.URL_REGEX_VALID_PATH_CHARS.']*)*)/',
+ $text,
+ $wmatches,
+ PREG_OFFSET_CAPTURE);
+ if ($result === false) {
+ common_log(LOG_ERR, __METHOD__ . ': Error parsing profile URL mentions from text (preg_last_error=='.preg_last_error().').');
+ } else {
+ common_debug(sprintf('Found %i matches for profile URL mentions: %s', count($wmatches), _ve($wmatches)));
+ }
+ return $wmatches[1];
+ }
+