I found a workaround involving the use of javascript that is executed when a post is submitted (either new or edited). I added this code to this function (part of an external js file that is called when the ckeditor is in use):
Code:
var el = document.getElementsByClassName('cke_source')[0];
if (!el)
{
var iFrame = document.getElementsByTagName('iframe')[iFrameIndex()];
var iFrameBody;
if (iFrame.contentDocument)
{ // FF
iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
}
else if (iFrame.contentWindow)
{ // IE
iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
}
var postContent = iFrameBody.innerHTML;
var n = 1, quit = false;
while (!quit)
{
var imgLoc = nth_occurrence(postContent, "<img src=\"http://mathhelpboards.com/attachment", n);
if (imgLoc == -1)
{
imgLoc = nth_occurrence(postContent, "<img alt=\"\" src=\"http://mathhelpboards.com/attachment", n);
}
if (imgLoc > -1)
{
var imgLocEnd = postContent.substr(imgLoc).indexOf(">") + 1;
var imgStr = postContent.substr(imgLoc, imgLocEnd);
if (nth_occurrence(imgStr, "/", 5) > -1)
{
var attachNumberBegin = nth_occurrence(imgStr, "/", 5) + 1;
var attachNumberEnd = imgStr.substr(attachNumberBegin).indexOf("-");
}
else if(imgStr.indexOf("attachment.php?attachmentid=") > -1)
{
var attachNumberBegin = imgStr.indexOf("attachment.php?attachmentid=") + 28;
var attachNumberEnd = imgStr.substr(attachNumberBegin).indexOf("&");
}
var attachNumber = imgStr.substr(attachNumberBegin, attachNumberEnd);
var newImgStr = "[ATTACH=CONFIG]" + attachNumber + "[/ATTACH]";
postContent = postContent.split(imgStr).join(newImgStr);
iFrameBody.innerHTML = postContent;
}
else
{
quit = true;
}
}
}
Replace the URLs in the code above (in red) with your own. You will also need this function (it is part of an external js file I call from the "head_include_bottom" template because I use it in several places):
Code:
function nth_occurrence(string, char, nth)
{
var first_index = string.indexOf(char);
var length_up_to_first_index = first_index + 1;
if (nth == 0)
{
return 0;
}
else if (nth == 1)
{
return first_index;
}
else
{
var string_after_first_occurrence = string.slice(length_up_to_first_index);
var next_occurrence = nth_occurrence(string_after_first_occurrence, char, nth - 1);
if (next_occurrence === -1)
{
return -1;
}
else
{
return length_up_to_first_index + next_occurrence;
}
}
}
edit: I realized after I signed off last night that you will also need the following function:
Code:
function iFrameIndex()
{
return document.getElementsByTagName('iframe').length - 1;
}
This function ensures you are referencing the last iframe element added to the page, which works on my board. It may not work for you if you have an iframe in your footer.