#!/usr/bin/php <?php include __DIR__ . '/../src/autoloader.php'; $configurator = new s9e\TextFormatter\Configurator(); $configurator->plugins->load('MediaEmbed', ['captureURLs' => false]); $configurator->registeredVars['cacheDir'] = __DIR__ . '/../tests/.cache'; $siteId = $_SERVER['argv'][1]; $configurator->MediaEmbed->add($siteId); $dirpath = realpath(__DIR__ . '/../src/Plugins/MediaEmbed/Configurator/sites'); $siteFile = $dirpath . '/' . $siteId . '.xml'; $parser = $configurator->getParser(); $renderer = $configurator->getRenderer(); $html = ''; $site = simplexml_load_file($siteFile); foreach ($site->example as $example) { $text = '[media=' . $siteId . ']' . $example . '[/media]'; $xml = $parser->parse($text); $html .= $renderer->render($xml) . "\n"; } $out = '<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>MediaEmbed test page</title> <base href="http://localhost"/> </head> <body>' . $html . '</body></html>'; file_put_contents('/tmp/MediaEmbed.html', $out); die("Done.\n");
$config[KEY_TAGS][(string) $tag] = 1; } } else { // Untagged sites go into the "misc" category $config[KEY_TAGS]['misc'] = 1; } // Default HTML replacement. Ensure that iframe and script have an end tag $html = preg_replace('#(<(iframe|script)[^>]+)/>#', '$1></$2>', $template); $useEmbedCallback = false; // Test whether the template needs to be rendered in PHP. Some sites don't like URL-encoding so // we force them to be rendered in PHP regardless of the template. XenForo encodes ":" to %3A // which Comedy Central's servers don't like if (strpos($html, '<xsl:') !== false || preg_match('(="[^"]*(?<!\\{)\\{(?!\\{|@id\\}))', $html) || strpos($html, 'media.mtvnservices.com') !== false || $siteId === 'cnn' || $siteId === 'mailru') { // Capture the PHP source for this template $regexp = '(if\\(\\$tb===0\\)\\{?(.*?)\\}?elseif\\(\\$tb===)s'; if (!preg_match($regexp, $configurator->getRenderer()->source, $m)) { die('Could not match ' . $site['name'] . " renderer\n"); } $src = "\$html='';" . $m[1]; $src = str_replace("\$html='';\$this->out.=", '$html=', $src); $src = preg_replace("#\\\$node->hasAttribute\\(('[^']+')\\)#", 'isset($vars[$1])', $src); $src = preg_replace("#\\\$node->getAttribute\\(('[^']+')\\)#", '$vars[$1]', $src); $src = str_replace('$this->out', '$html', $src); // Replace the template params $src = preg_replace_callback("#\\\$this->params\\['([^']+)'\\]#", function ($m) use($addon, &$optionNames) { $paramName = $m[1]; $optionName = $addon->getAttribute('addon_id') . '_' . $m[1]; $optionNames[$paramName] = $optionName; return "XenForo_Application::get('options')->" . $optionName; }, $src); if (preg_match("((?<!XenForo_Application::get\\('options'\\))->)", $src)) {