CKEDITOR.plugins.add("ipsautolink",{init:function(a){var e=this;a.on("key",function(c){if(32==c.data.keyCode||37==c.data.keyCode||38==c.data.keyCode||39==c.data.keyCode||40==c.data.keyCode||13==c.data.keyCode){var d=a.getSelection().getRanges()[0].getCommonAncestor().getParent().$;"A"!=d.tagName&&("PRE"!=d.tagName&&!d.getAttribute("ipsnoautolink"))&&(37==c.data.keyCode||38==c.data.keyCode?e.replaceLinks(a,d):setTimeout(function(){e.replaceLinks(a,d)},5))}});CKEDITOR.instances[a.name].on("contentDom",
function(){this.document.on("click",function(){e.replaceLinks(a,a.document.$)})})},autolinkExp:"(?<!\\[img\\]|\\[img='|\\[img=\"|\\[img=|\\[code\\].+?|\\[url='|\\[url=\"|\\[url=|\\u2063)((?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))*)(?::\\d{2,5})?(?:\\/\\S*)?)",
replaceLinks:function(a,e,c){for(var d=e.childNodes,g=0,h=d.length;g<h;g++){var b=d[g];if(b.nodeType==b.TEXT_NODE){if(b.previousSibling&&b.previousSibling.nodeType==b.TEXT_NODE&&("[url="==b.previousSibling.textContent.substr(-5)||"[img]"==b.previousSibling.textContent.substr(-5)||"[code]"==b.previousSibling.textContent.substr(-6)))b.textContent="⁣"+b.textContent;var f=!1;if(XRegExp.execLb(b.textContent,this.autolinkExp,"i"))f=!0;else for(key in a.config.ipsEmoticons){var j=RegExp("(?:\\s|^)("+key.replace(/([.?*+^$[\]\\(){}|-])/g,
"\\$1")+")(?:\\s|$)","i");if(b.textContent.match(j)){f=!0;break}}if(f){var j=null,i=a.getSelection().getRanges();if(i[0].startOffset==i[0].endOffset){var l=i[0].startContainer.getText(),m=l.slice(0,i[0].startOffset+1).search(/\S+$/),n=l.slice(i[0].startOffset).search(/\s/),i=0>n?l.slice(m):l.slice(m,n+i[0].startOffset);XRegExp.execLb(i,this.autolinkExp,"i")||(j=new CKEDITOR.dom.element.createFromHtml("<span>&#8203;</span>"),a.insertElement(j))}this.replaceLinksInNode(b,a);b.nextSibling&&(b.nextSibling.nextSibling&&
b.nextSibling.nextSibling.nextSibling)&&this.replaceLinksInNode(b.nextSibling.nextSibling.nextSibling,a);j&&j.remove()}}else b.nodeType==b.ELEMENT_NODE&&"A"!=b.tagName&&("PRE"!=b.tagName&&!b.getAttribute("ipsnoautolink"))&&this.replaceLinks(a,b,c)}if("P"==e.tagName||"DIV"==e.tagName){var k=/(^\s{0,}|^.*<br(?: \/)?>\s{0,})<a href="(.*)"(?:[^>]+?)?>(\2)<\/a>(\s{0,}<br(?: \/)?>|$)/i;if(!e.getAttribute("ipsNoEmbed")&&("P"==e.tagName&&e.innerHTML.match(k)||"DIV"==e.tagName&&e.innerHTML.match(k))){var f=
e.innerHTML.match(k),o=e.innerHTML;e.innerHTML=e.innerHTML.replace(k,f[1]+('<a data-cke-saved-href="'+f[2]+'" href="'+f[2]+'" ipsNoEmbed="true">'+f[2]+"</a>"+(f[4]?f[4]:"")));ips.getAjax()(ips.getSetting("baseURL")+"index.php?app=core&module=system&controller=editor&do=validateLink&url="+encodeURIComponent(f[2].replace(/&amp;/g,"&")),{async:void 0==c?!0:c}).done(function(a){if(a.embed){$(e).replaceWith($(o.replace(k,f[1]+a.preview)));for(var a=e.childNodes,b=0,c=a.length;b<c;b++)if(a[b].nodeType==
a[b].ELEMENT_NODE&&"IFRAME"==a[b].tagName){var d=a[b];void 0===$(d).data("embedcontent")&&setTimeout(function(){d.style.height=d.contentWindow.document.body.scrollHeight+"px";d.style.width=d.contentWindow.document.body.scrollWidth+"px";d.style.overflow="hidden";d.scrolling="no";d.seamless="seamless"},1500)}}})}}},replaceLinksInNode:function(a,e){for(var c=XRegExp.execLb(a.textContent,this.autolinkExp,"i");c;){var d=a.textContent.indexOf(c[0]),g=a.textContent.substring(0,d),g=document.createTextNode(g);
if(ips.utils.validate.isAllowedUrl(c[0])){var h=document.createElement("a");h.href=c[0];h.appendChild(document.createTextNode(decodeURI(c[0])))}else h=document.createTextNode(c[0]);a.textContent=a.textContent.substring(d+c[0].length);a.parentNode.insertBefore(g,a);a.parentNode.insertBefore(h,a);c=XRegExp.execLb(a.textContent,this.autolinkExp,"i")}for(key in e.config.ipsEmoticons){c=RegExp("(?:\\s|^)("+key.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")+")(?:\\s|$)","i");for(h=a.textContent.match(c);h;){var d=
a.textContent.indexOf(h[1]),g=a.textContent.substring(0,d),g=document.createTextNode(g),b=document.createElement("img");b.src=e.config.ipsEmoticons[key];b.alt=key;b.title=key;a.textContent=a.textContent.substring(d+h[1].length);a.parentNode.insertBefore(g,a);a.parentNode.insertBefore(b,a);h=a.textContent.match(c)}}}});