{"action":"created","comment":{"url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/comments/87329506","pull_request_review_id":7945461,"id":87329506,"diff_hunk":"@@ -35,61 +51,123 @@ function easyxdm_library() {\n }\n \n /**\n- * JS to initialize EasyXDM with the capacity to send and receive messages.\n+ * JS to initialize easyXDM with the capacity to send and receive messages.\n  *\n  * Note define the JS string here, rather than a traditional JS file, so that we\n  * can easily include dynamic values.\n  *\n  * @return string\n- *   EasyXDM consumer JS, with dynamic variables.\n+ *   easyXDM Consumer JS, with dynamic variables.\n  */\n-function easyxdm_script_init() {\n+function easyxdm_script_exec($remote_url = NULL, $init_msg = NULL, $on_msg_exec = NULL, $test = FALSE) {\n   //////////////////////////////////////////////////////////////\n-  /// USE HTTPS WHEN SENDING SENSITIVE DATA!\n+  /// USE HTTPS WHEN TRANSMITTING SENSITIVE DATA!\n   //////////////////////////////////////////////////////////////\n-  // @todo Make this variable.\n-  $provider_remote = 'http://d7-provider.local';\n+  if (!isset($remote_url)) {\n+    $remote_url = variable_get('easyxdm_remote_url', '');\n+  }\n+  if (!isset($init_msg)) {\n+    $init_msg = variable_get('easyxdm_init_msg', '');\n+  }\n+  // $on_msg_exec is stringified JavaScript to be rendered as HTML and then\n+  // executed when the HTML is processed by the browser. Extreme care must be\n+  // taken that only trusted developers submit the code which will be executed!\n+  if (!isset($on_msg_exec)) {\n+    $on_msg_exec = variable_get('easyxdm_on_msg_exec', '');\n+  }\n+\n+  $init_msg = addslashes($init_msg);\n   $js = <<<EOT\n-    (function (Drupal) {\n+    (function (Drupal, $) {\n       'use strict';\n \n       Drupal.easyXDM = Drupal.easyXDM || {};\n \n       // Check whether logged in on other domain.\n       if (easyXDM && easyXDM.constructor === Object) {\n         var socket = new easyXDM.Socket({\n-          remote: '$provider_remote',\n-          onMessage: function (message) {\n-            // Write the received message to the global Drupal object to be used elsewhere on the site\n-            drupalEasyXDM.messageConsumed = message;\n-/*\n+          remote: '$remote_url',\n+          onMessage: function (message, origin) {\n+            // Write the received message to the global Drupal object to be\n+            // accessed from JavaScripts in custom themes and modules.\n+            Drupal.easyXDM.inbox = message;\n+            $on_msg_exec\n           },\n           onReady: function () {\n-            socket.postMessage('');\n-*/\n+            if ('$init_msg' !== '') { \n+              socket.postMessage('$init_msg');\n+            }\n           }\n         });\n       }\n-console.info('easyxdm_script_init');\n-console.info(Drupal.easyXDM);\n-    })(Drupal);\n+    })(Drupal, jQuery);\n EOT;\n \n   return $js;\n }\n \n-function easyxdm_test_page() {\n+function easyxdm_render_provider_script_only() {\n+  global $base_url;\n+\n+  drupal_add_library('easyxdm', 'easyxdm');\n+  drupal_add_js(easyxdm_script_exec(), array('type' => 'inline'));\n+\n+  return '';\n+}\n+\n+function easyxdm_render_provider_script_only_test() {\n+  global $base_url;\n+\n   drupal_add_library('easyxdm', 'easyxdm');\n-  drupal_add_js(easyxdm_script_init(), array('type' => 'inline'));\n-\n-  $output = <<<EOT\n-    <script>\n-      (function ($) {\n-console.info(Object.keys(Drupal));\n-console.info(Drupal.easyXDM);\n-      })(jQuery);\n-    </script>\n+\n+  $on_msg_exec = <<<EOT\n+    if (message.indexOf(\"Sending Consumer message from \") === 0) {\n+      socket.postMessage(\"Responding with Provider message from $base_url\");\n+    }\n EOT;\n \n-  return theme('table', array('header'=>array('$header'), 'rows'=>array(array($output))));\n+  drupal_add_js(easyxdm_script_exec(NULL, NULL, $on_msg_exec), array('type' => 'inline'));\n+\n+  return '';\n+}\n+\n+function easyxdm_render_test_page() {\n+  global $base_url;\n+\n+  drupal_add_library('easyxdm', 'easyxdm');\n+\n+  $remote_url = NULL;\n+  $consumer_msg = 'Sending Consumer message from ' . $base_url;","path":"easyxdm.module","position":158,"original_position":158,"commit_id":"145b11e21ca2daf9a09a8912361e3bb1d245846d","original_commit_id":"145b11e21ca2daf9a09a8912361e3bb1d245846d","user":{"login":"scottrigby","id":407675,"avatar_url":"https://avatars.githubusercontent.com/u/407675?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrigby","html_url":"https://github.com/scottrigby","followers_url":"https://api.github.com/users/scottrigby/followers","following_url":"https://api.github.com/users/scottrigby/following{/other_user}","gists_url":"https://api.github.com/users/scottrigby/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrigby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrigby/subscriptions","organizations_url":"https://api.github.com/users/scottrigby/orgs","repos_url":"https://api.github.com/users/scottrigby/repos","events_url":"https://api.github.com/users/scottrigby/events{/privacy}","received_events_url":"https://api.github.com/users/scottrigby/received_events","type":"User","site_admin":false},"body":"We should wrap all strings in `t()` 😉 ","created_at":"2016-11-10T05:10:03Z","updated_at":"2016-11-10T05:22:48Z","html_url":"https://github.com/scottrigby/drupal-easyxdm/pull/1#discussion_r87329506","pull_request_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/comments/87329506"},"html":{"href":"https://github.com/scottrigby/drupal-easyxdm/pull/1#discussion_r87329506"},"pull_request":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1","id":92488074,"html_url":"https://github.com/scottrigby/drupal-easyxdm/pull/1","diff_url":"https://github.com/scottrigby/drupal-easyxdm/pull/1.diff","patch_url":"https://github.com/scottrigby/drupal-easyxdm/pull/1.patch","issue_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/1","number":1,"state":"open","locked":false,"title":"communication works, db vars established, test page shows pertinent info","user":{"login":"e2tha-e","id":3268498,"avatar_url":"https://avatars.githubusercontent.com/u/3268498?v=3","gravatar_id":"","url":"https://api.github.com/users/e2tha-e","html_url":"https://github.com/e2tha-e","followers_url":"https://api.github.com/users/e2tha-e/followers","following_url":"https://api.github.com/users/e2tha-e/following{/other_user}","gists_url":"https://api.github.com/users/e2tha-e/gists{/gist_id}","starred_url":"https://api.github.com/users/e2tha-e/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e2tha-e/subscriptions","organizations_url":"https://api.github.com/users/e2tha-e/orgs","repos_url":"https://api.github.com/users/e2tha-e/repos","events_url":"https://api.github.com/users/e2tha-e/events{/privacy}","received_events_url":"https://api.github.com/users/e2tha-e/received_events","type":"User","site_admin":false},"body":"@scottrigby The description pretty well describes what's happening thus far. To test this:\r\n* create 2 D7 sites locally\r\n* open up the provider's X-Frame-Options (ALLOWALL is fine locally)\r\n* set the appropriate db vars on both the consumer and provider\r\n  * `easyxdm_provide` must be TRUE on providers\r\n  * `easyxdm_remote_url` must point to a valid EasyXDM provider page on consumers\r\n  * /easyxdm-provider-script is the path for provider pages\r\n* view /easyxdm-test-page on both sites to check that everything works\r\n* consumer should show both Message sent and Message received\r\n* provider should only show Message sent","created_at":"2016-11-06T13:53:24Z","updated_at":"2016-11-10T05:22:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d76270bc358462322e963f35a0a12523a2cc64e0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1/commits","review_comments_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1/comments","review_comment_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/1/comments","statuses_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/statuses/145b11e21ca2daf9a09a8912361e3bb1d245846d","head":{"label":"scottrigby:dev","ref":"dev","sha":"145b11e21ca2daf9a09a8912361e3bb1d245846d","user":{"login":"scottrigby","id":407675,"avatar_url":"https://avatars.githubusercontent.com/u/407675?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrigby","html_url":"https://github.com/scottrigby","followers_url":"https://api.github.com/users/scottrigby/followers","following_url":"https://api.github.com/users/scottrigby/following{/other_user}","gists_url":"https://api.github.com/users/scottrigby/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrigby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrigby/subscriptions","organizations_url":"https://api.github.com/users/scottrigby/orgs","repos_url":"https://api.github.com/users/scottrigby/repos","events_url":"https://api.github.com/users/scottrigby/events{/privacy}","received_events_url":"https://api.github.com/users/scottrigby/received_events","type":"User","site_admin":false},"repo":{"id":72761525,"name":"drupal-easyxdm","full_name":"scottrigby/drupal-easyxdm","owner":{"login":"scottrigby","id":407675,"avatar_url":"https://avatars.githubusercontent.com/u/407675?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrigby","html_url":"https://github.com/scottrigby","followers_url":"https://api.github.com/users/scottrigby/followers","following_url":"https://api.github.com/users/scottrigby/following{/other_user}","gists_url":"https://api.github.com/users/scottrigby/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrigby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrigby/subscriptions","organizations_url":"https://api.github.com/users/scottrigby/orgs","repos_url":"https://api.github.com/users/scottrigby/repos","events_url":"https://api.github.com/users/scottrigby/events{/privacy}","received_events_url":"https://api.github.com/users/scottrigby/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/scottrigby/drupal-easyxdm","description":"GitHub repo for developing easyXDM Drupal module https://www.drupal.org/project/easyxdm","fork":false,"url":"https://api.github.com/repos/scottrigby/drupal-easyxdm","forks_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/forks","keys_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/teams","hooks_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/hooks","issue_events_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/events{/number}","events_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/events","assignees_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/assignees{/user}","branches_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/branches{/branch}","tags_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/tags","blobs_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/refs{/sha}","trees_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/statuses/{sha}","languages_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/languages","stargazers_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/stargazers","contributors_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/contributors","subscribers_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/subscribers","subscription_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/subscription","commits_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/commits{/sha}","git_commits_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/commits{/sha}","comments_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/comments{/number}","issue_comment_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/comments{/number}","contents_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/contents/{+path}","compare_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/merges","archive_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/downloads","issues_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues{/number}","pulls_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls{/number}","milestones_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/milestones{/number}","notifications_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/labels{/name}","releases_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/releases{/id}","deployments_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/deployments","created_at":"2016-11-03T15:52:22Z","updated_at":"2016-11-03T15:52:22Z","pushed_at":"2016-11-06T17:44:22Z","git_url":"git://github.com/scottrigby/drupal-easyxdm.git","ssh_url":"git@github.com:scottrigby/drupal-easyxdm.git","clone_url":"https://github.com/scottrigby/drupal-easyxdm.git","svn_url":"https://github.com/scottrigby/drupal-easyxdm","homepage":null,"size":15,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"scottrigby:master","ref":"master","sha":"fcce58f477030bce295156e3d0da07e593c20ba6","user":{"login":"scottrigby","id":407675,"avatar_url":"https://avatars.githubusercontent.com/u/407675?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrigby","html_url":"https://github.com/scottrigby","followers_url":"https://api.github.com/users/scottrigby/followers","following_url":"https://api.github.com/users/scottrigby/following{/other_user}","gists_url":"https://api.github.com/users/scottrigby/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrigby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrigby/subscriptions","organizations_url":"https://api.github.com/users/scottrigby/orgs","repos_url":"https://api.github.com/users/scottrigby/repos","events_url":"https://api.github.com/users/scottrigby/events{/privacy}","received_events_url":"https://api.github.com/users/scottrigby/received_events","type":"User","site_admin":false},"repo":{"id":72761525,"name":"drupal-easyxdm","full_name":"scottrigby/drupal-easyxdm","owner":{"login":"scottrigby","id":407675,"avatar_url":"https://avatars.githubusercontent.com/u/407675?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrigby","html_url":"https://github.com/scottrigby","followers_url":"https://api.github.com/users/scottrigby/followers","following_url":"https://api.github.com/users/scottrigby/following{/other_user}","gists_url":"https://api.github.com/users/scottrigby/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrigby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrigby/subscriptions","organizations_url":"https://api.github.com/users/scottrigby/orgs","repos_url":"https://api.github.com/users/scottrigby/repos","events_url":"https://api.github.com/users/scottrigby/events{/privacy}","received_events_url":"https://api.github.com/users/scottrigby/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/scottrigby/drupal-easyxdm","description":"GitHub repo for developing easyXDM Drupal module https://www.drupal.org/project/easyxdm","fork":false,"url":"https://api.github.com/repos/scottrigby/drupal-easyxdm","forks_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/forks","keys_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/teams","hooks_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/hooks","issue_events_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/events{/number}","events_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/events","assignees_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/assignees{/user}","branches_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/branches{/branch}","tags_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/tags","blobs_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/refs{/sha}","trees_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/statuses/{sha}","languages_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/languages","stargazers_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/stargazers","contributors_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/contributors","subscribers_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/subscribers","subscription_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/subscription","commits_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/commits{/sha}","git_commits_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/git/commits{/sha}","comments_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/comments{/number}","issue_comment_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/comments{/number}","contents_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/contents/{+path}","compare_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/merges","archive_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/downloads","issues_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues{/number}","pulls_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls{/number}","milestones_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/milestones{/number}","notifications_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/labels{/name}","releases_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/releases{/id}","deployments_url":"https://api.github.com/repos/scottrigby/drupal-easyxdm/deployments","created_at":"2016-11-03T15:52:22Z","updated_at":"2016-11-03T15:52:22Z","pushed_at":"2016-11-06T17:44:22Z","git_url":"git://github.com/scottrigby/drupal-easyxdm.git","ssh_url":"git@github.com:scottrigby/drupal-easyxdm.git","clone_url":"https://github.com/scottrigby/drupal-easyxdm.git","svn_url":"https://github.com/scottrigby/drupal-easyxdm","homepage":null,"size":15,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1"},"html":{"href":"https://github.com/scottrigby/drupal-easyxdm/pull/1"},"issue":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/1"},"comments":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/scottrigby/drupal-easyxdm/statuses/145b11e21ca2daf9a09a8912361e3bb1d245846d"}}}}
{"actor":{"display_login":"scottrigby"}}