Example #1
0
function widget_chatroom_list($arr)
{
    $a = get_app();
    require_once "include/chat.php";
    $r = chatroom_list($a->profile['profile_uid']);
    return replace_macros(get_markup_template('chatroomlist.tpl'), array('$header' => t('Chat Rooms'), '$baseurl' => z_root(), '$nickname' => $a->profile['channel_address'], '$items' => $r));
}
Example #2
0
 function get()
 {
     if (local_channel()) {
         $channel = \App::get_channel();
     }
     $ob = \App::get_observer();
     $observer = get_observer_hash();
     if (!$observer) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!perm_is_allowed(\App::$profile['profile_uid'], $observer, 'chat')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (argc() > 3 && intval(argv(2)) && argv(3) === 'leave') {
         chatroom_leave($observer, argv(2), $_SERVER['REMOTE_ADDR']);
         goaway(z_root() . '/channel/' . argv(1));
     }
     if (argc() > 3 && intval(argv(2)) && argv(3) === 'status') {
         $ret = array('success' => false);
         $room_id = intval(argv(2));
         if (!$room_id || !$observer) {
             return;
         }
         $r = q("select * from chatroom where cr_id = %d limit 1", intval($room_id));
         if (!$r) {
             json_return_and_die($ret);
         }
         require_once 'include/security.php';
         $sql_extra = permissions_sql($r[0]['cr_uid']);
         $x = q("select * from chatroom where cr_id = %d and cr_uid = %d {$sql_extra} limit 1", intval($room_id), intval($r[0]['cr_uid']));
         if (!$x) {
             json_return_and_die($ret);
         }
         $y = q("select count(*) as total from chatpresence where cp_room = %d", intval($room_id));
         if ($y) {
             $ret['success'] = true;
             $ret['chatroom'] = $r[0]['cr_name'];
             $ret['inroom'] = $y[0]['total'];
         }
         // figure out how to present a timestamp of the last activity, since we don't know the observer's timezone.
         $z = q("select created from chat where chat_room = %d order by created desc limit 1", intval($room_id));
         if ($z) {
             $ret['last'] = $z[0]['created'];
         }
         json_return_and_die($ret);
     }
     if (argc() > 2 && intval(argv(2))) {
         $room_id = intval(argv(2));
         $bookmark_link = get_bookmark_link($ob);
         $x = chatroom_enter($observer, $room_id, 'online', $_SERVER['REMOTE_ADDR']);
         if (!$x) {
             return;
         }
         $x = q("select * from chatroom where cr_id = %d and cr_uid = %d {$sql_extra} limit 1", intval($room_id), intval(\App::$profile['profile_uid']));
         if ($x) {
             $acl = new \Zotlabs\Access\AccessList(false);
             $acl->set($x[0]);
             $private = $acl->is_private();
             $room_name = $x[0]['cr_name'];
             if ($bookmark_link) {
                 $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . ($private ? '&private=1' : '') . '&ischat=1';
             }
         } else {
             notice(t('Room not found') . EOL);
             return;
         }
         $cipher = get_pconfig(local_channel(), 'system', 'default_cipher');
         if (!$cipher) {
             $cipher = 'aes256';
         }
         $o = replace_macros(get_markup_template('chat.tpl'), array('$is_owner' => local_channel() && local_channel() == $x[0]['cr_uid'] ? true : false, '$room_name' => $room_name, '$room_id' => $room_id, '$baseurl' => z_root(), '$nickname' => argv(1), '$submit' => t('Submit'), '$leave' => t('Leave Room'), '$drop' => t('Delete Room'), '$away' => t('I am away right now'), '$online' => t('I am online'), '$bookmark_link' => $bookmark_link, '$bookmark' => t('Bookmark this room'), '$feature_encrypt' => feature_enabled(local_channel(), 'content_encrypt') ? true : false, '$cipher' => $cipher, '$linkurl' => t('Please enter a link URL:'), '$encrypt' => t('Encrypt text'), '$insert' => t('Insert web link')));
         return $o;
     }
     require_once 'include/conversation.php';
     $o = profile_tabs($a, local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false, \App::$profile['channel_address']);
     if (!feature_enabled(\App::$profile['profile_uid'], 'ajaxchat')) {
         notice(t('Feature disabled.') . EOL);
         return $o;
     }
     $acl = new \Zotlabs\Access\AccessList($channel);
     $channel_acl = $acl->get();
     $lockstate = $channel_acl['allow_cid'] || $channel_acl['allow_gid'] || $channel_acl['deny_cid'] || $channel_acl['deny_gid'] ? 'lock' : 'unlock';
     require_once 'include/acl_selectors.php';
     $chatroom_new = '';
     if (local_channel()) {
         $chatroom_new = replace_macros(get_markup_template('chatroom_new.tpl'), array('$header' => t('New Chatroom'), '$name' => array('room_name', t('Chatroom name'), '', ''), '$chat_expire' => array('chat_expire', t('Expiration of chats (minutes)'), 120, ''), '$permissions' => t('Permissions'), '$acl' => populate_acl($channel_acl, false), '$lockstate' => $lockstate, '$submit' => t('Submit')));
     }
     $rooms = chatroom_list(\App::$profile['profile_uid']);
     $o .= replace_macros(get_markup_template('chatrooms.tpl'), array('$header' => sprintf(t('%1$s\'s Chatrooms'), \App::$profile['name']), '$name' => t('Name'), '$baseurl' => z_root(), '$nickname' => \App::$profile['channel_address'], '$rooms' => $rooms, '$norooms' => t('No chatrooms available'), '$newroom' => t('Create New'), '$is_owner' => local_channel() && local_channel() == \App::$profile['profile_uid'] ? 1 : 0, '$chatroom_new' => $chatroom_new, '$expire' => t('Expiration'), '$expire_unit' => t('min')));
     return $o;
 }
Example #3
0
File: nav.php Project: Mauru/red
/** @file */
function nav(&$a)
{
    /**
     *
     * Build page header and site navigation bars
     *
     */
    if (!x($a->page, 'nav')) {
        $a->page['nav'] = '';
    }
    $base = z_root();
    $a->page['htmlhead'] .= <<<EOT

<script>\$(document).ready(function() {
    var a;
    a = \$("#nav-search-text").autocomplete({
        serviceUrl: '{$base}/acl',
        minChars: 2,
        width: 250,
        id: 'nav-search-text-ac',
    });
    a.setOptions({ autoSubmit: true, params: { type: 'x' }});

});

</script>
EOT;
    if (local_user()) {
        $channel = $a->get_channel();
        $observer = $a->get_observer();
        $prof = q("select id from profile where uid = %d and is_default = 1", intval($channel['channel_id']));
        $chans = q("select channel_name, channel_id from channel where channel_account_id = %d and not ( channel_pageflags & %d ) order by channel_name ", intval(get_account_id()), intval(PAGE_REMOVED));
    } elseif (remote_user()) {
        $observer = $a->get_observer();
    }
    $myident = $channel ? $channel['xchan_addr'] : '';
    $sitelocation = $myident ? $myident : $a->get_hostname();
    /**
     *
     * Provide a banner/logo/whatever
     *
     */
    $banner = get_config('system', 'banner');
    if ($banner === false) {
        $banner = get_config('system', 'sitename');
    }
    $a->page['header'] .= replace_macros(get_markup_template('hdr.tpl'), array('$baseurl' => $a->get_baseurl(), '$sitelocation' => $sitelocation, '$banner' => $banner));
    // nav links: array of array('href', 'text', 'extra css classes', 'title')
    $nav = array();
    /**
     * Display login or logout
     */
    $nav['usermenu'] = array();
    $userinfo = null;
    if (local_user()) {
        if ($chans && count($chans) > 1 && feature_enabled(local_user(), 'nav_channel_select')) {
            $nav['channels'] = $chans;
        }
        $nav['logout'] = array('logout', t('Logout'), "", t('End this session'));
        // user menu
        $nav['usermenu'][] = array('channel/' . $channel['channel_address'], t('Home'), "", t('Your posts and conversations'));
        $nav['usermenu'][] = array('profile/' . $channel['channel_address'], t('View Profile'), "", t('Your profile page'));
        if (feature_enabled(local_user(), 'multi_profiles')) {
            $nav['usermenu'][] = array('profiles', t('Edit Profiles'), "", t('Manage/Edit profiles'));
        } else {
            $nav['usermenu'][] = array('profiles/' . $prof[0]['id'], t('Edit Profile'), "", t('Edit your profile'));
        }
        $nav['usermenu'][] = array('photos/' . $channel['channel_address'], t('Photos'), "", t('Your photos'));
        $nav['usermenu'][] = array('cloud/' . $channel['channel_address'], t('Files'), "", t('Your files'));
        require_once 'include/chat.php';
        $chats = chatroom_list(local_user());
        if (count($chats)) {
            $nav['usermenu'][] = array('chat/' . $channel['channel_address'], t('Chat'), "", t('Your chatrooms'));
        }
        $nav['usermenu'][] = array('bookmarks', t('Bookmarks'), "", t('Your bookmarks'));
        if (feature_enabled($channel['channel_id'], 'webpages')) {
            $nav['usermenu'][] = array('webpages/' . $channel['channel_address'], t('Webpages'), "", t('Your webpages'));
        }
    } else {
        if (!get_account_id()) {
            $nav['login'] = array('login', t('Login'), $a->module == 'login' ? 'selected' : '', t('Sign in'));
        } else {
            $nav['alogout'] = array('logout', t('Logout'), "", t('End this session'));
        }
    }
    if ($observer) {
        $userinfo = array('icon' => $observer['xchan_photo_m'], 'name' => $observer['xchan_addr']);
    }
    if ($observer) {
        $nav['locked'] = true;
        $nav['lock'] = array('logout', '', 'lock', sprintf(t('%s - click to logout'), $observer['xchan_addr']));
    } else {
        $nav['locked'] = false;
        $nav['lock'] = array('rmagic', '', 'unlock', t('Click to authenticate to your home hub'));
    }
    /**
     * "Home" should also take you home from an authenticated remote profile connection
     */
    $homelink = get_my_url();
    if (!$homelink) {
        $observer = $a->get_observer();
        $homelink = $observer ? $observer['xchan_url'] : '';
    }
    if ($a->module != 'home' && !local_user()) {
        $nav['home'] = array($homelink, t('Home'), "", t('Home Page'));
    }
    if ($a->config['system']['register_policy'] == REGISTER_OPEN && !local_user() && !remote_user()) {
        $nav['register'] = array('register', t('Register'), "", t('Create an account'));
    }
    $help_url = z_root() . '/help?f=&cmd=' . $a->cmd;
    if (!get_config('system', 'hide_help')) {
        $nav['help'] = array($help_url, t('Help'), "", t('Help and documentation'));
    }
    $nav['apps'] = array('apps', t('Apps'), "", t('Applications, utilities, links, games'));
    $nav['search'] = array('search', t('Search'), "", t('Search site content'));
    $nav['directory'] = array('directory', t('Directory'), "", t('Channel Locator'));
    /**
     *
     * The following nav links are only show to logged in users
     *
     */
    if (local_user()) {
        $nav['network'] = array('network', t('Matrix'), "", t('Your matrix'));
        $nav['network']['mark'] = array('', t('Mark all matrix notifications seen'), '', '');
        $nav['home'] = array('channel/' . $channel['channel_address'], t('Channel Home'), "", t('Channel home'));
        $nav['home']['mark'] = array('', t('Mark all channel notifications seen'), '', '');
        $nav['intros'] = array('connections/ifpending', t('Connections'), "", t('Connections'));
        $nav['notifications'] = array('notifications/system', t('Notices'), "", t('Notifications'));
        $nav['notifications']['all'] = array('notifications/system', t('See all notifications'), "", "");
        $nav['notifications']['mark'] = array('', t('Mark all system notifications seen'), '', '');
        $nav['messages'] = array('message', t('Mail'), "", t('Private mail'));
        $nav['messages']['all'] = array('message', t('See all private messages'), "", "");
        $nav['messages']['mark'] = array('', t('Mark all private messages seen'), '', '');
        $nav['messages']['inbox'] = array('message', t('Inbox'), "", t('Inbox'));
        $nav['messages']['outbox'] = array('message/sent', t('Outbox'), "", t('Outbox'));
        $nav['messages']['new'] = array('mail/new', t('New Message'), "", t('New Message'));
        $nav['all_events'] = array('events', t('Events'), "", t('Event Calendar'));
        $nav['all_events']['all'] = array('events', t('See all events'), "", "");
        $nav['all_events']['mark'] = array('', t('Mark all events seen'), '', '');
        $nav['manage'] = array('manage', t('Channel Manager'), "", t('Manage Your Channels'));
        $nav['settings'] = array('settings', t('Settings'), "", t('Account/Channel Settings'));
    }
    /**
     * Admin page
     */
    if (is_site_admin()) {
        $nav['admin'] = array('admin/', t('Admin'), "", t('Site Setup and Configuration'));
    }
    /**
     *
     * Provide a banner/logo/whatever
     *
     */
    $banner = get_config('system', 'banner');
    if ($banner === false) {
        $banner = get_config('system', 'sitename');
    }
    $x = array('nav' => $nav, 'usermenu' => $userinfo);
    call_hooks('nav', $x);
    $tpl = get_markup_template('nav.tpl');
    $a->page['nav'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$sitelocation' => $sitelocation, '$nav' => $x['nav'], '$banner' => $banner, '$emptynotifications' => t('Nothing new here'), '$userinfo' => $x['usermenu'], '$localuser' => local_user(), '$sel' => $a->nav_sel, '$pleasewait' => t('Please wait...')));
    call_hooks('page_header', $a->page['nav']);
}
Example #4
0
function profile_tabs($a, $is_owner = False, $nickname = Null)
{
    //echo "<pre>"; var_dump($a->user); killme();
    $channel = $a->get_channel();
    if (is_null($nickname)) {
        $nickname = $channel['channel_address'];
    }
    $uid = $a->profile['profile_uid'] ? $a->profile['profile_uid'] : local_user();
    if (get_pconfig($uid, 'system', 'noprofiletabs')) {
        return;
    }
    if (x($_GET, 'tab')) {
        $tab = notags(trim($_GET['tab']));
    }
    $url = $a->get_baseurl() . '/channel/' . $nickname;
    $pr = $a->get_baseurl() . '/profile/' . $nickname;
    $tabs = array(array('label' => t('Channel'), 'url' => $url, 'sel' => argv(0) == 'channel' ? 'active' : '', 'title' => t('Status Messages and Posts'), 'id' => 'status-tab'));
    $p = get_all_perms($uid, get_observer_hash());
    if ($p['view_profile']) {
        $tabs[] = array('label' => t('About'), 'url' => $pr, 'sel' => argv(0) == 'profile' ? 'active' : '', 'title' => t('Profile Details'), 'id' => 'profile-tab');
    }
    if ($p['view_photos']) {
        $tabs[] = array('label' => t('Photos'), 'url' => $a->get_baseurl() . '/photos/' . $nickname, 'sel' => argv(0) == 'photos' ? 'active' : '', 'title' => t('Photo Albums'), 'id' => 'photo-tab');
    }
    if ($p['view_storage']) {
        $tabs[] = array('label' => t('Files'), 'url' => $a->get_baseurl() . '/cloud/' . $nickname . (get_observer_hash() ? '' : '?f=&davguest=1'), 'sel' => argv(0) == 'cloud' ? 'active' : '', 'title' => t('Files and Storage'), 'id' => 'files-tab');
    }
    require_once 'include/chat.php';
    $chats = chatroom_list($uid);
    if (count($chats)) {
        $tabs[] = array('label' => t('Chatrooms'), 'url' => $a->get_baseurl() . '/chat/' . $nickname, 'sel' => argv(0) == 'chat' ? 'active' : '', 'title' => t('Chatrooms'), 'id' => 'chat-tab');
    }
    if ($is_owner) {
        $tabs[] = array('label' => t('Bookmarks'), 'url' => $a->get_baseurl() . '/bookmarks', 'sel' => argv(0) == 'bookmarks' ? 'active' : '', 'title' => t('Saved Bookmarks'), 'id' => 'bookmarks-tab');
    }
    if ($is_owner && feature_enabled($uid, 'webpages')) {
        $tabs[] = array('label' => t('Webpages'), 'url' => $a->get_baseurl() . '/webpages/' . $nickname, 'sel' => argv(0) == 'webpages' ? 'active' : '', 'title' => t('Manage Webpages'), 'id' => 'webpages-tab');
    } else {
        // FIXME
        // we probably need a listing of events that were created by
        // this channel and are visible to the observer
    }
    $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab ? $tab : false, 'tabs' => $tabs);
    call_hooks('profile_tabs', $arr);
    $tpl = get_markup_template('common_tabs.tpl');
    return replace_macros($tpl, array('$tabs' => $arr['tabs']));
}