2012-06-15 00:46:58 +00:00
< ? php
2012-07-23 12:15:06 +00:00
require_once ( 'include/items.php' );
2013-12-06 04:34:39 +00:00
require_once ( 'include/group.php' );
require_once ( 'include/contact_widgets.php' );
require_once ( 'include/conversation.php' );
require_once ( 'include/acl_selectors.php' );
2012-06-15 00:46:58 +00:00
function network_init ( & $a ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ()) {
2012-06-15 00:46:58 +00:00
notice ( t ( 'Permission denied.' ) . EOL );
return ;
}
2013-07-08 00:22:40 +00:00
2015-03-12 23:20:29 +00:00
if (( count ( $_GET ) < 2 ) || ( count ( $_GET ) < 3 && $_GET [ 'JS' ])) {
2015-03-09 23:25:55 +00:00
$network_options = get_pconfig ( local_channel (), 'system' , 'network_page_default' );
if ( $network_options )
goaway ( 'network' . '?f=&' . $network_options );
}
2016-03-31 23:06:03 +00:00
$channel = App :: get_channel ();
App :: $profile_uid = local_channel ();
2013-07-08 00:22:40 +00:00
head_set_icon ( $channel [ 'xchan_photo_s' ]);
2013-10-02 02:54:22 +00:00
2013-12-10 08:05:31 +00:00
}
function network_content ( & $a , $update = 0 , $load = false ) {
2015-01-29 04:56:04 +00:00
if ( ! local_channel ()) {
2016-03-31 23:06:03 +00:00
$_SESSION [ 'return_url' ] = App :: $query_string ;
2014-11-17 03:08:10 +00:00
return login ( false );
2013-12-10 08:05:31 +00:00
}
2015-03-21 23:46:28 +00:00
if ( $load )
$_SESSION [ 'loadtime' ] = datetime_convert ();
2013-12-10 08:05:31 +00:00
2016-03-31 23:06:03 +00:00
$arr = array ( 'query' => App :: $query_string );
2013-12-10 08:05:31 +00:00
call_hooks ( 'network_content_init' , $arr );
2016-03-31 23:06:03 +00:00
$channel = App :: get_channel ();
2015-06-10 23:59:04 +00:00
$item_normal = item_normal ();
2014-12-15 22:37:31 +00:00
$datequery = $datequery2 = '' ;
$group = 0 ;
$nouveau = false ;
$datequery = (( x ( $_GET , 'dend' ) && is_a_date_arg ( $_GET [ 'dend' ])) ? notags ( $_GET [ 'dend' ]) : '' );
$datequery2 = (( x ( $_GET , 'dbegin' ) && is_a_date_arg ( $_GET [ 'dbegin' ])) ? notags ( $_GET [ 'dbegin' ]) : '' );
$nouveau = (( x ( $_GET , 'new' )) ? intval ( $_GET [ 'new' ]) : 0 );
$gid = (( x ( $_GET , 'gid' )) ? intval ( $_GET [ 'gid' ]) : 0 );
$category = (( x ( $_REQUEST , 'cat' )) ? $_REQUEST [ 'cat' ] : '' );
$hashtags = (( x ( $_REQUEST , 'tag' )) ? $_REQUEST [ 'tag' ] : '' );
2015-01-14 02:41:11 +00:00
$verb = (( x ( $_REQUEST , 'verb' )) ? $_REQUEST [ 'verb' ] : '' );
2014-12-15 22:37:31 +00:00
2013-12-10 08:05:31 +00:00
$search = (( $_GET [ 'search' ]) ? $_GET [ 'search' ] : '' );
2013-10-02 02:54:22 +00:00
if ( $search ) {
if ( strpos ( $search , '@' ) === 0 ) {
$r = q ( " select abook_id from abook left join xchan on abook_xchan = xchan_hash where xchan_name = '%s' and abook_channel = %d limit 1 " ,
dbesc ( substr ( $search , 1 )),
2015-01-29 04:56:04 +00:00
intval ( local_channel ())
2013-10-02 02:54:22 +00:00
);
if ( $r ) {
$_GET [ 'cid' ] = $r [ 0 ][ 'abook_id' ];
$search = $_GET [ 'search' ] = '' ;
}
}
elseif ( strpos ( $search , '#' ) === 0 ) {
2014-12-15 22:37:31 +00:00
$hashtags = substr ( $search , 1 );
$search = $_GET [ 'search' ] = '' ;
2013-10-02 02:54:22 +00:00
}
}
2012-07-24 00:35:58 +00:00
if ( $datequery )
$_GET [ 'order' ] = 'post' ;
2014-11-17 03:08:10 +00:00
// filter by collection (e.g. group)
2012-07-24 00:35:58 +00:00
if ( $gid ) {
2014-11-17 03:08:10 +00:00
$r = q ( " SELECT * FROM groups WHERE id = %d AND uid = %d LIMIT 1 " ,
intval ( $gid ),
2015-01-29 04:56:04 +00:00
intval ( local_channel ())
2014-11-17 03:08:10 +00:00
);
if ( ! $r ) {
2013-11-29 22:08:37 +00:00
if ( $update )
killme ();
notice ( t ( 'No such group' ) . EOL );
2016-03-31 05:13:24 +00:00
goaway ( z_root () . '/network' );
2013-11-29 22:08:37 +00:00
// NOTREACHED
}
2014-11-17 03:08:10 +00:00
$group = $gid ;
2013-11-29 22:08:37 +00:00
$group_hash = $r [ 0 ][ 'hash' ];
2014-11-17 03:08:10 +00:00
$def_acl = array ( 'allow_gid' => '<' . $r [ 0 ][ 'hash' ] . '>' );
2012-07-24 00:35:58 +00:00
}
2012-06-15 00:46:58 +00:00
$o = '' ;
2012-11-09 07:04:34 +00:00
2013-12-06 05:00:14 +00:00
// if no tabs are selected, defaults to comments
2012-06-15 00:46:58 +00:00
2014-11-17 03:08:10 +00:00
$cid = (( x ( $_GET , 'cid' )) ? intval ( $_GET [ 'cid' ]) : 0 );
$star = (( x ( $_GET , 'star' )) ? intval ( $_GET [ 'star' ]) : 0 );
$order = (( x ( $_GET , 'order' )) ? notags ( $_GET [ 'order' ]) : 'comment' );
$liked = (( x ( $_GET , 'liked' )) ? intval ( $_GET [ 'liked' ]) : 0 );
$conv = (( x ( $_GET , 'conv' )) ? intval ( $_GET [ 'conv' ]) : 0 );
$spam = (( x ( $_GET , 'spam' )) ? intval ( $_GET [ 'spam' ]) : 0 );
$cmin = (( x ( $_GET , 'cmin' )) ? intval ( $_GET [ 'cmin' ]) : 0 );
$cmax = (( x ( $_GET , 'cmax' )) ? intval ( $_GET [ 'cmax' ]) : 99 );
$firehose = (( x ( $_GET , 'fh' )) ? intval ( $_GET [ 'fh' ]) : 0 );
$file = (( x ( $_GET , 'file' )) ? $_GET [ 'file' ] : '' );
2012-06-15 00:46:58 +00:00
2015-09-10 01:50:15 +00:00
$deftag = '' ;
2012-06-15 00:46:58 +00:00
if ( x ( $_GET , 'search' ) || x ( $_GET , 'file' ))
$nouveau = true ;
2015-03-21 12:37:55 +00:00
if ( $cid ) {
$r = q ( " SELECT abook_xchan FROM abook WHERE abook_id = %d AND abook_channel = %d LIMIT 1 " ,
intval ( $cid ),
intval ( local_channel ())
);
if ( ! $r ) {
if ( $update ) {
killme ();
}
notice ( t ( 'No such channel' ) . EOL );
2016-03-31 05:13:24 +00:00
goaway ( z_root () . '/network' );
2015-03-21 12:37:55 +00:00
// NOTREACHED
}
2015-09-10 01:50:15 +00:00
if ( $_GET [ 'pf' ] === '1' )
$deftag = '@' . t ( 'forum' ) . '+' . intval ( $cid ) . '+' ;
else
$def_acl = array ( 'allow_cid' => '<' . $r [ 0 ][ 'abook_xchan' ] . '>' );
2015-03-21 12:37:55 +00:00
}
2012-06-15 00:46:58 +00:00
if ( ! $update ) {
2015-03-20 23:06:18 +00:00
$tabs = network_tabs ();
$o .= $tabs ;
2012-07-19 10:59:32 +00:00
2012-07-19 08:43:23 +00:00
// search terms header
2015-03-20 23:06:18 +00:00
if ( $search ) {
$o .= replace_macros ( get_markup_template ( " section_title.tpl " ), array (
'$title' => t ( 'Search Results For:' ) . ' ' . htmlspecialchars ( $search , ENT_COMPAT , 'UTF-8' )
));
}
2012-07-19 08:43:23 +00:00
2012-06-15 00:46:58 +00:00
nav_set_selected ( 'network' );
2013-11-29 22:08:37 +00:00
$channel_acl = array (
'allow_cid' => $channel [ 'channel_allow_cid' ],
'allow_gid' => $channel [ 'channel_allow_gid' ],
2014-11-17 03:08:10 +00:00
'deny_cid' => $channel [ 'channel_deny_cid' ],
'deny_gid' => $channel [ 'channel_deny_gid' ]
2013-11-29 22:08:37 +00:00
);
2015-09-10 01:57:06 +00:00
$private_editing = ((( $group || $cid ) && ( ! intval ( $_GET [ 'pf' ]))) ? true : false );
2012-06-15 00:46:58 +00:00
$x = array (
2014-11-17 03:08:10 +00:00
'is_owner' => true ,
'allow_location' => (( intval ( get_pconfig ( $channel [ 'channel_id' ], 'system' , 'use_browser_location' ))) ? '1' : '' ),
2013-02-01 07:56:46 +00:00
'default_location' => $channel [ 'channel_location' ],
2014-11-17 03:08:10 +00:00
'nickname' => $channel [ 'channel_address' ],
2015-09-10 01:57:06 +00:00
'lockstate' => (( $private_editing || $channel [ 'channel_allow_cid' ] || $channel [ 'channel_allow_gid' ] || $channel [ 'channel_deny_cid' ] || $channel [ 'channel_deny_gid' ]) ? 'lock' : 'unlock' ),
2015-12-31 23:10:36 +00:00
'acl' => populate_acl ((( $private_editing ) ? $def_acl : $channel_acl ), true , (( $channel [ 'channel_r_stream' ] & PERMS_PUBLIC ) ? t ( 'Public' ) : '' )),
2015-09-10 01:57:06 +00:00
'bang' => (( $private_editing ) ? '!' : '' ),
2014-11-17 03:08:10 +00:00
'visitor' => true ,
2015-01-29 04:56:04 +00:00
'profile_uid' => local_channel ()
2012-06-15 00:46:58 +00:00
);
2015-09-10 01:50:15 +00:00
if ( $deftag )
2015-09-10 02:54:16 +00:00
$x [ 'pretext' ] = $deftag ;
2012-06-15 00:46:58 +00:00
2016-03-09 08:46:17 +00:00
2015-03-20 23:06:18 +00:00
$status_editor = status_editor ( $a , $x );
$o .= $status_editor ;
2016-03-09 08:46:17 +00:00
2012-06-15 00:46:58 +00:00
}
// We don't have to deal with ACL's on this page. You're looking at everything
// that belongs to you, hence you can see all of it. We will filter by group if
2014-11-17 03:08:10 +00:00
// desired.
2012-06-15 00:46:58 +00:00
2014-11-17 03:08:10 +00:00
$sql_options = (( $star )
2015-01-23 01:41:16 +00:00
? " and item_starred = 1 "
2012-10-29 09:41:25 +00:00
: '' );
2012-06-15 00:46:58 +00:00
2012-07-21 10:48:59 +00:00
$sql_nets = '' ;
2012-10-29 09:41:25 +00:00
2015-01-23 01:41:16 +00:00
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE item_thread_top = 1 $sql_options ) " ;
2012-06-15 00:46:58 +00:00
if ( $group ) {
2013-09-18 11:06:44 +00:00
$contact_str = '' ;
2014-11-17 03:08:10 +00:00
$contacts = group_get_members ( $group );
if ( $contacts ) {
2013-09-18 11:06:44 +00:00
foreach ( $contacts as $c ) {
if ( $contact_str )
$contact_str .= ',' ;
2014-11-17 03:08:10 +00:00
$contact_str .= " ' " . $c [ 'xchan' ] . " ' " ;
2013-09-18 11:06:44 +00:00
}
2014-11-17 03:08:10 +00:00
}
else {
$contact_str = ' 0 ' ;
2016-01-27 07:44:15 +00:00
info ( t ( 'Privacy group is empty' ));
2014-11-17 03:08:10 +00:00
}
2013-05-23 05:48:48 +00:00
2015-06-10 23:59:04 +00:00
$sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like ' " . protect_sprintf ( '%<' . dbesc ( $group_hash ) . '>%' ) . " ' ) and id = parent $item_normal ) " ;
2013-05-23 05:48:48 +00:00
2015-01-29 04:56:04 +00:00
$x = group_rec_byhash ( local_channel (), $group_hash );
2013-12-06 03:07:59 +00:00
2015-03-20 23:06:18 +00:00
if ( $x ) {
$title = replace_macros ( get_markup_template ( " section_title.tpl " ), array (
2016-01-27 07:44:15 +00:00
'$title' => t ( 'Privacy group: ' ) . $x [ 'name' ]
2015-03-20 23:06:18 +00:00
));
}
2013-12-06 03:07:59 +00:00
2015-03-20 23:06:18 +00:00
$o = $tabs ;
$o .= $title ;
$o .= $status_editor ;
2013-12-06 03:07:59 +00:00
2014-11-17 03:08:10 +00:00
}
2012-06-15 00:46:58 +00:00
elseif ( $cid ) {
2015-06-15 04:08:00 +00:00
$r = q ( " SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and abook_blocked = 0 limit 1 " ,
2013-05-23 05:48:48 +00:00
intval ( $cid ),
2015-01-29 04:56:04 +00:00
intval ( local_channel ())
2014-11-17 03:08:10 +00:00
);
if ( $r ) {
2015-06-10 23:59:04 +00:00
$sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval ( local_channel ()) . " AND ( author_xchan = ' " . dbesc ( $r [ 0 ][ 'abook_xchan' ]) . " ' or owner_xchan = ' " . dbesc ( $r [ 0 ][ 'abook_xchan' ]) . " ' ) $item_normal ) " ;
2015-03-20 23:06:18 +00:00
$title = replace_macros ( get_markup_template ( " section_title.tpl " ), array (
2015-09-11 02:35:26 +00:00
'$title' => '<a href="' . zid ( $r [ 0 ][ 'xchan_url' ]) . '" ><img src="' . zid ( $r [ 0 ][ 'xchan_photo_s' ]) . '" alt="' . urlencode ( $r [ 0 ][ 'xchan_name' ]) . '" /></a> <a href="' . zid ( $r [ 0 ][ 'xchan_url' ]) . '" >' . $r [ 0 ][ 'xchan_name' ] . '</a>'
2015-03-20 23:06:18 +00:00
));
$o = $tabs ;
$o .= $title ;
$o .= $status_editor ;
2014-11-17 03:08:10 +00:00
}
else {
2013-09-29 09:47:36 +00:00
notice ( t ( 'Invalid connection.' ) . EOL );
2016-03-31 05:13:24 +00:00
goaway ( z_root () . '/network' );
2014-11-17 03:08:10 +00:00
}
2012-06-15 00:46:58 +00:00
}
2014-12-15 22:37:31 +00:00
if ( x ( $category )) {
$sql_extra .= protect_sprintf ( term_query ( 'item' , $category , TERM_CATEGORY ));
}
if ( x ( $hashtags )) {
2015-11-20 08:15:48 +00:00
$sql_extra .= protect_sprintf ( term_query ( 'item' , $hashtags , TERM_HASHTAG , TERM_COMMUNITYTAG ));
2014-12-15 22:37:31 +00:00
}
2012-06-15 00:46:58 +00:00
if ( ! $update ) {
// The special div is needed for liveUpdate to kick in for this page.
2014-11-17 03:08:10 +00:00
// We only launch liveUpdate if you aren't filtering in some incompatible
2012-06-15 00:46:58 +00:00
// way and also you aren't writing a comment (discovered in javascript).
2014-06-18 04:51:20 +00:00
if ( $gid || $cid || $cmin || ( $cmax != 99 ) || $star || $liked || $conv || $spam || $nouveau || $list )
2014-11-17 03:08:10 +00:00
$firehose = 0 ;
2013-11-18 03:22:24 +00:00
2015-01-29 04:56:04 +00:00
$maxheight = get_pconfig ( local_channel (), 'system' , 'network_divmore_height' );
2014-11-18 07:48:03 +00:00
if ( ! $maxheight )
$maxheight = 400 ;
2014-06-18 04:51:20 +00:00
$o .= '<div id="live-network"></div>' . " \r \n " ;
2015-01-29 04:56:04 +00:00
$o .= " <script> var profile_uid = " . local_channel ()
2016-03-31 23:06:03 +00:00
. " ; var profile_page = " . App :: $pager [ 'page' ]
2014-11-18 07:48:03 +00:00
. " ; divmore_height = " . intval ( $maxheight ) . " ; </script> \r \n " ;
2012-07-17 09:11:20 +00:00
2016-03-31 23:06:03 +00:00
App :: $page [ 'htmlhead' ] .= replace_macros ( get_markup_template ( " build_query.tpl " ), array (
2012-12-13 12:06:56 +00:00
'$baseurl' => z_root (),
2014-11-17 03:08:10 +00:00
'$pgtype' => 'network' ,
2015-01-29 04:56:04 +00:00
'$uid' => (( local_channel ()) ? local_channel () : '0' ),
2014-11-17 03:08:10 +00:00
'$gid' => (( $gid ) ? $gid : '0' ),
'$cid' => (( $cid ) ? $cid : '0' ),
'$cmin' => (( $cmin ) ? $cmin : '0' ),
'$cmax' => (( $cmax ) ? $cmax : '0' ),
'$star' => (( $star ) ? $star : '0' ),
'$liked' => (( $liked ) ? $liked : '0' ),
'$conv' => (( $conv ) ? $conv : '0' ),
'$spam' => (( $spam ) ? $spam : '0' ),
'$fh' => (( $firehose ) ? $firehose : '0' ),
2012-12-13 12:06:56 +00:00
'$nouveau' => (( $nouveau ) ? $nouveau : '0' ),
2014-11-17 03:08:10 +00:00
'$wall' => '0' ,
'$list' => (( x ( $_REQUEST , 'list' )) ? intval ( $_REQUEST [ 'list' ]) : 0 ),
2016-03-31 23:06:03 +00:00
'$page' => (( App :: $pager [ 'page' ] != 1 ) ? App :: $pager [ 'page' ] : 1 ),
2014-11-17 03:08:10 +00:00
'$search' => (( $search ) ? $search : '' ),
'$order' => $order ,
'$file' => $file ,
2014-12-15 22:37:31 +00:00
'$cats' => $category ,
'$tags' => $hashtags ,
2014-11-17 03:08:10 +00:00
'$dend' => $datequery ,
'$mid' => '' ,
2015-01-14 02:41:11 +00:00
'$verb' => $verb ,
2014-11-17 03:08:10 +00:00
'$dbegin' => $datequery2
2012-12-13 12:06:56 +00:00
));
2012-06-15 00:46:58 +00:00
}
$sql_extra3 = '' ;
if ( $datequery ) {
$sql_extra3 .= protect_sprintf ( sprintf ( " AND item.created <= '%s' " , dbesc ( datetime_convert ( date_default_timezone_get (), '' , $datequery ))));
}
if ( $datequery2 ) {
$sql_extra3 .= protect_sprintf ( sprintf ( " AND item.created >= '%s' " , dbesc ( datetime_convert ( date_default_timezone_get (), '' , $datequery2 ))));
}
2014-11-17 03:08:10 +00:00
$sql_extra2 = (( $nouveau ) ? '' : " AND item.parent = item.id " );
2012-06-15 00:46:58 +00:00
$sql_extra3 = (( $nouveau ) ? '' : $sql_extra3 );
if ( x ( $_GET , 'search' )) {
$search = escape_tags ( $_GET [ 'search' ]);
2014-11-17 03:08:10 +00:00
if ( strpos ( $search , '#' ) === 0 ) {
2015-11-20 08:15:48 +00:00
$sql_extra .= term_query ( 'item' , substr ( $search , 1 ), TERM_HASHTAG , TERM_COMMUNITYTAG );
2014-11-17 03:08:10 +00:00
}
else {
$sql_extra .= sprintf ( " AND item.body like '%s' " ,
2012-07-17 04:07:59 +00:00
dbesc ( protect_sprintf ( '%' . $search . '%' ))
2012-06-15 00:46:58 +00:00
);
2014-11-17 03:08:10 +00:00
}
2012-06-15 00:46:58 +00:00
}
2012-07-17 04:07:59 +00:00
2015-01-14 02:41:11 +00:00
if ( $verb ) {
$sql_extra .= sprintf ( " AND item.verb like '%s' " ,
dbesc ( protect_sprintf ( '%' . $verb . '%' ))
);
}
2012-06-15 00:46:58 +00:00
if ( strlen ( $file )) {
2012-07-17 04:07:59 +00:00
$sql_extra .= term_query ( 'item' , $file , TERM_FILE );
2012-06-15 00:46:58 +00:00
}
if ( $conv ) {
2015-01-23 01:41:16 +00:00
$sql_extra .= sprintf ( " AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or item_mentionsme = 1 )) " ,
dbesc ( protect_sprintf ( $channel [ 'channel_hash' ]))
2012-07-17 04:07:59 +00:00
);
2012-06-15 00:46:58 +00:00
}
2012-07-25 05:06:21 +00:00
if ( $update && ! $load ) {
2012-06-15 00:46:58 +00:00
// only setup pagination on initial page view
$pager_sql = '' ;
}
else {
2015-01-29 04:56:04 +00:00
$itemspage = get_pconfig ( local_channel (), 'system' , 'itemspage' );
2016-03-31 23:06:03 +00:00
App :: set_pager_itemspage ((( intval ( $itemspage )) ? $itemspage : 20 ));
$pager_sql = sprintf ( " LIMIT %d OFFSET %d " , intval ( App :: $pager [ 'itemspage' ]), intval ( App :: $pager [ 'start' ]));
2012-06-15 00:46:58 +00:00
}
2012-07-19 08:43:23 +00:00
if (( $cmin != 0 ) || ( $cmax != 99 )) {
2012-10-30 03:47:56 +00:00
// Not everybody who shows up in the network stream will be in your address book.
// By default those that aren't are assumed to have closeness = 99; but this isn't
2014-11-17 03:08:10 +00:00
// recorded anywhere. So if cmax is 99, we'll open the search up to anybody in
2012-10-30 03:47:56 +00:00
// the stream with a NULL address book entry.
2012-10-29 09:41:25 +00:00
2012-10-30 03:47:56 +00:00
$sql_nets .= " AND " ;
2012-10-29 09:41:25 +00:00
if ( $cmax == 99 )
2012-10-30 03:47:56 +00:00
$sql_nets .= " ( " ;
$sql_nets .= " ( abook.abook_closeness >= " . intval ( $cmin ) . " " ;
$sql_nets .= " AND abook.abook_closeness <= " . intval ( $cmax ) . " ) " ;
if ( $cmax == 99 )
$sql_nets .= " OR abook.abook_closeness IS NULL ) " ;
2012-10-29 09:41:25 +00:00
2012-07-19 08:43:23 +00:00
}
2015-03-13 22:39:19 +00:00
$abook_uids = " and abook.abook_channel = " . local_channel () . " " ;
2014-03-30 22:01:31 +00:00
if ( $firehose && ( ! get_config ( 'system' , 'disable_discover_tab' ))) {
2014-03-27 05:05:19 +00:00
require_once ( 'include/identity.php' );
$sys = get_sys_channel ();
2014-03-27 22:35:29 +00:00
$uids = " and item.uid = " . intval ( $sys [ 'channel_id' ]) . " " ;
2016-03-31 23:06:03 +00:00
App :: $data [ 'firehose' ] = intval ( $sys [ 'channel_id' ]);
2014-03-27 05:05:19 +00:00
}
else {
2015-01-29 04:56:04 +00:00
$uids = " and item.uid = " . local_channel () . " " ;
2014-03-27 05:05:19 +00:00
}
2015-01-29 04:56:04 +00:00
if ( get_pconfig ( local_channel (), 'system' , 'network_list_mode' ))
2014-11-17 23:18:06 +00:00
$page_mode = 'list' ;
else
$page_mode = 'client' ;
2015-02-13 02:49:42 +00:00
$simple_update = (( $update ) ? " and item_unseen = 1 " : '' );
2014-07-22 04:15:03 +00:00
// This fixes a very subtle bug so I'd better explain it. You wake up in the morning or return after a day
2014-11-17 03:08:10 +00:00
// or three and look at your matrix page - after opening up your browser. The first page loads just as it
// should. All of a sudden a few seconds later, page 2 will get inserted at the beginning of the page
2014-07-22 04:15:03 +00:00
// (before the page 1 content). The update code is actually doing just what it's supposed
// to, it's fetching posts that have the ITEM_UNSEEN bit set. But the reason that page 2 content is being
2014-11-17 03:08:10 +00:00
// returned in an UPDATE is because you hadn't gotten that far yet - you're still on page 1 and everything
2014-07-22 04:15:03 +00:00
// that we loaded for page 1 is now marked as seen. But the stuff on page 2 hasn't been. So... it's being
2014-11-17 03:08:10 +00:00
// treated as "new fresh" content because it is unseen. We need to distinguish it somehow from content
2014-07-22 04:15:03 +00:00
// which "arrived as you were reading page 1". We're going to do this
// by storing in your session the current UTC time whenever you LOAD a network page, and only UPDATE items
// which are both ITEM_UNSEEN and have "changed" since that time. Cross fingers...
2014-11-17 03:08:10 +00:00
if ( $update && $_SESSION [ 'loadtime' ])
2015-03-22 22:00:41 +00:00
$simple_update = " AND (( item_unseen = 1 AND item.changed > ' " . datetime_convert ( 'UTC' , 'UTC' , $_SESSION [ 'loadtime' ]) . " ' ) OR item.changed > ' " . datetime_convert ( 'UTC' , 'UTC' , $_SESSION [ 'loadtime' ]) . " ' ) " ;
2012-07-25 05:06:21 +00:00
if ( $load )
$simple_update = '' ;
2012-06-15 00:46:58 +00:00
2012-07-25 05:06:21 +00:00
if ( $nouveau && $load ) {
2012-06-15 00:46:58 +00:00
// "New Item View" - show all items unthreaded in reverse created date order
2012-10-09 01:40:30 +00:00
2014-11-17 03:08:10 +00:00
$items = q ( " SELECT item.*, item.id AS item_id, received FROM item
2015-03-17 22:45:08 +00:00
left join abook on ( item . owner_xchan = abook . abook_xchan $abook_uids )
2015-06-10 23:59:04 +00:00
WHERE true $uids $item_normal
2015-06-15 04:08:00 +00:00
and ( abook . abook_blocked = 0 or abook . abook_flags is null )
2012-06-15 00:46:58 +00:00
$simple_update
2014-03-27 22:35:29 +00:00
$sql_extra $sql_nets
2015-06-15 04:08:00 +00:00
ORDER BY item . received DESC $pager_sql "
2012-06-15 00:46:58 +00:00
);
2012-10-09 01:40:30 +00:00
2012-07-17 12:30:32 +00:00
require_once ( 'include/items.php' );
2012-10-09 01:40:30 +00:00
xchan_query ( $items );
2013-02-11 08:20:14 +00:00
$items = fetch_post_tags ( $items , true );
2012-06-15 00:46:58 +00:00
}
2013-01-05 03:24:17 +00:00
elseif ( $update ) {
2012-07-26 05:55:43 +00:00
2012-06-15 00:46:58 +00:00
// Normal conversation view
if ( $order === 'post' )
2014-11-17 03:08:10 +00:00
$ordering = " created " ;
2012-06-15 00:46:58 +00:00
else
2014-11-17 03:08:10 +00:00
$ordering = " commented " ;
2012-06-15 00:46:58 +00:00
2013-01-05 03:24:17 +00:00
if ( $load ) {
2012-10-30 03:47:56 +00:00
2013-01-05 03:24:17 +00:00
// Fetch a page full of parent items for this page
2013-01-26 00:18:35 +00:00
2014-11-17 03:08:10 +00:00
$r = q ( " SELECT distinct item.id AS item_id, $ordering FROM item
2015-03-17 22:45:08 +00:00
left join abook on ( item . owner_xchan = abook . abook_xchan $abook_uids )
2015-06-10 23:59:04 +00:00
WHERE true $uids $item_normal
2013-01-05 03:24:17 +00:00
AND item . parent = item . id
2015-06-15 04:08:00 +00:00
and ( abook . abook_blocked = 0 or abook . abook_flags is null )
2014-03-27 22:35:29 +00:00
$sql_extra3 $sql_extra $sql_nets
2015-06-15 04:08:00 +00:00
ORDER BY $ordering DESC $pager_sql "
2012-06-15 00:46:58 +00:00
);
2013-01-26 00:18:35 +00:00
2012-10-09 01:40:30 +00:00
}
2012-06-15 00:46:58 +00:00
else {
2015-03-22 22:00:41 +00:00
// this is an update
$r = q ( " SELECT item.parent AS item_id FROM item
left join abook on ( item . owner_xchan = abook . abook_xchan $abook_uids )
2015-06-10 23:59:04 +00:00
WHERE true $uids $item_normal $simple_update
2015-06-15 04:08:00 +00:00
and ( abook . abook_blocked = 0 or abook . abook_flags is null )
$sql_extra3 $sql_extra $sql_nets "
2015-03-22 22:00:41 +00:00
);
$_SESSION [ 'loadtime' ] = datetime_convert ();
2012-06-15 00:46:58 +00:00
}
2013-01-05 03:26:53 +00:00
2012-06-15 00:46:58 +00:00
// Then fetch all the children of the parents that are on this page
2013-08-29 04:56:01 +00:00
$parents_str = '' ;
$update_unseen = '' ;
2012-06-15 00:46:58 +00:00
2013-01-05 03:24:17 +00:00
if ( $r ) {
2012-08-30 06:03:03 +00:00
$parents_str = ids_to_querystr ( $r , 'item_id' );
2012-06-15 00:46:58 +00:00
2014-11-17 03:08:10 +00:00
$items = q ( " SELECT item.*, item.id AS item_id FROM item
2015-06-10 23:59:04 +00:00
WHERE true $uids $item_normal
2014-11-17 03:08:10 +00:00
AND item . parent IN ( % s )
2014-03-27 22:35:29 +00:00
$sql_extra " ,
2012-06-15 00:46:58 +00:00
dbesc ( $parents_str )
);
2015-01-29 04:56:04 +00:00
xchan_query ( $items , true ,(( $firehose ) ? local_channel () : 0 ));
2013-02-11 08:20:14 +00:00
$items = fetch_post_tags ( $items , true );
2014-09-23 05:03:19 +00:00
$items = conv_sort ( $items , $ordering );
2014-11-17 03:08:10 +00:00
}
2013-01-05 03:24:17 +00:00
else {
2012-06-15 00:46:58 +00:00
$items = array ();
}
2013-02-04 04:39:43 +00:00
2014-11-17 23:18:06 +00:00
if ( $page_mode === 'list' ) {
/**
* in " list mode " , only mark the parent item and any like activities as " seen " .
* We won ' t distinguish between comment likes and post likes . The important thing
* is that the number of unseen comments will be accurate . The SQL to separate the
* comment likes could also get somewhat hairy .
*/
2013-02-04 04:39:43 +00:00
2014-11-17 23:18:06 +00:00
if ( $parents_str ) {
$update_unseen = " AND ( id IN ( " . dbesc ( $parents_str ) . " ) " ;
$update_unseen .= " OR ( parent IN ( " . dbesc ( $parents_str ) . " ) AND verb in ( ' " . dbesc ( ACTIVITY_LIKE ) . " ',' " . dbesc ( ACTIVITY_DISLIKE ) . " ' ))) " ;
}
}
else {
if ( $parents_str ) {
$update_unseen = " AND parent IN ( " . dbesc ( $parents_str ) . " ) " ;
}
}
2012-06-15 00:46:58 +00:00
}
2014-03-27 22:35:29 +00:00
if (( $update_unseen ) && ( ! $firehose ))
2015-01-23 01:41:16 +00:00
$r = q ( " UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d $update_unseen " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ())
2012-06-15 00:46:58 +00:00
);
$mode = (( $nouveau ) ? 'network-new' : 'network' );
2014-11-17 00:19:24 +00:00
$o .= conversation ( $a , $items , $mode , $update , $page_mode );
2012-06-15 00:46:58 +00:00
2014-11-17 03:08:10 +00:00
if (( $items ) && ( ! $update ))
$o .= alt_pager ( $a , count ( $items ));
2012-06-15 00:46:58 +00:00
return $o ;
}