]> git.mxchange.org Git - friendica.git/blob - Text/BBCode/Video.php
wrapping up 2019.12
[friendica.git] / Text / BBCode / Video.php
1 <?php
2
3 namespace Friendica\Content\Text\BBCode;
4
5 /**
6  * Video specific BBCode util class
7  */
8 final class Video
9 {
10         /**
11          * Transforms video BBCode tagged links to youtube/vimeo tagged links
12          *
13          * @param string $bbCodeString The input BBCode styled string
14          *
15          * @return string The transformed text
16          */
17         public function transform(string $bbCodeString)
18         {
19                 $matches = null;
20                 $found = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$bbCodeString,$matches,PREG_SET_ORDER);
21                 if ($found) {
22                         foreach ($matches as $match) {
23                                 if ((stristr($match[1], 'youtube')) || (stristr($match[1], 'youtu.be'))) {
24                                         $bbCodeString = str_replace($match[0], '[youtube]' . $match[1] . '[/youtube]', $bbCodeString);
25                                 } elseif (stristr($match[1], 'vimeo')) {
26                                         $bbCodeString = str_replace($match[0], '[vimeo]' . $match[1] . '[/vimeo]', $bbCodeString);
27                                 }
28                         }
29                 }
30                 return $bbCodeString;
31         }
32 }