issue #85, community tags and file tags lost during edits. This required splitting off communitytags as a separate tag type and is not backward compatible. Community tags on older posts or those federated from redmatrix clones will not be preserved during edits.
This commit is contained in:
@@ -674,7 +674,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
|
||||
$unverified = '';
|
||||
|
||||
// $tags=array();
|
||||
// $terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_UNKNOWN));
|
||||
// $terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_UNKNOWN,TERM_COMMUNITYTAG));
|
||||
// if(count($terms))
|
||||
// foreach($terms as $tag)
|
||||
// $tags[] = format_term_for_display($tag);
|
||||
|
||||
@@ -1408,7 +1408,7 @@ function encode_item_xchan($xchan) {
|
||||
function encode_item_terms($terms,$mirror = false) {
|
||||
$ret = array();
|
||||
|
||||
$allowed_export_terms = array( TERM_UNKNOWN, TERM_HASHTAG, TERM_MENTION, TERM_CATEGORY, TERM_BOOKMARK );
|
||||
$allowed_export_terms = array( TERM_UNKNOWN, TERM_HASHTAG, TERM_MENTION, TERM_CATEGORY, TERM_BOOKMARK, TERM_COMMUNITYTAG );
|
||||
|
||||
if($mirror) {
|
||||
$allowed_export_terms[] = TERM_PCATEGORY;
|
||||
@@ -1432,7 +1432,7 @@ function encode_item_terms($terms,$mirror = false) {
|
||||
* @return string
|
||||
*/
|
||||
function termtype($t) {
|
||||
$types = array('unknown','hashtag','mention','category','private_category','file','search','thing','bookmark');
|
||||
$types = array('unknown','hashtag','mention','category','private_category','file','search','thing','bookmark', 'hierarchy', 'communitytag');
|
||||
|
||||
return(($types[$t]) ? $types[$t] : 'unknown');
|
||||
}
|
||||
@@ -1478,6 +1478,9 @@ function decode_tags($t) {
|
||||
case 'bookmark':
|
||||
$tag['type'] = TERM_BOOKMARK;
|
||||
break;
|
||||
case 'communitytag':
|
||||
$tag['type'] = TERM_COMMUNITYTAG;
|
||||
break;
|
||||
default:
|
||||
case 'unknown':
|
||||
$tag['type'] = TERM_UNKNOWN;
|
||||
@@ -3032,7 +3035,7 @@ function tag_deliver($uid, $item_id) {
|
||||
if(is_array($j_obj['link']))
|
||||
$taglink = get_rel_link($j_obj['link'],'alternate');
|
||||
|
||||
store_item_tag($u[0]['channel_id'],$p[0]['id'],TERM_OBJ_POST,TERM_HASHTAG,$j_obj['title'],$j_obj['id']);
|
||||
store_item_tag($u[0]['channel_id'],$p[0]['id'],TERM_OBJ_POST,TERM_COMMUNITYTAG,$j_obj['title'],$j_obj['id']);
|
||||
$x = q("update item set edited = '%s', received = '%s', changed = '%s' where mid = '%s' and uid = %d",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
@@ -3437,7 +3440,7 @@ function check_item_source($uid, $item) {
|
||||
foreach($words as $word) {
|
||||
if(substr($word,0,1) === '#' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if(($t['type'] == TERM_HASHTAG) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
if((($t['type'] == TERM_HASHTAG) || ($t['type'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return true;
|
||||
}
|
||||
elseif((strpos($word,'/') === 0) && preg_match($word,$text))
|
||||
@@ -3490,7 +3493,7 @@ function post_is_importable($item,$abook) {
|
||||
continue;
|
||||
if(substr($word,0,1) === '#' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if(($t['type'] == TERM_HASHTAG) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
if((($t['type'] == TERM_HASHTAG) || ($t['type'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return false;
|
||||
}
|
||||
elseif((strpos($word,'/') === 0) && preg_match($word,$text))
|
||||
@@ -3511,7 +3514,7 @@ function post_is_importable($item,$abook) {
|
||||
continue;
|
||||
if(substr($word,0,1) === '#' && $tags) {
|
||||
foreach($tags as $t)
|
||||
if(($t['type'] == TERM_HASHTAG) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
if((($t['type'] == TERM_HASHTAG) || ($t['type'] == TERM_COMMUNITYTAG)) && (($t['term'] === substr($word,1)) || (substr($word,1) === '*')))
|
||||
return true;
|
||||
}
|
||||
elseif((strpos($word,'/') === 0) && preg_match($word,$text))
|
||||
@@ -4162,12 +4165,12 @@ function enumerate_permissions($obj) {
|
||||
|
||||
function item_getfeedtags($item) {
|
||||
|
||||
$terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION));
|
||||
$terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_COMMUNITYTAG));
|
||||
$ret = array();
|
||||
|
||||
if(count($terms)) {
|
||||
foreach($terms as $term) {
|
||||
if($term['type'] == TERM_HASHTAG)
|
||||
if(($term['type'] == TERM_HASHTAG) || ($term['type'] == TERM_COMMUNITYTAG))
|
||||
$ret[] = array('#',$term['url'],$term['term']);
|
||||
else
|
||||
$ret[] = array('@',$term['url'],$term['term']);
|
||||
@@ -4875,7 +4878,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
|
||||
if($arr['search']) {
|
||||
|
||||
if(strpos($arr['search'],'#') === 0)
|
||||
$sql_extra .= term_query('item',substr($arr['search'],1),TERM_HASHTAG);
|
||||
$sql_extra .= term_query('item',substr($arr['search'],1),TERM_HASHTAG,TERM_COMMUNITYTAG);
|
||||
else
|
||||
$sql_extra .= sprintf(" AND item.body like '%s' ",
|
||||
dbesc(protect_sprintf('%' . $arr['search'] . '%'))
|
||||
|
||||
@@ -26,12 +26,21 @@ function file_tag_file_query($table,$s,$type = 'file') {
|
||||
);
|
||||
}
|
||||
|
||||
function term_query($table,$s,$type = TERM_UNKNOWN) {
|
||||
function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') {
|
||||
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
intval($type),
|
||||
protect_sprintf(dbesc($s))
|
||||
);
|
||||
if($type2) {
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type in (%d, %d) and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
intval($type),
|
||||
intval($type2),
|
||||
protect_sprintf(dbesc($s))
|
||||
);
|
||||
}
|
||||
else {
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
intval($type),
|
||||
protect_sprintf(dbesc($s))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +93,7 @@ function get_terms_oftype($arr,$type) {
|
||||
|
||||
function format_term_for_display($term) {
|
||||
$s = '';
|
||||
if($term['type'] == TERM_HASHTAG)
|
||||
if(($term['type'] == TERM_HASHTAG) || ($term['type'] == TERM_COMMUNITYTAG))
|
||||
$s .= '#';
|
||||
elseif($term['type'] == TERM_MENTION)
|
||||
$s .= '@';
|
||||
|
||||
@@ -1298,7 +1298,7 @@ function format_categories(&$item,$writeable) {
|
||||
function format_hashtags(&$item) {
|
||||
$s = '';
|
||||
|
||||
$terms = get_terms_oftype($item['term'], TERM_HASHTAG);
|
||||
$terms = get_terms_oftype($item['term'], array(TERM_HASHTAG,TERM_COMMUNITYTAG));
|
||||
if($terms) {
|
||||
foreach($terms as $t) {
|
||||
$term = htmlspecialchars($t['term'], ENT_COMPAT, 'UTF-8', false) ;
|
||||
|
||||
@@ -1933,11 +1933,12 @@ function remove_community_tag($sender, $arr, $uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
q("delete from term where uid = %d and oid = %d and otype = %d and type = %d and term = '%s' and url = '%s'",
|
||||
q("delete from term where uid = %d and oid = %d and otype = %d and type in ( %d, %d ) and term = '%s' and url = '%s'",
|
||||
intval($uid),
|
||||
intval($r[0]['id']),
|
||||
intval(TERM_OBJ_POST),
|
||||
intval(TERM_HASHTAG),
|
||||
intval(TERM_COMMUNITYTAG),
|
||||
dbesc($i['object']['title']),
|
||||
dbesc(get_rel_link($i['object']['link'],'alternate'))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user