diff options
author | Joas Schilling <coding@schilljs.com> | 2017-03-09 17:37:20 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-03-09 17:37:20 +0300 |
commit | ac797ec57ddd71cd84b47e2b3741e94d8c94ed91 (patch) | |
tree | 2d9ad2c168587c14e1a760bdd66cd69cc62614ec | |
parent | f5b9daa01550a5a46f088ba7af8c4a4efee57c86 (diff) |
Move displaying to a controller
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | appinfo/app.php | 2 | ||||
-rw-r--r-- | appinfo/routes.php | 8 | ||||
-rw-r--r-- | css/style.css | 15 | ||||
-rw-r--r-- | index.php | 47 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 56 | ||||
-rw-r--r-- | templates/frame.php | 30 |
6 files changed, 99 insertions, 59 deletions
diff --git a/appinfo/app.php b/appinfo/app.php index 8557ff5..8b41035 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -32,7 +32,7 @@ if (!empty($sites)) { return [ 'id' => 'external_index' . ($i + 1), 'order' => 80 + $i, - 'href' => $urlGenerator->linkToRoute('external_index', ['id'=> $i + 1]), + 'href' => $urlGenerator->linkToRoute('external.page.showPage', ['id'=> $i + 1]), 'icon' => $urlGenerator->imagePath('external', !empty($sites[$i][2]) ? $sites[$i][2] : 'external.svg'), 'name' => $sites[$i][0], ]; diff --git a/appinfo/routes.php b/appinfo/routes.php index d6cf34d..2fc33e6 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -6,7 +6,11 @@ */ /** @var $this \OCP\Route\IRouter */ -$this->create('external_index', '/{id}') - ->actionInclude('external/index.php'); $this->create('external_ajax_setsites', 'ajax/setsites.php') ->actionInclude('external/ajax/setsites.php'); + +return [ + 'routes' => [ + ['name' => 'page#showPage', 'url' => '/{id}', 'verb' => 'GET'], + ], +]; diff --git a/css/style.css b/css/style.css index bbf8b2e..c2af138 100644 --- a/css/style.css +++ b/css/style.css @@ -1,14 +1,17 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- / -/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */ - .site_url { - width: 250px; + width: 250px; } .delete_button { - display: none; + display: none; } .external_sites { - width: 470px; + width: 470px; +} + +#ifm { + display: block; + width: 100%; + height: 100%; } diff --git a/index.php b/index.php deleted file mode 100644 index aee54d4..0000000 --- a/index.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -/** - * ownCloud - External plugin - * - * @author Frank Karlitschek - * @copyright 2012 Frank Karlitschek frank@owncloud.org - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -use OCA\External\External; - -OCP\JSON::checkAppEnabled('external'); -OCP\User::checkLoggedIn(); -OCP\Util::addStyle( 'external', 'style'); - -$id = isset($_GET['id']) ? (int)$_GET['id'] : 1; - -$sites = External::getSites(); -if (sizeof($sites) >= $id) { - $url = $sites[$id - 1][1]; - OCP\App::setActiveNavigationEntry('external_index' . $id); - - $tmpl = new OCP\Template('external', 'frame', 'user'); - //overwrite x-frame-options - header('X-Frame-Options: ALLOW-FROM *'); - - $tmpl->assign('url', $url); - $tmpl->printPage(); -} else { - \OC_Util::redirectToDefaultPage(); -} - diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php new file mode 100644 index 0000000..4818d2d --- /dev/null +++ b/lib/Controller/PageController.php @@ -0,0 +1,56 @@ +<?php +/** + * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\External\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\TemplateResponse; + +class PageController extends Controller { + + /** + * @NoAdminRequired + * @NoCSRFRequired + * + * @param int $id + * @return TemplateResponse|RedirectResponse + */ + public function showPage($id) { + + $sites = \OCA\External\External::getSites(); + if (isset($sites[$id - 1])) { + $url = $sites[$id - 1][1]; + \OCP\App::setActiveNavigationEntry('external_index' . $id); + + $response = new TemplateResponse('external', 'frame', [ + 'url' => $url + ], 'user'); + $policy = new ContentSecurityPolicy(); + $policy->addAllowedChildSrcDomain('*'); + $response->setContentSecurityPolicy($policy); + return $response; + } else { + return new RedirectResponse(\OC_Util::getDefaultPageUrl()); + } + } +} diff --git a/templates/frame.php b/templates/frame.php index 212bd9a..f5c5437 100644 --- a/templates/frame.php +++ b/templates/frame.php @@ -1,5 +1,29 @@ -<iframe src="<?php p($_['url']); ?>" width="100%" height="100%" id="ifm" style="display: block;"></iframe> +<?php +/** + * @copyright Copyright (c) 2012 Frank Karlitschek <frank@karlitschek.de> + * + * @author Frank Karlitschek <frank@karlitschek.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +script('external', 'external'); +style('external', 'style'); -<?php -OCP\Util::addscript('external', 'external'); +/** @var array $_ */ +?> +<iframe id="ifm" src="<?php p($_['url']); ?>"></iframe> |