<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*!
 * Securimage CAPTCHA Audio Library
 * https://www.phpcaptcha.org/
 * 
 * Copyright 2015 phpcaptcha.org
 * Released under the BSD-3 license
 * See https://github.com/dapphp/securimage/blob/master/README.md
 */

var SecurimageAudio = function(options) {
    this.html5Support    = true;
    this.flashFallback   = false;
    this.captchaId       = null;
    this.playing         = false;
    this.reload          = false;
    this.audioElement    = null;
    this.controlsElement = null;
    this.playButton      = null;
    this.playButtonImage = null;
    this.loadingImage    = null;
    
    if (options.audioElement) {
        this.audioElement = document.getElementById(options.audioElement);
    }
    if (options.controlsElement) {
        this.controlsElement = document.getElementById(options.controlsElement);
    }

    this.init();
}

SecurimageAudio.prototype.init = function() {
    var ua    = navigator.userAgent.toLowerCase();
    var ieVer = (ua.indexOf('msie') != -1) ? parseInt(ua.split('msie')[1]) : false;
    // ie 11+ detection
    if (!ieVer &amp;&amp; null != (ieVer = ua.match(/trident\/.*rv:(\d+\.\d+)/)))
        ieVer = parseInt(ieVer[1]);

    var objAu = this.audioElement.getElementsByTagName('object');
    if (objAu.length &gt; 0) {
        objAu = objAu[0];
    } else {
        objAu = null;
    }

    if (ieVer) {
        if (ieVer &lt; 9) {
            // no html5 audio support, hide player controls
            this.controlsElement.style.display = 'none';
            this.html5Support = false;
            return ;
        } else if ('' == this.audioElement.canPlayType('audio/wav')) {
            // check for mpeg &lt;source&gt; tag - if not found then fallback to flash
            var sources    = this.audioElement.getElementsByTagName('source');
            var mp3support = false;
            var type;
            
            if (objAu) {
                this.flashFallback = true;
            }

            for (var i = 0; i &lt; sources.length; ++i) {
                type = sources[i].attributes["type"].value;
                if (type.toLowerCase().indexOf('mpeg') &gt;= 0 || type.toLowerCase().indexOf('mp3') &gt;= 0) {
                    mp3support = true;
                    break;
                }
            }

            if (false == mp3support) {
                // browser supports &lt;audio&gt; but does not support WAV audio and no flash audio available
                this.html5Support = false;
                
                if (this.flashFallback) {
                    // ie9+? bug - flash object does not display when moved from within audio tag to other dom node
                    var newObjAu = document.createElement('object');
                    var newParams = document.createElement('param');
                    var oldParams = objAu.getElementsByTagName('param');
                    this.copyElementAttributes(newObjAu, objAu);
                    if (oldParams.length &gt; 0) {
                        this.copyElementAttributes(newParams, oldParams[0]);
                        newObjAu.appendChild(newParams);
                    }
                    objAu.parentNode.removeChild(objAu);
                    this.audioElement.parentNode.appendChild(newObjAu);
                }

                this.audioElement.parentNode.removeChild(this.audioElement);
                this.controlsElement.parentNode.removeChild(this.controlsElement);
                
                return ;
            }
        }
    }

    this.audioElement.addEventListener('playing', this.updateControls.bind(this), false);
    this.audioElement.addEventListener('ended',   this.audioStopped.bind(this), false);

    // find the element used as the play button and register click event to play/stop audio
    var children = this.controlsElement.getElementsByTagName('*');
    for (var i = 0; i &lt; children.length; ++i) {
        var el = children[i];
        if (undefined != el.className) {
            if (el.className.indexOf('play_button') &gt;= 0) {
                this.playButton = el;
                el.addEventListener('click', this.play.bind(this), false);
            } else if (el.className.indexOf('play_image') &gt;= 0) {
                this.playButtonImage = el;
            } else if (el.className.indexOf('loading_image') &gt;= 0) {
                this.loadingImage = el;
            }
        }
    }

    if (objAu) {
        // remove flash object from DOM
        objAu.parentNode.removeChild(objAu);
    }
}

SecurimageAudio.prototype.play = function(evt) {
    if (null != this.playButton) {
        this.playButton.blur();
    }

    if (this.reload) {
        this.replaceElements();
        this.reload = false;
    }

    try {
        if (!this.playing) {
            if (this.playButtonImage != null) {
                this.playButtonImage.style.display = 'none';
            }
            if (this.loadingImage != null) {
                this.loadingImage.style.display = '';
            }
            //TODO: FIX, most likely browser doesn't support audio type
            this.audioElement.onerror = this.audioError;
            try {
                this.audioElement.play();
            } catch(ex) {
                alert('Audio error: ' + ex);
            }
        } else {
            this.audioElement.pause();
            if (this.loadingImage != null) {
                this.loadingImage.style.display = 'none';
            }
            if (this.playButtonImage != null) {
                this.playButtonImage.style.display = '';
            }
            this.playing = false;
        }
    } catch (ex) {
        alert('Audio error: ' + ex);
    }
    
    if (undefined !== evt) {
        evt.preventDefault();
    }
    return false;
}

SecurimageAudio.prototype.refresh = function(captchaId) {
    if (!this.html5Support) {
        return;
    }

    if (undefined !== captchaId) {
        this.captchaId = captchaId;
    }    

    this.playing = true;
    this.reload  = false;
    this.play(); // stops audio if playing
    this.reload  = true;
    
    return false;
}

SecurimageAudio.prototype.copyElementAttributes = function(newEl, el) {
    for (var i = 0, atts = el.attributes, n = atts.length; i &lt; n; ++i) {
        newEl.setAttribute(atts[i].nodeName, atts[i].value);
    }
    
    return newEl;
}

SecurimageAudio.prototype.replaceElements = function() {
    var parent = this.audioElement.parentNode;
    parent.removeChild(this.audioElement);
    
    var newAudioEl = document.createElement('audio');
    newAudioEl.setAttribute('style', 'display: none;');
    newAudioEl.setAttribute('preload', 'false');

    for (var c = 0; c &lt; this.audioElement.children.length; ++c) {
        if (this.audioElement.children[c].tagName.toLowerCase() != 'source') continue;
        var sourceEl = document.createElement('source');
        this.copyElementAttributes(sourceEl, this.audioElement.children[c]);
        var cid = (null !== this.captchaId) ? this.captchaId : (Math.random() + '').replace('0.', '');
        sourceEl.src = sourceEl.src.replace(/id=[a-zA-Z0-9]+/, 'id=' + cid);
        newAudioEl.appendChild(sourceEl);
    }

    this.audioElement = null;
    this.audioElement = newAudioEl;
    parent.appendChild(this.audioElement);

    this.audioElement.addEventListener('playing', this.updateControls.bind(this), false);
    this.audioElement.addEventListener('ended',   this.audioStopped.bind(this), false);
}

SecurimageAudio.prototype.updateControls = function() {
    this.playing = true;
    if (this.loadingImage != null) {
        this.loadingImage.style.display = 'none';
    }
    if (this.playButtonImage != null) {
        this.playButtonImage.style.display = '';
    }
}

SecurimageAudio.prototype.audioStopped = function() {
    this.playing = false;
}

SecurimageAudio.prototype.audioError = function(err) {
    var msg = null;
    switch(err.target.error.code) {
        case err.target.error.MEDIA_ERR_ABORTED:
            break;
        case err.target.error.MEDIA_ERR_NETWORK:
            msg = 'A network error caused the audio download to fail.';
            break;
        case err.target.error.MEDIA_ERR_DECODE:
            alert('An error occurred while decoding the audio');
            break;
        case err.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
            alert('The audio format is not supported by your browser.');
            break;
        default:
            alert('An unknown error occurred trying to play the audio.');
            break;
    }
    if (msg) {
        alert('Audio playback error: ' + msg);
    }
}

/** Wordpress plugin specific code below */

function siwp_refresh(id, audioObj) {
    var cid = siwp_genid();

    document.getElementById('input_siwp_captcha_id_' + id).value = cid;
    document.getElementById('siwp_captcha_image_' + id).src = document.getElementById('siwp_captcha_image_' + id).src.replace(/\bid=[a-zA-Z0-9]{40}/, 'id=' + cid);

    if (null !== audioObj) {
        audioObj.refresh(cid);
    }
    
    // flash fallback refresh swf code
    var obj = document.getElementById('siwp_obj_' + id);
    if (null !== obj) {
        obj.setAttribute('data', obj.getAttribute('data').replace(/[a-zA-Z0-9]{40}$/, cid));
        var par = document.getElementById('siwp_param');
        par.value = par.value.replace(/[a-zA-Z0-9]{40}$/, cid);

        /* replace old flash w/ new one using new id */
        var newObj = obj.cloneNode(true);
        obj.parentNode.insertBefore(newObj, obj);
        obj.parentNode.removeChild(obj);
    }
    
    if (window.siwp_interval) {
        clearInterval(window.siwp_interval);
        siwpStartInterval();
    }
}
function siwp_genid() {
    var cid = '', chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
    for (var c = 0; c &lt; 40; ++c) { cid += chars.charAt(Math.floor(Math.random() * chars.length)); }
    return cid;
}

function siwpStartInterval() {
    window.siwp_interval = setInterval(siwpRefreshInterval, 900000); // 15 minutes (900s)
}

function siwpRefreshInterval() {
    var elems = document.querySelectorAll('.siwp_img');

    if (elems) {
        for (var i = 0; i &lt; elems.length; ++i) {
            siwp_refresh(i, window['siwp_captcha_image_' + i + '_audioObj']);
        }
    }
}

function registerAudioObjects() {
    //$audio_obj = new SecurimageAudio({ audioElement: '{$imgTagId}_audio', controlsElement: '{$imgTagId}_audio_controls' });

    var len = 0;
    var elems = document.querySelectorAll('.siwp_audio');
    len = elems.length;

    if (len) {
        for (var i = 0; i &lt; len; ++i) {
            var varname = 'siwp_captcha_image_' + i + '_audioObj';

            window[varname] = new SecurimageAudio({
               audioElement: 'siwp_captcha_image_' + i + '_audio',
               controlsElement: 'siwp_captcha_image_' + i + '_audio_controls'
            });
        }
    }

    siwpStartInterval();
}

if (window.addEventListener) {
    window.addEventListener('load', registerAudioObjects, false);
} else {
    window.attachEvent('onload', registerAudioObjects);
}
</pre></body></html>