Example to modify and transform a existing BBCode to Auto Video Embed
Instruction - collecting informations
The very important thing is to find the unique usable syntax of this bbcode
bbcodeCode:
[TUTV]{TEXT}[/TUTV]
replacementCode:
<object width="425" height="350"><param name="movie" value="http://tu.tv/tutvweb.swf?kpt={TEXT}"></param><param name="wmode" value="transparent"></param><embed src="http://tu.tv/tutvweb.swf?kpt={TEXT}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
aha, here it is:
{TEXT}which also shows us the important part in html-replacement
http://tu.tv/tutvweb.swf?kpt={TEXT}nothing else matters at this time.
now we have to find out the important embed part.
there he is:
http://tu.tv/tutvweb.swf?kpt=aHR0cDovL3d3dy50dS50di92aWRlb3Njb2RpL3QvZS90ZWxldHViYmllcy1wdXRvLmZsdg==&xtp=1025292in this example the "real" browser-link is not usable (like in youtube), bcs. it contains nothing we can use to embed
Code:
http://tu.tv/videos/teletubbies-puto
now we have all information we need
Instruction - name the portal-variable
first
find in both files:
auto_video_embed_post.php
auto_video_embed_view.php
Code:
$myvideo = false;
after add (bcs. of alphabetical-order)
Code:
$tutv = false;
Instruction - the main code-transform
1. enter the given
portal-variable ($tutv)
2. find a distinctive link part (except http://) which stands alone and have no interruption between (here we take
tu.tv/tutvweb.swf?kpt=)
3. mask all
/,
& and
? with
\ in
'#search_part#' of preg_replace and transform
{TEXT} with
(.*?)4. take the html-replacement to the
, 'replace_part' in preg_replace and notice like
(.*?) interact with its dual
$1 ($2 if it interact with a second (.*?) etc.)
auto_video_embed_post.phpQuote:
if (($tutv) && (strpos($preview_message, 'tu.tv/tutvweb.swf?kpt=') !== false)){
$preview_message = preg_replace('#<a class="postlink" href="http:\/\/tu.tv\/tutvweb.swf\?kpt=(.*?)">(.*?)<\/a>#U', '<object width="425" height="350"><param name="movie" value="http://tu.tv/tutvweb.swf?kpt=$1"></param><param name="wmode" value="transparent"></param><embed src="http://tu.tv/tutvweb.swf?kpt=$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', $preview_message);}
auto_video_embed_view.phpQuote:
if (($tutv) && (strpos($message, 'tu.tv/tutvweb.swf?kpt=') !== false)){
$message = preg_replace('#<a class="postlink" href="http:\/\/tu.tv\/tutvweb.swf\?kpt=(.*?)">(.*?)<\/a>#U', '<object width="425" height="350"><param name="movie" value="http://tu.tv/tutvweb.swf?kpt=$1"></param><param name="wmode" value="transparent"></param><embed src="http://tu.tv/tutvweb.swf?kpt=$1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', $message);}
the framework is (in brief exceptions) still the same
- follow the syntax in this example
- the
'#search_part#' is still the same, except other link or embed-part.
- the part
, 'replace_part' is the normal html-replacement (the difference is the transform from {TEXT} to $1 (if a (.*?) have the first position in '#search_part#')).
- take a look at the other codes in original-files (may youtube) where the url-link is directly usable to transform and learn a bit from those integrated "examples".