]> source.dussan.org Git - nextcloud-server.git/commitdiff
Adding Open Graph Support for public shares http://ogp.me/
authorThomas Müller <thomas.mueller@tmit.eu>
Fri, 22 Jul 2016 14:13:26 +0000 (16:13 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Fri, 21 Oct 2016 19:42:40 +0000 (21:42 +0200)
In case no preview is available we display the ownCloud logo

Fix unit test

apps/files_sharing/lib/AppInfo/Application.php
apps/files_sharing/lib/Controllers/ShareController.php
apps/files_sharing/templates/public.php
apps/files_sharing/tests/Controllers/ShareControllerTest.php
core/img/favicon-fb.png [new file with mode: 0644]

index 5558ffbdfc4cfd98dd3650fd560c1dde4ccc47f4..357860e8fa0912b45c66129de4140855b4c54689 100644 (file)
@@ -37,12 +37,14 @@ use OCA\Files_Sharing\Controllers\ExternalSharesController;
 use OCA\Files_Sharing\Controllers\ShareController;
 use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
 use \OCP\IContainer;
+use OCP\IServerContainer;
 
 class Application extends App {
        public function __construct(array $urlParams = array()) {
                parent::__construct('files_sharing', $urlParams);
 
                $container = $this->getContainer();
+               /** @var IServerContainer $server */
                $server = $container->getServer();
 
                /**
@@ -63,7 +65,9 @@ class Application extends App {
                                $server->getPreviewManager(),
                                $server->getRootFolder(),
                                $federatedSharingApp->getFederatedShareProvider(),
-                               $server->getEventDispatcher()
+                               $server->getEventDispatcher(),
+                               $server->getL10N($c->query('AppName')),
+                               $server->getThemingDefaults()
                        );
                });
                $container->registerService('ExternalSharesController', function (SimpleContainer $c) {
@@ -133,7 +137,7 @@ class Application extends App {
                });
 
                // Execute middlewares
-               $container->registerMiddleware('SharingCheckMiddleware');
+               $container->registerMiddleWare('SharingCheckMiddleware');
                $container->registerMiddleWare('OCSShareAPIMiddleware');
 
                $container->registerService('MountProvider', function (IContainer $c) {
index 5ccaab746fce99ce6bdd5ff378adf5c3b5c840d3..8e3405311e93464d419208af0db702ff5f3b52fd 100644 (file)
@@ -35,6 +35,8 @@ namespace OCA\Files_Sharing\Controllers;
 use OC_Files;
 use OC_Util;
 use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCP\Defaults;
+use OCP\IL10N;
 use OCP\Template;
 use OCP\Share;
 use OCP\AppFramework\Controller;
@@ -84,6 +86,10 @@ class ShareController extends Controller {
        protected $federatedShareProvider;
        /** @var EventDispatcherInterface */
        protected $eventDispatcher;
+       /** @var IL10N */
+       protected $l10n;
+       /** @var Defaults */
+       protected $defaults;
 
        /**
         * @param string $appName
@@ -99,6 +105,8 @@ class ShareController extends Controller {
         * @param IRootFolder $rootFolder
         * @param FederatedShareProvider $federatedShareProvider
         * @param EventDispatcherInterface $eventDispatcher
+        * @param IL10N $l10n
+        * @param \OC_Defaults $defaults
         */
        public function __construct($appName,
                                                                IRequest $request,
@@ -112,7 +120,9 @@ class ShareController extends Controller {
                                                                IPreview $previewManager,
                                                                IRootFolder $rootFolder,
                                                                FederatedShareProvider $federatedShareProvider,
-                                                               EventDispatcherInterface $eventDispatcher) {
+                                                               EventDispatcherInterface $eventDispatcher,
+                                                               IL10N $l10n,
+                                                               \OC_Defaults $defaults) {
                parent::__construct($appName, $request);
 
                $this->config = $config;
@@ -126,6 +136,8 @@ class ShareController extends Controller {
                $this->rootFolder = $rootFolder;
                $this->federatedShareProvider = $federatedShareProvider;
                $this->eventDispatcher = $eventDispatcher;
+               $this->l10n = $l10n;
+               $this->defaults = $defaults;
        }
 
        /**
@@ -352,12 +364,19 @@ class ShareController extends Controller {
 
                $shareTmpl['hideFileList'] = $hideFileList;
                $shareTmpl['shareOwner'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
-               $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
+               $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);
                $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null);
+               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'));
+               }
 
                // Load files we need
                \OCP\Util::addScript('files', 'file-upload');
@@ -382,6 +401,14 @@ class ShareController extends Controller {
                        \OCP\Util::addScript('files', 'keyboardshortcuts');
                }
 
+               // OpenGraph Support: http://ogp.me/
+               \OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $this->defaults->getName() . ' - ' . $this->defaults->getSlogan()]);
+               \OCP\Util::addHeader('meta', ['property' => "og:description", 'content' => $this->l10n->t('%s is publicly shared', [$shareTmpl['filename']])]);
+               \OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $this->defaults->getName()]);
+               \OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $shareTmpl['shareUrl']]);
+               \OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
+               \OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $shareTmpl['previewImage']]);
+
                $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts');
 
                $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
index bdedb04d2442d09343fe5320899b1882cf5bfe29..80c7d4d7460e82b80fb73fbe59f16836e2d65238 100644 (file)
@@ -4,7 +4,7 @@
 ?>
 
 <?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', array('x' => $_['previewMaxX'], 'y' => $_['previewMaxY'], 'file' => $_['directory_path'], 't' => $_['dirToken']))); ?>" />
+       <link rel="image_src" href="<?php p($_['previewImage']); ?>" />
 <?php endif; ?>
 
 <div id="notification-container">
index 1b9fd401f780860adb28958b19feb61fb14e2af9..cc51d0b1f821ac7a44e3b7b690e55bc6b2f439a6 100644 (file)
@@ -109,7 +109,9 @@ class ShareControllerTest extends \Test\TestCase {
                        $this->previewManager,
                        $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(),
                        $this->federatedShareProvider,
-                       $this->eventDispatcher
+                       $this->eventDispatcher,
+                       $this->getMockBuilder('\OCP\IL10N')->getMock(),
+                       $this->getMockBuilder('\OCP\Defaults')->getMock()
                );
 
 
@@ -392,6 +394,8 @@ class ShareControllerTest extends \Test\TestCase {
                        'hideFileList' => false,
                        'shareOwner' => 'ownerDisplay',
                        'disclaimer' => 'My disclaimer text',
+                       'shareUrl' => null,
+                       'previewImage' => null
                );
 
                $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
diff --git a/core/img/favicon-fb.png b/core/img/favicon-fb.png
new file mode 100644 (file)
index 0000000..9f0c3f4
Binary files /dev/null and b/core/img/favicon-fb.png differ