mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-03-21 12:29:14 +01:00
Make Bookmarks class non-static
This commit is contained in:
parent
7910aef7c3
commit
38f9fc7942
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
namespace OCA\Bookmarks\AppInfo;
|
namespace OCA\Bookmarks\AppInfo;
|
||||||
|
|
||||||
|
use OCA\Bookmarks\Controller\Lib\Bookmarks;
|
||||||
use \OCP\AppFramework\App;
|
use \OCP\AppFramework\App;
|
||||||
use \OCP\IContainer;
|
use \OCP\IContainer;
|
||||||
use \OCA\Bookmarks\Controller\WebViewController;
|
use \OCA\Bookmarks\Controller\WebViewController;
|
||||||
@ -45,25 +46,19 @@ class Application extends App {
|
|||||||
$c->query('Request'),
|
$c->query('Request'),
|
||||||
$uid,
|
$uid,
|
||||||
$c->query('ServerContainer')->getURLGenerator(),
|
$c->query('ServerContainer')->getURLGenerator(),
|
||||||
$c->query('ServerContainer')->getDb()
|
$c->query('ServerContainer')->query(Bookmarks::class)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->registerService('BookmarkController', function($c) {
|
$container->registerService('BookmarkController', function($c) {
|
||||||
if(method_exists($c->query('ServerContainer'), 'getL10NFactory')) {
|
|
||||||
$l = $c->query('ServerContainer')->getL10NFactory()->get('bookmarks');
|
|
||||||
} else {
|
|
||||||
// OC 8.1 compatibility
|
|
||||||
$l = new \OC_L10N('bookmarks');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var IContainer $c */
|
/** @var IContainer $c */
|
||||||
return new BookmarkController(
|
return new BookmarkController(
|
||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
$c->query('Request'),
|
$c->query('Request'),
|
||||||
$c->query('ServerContainer')->getUserSession()->getUser()->getUID(),
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID(),
|
||||||
$c->query('ServerContainer')->getDb(),
|
$c->query('ServerContainer')->getDb(),
|
||||||
$l
|
$c->query('ServerContainer')->getL10NFactory()->get('bookmarks'),
|
||||||
|
$c->query('ServerContainer')->query(Bookmarks::class)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,7 +68,7 @@ class Application extends App {
|
|||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
$c->query('Request'),
|
$c->query('Request'),
|
||||||
$c->query('ServerContainer')->getUserSession()->getUser()->getUID(),
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID(),
|
||||||
$c->query('ServerContainer')->getDb()
|
$c->query('ServerContainer')->query(Bookmarks::class)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -82,7 +77,7 @@ class Application extends App {
|
|||||||
return new PublicController(
|
return new PublicController(
|
||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
$c->query('Request'),
|
$c->query('Request'),
|
||||||
$c->query('ServerContainer')->getDb(),
|
$c->query('ServerContainer')->query(Bookmarks::class),
|
||||||
$c->query('ServerContainer')->getUserManager()
|
$c->query('ServerContainer')->getUserManager()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -27,36 +27,69 @@
|
|||||||
namespace OCA\Bookmarks\Controller\Lib;
|
namespace OCA\Bookmarks\Controller\Lib;
|
||||||
|
|
||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use \OCP\IDb;
|
use OCP\Http\Client\IClientService;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IDb;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\ILogger;
|
||||||
|
|
||||||
class Bookmarks {
|
class Bookmarks {
|
||||||
|
|
||||||
|
/** @var IDb */
|
||||||
|
private $db;
|
||||||
|
|
||||||
|
/** @var IConfig */
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/** @var IL10N */
|
||||||
|
private $l;
|
||||||
|
|
||||||
|
/** @var IClientService */
|
||||||
|
private $httpClientService;
|
||||||
|
|
||||||
|
/** @var ILogger */
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
IDb $db,
|
||||||
|
IConfig $config,
|
||||||
|
IL10N $l,
|
||||||
|
IClientService $httpClientService,
|
||||||
|
ILogger $logger
|
||||||
|
) {
|
||||||
|
$this->db = $db;
|
||||||
|
$this->config = $config;
|
||||||
|
$this->l = $l;
|
||||||
|
$this->httpClientService = $httpClientService;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds all tags for bookmarks
|
* @brief Finds all tags for bookmarks
|
||||||
* @param string $userId UserId
|
* @param string $userId UserId
|
||||||
* @param IDb $db Database Interface
|
* @param array $filterTags of tag to look for if empty then every tag
|
||||||
* @param filterTags array of tag to look for if empty then every tag
|
* @param int $offset
|
||||||
* @param offset integer offset
|
* @param int $limit
|
||||||
* @param limit integer of item to return
|
* @return array Found Tags
|
||||||
* @return Found Tags
|
|
||||||
*/
|
*/
|
||||||
public static function findTags($userId, IDb $db, $filterTags = array(), $offset = 0, $limit = -1) {
|
public function findTags($userId, $filterTags = [], $offset = 0, $limit = -1) {
|
||||||
$params = array_merge($filterTags, $filterTags);
|
$params = array_merge($filterTags, $filterTags);
|
||||||
array_unshift($params, $userId);
|
array_unshift($params, $userId);
|
||||||
$not_in = '';
|
$notIn = '';
|
||||||
if (!empty($filterTags)) {
|
if (!empty($filterTags)) {
|
||||||
$exist_clause = " AND exists (select 1 from `*PREFIX*bookmarks_tags`
|
$existClause = " AND exists (select 1 from `*PREFIX*bookmarks_tags`
|
||||||
`t2` where `t2`.`bookmark_id` = `t`.`bookmark_id` and `tag` = ?) ";
|
`t2` where `t2`.`bookmark_id` = `t`.`bookmark_id` and `tag` = ?) ";
|
||||||
|
|
||||||
$not_in = ' AND `tag` not in (' . implode(',', array_fill(0, count($filterTags), '?')) . ')' .
|
$notIn = ' AND `tag` not in (' . implode(',', array_fill(0, count($filterTags), '?')) . ')' .
|
||||||
str_repeat($exist_clause, count($filterTags));
|
str_repeat($existClause, count($filterTags));
|
||||||
}
|
}
|
||||||
$sql = 'SELECT tag, count(*) as nbr from *PREFIX*bookmarks_tags t ' .
|
$sql = 'SELECT tag, count(*) AS nbr FROM *PREFIX*bookmarks_tags t ' .
|
||||||
' WHERE EXISTS( SELECT 1 from *PREFIX*bookmarks bm where t.bookmark_id = bm.id and user_id = ?) ' .
|
' WHERE EXISTS( SELECT 1 FROM *PREFIX*bookmarks bm ' .
|
||||||
$not_in .
|
' WHERE t.bookmark_id = bm.id AND user_id = ?) ' .
|
||||||
|
$notIn .
|
||||||
' GROUP BY `tag` ORDER BY `nbr` DESC ';
|
' GROUP BY `tag` ORDER BY `nbr` DESC ';
|
||||||
|
|
||||||
$query = $db->prepareQuery($sql, $limit, $offset);
|
$query = $this->db->prepareQuery($sql, $limit, $offset);
|
||||||
$tags = $query->execute($params)->fetchAll();
|
$tags = $query->execute($params)->fetchAll();
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
@ -65,20 +98,20 @@ class Bookmarks {
|
|||||||
* @brief Finds Bookmark with certain ID
|
* @brief Finds Bookmark with certain ID
|
||||||
* @param int $id BookmarkId
|
* @param int $id BookmarkId
|
||||||
* @param string $userId UserId
|
* @param string $userId UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @return array Specific Bookmark
|
* @return array Specific Bookmark
|
||||||
*/
|
*/
|
||||||
public static function findUniqueBookmark($id, $userId, IDb $db) {
|
public function findUniqueBookmark($id, $userId) {
|
||||||
$CONFIG_DBTYPE = \OCP\Config::getSystemValue('dbtype', 'sqlite');
|
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
||||||
if ($CONFIG_DBTYPE == 'pgsql') {
|
if ($dbType == 'pgsql') {
|
||||||
$group_fct = 'array_agg(`tag`)';
|
$groupFunction = 'array_agg(`tag`)';
|
||||||
} else {
|
} else {
|
||||||
$group_fct = 'GROUP_CONCAT(`tag`)';
|
$groupFunction = 'GROUP_CONCAT(`tag`)';
|
||||||
}
|
}
|
||||||
$sql = "SELECT *, (select $group_fct from `*PREFIX*bookmarks_tags` where `bookmark_id` = `b`.`id`) as `tags`
|
$sql = "SELECT *, (SELECT $groupFunction FROM `*PREFIX*bookmarks_tags`
|
||||||
|
WHERE `bookmark_id` = `b`.`id`) AS `tags`
|
||||||
FROM `*PREFIX*bookmarks` `b`
|
FROM `*PREFIX*bookmarks` `b`
|
||||||
WHERE `user_id` = ? AND `id` = ?";
|
WHERE `user_id` = ? AND `id` = ?";
|
||||||
$query = $db->prepareQuery($sql);
|
$query = $this->db->prepareQuery($sql);
|
||||||
$result = $query->execute(array($userId, $id))->fetchRow();
|
$result = $query->execute(array($userId, $id))->fetchRow();
|
||||||
$result['tags'] = explode(',', $result['tags']);
|
$result['tags'] = explode(',', $result['tags']);
|
||||||
return $result;
|
return $result;
|
||||||
@ -88,14 +121,13 @@ class Bookmarks {
|
|||||||
* @brief Check if an URL is bookmarked
|
* @brief Check if an URL is bookmarked
|
||||||
* @param string $url Url of a possible bookmark
|
* @param string $url Url of a possible bookmark
|
||||||
* @param string $userId UserId
|
* @param string $userId UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @return boolean if the url is already bookmarked
|
* @return boolean if the url is already bookmarked
|
||||||
*/
|
*/
|
||||||
public static function bookmarkExists($url, $userId, IDb $db) {
|
public function bookmarkExists($url, $userId) {
|
||||||
$enc_url = htmlspecialchars_decode($url);
|
$encodedUrl = htmlspecialchars_decode($url);
|
||||||
$sql = "SELECT id from `*PREFIX*bookmarks` where `url` = ? and `user_id` = ?";
|
$sql = "SELECT id FROM `*PREFIX*bookmarks` WHERE `url` = ? AND `user_id` = ?";
|
||||||
$query = $db->prepareQuery($sql);
|
$query = $this->db->prepareQuery($sql);
|
||||||
$result = $query->execute(array($enc_url, $userId))->fetchRow();
|
$result = $query->execute(array($encodedUrl, $userId))->fetchRow();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $result['id'];
|
return $result['id'];
|
||||||
} else {
|
} else {
|
||||||
@ -106,7 +138,6 @@ class Bookmarks {
|
|||||||
/**
|
/**
|
||||||
* @brief Finds all bookmarks, matching the filter
|
* @brief Finds all bookmarks, matching the filter
|
||||||
* @param string $userid UserId
|
* @param string $userid UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param int $offset offset
|
* @param int $offset offset
|
||||||
* @param string $sqlSortColumn result with this column
|
* @param string $sqlSortColumn result with this column
|
||||||
* @param string|array $filters filters can be: empty -> no filter, a string -> filter this, a string array -> filter for all strings
|
* @param string|array $filters filters can be: empty -> no filter, a string -> filter this, a string array -> filter for all strings
|
||||||
@ -115,12 +146,20 @@ class Bookmarks {
|
|||||||
* @param bool $public check if only public bookmarks should be returned
|
* @param bool $public check if only public bookmarks should be returned
|
||||||
* @param array $requestedAttributes select all the attributes that should be returned. default is * + tags
|
* @param array $requestedAttributes select all the attributes that should be returned. default is * + tags
|
||||||
* @param string $tagFilterConjunction select wether the filterTagOnly should filter with an AND or an OR conjunction
|
* @param string $tagFilterConjunction select wether the filterTagOnly should filter with an AND or an OR conjunction
|
||||||
* @return Collection of specified bookmarks
|
* @return array Collection of specified bookmarks
|
||||||
*/
|
*/
|
||||||
public static function findBookmarks(
|
public function findBookmarks(
|
||||||
$userid, IDb $db, $offset, $sqlSortColumn, $filters, $filterTagOnly, $limit = 10, $public = false, $requestedAttributes = null, $tagFilterConjunction = "and") {
|
$userid,
|
||||||
|
$offset,
|
||||||
$CONFIG_DBTYPE = \OCP\Config::getSystemValue('dbtype', 'sqlite');
|
$sqlSortColumn,
|
||||||
|
$filters,
|
||||||
|
$filterTagOnly,
|
||||||
|
$limit = 10,
|
||||||
|
$public = false,
|
||||||
|
$requestedAttributes = null,
|
||||||
|
$tagFilterConjunction = "and"
|
||||||
|
) {
|
||||||
|
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
||||||
if (is_string($filters)) {
|
if (is_string($filters)) {
|
||||||
$filters = array($filters);
|
$filters = array($filters);
|
||||||
}
|
}
|
||||||
@ -143,14 +182,14 @@ class Bookmarks {
|
|||||||
$toSelect = implode(",", array_intersect($tableAttributes, $requestedAttributes));
|
$toSelect = implode(",", array_intersect($tableAttributes, $requestedAttributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($CONFIG_DBTYPE == 'pgsql') {
|
if ($dbType == 'pgsql') {
|
||||||
$sql = "SELECT " . $toSelect . " FROM (SELECT *, (select array_to_string(array_agg(`tag`),',')
|
$sql = "SELECT " . $toSelect . " FROM (SELECT *, (select array_to_string(array_agg(`tag`),',')
|
||||||
from `*PREFIX*bookmarks_tags` where `bookmark_id` = `b2`.`id`) as `tags`
|
FROM `*PREFIX*bookmarks_tags` WHERE `bookmark_id` = `b2`.`id`) AS `tags`
|
||||||
FROM `*PREFIX*bookmarks` `b2`
|
FROM `*PREFIX*bookmarks` `b2`
|
||||||
WHERE `user_id` = ? ) as `b` WHERE true ";
|
WHERE `user_id` = ? ) as `b` WHERE true ";
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT " . $toSelect . ", (SELECT GROUP_CONCAT(`tag`) from `*PREFIX*bookmarks_tags`
|
$sql = "SELECT " . $toSelect . ", (SELECT GROUP_CONCAT(`tag`) FROM `*PREFIX*bookmarks_tags`
|
||||||
WHERE `bookmark_id` = `b`.`id`) as `tags`
|
WHERE `bookmark_id` = `b`.`id`) AS `tags`
|
||||||
FROM `*PREFIX*bookmarks` `b`
|
FROM `*PREFIX*bookmarks` `b`
|
||||||
WHERE `user_id` = ? ";
|
WHERE `user_id` = ? ";
|
||||||
}
|
}
|
||||||
@ -162,7 +201,7 @@ class Bookmarks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($filters) > 0) {
|
if (count($filters) > 0) {
|
||||||
Bookmarks::findBookmarksBuildFilter($sql, $params, $filters, $filterTagOnly, $tagFilterConjunction, $CONFIG_DBTYPE);
|
$this->findBookmarksBuildFilter($sql, $params, $filters, $filterTagOnly, $tagFilterConjunction, $dbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($sqlSortColumn, $tableAttributes)) {
|
if (!in_array($sqlSortColumn, $tableAttributes)) {
|
||||||
@ -174,7 +213,7 @@ class Bookmarks {
|
|||||||
$offset = null;
|
$offset = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $db->prepareQuery($sql, $limit, $offset);
|
$query = $this->db->prepareQuery($sql, $limit, $offset);
|
||||||
$results = $query->execute($params)->fetchAll();
|
$results = $query->execute($params)->fetchAll();
|
||||||
$bookmarks = array();
|
$bookmarks = array();
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
@ -188,7 +227,7 @@ class Bookmarks {
|
|||||||
return $bookmarks;
|
return $bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function findBookmarksBuildFilter(&$sql, &$params, $filters, $filterTagOnly, $tagFilterConjunction, $CONFIG_DBTYPE) {
|
private function findBookmarksBuildFilter(&$sql, &$params, $filters, $filterTagOnly, $tagFilterConjunction, $dbType) {
|
||||||
$tagOrSearch = false;
|
$tagOrSearch = false;
|
||||||
$connectWord = 'AND';
|
$connectWord = 'AND';
|
||||||
|
|
||||||
@ -203,9 +242,9 @@ class Bookmarks {
|
|||||||
} else {
|
} else {
|
||||||
$sql .= 'AND';
|
$sql .= 'AND';
|
||||||
}
|
}
|
||||||
$exist_clause = " exists (SELECT `id` FROM `*PREFIX*bookmarks_tags`
|
$existClause = " exists (SELECT `id` FROM `*PREFIX*bookmarks_tags`
|
||||||
`t2` WHERE `t2`.`bookmark_id` = `b`.`id` AND `tag` = ?) ";
|
`t2` WHERE `t2`.`bookmark_id` = `b`.`id` AND `tag` = ?) ";
|
||||||
$sql .= str_repeat($exist_clause . $connectWord, count($filters));
|
$sql .= str_repeat($existClause . $connectWord, count($filters));
|
||||||
if ($tagOrSearch) {
|
if ($tagOrSearch) {
|
||||||
$sql = rtrim($sql, 'OR');
|
$sql = rtrim($sql, 'OR');
|
||||||
$sql .= ')';
|
$sql .= ')';
|
||||||
@ -214,14 +253,14 @@ class Bookmarks {
|
|||||||
}
|
}
|
||||||
$params = array_merge($params, $filters);
|
$params = array_merge($params, $filters);
|
||||||
} else {
|
} else {
|
||||||
if ($CONFIG_DBTYPE == 'mysql') { //Dirty hack to allow usage of alias in where
|
if ($dbType == 'mysql') { //Dirty hack to allow usage of alias in where
|
||||||
$sql .= ' HAVING true ';
|
$sql .= ' HAVING true ';
|
||||||
}
|
}
|
||||||
foreach ($filters as $filter) {
|
foreach ($filters as $filter) {
|
||||||
if ($CONFIG_DBTYPE == 'mysql') {
|
if ($dbType == 'mysql') {
|
||||||
$sql .= ' AND lower( concat(url,title,description,IFNULL(tags,\'\') )) like ? ';
|
$sql .= ' AND lower( concat(url,title,description,IFNULL(tags,\'\') )) like ? ';
|
||||||
} else {
|
} else {
|
||||||
$sql .= ' AND lower(url || title || description || ifnull(tags,\'\') ) like ? ';
|
$sql .= ' AND lower(url || title || description || IFNULL(tags,\'\') ) like ? ';
|
||||||
}
|
}
|
||||||
$params[] = '%' . strtolower($filter) . '%';
|
$params[] = '%' . strtolower($filter) . '%';
|
||||||
}
|
}
|
||||||
@ -231,14 +270,13 @@ class Bookmarks {
|
|||||||
/**
|
/**
|
||||||
* @brief Delete bookmark with specific id
|
* @brief Delete bookmark with specific id
|
||||||
* @param string $userId UserId
|
* @param string $userId UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param int $id Bookmark ID to delete
|
* @param int $id Bookmark ID to delete
|
||||||
* @return boolean Success of operation
|
* @return boolean Success of operation
|
||||||
*/
|
*/
|
||||||
public static function deleteUrl($userId, IDb $db, $id) {
|
public function deleteUrl($userId, $id) {
|
||||||
$user = $userId;
|
$user = $userId;
|
||||||
|
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
SELECT `id` FROM `*PREFIX*bookmarks`
|
SELECT `id` FROM `*PREFIX*bookmarks`
|
||||||
WHERE `id` = ?
|
WHERE `id` = ?
|
||||||
AND `user_id` = ?
|
AND `user_id` = ?
|
||||||
@ -250,14 +288,14 @@ class Bookmarks {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
DELETE FROM `*PREFIX*bookmarks`
|
DELETE FROM `*PREFIX*bookmarks`
|
||||||
WHERE `id` = ?
|
WHERE `id` = ?
|
||||||
");
|
");
|
||||||
|
|
||||||
$query->execute(array($id));
|
$query->execute(array($id));
|
||||||
|
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
DELETE FROM `*PREFIX*bookmarks_tags`
|
DELETE FROM `*PREFIX*bookmarks_tags`
|
||||||
WHERE `bookmark_id` = ?
|
WHERE `bookmark_id` = ?
|
||||||
");
|
");
|
||||||
@ -269,19 +307,17 @@ class Bookmarks {
|
|||||||
/**
|
/**
|
||||||
* @brief Rename a tag
|
* @brief Rename a tag
|
||||||
* @param string $userId UserId
|
* @param string $userId UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param string $old Old Tag Name
|
* @param string $old Old Tag Name
|
||||||
* @param string $new New Tag Name
|
* @param string $new New Tag Name
|
||||||
* @return boolean Success of operation
|
* @return boolean Success of operation
|
||||||
*/
|
*/
|
||||||
public static function renameTag($userId, IDb $db, $old, $new) {
|
public function renameTag($userId, $old, $new) {
|
||||||
$user_id = $userId;
|
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
||||||
$CONFIG_DBTYPE = \OCP\Config::getSystemValue('dbtype', 'sqlite');
|
|
||||||
|
|
||||||
|
|
||||||
if ($CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3') {
|
if ($dbType == 'sqlite' or $dbType == 'sqlite3') {
|
||||||
// Update tags to the new label unless it already exists a tag like this
|
// Update tags to the new label unless it already exists a tag like this
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
UPDATE OR REPLACE `*PREFIX*bookmarks_tags`
|
UPDATE OR REPLACE `*PREFIX*bookmarks_tags`
|
||||||
SET `tag` = ?
|
SET `tag` = ?
|
||||||
WHERE `tag` = ?
|
WHERE `tag` = ?
|
||||||
@ -289,34 +325,24 @@ class Bookmarks {
|
|||||||
WHERE `b`.`user_id` = ? AND `bookmark_id` = `b`.`id`)
|
WHERE `b`.`user_id` = ? AND `bookmark_id` = `b`.`id`)
|
||||||
");
|
");
|
||||||
|
|
||||||
$params = array(
|
$params = [$new, $old, $userId];
|
||||||
$new,
|
|
||||||
$old,
|
|
||||||
$user_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Remove potentialy duplicated tags
|
// Remove potentially duplicated tags
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
DELETE FROM `*PREFIX*bookmarks_tags` as `tgs` WHERE `tgs`.`tag` = ?
|
DELETE FROM `*PREFIX*bookmarks_tags` as `tgs` WHERE `tgs`.`tag` = ?
|
||||||
AND exists( SELECT `id` FROM `*PREFIX*bookmarks` WHERE `user_id` = ?
|
AND exists( SELECT `id` FROM `*PREFIX*bookmarks` WHERE `user_id` = ?
|
||||||
AND `tgs`.`bookmark_id` = `id`)
|
AND `tgs`.`bookmark_id` = `id`)
|
||||||
AND exists( SELECT `t`.`tag` FROM `*PREFIX*bookmarks_tags` `t` where `t`.`tag` = ?
|
AND exists( SELECT `t`.`tag` FROM `*PREFIX*bookmarks_tags` `t` where `t`.`tag` = ?
|
||||||
AND `tgs`.`bookmark_id` = `t`.`bookmark_id`)");
|
AND `tgs`.`bookmark_id` = `t`.`bookmark_id`)");
|
||||||
|
|
||||||
$params = array(
|
$params = [$new, $userId, $new];
|
||||||
$new,
|
|
||||||
$user_id,
|
|
||||||
$new
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
|
|
||||||
|
|
||||||
// Update tags to the new label unless it already exists a tag like this
|
// Update tags to the new label unless it already exists a tag like this
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
UPDATE `*PREFIX*bookmarks_tags`
|
UPDATE `*PREFIX*bookmarks_tags`
|
||||||
SET `tag` = ?
|
SET `tag` = ?
|
||||||
WHERE `tag` = ?
|
WHERE `tag` = ?
|
||||||
@ -324,63 +350,51 @@ class Bookmarks {
|
|||||||
WHERE `b`.`user_id` = ? AND `bookmark_id` = `b`.`id`)
|
WHERE `b`.`user_id` = ? AND `bookmark_id` = `b`.`id`)
|
||||||
");
|
");
|
||||||
|
|
||||||
$params = array(
|
$params = [$new, $old, $userId];
|
||||||
$new,
|
|
||||||
$old,
|
|
||||||
$user_id
|
|
||||||
);
|
|
||||||
|
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Delete a tag
|
* @brief Delete a tag
|
||||||
* @param string $userid UserId
|
* @param string $userid UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param string $old Tag Name to delete
|
* @param string $old Tag Name to delete
|
||||||
* @return boolean Success of operation
|
* @return boolean Success of operation
|
||||||
*/
|
*/
|
||||||
public static function deleteTag($userid, IDb $db, $old) {
|
public function deleteTag($userid, $old) {
|
||||||
|
|
||||||
// Update the record
|
// Update the record
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
DELETE FROM `*PREFIX*bookmarks_tags`
|
DELETE FROM `*PREFIX*bookmarks_tags`
|
||||||
WHERE `tag` = ?
|
WHERE `tag` = ?
|
||||||
AND exists( SELECT `id` FROM `*PREFIX*bookmarks` WHERE `user_id` = ? AND `bookmark_id` = `id`)
|
AND exists( SELECT `id` FROM `*PREFIX*bookmarks` WHERE `user_id` = ? AND `bookmark_id` = `id`)
|
||||||
");
|
");
|
||||||
|
|
||||||
$params = array(
|
$params = [$old, $userid];
|
||||||
$old,
|
|
||||||
$userid,
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $query->execute($params);
|
$result = $query->execute($params);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit a bookmark
|
* Edit a bookmark
|
||||||
|
*
|
||||||
* @param string $userid UserId
|
* @param string $userid UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param int $id The id of the bookmark to edit
|
* @param int $id The id of the bookmark to edit
|
||||||
* @param string $url The url to set
|
* @param string $url The url to set
|
||||||
* @param string $title Name of the bookmark
|
* @param string $title Name of the bookmark
|
||||||
* @param array $tags Simple array of tags to qualify the bookmark (different tags are taken from values)
|
* @param array $tags Simple array of tags to qualify the bookmark (different tags are taken from values)
|
||||||
* @param string $description A longer description about the bookmark
|
* @param string $description A longer description about the bookmark
|
||||||
* @param boolean $is_public True if the bookmark is publishable to not registered users
|
* @param boolean $isPublic True if the bookmark is publishable to not registered users
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public static function editBookmark($userid, IDb $db, $id, $url, $title, $tags = array(), $description = '', $is_public = false) {
|
public function editBookmark($userid, $id, $url, $title, $tags = [], $description = '', $isPublic = false) {
|
||||||
|
|
||||||
$is_public = $is_public ? 1 : 0;
|
$isPublic = $isPublic ? 1 : 0;
|
||||||
$user_id = $userid;
|
|
||||||
|
|
||||||
// Update the record
|
// Update the record
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
UPDATE `*PREFIX*bookmarks` SET
|
UPDATE `*PREFIX*bookmarks` SET
|
||||||
`url` = ?, `title` = ?, `public` = ?, `description` = ?,
|
`url` = ?, `title` = ?, `public` = ?, `description` = ?,
|
||||||
`lastmodified` = UNIX_TIMESTAMP()
|
`lastmodified` = UNIX_TIMESTAMP()
|
||||||
@ -391,87 +405,87 @@ class Bookmarks {
|
|||||||
$params = array(
|
$params = array(
|
||||||
htmlspecialchars_decode($url),
|
htmlspecialchars_decode($url),
|
||||||
htmlspecialchars_decode($title),
|
htmlspecialchars_decode($title),
|
||||||
$is_public,
|
$isPublic,
|
||||||
htmlspecialchars_decode($description),
|
htmlspecialchars_decode($description),
|
||||||
$id,
|
$id,
|
||||||
$user_id,
|
$userid,
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $query->execute($params);
|
$result = $query->execute($params);
|
||||||
|
|
||||||
// Abort the operation if bookmark couldn't be set
|
// Abort the operation if bookmark couldn't be set
|
||||||
// (probably because the user is not allowed to edit this bookmark)
|
// (probably because the user is not allowed to edit this bookmark)
|
||||||
if ($result == 0)
|
if ($result == 0) {
|
||||||
exit();
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
// Remove old tags
|
// Remove old tags
|
||||||
$sql = "DELETE FROM `*PREFIX*bookmarks_tags` WHERE `bookmark_id` = ?";
|
$sql = "DELETE FROM `*PREFIX*bookmarks_tags` WHERE `bookmark_id` = ?";
|
||||||
$query = $db->prepareQuery($sql);
|
$query = $this->db->prepareQuery($sql);
|
||||||
$query->execute(array($id));
|
$query->execute(array($id));
|
||||||
|
|
||||||
// Add New Tags
|
// Add New Tags
|
||||||
self::addTags($db, $id, $tags);
|
$this->addTags($id, $tags);
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a bookmark
|
* Add a bookmark
|
||||||
|
*
|
||||||
* @param string $userid UserId
|
* @param string $userid UserId
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $title Name of the bookmark
|
* @param string $title Name of the bookmark
|
||||||
* @param array $tags Simple array of tags to qualify the bookmark (different tags are taken from values)
|
* @param array $tags Simple array of tags to qualify the bookmark (different tags are taken from values)
|
||||||
* @param string $description A longer description about the bookmark
|
* @param string $description A longer description about the bookmark
|
||||||
* @param boolean $public True if the bookmark is publishable to not registered users
|
* @param boolean $isPublic True if the bookmark is publishable to not registered users
|
||||||
* @return int The id of the bookmark created
|
* @return int The id of the bookmark created
|
||||||
*/
|
*/
|
||||||
public static function addBookmark($userid, IDb $db, $url, $title, $tags = array(), $description = '', $is_public = false) {
|
public function addBookmark($userid, $url, $title, $tags = array(), $description = '', $isPublic = false) {
|
||||||
$public = $is_public ? 1 : 0;
|
$public = $isPublic ? 1 : 0;
|
||||||
$url_without_prefix = trim(substr($url, strpos($url, "://") + 3)); // Removes everything from the url before the "://" pattern (included)
|
$urlWithoutPrefix = trim(substr($url, strpos($url, "://") + 3)); // Removes everything from the url before the "://" pattern (included)
|
||||||
if($url_without_prefix === '') {
|
if($urlWithoutPrefix === '') {
|
||||||
throw new \InvalidArgumentException('Bookmark URL is missing');
|
throw new \InvalidArgumentException('Bookmark URL is missing');
|
||||||
}
|
}
|
||||||
$enc_url_noprefix = htmlspecialchars_decode($url_without_prefix);
|
$decodedUrlNoPrefix = htmlspecialchars_decode($urlWithoutPrefix);
|
||||||
$enc_url = htmlspecialchars_decode($url);
|
$decodedUrl = htmlspecialchars_decode($url);
|
||||||
|
|
||||||
$title = mb_substr($title, 0, 4096);
|
$title = mb_substr($title, 0, 4096);
|
||||||
$description = mb_substr($description, 0, 4096);
|
$description = mb_substr($description, 0, 4096);
|
||||||
|
|
||||||
// Change lastmodified date if the record if already exists
|
// Change lastmodified date if the record if already exists
|
||||||
$sql = "SELECT * from `*PREFIX*bookmarks` WHERE `url` like ? AND `user_id` = ?";
|
$sql = "SELECT * from `*PREFIX*bookmarks` WHERE `url` like ? AND `user_id` = ?";
|
||||||
$query = $db->prepareQuery($sql, 1);
|
$query = $this->db->prepareQuery($sql, 1);
|
||||||
$result = $query->execute(array('%'.$enc_url_noprefix, $userid)); // Find url in the db independantly from its protocol
|
$result = $query->execute(array('%'.$decodedUrlNoPrefix, $userid)); // Find url in the db independantly from its protocol
|
||||||
if ($row = $result->fetchRow()) {
|
if ($row = $result->fetchRow()) {
|
||||||
$params = array();
|
$params = array();
|
||||||
$title_str = '';
|
$titleStr = '';
|
||||||
if (trim($title) != '') { // Do we replace the old title
|
if (trim($title) != '') { // Do we replace the old title
|
||||||
$title_str = ' , title = ?';
|
$titleStr = ' , title = ?';
|
||||||
$params[] = $title;
|
$params[] = $title;
|
||||||
}
|
}
|
||||||
$desc_str = '';
|
$descriptionStr = '';
|
||||||
if (trim($description) != '') { // Do we replace the old description
|
if (trim($description) != '') { // Do we replace the old description
|
||||||
$desc_str = ' , description = ?';
|
$descriptionStr = ' , description = ?';
|
||||||
$params[] = $description;
|
$params[] = $description;
|
||||||
}
|
}
|
||||||
$sql = "UPDATE `*PREFIX*bookmarks` SET `lastmodified` = "
|
$sql = "UPDATE `*PREFIX*bookmarks` SET `lastmodified` = "
|
||||||
. "UNIX_TIMESTAMP() $title_str $desc_str , `url` = ? WHERE `url` like ? and `user_id` = ?";
|
. "UNIX_TIMESTAMP() $titleStr $descriptionStr , `url` = ? WHERE `url` like ? and `user_id` = ?";
|
||||||
$params[] = $enc_url;
|
$params[] = $decodedUrl;
|
||||||
$params[] = '%'.$enc_url_noprefix;
|
$params[] = '%'.$decodedUrlNoPrefix;
|
||||||
$params[] = $userid;
|
$params[] = $userid;
|
||||||
$query = $db->prepareQuery($sql);
|
$query = $this->db->prepareQuery($sql);
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
return $row['id'];
|
return $row['id'];
|
||||||
} else {
|
} else {
|
||||||
$query = $db->prepareQuery("
|
$query = $this->db->prepareQuery("
|
||||||
INSERT INTO `*PREFIX*bookmarks`
|
INSERT INTO `*PREFIX*bookmarks`
|
||||||
(`url`, `title`, `user_id`, `public`, `added`, `lastmodified`, `description`)
|
(`url`, `title`, `user_id`, `public`, `added`, `lastmodified`, `description`)
|
||||||
VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?)
|
VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?)
|
||||||
");
|
");
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
$enc_url,
|
$decodedUrl,
|
||||||
htmlspecialchars_decode($title),
|
htmlspecialchars_decode($title),
|
||||||
$userid,
|
$userid,
|
||||||
$public,
|
$public,
|
||||||
@ -479,32 +493,31 @@ class Bookmarks {
|
|||||||
);
|
);
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
|
|
||||||
$b_id = $db->getInsertId('*PREFIX*bookmarks');
|
$insertId = $this->db->getInsertId('*PREFIX*bookmarks');
|
||||||
|
|
||||||
if ($b_id !== false) {
|
if ($insertId !== false) {
|
||||||
self::addTags($db, $b_id, $tags);
|
$this->addTags($insertId, $tags);
|
||||||
return $b_id;
|
return $insertId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add a set of tags for a bookmark
|
* @brief Add a set of tags for a bookmark
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param int $bookmarkID The bookmark reference
|
* @param int $bookmarkID The bookmark reference
|
||||||
* @param array $tags Set of tags to add to the bookmark
|
* @param array $tags Set of tags to add to the bookmark
|
||||||
* @return null
|
|
||||||
* */
|
* */
|
||||||
private static function addTags(IDb $db, $bookmarkID, $tags) {
|
private function addTags($bookmarkID, $tags) {
|
||||||
$sql = 'INSERT INTO `*PREFIX*bookmarks_tags` (`bookmark_id`, `tag`) select ?, ? ';
|
$sql = 'INSERT INTO `*PREFIX*bookmarks_tags` (`bookmark_id`, `tag`) select ?, ? ';
|
||||||
$dbtype = \OCP\Config::getSystemValue('dbtype', 'sqlite');
|
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
||||||
|
|
||||||
if ($dbtype === 'mysql') {
|
if ($dbType === 'mysql') {
|
||||||
$sql .= 'from dual ';
|
$sql .= 'from dual ';
|
||||||
}
|
}
|
||||||
$sql .= 'where not exists(select * from `*PREFIX*bookmarks_tags` where `bookmark_id` = ? and `tag` = ?)';
|
$sql .= 'where not exists(select * from `*PREFIX*bookmarks_tags` where `bookmark_id` = ? and `tag` = ?)';
|
||||||
|
|
||||||
$query = $db->prepareQuery($sql);
|
$query = $this->db->prepareQuery($sql);
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$tag = trim($tag);
|
$tag = trim($tag);
|
||||||
if (empty($tag)) {
|
if (empty($tag)) {
|
||||||
@ -519,18 +532,16 @@ class Bookmarks {
|
|||||||
/**
|
/**
|
||||||
* @brief Import Bookmarks from html formatted file
|
* @brief Import Bookmarks from html formatted file
|
||||||
* @param string $user User imported Bookmarks should belong to
|
* @param string $user User imported Bookmarks should belong to
|
||||||
* @param IDb $db Database Interface
|
|
||||||
* @param string $file Content to import
|
* @param string $file Content to import
|
||||||
* @return null
|
* @return null
|
||||||
* */
|
* */
|
||||||
public static function importFile($user, IDb $db, $file) {
|
public function importFile($user, $file) {
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$dom = new \domDocument();
|
$dom = new \domDocument();
|
||||||
|
|
||||||
$dom->loadHTMLFile($file);
|
$dom->loadHTMLFile($file);
|
||||||
$links = $dom->getElementsByTagName('a');
|
$links = $dom->getElementsByTagName('a');
|
||||||
|
|
||||||
$l = \OC::$server->getL10NFactory()->get('bookmarks');
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
// Reintroduce transaction here!?
|
// Reintroduce transaction here!?
|
||||||
@ -538,19 +549,19 @@ class Bookmarks {
|
|||||||
/* @var \DOMElement $link */
|
/* @var \DOMElement $link */
|
||||||
$title = $link->nodeValue;
|
$title = $link->nodeValue;
|
||||||
$ref = $link->getAttribute("href");
|
$ref = $link->getAttribute("href");
|
||||||
$tag_str = '';
|
$tagStr = '';
|
||||||
if ($link->hasAttribute("tags"))
|
if ($link->hasAttribute("tags"))
|
||||||
$tag_str = $link->getAttribute("tags");
|
$tagStr = $link->getAttribute("tags");
|
||||||
$tags = explode(',', $tag_str);
|
$tags = explode(',', $tagStr);
|
||||||
|
|
||||||
$desc_str = '';
|
$descriptionStr = '';
|
||||||
if ($link->hasAttribute("description"))
|
if ($link->hasAttribute("description"))
|
||||||
$desc_str = $link->getAttribute("description");
|
$descriptionStr = $link->getAttribute("description");
|
||||||
try {
|
try {
|
||||||
self::addBookmark($user, $db, $ref, $title, $tags, $desc_str);
|
$this->addBookmark($user, $ref, $title, $tags, $descriptionStr);
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
\OC::$server->getLogger()->logException($e, ['app' => 'bookmarks']);
|
$this->logger->logException($e, ['app' => 'bookmarks']);
|
||||||
$errors[] = $l->t('Failed to import one bookmark, because: ') . $e->getMessage();
|
$errors[] = $this->l->t('Failed to import one bookmark, because: ') . $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,14 +574,14 @@ class Bookmarks {
|
|||||||
* @return array Metadata for url;
|
* @return array Metadata for url;
|
||||||
* @throws \Exception|ClientException
|
* @throws \Exception|ClientException
|
||||||
*/
|
*/
|
||||||
public static function getURLMetadata($url) {
|
public function getURLMetadata($url) {
|
||||||
|
|
||||||
$metadata = array();
|
$metadata = array();
|
||||||
$metadata['url'] = $url;
|
$metadata['url'] = $url;
|
||||||
$page = "";
|
$page = $contentType = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$request = \OC::$server->getHTTPClientService()->newClient()->get($url);
|
$request = $this->httpClientService->newClient()->get($url);
|
||||||
$page = $request->getBody();
|
$page = $request->getBody();
|
||||||
$contentType = $request->getHeader('Content-Type');
|
$contentType = $request->getHeader('Content-Type');
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
@ -614,11 +625,11 @@ class Bookmarks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Seperate Url String at comma charachter
|
* @brief Separate Url String at comma character
|
||||||
* @param $line String of Tags
|
* @param $line String of Tags
|
||||||
* @return array Array of Tags
|
* @return array Array of Tags
|
||||||
* */
|
* */
|
||||||
public static function analyzeTagRequest($line) {
|
public function analyzeTagRequest($line) {
|
||||||
$tags = explode(',', $line);
|
$tags = explode(',', $line);
|
||||||
$filterTag = array();
|
$filterTag = array();
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
namespace OCA\Bookmarks\Controller\Lib;
|
namespace OCA\Bookmarks\Controller\Lib;
|
||||||
|
|
||||||
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
|
use OCA\Bookmarks\AppInfo\Application;
|
||||||
|
|
||||||
class Search extends \OCP\Search\Provider{
|
class Search extends \OCP\Search\Provider{
|
||||||
|
|
||||||
@ -36,10 +36,12 @@ class Search extends \OCP\Search\Provider{
|
|||||||
$search_words = $query;
|
$search_words = $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db = \OC::$server->getDb();
|
|
||||||
$user = \OCP\User::getUser();
|
$user = \OCP\User::getUser();
|
||||||
|
|
||||||
$bookmarks = Bookmarks::findBookmarks($user, $db, 0, 'id', $search_words, false);
|
$app = new Application();
|
||||||
|
$libBookmarks = $app->getContainer()->query(Bookmarks::class);
|
||||||
|
|
||||||
|
$bookmarks = $libBookmarks->findBookmarks($user, 0, 'id', $search_words, false);
|
||||||
$l = new \OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type
|
$l = new \OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type
|
||||||
foreach ($bookmarks as $bookmark) {
|
foreach ($bookmarks as $bookmark) {
|
||||||
$results[] = new \OC_Search_Result($bookmark['title'], $bookmark['title'], $bookmark['url'], (string) $l->t('Bookm.'));
|
$results[] = new \OC_Search_Result($bookmark['title'], $bookmark['title'], $bookmark['url'], (string) $l->t('Bookm.'));
|
||||||
|
@ -29,12 +29,16 @@ class BookmarkController extends ApiController {
|
|||||||
private $db;
|
private $db;
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, $userId, IDb $db, IL10N $l10n) {
|
/** @var Bookmarks */
|
||||||
|
private $bookmarks;
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, $userId, IDb $db, IL10N $l10n, Bookmarks $bookmarks) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
|
$this->bookmarks = $bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,11 +66,11 @@ class BookmarkController extends ApiController {
|
|||||||
public function getBookmarks($type = "bookmark", $tag = '', $page = 0, $sort = "bookmarks_sorting_recent") {
|
public function getBookmarks($type = "bookmark", $tag = '', $page = 0, $sort = "bookmarks_sorting_recent") {
|
||||||
|
|
||||||
if ($type == 'rel_tags') {
|
if ($type == 'rel_tags') {
|
||||||
$tags = Bookmarks::analyzeTagRequest($tag);
|
$tags = $this->bookmarks->analyzeTagRequest($tag);
|
||||||
$qtags = Bookmarks::findTags($this->userId, $this->db, $tags);
|
$qtags = $this->bookmarks->findTags($this->userId, $tags);
|
||||||
return new JSONResponse(array('data' => $qtags, 'status' => 'success'));
|
return new JSONResponse(array('data' => $qtags, 'status' => 'success'));
|
||||||
} else { // type == bookmark
|
} else { // type == bookmark
|
||||||
$filterTag = Bookmarks::analyzeTagRequest($tag);
|
$filterTag = $this->bookmarks->analyzeTagRequest($tag);
|
||||||
|
|
||||||
$offset = $page * 10;
|
$offset = $page * 10;
|
||||||
|
|
||||||
@ -75,7 +79,7 @@ class BookmarkController extends ApiController {
|
|||||||
} else {
|
} else {
|
||||||
$sqlSortColumn = 'lastmodified';
|
$sqlSortColumn = 'lastmodified';
|
||||||
}
|
}
|
||||||
$bookmarks = Bookmarks::findBookmarks($this->userId, $this->db, $offset, $sqlSortColumn, $filterTag, true);
|
$bookmarks = $this->bookmarks->findBookmarks($this->userId, $offset, $sqlSortColumn, $filterTag, true);
|
||||||
return new JSONResponse(array('data' => $bookmarks, 'status' => 'success'));
|
return new JSONResponse(array('data' => $bookmarks, 'status' => 'success'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,15 +102,15 @@ class BookmarkController extends ApiController {
|
|||||||
$protocols = '/^(https?|s?ftp)\:\/\//i';
|
$protocols = '/^(https?|s?ftp)\:\/\//i';
|
||||||
try {
|
try {
|
||||||
if (preg_match($protocols, $url)) {
|
if (preg_match($protocols, $url)) {
|
||||||
$data = Bookmarks::getURLMetadata($url);
|
$data = $this->bookmarks->getURLMetadata($url);
|
||||||
// if not (allowed) protocol is given, assume http and https (and fetch both)
|
// if not (allowed) protocol is given, assume http and https (and fetch both)
|
||||||
} else {
|
} else {
|
||||||
// append https to url and fetch it
|
// append https to url and fetch it
|
||||||
$url_https = 'https://' . $url;
|
$url_https = 'https://' . $url;
|
||||||
$data_https = Bookmarks::getURLMetadata($url_https);
|
$data_https = $this->bookmarks->getURLMetadata($url_https);
|
||||||
// append http to url and fetch it
|
// append http to url and fetch it
|
||||||
$url_http = 'http://' . $url;
|
$url_http = 'http://' . $url;
|
||||||
$data_http = Bookmarks::getURLMetadata($url_http);
|
$data_http = $this->bookmarks->getURLMetadata($url_http);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return new JSONResponse(array('status' => 'error'), Http::STATUS_BAD_REQUEST);
|
return new JSONResponse(array('status' => 'error'), Http::STATUS_BAD_REQUEST);
|
||||||
@ -132,8 +136,8 @@ class BookmarkController extends ApiController {
|
|||||||
|
|
||||||
$tags = isset($item['tags']) ? $item['tags'] : array();
|
$tags = isset($item['tags']) ? $item['tags'] : array();
|
||||||
|
|
||||||
$id = Bookmarks::addBookmark($this->userId, $this->db, $url, $title, $tags, $description, $is_public);
|
$id = $this->bookmarks->addBookmark($this->userId, $url, $title, $tags, $description, $is_public);
|
||||||
$bm = Bookmarks::findUniqueBookmark($id, $this->userId, $this->db);
|
$bm = $this->bookmarks->findUniqueBookmark($id, $this->userId);
|
||||||
return new JSONResponse(array('item' => $bm, 'status' => 'success'));
|
return new JSONResponse(array('item' => $bm, 'status' => 'success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,10 +189,10 @@ class BookmarkController extends ApiController {
|
|||||||
$tags = isset($item['tags']) ? $item['tags'] : array();
|
$tags = isset($item['tags']) ? $item['tags'] : array();
|
||||||
|
|
||||||
if (is_numeric($record_id)) {
|
if (is_numeric($record_id)) {
|
||||||
$id = Bookmarks::editBookmark($this->userId, $this->db, $record_id, $url, $title, $tags, $description, $is_public = false);
|
$id = $this->bookmarks->editBookmark($this->userId, $record_id, $url, $title, $tags, $description, $is_public = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$bm = Bookmarks::findUniqueBookmark($id, $this->userId, $this->db);
|
$bm = $this->bookmarks->findUniqueBookmark($id, $this->userId);
|
||||||
return new JSONResponse(array('item' => $bm, 'status' => 'success'));
|
return new JSONResponse(array('item' => $bm, 'status' => 'success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +217,7 @@ class BookmarkController extends ApiController {
|
|||||||
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Bookmarks::deleteUrl($this->userId, $this->db, $id)) {
|
if (!$this->bookmarks->deleteUrl($this->userId, $id)) {
|
||||||
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
||||||
} else {
|
} else {
|
||||||
return new JSONResponse(array('status' => 'success'), Http::STATUS_OK);
|
return new JSONResponse(array('status' => 'success'), Http::STATUS_OK);
|
||||||
@ -263,7 +267,7 @@ class BookmarkController extends ApiController {
|
|||||||
$error = array();
|
$error = array();
|
||||||
$file = $full_input['tmp_name'];
|
$file = $full_input['tmp_name'];
|
||||||
if ($full_input['type'] == 'text/html') {
|
if ($full_input['type'] == 'text/html') {
|
||||||
$error = Bookmarks::importFile($this->userId, $this->db, $file);
|
$error = $this->bookmarks->importFile($this->userId, $file);
|
||||||
if (empty($error)) {
|
if (empty($error)) {
|
||||||
return new JSONResponse(array('status' => 'success'));
|
return new JSONResponse(array('status' => 'success'));
|
||||||
}
|
}
|
||||||
@ -292,7 +296,7 @@ Do Not Edit! -->
|
|||||||
<H1>Bookmarks</H1>
|
<H1>Bookmarks</H1>
|
||||||
<DL><p>
|
<DL><p>
|
||||||
EOT;
|
EOT;
|
||||||
$bookmarks = Bookmarks::findBookmarks($this->userId, $this->db, 0, 'id', array(), true, -1);
|
$bookmarks = $this->bookmarks->findBookmarks($this->userId, 0, 'id', [], true, -1);
|
||||||
foreach ($bookmarks as $bm) {
|
foreach ($bookmarks as $bm) {
|
||||||
$title = $bm['title'];
|
$title = $bm['title'];
|
||||||
if (trim($title) === '') {
|
if (trim($title) === '') {
|
||||||
|
@ -4,7 +4,6 @@ namespace OCA\Bookmarks\Controller\Rest;
|
|||||||
|
|
||||||
use \OCP\AppFramework\ApiController;
|
use \OCP\AppFramework\ApiController;
|
||||||
use \OCP\IRequest;
|
use \OCP\IRequest;
|
||||||
use \OCP\IDb;
|
|
||||||
use \OCP\AppFramework\Http\JSONResponse;
|
use \OCP\AppFramework\Http\JSONResponse;
|
||||||
use \OC\User\Manager;
|
use \OC\User\Manager;
|
||||||
use OCA\Bookmarks\Controller\Lib\Bookmarks;
|
use OCA\Bookmarks\Controller\Lib\Bookmarks;
|
||||||
@ -12,14 +11,15 @@ use OCP\Util;
|
|||||||
|
|
||||||
class PublicController extends ApiController {
|
class PublicController extends ApiController {
|
||||||
|
|
||||||
private $db;
|
|
||||||
private $userManager;
|
private $userManager;
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, IDb $db, Manager $userManager) {
|
/** @var Bookmarks */
|
||||||
parent::__construct(
|
protected $bookmarks;
|
||||||
$appName, $request);
|
|
||||||
|
|
||||||
$this->db = $db;
|
public function __construct($appName, IRequest $request, Bookmarks $bookmarks, Manager $userManager) {
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
|
||||||
|
$this->bookmarks = $bookmarks;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ class PublicController extends ApiController {
|
|||||||
$attributesToSelect = array_unique($attributesToSelect);
|
$attributesToSelect = array_unique($attributesToSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = Bookmarks::findBookmarks($user, $this->db, 0, $sortby, $tags, true, -1, $public, $attributesToSelect, $conjunction);
|
$output = $this->bookmarks->findBookmarks($user, 0, $sortby, $tags, true, -1, $public, $attributesToSelect, $conjunction);
|
||||||
|
|
||||||
if (count($output) == 0) {
|
if (count($output) == 0) {
|
||||||
$output["status"] = 'error';
|
$output["status"] = 'error';
|
||||||
|
@ -7,17 +7,18 @@ use \OCP\AppFramework\Http\JSONResponse;
|
|||||||
use \OCP\AppFramework\Http;
|
use \OCP\AppFramework\Http;
|
||||||
use \OCP\AppFramework\ApiController;
|
use \OCP\AppFramework\ApiController;
|
||||||
use \OCP\IRequest;
|
use \OCP\IRequest;
|
||||||
use \OCP\IDb;
|
|
||||||
|
|
||||||
class TagsController extends ApiController {
|
class TagsController extends ApiController {
|
||||||
|
|
||||||
private $userId;
|
private $userId;
|
||||||
private $db;
|
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, $userId, IDb $db) {
|
/** @var Bookmarks */
|
||||||
|
private $bookmarks;
|
||||||
|
|
||||||
|
public function __construct($appName, IRequest $request, $userId, Bookmarks $bookmarks) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->db = $db;
|
$this->bookmarks = $bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +33,7 @@ class TagsController extends ApiController {
|
|||||||
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bookmarks::deleteTag($this->userId, $this->db, $old_name);
|
$this->bookmarks->deleteTag($this->userId, $old_name);
|
||||||
return new JSONResponse(array('status' => 'success'));
|
return new JSONResponse(array('status' => 'success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class TagsController extends ApiController {
|
|||||||
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bookmarks::renameTag($this->userId, $this->db, $old_name, $new_name);
|
$this->bookmarks->renameTag($this->userId, $old_name, $new_name);
|
||||||
return new JSONResponse(array('status' => 'success'));
|
return new JSONResponse(array('status' => 'success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ class TagsController extends ApiController {
|
|||||||
header("Cache-Control: no-cache, must-revalidate");
|
header("Cache-Control: no-cache, must-revalidate");
|
||||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
||||||
|
|
||||||
$qtags = Bookmarks::findTags($this->userId, $this->db, array(), 0, 400);
|
$qtags = $this->bookmarks->findTags($this->userId, array(), 0, 400);
|
||||||
$tags = array();
|
$tags = array();
|
||||||
foreach ($qtags as $tag) {
|
foreach ($qtags as $tag) {
|
||||||
$tags[] = $tag['tag'];
|
$tags[] = $tag['tag'];
|
||||||
|
@ -16,7 +16,6 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|||||||
use \OCP\IRequest;
|
use \OCP\IRequest;
|
||||||
use \OCP\AppFramework\Http\TemplateResponse;
|
use \OCP\AppFramework\Http\TemplateResponse;
|
||||||
use \OCP\AppFramework\Controller;
|
use \OCP\AppFramework\Controller;
|
||||||
use \OCP\IDb;
|
|
||||||
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
|
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
@ -28,8 +27,8 @@ class WebViewController extends Controller {
|
|||||||
/** @var IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
private $urlgenerator;
|
private $urlgenerator;
|
||||||
|
|
||||||
/** @var IDb */
|
/** @var Bookmarks */
|
||||||
private $db;
|
private $bookmarks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebViewController constructor.
|
* WebViewController constructor.
|
||||||
@ -38,13 +37,13 @@ class WebViewController extends Controller {
|
|||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
* @param $userId
|
* @param $userId
|
||||||
* @param IURLGenerator $urlgenerator
|
* @param IURLGenerator $urlgenerator
|
||||||
* @param IDb $db
|
* @param Bookmarks $bookmarks
|
||||||
*/
|
*/
|
||||||
public function __construct($appName, IRequest $request, $userId, IURLGenerator $urlgenerator, IDb $db) {
|
public function __construct($appName, IRequest $request, $userId, IURLGenerator $urlgenerator, Bookmarks $bookmarks) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->urlgenerator = $urlgenerator;
|
$this->urlgenerator = $urlgenerator;
|
||||||
$this->db = $db;
|
$this->bookmarks = $bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,11 +71,11 @@ class WebViewController extends Controller {
|
|||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function bookmarklet($url = "", $title = "") {
|
public function bookmarklet($url = "", $title = "") {
|
||||||
$bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db);
|
$bookmarkExists = $this->bookmarks->bookmarkExists($url, $this->userId);
|
||||||
$description = "";
|
$description = "";
|
||||||
$tags = [];
|
$tags = [];
|
||||||
if ($bookmarkExists !== false){
|
if ($bookmarkExists !== false){
|
||||||
$bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db);
|
$bookmark = $this->bookmarks->findUniqueBookmark($bookmarkExists, $this->userId);
|
||||||
$description = $bookmark['description'];
|
$description = $bookmark['description'];
|
||||||
$tags = $bookmark['tags'];
|
$tags = $bookmark['tags'];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user