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

Check if URL already exists before adding

Changed the way `addBookmark` function checks if url already exists.

Now the `addBookmark` function checks wether the url one want to bookmark exists or not, independantly from its protocol.

In order to achieve this, the script :
- Removes everything from the url before the `://` part (included)
- Uses a `like` statement in the SQL query instead of `=`
- Adds a `%` to the url at the query execution
This commit is contained in:
TtuxX 2015-01-05 22:22:43 +01:00
parent b6048dd3a8
commit 0c1a52e4d5

View File

@ -426,11 +426,12 @@ 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;
$enc_url = htmlspecialchars_decode($url); $url_without_prefix = substr($url, strpos($url, "://") + 3); // Removes everything from the url before the "://" pattern (included)
$enc_url = htmlspecialchars_decode($url_without_prefix);
// 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` = ? AND `user_id` = ?"; $sql = "SELECT * from `*PREFIX*bookmarks` WHERE `url` like ? AND `user_id` = ?";
$query = $db->prepareQuery($sql, 1); $query = $db->prepareQuery($sql, 1);
$result = $query->execute(array($enc_url, $userid)); $result = $query->execute(array('%'.$enc_url, $userid)); // Find url in the db independantly from its protocol
if ($row = $result->fetchRow()) { if ($row = $result->fetchRow()) {
$params = array(); $params = array();
$title_str = ''; $title_str = '';