From 674af792a2dc857d9f4cc1d388241db2d5087656 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 19 Sep 2016 11:52:08 +0200 Subject: [PATCH] add opengraph support & clean unused routes --- appinfo/application.php | 10 ++-------- appinfo/routes.php | 2 -- controller/viewcontroller.php | 16 +++++++++++++--- templates/main.php | 8 ++++++++ tests/unit/controller/viewcontrollerTest.php | 11 +++++++++-- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/appinfo/application.php b/appinfo/application.php index 510fa0d795..ea0c71f377 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -55,8 +55,9 @@ public function __construct($params=[]) { $mailer = $c->getServer()->getMailer(); $l10n = $c->getServer()->getL10N($c->query('AppName')); $defaults = new \OCP\Defaults(); + $urlGenerator = $c->getServer()->getURLGenerator(); - return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults); + return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults, $urlGenerator); }); $container->registerService('ProxyController', function(IAppContainer $c) { $request = $c->query('Request'); @@ -64,13 +65,6 @@ public function __construct($params=[]) { return new Controller\ProxyController($c->getAppName(), $request, $client); }); - $container->registerService('PublicController', function(IAppContainer $c) { - $request = $c->query('Request'); - $userSession = $c->getServer()->getUserSession(); - $config = $c->getServer()->getConfig(); - - return new Controller\PublicController($c->getAppName(), $request, $userSession, $config); - }); } /** diff --git a/appinfo/routes.php b/appinfo/routes.php index c92fd05075..812c0832b5 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -40,7 +40,5 @@ ['name' => 'contact#searchLocation', 'url' => '/v1/autocompletion/location', 'verb' => 'GET'], ['name' => 'proxy#proxy', 'url' => '/v1/proxy', 'verb' => 'GET'], - // Public - ['name' => 'public#index', 'url' => '/public/{calendarid}', 'verb' => 'GET'], ] ]; diff --git a/controller/viewcontroller.php b/controller/viewcontroller.php index 6df28e5b37..8e50a65bfd 100644 --- a/controller/viewcontroller.php +++ b/controller/viewcontroller.php @@ -36,9 +36,15 @@ use OCP\IRequest; use OCP\IUserSession; use OCP\Mail\IMailer; +use OCP\IURLGenerator; class ViewController extends Controller { + /** + * @var IURLGenerator + */ + private $urlGenerator; + /** * @var IConfig */ @@ -72,15 +78,17 @@ class ViewController extends Controller { * @param IMailer $mailer * @param L10N $l10N * @param Defaults $defaults + * @param IURLGenerator $urlGenerator */ public function __construct($appName, IRequest $request, - IUserSession $userSession, IConfig $config, IMailer $mailer, L10N $l10N, Defaults $defaults) { + IUserSession $userSession, IConfig $config, IMailer $mailer, L10N $l10N, Defaults $defaults, IURLGenerator $urlGenerator) { parent::__construct($appName, $request); $this->config = $config; $this->userSession = $userSession; $this->mailer = $mailer; $this->l10n = $l10N; $this->defaults = $defaults; + $this->urlGenerator = $urlGenerator; } /** @@ -110,9 +118,9 @@ public function index() { $skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no'); $weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no'); $defaultColor = $this->config->getAppValue('theming', 'color', '#0082C9'); - - $webCalWorkaround = $runningOnNextcloud10OrLater ? 'no' : 'yes'; + $webCalWorkaround = $runningOnNextcloud10OrLater ? 'no' : 'yes'; + return new TemplateResponse('calendar', 'main', [ 'appVersion' => $appVersion, 'defaultView' => $defaultView, @@ -152,6 +160,8 @@ public function publicIndex() { 'emailAddress' => '', 'supportsClass' => $supportsClass, 'isPublic' => true, + 'shareURL' => $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . $this->request->getRequestUri(), + 'previewImage' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png')), ], 'public'); $response->addHeader('X-Frame-Options', 'ALLOW'); $csp = new ContentSecurityPolicy(); diff --git a/templates/main.php b/templates/main.php index 1b3de21b3d..3472e8ac92 100644 --- a/templates/main.php +++ b/templates/main.php @@ -21,6 +21,14 @@ * License along with this library. If not, see . * */ + + /* OpenGraph */ + OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $theme->getName() . ' - ' . $theme->getSlogan()]); + 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']]); + $styles = [ '../js/vendor/fullcalendar/dist/fullcalendar', '../js/vendor/jquery-timepicker/jquery.ui.timepicker', diff --git a/tests/unit/controller/viewcontrollerTest.php b/tests/unit/controller/viewcontrollerTest.php index ba6300ef3a..2c2d4161c0 100755 --- a/tests/unit/controller/viewcontrollerTest.php +++ b/tests/unit/controller/viewcontrollerTest.php @@ -61,6 +61,7 @@ class ViewControllerTest extends \PHPUnit_Framework_TestCase { private $mailer; private $l10n; private $defaults; + private $urlGenerator; private $dummyUser; @@ -94,8 +95,12 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); + $this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator') + ->disableOriginalConstructor() + ->getMock(); + $this->controller = new ViewController($this->appName, $this->request, - $this->userSession, $this->config, $this->mailer, $this->l10n, $this->defaults); + $this->userSession, $this->config, $this->mailer, $this->l10n, $this->defaults, $this->urlGenerator); } /** @@ -218,7 +223,9 @@ public function testPublicIndex($isAssetPipelineEnabled, $showAssetPipelineError 'defaultView' => 'month', 'emailAddress' => '', 'supportsClass' => $expectsSupportsClass, - 'isPublic' => true + 'isPublic' => true, + 'shareURL' => '://', + 'previewImage' => null, ], $actual->getParams()); $this->assertEquals('main', $actual->getTemplateName()); }