Support deleting items from private feeds or if you are admin
parent
686167a883
commit
53a4eaace3
84
fof-db.php
84
fof-db.php
|
@ -600,7 +600,7 @@ function fof_db_create_tag($user_id, $tag)
|
|||
|
||||
function fof_db_get_tag_by_name($user_id, $tag)
|
||||
{
|
||||
global $FOF_TAG_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE, $fof_connection;
|
||||
global $FOF_TAG_TABLE, $FOF_ITEM_TABLE, $FOF_ITEM_TAG_TABLE;
|
||||
|
||||
$result = fof_safe_query("select $FOF_TAG_TABLE.tag_id from $FOF_TAG_TABLE where $FOF_TAG_TABLE.tag_name = '%s'", $tag);
|
||||
|
||||
|
@ -624,16 +624,36 @@ function fof_db_mark_read($user_id, $items)
|
|||
fof_db_untag_items($user_id, 1, $items);
|
||||
}
|
||||
|
||||
function fof_db_delete_items($user_id, $items, $check_private)
|
||||
{
|
||||
global $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE;
|
||||
if (!$items)
|
||||
return;
|
||||
if ($check_private)
|
||||
{
|
||||
// Check if items correspond to $user_id's private feed
|
||||
$result = fof_db_query(
|
||||
"SELECT i.item_id FROM $FOF_ITEM_TABLE i".
|
||||
" LEFT JOIN $FOF_SUBSCRIPTION_TABLE s ON s.feed_id=i.feed_id AND s.user_id != $user_id".
|
||||
" WHERE s.feed_id IS NULL AND i.item_id IN (".implode(',', array_map('intval', $items)).")"
|
||||
);
|
||||
$items = array();
|
||||
foreach ($result as $r)
|
||||
$items[] = $r['item_id'];
|
||||
}
|
||||
if (!$items)
|
||||
return;
|
||||
$items = implode(',', array_map('intval', $items));
|
||||
fof_db_query("DELETE FROM $FOF_ITEM_TABLE WHERE item_id IN ($items)");
|
||||
}
|
||||
|
||||
function fof_db_mark_feed_read($user_id, $feed_id)
|
||||
{
|
||||
global $FOF_ITEM_TAG_TABLE;
|
||||
|
||||
$result = fof_db_get_items($user_id, $feed_id, $what="all");
|
||||
|
||||
foreach($result as $r)
|
||||
{
|
||||
foreach ($result as $r)
|
||||
$items[] = $r['item_id'];
|
||||
}
|
||||
|
||||
fof_db_untag_items($user_id, 1, $items);
|
||||
}
|
||||
|
@ -665,43 +685,36 @@ function fof_db_mark_item_unread($users, $id)
|
|||
{
|
||||
global $FOF_ITEM_TAG_TABLE;
|
||||
|
||||
if(count($users) == 0) return;
|
||||
if (!$users)
|
||||
return;
|
||||
|
||||
$sql = array();
|
||||
foreach($users as $user)
|
||||
{
|
||||
$sql[] = sprintf("(%d, 1, %d)", $user, $id);
|
||||
}
|
||||
|
||||
$values = implode ( ",", $sql );
|
||||
|
||||
$sql = "insert into $FOF_ITEM_TAG_TABLE (user_id, tag_id, item_id) values " . $values;
|
||||
$values = implode(",", $sql);
|
||||
|
||||
$sql = "insert into $FOF_ITEM_TAG_TABLE (user_id, tag_id, item_id)".
|
||||
" values $values on duplicate key update item_id=item_id";
|
||||
$result = fof_db_query($sql, 1);
|
||||
|
||||
if(!$result && (mysql_errno() != 1062))
|
||||
if (!$result)
|
||||
fof_die_mysql_error("Cannot run query '$sql': ".mysql_errno().": ".mysql_error());
|
||||
}
|
||||
|
||||
function fof_db_tag_items($user_id, $tag_id, $items)
|
||||
{
|
||||
global $FOF_ITEM_TAG_TABLE;
|
||||
|
||||
if(!$items) return;
|
||||
|
||||
if(!is_array($items)) $items = array($items);
|
||||
if (!$items)
|
||||
return;
|
||||
if (!is_array($items))
|
||||
$items = array($items);
|
||||
|
||||
foreach($items as $item)
|
||||
{
|
||||
$sql[] = sprintf("(%d, %d, %d)", $user_id, $tag_id, $item);
|
||||
}
|
||||
|
||||
$values = implode ( ",", $sql );
|
||||
|
||||
$sql = "insert into $FOF_ITEM_TAG_TABLE (user_id, tag_id, item_id) values " . $values;
|
||||
$values = implode(",", $sql);
|
||||
$sql = "insert into $FOF_ITEM_TAG_TABLE (user_id, tag_id, item_id) values $values on duplicate key update item_id=item_id";
|
||||
|
||||
$result = fof_db_query($sql, 1);
|
||||
|
||||
if(!$result && (mysql_errno() != 1062))
|
||||
if (!$result)
|
||||
fof_die_mysql_error("Cannot run query '$sql': ".mysql_errno().": ".mysql_error());
|
||||
}
|
||||
|
||||
|
@ -709,19 +722,13 @@ function fof_db_untag_items($user_id, $tag_id, $items)
|
|||
{
|
||||
global $FOF_ITEM_TAG_TABLE;
|
||||
|
||||
if(!$items) return;
|
||||
if(!$items)
|
||||
return;
|
||||
if(!is_array($items))
|
||||
$items = array($items);
|
||||
|
||||
if(!is_array($items)) $items = array($items);
|
||||
|
||||
foreach($items as $item)
|
||||
{
|
||||
$sql[] = " item_id = %d ";
|
||||
$args[] = $item;
|
||||
}
|
||||
|
||||
$values = implode ( " or ", $sql );
|
||||
|
||||
$sql = "delete from $FOF_ITEM_TAG_TABLE where user_id = %d and tag_id = %d and ( $values )";
|
||||
$sql = "item_id IN (".implode(",", array_map('intval', $items)).")";
|
||||
$sql = "delete from $FOF_ITEM_TAG_TABLE where user_id = %d and tag_id = %d and $sql";
|
||||
|
||||
array_unshift($args, $tag_id);
|
||||
array_unshift($args, $user_id);
|
||||
|
@ -729,7 +736,6 @@ function fof_db_untag_items($user_id, $tag_id, $items)
|
|||
fof_safe_query($sql, $args);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// User stuff
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
13
fof.js
13
fof.js
|
@ -658,7 +658,6 @@ function flag_all()
|
|||
elements.each( function(e) { e.checked = true; });
|
||||
}
|
||||
|
||||
|
||||
function toggle_all()
|
||||
{
|
||||
elements = $A(Form.getInputs('itemform', 'checkbox'));
|
||||
|
@ -671,7 +670,6 @@ function unflag_all()
|
|||
elements.each( function(e) { e.checked = false; });
|
||||
}
|
||||
|
||||
|
||||
function mark_read()
|
||||
{
|
||||
document.items['action'].value = 'read';
|
||||
|
@ -686,6 +684,17 @@ function mark_unread()
|
|||
document.items.submit();
|
||||
}
|
||||
|
||||
function delete_flagged(is_adm)
|
||||
{
|
||||
if (confirm('Are you sure to remove selected items from FeedOnFeeds database?'+
|
||||
(is_adm ? '' : ' Only items from your private feeds can be removed!')))
|
||||
{
|
||||
document.items['action'].value = 'delete';
|
||||
document.items['return'].value = escape(location);
|
||||
document.items.submit();
|
||||
}
|
||||
}
|
||||
|
||||
function mark_feed_read(id)
|
||||
{
|
||||
throb();
|
||||
|
|
|
@ -61,6 +61,7 @@ $noedit = $_GET['noedit'];
|
|||
<li><a href="javascript:mark_unread()">Mark flagged unread</a></li>
|
||||
<li><a href="javascript:show_all()">Show all</a></li>
|
||||
<li><a href="javascript:hide_all()">Hide all</a></li>
|
||||
<li><a href="javascript:delete_flagged(<?= fof_is_admin() ? 1 : 0 ?>)">Delete flagged</a></li>
|
||||
</ul>
|
||||
|
||||
<!-- close this form to fix first item! -->
|
||||
|
|
|
@ -4,12 +4,10 @@
|
|||
*
|
||||
* view-action.php - marks selected items as read (or unread)
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2004-2007 Stephen Minutillo
|
||||
* steve@minutillo.com - http://minutillo.com/steve/
|
||||
*
|
||||
* Distributed under the GPL - see LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
include_once("fof-main.php");
|
||||
|
@ -17,37 +15,32 @@ include_once("fof-main.php");
|
|||
while (list ($key, $val) = each ($_POST))
|
||||
{
|
||||
$first = false;
|
||||
|
||||
if($val == "checked")
|
||||
if ($val == "checked")
|
||||
{
|
||||
$key = substr($key, 1);
|
||||
$items[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($_REQUEST['deltag'])
|
||||
if ($_REQUEST['deltag'])
|
||||
{
|
||||
fof_untag(fof_current_user(), $_REQUEST['deltag']);
|
||||
fof_untag(fof_current_user(), $_REQUEST['deltag']);
|
||||
}
|
||||
else if($_POST['feed'])
|
||||
elseif ($_POST['feed'])
|
||||
{
|
||||
fof_db_mark_feed_read(fof_current_user(), $_POST['feed']);
|
||||
fof_db_mark_feed_read(fof_current_user(), $_POST['feed']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($items)
|
||||
{
|
||||
if($_POST['action'] == 'read')
|
||||
{
|
||||
fof_db_mark_read(fof_current_user(), $items);
|
||||
}
|
||||
|
||||
if($_POST['action'] == 'unread')
|
||||
{
|
||||
fof_db_mark_unread(fof_current_user(), $items);
|
||||
}
|
||||
}
|
||||
|
||||
if ($items)
|
||||
{
|
||||
if ($_POST['action'] == 'read')
|
||||
fof_db_mark_read(fof_current_user(), $items);
|
||||
elseif ($_POST['action'] == 'unread')
|
||||
fof_db_mark_unread(fof_current_user(), $items);
|
||||
elseif ($_POST['action'] == 'delete')
|
||||
fof_db_delete_items(fof_current_user(), $items, !fof_is_admin());
|
||||
}
|
||||
|
||||
header("Location: " . urldecode($_POST['return']));
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue