OSDN Git Service

MERGE: リビジョン1792の一部。getBookmarklet()の変更。
authorsakamocchi <o-takashi@sakamocchi.jp>
Sun, 29 Apr 2012 04:54:57 +0000 (13:54 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sun, 29 Apr 2012 04:55:24 +0000 (13:55 +0900)
getBookmarklet()で返されるJavaScriptのコード中で、文字列をx-www-urlencodedに従ってエンコードする目的でescape()を使っていた。しかしこれは、JavaScriptの言語仕様であるStandard
ECMA Script-262に定義されているencodeURIComponent()でエンコードされるべきものである。

これにより、コミットf29dc242d5f30a1394ad4174e7c87e12076e9fc2で指摘されたバグを修正する。

Revision 1792:
REMOVE: bookmarklet registering to Windows operating system
This function heavily depends on Windows operating system and hard to
maintain for us. There is no alternatives after this commit.
http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1792

Standard ECMA-262 (ECMAScript Language Specification 5th Edition)
http://www.ecma-international.org/publications/standards/Ecma-262.htm
15.1.3 URI Handling Function Properties
15.1.3.1 decodeURI(encodeedURI)
15.1.3.2 decodeURIComponent(encodedURIComponent)
15.1.3.3 encodeURI(uri)
15.1.3.4 encodeURIComponent(uriComponent)

Microsoft Developer Network
JavaScript Reference
decodeURI Function (JavaScript)
http://msdn.microsoft.com/en-us/library/ht8a077w(v=vs.94).aspx
decodeURIComponent Function (JavaScript)
http://msdn.microsoft.com/en-us/library/91b80x6x(v=vs.94).aspx
encodeURI Function (JavaScript)
http://msdn.microsoft.com/en-us/library/xh9be5xc(v=vs.94).aspx
encodeURIComponent Function (JavaScript)
http://msdn.microsoft.com/en-us/library/aeh9cef7(v=vs.94).aspx
escape Function (JavaScript)
http://msdn.microsoft.com/en-us/library/9yzah1fh(v=vs.94).aspx
unescape Function (JavaScript)
http://msdn.microsoft.com/en-us/library/dz4x90hk(v=vs.94).aspx

Mozilla Developer Network
JavaScript Reference
decodeURI
https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/decodeURI
decodeURIComponent
https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/decodeURIComponent
encodeURI
https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/encodeURI
encodeURIComponent
https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/encodeURIComponent
escape
https://developer.mozilla.org/ja/DOM/window.escape
unescape
https://developer.mozilla.org/ja/DOM/window.unescape

NOTE:
decodeURI/decodeURIComponent/encodeURI/encodeURIComponent are in
specification,
but escape/unescape is defferent for each vendor's implement.
For example, Microsoft defines it as one of Global Object
http://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx
But Mozilla define it as one of methods in DOM Window Object
https://developer.mozilla.org/ja/DOM/window

NOTE:
urldecode() already applied to each elements in
$_GET/$_POST/$_REQUEST/$_COOKIE
http://php.net/manual/en/function.urldecode.php
rawurldecode()
http://www.php.net/manual/en/function.rawurldecode.php
urlencode()
http://www.php.net/manual/en/function.rawurlencode.php
rawurldecode()
http://www.php.net/manual/en/function.urldecode.php

nucleus/libs/globalfunctions.php

index 79fdde8..74fef08 100644 (file)
@@ -1988,20 +1988,41 @@ function redirect($url) {
     exit;\r
 }\r
 \r
-/*\r
+/**\r
+ * getBookmarklet()\r
  * Returns the Javascript code for a bookmarklet that works on most modern browsers\r
- * @param blogid\r
+ * \r
+ * @param      integer $blogid ID for weblog\r
+ * @return     script to call Bookmarklet\r
  */\r
-function getBookmarklet($blogid) {\r
-    global $CONF;\r
-\r
-    // normal\r
-    $document = 'document';\r
-    $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";\r
-    $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";\r
-    $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');wingm.focus();";\r
-\r
-    return $bookmarkletline;\r
+function getBookmarklet($blogid, $width=600,  $height=500)\r
+{\r
+       global $CONF;\r
+       \r
+       $script = "Q='';"\r
+               . "x=document;"\r
+               . "y=window;"\r
+               . "if ( x.selection )"\r
+               . "{"\r
+               . " Q=x.selection.createRange().text;"\r
+               . "}"\r
+               . "else if ( y.getSelection )"\r
+               . "{"\r
+               . " Q=y.getSelection();"\r
+               . "}"\r
+               . "else if ( x.getSelection )"\r
+               . "{"\r
+               . " Q=x.getSelection();"\r
+               . "}"\r
+               . "wingm = window.open('{$CONF['AdminURL']}bookmarklet.php?blogid={$blogid}"\r
+               . " &logtext=' + encodeURIComponent(Q) +"\r
+               . " '&loglink=' + encodeURIComponent(x.location.href) +"\r
+               . " '&loglinktitle=' + encodeURIComponent(x.title),"\r
+               . " 'nucleusbm',"\r
+               . " 'scrollbars=yes,width={$width},height={$height},left=10,top=10,status=yes,resizable=yes');"\r
+               . "wingm.focus();";\r
+       \r
+       return $script;\r
 }\r
 // END: functions from the end of file ADMIN.php\r
 \r