|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+App::uses('TextHelper', 'View/Helper/');
|
|
|
4
|
+
|
|
|
5
|
+class TextExtendedHelper extends TextHelper {
|
|
|
6
|
+
|
|
|
7
|
+ private $embedRegexp = array(
|
|
|
8
|
+ "/<a href=\"(?:http:\\/\\/|https:\\/\\/)?(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/(?:watch\\?v=)?([^\\&\"]+).*\".*>.*<\\/a>/",
|
|
|
9
|
+ "/<a href=\"(?:http:\\/\\/|https:\\/\\/)?(?:www\\.)?(?:vimeo\\.com)\\/([^\\&\"]+).*\".*>.*<\\/a>/",
|
|
|
10
|
+ "/<a href=\"(?:http:\\/\\/|https:\\/\\/)?(?:www\\.)?(?:dailymotion\\.com|dai\\.ly)\\/([^\\&\"]+).*\".*>.*<\\/a>/"
|
|
|
11
|
+ );
|
|
|
12
|
+
|
|
|
13
|
+ private $embedIframe = array(
|
|
|
14
|
+ '<center><iframe width="480" height="270" src="http://www.youtube.com/embed/$1?modestbranding=1&rel=0&wmode=transparent&theme=light&color=white" frameborder="0" allowfullscreen></iframe></center>',
|
|
|
15
|
+ '<center><iframe src="//player.vimeo.com/video/$1" width="480" height="270" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></center>',
|
|
|
16
|
+ '<center><iframe frameborder="0" width="480" height="270" src="http://www.dailymotion.com/embed/video/$1?logo=0&foreground=ffffff&highlight=1bb4c6&background=000000" allowfullscreen></iframe></center>'
|
|
|
17
|
+ );
|
|
|
18
|
+
|
|
|
19
|
+ public function autoLink($text, $htmlOptions = array()) {
|
|
|
20
|
+ $text = parent::autoLink($text, $htmlOptions);
|
|
|
21
|
+ return preg_replace($this->embedRegexp, $this->embedIframe, $text);
|
|
|
22
|
+ }
|
|
|
23
|
+
|
|
|
24
|
+}
|