|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - bookmarks |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Stefan Klemm <[email protected]> |
|
10
|
|
|
* @copyright Stefan Klemm 2014 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace OCA\Bookmarks\Controller; |
|
14
|
|
|
|
|
15
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
|
16
|
|
|
use \OCP\IRequest; |
|
17
|
|
|
use \OCP\AppFramework\Http\TemplateResponse; |
|
18
|
|
|
use \OCP\AppFramework\Controller; |
|
19
|
|
|
use \OCP\IDb; |
|
20
|
|
|
use \OCA\Bookmarks\Controller\Lib\Bookmarks; |
|
21
|
|
|
use OCP\IURLGenerator; |
|
22
|
|
|
|
|
23
|
|
|
class WebViewController extends Controller { |
|
24
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $userId; |
|
27
|
|
|
|
|
28
|
|
|
/** @var IURLGenerator */ |
|
29
|
|
|
private $urlgenerator; |
|
30
|
|
|
|
|
31
|
|
|
/** @var IDb */ |
|
32
|
|
|
private $db; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* WebViewController constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $appName |
|
38
|
|
|
* @param IRequest $request |
|
39
|
|
|
* @param $userId |
|
40
|
|
|
* @param IURLGenerator $urlgenerator |
|
41
|
|
|
* @param IDb $db |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct($appName, IRequest $request, $userId, IURLGenerator $urlgenerator, IDb $db) { |
|
44
|
|
|
parent::__construct($appName, $request); |
|
45
|
|
|
$this->userId = $userId; |
|
46
|
|
|
$this->urlgenerator = $urlgenerator; |
|
47
|
|
|
$this->db = $db; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @NoAdminRequired |
|
52
|
|
|
* @NoCSRFRequired |
|
53
|
|
|
*/ |
|
54
|
|
|
public function index() { |
|
55
|
|
|
$bookmarkleturl = $this->urlgenerator->getAbsoluteURL('index.php/apps/bookmarks/bookmarklet'); |
|
56
|
|
|
$params = array('user' => $this->userId, 'bookmarkleturl' => $bookmarkleturl); |
|
57
|
|
|
|
|
58
|
|
|
$policy = new ContentSecurityPolicy(); |
|
59
|
|
|
$policy->addAllowedFrameDomain("'self'"); |
|
60
|
|
|
|
|
61
|
|
|
$response = new TemplateResponse('bookmarks', 'main', $params); |
|
62
|
|
|
$response->setContentSecurityPolicy($policy); |
|
63
|
|
|
return $response; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $url |
|
68
|
|
|
* @param string $title |
|
69
|
|
|
* @return TemplateResponse |
|
70
|
|
|
* |
|
71
|
|
|
* @NoAdminRequired |
|
72
|
|
|
* @NoCSRFRequired |
|
73
|
|
|
*/ |
|
74
|
|
|
public function bookmarklet($url = "", $title = "") { |
|
75
|
|
|
$bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db); |
|
76
|
|
|
$description = ""; |
|
77
|
|
|
$tags = []; |
|
78
|
|
|
if ($bookmarkExists !== false){ |
|
79
|
|
|
$bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db); |
|
|
|
|
|
|
80
|
|
|
$description = $bookmark['description']; |
|
81
|
|
|
$tags = $bookmark['tags']; |
|
82
|
|
|
} |
|
83
|
|
|
$params = array( |
|
84
|
|
|
'url' => $url, |
|
85
|
|
|
'title' => $title, |
|
86
|
|
|
'description' => $description, |
|
87
|
|
|
'bookmarkExists'=> $bookmarkExists, |
|
88
|
|
|
'tags' => $tags |
|
89
|
|
|
); |
|
90
|
|
|
return new TemplateResponse('bookmarks', 'addBookmarklet', $params); // templates/main.php |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: