2014-11-25 22:43:48 +01:00
|
|
|
<?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;
|
2014-11-25 22:43:48 +01:00
|
|
|
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;
|
2014-11-25 22:43:48 +01:00
|
|
|
|
|
|
|
class WebViewController extends Controller {
|
|
|
|
|
2016-08-06 11:32:18 +02:00
|
|
|
/** @var string */
|
2014-11-25 22:43:48 +01:00
|
|
|
private $userId;
|
2016-08-06 11:32:18 +02:00
|
|
|
|
|
|
|
/** @var IURLGenerator */
|
2014-11-25 22:43:48 +01:00
|
|
|
private $urlgenerator;
|
2016-08-06 11:32:18 +02:00
|
|
|
|
|
|
|
/** @var IDb */
|
2014-11-25 22:43:48 +01:00
|
|
|
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) {
|
2014-11-25 22:43:48 +01:00
|
|
|
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;
|
2014-11-25 22:43:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-06 11:32:18 +02:00
|
|
|
* @param string $url
|
|
|
|
* @param string $title
|
|
|
|
* @return TemplateResponse
|
|
|
|
*
|
2014-11-25 22:43:48 +01:00
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function bookmarklet($url = "", $title = "") {
|
|
|
|
$bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db);
|
|
|
|
$description = "";
|
2015-03-08 13:38:54 +01:00
|
|
|
$tags = [];
|
2015-07-14 14:24:13 +02:00
|
|
|
if ($bookmarkExists !== false){
|
2014-11-25 22:43:48 +01:00
|
|
|
$bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db);
|
|
|
|
$description = $bookmark['description'];
|
2015-03-08 13:38:54 +01:00
|
|
|
$tags = $bookmark['tags'];
|
2014-11-25 22:43:48 +01:00
|
|
|
}
|
2015-03-08 13:38:54 +01:00
|
|
|
$params = array(
|
|
|
|
'url' => $url,
|
|
|
|
'title' => $title,
|
|
|
|
'description' => $description,
|
|
|
|
'bookmarkExists'=> $bookmarkExists,
|
|
|
|
'tags' => $tags
|
|
|
|
);
|
2014-11-25 22:43:48 +01:00
|
|
|
return new TemplateResponse('bookmarks', 'addBookmarklet', $params); // templates/main.php
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|