<?php
    
class attr_full_url extends attr {


    function render_text( $crop = false ) {
 	    	return $this->getCurVal();
    }
   
    function lPost() {
	    $url = preg_replace('/[^A-Za-z0-9_\-\/\.]/','', $_POST[$this->attr_name]);
        
        if (!$this->getCurVal()) {
            $url = strtolower($url);   
        }
        
    	$this->obj->set($this->attr_name,$url);
    }  
    
   
   
   function render_input() {
        $templ  = $this->getAttrTempl();
        list($prefix, $cat_id ) = explode('|', $templ);
        if ( $this->getCurVal() && $this->obj->id ) {
        	return '<div class="form-control"><input id="' . $this->attr_name . '" type="hidden"  name="' . $this->attr_name . '" value="' .$this->getCurVal() . '">
                             
                                <a target="_blank" class="py-2" href="'._SHOP_ROOT_.$this->getCurVal().'"><i class="far fa-external-link"></i></a> '.$this->getCurVal().'</div>
                    ';
        } else {
	    	$str = '<input id="' . $this->attr_name . '" type="text" class="form-control" name="' . $this->attr_name . '" value="' .$this->getCurVal() . '"  required="required">'."
                
<script>
 $(document).ready( function() {
    $('#title').keyup( function() {
        if ( $('#url').attr('type') == 'hidden' ) return true;";
        if ($prefix) {
            $str .= "$('#url').val( '".$prefix."/' + translateStr( $('#title').val() )  + '-' + Math.floor((Math.random()*10000)+1) + '.htm');";
        } else {
            $str .= "$('#url').val( translateStr( $('#title').val() )  + '-' + Math.floor((Math.random()*10000)+1) + '.htm' );";
        }
        $str.="
        return true;
    });
 });
</script>";    	
        return $str;
        }
    }
    

}

?>