1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2024-12-01 05:24:11 +01:00
OwncloudBookmarksOfficial/controller/webviewcontroller.php

94 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* ownCloud - bookmarks
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Stefan Klemm <mail@stefan-klemm.de>
* @copyright Stefan Klemm 2014
*/
namespace OCA\Bookmarks\Controller;
2015-07-22 21:21:59 +02:00
use OCP\AppFramework\Http\ContentSecurityPolicy;
use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
use \OCP\IDb;
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
2016-08-06 11:32:18 +02:00
use OCP\IURLGenerator;
class WebViewController extends Controller {
2016-08-06 11:32:18 +02:00
/** @var string */
private $userId;
2016-08-06 11:32:18 +02:00
/** @var IURLGenerator */
private $urlgenerator;
2016-08-06 11:32:18 +02:00
/** @var IDb */
private $db;
2016-08-06 11:32:18 +02:00
/**
* WebViewController constructor.
*
* @param string $appName
* @param IRequest $request
* @param $userId
* @param IURLGenerator $urlgenerator
* @param IDb $db
*/
public function __construct($appName, IRequest $request, $userId, IURLGenerator $urlgenerator, IDb $db) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->urlgenerator = $urlgenerator;
$this->db = $db;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index() {
$bookmarkleturl = $this->urlgenerator->getAbsoluteURL('index.php/apps/bookmarks/bookmarklet');
$params = array('user' => $this->userId, 'bookmarkleturl' => $bookmarkleturl);
2015-07-22 21:21:59 +02:00
$policy = new ContentSecurityPolicy();
$policy->addAllowedFrameDomain("'self'");
$response = new TemplateResponse('bookmarks', 'main', $params);
$response->setContentSecurityPolicy($policy);
return $response;
}
/**
2016-08-06 11:32:18 +02:00
* @param string $url
* @param string $title
* @return TemplateResponse
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function bookmarklet($url = "", $title = "") {
$bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db);
$description = "";
$tags = [];
if ($bookmarkExists !== false){
$bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db);
$description = $bookmark['description'];
$tags = $bookmark['tags'];
}
$params = array(
'url' => $url,
'title' => $title,
'description' => $description,
'bookmarkExists'=> $bookmarkExists,
'tags' => $tags
);
return new TemplateResponse('bookmarks', 'addBookmarklet', $params); // templates/main.php
}
}