Example #1
0
function networks_widget($baseurl, $selected = '')
{
    $a = get_app();
    if (!local_user()) {
        return '';
    }
    if (!feature_enabled(local_user(), 'networks')) {
        return '';
    }
    $extra_sql = unavailable_networks();
    $r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND NOT `self` {$extra_sql} ORDER BY `network`", intval(local_user()));
    $nets = array();
    if (count($r)) {
        require_once 'include/contact_selectors.php';
        foreach ($r as $rr) {
            if ($rr['network']) {
                $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => $selected == $rr['network'] ? 'selected' : '');
            }
        }
    }
    if (count($nets) < 2) {
        return '';
    }
    return replace_macros(get_markup_template('nets.tpl'), array('$title' => t('Networks'), '$desc' => '', '$sel_all' => $selected == '' ? 'selected' : '', '$all' => t('All Networks'), '$nets' => $nets, '$base' => $baseurl));
}
Example #2
0
function suggest_content(&$a)
{
    require_once "mod/proxy.php";
    $o = '';
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
    $a->page['aside'] .= findpeople_widget();
    $a->page['aside'] .= follow_widget();
    $r = suggestion_query(local_user());
    if (!count($r)) {
        $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');
        return $o;
    }
    require_once 'include/contact_selectors.php';
    foreach ($r as $rr) {
        $connlnk = $a->get_baseurl() . '/follow/?url=' . ($rr['connect'] ? $rr['connect'] : $rr['url']);
        $ignlnk = $a->get_baseurl() . '/suggest?ignore=' . $rr['id'];
        $photo_menu = array(array(t("View Profile"), zrl($rr["url"])));
        $photo_menu[] = array(t("Connect/Follow"), $connlnk);
        $photo_menu[] = array(t('Ignore/Hide'), $ignlnk);
        $contact_details = get_contact_details_by_url($rr["url"], local_user());
        $entry = array('url' => zrl($rr['url']), 'itemurl' => $contact_details['addr'] != "" ? $contact_details['addr'] : $rr['url'], 'img_hover' => $rr['url'], 'name' => $rr['name'], 'thumb' => proxy_url($rr['photo'], false, PROXY_SIZE_THUMB), 'details' => $contact_details['location'], 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => $contact_details['community'] ? t('Forum') : '', 'ignlnk' => $ignlnk, 'ignid' => $rr['id'], 'conntxt' => t('Connect'), 'connlnk' => $connlnk, 'photo_menu' => $photo_menu, 'ignore' => t('Ignore/Hide'), 'network' => network_to_name($rr['network'], $rr['url']), 'id' => ++$id);
        $entries[] = $entry;
    }
    $tpl = get_markup_template('viewcontact_template.tpl');
    $o .= replace_macros($tpl, array('$title' => t('Friend Suggestions'), '$contacts' => $entries));
    return $o;
}
Example #3
0
function allfriends_content(&$a)
{
    $o = '';
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc > 1) {
        $cid = intval($a->argv[1]);
    }
    if (!$cid) {
        return;
    }
    $uid = $a->user[uid];
    $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($cid), intval(local_user()));
    if (!count($c)) {
        return;
    }
    $a->page['aside'] = "";
    profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"]));
    $total = count_all_friends(local_user(), $cid);
    if (count($total)) {
        $a->set_pager_total($total);
    }
    $r = all_friends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
    if (!count($r)) {
        $o .= t('No friends to display.');
        return $o;
    }
    $id = 0;
    foreach ($r as $rr) {
        //get further details of the contact
        $contact_details = get_contact_details_by_url($rr['url'], $uid);
        $photo_menu = '';
        // $rr[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photo_menu
        // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
        if ($rr[cid]) {
            $rr[id] = $rr[cid];
            $photo_menu = contact_photo_menu($rr);
        } else {
            $connlnk = $a->get_baseurl() . '/follow/?url=' . $rr['url'];
            $photo_menu = array(array(t("View Profile"), zrl($rr['url'])));
            $photo_menu[] = array(t("Connect/Follow"), $connlnk);
        }
        $entry = array('url' => $rr['url'], 'itemurl' => $contact_details['addr'] != "" ? $contact_details['addr'] : $rr['url'], 'name' => htmlentities($rr['name']), 'thumb' => proxy_url($rr['photo'], false, PROXY_SIZE_THUMB), 'img_hover' => htmlentities($rr['name']), 'details' => $contact_details['location'], 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => $contact_details['community'] ? t('Forum') : '', 'network' => network_to_name($contact_details['network'], $contact_details['url']), 'photo_menu' => $photo_menu, 'conntxt' => t('Connect'), 'connlnk' => $connlnk, 'id' => ++$id);
        $entries[] = $entry;
    }
    $tab_str = contacts_tab($a, $cid, 3);
    $tpl = get_markup_template('viewcontact_template.tpl');
    $o .= replace_macros($tpl, array('$tab_str' => $tab_str, '$contacts' => $entries, '$paginate' => paginate($a)));
    return $o;
}
Example #4
0
function follow_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    $uid = local_user();
    $url = notags(trim($_REQUEST['url']));
    // There is a current issue. It seems as if you can't start following a Friendica that is following you
    // With Diaspora this works - but Friendica is special, it seems ...
    $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND\n\t\t(`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND\n\t\t`network` != '%s' LIMIT 1", intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)), dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
    if ($r) {
        notice(t('You already added this contact.') . EOL);
        goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    $ret = probe_url($url);
    if ($ret["network"] == NETWORK_MAIL) {
        $ret["url"] = $ret["addr"];
    }
    if ($ret['network'] === NETWORK_DFRN) {
        $request = $ret["request"];
        $tpl = get_markup_template('dfrn_request.tpl');
    } else {
        $request = $a->get_baseurl() . "/follow";
        $tpl = get_markup_template('auto_request.tpl');
    }
    $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
    if (!$r) {
        notice(t('Permission denied.') . EOL);
        goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    $myaddr = $r[0]["url"];
    // Makes the connection request for friendica contacts easier
    $_SESSION["fastlane"] = $ret["url"];
    $header = $ret["name"];
    if ($ret["addr"] != "") {
        $header .= " <" . $ret["addr"] . ">";
    }
    $header .= " (" . network_to_name($ret['network']) . ")";
    $o = replace_macros($tpl, array('$header' => htmlentities($header), '$photo' => $ret["photo"], '$desc' => "", '$pls_answer' => t('Please answer the following:'), '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'), $ret["name"]), false, '', array(t('No'), t('Yes'))), '$add_note' => t('Add a personal note:'), '$page_desc' => "", '$friendica' => "", '$statusnet' => "", '$diaspora' => "", '$diasnote' => "", '$your_address' => t('Your Identity Address:'), '$invite_desc' => "", '$emailnet' => "", '$submit' => t('Submit Request'), '$cancel' => t('Cancel'), '$nickname' => "", '$name' => $ret["name"], '$url' => $ret["url"], '$myaddr' => $myaddr, '$request' => $request));
    return $o;
}
Example #5
0
function viewcontacts_content(&$a)
{
    require_once "mod/proxy.php";
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (!count($a->profile) || $a->profile['hide-friends']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o = "";
    // tabs
    $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']);
    $r = q("SELECT COUNT(*) AS `total` FROM `contact`\n\t\tWHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0\n\t\t\tAND `network` IN ('%s', '%s', '%s')", intval($a->profile['uid']), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    $r = q("SELECT * FROM `contact`\n\t\tWHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0\n\t\t\tAND `network` IN ('%s', '%s', '%s')\n\t\tORDER BY `name` ASC LIMIT %d, %d", intval($a->profile['uid']), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS), intval($a->pager['start']), intval($a->pager['itemspage']));
    if (!count($r)) {
        info(t('No contacts.') . EOL);
        return $o;
    }
    $contacts = array();
    foreach ($r as $rr) {
        if ($rr['self']) {
            continue;
        }
        $url = $rr['url'];
        // route DFRN profiles through the redirect
        $is_owner = local_user() && $a->profile['profile_uid'] == local_user() ? true : false;
        if ($is_owner && $rr['network'] === NETWORK_DFRN && $rr['rel']) {
            $url = 'redir/' . $rr['id'];
        } else {
            $url = zrl($url);
        }
        $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid']);
        $contacts[] = array('id' => $rr['id'], 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'photo_menu' => contact_photo_menu($rr), 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB), 'name' => htmlentities(substr($rr['name'], 0, 20)), 'username' => htmlentities($rr['name']), 'details' => $contact_details['location'], 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => $contact_details['community'] ? t('Forum') : '', 'url' => $url, 'sparkle' => '', 'itemurl' => $contact_details['addr'] != "" ? $contact_details['addr'] : $rr['url'], 'network' => network_to_name($rr['network'], $rr['url']));
    }
    $tpl = get_markup_template("viewcontact_template.tpl");
    $o .= replace_macros($tpl, array('$title' => t('Contacts'), '$contacts' => $contacts, '$paginate' => paginate($a)));
    return $o;
}
Example #6
0
function networks_widget($baseurl, $selected = '')
{
    $a = get_app();
    if (!local_user()) {
        return '';
    }
    $r = q("select distinct(network) from contact where uid = %d and self = 0", intval(local_user()));
    $nets = array();
    if (count($r)) {
        require_once 'include/contact_selectors.php';
        foreach ($r as $rr) {
            if ($rr['network']) {
                $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => $selected == $rr['network'] ? 'selected' : '');
            }
        }
    }
    if (count($nets) < 2) {
        return '';
    }
    return replace_macros(get_markup_template('nets.tpl'), array('$title' => t('Networks'), '$desc' => '', '$sel_all' => $selected == '' ? 'selected' : '', '$all' => t('All Networks'), '$nets' => $nets, '$base' => $baseurl));
}
Example #7
0
function nogroup_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return '';
    }
    require_once 'include/Contact.php';
    $r = contacts_not_grouped(local_user());
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    $r = contacts_not_grouped(local_user(), $a->pager['start'], $a->pager['itemspage']);
    if (count($r)) {
        foreach ($r as $rr) {
            $contacts[] = array('img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'edit_hover' => t('Edit contact'), 'photo_menu' => contact_photo_menu($rr), 'id' => $rr['id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, 'thumb' => $rr['thumb'], 'name' => $rr['name'], 'username' => $rr['name'], 'sparkle' => $sparkle, 'itemurl' => $rr['url'], 'url' => $url, 'network' => network_to_name($rr['network']));
        }
    }
    $tpl = get_markup_template("nogroup-template.tpl");
    $o .= replace_macros($tpl, array('$header' => t('Contacts who are not members of a group'), '$contacts' => $contacts, '$paginate' => paginate($a)));
    return $o;
}
Example #8
0
function viewcontacts_content(&$a)
{
    require_once "mod/proxy.php";
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (!count($a->profile) || $a->profile['hide-friends']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $r = q("SELECT COUNT(*) as `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ", intval($a->profile['uid']));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY `name` ASC LIMIT %d , %d ", intval($a->profile['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
    if (!count($r)) {
        info(t('No contacts.') . EOL);
        return $o;
    }
    $contacts = array();
    foreach ($r as $rr) {
        if ($rr['self']) {
            continue;
        }
        $url = $rr['url'];
        // route DFRN profiles through the redirect
        $is_owner = local_user() && $a->profile['profile_uid'] == local_user() ? true : false;
        if ($is_owner && $rr['network'] === NETWORK_DFRN && $rr['rel']) {
            $url = 'redir/' . $rr['id'];
        } else {
            $url = zrl($url);
        }
        $contacts[] = array('id' => $rr['id'], 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'thumb' => proxy_url($rr['thumb']), 'name' => substr($rr['name'], 0, 20), 'username' => $rr['name'], 'url' => $url, 'sparkle' => '', 'itemurl' => $rr['url'], 'network' => network_to_name($rr['network'], $rr['url']));
    }
    $tpl = get_markup_template("viewcontact_template.tpl");
    $o .= replace_macros($tpl, array('$title' => t('View Contacts'), '$contacts' => $contacts, '$paginate' => paginate($a)));
    return $o;
}
Example #9
0
function contacts_content(&$a)
{
    $sort_type = 0;
    $o = '';
    nav_set_selected('contacts');
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc == 3) {
        $contact_id = intval($a->argv[1]);
        if (!$contact_id) {
            return;
        }
        $cmd = $a->argv[2];
        $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1", intval($contact_id), intval(local_user()));
        if (!count($orig_record)) {
            notice(t('Could not access contact record.') . EOL);
            goaway($a->get_baseurl() . '/contacts');
            return;
            // NOTREACHED
        }
        if ($cmd === 'update') {
            // pull feed and consume it, which should subscribe to the hub.
            proc_run('php', "include/poller.php", "{$contact_id}");
            goaway($a->get_baseurl() . '/contacts/' . $contact_id);
            // NOTREACHED
        }
        if ($cmd === 'block') {
            $blocked = $orig_record[0]['blocked'] ? 0 : 1;
            $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($blocked), intval($contact_id), intval(local_user()));
            if ($r) {
                //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
                info(($blocked ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL);
            }
            goaway($a->get_baseurl() . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'ignore') {
            $readonly = $orig_record[0]['readonly'] ? 0 : 1;
            $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($readonly), intval($contact_id), intval(local_user()));
            if ($r) {
                info(($readonly ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL);
            }
            goaway($a->get_baseurl() . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'drop') {
            // create an unfollow slap
            if ($orig_record[0]['network'] === NETWORK_OSTATUS) {
                $tpl = get_markup_template('follow_slap.tpl');
                $slap = replace_macros($tpl, array('$name' => $a->user['username'], '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'], '$photo' => $a->contact['photo'], '$thumb' => $a->contact['thumb'], '$published' => datetime_convert('UTC', 'UTC', 'now', ATOM_TIME), '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(), '$title' => '', '$type' => 'text', '$content' => t('stopped following'), '$nick' => $a->user['nickname'], '$verb' => 'http://ostatus.org/schema/1.0/unfollow', '$ostat_follow' => ''));
                if (x($orig_record[0], 'notify') && strlen($orig_record[0]['notify'])) {
                    require_once 'include/salmon.php';
                    slapper($a->user, $orig_record[0]['notify'], $slap);
                }
            } elseif ($orig_record[0]['network'] === NETWORK_DIASPORA) {
                require_once 'include/diaspora.php';
                diaspora_unshare($a->user, $orig_record[0]);
            } elseif ($orig_record[0]['network'] === NETWORK_DFRN) {
                require_once 'include/items.php';
                dfrn_deliver($a->user, $orig_record[0], 'placeholder', 1);
            }
            contact_remove($orig_record[0]['id']);
            info(t('Contact has been removed.') . EOL);
            if (x($_SESSION, 'return_url')) {
                goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
            } else {
                goaway($a->get_baseurl() . '/contacts');
            }
            return;
            // NOTREACHED
        }
    }
    if (x($a->data, 'contact') && is_array($a->data['contact'])) {
        $contact_id = $a->data['contact']['id'];
        $contact = $a->data['contact'];
        $tpl = get_markup_template('contact_head.tpl');
        $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
        require_once 'include/contact_selectors.php';
        $tpl = get_markup_template("contact_edit.tpl");
        switch ($contact['rel']) {
            case CONTACT_IS_FRIEND:
                $dir_icon = 'images/lrarrow.gif';
                $relation_text = t('You are mutual friends with %s');
                break;
            case CONTACT_IS_FOLLOWER:
                $dir_icon = 'images/larrow.gif';
                $relation_text = t('You are sharing with %s');
                break;
            case CONTACT_IS_SHARING:
                $dir_icon = 'images/rarrow.gif';
                $relation_text = t('%s is sharing with you');
                break;
            default:
                break;
        }
        $relation_text = sprintf($relation_text, $contact['name']);
        if ($contact['network'] === NETWORK_DFRN && $contact['rel']) {
            $url = "redir/{$contact['id']}";
            $sparkle = ' class="sparkle" ';
        } else {
            $url = $contact['url'];
            $sparkle = '';
        }
        $insecure = t('Private communications are not available for this contact.');
        $last_update = $contact['last-update'] == '0000-00-00 00:00:00' ? t('Never') : datetime_convert('UTC', date_default_timezone_get(), $contact['last-update'], 'D, j M Y, g:i A');
        if ($contact['last-update'] !== '0000-00-00 00:00:00') {
            $last_update .= ' ' . ($contact['last-update'] == $contact['success_update'] ? t("(Update was successful)") : t("(Update was not successful)"));
        }
        $lblsuggest = $contact['network'] === NETWORK_DFRN ? t('Suggest friends') : '';
        $poll_enabled = $contact['network'] !== NETWORK_DIASPORA ? true : false;
        $nettype = sprintf(t('Network type: %s'), network_to_name($contact['network']));
        $common = count_common_friends(local_user(), $contact['id']);
        $common_text = $common ? sprintf(tt('%d contact in common', '%d contacts in common', $common), $common) : '';
        $polling = $contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED ? 'polling' : '';
        $x = count_all_friends(local_user(), $contact['id']);
        $all_friends = $x ? t('View all contacts') : '';
        // tabs
        $tabs = array(array('label' => $contact['blocked'] ? t('Unblock') : t('Block'), 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block', 'sel' => ''), array('label' => $contact['readonly'] ? t('Unignore') : t('Ignore'), 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore', 'sel' => ''), array('label' => t('Repair'), 'url' => $a->get_baseurl() . '/crepair/' . $contact_id, 'sel' => ''));
        $tab_tpl = get_markup_template('common_tabs.tpl');
        $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
        $o .= replace_macros($tpl, array('$header' => t('Contact Editor'), '$tab_str' => $tab_str, '$submit' => t('Submit'), '$lbl_vis1' => t('Profile Visibility'), '$lbl_vis2' => sprintf(t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']), '$lbl_info1' => t('Contact Information / Notes'), '$infedit' => t('Edit contact notes'), '$common_text' => $common_text, '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'], '$all_friends' => $all_friends, '$relation_text' => $relation_text, '$visit' => sprintf(t('Visit %s\'s profile [%s]'), $contact['name'], $contact['url']), '$blockunblock' => t('Block/Unblock contact'), '$ignorecont' => t('Ignore contact'), '$lblcrepair' => t("Repair URL settings"), '$lblrecent' => t('View conversations'), '$lblsuggest' => $lblsuggest, '$delete' => t('Delete contact'), '$nettype' => $nettype, '$poll_interval' => contact_poll_interval($contact['priority'], !$poll_enabled), '$poll_enabled' => $poll_enabled, '$lastupdtext' => t('Last update:'), '$updpub' => t('Update public posts'), '$last_update' => $last_update, '$udnow' => t('Update now'), '$profile_select' => contact_profile_assign($contact['profile-id'], $contact['network'] !== NETWORK_DFRN ? true : false), '$contact_id' => $contact['id'], '$block_text' => $contact['blocked'] ? t('Unblock') : t('Block'), '$ignore_text' => $contact['readonly'] ? t('Unignore') : t('Ignore'), '$insecure' => $contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA ? $insecure : '', '$info' => $contact['info'], '$blocked' => $contact['blocked'] ? t('Currently blocked') : '', '$ignored' => $contact['readonly'] ? t('Currently ignored') : '', '$hidden' => array('hidden', t('Hide this contact from others'), $contact['hidden'] == 1, t('Replies/likes to your public posts <strong>may</strong> still be visible')), '$photo' => $contact['photo'], '$name' => $contact['name'], '$dir_icon' => $dir_icon, '$alt_text' => $alt_text, '$sparkle' => $sparkle, '$url' => $url));
        $arr = array('contact' => $contact, 'output' => $o);
        call_hooks('contact_edit', $arr);
        return $arr['output'];
    }
    $blocked = false;
    $hidden = false;
    $ignored = false;
    $all = false;
    $_SESSION['return_url'] = $a->query_string;
    if ($a->argc == 2 && $a->argv[1] === 'all') {
        $sql_extra = '';
        $all = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'blocked') {
        $sql_extra = " AND `blocked` = 1 ";
        $blocked = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'hidden') {
        $sql_extra = " AND `hidden` = 1 ";
        $hidden = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'ignored') {
        $sql_extra = " AND `readonly` = 1 ";
        $ignored = true;
    } else {
        $sql_extra = " AND `blocked` = 0 ";
    }
    $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
    $nets = x($_GET, 'nets') ? notags(trim($_GET['nets'])) : '';
    $tabs = array(array('label' => t('All Contacts'), 'url' => $a->get_baseurl() . '/contacts/all', 'sel' => $all ? 'active' : ''), array('label' => t('Unblocked Contacts'), 'url' => $a->get_baseurl() . '/contacts', 'sel' => !$all && !$blocked && !$hidden && !$search && !$nets && !$ignored ? 'active' : ''), array('label' => t('Blocked Contacts'), 'url' => $a->get_baseurl() . '/contacts/blocked', 'sel' => $blocked ? 'active' : ''), array('label' => t('Ignored Contacts'), 'url' => $a->get_baseurl() . '/contacts/ignored', 'sel' => $ignored ? 'active' : ''), array('label' => t('Hidden Contacts'), 'url' => $a->get_baseurl() . '/contacts/hidden', 'sel' => $hidden ? 'active' : ''));
    $tab_tpl = get_markup_template('common_tabs.tpl');
    $t = replace_macros($tab_tpl, array('$tabs' => $tabs));
    if ($search) {
        $search_hdr = $search;
        $search = dbesc($search . '*');
    }
    $sql_extra .= strlen($search) ? " AND MATCH `name` AGAINST ('{$search}' IN BOOLEAN MODE) " : "";
    if ($nets) {
        $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
    }
    $sql_extra2 = $sort_type > 0 && $sort_type <= CONTACT_IS_FRIEND ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '';
    $r = q("SELECT COUNT(*) AS `total` FROM `contact` \n\t\tWHERE `uid` = %d AND `pending` = 0 {$sql_extra} {$sql_extra2} ", intval($_SESSION['uid']));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
    }
    $tpl = get_markup_template("contacts-top.tpl");
    $o .= replace_macros($tpl, array('$header' => t('Contacts') . ($nets ? ' - ' . network_to_name($nets) : ''), '$tabs' => $t, '$total' => $r[0]['total'], '$search' => $search_hdr, '$desc' => t('Search your contacts'), '$finding' => strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "", '$submit' => t('Find'), '$cmd' => $a->cmd));
    $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 {$sql_extra} {$sql_extra2} ORDER BY `name` ASC LIMIT %d , %d ", intval($_SESSION['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
    if (count($r)) {
        $tpl = get_markup_template("contact_template.tpl");
        foreach ($r as $rr) {
            if ($rr['self']) {
                continue;
            }
            switch ($rr['rel']) {
                case CONTACT_IS_FRIEND:
                    $dir_icon = 'images/lrarrow.gif';
                    $alt_text = t('Mutual Friendship');
                    break;
                case CONTACT_IS_FOLLOWER:
                    $dir_icon = 'images/larrow.gif';
                    $alt_text = t('is a fan of yours');
                    break;
                case CONTACT_IS_SHARING:
                    $dir_icon = 'images/rarrow.gif';
                    $alt_text = t('you are a fan of');
                    break;
                default:
                    break;
            }
            if ($rr['network'] === 'dfrn' && $rr['rel']) {
                $url = "redir/{$rr['id']}";
                $sparkle = ' class="sparkle" ';
            } else {
                $url = $rr['url'];
                $sparkle = '';
            }
            $o .= replace_macros($tpl, array('$img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), '$edit_hover' => t('Edit contact'), '$contact_photo_menu' => contact_photo_menu($rr), '$id' => $rr['id'], '$alt_text' => $alt_text, '$dir_icon' => $dir_icon, '$thumb' => $rr['thumb'], '$name' => $rr['name'], '$username' => $rr['name'], '$sparkle' => $sparkle, '$url' => $url));
        }
        $o .= '<div id="contact-edit-end"></div>';
    }
    $o .= paginate($a);
    return $o;
}
Example #10
0
 /**
  * Get data in a form usable by a conversation template
  *
  * Returns:
  *      _ The data requested on success
  *      _ false on failure
  */
 public function get_template_data($alike, $dlike, $thread_level = 1)
 {
     require_once "mod/proxy.php";
     $result = array();
     $a = $this->get_app();
     $item = $this->get_data();
     $edited = false;
     if (strcmp($item['created'], $item['edited']) != 0) {
         $edited = array('label' => t('This entry was edited'), 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), 'relative' => relative_date($item['edited']));
     }
     $commentww = '';
     $sparkle = '';
     $buttons = '';
     $dropping = false;
     $star = false;
     $ignore = false;
     $isstarred = "unstarred";
     $indent = '';
     $shiny = '';
     $osparkle = '';
     $total_children = $this->count_descendants();
     $conv = $this->get_conversation();
     $lock = $item['private'] == 1 || $item['uid'] == local_user() && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false;
     $shareable = $conv->get_profile_owner() == local_user() && $item['private'] != 1 ? true : false;
     if (local_user() && link_compare($a->contact['url'], $item['author-link'])) {
         $edpost = array($a->get_baseurl($ssl_state) . "/editpost/" . $item['id'], t("Edit"));
     } else {
         $edpost = false;
     }
     if ($this->get_data_value('uid') == local_user() || $this->is_visiting()) {
         $dropping = true;
     }
     $drop = array('dropping' => $dropping, 'pagedrop' => feature_enabled($conv->get_profile_owner(), 'multi_delete') ? $item['pagedrop'] : '', 'select' => t('Select'), 'delete' => t('Delete'));
     $filer = $conv->get_profile_owner() == local_user() ? t("save to folder") : false;
     $diff_author = link_compare($item['url'], $item['author-link']) ? false : true;
     $profile_name = strlen($item['author-name']) && $diff_author ? $item['author-name'] : $item['name'];
     if ($item['author-link'] && !$item['author-name']) {
         $profile_name = $item['author-link'];
     }
     $sp = false;
     $profile_link = best_link_url($item, $sp);
     if ($profile_link === 'mailbox') {
         $profile_link = '';
     }
     if ($sp) {
         $sparkle = ' sparkle';
     } else {
         $profile_link = zrl($profile_link);
     }
     $normalised = normalise_link(strlen($item['author-link']) ? $item['author-link'] : $item['url']);
     if ($normalised != 'mailbox' && x($a->contacts, $normalised)) {
         $profile_avatar = $a->contacts[$normalised]['thumb'];
     } else {
         $profile_avatar = strlen($item['author-avatar']) && $diff_author ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_data_value('thumb'));
     }
     $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
     call_hooks('render_location', $locate);
     $location = strlen($locate['html']) ? $locate['html'] : render_location_google($locate);
     $searchpath = $a->get_baseurl() . "/search?tag=";
     $tags = array();
     $hashtags = array();
     $mentions = array();
     /*foreach(explode(',',$item['tag']) as $tag){
     			$tag = trim($tag);
     			if ($tag!="") {
     				$t = bbcode($tag);
     				$tags[] = $t;
     				if($t[0] == '#')
     					$hashtags[] = $t;
     				elseif($t[0] == '@')
     					$mentions[] = $t;
     			}
     		}*/
     $like = x($alike, $item['uri']) ? format_like($alike[$item['uri']], $alike[$item['uri'] . '-l'], 'like', $item['uri']) : '';
     $dislike = x($dlike, $item['uri']) ? format_like($dlike[$item['uri']], $dlike[$item['uri'] . '-l'], 'dislike', $item['uri']) : '';
     /*
      * We should avoid doing this all the time, but it depends on the conversation mode
      * And the conv mode may change when we change the conv, or it changes its mode
      * Maybe we should establish a way to be notified about conversation changes
      */
     $this->check_wall_to_wall();
     if ($this->is_wall_to_wall() && $this->get_owner_url() == $this->get_redirect_url()) {
         $osparkle = ' sparkle';
     }
     if ($this->is_toplevel()) {
         if ($conv->get_profile_owner() == local_user()) {
             $isstarred = $item['starred'] ? "starred" : "unstarred";
             $star = array('do' => t("add star"), 'undo' => t("remove star"), 'toggle' => t("toggle star status"), 'classdo' => $item['starred'] ? "hidden" : "", 'classundo' => $item['starred'] ? "" : "hidden", 'starred' => t('starred'));
             $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", intval($item['uid']), intval($item['id']));
             if (count($r)) {
                 $ignore = array('do' => t("ignore thread"), 'undo' => t("unignore thread"), 'toggle' => t("toggle ignore status"), 'classdo' => $r[0]['ignored'] ? "hidden" : "", 'classundo' => $r[0]['ignored'] ? "" : "hidden", 'ignored' => t('ignored'));
             }
             $tagger = '';
             if (feature_enabled($conv->get_profile_owner(), 'commtag')) {
                 $tagger = array('add' => t("add tag"), 'class' => "");
             }
         }
     } else {
         $indent = 'comment';
     }
     if ($conv->is_writable()) {
         $buttons = array('like' => array(t("I like this (toggle)"), t("like")), 'dislike' => feature_enabled($conv->get_profile_owner(), 'dislike') ? array(t("I don't like this (toggle)"), t("dislike")) : '');
         if ($shareable) {
             $buttons['share'] = array(t('Share this'), t('share'));
         }
     }
     if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
         $shiny = 'shiny';
     }
     localize_item($item);
     if ($item["postopts"] and !get_config("system", "suppress_language")) {
         //$langdata = explode(";", $item["postopts"]);
         //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
         $langstr = "";
         if (substr($item["postopts"], 0, 5) == "lang=") {
             $postopts = substr($item["postopts"], 5);
             $languages = explode(":", $postopts);
             if (sizeof($languages) == 1) {
                 $languages = array();
                 $languages[] = $postopts;
             }
             foreach ($languages as $language) {
                 $langdata = explode(";", $language);
                 if ($langstr != "") {
                     $langstr .= ", ";
                 }
                 //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
                 $langstr .= round($langdata[1] * 100, 1) . "% " . $langdata[0];
             }
         }
     }
     $body = prepare_body($item, true);
     list($categories, $folders) = get_cats_and_terms($item);
     if ($a->theme['template_engine'] === 'internal') {
         $body_e = template_escape($body);
         $text_e = strip_tags(template_escape($body));
         $name_e = template_escape($profile_name);
         $title_e = template_escape($item['title']);
         $location_e = template_escape($location);
         $owner_name_e = template_escape($this->get_owner_name());
     } else {
         $body_e = $body;
         $text_e = strip_tags($body);
         $name_e = $profile_name;
         $title_e = $item['title'];
         $location_e = $location;
         $owner_name_e = $this->get_owner_name();
     }
     // Disable features that aren't available in several networks
     if ($item["item_network"] != "dfrn" and isset($buttons["dislike"])) {
         unset($buttons["dislike"]);
         $tagger = '';
     }
     if ($item["item_network"] == "feed" and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     if ($item["item_network"] == "mail" and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     if ($item["item_network"] == "dspr" and $indent == 'comment' and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     // Facebook can like comments - but it isn't programmed in the connector yet.
     if ($item["item_network"] == "face" and $indent == 'comment' and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     $tmp_item = array('template' => $this->get_template(), 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), 'tags' => $item['tags'], 'hashtags' => $item['hashtags'], 'mentions' => $item['mentions'], 'txt_cats' => t('Categories:'), 'txt_folders' => t('Filed under:'), 'has_cats' => count($categories) ? 'true' : '', 'has_folders' => count($folders) ? 'true' : '', 'categories' => $categories, 'folders' => $folders, 'body' => $body_e, 'text' => $text_e, 'id' => $this->get_id(), 'guid' => $item['guid'], 'linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['author-link']) ? $item['author-link'] : $item['url']), 'olinktitle' => sprintf(t('View %s\'s profile @ %s'), $this->get_owner_name(), strlen($item['owner-link']) ? $item['owner-link'] : $item['url']), 'to' => t('to'), 'via' => t('via'), 'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $name_e, 'thumb' => proxy_url($profile_avatar), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title_e, 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'ago' => $item['app'] ? sprintf(t('%s from %s'), relative_date($item['created']), $item['app']) : relative_date($item['created']), 'app' => $item['app'], 'created' => relative_date($item['created']), 'lock' => $lock, 'location' => $location_e, 'indent' => $indent, 'shiny' => $shiny, 'owner_url' => $this->get_owner_url(), 'owner_photo' => proxy_url($this->get_owner_photo()), 'owner_name' => $owner_name_e, 'plink' => get_plink($item), 'edpost' => feature_enabled($conv->get_profile_owner(), 'edit_posts') ? $edpost : '', 'isstarred' => $isstarred, 'star' => feature_enabled($conv->get_profile_owner(), 'star_posts') ? $star : '', 'ignore' => feature_enabled($conv->get_profile_owner(), 'ignore_posts') ? $ignore : '', 'tagger' => $tagger, 'filer' => feature_enabled($conv->get_profile_owner(), 'filing') ? $filer : '', 'drop' => $drop, 'vote' => $buttons, 'like' => $like, 'dislike' => $dislike, 'switchcomment' => t('Comment'), 'comment' => $this->get_comment_box($indent), 'previewing' => $conv->is_preview() ? ' preview ' : '', 'wait' => t('Please wait'), 'thread_level' => $thread_level, 'postopts' => $langstr, 'edited' => $edited, 'network' => $item["item_network"], 'network_name' => network_to_name($item['item_network']));
     $arr = array('item' => $item, 'output' => $tmp_item);
     call_hooks('display_item', $arr);
     $result = $arr['output'];
     $result['children'] = array();
     $children = $this->get_children();
     $nb_children = count($children);
     if ($nb_children > 0) {
         foreach ($children as $child) {
             $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1);
         }
         // Collapse
         if ($nb_children > 2 || $thread_level > 1) {
             $result['children'][0]['comment_firstcollapsed'] = true;
             $result['children'][0]['num_comments'] = sprintf(tt('%d comment', '%d comments', $total_children), $total_children);
             $result['children'][0]['hidden_comments_num'] = $total_children;
             $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
             $result['children'][0]['hide_text'] = t('show more');
             if ($thread_level > 1) {
                 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
             } else {
                 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
             }
         }
     }
     if ($this->is_toplevel()) {
         $result['total_comments_num'] = "{$total_children}";
         $result['total_comments_text'] = tt('comment', 'comments', $total_children);
     }
     $result['private'] = $item['private'];
     $result['toplevel'] = $this->is_toplevel() ? 'toplevel_item' : '';
     if ($this->is_threaded()) {
         $result['flatten'] = false;
         $result['threaded'] = true;
     } else {
         $result['flatten'] = true;
         $result['threaded'] = false;
     }
     return $result;
 }
Example #11
0
function dirfind_content(&$a, $prefix = "")
{
    $community = false;
    $discover_user = false;
    $local = get_config('system', 'poco_local_search');
    $search = $prefix . notags(trim($_REQUEST['search']));
    if (strpos($search, '@') === 0) {
        $search = substr($search, 1);
        if (valid_email($search) and validate_email($search) or substr(normalise_link($search), 0, 7) == "http://") {
            $user_data = probe_url($search);
            $discover_user = in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA));
        }
    }
    if (strpos($search, '!') === 0) {
        $search = substr($search, 1);
        $community = true;
    }
    $o = '';
    if ($search) {
        if ($discover_user) {
            $j = new stdClass();
            $j->total = 1;
            $j->items_page = 1;
            $j->page = $a->pager['page'];
            $objresult = new stdClass();
            $objresult->cid = 0;
            $objresult->name = $user_data["name"];
            $objresult->addr = $user_data["addr"];
            $objresult->url = $user_data["url"];
            $objresult->photo = $user_data["photo"];
            $objresult->tags = "";
            $objresult->network = $user_data["network"];
            $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", dbesc(normalise_link($user_data["url"])), intval(local_user()));
            if ($contact) {
                $objresult->cid = $contact[0]["id"];
            }
            $j->results[] = $objresult;
            poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"], "", "", "", "", "", datetime_convert(), 0);
        } elseif ($local) {
            if ($community) {
                $extra_sql = " AND `community`";
            } else {
                $extra_sql = "";
            }
            $perpage = 80;
            $startrec = $a->pager['page'] * $perpage - $perpage;
            if (get_config('system', 'diaspora_enabled')) {
                $diaspora = NETWORK_DIASPORA;
            } else {
                $diaspora = NETWORK_DFRN;
            }
            if (!get_config('system', 'ostatus_disabled')) {
                $ostatus = NETWORK_OSTATUS;
            } else {
                $ostatus = NETWORK_DFRN;
            }
            $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND\n\t\t\t\t\t(`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR\n\t\t\t\t\t\t`about` REGEXP '%s' OR `keywords` REGEXP '%s')" . $extra_sql, dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)));
            $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`\n\t\t\t\t\tFROM `gcontact`\n\t\t\t\t\tLEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`\n\t\t\t\t\t\tAND `contact`.`uid` = %d AND NOT `contact`.`blocked`\n\t\t\t\t\t\tAND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')\n\t\t\t\t\tWHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND\n\t\t\t\t\t((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND\n\t\t\t\t\t(`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR\n\t\t\t\t\t\t`gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') {$extra_sql}\n\t\t\t\t\t\tGROUP BY `gcontact`.`nurl`\n\t\t\t\t\t\tORDER BY `gcontact`.`updated` DESC LIMIT %d, %d", intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND), dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), intval($startrec), intval($perpage));
            $j = new stdClass();
            $j->total = $count[0]["total"];
            $j->items_page = $perpage;
            $j->page = $a->pager['page'];
            foreach ($results as $result) {
                if (poco_alternate_ostatus_url($result["url"])) {
                    continue;
                }
                if ($result["name"] == "") {
                    $urlparts = parse_url($result["url"]);
                    $result["name"] = end(explode("/", $urlparts["path"]));
                }
                $objresult = new stdClass();
                $objresult->cid = $result["cid"];
                $objresult->name = $result["name"];
                $objresult->addr = $result["addr"];
                $objresult->url = $result["url"];
                $objresult->photo = $result["photo"];
                $objresult->tags = $result["keywords"];
                $objresult->network = $result["network"];
                $j->results[] = $objresult;
            }
            // Add found profiles from the global directory to the local directory
            proc_run('php', 'include/discover_poco.php', "dirsearch", urlencode($search));
        } else {
            $p = $a->pager['page'] != 1 ? '&p=' . $a->pager['page'] : '';
            if (strlen(get_config('system', 'directory'))) {
                $x = fetch_url(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search));
            }
            $j = json_decode($x);
        }
        if ($j->total) {
            $a->set_pager_total($j->total);
            $a->set_pager_itemspage($j->items_page);
        }
        if (count($j->results)) {
            $id = 0;
            foreach ($j->results as $jj) {
                $alt_text = "";
                $contact_details = get_contact_details_by_url($jj->url, local_user());
                $itemurl = $contact_details["addr"] != "" ? $contact_details["addr"] : $jj->url;
                // If We already know this contact then don't show the "connect" button
                if ($jj->cid > 0) {
                    $connlnk = "";
                    $conntxt = "";
                    $contact = q("SELECT * FROM `contact` WHERE `id` = %d", intval($jj->cid));
                    if ($contact) {
                        $photo_menu = contact_photo_menu($contact[0]);
                        $details = _contact_detail_for_template($contact[0]);
                        $alt_text = $details['alt_text'];
                    } else {
                        $photo_menu = array();
                    }
                } else {
                    $connlnk = $a->get_baseurl() . '/follow/?url=' . ($jj->connect ? $jj->connect : $jj->url);
                    $conntxt = t('Connect');
                    $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
                    $photo_menu[] = array(t("Connect/Follow"), $connlnk);
                }
                $jj->photo = str_replace("http:///photo/", get_server() . "/photo/", $jj->photo);
                $entry = array('alt_text' => $alt_text, 'url' => zrl($jj->url), 'itemurl' => $itemurl, 'name' => htmlentities($jj->name), 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB), 'img_hover' => $jj->tags, 'conntxt' => $conntxt, 'connlnk' => $connlnk, 'photo_menu' => $photo_menu, 'details' => $contact_details['location'], 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => $contact_details['community'] ? t('Forum') : '', 'network' => network_to_name($jj->network, $jj->url), 'id' => ++$id);
                $entries[] = $entry;
            }
            $tpl = get_markup_template('viewcontact_template.tpl');
            $o .= replace_macros($tpl, array('title' => sprintf(t('People Search - %s'), $search), '$contacts' => $entries, '$paginate' => paginate($a)));
        } else {
            info(t('No matches') . EOL);
        }
    }
    return $o;
}
Example #12
0
function diaspora_send_relay($item, $owner, $contact, $public_batch = false)
{
    $a = get_app();
    $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3);
    $theiraddr = $contact['addr'];
    $p = q("select guid from item where parent = %d limit 1", $item['parent']);
    if (count($p)) {
        $parent_guid = $p[0]['guid'];
    } else {
        return;
    }
    if ($item['verb'] === ACTIVITY_LIKE) {
        $tpl = get_markup_template('diaspora_like_relay.tpl');
        $like = true;
        $target_type = 'Post';
        $positive = $item['deleted'] ? 'false' : 'true';
    } else {
        $tpl = get_markup_template('diaspora_comment_relay.tpl');
        $like = false;
    }
    $body = $item['body'];
    $text = html_entity_decode(bb2diaspora($body));
    // fetch the original signature	if somebody sent the post to us to relay
    // If we are relaying for a reply originating on our own account, there wasn't a 'send to relay'
    // action. It wasn't needed. In that case create the original signature and the
    // owner (parent author) signature
    // comments from other networks will be relayed under our name, with a brief
    // preamble to describe what's happening and noting the real author
    $r = q("select * from sign where iid = %d limit 1", intval($item['id']));
    if (count($r)) {
        $orig_sign = $r[0];
        $signed_text = $orig_sign['signed_text'];
        $authorsig = $orig_sign['signature'];
        $handle = $orig_sign['signer'];
    } else {
        $itemcontact = q("select * from contact where `id` = %d limit 1", intval($item['contact-id']));
        if (count($itemcontact)) {
            if (!$itemcontact[0]['self']) {
                $prefix = sprintf(t('[Relayed] Comment authored by %s from network %s'), '[' . $item['author-name'] . ']' . '(' . $item['author-link'] . ')', network_to_name($itemcontact['network'])) . "\n";
                $body = $prefix . $body;
            }
        } else {
            if ($like) {
                $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr;
            } else {
                $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr;
            }
            $authorsig = base64_encode(rsa_sign($signed_text, $owner['uprvkey'], 'sha256'));
            q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($item['id']), dbesc($signed_text), dbesc(base64_encode($authorsig)), dbesc($myaddr));
            $handle = $myaddr;
        }
    }
    // sign it
    $parentauthorsig = base64_encode(rsa_sign($signed_text, $owner['uprvkey'], 'sha256'));
    $msg = replace_macros($tpl, array('$guid' => xmlify($item['guid']), '$parent_guid' => xmlify($parent_guid), '$target_type' => xmlify($target_type), '$authorsig' => xmlify($orig_sign['signature']), '$parentsig' => xmlify($parentauthorsig), '$body' => xmlify($text), '$positive' => xmlify($positive), '$handle' => xmlify($handle)));
    logger('diaspora_relay_comment: base message: ' . $msg, LOGGER_DATA);
    $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch)));
    return diaspora_transmit($owner, $contact, $slap, $public_batch);
}
Example #13
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) {
         require_once 'include/contact_selectors.php';
         if ($profile['url'] != "") {
             $profile['network_name'] = '<a href="' . $profile['url'] . '">' . network_to_name($profile['network']) . "</a>";
         } else {
             $profile['network_name'] = network_to_name($profile['network']);
         }
     } 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 (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());
     }
     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;
     if (($profile['hidewall'] || $block) && !local_user() && !remote_user()) {
         $location = $pdesc = $gender = $marital = $homepage = 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('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();
     }
     $p = array();
     foreach ($profile as $k => $v) {
         $k = str_replace('-', '_', $k);
         $p[$k] = $v;
     }
     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, '$wallmessage' => $wallmessage, '$location' => $location, '$gender' => $gender, '$pdesc' => $pdesc, '$marital' => $marital, '$homepage' => $homepage, '$network' => t('Network:'), '$diaspora' => $diaspora, '$contact_block' => $contact_block));
     $arr = array('profile' => &$profile, 'entry' => &$o);
     call_hooks('profile_sidebar', $arr);
     return $o;
 }
Example #14
0
function common_content(&$a)
{
    $o = '';
    $cmd = $a->argv[1];
    $uid = intval($a->argv[2]);
    $cid = intval($a->argv[3]);
    $zcid = 0;
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($cmd !== 'loc' && $cmd != 'rem') {
        return;
    }
    if (!$uid) {
        return;
    }
    if ($cmd === 'loc' && $cid) {
        $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($cid), intval($uid));
        $a->page['aside'] = "";
        profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"]));
    } else {
        $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid));
        $vcard_widget .= replace_macros(get_markup_template("vcard-widget.tpl"), array('$name' => htmlentities($c[0]['name']), '$photo' => $c[0]['photo'], 'url' => z_root() . '/contacts/' . $cid));
        if (!x($a->page, 'aside')) {
            $a->page['aside'] = '';
        }
        $a->page['aside'] .= $vcard_widget;
    }
    if (!count($c)) {
        return;
    }
    if (!$cid) {
        if (get_my_url()) {
            $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", dbesc(normalise_link(get_my_url())), intval($profile_uid));
            if (count($r)) {
                $cid = $r[0]['id'];
            } else {
                $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link(get_my_url())));
                if (count($r)) {
                    $zcid = $r[0]['id'];
                }
            }
        }
    }
    if ($cid == 0 && $zcid == 0) {
        return;
    }
    if ($cid) {
        $t = count_common_friends($uid, $cid);
    } else {
        $t = count_common_friends_zcid($uid, $zcid);
    }
    if (count($t)) {
        $a->set_pager_total($t);
    } else {
        notice(t('No contacts in common.') . EOL);
        return $o;
    }
    if ($cid) {
        $r = common_friends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
    } else {
        $r = common_friends_zcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
    }
    if (!count($r)) {
        return $o;
    }
    $id = 0;
    foreach ($r as $rr) {
        //get further details of the contact
        $contact_details = get_contact_details_by_url($rr['url'], $uid);
        // $rr[id] is needed to use contact_photo_menu()
        $rr[id] = $rr[cid];
        $photo_menu = '';
        $photo_menu = contact_photo_menu($rr);
        $entry = array('url' => $rr['url'], 'itemurl' => $contact_details['addr'] != "" ? $contact_details['addr'] : $rr['url'], 'name' => $rr['name'], 'thumb' => proxy_url($rr['photo'], false, PROXY_SIZE_THUMB), 'img_hover' => htmlentities($rr['name']), 'details' => $contact_details['location'], 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => $contact_details['community'] ? t('Forum') : '', 'network' => network_to_name($contact_details['network'], $contact_details['url']), 'photo_menu' => $photo_menu, 'id' => ++$id);
        $entries[] = $entry;
    }
    if ($cmd === 'loc' && $cid && $uid == local_user()) {
        $tab_str = contacts_tab($a, $cid, 4);
    } else {
        $title = t('Common Friends');
    }
    $tpl = get_markup_template('viewcontact_template.tpl');
    $o .= replace_macros($tpl, array('$title' => $title, '$tab_str' => $tab_str, '$contacts' => $entries, '$paginate' => paginate($a)));
    return $o;
}
Example #15
0
function _contact_detail_for_template($rr)
{
    switch ($rr['rel']) {
        case CONTACT_IS_FRIEND:
            $dir_icon = 'images/lrarrow.gif';
            $alt_text = t('Mutual Friendship');
            break;
        case CONTACT_IS_FOLLOWER:
            $dir_icon = 'images/larrow.gif';
            $alt_text = t('is a fan of yours');
            break;
        case CONTACT_IS_SHARING:
            $dir_icon = 'images/rarrow.gif';
            $alt_text = t('you are a fan of');
            break;
        default:
            break;
    }
    if ($rr['network'] === NETWORK_DFRN && $rr['rel']) {
        $url = "redir/{$rr['id']}";
        $sparkle = ' class="sparkle" ';
    } else {
        $url = $rr['url'];
        $sparkle = '';
    }
    return array('img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'edit_hover' => t('Edit contact'), 'photo_menu' => contact_photo_menu($rr), 'id' => $rr['id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, 'thumb' => proxy_url($rr['thumb']), 'name' => $rr['name'], 'username' => $rr['name'], 'sparkle' => $sparkle, 'itemurl' => $rr['url'], 'url' => $url, 'network' => network_to_name($rr['network']));
}
Example #16
0
function _contact_detail_for_template($rr)
{
    $community = '';
    switch ($rr['rel']) {
        case CONTACT_IS_FRIEND:
            $dir_icon = 'images/lrarrow.gif';
            $alt_text = t('Mutual Friendship');
            break;
        case CONTACT_IS_FOLLOWER:
            $dir_icon = 'images/larrow.gif';
            $alt_text = t('is a fan of yours');
            break;
        case CONTACT_IS_SHARING:
            $dir_icon = 'images/rarrow.gif';
            $alt_text = t('you are a fan of');
            break;
        default:
            break;
    }
    if ($rr['network'] === NETWORK_DFRN && $rr['rel']) {
        $url = "redir/{$rr['id']}";
        $sparkle = ' class="sparkle" ';
    } else {
        $url = $rr['url'];
        $sparkle = '';
    }
    //test if contact is a forum page
    if (isset($rr['forum']) or isset($rr['prv'])) {
        $community = ($rr['forum'] or $rr['prv']);
    }
    return array('img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'edit_hover' => t('Edit contact'), 'photo_menu' => contact_photo_menu($rr), 'id' => $rr['id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB), 'name' => htmlentities($rr['name']), 'username' => htmlentities($rr['name']), 'account_type' => $community ? t('Forum') : '', 'sparkle' => $sparkle, 'itemurl' => $rr['addr'] != "" ? $rr['addr'] : $rr['url'], 'url' => $url, 'network' => network_to_name($rr['network'], $rr['url']));
}
Example #17
0
function connections_content(&$a)
{
    $sort_type = 0;
    $o = '';
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return login();
    }
    $blocked = false;
    $hidden = false;
    $ignored = false;
    $archived = false;
    $unblocked = false;
    $pending = false;
    $unconnected = false;
    $all = false;
    if (!$_REQUEST['aj']) {
        $_SESSION['return_url'] = $a->query_string;
    }
    $search_flags = 0;
    $head = '';
    if (argc() == 2) {
        switch (argv(1)) {
            case 'blocked':
                $search_flags = ABOOK_FLAG_BLOCKED;
                $head = t('Blocked');
                $blocked = true;
                break;
            case 'ignored':
                $search_flags = ABOOK_FLAG_IGNORED;
                $head = t('Ignored');
                $ignored = true;
                break;
            case 'hidden':
                $search_flags = ABOOK_FLAG_HIDDEN;
                $head = t('Hidden');
                $hidden = true;
                break;
            case 'archived':
                $search_flags = ABOOK_FLAG_ARCHIVED;
                $head = t('Archived');
                $archived = true;
                break;
            case 'pending':
                $search_flags = ABOOK_FLAG_PENDING;
                $head = t('New');
                $pending = true;
                nav_set_selected('intros');
                break;
            case 'ifpending':
                $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", intval(local_channel()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF | ABOOK_FLAG_IGNORED), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
                if ($r && $r[0]['total']) {
                    $search_flags = ABOOK_FLAG_PENDING;
                    $head = t('New');
                    $pending = true;
                    nav_set_selected('intros');
                    $a->argv[1] = 'pending';
                } else {
                    $head = t('All');
                    $search_flags = 0;
                    $all = true;
                    $a->argc = 1;
                    unset($a->argv[1]);
                }
                nav_set_selected('intros');
                break;
                //			case 'unconnected':
                //				$search_flags = ABOOK_FLAG_UNCONNECTED;
                //				$head = t('Unconnected');
                //				$unconnected = true;
                //				break;
            //			case 'unconnected':
            //				$search_flags = ABOOK_FLAG_UNCONNECTED;
            //				$head = t('Unconnected');
            //				$unconnected = true;
            //				break;
            case 'all':
                $head = t('All');
            default:
                $search_flags = 0;
                $all = true;
                break;
        }
        $sql_extra = $search_flags ? " and ( abook_flags & " . $search_flags . " )>0 " : "";
        if (argv(1) === 'pending') {
            $sql_extra .= " and not ( abook_flags & " . ABOOK_FLAG_IGNORED . " )>0 ";
        }
    } else {
        $sql_extra = " and not ( abook_flags & " . ABOOK_FLAG_BLOCKED . " )>0 ";
        $unblocked = true;
    }
    $search = x($_REQUEST, 'search') ? notags(trim($_REQUEST['search'])) : '';
    $tabs = array(array('label' => t('Suggestions'), 'url' => z_root() . '/suggest', 'sel' => '', 'title' => t('Suggest new connections')), array('label' => t('New Connections'), 'url' => z_root() . '/connections/pending', 'sel' => $pending ? 'active' : '', 'title' => t('Show pending (new) connections')), array('label' => t('All Connections'), 'url' => z_root() . '/connections/all', 'sel' => $all ? 'active' : '', 'title' => t('Show all connections')), array('label' => t('Unblocked'), 'url' => z_root() . '/connections', 'sel' => $unblocked && !$search && !$nets ? 'active' : '', 'title' => t('Only show unblocked connections')), array('label' => t('Blocked'), 'url' => z_root() . '/connections/blocked', 'sel' => $blocked ? 'active' : '', 'title' => t('Only show blocked connections')), array('label' => t('Ignored'), 'url' => z_root() . '/connections/ignored', 'sel' => $ignored ? 'active' : '', 'title' => t('Only show ignored connections')), array('label' => t('Archived'), 'url' => z_root() . '/connections/archived', 'sel' => $archived ? 'active' : '', 'title' => t('Only show archived connections')), array('label' => t('Hidden'), 'url' => z_root() . '/connections/hidden', 'sel' => $hidden ? 'active' : '', 'title' => t('Only show hidden connections')));
    $tab_tpl = get_markup_template('common_tabs.tpl');
    $t = replace_macros($tab_tpl, array('$tabs' => $tabs));
    $searching = false;
    if ($search) {
        $search_hdr = $search;
        $search_txt = dbesc(protect_sprintf(preg_quote($search)));
        $searching = true;
    }
    $sql_extra .= $searching ? protect_sprintf(" AND xchan_name like '%{$search_txt}%' ") : "";
    if ($_REQUEST['gid']) {
        $sql_extra .= " and xchan_hash in ( select xchan from group_member where gid = " . intval($_REQUEST['gid']) . " and uid = " . intval(local_channel()) . " ) ";
    }
    $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash \n\t\twhere abook_channel = %d and not (abook_flags & %d)>0 and not (xchan_flags & %d )>0 {$sql_extra} {$sql_extra2} ", intval(local_channel()), intval(ABOOK_FLAG_SELF), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
    if ($r) {
        $a->set_pager_total($r[0]['total']);
        $total = $r[0]['total'];
    }
    $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash\n\t\tWHERE abook_channel = %d and not (abook_flags & %d)>0 and not ( xchan_flags & %d)>0 {$sql_extra} {$sql_extra2} ORDER BY xchan_name LIMIT %d OFFSET %d ", intval(local_channel()), intval(ABOOK_FLAG_SELF), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN), intval($a->pager['itemspage']), intval($a->pager['start']));
    $contacts = array();
    if (count($r)) {
        foreach ($r as $rr) {
            if ($rr['xchan_url']) {
                $contacts[] = array('img_hover' => sprintf(t('%1$s [%2$s]'), $rr['xchan_name'], $rr['xchan_url']), 'edit_hover' => t('Edit connection'), 'id' => $rr['abook_id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, 'thumb' => $rr['xchan_photo_m'], 'name' => $rr['xchan_name'], 'username' => $rr['xchan_name'], 'classes' => $rr['abook_flags'] & ABOOK_FLAG_ARCHIVED ? 'archived' : '', 'link' => z_root() . '/connedit/' . $rr['abook_id'], 'edit' => t('Edit'), 'url' => chanlink_url($rr['xchan_url']), 'network' => network_to_name($rr['network']));
            }
        }
    }
    if ($_REQUEST['aj']) {
        if ($contacts) {
            $o = replace_macros(get_markup_template('contactsajax.tpl'), array('$contacts' => $contacts, '$edit' => t('Edit')));
        } else {
            $o = '<div id="content-complete"></div>';
        }
        echo $o;
        killme();
    } else {
        $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
        $o .= replace_macros(get_markup_template('connections.tpl'), array('$header' => t('Connections') . ($head ? ' - ' . $head : ''), '$tabs' => $t, '$total' => $total, '$search' => $search_hdr, '$desc' => t('Search your connections'), '$finding' => $searching ? t('Finding: ') . "'" . $search . "'" : "", '$submit' => t('Find'), '$edit' => t('Edit'), '$cmd' => $a->cmd, '$contacts' => $contacts, '$paginate' => paginate($a)));
    }
    if (!$contacts) {
        $o .= '<div id="content-complete"></div>';
    }
    return $o;
}
Example #18
0
function follow_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    $uid = local_user();
    $url = notags(trim($_REQUEST['url']));
    $submit = t('Submit Request');
    // There is a current issue. It seems as if you can't start following a Friendica that is following you
    // With Diaspora this works - but Friendica is special, it seems ...
    $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND\n\t\t(`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND\n\t\t`network` != '%s' LIMIT 1", intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)), dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
    if ($r) {
        notice(t('You already added this contact.') . EOL);
        $submit = "";
        //goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    $ret = probe_url($url);
    if ($ret["network"] == NETWORK_DIASPORA and !get_config('system', 'diaspora_enabled')) {
        notice(t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
        $submit = "";
        //goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    if ($ret["network"] == NETWORK_OSTATUS and get_config('system', 'ostatus_disabled')) {
        notice(t("OStatus support is disabled. Contact can't be added.") . EOL);
        $submit = "";
        //goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    if ($ret["network"] == NETWORK_PHANTOM) {
        notice(t("The network type couldn't be detected. Contact can't be added.") . EOL);
        $submit = "";
        //goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    if ($ret["network"] == NETWORK_MAIL) {
        $ret["url"] = $ret["addr"];
    }
    if ($ret['network'] === NETWORK_DFRN) {
        $request = $ret["request"];
        $tpl = get_markup_template('dfrn_request.tpl');
    } else {
        $request = $a->get_baseurl() . "/follow";
        $tpl = get_markup_template('auto_request.tpl');
    }
    $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
    if (!$r) {
        notice(t('Permission denied.') . EOL);
        goaway($_SESSION['return_url']);
        // NOTREACHED
    }
    $myaddr = $r[0]["url"];
    // Makes the connection request for friendica contacts easier
    $_SESSION["fastlane"] = $ret["url"];
    $r = q("SELECT `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($ret["url"]));
    if (!$r) {
        $r = array(array("location" => "", "about" => "", "keywords" => ""));
    }
    if ($ret['network'] === NETWORK_DIASPORA) {
        $r[0]["location"] = "";
        $r[0]["about"] = "";
    }
    $header = $ret["name"];
    if ($ret["addr"] != "") {
        $header .= " <" . $ret["addr"] . ">";
    }
    $header .= " (" . network_to_name($ret['network'], $ret['url']) . ")";
    $o = replace_macros($tpl, array('$header' => htmlentities($header), '$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL), '$desc' => "", '$pls_answer' => t('Please answer the following:'), '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'), $ret["name"]), false, '', array(t('No'), t('Yes'))), '$add_note' => t('Add a personal note:'), '$page_desc' => "", '$friendica' => "", '$statusnet' => "", '$diaspora' => "", '$diasnote' => "", '$your_address' => t('Your Identity Address:'), '$invite_desc' => "", '$emailnet' => "", '$submit' => $submit, '$cancel' => t('Cancel'), '$nickname' => "", '$name' => $ret["name"], '$url' => $ret["url"], '$zrl' => zrl($ret["url"]), '$url_label' => t("Profile URL"), '$myaddr' => $myaddr, '$request' => $request, '$location' => bbcode($r[0]["location"]), '$location_label' => t("Location:"), '$about' => bbcode($r[0]["about"], false, false), '$about_label' => t("About:"), '$keywords' => $r[0]["keywords"], '$keywords_label' => t("Tags:")));
    return $o;
}
Example #19
0
function api_format_items($r, $user_info, $filter_user = false)
{
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        api_share_as_retweet($a, api_user(), $item);
        localize_item($item);
        $status_user = api_item_get_user($a, $item);
        // Look if the posts are matching if they should be filtered by user id
        if ($filter_user and $status_user["id"] != $user_info["id"]) {
            continue;
        }
        if ($item['thr-parent'] != $item['uri']) {
            $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent']));
            if ($r) {
                $in_reply_to_status_id = intval($r[0]['id']);
            } else {
                $in_reply_to_status_id = intval($item['parent']);
            }
            $in_reply_to_status_id_str = (string) intval($item['parent']);
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id));
            if ($r) {
                $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
                if ($r) {
                    if ($r[0]['nick'] == "") {
                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                    }
                    $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'];
                    $in_reply_to_user_id = intval($r[0]['id']);
                    $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                }
            }
        } else {
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_status_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $in_reply_to_status_id_str = NULL;
        }
        // Workaround for ostatus messages where the title is identically to the body
        //$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 5, true), 0));
        $html = bbcode(api_clean_plain_items($item['body']), false, false, 2, true);
        $statusbody = trim(html2plain($html, 0));
        $statustitle = trim($item['title']);
        if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) {
            $statustext = trim($statusbody);
        } else {
            $statustext = trim($statustitle . "\n\n" . $statusbody);
        }
        if ($item["network"] == NETWORK_FEED and strlen($statustext) > 1000) {
            $statustext = substr($statustext, 0, 1000) . "... \n" . $item["plink"];
        }
        $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id_str' => $in_reply_to_status_id_str, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'id_str' => (string) intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_user_id_str' => $in_reply_to_user_id_str, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => NULL, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => trim(bbcode($item['body'], false, false)), 'statusnet_conversation_id' => $item['parent']);
        if ($item['title'] != "") {
            $status['statusnet_html'] = "<h4>" . bbcode($item['title']) . "</h4>\n" . $status['statusnet_html'];
        }
        $entities = api_get_entitities($status['text'], $item['body']);
        if (count($entities) > 0) {
            $status['entities'] = $entities;
        }
        if ($item['item_network'] != "" and $status["source"] == 'web') {
            $status["source"] = network_to_name($item['item_network']);
        } else {
            if ($item['item_network'] != "" and network_to_name($item['item_network']) != $status["source"]) {
                $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network']) . ')');
            }
        }
        // Retweets are only valid for top postings
        // It doesn't work reliable with the link if its a feed
        $IsRetweet = $item['owner-link'] != $item['author-link'];
        if ($IsRetweet) {
            $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']);
        }
        if ($IsRetweet and $item["id"] == $item["parent"]) {
            $retweeted_status = $status;
            $retweeted_status["user"] = api_get_user($a, $item["author-link"]);
            $status["retweeted_status"] = $retweeted_status;
        }
        // "uid" and "self" are only needed for some internal stuff, so remove it from here
        unset($status["user"]["uid"]);
        unset($status["user"]["self"]);
        // 'geo' => array('type' => 'Point',
        //                   'coordinates' => array((float) $notice->lat,
        //                                          (float) $notice->lon));
        $ret[] = $status;
    }
    return $ret;
}
Example #20
0
 function get()
 {
     $sort_type = 0;
     $o = '';
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return login();
     }
     $blocked = false;
     $hidden = false;
     $ignored = false;
     $archived = false;
     $unblocked = false;
     $pending = false;
     $unconnected = false;
     $all = false;
     if (!$_REQUEST['aj']) {
         $_SESSION['return_url'] = \App::$query_string;
     }
     $search_flags = '';
     $head = '';
     if (argc() == 2) {
         switch (argv(1)) {
             case 'blocked':
                 $search_flags = " and abook_blocked = 1 ";
                 $head = t('Blocked');
                 $blocked = true;
                 break;
             case 'ignored':
                 $search_flags = " and abook_ignored = 1 ";
                 $head = t('Ignored');
                 $ignored = true;
                 break;
             case 'hidden':
                 $search_flags = " and abook_hidden = 1 ";
                 $head = t('Hidden');
                 $hidden = true;
                 break;
             case 'archived':
                 $search_flags = " and abook_archived = 1 ";
                 $head = t('Archived');
                 $archived = true;
                 break;
             case 'pending':
                 $search_flags = " and abook_pending = 1 ";
                 $head = t('New');
                 $pending = true;
                 nav_set_selected('intros');
                 break;
             case 'ifpending':
                 $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", intval(local_channel()));
                 if ($r && $r[0]['total']) {
                     $search_flags = " and abook_pending = 1 ";
                     $head = t('New');
                     $pending = true;
                     nav_set_selected('intros');
                     \App::$argv[1] = 'pending';
                 } else {
                     $head = t('All');
                     $search_flags = '';
                     $all = true;
                     \App::$argc = 1;
                     unset(\App::$argv[1]);
                 }
                 nav_set_selected('intros');
                 break;
                 //			case 'unconnected':
                 //				$search_flags = " and abook_unconnected = 1 ";
                 //				$head = t('Unconnected');
                 //				$unconnected = true;
                 //				break;
             //			case 'unconnected':
             //				$search_flags = " and abook_unconnected = 1 ";
             //				$head = t('Unconnected');
             //				$unconnected = true;
             //				break;
             case 'all':
                 $head = t('All');
             default:
                 $search_flags = '';
                 $all = true;
                 break;
         }
         $sql_extra = $search_flags;
         if (argv(1) === 'pending') {
             $sql_extra .= " and abook_ignored = 0 ";
         }
     } else {
         $sql_extra = " and abook_blocked = 0 ";
         $unblocked = true;
     }
     $search = x($_REQUEST, 'search') ? notags(trim($_REQUEST['search'])) : '';
     $tabs = array('pending' => array('label' => t('New Connections'), 'url' => z_root() . '/connections/pending', 'sel' => $pending ? 'active' : '', 'title' => t('Show pending (new) connections')), 'all' => array('label' => t('All Connections'), 'url' => z_root() . '/connections/all', 'sel' => $all ? 'active' : '', 'title' => t('Show all connections')), 'blocked' => array('label' => t('Blocked'), 'url' => z_root() . '/connections/blocked', 'sel' => $blocked ? 'active' : '', 'title' => t('Only show blocked connections')), 'ignored' => array('label' => t('Ignored'), 'url' => z_root() . '/connections/ignored', 'sel' => $ignored ? 'active' : '', 'title' => t('Only show ignored connections')), 'archived' => array('label' => t('Archived'), 'url' => z_root() . '/connections/archived', 'sel' => $archived ? 'active' : '', 'title' => t('Only show archived connections')), 'hidden' => array('label' => t('Hidden'), 'url' => z_root() . '/connections/hidden', 'sel' => $hidden ? 'active' : '', 'title' => t('Only show hidden connections')));
     //$tab_tpl = get_markup_template('common_tabs.tpl');
     //$t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
     $searching = false;
     if ($search) {
         $search_hdr = $search;
         $search_txt = dbesc(protect_sprintf(preg_quote($search)));
         $searching = true;
     }
     $sql_extra .= $searching ? protect_sprintf(" AND xchan_name like '%{$search_txt}%' ") : "";
     if ($_REQUEST['gid']) {
         $sql_extra .= " and xchan_hash in ( select xchan from group_member where gid = " . intval($_REQUEST['gid']) . " and uid = " . intval(local_channel()) . " ) ";
     }
     $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash \n\t\t\twhere abook_channel = %d and abook_self = 0 and xchan_deleted = 0 and xchan_orphan = 0 {$sql_extra} {$sql_extra2} ", intval(local_channel()));
     if ($r) {
         \App::set_pager_total($r[0]['total']);
         $total = $r[0]['total'];
     }
     $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash\n\t\t\tWHERE abook_channel = %d and abook_self = 0 and xchan_deleted = 0 and xchan_orphan = 0 {$sql_extra} {$sql_extra2} ORDER BY xchan_name LIMIT %d OFFSET %d ", intval(local_channel()), intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     $contacts = array();
     if (count($r)) {
         foreach ($r as $rr) {
             if ($rr['xchan_url']) {
                 $status_str = '';
                 $status = array(intval($rr['abook_pending']) ? t('Pending approval') : '', intval($rr['abook_archived']) ? t('Archived') : '', intval($rr['abook_hidden']) ? t('Hidden') : '', intval($rr['abook_ignored']) ? t('Ignored') : '', intval($rr['abook_blocked']) ? t('Blocked') : '');
                 foreach ($status as $str) {
                     if (!$str) {
                         continue;
                     }
                     $status_str .= $str;
                     $status_str .= ', ';
                 }
                 $status_str = rtrim($status_str, ', ');
                 $contacts[] = array('img_hover' => sprintf(t('%1$s [%2$s]'), $rr['xchan_name'], $rr['xchan_url']), 'edit_hover' => t('Edit connection'), 'delete_hover' => t('Delete connection'), 'id' => $rr['abook_id'], 'thumb' => $rr['xchan_photo_m'], 'name' => $rr['xchan_name'], 'classes' => intval($rr['abook_archived']) ? 'archived' : '', 'link' => z_root() . '/connedit/' . $rr['abook_id'], 'deletelink' => z_root() . '/connedit/' . intval($rr['abook_id']) . '/drop', 'delete' => t('Delete'), 'url' => chanlink_url($rr['xchan_url']), 'webbie_label' => t('Channel address'), 'webbie' => $rr['xchan_addr'], 'network_label' => t('Network'), 'network' => network_to_name($rr['xchan_network']), 'public_forum' => intval($rr['xchan_pubforum']) ? true : false, 'status_label' => t('Status'), 'status' => $status_str, 'connected_label' => t('Connected'), 'connected' => datetime_convert('UTC', date_default_timezone_get(), $rr['abook_created'], 'c'), 'approve_hover' => t('Approve connection'), 'approve' => $rr['abook_pending'] ? t('Approve') : false, 'ignore_hover' => t('Ignore connection'), 'ignore' => !$rr['abook_ignored'] ? t('Ignore') : false, 'recent_label' => t('Recent activity'), 'recentlink' => z_root() . '/network/?f=&cid=' . intval($rr['abook_id']));
             }
         }
     }
     if ($_REQUEST['aj']) {
         if ($contacts) {
             $o = replace_macros(get_markup_template('contactsajax.tpl'), array('$contacts' => $contacts, '$edit' => t('Edit')));
         } else {
             $o = '<div id="content-complete"></div>';
         }
         echo $o;
         killme();
     } else {
         $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; </script>";
         $o .= replace_macros(get_markup_template('connections.tpl'), array('$header' => t('Connections') . ($head ? ': ' . $head : ''), '$tabs' => $tabs, '$total' => $total, '$search' => $search_hdr, '$label' => t('Search'), '$desc' => t('Search your connections'), '$finding' => $searching ? t('Connections search') . ": '" . $search . "'" : "", '$submit' => t('Find'), '$edit' => t('Edit'), '$cmd' => \App::$cmd, '$contacts' => $contacts, '$paginate' => paginate($a)));
     }
     if (!$contacts) {
         $o .= '<div id="content-complete"></div>';
     }
     return $o;
 }
Example #21
0
function api_format_items($r, $user_info, $filter_user = false)
{
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        api_share_as_retweet($item);
        localize_item($item);
        $status_user = api_item_get_user($a, $item);
        // Look if the posts are matching if they should be filtered by user id
        if ($filter_user and $status_user["id"] != $user_info["id"]) {
            continue;
        }
        if ($item['thr-parent'] != $item['uri']) {
            $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent']));
            if ($r) {
                $in_reply_to_status_id = intval($r[0]['id']);
            } else {
                $in_reply_to_status_id = intval($item['parent']);
            }
            $in_reply_to_status_id_str = (string) intval($item['parent']);
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id));
            if ($r) {
                $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
                if ($r) {
                    if ($r[0]['nick'] == "") {
                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                    }
                    $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'];
                    $in_reply_to_user_id = intval($r[0]['id']);
                    $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                }
            }
        } else {
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_status_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $in_reply_to_status_id_str = NULL;
        }
        $converted = api_convert_item($item);
        $status = array('text' => $converted["text"], 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id_str' => $in_reply_to_status_id_str, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'id_str' => (string) intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_user_id_str' => $in_reply_to_user_id_str, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => NULL, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => $converted["html"], 'statusnet_conversation_id' => $item['parent']);
        if (count($converted["attachments"]) > 0) {
            $status["attachments"] = $converted["attachments"];
        }
        if (count($converted["entities"]) > 0) {
            $status["entities"] = $converted["entities"];
        }
        if ($item['item_network'] != "" and $status["source"] == 'web') {
            $status["source"] = network_to_name($item['item_network'], $user_info['url']);
        } else {
            if ($item['item_network'] != "" and network_to_name($item['item_network'], $user_info['url']) != $status["source"]) {
                $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network'], $user_info['url']) . ')');
            }
        }
        // Retweets are only valid for top postings
        // It doesn't work reliable with the link if its a feed
        $IsRetweet = $item['owner-link'] != $item['author-link'];
        if ($IsRetweet) {
            $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']);
        }
        if ($IsRetweet and $item["id"] == $item["parent"]) {
            $retweeted_status = $status;
            $retweeted_status["user"] = api_get_user($a, $item["author-link"]);
            $status["retweeted_status"] = $retweeted_status;
        }
        // "uid" and "self" are only needed for some internal stuff, so remove it from here
        unset($status["user"]["uid"]);
        unset($status["user"]["self"]);
        if ($item["coord"] != "") {
            $coords = explode(' ', $item["coord"]);
            if (count($coords) == 2) {
                $status["geo"] = array('type' => 'Point', 'coordinates' => array((double) $coords[0], (double) $coords[1]));
            }
        }
        $ret[] = $status;
    }
    return $ret;
}
Example #22
0
function notifications_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('notifications');
    $json = $a->argc > 1 && $a->argv[$a->argc - 1] === 'json' ? true : false;
    $o = '';
    $tabs = array(array('label' => t('System'), 'url' => $a->get_baseurl(true) . '/notifications/system', 'sel' => $a->argv[1] == 'system' ? 'active' : '', 'accesskey' => 'y'), array('label' => t('Network'), 'url' => $a->get_baseurl(true) . '/notifications/network', 'sel' => $a->argv[1] == 'network' ? 'active' : '', 'accesskey' => 'w'), array('label' => t('Personal'), 'url' => $a->get_baseurl(true) . '/notifications/personal', 'sel' => $a->argv[1] == 'personal' ? 'active' : '', 'accesskey' => 'r'), array('label' => t('Home'), 'url' => $a->get_baseurl(true) . '/notifications/home', 'sel' => $a->argv[1] == 'home' ? 'active' : '', 'accesskey' => 'h'), array('label' => t('Introductions'), 'url' => $a->get_baseurl(true) . '/notifications/intros', 'sel' => $a->argv[1] == 'intros' ? 'active' : '', 'accesskey' => 'i'));
    $o = "";
    if ($a->argc > 1 && $a->argv[1] == 'intros' || $a->argc == 1) {
        nav_set_selected('introductions');
        if ($a->argc > 2 && $a->argv[2] == 'all') {
            $sql_extra = '';
        } else {
            $sql_extra = " AND `ignore` = 0 ";
        }
        $notif_tpl = get_markup_template('notifications.tpl');
        $notif_content .= '<a href="' . (strlen($sql_extra) ? 'notifications/intros/all' : 'notifications/intros') . '" id="notifications-show-hide-link" >' . (strlen($sql_extra) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
        $r = q("SELECT COUNT(*)\tAS `total` FROM `intro`\n\t\t\tWHERE `intro`.`uid` = %d {$sql_extra} AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']));
        if ($r && count($r)) {
            $a->set_pager_total($r[0]['total']);
            $a->set_pager_itemspage(20);
        }
        $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest`,\n\t\t\t\t`gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,\n\t\t\t\t`gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,\n\t\t\t\t`gcontact`.`network` AS `gnetwork`\n\t\t\tFROM `intro`\n\t\t\t\tLEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`\n\t\t\t\tLEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`\n\t\t\t\tLEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d {$sql_extra} AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']));
        if ($r !== false && count($r)) {
            $sugg = get_markup_template('suggestions.tpl');
            $tpl = get_markup_template("intros.tpl");
            foreach ($r as $rr) {
                if ($rr['fid']) {
                    $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . ($a->path ? '/' . $a->path : ''));
                    $notif_content .= replace_macros($sugg, array('$str_notifytype' => t('Notification type: '), '$notify_type' => t('Friend Suggestion'), '$intro_id' => $rr['intro_id'], '$madeby' => sprintf(t('suggested by %s'), $rr['name']), '$contact_id' => $rr['contact-id'], '$photo' => x($rr, 'fphoto') ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg", '$fullname' => $rr['fname'], '$url' => zrl($rr['furl']), '$hidden' => array('hidden', t('Hide this contact from others'), $rr['hidden'] == 1, ''), '$activity' => array('activity', t('Post a new friend activity'), intval(get_pconfig(local_user(), 'system', 'post_newfriend')) ? '1' : 0, t('if applicable')), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $rr['note'], '$request' => $rr['frequest'] . '?addr=' . $return_addr, '$ignore' => t('Ignore'), '$discard' => t('Discard')));
                    continue;
                }
                $friend_selected = $rr['network'] !== NETWORK_OSTATUS ? ' checked="checked" ' : ' disabled ';
                $fan_selected = $rr['network'] === NETWORK_OSTATUS ? ' checked="checked" disabled ' : '';
                $dfrn_tpl = get_markup_template('netfriend.tpl');
                $knowyou = '';
                $dfrn_text = '';
                if ($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
                    if ($rr['network'] === NETWORK_DFRN) {
                        $knowyou = t('Claims to be known to you: ') . ($rr['knowyou'] ? t('yes') : t('no'));
                        $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: ');
                    } else {
                        $knowyou = '';
                        $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: ');
                    }
                    $dfrn_text = replace_macros($dfrn_tpl, array('$intro_id' => $rr['intro_id'], '$friend_selected' => $friend_selected, '$fan_selected' => $fan_selected, '$approve_as' => $helptext, '$as_friend' => t('Friend'), '$as_fan' => $rr['network'] == NETWORK_DIASPORA ? t('Sharer') : t('Fan/Admirer')));
                }
                $header = $rr["name"];
                $ret = probe_url($rr["url"]);
                if ($rr['gnetwork'] == "") {
                    $rr['gnetwork'] = $ret["network"];
                }
                if ($ret["addr"] != "") {
                    $header .= " <" . $ret["addr"] . ">";
                }
                $header .= " (" . network_to_name($rr['gnetwork'], $rr['url']) . ")";
                // Don't show these data until you are connected. Diaspora is doing the same.
                if ($rr['gnetwork'] === NETWORK_DIASPORA) {
                    $rr['glocation'] = "";
                    $rr['gabout'] = "";
                    $rr['ggender'] = "";
                }
                $notif_content .= replace_macros($tpl, array('$header' => htmlentities($header), '$str_notifytype' => t('Notification type: '), '$notify_type' => $rr['network'] !== NETWORK_OSTATUS ? t('Friend/Connect Request') : t('New Follower'), '$dfrn_text' => $dfrn_text, '$dfrn_id' => $rr['issued-id'], '$uid' => $_SESSION['uid'], '$intro_id' => $rr['intro_id'], '$contact_id' => $rr['contact-id'], '$photo' => x($rr, 'photo') ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg", '$fullname' => $rr['name'], '$location' => bbcode($rr['glocation'], false, false), '$location_label' => t('Location:'), '$about' => bbcode($rr['gabout'], false, false), '$about_label' => t('About:'), '$keywords' => $rr['gkeywords'], '$keywords_label' => t('Tags:'), '$gender' => $rr['ggender'], '$gender_label' => t('Gender:'), '$hidden' => array('hidden', t('Hide this contact from others'), $rr['hidden'] == 1, ''), '$activity' => array('activity', t('Post a new friend activity'), intval(get_pconfig(local_user(), 'system', 'post_newfriend')) ? '1' : 0, t('if applicable')), '$url' => $rr['url'], '$zrl' => zrl($rr['url']), '$url_label' => t('Profile URL'), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $rr['note'], '$ignore' => t('Ignore'), '$discard' => t('Discard')));
            }
        } else {
            info(t('No introductions.') . EOL);
        }
        $o .= replace_macros($notif_tpl, array('$notif_header' => t('Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
        $o .= paginate($a);
        return $o;
    } else {
        if ($a->argc > 1 && $a->argv[1] == 'network') {
            $notif_tpl = get_markup_template('notifications.tpl');
            $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC", intval(local_user()));
            $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
            $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
            $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
            $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
            $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
            $notif_content = '';
            if ($r) {
                foreach ($r as $it) {
                    switch ($it['verb']) {
                        case ACTIVITY_LIKE:
                            $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                            break;
                        case ACTIVITY_DISLIKE:
                            $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                            break;
                        case ACTIVITY_FRIEND:
                            $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                            $obj = parse_xml_string($xmlhead . $it['object']);
                            $it['fname'] = $obj->title;
                            $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                            break;
                        default:
                            $item_text = $it['id'] == $it['parent'] ? sprintf(t("%s created a new post"), $it['author-name']) : sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
                            $tpl = $it['id'] == $it['parent'] ? $tpl_item_posts : $tpl_item_comments;
                            $notif_content .= replace_macros($tpl, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), '$item_text' => $item_text, '$item_when' => relative_date($it['created'])));
                    }
                }
            } else {
                $notif_content = t('No more network notifications.');
            }
            $o .= replace_macros($notif_tpl, array('$notif_header' => t('Network Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
        } else {
            if ($a->argc > 1 && $a->argv[1] == 'system') {
                $notif_tpl = get_markup_template('notifications.tpl');
                $not_tpl = get_markup_template('notify.tpl');
                require_once 'include/bbcode.php';
                $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc", intval(local_user()));
                if (count($r) > 0) {
                    foreach ($r as $it) {
                        $notif_content .= replace_macros($not_tpl, array('$item_link' => $a->get_baseurl(true) . '/notify/view/' . $it['id'], '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO), '$item_text' => strip_tags(bbcode($it['msg'])), '$item_when' => relative_date($it['date'])));
                    }
                } else {
                    $notif_content .= t('No more system notifications.');
                }
                $o .= replace_macros($notif_tpl, array('$notif_header' => t('System Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
            } else {
                if ($a->argc > 1 && $a->argv[1] == 'personal') {
                    $notif_tpl = get_markup_template('notifications.tpl');
                    $myurl = $a->get_baseurl(true) . '/profile/' . $a->user['nickname'];
                    $myurl = substr($myurl, strpos($myurl, '://') + 3);
                    $myurl = str_replace(array('www.', '.'), array('', '\\.'), $myurl);
                    $diasp_url = str_replace('/profile/', '/u/', $myurl);
                    $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", dbesc($myurl . '$'), dbesc($myurl . '\\]'), dbesc($diasp_url . '\\]'));
                    $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1\n\t\t\t\t{$sql_extra}\n\t\t\t\tAND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC", intval(local_user()));
                    $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
                    $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
                    $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
                    $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
                    $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
                    $notif_content = '';
                    if (count($r) > 0) {
                        foreach ($r as $it) {
                            switch ($it['verb']) {
                                case ACTIVITY_LIKE:
                                    $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                    break;
                                case ACTIVITY_DISLIKE:
                                    $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                    break;
                                case ACTIVITY_FRIEND:
                                    $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                                    $obj = parse_xml_string($xmlhead . $it['object']);
                                    $it['fname'] = $obj->title;
                                    $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                                    break;
                                default:
                                    $item_text = $it['id'] == $it['parent'] ? sprintf(t("%s created a new post"), $it['author-name']) : sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
                                    $tpl = $it['id'] == $it['parent'] ? $tpl_item_posts : $tpl_item_comments;
                                    $notif_content .= replace_macros($tpl, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => $item_text, '$item_when' => relative_date($it['created'])));
                            }
                        }
                    } else {
                        $notif_content = t('No more personal notifications.');
                    }
                    $o .= replace_macros($notif_tpl, array('$notif_header' => t('Personal Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
                } else {
                    if ($a->argc > 1 && $a->argv[1] == 'home') {
                        $notif_tpl = get_markup_template('notifications.tpl');
                        $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC", intval(local_user()));
                        $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
                        $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
                        $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
                        $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
                        $notif_content = '';
                        if (count($r) > 0) {
                            foreach ($r as $it) {
                                switch ($it['verb']) {
                                    case ACTIVITY_LIKE:
                                        $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                        break;
                                    case ACTIVITY_DISLIKE:
                                        $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                        break;
                                    case ACTIVITY_FRIEND:
                                        $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                                        $obj = parse_xml_string($xmlhead . $it['object']);
                                        $it['fname'] = $obj->title;
                                        $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                                        break;
                                    default:
                                        $notif_content .= replace_macros($tpl_item_comments, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                                }
                            }
                        } else {
                            $notif_content = t('No more home notifications.');
                        }
                        $o .= replace_macros($notif_tpl, array('$notif_header' => t('Home Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
                    }
                }
            }
        }
    }
    $o .= paginate($a);
    return $o;
}
Example #23
0
function contacts_content(&$a)
{
    $sort_type = 0;
    $o = '';
    nav_set_selected('contacts');
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc == 3) {
        $contact_id = intval($a->argv[1]);
        if (!$contact_id) {
            return;
        }
        $cmd = $a->argv[2];
        $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1", intval($contact_id), intval(local_user()));
        if (!count($orig_record)) {
            notice(t('Could not access contact record.') . EOL);
            goaway($a->get_baseurl(true) . '/contacts');
            return;
            // NOTREACHED
        }
        if ($cmd === 'update') {
            _contact_update($contact_id);
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            // NOTREACHED
        }
        if ($cmd === 'block') {
            $r = _contact_block($contact_id, $orig_record[0]);
            if ($r) {
                $blocked = $orig_record[0]['blocked'] ? 0 : 1;
                info(($blocked ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL);
            }
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'ignore') {
            $r = _contact_ignore($contact_id, $orig_record[0]);
            if ($r) {
                $readonly = $orig_record[0]['readonly'] ? 0 : 1;
                info(($readonly ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL);
            }
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'archive') {
            $r = _contact_archive($contact_id, $orig_record[0]);
            if ($r) {
                $archived = $orig_record[0]['archive'] ? 0 : 1;
                info(($archived ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL);
            }
            goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
            return;
            // NOTREACHED
        }
        if ($cmd === 'drop') {
            // Check if we should do HTML-based delete confirmation
            if ($_REQUEST['confirm']) {
                // <form> can't take arguments in its "action" parameter
                // so add any arguments as hidden inputs
                $query = explode_querystring($a->query_string);
                $inputs = array();
                foreach ($query['args'] as $arg) {
                    if (strpos($arg, 'confirm=') === false) {
                        $arg_parts = explode('=', $arg);
                        $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
                    }
                }
                $a->page['aside'] = '';
                return replace_macros(get_markup_template('confirm.tpl'), array('$method' => 'get', '$message' => t('Do you really want to delete this contact?'), '$extra_inputs' => $inputs, '$confirm' => t('Yes'), '$confirm_url' => $query['base'], '$confirm_name' => 'confirmed', '$cancel' => t('Cancel')));
            }
            // Now check how the user responded to the confirmation query
            if ($_REQUEST['canceled']) {
                if (x($_SESSION, 'return_url')) {
                    goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
                } else {
                    goaway($a->get_baseurl(true) . '/contacts');
                }
            }
            _contact_drop($contact_id, $orig_record[0]);
            info(t('Contact has been removed.') . EOL);
            if (x($_SESSION, 'return_url')) {
                goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
            } else {
                goaway($a->get_baseurl(true) . '/contacts');
            }
            return;
            // NOTREACHED
        }
    }
    $_SESSION['return_url'] = $a->query_string;
    if (x($a->data, 'contact') && is_array($a->data['contact'])) {
        $contact_id = $a->data['contact']['id'];
        $contact = $a->data['contact'];
        $editselect = 'none';
        if (feature_enabled(local_user(), 'richtext')) {
            $editselect = 'exact';
        }
        $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array('$baseurl' => $a->get_baseurl(true), '$editselect' => $editselect));
        $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array('$baseurl' => $a->get_baseurl(true), '$editselect' => $editselect));
        require_once 'include/contact_selectors.php';
        $tpl = get_markup_template("contact_edit.tpl");
        switch ($contact['rel']) {
            case CONTACT_IS_FRIEND:
                $dir_icon = 'images/lrarrow.gif';
                $relation_text = t('You are mutual friends with %s');
                break;
            case CONTACT_IS_FOLLOWER:
                $dir_icon = 'images/larrow.gif';
                $relation_text = t('You are sharing with %s');
                break;
            case CONTACT_IS_SHARING:
                $dir_icon = 'images/rarrow.gif';
                $relation_text = t('%s is sharing with you');
                break;
            default:
                break;
        }
        $relation_text = sprintf($relation_text, $contact['name']);
        if ($contact['network'] === NETWORK_DFRN && $contact['rel']) {
            $url = "redir/{$contact['id']}";
            $sparkle = ' class="sparkle" ';
        } else {
            $url = $contact['url'];
            $sparkle = '';
        }
        $insecure = t('Private communications are not available for this contact.');
        $last_update = $contact['last-update'] == '0000-00-00 00:00:00' ? t('Never') : datetime_convert('UTC', date_default_timezone_get(), $contact['last-update'], 'D, j M Y, g:i A');
        if ($contact['last-update'] !== '0000-00-00 00:00:00') {
            $last_update .= ' ' . ($contact['last-update'] == $contact['success_update'] ? t("(Update was successful)") : t("(Update was not successful)"));
        }
        $lblsuggest = $contact['network'] === NETWORK_DFRN ? t('Suggest friends') : '';
        $poll_enabled = $contact['network'] !== NETWORK_DIASPORA ? true : false;
        $nettype = sprintf(t('Network type: %s'), network_to_name($contact['network']));
        $common = count_common_friends(local_user(), $contact['id']);
        $common_text = $common ? sprintf(tt('%d contact in common', '%d contacts in common', $common), $common) : '';
        $polling = $contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED ? 'polling' : '';
        $x = count_all_friends(local_user(), $contact['id']);
        $all_friends = $x ? t('View all contacts') : '';
        // tabs
        $tabs = array(array('label' => $contact['blocked'] ? t('Unblock') : t('Block'), 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block', 'sel' => '', 'title' => t('Toggle Blocked status')), array('label' => $contact['readonly'] ? t('Unignore') : t('Ignore'), 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore', 'sel' => '', 'title' => t('Toggle Ignored status')), array('label' => $contact['archive'] ? t('Unarchive') : t('Archive'), 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive', 'sel' => '', 'title' => t('Toggle Archive status')), array('label' => t('Repair'), 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id, 'sel' => '', 'title' => t('Advanced Contact Settings')));
        $tab_tpl = get_markup_template('common_tabs.tpl');
        $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
        $lost_contact = $contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('', '', 'now') ? t('Communications lost with this contact!') : '';
        $o .= replace_macros($tpl, array('$header' => t('Contact Editor'), '$tab_str' => $tab_str, '$submit' => t('Submit'), '$lbl_vis1' => t('Profile Visibility'), '$lbl_vis2' => sprintf(t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']), '$lbl_info1' => t('Contact Information / Notes'), '$infedit' => t('Edit contact notes'), '$common_text' => $common_text, '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'], '$all_friends' => $all_friends, '$relation_text' => $relation_text, '$visit' => sprintf(t('Visit %s\'s profile [%s]'), $contact['name'], $contact['url']), '$blockunblock' => t('Block/Unblock contact'), '$ignorecont' => t('Ignore contact'), '$lblcrepair' => t("Repair URL settings"), '$lblrecent' => t('View conversations'), '$lblsuggest' => $lblsuggest, '$delete' => t('Delete contact'), '$nettype' => $nettype, '$poll_interval' => contact_poll_interval($contact['priority'], !$poll_enabled), '$poll_enabled' => $poll_enabled, '$lastupdtext' => t('Last update:'), '$lost_contact' => $lost_contact, '$updpub' => t('Update public posts'), '$last_update' => $last_update, '$udnow' => t('Update now'), '$profile_select' => contact_profile_assign($contact['profile-id'], $contact['network'] !== NETWORK_DFRN ? true : false), '$contact_id' => $contact['id'], '$block_text' => $contact['blocked'] ? t('Unblock') : t('Block'), '$ignore_text' => $contact['readonly'] ? t('Unignore') : t('Ignore'), '$insecure' => $contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA ? $insecure : '', '$info' => $contact['info'], '$blocked' => $contact['blocked'] ? t('Currently blocked') : '', '$ignored' => $contact['readonly'] ? t('Currently ignored') : '', '$archived' => $contact['archive'] ? t('Currently archived') : '', '$hidden' => array('hidden', t('Hide this contact from others'), $contact['hidden'] == 1, t('Replies/likes to your public posts <strong>may</strong> still be visible')), '$notify' => array('notify', t('Notification for new posts'), $contact['notify_new_posts'] == 1, t('Send a notification of every new post of this contact')), '$fetch_further_information' => array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'] == 1, t('Fetch further information for feeds')), '$photo' => $contact['photo'], '$name' => $contact['name'], '$dir_icon' => $dir_icon, '$alt_text' => $alt_text, '$sparkle' => $sparkle, '$url' => $url));
        $arr = array('contact' => $contact, 'output' => $o);
        call_hooks('contact_edit', $arr);
        return $arr['output'];
    }
    $blocked = false;
    $hidden = false;
    $ignored = false;
    $all = false;
    if ($a->argc == 2 && $a->argv[1] === 'all') {
        $sql_extra = '';
        $all = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'blocked') {
        $sql_extra = " AND `blocked` = 1 ";
        $blocked = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'hidden') {
        $sql_extra = " AND `hidden` = 1 ";
        $hidden = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'ignored') {
        $sql_extra = " AND `readonly` = 1 ";
        $ignored = true;
    } elseif ($a->argc == 2 && $a->argv[1] === 'archived') {
        $sql_extra = " AND `archive` = 1 ";
        $archived = true;
    } else {
        $sql_extra = " AND `blocked` = 0 ";
    }
    $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
    $nets = x($_GET, 'nets') ? notags(trim($_GET['nets'])) : '';
    $tabs = array(array('label' => t('Suggestions'), 'url' => $a->get_baseurl(true) . '/suggest', 'sel' => '', 'title' => t('Suggest potential friends')), array('label' => t('All Contacts'), 'url' => $a->get_baseurl(true) . '/contacts/all', 'sel' => $all ? 'active' : '', 'title' => t('Show all contacts')), array('label' => t('Unblocked'), 'url' => $a->get_baseurl(true) . '/contacts', 'sel' => !$all && !$blocked && !$hidden && !$search && !$nets && !$ignored && !$archived ? 'active' : '', 'title' => t('Only show unblocked contacts')), array('label' => t('Blocked'), 'url' => $a->get_baseurl(true) . '/contacts/blocked', 'sel' => $blocked ? 'active' : '', 'title' => t('Only show blocked contacts')), array('label' => t('Ignored'), 'url' => $a->get_baseurl(true) . '/contacts/ignored', 'sel' => $ignored ? 'active' : '', 'title' => t('Only show ignored contacts')), array('label' => t('Archived'), 'url' => $a->get_baseurl(true) . '/contacts/archived', 'sel' => $archived ? 'active' : '', 'title' => t('Only show archived contacts')), array('label' => t('Hidden'), 'url' => $a->get_baseurl(true) . '/contacts/hidden', 'sel' => $hidden ? 'active' : '', 'title' => t('Only show hidden contacts')));
    $tab_tpl = get_markup_template('common_tabs.tpl');
    $t = replace_macros($tab_tpl, array('$tabs' => $tabs));
    $searching = false;
    if ($search) {
        $search_hdr = $search;
        $search_txt = dbesc(protect_sprintf(preg_quote($search)));
        $searching = true;
    }
    $sql_extra .= $searching ? " AND (name REGEXP '{$search_txt}' OR url REGEXP '{$search_txt}'  OR nick REGEXP '{$search_txt}') " : "";
    if ($nets) {
        $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
    }
    $sql_extra2 = $sort_type > 0 && $sort_type <= CONTACT_IS_FRIEND ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '';
    $r = q("SELECT COUNT(*) AS `total` FROM `contact` \n\t\tWHERE `uid` = %d AND `self` = 0 AND `pending` = 0 {$sql_extra} {$sql_extra2} ", intval($_SESSION['uid']));
    if (count($r)) {
        $a->set_pager_total($r[0]['total']);
        $total = $r[0]['total'];
    }
    $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 {$sql_extra} {$sql_extra2} ORDER BY `name` ASC LIMIT %d , %d ", intval($_SESSION['uid']), intval($a->pager['start']), intval($a->pager['itemspage']));
    $contacts = array();
    if (count($r)) {
        foreach ($r as $rr) {
            switch ($rr['rel']) {
                case CONTACT_IS_FRIEND:
                    $dir_icon = 'images/lrarrow.gif';
                    $alt_text = t('Mutual Friendship');
                    break;
                case CONTACT_IS_FOLLOWER:
                    $dir_icon = 'images/larrow.gif';
                    $alt_text = t('is a fan of yours');
                    break;
                case CONTACT_IS_SHARING:
                    $dir_icon = 'images/rarrow.gif';
                    $alt_text = t('you are a fan of');
                    break;
                default:
                    break;
            }
            if ($rr['network'] === 'dfrn' && $rr['rel']) {
                $url = "redir/{$rr['id']}";
                $sparkle = ' class="sparkle" ';
            } else {
                $url = $rr['url'];
                $sparkle = '';
            }
            $contacts[] = array('img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['name'], $rr['url']), 'edit_hover' => t('Edit contact'), 'photo_menu' => contact_photo_menu($rr), 'id' => $rr['id'], 'alt_text' => $alt_text, 'dir_icon' => $dir_icon, 'thumb' => $rr['thumb'], 'name' => $rr['name'], 'username' => $rr['name'], 'sparkle' => $sparkle, 'itemurl' => $rr['url'], 'url' => $url, 'network' => network_to_name($rr['network']));
        }
    }
    $tpl = get_markup_template("contacts-template.tpl");
    $o .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$header' => t('Contacts') . ($nets ? ' - ' . network_to_name($nets) : ''), '$tabs' => $t, '$total' => $total, '$search' => $search_hdr, '$desc' => t('Search your contacts'), '$finding' => $searching ? t('Finding: ') . "'" . $search . "'" : "", '$submit' => t('Find'), '$cmd' => $a->cmd, '$contacts' => $contacts, '$contact_drop_confirm' => t('Do you really want to delete this contact?'), '$batch_actions' => array('contacts_batch_update' => t('Update'), 'contacts_batch_block' => t('Block') . "/" . t("Unblock"), "contacts_batch_ignore" => t('Ignore') . "/" . t("Unignore"), "contacts_batch_archive" => t('Archive') . "/" . t("Unarchive"), "contacts_batch_drop" => t('Delete')), '$paginate' => paginate($a)));
    return $o;
}
Example #24
0
/**
 * @brief translate and format the networkname of a contact
 * 
 * @param string $network
 *	Networkname of the contact (e.g. dfrn, rss and so on)
 * @param sting $url
 *	The contact url
 * @return string
 */
function format_network_name($network, $url = 0)
{
    if ($network != "") {
        require_once 'include/contact_selectors.php';
        if ($url != "") {
            $network_name = '<a href="' . $url . '">' . network_to_name($network, $url) . "</a>";
        } else {
            $network_name = network_to_name($network);
        }
        return $network_name;
    }
}