Embedding YouTube videos in the Prado’s THtmlArea

I had problem in Prado’s THtmlArea with embedding videos not only from YouTube but also from other alternatives. It seems that THtmlArea is coded so that there is no way of allowing just object and embed tags. However you can use Text property and everything is fine. But when you want to use the SafeText property you are in a trouble with embeded videos. So what I did was to extend the THtmlArea component and created my own that goes beyond that limitation. Here it is:

<?php
/**
 * MTHtmlArea class file.
 *
 * @author Georgi Budinov <georgi[at]budinov[dot]com>
 * @link http://georgi.budinov.com/
 *
 * MTHtmlArea class
 *
 * Enables the embed and object tag in order post embeded videos from YouTube for example still using the safe text property
 */

//Includes THtmlArea class
Prado::using('System.Web.UI.WebControls.THtmlArea');
class MTHtmlArea extends THtmlArea
{
 public function __construct()
 {
   parent::__construct();

   $ind = array_search('object', $this->SafeTextParser->deleteTags);
   if($ind >= 0)
   {
     unset($this->SafeTextParser->deleteTags[$ind]);
   }

   // remove the embed tag from the list if it is there
   $ind = array_search('embed', $this->SafeTextParser->deleteTags);
   if($ind >= 0)
   {
     unset($this->SafeTextParser->deleteTags[$ind]);
   }

   //reset the indexes
   $this->SafeTextParser->deleteTags = array_values($this->SafeTextParser->deleteTags);
 }
}
?>

You can use this class as the following example shows:

<com:MTHtmlArea ID="Test">
 <prop:Options>
   extended_valid_elements: "object[width|height],param[name|value],embed[src|type|allowscriptaccess|allowfullscreen|width|height]"
 </prop:Options>
</com:MTHtmlArea>

You have to add the extended_valid_elements option in order to allow the tinymce to accept these tags.
If you use one of the earlier versions of Prado it is not required.
Enjoy!

This post is also available in: Bulgarian

  1. Grabbing an opportunity, I point out it might be easier to make the perfect party with his big clients like Delta, Pepsi, award shows or corporate retreats, or even his personal high end clients who can simply pay for what is needed to make their dreams come true.

  1. No trackbacks yet.