1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-02-01 02:52:09 +01:00

Fix protocol cut off + Attempt URL https upgrade

- Fix protocol cut off bug
- Automatically attemps to upgrade existing URL from http to https if user add it a second time to bookmarks application (without specifying protocol)
This commit is contained in:
TtuxX 2015-02-14 17:01:41 +01:00
parent 0c1a52e4d5
commit bc1b9daa1d

View File

@ -427,11 +427,12 @@ class Bookmarks {
public static function addBookmark($userid, IDb $db, $url, $title, $tags = array(), $description = '', $is_public = false) {
$public = $is_public ? 1 : 0;
$url_without_prefix = substr($url, strpos($url, "://") + 3); // Removes everything from the url before the "://" pattern (included)
$enc_url = htmlspecialchars_decode($url_without_prefix);
$enc_url_noprefix = htmlspecialchars_decode($url_without_prefix);
$enc_url = htmlspecialchars_decode($url);
// Change lastmodified date if the record if already exists
$sql = "SELECT * from `*PREFIX*bookmarks` WHERE `url` like ? AND `user_id` = ?";
$query = $db->prepareQuery($sql, 1);
$result = $query->execute(array('%'.$enc_url, $userid)); // Find url in the db independantly from its protocol
$result = $query->execute(array('%'.$enc_url_noprefix, $userid)); // Find url in the db independantly from its protocol
if ($row = $result->fetchRow()) {
$params = array();
$title_str = '';
@ -445,8 +446,9 @@ class Bookmarks {
$params[] = $description;
}
$sql = "UPDATE `*PREFIX*bookmarks` SET `lastmodified` = "
. "UNIX_TIMESTAMP() $title_str $desc_str WHERE `url` = ? and `user_id` = ?";
. "UNIX_TIMESTAMP() $title_str $desc_str , `url` = ? WHERE `url` like ? and `user_id` = ?";
$params[] = $enc_url;
$params[] = '%'.$enc_url_noprefix;
$params[] = $userid;
$query = $db->prepareQuery($sql);
$query->execute($params);