Use iframe for crossite loading instead of CORS header
This commit is contained in:
parent
255685c176
commit
a3eb7268ae
|
@ -11,6 +11,11 @@ function friends_widget_args(){
|
||||||
return Array();
|
return Array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function friends_widget_size(){
|
||||||
|
return Array('100%','200px');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function friends_widget_content(&$a, $conf){
|
function friends_widget_content(&$a, $conf){
|
||||||
|
|
||||||
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
|
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
|
||||||
|
@ -23,12 +28,12 @@ function friends_widget_content(&$a, $conf){
|
||||||
|
|
||||||
$o = "";
|
$o = "";
|
||||||
$o .= "<style>
|
$o .= "<style>
|
||||||
.f9k_widget {font-size: 0.8em;}
|
body {font-size: 0.8em; margin: 0px; padding: 0px;}
|
||||||
.f9k_widget #contact-block { overflow: hidden; height: auto; }
|
#contact-block { overflow: hidden; height: auto; }
|
||||||
.f9k_widget .contact-block-h4 { float: left; margin: 0px; }
|
.contact-block-h4 { float: left; margin: 0px; }
|
||||||
.f9k_widget .allcontact-link { float: right; margin: 0px; }
|
.allcontact-link { float: right; margin: 0px; }
|
||||||
.f9k_widget .contact-block-content { clear:both; }
|
.contact-block-content { clear:both; }
|
||||||
.f9k_widget .contact-block-div { display: block !important; float: left!important; width: 50px!important; height: 50px!important; margin: 2px!important;}
|
.contact-block-div { display: block !important; float: left!important; width: 50px!important; height: 50px!important; margin: 2px!important;}
|
||||||
|
|
||||||
</style>";
|
</style>";
|
||||||
$o .= _abs_url(contact_block());
|
$o .= _abs_url(contact_block());
|
||||||
|
|
|
@ -11,6 +11,11 @@ function like_widget_args(){
|
||||||
return Array("KEY");
|
return Array("KEY");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function like_widget_size(){
|
||||||
|
return Array('60px','20px');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function like_widget_content(&$a, $conf){
|
function like_widget_content(&$a, $conf){
|
||||||
$args = explode(",",$_GET['a']);
|
$args = explode(",",$_GET['a']);
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
<style>body {font-size: 0.8em; margin: 0px; padding: 0px;}</style>
|
||||||
<span class='f9k_like' title="$strlike">$like <img src="$baseurl/images/like.gif" alt="like"/></span>
|
<span class='f9k_like' title="$strlike">$like <img src="$baseurl/images/like.gif" alt="like"/></span>
|
||||||
<span class='f9k_dislike' title="$strdislike">$dislike <img src="$baseurl/images/dislike.gif" alt="dislike"/></span>
|
<span class='f9k_dislike' title="$strdislike">$dislike <img src="$baseurl/images/dislike.gif" alt="dislike"/></span>
|
||||||
|
|
|
@ -1,26 +1,16 @@
|
||||||
/**
|
/**
|
||||||
* @author Fabio Comuni
|
* @author Fabio Comuni
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var f9a_widget_$widget_id = {
|
var f9a_widget_$widget_id = {
|
||||||
|
width: "$width",
|
||||||
|
height: "$height",
|
||||||
entrypoint : "$entrypoint",
|
entrypoint : "$entrypoint",
|
||||||
key : "$key",
|
key : "$key",
|
||||||
widgetid: "$widget_id",
|
widgetid: "$widget_id",
|
||||||
argstr: "$args",
|
argstr: "$args",
|
||||||
xmlhttp : null,
|
|
||||||
|
|
||||||
getXHRObj : function(){
|
load : function() {
|
||||||
if (window.XMLHttpRequest) {
|
var args = new Array();
|
||||||
// code for IE7+, Firefox, Chrome, Opera, Safari
|
|
||||||
this.xmlhttp = new XMLHttpRequest();
|
|
||||||
} else {
|
|
||||||
// code for IE6, IE5
|
|
||||||
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
dorequest : function(args, cb) {
|
|
||||||
if (args===null) args = new Array();
|
|
||||||
args['k']=this.key;
|
args['k']=this.key;
|
||||||
args['s']=window.location.href;
|
args['s']=window.location.href;
|
||||||
args['a']=this.argstr;
|
args['a']=this.argstr;
|
||||||
|
@ -31,36 +21,17 @@ var f9a_widget_$widget_id = {
|
||||||
}
|
}
|
||||||
var url = this.entrypoint + "?"+ urlencodedargs.join("&");
|
var url = this.entrypoint + "?"+ urlencodedargs.join("&");
|
||||||
|
|
||||||
this.xmlhttp.open("GET", url ,true);
|
console.log(this.widgetid);
|
||||||
this.xmlhttp.send();
|
console.log(document.getElementById(this.widgetid));
|
||||||
this.xmlhttp.obj = this;
|
document.getElementById(this.widgetid).innerHTML = '<iframe style="border:0px; width: '+this.width+'; height:'+this.height+'" src="'+url+'"></iframe>';
|
||||||
this.xmlhttp.onreadystatechange=function(){
|
|
||||||
if (this.readyState==4){
|
|
||||||
if (this.status==200) {
|
|
||||||
cb(this.obj, this.responseText);
|
|
||||||
} else {
|
|
||||||
document.getElementById(this.obj.widgetid).innerHTML="Error loading widget.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
requestcb: function(obj, responseText) {
|
|
||||||
document.getElementById(obj.widgetid).innerHTML=responseText;
|
|
||||||
},
|
|
||||||
|
|
||||||
load : function (){
|
|
||||||
this.getXHRObj();
|
|
||||||
this.dorequest(null, this.requestcb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
document.writeln("<div id='$widget_id' class='f9k_widget $type'>");
|
||||||
|
document.writeln("<img id='$widget_id_ld' src='$loader'>");
|
||||||
|
document.writeln("</div>");
|
||||||
(function() {
|
(function() {
|
||||||
f9a_widget_$widget_id.load();
|
f9a_widget_$widget_id.load();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
document.writeln("<div id='$widget_id' class='f9k_widget'>");
|
|
||||||
document.writeln("<img id='$widget_id_ld' src='$loader'>");
|
|
||||||
document.writeln("</div>");
|
|
||||||
|
|
|
@ -72,6 +72,10 @@ function _abs_url($s){
|
||||||
return preg_replace("|href=(['\"])([^h][^t][^t][^p])|", "href=\$1".$a->get_baseurl()."/\$2", $s);
|
return preg_replace("|href=(['\"])([^h][^t][^t][^p])|", "href=\$1".$a->get_baseurl()."/\$2", $s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _randomAlphaNum($length){
|
||||||
|
return substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',$length)),0,$length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function widgets_content(&$a) {
|
function widgets_content(&$a) {
|
||||||
|
|
||||||
|
@ -106,7 +110,7 @@ function widgets_content(&$a) {
|
||||||
|
|
||||||
//echo "<pre>"; var_dump($a->argv); die();
|
//echo "<pre>"; var_dump($a->argv); die();
|
||||||
if ($a->argv[2]=="cb"){
|
if ($a->argv[2]=="cb"){
|
||||||
header('Access-Control-Allow-Origin: *');
|
/*header('Access-Control-Allow-Origin: *');*/
|
||||||
$o .= call_user_func($a->argv[1].'_widget_content',$a, $conf);
|
$o .= call_user_func($a->argv[1].'_widget_content',$a, $conf);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,14 +131,18 @@ function widgets_content(&$a) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$widget_size = call_user_func($a->argv[1].'_widget_size');
|
||||||
|
|
||||||
$script = file_get_contents(dirname(__file__)."/widgets.js");
|
$script = file_get_contents(dirname(__file__)."/widgets.js");
|
||||||
$o .= replace_macros($script, array(
|
$o .= replace_macros($script, array(
|
||||||
'$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
|
'$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
|
||||||
'$key' => $conf['key'],
|
'$key' => $conf['key'],
|
||||||
'$widget_id' => 'f9a_'.$a->argv[1]."_". ceil(microtime(true)*100),
|
'$widget_id' => 'f9a_'.$a->argv[1]."_"._randomAlphaNum(6),
|
||||||
'$loader' => $a->get_baseurl()."/images/rotator.gif",
|
'$loader' => $a->get_baseurl()."/images/rotator.gif",
|
||||||
'$args' => (isset($_GET['a'])?$_GET['a']:''),
|
'$args' => (isset($_GET['a'])?$_GET['a']:''),
|
||||||
|
'$width' => $widget_size[0],
|
||||||
|
'$height' => $widget_size[1],
|
||||||
|
'$type' => $a->argv[1],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user