1
0
Fork 0
forked from mirror/pixelfed

Update Extractor

This commit is contained in:
Daniel Supernault 2019-06-01 21:31:24 -06:00
parent 070dc14f31
commit 59a1346277
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -10,6 +10,7 @@
namespace App\Util\Lexer; namespace App\Util\Lexer;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Status;
/** /**
* Twitter Extractor Class. * Twitter Extractor Class.
@ -121,7 +122,7 @@ class Extractor extends Regex
$hashtagsOnly[] = $hashtagWithIndex['hashtag']; $hashtagsOnly[] = $hashtagWithIndex['hashtag'];
} }
return $hashtagsOnly; return array_slice($hashtagsOnly, 0, Status::MAX_HASHTAGS);
} }
/** /**
@ -134,12 +135,6 @@ class Extractor extends Regex
public function extractCashtags($tweet = null) public function extractCashtags($tweet = null)
{ {
$cashtagsOnly = []; $cashtagsOnly = [];
$cashtagsWithIndices = $this->extractCashtagsWithIndices($tweet);
foreach ($cashtagsWithIndices as $cashtagWithIndex) {
$cashtagsOnly[] = $cashtagWithIndex['cashtag'];
}
return $cashtagsOnly; return $cashtagsOnly;
} }
@ -159,7 +154,7 @@ class Extractor extends Regex
$urlsOnly[] = $urlWithIndex['url']; $urlsOnly[] = $urlWithIndex['url'];
} }
return $urlsOnly; return array_slice($urlsOnly, 0, Status::MAX_LINKS);
} }
/** /**
@ -277,7 +272,7 @@ class Extractor extends Regex
} }
if (!$checkUrlOverlap) { if (!$checkUrlOverlap) {
return $tags; return array_slice($tags, 0, Status::MAX_HASHTAGS);
} }
// check url overlap // check url overlap
@ -292,7 +287,7 @@ class Extractor extends Regex
$validTags[] = $entity; $validTags[] = $entity;
} }
return $validTags; return array_slice($validTags, 0, Status::MAX_HASHTAGS);
} }
/** /**
@ -390,7 +385,7 @@ class Extractor extends Regex
} }
} }
return $urls; return array_slice($urls, 0, Status::MAX_LINKS);
} }
/** /**
@ -415,7 +410,7 @@ class Extractor extends Regex
$usernamesOnly[] = $mention; $usernamesOnly[] = $mention;
} }
return $usernamesOnly; return array_slice($usernamesOnly, 0, Status::MAX_MENTIONS);
} }
/** /**
@ -472,7 +467,7 @@ class Extractor extends Regex
$results[] = $entity; $results[] = $entity;
} }
return $results; return array_slice($results, 0, Status::MAX_MENTIONS);
} }
/** /**