lilurlパッチとブックマークレット修正(クロスドメイン対応)
さっきアップしたパッチとブックマークレットではクロスドメインで動かなかったので修正した。
lilurlでGETメソッドによる短縮URL発行するインターフェースを追加するパッチ
--- index.php.orig 2009-01-09 16:00:32.000000000 +0900 +++ index.php 2009-01-10 00:29:34.000000000 +0900 @@ -7,10 +7,19 @@ $msg = ''; // if the form has been submitted -if ( isset($_POST['longurl']) ) +if ( isset($_POST['longurl']) || isset($_GET['longurl']) ) { + if (isset($_POST['longurl'])) { + $method = 'POST'; + $longurl = $_POST['longurl']; + } + else + { + $method = 'GET'; + $longurl = $_GET['longurl']; + } // escape bad characters from the user's url - $longurl = trim(mysql_escape_string($_POST['longurl'])); + $longurl = trim(mysql_escape_string($longurl)); // set the protocol to not ok by default $protocol_ok = false; @@ -55,6 +64,13 @@ { $msg = '<p class="error">Creation of your lil´ URL failed for some reason.</p>'; } + + // for RESTful interface + if ($method == 'GET') { + header('Content-Type: Text/Plain'); + echo("show_lilurl('$url');"); + exit; + } } else // if the form hasn't been submitted, look for an id to redirect to {
ブックマークレットから呼び出されるjavascript(適当なサーバに配置する)
// make_lil.js show_lilurl = function(url) { if(window.clipboardData) { window.clipboardData.setData('Text',url); alert('Copy to clipboard : '+url); } else prompt('Copy this',url); }
javascript: var s0=document.createElement('script'); s0.src='http://hoge/~snaka/dev/make_lil.js'; document.body.appendChild(s0); var s=document.createElement('script'); s.src='http://hoge/lilurl/index.php?longurl='+encodeURIComponent(location); document.body.appendChild(s); void(0);
うーん全部ブックマークレットに押し込めたいけど... なんかうまくいかなかったなぁ。なぜだろう。