2014-12-07 18:27:14 +00:00
< ? php
/**
* @ file include / widgets . php
*
2017-03-16 01:48:27 +00:00
* @ brief This file contains some widgets .
2014-12-07 18:27:14 +00:00
*/
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
2013-12-10 08:05:31 +00:00
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
}
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
}
2014-12-07 18:27:14 +00:00
2014-01-29 09:52:23 +00:00
2014-12-07 18:27:14 +00:00
2016-04-03 23:41:40 +00:00
2016-05-31 00:59:54 +00:00
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-12-02 20:15:18 +00:00
$xf = false ;
2016-12-15 04:51:10 +00:00
$x1 = q ( " select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'send_stream' and v = '0' " ,
2016-12-02 20:15:18 +00:00
intval ( local_channel ())
);
if ( $x1 ) {
$xc = ids_to_querystr ( $x1 , 'xchan' , true );
2016-12-15 04:51:10 +00:00
$x2 = q ( " select xchan from abconfig where chan = %d and cat = 'their_perms' and k = 'tag_deliver' and v = '1' and xchan in ( " . $xc . " ) " ,
2016-12-02 20:15:18 +00:00
intval ( local_channel ())
);
if ( $x2 )
$xf = ids_to_querystr ( $x2 , 'xchan' , true );
}
$sql_extra = (( $xf ) ? " and ( xchan_hash in ( " . $xf . " ) or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 " );
$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_deleted = 0 and abook_channel = %d $sql_extra 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
2017-03-03 01:32:43 +00:00
function widget_activity ( $arr ) {
if ( ! local_channel ())
return '' ;
$o = '' ;
if ( is_array ( $arr ) && array_key_exists ( 'limit' , $arr ))
$limit = " limit " . intval ( $limit ) . " " ;
else
$limit = '' ;
$perms_sql = item_permissions_sql ( local_channel ()) . item_normal ();
2017-03-03 02:10:23 +00:00
$r = q ( " select author_xchan from item where item_unseen = 1 and uid = %d $perms_sql " ,
2017-03-03 01:32:43 +00:00
intval ( local_channel ())
);
$contributors = [];
$arr = [];
if ( $r ) {
foreach ( $r as $rv ) {
2017-03-03 02:10:23 +00:00
if ( array_key_exists ( $rv [ 'author_xchan' ], $contributors )) {
2017-03-03 01:32:43 +00:00
$contributors [ $rv [ 'author_xchan' ]] ++ ;
2017-03-03 02:10:23 +00:00
}
else {
2017-03-03 01:32:43 +00:00
$contributors [ $rv [ 'author_xchan' ]] = 1 ;
2017-03-03 02:10:23 +00:00
}
2017-03-03 01:32:43 +00:00
}
foreach ( $contributors as $k => $v ) {
$arr [] = [ 'author_xchan' => $k , 'total' => $v ];
}
usort ( $arr , 'total_sort' );
xchan_query ( $arr );
}
$x = [ 'entries' => $arr ];
call_hooks ( 'activity_widget' , $x );
$arr = $x [ 'entries' ];
if ( $arr ) {
$o .= '<div class="widget">' ;
$o .= '<h3>' . t ( 'Activity' , 'widget' ) . '</h3><ul class="nav nav-pills nav-stacked">' ;
foreach ( $arr as $rv ) {
$o .= '<li><a href="network?f=&xchan=' . urlencode ( $rv [ 'author_xchan' ]) . '" ><span class="badge pull-right">' . (( intval ( $rv [ 'total' ])) ? intval ( $rv [ 'total' ]) : '' ) . '</span><img src="' . $rv [ 'author' ][ 'xchan_photo_s' ] . '" style="width: 16px; height: 16px;" /> ' . $rv [ 'author' ][ 'xchan_name' ] . '</a></li>' ;
}
$o .= '</ul></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">' ;
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
}
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 ;
}