category removal

This commit is contained in:
friendica 2012-05-04 06:42:56 -07:00
parent 9ecd128e5e
commit 10754ced3e
2 changed files with 16 additions and 5 deletions

View File

@ -930,7 +930,7 @@ function prepare_body($item,$attach = false) {
foreach($matches as $mtch) { foreach($matches as $mtch) {
if(strlen($x)) if(strlen($x))
$x .= ','; $x .= ',';
$x .= xmlify(file_tag_decode($mtch[1])); $x .= xmlify(file_tag_decode($mtch[1])) . ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>';
} }
if(strlen($x)) if(strlen($x))
$s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>'; $s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>';
@ -1466,12 +1466,16 @@ function file_tag_save_file($uid,$item,$file) {
return true; return true;
} }
function file_tag_unsave_file($uid,$item,$file) { function file_tag_unsave_file($uid,$item,$file,$cat = false) {
$result = false; $result = false;
if(! intval($uid)) if(! intval($uid))
return false; return false;
$pattern = '[' . file_tag_encode($file) . ']' ; if($cat == true)
$pattern = '<' . file_tag_encode($file) . '>' ;
else
$pattern = '[' . file_tag_encode($file) . ']' ;
$r = q("select file from item where id = %d and uid = %d limit 1", $r = q("select file from item where id = %d and uid = %d limit 1",
intval($item), intval($item),
@ -1486,13 +1490,14 @@ function file_tag_unsave_file($uid,$item,$file) {
intval($uid) intval($uid)
); );
$r = q("select file from item where uid = %d " . file_tag_file_query('item',$file), $r = q("select file from item where uid = %d " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')),
intval($uid) intval($uid)
); );
if(! count($r)) { if(! count($r)) {
$saved = get_pconfig($uid,'system','filetags'); $saved = get_pconfig($uid,'system','filetags');
set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved)); set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved));
} }
return true; return true;
} }

View File

@ -7,12 +7,18 @@ function filerm_content(&$a) {
} }
$term = unxmlify(trim($_GET['term'])); $term = unxmlify(trim($_GET['term']));
$cat = unxmlify(trim($_GET['cat']));
$category = (($cat) ? true : false);
if($category)
$term = $cat;
$item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
logger('filerm: tag ' . $term . ' item ' . $item_id); logger('filerm: tag ' . $term . ' item ' . $item_id);
if($item_id && strlen($term)) if($item_id && strlen($term))
file_tag_unsave_file(local_user(),$item_id,$term); file_tag_unsave_file(local_user(),$item_id,$term, $category);
if(x($_SESSION,'return_url')) if(x($_SESSION,'return_url'))
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);