Using default sites

A collection of site definitions is available by default via the defaultSites property. The collection can be accessed as an array or via this API and can be iterated. Each entry contains the definition for a given site as well as optional information such as the site's name or homepage URL.

Read the list of default sites

$configurator = new s9e\TextFormatter\Configurator;

foreach ($configurator->MediaEmbed->defaultSites as $siteId => $siteConfig)
    echo "$siteId => ", print_r(array_filter($siteConfig), true);

    // We only need one entry for this example
abcnews => Array
    [example] =>
    [extract] => Array
            [0] => !abcnews\.go\.com/(?:video/embed\?id=|[^/]+/video/[^/]+-)(?'id'\d+)!

    [homepage] =>
    [host] => Array
            [0] =>

    [iframe] => Array
            [src] => //{@id}

    [name] => ABC News
    [tags] => Array
            [0] => news


Modify the default sites collection

$configurator = new s9e\TextFormatter\Configurator;

echo 'Does YouTube exist? ';
echo $configurator->MediaEmbed->defaultSites->exists('youtube') ? "yes\n" : "no\n";

// Delete YouTube
echo 'What about now? ';
echo $configurator->MediaEmbed->defaultSites->exists('youtube') ? "yes\n" : "no\n";

// Replace it with your own
        'host'    => '',
        'extract' => '!youtu\.be/(?<id>\w+)!',
        'iframe'  => ['src' => '//{@id}']

// Or remove them all
echo count($configurator->MediaEmbed->defaultSites), " sites remaining.\n";
echo count($configurator->MediaEmbed->defaultSites), " sites remaining.\n";
Does YouTube exist? yes
What about now? no
131 sites remaining.
0 sites remaining.

Template parameters

Some default sites support some level of configuration at runtime via template parameters.

AMAZON_ASSOCIATE_TAG Amazon Associate tag (.com)
AMAZON_ASSOCIATE_TAG_CA Amazon Associate tag (.ca)
AMAZON_ASSOCIATE_TAG_DE Amazon Associate tag (.de)
AMAZON_ASSOCIATE_TAG_ES Amazon Associate tag (.es)
AMAZON_ASSOCIATE_TAG_FR Amazon Associate tag (.fr)
AMAZON_ASSOCIATE_TAG_IN Amazon Associate tag (.in)
AMAZON_ASSOCIATE_TAG_IT Amazon Associate tag (.it)
AMAZON_ASSOCIATE_TAG_JP Amazon Associate tag (
AMAZON_ASSOCIATE_TAG_UK Amazon Associate tag (
MEDIAEMBED_THEME Either an empty string (default) or "dark" for dark theme