Jump to content
php.lv forumi

youtube embed


anonīms

Recommended Posts

Sveiki. Ir doma izveidot video sadaļu ar youtube embed, tikai liels jautājums ir drošība.

Kā atļaut, ka visi html tagi tiek apbriezti izņemot embed un arī iekšs embed nevar vēl kkādu xss fīču iemaukt.

teiksim javascript onclick vai ko tādu?

Link to comment
Share on other sites

http://htmlpurifier.org/ ar to tiek galā ļoti labi.

 

 

Ā un vispār jaunākais standars skaitās embedod izmantojot ifreimus, arī youtubei.

Tam es izmantoju paštaisītu klasi priekš htmlpurifier-a:

 

class HTMLPurifier_AttrDef_URI_AllowedHosts extends HTMLPurifier_AttrDef_URI
{
 protected $allowd_hosts;
 public function __construct($embeds_resource = false,$allowed_hosts=array()){
$this->allowed_hosts=$allowed_hosts;
parent::__construct($embeds_resource);
 }
 public function validate($uri, $config, $context){
$p=parse_url($uri);
if (!in_array($p['host'],$this->allowed_hosts)) {return false;}
return parent::validate($uri, $config, $context);
 }
}

 

Kura atļauj tikai noteiktus domeinus. Tālāk izmanto šādi:

 

$def = $config->getHTMLDefinition(true);
$iframe = $def->addElement('iframe','Inline','Flow','Common',
  array(
    'src*'=>new HTMLPurifier_AttrDef_URI_AllowedHosts(false,array('www.youtube.com','youtube.com','maps.google.com')),
    'width'=>'Pixels#800',
    'height'=>'Pixels#600',
    'frameborder'=>'Number',
    'name'=>'ID',
     'title'=>'CDATA'
  )
);

Edited by codez
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...