<?php
require_once(dirname(__FILE__) . '/../dashlet-helper.inc.php');

custom_url_dashlet();

function custom_url_dashlet()
{
    $valid_url = true;

    $url = grab_request_var('url');
   
    $rand = random_string(10);
    $id = "custom_url_$rand";
   

//  Check to see if user added https:// - add it if they didn't
    if  ( $ret = parse_url($url) ) {

        if ( !isset($ret["scheme"]) )
         {
         $url = "https://{$url}";
         }
  }
  
  if (!filter_var($url, FILTER_VALIDATE_URL)) {
    $valid_url = false;
}
 
    if ($valid_url) {
    ?>

    <iframe id="<?php echo $id;?>" src="<?php echo encode_html($url); ?>" height=100% width=100% frameborder="0"></iframe>
        
    <?php
    } else {
        echo '<p style="text-align: center;">'._('The URL provided is not valid').'.</p>';
    }
}