All pastes #733326 Raw Edit

mkp

public text v1 · immutable
·published 2007-10-11 18:41 UTC
rendered paste body
<?PHP
header("Content-type:text/javascript");
require_once("../includes/comm.inc.php");
?>var MKPConfig = {
		CaseSensitive: "off",
		Charset: "UTF-8",
		CtrlURL: "<?=get_full_path()?>script/mkp_controller.php",
		divName: 'divMKPScript',
		MemoryCache: 'on',
		parseElements: []
};

var MKPTimer = null;
var MKPCache = [];
var MKPSubstitutionTable = new Array();
var MKPScript = null;
var MKPDiv = document.createElement('div');
MKPDiv.setAttribute('id', MKPConfig.divName);
MKPDiv.setAttribute('onmouseover', 'MKPclearTimer()');
MKPDiv.setAttribute('onmouseout', 'MKPsetTimer()');
MKPDiv.setAttribute('class', 'mkpScript');

if(document.implementation && document.implementation.createDocument) var MKPisMozilla=true;
else var MKPisMozilla=false;

// Short name of function
function $(divName) {
	return document.getElementById(divName);
}

function MKPhideMessage(){
	var MessageObj=$(MKPConfig.divName);
	MessageObj.style.visibility="hidden";
}

function MKPclearTimer() {
 if (MKPTimer) {
   clearTimeout(MKPTimer);
   MKPTimer = null;
 }
}

function MKPsetTimer() {
 	MKPTimer = window.setTimeout('MKPhideMessage()', 250);
}

window.MKPSize = function()
{
	var w = 0;
	var h = 0;
	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0)) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else {
			if(document.body.clientWidth) {
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			} else {
				w = window.document.body.offsetWidth;
				h = window.document.body.offsetHeight;
			}
		}
	}
	//w3c
	else {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

function MKPadjustMessage(evt) {
	var left;
	var top;
	MKPclearTimer();
	MessageObj = $(MKPConfig.divName);
	if (MKPisMozilla) event=evt;

	wsize = window.MKPSize();
	var rightedge = wsize.width-event.clientX;
	var bottomedge = wsize.height-event.clientY;

	// Compliance with HTML 4/XHTML
	if(document.documentElement && document.documentElement.scrollTop)
		scrollTop = document.documentElement.scrollTop;
	else
		scrollTop = document.body.scrollTop;

	// Compliance with HTML 4/XHTML
	if(document.documentElement && document.documentElement.scrollLeft)
		scrollLeft = document.documentElement.scrollLeft;
	else
		scrollLeft = document.body.scrollLeft;


	if (rightedge < MessageObj.offsetWidth)
		left = scrollLeft + event.clientX - MessageObj.offsetWidth;
	else
		left = scrollLeft + event.clientX;

	if (bottomedge < MessageObj.offsetHeight)
		top = scrollTop + event.clientY - MessageObj.offsetHeight;
	else
		top = scrollTop + event.clientY;

		MessageObj.style.top = (top)+"px";
		MessageObj.style.left = (left)+"px";
		MessageObj.innerHTML = '';
		MessageObj.style.visibility = "visible";
}
function MKPdeliveryMessage(respondStructure) {
	MessageObj.innerHTML = MKPdiv_content(respondStructure);
}

function MKPshowMessage(respondStructure) {
	MKPdeliveryMessage(respondStructure);
	if(MKPConfig.MemoryCache=="on") MKPCache[respondStructure.term] = respondStructure;
	return false;
}

var handleSuccess = function(respondStructure){
	if(respondStructure !== undefined){
		MKPshowMessage(respondStructure);
	}
};

function MKPgetDefinition(term,evt){
	MKPadjustMessage(evt);
	if(MKPCache[term]!=undefined) { return MKPdeliveryMessage(MKPCache[term]);  }
	MKPserverRequest(MKPConfig.CtrlURL, 'call=getDataAndFitlering&term='+encodeURIComponent(term)+'&charset='+MKPConfig.Charset+'&casesensitive='+MKPConfig.CaseSensitive+'&sourceurl='+document.URL+'&PubId='+MKPConfig.PubID, 'handleSuccess');
}

function MKPstripSlashes(content) {
	// Strip Slashes
	re = /\\\"/gi;
	content = content.replace(re, '"');
	re = /\\\'/gi;
	content = content.replace(re, "'");
	return content;
}

var MKPphandleSuccess = function(respondStructure){
	if(respondStructure !== undefined){
		MKPSubstitutionTable = respondStructure.termlist;
		if(MKPConfig.parseElements.length>0) {
			// Elements to parse are defined
			for(var Inx in MKPConfig.parseElements) {
				MKPparseChildNodes($(MKPConfig.parseElements[Inx]));
				re = /\{th\}(.*?)\{\/th\}/gi;
				text_str = $(MKPConfig.parseElements[Inx]).innerHTML + '';
				//$(MKPConfig.parseElements[Inx]).innerHTML = text_str.replace(re, "<a class=\"mkpUnderlined\" onclick=\"return MKPcalcClick('$1');\" onmouseover=\"MKPgetDefinition('$1', event); MKPcalcImpression('$1');\" onmouseout=\"MKPsetTimer();\">$1</a>");
			}
		} else {
			// Otherwise parse whole BODY content
			BodyObj = document.getElementsByTagName("BODY");
			MKPparseChildNodes(BodyObj[0]);
			re = /\{th\}(.*?)\{\/th\}/gi;
			text_str = BodyObj[0].innerHTML + '';
			//BodyObj[0].innerHTML = text_str.replace(re, "<a class=\"mkpUnderlined\"  onclick=\"return MKPcalcClick('$1');\" onmouseover=\"MKPgetDefinition('$1', event); MKPcalcImpression('$1');\" onmouseout=\"MKPsetTimer();\">$1</a>");
		}

	}
};


function MKPparseContent(){
	document.getElementsByTagName("body")[0].appendChild(MKPDiv);
	MKPserverRequest(MKPConfig.CtrlURL, 'PubWpID='+MKPConfig.PubWpID+'&charset='+MKPConfig.Charset+'&casesensitive='+MKPConfig.CaseSensitive+'&call=getDataAndParsing', 'MKPphandleSuccess');
}

function MKPcalcClick(term){
	if(MKPConfig.MemoryCache!="on") return true;
	MKPserverRequest(MKPConfig.CtrlURL, 'call=MKPcalcClick&casesensitive='+MKPConfig.CaseSensitive+'&term='+term+'&sourceurl='+document.URL+'&PubId='+MKPConfig.PubID, 'MKPphandleSuccess');
	return true;
}

function MKPcalcImpression(term){
	if(MKPCache[term]!=undefined) { return MKPdeliveryMessage(MKPCache[term]);  }
	if(MKPConfig.MemoryCache!="on") return true;
	return true;
}

function MKPparseText(obj) {
	var text_str = obj.nodeValue + '';
	if(text_str.length<2 || text_str=="null") return false;
	for(var i=0;i<MKPSubstitutionTable.length;i++) {
		re = new RegExp(MKPSubstitutionTable[i],(MKPConfig.CaseSensitive=="on"?"g":"gi"));
		if(re.test(text_str)) {
			//obj.nodeValue = MKPapplyTerm(MKPSubstitutionTable[i], text_str);
			MKPapplyTerm2(obj, MKPSubstitutionTable[i], text_str);
			text_str = ''+obj.nodeValue+'';
		}
	}
}

function MKPapplyTerm(term, text_str) {
	if(term+''==text_str+'') return "{th}"+text_str+"{/th}";
	re = new RegExp("^("+term+")([ \r\n\.!;,%\"'])",(MKPConfig.CaseSensitive=="on"?"g":"gi"));
	text_str = text_str.replace(re, "{th}$1{/th}$2");
	re = new RegExp("([ \r\n\.!;,%\"'])("+term+")$",(MKPConfig.CaseSensitive=="on"?"g":"gi"));
	text_str = text_str.replace(re, "$1{th}$2{/th}");
	re = new RegExp("([ \r\n\.!;,%\"'])("+term+")([ \r\n\.!;,%\"'])",(MKPConfig.CaseSensitive=="on"?"g":"gi"));
	text_str = text_str.replace(re, "$1{th}$2{/th}$3");
	return text_str;
}

function MKPapplyTermAddText(obj, term, prefix, suffix){
	if(term == '') return;
	var a = document.createElement('a');
	//a.setAttribute('class', '#');
	a.setAttribute('href', '#');
	//a.setAttribute('onclick', '#');
	//a.setAttribute('onmouseover', '#');
	//a.setAttribute('onmouseout', '#');
	a.innerHTML = term;
	obj.appendChild(a);
}

function MKPapplyTerm2(obj, term, text_str){
	if(term+''==text_str+'') return "{th}"+text_str+"{/th}";
	re = new RegExp("^("+term+")([ \r\n\.!;,%\"'])",(MKPConfig.CaseSensitive=="on"?"g":"gi"));
	//obj.nodeValue = obj.nodeValue.replace(re, "{th}$1{/th}$2");
	MKPapplyTermAddText(obj, term, '', '');

	re = new RegExp("([ \r\n\.!;,%\"'])("+term+")$",(MKPConfig.CaseSensitive=="on"?"g":"gi"));
	obj.nodeValue = obj.nodeValue.replace(re, "$1{th}$2{/th}");
	re = new RegExp("([ \r\n\.!;,%\"'])("+term+")([ \r\n\.!;,%\"'])",(MKPConfig.CaseSensitive=="on"?"g":"gi"));
	obj.nodeValue = obj.nodeValue.replace(re, "$1{th}$2{/th}$3");
}

function MKPparseChildNodes(obj) {
	for (var i=0; i<obj.childNodes.length; i++) {
		if(	obj.childNodes[i].childNodes.length>0 &&
			obj.childNodes[i].nodeName!="IFRAME" &&
			obj.childNodes[i].nodeName!="SCRIPT" &&
			obj.childNodes[i].nodeName!="A" &&
			obj.childNodes[i].nodeName!="H1" &&
			obj.childNodes[i].nodeName!="H2" &&
			obj.childNodes[i].nodeName!="H3")
				MKPparseChildNodes(obj.childNodes[i]);
		else MKPparseText(obj.childNodes[i]);
	}
}

function MKPserverRequest(url, data, callback) {
	var fUrl = url+'?'+data+'&callback='+callback;
	MKPScript = document.createElement('script');
	MKPScript.setAttribute('type', 'text/javascript');
	MKPScript.setAttribute('src', fUrl);
	MKPScript.setAttribute('id', 'scrMKPScript');
	document.getElementsByTagName("head")[0].appendChild(MKPScript);
}

function MKPexec_clicks(url, ad_kwo_id){
	window.open(url);
	MKPserverRequest(MKPConfig.CtrlURL, 'call=MKPcalcClick&ad_kwo_id='+encodeURIComponent(ad_kwo_id)+'&sourceurl='+document.URL+'&PubId='+MKPConfig.PubID, 'handleSuccess');
}

function MKPdiv_content(respondStructure){
	text='';
	if(respondStructure.ad_Type==1)//text only
		text = '<div id="mkpIm" class="mkpTxtIm"><div id="mkpBtn"><a href="javascript:;" onclick="javascript:MKPhideMessage()" id="mkpBtnClose">&nbsp;</a><a href="<?=get_full_path()?>" id="mkpBtnHelp" target="_blank">&nbsp;</a></div><div id="mkpTxtBox"><h1>'+respondStructure.ad_Title+'</h1>'+respondStructure.ad_Text+'</div><div id="mkpBtn"><a href="javascript:void(0);" onclick="javascript:MKPexec_clicks(\''+respondStructure.ad_Link+'\', '+respondStructure.ad_kwo_id+')" id="mkpBtnMerLink">'+respondStructure.ad_VisibleUrl+'</a><a href="javascript:void(0);" onclick="javascript:MKPexec_clicks(\''+respondStructure.ad_Link+'\', '+respondStructure.ad_kwo_id+')" id="mkpBtnRMLink">'+respondStructure.ad_butt_text+'</a></div></div>';


	if(respondStructure.ad_Type==2)//image + text
		text = '<div id="mkpIm" class="mkpImgIm"><div id="mkpBtn"><a href="javascript:;" onclick="javascript:MKPhideMessage()" id="mkpBtnClose">&nbsp;</a><a href="<?=get_full_path()?>" id="mkpBtnHelp" target="_blank">&nbsp;</a></div><div id="mkpImgBox"><h1>'+respondStructure.ad_Title+'</h1><div><img src="'+respondStructure.ad_Image+'" alt="" /></div>'+respondStructure.ad_Text+'</div><div id="mkpBtn"><a href="javascript:void(0);" onclick="javascript:MKPexec_clicks(\''+respondStructure.ad_Link+'\', '+respondStructure.ad_kwo_id+')" id="mkpBtnMerLink">'+respondStructure.ad_VisibleUrl+'</a><a href="javascript:void(0);" onclick="javascript:MKPexec_clicks(\''+respondStructure.ad_Link+'\', '+respondStructure.ad_kwo_id+')" id="mkpBtnRMLink">'+respondStructure.ad_butt_text+'</a></div></div>';

	return text;
}