You are here

public static function AmpSocialPost::getPatterns in Accelerated Mobile Pages (AMP) 8.3

Provider regex patterns.

return array Array of regex patterns for all supported providers.

See also

https://code.tutsplus.com/tutorials/advanced-regular-expression-tips-and...

3 calls to AmpSocialPost::getPatterns()
AmpSocialPost::getId in src/Element/AmpSocialPost.php
Get the provider id from an url.
AmpSocialPost::getProvider in src/Element/AmpSocialPost.php
Find the provider from an url.
AmpSocialPostTest::testGetPatterns in tests/src/Unit/AmpSocialPostTest.php
@covers ::getPatterns

File

src/Element/AmpSocialPost.php, line 142

Class

AmpSocialPost
Provides AMP social post elements.

Namespace

Drupal\amp\Element

Code

public static function getPatterns() {
  return [
    'facebook' => [
      '@https?://(?:www\\.)?(?<provider>facebook)\\.com/?(.*/)?(?<id>[a-zA-Z0-9.]*)($|\\?.*)@',
    ],
    'twitter' => [
      '@https?://(?:www\\.)?(?<provider>twitter)\\.com/(?<user>[a-z0-9_-]+)/(status(es){0,1})/(?<id>[\\d]+)@i',
    ],
    'instagram' => [
      '@https?://(?:www\\.)?(?<provider>instagram)\\.com/p/(?<id>[a-z0-9_-]+)@i',
      '@https?://(?:www\\.)?(?<provider>instagr\\.am)/p/(?<id>[a-z0-9_-]+)@i',
    ],
    'pinterest' => [
      '@https?://(?:www\\.)?(?<provider>pinterest)\\.([a-zA-Z]+\\.)?([a-zA-Z]+)/pin/(?<id>\\d+)/?\\s*$$@i',
    ],
  ];
}