Exemple #1
0
function contacts_init(&$a)
{
    if (!local_user()) {
        return;
    }
    $contact_id = 0;
    if ($a->argc == 2 && intval($a->argv[1]) or $a->argc == 3 && intval($a->argv[1]) && $a->argv[2] == "posts") {
        $contact_id = intval($a->argv[1]);
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1", intval(local_user()), intval($contact_id));
        if (!count($r)) {
            $contact_id = 0;
        }
    }
    require_once 'include/group.php';
    require_once 'include/contact_widgets.php';
    if ($_GET['nets'] == "all") {
        $_GET['nets'] = "";
    }
    if (!x($a->page, 'aside')) {
        $a->page['aside'] = '';
    }
    if ($contact_id) {
        $a->data['contact'] = $r[0];
        if ($a->data['contact']['network'] != "" and $a->data['contact']['network'] != NETWORK_DFRN) {
            $networkname = format_network_name($a->data['contact']['network'], $a->data['contact']['url']);
        } else {
            $networkname = '';
        }
        $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), array('$name' => htmlentities($a->data['contact']['name']), '$photo' => $a->data['contact']['photo'], '$url' => $a->data['contact']['network'] == NETWORK_DFRN ? z_root() . "/redir/" . $a->data['contact']['id'] : $a->data['contact']['url'], '$addr' => $a->data['contact']['addr'] != "" ? $a->data['contact']['addr'] : "", '$network_name' => $networkname, '$network' => t('Network:'), 'account_type' => $a->data['contact']['forum'] || $a->data['contact']['prv'] ? t('Forum') : ''));
        $finpeople_widget = '';
        $follow_widget = '';
        $networks_widget = '';
    } else {
        $vcard_widget = '';
        $networks_widget .= networks_widget('contacts', $_GET['nets']);
        if (isset($_GET['add'])) {
            $follow_widget = follow_widget($_GET['add']);
        } else {
            $follow_widget = follow_widget();
        }
        $findpeople_widget .= findpeople_widget();
    }
    $groups_widget .= group_side('contacts', 'group', 'full', 0, $contact_id);
    $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), array('$vcard_widget' => $vcard_widget, '$findpeople_widget' => $findpeople_widget, '$follow_widget' => $follow_widget, '$groups_widget' => $groups_widget, '$networks_widget' => $networks_widget));
    $base = z_root();
    $tpl = get_markup_template("contacts-head.tpl");
    $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true), '$base' => $base));
    $tpl = get_markup_template("contacts-end.tpl");
    $a->page['end'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true), '$base' => $base));
}
Exemple #2
0
 function profile_sidebar($profile, $block = 0)
 {
     $a = get_app();
     $o = '';
     $location = false;
     $address = false;
     //		$pdesc = true;
     if (!is_array($profile) && !count($profile)) {
         return $o;
     }
     $profile['picdate'] = urlencode($profile['picdate']);
     if ($profile['network'] != "" and $profile['network'] != NETWORK_DFRN) {
         $profile['network_name'] = format_network_name($profile['network'], $profile['url']);
     } else {
         $profile['network_name'] = "";
     }
     call_hooks('profile_sidebar_enter', $profile);
     // don't show connect link to yourself
     $connect = $profile['uid'] != local_user() ? t('Connect') : False;
     // don't show connect link to authenticated visitors either
     if (remote_user() && count($_SESSION['remote'])) {
         foreach ($_SESSION['remote'] as $visitor) {
             if ($visitor['uid'] == $profile['uid']) {
                 $connect = false;
                 break;
             }
         }
     }
     // Is the local user already connected to that user?
     if ($connect and local_user()) {
         if (isset($profile["url"])) {
             $profile_url = normalise_link($profile["url"]);
         } else {
             $profile_url = normalise_link($a->get_baseurl() . "/profile/" . $profile["nickname"]);
         }
         $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'", local_user(), $profile_url);
         if (count($r)) {
             $connect = false;
         }
     }
     if ($connect and $profile['network'] != NETWORK_DFRN and !isset($profile['remoteconnect'])) {
         $connect = false;
     }
     if (isset($profile['remoteconnect'])) {
         $remoteconnect = $profile['remoteconnect'];
     }
     if ($connect and $profile['network'] == NETWORK_DFRN and !isset($remoteconnect)) {
         $subscribe_feed = t("Atom feed");
     } else {
         $subscribe_feed = false;
     }
     if (get_my_url() && $profile['unkmail'] && $profile['uid'] != local_user()) {
         $wallmessage = t('Message');
     } else {
         $wallmessage = false;
     }
     // show edit profile to yourself
     if ($profile['uid'] == local_user() && feature_enabled(local_user(), 'multi_profiles')) {
         $profile['edit'] = array($a->get_baseurl() . '/profiles', t('Profiles'), "", t('Manage/edit profiles'));
         $r = q("SELECT * FROM `profile` WHERE `uid` = %d", local_user());
         $profile['menu'] = array('chg_photo' => t('Change profile photo'), 'cr_new' => t('Create New Profile'), 'entries' => array());
         if (count($r)) {
             foreach ($r as $rr) {
                 $profile['menu']['entries'][] = array('photo' => $rr['thumb'], 'id' => $rr['id'], 'alt' => t('Profile Image'), 'profile_name' => $rr['profile-name'], 'isdefault' => $rr['is-default'], 'visibile_to_everybody' => t('visible to everybody'), 'edit_visibility' => t('Edit visibility'));
             }
         }
     }
     if ($profile['uid'] == local_user() && !feature_enabled(local_user(), 'multi_profiles')) {
         $profile['edit'] = array($a->get_baseurl() . '/profiles/' . $profile['id'], t('Edit profile'), "", t('Edit profile'));
         $profile['menu'] = array('chg_photo' => t('Change profile photo'), 'cr_new' => null, 'entries' => array());
     }
     // check if profile is a forum
     if (intval($profile['page-flags']) == PAGE_COMMUNITY || intval($profile['page-flags']) == PAGE_PRVGROUP || intval($profile['forum']) || intval($profile['prv']) || intval($profile['community'])) {
         $account_type = t('Forum');
     } else {
         $account_type = "";
     }
     if (x($profile, 'address') == 1 || x($profile, 'locality') == 1 || x($profile, 'region') == 1 || x($profile, 'postal-code') == 1 || x($profile, 'country-name') == 1) {
         $location = t('Location:');
     }
     $gender = x($profile, 'gender') == 1 ? t('Gender:') : False;
     $marital = x($profile, 'marital') == 1 ? t('Status:') : False;
     $homepage = x($profile, 'homepage') == 1 ? t('Homepage:') : False;
     $about = x($profile, 'about') == 1 ? t('About:') : False;
     if (($profile['hidewall'] || $block) && !local_user() && !remote_user()) {
         $location = $pdesc = $gender = $marital = $homepage = $about = False;
     }
     $firstname = strpos($profile['name'], ' ') ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name'];
     $lastname = $firstname === $profile['name'] ? '' : trim(substr($profile['name'], strlen($firstname)));
     $diaspora = array('guid' => $profile['guid'], 'podloc' => $a->get_baseurl(), 'searchable' => $profile['publish'] && $profile['net-publish'] ? 'true' : 'false', 'nickname' => $profile['nickname'], 'fullname' => $profile['name'], 'firstname' => $firstname, 'lastname' => $lastname, 'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'), 'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'), 'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'));
     if (!$block) {
         $contact_block = contact_block();
         if (is_array($a->profile) and !$a->profile['hide-friends']) {
             $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1", intval($a->profile['uid']));
             if (count($r)) {
                 $updated = date("c", strtotime($r[0]['updated']));
             }
             $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0\n\t\t\t\t\t\tAND `network` IN ('%s', '%s', '%s', '')", intval($profile['uid']), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
             if (count($r)) {
                 $contacts = intval($r[0]['total']);
             }
         }
     }
     $p = array();
     foreach ($profile as $k => $v) {
         $k = str_replace('-', '_', $k);
         $p[$k] = $v;
     }
     if (isset($p["about"])) {
         $p["about"] = bbcode($p["about"]);
     }
     if (isset($p["location"])) {
         $p["location"] = bbcode($p["location"]);
     }
     if (isset($p["photo"])) {
         $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
     }
     if ($a->theme['template_engine'] === 'internal') {
         $location = template_escape($location);
     }
     $tpl = get_markup_template('profile_vcard.tpl');
     $o .= replace_macros($tpl, array('$profile' => $p, '$connect' => $connect, '$remoteconnect' => $remoteconnect, '$subscribe_feed' => $subscribe_feed, '$wallmessage' => $wallmessage, '$account_type' => $account_type, '$location' => $location, '$gender' => $gender, '$marital' => $marital, '$homepage' => $homepage, '$about' => $about, '$network' => t('Network:'), '$contacts' => $contacts, '$updated' => $updated, '$diaspora' => $diaspora, '$contact_block' => $contact_block));
     $arr = array('profile' => &$profile, 'entry' => &$o);
     call_hooks('profile_sidebar', $arr);
     return $o;
 }