2021-12-03 03:01:39 +00:00
< ? php
/** @file */
2013-06-20 04:50:14 +00:00
2022-02-16 04:08:28 +00:00
use Code\Lib\Apps ;
use Code\Lib\Channel ;
use Code\Extend\Hook ;
2019-03-25 03:11:24 +00:00
2013-06-20 04:50:14 +00:00
// post categories and "save to file" use the same item.file table for storage.
// We will differentiate the different uses by wrapping categories in angle brackets
// and save to file categories in square brackets.
2021-12-03 03:01:39 +00:00
// To do this we need to escape these characters if they appear in our tag.
2013-06-20 04:50:14 +00:00
2021-12-03 03:01:39 +00:00
function file_tag_encode ( $s )
{
2023-06-12 19:21:37 +00:00
return str_replace ([ '<' , '>' , '[' , ']' ], [ '%3c' , '%3e' , '%5b' , '%5d' ], $s );
2013-06-20 04:50:14 +00:00
}
2021-12-03 03:01:39 +00:00
function file_tag_decode ( $s )
{
2023-06-12 19:21:37 +00:00
return str_replace ([ '%3c' , '%3e' , '%5b' , '%5d' ], [ '<' , '>' , '[' , ']' ], $s );
2013-06-20 04:50:14 +00:00
}
2021-12-03 03:01:39 +00:00
function file_tag_file_query ( $table , $s , $type = 'file' )
{
2013-06-20 04:50:14 +00:00
2021-12-03 03:01:39 +00:00
if ( $type == 'file' ) {
$termtype = TERM_FILE ;
} else {
$termtype = TERM_CATEGORY ;
}
2013-06-20 04:50:14 +00:00
2021-12-03 03:01:39 +00:00
return sprintf (
" AND " . (( $table ) ? dbesc ( $table ) . '.' : '' ) . " id in (select term.oid from term where term.ttype = %d and term.term = '%s' and term.uid = " . (( $table ) ? dbesc ( $table ) . '.' : '' ) . " uid ) " ,
intval ( $termtype ),
protect_sprintf ( dbesc ( $s ))
);
2013-06-20 04:50:14 +00:00
}
2021-12-03 03:01:39 +00:00
function term_query ( $table , $s , $type = TERM_UNKNOWN , $type2 = '' )
{
if ( $type2 ) {
return sprintf (
" AND " . (( $table ) ? dbesc ( $table ) . '.' : '' ) . " id in (select term.oid from term where term.ttype 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.ttype = %d and term.term = '%s' and term.uid = " . (( $table ) ? dbesc ( $table ) . '.' : '' ) . " uid ) " ,
intval ( $type ),
protect_sprintf ( dbesc ( $s ))
);
}
2013-06-20 04:50:14 +00:00
}
2021-12-03 03:01:39 +00:00
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 and item.verb != '%s' " ,
intval ( $type ),
intval ( $type2 ),
dbesc ( $s ),
intval ( $uid ),
dbesc ( ACTIVITY_UPDATE )
);
} 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 and item.verb != '%s' " ,
intval ( $type ),
dbesc ( $s ),
intval ( $uid ),
dbesc ( ACTIVITY_UPDATE )
);
}
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 " ;
2017-06-07 00:38:34 +00:00
}
2021-12-03 03:01:39 +00:00
function store_item_tag ( $uid , $iid , $otype , $type , $term , $url = '' )
{
if ( ! $term ) {
return false ;
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
$r = q (
" select * from term
2016-06-01 04:45:33 +00:00
where uid = % d and oid = % d and otype = % d and ttype = % d
2013-06-20 04:50:14 +00:00
and term = '%s' and url = '%s' " ,
2021-12-03 03:01:39 +00:00
intval ( $uid ),
intval ( $iid ),
intval ( $otype ),
intval ( $type ),
dbesc ( $term ),
dbesc ( $url )
);
if ( $r ) {
return false ;
}
$r = q (
" insert into term (uid, oid, otype, ttype, term, url)
2013-06-20 04:50:14 +00:00
values ( % d , % d , % d , % d , '%s' , '%s' ) " ,
2021-12-03 03:01:39 +00:00
intval ( $uid ),
intval ( $iid ),
intval ( $otype ),
intval ( $type ),
dbesc ( $term ),
dbesc ( $url )
);
return $r ;
2013-06-20 04:50:14 +00:00
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
function get_terms_oftype ( $arr , $type )
{
$ret = [];
if ( ! ( is_array ( $arr ) && count ( $arr ))) {
return $ret ;
}
2013-06-20 04:50:14 +00:00
2021-12-03 03:01:39 +00:00
if ( ! is_array ( $type )) {
2023-06-12 19:21:37 +00:00
$type = [ $type ];
2021-12-03 03:01:39 +00:00
}
2013-06-20 04:50:14 +00:00
2021-12-03 03:01:39 +00:00
foreach ( $type as $t ) {
foreach ( $arr as $x ) {
if ( $x [ 'ttype' ] == $t ) {
$ret [] = $x ;
}
}
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
return $ret ;
2013-06-20 04:50:14 +00:00
}
2021-12-03 03:01:39 +00:00
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 {
return $s ;
}
if ( $term [ 'url' ]) {
$s .= '<a href="' . $term [ 'url' ] . '">' . htmlspecialchars ( $term [ 'term' ], ENT_COMPAT , 'UTF-8' ) . '</a>' ;
} else {
$s .= htmlspecialchars ( $term [ 'term' ], ENT_COMPAT , 'UTF-8' );
}
return $s ;
2013-06-20 04:50:14 +00:00
}
2013-06-21 22:15:07 +00:00
// Tag cloud functions - need to be adpated to this database format
2021-12-03 03:01:39 +00:00
function tagadelic ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_HASHTAG )
{
2013-07-04 00:22:40 +00:00
2021-12-03 03:01:39 +00:00
require_once ( 'include/security.php' );
2023-06-11 23:13:03 +00:00
$channel = Channel :: from_id ( $uid );
if ( ! $channel ) {
return [];
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
if ( ! perm_is_allowed ( $uid , get_observer_hash (), 'view_stream' )) {
return [];
}
2015-02-18 02:13:20 +00:00
2015-11-27 01:35:41 +00:00
2021-12-03 03:01:39 +00:00
$item_normal = item_normal ();
$sql_options = item_permissions_sql ( $uid );
$count = intval ( $count );
2013-07-03 04:30:27 +00:00
2021-12-03 03:01:39 +00:00
if ( $flags ) {
if ( $flags === 'wall' ) {
$sql_options .= " and item_wall = 1 " ;
}
}
2013-10-27 23:30:55 +00:00
2021-12-03 03:01:39 +00:00
if ( $authors ) {
if ( ! is_array ( $authors )) {
2023-06-12 19:21:37 +00:00
$authors = [ $authors ];
2021-12-03 03:01:39 +00:00
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
$sql_options .= " and author_xchan in ( " . stringify_array ( $authors , true ) . " ) " ;
}
2013-07-04 00:22:40 +00:00
2021-12-03 03:01:39 +00:00
if ( $owner ) {
$sql_options .= " and owner_xchan = ' " . dbesc ( $owner ) . " ' " ;
}
2015-07-16 04:43:42 +00:00
2023-06-12 19:21:37 +00:00
// This needs fixing so that cloned groups will show categories originating
// from other group clone instances - not just this one. For now, this is needed
// to prevent a group from displaying personal categories of the post author;
// when posted remotely.
2023-06-11 23:43:38 +00:00
$urlFilter = ( $type === TERM_CATEGORY && intval ( $channel [ 'xchan_type' ]) === XCHAN_TYPE_GROUP ) ? " and url like ' " . Channel :: url ( $channel ) . " %%' " : '' ;
2023-06-11 23:13:03 +00:00
2021-12-03 03:01:39 +00:00
// Fetch tags
$r = q (
" select term, count(term) as total from term left join item on term.oid = item.id
2016-06-01 04:45:33 +00:00
where term . uid = % d and term . ttype = % d
2018-03-23 04:23:12 +00:00
and otype = % d and item_type = % d
2023-06-11 23:13:03 +00:00
$sql_options $item_normal $urlFilter
2013-06-21 22:15:07 +00:00
group by term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
intval ( $uid ),
intval ( $type ),
intval ( TERM_OBJ_POST ),
intval ( $restrict ),
(( intval ( $count )) ? " limit $count " : '' )
);
2018-03-23 04:23:12 +00:00
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
if ( ! $r ) {
return [];
}
2015-03-03 23:03:19 +00:00
2022-02-16 04:08:28 +00:00
return Code\Text\Tagadelic :: calc ( $r );
2013-06-21 22:15:07 +00:00
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
function card_tagadelic ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_CATEGORY )
{
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
require_once ( 'include/security.php' );
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
if ( ! perm_is_allowed ( $uid , get_observer_hash (), 'view_pages' )) {
return [];
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
$item_normal = " and item.item_hidden = 0 and item.item_deleted = 0 and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
2018-04-10 04:44:04 +00:00
and item . item_blocked = 0 and item . obj_type != 'http://purl.org/zot/activity/file' " ;
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
$sql_options = item_permissions_sql ( $uid );
$count = intval ( $count );
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
if ( $flags ) {
if ( $flags === 'wall' ) {
$sql_options .= " and item_wall = 1 " ;
}
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
if ( $authors ) {
if ( ! is_array ( $authors )) {
2023-06-12 19:21:37 +00:00
$authors = [ $authors ];
2021-12-03 03:01:39 +00:00
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
$sql_options .= " and author_xchan in ( " . stringify_array ( $authors , true ) . " ) " ;
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
if ( $owner ) {
$sql_options .= " and owner_xchan = ' " . dbesc ( $owner ) . " ' " ;
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
// Fetch tags
2018-04-10 04:44:04 +00:00
2021-12-03 03:01:39 +00:00
$r = q (
" select term, count(term) as total from term left join item on term.oid = item.id
2017-08-23 07:01:02 +00:00
where term . uid = % d and term . ttype = % d
2018-04-10 04:44:04 +00:00
and otype = % d and item_type = % d
2017-08-23 07:01:02 +00:00
$sql_options $item_normal
group by term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
intval ( $uid ),
intval ( $type ),
intval ( TERM_OBJ_POST ),
intval ( ITEM_TYPE_CARD ),
(( intval ( $count )) ? " limit $count " : '' )
);
if ( ! $r ) {
return [];
}
2017-08-23 07:01:02 +00:00
2022-02-16 04:08:28 +00:00
return Code\Text\Tagadelic :: calc ( $r );
2017-08-23 07:01:02 +00:00
}
2021-12-03 03:01:39 +00:00
function article_tagadelic ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_CATEGORY )
{
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
require_once ( 'include/security.php' );
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if ( ! perm_is_allowed ( $uid , get_observer_hash (), 'view_pages' )) {
return [];
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
$item_normal = " and item.item_hidden = 0 and item.item_deleted = 0 and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
2018-04-10 04:44:04 +00:00
and item . item_blocked = 0 and item . obj_type != 'http://purl.org/zot/activity/file' " ;
2021-12-03 03:01:39 +00:00
$sql_options = item_permissions_sql ( $uid );
$count = intval ( $count );
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if ( $flags ) {
if ( $flags === 'wall' ) {
$sql_options .= " and item_wall = 1 " ;
}
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if ( $authors ) {
if ( ! is_array ( $authors )) {
2023-06-12 19:21:37 +00:00
$authors = [ $authors ];
2021-12-03 03:01:39 +00:00
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
$sql_options .= " and author_xchan in ( " . stringify_array ( $authors , true ) . " ) " ;
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if ( $owner ) {
$sql_options .= " and owner_xchan = ' " . dbesc ( $owner ) . " ' " ;
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
// Fetch tags
$r = q (
" select term, count(term) as total from term left join item on term.oid = item.id
2017-11-22 23:39:06 +00:00
where term . uid = % d and term . ttype = % d
2018-04-10 04:44:04 +00:00
and otype = % d and item_type = % d
2017-11-22 23:39:06 +00:00
$sql_options $item_normal
group by term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
intval ( $uid ),
intval ( $type ),
intval ( TERM_OBJ_POST ),
intval ( ITEM_TYPE_ARTICLE ),
(( intval ( $count )) ? " limit $count " : '' )
);
if ( ! $r ) {
return [];
}
2017-11-22 23:39:06 +00:00
2022-02-16 04:08:28 +00:00
return Code\Text\Tagadelic :: calc ( $r );
2017-11-22 23:39:06 +00:00
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
function pubtagblock ( $mode , $limit , $recent = 0 , $safemode = 1 , $type = TERM_HASHTAG )
{
$o = '' ;
2018-04-18 03:08:14 +00:00
2021-12-03 03:01:39 +00:00
$r = pub_tagadelic ( $mode , $limit , $recent , $safemode , $type );
2018-04-20 00:43:50 +00:00
2021-12-03 03:01:39 +00:00
$link = z_root () . '/pubstream' ;
2018-04-18 03:08:14 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$o = '<div class="tagblock widget"><h3>' . (( $recent ) ? t ( 'Popular Tags' ) : t ( 'Tags' )) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<span class="tag' . $rr [ 2 ] . '">#</span><a href="' . $link . '/' . '?f=&tag=' . urlencode ( $rr [ 0 ]) . '" class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2018-04-18 03:08:14 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2018-04-18 03:08:14 +00:00
}
2021-12-03 03:01:39 +00:00
function pub_tagadelic ( $mode , $limit , $recent , $safemode , $type )
{
2018-04-18 03:08:14 +00:00
2021-12-03 03:01:39 +00:00
$item_normal = item_normal ();
$count = intval ( $limit );
2018-04-18 03:08:14 +00:00
2021-12-03 03:01:39 +00:00
if ( intval ( $mode ) === PUBLIC_STREAM_SITE ) {
$uids = " and item_private = 0 and item_wall = 1 " ;
} else {
2022-01-25 01:26:12 +00:00
$sys = Channel :: get_system ();
2018-04-18 03:08:14 +00:00
$uids = " and item.uid = " . intval ( $sys [ 'channel_id' ]) . " " ;
2021-12-03 03:01:39 +00:00
$sql_extra = " and item_private = 0 " ;
2018-04-18 03:08:14 +00:00
}
2021-12-03 03:01:39 +00:00
if ( $recent ) {
$sql_extra .= " and item.created > ' " . datetime_convert ( 'UTC' , 'UTC' , 'now - ' . intval ( $recent ) . ' days ' ) . " ' " ;
}
if ( $safemode ) {
$unsafetags = get_config ( 'system' , 'unsafepubtags' , [ 'boobs' , 'bot' , 'rss' , 'girl' , 'girls' , 'nsfw' , 'sexy' , 'nude' ]);
if ( $unsafetags ) {
$sql_extra .= " and not term.term in ( " . stringify_array ( $unsafetags , true ) . " ) " ;
}
}
2018-04-18 03:08:14 +00:00
2018-04-18 04:48:43 +00:00
2021-12-03 03:01:39 +00:00
// Fetch tags
$r = q (
" select term, count(term) as total from term left join item on term.oid = item.id
2018-04-18 03:08:14 +00:00
where term . ttype = % d
and otype = % d and item_type = % d
$sql_extra $uids $item_normal
group by term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
intval ( $type ),
intval ( TERM_OBJ_POST ),
intval ( ITEM_TYPE_POST ),
(( intval ( $count )) ? " limit $count " : '' )
);
if ( ! $r ) {
return [];
}
2022-02-16 04:08:28 +00:00
return Code\Text\Tagadelic :: calc ( $r );
2018-04-18 03:08:14 +00:00
}
2021-12-03 03:01:39 +00:00
function dir_tagadelic ( $count = 0 , $hub = '' , $type = 0 , $safe = '' )
{
2013-09-18 05:52:46 +00:00
2021-12-03 03:01:39 +00:00
$count = intval ( $count );
2013-09-18 05:52:46 +00:00
2021-12-03 03:01:39 +00:00
$sql_extra = EMPTY_STR ;
2019-04-03 02:20:40 +00:00
2021-12-03 03:01:39 +00:00
if ( $type ) {
return [];
}
2019-04-03 02:20:40 +00:00
2021-12-03 03:01:39 +00:00
if ( $hub ) {
$r = q (
" select xtag_term as term, count(xtag_term) as total from xtag
2017-12-26 21:19:27 +00:00
left join hubloc on xtag_hash = hubloc_hash
2022-06-17 02:46:54 +00:00
where xtag_flags = 0 and xtag_hash in ( select hubloc_hash from hubloc where hubloc_host = '%s' and hubloc_deleted = 0 )
2019-04-03 02:20:40 +00:00
$sql_extra
2017-12-26 21:19:27 +00:00
group by xtag_term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
dbesc ( $hub ),
(( intval ( $count )) ? " limit $count " : '' )
);
} else {
$r = q (
" select xtag_term as term, count(xtag_term) as total from xtag left join xchan on xtag_hash = xchan_hash where xtag_flags = 0
2019-06-21 06:17:04 +00:00
$sql_extra $safe
2017-12-26 21:19:27 +00:00
group by xtag_term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
(( intval ( $count )) ? " limit $count " : '' )
);
}
if ( ! $r ) {
return [];
}
2013-09-18 05:52:46 +00:00
2022-02-16 04:08:28 +00:00
return Code\Text\Tagadelic :: calc ( $r );
2013-09-18 05:52:46 +00:00
}
2021-12-03 03:01:39 +00:00
function app_tagblock ( $link , $count = 0 )
{
$o = '' ;
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
$r = app_tagadelic ( $count );
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$o = '<div class="tagblock widget"><h3>' . t ( 'Categories' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<a href="' . $link . '/' . '?f=&cat=' . urlencode ( $rr [ 0 ]) . '" class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2016-05-05 01:27:46 +00:00
}
2021-12-03 03:01:39 +00:00
function app_tagadelic ( $count = 0 )
{
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
if ( ! local_channel ()) {
return '' ;
}
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
$count = intval ( $count );
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
// Fetch tags
$r = q (
" select term, count(term) as total from term left join app on term.uid = app_channel where term.uid = %d
2016-05-05 01:27:46 +00:00
and term . otype = % d group by term order by total desc % s " ,
2021-12-03 03:01:39 +00:00
intval ( local_channel ()),
intval ( TERM_OBJ_APP ),
(( intval ( $count )) ? " limit $count " : '' )
);
2016-05-05 01:27:46 +00:00
2021-12-03 03:01:39 +00:00
if ( ! $r ) {
return [];
}
2016-05-05 01:27:46 +00:00
2022-02-16 04:08:28 +00:00
return Code\Text\Tagadelic :: calc ( $r );
2016-05-05 01:27:46 +00:00
}
2021-12-03 03:01:39 +00:00
function tagblock ( $link , $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_HASHTAG )
{
$o = '' ;
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
$r = tagadelic ( $uid , $count , $authors , $owner , $flags , $restrict , $type );
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$o = '<div class="tagblock widget"><h3>' . t ( 'Tags' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<span class="tag' . $rr [ 2 ] . '">#</span><a href="' . $link . '/' . '?f=&tag=' . urlencode ( $rr [ 0 ]) . '" class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2013-06-21 22:15:07 +00:00
}
2013-09-18 05:52:46 +00:00
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
function wtagblock ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_HASHTAG )
{
$o = '' ;
2014-12-15 22:37:31 +00:00
2021-12-03 03:01:39 +00:00
$r = tagadelic ( $uid , $count , $authors , $owner , $flags , $restrict , $type );
2014-12-15 22:37:31 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$c = q (
" select channel_address from channel where channel_id = %d limit 1 " ,
intval ( $uid )
);
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
$o = '<div class="tagblock widget"><h3>' . t ( 'Tags' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<span class="tag' . $rr [ 2 ] . '">#</span><a href="channel/' . $c [ 0 ][ 'channel_address' ] . '?f=&tag=' . urlencode ( $rr [ 0 ]) . '" class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2014-11-06 09:24:04 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
}
2019-03-25 03:08:23 +00:00
2014-11-06 09:24:04 +00:00
2021-12-03 03:01:39 +00:00
function catblock ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_CATEGORY )
{
$o = '' ;
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
if ( ! Apps :: system_app_installed ( $uid , 'Categories' )) {
return $o ;
}
2014-11-06 09:24:04 +00:00
2021-12-03 03:01:39 +00:00
$r = tagadelic ( $uid , $count , $authors , $owner , $flags , $restrict , $type );
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$c = q (
" select channel_address from channel where channel_id = %d limit 1 " ,
intval ( $uid )
);
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
$o = '<div class="tagblock widget"><h3>' . t ( 'Categories' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<a href="channel/' . $c [ 0 ][ 'channel_address' ] . '?f=&cat=' . urlencode ( $rr [ 0 ]) . '" class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2017-08-23 07:01:02 +00:00
}
2021-12-03 03:01:39 +00:00
function card_catblock ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_CATEGORY )
{
$o = '' ;
2014-11-06 09:24:04 +00:00
2021-12-03 03:01:39 +00:00
$r = card_tagadelic ( $uid , $count , $authors , $owner , $flags , $restrict , $type );
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$c = q (
" select channel_address from channel where channel_id = %d limit 1 " ,
intval ( $uid )
);
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
$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>' ;
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2017-11-22 23:39:06 +00:00
}
2021-12-03 03:01:39 +00:00
function article_catblock ( $uid , $count = 0 , $authors = '' , $owner = '' , $flags = 0 , $restrict = 0 , $type = TERM_CATEGORY )
{
$o = '' ;
2013-09-18 05:52:46 +00:00
2021-12-03 03:01:39 +00:00
$r = article_tagadelic ( $uid , $count , $authors , $owner , $flags , $restrict , $type );
2013-09-18 05:52:46 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$c = q (
" select channel_address from channel where channel_id = %d limit 1 " ,
intval ( $uid )
);
2013-12-20 20:43:04 +00:00
2021-12-03 03:01:39 +00:00
$o = '<div class="tagblock widget"><h3>' . t ( 'Categories' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<a href="articles/' . $c [ 0 ][ 'channel_address' ] . '?f=&cat=' . urlencode ( $rr [ 0 ]) . '" class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2015-03-03 23:03:19 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2013-09-18 05:52:46 +00:00
}
2021-12-03 03:01:39 +00:00
function dir_tagblock ( $link , $r )
{
$o = '' ;
2013-09-18 05:52:46 +00:00
2021-12-03 03:01:39 +00:00
$observer = get_observer_hash ();
2013-07-04 02:30:52 +00:00
2021-12-03 03:01:39 +00:00
if ( ! $r ) {
$r = App :: $data [ 'directory_keywords' ];
}
2013-07-04 03:37:39 +00:00
2021-12-03 03:01:39 +00:00
if ( $r ) {
$o = '<div class="dirtagblock widget"><h3>' . t ( 'Keywords' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<a href="' . $link . '/' . '?f=&keywords=' . urlencode ( $rr [ 'term' ]) . '" class="tag' . $rr [ 'normalise' ] . '" rel="nofollow" >' . $rr [ 'term' ] . '</a> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
2013-07-05 03:35:42 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
2013-12-29 01:04:23 +00:00
}
2021-12-03 03:01:39 +00:00
/**
* verbs : [ 0 ] = first person singular , e . g . " I want " , [ 1 ] = 3 rd person singular , e . g . " Bill wants "
* We use the first person form when creating an activity , but the third person for use in activities
* FIXME : There is no accounting for verb gender for languages where this is significant . We may eventually
* require obj_verbs () to provide full conjugations and specify which form to use in the $_REQUEST params to this module .
*/
2013-12-29 01:04:23 +00:00
2021-12-03 03:01:39 +00:00
function obj_verbs ()
{
2023-06-12 19:21:37 +00:00
$verbs = [
'has' => [ t ( 'have' ), t ( 'has' )],
'wants' => [ t ( 'want' ), t ( 'wants' )],
'likes' => [ t ( 'like' ), t ( 'likes' )],
'dislikes' => [ t ( 'dislike' ), t ( 'dislikes' )],
];
$arr = [ 'verbs' => $verbs ];
2022-02-12 08:50:48 +00:00
Hook :: call ( 'obj_verbs' , $arr );
2013-12-29 01:04:23 +00:00
2021-12-03 03:01:39 +00:00
return $arr [ 'verbs' ];
}
2013-12-29 01:04:23 +00:00
2021-12-03 03:01:39 +00:00
function obj_verb_selector ( $current = '' )
{
$verbs = obj_verbs ();
$o = '<select class="obj-verb-selector" name="verb">' ;
foreach ( $verbs as $k => $v ) {
$selected = (( $k == $current ) ? ' selected="selected" ' : '' );
$o .= '<option value="' . urlencode ( $k ) . '"' . $selected . '>' . $v [ 1 ] . '</option>' ;
}
$o .= '</select>' ;
2013-12-29 01:04:23 +00:00
2021-12-03 03:01:39 +00:00
return $o ;
}
2014-06-23 12:19:28 +00:00
2021-12-03 03:01:39 +00:00
function get_things ( $profile_hash , $uid )
{
$sql_extra = (( $profile_hash ) ? " and obj_page = ' " . $profile_hash . " ' " : '' );
$r = q (
" select * from obj where obj_channel = %d and obj_type = %d $sql_extra order by obj_verb, obj_term " ,
intval ( $uid ),
intval ( TERM_OBJ_THING )
);
$things = $sorted_things = null ;
$profile_hashes = [];
if ( $r ) {
// if no profile_hash was specified (display on profile page mode), match each of the things to a profile name
// (list all my things mode). This is harder than it sounds.
foreach ( $r as $rr ) {
$rr [ 'profile_name' ] = '' ;
if ( ! in_array ( $rr [ 'obj_obj' ], $profile_hashes )) {
$profile_hashes [] = $rr [ 'obj_obj' ];
}
}
if ( ! $profile_hash ) {
$exp = stringify_array ( $profile_hashes , true );
$p = q ( " select profile_guid as hash, profile_name as name from profile where profile_guid in ( $exp ) " );
if ( $p ) {
foreach ( $r as $rr ) {
foreach ( $p as $pp ) {
if ( $rr [ 'obj_page' ] == $pp [ 'hash' ]) {
$rr [ 'profile_name' ] == $pp [ 'name' ];
}
}
}
}
}
$things = [];
// Use the system obj_verbs array as a sort key, since we don't really
// want an alphabetic sort. To change the order, use a plugin to
// alter the obj_verbs() array or alter it in code. Unknown verbs come
// after the known ones - in no particular order.
$v = obj_verbs ();
foreach ( $v as $k => $foo ) {
$things [ $k ] = null ;
}
foreach ( $r as $rr ) {
$l = q (
" select xchan_name, xchan_photo_s, xchan_url from likes left join xchan on liker = xchan_hash where
2014-06-23 12:19:28 +00:00
target_type = '%s' and target_id = '%s' and channel_id = % d " ,
2021-12-03 03:01:39 +00:00
dbesc ( ACTIVITY_OBJ_THING ),
dbesc ( $rr [ 'obj_obj' ]),
intval ( $uid )
);
for ( $x = 0 ; $x < count ( $l ); $x ++ ) {
$l [ $x ][ 'xchan_url' ] = zid ( $l [ $x ][ 'xchan_url' ]);
$l [ $x ][ 'xchan_photo_s' ] = zid ( $l [ $x ][ 'xchan_photo_s' ]);
}
if ( ! $things [ $rr [ 'obj_verb' ]]) {
$things [ $rr [ 'obj_verb' ]] = [];
}
2023-06-12 19:21:37 +00:00
$things [ $rr [ 'obj_verb' ]][] = [ 'term' => $rr [ 'obj_term' ], 'url' => $rr [ 'obj_url' ], 'img' => $rr [ 'obj_imgurl' ], 'editurl' => z_root () . '/thing/' . $rr [ 'obj_obj' ], 'profile' => $rr [ 'profile_name' ], 'term_hash' => $rr [ 'obj_obj' ], 'likes' => $l , 'like_count' => count ( $l ), 'like_label' => tt ( 'Like' , 'Likes' , count ( $l ), 'noun' )];
2021-12-03 03:01:39 +00:00
}
$sorted_things = [];
if ( $things ) {
foreach ( $things as $k => $v ) {
if ( is_array ( $things [ $k ])) {
$sorted_things [ $k ] = $v ;
}
}
}
}
2014-06-23 12:19:28 +00:00
//logger('things: ' . print_r($sorted_things,true));
2013-12-29 01:04:23 +00:00
2021-12-03 03:01:39 +00:00
return $sorted_things ;
2015-07-07 19:41:37 +00:00
}