";
$data_uri_js="
var urltoreplace='', urlprefixtoreplace='', urlsuffixtoreplace='';
var typereplacement='application/octet-stream';
function readBlob(opt_startByte, opt_stopByte) {
var w='';
var files = document.getElementById('file').files;
//alert('files.length=' + files.length);
if (!files.length) {
return;
} else {
typereplacement='application/octet-stream';
w = files[0].name;
if (('' + files[0].type) != '') { typereplacement=files[0].type; }
//alert('w=' + w + ' and looking for ' + (urlprefixtoreplace + urltoreplace + urlsuffixtoreplace));
}
var file = files[0];
var start = parseInt(opt_startByte) || 0;
var stop = parseInt(opt_stopByte) || file.size - 1;
var reader = new FileReader();
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) {
//alert('start done');
if (document.getElementById('content-textarea-clone')) {
while (document.getElementById('content-textarea-clone').innerHTML.indexOf(urlprefixtoreplace + urltoreplace + urlsuffixtoreplace) != -1) {
//alert(urlprefixtoreplace + urltoreplace + urlsuffixtoreplace + ' with string of Length ' + (urlprefixtoreplace + evt.target.result + urlsuffixtoreplace).length);
document.getElementById('content-textarea-clone').innerHTML=document.getElementById('content-textarea-clone').innerHTML.replace(urlprefixtoreplace + urltoreplace + urlsuffixtoreplace, urlprefixtoreplace + evt.target.result.replace('application/octet-stream',typereplacement) + urlsuffixtoreplace);
}
}
//alert('middle done');
while (document.getElementById('content').value.indexOf(urlprefixtoreplace + urltoreplace + urlsuffixtoreplace) != -1) {
//alert(urlprefixtoreplace + urltoreplace + urlsuffixtoreplace + ' with String of length ' + (urlprefixtoreplace + evt.target.result + urlsuffixtoreplace).length);
document.getElementById('content').value=document.getElementById('content').value.replace(urlprefixtoreplace + urltoreplace + urlsuffixtoreplace, urlprefixtoreplace + evt.target.result.replace('application/octet-stream',typereplacement) + urlsuffixtoreplace);
}
document.getElementById('file').value='';
//alert('all done');
}
};
var blob = file.slice(start, stop + 1);
reader.readAsDataURL(blob);
}
function filechk() {
if (document.getElementById('file').value == '') {
setTimeout(filechk, 1000);
} else {
document.getElementById('button').click();
}
}
function perhapsreplace(rora_url) {
if (rora_url != '') {
if (rora_url.toLowerCase().indexOf('http') == 0 || rora_url.toLowerCase().indexOf('//') == 0 || rora_url.toLowerCase().indexOf('/') == 0 || rora_url.toLowerCase().indexOf('..') == 0 || rora_url.toLowerCase().indexOf('.') == 0 || (rora_url.substring(0,1) == String.fromCharCode(39) && rora_url.slice(-1) == String.fromCharCode(39)) || (rora_url.substring(0,1) == String.fromCharCode(34) && rora_url.slice(-1) == String.fromCharCode(34))) {
if (document.getElementById('content')) {
if (('' + document.getElementById('content').className).indexOf('wp-editor-area') != -1) {
if (document.getElementById('content').value.indexOf(rora_url) != -1) {
urltoreplace=rora_url;
urlprefixtoreplace='';
urlsuffixtoreplace='';
if (rora_url.substring(0,1) == String.fromCharCode(39) && rora_url.slice(-1) == String.fromCharCode(39)) { urlprefixtoreplace=String.fromCharCode(39), urlsuffixtoreplace=String.fromCharCode(39); urltoreplace=rora_url.substring(1,eval(-1 + rora_url.length)); }
if (rora_url.substring(0,1) == String.fromCharCode(34) && rora_url.slice(-1) == String.fromCharCode(34)) { urlprefixtoreplace=String.fromCharCode(34), urlsuffixtoreplace=String.fromCharCode(34); urltoreplace=rora_url.substring(1,eval(-1 + rora_url.length)); }
document.querySelector('.readBytesButtons').addEventListener('click', function(evt) {
if (evt.target.tagName.toLowerCase() == 'button') {
var startByte = evt.target.getAttribute('data-startbyte');
var endByte = evt.target.getAttribute('data-endbyte');
readBlob(startByte, endByte);
}
}, false);
setTimeout(filechk, 1000);
document.getElementById('file').click();
//alert('More to do allowing a data URI to replace ' + rora_url);
} else {
alert('Textarea content does not contain this ' + rora_url + ' string.');
}
} else {
alert('No textarea content with class wp-editor-area found.');
}
} else {
alert('No textarea content found.');
}
}
}
}
";
$data_uri_link_words = "Data URI Highlighted Text Replacer";
echo $data_uri_js . '' . $data_uri_link_words . '' . $data_uri_html;
}
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'rjmprogramming_Data_URI_Helper' );
// We need some CSS to position the hyperlink
function rjmprogramming_data_uri_helper_css() {
// This makes sure that the positioning is also good for right-to-left languages
$x = is_rtl() ? 'left' : 'right';
echo "
";
}
add_action( 'admin_footer', 'rjmprogramming_data_uri_helper_css' );
?>