streams/Zotlabs/Lib/Libprofile.php

696 lines
24 KiB
PHP
Raw Normal View History

2019-04-17 23:54:06 +00:00
<?php
namespace Zotlabs\Lib;
use App;
2022-01-25 01:26:12 +00:00
use Zotlabs\Lib\Channel;
2022-01-25 23:25:21 +00:00
use Zotlabs\Lib\Features;
2022-01-26 05:43:05 +00:00
use Zotlabs\Lib\Menu;
2021-12-02 23:02:31 +00:00
class Libprofile
{
/**
* @brief Loads a profile into the App structure.
*
* The function requires the nickname of a valid channel.
*
* Permissions of the current observer are checked. If a restricted profile is available
* to the current observer, that will be loaded instead of the channel default profile.
*
* The channel owner can set $profile to a valid profile_guid to preview that profile.
*
* The channel default theme is also selected for use, unless over-riden elsewhere.
*
* @param string $nickname
* @param string $profile_guid
*/
public static function load($nickname, $profile = '')
{
2021-12-03 03:01:39 +00:00
// logger('Libprofile::load: ' . $nickname . (($profile) ? ' profile: ' . $profile : ''));
2021-12-02 23:02:31 +00:00
2022-01-25 01:26:12 +00:00
$channel = Channel::from_username($nickname);
2021-12-02 23:02:31 +00:00
if (!$channel) {
logger('profile error: ' . App::$query_string, LOGGER_DEBUG);
notice(t('Requested channel is not available.') . EOL);
App::$error = 404;
return;
}
// get the current observer
$observer = App::get_observer();
$can_view_profile = true;
// Can the observer see our profile?
require_once('include/permissions.php');
if (!perm_is_allowed($channel['channel_id'], (($observer) ? $observer['xchan_hash'] : ''), 'view_profile')) {
$can_view_profile = false;
}
if (!$profile) {
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT abook_profile FROM abook WHERE abook_xchan = '%s' and abook_channel = '%d' limit 1",
2021-12-02 23:02:31 +00:00
dbesc(($observer) ? $observer['xchan_hash'] : ''),
intval($channel['channel_id'])
);
2021-12-03 03:01:39 +00:00
if ($r) {
2021-12-02 23:02:31 +00:00
$profile = $r[0]['abook_profile'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
$p = null;
if ($profile) {
2021-12-03 03:01:39 +00:00
$p = q(
"SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
2019-08-16 06:53:02 +00:00
LEFT JOIN channel ON profile.uid = channel.channel_id
WHERE channel.channel_address = '%s' AND profile.profile_guid = '%s' LIMIT 1",
2021-12-02 23:02:31 +00:00
dbesc($nickname),
dbesc($profile)
);
if (!$p) {
2021-12-03 03:01:39 +00:00
$p = q(
"SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
2019-04-17 23:54:06 +00:00
LEFT JOIN channel ON profile.uid = channel.channel_id
2019-08-16 06:53:02 +00:00
WHERE channel.channel_address = '%s' AND profile.id = %d LIMIT 1",
2021-12-02 23:02:31 +00:00
dbesc($nickname),
intval($profile)
);
}
}
if (!$p) {
2021-12-03 03:01:39 +00:00
$p = q(
"SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile
2019-04-17 23:54:06 +00:00
LEFT JOIN channel ON profile.uid = channel.channel_id
WHERE channel.channel_address = '%s' and channel_removed = 0
AND profile.is_default = 1 LIMIT 1",
2021-12-02 23:02:31 +00:00
dbesc($nickname)
);
}
if (!$p) {
logger('profile error: ' . App::$query_string, LOGGER_DEBUG);
notice(t('Requested profile is not available.') . EOL);
App::$error = 404;
return;
}
2021-12-03 03:01:39 +00:00
$q = q(
"select * from profext where hash = '%s' and channel_id = %d",
2021-12-02 23:02:31 +00:00
dbesc($p[0]['profile_guid']),
intval($p[0]['profile_uid'])
);
if ($q) {
$extra_fields = [];
2022-01-25 01:26:12 +00:00
$profile_fields_basic = Channel::get_profile_fields_basic();
$profile_fields_advanced = Channel::get_profile_fields_advanced();
2021-12-02 23:02:31 +00:00
2022-01-25 23:20:02 +00:00
$advanced = ((Features::enabled(local_channel(), 'advanced_profiles')) ? true : false);
2021-12-03 03:01:39 +00:00
if ($advanced) {
2021-12-02 23:02:31 +00:00
$fields = $profile_fields_advanced;
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$fields = $profile_fields_basic;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
foreach ($q as $qq) {
foreach ($fields as $k => $f) {
if ($k == $qq['k']) {
$p[0][$k] = $qq['v'];
$extra_fields[] = $k;
break;
}
}
}
}
$p[0]['extra_fields'] = ((isset($extra_fields)) ? $extra_fields : []);
2021-12-03 03:01:39 +00:00
$z = q(
"select xchan_photo_date, xchan_addr from xchan where xchan_hash = '%s' limit 1",
2021-12-02 23:02:31 +00:00
dbesc($p[0]['channel_hash'])
);
if ($z) {
$p[0]['picdate'] = $z[0]['xchan_photo_date'];
$p[0]['reddress'] = str_replace('@', '&#x40;', unpunify($z[0]['xchan_addr']));
}
// fetch user tags if this isn't the default profile
if (!$p[0]['is_default']) {
2021-12-03 03:01:39 +00:00
$x = q(
"select keywords from profile where uid = %d and is_default = 1 limit 1",
2021-12-02 23:02:31 +00:00
intval($p[0]['profile_uid'])
);
2021-12-03 03:01:39 +00:00
if ($x && $can_view_profile) {
2021-12-02 23:02:31 +00:00
$p[0]['keywords'] = $x[0]['keywords'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
if ($p[0]['keywords']) {
$keywords = str_replace(array('#', ',', ' ', ',,'), array('', ' ', ',', ','), $p[0]['keywords']);
if (strlen($keywords) && $can_view_profile) {
if (!isset(App::$page['htmlhead'])) {
App::$page['htmlhead'] = EMPTY_STR;
}
App::$page['htmlhead'] .= '<meta name="keywords" content="' . htmlentities($keywords, ENT_COMPAT, 'UTF-8') . '" />' . "\r\n";
}
}
App::$profile = $p[0];
App::$profile_uid = $p[0]['profile_uid'];
2022-01-25 01:26:12 +00:00
App::$page['title'] = App::$profile['channel_name'] . " - " . unpunify(Channel::get_webfinger(App::$profile));
2021-12-02 23:02:31 +00:00
App::$profile['permission_to_view'] = $can_view_profile;
if ($can_view_profile) {
2022-01-25 01:26:12 +00:00
$online = Channel::get_online_status($nickname);
2021-12-02 23:02:31 +00:00
App::$profile['online_status'] = $online['result'];
}
if (local_channel()) {
App::$profile['channel_mobile_theme'] = get_pconfig(local_channel(), 'system', 'mobile_theme');
$_SESSION['mobile_theme'] = App::$profile['channel_mobile_theme'];
}
/*
* load/reload current theme info
*/
2021-12-03 03:01:39 +00:00
// $_SESSION['theme'] = $p[0]['channel_theme'];
2021-12-02 23:02:31 +00:00
}
public static function edit_menu($uid)
{
$ret = [];
$is_owner = (($uid == local_channel()) ? true : false);
// show edit profile to profile owner
if ($is_owner) {
$ret['menu'] = array(
'chg_photo' => t('Change profile photo'),
'entries' => [],
);
2022-01-25 23:20:02 +00:00
$multi_profiles = Features::enabled(local_channel(), 'multi_profiles');
2021-12-02 23:02:31 +00:00
if ($multi_profiles) {
$ret['multi'] = 1;
$ret['edit'] = [z_root() . '/profiles', t('Edit Profiles'), '', t('Edit')];
$ret['menu']['cr_new'] = t('Create New Profile');
} else {
$ret['edit'] = [z_root() . '/profiles/' . $uid, t('Edit Profile'), '', t('Edit')];
}
2021-12-03 03:01:39 +00:00
$r = q(
"SELECT * FROM profile WHERE uid = %d",
2021-12-02 23:02:31 +00:00
local_channel()
);
if ($r) {
foreach ($r as $rr) {
2021-12-03 03:01:39 +00:00
if (!($multi_profiles || $rr['is_default'])) {
2021-12-02 23:02:31 +00:00
continue;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$ret['menu']['entries'][] = [
'photo' => $rr['thumb'],
'id' => $rr['id'],
'alt' => t('Profile Image'),
'profile_name' => $rr['profile_name'],
'isdefault' => $rr['is_default'],
'visible_to_everybody' => t('Visible to everybody'),
'edit_visibility' => t('Edit visibility'),
];
}
}
}
return $ret;
}
/**
* @brief Formats a profile for display in the sidebar.
*
* It is very difficult to templatise the HTML completely
* because of all the conditional logic.
*
* @param array $profile
* @param int $block
* @param bool $show_connect (optional) default true
* @param mixed $zcard (optional) default false
*
* @return HTML string suitable for sidebar inclusion
* Exceptions: Returns empty string if passed $profile is wrong type or not populated
*/
public static function widget($profile, $block = 0, $show_connect = true, $zcard = false)
{
$observer = App::get_observer();
$o = '';
$location = false;
$pdesc = true;
$reddress = true;
if (!perm_is_allowed($profile['uid'], ((is_array($observer)) ? $observer['xchan_hash'] : ''), 'view_profile')) {
$block = true;
}
2021-12-03 03:01:39 +00:00
if ((!is_array($profile)) && (!count($profile))) {
2021-12-02 23:02:31 +00:00
return $o;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
head_set_icon($profile['thumb']);
2022-01-25 01:26:12 +00:00
if (Channel::is_system($profile['uid'])) {
2021-12-02 23:02:31 +00:00
$show_connect = false;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$profile['picdate'] = urlencode($profile['picdate']);
/**
* @hooks profile_sidebar_enter
* Called before generating the 'channel sidebar' or mini-profile.
*/
call_hooks('profile_sidebar_enter', $profile);
2021-12-25 22:45:01 +00:00
$profdm = EMPTY_STR;
$profdm_url = EMPTY_STR;
$can_dm = perm_is_allowed($profile['uid'], (is_array($observer)) ? $observer['xchan_hash'] : EMPTY_STR, 'post_mail') && intval($observer['xchan_type']) !== XCHAN_TYPE_GROUP ;
if (intval($profile['uid']) === local_channel()) {
$can_dm = false;
}
2021-12-25 22:45:01 +00:00
if ($can_dm) {
$dm_path = Libzot::get_rpost_path($observer);
if ($dm_path) {
$profdm = t('Direct Message');
$profdm_url = $dm_path
. '&to='
. urlencode($profile['channel_hash'])
. '&body='
. urlencode('@!{' . $profile['channel_address'] . '@' . App::get_hostname() . '}');
}
}
2021-12-02 23:02:31 +00:00
if ($show_connect) {
// This will return an empty string if we're already connected.
$connect_url = rconnect_url($profile['uid'], get_observer_hash());
$connect = (($connect_url) ? t('Connect') : '');
2021-12-03 03:01:39 +00:00
if ($connect_url) {
2022-01-25 01:26:12 +00:00
$connect_url = sprintf($connect_url, urlencode(Channel::get_webfinger($profile)));
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
// premium channel - over-ride
2021-12-03 03:01:39 +00:00
if ($profile['channel_pageflags'] & PAGE_PREMIUM) {
2021-12-02 23:02:31 +00:00
$connect_url = z_root() . '/connect/' . $profile['channel_address'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
2021-12-03 03:01:39 +00:00
if (
(x($profile, 'address') == 1)
2021-12-02 23:02:31 +00:00
|| (x($profile, 'locality') == 1)
|| (x($profile, 'region') == 1)
|| (x($profile, 'postal_code') == 1)
2021-12-03 03:01:39 +00:00
|| (x($profile, 'country_name') == 1)
) {
2021-12-02 23:02:31 +00:00
$location = t('Location:');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$profile['homepage'] = linkify($profile['homepage'], true);
2021-12-03 03:01:39 +00:00
$gender = ((x($profile, 'gender') == 1) ? t('Gender:') : false);
$marital = ((x($profile, 'marital') == 1) ? t('Status:') : false);
$homepage = ((x($profile, 'homepage') == 1) ? t('Homepage:') : false);
$pronouns = ((x($profile, 'pronouns') == 1) ? t('Pronouns:') : false);
2021-12-02 23:02:31 +00:00
// zap/osada do not have a realtime chat system at this time so don't show online state
2021-12-03 03:01:39 +00:00
// $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False);
// logger('online: ' . $profile['online']);
2021-12-02 23:02:31 +00:00
$profile['online'] = false;
if (($profile['hidewall'] && (!local_channel()) && (!remote_channel())) || $block) {
2021-12-03 03:01:39 +00:00
$location = $reddress = $pdesc = $gender = $marital = $homepage = false;
2021-12-02 23:02:31 +00:00
}
if ($profile['gender']) {
$profile['gender_icon'] = self::gender_icon($profile['gender']);
}
if ($profile['pronouns']) {
$profile['pronouns_icon'] = self::pronouns_icon($profile['pronouns']);
}
$firstname = ((strpos($profile['channel_name'], ' '))
? trim(substr($profile['channel_name'], 0, strpos($profile['channel_name'], ' '))) : $profile['channel_name']);
$lastname = (($firstname === $profile['channel_name']) ? '' : trim(substr($profile['channel_name'], strlen($firstname))));
$contact_block = contact_block();
$channel_menu = false;
$menu = get_pconfig($profile['uid'], 'system', 'channel_menu');
if ($menu && !$block) {
2022-01-26 05:43:05 +00:00
$m = Menu::fetch($menu, $profile['uid'], $observer['xchan_hash']);
2021-12-03 03:01:39 +00:00
if ($m) {
2022-01-26 05:43:05 +00:00
$channel_menu = Menu::render($m);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
$menublock = get_pconfig($profile['uid'], 'system', 'channel_menublock');
if ($menublock && (!$block)) {
$comanche = new Comanche();
$channel_menu .= $comanche->block($menublock);
}
2021-12-03 03:01:39 +00:00
if ($zcard) {
2021-12-02 23:02:31 +00:00
$tpl = get_markup_template('profile_vcard_short.tpl');
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$tpl = get_markup_template('profile_vcard.tpl');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$o .= replace_macros($tpl, array(
'$zcard' => $zcard,
'$profile' => $profile,
'$connect' => $connect,
'$connect_url' => $connect_url,
2021-12-25 22:45:01 +00:00
'$profdm' => $profdm,
'$profdm_url' => $profdm_url,
'$location' => $location,
2021-12-02 23:02:31 +00:00
'$gender' => $gender,
'$pronouns' => $pronouns,
'$pdesc' => $pdesc,
'$marital' => $marital,
'$homepage' => $homepage,
'$chanmenu' => $channel_menu,
'$reddress' => $reddress,
'$active' => t('Active'),
'$activewhen' => relative_date($profile['channel_lastpost']),
'$rating' => '',
'$contact_block' => $contact_block,
'$change_photo' => t('Change your profile photo'),
'$copyto' => t('Copy to clipboard'),
'$copied' => t('Address copied to clipboard'),
'$editmenu' => self::edit_menu($profile['uid'])
));
$arr = [
'profile' => $profile,
'entry' => $o
];
/**
* @hooks profile_sidebar
* Called when generating the 'channel sidebar' or mini-profile.
* * \e array \b profile
* * \e string \b entry - The parsed HTML template
*/
call_hooks('profile_sidebar', $arr);
return $arr['entry'];
}
public static function gender_icon($gender)
{
2021-12-03 03:01:39 +00:00
// logger('gender: ' . $gender);
2021-12-02 23:02:31 +00:00
// This can easily get throw off if the observer language is different
// than the channel owner language.
2021-12-03 03:01:39 +00:00
if (strpos(strtolower($gender), strtolower(t('Female'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'venus';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($gender), strtolower(t('Male'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'mars';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($gender), strtolower(t('Trans'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'transgender';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($gender), strtolower(t('Inter'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'transgender';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($gender), strtolower(t('Neuter'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'neuter';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($gender), strtolower(t('Non-specific'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'genderless';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
return '';
}
public static function pronouns_icon($pronouns)
{
// This can easily get throw off if the observer language is different
// than the channel owner language.
2021-12-03 03:01:39 +00:00
if (strpos(strtolower($pronouns), strtolower(t('She'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'venus';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($pronouns), strtolower(t('Him'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'mars';
2021-12-03 03:01:39 +00:00
}
if (strpos(strtolower($pronouns), strtolower(t('Them'))) !== false) {
2021-12-02 23:02:31 +00:00
return 'users';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
return '';
}
public static function advanced()
{
2021-12-03 03:01:39 +00:00
if (!perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_profile')) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
if (App::$profile['fullname']) {
2022-01-25 01:26:12 +00:00
$profile_fields_basic = Channel::get_profile_fields_basic();
$profile_fields_advanced = Channel::get_profile_fields_advanced();
2021-12-02 23:02:31 +00:00
2022-01-25 23:20:02 +00:00
$advanced = ((Features::enabled(App::$profile['profile_uid'], 'advanced_profiles')) ? true : false);
2021-12-03 03:01:39 +00:00
if ($advanced) {
2021-12-02 23:02:31 +00:00
$fields = $profile_fields_advanced;
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$fields = $profile_fields_basic;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$clean_fields = [];
if ($fields) {
foreach ($fields as $k => $v) {
$clean_fields[] = trim($k);
}
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
$tpl = get_markup_template('profile_advanced.tpl');
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
$profile = [];
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
$profile['fullname'] = array(t('Full Name:'), App::$profile['fullname']);
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['gender']) {
$profile['gender'] = array(t('Gender:'), App::$profile['gender']);
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
$ob_hash = get_observer_hash();
// this may not work at all any more, but definitely won't work correctly if the liked profile belongs to a group
// comment out until we are able to look at it much closer
2021-12-03 03:01:39 +00:00
// if($ob_hash && perm_is_allowed(App::$profile['profile_uid'],$ob_hash,'post_like')) {
// $profile['canlike'] = true;
// $profile['likethis'] = t('Like this channel');
// $profile['profile_guid'] = App::$profile['profile_guid'];
// }
// $likers = q("select liker, xchan.* from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'",
// intval(App::$profile['profile_uid']),
// dbesc(ACTIVITY_OBJ_PROFILE),
// dbesc(ACTIVITY_LIKE)
// );
// $profile['likers'] = [];
// $profile['like_count'] = count($likers);
// $profile['like_button_label'] = tt('Like','Likes',$profile['like_count'],'noun');
// if($likers) {
// foreach($likers as $l)
// $profile['likers'][] = array('name' => $l['xchan_name'],'photo' => zid($l['xchan_photo_s']), 'url' => zid($l['xchan_url']));
// }
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
if ((App::$profile['dob']) && (App::$profile['dob'] != '0000-00-00')) {
$val = '';
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ((substr(App::$profile['dob'], 5, 2) === '00') || (substr(App::$profile['dob'], 8, 2) === '00')) {
2021-12-02 23:02:31 +00:00
$val = substr(App::$profile['dob'], 0, 4);
2021-12-03 03:01:39 +00:00
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
$year_bd_format = t('j F, Y');
$short_bd_format = t('j F');
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
if (!$val) {
$val = ((intval(App::$profile['dob']))
? day_translate(datetime_convert('UTC', 'UTC', App::$profile['dob'] . ' 00:00 +00:00', $year_bd_format))
: day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr(App::$profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)));
}
$profile['birthday'] = array(t('Birthday:'), $val);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($age = age(App::$profile['dob'], App::$profile['timezone'], '')) {
2021-12-02 23:02:31 +00:00
$profile['age'] = array(t('Age:'), $age);
2021-12-03 03:01:39 +00:00
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['marital']) {
2021-12-02 23:02:31 +00:00
$profile['marital'] = array(t('Status:'), App::$profile['marital']);
2021-12-03 03:01:39 +00:00
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['partner']) {
2021-12-02 23:02:31 +00:00
$profile['marital']['partner'] = zidify_links(bbcode(App::$profile['partner']));
2021-12-03 03:01:39 +00:00
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
if (strlen(App::$profile['howlong']) && App::$profile['howlong'] > NULL_DATE) {
$profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s'));
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
if (App::$profile['keywords']) {
$keywords = str_replace(',', ' ', App::$profile['keywords']);
$keywords = str_replace(' ', ' ', $keywords);
$karr = explode(' ', $keywords);
if ($karr) {
for ($cnt = 0; $cnt < count($karr); $cnt++) {
$karr[$cnt] = '<a href="' . z_root() . '/directory/f=&keywords=' . trim($karr[$cnt]) . '">' . $karr[$cnt] . '</a>';
}
}
$profile['keywords'] = array(t('Tags:'), implode(' ', $karr));
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['sexual']) {
$profile['sexual'] = array(t('Sexual Preference:'), App::$profile['sexual']);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['pronouns']) {
$profile['pronouns'] = array(t('Pronouns:'), App::$profile['pronouns']);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['homepage']) {
$profile['homepage'] = array(t('Homepage:'), linkify(App::$profile['homepage']));
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['hometown']) {
$profile['hometown'] = array(t('Hometown:'), linkify(App::$profile['hometown']));
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['politic']) {
$profile['politic'] = array(t('Political Views:'), App::$profile['politic']);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if (App::$profile['religion']) {
$profile['religion'] = array(t('Religion:'), App::$profile['religion']);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['about'])) {
$profile['about'] = array(t('About:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['interest'])) {
$profile['interest'] = array(t('Hobbies/Interests:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['likes'])) {
$profile['likes'] = array(t('Likes:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['dislikes'])) {
$profile['dislikes'] = array(t('Dislikes:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['contact'])) {
$profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['channels'])) {
$profile['channels'] = array(t('My other channels:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['music'])) {
$profile['music'] = array(t('Musical interests:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['book'])) {
$profile['book'] = array(t('Books, literature:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['tv'])) {
$profile['tv'] = array(t('Television:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['film'])) {
$profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['romance'])) {
$profile['romance'] = array(t('Love/Romance:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['employment'])) {
$profile['employment'] = array(t('Work/employment:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
if ($txt = prepare_text(App::$profile['education'])) {
$profile['education'] = array(t('School/education:'), $txt);
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
if (App::$profile['extra_fields']) {
foreach (App::$profile['extra_fields'] as $f) {
2021-12-03 03:01:39 +00:00
$x = q(
"select * from profdef where field_name = '%s' limit 1",
2021-12-02 23:02:31 +00:00
dbesc($f)
);
2021-12-03 03:01:39 +00:00
if ($x && $txt = prepare_text(App::$profile[$f])) {
2021-12-02 23:02:31 +00:00
$profile[$f] = array($x[0]['field_desc'] . ':', $txt);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
$profile['extra_fields'] = App::$profile['extra_fields'];
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
$things = get_things(App::$profile['profile_guid'], App::$profile['profile_uid']);
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
// logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
2019-04-17 23:54:06 +00:00
2021-12-03 03:01:39 +00:00
// $exportlink = ((App::$profile['profile_vcard']) ? zid(z_root() . '/profile/' . App::$profile['channel_address'] . '/vcard') : '');
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
return replace_macros($tpl, array(
'$title' => t('Profile'),
'$canlike' => (($profile['canlike']) ? true : false),
'$likethis' => t('Like this thing'),
'$export' => t('Export'),
'$exportlink' => '', // $exportlink,
'$profile' => $profile,
'$fields' => $clean_fields,
'$editmenu' => self::edit_menu(App::$profile['profile_uid']),
'$things' => $things
));
}
2019-04-17 23:54:06 +00:00
2021-12-02 23:02:31 +00:00
return '';
}
2021-12-03 03:01:39 +00:00
}