/**
 * @brief Generate an Atom feed.
 *
 * @param array $channel
 * @param array $params
 */
function get_public_feed($channel, $params)
{
    $type = 'xml';
    $begin = NULL_DATE;
    $end = '';
    $start = 0;
    $records = 40;
    $direction = 'desc';
    $pages = 0;
    if (!$params) {
        $params = array();
    }
    $params['type'] = x($params, 'type') ? $params['type'] : 'xml';
    $params['begin'] = x($params, 'begin') ? $params['begin'] : NULL_DATE;
    $params['end'] = x($params, 'end') ? $params['end'] : datetime_convert('UTC', 'UTC', 'now');
    $params['start'] = x($params, 'start') ? $params['start'] : 0;
    $params['records'] = x($params, 'records') ? $params['records'] : 40;
    $params['direction'] = x($params, 'direction') ? $params['direction'] : 'desc';
    $params['pages'] = x($params, 'pages') ? intval($params['pages']) : 0;
    $params['top'] = x($params, 'top') ? intval($params['top']) : 0;
    $params['cat'] = x($params, 'cat') ? $params['cat'] : '';
    // put a sane lower limit on feed requests if not specified
    //	if($params['begin'] === NULL_DATE)
    //		$params['begin'] = datetime_convert('UTC','UTC','now - 1 month');
    switch ($params['type']) {
        case 'json':
            header("Content-type: application/atom+json");
            break;
        case 'xml':
        default:
            header("Content-type: application/atom+xml");
            break;
    }
    return get_feed_for($channel, get_observer_hash(), $params);
}
 function get()
 {
     $o = '';
     if (!\App::$profile['profile_uid']) {
         return;
     }
     $observer_hash = get_observer_hash();
     if (!perm_is_allowed(\App::$profile['profile_uid'], $observer_hash, 'view_contacts')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $o .= '<h2>' . t('Common connections') . '</h2>';
     $t = count_common_friends(\App::$profile['profile_uid'], $observer_hash);
     if (!$t) {
         notice(t('No connections in common.') . EOL);
         return $o;
     }
     $r = common_friends(\App::$profile['profile_uid'], $observer_hash);
     if ($r) {
         $tpl = get_markup_template('common_friends.tpl');
         foreach ($r as $rr) {
             $o .= replace_macros($tpl, array('$url' => $rr['xchan_url'], '$name' => $rr['xchan_name'], '$photo' => $rr['xchan_photo_m'], '$tags' => ''));
         }
         $o .= cleardiv();
     }
     return $o;
 }
Exemple #3
0
function menu_render($menu, $class = '', $edit = false, $var = array())
{
    if (!$menu) {
        return '';
    }
    $channel_id = is_array(App::$profile) ? App::$profile['profile_uid'] : 0;
    if (!$channel_id && local_channel()) {
        $channel_id = local_channel();
    }
    $menu_list = menu_list($channel_id);
    $menu_names = array();
    foreach ($menu_list as $menus) {
        if ($menus['menu_name'] != $menu['menu']['menu_name']) {
            $menu_names[] = $menus['menu_name'];
        }
    }
    for ($x = 0; $x < count($menu['items']); $x++) {
        if (in_array($menu['items'][$x]['mitem_link'], $menu_names)) {
            $m = menu_fetch($menu['items'][$x]['mitem_link'], $channel_id, get_observer_hash());
            $submenu = menu_render($m, 'dropdown-menu', $edit = false, array('wrap' => 'none'));
            $menu['items'][$x]['submenu'] = $submenu;
        }
        if ($menu['items'][$x]['mitem_flags'] & MENU_ITEM_ZID) {
            $menu['items'][$x]['mitem_link'] = zid($menu['items'][$x]['mitem_link']);
        }
        if ($menu['items'][$x]['mitem_flags'] & MENU_ITEM_NEWWIN) {
            $menu['items'][$x]['newwin'] = '1';
        }
        $menu['items'][$x]['mitem_desc'] = bbcode($menu['items'][$x]['mitem_desc']);
    }
    $wrap = $var['wrap'] === 'none' ? false : true;
    $ret = replace_macros(get_markup_template('usermenu.tpl'), array('$menu' => $menu['menu'], '$class' => $class, '$edit' => $edit ? t("Edit") : '', '$id' => $menu['menu']['menu_id'], '$items' => $menu['items'], '$wrap' => $wrap));
    return $ret;
}
Exemple #4
0
function bookmarks_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    require_once 'include/menu.php';
    require_once 'include/conversation.php';
    $channel = $a->get_channel();
    $o = profile_tabs($a, true, $channel['channel_address']);
    $o .= '<h3>' . t('My Bookmarks') . '</h3>';
    $x = menu_list(local_user(), '', MENU_BOOKMARK);
    if ($x) {
        foreach ($x as $xx) {
            $y = menu_fetch($xx['menu_name'], local_user(), get_observer_hash());
            $o .= menu_render($y, '', true);
        }
    }
    $o .= '<h3>' . t('My Connections Bookmarks') . '</h3>';
    $x = menu_list(local_user(), '', MENU_SYSTEM | MENU_BOOKMARK);
    if ($x) {
        foreach ($x as $xx) {
            $y = menu_fetch($xx['menu_name'], local_user(), get_observer_hash());
            $o .= menu_render($y, '', true);
        }
    }
    return $o;
}
Exemple #5
0
 function post()
 {
     // logger('file upload: ' . print_r($_REQUEST,true));
     $channel = $_REQUEST['channick'] ? get_channel_by_nick($_REQUEST['channick']) : null;
     if (!$channel) {
         logger('channel not found');
         killme();
     }
     $_REQUEST['source'] = 'file_upload';
     if ($channel['channel_id'] != local_channel()) {
         $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']);
         $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']);
         $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']);
         $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
     }
     if ($_REQUEST['filename']) {
         $_REQUEST['allow_cid'] = perms2str($_REQUEST['contact_allow']);
         $_REQUEST['allow_gid'] = perms2str($_REQUEST['group_allow']);
         $_REQUEST['deny_cid'] = perms2str($_REQUEST['contact_deny']);
         $_REQUEST['deny_gid'] = perms2str($_REQUEST['group_deny']);
         $r = attach_mkdir($channel, get_observer_hash(), $_REQUEST);
     } else {
         $r = attach_store($channel, get_observer_hash(), '', $_REQUEST);
     }
     goaway(z_root() . '/' . $_REQUEST['return_url']);
 }
Exemple #6
0
 function init()
 {
     if (!is_dir('store')) {
         os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false);
     }
     $which = null;
     if (argc() > 1) {
         $which = argv(1);
     }
     $profile = 0;
     \App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n";
     if ($which) {
         profile_load($which, $profile);
     }
     $auth = new \Zotlabs\Storage\BasicAuth();
     $ob_hash = get_observer_hash();
     if ($ob_hash) {
         if (local_channel()) {
             $channel = \App::get_channel();
             $auth->setCurrentUser($channel['channel_address']);
             $auth->channel_id = $channel['channel_id'];
             $auth->channel_hash = $channel['channel_hash'];
             $auth->channel_account_id = $channel['channel_account_id'];
             if ($channel['channel_timezone']) {
                 $auth->setTimezone($channel['channel_timezone']);
             }
         }
         $auth->observer = $ob_hash;
     }
     if ($_GET['davguest']) {
         $_SESSION['davguest'] = true;
     }
     $_SERVER['QUERY_STRING'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['QUERY_STRING']);
     $_SERVER['QUERY_STRING'] = strip_zids($_SERVER['QUERY_STRING']);
     $_SERVER['QUERY_STRING'] = preg_replace('/[\\?&]davguest=(.*?)([\\?&]|$)/ism', '', $_SERVER['QUERY_STRING']);
     $_SERVER['REQUEST_URI'] = str_replace(array('?f=', '&f='), array('', ''), $_SERVER['REQUEST_URI']);
     $_SERVER['REQUEST_URI'] = strip_zids($_SERVER['REQUEST_URI']);
     $_SERVER['REQUEST_URI'] = preg_replace('/[\\?&]davguest=(.*?)([\\?&]|$)/ism', '', $_SERVER['REQUEST_URI']);
     $rootDirectory = new \Zotlabs\Storage\Directory('/', $auth);
     // A SabreDAV server-object
     $server = new SDAV\Server($rootDirectory);
     // prevent overwriting changes each other with a lock backend
     $lockBackend = new SDAV\Locks\Backend\File('store/[data]/locks');
     $lockPlugin = new SDAV\Locks\Plugin($lockBackend);
     $server->addPlugin($lockPlugin);
     $is_readable = false;
     // provide a directory view for the cloud in Hubzilla
     $browser = new \Zotlabs\Storage\Browser($auth);
     $auth->setBrowserPlugin($browser);
     $server->addPlugin($browser);
     // Experimental QuotaPlugin
     //	require_once('\Zotlabs\Storage/QuotaPlugin.php');
     //	$server->addPlugin(new \Zotlabs\Storage\\QuotaPlugin($auth));
     ob_start();
     // All we need to do now, is to fire up the server
     $server->exec();
     ob_end_flush();
     killme();
 }
Exemple #7
0
function comanche_menu($name, $class = '')
{
    $channel_id = comanche_get_channel_id();
    if ($channel_id) {
        $m = menu_fetch($name, $channel_id, get_observer_hash());
        return menu_render($m, $class);
    }
}
 function get()
 {
     if (!\App::$profile) {
         notice(t('Requested profile is not available.') . EOL);
         \App::$error = 404;
         return;
     }
     $which = argv(1);
     $uid = local_channel();
     $owner = 0;
     $channel = null;
     $observer = \App::get_observer();
     $channel = \App::get_channel();
     if (\App::$is_sys && is_site_admin()) {
         $sys = get_sys_channel();
         if ($sys && intval($sys['channel_id'])) {
             $uid = $owner = intval($sys['channel_id']);
             $channel = $sys;
             $observer = $sys;
         }
     }
     if (!$owner) {
         // Figure out who the page owner is.
         $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
         if ($r) {
             $owner = intval($r[0]['channel_id']);
         }
     }
     $ob_hash = $observer ? $observer['xchan_hash'] : '';
     if (!perm_is_allowed($owner, $ob_hash, 'write_pages')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $is_owner = $uid && $uid == $owner ? true : false;
     $o = '';
     // Figure out which post we're editing
     $post_id = argc() > 2 ? intval(argv(2)) : 0;
     if (!($post_id && $owner)) {
         notice(t('Item not found') . EOL);
         return;
     }
     $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", intval($post_id), intval($owner));
     if ($itm) {
         $item_id = q("select * from item_id where service = 'BUILDBLOCK' and iid = %d limit 1", intval($itm[0]['id']));
         if ($item_id) {
             $block_title = $item_id[0]['sid'];
         }
     } else {
         notice(t('Item not found') . EOL);
         return;
     }
     $mimetype = $itm[0]['mimetype'];
     $rp = 'blocks/' . $channel['channel_address'];
     $x = array('nickname' => $channel['channel_address'], 'bbco_autocomplete' => $mimetype == 'text/bbcode' ? 'bbcode' : 'comanche-block', 'return_path' => $rp, 'webpage' => ITEM_TYPE_BLOCK, 'ptlabel' => t('Block Name'), 'button' => t('Edit'), 'writefiles' => $mimetype == 'text/bbcode' ? perm_is_allowed($owner, get_observer_hash(), 'write_storage') : false, 'weblink' => $mimetype == 'text/bbcode' ? t('Insert web link') : false, 'hide_voting' => true, 'hide_future' => true, 'hide_location' => true, 'hide_expire' => true, 'showacl' => false, 'ptyp' => $itm[0]['type'], 'mimeselect' => true, 'mimetype' => $itm[0]['mimetype'], 'body' => undo_post_tagging($itm[0]['body']), 'post_id' => $post_id, 'visitor' => true, 'title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), 'placeholdertitle' => t('Title (optional)'), 'pagetitle' => $block_title, 'profile_uid' => intval($channel['channel_id']), 'bbcode' => $mimetype == 'text/bbcode' ? true : false);
     $editor = status_editor($a, $x);
     $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit Block'), '$delete' => $itm[0]['author_xchan'] === $ob_hash || $itm[0]['owner_xchan'] === $ob_hash ? t('Delete') : false, '$id' => $itm[0]['id'], '$editor' => $editor));
     return $o;
 }
function viewconnections_content(&$a)
{
    if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    if (!count($a->profile) || $a->profile['hide_friends']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (!perm_is_allowed($a->profile['uid'], get_observer_hash(), 'view_contacts')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (!$_REQUEST['aj']) {
        $_SESSION['return_url'] = $a->query_string;
    }
    $is_owner = local_channel() && local_channel() == $a->profile['uid'] ? true : false;
    $abook_flags = ABOOK_FLAG_PENDING | ABOOK_FLAG_SELF;
    $xchan_flags = XCHAN_FLAGS_ORPHAN | XCHAN_FLAGS_DELETED;
    if (!$is_owner) {
        $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN;
        $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN;
    }
    $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not (abook_flags & %d )>0 and not ( xchan_flags & %d )>0 ", intval($a->profile['uid']), intval($abook_flags), intval($xchan_flags));
    if ($r) {
        $a->set_pager_total($r[0]['total']);
    }
    $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not ( abook_flags & %d )>0 and not ( xchan_flags & %d )>0 order by xchan_name LIMIT %d OFFSET %d ", intval($a->profile['uid']), intval($abook_flags), intval($xchan_flags), intval($a->pager['itemspage']), intval($a->pager['start']));
    if (!$r && !$_REQUEST['aj']) {
        info(t('No connections.') . EOL);
        return $o;
    }
    $contacts = array();
    foreach ($r as $rr) {
        $url = chanlink_url($rr['xchan_url']);
        if ($url) {
            $contacts[] = array('id' => $rr['abook_id'], 'archived' => $rr['abook_flags'] & ABOOK_FLAG_ARCHIVED ? true : false, 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['xchan_name'], $rr['xchan_url']), 'thumb' => $rr['xchan_photo_m'], 'name' => substr($rr['xchan_name'], 0, 20), 'username' => $rr['xchan_addr'], 'link' => $url, 'sparkle' => '', 'itemurl' => $rr['url'], 'network' => '');
        }
    }
    if ($_REQUEST['aj']) {
        if ($contacts) {
            $o = replace_macros(get_markup_template('viewcontactsajax.tpl'), array('$contacts' => $contacts));
        } 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>";
        $tpl = get_markup_template("viewcontact_template.tpl");
        $o .= replace_macros($tpl, array('$title' => t('View Connections'), '$contacts' => $contacts));
    }
    if (!$contacts) {
        $o .= '<div id="content-complete"></div>';
    }
    return $o;
}
 function get()
 {
     if (observer_prohibited()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     if (!count(\App::$profile) || \App::$profile['hide_friends']) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!perm_is_allowed(\App::$profile['uid'], get_observer_hash(), 'view_contacts')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     if (!$_REQUEST['aj']) {
         $_SESSION['return_url'] = \App::$query_string;
     }
     $is_owner = local_channel() && local_channel() == \App::$profile['uid'] ? true : false;
     $abook_flags = " and abook_pending = 0 and abook_self = 0 ";
     $sql_extra = '';
     if (!$is_owner) {
         $abook_flags = " and abook_hidden = 0 ";
         $sql_extra = " and xchan_hidden = 0 ";
     }
     $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d {$abook_flags} and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra} ", intval(\App::$profile['uid']));
     if ($r) {
         \App::set_pager_total($r[0]['total']);
     }
     $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d {$abook_flags} and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra} order by xchan_name LIMIT %d OFFSET %d ", intval(\App::$profile['uid']), intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     if (!$r && !$_REQUEST['aj']) {
         info(t('No connections.') . EOL);
         return $o;
     }
     $contacts = array();
     foreach ($r as $rr) {
         $url = chanlink_url($rr['xchan_url']);
         if ($url) {
             $contacts[] = array('id' => $rr['abook_id'], 'archived' => intval($rr['abook_archived']) ? true : false, 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['xchan_name'], $rr['xchan_url']), 'thumb' => $rr['xchan_photo_m'], 'name' => substr($rr['xchan_name'], 0, 20), 'username' => $rr['xchan_addr'], 'link' => $url, 'sparkle' => '', 'itemurl' => $rr['url'], 'network' => '');
         }
     }
     if ($_REQUEST['aj']) {
         if ($contacts) {
             $o = replace_macros(get_markup_template('viewcontactsajax.tpl'), array('$contacts' => $contacts));
         } 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>";
         $tpl = get_markup_template("viewcontact_template.tpl");
         $o .= replace_macros($tpl, array('$title' => t('View Connections'), '$contacts' => $contacts));
     }
     if (!$contacts) {
         $o .= '<div id="content-complete"></div>';
     }
     return $o;
 }
 function get()
 {
     $o = '';
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $post_id = argc() > 1 ? intval(argv(1)) : 0;
     if (!$post_id) {
         notice(t('Item not found') . EOL);
         return;
     }
     $itm = q("SELECT * FROM `item` WHERE `id` = %d AND ( owner_xchan = '%s' OR author_xchan = '%s' ) LIMIT 1", intval($post_id), dbesc(get_observer_hash()), dbesc(get_observer_hash()));
     if (!count($itm)) {
         notice(t('Item is not editable') . EOL);
         return;
     }
     if ($itm[0]['resource_type'] === 'event' && $itm[0]['resource_id']) {
         goaway(z_root() . '/events/' . $itm[0]['resource_id'] . '?expandform=1');
     }
     $owner_uid = $itm[0]['uid'];
     $channel = \App::get_channel();
     if (intval($itm[0]['item_obscured'])) {
         $key = get_config('system', 'prvkey');
         if ($itm[0]['title']) {
             $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']), $key);
         }
         if ($itm[0]['body']) {
             $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']), $key);
         }
     }
     $category = '';
     $catsenabled = feature_enabled($owner_uid, 'categories') ? 'categories' : '';
     if ($catsenabled) {
         $itm = fetch_post_tags($itm);
         $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
         foreach ($cats as $cat) {
             if (strlen($category)) {
                 $category .= ', ';
             }
             $category .= $cat['term'];
         }
     }
     if ($itm[0]['attach']) {
         $j = json_decode($itm[0]['attach'], true);
         if ($j) {
             foreach ($j as $jj) {
                 $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n";
             }
         }
     }
     $x = array('nickname' => $channel['channel_address'], 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'return_path' => $_SESSION['return_url'], 'button' => t('Edit'), 'hide_voting' => true, 'hide_future' => true, 'hide_location' => true, 'mimetype' => $itm[0]['mimetype'], 'ptyp' => $itm[0]['obj_type'], 'body' => undo_post_tagging($itm[0]['body']), 'post_id' => $post_id, 'defloc' => $channel['channel_location'], 'visitor' => true, 'title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), 'category' => $category, 'showacl' => false, 'profile_uid' => $owner_uid, 'catsenabled' => $catsenabled, 'hide_expire' => true, 'bbcode' => true);
     $editor = status_editor($a, $x);
     $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit post'), '$editor' => $editor));
     return $o;
 }
Exemple #12
0
function editlayout_content(&$a)
{
    // We first need to figure out who owns the webpage, grab it from an argument
    $which = argv(1);
    // $a->get_channel() and stuff don't work here, so we've got to find the owner for ourselves.
    $r = q("select channel_id from channel where channel_address = '%s'", dbesc($which));
    if ($r) {
        $owner = intval($r[0]['channel_id']);
        //logger('owner: ' . print_r($owner,true));
    }
    if (local_user() && argc() > 2 && argv(2) === 'view') {
        $which = $channel['channel_address'];
    }
    $o = '';
    // Figure out which post we're editing
    $post_id = argc() > 2 ? intval(argv(2)) : 0;
    if (!$post_id) {
        notice(t('Item not found') . EOL);
        return;
    }
    // Now we've got a post and an owner, let's find out if we're allowed to edit it
    $observer = $a->get_observer();
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($owner, $ob_hash);
    if (!$perms['write_pages']) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    // We've already figured out which item we want and whose copy we need, so we don't need anything fancy here
    $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", intval($post_id), intval($owner));
    $item_id = q("select * from item_id where service = 'PDL' and iid = %d limit 1", $itm[0]['id']);
    if ($item_id) {
        $layout_title = $item_id[0]['sid'];
    }
    $plaintext = true;
    // You may or may not be a local user.  This won't work,
    //	if(feature_enabled(local_user(),'richtext'))
    //		$plaintext = false;
    $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit Layout')));
    $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : '/(profile-jot-text|prvmail-text)/', '$ispublic' => '&nbsp;', '$geotag' => $geotag, '$nickname' => $a->user['nickname'], '$confirmdelete' => t('Delete layout?')));
    $tpl = get_markup_template("jot.tpl");
    $jotplugins = '';
    $jotnets = '';
    call_hooks('jot_tool', $jotplugins);
    call_hooks('jot_networks', $jotnets);
    $channel = $a->get_channel();
    //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
    //FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD instead of loading a sensible page.  So, send folk to the webpage list.
    $rp = '/layouts/' . $which;
    $o .= replace_macros($tpl, array('$return_path' => $rp, '$action' => 'item', '$webpage' => ITEM_PDL, '$share' => t('Edit'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$weblink' => t('Insert web link'), '$youtube' => t('Insert YouTube video'), '$video' => t('Insert Vorbis [.ogg] video'), '$audio' => t('Insert Vorbis [.ogg] audio'), '$setloc' => t('Set your location'), '$noloc' => t('Clear browser location'), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$baseurl' => $a->get_baseurl(), '$defloc' => $channel['channel_location'], '$visitor' => false, '$public' => t('Public post'), '$jotnets' => $jotnets, '$title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'), '$placeholdertitle' => t('Set title'), '$pagetitle' => $layout_title, '$category' => '', '$placeholdercategory' => t('Categories (comma-separated list)'), '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', '$bang' => '', '$profile_uid' => intval($owner), '$preview' => feature_enabled(local_user(), 'preview') ? t('Preview') : '', '$jotplugins' => $jotplugins, '$sourceapp' => t($a->sourcename), '$defexpire' => '', '$feature_expire' => false, '$expires' => t('Set expiration date')));
    $ob = get_observer_hash();
    if ($itm[0]['author_xchan'] === $ob || $itm[0]['owner_xchan'] === $ob) {
        $o .= '<br /><br /><a class="layout-delete-link" href="item/drop/' . $itm[0]['id'] . '" >' . t('Delete Layout') . '</a><br />';
    }
    return $o;
}
 /**
  * The DAV browser is instantiated after the auth module and directory classes
  * but before we know the current directory and who the owner and observer
  * are. So we add a pointer to the browser into the auth module and vice versa.
  * Then when we've figured out what directory is actually being accessed, we
  * call the following function to decide whether or not to show web elements
  * which include writeable objects.
  *
  * @fixme It only disable/enable the visible parts. Not the POST handler
  * which handels the actual requests when uploading files or creating folders.
  *
  * @todo Maybe this whole way of doing this can be solved with some
  * $server->subscribeEvent().
  */
 public function set_writeable()
 {
     if (!$this->auth->owner_id) {
         $this->enablePost = false;
     }
     if (!perm_is_allowed($this->auth->owner_id, get_observer_hash(), 'write_storage')) {
         $this->enablePost = false;
     } else {
         $this->enablePost = true;
     }
 }
 function get()
 {
     $status = strip_tags($_REQUEST['status']);
     $room_id = intval(\App::$data['chat']['room_id']);
     $stopped = x($_REQUEST, 'stopped') && intval($_REQUEST['stopped']) ? true : false;
     if ($status && $room_id) {
         $x = q("select channel_address from channel where channel_id = %d limit 1", intval(\App::$data['chat']['uid']));
         $r = q("update chatpresence set cp_status = '%s', cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s'", dbesc($status), dbesc(datetime_convert()), intval($room_id), dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']));
         goaway(z_root() . '/chat/' . $x[0]['channel_address'] . '/' . $room_id);
     }
     if (!$stopped) {
         $lastseen = intval($_REQUEST['last']);
         $ret = array('success' => false);
         $sql_extra = permissions_sql(\App::$data['chat']['uid']);
         $r = q("select * from chatroom where cr_uid = %d and cr_id = %d {$sql_extra}", intval(\App::$data['chat']['uid']), intval(\App::$data['chat']['room_id']));
         if (!$r) {
             json_return_and_die($ret);
         }
         $inroom = array();
         $r = q("select * from chatpresence left join xchan on xchan_hash = cp_xchan where cp_room = %d order by xchan_name", intval(\App::$data['chat']['room_id']));
         if ($r) {
             foreach ($r as $rr) {
                 switch ($rr['cp_status']) {
                     case 'away':
                         $status = t('Away');
                         $status_class = 'away';
                         break;
                     case 'online':
                     default:
                         $status = t('Online');
                         $status_class = 'online';
                         break;
                 }
                 $inroom[] = array('img' => zid($rr['xchan_photo_m']), 'img_type' => $rr['xchan_photo_mimetype'], 'name' => $rr['xchan_name'], 'status' => $status, 'status_class' => $status_class);
             }
         }
         $chats = array();
         $r = q("select * from chat left join xchan on chat_xchan = xchan_hash where chat_room = %d and chat_id > %d order by created", intval(\App::$data['chat']['room_id']), intval($lastseen));
         if ($r) {
             foreach ($r as $rr) {
                 $chats[] = array('id' => $rr['chat_id'], 'img' => zid($rr['xchan_photo_m']), 'img_type' => $rr['xchan_photo_mimetype'], 'name' => $rr['xchan_name'], 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'r'), 'text' => smilies(bbcode($rr['chat_text'])), 'self' => get_observer_hash() == $rr['chat_xchan'] ? 'self' : '');
             }
         }
     }
     $r = q("update chatpresence set cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s'", dbesc(datetime_convert()), intval(\App::$data['chat']['room_id']), dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']));
     $ret['success'] = true;
     if (!$stopped) {
         $ret['inroom'] = $inroom;
         $ret['chats'] = $chats;
     }
     json_return_and_die($ret);
 }
Exemple #15
0
function menu_content(&$a)
{
    $uid = local_channel();
    if ($a->is_sys && is_site_admin()) {
        $sys = get_sys_channel();
        $uid = intval($sys['channel_id']);
    }
    if (!$uid) {
        notice(t('Permission denied.') . EOL);
        return '';
    }
    if (argc() == 1) {
        // list menus
        $x = menu_list($uid);
        if ($x) {
            for ($y = 0; $y < count($x); $y++) {
                $m = menu_fetch($x[$y]['menu_name'], $uid, get_observer_hash());
                if ($m) {
                    $x[$y]['element'] = '[element]' . base64url_encode(json_encode(menu_element($m))) . '[/element]';
                }
                $x[$y]['bookmark'] = $x[$y]['menu_flags'] & MENU_BOOKMARK ? true : false;
            }
        }
        $create = replace_macros(get_markup_template('menuedit.tpl'), array('$menu_name' => array('menu_name', t('Menu Name'), '', t('Unique name (not visible on webpage) - required'), '*'), '$menu_desc' => array('menu_desc', t('Menu Title'), '', t('Visible on webpage - leave empty for no title'), ''), '$menu_bookmark' => array('menu_bookmark', t('Allow Bookmarks'), 0, t('Menu may be used to store saved bookmarks'), array(t('No'), t('Yes'))), '$submit' => t('Submit and proceed'), '$sys' => $a->is_sys, '$display' => 'none'));
        $o = replace_macros(get_markup_template('menulist.tpl'), array('$title' => t('Menus'), '$create' => $create, '$menus' => $x, '$nametitle' => t('Menu Name'), '$desctitle' => t('Menu Title'), '$edit' => t('Edit'), '$drop' => t('Drop'), '$created' => t('Created'), '$edited' => t('Edited'), '$new' => t('New'), '$bmark' => t('Bookmarks allowed'), '$hintnew' => t('Create'), '$hintdrop' => t('Delete this menu'), '$hintcontent' => t('Edit menu contents'), '$hintedit' => t('Edit this menu'), '$sys' => $a->is_sys));
        return $o;
    }
    if (argc() > 1) {
        if (intval(argv(1))) {
            if (argc() == 3 && argv(2) == 'drop') {
                menu_sync_packet($uid, get_observer_hash(), intval(argv(1)), true);
                $r = menu_delete_id(intval(argv(1)), $uid);
                if (!$r) {
                    notice(t('Menu could not be deleted.') . EOL);
                }
                goaway(z_root() . '/menu' . ($a->is_sys ? '?f=&sys=1' : ''));
            }
            $m = menu_fetch_id(intval(argv(1)), $uid);
            if (!$m) {
                notice(t('Menu not found.') . EOL);
                return '';
            }
            $o = replace_macros(get_markup_template('menuedit.tpl'), array('$header' => t('Edit Menu'), '$sys' => $a->is_sys, '$menu_id' => intval(argv(1)), '$menu_edit_link' => 'mitem/' . intval(argv(1)) . ($a->is_sys ? '?f=&sys=1' : ''), '$hintedit' => t('Add or remove entries to this menu'), '$editcontents' => t('Edit menu contents'), '$menu_name' => array('menu_name', t('Menu name'), $m['menu_name'], t('Must be unique, only seen by you'), '*'), '$menu_desc' => array('menu_desc', t('Menu title'), $m['menu_desc'], t('Menu title as seen by others'), ''), '$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), $m['menu_flags'] & MENU_BOOKMARK ? 1 : 0, t('Menu may be used to store saved bookmarks'), array(t('No'), t('Yes'))), '$menu_system' => $m['menu_flags'] & MENU_SYSTEM ? 1 : 0, '$submit' => t('Submit and proceed')));
            return $o;
        } else {
            notice(t('Not found.') . EOL);
            return;
        }
    }
}
Exemple #16
0
function wall_attach_post(&$a)
{
    if (argc() > 1) {
        $channel = get_channel_by_nick(argv(1));
    } else {
        killme();
    }
    $r = attach_store($channel, get_observer_hash());
    if (!$r['success']) {
        notice($r['message'] . EOL);
        killme();
    }
    echo "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
    killme();
}
Exemple #17
0
function common_friends_visitor_widget($profile_uid)
{
    if (local_channel() == $profile_uid) {
        return;
    }
    $observer_hash = get_observer_hash();
    if (!$observer_hash || !perm_is_allowed($profile_uid, $observer_hash, 'view_contacts')) {
        return;
    }
    require_once 'include/socgraph.php';
    $t = count_common_friends($profile_uid, $observer_hash);
    if (!$t) {
        return;
    }
    $r = common_friends($profile_uid, $observer_hash, 0, 5, true);
    return replace_macros(get_markup_template('remote_friends_common.tpl'), array('$desc' => sprintf(tt("%d connection in common", "%d connections in common", $t), $t), '$base' => z_root(), '$uid' => $profile_uid, '$cid' => $observer, '$linkmore' => $t > 5 ? 'true' : '', '$more' => t('show more'), '$items' => $r));
}
Exemple #18
0
function dir_safe_mode()
{
    $observer = get_observer_hash();
    if (!$observer) {
        return;
    }
    if ($observer) {
        $safe_mode = get_xconfig($observer, 'directory', 'safe_mode');
    }
    if ($safe_mode === '0') {
        $toggle = t('Enable Safe Search');
    } else {
        $toggle = t('Disable Safe Search');
    }
    $o = replace_macros(get_markup_template('safesearch.tpl'), array('$safemode' => t('Safe Mode'), '$toggle' => $toggle));
    return $o;
}
Exemple #19
0
function mitem_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return '';
    }
    if (argc() < 2 || !$a->data['menu']) {
        notice(t('Not found.') . EOL);
        return '';
    }
    $channel = $a->get_channel();
    $m = menu_fetch($a->data['menu']['menu_name'], local_user(), get_observer_hash());
    $a->data['menu_item'] = $m;
    if (argc() == 2) {
        $r = q("select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d order by mitem_order asc, mitem_desc asc", intval($a->data['menu']['menu_id']), local_user());
        $o .= replace_macros(get_markup_template('mitemlist.tpl'), array('$title' => t('Manage Menu Elements'), '$menuname' => $a->data['menu']['menu_name'], '$menudesc' => $a->data['menu']['menu_desc'], '$edmenu' => t('Edit menu'), '$menu_id' => $a->data['menu']['menu_id'], '$mlist' => $r, '$edit' => t('Edit element'), '$drop' => t('Drop element'), '$new' => t('New element'), '$hintmenu' => t('Edit this menu container'), '$hintnew' => t('Add menu element'), '$hintdrop' => t('Delete this menu item'), '$hintedit' => t('Edit this menu item')));
        return $o;
    }
    if (argc() > 2) {
        if (argv(2) === 'new') {
            $perm_defaults = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
            $o = replace_macros(get_markup_template('mitemedit.tpl'), array('$header' => t('New Menu Element'), '$menu_id' => $a->data['menu']['menu_id'], '$permissions' => t('Menu Item Permissions'), '$permdesc' => t("(click to open/close)"), '$aclselect' => populate_acl($perm_defaults, false), '$mitem_desc' => array('mitem_desc', t('Link text'), '', '', '*'), '$mitem_link' => array('mitem_link', t('URL of link'), '', '', '*'), '$usezid' => array('usezid', t('Use Red magic-auth if available'), true, ''), '$newwin' => array('newwin', t('Open link in new window'), false, ''), '$mitem_order' => array('mitem_order', t('Order in list'), '0', t('Higher numbers will sink to bottom of listing')), '$submit' => t('Create')));
            return $o;
        } elseif (intval(argv(2))) {
            $m = q("select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1", intval(argv(2)), intval(local_user()));
            if (!$m) {
                notice(t('Menu item not found.') . EOL);
                goaway(z_root() . '/menu');
            }
            $mitem = $m[0];
            if (argc() == 4 && argv(3) == 'drop') {
                $r = menu_del_item($mitem['mitem_menu_id'], local_user(), intval(argv(2)));
                if ($r) {
                    info(t('Menu item deleted.') . EOL);
                } else {
                    notice(t('Menu item could not be deleted.') . EOL);
                }
                goaway(z_root() . '/mitem/' . $mitem['mitem_menu_id']);
            } else {
                // edit menu item
                $o = replace_macros(get_markup_template('mitemedit.tpl'), array('$header' => t('Edit Menu Element'), '$menu_id' => $a->data['menu']['menu_id'], '$permissions' => t('Menu Item Permissions'), '$permdesc' => t("(click to open/close)"), '$aclselect' => populate_acl($mitem, false), '$mitem_id' => intval(argv(2)), '$mitem_desc' => array('mitem_desc', t('Link text'), $mitem['mitem_desc'], '', '*'), '$mitem_link' => array('mitem_link', t('URL of link'), $mitem['mitem_link'], '', '*'), '$usezid' => array('usezid', t('Use Red magic-auth if available'), $mitem['mitem_flags'] & MENU_ITEM_ZID ? 1 : 0, ''), '$newwin' => array('newwin', t('Open link in new window'), $mitem['mitem_flags'] & MENU_ITEM_NEWWIN ? 1 : 0, ''), '$mitem_order' => array('mitem_order', t('Order in list'), $mitem['mitem_order'], t('Higher numbers will sink to bottom of listing')), '$submit' => t('Modify')));
                return $o;
            }
        }
    }
}
Exemple #20
0
function tagadelic($uid, $count = 0, $authors = '', $flags = 0, $restrict = 0, $type = TERM_HASHTAG)
{
    require_once 'include/security.php';
    if (!perm_is_allowed($uid, get_observer_hash(), 'view_stream')) {
        return array();
    }
    $sql_options = item_permissions_sql($uid);
    $count = intval($count);
    if ($flags) {
        $sql_options .= " and ((item_flags & " . intval($flags) . ") = " . intval($flags) . ") ";
    }
    if ($authors) {
        if (!is_array($authors)) {
            $authors = array($authors);
        }
        stringify_array_elms($authors, true);
        $sql_options .= " and author_xchan in (" . implode(',', $authors) . ") ";
    }
    // Fetch tags
    $r = q("select term, count(term) as total from term left join item on term.oid = item.id\n\t\twhere term.uid = %d and term.type = %d \n\t\tand otype = %d and item_restrict = %d\n\t\t{$sql_options}\n\t\tgroup by term order by total desc %s", intval($uid), intval($type), intval(TERM_OBJ_POST), intval($restrict), intval($count) ? "limit {$count}" : '');
    if (!$r) {
        return array();
    }
    // Find minimum and maximum log-count.
    $tags = array();
    $min = 1000000000.0;
    $max = -1000000000.0;
    $x = 0;
    foreach ($r as $rr) {
        $tags[$x][0] = $rr['term'];
        $tags[$x][1] = log($rr['total']);
        $tags[$x][2] = 0;
        $min = min($min, $tags[$x][1]);
        $max = max($max, $tags[$x][1]);
        $x++;
    }
    usort($tags, 'tags_sort');
    $range = max(0.01, $max - $min) * 1.0001;
    for ($x = 0; $x < count($tags); $x++) {
        $tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range);
    }
    return $tags;
}
Exemple #21
0
function block_content(&$a)
{
    if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_pages')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (argc() < 3) {
        notice(t('Invalid item.') . EOL);
        return;
    }
    $channel_address = argv(1);
    $page_id = argv(2);
    $u = q("select channel_id from channel where channel_address = '%s' limit 1", dbesc($channel_address));
    if (!$u) {
        notice(t('Channel not found.') . EOL);
        return;
    }
    if ($_REQUEST['rev']) {
        $revision = " and revision = " . intval($_REQUEST['rev']) . " ";
    } else {
        $revision = " order by revision desc ";
    }
    require_once 'include/security.php';
    $sql_options = item_permissions_sql($u[0]['channel_id']);
    $r = q("select item.* from item left join item_id on item.id = item_id.iid\n\t\twhere item.uid = %d and sid = '%s' and service = 'BUILDBLOCK' and \n\t\titem_type = %d {$sql_options} {$revision} limit 1", intval($u[0]['channel_id']), dbesc($page_id), intval(ITEM_TYPE_BLOCK));
    if (!$r) {
        // Check again with no permissions clause to see if it is a permissions issue
        $x = q("select item.* from item left join item_id on item.id = item_id.iid\n\t\twhere item.uid = %d and sid = '%s' and service = 'BUILDBLOCK' and \n\t\titem_type = %d {$revision} limit 1", intval($u[0]['channel_id']), dbesc($page_id), intval(ITEM_TYPE_BLOCK));
        if ($x) {
            // Yes, it's there. You just aren't allowed to see it.
            notice(t('Permission denied.') . EOL);
        } else {
            notice(t('Page not found.') . EOL);
        }
        return;
    }
    xchan_query($r);
    $r = fetch_post_tags($r, true);
    $o .= prepare_page($r[0]);
    return $o;
}
Exemple #22
0
function viewconnections_content(&$a)
{
    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;
    }
    if (!perm_is_allowed($a->profile['uid'], get_observer_hash(), 'view_contacts')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $is_owner = local_user() && local_user() == $a->profile['uid'] ? true : false;
    $abook_flags = ABOOK_FLAG_PENDING | ABOOK_FLAG_SELF;
    $xchan_flags = XCHAN_FLAGS_ORPHAN | XCHAN_FLAGS_DELETED;
    if (!$is_owner) {
        $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN;
        $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN;
    }
    $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not (abook_flags & %d ) and not ( xchan_flags & %d ) ", intval($a->profile['uid']), intval($abook_flags), intval($xchan_flags));
    if ($r) {
        $a->set_pager_total($r[0]['total']);
    }
    $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not ( abook_flags & %d ) and not ( xchan_flags & %d ) order by xchan_name LIMIT %d , %d ", intval($a->profile['uid']), intval($abook_flags), intval($xchan_flags), intval($a->pager['start']), intval($a->pager['itemspage']));
    if (!$r) {
        info(t('No connections.') . EOL);
        return $o;
    }
    $contacts = array();
    foreach ($r as $rr) {
        $url = chanlink_url($rr['xchan_url']);
        if ($url) {
            $contacts[] = array('id' => $rr['abook_id'], 'archived' => $rr['abook_flags'] & ABOOK_FLAG_ARCHIVED ? true : false, 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $rr['xchan_name'], $rr['xchan_url']), 'thumb' => $rr['xchan_photo_m'], 'name' => substr($rr['xchan_name'], 0, 20), 'username' => $rr['xchan_addr'], 'link' => $url, 'sparkle' => '', 'itemurl' => $rr['url'], 'network' => '');
        }
    }
    $tpl = get_markup_template("viewcontact_template.tpl");
    $o .= replace_macros($tpl, array('$title' => t('View Connnections'), '$contacts' => $contacts, '$paginate' => paginate($a)));
    return $o;
}
Exemple #23
0
 function get()
 {
     $o = '';
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $_SESSION['return_url'] = z_root() . '/' . \App::$cmd;
     $r = suggestion_query(local_channel(), get_observer_hash());
     if (!$r) {
         info(t('No suggestions available. If this is a new site, please try again in 24 hours.'));
         return;
     }
     $arr = array();
     foreach ($r as $rr) {
         $connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr'];
         $arr[] = array('url' => chanlink_url($rr['xchan_url']), 'common' => $rr['total'], 'profile' => $rr['xchan_url'], 'name' => $rr['xchan_name'], 'photo' => $rr['xchan_photo_m'], 'ignlnk' => z_root() . '/suggest?ignore=' . $rr['xchan_hash'], 'conntxt' => t('Connect'), 'connlnk' => $connlnk, 'ignore' => t('Ignore/Hide'));
     }
     $o = replace_macros(get_markup_template('suggest_page.tpl'), array('$title' => t('Channel Suggestions'), '$entries' => $arr));
     return $o;
 }
Exemple #24
0
 function init()
 {
     if (argc() < 2) {
         notice(t('Item not available.') . EOL);
         return;
     }
     $r = attach_by_hash(argv(1), get_observer_hash(), argc() > 2 ? intval(argv(2)) : 0);
     if (!$r['success']) {
         notice($r['message'] . EOL);
         return;
     }
     $c = q("select channel_address from channel where channel_id = %d limit 1", intval($r['data']['uid']));
     if (!$c) {
         return;
     }
     $unsafe_types = array('text/html', 'text/css', 'application/javascript');
     if (in_array($r['data']['filetype'], $unsafe_types)) {
         header('Content-type: text/plain');
     } else {
         header('Content-type: ' . $r['data']['filetype']);
     }
     header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"');
     if (intval($r['data']['os_storage'])) {
         $fname = dbunescbin($r['data']['content']);
         if (strpos($fname, 'store') !== false) {
             $istream = fopen($fname, 'rb');
         } else {
             $istream = fopen('store/' . $c[0]['channel_address'] . '/' . $fname, 'rb');
         }
         $ostream = fopen('php://output', 'wb');
         if ($istream && $ostream) {
             pipe_streams($istream, $ostream);
             fclose($istream);
             fclose($ostream);
         }
     } else {
         echo dbunescbin($r['data']['content']);
     }
     killme();
 }
Exemple #25
0
function profile_content(&$a, $update = 0)
{
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        return login();
    }
    $groups = array();
    $tab = 'profile';
    $o = '';
    if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_profile')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $is_owner = local_channel() && local_channel() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !remote_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']);
    $o .= advanced_profile($a);
    call_hooks('profile_advanced', $o);
    return $o;
}
Exemple #26
0
function profile_content(&$a, $update = 0)
{
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        return login();
    }
    $groups = array();
    $tab = 'profile';
    $o = '';
    if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_profile')) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $is_owner = local_channel() && local_channel() == $a->profile['profile_uid'] ? true : false;
    if ($a->profile['hidewall'] && !$is_owner && !remote_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']);
    $a->page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . $a->query_string) . '" title="oembed" />' . "\r\n";
    $o .= advanced_profile($a);
    call_hooks('profile_advanced', $o);
    return $o;
}
 function get()
 {
     if (observer_prohibited(true)) {
         return login();
     }
     $groups = array();
     $tab = 'profile';
     $o = '';
     if (!perm_is_allowed(\App::$profile['profile_uid'], get_observer_hash(), 'view_profile')) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $is_owner = local_channel() && local_channel() == \App::$profile['profile_uid'] ? true : false;
     if (\App::$profile['hidewall'] && !$is_owner && !remote_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
     \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n";
     $o .= advanced_profile($a);
     call_hooks('profile_advanced', $o);
     return $o;
 }
 function init()
 {
     $observer = get_observer_hash();
     if (!$observer) {
         return;
     }
     if ($observer) {
         $safe_mode = get_xconfig($observer, 'directory', 'safe_mode');
     }
     if ($safe_mode == '') {
         set_xconfig($observer, 'directory', 'safe_mode', '0');
     } elseif ($safe_mode == '0') {
         set_xconfig($observer, 'directory', 'safe_mode', '1');
     } elseif ($safe_mode == '1') {
         set_xconfig($observer, 'directory', 'safe_mode', '0');
     }
     if (isset($_GET['address'])) {
         $address = $_GET['address'];
     } else {
         $address = z_root() . '/directory';
     }
     goaway($address);
 }
Exemple #29
0
function widget_item($arr)
{
    $uid = $a->profile['profile_uid'];
    if (!$uid || !$arr['mid']) {
        return '';
    }
    if (!perm_is_allowed($uid, get_observer_hash(), 'view_pages')) {
        return '';
    }
    require_once 'include/security.php';
    $sql_extra = item_permissions_sql($uid);
    $r = q("select * from item where mid = '%s' and uid = %d and item_restrict = " . intval(ITEM_WEBPAGE) . " {$sql_extra} limit 1", dbesc($arr['mid']), intval($uid));
    if (!$r) {
        return '';
    }
    xchan_query($r);
    $r = fetch_post_tags($r, true);
    $o .= prepare_page($r[0]);
    return $o;
}
Exemple #30
0
/**
 * @brief do several updates when pinged.
 *
 * This function does several tasks. Whenever called it checks for new messages,
 * introductions, notifications, etc. and returns a json with the results.
 *
 * @param App &$a
 * @result JSON
 */
function ping_init(&$a)
{
    $result = array();
    $notifs = array();
    $result['notify'] = 0;
    $result['home'] = 0;
    $result['network'] = 0;
    $result['intros'] = 0;
    $result['mail'] = 0;
    $result['register'] = 0;
    $result['events'] = 0;
    $result['events_today'] = 0;
    $result['birthdays'] = 0;
    $result['birthdays_today'] = 0;
    $result['all_events'] = 0;
    $result['all_events_today'] = 0;
    $result['notice'] = array();
    $result['info'] = array();
    $t0 = dba_timer();
    header("content-type: application/json");
    /**
     * If you have several windows open to this site and switch to a different channel
     * in one of them, the others may get into a confused state showing you a page or options 
     * on that page which were only valid under the old identity. You session has changed.
     * Therefore we send a notification of this fact back to the browser where it is picked up
     * in javascript and which reloads the page it is on so that it is valid under the context
     * of the now current channel. 
     */
    $result['invalid'] = intval($_GET['uid']) && intval($_GET['uid']) != local_user() ? 1 : 0;
    /**
     * Send all system messages (alerts) to the browser.
     * Some are marked as informational and some represent
     * errors or serious notifications. These typically
     * will popup on the current page (no matter what page it is)
     */
    if (x($_SESSION, 'sysmsg')) {
        foreach ($_SESSION['sysmsg'] as $m) {
            $result['notice'][] = array('message' => $m);
        }
        unset($_SESSION['sysmsg']);
    }
    if (x($_SESSION, 'sysmsg_info')) {
        foreach ($_SESSION['sysmsg_info'] as $m) {
            $result['info'][] = array('message' => $m);
        }
        unset($_SESSION['sysmsg_info']);
    }
    if ($a->install) {
        echo json_encode($result);
        killme();
    }
    /**
     * Update chat presence indication (if applicable)
     */
    if (get_observer_hash() && !$result['invalid']) {
        $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']));
        $basic_presence = false;
        if ($r) {
            $basic_presence = true;
            q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1", dbesc(datetime_convert()), intval($r[0]['cp_id']));
        }
        if (!$basic_presence) {
            q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client)\n\t\t\t\tvalues( '%s', '%s', '%s', '%s' ) ", dbesc(get_observer_hash()), dbesc(datetime_convert()), dbesc('online'), dbesc($_SERVER['REMOTE_ADDR']));
        }
    }
    /**
     * Chatpresence continued... if somebody hasn't pinged recently, they've most likely left the page
     * and shouldn't count as online anymore. We allow an expection for bots.
     */
    q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 3 MINUTE and cp_client != 'auto' ");
    if (!local_user() || $result['invalid']) {
        echo json_encode($result);
        killme();
    }
    /**
     * Everything following is only permitted under the context of a locally authenticated site member.
     */
    /**
     * Handle "mark all xyz notifications read" requests.
     */
    // mark all items read
    if (x($_REQUEST, 'markRead') && local_user()) {
        switch ($_REQUEST['markRead']) {
            case 'network':
                $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and uid = %d", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(local_user()));
                break;
            case 'home':
                $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and (item_flags & %d) and uid = %d", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(ITEM_WALL), intval(local_user()));
                break;
            case 'messages':
                $r = q("update mail set mail_flags = ( mail_flags ^ %d ) where channel_id = %d and not (mail_flags & %d)", intval(MAIL_SEEN), intval(local_user()), intval(MAIL_SEEN));
                break;
            case 'all_events':
                $r = q("update event set `ignore` = 1 where `ignore` = 0 and uid = %d", intval(local_user()));
                break;
            case 'notify':
                $r = q("update notify set seen = 1 where uid = %d", intval(local_user()));
                break;
            default:
                break;
        }
    }
    /**
     * URL ping/something will return detail for "something", e.g. a json list with which to populate a notification
     * dropdown menu.
     */
    if (argc() > 1 && argv(1) === 'notify') {
        $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()));
        if ($t && intval($t[0]['total']) > 49) {
            $z = q("select * from notify where uid = %d\n\t\t\t\tand seen = 0 order by date desc limit 0, 50", intval(local_user()));
        } else {
            $z1 = q("select * from notify where uid = %d\n\t\t\t\tand seen = 0 order by date desc limit 0, 50", intval(local_user()));
            $z2 = q("select * from notify where uid = %d\n\t\t\t\tand seen = 1 order by date desc limit 0, %d", intval(local_user()), intval(50 - intval($t[0]['total'])));
            $z = array_merge($z1, $z2);
        }
        if (count($z)) {
            foreach ($z as $zz) {
                $notifs[] = array('notify_link' => $a->get_baseurl() . '/notify/view/' . $zz['id'], 'name' => '', 'url' => $zz['url'], 'photo' => $zz['photo'], 'when' => relative_date($zz['date']), 'class' => $zz['seen'] ? 'notify-seen' : 'notify-unseen', 'message' => strip_tags(bbcode($zz['msg'])));
            }
        }
        echo json_encode(array('notify' => $notifs));
        killme();
    }
    if (argc() > 1 && argv(1) === 'messages') {
        $channel = $a->get_channel();
        $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan \n\t\t\twhere channel_id = %d and not ( mail_flags & %d ) and not (mail_flags & %d ) \n\t\t\tand from_xchan != '%s' order by created desc limit 0,50", intval(local_user()), intval(MAIL_SEEN), intval(MAIL_DELETED), dbesc($channel['channel_hash']));
        if ($t) {
            foreach ($t as $zz) {
                $notifs[] = array('notify_link' => $a->get_baseurl() . '/mail/' . $zz['id'], 'name' => $zz['xchan_name'], 'url' => $zz['xchan_url'], 'photo' => $zz['xchan_photo_s'], 'when' => relative_date($zz['created']), 'class' => $zz['mail_flags'] & MAIL_SEEN ? 'notify-seen' : 'notify-unseen', 'message' => t('sent you a private message'));
            }
        }
        echo json_encode(array('notify' => $notifs));
        killme();
    }
    if (argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) {
        $result = array();
        $r = q("SELECT * FROM item\n\t\t\tWHERE item_restrict = %d and ( item_flags & %d ) and uid = %d", intval(ITEM_VISIBLE), intval(ITEM_UNSEEN), intval(local_user()));
        if ($r) {
            xchan_query($r);
            foreach ($r as $item) {
                if (argv(1) === 'home' && !($item['item_flags'] & ITEM_WALL)) {
                    continue;
                }
                $result[] = format_notification($item);
            }
        }
        logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA);
        echo json_encode(array('notify' => $result));
        killme();
    }
    if (argc() > 1 && argv(1) === 'intros') {
        $result = array();
        $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) and not ((abook_flags & %d) or (xchan_flags & %d))", intval(local_user()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF | ABOOK_FLAG_IGNORED), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
        if ($r) {
            foreach ($r as $rr) {
                $result[] = array('notify_link' => $a->get_baseurl() . '/connedit/' . $rr['abook_id'], 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => relative_date($rr['abook_created']), 'class' => 'notify-unseen', 'message' => t('added your channel'));
            }
        }
        logger('ping (intros): ' . print_r($result, true), LOGGER_DATA);
        echo json_encode(array('notify' => $result));
        killme();
    }
    if (argc() > 1 && argv(1) === 'all_events') {
        $bd_format = t('g A l F d');
        // 8 AM Friday January 18
        $result = array();
        $r = q("SELECT * FROM event left join xchan on event_xchan = xchan_hash\n\t\t\tWHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0\n\t\t\tORDER BY `start` DESC ", intval(local_user()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
        if ($r) {
            foreach ($r as $rr) {
                if ($rr['adjust']) {
                    $md = datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'Y/m');
                } else {
                    $md = datetime_convert('UTC', 'UTC', $rr['start'], 'Y/m');
                }
                $strt = datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start']);
                $today = substr($strt, 0, 10) === datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d') ? true : false;
                $when = day_translate(datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start'], $bd_format)) . ($today ? ' ' . t('[today]') : '');
                $result[] = array('notify_link' => $a->get_baseurl() . '/events', 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => $when, 'class' => 'notify-unseen', 'message' => t('posted an event'));
            }
        }
        logger('ping (all_events): ' . print_r($result, true), LOGGER_DATA);
        echo json_encode(array('notify' => $result));
        killme();
    }
    /**
     * Normal ping - just the counts, no detail
     */
    $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()));
    if ($t) {
        $result['notify'] = intval($t[0]['total']);
    }
    $t1 = dba_timer();
    $r = q("SELECT id, item_restrict, item_flags FROM item\n\t\tWHERE (item_restrict = %d) and ( item_flags & %d ) and uid = %d", intval(ITEM_VISIBLE), intval(ITEM_UNSEEN), intval(local_user()));
    if (count($r)) {
        $arr = array('items' => $r);
        call_hooks('network_ping', $arr);
        foreach ($r as $it) {
            if ($it['item_flags'] & ITEM_WALL) {
                $result['home']++;
            } else {
                $result['network']++;
            }
        }
    }
    $t2 = dba_timer();
    $intr = 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) and not ((abook_flags & %d) or (xchan_flags & %d))", intval(local_user()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF | ABOOK_FLAG_IGNORED), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
    $t3 = dba_timer();
    if ($intr) {
        $result['intros'] = intval($intr[0]['total']);
    }
    $t4 = dba_timer();
    $channel = get_app()->get_channel();
    $mails = q("SELECT count(id) as total from mail\n\t\tWHERE channel_id = %d AND not (mail_flags & %d) and from_xchan != '%s' ", intval(local_user()), intval(MAIL_SEEN), dbesc($channel['channel_hash']));
    if ($mails) {
        $result['mail'] = intval($mails[0]['total']);
    }
    if ($a->config['system']['register_policy'] == REGISTER_APPROVE && is_site_admin()) {
        $regs = q("SELECT count(account_id) as total from account where (account_flags & %d)", intval(ACCOUNT_PENDING));
        if ($regs) {
            $result['register'] = intval($regs[0]['total']);
        }
    }
    $t5 = dba_timer();
    $events = q("SELECT type, start, adjust FROM `event`\n\t\tWHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0\n\t\tORDER BY `start` ASC ", intval(local_user()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
    if ($events) {
        $result['all_events'] = count($events);
        if ($result['all_events']) {
            $str_now = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d');
            foreach ($events as $x) {
                $bd = false;
                if ($x['type'] === 'birthday') {
                    $result['birthdays']++;
                    $bd = true;
                } else {
                    $result['events']++;
                }
                if (datetime_convert('UTC', intval($x['adjust']) ? date_default_timezone_get() : 'UTC', $x['start'], 'Y-m-d') === $str_now) {
                    $result['all_events_today']++;
                    if ($bd) {
                        $result['birthdays_today']++;
                    } else {
                        $result['events_today']++;
                    }
                }
            }
        }
    }
    $x = json_encode($result);
    $t6 = dba_timer();
    //	logger('ping timer: ' . sprintf('%01.4f %01.4f %01.4f %01.4f %01.4f %01.4f',$t6 - $t5, $t5 - $t4, $t4 - $t3, $t3 - $t2, $t2 - $t1, $t1 - $t0));
    echo $x;
    killme();
}