Beispiel #1
0
/**
 * @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 boolean $show_connect
 *
 * @return HTML string suitable for sidebar inclusion
 * Exceptions: Returns empty string if passed $profile is wrong type or not populated
 */
function profile_sidebar($profile, $block = 0, $show_connect = true)
{
    $a = get_app();
    $observer = $a->get_observer();
    $o = '';
    $location = false;
    $pdesc = true;
    $reddress = true;
    if (!is_array($profile) && !count($profile)) {
        return $o;
    }
    head_set_icon($profile['thumb']);
    $is_owner = $profile['uid'] == local_channel() ? true : false;
    if (is_sys_channel($profile['uid'])) {
        $show_connect = false;
    }
    $profile['picdate'] = urlencode($profile['picdate']);
    call_hooks('profile_sidebar_enter', $profile);
    require_once 'include/Contact.php';
    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') : '';
        if ($connect_url) {
            $connect_url = sprintf($connect_url, urlencode($profile['channel_address'] . '@' . $a->get_hostname()));
        }
        // premium channel - over-ride
        if ($profile['channel_pageflags'] & PAGE_PREMIUM) {
            $connect_url = z_root() . '/connect/' . $profile['channel_address'];
        }
    }
    // show edit profile to yourself
    if ($is_owner) {
        $profile['menu'] = array('chg_photo' => t('Change profile photo'), 'entries' => array());
        $multi_profiles = feature_enabled(local_channel(), 'multi_profiles');
        if ($multi_profiles) {
            $profile['edit'] = array($a->get_baseurl() . '/profiles', t('Profiles'), "", t('Manage/edit profiles'));
            $profile['menu']['cr_new'] = t('Create New Profile');
        } else {
            $profile['edit'] = array($a->get_baseurl() . '/profiles/' . $profile['id'], t('Edit Profile'), '', t('Edit Profile'));
        }
        $r = q("SELECT * FROM `profile` WHERE `uid` = %d", local_channel());
        if ($r) {
            foreach ($r as $rr) {
                if (!($multi_profiles || $rr['is_default'])) {
                    continue;
                }
                $profile['menu']['entries'][] = array('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'));
            }
        }
    }
    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:');
    }
    $profile['homepage'] = linkify($profile['homepage'], true);
    $gender = x($profile, 'gender') == 1 ? t('Gender:') : False;
    $marital = x($profile, 'marital') == 1 ? t('Status:') : False;
    $homepage = x($profile, 'homepage') == 1 ? t('Homepage:') : False;
    $profile['online'] = $profile['online_status'] === 'online' ? t('Online Now') : False;
    //	logger('online: ' . $profile['online']);
    if (!perm_is_allowed($profile['uid'], is_array($observer) ? $observer['xchan_hash'] : '', 'view_profile')) {
        $block = true;
    }
    if ($profile['hidewall'] && !local_channel() && !remote_channel() || $block) {
        $location = $reddress = $pdesc = $gender = $marital = $homepage = False;
    }
    $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)));
    $diaspora = array('podloc' => z_root(), 'searchable' => $block ? 'false' : 'true', 'nickname' => $profile['channel_address'], 'fullname' => $profile['channel_name'], 'firstname' => $firstname, 'lastname' => $lastname, 'photo300' => z_root() . '/photo/profile/300/' . $profile['uid'] . '.jpg', 'photo100' => z_root() . '/photo/profile/100/' . $profile['uid'] . '.jpg', 'photo50' => z_root() . '/photo/profile/50/' . $profile['uid'] . '.jpg');
    $contact_block = contact_block();
    $channel_menu = false;
    $menu = get_pconfig($profile['uid'], 'system', 'channel_menu');
    if ($menu && !$block) {
        require_once 'include/menu.php';
        $m = menu_fetch($menu, $profile['uid'], $observer['xchan_hash']);
        if ($m) {
            $channel_menu = menu_render($m);
        }
    }
    $menublock = get_pconfig($profile['uid'], 'system', 'channel_menublock');
    if ($menublock && !$block) {
        require_once 'include/comanche.php';
        $channel_menu .= comanche_block($menublock);
    }
    $tpl = get_markup_template('profile_vcard.tpl');
    require_once 'include/widgets.php';
    $z = widget_rating(array('target' => $profile['channel_hash']));
    $o .= replace_macros($tpl, array('$profile' => $profile, '$connect' => $connect, '$connect_url' => $connect_url, '$location' => $location, '$gender' => $gender, '$pdesc' => $pdesc, '$marital' => $marital, '$homepage' => $homepage, '$chanmenu' => $channel_menu, '$diaspora' => $diaspora, '$reddress' => $reddress, '$rating' => $z, '$contact_block' => $contact_block));
    $arr = array('profile' => &$profile, 'entry' => &$o);
    call_hooks('profile_sidebar', $arr);
    return $o;
}
Beispiel #2
0
function comanche_region(&$a, $s)
{
    $matches = array();
    $cnt = preg_match_all("/\\[menu\\](.*?)\\[\\/menu\\]/ism", $s, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            $s = str_replace($mtch[0], comanche_menu(trim($mtch[1])), $s);
        }
    }
    // menu class e.g. [menu=horizontal]my_menu[/menu] or [menu=tabbed]my_menu[/menu]
    // allows different menu renderings to be applied
    $cnt = preg_match_all("/\\[menu=(.*?)\\](.*?)\\[\\/menu\\]/ism", $s, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            $s = str_replace($mtch[0], comanche_menu(trim($mtch[2]), $mtch[1]), $s);
        }
    }
    $cnt = preg_match_all("/\\[block\\](.*?)\\[\\/block\\]/ism", $s, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            $s = str_replace($mtch[0], comanche_block(trim($mtch[1])), $s);
        }
    }
    // need to modify this to accept parameters
    $cnt = preg_match_all("/\\[widget=(.*?)\\](.*?)\\[\\/widget\\]/ism", $s, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            $s = str_replace($mtch[0], comanche_widget(trim($mtch[1]), $mtch[2]), $s);
        }
    }
    return $s;
}