Guest User

not twerking

a guest
Feb 17th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1.     //phrase image and youtube links
  2.     foreach ($template->query('//article/div/p[a and count(*)=1 and not(normalize-space(text()))]') as $node) {
  3.         $link = trim($node->nodeValue);
  4.         $replace = false;
  5.  
  6.         if (
  7.             preg_match('~(?:
  8.                 https?://(?:www\.)?youtu(?:be\.com/(?:embed/|watch\?(?:.+&)?v=)|\.be/)([a-z0-9_\-]+) # Parsing YouTube URLs.
  9.                 |
  10.                 (.+\.(?:png|jpe?g|gif|webp)$) # Parsing image URLs.
  11.                 |
  12.                 (.+\.(?:webm|mp4|mov|3gp|avi)$) # Parsing video URLs.
  13.             )~ixA', $link, $matches)
  14.         ) {
  15.             if (strlen($matches[1])) { // We found a YouTube video.
  16.                 $replace = '<iframe width="100%" height="360" src="http://www.youtube-nocookie.com/embed/' . $matches[1] . '?autoplay=0&amp;rel=0" frameborder="0" allowfullscreen="allowfullscreen">' . safeHTML($link) . '</iframe>';
  17.             } else if (strlen($matches[2])) { // We found an image link.
  18.                 $replace = '<a target="_blank" href="' . safeHTML($link) . '"><img style="max-width: 100%;" src="' . $matches[2] . '" alt="Click to view full size image." /></a>';
  19.             } else if (strlen($matches[3])) { // We found an video link.
  20.                 $replace = '<video style="max-width: 100%;" src="' . $matches[3] . '" controls />';
  21.             }
  22.         }
  23.  
  24.         if ($replace) {
  25.             $frag = $node->ownerDocument->createDocumentFragment();
  26.             if (!@$frag->appendXML($replace) || !@$node->parentNode->replaceChild($frag, $node)) {
  27.                 throw new Exception("Invalid HTML");
  28.             }
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment