{"action":"created","comment":{"url":"https://api.github.com/repos/ding2/ding2/pulls/comments/46394923","id":46394923,"diff_hunk":"@@ -397,6 +412,116 @@ function bpi_form_node_form_alter(&$form, &$form_state, $form_id) {\n }\n \n /**\n+ * Decide if the given field is a container for the given bpi image type.\n+ *\n+ * @param string $field_name\n+ *   The field name.\n+ * @param array $node\n+ *   The node.\n+ * @param string $image_type\n+ *   The bpi image type.\n+ *\n+ * @return bool\n+ *   True if the field is a container for the the bpi image type.\n+ */\n+function bpi_is_bpi_image_field($field_name, array $node, $image_type) {\n+  return bpi_get_image_type($field_name, $node) == $image_type;\n+}\n+\n+/**\n+ * Place syndicated images in node edit form.\n+ *\n+ * @param array $form\n+ *   The form.\n+ * @param string $current_language\n+ *   The current language.\n+ * @param array $syndicated_images\n+ *   The syndicated images.\n+ */\n+function bpi_place_images(array &$form, $current_language, array $syndicated_images) {\n+  $node = $form['#node'];\n+  $image_field_names = bpi_fetch_image_fields($node->type);\n+  if (!empty($image_field_names)) {\n+    foreach ($syndicated_images as $image_type => $images) {\n+      foreach ($image_field_names as $image_field_name) {\n+        if (bpi_is_bpi_image_field($image_field_name, $node, $image_type)) {\n+          $field = &$form[$image_field_name][$current_language];\n+          $cardinality = isset($field['#cardinality']) ? $field['#cardinality'] : 1;\n+          $number_of_images = count($images);\n+          for ($i = 0; $i < min($cardinality, $number_of_images); $i++) {\n+            if (is_object($images[$i]['@managed_file'])) {\n+              $field[$i]['#default_value'] = array('fid' => $images[$i]['@managed_file']->fid);\n+            }\n+          }\n+        }\n+      }\n+    }\n+  }\n+}\n+\n+/**\n+ * Replace inline images in content with references to syndicated images.\n+ *\n+ * @param string $field_name\n+ *   The field name.\n+ * @param string $content\n+ *   The content.\n+ * @param string $current_language\n+ *    The current language.\n+ * @param array $syndicated_images\n+ *   The syndicated images.\n+ *\n+ * @return string\n+ *   The content with inline images replaced by references to syndicated images.\n+ */\n+function bpi_place_inline_images($field_name, $content, $current_language, array $syndicated_images) {\n+  if (!empty($syndicated_images)) {\n+    $url_to_image_map = array();\n+    foreach ($syndicated_images as $type => $images) {\n+      foreach ($images as $image) {\n+        $url_to_image_map[$image['path']] = $image;\n+      }\n+    }\n+\n+    // Find <img/> elements in content and replace with file placeholders.\n+    $image_pattern = '@<img\\s*[^>]*\\ssrc=[\\'\"](?<url>[^\\'\">]+)[\\'\"][^>]*>@';\n+\n+    $content = preg_replace_callback($image_pattern, function($matches) use ($current_language, $url_to_image_map) {\n+      $url = $matches['url'];\n+      if (isset($url_to_image_map[$url])) {\n+        $image = $url_to_image_map[$url];\n+        $file = $image['@managed_file'];\n+\n+        // Build data for file placeholder.\n+        $data = array(\n+          'fid' => $file->fid,\n+          'view_mode' => 'default',\n+          'fields' => array(\n+            'format' => 'default',\n+            'field_file_image_alt_text[' . $current_language . '][0][value]' => isset($image['alt']) ? $image['alt'] : $image['name'],\n+            'field_file_image_title_text[' . $current_language . '][0][value]' => isset($image['title']) ? $image['title'] : $image['name'],\n+          ),\n+          'type' => 'media',\n+          'attributes' => array(\n+            'width' => isset($image['width']) ? $image['width'] : 800,\n+            'height' => isset($image['height']) ? $image['height'] : 100,","path":"modules/bpi/bpi.module","position":null,"original_position":147,"commit_id":"cb8d549002850dbafeff5fa12be2193de544a6f6","original_commit_id":"fd0a6574a96b193d6b9080454810feef366903ed","user":{"login":"kasperg","id":73966,"avatar_url":"https://avatars.githubusercontent.com/u/73966?v=3","gravatar_id":"","url":"https://api.github.com/users/kasperg","html_url":"https://github.com/kasperg","followers_url":"https://api.github.com/users/kasperg/followers","following_url":"https://api.github.com/users/kasperg/following{/other_user}","gists_url":"https://api.github.com/users/kasperg/gists{/gist_id}","starred_url":"https://api.github.com/users/kasperg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kasperg/subscriptions","organizations_url":"https://api.github.com/users/kasperg/orgs","repos_url":"https://api.github.com/users/kasperg/repos","events_url":"https://api.github.com/users/kasperg/events{/privacy}","received_events_url":"https://api.github.com/users/kasperg/received_events","type":"User","site_admin":false},"body":"Alright. Do we need any defaults at all?","created_at":"2015-12-02T09:54:54Z","updated_at":"2015-12-02T09:54:54Z","html_url":"https://github.com/ding2/ding2/pull/55#discussion_r46394923","pull_request_url":"https://api.github.com/repos/ding2/ding2/pulls/55","_links":{"self":{"href":"https://api.github.com/repos/ding2/ding2/pulls/comments/46394923"},"html":{"href":"https://github.com/ding2/ding2/pull/55#discussion_r46394923"},"pull_request":{"href":"https://api.github.com/repos/ding2/ding2/pulls/55"}}},"pull_request":{"url":"https://api.github.com/repos/ding2/ding2/pulls/55","id":50640512,"html_url":"https://github.com/ding2/ding2/pull/55","diff_url":"https://github.com/ding2/ding2/pull/55.diff","patch_url":"https://github.com/ding2/ding2/pull/55.patch","issue_url":"https://api.github.com/repos/ding2/ding2/issues/55","number":55,"state":"open","locked":false,"title":"Issue #1476 by rimi-itk: Added push and syndication of assets","user":{"login":"rimi-itk","id":11267554,"avatar_url":"https://avatars.githubusercontent.com/u/11267554?v=3","gravatar_id":"","url":"https://api.github.com/users/rimi-itk","html_url":"https://github.com/rimi-itk","followers_url":"https://api.github.com/users/rimi-itk/followers","following_url":"https://api.github.com/users/rimi-itk/following{/other_user}","gists_url":"https://api.github.com/users/rimi-itk/gists{/gist_id}","starred_url":"https://api.github.com/users/rimi-itk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rimi-itk/subscriptions","organizations_url":"https://api.github.com/users/rimi-itk/orgs","repos_url":"https://api.github.com/users/rimi-itk/repos","events_url":"https://api.github.com/users/rimi-itk/events{/privacy}","received_events_url":"https://api.github.com/users/rimi-itk/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-13T13:27:02Z","updated_at":"2015-12-02T09:54:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e90144aab7777d688a45625110139dcb6e72b74d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ding2/ding2/pulls/55/commits","review_comments_url":"https://api.github.com/repos/ding2/ding2/pulls/55/comments","review_comment_url":"https://api.github.com/repos/ding2/ding2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ding2/ding2/issues/55/comments","statuses_url":"https://api.github.com/repos/ding2/ding2/statuses/cb8d549002850dbafeff5fa12be2193de544a6f6","head":{"label":"rimi-itk:Issue-1476","ref":"Issue-1476","sha":"cb8d549002850dbafeff5fa12be2193de544a6f6","user":{"login":"rimi-itk","id":11267554,"avatar_url":"https://avatars.githubusercontent.com/u/11267554?v=3","gravatar_id":"","url":"https://api.github.com/users/rimi-itk","html_url":"https://github.com/rimi-itk","followers_url":"https://api.github.com/users/rimi-itk/followers","following_url":"https://api.github.com/users/rimi-itk/following{/other_user}","gists_url":"https://api.github.com/users/rimi-itk/gists{/gist_id}","starred_url":"https://api.github.com/users/rimi-itk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rimi-itk/subscriptions","organizations_url":"https://api.github.com/users/rimi-itk/orgs","repos_url":"https://api.github.com/users/rimi-itk/repos","events_url":"https://api.github.com/users/rimi-itk/events{/privacy}","received_events_url":"https://api.github.com/users/rimi-itk/received_events","type":"User","site_admin":false},"repo":{"id":45179782,"name":"ding2","full_name":"rimi-itk/ding2","owner":{"login":"rimi-itk","id":11267554,"avatar_url":"https://avatars.githubusercontent.com/u/11267554?v=3","gravatar_id":"","url":"https://api.github.com/users/rimi-itk","html_url":"https://github.com/rimi-itk","followers_url":"https://api.github.com/users/rimi-itk/followers","following_url":"https://api.github.com/users/rimi-itk/following{/other_user}","gists_url":"https://api.github.com/users/rimi-itk/gists{/gist_id}","starred_url":"https://api.github.com/users/rimi-itk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rimi-itk/subscriptions","organizations_url":"https://api.github.com/users/rimi-itk/orgs","repos_url":"https://api.github.com/users/rimi-itk/repos","events_url":"https://api.github.com/users/rimi-itk/events{/privacy}","received_events_url":"https://api.github.com/users/rimi-itk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rimi-itk/ding2","description":"Ding install profile","fork":true,"url":"https://api.github.com/repos/rimi-itk/ding2","forks_url":"https://api.github.com/repos/rimi-itk/ding2/forks","keys_url":"https://api.github.com/repos/rimi-itk/ding2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rimi-itk/ding2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rimi-itk/ding2/teams","hooks_url":"https://api.github.com/repos/rimi-itk/ding2/hooks","issue_events_url":"https://api.github.com/repos/rimi-itk/ding2/issues/events{/number}","events_url":"https://api.github.com/repos/rimi-itk/ding2/events","assignees_url":"https://api.github.com/repos/rimi-itk/ding2/assignees{/user}","branches_url":"https://api.github.com/repos/rimi-itk/ding2/branches{/branch}","tags_url":"https://api.github.com/repos/rimi-itk/ding2/tags","blobs_url":"https://api.github.com/repos/rimi-itk/ding2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rimi-itk/ding2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rimi-itk/ding2/git/refs{/sha}","trees_url":"https://api.github.com/repos/rimi-itk/ding2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rimi-itk/ding2/statuses/{sha}","languages_url":"https://api.github.com/repos/rimi-itk/ding2/languages","stargazers_url":"https://api.github.com/repos/rimi-itk/ding2/stargazers","contributors_url":"https://api.github.com/repos/rimi-itk/ding2/contributors","subscribers_url":"https://api.github.com/repos/rimi-itk/ding2/subscribers","subscription_url":"https://api.github.com/repos/rimi-itk/ding2/subscription","commits_url":"https://api.github.com/repos/rimi-itk/ding2/commits{/sha}","git_commits_url":"https://api.github.com/repos/rimi-itk/ding2/git/commits{/sha}","comments_url":"https://api.github.com/repos/rimi-itk/ding2/comments{/number}","issue_comment_url":"https://api.github.com/repos/rimi-itk/ding2/issues/comments{/number}","contents_url":"https://api.github.com/repos/rimi-itk/ding2/contents/{+path}","compare_url":"https://api.github.com/repos/rimi-itk/ding2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rimi-itk/ding2/merges","archive_url":"https://api.github.com/repos/rimi-itk/ding2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rimi-itk/ding2/downloads","issues_url":"https://api.github.com/repos/rimi-itk/ding2/issues{/number}","pulls_url":"https://api.github.com/repos/rimi-itk/ding2/pulls{/number}","milestones_url":"https://api.github.com/repos/rimi-itk/ding2/milestones{/number}","notifications_url":"https://api.github.com/repos/rimi-itk/ding2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rimi-itk/ding2/labels{/name}","releases_url":"https://api.github.com/repos/rimi-itk/ding2/releases{/id}","created_at":"2015-10-29T11:47:39Z","updated_at":"2015-10-29T11:47:48Z","pushed_at":"2015-12-02T09:29:56Z","git_url":"git://github.com/rimi-itk/ding2.git","ssh_url":"git@github.com:rimi-itk/ding2.git","clone_url":"https://github.com/rimi-itk/ding2.git","svn_url":"https://github.com/rimi-itk/ding2","homepage":"","size":79100,"stargazers_count":0,"watchers_count":0,"language":"SourcePawn","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ding2:master","ref":"master","sha":"3210981cbdfcc15999952362c6ca238119adc628","user":{"login":"ding2","id":564698,"avatar_url":"https://avatars.githubusercontent.com/u/564698?v=3","gravatar_id":"","url":"https://api.github.com/users/ding2","html_url":"https://github.com/ding2","followers_url":"https://api.github.com/users/ding2/followers","following_url":"https://api.github.com/users/ding2/following{/other_user}","gists_url":"https://api.github.com/users/ding2/gists{/gist_id}","starred_url":"https://api.github.com/users/ding2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ding2/subscriptions","organizations_url":"https://api.github.com/users/ding2/orgs","repos_url":"https://api.github.com/users/ding2/repos","events_url":"https://api.github.com/users/ding2/events{/privacy}","received_events_url":"https://api.github.com/users/ding2/received_events","type":"Organization","site_admin":false},"repo":{"id":1266749,"name":"ding2","full_name":"ding2/ding2","owner":{"login":"ding2","id":564698,"avatar_url":"https://avatars.githubusercontent.com/u/564698?v=3","gravatar_id":"","url":"https://api.github.com/users/ding2","html_url":"https://github.com/ding2","followers_url":"https://api.github.com/users/ding2/followers","following_url":"https://api.github.com/users/ding2/following{/other_user}","gists_url":"https://api.github.com/users/ding2/gists{/gist_id}","starred_url":"https://api.github.com/users/ding2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ding2/subscriptions","organizations_url":"https://api.github.com/users/ding2/orgs","repos_url":"https://api.github.com/users/ding2/repos","events_url":"https://api.github.com/users/ding2/events{/privacy}","received_events_url":"https://api.github.com/users/ding2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ding2/ding2","description":"Ding install profile","fork":false,"url":"https://api.github.com/repos/ding2/ding2","forks_url":"https://api.github.com/repos/ding2/ding2/forks","keys_url":"https://api.github.com/repos/ding2/ding2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ding2/ding2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ding2/ding2/teams","hooks_url":"https://api.github.com/repos/ding2/ding2/hooks","issue_events_url":"https://api.github.com/repos/ding2/ding2/issues/events{/number}","events_url":"https://api.github.com/repos/ding2/ding2/events","assignees_url":"https://api.github.com/repos/ding2/ding2/assignees{/user}","branches_url":"https://api.github.com/repos/ding2/ding2/branches{/branch}","tags_url":"https://api.github.com/repos/ding2/ding2/tags","blobs_url":"https://api.github.com/repos/ding2/ding2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ding2/ding2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ding2/ding2/git/refs{/sha}","trees_url":"https://api.github.com/repos/ding2/ding2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ding2/ding2/statuses/{sha}","languages_url":"https://api.github.com/repos/ding2/ding2/languages","stargazers_url":"https://api.github.com/repos/ding2/ding2/stargazers","contributors_url":"https://api.github.com/repos/ding2/ding2/contributors","subscribers_url":"https://api.github.com/repos/ding2/ding2/subscribers","subscription_url":"https://api.github.com/repos/ding2/ding2/subscription","commits_url":"https://api.github.com/repos/ding2/ding2/commits{/sha}","git_commits_url":"https://api.github.com/repos/ding2/ding2/git/commits{/sha}","comments_url":"https://api.github.com/repos/ding2/ding2/comments{/number}","issue_comment_url":"https://api.github.com/repos/ding2/ding2/issues/comments{/number}","contents_url":"https://api.github.com/repos/ding2/ding2/contents/{+path}","compare_url":"https://api.github.com/repos/ding2/ding2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ding2/ding2/merges","archive_url":"https://api.github.com/repos/ding2/ding2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ding2/ding2/downloads","issues_url":"https://api.github.com/repos/ding2/ding2/issues{/number}","pulls_url":"https://api.github.com/repos/ding2/ding2/pulls{/number}","milestones_url":"https://api.github.com/repos/ding2/ding2/milestones{/number}","notifications_url":"https://api.github.com/repos/ding2/ding2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ding2/ding2/labels{/name}","releases_url":"https://api.github.com/repos/ding2/ding2/releases{/id}","created_at":"2011-01-18T10:54:00Z","updated_at":"2015-11-02T10:11:44Z","pushed_at":"2015-12-02T09:39:45Z","git_url":"git://github.com/ding2/ding2.git","ssh_url":"git@github.com:ding2/ding2.git","clone_url":"https://github.com/ding2/ding2.git","svn_url":"https://github.com/ding2/ding2","homepage":"","size":79236,"stargazers_count":11,"watchers_count":11,"language":"SourcePawn","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":31,"forks":27,"open_issues":31,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ding2/ding2/pulls/55"},"html":{"href":"https://github.com/ding2/ding2/pull/55"},"issue":{"href":"https://api.github.com/repos/ding2/ding2/issues/55"},"comments":{"href":"https://api.github.com/repos/ding2/ding2/issues/55/comments"},"review_comments":{"href":"https://api.github.com/repos/ding2/ding2/pulls/55/comments"},"review_comment":{"href":"https://api.github.com/repos/ding2/ding2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ding2/ding2/pulls/55/commits"},"statuses":{"href":"https://api.github.com/repos/ding2/ding2/statuses/cb8d549002850dbafeff5fa12be2193de544a6f6"}}}}