{"action":"created","comment":{"url":"https://api.github.com/repos/andig/carddav2fb/pulls/comments/241819718","pull_request_review_id":185190931,"id":241819718,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MTgxOTcxOA==","diff_hunk":"@@ -145,17 +163,99 @@ private function getClientOptions($options = [])\n         return $options;\n     }\n \n-    public function fetchImage($uri)\n+    /**\n+     * If elements are declared as to be substituted,\n+     * the data from possibly linked sources are embedded directly into the vCard\n+     *\n+     * @param   string $vcard               single parsed vCard\n+     * @param   string $substituteID        the property whose value is to be replaced ('logo', 'key', 'photo' or 'sound')\n+     * @param   string $server              the current CardDAV server adress\n+     * @return  string                      single vCard with embedded value\n+     */\n+    private function embedBase64($vcard, $substituteID, $server) \n     {\n-        $request = new Request('GET', $uri);\n+        if (!array_key_exists($substituteID, $vcard)) {\n+            return $vcard;\n+        }\n+        if (!preg_match(\"/http/\", $vcard->{$substituteID})) {    // no external URL set -> must be already base64 or local\n+            return $vcard;    \n+        }\n+        // check if mime is linked onto the same server \n+        $serv = explode('/', $server, 4);                      // get the beginning of the current server adress\n+        $link = explode('/', $vcard->{$substituteID}, 4);      // get the beginning of the linked adress\n+        if (strcasecmp($serv[2], $link[2]) !== 0) {            // if they aren´t equal authorisation will fail!\n+            return $vcard;\n+        }\n+        $embedded = $this->getLinkedData($vcard->{$substituteID});   // get the data from the external URL\n+        $types = '';\n+        switch ($vcard->version) {                             // the different vCard versions must be considered\n+            case '3.0':\n+                $types = \"TYPE=\" . strtoupper($embedded['subtype']) . \";ENCODING=b\";\n+                break;\n+            case '4.0':\n+                $types = \"data:\" . $embedded['mimetype'] . \";base64\";\n+                break;\n+        }\n+        switch ($substituteID) {\n+            case 'photo':\n+                $vcard->rawPhoto  = $embedded['data'];\n+                $vcard->photoData = $types;\n+                break;\n+            case 'logo':\n+                $vcard->rawLogo  = $embedded['data'];\n+                $vcard->logoData = $types;\n+                break;\n+            case 'sound':\n+                $vcard->rawSound  = $embedded['data'];\n+                $vcard->SoundData = $types;\n+                break;\n+            case 'key':\n+                $vcard->rawKey  = $embedded['data'];\n+                $vcard->keyData = $types;    \n+        }\n+        return $vcard;\n+    }\n \n-        $response = $this->getClient()->send($request);\n+    /**\n+     * delivers an array including the previously linked data and its mime type details\n+     * a mime type is composed of a type, a subtype, and optional parameters (e.g. \"; charset=UTF-8\")\n+     * \n+     * @param    string $uri           URL of the external linked data\n+     * @return   array ['mimetype',    e.g. \"image/jpeg\" \n+     *                  'type',        e.g. \"audio\"  \n+     *                  'subtype',     e.g. \"mpeg\"\n+     *                  'parameters',  whatever\n+     *                  'data']        the base64 encoded data\n+     */\n+    public function getLinkedData($uri)\n+    {\n+        $externalData = array();\n+        \n+        $this->client = $this->client ?? new Client();\n+        $request = new Request('GET', $uri);\n \n+        if ($this->username) {\n+            $credentials = base64_encode($this->username . ':' . $this->password);\n+            $request = $request->withHeader('Authorization', 'Basic ' . $credentials);\n+        }\n+        $response = $this->client->send($request);\n+        \n         if (200 !== $response->getStatusCode()) {\n             throw new \\Exception('Received HTTP ' . $response->getStatusCode());\n         }\n-\n-        return (string)$response->getBody();\n+        else {\n+            $contentType = $response->getHeader('Content-Type');\n+            \n+            @list($mimeType,$parameters) = explode(';', $contentType[0], 2);\n+            @list($type, $subType) = explode('/', $mimeType);\n+                        \n+            $externalData['mimetype']   = $mimeType ?? '';\n+            $externalData['type']       = $type ?? '';\n+            $externalData['subtype']    = $subType ?? '';\n+            $externalData['parameters'] = $parameters ?? '';\n+            $externalData['data']       = (string)$response->getBody();\n+        }","path":"src/CardDav/Backend.php","position":139,"original_position":139,"commit_id":"941ab078be77458ebf8d6a2f732ca576dbc63640","original_commit_id":"941ab078be77458ebf8d6a2f732ca576dbc63640","user":{"login":"andig","id":184815,"node_id":"MDQ6VXNlcjE4NDgxNQ==","avatar_url":"https://avatars1.githubusercontent.com/u/184815?v=4","gravatar_id":"","url":"https://api.github.com/users/andig","html_url":"https://github.com/andig","followers_url":"https://api.github.com/users/andig/followers","following_url":"https://api.github.com/users/andig/following{/other_user}","gists_url":"https://api.github.com/users/andig/gists{/gist_id}","starred_url":"https://api.github.com/users/andig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andig/subscriptions","organizations_url":"https://api.github.com/users/andig/orgs","repos_url":"https://api.github.com/users/andig/repos","events_url":"https://api.github.com/users/andig/events{/privacy}","received_events_url":"https://api.github.com/users/andig/received_events","type":"User","site_admin":false},"body":"besser:\r\n\r\n\r\n\t\t\t$externalData = [\r\n\t\t\t\t'mimetype'   => $mimeType ?? '',\r\n\t\t\t\t'type'       => $type ?? '',\r\n\t\t\t\t'subtype'    => $subType ?? '',\r\n\t\t\t\t'parameters' => $parameters ?? '',\r\n\t\t\t\t'data'       => (string)$response->getBody(),\r\n\t\t\t];\r\n\t\t\t","created_at":"2018-12-14T16:50:02Z","updated_at":"2018-12-14T16:54:43Z","html_url":"https://github.com/andig/carddav2fb/pull/59#discussion_r241819718","pull_request_url":"https://api.github.com/repos/andig/carddav2fb/pulls/59","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/andig/carddav2fb/pulls/comments/241819718"},"html":{"href":"https://github.com/andig/carddav2fb/pull/59#discussion_r241819718"},"pull_request":{"href":"https://api.github.com/repos/andig/carddav2fb/pulls/59"}}},"pull_request":{"url":"https://api.github.com/repos/andig/carddav2fb/pulls/59","id":218077640,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE4MDc3NjQw","html_url":"https://github.com/andig/carddav2fb/pull/59","diff_url":"https://github.com/andig/carddav2fb/pull/59.diff","patch_url":"https://github.com/andig/carddav2fb/pull/59.patch","issue_url":"https://api.github.com/repos/andig/carddav2fb/issues/59","number":59,"state":"open","locked":false,"title":"Image upload","user":{"login":"BlackSenator","id":31481294,"node_id":"MDQ6VXNlcjMxNDgxMjk0","avatar_url":"https://avatars1.githubusercontent.com/u/31481294?v=4","gravatar_id":"","url":"https://api.github.com/users/BlackSenator","html_url":"https://github.com/BlackSenator","followers_url":"https://api.github.com/users/BlackSenator/followers","following_url":"https://api.github.com/users/BlackSenator/following{/other_user}","gists_url":"https://api.github.com/users/BlackSenator/gists{/gist_id}","starred_url":"https://api.github.com/users/BlackSenator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BlackSenator/subscriptions","organizations_url":"https://api.github.com/users/BlackSenator/orgs","repos_url":"https://api.github.com/users/BlackSenator/repos","events_url":"https://api.github.com/users/BlackSenator/events{/privacy}","received_events_url":"https://api.github.com/users/BlackSenator/received_events","type":"User","site_admin":false},"body":"Implementation for image upload","created_at":"2018-09-25T18:33:32Z","updated_at":"2018-12-14T16:54:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fc04f320e41fe962c67ad6a79124203531b9f2d3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/andig/carddav2fb/pulls/59/commits","review_comments_url":"https://api.github.com/repos/andig/carddav2fb/pulls/59/comments","review_comment_url":"https://api.github.com/repos/andig/carddav2fb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andig/carddav2fb/issues/59/comments","statuses_url":"https://api.github.com/repos/andig/carddav2fb/statuses/941ab078be77458ebf8d6a2f732ca576dbc63640","head":{"label":"BlackSenator:image_upload","ref":"image_upload","sha":"941ab078be77458ebf8d6a2f732ca576dbc63640","user":{"login":"BlackSenator","id":31481294,"node_id":"MDQ6VXNlcjMxNDgxMjk0","avatar_url":"https://avatars1.githubusercontent.com/u/31481294?v=4","gravatar_id":"","url":"https://api.github.com/users/BlackSenator","html_url":"https://github.com/BlackSenator","followers_url":"https://api.github.com/users/BlackSenator/followers","following_url":"https://api.github.com/users/BlackSenator/following{/other_user}","gists_url":"https://api.github.com/users/BlackSenator/gists{/gist_id}","starred_url":"https://api.github.com/users/BlackSenator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BlackSenator/subscriptions","organizations_url":"https://api.github.com/users/BlackSenator/orgs","repos_url":"https://api.github.com/users/BlackSenator/repos","events_url":"https://api.github.com/users/BlackSenator/events{/privacy}","received_events_url":"https://api.github.com/users/BlackSenator/received_events","type":"User","site_admin":false},"repo":{"id":150019998,"node_id":"MDEwOlJlcG9zaXRvcnkxNTAwMTk5OTg=","name":"carddav2fb","full_name":"BlackSenator/carddav2fb","private":false,"owner":{"login":"BlackSenator","id":31481294,"node_id":"MDQ6VXNlcjMxNDgxMjk0","avatar_url":"https://avatars1.githubusercontent.com/u/31481294?v=4","gravatar_id":"","url":"https://api.github.com/users/BlackSenator","html_url":"https://github.com/BlackSenator","followers_url":"https://api.github.com/users/BlackSenator/followers","following_url":"https://api.github.com/users/BlackSenator/following{/other_user}","gists_url":"https://api.github.com/users/BlackSenator/gists{/gist_id}","starred_url":"https://api.github.com/users/BlackSenator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BlackSenator/subscriptions","organizations_url":"https://api.github.com/users/BlackSenator/orgs","repos_url":"https://api.github.com/users/BlackSenator/repos","events_url":"https://api.github.com/users/BlackSenator/events{/privacy}","received_events_url":"https://api.github.com/users/BlackSenator/received_events","type":"User","site_admin":false},"html_url":"https://github.com/BlackSenator/carddav2fb","description":"Download CardDAV VCards and upload as phonebook to AVM FRITZ!Box","fork":true,"url":"https://api.github.com/repos/BlackSenator/carddav2fb","forks_url":"https://api.github.com/repos/BlackSenator/carddav2fb/forks","keys_url":"https://api.github.com/repos/BlackSenator/carddav2fb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BlackSenator/carddav2fb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BlackSenator/carddav2fb/teams","hooks_url":"https://api.github.com/repos/BlackSenator/carddav2fb/hooks","issue_events_url":"https://api.github.com/repos/BlackSenator/carddav2fb/issues/events{/number}","events_url":"https://api.github.com/repos/BlackSenator/carddav2fb/events","assignees_url":"https://api.github.com/repos/BlackSenator/carddav2fb/assignees{/user}","branches_url":"https://api.github.com/repos/BlackSenator/carddav2fb/branches{/branch}","tags_url":"https://api.github.com/repos/BlackSenator/carddav2fb/tags","blobs_url":"https://api.github.com/repos/BlackSenator/carddav2fb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BlackSenator/carddav2fb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BlackSenator/carddav2fb/git/refs{/sha}","trees_url":"https://api.github.com/repos/BlackSenator/carddav2fb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BlackSenator/carddav2fb/statuses/{sha}","languages_url":"https://api.github.com/repos/BlackSenator/carddav2fb/languages","stargazers_url":"https://api.github.com/repos/BlackSenator/carddav2fb/stargazers","contributors_url":"https://api.github.com/repos/BlackSenator/carddav2fb/contributors","subscribers_url":"https://api.github.com/repos/BlackSenator/carddav2fb/subscribers","subscription_url":"https://api.github.com/repos/BlackSenator/carddav2fb/subscription","commits_url":"https://api.github.com/repos/BlackSenator/carddav2fb/commits{/sha}","git_commits_url":"https://api.github.com/repos/BlackSenator/carddav2fb/git/commits{/sha}","comments_url":"https://api.github.com/repos/BlackSenator/carddav2fb/comments{/number}","issue_comment_url":"https://api.github.com/repos/BlackSenator/carddav2fb/issues/comments{/number}","contents_url":"https://api.github.com/repos/BlackSenator/carddav2fb/contents/{+path}","compare_url":"https://api.github.com/repos/BlackSenator/carddav2fb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BlackSenator/carddav2fb/merges","archive_url":"https://api.github.com/repos/BlackSenator/carddav2fb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BlackSenator/carddav2fb/downloads","issues_url":"https://api.github.com/repos/BlackSenator/carddav2fb/issues{/number}","pulls_url":"https://api.github.com/repos/BlackSenator/carddav2fb/pulls{/number}","milestones_url":"https://api.github.com/repos/BlackSenator/carddav2fb/milestones{/number}","notifications_url":"https://api.github.com/repos/BlackSenator/carddav2fb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BlackSenator/carddav2fb/labels{/name}","releases_url":"https://api.github.com/repos/BlackSenator/carddav2fb/releases{/id}","deployments_url":"https://api.github.com/repos/BlackSenator/carddav2fb/deployments","created_at":"2018-09-23T19:52:29Z","updated_at":"2018-12-11T21:43:23Z","pushed_at":"2018-12-14T14:19:54Z","git_url":"git://github.com/BlackSenator/carddav2fb.git","ssh_url":"git@github.com:BlackSenator/carddav2fb.git","clone_url":"https://github.com/BlackSenator/carddav2fb.git","svn_url":"https://github.com/BlackSenator/carddav2fb","homepage":"","size":332,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"andig:master","ref":"master","sha":"b510882ca554b81e58790ad591138e0452aec3af","user":{"login":"andig","id":184815,"node_id":"MDQ6VXNlcjE4NDgxNQ==","avatar_url":"https://avatars1.githubusercontent.com/u/184815?v=4","gravatar_id":"","url":"https://api.github.com/users/andig","html_url":"https://github.com/andig","followers_url":"https://api.github.com/users/andig/followers","following_url":"https://api.github.com/users/andig/following{/other_user}","gists_url":"https://api.github.com/users/andig/gists{/gist_id}","starred_url":"https://api.github.com/users/andig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andig/subscriptions","organizations_url":"https://api.github.com/users/andig/orgs","repos_url":"https://api.github.com/users/andig/repos","events_url":"https://api.github.com/users/andig/events{/privacy}","received_events_url":"https://api.github.com/users/andig/received_events","type":"User","site_admin":false},"repo":{"id":110834554,"node_id":"MDEwOlJlcG9zaXRvcnkxMTA4MzQ1NTQ=","name":"carddav2fb","full_name":"andig/carddav2fb","private":false,"owner":{"login":"andig","id":184815,"node_id":"MDQ6VXNlcjE4NDgxNQ==","avatar_url":"https://avatars1.githubusercontent.com/u/184815?v=4","gravatar_id":"","url":"https://api.github.com/users/andig","html_url":"https://github.com/andig","followers_url":"https://api.github.com/users/andig/followers","following_url":"https://api.github.com/users/andig/following{/other_user}","gists_url":"https://api.github.com/users/andig/gists{/gist_id}","starred_url":"https://api.github.com/users/andig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andig/subscriptions","organizations_url":"https://api.github.com/users/andig/orgs","repos_url":"https://api.github.com/users/andig/repos","events_url":"https://api.github.com/users/andig/events{/privacy}","received_events_url":"https://api.github.com/users/andig/received_events","type":"User","site_admin":false},"html_url":"https://github.com/andig/carddav2fb","description":"Download CardDAV VCards and upload as phonebook to AVM FRITZ!Box","fork":true,"url":"https://api.github.com/repos/andig/carddav2fb","forks_url":"https://api.github.com/repos/andig/carddav2fb/forks","keys_url":"https://api.github.com/repos/andig/carddav2fb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andig/carddav2fb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andig/carddav2fb/teams","hooks_url":"https://api.github.com/repos/andig/carddav2fb/hooks","issue_events_url":"https://api.github.com/repos/andig/carddav2fb/issues/events{/number}","events_url":"https://api.github.com/repos/andig/carddav2fb/events","assignees_url":"https://api.github.com/repos/andig/carddav2fb/assignees{/user}","branches_url":"https://api.github.com/repos/andig/carddav2fb/branches{/branch}","tags_url":"https://api.github.com/repos/andig/carddav2fb/tags","blobs_url":"https://api.github.com/repos/andig/carddav2fb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andig/carddav2fb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andig/carddav2fb/git/refs{/sha}","trees_url":"https://api.github.com/repos/andig/carddav2fb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andig/carddav2fb/statuses/{sha}","languages_url":"https://api.github.com/repos/andig/carddav2fb/languages","stargazers_url":"https://api.github.com/repos/andig/carddav2fb/stargazers","contributors_url":"https://api.github.com/repos/andig/carddav2fb/contributors","subscribers_url":"https://api.github.com/repos/andig/carddav2fb/subscribers","subscription_url":"https://api.github.com/repos/andig/carddav2fb/subscription","commits_url":"https://api.github.com/repos/andig/carddav2fb/commits{/sha}","git_commits_url":"https://api.github.com/repos/andig/carddav2fb/git/commits{/sha}","comments_url":"https://api.github.com/repos/andig/carddav2fb/comments{/number}","issue_comment_url":"https://api.github.com/repos/andig/carddav2fb/issues/comments{/number}","contents_url":"https://api.github.com/repos/andig/carddav2fb/contents/{+path}","compare_url":"https://api.github.com/repos/andig/carddav2fb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andig/carddav2fb/merges","archive_url":"https://api.github.com/repos/andig/carddav2fb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andig/carddav2fb/downloads","issues_url":"https://api.github.com/repos/andig/carddav2fb/issues{/number}","pulls_url":"https://api.github.com/repos/andig/carddav2fb/pulls{/number}","milestones_url":"https://api.github.com/repos/andig/carddav2fb/milestones{/number}","notifications_url":"https://api.github.com/repos/andig/carddav2fb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andig/carddav2fb/labels{/name}","releases_url":"https://api.github.com/repos/andig/carddav2fb/releases{/id}","deployments_url":"https://api.github.com/repos/andig/carddav2fb/deployments","created_at":"2017-11-15T13:07:42Z","updated_at":"2018-12-14T11:35:31Z","pushed_at":"2018-12-14T14:19:55Z","git_url":"git://github.com/andig/carddav2fb.git","ssh_url":"git@github.com:andig/carddav2fb.git","clone_url":"https://github.com/andig/carddav2fb.git","svn_url":"https://github.com/andig/carddav2fb","homepage":"","size":315,"stargazers_count":22,"watchers_count":22,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":2,"open_issues":9,"watchers":22,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andig/carddav2fb/pulls/59"},"html":{"href":"https://github.com/andig/carddav2fb/pull/59"},"issue":{"href":"https://api.github.com/repos/andig/carddav2fb/issues/59"},"comments":{"href":"https://api.github.com/repos/andig/carddav2fb/issues/59/comments"},"review_comments":{"href":"https://api.github.com/repos/andig/carddav2fb/pulls/59/comments"},"review_comment":{"href":"https://api.github.com/repos/andig/carddav2fb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andig/carddav2fb/pulls/59/commits"},"statuses":{"href":"https://api.github.com/repos/andig/carddav2fb/statuses/941ab078be77458ebf8d6a2f732ca576dbc63640"}},"author_association":"NONE"}}
{"actor":{"display_login":"andig"}}