diff options
Diffstat (limited to 'include/taxonomy.php')
-rw-r--r-- | include/taxonomy.php | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/include/taxonomy.php b/include/taxonomy.php index 0b4b2aa9a..23acaa24d 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -44,6 +44,45 @@ function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') { } +function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = '') { + + // Allow asterisks for wildcard search + // In theory this means '%' will also do a wildcard search, but there appear to be multiple escape + // issues with '%' in term names and trying to fix this with '\\%' here did not help. + // Ideally I think we want '*' to indicate wildcards and allow '%' literally in names, but that is being + // left for another developer on another day. + + $s = str_replace('*','%',$s); + + if($type2) { + $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term like '%s' and term.uid = %d and term.otype = 1", + intval($type), + intval($type2), + dbesc($s), + intval($uid) + ); + } + else { + $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term like '%s' and term.uid = %d and term.otype = 1", + intval($type), + dbesc($s), + intval($uid) + ); + } + + if($r) { + $str = ''; + foreach($r as $rv) { + if($str) + $str .= ','; + $str .= intval($rv['parent']); + } + return " AND " . (($table) ? dbesc($table) . '.' : '') . "id in ( $str ) "; + } + return " AND false "; +} + + function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { if(! $term) return false; @@ -95,6 +134,8 @@ function format_term_for_display($term) { $s = ''; if(($term['ttype'] == TERM_HASHTAG) || ($term['ttype'] == TERM_COMMUNITYTAG)) $s .= '#'; + elseif($term['ttype'] == TERM_FORUM) + $s .= '!'; elseif($term['ttype'] == TERM_MENTION) $s .= '@'; else @@ -160,6 +201,62 @@ function tagadelic($uid, $count = 0, $authors = '', $owner = '', $flags = 0, $re } + + +function card_tagadelic($uid, $count = 0, $authors = '', $owner = '', $flags = 0, $restrict = 0, $type = TERM_CATEGORY) { + + require_once('include/security.php'); + + if(! perm_is_allowed($uid,get_observer_hash(),'view_pages')) + return array(); + + + $item_normal = item_normal(); + $sql_options = item_permissions_sql($uid); + $count = intval($count); + + if($flags) { + if($flags === 'wall') + $sql_options .= " and item_wall = 1 "; + } + + if($authors) { + if(! is_array($authors)) + $authors = array($authors); + + stringify_array_elms($authors,true); + $sql_options .= " and author_xchan in (" . implode(',',$authors) . ") "; + } + + if($owner) { + $sql_options .= " and owner_xchan = '" . dbesc($owner) . "' "; + } + + + // Fetch tags + $r = q("select term, count(term) as total from term left join item on term.oid = item.id + where term.uid = %d and term.ttype = %d + and otype = %d and item_type = %d and item_private = 0 + $sql_options $item_normal + group by term order by total desc %s", + intval($uid), + intval($type), + intval(TERM_OBJ_POST), + intval($restrict), + ((intval($count)) ? "limit $count" : '') + ); + + if(! $r) + return array(); + + return Zotlabs\Text\Tagadelic::calc($r); + +} + + + + + function dir_tagadelic($count = 0) { $count = intval($count); @@ -277,6 +374,26 @@ function catblock($uid,$count = 0,$authors = '',$owner = '', $flags = 0,$restric return $o; } +function card_catblock($uid,$count = 0,$authors = '',$owner = '', $flags = 0,$restrict = 0,$type = TERM_CATEGORY) { + $o = ''; + + $r = card_tagadelic($uid,$count,$authors,$owner,$flags,$restrict,$type); + + if($r) { + $c = q("select channel_address from channel where channel_id = %d limit 1", + intval($uid) + ); + + $o = '<div class="tagblock widget"><h3>' . t('Categories') . '</h3><div class="tags" align="center">'; + foreach($r as $rr) { + $o .= '<a href="cards/' . $c[0]['channel_address']. '?f=&cat=' . urlencode($rr[0]).'" class="tag'.$rr[2].'">'.$rr[0].'</a> ' . "\r\n"; + } + $o .= '</div></div>'; + } + + return $o; +} + function dir_tagblock($link,$r) { $o = ''; |