Subversion Repositories Sites.tela-botanica.org

Rev

Rev 609 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 florian 1
<?php
2
	ob_start("ob_gzhandler");
3
	require_once(realpath(dirname(__FILE__) . '/') . '/secret/wp-hashcash.lib');
4
 
5
	$field_id = hashcash_random_string(rand(6,18));
6
	$fn_enable_name = hashcash_random_string(rand(6,18));
7
?>
8
 
9
addLoadEvent(<?php echo $fn_enable_name; ?>);
10
 
11
function createHiddenField(){
12
	var inp = document.createElement('input');
13
	inp.setAttribute('type', 'hidden');
14
	inp.setAttribute('id', '<?php echo $field_id; ?>');
15
	inp.setAttribute('name', 'hashcash_value');
16
	inp.setAttribute('value', '-1');
17
 
18
	var e = document.getElementById('<?php echo HASHCASH_FORM_ID; ?>');
19
    e.appendChild(inp);
20
}
21
 
22
function addVerbage(){
23
	var e = getElementsByClass('<?php echo HASHCASH_FORM_CLASS; ?>');
24
	var p = document.createElement('p');
25
	p.innerHTML = '<?php echo str_replace("'", "\'", hashcash_verbage()); ?>';
26
	e[0].appendChild(p);
27
}
28
 
29
function <?php echo $fn_enable_name;?>(){
30
	createHiddenField();
31
	addVerbage();
32
	loadHashCashKey('<?php
33
	echo $_GET['siteurl']; ?>/tools/hashcash/wp-hashcash-getkey.php', '<?php echo $field_id; ?>');
34
}
35
 
36
function loadHashCashKey(fragment_url, e_id) {
37
	var xmlhttp=createXMLHttp();
38
	var element = document.getElementById(e_id);
39
 
40
	xmlhttp.open("GET", fragment_url, true);
41
	xmlhttp.onreadystatechange = function() {
42
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
43
			element.value = eval(xmlhttp.responseText);
44
		}
45
	}
46
 
47
	xmlhttp.send(null);
48
}
49
 
50
function getElementsByClass(searchClass,node,tag) {
51
	var classElements = new Array();
52
	if ( node == null )
53
		node = document;
54
	if ( tag == null )
55
		tag = '*';
56
	var els = node.getElementsByTagName(tag);
57
	var elsLen = els.length;
58
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
59
	for (i = 0, j = 0; i < elsLen; i++) {
60
		if ( pattern.test(els[i].className) ) {
61
			classElements[j] = els[i];
62
			j++;
63
		}
64
	}
65
	return classElements;
66
}
67
 
68
function createXMLHttp() {
69
	if (typeof XMLHttpRequest != "undefined")
70
		return new XMLHttpRequest();
71
 
72
	var xhrVersion = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
73
 
74
	for (var i = 0; i < xhrVersion.length; i++) {
75
  	try {
76
			var xhrObj = new ActiveXObject(xhrVersion[i]);
77
      return xhrObj;
78
    } catch (e) { }
79
  }
80
 
81
  return null;
82
}
83
 
84
function addLoadEvent(func) {
85
  var oldonload = window.onload;
86
  if (typeof window.onload != 'function') {
87
    window.onload = func;
88
  } else {
89
    window.onload = function() {
90
		func();
91
		oldonload();
92
    }
93
  }
94
}