diff --git a/add-tag.php b/add-tag.php index 134a891..e3bcf81 100644 --- a/add-tag.php +++ b/add-tag.php @@ -17,17 +17,19 @@ header("Content-Type: text/plain; charset=utf-8"); include_once("fof-main.php"); -$tag = $_GET['tag']; +$tags = $_GET['tag']; $item = $_GET['item']; $remove = $_GET['remove']; -if($remove == 'true') +foreach(explode(" ", $tags) as $tag) { -fof_untag_item(fof_current_user(), $item, $tag); + if($remove == 'true') + { + fof_untag_item(fof_current_user(), $item, $tag); + } + else + { + fof_tag_item(fof_current_user(), $item, $tag); + } } -else -{ -fof_tag_item(fof_current_user(), $item, $tag); -} - ?> diff --git a/fof-db.php b/fof-db.php index b210295..84e60fe 100644 --- a/fof-db.php +++ b/fof-db.php @@ -318,37 +318,42 @@ function fof_db_get_items($user_id=1, $feed=NULL, $what="unread", $when=NULL, $s $limit_clause = " limit $start, $limit "; } - $query = "select distinct $FOF_FEED_TABLE.feed_title as feed_title, $FOF_FEED_TABLE.feed_link as feed_link, $FOF_FEED_TABLE.feed_description as feed_description, $FOF_FEED_TABLE.feed_image as feed_image, $FOF_ITEM_TABLE.item_id as item_id, $FOF_ITEM_TABLE.item_link as item_link, $FOF_ITEM_TABLE.item_title as item_title, $FOF_ITEM_TABLE.item_cached, $FOF_ITEM_TABLE.item_published, $FOF_ITEM_TABLE.item_updated, $FOF_ITEM_TABLE.item_content as item_content from $FOF_TAG_TABLE, $FOF_SUBSCRIPTION_TABLE, $FOF_FEED_TABLE, $FOF_ITEM_TABLE left outer join $FOF_ITEM_TAG_TABLE on $FOF_ITEM_TABLE.item_id = $FOF_ITEM_TAG_TABLE.item_id where $FOF_ITEM_TABLE.feed_id=$FOF_FEED_TABLE.feed_id and $FOF_SUBSCRIPTION_TABLE.user_id = %d and $FOF_FEED_TABLE.feed_id = $FOF_SUBSCRIPTION_TABLE.feed_id"; - $args[] = $user_id; - + $args = array(); + $select = "SELECT i.* , f.* "; + $from = "FROM $FOF_FEED_TABLE f, $FOF_ITEM_TABLE i, $FOF_SUBSCRIPTION_TABLE s "; + $where = sprintf("WHERE s.user_id = %d AND s.feed_id = f.feed_id AND f.feed_id = i.feed_id ", $user_id); + if(!is_null($feed) && $feed != "") { - $query .= " and $FOF_FEED_TABLE.feed_id = %d"; - $args[] = $feed; + $where .= sprintf("AND f.feed_id = %d ", $feed); } if(!is_null($when) && $when != "") { - $query .= " and $FOF_ITEM_TABLE.item_published > %d and $FOF_ITEM_TABLE.item_published < %d"; - $args[] = $begin; - $args[] = $end; + $where .= sprintf("AND i.item_published > %d and i.item_published < %d ", $begin, $end); } if($what != "all") { - $query .= " and $FOF_ITEM_TABLE.item_id = $FOF_ITEM_TAG_TABLE.item_id and $FOF_ITEM_TAG_TABLE.tag_id = $FOF_TAG_TABLE.tag_id and $FOF_TAG_TABLE.tag_name = '%s' and $FOF_ITEM_TAG_TABLE.user_id = %d"; - $args[] = $what; - $args[] = $user_id; + $tags = split(" ", $what); + $in = implode(", ", array_fill(0, count($tags), "'%s'")); + $from .= ", $FOF_TAG_TABLE t, $FOF_ITEM_TAG_TABLE it "; + $where .= sprintf("AND it.user_id = %d ", $user_id); + $where .= "AND it.tag_id = t.tag_id AND ( t.tag_name IN ( $in ) ) AND i.item_id = it.item_id "; + $group = sprintf("GROUP BY i.item_id HAVING COUNT( i.item_id ) = %d ", count($tags)); + $args = array_merge($args, $tags); } if(!is_null($search) && $search != "") { - $query .= " and ($FOF_ITEM_TABLE.item_title like '%%%s%%' or $FOF_ITEM_TABLE.item_content like '%%%s%%' )"; + $where .= "AND (i.item_title like '%%%s%%' or i.item_content like '%%%s%%' )"; $args[] = $search; $args[] = $search; } - $query .= " order by $FOF_ITEM_TABLE.item_published desc $limit_clause"; + $order = "order by i.item_published desc $limit_clause "; + + $query = $select . $from . $where . $group . $order; $result = fof_safe_query($query, $args); @@ -416,6 +421,51 @@ function fof_db_get_item($user_id, $item_id) // Tag stuff //////////////////////////////////////////////////////////////////////////////// +function fof_db_get_subscription_to_tags() +{ + $r = array(); + global $FOF_SUBSCRIPTION_TABLE; + $result = fof_safe_query("select * from $FOF_SUBSCRIPTION_TABLE"); + while($row = fof_db_get_row($result)) + { + $prefs = unserialize($row['subscription_prefs']); + $tags = $prefs['tags']; + if(!is_array($r[$row['feed_id']])) $r[$row['feed_id']] = array(); + $r[$row['feed_id']][$row['user_id']] = $tags; + } + + return $r; +} + +function fof_db_tag_feed($user_id, $feed_id, $tag_id) +{ + global $FOF_SUBSCRIPTION_TABLE; + + $result = fof_safe_query("select subscription_prefs from $FOF_SUBSCRIPTION_TABLE where feed_id = %d and user_id = %d", $feed_id, $user_id); + $row = fof_db_get_row($result); + $prefs = unserialize($row['subscription_prefs']); + + if(!is_array($prefs['tags']) || !in_array($tag_id, $prefs['tags'])) $prefs['tags'][] = $tag_id; + + fof_safe_query("update $FOF_SUBSCRIPTION_TABLE set subscription_prefs = '%s' where feed_id = %d and user_id = %d", serialize($prefs), $feed_id, $user_id); +} + +function fof_db_untag_feed($user_id, $feed_id, $tag_id) +{ + global $FOF_SUBSCRIPTION_TABLE; + + $result = fof_safe_query("select subscription_prefs from $FOF_SUBSCRIPTION_TABLE where feed_id = %d and user_id = %d", $feed_id, $user_id); + $row = fof_db_get_row($result); + $prefs = unserialize($row['subscription_prefs']); + + if(is_array($prefs['tags'])) + { + $prefs['tags'] = array_diff($prefs['tags'], array($tag_id)); + } + + fof_safe_query("update $FOF_SUBSCRIPTION_TABLE set subscription_prefs = '%s' where feed_id = %d and user_id = %d", serialize($prefs), $feed_id, $user_id); +} + function fof_db_get_item_tags($user_id, $item_id) { global $FOF_TAG_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE, $fof_connection; @@ -445,6 +495,21 @@ function fof_db_get_unread_count($user_id) return $row["count"]; } +function fof_db_get_tag_unread($user_id) +{ + global $FOF_TAG_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE; + + $result = fof_safe_query("SELECT count(*) as count, it2.tag_id FROM $FOF_ITEM_TABLE i, $FOF_ITEM_TAG_TABLE it , $FOF_ITEM_TAG_TABLE it2 where it.item_id = it2.item_id and it.tag_id = 1 and i.item_id = it.item_id and i.item_id = it2.item_id and it.user_id = %d and it2.user_id = %d group by it2.tag_id", $user_id, $user_id); + + $counts = array(); + while($row = fof_db_get_row($result)) + { + $counts[$row['tag_id']] = $row['count']; + } + + return $counts; +} + function fof_db_get_tags($user_id) { global $FOF_TAG_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE, $fof_connection; @@ -460,6 +525,24 @@ function fof_db_get_tags($user_id) return $result; } +function fof_db_get_tag_id_map() +{ + global $FOF_TAG_TABLE; + + $sql = "select * from $FOF_TAG_TABLE"; + + $result = fof_safe_query($sql); + + $tags = array(); + + while($row = fof_db_get_row($result)) + { + $tags[$row['tag_id']] = $row['tag_name']; + } + + return $tags; +} + function fof_db_create_tag($user_id, $tag) { global $FOF_TAG_TABLE, $fof_connection; diff --git a/fof-main.php b/fof-main.php index c0bb873..c97b48a 100644 --- a/fof-main.php +++ b/fof-main.php @@ -116,8 +116,15 @@ function fof_get_tags($user_id) $result = fof_db_get_tags($user_id); + $counts = fof_db_get_tag_unread($user_id); + while($row = fof_db_get_row($result)) { + if(isset($counts[$row['tag_id']])) + $row['unread'] = $counts[$row['tag_id']]; + else + $row['unread'] = 0; + $tags[] = $row; } @@ -138,6 +145,46 @@ function fof_get_item_tags($user_id, $item_id) return $tags; } +function fof_tag_feed($user_id, $feed_id, $tag) +{ + $tag_id = fof_db_get_tag_by_name($user_id, $tag); + if($tag_id == NULL) + { + $tag_id = fof_db_create_tag($user_id, $tag); + } + + $result = fof_db_get_items($user_id, $feed_id, $what="all", NULL, NULL); + + foreach($result as $r) + { + $items[] = $r['item_id']; + } + + fof_db_tag_items($user_id, $tag_id, $items); + + fof_db_tag_feed($user_id, $feed_id, $tag_id); +} + +function fof_untag_feed($user_id, $feed_id, $tag) +{ + $tag_id = fof_db_get_tag_by_name($user_id, $tag); + if($tag_id == NULL) + { + $tag_id = fof_db_create_tag($user_id, $tag); + } + + $result = fof_db_get_items($user_id, $feed_id, $what="all", NULL, NULL); + + foreach($result as $r) + { + $items[] = $r['item_id']; + } + + fof_db_untag_items($user_id, $tag_id, $items); + + fof_db_untag_feed($user_id, $feed_id, $tag_id); +} + function fof_tag_item($user_id, $item_id, $tag) { $tag_id = fof_db_get_tag_by_name($user_id, $tag); @@ -155,6 +202,20 @@ function fof_untag_item($user_id, $item_id, $tag) fof_db_untag_items($user_id, $tag_id, $item_id); } +function fof_untag($user_id, $tag) +{ + $tag_id = fof_db_get_tag_by_name($user_id, $tag); + + $result = fof_db_get_items($user_id, $feed_id, $tag, NULL, NULL); + + foreach($result as $r) + { + $items[] = $r['item_id']; + } + + fof_db_untag_items($user_id, $tag_id, $items); +} + function fof_nice_time_stamp($age) { $age = time() - $age; @@ -230,6 +291,7 @@ function fof_get_feeds($user_id, $order = 'feed_title', $direction = 'asc') $feeds[$i]['feed_link'] = $row['feed_link']; $feeds[$i]['feed_description'] = $row['feed_description']; $feeds[$i]['feed_image'] = $row['feed_image']; + $feeds[$i]['prefs'] = unserialize($row['subscription_prefs']); $feeds[$i]['feed_age'] = $age; list($agestr, $agestrabbr) = fof_nice_time_stamp($age); @@ -238,9 +300,22 @@ function fof_get_feeds($user_id, $order = 'feed_title', $direction = 'asc') $feeds[$i]['agestrabbr'] = $agestrabbr; $i++; - } - + + $tags = fof_db_get_tag_id_map(); + + for($i=0; $i $tags) + { + if(is_array($tags)) + { + foreach($tags as $tag) + { + fof_db_tag_items($user_id, $tag, $item_id); + } + } + } +} + function fof_update_feed($id) { if(!$id) return 0; @@ -631,6 +727,8 @@ function fof_update_feed($id) $n++; $id = fof_db_add_item($feed_id, $item_id, $link, $title, $content, time(), $date, $date); fof_mark_item_unread($feed_id, $id); + + fof_apply_tags($feed_id, $id); } $ids[] = $id; diff --git a/fof.js b/fof.js index bf4ac2b..7c9deb1 100644 --- a/fof.js +++ b/fof.js @@ -257,6 +257,20 @@ function remove_tag(id, tag) return false; } +function delete_tag(tag) +{ + throb(); + + var url = "view-action.php"; + var params = "deltag=" + tag; + var complete = function () { refreshlist(); }; + var options = { method: 'get', parameters: params, onComplete: complete }; + + new Ajax.Request(url, options); + + return false; +} + function toggle_favorite(id) { throb(); diff --git a/prefs.php b/prefs.php index 1384bdb..d2c3ea6 100644 --- a/prefs.php +++ b/prefs.php @@ -27,6 +27,32 @@ if(isset($_POST['adminprefs'])) $message .= ' Saved admin prefs.'; } +if(isset($_POST['tagfeed'])) +{ + $tags = $_POST['tag']; + $feed_id = $_POST['feed_id']; + $title = $_POST['title']; + + foreach(explode(" ", $tags) as $tag) + { + fof_tag_feed(fof_current_user(), $feed_id, $tag); + $message .= " Tagged '$title' as $tag."; + } +} + +if(isset($_GET['untagfeed'])) +{ + $feed_id = $_GET['untagfeed']; + $tags = $_GET['tag']; + $title = $_GET['title']; + + foreach(explode(" ", $tags) as $tag) + { + fof_untag_feed(fof_current_user(), $feed_id, $tag); + $message .= " Dropped $tag from '$title'."; + } +} + if(isset($_POST['prefs'])) { $fof_user_prefs['favicons'] = isset($_POST['favicons']); @@ -110,6 +136,72 @@ Time offset in hours: +

Feed on Feeds - Feeds and Tags

+
+ +"; + } + else + { + print ""; + } + + if($row['feed_image'] && $fof_user_prefs['favicons']) + { + print ""; + } + else + { + print ""; + } + + print ""; + + print ""; + $title = htmlspecialchars($title); + print ""; +} +?> +
$title"; + + if($tags) + { + foreach($tags as $tag) + { + $utag = urlencode($tag); + $utitle = urlencode($title); + print "$tag [x] "; + } + } + else + { + } + + print "
(separate tags with spaces)
+
+ +

Feed on Feeds - Admin Options

diff --git a/sidebar.php b/sidebar.php index 63da0e8..093e09c 100644 --- a/sidebar.php +++ b/sidebar.php @@ -112,7 +112,7 @@ else - +"; } - print ""; - print ""; - print ""; + print ""; + print ""; + print ""; + print ""; } diff --git a/view-action.php b/view-action.php index 0358344..6c9e489 100644 --- a/view-action.php +++ b/view-action.php @@ -27,7 +27,11 @@ while (list ($key, $val) = each ($_POST)) } } -if($_POST['feed']) +if($_REQUEST['deltag']) +{ + fof_untag(fof_current_user(), $_REQUEST['deltag']); +} +else if($_POST['feed']) { fof_db_mark_feed_read(fof_current_user(), $_POST['feed']); }
itemstag name#tag nameuntag all items
$count$tag_name[x]"; + if($unread) print "$unread/"; + print "$count$tag_name[x]