2019-10-27 14:08:14 +00:00
< ? php
2020-02-09 14:45:36 +00:00
/**
* @ copyright Copyright ( C ) 2020 , Friendica
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
2019-10-27 14:08:14 +00:00
namespace Friendica\Module\Profile ;
use Friendica\Content\Nav ;
use Friendica\Content\Pager ;
use Friendica\Content\Widget ;
use Friendica\Core\ACL ;
use Friendica\Core\Session ;
use Friendica\Database\DBA ;
use Friendica\DI ;
use Friendica\Model\Item ;
2020-05-03 15:13:40 +00:00
use Friendica\Model\Post\Category ;
2019-10-27 14:08:14 +00:00
use Friendica\Model\Profile as ProfileModel ;
use Friendica\Model\User ;
2020-01-26 14:49:11 +00:00
use Friendica\Module\BaseProfile ;
2019-10-27 14:08:14 +00:00
use Friendica\Module\Security\Login ;
2020-07-08 13:49:39 +00:00
use Friendica\Network\HTTPException ;
2019-10-27 14:08:14 +00:00
use Friendica\Util\DateTimeFormat ;
use Friendica\Util\Security ;
use Friendica\Util\Strings ;
use Friendica\Util\XML ;
2020-01-26 14:49:11 +00:00
class Status extends BaseProfile
2019-10-27 14:08:14 +00:00
{
public static function content ( array $parameters = [])
{
$args = DI :: args ();
$a = DI :: app ();
ProfileModel :: load ( $a , $parameters [ 'nickname' ]);
2020-07-08 13:49:39 +00:00
if ( empty ( $a -> profile )) {
throw new HTTPException\NotFoundException ( DI :: l10n () -> t ( 'User not found.' ));
}
2020-02-16 15:39:44 +00:00
if ( ! $a -> profile [ 'net-publish' ]) {
2019-10-27 14:08:14 +00:00
DI :: page ()[ 'htmlhead' ] .= '<meta content="noindex, noarchive" name="robots" />' . " \n " ;
}
2020-04-25 07:29:02 +00:00
DI :: page ()[ 'htmlhead' ] .= '<link rel="alternate" type="application/atom+xml" href="' . DI :: baseUrl () . '/dfrn_poll/' . $parameters [ 'nickname' ] . '" title="DFRN: ' . DI :: l10n () -> t ( '%s\'s timeline' , $a -> profile [ 'name' ]) . '"/>' . " \n " ;
DI :: page ()[ 'htmlhead' ] .= '<link rel="alternate" type="application/atom+xml" href="' . DI :: baseUrl () . '/feed/' . $parameters [ 'nickname' ] . '/" title="' . DI :: l10n () -> t ( '%s\'s posts' , $a -> profile [ 'name' ]) . '"/>' . " \n " ;
DI :: page ()[ 'htmlhead' ] .= '<link rel="alternate" type="application/atom+xml" href="' . DI :: baseUrl () . '/feed/' . $parameters [ 'nickname' ] . '/comments" title="' . DI :: l10n () -> t ( '%s\'s comments' , $a -> profile [ 'name' ]) . '"/>' . " \n " ;
DI :: page ()[ 'htmlhead' ] .= '<link rel="alternate" type="application/atom+xml" href="' . DI :: baseUrl () . '/feed/' . $parameters [ 'nickname' ] . '/activity" title="' . DI :: l10n () -> t ( '%s\'s timeline' , $a -> profile [ 'name' ]) . '"/>' . " \n " ;
2019-10-27 14:08:14 +00:00
$category = $datequery = $datequery2 = '' ;
$dtFormat = DI :: dtFormat ();
2020-01-25 21:23:09 +00:00
if ( $args -> getArgc () > 3 ) {
for ( $x = 3 ; $x < $args -> getArgc (); $x ++ ) {
2020-02-01 13:06:35 +00:00
if ( $dtFormat -> isYearMonthDay ( $args -> get ( $x ))) {
2019-10-27 14:08:14 +00:00
if ( $datequery ) {
$datequery2 = Strings :: escapeHtml ( $args -> get ( $x ));
} else {
$datequery = Strings :: escapeHtml ( $args -> get ( $x ));
}
} else {
$category = $args -> get ( $x );
}
}
}
if ( empty ( $category )) {
$category = $_GET [ 'category' ] ? ? '' ;
}
$hashtags = $_GET [ 'tag' ] ? ? '' ;
2019-11-03 01:19:42 +00:00
if ( DI :: config () -> get ( 'system' , 'block_public' ) && ! local_user () && ! Session :: getRemoteContactID ( $a -> profile [ 'uid' ])) {
2019-10-27 14:08:14 +00:00
return Login :: form ();
}
$o = '' ;
2019-11-03 01:19:42 +00:00
if ( $a -> profile [ 'uid' ] == local_user ()) {
2019-10-27 14:08:14 +00:00
Nav :: setSelected ( 'home' );
}
2019-11-03 01:19:42 +00:00
$remote_contact = Session :: getRemoteContactID ( $a -> profile [ 'uid' ]);
$is_owner = local_user () == $a -> profile [ 'uid' ];
$last_updated_key = " profile: " . $a -> profile [ 'uid' ] . " : " . local_user () . " : " . $remote_contact ;
2019-10-27 14:08:14 +00:00
if ( ! empty ( $a -> profile [ 'hidewall' ]) && ! $is_owner && ! $remote_contact ) {
2020-07-23 06:25:01 +00:00
notice ( DI :: l10n () -> t ( 'Access to this profile has been restricted.' ));
2019-10-27 14:08:14 +00:00
return '' ;
}
2020-01-26 14:49:11 +00:00
$o .= self :: getTabsHTML ( $a , 'status' , $is_owner , $a -> profile [ 'nickname' ]);
2019-10-27 14:08:14 +00:00
2020-08-05 03:06:11 +00:00
$o .= Widget :: commonFriendsVisitor ( $a -> profile [ 'uid' ], $a -> profile [ 'nickname' ]);
2019-10-27 14:08:14 +00:00
$commpage = $a -> profile [ 'page-flags' ] == User :: PAGE_FLAGS_COMMUNITY ;
$commvisitor = $commpage && $remote_contact ;
DI :: page ()[ 'aside' ] .= Widget :: postedByYear ( DI :: baseUrl () . '/profile/' . $a -> profile [ 'nickname' ] . '/status' , $a -> profile [ 'profile_uid' ] ? ? 0 , true );
DI :: page ()[ 'aside' ] .= Widget :: categories ( DI :: baseUrl () . '/profile/' . $a -> profile [ 'nickname' ] . '/status' , XML :: escape ( $category ));
DI :: page ()[ 'aside' ] .= Widget :: tagCloud ();
2019-11-03 01:19:42 +00:00
if ( Security :: canWriteToUserWall ( $a -> profile [ 'uid' ])) {
2019-10-27 14:08:14 +00:00
$x = [
'is_owner' => $is_owner ,
'allow_location' => ( $is_owner || $commvisitor ) && $a -> profile [ 'allow_location' ],
'default_location' => $is_owner ? $a -> user [ 'default-location' ] : '' ,
'nickname' => $a -> profile [ 'nickname' ],
'lockstate' => is_array ( $a -> user )
&& ( strlen ( $a -> user [ 'allow_cid' ])
|| strlen ( $a -> user [ 'allow_gid' ])
|| strlen ( $a -> user [ 'deny_cid' ])
|| strlen ( $a -> user [ 'deny_gid' ])
) ? 'lock' : 'unlock' ,
'acl' => $is_owner ? ACL :: getFullSelectorHTML ( DI :: page (), $a -> user , true ) : '' ,
'bang' => '' ,
'visitor' => $is_owner || $commvisitor ? 'block' : 'none' ,
2019-11-03 01:19:42 +00:00
'profile_uid' => $a -> profile [ 'uid' ],
2019-10-27 14:08:14 +00:00
];
$o .= status_editor ( $a , $x );
}
// Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
2019-11-03 01:19:42 +00:00
$sql_extra = Item :: getPermissionsSQLByUserId ( $a -> profile [ 'uid' ]);
2019-10-27 14:08:14 +00:00
$sql_extra2 = '' ;
$last_updated_array = Session :: get ( 'last_updated' , []);
$sql_post_table = " " ;
if ( ! empty ( $category )) {
2020-05-03 15:13:40 +00:00
$sql_post_table = sprintf ( " INNER JOIN (SELECT `uri-id` FROM `category-view` WHERE `name` = '%s' AND `type` = %d AND `uid` = %d ORDER BY `uri-id` DESC) AS `category` ON `item`.`uri-id` = `category`.`uri-id` " ,
DBA :: escape ( Strings :: protectSprintf ( $category )), intval ( Category :: CATEGORY ), intval ( $a -> profile [ 'uid' ]));
2019-10-27 14:08:14 +00:00
}
if ( ! empty ( $hashtags )) {
2020-05-01 08:02:21 +00:00
$sql_post_table .= sprintf ( " INNER JOIN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = '%s' AND `uid` = %d ORDER BY `uri-id` DESC) AS `tag-search` ON `item`.`uri-id` = `tag-search`.`uri-id` " ,
DBA :: escape ( Strings :: protectSprintf ( $hashtags )), intval ( $a -> profile [ 'uid' ]));
2019-10-27 14:08:14 +00:00
}
if ( ! empty ( $datequery )) {
$sql_extra2 .= Strings :: protectSprintf ( sprintf ( " AND `thread`.`received` <= '%s' " , DBA :: escape ( DateTimeFormat :: convert ( $datequery , 'UTC' , date_default_timezone_get ()))));
}
if ( ! empty ( $datequery2 )) {
$sql_extra2 .= Strings :: protectSprintf ( sprintf ( " AND `thread`.`received` >= '%s' " , DBA :: escape ( DateTimeFormat :: convert ( $datequery2 , 'UTC' , date_default_timezone_get ()))));
}
// Does the profile page belong to a forum?
// If not then we can improve the performance with an additional condition
2019-11-03 01:19:42 +00:00
$condition = [ 'uid' => $a -> profile [ 'uid' ], 'page-flags' => [ User :: PAGE_FLAGS_COMMUNITY , User :: PAGE_FLAGS_PRVGROUP ]];
2019-10-27 14:08:14 +00:00
if ( ! DBA :: exists ( 'user' , $condition )) {
2020-04-25 07:29:02 +00:00
$sql_extra3 = sprintf ( " AND `thread`.`contact-id` = %d " , intval ( intval ( $a -> profile [ 'id' ])));
2019-10-27 14:08:14 +00:00
} else {
$sql_extra3 = " " ;
}
if ( DI :: mode () -> isMobile ()) {
2020-02-16 18:04:26 +00:00
$itemspage_network = DI :: pConfig () -> get ( local_user (), 'system' , 'itemspage_mobile_network' ,
DI :: config () -> get ( 'system' , 'itemspage_network_mobile' ));
2019-10-27 14:08:14 +00:00
} else {
2020-02-16 18:04:26 +00:00
$itemspage_network = DI :: pConfig () -> get ( local_user (), 'system' , 'itemspage_network' ,
DI :: config () -> get ( 'system' , 'itemspage_network' ));
2019-10-27 14:08:14 +00:00
}
// now that we have the user settings, see if the theme forces
// a maximum item number which is lower then the user choice
if (( $a -> force_max_items > 0 ) && ( $a -> force_max_items < $itemspage_network )) {
$itemspage_network = $a -> force_max_items ;
}
2020-02-16 16:53:52 +00:00
$pager = new Pager ( DI :: l10n (), $args -> getQueryString (), $itemspage_network );
2019-10-27 14:08:14 +00:00
$pager_sql = sprintf ( " LIMIT %d, %d " , $pager -> getStart (), $pager -> getItemsPerPage ());
$items_stmt = DBA :: p (
" SELECT `item`.`uri`
FROM `thread`
STRAIGHT_JOIN `item` ON `item` . `id` = `thread` . `iid`
$sql_post_table
STRAIGHT_JOIN `contact`
ON `contact` . `id` = `thread` . `contact-id`
AND NOT `contact` . `blocked`
AND NOT `contact` . `pending`
WHERE `thread` . `uid` = ?
AND `thread` . `visible`
AND NOT `thread` . `deleted`
AND NOT `thread` . `moderated`
AND `thread` . `wall`
$sql_extra3
$sql_extra
$sql_extra2
ORDER BY `thread` . `received` DESC
$pager_sql " ,
2019-11-03 01:19:42 +00:00
$a -> profile [ 'uid' ]
2019-10-27 14:08:14 +00:00
);
// Set a time stamp for this page. We will make use of it when we
// search for new items (update routine)
$last_updated_array [ $last_updated_key ] = time ();
Session :: set ( 'last_updated' , $last_updated_array );
if ( $is_owner && ! DI :: config () -> get ( 'theme' , 'hide_eventlist' )) {
$o .= ProfileModel :: getBirthdays ();
$o .= ProfileModel :: getEventsReminderHTML ();
}
if ( $is_owner ) {
$unseen = Item :: exists ([ 'wall' => true , 'unseen' => true , 'uid' => local_user ()]);
if ( $unseen ) {
Item :: update ([ 'unseen' => false ], [ 'wall' => true , 'unseen' => true , 'uid' => local_user ()]);
}
}
$items = DBA :: toArray ( $items_stmt );
2020-01-26 19:14:36 +00:00
if ( $pager -> getStart () == 0 && ! empty ( $a -> profile [ 'uid' ])) {
$pinned_items = Item :: selectPinned ( $a -> profile [ 'uid' ], [ 'uri' , 'pinned' ]);
$pinned = Item :: inArray ( $pinned_items );
$items = array_merge ( $items , $pinned );
}
2020-02-14 04:40:00 +00:00
$o .= conversation ( $a , $items , 'profile' , false , false , 'pinned_received' , $a -> profile [ 'uid' ]);
2019-10-27 14:08:14 +00:00
$o .= $pager -> renderMinimal ( count ( $items ));
return $o ;
}
}