THIS CHECKIN IS BANANAS!

tagging is now useful!  you can tag feeds as well as individual items.  you can also see unread items per tag.
this opens up lots of ways to actually use the tagging functionality.
orig_fof
steveminutillo 2007-06-13 03:51:41 +00:00
parent d24875f060
commit 07c0632922
7 changed files with 325 additions and 28 deletions

View File

@ -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);
}
?>

View File

@ -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;

View File

@ -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<count($feeds); $i++)
{
$feeds[$i]['tags'] = array();
if(is_array($feeds[$i]['prefs']['tags']))
{
foreach($feeds[$i]['prefs']['tags'] as $tag)
{
$feeds[$i]['tags'][] = $tags[$tag];
}
}
}
$result = fof_db_get_item_count($user_id);
while($row = fof_db_get_row($result))
@ -584,6 +659,27 @@ function fof_parse($url)
return $pie;
}
function fof_apply_tags($feed_id, $item_id)
{
global $fof_subscription_to_tags;
if(!isset($fof_subscription_to_tags))
{
$fof_subscription_to_tags = fof_db_get_subscription_to_tags();
}
foreach($fof_subscription_to_tags[$feed_id] as $user_id => $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;

14
fof.js
View File

@ -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();

View File

@ -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: <input size=3 type=string name=tzoffset value="<?php echo
<input type=submit name=prefs value="Save Preferences">
</form>
<br><h1>Feed on Feeds - Feeds and Tags</h1>
<div style="border: 1px solid black; margin: 10px; padding: 10px; font-size: 12px; font-family: verdana, arial;">
<table cellpadding=3 cellspacing=0>
<?php
foreach($feeds as $row)
{
$id = $row['feed_id'];
$url = $row['feed_url'];
$title = $row['feed_title'];
$link = $row['feed_link'];
$description = $row['feed_description'];
$age = $row['feed_age'];
$unread = $row['feed_unread'];
$starred = $row['feed_starred'];
$items = $row['feed_items'];
$agestr = $row['agestr'];
$agestrabbr = $row['agestrabbr'];
$lateststr = $row['lateststr'];
$lateststrabbr = $row['lateststrabbr'];
$prefs = $row['prefs'];
$tags = $row['tags'];
if(++$t % 2)
{
print "<tr class=\"odd-row\">";
}
else
{
print "<tr>";
}
if($row['feed_image'] && $fof_user_prefs['favicons'])
{
print "<td><a href=\"$url\" title=\"feed\"><img src='" . $row['feed_image'] . "' width='16' height='16' border='0' /></a></td>";
}
else
{
print "<td><a href=\"$url\" title=\"feed\"><img src='image/feed-icon.png' width='16' height='16' border='0' /></a></td>";
}
print "<td><a href=\"$link\" title=\"home page\">$title</a></td>";
print "<td align=right>";
if($tags)
{
foreach($tags as $tag)
{
$utag = urlencode($tag);
$utitle = urlencode($title);
print "$tag <a href='prefs.php?untagfeed=$id&tag=$utag&title=$utitle'>[x]</a> ";
}
}
else
{
}
print "</td>";
$title = htmlspecialchars($title);
print "<td><form method=post action=prefs.php><input type=hidden name=title value=\"$title\"><input type=hidden name=feed_id value=$id><input type=string name=tag> <input type=submit name=tagfeed value='Tag Feed'> <small><i>(separate tags with spaces)</i></small></form></td></tr>";
}
?>
</table>
</div>
<?php if(fof_is_admin()) { ?>
<br><h1>Feed on Feeds - Admin Options</h1>

View File

@ -112,7 +112,7 @@ else
<table cellspacing="0" cellpadding="1" border="0" id="taglist">
<tr class="heading">
<td>items</td><td>tag name</td><td></td>
<td><span class="unread">#</span></td><td>tag name</td><td>untag all items</td>
</tr>
<?php
@ -131,6 +131,7 @@ foreach($tags as $tag)
$tag_name = $tag['tag_name'];
$tag_id = $tag['tag_id'];
$count = $tag['count'];
$unread = $tag['unread'];
if($tag_id == 1 || $tag_id == 2) continue;
@ -143,9 +144,12 @@ foreach($tags as $tag)
print "<tr>";
}
print "<td>$count</td>";
print "<td><a href='.?what=$tag_name'>$tag_name</a></td>";
print "<td>[x]</td>";
print "<td>";
if($unread) print "<a class='unread' href='.?what=$tag_name+unread'>$unread</a>/";
print "<a href='.?what=$tag_name'>$count</a></td>";
print "<td><b><a href='.?what=$tag_name'>$tag_name</a></b></td>";
print "<td><a href=\"#\" title=\"untag all items\" onclick=\"if(confirm('Untag all [$tag_name] items --are you SURE?')) { delete_tag('$tag_name'); return false; } else { return false; }\">[x]</a></td>";
print "</tr>";
}

View File

@ -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']);
}