Skip to content

Commit

Permalink
considering recommendation from Codacy/PR Quality Review
Browse files Browse the repository at this point in the history
  • Loading branch information
call-me-matt committed Apr 14, 2020
1 parent a30a67d commit 32bd255
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
['name' => 'page#index', 'url' => '/{group}', 'verb' => 'GET', 'postfix' => 'group'],
['name' => 'page#index', 'url' => '/{group}/{contact}', 'verb' => 'GET', 'postfix' => 'group.contact'],
['name' => 'avatar#view', 'url' => '/{group}/settings/avatars', 'verb' => 'GET'],
['name' => 'avatar#fetch', 'url' => '/{group}/{contact}/avatar/{network}/{id}', 'verb' => 'GET', 'requirements' => ['id' => '\d+']]
['name' => 'avatar#fetch', 'url' => '/{group}/{contact}/avatar/{network}/{profileid}', 'verb' => 'GET', 'requirements' => ['profileid' => '\d+']]
]
];
24 changes: 13 additions & 11 deletions lib/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ public function view(): TemplateResponse {
* param id profile identifier
* param network from where to retrieve
*/
public function fetch($network, $id) {
public function fetch($network, $profileid) {
$url = "";
$response = 404;

try {
// add your social networks here!
if ($network == 'facebook') {
$url = "https://graph.facebook.com/" . ($id) . "/picture?width=720";
} else {
$response = 400;
throw new Exception('Unknown network');
switch ($network) {
case 'facebook':
$url = "https://graph.facebook.com/" . ($profileid) . "/picture?width=720";
break;
default:
$response = 400;
throw new Exception('Unknown network');
}

$host = parse_url($url);
Expand All @@ -105,13 +107,13 @@ public function fetch($network, $id) {
$context = stream_context_create($opts);
$image = file_get_contents($url, false, $context);
if (!$image) {
throw new Exception('Could not parse URL');
$response = 404;
} else {
$response = 200;
header("Content-type:image/png");
echo $image;
throw new Exception('Could not parse URL');
}

$response = 200;
header("Content-type:image/png");
echo $image;
}
catch (Exception $e) {
}
Expand Down

0 comments on commit 32bd255

Please sign in to comment.