Skip to content

Commit

Permalink
add opengraph support & clean unused routes
Browse files Browse the repository at this point in the history
  • Loading branch information
tcitworld committed Sep 26, 2016
1 parent dce3a46 commit 674af79
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
10 changes: 2 additions & 8 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,16 @@ 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');
$client = $c->getServer()->getHTTPClientService();

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);
});
}

/**
Expand Down
2 changes: 0 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]
];
16 changes: 13 additions & 3 deletions controller/viewcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions templates/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

/* 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',
Expand Down
11 changes: 9 additions & 2 deletions tests/unit/controller/viewcontrollerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ViewControllerTest extends \PHPUnit_Framework_TestCase {
private $mailer;
private $l10n;
private $defaults;
private $urlGenerator;

private $dummyUser;

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 674af79

Please sign in to comment.