Commit 15981e3b authored by Vincent Petry's avatar Vincent Petry Committed by GitHub
Browse files

Merge pull request #25579 from owncloud/facebook-preview-public-links

[9.2] Adding Open Graph Support for public shares http://ogp.me/
parents eadcffcf 8c3ef3c8
......@@ -251,7 +251,7 @@ class ShareController extends Controller {
*
* @param string $token
* @param string $path
* @return TemplateResponse|RedirectResponse
* @return NotFoundResponse|RedirectResponse|TemplateResponse
* @throws NotFoundException
*/
public function showShare($token, $path = '') {
......@@ -344,10 +344,17 @@ class ShareController extends Controller {
}
$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', ['token' => $token]);
$shareTmpl['shareUrl'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]);
$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
$shareTmpl['previewMaxX'] = $this->config->getSystemValue('preview_max_x', 1024);
$shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024);
if ($shareTmpl['previewSupported']) {
$shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'core_ajax_public_preview',
['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 't' => $shareTmpl['dirToken']]);
} else {
$shareTmpl['previewImage'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-fb.png'));
}
$csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
......@@ -367,7 +374,7 @@ class ShareController extends Controller {
* @param string $files
* @param string $path
* @param string $downloadStartSecret
* @return void|RedirectResponse
* @return NotFoundResponse|RedirectResponse|void
*/
public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
\OC_User::setIncognitoMode(true);
......
<?php
/** @var $l OC_L10N */
/** @var $theme OC_Defaults */
/** @var $_ array */
OCP\Util::addScript('files', 'file-upload');
......@@ -20,10 +21,18 @@ OCP\Util::addScript('files', 'newfilemenu');
OCP\Util::addScript('files', 'files');
OCP\Util::addScript('files', 'filelist');
OCP\Util::addScript('files', 'keyboardshortcuts');
// OpenGraph Support: http://ogp.me/
OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $theme->getName() . ' - ' . $theme->getSlogan()]);
OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $l->t('%s is publicly shared', [$_['filename']])]);
OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $theme->getName()]);
OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $_['shareUrl']]);
OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $_['previewImage']]);
?>
<?php if ($_['previewSupported']): /* This enables preview images for links (e.g. on Facebook, Google+, ...)*/?>
<link rel="image_src" href="<?php p(\OC::$server->getURLGenerator()->linkToRoute( 'core_ajax_public_preview', ['x' => $_['previewMaxX'], 'y' => $_['previewMaxY'], 'file' => $_['directory_path'], 't' => $_['dirToken']])); ?>" />
<link rel="image_src" href="<?php p($_['previewImage']); ?>" />
<?php endif; ?>
<div id="notification-container">
......
......@@ -372,6 +372,8 @@ class ShareControllerTest extends \Test\TestCase {
'previewEnabled' => true,
'previewMaxX' => 1024,
'previewMaxY' => 1024,
'shareUrl' => null,
'previewImage' => null
];
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment