1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2024-12-02 06:24:11 +01:00
OwncloudBookmarksOfficial/controller/webviewcontroller.php
ganomi ae81b9dcd2 This is a refactored / rewritten version of the bookmarks app using the app frameworks design and controller features.
Dependency Injection for user and db is used througout the controllers
The Routing features a consistent rest api
The Routing provides some legacy routes, so that for exampe the Android Bookmarks App still works.

There is a publicly available api that provides access to bookmarks per user.
(This is usefull in connection with the WP Plugin https://github.com/mario-nolte/oc2wp-bookmarks)
2014-11-26 12:24:18 +01:00

60 lines
1.6 KiB
PHP

<?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;
use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
use \OCP\IDb;
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
class WebViewController extends Controller {
private $userId;
private $urlgenerator;
private $db;
public function __construct($appName, IRequest $request, $userId, $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);
return new TemplateResponse('bookmarks', 'main', $params);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function bookmarklet($url = "", $title = "") {
$bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db);
$description = "";
if ($bookmarkExists != false){
$bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db);
$description = $bookmark['description'];
}
$params = array('url' => $url, 'title' => $title, 'description' => $description, 'bookmarkExists' => $bookmarkExists);
return new TemplateResponse('bookmarks', 'addBookmarklet', $params); // templates/main.php
}
}