Jump to content
php.lv forumi

bbcode embed video youtube, vimeo


Леший

Recommended Posts

Sveiki!

 

Vajag uztaisīt embed video. Tiek izmantots ckeditor un plugins, kurā var iemest youtube vai vimeo linku, youtube shortlinku vai youtube embed.

Tas, kas ir iemests, tiek ielikts editorā, iekš [media] tega.

Problēma ir ar attēlošanu. Pašlaik bbcode parsēšanai tiek izmantots preg_replace:

$code = array(

 "/\[b\](.*?)\[\/b\]/is" => "<strong>$1</strong>",
 "/\[i\](.*?)\[\/i\]/is" => "<i>$1</i>",
 "/\[url\=(.*?)\](.*?)\[\/url\]/is" => "<a href='$1'>$2</a>",
 "/\[url\](.*?)\[\/url\]/is" => "<a href='$1'>$1</a>",
 "/\[list\=(.*?)\](.*?)\[\/list\]/is" => "<ol>$2</ol>",
 "/\[list\](.*?)\[\/list\]/is" => "<ul>$1</ul>",
 "/\[\*\](.*?)\n/is" => "<li>$1</li>",

 "/\[media\].*?vimeo\.com\/([0-9]+)\[\/media\]/is" => '<iframe src="http://player.vimeo.com/video/$1" width="415" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>',
 "/\[media\].*?youtube\..*v=([^&]+).*?\[\/media\]/is" => '<iframe width="415" height="315" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
 "/\[media\].*?youtu\.be\/([\w-]{11}).*?\[\/media\]/is" => '<iframe width="415" height="315" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
 "/\[media\].*?youtube\..*\/embed\/([\w-]{11}).*?\[\/media\]/is" => '<iframe width="415" height="315" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
 "/\n/" => "<br />",
);
return preg_replace(array_keys($code), array_values($code), $text);

Un viss ok rādās, ja video ir salikti tādā secībā, kādā ir aprakstīts tajā masīvā, tas ir, ja ielikt sākumā vimeo, pēc tam youtube short, piemēram:

[media]http://vimeo.com/37873697[/media]
[media]http://youtu.be/8-1F-CokXNU[/media]

tad viss ok, bet ja samainīt secību, tad parādās tikai vimeo, bet iepriekšajais video tiek repleisots uz <br /> (masīva pēdējais elements).

Kur var būt problēma?

 

P. S. Zinu, ka regexi briesmīgi, bet nav laika tos pārtaisīt.

Edited by Леший
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...