2014-12-07 18:27:14 +00:00
< ? php
/**
* @ file include / widgets . php
*
* @ brief This file contains the widgets .
*/
2013-10-27 23:30:55 +00:00
2013-12-20 20:43:04 +00:00
require_once ( 'include/dir_fns.php' );
require_once ( 'include/contact_widgets.php' );
2015-11-18 10:45:22 +00:00
require_once ( 'include/attach.php' );
2016-05-22 23:54:30 +00:00
2013-10-27 23:30:55 +00:00
function widget_profile ( $args ) {
2016-04-01 03:15:47 +00:00
2016-05-23 00:52:30 +00:00
$block = observer_prohibited ();
2016-03-31 23:06:03 +00:00
return profile_sidebar ( App :: $profile , $block , true );
2013-10-27 23:30:55 +00:00
}
2016-02-09 02:16:42 +00:00
function widget_zcard ( $args ) {
2016-04-01 03:15:47 +00:00
2016-05-23 00:52:30 +00:00
$block = observer_prohibited ();
2016-03-31 23:06:03 +00:00
$channel = channelx_by_n ( App :: $profile_uid );
2016-02-09 02:16:42 +00:00
return get_zcard ( $channel , get_observer_hash (), array ( 'width' => 875 ));
}
2013-10-27 23:30:55 +00:00
// FIXME The problem with the next widget is that we don't have a search function for webpages that we can send the links to.
// Then we should also provide an option to search webpages and conversations.
function widget_tagcloud ( $args ) {
$o = '' ;
2014-12-07 18:27:14 +00:00
//$tab = 0;
2016-04-01 03:15:47 +00:00
2016-03-31 23:06:03 +00:00
$uid = App :: $profile_uid ;
2013-10-27 23:30:55 +00:00
$count = (( x ( $args , 'count' )) ? intval ( $args [ 'count' ]) : 24 );
$flags = 0 ;
$type = TERM_CATEGORY ;
2014-12-07 18:27:14 +00:00
// FIXME there exists no $authors variable
2015-07-16 04:43:42 +00:00
$r = tagadelic ( $uid , $count , $authors , $owner , $flags , ITEM_TYPE_WEBPAGE , $type );
2013-10-27 23:30:55 +00:00
if ( $r ) {
$o = '<div class="tagblock widget"><h3>' . t ( 'Categories' ) . '</h3><div class="tags" align="center">' ;
foreach ( $r as $rr ) {
$o .= '<span class="tag' . $rr [ 2 ] . '">' . $rr [ 0 ] . '</span> ' . " \r \n " ;
}
$o .= '</div></div>' ;
}
return $o ;
}
2013-12-09 00:04:28 +00:00
function widget_collections ( $args ) {
require_once ( 'include/group.php' );
2013-12-20 07:56:37 +00:00
$mode = (( array_key_exists ( 'mode' , $args )) ? $args [ 'mode' ] : 'conversation' );
switch ( $mode ) {
case 'conversation' :
$every = argv ( 0 );
$each = argv ( 0 );
$edit = true ;
$current = $_REQUEST [ 'gid' ];
$abook_id = 0 ;
$wmode = 0 ;
break ;
2014-08-18 00:48:41 +00:00
case 'connections' :
$every = 'connections' ;
$each = 'group' ;
$edit = true ;
$current = $_REQUEST [ 'gid' ];
$abook_id = 0 ;
$wmode = 0 ;
2013-12-20 07:56:37 +00:00
case 'groups' :
$every = 'connections' ;
$each = argv ( 0 );
$edit = false ;
$current = intval ( argv ( 1 ));
$abook_id = 0 ;
$wmode = 1 ;
break ;
case 'abook' :
$every = 'connections' ;
$each = 'group' ;
$edit = false ;
$current = 0 ;
2016-03-31 23:06:03 +00:00
$abook_id = App :: $poi [ 'abook_xchan' ];
2013-12-20 07:56:37 +00:00
$wmode = 1 ;
break ;
default :
return '' ;
break ;
}
2013-12-09 00:04:28 +00:00
2014-12-07 18:27:14 +00:00
return group_side ( $every , $each , $edit , $current , $abook_id , $wmode );
2013-12-09 04:08:50 +00:00
}
2014-05-16 03:20:20 +00:00
function widget_appselect ( $arr ) {
return replace_macros ( get_markup_template ( 'app_select.tpl' ), array (
2014-05-22 03:54:09 +00:00
'$title' => t ( 'Apps' ),
2014-05-16 03:20:20 +00:00
'$system' => t ( 'System' ),
2015-01-29 04:56:04 +00:00
'$authed' => (( local_channel ()) ? true : false ),
2014-05-22 03:54:09 +00:00
'$personal' => t ( 'Personal' ),
2016-05-04 03:37:05 +00:00
'$new' => t ( 'New App' ),
'$edit' => t ( 'Edit App' )
2014-05-16 03:20:20 +00:00
));
}
2013-12-09 04:08:50 +00:00
function widget_suggestions ( $arr ) {
2015-01-29 04:56:04 +00:00
if (( ! local_channel ()) || ( ! feature_enabled ( local_channel (), 'suggest' )))
2013-12-11 11:01:28 +00:00
return '' ;
2013-12-09 04:08:50 +00:00
require_once ( 'include/socgraph.php' );
2015-01-29 04:56:04 +00:00
$r = suggestion_query ( local_channel (), get_observer_hash (), 0 , 20 );
2013-12-09 04:08:50 +00:00
if ( ! $r ) {
return ;
}
$arr = array ();
// Get two random entries from the top 20 returned.
// We'll grab the first one and the one immediately following.
2016-10-01 22:41:25 +00:00
// This will throw some entropy intot he situation so you won't
2013-12-09 04:08:50 +00:00
// be looking at the same two mug shots every time the widget runs
$index = (( count ( $r ) > 2 ) ? mt_rand ( 0 , count ( $r ) - 2 ) : 0 );
for ( $x = $index ; $x <= ( $index + 1 ); $x ++ ) {
$rr = $r [ $x ];
if ( ! $rr [ 'xchan_url' ])
break ;
2014-12-07 18:27:14 +00:00
2013-12-09 04:08:50 +00:00
$connlnk = z_root () . '/follow/?url=' . $rr [ 'xchan_addr' ];
$arr [] = array (
'url' => chanlink_url ( $rr [ 'xchan_url' ]),
'profile' => $rr [ 'xchan_url' ],
'name' => $rr [ 'xchan_name' ],
'photo' => $rr [ 'xchan_photo_m' ],
2015-07-07 12:46:47 +00:00
'ignlnk' => z_root () . '/directory?ignore=' . $rr [ 'xchan_hash' ],
2013-12-09 04:08:50 +00:00
'conntxt' => t ( 'Connect' ),
'connlnk' => $connlnk ,
'ignore' => t ( 'Ignore/Hide' )
);
}
$o = replace_macros ( get_markup_template ( 'suggest_widget.tpl' ), array (
'$title' => t ( 'Suggestions' ),
'$more' => t ( 'See more...' ),
'$entries' => $arr
));
return $o ;
2013-12-09 08:12:44 +00:00
}
function widget_follow ( $args ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-09 08:12:44 +00:00
return '' ;
2014-12-07 18:27:14 +00:00
2016-04-01 03:15:47 +00:00
$uid = App :: $channel [ 'channel_id' ];
2015-06-15 04:08:00 +00:00
$r = q ( " select count(*) as total from abook where abook_channel = %d and abook_self = 0 " ,
intval ( $uid )
2013-12-09 08:12:44 +00:00
);
if ( $r )
2016-10-01 22:41:25 +00:00
$total_channels = $r [ 0 ][ 'total' ];
2013-12-09 08:12:44 +00:00
$limit = service_class_fetch ( $uid , 'total_channels' );
if ( $limit !== false ) {
2014-12-07 18:27:14 +00:00
$abook_usage_message = sprintf ( t ( " You have %1 $ .0f of %2 $ .0f allowed connections. " ), $total_channels , $limit );
2013-12-09 08:12:44 +00:00
}
else {
2014-12-07 18:27:14 +00:00
$abook_usage_message = '' ;
2013-12-09 08:12:44 +00:00
}
return replace_macros ( get_markup_template ( 'follow.tpl' ), array (
'$connect' => t ( 'Add New Connection' ),
2016-01-14 09:36:45 +00:00
'$desc' => t ( 'Enter channel address' ),
2016-01-14 12:50:47 +00:00
'$hint' => t ( 'Examples: bob@example.com, https://example.com/barbara' ),
2013-12-09 08:12:44 +00:00
'$follow' => t ( 'Connect' ),
'$abook_usage_message' => $abook_usage_message
));
}
2013-12-09 23:27:46 +00:00
function widget_notes ( $arr ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-09 23:27:46 +00:00
return '' ;
2015-01-29 04:56:04 +00:00
if ( ! feature_enabled ( local_channel (), 'private_notes' ))
2013-12-10 02:54:50 +00:00
return '' ;
2015-01-29 04:56:04 +00:00
$text = get_pconfig ( local_channel (), 'notes' , 'text' );
2013-12-09 23:27:46 +00:00
$o = replace_macros ( get_markup_template ( 'notes.tpl' ), array (
'$banner' => t ( 'Notes' ),
'$text' => $text ,
'$save' => t ( 'Save' ),
));
2014-12-07 18:27:14 +00:00
2013-12-09 23:27:46 +00:00
return $o ;
}
2013-12-10 05:20:55 +00:00
function widget_savedsearch ( $arr ) {
2015-01-29 04:56:04 +00:00
if (( ! local_channel ()) || ( ! feature_enabled ( local_channel (), 'savedsearch' )))
2013-12-10 05:20:55 +00:00
return '' ;
2016-09-01 04:57:08 +00:00
$search = (( x ( $_GET , 'netsearch' )) ? $_GET [ 'netsearch' ] : '' );
if ( ! $search )
$search = (( x ( $_GET , 'search' )) ? $_GET [ 'search' ] : '' );
2016-10-01 22:41:25 +00:00
2013-12-10 05:20:55 +00:00
if ( x ( $_GET , 'searchsave' ) && $search ) {
2016-10-09 23:31:04 +00:00
$r = q ( " select * from term where uid = %d and ttype = %d and term = '%s' limit 1 " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ()),
2013-12-10 05:20:55 +00:00
intval ( TERM_SAVEDSEARCH ),
dbesc ( $search )
);
if ( ! $r ) {
2016-10-09 23:31:04 +00:00
q ( " insert into term ( uid,ttype,term ) values ( %d, %d, '%s') " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ()),
2013-12-10 05:20:55 +00:00
intval ( TERM_SAVEDSEARCH ),
dbesc ( $search )
);
}
}
if ( x ( $_GET , 'searchremove' ) && $search ) {
2016-10-09 23:31:04 +00:00
q ( " delete from term where uid = %d and ttype = %d and term = '%s' " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ()),
2013-12-10 05:20:55 +00:00
intval ( TERM_SAVEDSEARCH ),
dbesc ( $search )
);
$search = '' ;
}
2016-03-31 23:06:03 +00:00
$srchurl = App :: $query_string ;
2013-12-10 05:20:55 +00:00
$srchurl = rtrim ( preg_replace ( '/searchsave\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
$hasq = (( strpos ( $srchurl , '?' ) !== false ) ? true : false );
$srchurl = rtrim ( preg_replace ( '/searchremove\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
$srchurl = rtrim ( preg_replace ( '/search\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
2014-12-15 22:37:31 +00:00
$srchurl = rtrim ( preg_replace ( '/submit\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
2013-12-11 04:36:11 +00:00
$srchurl = str_replace ( array ( '?f=' , '&f=' ), array ( '' , '' ), $srchurl );
2014-12-15 22:37:31 +00:00
2013-12-10 05:20:55 +00:00
$hasq = (( strpos ( $srchurl , '?' ) !== false ) ? true : false );
2015-03-09 23:25:55 +00:00
$hasamp = (( strpos ( $srchurl , '&' ) !== false ) ? true : false );
2014-12-07 18:27:14 +00:00
2015-03-09 23:25:55 +00:00
if (( $hasamp ) && ( ! $hasq ))
2016-10-01 22:41:25 +00:00
$srchurl = substr ( $srchurl , 0 , strpos ( $srchurl , '&' )) . '?f=&' . substr ( $srchurl , strpos ( $srchurl , '&' ) + 1 );
2014-12-15 22:37:31 +00:00
2013-12-10 05:20:55 +00:00
$o = '' ;
2016-10-09 23:31:04 +00:00
$r = q ( " select tid,term from term WHERE uid = %d and ttype = %d " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ()),
2013-12-10 05:20:55 +00:00
intval ( TERM_SAVEDSEARCH )
);
$saved = array ();
if ( count ( $r )) {
foreach ( $r as $rr ) {
$saved [] = array (
'id' => $rr [ 'tid' ],
2014-12-07 18:27:14 +00:00
'term' => $rr [ 'term' ],
2015-03-09 23:25:55 +00:00
'dellink' => z_root () . '/' . $srchurl . (( $hasq || $hasamp ) ? '' : '?f=' ) . '&searchremove=1&search=' . urlencode ( $rr [ 'term' ]),
'srchlink' => z_root () . '/' . $srchurl . (( $hasq || $hasamp ) ? '' : '?f=' ) . '&search=' . urlencode ( $rr [ 'term' ]),
2013-12-12 10:15:02 +00:00
'displayterm' => htmlspecialchars ( $rr [ 'term' ], ENT_COMPAT , 'UTF-8' ),
2014-12-07 18:27:14 +00:00
'encodedterm' => urlencode ( $rr [ 'term' ]),
'delete' => t ( 'Remove term' ),
'selected' => ( $search == $rr [ 'term' ]),
2013-12-10 05:20:55 +00:00
);
}
2014-12-07 18:27:14 +00:00
}
2013-12-10 05:20:55 +00:00
$tpl = get_markup_template ( " saved_searches.tpl " );
$o = replace_macros ( $tpl , array (
'$title' => t ( 'Saved Searches' ),
'$add' => t ( 'add' ),
2014-12-07 18:27:14 +00:00
'$searchbox' => searchbox ( $search , 'netsearch-box' , $srchurl . (( $hasq ) ? '' : '?f=' ), true ),
2013-12-10 05:20:55 +00:00
'$saved' => $saved ,
));
2013-12-10 08:05:31 +00:00
2013-12-10 05:20:55 +00:00
return $o ;
}
2013-12-10 08:05:31 +00:00
2016-09-01 04:57:08 +00:00
function widget_sitesearch ( $arr ) {
$search = (( x ( $_GET , 'search' )) ? $_GET [ 'search' ] : '' );
2016-10-01 22:41:25 +00:00
2016-09-01 04:57:08 +00:00
$srchurl = App :: $query_string ;
$srchurl = rtrim ( preg_replace ( '/search\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
$srchurl = rtrim ( preg_replace ( '/submit\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
$srchurl = str_replace ( array ( '?f=' , '&f=' ), array ( '' , '' ), $srchurl );
$hasq = (( strpos ( $srchurl , '?' ) !== false ) ? true : false );
$hasamp = (( strpos ( $srchurl , '&' ) !== false ) ? true : false );
if (( $hasamp ) && ( ! $hasq ))
2016-10-01 22:41:25 +00:00
$srchurl = substr ( $srchurl , 0 , strpos ( $srchurl , '&' )) . '?f=&' . substr ( $srchurl , strpos ( $srchurl , '&' ) + 1 );
2016-09-01 04:57:08 +00:00
$o = '' ;
$saved = array ();
$tpl = get_markup_template ( " sitesearch.tpl " );
$o = replace_macros ( $tpl , array (
'$title' => t ( 'Search' ),
'$searchbox' => searchbox ( $search , 'netsearch-box' , $srchurl . (( $hasq ) ? '' : '?f=' ), false ),
'$saved' => $saved ,
));
return $o ;
}
2013-12-10 08:05:31 +00:00
function widget_filer ( $arr ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-10 08:05:31 +00:00
return '' ;
$selected = (( x ( $_REQUEST , 'file' )) ? $_REQUEST [ 'file' ] : '' );
$terms = array ();
2016-07-10 01:10:13 +00:00
$r = q ( " select distinct term from term where uid = %d and ttype = %d order by term asc " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ()),
2013-12-10 08:05:31 +00:00
intval ( TERM_FILE )
);
if ( ! $r )
return ;
foreach ( $r as $rr )
$terms [] = array ( 'name' => $rr [ 'term' ], 'selected' => (( $selected == $rr [ 'term' ]) ? 'selected' : '' ));
return replace_macros ( get_markup_template ( 'fileas_widget.tpl' ), array (
'$title' => t ( 'Saved Folders' ),
'$desc' => '' ,
'$sel_all' => (( $selected == '' ) ? 'selected' : '' ),
'$all' => t ( 'Everything' ),
'$terms' => $terms ,
2016-03-31 23:06:03 +00:00
'$base' => z_root () . '/' . App :: $cmd
2013-12-10 08:05:31 +00:00
));
}
function widget_archive ( $arr ) {
$o = '' ;
2016-03-31 23:06:03 +00:00
if ( ! App :: $profile_uid ) {
2013-12-10 08:05:31 +00:00
return '' ;
}
2016-03-31 23:06:03 +00:00
$uid = App :: $profile_uid ;
2013-12-10 08:05:31 +00:00
if ( ! feature_enabled ( $uid , 'archives' ))
return '' ;
2014-04-14 23:45:16 +00:00
if ( ! perm_is_allowed ( $uid , get_observer_hash (), 'view_stream' ))
return '' ;
2013-12-10 08:05:31 +00:00
$wall = (( array_key_exists ( 'wall' , $arr )) ? intval ( $arr [ 'wall' ]) : 0 );
2014-03-23 23:20:44 +00:00
$style = (( array_key_exists ( 'style' , $arr )) ? $arr [ 'style' ] : 'select' );
2014-11-03 22:49:03 +00:00
$showend = (( get_pconfig ( $uid , 'system' , 'archive_show_end_date' )) ? true : false );
$mindate = get_pconfig ( $uid , 'system' , 'archive_mindate' );
$visible_years = get_pconfig ( $uid , 'system' , 'archive_visible_years' );
if ( ! $visible_years )
$visible_years = 5 ;
2016-03-31 23:06:03 +00:00
$url = z_root () . '/' . App :: $cmd ;
2013-12-10 08:05:31 +00:00
2014-11-03 22:49:03 +00:00
$ret = list_post_dates ( $uid , $wall , $mindate );
2013-12-10 08:05:31 +00:00
if ( ! count ( $ret ))
return '' ;
2014-11-03 22:49:03 +00:00
$cutoff_year = intval ( datetime_convert ( '' , date_default_timezone_get (), 'now' , 'Y' )) - $visible_years ;
$cutoff = (( array_key_exists ( $cutoff_year , $ret )) ? true : false );
2013-12-10 08:05:31 +00:00
$o = replace_macros ( get_markup_template ( 'posted_date_widget.tpl' ), array (
'$title' => t ( 'Archives' ),
2014-11-03 22:49:03 +00:00
'$size' => $visible_years ,
'$cutoff_year' => $cutoff_year ,
'$cutoff' => $cutoff ,
2013-12-10 08:05:31 +00:00
'$url' => $url ,
2014-03-23 23:20:44 +00:00
'$style' => $style ,
2014-11-03 22:49:03 +00:00
'$showend' => $showend ,
2013-12-10 08:05:31 +00:00
'$dates' => $ret
));
return $o ;
}
2013-12-11 04:36:11 +00:00
function widget_fullprofile ( $arr ) {
2016-04-01 03:15:47 +00:00
2016-03-31 23:06:03 +00:00
if ( ! App :: $profile [ 'profile_uid' ])
2013-12-11 04:36:11 +00:00
return ;
2016-05-23 00:52:30 +00:00
$block = observer_prohibited ();
2013-12-11 04:36:11 +00:00
2016-03-31 23:06:03 +00:00
return profile_sidebar ( App :: $profile , $block );
2013-12-11 04:36:11 +00:00
}
2016-02-09 02:16:42 +00:00
function widget_shortprofile ( $arr ) {
2016-04-01 03:15:47 +00:00
2016-03-31 23:06:03 +00:00
if ( ! App :: $profile [ 'profile_uid' ])
2016-02-09 02:16:42 +00:00
return ;
2016-05-23 00:52:30 +00:00
$block = observer_prohibited ();
2016-02-09 02:16:42 +00:00
2016-03-31 23:06:03 +00:00
return profile_sidebar ( App :: $profile , $block , true , true );
2016-02-09 02:16:42 +00:00
}
2013-12-11 04:36:11 +00:00
function widget_categories ( $arr ) {
2016-04-01 03:15:47 +00:00
2014-04-14 23:45:16 +00:00
2016-03-31 23:06:03 +00:00
if ( App :: $profile [ 'profile_uid' ] && ( ! perm_is_allowed ( App :: $profile [ 'profile_uid' ], get_observer_hash (), 'view_stream' )))
2014-04-14 23:45:16 +00:00
return '' ;
2013-12-12 10:15:02 +00:00
$cat = (( x ( $_REQUEST , 'cat' )) ? htmlspecialchars ( $_REQUEST [ 'cat' ], ENT_COMPAT , 'UTF-8' ) : '' );
2016-03-31 23:06:03 +00:00
$srchurl = App :: $query_string ;
2013-12-11 04:36:11 +00:00
$srchurl = rtrim ( preg_replace ( '/cat\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
$srchurl = str_replace ( array ( '?f=' , '&f=' ), array ( '' , '' ), $srchurl );
2014-12-07 18:27:14 +00:00
return categories_widget ( $srchurl , $cat );
2015-07-16 04:01:18 +00:00
2013-12-11 04:36:11 +00:00
}
2016-05-05 07:45:38 +00:00
function widget_appcategories ( $arr ) {
if ( ! local_channel ())
return '' ;
$cat = (( x ( $_REQUEST , 'cat' )) ? htmlspecialchars ( $_REQUEST [ 'cat' ], ENT_COMPAT , 'UTF-8' ) : '' );
$srchurl = App :: $query_string ;
$srchurl = rtrim ( preg_replace ( '/cat\=[^\&].*?(\&|$)/is' , '' , $srchurl ), '&' );
$srchurl = str_replace ( array ( '?f=' , '&f=' ), array ( '' , '' ), $srchurl );
$terms = array ();
$r = q ( " select distinct(term.term)
from term join app on term . oid = app . id
where app_channel = % d
and term . uid = app_channel
and term . otype = % d
order by term . term asc " ,
intval ( local_channel ()),
intval ( TERM_OBJ_APP )
);
if ( $r ) {
foreach ( $r as $rr )
$terms [] = array ( 'name' => $rr [ 'term' ], 'selected' => (( $selected == $rr [ 'term' ]) ? 'selected' : '' ));
return replace_macros ( get_markup_template ( 'categories_widget.tpl' ), array (
'$title' => t ( 'Categories' ),
'$desc' => '' ,
'$sel_all' => (( $selected == '' ) ? 'selected' : '' ),
'$all' => t ( 'Everything' ),
'$terms' => $terms ,
'$base' => $srchurl ,
));
}
}
2016-05-05 01:27:46 +00:00
function widget_appcloud ( $arr ) {
if ( ! local_channel ())
return '' ;
return app_tagblock ( z_root () . '/apps' );
}
2013-12-11 04:36:11 +00:00
function widget_tagcloud_wall ( $arr ) {
2016-04-01 03:15:47 +00:00
2014-12-07 18:27:14 +00:00
2016-03-31 23:06:03 +00:00
if (( ! App :: $profile [ 'profile_uid' ]) || ( ! App :: $profile [ 'channel_hash' ]))
2013-12-11 04:36:11 +00:00
return '' ;
2016-03-31 23:06:03 +00:00
if ( ! perm_is_allowed ( App :: $profile [ 'profile_uid' ], get_observer_hash (), 'view_stream' ))
2014-04-14 23:45:16 +00:00
return '' ;
2014-12-07 18:27:14 +00:00
$limit = (( array_key_exists ( 'limit' , $arr )) ? intval ( $arr [ 'limit' ]) : 50 );
2016-03-31 23:06:03 +00:00
if ( feature_enabled ( App :: $profile [ 'profile_uid' ], 'tagadelic' ))
return wtagblock ( App :: $profile [ 'profile_uid' ], $limit , '' , App :: $profile [ 'channel_hash' ], 'wall' );
2014-12-07 18:27:14 +00:00
2013-12-11 04:36:11 +00:00
return '' ;
2013-12-11 11:01:28 +00:00
}
2014-12-07 18:27:14 +00:00
2014-11-06 09:24:04 +00:00
function widget_catcloud_wall ( $arr ) {
2016-04-01 03:15:47 +00:00
2014-12-07 18:27:14 +00:00
2016-03-31 23:06:03 +00:00
if (( ! App :: $profile [ 'profile_uid' ]) || ( ! App :: $profile [ 'channel_hash' ]))
2014-11-06 09:24:04 +00:00
return '' ;
2016-03-31 23:06:03 +00:00
if ( ! perm_is_allowed ( App :: $profile [ 'profile_uid' ], get_observer_hash (), 'view_stream' ))
2014-11-06 09:24:04 +00:00
return '' ;
$limit = (( array_key_exists ( 'limit' , $arr )) ? intval ( $arr [ 'limit' ]) : 50 );
2014-12-07 18:27:14 +00:00
2016-03-31 23:06:03 +00:00
return catblock ( App :: $profile [ 'profile_uid' ], $limit , '' , App :: $profile [ 'channel_hash' ], 'wall' );
2014-11-06 09:24:04 +00:00
}
2013-12-12 03:43:41 +00:00
function widget_affinity ( $arr ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-12 03:43:41 +00:00
return '' ;
2013-12-12 03:56:57 +00:00
$cmin = (( x ( $_REQUEST , 'cmin' )) ? intval ( $_REQUEST [ 'cmin' ]) : 0 );
$cmax = (( x ( $_REQUEST , 'cmax' )) ? intval ( $_REQUEST [ 'cmax' ]) : 99 );
2015-04-10 02:51:58 +00:00
2015-01-29 04:56:04 +00:00
if ( feature_enabled ( local_channel (), 'affinity' )) {
2015-04-10 02:51:58 +00:00
$labels = array (
t ( 'Me' ),
t ( 'Family' ),
t ( 'Friends' ),
t ( 'Acquaintances' ),
t ( 'All' )
);
call_hooks ( 'affinity_labels' , $labels );
$label_str = '' ;
if ( $labels ) {
foreach ( $labels as $l ) {
if ( $label_str ) {
$label_str .= " , '|' " ;
$label_str .= " , ' " . $l . " ' " ;
}
else
$label_str .= " ' " . $l . " ' " ;
}
}
2013-12-12 03:43:41 +00:00
$tpl = get_markup_template ( 'main_slider.tpl' );
$x = replace_macros ( $tpl , array (
2015-01-05 17:30:12 +00:00
'$val' => $cmin . ',' . $cmax ,
2013-12-12 03:43:41 +00:00
'$refresh' => t ( 'Refresh' ),
2015-04-10 02:51:58 +00:00
'$labels' => $label_str ,
2013-12-12 03:43:41 +00:00
));
$arr = array ( 'html' => $x );
call_hooks ( 'main_slider' , $arr );
2016-10-01 22:41:25 +00:00
return $arr [ 'html' ];
2013-12-12 03:43:41 +00:00
}
2014-12-07 18:27:14 +00:00
2013-12-12 03:43:41 +00:00
return '' ;
2013-12-14 21:26:40 +00:00
}
function widget_settings_menu ( $arr ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-14 21:26:40 +00:00
return ;
2016-04-01 03:15:47 +00:00
2016-03-31 23:06:03 +00:00
$channel = App :: get_channel ();
2013-12-14 21:26:40 +00:00
$abook_self_id = 0 ;
// Retrieve the 'self' address book entry for use in the auto-permissions link
2015-01-29 04:56:04 +00:00
$role = get_pconfig ( local_channel (), 'system' , 'permissions_role' );
2014-10-27 02:32:12 +00:00
2015-06-15 04:08:00 +00:00
$abk = q ( " select abook_id from abook where abook_channel = %d and abook_self = 1 limit 1 " ,
intval ( local_channel ())
2013-12-14 21:26:40 +00:00
);
if ( $abk )
$abook_self_id = $abk [ 0 ][ 'abook_id' ];
2016-03-26 17:43:38 +00:00
$hublocs = q ( " select count(*) as total from hubloc where hubloc_hash = '%s' " ,
dbesc ( $channel [ 'channel_hash' ])
);
$hublocs = (( $hublocs [ 0 ][ 'total' ] > 1 ) ? true : false );
2013-12-14 21:26:40 +00:00
$tabs = array (
array (
'label' => t ( 'Account settings' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/settings/account' ,
2013-12-14 21:26:40 +00:00
'selected' => (( argv ( 1 ) === 'account' ) ? 'active' : '' ),
),
2014-12-07 18:27:14 +00:00
2013-12-14 21:26:40 +00:00
array (
'label' => t ( 'Channel settings' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/settings/channel' ,
2013-12-14 21:26:40 +00:00
'selected' => (( argv ( 1 ) === 'channel' ) ? 'active' : '' ),
),
2014-12-07 18:27:14 +00:00
2016-01-04 09:02:10 +00:00
);
2013-12-14 21:26:40 +00:00
2016-09-20 13:05:20 +00:00
if ( get_account_techlevel () > 0 && get_features ()) {
2016-01-04 09:02:10 +00:00
$tabs [] = array (
'label' => t ( 'Additional features' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/settings/features' ,
2016-01-04 09:02:10 +00:00
'selected' => (( argv ( 1 ) === 'features' ) ? 'active' : '' ),
);
}
2013-12-14 21:26:40 +00:00
2016-01-04 09:02:10 +00:00
$tabs [] = array (
'label' => t ( 'Feature/Addon settings' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/settings/featured' ,
2016-01-04 09:02:10 +00:00
'selected' => (( argv ( 1 ) === 'featured' ) ? 'active' : '' ),
);
2014-12-07 18:27:14 +00:00
2016-01-04 09:02:10 +00:00
$tabs [] = array (
'label' => t ( 'Display settings' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/settings/display' ,
2016-01-04 09:02:10 +00:00
'selected' => (( argv ( 1 ) === 'display' ) ? 'active' : '' ),
);
2013-12-14 21:26:40 +00:00
2016-03-26 17:43:38 +00:00
if ( $hublocs ) {
$tabs [] = array (
'label' => t ( 'Manage locations' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/locs' ,
2016-03-26 17:43:38 +00:00
'selected' => (( argv ( 1 ) === 'locs' ) ? 'active' : '' ),
);
}
2016-09-01 00:49:22 +00:00
$tabs [] = array (
'label' => t ( 'Export channel' ),
'url' => z_root () . '/uexport' ,
'selected' => ''
);
2014-10-27 02:32:12 +00:00
2016-03-26 18:34:38 +00:00
$tabs [] = array (
'label' => t ( 'Connected apps' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/settings/oauth' ,
2016-03-26 18:34:38 +00:00
'selected' => (( argv ( 1 ) === 'oauth' ) ? 'active' : '' ),
);
2016-09-01 00:49:22 +00:00
if ( get_account_techlevel () > 2 ) {
2016-07-15 05:41:53 +00:00
$tabs [] = array (
'label' => t ( 'Guest Access Tokens' ),
'url' => z_root () . '/settings/tokens' ,
'selected' => (( argv ( 1 ) === 'tokens' ) ? 'active' : '' ),
);
}
2014-10-27 02:32:12 +00:00
if ( $role === false || $role === 'custom' ) {
$tabs [] = array (
2014-11-05 01:11:02 +00:00
'label' => t ( 'Connection Default Permissions' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/connedit/' . $abook_self_id ,
2013-12-14 21:26:40 +00:00
'selected' => ''
2014-10-27 02:32:12 +00:00
);
}
2013-12-14 21:26:40 +00:00
2015-01-29 04:56:04 +00:00
if ( feature_enabled ( local_channel (), 'premium_channel' )) {
2013-12-14 21:26:40 +00:00
$tabs [] = array (
'label' => t ( 'Premium Channel Settings' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/connect/' . $channel [ 'channel_address' ],
2013-12-14 21:26:40 +00:00
'selected' => ''
);
}
2015-01-29 04:56:04 +00:00
if ( feature_enabled ( local_channel (), 'channel_sources' )) {
2013-12-14 21:26:40 +00:00
$tabs [] = array (
'label' => t ( 'Channel Sources' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/sources' ,
2013-12-14 21:26:40 +00:00
'selected' => ''
);
}
$tabtpl = get_markup_template ( " generic_links_widget.tpl " );
return replace_macros ( $tabtpl , array (
'$title' => t ( 'Settings' ),
'$class' => 'settings-widget' ,
'$items' => $tabs ,
));
}
function widget_mailmenu ( $arr ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-14 21:26:40 +00:00
return ;
2015-09-24 12:07:44 +00:00
2013-12-14 21:26:40 +00:00
return replace_macros ( get_markup_template ( 'message_side.tpl' ), array (
2015-09-24 12:07:44 +00:00
'$title' => t ( 'Private Mail Menu' ),
'$combined' => array (
'label' => t ( 'Combined View' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/mail/combined' ,
2015-09-24 12:07:44 +00:00
'sel' => ( argv ( 1 ) == 'combined' ),
),
'$inbox' => array (
'label' => t ( 'Inbox' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/mail/inbox' ,
2015-09-24 12:07:44 +00:00
'sel' => ( argv ( 1 ) == 'inbox' ),
),
'$outbox' => array (
'label' => t ( 'Outbox' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/mail/outbox' ,
2015-09-24 12:07:44 +00:00
'sel' => ( argv ( 1 ) == 'outbox' ),
),
2013-12-14 21:26:40 +00:00
'$new' => array (
'label' => t ( 'New Message' ),
2016-03-31 05:13:24 +00:00
'url' => z_root () . '/mail/new' ,
2013-12-14 21:26:40 +00:00
'sel' => ( argv ( 1 ) == 'new' ),
)
));
2013-12-19 10:16:14 +00:00
}
2015-09-24 12:07:44 +00:00
function widget_conversations ( $arr ) {
if ( ! local_channel ())
return ;
if ( argc () > 1 ) {
switch ( argv ( 1 )) {
case 'combined' :
$mailbox = 'combined' ;
$header = t ( 'Conversations' );
break ;
case 'inbox' :
$mailbox = 'inbox' ;
$header = t ( 'Received Messages' );
break ;
case 'outbox' :
$mailbox = 'outbox' ;
$header = t ( 'Sent Messages' );
break ;
default :
$mailbox = 'combined' ;
$header = t ( 'Conversations' );
break ;
}
require_once ( 'include/message.php' );
// private_messages_list() can do other more complicated stuff, for now keep it simple
2016-03-31 23:06:03 +00:00
$r = private_messages_list ( local_channel (), $mailbox , App :: $pager [ 'start' ], App :: $pager [ 'itemspage' ]);
2015-09-24 12:07:44 +00:00
if ( ! $r ) {
info ( t ( 'No messages.' ) . EOL );
return $o ;
}
$messages = array ();
foreach ( $r as $rr ) {
$messages [] = array (
2015-09-28 15:40:38 +00:00
'mailbox' => $mailbox ,
2015-09-24 12:07:44 +00:00
'id' => $rr [ 'id' ],
'from_name' => $rr [ 'from' ][ 'xchan_name' ],
'from_url' => chanlink_hash ( $rr [ 'from_xchan' ]),
'from_photo' => $rr [ 'from' ][ 'xchan_photo_s' ],
'to_name' => $rr [ 'to' ][ 'xchan_name' ],
'to_url' => chanlink_hash ( $rr [ 'to_xchan' ]),
'to_photo' => $rr [ 'to' ][ 'xchan_photo_s' ],
'subject' => (( $rr [ 'seen' ]) ? $rr [ 'title' ] : '<strong>' . $rr [ 'title' ] . '</strong>' ),
'delete' => t ( 'Delete conversation' ),
'body' => $rr [ 'body' ],
2015-11-03 10:19:22 +00:00
'date' => datetime_convert ( 'UTC' , date_default_timezone_get (), $rr [ 'created' ], 'c' ),
2015-09-28 15:40:38 +00:00
'seen' => $rr [ 'seen' ],
'selected' => (( argv ( 2 )) ? ( argv ( 2 ) == $rr [ 'id' ]) : ( $r [ 0 ][ 'id' ] == $rr [ 'id' ]))
2015-09-24 12:07:44 +00:00
);
}
$tpl = get_markup_template ( 'mail_head.tpl' );
$o .= replace_macros ( $tpl , array (
'$header' => $header ,
'$messages' => $messages
));
$o .= alt_pager ( $a , count ( $r ));
}
return $o ;
}
2015-11-27 21:45:28 +00:00
function widget_eventstools ( $arr ) {
if ( ! local_channel ())
return ;
return replace_macros ( get_markup_template ( 'events_tools_side.tpl' ), array (
'$title' => t ( 'Events Tools' ),
'$export' => t ( 'Export Calendar' ),
'$import' => t ( 'Import Calendar' ),
'$submit' => t ( 'Submit' )
));
}
2013-12-19 10:16:14 +00:00
function widget_design_tools ( $arr ) {
// mod menu doesn't load a profile. For any modules which load a profile, check it.
2015-01-29 04:56:04 +00:00
// otherwise local_channel() is sufficient for permissions.
2013-12-19 10:16:14 +00:00
2016-10-01 22:41:25 +00:00
if ( App :: $profile [ 'profile_uid' ])
2016-03-31 23:06:03 +00:00
if (( App :: $profile [ 'profile_uid' ] != local_channel ()) && ( ! App :: $is_sys ))
2014-12-07 18:27:14 +00:00
return '' ;
2016-10-01 22:41:25 +00:00
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2013-12-19 10:16:14 +00:00
return '' ;
return design_tools ();
2013-12-19 10:25:44 +00:00
}
2016-08-18 01:25:50 +00:00
function widget_website_portation_tools ( $arr ) {
2016-07-10 10:58:20 +00:00
// mod menu doesn't load a profile. For any modules which load a profile, check it.
// otherwise local_channel() is sufficient for permissions.
2016-10-01 22:41:25 +00:00
if ( App :: $profile [ 'profile_uid' ])
2016-07-10 10:58:20 +00:00
if (( App :: $profile [ 'profile_uid' ] != local_channel ()) && ( ! App :: $is_sys ))
return '' ;
2016-10-01 22:41:25 +00:00
2016-07-10 10:58:20 +00:00
if ( ! local_channel ())
return '' ;
2016-08-18 01:25:50 +00:00
return website_portation_tools ();
2016-08-17 22:19:36 +00:00
}
2013-12-19 10:25:44 +00:00
function widget_findpeople ( $arr ) {
return findpeople_widget ();
2013-12-20 01:36:31 +00:00
}
function widget_photo_albums ( $arr ) {
2014-12-07 18:27:14 +00:00
2016-03-31 23:06:03 +00:00
if ( ! App :: $profile [ 'profile_uid' ])
2013-12-20 01:36:31 +00:00
return '' ;
2016-03-31 23:06:03 +00:00
$channelx = channelx_by_n ( App :: $profile [ 'profile_uid' ]);
if (( ! $channelx ) || ( ! perm_is_allowed ( App :: $profile [ 'profile_uid' ], get_observer_hash (), 'view_storage' )))
2013-12-20 01:36:31 +00:00
return '' ;
2014-12-04 21:52:22 +00:00
require_once ( 'include/photos.php' );
2016-06-07 23:23:14 +00:00
$sortkey = (( array_key_exists ( 'sortkey' , $arr )) ? $arr [ 'sortkey' ] : 'album' );
2016-10-01 22:41:25 +00:00
$direction = (( array_key_exists ( 'direction' , $arr )) ? $arr [ 'direction' ] : 'asc' );
2013-12-20 01:36:31 +00:00
2016-06-07 23:23:14 +00:00
return photos_album_widget ( $channelx , App :: get_observer (), $sortkey , $direction );
2013-12-20 01:36:31 +00:00
}
function widget_vcard ( $arr ) {
2016-03-31 23:06:03 +00:00
return vcard_from_xchan ( '' , App :: get_observer ());
2013-12-20 01:36:31 +00:00
}
2013-12-20 20:43:04 +00:00
2014-12-07 18:27:14 +00:00
/*
2013-12-20 20:43:04 +00:00
* The following directory widgets are only useful on the directory page
*/
function widget_dirsort ( $arr ) {
return dir_sort_links ();
}
function widget_dirtags ( $arr ) {
2014-12-07 18:27:14 +00:00
return dir_tagblock ( z_root () . '/directory' , null );
2013-12-22 10:04:55 +00:00
}
function widget_menu_preview ( $arr ) {
2016-03-31 23:06:03 +00:00
if ( ! App :: $data [ 'menu_item' ])
2013-12-22 10:04:55 +00:00
return ;
require_once ( 'include/menu.php' );
2014-12-07 18:27:14 +00:00
2016-03-31 23:06:03 +00:00
return menu_render ( App :: $data [ 'menu_item' ]);
2013-12-22 10:04:55 +00:00
}
2014-01-29 09:52:23 +00:00
function widget_chatroom_list ( $arr ) {
2014-12-07 18:27:14 +00:00
2016-04-03 23:41:40 +00:00
2016-05-23 03:54:52 +00:00
$r = Zotlabs\Lib\Chatroom :: roomlist ( App :: $profile [ 'profile_uid' ]);
2016-03-30 12:31:55 +00:00
if ( $r ) {
return replace_macros ( get_markup_template ( 'chatroomlist.tpl' ), array (
2016-04-01 07:46:41 +00:00
'$header' => t ( 'Chatrooms' ),
2016-03-30 12:31:55 +00:00
'$baseurl' => z_root (),
2016-03-31 23:06:03 +00:00
'$nickname' => App :: $profile [ 'channel_address' ],
2016-03-30 12:31:55 +00:00
'$items' => $r ,
2016-03-30 12:44:03 +00:00
'$overview' => t ( 'Overview' )
2016-03-30 12:31:55 +00:00
));
}
2014-01-30 05:29:48 +00:00
}
2016-03-31 11:21:48 +00:00
function widget_chatroom_members () {
$o = replace_macros ( get_markup_template ( 'chatroom_members.tpl' ), array (
2016-03-31 20:42:28 +00:00
'$header' => t ( 'Chat Members' )
2016-03-31 11:21:48 +00:00
));
return $o ;
}
2016-05-21 18:56:42 +00:00
function widget_wiki_list ( $arr ) {
require_once ( " include/wiki.php " );
2016-06-03 02:27:26 +00:00
$channel = null ;
2016-10-01 22:41:25 +00:00
if ( argc () < 2 && local_channel ()) {
2016-06-03 02:27:26 +00:00
// This should not occur because /wiki should redirect to /wiki/channel ...
2016-05-22 01:55:09 +00:00
$channel = \App :: get_channel ();
2016-05-30 00:39:19 +00:00
} else {
2016-06-03 02:27:26 +00:00
$channel = get_channel_by_nick ( argv ( 1 )); // Channel being viewed by observer
2016-05-30 00:39:19 +00:00
}
2016-06-03 02:27:26 +00:00
if ( ! $channel ) {
return '' ;
}
$wikis = wiki_list ( $channel , get_observer_hash ());
2016-05-30 00:39:19 +00:00
if ( $wikis ) {
2016-05-21 18:56:42 +00:00
return replace_macros ( get_markup_template ( 'wikilist.tpl' ), array (
'$header' => t ( 'Wiki List' ),
2016-06-03 02:27:26 +00:00
'$channel' => $channel [ 'channel_address' ],
2016-05-30 00:39:19 +00:00
'$wikis' => $wikis [ 'wikis' ],
2016-06-03 02:27:26 +00:00
// If the observer is the local channel owner, show the wiki controls
'$showControls' => (( local_channel () === intval ( $channel [ 'channel_id' ])) ? true : false )
2016-05-21 18:56:42 +00:00
));
}
2016-06-03 02:27:26 +00:00
return '' ;
2016-05-21 18:56:42 +00:00
}
function widget_wiki_pages ( $arr ) {
require_once ( " include/wiki.php " );
2016-05-28 11:42:18 +00:00
$channelname = (( array_key_exists ( 'channel' , $arr )) ? $arr [ 'channel' ] : '' );
$wikiname = '' ;
if ( array_key_exists ( 'refresh' , $arr )) {
$not_refresh = (( $arr [ 'refresh' ] === true ) ? false : true );
} else {
$not_refresh = true ;
}
2016-05-28 11:17:42 +00:00
$pages = array ();
if ( ! array_key_exists ( 'resource_id' , $arr )) {
$hide = true ;
} else {
$p = wiki_page_list ( $arr [ 'resource_id' ]);
if ( $p [ 'pages' ]) {
$pages = $p [ 'pages' ];
2016-06-04 19:12:04 +00:00
$w = $p [ 'wiki' ];
// Wiki item record is $w['wiki']
$wikiname = $w [ 'urlName' ];
2016-05-28 11:42:18 +00:00
if ( ! $wikiname ) {
$wikiname = '' ;
}
2016-05-28 11:17:42 +00:00
}
2016-05-21 18:56:42 +00:00
}
2016-05-28 11:17:42 +00:00
return replace_macros ( get_markup_template ( 'wiki_page_list.tpl' ), array (
'$hide' => $hide ,
2016-05-28 11:42:18 +00:00
'$not_refresh' => $not_refresh ,
2016-05-28 11:17:42 +00:00
'$header' => t ( 'Wiki Pages' ),
2016-05-28 11:42:18 +00:00
'$channel' => $channelname ,
'$wikiname' => $wikiname ,
2016-05-28 11:17:42 +00:00
'$pages' => $pages
));
2016-05-21 18:56:42 +00:00
}
2016-05-31 00:59:54 +00:00
function widget_wiki_page_history ( $arr ) {
require_once ( " include/wiki.php " );
2016-06-04 19:12:04 +00:00
$pageUrlName = (( array_key_exists ( 'pageUrlName' , $arr )) ? $arr [ 'pageUrlName' ] : '' );
2016-05-31 00:59:54 +00:00
$resource_id = (( array_key_exists ( 'resource_id' , $arr )) ? $arr [ 'resource_id' ] : '' );
2016-06-04 19:12:04 +00:00
$pageHistory = wiki_page_history ( array ( 'resource_id' => $resource_id , 'pageUrlName' => $pageUrlName ));
2016-05-31 00:59:54 +00:00
return replace_macros ( get_markup_template ( 'wiki_page_history.tpl' ), array (
'$pageHistory' => $pageHistory [ 'history' ]
));
}
2014-02-28 01:07:11 +00:00
function widget_bookmarkedchats ( $arr ) {
2016-04-03 23:41:40 +00:00
if ( ! feature_enabled ( App :: $profile [ 'profile_uid' ], 'ajaxchat' ))
return '' ;
2014-02-28 01:07:11 +00:00
$h = get_observer_hash ();
if ( ! $h )
return ;
2015-01-29 01:37:34 +00:00
$r = q ( " select xchat_url, xchat_desc from xchat where xchat_xchan = '%s' order by xchat_desc " ,
2014-12-07 18:27:14 +00:00
dbesc ( $h )
2014-02-28 01:07:11 +00:00
);
2014-11-24 04:29:34 +00:00
if ( $r ) {
for ( $x = 0 ; $x < count ( $r ); $x ++ ) {
$r [ $x ][ 'xchat_url' ] = zid ( $r [ $x ][ 'xchat_url' ]);
}
}
2014-02-28 01:07:11 +00:00
return replace_macros ( get_markup_template ( 'bookmarkedchats.tpl' ), array (
'$header' => t ( 'Bookmarked Chatrooms' ),
'$rooms' => $r
));
}
function widget_suggestedchats ( $arr ) {
2016-04-03 23:41:40 +00:00
if ( ! feature_enabled ( App :: $profile [ 'profile_uid' ], 'ajaxchat' ))
return '' ;
2016-10-01 22:41:25 +00:00
// There are reports that this tool does not ever remove chatrooms on dead sites,
2016-09-05 04:09:00 +00:00
// and also will happily link to private chats which you cannot enter.
2016-10-01 22:41:25 +00:00
// For those reasons, it will be disabled until somebody decides it's worth
2016-09-05 04:09:00 +00:00
// fixing and comes up with a plan for doing so.
return '' ;
2014-02-28 01:07:11 +00:00
// probably should restrict this to your friends, but then the widget will only work
// if you are logged in locally.
$h = get_observer_hash ();
if ( ! $h )
return ;
2015-01-29 01:37:34 +00:00
$r = q ( " select xchat_url, xchat_desc, count(xchat_xchan) as total from xchat group by xchat_url, xchat_desc order by total desc, xchat_desc limit 24 " );
2014-11-24 04:29:34 +00:00
if ( $r ) {
for ( $x = 0 ; $x < count ( $r ); $x ++ ) {
$r [ $x ][ 'xchat_url' ] = zid ( $r [ $x ][ 'xchat_url' ]);
}
}
2014-02-28 01:07:11 +00:00
return replace_macros ( get_markup_template ( 'bookmarkedchats.tpl' ), array (
'$header' => t ( 'Suggested Chatrooms' ),
'$rooms' => $r
));
}
2014-03-04 02:20:52 +00:00
function widget_item ( $arr ) {
2016-01-26 22:14:18 +00:00
$channel_id = 0 ;
if ( array_key_exists ( 'channel_id' , $arr ) && intval ( $arr [ 'channel_id' ]))
$channel_id = intval ( $arr [ 'channel_id' ]);
if ( ! $channel_id )
2016-03-31 23:06:03 +00:00
$channel_id = App :: $profile_uid ;
2016-01-26 22:14:18 +00:00
if ( ! $channel_id )
2014-03-04 02:20:52 +00:00
return '' ;
2016-01-26 22:14:18 +00:00
2016-01-28 23:23:42 +00:00
if (( ! $arr [ 'mid' ]) && ( ! $arr [ 'title' ]))
2016-01-26 22:14:18 +00:00
return '' ;
if ( ! perm_is_allowed ( $channel_id , get_observer_hash (), 'view_pages' ))
2014-03-04 02:20:52 +00:00
return '' ;
require_once ( 'include/security.php' );
2016-01-26 22:14:18 +00:00
$sql_extra = item_permissions_sql ( $channel_id );
2014-03-04 02:20:52 +00:00
2016-01-28 23:23:42 +00:00
if ( $arr [ 'title' ]) {
2016-06-14 02:58:24 +00:00
$r = q ( " select item.* from item left join iconfig on item.id = iconfig.iid
2016-10-01 22:41:25 +00:00
where item . uid = % d and iconfig . cat = 'system' and iconfig . v = '%s'
2016-06-14 02:58:24 +00:00
and iconfig . k = 'WEBPAGE' and item_type = % d $sql_options $revision limit 1 " ,
2016-01-28 23:23:42 +00:00
intval ( $channel_id ),
dbesc ( $arr [ 'title' ]),
intval ( ITEM_TYPE_WEBPAGE )
);
}
else {
$r = q ( " select * from item where mid = '%s' and uid = %d and item_type = " . intval ( ITEM_TYPE_WEBPAGE ) . " $sql_extra limit 1 " ,
dbesc ( $arr [ 'mid' ]),
intval ( $channel_id )
);
}
2014-03-04 02:20:52 +00:00
if ( ! $r )
return '' ;
xchan_query ( $r );
2014-12-07 18:27:14 +00:00
$r = fetch_post_tags ( $r , true );
2014-03-04 02:20:52 +00:00
2014-12-07 18:27:14 +00:00
$o = prepare_page ( $r [ 0 ]);
2014-03-04 02:20:52 +00:00
return $o ;
2014-03-05 12:28:48 +00:00
}
function widget_clock ( $arr ) {
$miltime = 0 ;
if ( isset ( $arr [ 'military' ]) && $arr [ 'military' ])
$miltime = 1 ;
$o = <<< EOT
< div class = " widget " >
< h3 class = " clockface " ></ h3 >
< script >
var timerID = null
var timerRunning = false
function stopclock (){
if ( timerRunning )
clearTimeout ( timerID )
timerRunning = false
}
function startclock (){
stopclock ()
showtime ()
}
function showtime (){
var now = new Date ()
var hours = now . getHours ()
var minutes = now . getMinutes ()
var seconds = now . getSeconds ()
var military = $miltime
var timeValue = " "
if ( military )
timeValue = hours
else
timeValue = (( hours > 12 ) ? hours - 12 : hours )
timeValue += (( minutes < 10 ) ? " :0 " : " : " ) + minutes
// timeValue += ((seconds < 10) ? ":0" : ":") + seconds
if ( ! military )
timeValue += ( hours >= 12 ) ? " P.M. " : " A.M. "
2016-10-01 22:41:25 +00:00
$ ( '.clockface' ) . html ( timeValue )
2014-03-05 12:28:48 +00:00
timerID = setTimeout ( " showtime() " , 1000 )
timerRunning = true
}
$ ( document ) . ready ( function () {
startclock ();
});
</ script >
</ div >
EOT ;
return $o ;
2014-05-14 04:33:39 +00:00
}
/**
2016-10-01 22:41:25 +00:00
* @ brief Widget to display a single photo .
*
* @ param array $arr associative array with
* * \e string \b src URL of photo ; URL must be an http or https URL
* * \e boolean \b zrl use zid in URL
* * \e string \b style CSS string
*
* @ return string with parsed HTML
2014-05-14 04:33:39 +00:00
*/
function widget_photo ( $arr ) {
$style = $zrl = false ;
2014-12-07 18:27:14 +00:00
if ( array_key_exists ( 'src' , $arr ) && isset ( $arr [ 'src' ]))
2014-05-14 04:33:39 +00:00
$url = $arr [ 'src' ];
2016-10-01 22:41:25 +00:00
if ( strpos ( $url , 'http' ) !== 0 )
2014-05-14 04:33:39 +00:00
return '' ;
2014-12-07 18:27:14 +00:00
if ( array_key_exists ( 'style' , $arr ) && isset ( $arr [ 'style' ]))
2014-05-14 04:33:39 +00:00
$style = $arr [ 'style' ];
2014-05-14 07:55:32 +00:00
// ensure they can't sneak in an eval(js) function
2016-10-01 22:41:25 +00:00
if ( strpbrk ( $style , '(\'"<>' ) !== false )
2016-01-16 22:00:22 +00:00
$style = '' ;
2014-05-14 07:55:32 +00:00
2014-12-07 18:27:14 +00:00
if ( array_key_exists ( 'zrl' , $arr ) && isset ( $arr [ 'zrl' ]))
2014-05-14 04:33:39 +00:00
$zrl = (( $arr [ 'zrl' ]) ? true : false );
if ( $zrl )
$url = zid ( $url );
$o = '<div class="widget">' ;
2016-10-01 22:41:25 +00:00
$o .= '<img ' . (( $zrl ) ? ' class="zrl" ' : '' )
. (( $style ) ? ' style="' . $style . '"' : '' )
2014-12-07 18:27:14 +00:00
. ' src="' . $url . '" alt="' . t ( 'photo/image' ) . '">' ;
2014-11-20 23:34:49 +00:00
$o .= '</div>' ;
return $o ;
}
2016-01-15 01:25:27 +00:00
function widget_cover_photo ( $arr ) {
2016-05-22 23:54:30 +00:00
require_once ( 'include/channel.php' );
2016-01-15 01:25:27 +00:00
$o = '' ;
2016-10-01 22:41:25 +00:00
2016-03-31 23:06:03 +00:00
if ( App :: $module == 'channel' && $_REQUEST [ 'mid' ])
2016-03-09 00:46:47 +00:00
return '' ;
2016-03-03 11:07:58 +00:00
2016-01-15 01:25:27 +00:00
$channel_id = 0 ;
if ( array_key_exists ( 'channel_id' , $arr ) && intval ( $arr [ 'channel_id' ]))
$channel_id = intval ( $arr [ 'channel_id' ]);
if ( ! $channel_id )
2016-03-31 23:06:03 +00:00
$channel_id = App :: $profile_uid ;
2016-01-15 01:25:27 +00:00
if ( ! $channel_id )
return '' ;
2016-03-03 11:07:58 +00:00
$channel = channelx_by_n ( $channel_id );
2016-01-15 01:25:27 +00:00
if ( array_key_exists ( 'style' , $arr ) && isset ( $arr [ 'style' ]))
$style = $arr [ 'style' ];
2016-10-01 22:41:25 +00:00
else
2016-03-02 11:31:25 +00:00
$style = 'width:100%; height: auto;' ;
2016-01-15 01:25:27 +00:00
// ensure they can't sneak in an eval(js) function
2016-01-16 22:00:22 +00:00
if ( strpbrk ( $style , '(\'"<>' ) !== false )
$style = '' ;
2016-01-15 01:25:27 +00:00
2016-03-03 11:07:58 +00:00
if ( array_key_exists ( 'title' , $arr ) && isset ( $arr [ 'title' ]))
$title = $arr [ 'title' ];
else
$title = $channel [ 'channel_name' ];
if ( array_key_exists ( 'subtitle' , $arr ) && isset ( $arr [ 'subtitle' ]))
$subtitle = $arr [ 'subtitle' ];
else
2016-06-23 01:00:18 +00:00
$subtitle = str_replace ( '@' , '@' , $channel [ 'xchan_addr' ]);
2016-03-03 11:07:58 +00:00
2016-01-15 01:25:27 +00:00
$c = get_cover_photo ( $channel_id , 'html' );
if ( $c ) {
2016-03-03 11:07:58 +00:00
$photo_html = (( $style ) ? str_replace ( 'alt=' , ' style="' . $style . '" alt=' , $c ) : $c );
$o = replace_macros ( get_markup_template ( 'cover_photo_widget.tpl' ), array (
'$photo_html' => $photo_html ,
'$title' => $title ,
'$subtitle' => $subtitle ,
2016-03-06 16:02:58 +00:00
'$hovertitle' => t ( 'Click to show more' ),
2016-03-03 11:07:58 +00:00
));
2016-01-15 01:25:27 +00:00
}
return $o ;
}
2014-11-20 23:34:49 +00:00
function widget_photo_rand ( $arr ) {
require_once ( 'include/photos.php' );
2014-12-07 18:27:14 +00:00
$style = false ;
if ( array_key_exists ( 'album' , $arr ) && isset ( $arr [ 'album' ]))
2014-11-20 23:34:49 +00:00
$album = $arr [ 'album' ];
else
$album = '' ;
2014-11-21 03:33:08 +00:00
$channel_id = 0 ;
2014-12-07 18:27:14 +00:00
if ( array_key_exists ( 'channel_id' , $arr ) && intval ( $arr [ 'channel_id' ]))
2014-11-21 03:33:08 +00:00
$channel_id = intval ( $arr [ 'channel_id' ]);
if ( ! $channel_id )
2016-03-31 23:06:03 +00:00
$channel_id = App :: $profile_uid ;
2014-11-20 23:34:49 +00:00
if ( ! $channel_id )
return '' ;
$scale = (( array_key_exists ( 'scale' , $arr )) ? intval ( $arr [ 'scale' ]) : 0 );
2016-03-31 23:06:03 +00:00
$ret = photos_list_photos ( array ( 'channel_id' => $channel_id ), App :: get_observer (), $album );
2014-12-07 18:27:14 +00:00
2014-11-20 23:34:49 +00:00
$filtered = array ();
if ( $ret [ 'success' ] && $ret [ 'photos' ])
foreach ( $ret [ 'photos' ] as $p )
2016-06-02 04:48:54 +00:00
if ( $p [ 'imgscale' ] == $scale )
2014-11-20 23:34:49 +00:00
$filtered [] = $p [ 'src' ];
if ( $filtered ) {
2014-12-07 18:27:14 +00:00
$e = mt_rand ( 0 , count ( $filtered ) - 1 );
2014-11-20 23:34:49 +00:00
$url = $filtered [ $e ];
}
2014-12-07 18:27:14 +00:00
if ( strpos ( $url , 'http' ) !== 0 )
2014-11-20 23:34:49 +00:00
return '' ;
2014-12-07 18:27:14 +00:00
if ( array_key_exists ( 'style' , $arr ) && isset ( $arr [ 'style' ]))
2014-11-20 23:34:49 +00:00
$style = $arr [ 'style' ];
// ensure they can't sneak in an eval(js) function
if ( strpos ( $style , '(' ) !== false )
return '' ;
$url = zid ( $url );
$o = '<div class="widget">' ;
2016-10-01 22:41:25 +00:00
$o .= '<img class="zrl" '
. (( $style ) ? ' style="' . $style . '"' : '' )
2014-12-07 18:27:14 +00:00
. ' src="' . $url . '" alt="' . t ( 'photo/image' ) . '">' ;
2014-05-14 04:33:39 +00:00
$o .= '</div>' ;
return $o ;
}
2014-11-22 20:26:04 +00:00
function widget_random_block ( $arr ) {
$channel_id = 0 ;
if ( array_key_exists ( 'channel_id' , $arr ) && intval ( $arr [ 'channel_id' ]))
$channel_id = intval ( $arr [ 'channel_id' ]);
if ( ! $channel_id )
2016-03-31 23:06:03 +00:00
$channel_id = App :: $profile_uid ;
2014-11-22 20:26:04 +00:00
if ( ! $channel_id )
return '' ;
if ( array_key_exists ( 'contains' , $arr ))
$contains = $arr [ 'contains' ];
$o = '' ;
require_once ( 'include/security.php' );
$sql_options = item_permissions_sql ( $channel_id );
$randfunc = db_getfunc ( 'RAND' );
2016-06-14 02:58:24 +00:00
$r = q ( " select item.* from item left join iconfig on item.id = iconfig.iid
2016-10-01 22:41:25 +00:00
where item . uid = % d and iconfig . cat = 'system' and iconfig . v like '%s' and iconfig . k = 'BUILDBLOCK' and
2015-05-22 05:17:17 +00:00
item_type = % d $sql_options order by $randfunc limit 1 " ,
2014-11-22 20:26:04 +00:00
intval ( $channel_id ),
dbesc ( '%' . $contains . '%' ),
2015-07-09 01:05:38 +00:00
intval ( ITEM_TYPE_BLOCK )
2014-11-22 20:26:04 +00:00
);
if ( $r ) {
$o = '<div class="widget bblock">' ;
if ( $r [ 0 ][ 'title' ])
$o .= '<h3>' . $r [ 0 ][ 'title' ] . '</h3>' ;
2014-12-07 18:27:14 +00:00
2014-11-22 20:26:04 +00:00
$o .= prepare_text ( $r [ 0 ][ 'body' ], $r [ 0 ][ 'mimetype' ]);
$o .= '</div>' ;
}
2014-12-07 18:27:14 +00:00
return $o ;
2014-12-04 21:52:22 +00:00
}
2015-02-04 23:48:39 +00:00
function widget_rating ( $arr ) {
2016-04-01 03:15:47 +00:00
2015-02-04 23:48:39 +00:00
2016-08-26 00:43:07 +00:00
$rating_enabled = get_config ( 'system' , 'rating_enabled' );
if ( ! $rating_enabled ) {
2015-02-05 01:34:53 +00:00
return ;
}
2015-02-04 23:48:39 +00:00
if ( $arr [ 'target' ])
$hash = $arr [ 'target' ];
else
2016-03-31 23:06:03 +00:00
$hash = App :: $poi [ 'xchan_hash' ];
2015-02-04 23:48:39 +00:00
if ( ! $hash )
return ;
2015-02-05 01:32:29 +00:00
$url = '' ;
$remote = false ;
if ( remote_channel () && ! local_channel ()) {
2016-03-31 23:06:03 +00:00
$ob = App :: get_observer ();
2015-02-05 01:32:29 +00:00
if ( $ob && $ob [ 'xchan_url' ]) {
$p = parse_url ( $ob [ 'xchan_url' ]);
if ( $p ) {
$url = $p [ 'scheme' ] . '://' . $p [ 'host' ] . (( $p [ 'port' ]) ? ':' . $p [ 'port' ] : '' );
$url .= '/rate?f=&target=' . urlencode ( $hash );
}
$remote = true ;
}
}
2015-02-04 23:48:39 +00:00
2015-02-05 02:31:12 +00:00
$self = false ;
2015-02-05 01:32:29 +00:00
if ( local_channel ()) {
2016-03-31 23:06:03 +00:00
$channel = App :: get_channel ();
2015-02-05 01:32:29 +00:00
if ( $hash == $channel [ 'channel_hash' ])
2015-02-05 02:31:12 +00:00
$self = true ;
2015-02-05 01:32:29 +00:00
head_add_js ( 'ratings.js' );
}
2016-01-21 09:42:20 +00:00
$o = '<div class="widget">' ;
$o .= '<h3>' . t ( 'Rating Tools' ) . '</h3>' ;
2015-02-05 02:31:12 +00:00
if ((( $remote ) || ( local_channel ())) && ( ! $self )) {
2015-02-05 02:26:59 +00:00
if ( $remote )
2016-04-30 18:39:57 +00:00
$o .= '<a class="btn btn-block btn-primary btn-sm" href="' . $url . '"><i class="fa fa-pencil"></i> ' . t ( 'Rate Me' ) . '</a>' ;
2015-02-05 02:26:59 +00:00
else
2016-04-30 18:39:57 +00:00
$o .= '<div class="btn btn-block btn-primary btn-sm" onclick="doRatings(\'' . $hash . '\'); return false;"><i class="fa fa-pencil"></i> ' . t ( 'Rate Me' ) . '</div>' ;
2015-02-05 02:26:59 +00:00
}
2015-02-05 02:18:04 +00:00
2016-04-30 18:39:57 +00:00
$o .= '<a class="btn btn-block btn-default btn-sm" href="ratings/' . $hash . '"><i class="fa fa-eye"></i> ' . t ( 'View Ratings' ) . '</a>' ;
2015-02-05 02:18:04 +00:00
$o .= '</div>' ;
2015-02-04 23:48:39 +00:00
return $o ;
2015-02-06 03:38:43 +00:00
}
2015-02-16 19:09:12 +00:00
// used by site ratings pages to provide a return link
2015-08-12 00:39:29 +00:00
function widget_pubsites ( $arr ) {
2016-03-31 23:06:03 +00:00
if ( App :: $poi )
2015-02-16 19:09:12 +00:00
return ;
return '<div class="widget"><ul class="nav nav-pills"><li><a href="pubsites">' . t ( 'Public Hubs' ) . '</a></li></ul></div>' ;
2015-04-09 08:53:37 +00:00
}
2015-04-24 02:49:41 +00:00
2015-08-12 00:39:29 +00:00
function widget_forums ( $arr ) {
if ( ! local_channel ())
return '' ;
$o = '' ;
if ( is_array ( $arr ) && array_key_exists ( 'limit' , $arr ))
$limit = " limit " . intval ( $limit ) . " " ;
else
2015-08-12 03:58:03 +00:00
$limit = '' ;
2015-08-12 00:39:29 +00:00
2015-08-12 05:23:20 +00:00
$unseen = 0 ;
if ( is_array ( $arr ) && array_key_exists ( 'unseen' , $arr ) && intval ( $arr [ 'unseen' ]))
$unseen = 1 ;
2015-08-12 00:39:29 +00:00
$perms_sql = item_permissions_sql ( local_channel ()) . item_normal ();
2015-08-12 05:23:20 +00:00
2016-07-13 04:47:24 +00:00
/**
* We used to try and find public forums with custom permissions by checking to see if
2016-10-01 22:41:25 +00:00
* send_stream was false and tag_deliver was true . However with the newer extensible
2016-07-13 04:47:24 +00:00
* permissions infrastructure this makes for a very complicated query . Now we ' re only
* checking channels that report themselves specifically as pubforums
*/
$r1 = q ( " select abook_id, xchan_hash, xchan_name, xchan_url, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_pubforum = 1 and xchan_deleted = 0 and abook_channel = %d order by xchan_name $limit " ,
2015-08-12 03:25:02 +00:00
intval ( local_channel ())
2015-08-12 00:39:29 +00:00
);
2015-08-12 05:23:20 +00:00
if ( ! $r1 )
return $o ;
$str = '' ;
// Trying to cram all this into a single query with joins and the proper group by's is tough.
// There also should be a way to update this via ajax.
for ( $x = 0 ; $x < count ( $r1 ); $x ++ ) {
2016-07-09 23:07:53 +00:00
$r = q ( " select sum(item_unseen) as unseen from item where owner_xchan = '%s' and uid = %d and item_unseen = 1 $perms_sql " ,
2015-08-12 05:23:20 +00:00
dbesc ( $r1 [ $x ][ 'xchan_hash' ]),
intval ( local_channel ())
);
if ( $r )
$r1 [ $x ][ 'unseen' ] = $r [ 0 ][ 'unseen' ];
2016-07-09 23:07:53 +00:00
/**
* @ FIXME
* This SQL makes the counts correct when you get forum posts arriving from different routes / sources
2016-10-01 22:41:25 +00:00
* ( like personal channels ) . However the network query for these posts doesn ' t yet include this
* correction and it makes the SQL for that query pretty hairy so this is left as a future exercise .
2016-07-09 23:07:53 +00:00
* It may make more sense in that query to look for the mention in the body rather than another join ,
* but that makes it very inefficient .
2016-10-01 22:41:25 +00:00
*
2016-07-09 23:07:53 +00:00
$r = q ( " select sum(item_unseen) as unseen from item left join term on oid = id where otype = %d and owner_xchan != '%s' and item.uid = %d and url = '%s' and ttype = %d $perms_sql " ,
intval ( TERM_OBJ_POST ),
dbesc ( $r1 [ $x ][ 'xchan_hash' ]),
intval ( local_channel ()),
dbesc ( $r1 [ $x ][ 'xchan_url' ]),
intval ( TERM_MENTION )
);
if ( $r )
$r1 [ $x ][ 'unseen' ] = (( array_key_exists ( 'unseen' , $r1 [ $x ])) ? $r1 [ $x ][ 'unseen' ] + $r [ 0 ][ 'unseen' ] : $r [ 0 ][ 'unseen' ]);
*
* end @ FIXME
*/
2016-10-01 22:41:25 +00:00
2015-08-12 05:23:20 +00:00
}
if ( $r1 ) {
2015-08-12 00:39:29 +00:00
$o .= '<div class="widget">' ;
2015-08-12 02:22:14 +00:00
$o .= '<h3>' . t ( 'Forums' ) . '</h3><ul class="nav nav-pills nav-stacked">' ;
2015-08-12 00:39:29 +00:00
2015-08-12 05:23:20 +00:00
foreach ( $r1 as $rr ) {
if ( $unseen && ( ! intval ( $rr [ 'unseen' ])))
continue ;
2015-12-04 09:17:13 +00:00
$o .= '<li><a href="network?f=&pf=1&cid=' . $rr [ 'abook_id' ] . '" ><span class="badge pull-right">' . (( intval ( $rr [ 'unseen' ])) ? intval ( $rr [ 'unseen' ]) : '' ) . '</span><img src="' . $rr [ 'xchan_photo_s' ] . '" style="width: 16px; height: 16px;" /> ' . $rr [ 'xchan_name' ] . '</a></li>' ;
2015-08-12 00:39:29 +00:00
}
2015-08-12 02:22:14 +00:00
$o .= '</ul></div>' ;
2015-08-12 00:39:29 +00:00
}
2016-10-01 22:41:25 +00:00
return $o ;
2015-08-12 00:39:29 +00:00
}
2015-08-21 01:43:01 +00:00
function widget_tasklist ( $arr ) {
2015-11-27 21:45:28 +00:00
if ( ! local_channel ())
return ;
2015-08-21 01:43:01 +00:00
require_once ( 'include/event.php' );
2015-08-21 03:40:42 +00:00
$o .= '<script>var tasksShowAll = 0; $(document).ready(function() { tasksFetch(); $("#tasklist-new-form").submit(function(event) { event.preventDefault(); $.post( "tasks/new", $("#tasklist-new-form").serialize(), function(data) { tasksFetch(); $("#tasklist-new-summary").val(""); } ); return false; } )});</script>' ;
$o .= ' < script > function taskComplete ( id ) { $ . post ( " tasks/complete/ " + id , function ( data ) { tasksFetch ();}); }
function tasksFetch () {
$ . get ( " tasks/fetch " + (( tasksShowAll ) ? " /all " : " " ), function ( data ) {
$ ( " .tasklist-tasks " ) . html ( data . html );
});
2015-08-21 01:43:01 +00:00
}
2016-10-01 22:41:25 +00:00
</ script > ' ;
2015-08-21 03:40:42 +00:00
$o .= '<div class="widget">' . '<h3>' . t ( 'Tasks' ) . '</h3><div class="tasklist-tasks">' ;
$o .= '</div><form id="tasklist-new-form" action="" ><input id="tasklist-new-summary" type="text" name="summary" value="" /></form>' ;
2015-08-21 01:43:01 +00:00
$o .= '</div>' ;
return $o ;
}
2015-08-31 05:39:33 +00:00
function widget_helpindex ( $arr ) {
2016-09-04 07:50:35 +00:00
2016-09-05 01:35:06 +00:00
$o .= '<div class="widget">' ;
$o .= '<h3>' . t ( 'Documentation' ) . '</h3>' ;
2016-09-04 07:50:35 +00:00
2016-09-26 23:34:53 +00:00
$level_0 = get_help_content ( 'sitetoc' );
if ( ! $level_0 )
$level_0 = get_help_content ( 'toc' );
2016-09-05 01:35:06 +00:00
$level_0 = preg_replace ( '/\<ul(.*?)\>/' , '<ul class="nav nav-pills nav-stacked">' , $level_0 );
$levels = array ();
if ( argc () > 2 ) {
$path = '' ;
for ( $x = 1 ; $x < argc (); $x ++ ) {
2016-10-01 22:41:25 +00:00
$path .= argv ( $x ) . '/' ;
2016-09-26 23:34:53 +00:00
$y = get_help_content ( $path . 'sitetoc' );
if ( ! $y )
$y = get_help_content ( $path . 'toc' );
2016-09-05 01:35:06 +00:00
if ( $y )
$levels [] = preg_replace ( '/\<ul(.*?)\>/' , '<ul class="nav nav-pills nav-stacked">' , $y );
}
}
if ( $level_0 )
$o .= $level_0 ;
if ( $levels ) {
foreach ( $levels as $l ) {
$o .= '<br /><br />' ;
$o .= $l ;
}
}
$o .= '</div>' ;
2016-09-04 07:50:35 +00:00
2015-08-31 05:39:33 +00:00
return $o ;
2015-09-09 03:48:35 +00:00
}
function widget_admin ( $arr ) {
/*
* Side bar links
*/
if ( ! is_site_admin ()) {
return login ( false );
}
$o = '' ;
// array( url, name, extra css classes )
$aside = array (
'site' => array ( z_root () . '/admin/site/' , t ( 'Site' ), 'site' ),
2016-06-07 02:44:22 +00:00
'accounts' => array ( z_root () . '/admin/accounts/' , t ( 'Accounts' ), 'accounts' , 'pending-update' , t ( 'Member registrations waiting for confirmation' )),
2015-09-09 03:48:35 +00:00
'channels' => array ( z_root () . '/admin/channels/' , t ( 'Channels' ), 'channels' ),
2016-02-04 04:24:46 +00:00
'security' => array ( z_root () . '/admin/security/' , t ( 'Security' ), 'security' ),
2016-01-06 21:01:28 +00:00
'features' => array ( z_root () . '/admin/features/' , t ( 'Features' ), 'features' ),
2015-09-09 03:48:35 +00:00
'plugins' => array ( z_root () . '/admin/plugins/' , t ( 'Plugins' ), 'plugins' ),
'themes' => array ( z_root () . '/admin/themes/' , t ( 'Themes' ), 'themes' ),
'queue' => array ( z_root () . '/admin/queue' , t ( 'Inspect queue' ), 'queue' ),
2016-03-03 00:39:34 +00:00
'profs' => array ( z_root () . '/admin/profs' , t ( 'Profile Fields' ), 'profs' ),
2015-09-09 03:48:35 +00:00
'dbsync' => array ( z_root () . '/admin/dbsync/' , t ( 'DB updates' ), 'dbsync' )
);
/* get plugins admin page */
$r = q ( " SELECT * FROM addon WHERE plugin_admin = 1 " );
2016-03-19 23:17:19 +00:00
$plugins = array ();
2015-09-09 03:48:35 +00:00
if ( $r ) {
foreach ( $r as $h ){
2016-05-31 02:44:30 +00:00
$plugin = $h [ 'aname' ];
2016-03-19 23:17:19 +00:00
$plugins [] = array ( z_root () . '/admin/plugins/' . $plugin , $plugin , 'plugin' );
2015-09-09 03:48:35 +00:00
// temp plugins with admin
2016-03-31 23:06:03 +00:00
App :: $plugins_admin [] = $plugin ;
2015-09-09 03:48:35 +00:00
}
}
2016-03-19 23:17:19 +00:00
$logs = array ( z_root () . '/admin/logs/' , t ( 'Logs' ), 'logs' );
$arr = array ( 'links' => $aside , 'plugins' => $plugins , 'logs' => $logs );
call_hooks ( 'admin_aside' , $arr );
2015-09-09 03:48:35 +00:00
$o .= replace_macros ( get_markup_template ( 'admin_aside.tpl' ), array (
2016-10-01 22:41:25 +00:00
'$admin' => $aside ,
2015-09-09 03:48:35 +00:00
'$admtxt' => t ( 'Admin' ),
'$plugadmtxt' => t ( 'Plugin Features' ),
2016-03-19 23:17:19 +00:00
'$plugins' => $plugins ,
2015-09-09 03:48:35 +00:00
'$logtxt' => t ( 'Logs' ),
2016-03-19 23:17:19 +00:00
'$logs' => $logs ,
'$h_pending' => t ( 'Member registrations waiting for confirmation' ),
2015-09-09 03:48:35 +00:00
'$admurl' => z_root () . '/admin/'
));
return $o ;
2015-09-24 12:07:44 +00:00
}
2015-11-13 04:22:36 +00:00
function widget_album ( $args ) {
2016-03-31 23:06:03 +00:00
$owner_uid = App :: $profile_uid ;
2015-11-13 04:22:36 +00:00
$sql_extra = permissions_sql ( $owner_uid );
2015-11-17 23:03:27 +00:00
if ( ! perm_is_allowed ( $owner_uid , get_observer_hash (), 'view_storage' ))
return '' ;
2015-11-13 04:22:36 +00:00
if ( $args [ 'album' ])
$album = $args [ 'album' ];
if ( $args [ 'title' ])
$title = $args [ 'title' ];
2016-10-01 22:41:25 +00:00
/**
2015-11-18 04:44:57 +00:00
* This may return incorrect permissions if you have multiple directories of the same name .
* It is a limitation of the photo table using a name for a photo album instead of a folder hash
*/
if ( $album ) {
$x = q ( " select hash from attach where filename = '%s' and uid = %d limit 1 " ,
dbesc ( $album ),
intval ( $owner_uid )
);
if ( $x ) {
$y = attach_can_view_folder ( $owner_uid , get_observer_hash (), $x [ 0 ][ 'hash' ]);
if ( ! $y )
return '' ;
}
}
2015-11-13 04:22:36 +00:00
$order = 'DESC' ;
2016-06-02 04:48:54 +00:00
$r = q ( " SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN
2016-10-01 22:41:25 +00:00
( SELECT resource_id , max ( imgscale ) imgscale FROM photo WHERE uid = % d AND album = '%s' AND imgscale <= 4 AND photo_usage IN ( % d , % d ) $sql_extra GROUP BY resource_id ) ph
2016-06-02 04:48:54 +00:00
ON ( p . resource_id = ph . resource_id AND p . imgscale = ph . imgscale )
2015-11-13 04:22:36 +00:00
ORDER BY created $order " ,
intval ( $owner_uid ),
dbesc ( $album ),
intval ( PHOTO_NORMAL ),
intval ( PHOTO_PROFILE )
);
2016-10-01 22:41:25 +00:00
2015-11-13 04:22:36 +00:00
//edit album name
$album_edit = null ;
$photos = array ();
if ( $r ) {
$twist = 'rotright' ;
foreach ( $r as $rr ) {
if ( $twist == 'rotright' )
$twist = 'rotleft' ;
else
$twist = 'rotright' ;
2016-10-01 22:41:25 +00:00
2016-06-02 04:48:54 +00:00
$ext = $phototypes [ $rr [ 'mimetype' ]];
2015-11-13 04:22:36 +00:00
$imgalt_e = $rr [ 'filename' ];
$desc_e = $rr [ 'description' ];
2016-03-31 23:06:03 +00:00
$imagelink = ( z_root () . '/photos/' . App :: $profile [ 'channel_address' ] . '/image/' . $rr [ 'resource_id' ]);
2015-11-13 04:22:36 +00:00
$photos [] = array (
'id' => $rr [ 'id' ],
'twist' => ' ' . $twist . rand ( 2 , 4 ),
'link' => $imagelink ,
'title' => t ( 'View Photo' ),
2016-06-02 04:48:54 +00:00
'src' => z_root () . '/photo/' . $rr [ 'resource_id' ] . '-' . $rr [ 'imgscale' ] . '.' . $ext ,
2015-11-13 04:22:36 +00:00
'alt' => $imgalt_e ,
'desc' => $desc_e ,
'ext' => $ext ,
'hash' => $rr [ 'resource_id' ],
'unknown' => t ( 'Unknown' )
);
}
}
$tpl = get_markup_template ( 'photo_album.tpl' );
$o .= replace_macros ( $tpl , array (
'$photos' => $photos ,
'$album' => (( $title ) ? $title : $album ),
2015-12-07 11:13:51 +00:00
'$album_id' => rand (),
2015-11-13 04:22:36 +00:00
'$album_edit' => array ( t ( 'Edit Album' ), $album_edit ),
'$can_post' => false ,
2016-03-31 23:06:03 +00:00
'$upload' => array ( t ( 'Upload' ), z_root () . '/photos/' . App :: $profile [ 'channel_address' ] . '/upload/' . bin2hex ( $album )),
2015-11-13 04:22:36 +00:00
'$order' => false ,
'$upload_form' => $upload_form ,
'$usage' => $usage_message
));
return $o ;
}