Skip to content

Commit a06fb63

Browse files
committed
add opengraph support & clean unused routes
1 parent 0303c80 commit a06fb63

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

appinfo/application.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,16 @@ public function __construct($params=[]) {
5555
$mailer = $c->getServer()->getMailer();
5656
$l10n = $c->getServer()->getL10N($c->query('AppName'));
5757
$defaults = new \OCP\Defaults();
58+
$urlGenerator = $c->getServer()->getURLGenerator();
5859

59-
return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults);
60+
return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults, $urlGenerator);
6061
});
6162
$container->registerService('ProxyController', function(IAppContainer $c) {
6263
$request = $c->query('Request');
6364
$client = $c->getServer()->getHTTPClientService();
6465

6566
return new Controller\ProxyController($c->getAppName(), $request, $client);
6667
});
67-
$container->registerService('PublicController', function(IAppContainer $c) {
68-
$request = $c->query('Request');
69-
$userSession = $c->getServer()->getUserSession();
70-
$config = $c->getServer()->getConfig();
71-
72-
return new Controller\PublicController($c->getAppName(), $request, $userSession, $config);
73-
});
7468
}
7569

7670
/**

appinfo/routes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,5 @@
4040
['name' => 'contact#searchLocation', 'url' => '/v1/autocompletion/location', 'verb' => 'GET'],
4141

4242
['name' => 'proxy#proxy', 'url' => '/v1/proxy', 'verb' => 'GET'],
43-
// Public
44-
['name' => 'public#index', 'url' => '/public/{calendarid}', 'verb' => 'GET'],
4543
]
4644
];

controller/viewcontroller.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@
3636
use OCP\IRequest;
3737
use OCP\IUserSession;
3838
use OCP\Mail\IMailer;
39+
use OCP\IURLGenerator;
3940

4041
class ViewController extends Controller {
4142

43+
/**
44+
* @var IURLGenerator
45+
*/
46+
private $urlGenerator;
47+
4248
/**
4349
* @var IConfig
4450
*/
@@ -72,15 +78,17 @@ class ViewController extends Controller {
7278
* @param IMailer $mailer
7379
* @param L10N $l10N
7480
* @param Defaults $defaults
81+
* @param IURLGenerator $urlGenerator
7582
*/
7683
public function __construct($appName, IRequest $request,
77-
IUserSession $userSession, IConfig $config, IMailer $mailer, L10N $l10N, Defaults $defaults) {
84+
IUserSession $userSession, IConfig $config, IMailer $mailer, L10N $l10N, Defaults $defaults, IURLGenerator $urlGenerator) {
7885
parent::__construct($appName, $request);
7986
$this->config = $config;
8087
$this->userSession = $userSession;
8188
$this->mailer = $mailer;
8289
$this->l10n = $l10N;
8390
$this->defaults = $defaults;
91+
$this->urlGenerator = $urlGenerator;
8492
}
8593

8694
/**
@@ -110,9 +118,9 @@ public function index() {
110118
$skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no');
111119
$weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no');
112120
$defaultColor = $this->config->getAppValue('theming', 'color', '#0082C9');
113-
114-
$webCalWorkaround = $runningOnNextcloud10OrLater ? 'no' : 'yes';
115121

122+
$webCalWorkaround = $runningOnNextcloud10OrLater ? 'no' : 'yes';
123+
116124
return new TemplateResponse('calendar', 'main', [
117125
'appVersion' => $appVersion,
118126
'defaultView' => $defaultView,
@@ -152,6 +160,8 @@ public function publicIndex() {
152160
'emailAddress' => '',
153161
'supportsClass' => $supportsClass,
154162
'isPublic' => true,
163+
'shareURL' => $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . $this->request->getRequestUri(),
164+
'previewImage' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png')),
155165
], 'public');
156166
$response->addHeader('X-Frame-Options', 'ALLOW');
157167
$csp = new ContentSecurityPolicy();

templates/main.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
2222
*
2323
*/
24+
25+
/* OpenGraph */
26+
OCP\Util::addHeader('meta', ['property' => "og:title", 'content' => $theme->getName() . ' - ' . $theme->getSlogan()]);
27+
OCP\Util::addHeader('meta', ['property' => "og:site_name", 'content' => $theme->getName()]);
28+
OCP\Util::addHeader('meta', ['property' => "og:url", 'content' => $_['shareURL']]);
29+
OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]);
30+
OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $_['previewImage']]);
31+
2432
$styles = [
2533
'../js/vendor/fullcalendar/dist/fullcalendar',
2634
'../js/vendor/jquery-timepicker/jquery.ui.timepicker',

tests/unit/controller/viewcontrollerTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class ViewControllerTest extends \PHPUnit_Framework_TestCase {
6161
private $mailer;
6262
private $l10n;
6363
private $defaults;
64+
private $urlGenerator;
6465

6566
private $dummyUser;
6667

@@ -94,8 +95,12 @@ public function setUp() {
9495
->disableOriginalConstructor()
9596
->getMock();
9697

98+
$this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')
99+
->disableOriginalConstructor()
100+
->getMock();
101+
97102
$this->controller = new ViewController($this->appName, $this->request,
98-
$this->userSession, $this->config, $this->mailer, $this->l10n, $this->defaults);
103+
$this->userSession, $this->config, $this->mailer, $this->l10n, $this->defaults, $this->urlGenerator);
99104
}
100105

101106
/**
@@ -218,7 +223,9 @@ public function testPublicIndex($isAssetPipelineEnabled, $showAssetPipelineError
218223
'defaultView' => 'month',
219224
'emailAddress' => '',
220225
'supportsClass' => $expectsSupportsClass,
221-
'isPublic' => true
226+
'isPublic' => true,
227+
'shareURL' => '://',
228+
'previewImage' => null,
222229
], $actual->getParams());
223230
$this->assertEquals('main', $actual->getTemplateName());
224231
}

0 commit comments

Comments
 (0)