{"action":"created","comment":{"url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/comments/29876396","id":29876396,"diff_hunk":"@@ -207,24 +207,47 @@ function _use_pdf_template() {\n \n       if( defined('FETCH_COOKIES_ENABLED') && FETCH_COOKIES_ENABLED ) {\n \n-        // we want a html template\n-        $header = 'Accept:text/html' . \"\\n\";\n-\n-        // pass cookies from current request\n-        if( isset( $_SERVER['HTTP_COOKIE'] ) ) {\n-          $header .= 'Cookie: ' . $_SERVER['HTTP_COOKIE'] . \"\\n\";\n-        }\n-\n-        // create a request context for file_get_contents\n-        $context = stream_context_create(array(\n-          'http' => array(\n-            'method' => 'GET',\n-            'header' => $header,\n-          )\n-        ));\n-\n-        // load the generated html from the template endpoint\n-        $html = file_get_contents($link . (strpos($link, '?') === false ? '?' : '&') . 'pdf-template', false, $context);\n+\t\t$url =  $link . (strpos($link, '?') === false ? '?' : '&') . 'pdf-template';\n+\t\t$ch = curl_init();\n+\t\t\n+\t\tcurl_setopt($ch, CURLOPT_URL, $url);\n+\t\tcurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n+\t\t\n+\t\t// get http headers for cookies\n+\t\tcurl_setopt($ch, CURLOPT_VERBOSE, 1);\n+\t\tcurl_setopt($ch, CURLOPT_HEADER, 1);\n+\t\t\n+\t\t// store the cookies\n+\t\t$cookies = array();\n+\t\tforeach ($_COOKIE as $key => $value)\n+\t\t{\n+\t\t\tif ($key != 'Array')\n+\t\t\t{\n+\t\t\t\t$cookies[] = $key . '=' . $value;\n+\t\t\t}\n+\t\t}\n+\t\t// add the cookies to the request\n+\t\tcurl_setopt( $ch, CURLOPT_COOKIE, implode(';', $cookies) );\n+\t\t\n+\t\t// Stop session so curl can use the same session without conflicts\n+\t\tsession_write_close();\n+\t\t\n+\t\t$response = curl_exec($ch);\n+\t\tcurl_close($ch);\n+\t\t\n+\t\t// Session restart\n+\t\tsession_start();","path":"wp-pdf-templates.php","position":51,"original_position":51,"commit_id":"6ce05b08dab3b23a2c68a79809848a7e2d248954","original_commit_id":"6ce05b08dab3b23a2c68a79809848a7e2d248954","user":{"login":"anttiviljami","id":6105650,"avatar_url":"https://avatars.githubusercontent.com/u/6105650?v=3","gravatar_id":"","url":"https://api.github.com/users/anttiviljami","html_url":"https://github.com/anttiviljami","followers_url":"https://api.github.com/users/anttiviljami/followers","following_url":"https://api.github.com/users/anttiviljami/following{/other_user}","gists_url":"https://api.github.com/users/anttiviljami/gists{/gist_id}","starred_url":"https://api.github.com/users/anttiviljami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anttiviljami/subscriptions","organizations_url":"https://api.github.com/users/anttiviljami/orgs","repos_url":"https://api.github.com/users/anttiviljami/repos","events_url":"https://api.github.com/users/anttiviljami/events{/privacy}","received_events_url":"https://api.github.com/users/anttiviljami/received_events","type":"User","site_admin":false},"body":"What if there's no pre-existing session? We really don't want to start an unnecessary session for users that just want to download PDFs.","created_at":"2015-05-07T17:43:03Z","updated_at":"2015-05-07T17:43:03Z","html_url":"https://github.com/Seravo/wp-pdf-templates/pull/3#discussion_r29876396","pull_request_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/comments/29876396"},"html":{"href":"https://github.com/Seravo/wp-pdf-templates/pull/3#discussion_r29876396"},"pull_request":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3","id":34935430,"html_url":"https://github.com/Seravo/wp-pdf-templates/pull/3","diff_url":"https://github.com/Seravo/wp-pdf-templates/pull/3.diff","patch_url":"https://github.com/Seravo/wp-pdf-templates/pull/3.patch","issue_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues/3","number":3,"state":"open","locked":false,"title":"convert FETCH_COOKIES requests to use curl for better authentication support","user":{"login":"gtrout","id":1821848,"avatar_url":"https://avatars.githubusercontent.com/u/1821848?v=3","gravatar_id":"","url":"https://api.github.com/users/gtrout","html_url":"https://github.com/gtrout","followers_url":"https://api.github.com/users/gtrout/followers","following_url":"https://api.github.com/users/gtrout/following{/other_user}","gists_url":"https://api.github.com/users/gtrout/gists{/gist_id}","starred_url":"https://api.github.com/users/gtrout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gtrout/subscriptions","organizations_url":"https://api.github.com/users/gtrout/orgs","repos_url":"https://api.github.com/users/gtrout/repos","events_url":"https://api.github.com/users/gtrout/events{/privacy}","received_events_url":"https://api.github.com/users/gtrout/received_events","type":"User","site_admin":false},"body":"The original file_get_contents method wasn't passing all the cookies needed to render private/authenticated content. I tried converting it to use curl and it worked, so here are my changes for your consideration.\r\n\r\nCredit to stackoverflow user **PiTheNumber** for the curl example I started with (http://stackoverflow.com/a/23907823/3735757).","created_at":"2015-05-07T16:49:43Z","updated_at":"2015-05-07T17:43:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5bf7e600f179ed9494aeae7153f526d46032eab2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3/commits","review_comments_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3/comments","review_comment_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues/3/comments","statuses_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/statuses/6ce05b08dab3b23a2c68a79809848a7e2d248954","head":{"label":"gtrout:master","ref":"master","sha":"6ce05b08dab3b23a2c68a79809848a7e2d248954","user":{"login":"gtrout","id":1821848,"avatar_url":"https://avatars.githubusercontent.com/u/1821848?v=3","gravatar_id":"","url":"https://api.github.com/users/gtrout","html_url":"https://github.com/gtrout","followers_url":"https://api.github.com/users/gtrout/followers","following_url":"https://api.github.com/users/gtrout/following{/other_user}","gists_url":"https://api.github.com/users/gtrout/gists{/gist_id}","starred_url":"https://api.github.com/users/gtrout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gtrout/subscriptions","organizations_url":"https://api.github.com/users/gtrout/orgs","repos_url":"https://api.github.com/users/gtrout/repos","events_url":"https://api.github.com/users/gtrout/events{/privacy}","received_events_url":"https://api.github.com/users/gtrout/received_events","type":"User","site_admin":false},"repo":{"id":35193547,"name":"wp-pdf-templates","full_name":"gtrout/wp-pdf-templates","owner":{"login":"gtrout","id":1821848,"avatar_url":"https://avatars.githubusercontent.com/u/1821848?v=3","gravatar_id":"","url":"https://api.github.com/users/gtrout","html_url":"https://github.com/gtrout","followers_url":"https://api.github.com/users/gtrout/followers","following_url":"https://api.github.com/users/gtrout/following{/other_user}","gists_url":"https://api.github.com/users/gtrout/gists{/gist_id}","starred_url":"https://api.github.com/users/gtrout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gtrout/subscriptions","organizations_url":"https://api.github.com/users/gtrout/orgs","repos_url":"https://api.github.com/users/gtrout/repos","events_url":"https://api.github.com/users/gtrout/events{/privacy}","received_events_url":"https://api.github.com/users/gtrout/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gtrout/wp-pdf-templates","description":"","fork":true,"url":"https://api.github.com/repos/gtrout/wp-pdf-templates","forks_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/forks","keys_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/teams","hooks_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/hooks","issue_events_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/issues/events{/number}","events_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/events","assignees_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/assignees{/user}","branches_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/branches{/branch}","tags_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/tags","blobs_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/git/refs{/sha}","trees_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/statuses/{sha}","languages_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/languages","stargazers_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/stargazers","contributors_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/contributors","subscribers_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/subscribers","subscription_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/subscription","commits_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/commits{/sha}","git_commits_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/git/commits{/sha}","comments_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/comments{/number}","issue_comment_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/issues/comments{/number}","contents_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/contents/{+path}","compare_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/merges","archive_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/downloads","issues_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/issues{/number}","pulls_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/pulls{/number}","milestones_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/milestones{/number}","notifications_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/labels{/name}","releases_url":"https://api.github.com/repos/gtrout/wp-pdf-templates/releases{/id}","created_at":"2015-05-07T02:07:29Z","updated_at":"2015-05-07T16:06:40Z","pushed_at":"2015-05-07T16:06:40Z","git_url":"git://github.com/gtrout/wp-pdf-templates.git","ssh_url":"git@github.com:gtrout/wp-pdf-templates.git","clone_url":"https://github.com/gtrout/wp-pdf-templates.git","svn_url":"https://github.com/gtrout/wp-pdf-templates","homepage":null,"size":8068,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"Seravo:master","ref":"master","sha":"1b6ea2cf32d0b119aa0fce053178d69fd5f7b5e9","user":{"login":"Seravo","id":1504292,"avatar_url":"https://avatars.githubusercontent.com/u/1504292?v=3","gravatar_id":"","url":"https://api.github.com/users/Seravo","html_url":"https://github.com/Seravo","followers_url":"https://api.github.com/users/Seravo/followers","following_url":"https://api.github.com/users/Seravo/following{/other_user}","gists_url":"https://api.github.com/users/Seravo/gists{/gist_id}","starred_url":"https://api.github.com/users/Seravo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Seravo/subscriptions","organizations_url":"https://api.github.com/users/Seravo/orgs","repos_url":"https://api.github.com/users/Seravo/repos","events_url":"https://api.github.com/users/Seravo/events{/privacy}","received_events_url":"https://api.github.com/users/Seravo/received_events","type":"Organization","site_admin":false},"repo":{"id":21115788,"name":"wp-pdf-templates","full_name":"Seravo/wp-pdf-templates","owner":{"login":"Seravo","id":1504292,"avatar_url":"https://avatars.githubusercontent.com/u/1504292?v=3","gravatar_id":"","url":"https://api.github.com/users/Seravo","html_url":"https://github.com/Seravo","followers_url":"https://api.github.com/users/Seravo/followers","following_url":"https://api.github.com/users/Seravo/following{/other_user}","gists_url":"https://api.github.com/users/Seravo/gists{/gist_id}","starred_url":"https://api.github.com/users/Seravo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Seravo/subscriptions","organizations_url":"https://api.github.com/users/Seravo/orgs","repos_url":"https://api.github.com/users/Seravo/repos","events_url":"https://api.github.com/users/Seravo/events{/privacy}","received_events_url":"https://api.github.com/users/Seravo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Seravo/wp-pdf-templates","description":"","fork":false,"url":"https://api.github.com/repos/Seravo/wp-pdf-templates","forks_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/forks","keys_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/teams","hooks_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/hooks","issue_events_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues/events{/number}","events_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/events","assignees_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/assignees{/user}","branches_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/branches{/branch}","tags_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/tags","blobs_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/git/refs{/sha}","trees_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/statuses/{sha}","languages_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/languages","stargazers_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/stargazers","contributors_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/contributors","subscribers_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/subscribers","subscription_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/subscription","commits_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/commits{/sha}","git_commits_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/git/commits{/sha}","comments_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/comments{/number}","issue_comment_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues/comments{/number}","contents_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/contents/{+path}","compare_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/merges","archive_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/downloads","issues_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues{/number}","pulls_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls{/number}","milestones_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/milestones{/number}","notifications_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/labels{/name}","releases_url":"https://api.github.com/repos/Seravo/wp-pdf-templates/releases{/id}","created_at":"2014-06-23T06:13:03Z","updated_at":"2015-05-06T17:12:17Z","pushed_at":"2015-05-07T16:49:44Z","git_url":"git://github.com/Seravo/wp-pdf-templates.git","ssh_url":"git@github.com:Seravo/wp-pdf-templates.git","clone_url":"https://github.com/Seravo/wp-pdf-templates.git","svn_url":"https://github.com/Seravo/wp-pdf-templates","homepage":null,"size":8068,"stargazers_count":2,"watchers_count":2,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3"},"html":{"href":"https://github.com/Seravo/wp-pdf-templates/pull/3"},"issue":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues/3"},"comments":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/Seravo/wp-pdf-templates/statuses/6ce05b08dab3b23a2c68a79809848a7e2d248954"}}}}