diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-03-10 18:14:43 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-03-10 18:14:43 +0100 |
commit | 1acd18510a8fc5b843bf793322ed79b249b195dc (patch) | |
tree | 8218a340193e2827e1c4b0a6117adf81344e7b43 /inc/poche | |
parent | d47a05a9a5185e835d51341febc8257f5262ce03 (diff) | |
parent | fb26cc9375ce9ef8df748eb473eb6e58884421c6 (diff) | |
download | wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.tar.gz wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.tar.zst wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.zip |
Merge pull request #544 from mariroz/feature-tags-autocomplete
a lot of enhancements related to tags: tags list is now sorted, shows number of articles, autocomplete added according to #477, #542
Diffstat (limited to 'inc/poche')
-rwxr-xr-x | inc/poche/Database.class.php | 11 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 52 | ||||
-rwxr-xr-x[-rw-r--r--] | inc/poche/Tools.class.php | 10 |
3 files changed, 52 insertions, 21 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index edc775f5..5b51b507 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -389,12 +389,15 @@ class Database { | |||
389 | return $this->getHandle()->lastInsertId($column); | 389 | return $this->getHandle()->lastInsertId($column); |
390 | } | 390 | } |
391 | 391 | ||
392 | public function retrieveAllTags($user_id) { | 392 | public function retrieveAllTags($user_id, $term = null) { |
393 | $sql = "SELECT DISTINCT tags.* FROM tags | 393 | $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags |
394 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id | 394 | LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id |
395 | LEFT JOIN entries ON tags_entries.entry_id=entries.id | 395 | LEFT JOIN entries ON tags_entries.entry_id=entries.id |
396 | WHERE entries.content <> '' AND entries.user_id=?"; | 396 | WHERE entries.content <> '' AND entries.user_id=? |
397 | $query = $this->executeQuery($sql, array($user_id)); | 397 | ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ." |
398 | GROUP BY tags.id, tags.value | ||
399 | ORDER BY tags.value"; | ||
400 | $query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) )); | ||
398 | $tags = $query->fetchAll(); | 401 | $tags = $query->fetchAll(); |
399 | 402 | ||
400 | return $tags; | 403 | return $tags; |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 0c8e798c..480f6d45 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -488,25 +488,33 @@ class Poche | |||
488 | Tools::logm('error : article not found'); | 488 | Tools::logm('error : article not found'); |
489 | Tools::redirect(); | 489 | Tools::redirect(); |
490 | } | 490 | } |
491 | //get all already set tags to preven duplicates | ||
492 | $already_set_tags = array(); | ||
493 | $entry_tags = $this->store->retrieveTagsByEntry($entry_id); | ||
494 | foreach ($entry_tags as $tag) { | ||
495 | $already_set_tags[] = $tag['value']; | ||
496 | } | ||
491 | foreach($tags as $key => $tag_value) { | 497 | foreach($tags as $key => $tag_value) { |
492 | $value = trim($tag_value); | 498 | $value = trim($tag_value); |
493 | $tag = $this->store->retrieveTagByValue($value); | 499 | if ($value && !in_array($value, $already_set_tags)) { |
494 | 500 | $tag = $this->store->retrieveTagByValue($value); | |
495 | if (is_null($tag)) { | 501 | |
496 | # we create the tag | 502 | if (is_null($tag)) { |
497 | $tag = $this->store->createTag($value); | 503 | # we create the tag |
498 | $sequence = ''; | 504 | $tag = $this->store->createTag($value); |
499 | if (STORAGE == 'postgres') { | 505 | $sequence = ''; |
500 | $sequence = 'tags_id_seq'; | 506 | if (STORAGE == 'postgres') { |
501 | } | 507 | $sequence = 'tags_id_seq'; |
502 | $tag_id = $this->store->getLastId($sequence); | 508 | } |
503 | } | 509 | $tag_id = $this->store->getLastId($sequence); |
504 | else { | 510 | } |
505 | $tag_id = $tag['id']; | 511 | else { |
512 | $tag_id = $tag['id']; | ||
513 | } | ||
514 | |||
515 | # we assign the tag to the article | ||
516 | $this->store->setTagToEntry($tag_id, $entry_id); | ||
506 | } | 517 | } |
507 | |||
508 | # we assign the tag to the article | ||
509 | $this->store->setTagToEntry($tag_id, $entry_id); | ||
510 | } | 518 | } |
511 | if(!$import) { | 519 | if(!$import) { |
512 | Tools::redirect(); | 520 | Tools::redirect(); |
@@ -579,7 +587,17 @@ class Poche | |||
579 | break; | 587 | break; |
580 | case 'tags': | 588 | case 'tags': |
581 | $token = $this->user->getConfigValue('token'); | 589 | $token = $this->user->getConfigValue('token'); |
582 | $tags = $this->store->retrieveAllTags($this->user->getId()); | 590 | //if term is set - search tags for this term |
591 | $term = Tools::checkVar('term'); | ||
592 | $tags = $this->store->retrieveAllTags($this->user->getId(), $term); | ||
593 | if (Tools::isAjaxRequest()) { | ||
594 | $result = array(); | ||
595 | foreach ($tags as $tag) { | ||
596 | $result[] = $tag['value']; | ||
597 | } | ||
598 | echo json_encode($result); | ||
599 | exit; | ||
600 | } | ||
583 | $tpl_vars = array( | 601 | $tpl_vars = array( |
584 | 'token' => $token, | 602 | 'token' => $token, |
585 | 'user_id' => $this->user->getId(), | 603 | 'user_id' => $this->user->getId(), |
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index eeb101b4..ad451fc6 100644..100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -311,4 +311,14 @@ class Tools | |||
311 | 311 | ||
312 | return json_decode($json, true); | 312 | return json_decode($json, true); |
313 | } | 313 | } |
314 | |||
315 | /** | ||
316 | * Returns whether we handle an AJAX (XMLHttpRequest) request. | ||
317 | * @return boolean whether we handle an AJAX (XMLHttpRequest) request. | ||
318 | */ | ||
319 | public static function isAjaxRequest() | ||
320 | { | ||
321 | return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest'; | ||
322 | } | ||
323 | |||
314 | } | 324 | } |