
  #extension to def customCheck():
        # Here we deconstruct incoming iframes and reconstruct them safely.
        # After this, both url and label will be scanned for html purity in the model, upon saving to db.

        # The 'link' radio button on form was checked.  Make the label a link using the url as href.
        #if request.POST.get("urlType")=='link':

        # The 'embed' radio button on form was checked.  Deconstruct the url getting its src for client to reconstruct as a secure iframe.
        #elif request.POST.get("urlType") and request.POST["urlType"]=='embed':
            #if not request.POST.get("url"):
                #urlError = "Need an address if 'Embed' is checked."
            #if not request.POST.get("label"):
                #labelError = "Need a label if 'Embed' is checked."
            # not just if, but elif. Don't show the iframe label about to be created.
            #elif request.POST.get("url"):
                #request.POST["url"] = parseSrcFromVideoLink(request.POST["url"])
                #request.POST["nodetype"]=settings.VIDEO_NODE



def parseSrcFromVideoLink(request):
    try:
        # youtube
        embed = settings.VIDEOREGEX["youtube"]["embed"]
        share = settings.VIDEOREGEX["youtube"]["share"]
        URI = settings.VIDEOREGEX["youtube"]["URI"]
        re = r'%'+URI + "|" + share + "|" + embed + '%ui'
        match = re.search(re, url)
        if match:
            src = match.group(0)
            # SEE: how to secure youtube videos, see: http://stackoverflow.com/questions/10324159/is-there-any-point-in-using-the-seamless-and-or-sandbox-attribute-for-youtube-if
            # SEE: youtube's docs on parameters: https://developers.google.com/youtube/player_parameters
            # How a youtube iframe video player is reconstructed on the client from the above:
            # src = "//www.youtube.com/embed/" + src + youTubeOptions
            # $noIframeMsg="Your browser isn't new enough to support embedded content. Please update.";
            # See more vars in Itree.php5
            # Values["label"]=Values["label"] + "<br/><iframe "+ iframeRequiredParams + " frameborder=\"0\" width=\"320\" height=\"240\" src=\"" + src + "\">" + noIframeMsg + "</iframe>"
            url="yt:" + src
        # vimeo
        else:
            # it's possible to do this in one regular expression without the '|', but less efficient
            embed = settings.VIDEOREGEX["vimeo"]["embed"]
            link = settings.VIDEOREGEX["vimeo"]["link"]
            re = r"%" + link + "| "+ embed + "%ui"
            match = re.search(re, url)
            if match:
                src = match.group(0)
                # how an vimeo iframe video player is reconstructed on the client from the above:
                # src="//player.vimeo.com/video/" + match + vimeoOptions
                # Values["label"] = Values["label"] + "<br/><iframe " + frameRequiredParams + " frameborder=\"0\" width=\"320\" height=\"240\" src=\"" + src + "\">" + noIframeMsg + "</iframe>"
                url="vm:" + src
                return(url)
            else:
                urlError = "Unrecognized url format.<br/>Try copying from the video site's 'Share->Embed' link."
    except:
        raise



def checkVideoIframeRequiredParams(field):
    try:
        if not settings.IFRAME_REQUIRED_PARAMS in field:
            return field.replace("<iframe","<iframe " + settings.IFRAME_REQUIRED_PARAMS)
    except:
        raise



# extension to storeNodeToDB():
        #if data.get("label"):
            # add sandbox attribute to iframe for security
            #data["label"] = checkVideoIframeRequiredParams(data["label"])
        #if data.get("url"):
            #data["url"] = checkVideoIframeRequiredParams(data["url"])
        # Node is always an update because we allocate Provisional Nodes ahead of time.



# extension to map():
         #video-regex = json.dumps(settings.VIDEOREGEX)
        #iframe-required-params = settings.IFRAME_REQUIRED_PARAMS
        #vimeo-options = settings.VIMEO_OPTIONS
        #no-iframe-message = 
        #youtube-options = 

