mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-23 20:54:23 +01:00
Merge pull request #272 from owncloud/backport-264-266-stable9
[stable9] Backport #264 and #266
This commit is contained in:
commit
dcef796423
@ -27,7 +27,7 @@
|
|||||||
<type>text</type>
|
<type>text</type>
|
||||||
<default></default>
|
<default></default>
|
||||||
<notnull>true</notnull>
|
<notnull>true</notnull>
|
||||||
<length>140</length>
|
<length>4096</length>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>user_id</name>
|
<name>user_id</name>
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
<owncloud min-version="8.1" max-version="9.0" />
|
<owncloud min-version="8.1" max-version="9.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<ocsid>168710</ocsid>
|
<ocsid>168710</ocsid>
|
||||||
<version>0.7</version>
|
<version>0.7.1</version>
|
||||||
</info>
|
</info>
|
||||||
|
@ -428,9 +428,16 @@ class Bookmarks {
|
|||||||
*/
|
*/
|
||||||
public static function addBookmark($userid, IDb $db, $url, $title, $tags = array(), $description = '', $is_public = false) {
|
public static function addBookmark($userid, IDb $db, $url, $title, $tags = array(), $description = '', $is_public = false) {
|
||||||
$public = $is_public ? 1 : 0;
|
$public = $is_public ? 1 : 0;
|
||||||
$url_without_prefix = substr($url, strpos($url, "://") + 3); // Removes everything from the url before the "://" pattern (included)
|
$url_without_prefix = trim(substr($url, strpos($url, "://") + 3)); // Removes everything from the url before the "://" pattern (included)
|
||||||
|
if($url_without_prefix === '') {
|
||||||
|
throw new \InvalidArgumentException('Bookmark URL is missing');
|
||||||
|
}
|
||||||
$enc_url_noprefix = htmlspecialchars_decode($url_without_prefix);
|
$enc_url_noprefix = htmlspecialchars_decode($url_without_prefix);
|
||||||
$enc_url = htmlspecialchars_decode($url);
|
$enc_url = htmlspecialchars_decode($url);
|
||||||
|
|
||||||
|
$title = mb_substr($title, 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 = $db->prepareQuery($sql, 1);
|
||||||
@ -522,8 +529,12 @@ class Bookmarks {
|
|||||||
$dom->loadHTMLFile($file);
|
$dom->loadHTMLFile($file);
|
||||||
$links = $dom->getElementsByTagName('a');
|
$links = $dom->getElementsByTagName('a');
|
||||||
|
|
||||||
|
$l = \OC::$server->getL10NFactory()->get('bookmarks');
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
// Reintroduce transaction here!?
|
// Reintroduce transaction here!?
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
|
/* @var \DOMElement $link */
|
||||||
$title = $link->nodeValue;
|
$title = $link->nodeValue;
|
||||||
$ref = $link->getAttribute("href");
|
$ref = $link->getAttribute("href");
|
||||||
$tag_str = '';
|
$tag_str = '';
|
||||||
@ -534,11 +545,15 @@ class Bookmarks {
|
|||||||
$desc_str = '';
|
$desc_str = '';
|
||||||
if ($link->hasAttribute("description"))
|
if ($link->hasAttribute("description"))
|
||||||
$desc_str = $link->getAttribute("description");
|
$desc_str = $link->getAttribute("description");
|
||||||
|
try {
|
||||||
self::addBookmark($user, $db, $ref, $title, $tags, $desc_str);
|
self::addBookmark($user, $db, $ref, $title, $tags, $desc_str);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
\OC::$server->getLogger()->logException($e, ['app' => 'bookmarks']);
|
||||||
|
$errors[] = $l->t('Failed to import one bookmark, because: ') . $e->getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user