-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
266 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Filesystems; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Samwilson\PhpFlickr\PhpFlickr; | ||
use App\Repository\PostRepository; | ||
use App\Repository\SyndicationRepository; | ||
use App\Settings; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
use OAuth\OAuth1\Token\StdOAuth1Token; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use App\Entity\Post; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class FlickrController extends ControllerBase | ||
{ | ||
|
||
private function getPhpFlickr(Settings $settings): PhpFlickr | ||
{ | ||
$phpFlickr = new PhpFlickr($settings->flickrApiKey(), $settings->flickrApiSecret()); | ||
$accessToken = new StdOAuth1Token(); | ||
$accessToken->setAccessToken($settings->flickrToken()); | ||
$accessToken->setAccessTokenSecret($settings->flickrTokenSecret()); | ||
$phpFlickr->getOauthTokenStorage()->storeAccessToken('Flickr', $accessToken); | ||
return $phpFlickr; | ||
} | ||
|
||
/** | ||
* @Route("/P{id}/flickr", name="flickr", methods={"GET"}) | ||
* @IsGranted("ROLE_ADMIN") | ||
*/ | ||
public function form( | ||
PostRepository $postRepository, | ||
Settings $settings, | ||
string $id | ||
): Response { | ||
$post = $postRepository->find($id); | ||
if (!$post) { | ||
throw $this->createNotFoundException(); | ||
} | ||
$userInfo = $this->getPhpFlickr($settings)->test()->login(); | ||
return $this->render('post/flickr.html.twig', [ | ||
'flickr_user' => $userInfo, | ||
'post' => $post, | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/P{id}/flickr", name="flickr_save", methods={"POST"}) | ||
* @IsGranted("ROLE_ADMIN") | ||
*/ | ||
public function upload( | ||
PostRepository $postRepository, | ||
SyndicationRepository $syndicationRepository, | ||
Settings $settings, | ||
Filesystems $filesystems, | ||
Request $request, | ||
$id | ||
) { | ||
/** @var Post $post */ | ||
$post = $postRepository->find($id); | ||
if (!$post) { | ||
throw $this->createNotFoundException(); | ||
} | ||
$fullTempPath = $filesystems->getLocalTempFilepath($post->getFile()); | ||
$tags = []; | ||
foreach ($request->get('tags', []) as $tag) { | ||
// implode(' ', $request->get('tags', [])), | ||
$tags[] = '"' . str_replace('"', "'", $tag) . '"'; | ||
} | ||
$phpFlickr = $this->getPhpFlickr($settings); | ||
$postUrl = $this->generateUrl('post_view', ['id' => $post->getId()], UrlGeneratorInterface::ABSOLUTE_URL); | ||
$result = $phpFlickr->uploader()->upload( | ||
$fullTempPath, | ||
$request->get('title'), | ||
trim($request->get('description')) . "\n\n" . $postUrl, | ||
implode(' ', $tags), | ||
$request->get('is_public') !== null, | ||
$request->get('is_friend') !== null, | ||
$request->get('is_family') !== null, | ||
); | ||
if (isset($result['message'])) { | ||
$this->addFlash(self::FLASH_NOTICE, $result['message']); | ||
return $this->redirectToRoute('flickr', ['id' => $id]); | ||
} | ||
if (isset($result['stat']) && $result['stat'] === 'ok') { | ||
if ($post->getLocation()) { | ||
$phpFlickr->photosGeo()->setLocation( | ||
$result['photoid'], | ||
$post->getLocation()->getY(), | ||
$post->getLocation()->getX() | ||
); | ||
} | ||
$userInfo = $this->getPhpFlickr($settings)->test()->login(); | ||
$flickrUrl = 'https://www.flickr.com/photos/' . $userInfo['path_alias'] . '/' . $result['photoid']; | ||
$syndicationRepository->addSyndication($post, $flickrUrl, 'Flickr'); | ||
$this->addFlash(self::FLASH_SUCCESS, 'Uploaded: ' . $flickrUrl); | ||
return $this->redirectToRoute('post_view', ['id' => $id]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %} | ||
{{'posts.flickr.copy_to'|trans}} | ||
{% endblock %} | ||
|
||
{% block body %} | ||
|
||
<h1>{{'posts.flickr.copy_to'|trans}}</h1> | ||
|
||
<p><a href="{{ path('post_edit', {id:post.id}) }}">← Return to editing this post</a></p> | ||
|
||
<form action="{{ path('flickr_save', {id:post.id}) }}" method="post" class="posse"> | ||
<div class="image"> | ||
<img src="{{ path('file', {id:post.id, size:'D', ext:'jpg'}) }}" alt="Image of the file attached to this post." /> | ||
</div> | ||
<div class="form"> | ||
<p> | ||
{% set flickr_link -%} | ||
<a href="https://flickr.com/photos/{% if flickr_user.path_alias %}{{flickr_user.path_alias}}{% else %}{{flickr_user.id}}{% endif %}"> | ||
{{- flickr_user.username -}} | ||
</a> | ||
{%- endset %} | ||
{{ 'posts.flickr.logged_in'|trans({'%username_link%': flickr_link})|raw }} | ||
</p> | ||
<p> | ||
<label for="title">{{'posts.flickr.title'|trans}}</label> | ||
<input type="text" id="title" name="title" value="{{ post.title }}" /> | ||
</p> | ||
<p> | ||
<label for="description">{{'posts.flickr.description'|trans}}</label> | ||
<textarea id="description" name="description">{{ post.body }}</textarea> | ||
</p> | ||
<p> | ||
<label for="tags">Tags:</label> | ||
<select id="tags" name="tags[]" multiple> | ||
{% for tag in post.tags %} | ||
<option value="{{ tag.title }}" selected>{{ tag.title }}</option> | ||
{% endfor %} | ||
</select> | ||
</p> | ||
<p> | ||
<label for="is_public"> | ||
<input type="checkbox" name="is_public" id="is_public" /> | ||
{{'posts.flickr.is_public'|trans}} | ||
</label> | ||
<label for="is_friend"> | ||
<input type="checkbox" name="is_friend" id="is_friend" /> | ||
{{'posts.flickr.is_friend'|trans}} | ||
</label> | ||
<label for="is_family"> | ||
<input type="checkbox" name="is_family" id="is_family" /> | ||
{{'posts.flickr.is_family'|trans}} | ||
</label> | ||
</p> | ||
<p> | ||
<input type="submit" value="Upload" /> | ||
</p> | ||
</div> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters