a couple of photo tag issues

This commit is contained in:
friendica 2014-10-26 21:37:59 -07:00
parent d4d44b7a87
commit 95de759766
2 changed files with 34 additions and 23 deletions

View File

@ -319,6 +319,7 @@ function photos_post(&$a) {
$old_inform = $r[0]['inform']; $old_inform = $r[0]['inform'];
} }
// make sure the linked item has the same permissions as the photo regardless of any other changes // make sure the linked item has the same permissions as the photo regardless of any other changes
$x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d
where id = %d limit 1", where id = %d limit 1",
@ -380,6 +381,7 @@ function photos_post(&$a) {
if($success['replaced']) { if($success['replaced']) {
$tagged[] = $tag; $tagged[] = $tag;
$post_tags[] = array( $post_tags[] = array(
'uid' => $a->profile['profile_uid'], 'uid' => $a->profile['profile_uid'],
'type' => $success['termtype'], 'type' => $success['termtype'],
@ -397,8 +399,14 @@ function photos_post(&$a) {
); );
if($r) { if($r) {
$r = fetch_post_tags($r,true);
$datarray = $r[0]; $datarray = $r[0];
if($post_tags) {
if((! array_key_exists('term',$datarray)) || (! is_array($datarray['term'])))
$datarray['term'] = $post_tags; $datarray['term'] = $post_tags;
else
$datarray['term'] = array_merge($datarray['term'],$post_tags);
}
item_store_update($datarray,$execflag); item_store_update($datarray,$execflag);
} }
@ -910,12 +918,10 @@ function photos_content(&$a) {
$r = conv_sort($r,'commented'); $r = conv_sort($r,'commented');
} }
$tags = array(); $tags = array();
if($link_item['term']) { if($link_item['term']) {
$cnt = 0; $cnt = 0;
foreach($link_item['term'] as $t) foreach($link_item['term'] as $t) {
$tags[$cnt] = array(0 => format_term_for_display($t)); $tags[$cnt] = array(0 => format_term_for_display($t));
if($can_post && ($ph[0]['uid'] == $owner_uid)) { if($can_post && ($ph[0]['uid'] == $owner_uid)) {
$tags[$cnt][1] = 'tagrm?f=&item=' . $link_item['id']; $tags[$cnt][1] = 'tagrm?f=&item=' . $link_item['id'];
@ -923,7 +929,7 @@ function photos_content(&$a) {
} }
$cnt ++; $cnt ++;
} }
}
if((local_user()) && (local_user() == $link_item['uid'])) { if((local_user()) && (local_user() == $link_item['uid'])) {
q("UPDATE `item` SET item_flags = (item_flags ^ %d) WHERE parent = %d and uid = %d and (item_flags & %d)", q("UPDATE `item` SET item_flags = (item_flags ^ %d) WHERE parent = %d and uid = %d and (item_flags & %d)",

View File

@ -19,24 +19,27 @@ function tagrm_post(&$a) {
intval(local_user()) intval(local_user())
); );
if(! count($r)) if(! $r)
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
$arr = explode(',', $r[0]['tag']); $r = fetch_post_tags($r,true);
for($x = 0; $x < count($arr); $x ++) {
if($arr[$x] === $tag) { $item = $r[0];
unset($arr[$x]); $new_tags = array();
break;
if($item['term']) {
for($x = 0; $x < count($item['term']); $x ++) {
if($item['term'][$x]['term'] !== hex2bin($tag))
$new_tags[] = $item['term'][$x];
} }
} }
$tag_str = implode(',',$arr); if($new_tags)
$item['term'] = $new_tags;
else
unset($item['term']);
q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", item_store_update($item);
dbesc($tag_str),
intval($item),
intval(local_user())
);
info( t('Tag removed') . EOL ); info( t('Tag removed') . EOL );
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
@ -56,7 +59,7 @@ function tagrm_content(&$a) {
// NOTREACHED // NOTREACHED
} }
$item = (($a->argc > 1) ? intval($a->argv[1]) : 0); $item = intval($_GET['item']);
if(! $item) { if(! $item) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
// NOTREACHED // NOTREACHED
@ -68,12 +71,14 @@ function tagrm_content(&$a) {
intval(local_user()) intval(local_user())
); );
if(! count($r))
if(! $r)
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
$arr = explode(',', $r[0]['tag']); $r = fetch_post_tags($r,true);
if(! count($arr))
if(! count($r[0]['term']))
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
$o .= '<h3>' . t('Remove Item Tag') . '</h3>'; $o .= '<h3>' . t('Remove Item Tag') . '</h3>';
@ -85,8 +90,8 @@ function tagrm_content(&$a) {
$o .= '<ul>'; $o .= '<ul>';
foreach($arr as $x) { foreach($r[0]['term'] as $x) {
$o .= '<li><input type="checkbox" name="tag" value="' . bin2hex($x) . '" >' . bbcode($x) . '</input></li>'; $o .= '<li><input type="checkbox" name="tag" value="' . bin2hex($x['term']) . '" >' . bbcode($x['term']) . '</input></li>';
} }
$o .= '</ul>'; $o .= '</ul>';