Ejemplo n.º 1
0
 function init()
 {
     $result = array('success' => false);
     $mindate = $_REQUEST['mindate'] ? datetime_convert('UTC', 'UTC', $_REQUEST['mindate']) : '';
     if (!$mindate) {
         $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days');
     }
     if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
         $result['message'] = 'Public access denied';
         json_return_and_die($result);
     }
     $observer = \App::get_observer();
     $channel_address = argc() > 1 ? argv(1) : '';
     if ($channel_address) {
         $r = q("select channel_id, channel_name from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc(argv(1)));
     } else {
         $x = get_sys_channel();
         if ($x) {
             $r = array($x);
         }
         $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days');
     }
     if (!$r) {
         $result['message'] = 'Channel not found.';
         json_return_and_die($result);
     }
     logger('zotfeed request: ' . $r[0]['channel_name'], LOGGER_DEBUG);
     $result['messages'] = zot_feed($r[0]['channel_id'], $observer['xchan_hash'], array('mindate' => $mindate));
     $result['success'] = true;
     json_return_and_die($result);
 }
Ejemplo n.º 2
0
 function init()
 {
     $ret = array();
     call_hooks('home_init', $ret);
     $splash = argc() > 1 && argv(1) === 'splash' ? true : false;
     $channel = \App::get_channel();
     if (local_channel() && $channel && $channel['xchan_url'] && !$splash) {
         $dest = $channel['channel_startpage'];
         if (!$dest) {
             $dest = get_pconfig(local_channel(), 'system', 'startpage');
         }
         if (!$dest) {
             $dest = get_config('system', 'startpage');
         }
         if (!$dest) {
             $dest = z_root() . '/network';
         }
         goaway($dest);
     }
     if (remote_channel() && !$splash && $_SESSION['atoken']) {
         $r = q("select * from atoken where atoken_id = %d", intval($_SESSION['atoken']));
         if ($r) {
             $x = channelx_by_n($r[0]['atoken_uid']);
             if ($x) {
                 goaway(z_root() . '/channel/' . $x['channel_address']);
             }
         }
     }
     if (get_account_id() && !$splash) {
         goaway(z_root() . '/new_channel');
     }
 }
Ejemplo n.º 3
0
function share_init(&$a)
{
    $post_id = argc() > 1 ? intval(argv(1)) : 0;
    if (!$post_id) {
        killme();
    }
    if (!(local_channel() || remote_channel())) {
        killme();
    }
    $r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d  LIMIT 1", intval($post_id));
    if (!$r) {
        killme();
    }
    if ($r[0]['item_private'] && $r[0]['xchan_network'] !== 'rss') {
        killme();
    }
    $sql_extra = item_permissions_sql($r[0]['uid']);
    $r = q("select * from item where id = %d {$sql_extra}", intval($post_id));
    if (!$r) {
        killme();
    }
    /** @FIXME we only share bbcode */
    if ($r[0]['mimetype'] !== 'text/bbcode') {
        killme();
    }
    /** @FIXME eventually we want to post remotely via rpost on your home site */
    // When that works remove this next bit:
    if (!local_channel()) {
        killme();
    }
    xchan_query($r);
    if (strpos($r[0]['body'], "[/share]") !== false) {
        $pos = strpos($r[0]['body'], "[share");
        $o = substr($r[0]['body'], $pos);
    } else {
        $o = "[share author='" . urlencode($r[0]['author']['xchan_name']) . "' profile='" . $r[0]['author']['xchan_url'] . "' avatar='" . $r[0]['author']['xchan_photo_s'] . "' link='" . $r[0]['plink'] . "' posted='" . $r[0]['created'] . "' message_id='" . $r[0]['mid'] . "']";
        if ($r[0]['title']) {
            $o .= '[b]' . $r[0]['title'] . '[/b]' . "\n";
        }
        $o .= $r[0]['body'];
        $o .= "[/share]";
    }
    if (local_channel()) {
        echo $o;
        killme();
    }
    $observer = $a->get_observer();
    $parsed = $observer['xchan_url'];
    if ($parsed) {
        $post_url = $parsed['scheme'] . ':' . $parsed['host'] . ($parsed['port'] ? ':' . $parsed['port'] : '') . '/rpost';
        /**
         * @FIXME we were probably called from JS so we don't know the return page.
         * In fact we won't be able to load the remote page.
         * we might need an iframe
         */
        $x = z_post_url($post_url, array('f' => '', 'body' => $o));
        killme();
    }
}
Ejemplo n.º 4
0
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 = " 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($a->profile['uid']));
    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 {$abook_flags} and xchan_orphan = 0 and xchan_deleted = 0 {$sql_extra} order by xchan_name LIMIT %d OFFSET %d ", intval($a->profile['uid']), 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' => 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;
}
Ejemplo n.º 5
0
 function get()
 {
     if (local_channel()) {
         goaway(z_root());
     }
     if (remote_channel() && $_SESSION['atoken']) {
         goaway(z_root());
     }
     return login(\App::$config['system']['register_policy'] == REGISTER_CLOSED ? false : true);
 }
Ejemplo n.º 6
0
 function get()
 {
     if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $poco_rating = get_config('system', 'poco_rating_enable');
     // if unset default to enabled
     if ($poco_rating === false) {
         $poco_rating = true;
     }
     if (!$poco_rating) {
         return;
     }
     $site_target = array_key_exists('target', \App::$data) && array_key_exists('site_url', \App::$data['target']) ? '<a href="' . \App::$data['target']['site_url'] . '" >' . \App::$data['target']['site_url'] . '</a>' : '';
     $o = replace_macros(get_markup_template('prep.tpl'), array('$header' => t('Ratings'), '$rating_lbl' => t('Rating: '), '$website' => t('Website: '), '$site' => $site_target, '$rating_text_lbl' => t('Description: '), '$raters' => \App::$data['results']));
     return $o;
 }
Ejemplo n.º 7
0
function oexchange_content(&$a)
{
    if (!local_channel()) {
        if (remote_channel()) {
            $observer = $a->get_observer();
            if ($observer && $observer['xchan_url']) {
                $parsed = @parse_url($observer['xchan_url']);
                if (!$parsed) {
                    notice(t('Unable to find your hub.') . EOL);
                    return;
                }
                $url = $parsed['scheme'] . '://' . $parsed['host'] . ($parsed['port'] ? ':' . $parsed['port'] : '');
                $url .= '/oexchange';
                $result = z_post_url($url, $_REQUEST);
                json_return_and_die($result);
            }
        }
        return login(false);
    }
    if (argc() > 1 && argv(1) === 'done') {
        info(t('Post successful.') . EOL);
        return;
    }
    $url = x($_REQUEST, 'url') && strlen($_REQUEST['url']) ? urlencode(notags(trim($_REQUEST['url']))) : '';
    $title = x($_REQUEST, 'title') && strlen($_REQUEST['title']) ? '&title=' . urlencode(notags(trim($_REQUEST['title']))) : '';
    $description = x($_REQUEST, 'description') && strlen($_REQUEST['description']) ? '&description=' . urlencode(notags(trim($_REQUEST['description']))) : '';
    $tags = x($_REQUEST, 'tags') && strlen($_REQUEST['tags']) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '';
    $ret = z_fetch_url($a->get_baseurl() . '/urlinfo?f=&url=' . $url . $title . $description . $tags);
    if ($ret['success']) {
        $s = $ret['body'];
    }
    if (!strlen($s)) {
        return;
    }
    $post = array();
    $post['profile_uid'] = local_channel();
    $post['return'] = '/oexchange/done';
    $post['body'] = $s;
    $post['type'] = 'wall';
    $_REQUEST = $post;
    require_once 'mod/item.php';
    item_post($a);
}
Ejemplo n.º 8
0
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;
    }
    $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) {
        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 Connections'), '$contacts' => $contacts, '$paginate' => paginate($a)));
    return $o;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
 function write($id, $data)
 {
     if (!$id || !$data) {
         return false;
     }
     // Unless we authenticate somehow, only keep a session for 5 minutes
     // The viewer can extend this by performing any web action using the
     // original cookie, but this allows us to cleanup the hundreds or
     // thousands of empty sessions left around from web crawlers which are
     // assigned cookies on each page that they never use.
     $expire = time() + 300;
     if ($_SESSION) {
         if (array_key_exists('remember_me', $_SESSION) && intval($_SESSION['remember_me'])) {
             $expire = time() + 60 * 60 * 24 * 365;
         } elseif (local_channel()) {
             $expire = time() + 60 * 60 * 24 * 3;
         } elseif (remote_channel()) {
             $expire = time() + 60 * 60 * 24 * 1;
         }
     }
     q("UPDATE `session`\n\t\t\tSET `sess_data` = '%s', `expire` = '%s' WHERE `sid` = '%s'", dbesc($data), dbesc($expire), dbesc($id));
     return true;
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
function search_content(&$a, $update = 0, $load = false)
{
    if (get_config('system', 'block_public') || get_config('system', 'block_public_search')) {
        if (!local_channel() && !remote_channel()) {
            notice(t('Public access denied.') . EOL);
            return;
        }
    }
    if ($load) {
        $_SESSION['loadtime'] = datetime_convert();
    }
    nav_set_selected('search');
    require_once "include/bbcode.php";
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    require_once 'include/items.php';
    $format = $_REQUEST['format'] ? $_REQUEST['format'] : '';
    if ($format !== '') {
        $update = $load = 1;
    }
    $observer = $a->get_observer();
    $observer_hash = $observer ? $observer['xchan_hash'] : '';
    $o = '<div id="live-search"></div>' . "\r\n";
    $o .= '<h3>' . t('Search') . '</h3>';
    if (x($a->data, 'search')) {
        $search = trim($a->data['search']);
    } else {
        $search = x($_GET, 'search') ? trim(rawurldecode($_GET['search'])) : '';
    }
    $tag = false;
    if (x($_GET, 'tag')) {
        $tag = true;
        $search = x($_GET, 'tag') ? trim(rawurldecode($_GET['tag'])) : '';
    }
    if (!local_channel() || !feature_enabled(local_channel(), 'savedsearch')) {
        $o .= search($search, 'search-box', '/search', local_channel() ? true : false);
    }
    if (strpos($search, '#') === 0) {
        $tag = true;
        $search = substr($search, 1);
    }
    if (strpos($search, '@') === 0) {
        $search = substr($search, 1);
        goaway(z_root() . '/directory' . '?f=1&search=' . $search);
    }
    // look for a naked webbie
    if (strpos($search, '@') !== false) {
        goaway(z_root() . '/directory' . '?f=1&search=' . $search);
    }
    if (!$search) {
        return $o;
    }
    if ($tag) {
        $sql_extra = sprintf(" AND `item`.`id` IN (select `oid` from term where otype = %d and type = %d and term = '%s') ", intval(TERM_OBJ_POST), intval(TERM_HASHTAG), dbesc(protect_sprintf($search)));
    } else {
        $regstr = db_getfunc('REGEXP');
        $sql_extra = sprintf(" AND `item`.`body` {$regstr} '%s' ", dbesc(protect_sprintf(preg_quote($search))));
    }
    // Here is the way permissions work in the search module...
    // Only public posts can be shown
    // OR your own posts if you are a logged in member
    // No items will be shown if the member has a blocked profile wall.
    if (!$update && !$load) {
        // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
        // because browser prefetching might change it on us. We have to deliver it with the page.
        $o .= '<div id="live-search"></div>' . "\r\n";
        $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
        $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'search', '$uid' => $a->profile['profile_uid'] ? $a->profile['profile_uid'] : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '0', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$fh' => '0', '$nouveau' => '0', '$wall' => '0', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$page' => $a->pager['page'] != 1 ? $a->pager['page'] : 1, '$search' => ($tag ? urlencode('#') : '') . $search, '$order' => '', '$file' => '', '$cats' => '', '$tags' => '', '$mid' => '', '$verb' => '', '$dend' => '', '$dbegin' => ''));
    }
    $pub_sql = public_permissions_sql($observer_hash);
    require_once 'include/identity.php';
    $sys = get_sys_channel();
    if ($update && $load) {
        $itemspage = get_pconfig(local_channel(), 'system', 'itemspage');
        $a->set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
        $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
        // in case somebody turned off public access to sys channel content with permissions
        if (!perm_is_allowed($sys['channel_id'], $observer_hash, 'view_stream')) {
            $sys['xchan_hash'] .= 'disabled';
        }
        if ($load) {
            $r = null;
            if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
                $prefix = 'distinct on (created, mid)';
                $suffix = 'ORDER BY created DESC, mid';
            } else {
                $prefix = 'distinct';
                $suffix = 'group by mid ORDER BY created DESC';
            }
            if (local_channel()) {
                $r = q("SELECT {$prefix} mid, item.id as item_id, item.* from item\n\t\t\t\t\tWHERE item_restrict = 0\n\t\t\t\t\tAND ((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\tOR ( `item`.`uid` = %d )) OR item.owner_xchan = '%s' )\n\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t{$suffix} {$pager_sql} ", intval(local_channel()), dbesc($sys['xchan_hash']));
            }
            if ($r === null) {
                $r = q("SELECT {$prefix} mid, item.id as item_id, item.* from item\n\t\t\t\t\tWHERE item_restrict = 0\n\t\t\t\t\tAND (((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = ''\n\t\t\t\t\tAND `item`.`deny_gid`  = '' AND item_private = 0 )\n\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\t\t{$pub_sql} ) OR owner_xchan = '%s')\n\t\t\t\t\t{$sql_extra} \n\t\t\t\t\t{$suffix} {$pager_sql}", dbesc($sys['xchan_hash']));
            }
        } else {
            $r = array();
        }
    }
    if ($r) {
        xchan_query($r);
        $items = fetch_post_tags($r, true);
    } else {
        $items = array();
    }
    if ($format == 'json') {
        $result = array();
        require_once 'include/conversation.php';
        foreach ($items as $item) {
            $item['html'] = bbcode($item['body']);
            $x = encode_item($item);
            $x['html'] = prepare_text($item['body'], $item['mimetype']);
            $result[] = $x;
        }
        json_return_and_die(array('success' => true, 'messages' => $result));
    }
    if ($tag) {
        $o .= '<h2>Items tagged with: ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8') . '</h2>';
    } else {
        $o .= '<h2>Search results for: ' . htmlspecialchars($search, ENT_COMPAT, 'UTF-8') . '</h2>';
    }
    $o .= conversation($a, $items, 'search', $update, 'client');
    return $o;
}
Ejemplo n.º 14
0
/**
 * API: map_getSharedData
 * Retrieve the available data
 * @param type $type
 * @param type $filter
 */
function map_getSharedData($type, $filter)
{
    if (local_channel() || remote_channel()) {
        $channel = App::get_channel();
        $sql_extra = item_permissions_sql($channel['channel_id'], get_observer_hash());
    } else {
        $sql_extra = " AND item_private = 0 ";
    }
    switch ($filter) {
        case 'owner':
            $shares = q("SELECT owner_xchan,resource_id FROM item WHERE resource_type = '%s' AND owner_xchan != '%s' AND object LIKE '%s' {$sql_extra}", dbesc('locserv'), dbesc(App::get_channel()['channel_hash']), dbesc('%"locationDataType":"' . $type . '"%'));
            $channels = [];
            foreach ($shares as $share) {
                $channel = channelx_by_hash($share['owner_xchan']);
                $channels[] = array('name' => $channel['channel_name'], 'address' => $channel['xchan_addr'], 'photo_address' => $channel['xchan_photo_s']);
            }
            echo json_encode(array('sharedData' => $shares, 'channels' => $channels, 'status' => true));
            die;
        case 'all':
            $shares = q("SELECT owner_xchan,resource_id FROM item WHERE resource_type = '%s' AND owner_xchan != '%s' AND object LIKE '%s' {$sql_extra}", dbesc('locserv'), dbesc(App::get_channel()['channel_hash']), dbesc('%"locationDataType":"' . $type . '"%'));
            $channels = [];
            $markers = [];
            foreach ($shares as $share) {
                $channel = channelx_by_hash($share['owner_xchan']);
                $channels[] = array('name' => $channel['channel_name'], 'address' => $channel['xchan_addr'], 'photo_address' => $channel['xchan_photo_s']);
                // FIXME: Not sure the permissions are checked appropriately here
                $marker = q("SELECT lat,lon,title,body,layer,created,resource_id FROM `locserv-static-markers` WHERE resource_id = '%s' limit 1", dbesc($share['resource_id']));
                $markers[] = $marker[0];
            }
            echo json_encode(array('sharedData' => $shares, 'channels' => $channels, 'markers' => $markers, 'status' => true));
            die;
        default:
            echo json_encode(array('sharedData' => null, 'channels' => null, 'markers' => null, 'status' => false));
            die;
    }
}
Ejemplo n.º 15
0
/**
 * remote_user() got deprecated and replaced by remote_channel().
 *
 * @deprecated since v2.1, use remote_channel()
 * @see remote_channel()
 */
function remote_user()
{
    logger('remote_user() is DEPRECATED, use remote_channel()');
    return remote_channel();
}
Ejemplo n.º 16
0
function channel_content(&$a, $update = 0, $load = false)
{
    if ($load) {
        $_SESSION['loadtime'] = datetime_convert();
    }
    $category = $datequery = $datequery2 = '';
    $mid = x($_REQUEST, 'mid') ? $_REQUEST['mid'] : '';
    $datequery = x($_GET, 'dend') && is_a_date_arg($_GET['dend']) ? notags($_GET['dend']) : '';
    $datequery2 = x($_GET, 'dbegin') && is_a_date_arg($_GET['dbegin']) ? notags($_GET['dbegin']) : '';
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        return login();
    }
    $category = x($_REQUEST, 'cat') ? $_REQUEST['cat'] : '';
    $hashtags = x($_REQUEST, 'tag') ? $_REQUEST['tag'] : '';
    $groups = array();
    $o = '';
    if ($update) {
        // Ensure we've got a profile owner if updating.
        $a->profile['profile_uid'] = $a->profile_uid = $update;
    } else {
        if ($a->profile['profile_uid'] == local_channel()) {
            nav_set_selected('home');
        }
    }
    $is_owner = local_channel() && $a->profile['profile_uid'] == local_channel() ? true : false;
    $channel = $a->get_channel();
    $observer = $a->get_observer();
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    $perms = get_all_perms($a->profile['profile_uid'], $ob_hash);
    if (!$perms['view_stream']) {
        // We may want to make the target of this redirect configurable
        if ($perms['view_profile']) {
            notice(t('Insufficient permissions.  Request redirected to profile page.') . EOL);
            goaway(z_root() . "/profile/" . $a->profile['channel_address']);
        }
        notice(t('Permission denied.') . EOL);
        return;
    }
    if (!$update) {
        $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']);
        $o .= common_friends_visitor_widget($a->profile['profile_uid']);
        if ($channel && $is_owner) {
            $channel_acl = 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']);
        } else {
            $channel_acl = array();
        }
        if ($perms['post_wall']) {
            $x = array('is_owner' => $is_owner, 'allow_location' => ($is_owner || $observer) && intval(get_pconfig($a->profile['profile_uid'], 'system', 'use_browser_location')) ? true : false, 'default_location' => $is_owner ? $a->profile['channel_location'] : '', 'nickname' => $a->profile['channel_address'], 'lockstate' => strlen($a->profile['channel_allow_cid']) || strlen($a->profile['channel_allow_gid']) || strlen($a->profile['channel_deny_cid']) || strlen($a->profile['channel_deny_gid']) ? 'lock' : 'unlock', 'acl' => $is_owner ? populate_acl($channel_acl, true, $a->profile['channel_r_stream'] & PERMS_PUBLIC ? t('Public') : '') : '', 'showacl' => $is_owner ? 'yes' : '', 'bang' => '', 'visitor' => $is_owner || $observer ? true : false, 'profile_uid' => $a->profile['profile_uid']);
            $o .= status_editor($a, $x);
        }
    }
    /**
     * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
     */
    $item_normal = item_normal();
    $sql_extra = item_permissions_sql($a->profile['profile_uid']);
    if (get_pconfig($a->profile['profile_uid'], 'system', 'channel_list_mode') && !$mid) {
        $page_mode = 'list';
    } else {
        $page_mode = 'client';
    }
    $abook_uids = " and abook.abook_channel = " . intval($a->profile['profile_uid']) . " ";
    $simple_update = $update ? " AND item_unseen = 1 " : '';
    $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";
    if ($update && $_SESSION['loadtime']) {
        $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
    }
    if ($load) {
        $simple_update = '';
    }
    if ($update && !$load) {
        if ($mid) {
            $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d {$item_normal}\n\t\t\t\tAND item_wall = 1 AND item_unseen = 1 {$sql_extra} limit 1", dbesc($mid . '%'), intval($a->profile['profile_uid']));
        } else {
            $r = q("SELECT distinct parent AS `item_id`, created from item\n\t\t\t\tleft join abook on ( item.owner_xchan = abook.abook_xchan {$abook_uids} )\n\t\t\t\tWHERE uid = %d {$item_normal}\n\t\t\t\tAND item_wall = 1 {$simple_update}\n\t\t\t\tAND (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t{$sql_extra}\n\t\t\t\tORDER BY created DESC", intval($a->profile['profile_uid']));
            $_SESSION['loadtime'] = datetime_convert();
        }
    } else {
        if (x($category)) {
            $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY));
        }
        if (x($hashtags)) {
            $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG));
        }
        if ($datequery) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery))));
        }
        if ($datequery2) {
            $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2))));
        }
        $itemspage = get_pconfig(local_channel(), 'system', 'itemspage');
        $a->set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
        $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
        if ($load || $_COOKIE['jsAvailable'] != 1) {
            if ($mid) {
                $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d {$item_normal}\n\t\t\t\t\tAND item_wall = 1 {$sql_extra} limit 1", dbesc($mid), intval($a->profile['profile_uid']));
                if (!$r) {
                    notice(t('Permission denied.') . EOL);
                }
            } else {
                $r = q("SELECT distinct id AS item_id, created FROM item \n\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\tWHERE uid = %d {$item_normal}\n\t\t\t\t\tAND item_wall = 1 and item_thread_top = 1\n\t\t\t\t\tAND (abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t\t{$sql_extra} {$sql_extra2}\n\t\t\t\t\tORDER BY created DESC {$pager_sql} ", intval($a->profile['profile_uid']));
            }
        } else {
            $r = array();
        }
    }
    if ($r) {
        $parents_str = ids_to_querystr($r, 'item_id');
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id` \n\t\t\tFROM `item`\n\t\t\tWHERE `item`.`uid` = %d {$item_normal}\n\t\t\tAND `item`.`parent` IN ( %s )\n\t\t\t{$sql_extra} ", intval($a->profile['profile_uid']), dbesc($parents_str));
        xchan_query($items);
        $items = fetch_post_tags($items, true);
        $items = conv_sort($items, 'created');
        if ($load && $mid && !count($items)) {
            // This will happen if we don't have sufficient permissions
            // to view the parent item (or the item itself if it is toplevel)
            notice(t('Permission denied.') . EOL);
        }
    } else {
        $items = array();
    }
    if (!$update && !$load) {
        // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
        // because browser prefetching might change it on us. We have to deliver it with the page.
        $maxheight = get_pconfig($a->profile['profile_uid'], 'system', 'channel_divmore_height');
        if (!$maxheight) {
            $maxheight = 400;
        }
        $o .= '<div id="live-channel"></div>' . "\r\n";
        $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; divmore_height = " . intval($maxheight) . "; </script>\r\n";
        $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'channel', '$uid' => $a->profile['profile_uid'] ? $a->profile['profile_uid'] : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '0', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$nouveau' => '0', '$wall' => '1', '$fh' => '0', '$page' => $a->pager['page'] != 1 ? $a->pager['page'] : 1, '$search' => '', '$order' => '', '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$file' => '', '$cats' => $category ? $category : '', '$tags' => $hashtags ? $hashtags : '', '$mid' => $mid, '$verb' => '', '$dend' => $datequery, '$dbegin' => $datequery2));
    }
    $update_unseen = '';
    if ($page_mode === 'list') {
        /**
         * in "list mode", only mark the parent item and any like activities as "seen". 
         * We won't distinguish between comment likes and post likes. The important thing
         * is that the number of unseen comments will be accurate. The SQL to separate the
         * comment likes could also get somewhat hairy. 
         */
        if ($parents_str) {
            $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )";
            $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) ";
        }
    } else {
        if ($parents_str) {
            $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )";
        }
    }
    if ($is_owner && $update_unseen) {
        $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d {$update_unseen}", intval(local_channel()));
    }
    if ($_COOKIE['jsAvailable'] == 1) {
        $o .= conversation($a, $items, 'channel', $update, $page_mode);
    } else {
        $o .= conversation($a, $items, 'channel', $update, 'traditional');
    }
    if (!$update || $_COOKIE['jsAvailable'] != 1) {
        $o .= alt_pager($a, count($items));
        if ($mid && $items[0]['title']) {
            $a->page['title'] = $items[0]['title'] . " - " . $a->page['title'];
        }
    }
    if ($mid) {
        $o .= '<div id="content-complete"></div>';
    }
    return $o;
}
Ejemplo n.º 17
0
function public_content(&$a, $update = 0, $load = false)
{
    if ($load) {
        $_SESSION['loadtime'] = datetime_convert();
    }
    if (get_config('system', 'block_public') && !get_account_id() && !remote_channel()) {
        return login();
    }
    if (get_config('system', 'disable_discover_tab')) {
        return;
    }
    $item_normal = item_normal();
    if (!$update) {
        $maxheight = get_config('system', 'home_divmore_height');
        if (!$maxheight) {
            $maxheight = 400;
        }
        $o .= '<div id="live-public"></div>' . "\r\n";
        $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; var profile_page = " . App::$pager['page'] . "; divmore_height = " . intval($maxheight) . "; </script>\r\n";
        App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'public', '$uid' => local_channel() ? local_channel() : '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '99', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$fh' => '1', '$nouveau' => '0', '$wall' => '0', '$list' => '0', '$page' => App::$pager['page'] != 1 ? App::$pager['page'] : 1, '$search' => '', '$order' => 'comment', '$file' => '', '$cats' => '', '$tags' => '', '$dend' => '', '$mid' => '', '$verb' => '', '$dbegin' => ''));
    }
    if ($update && !$load) {
        // only setup pagination on initial page view
        $pager_sql = '';
    } else {
        App::set_pager_itemspage(20);
        $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
    }
    require_once 'include/identity.php';
    require_once 'include/security.php';
    if (get_config('system', 'site_firehose')) {
        $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0  and item_wall = 1 ";
    } else {
        $sys = get_sys_channel();
        $uids = " and item.uid  = " . intval($sys['channel_id']) . " ";
        $sql_extra = item_permissions_sql($sys['channel_id']);
        App::$data['firehose'] = intval($sys['channel_id']);
    }
    if (get_config('system', 'public_list_mode')) {
        $page_mode = 'list';
    } else {
        $page_mode = 'client';
    }
    $simple_update = $update ? " and item.item_unseen = 1 " : '';
    if ($update && $_SESSION['loadtime']) {
        $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
    }
    if ($load) {
        $simple_update = '';
    }
    //logger('update: ' . $update . ' load: ' . $load);
    if ($update) {
        $ordering = "commented";
        if ($load) {
            // Fetch a page full of parent items for this page
            $r = q("SELECT distinct item.id AS item_id, {$ordering} FROM item\n\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\tAND item.parent = item.id\n\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}\n\t\t\t\tORDER BY {$ordering} DESC {$pager_sql} ");
        } elseif ($update) {
            $r = q("SELECT distinct item.id AS item_id, {$ordering} FROM item\n\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\tAND item.parent = item.id {$simple_update}\n\t\t\t\tand (abook.abook_blocked = 0 or abook.abook_flags is null)\n\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}");
            $_SESSION['loadtime'] = datetime_convert();
        }
        // Then fetch all the children of the parents that are on this page
        $parents_str = '';
        $update_unseen = '';
        if ($r) {
            $parents_str = ids_to_querystr($r, 'item_id');
            $items = q("SELECT item.*, item.id AS item_id FROM item\n\t\t\t\tWHERE true {$uids} {$item_normal}\n\t\t\t\tAND item.parent IN ( %s )\n\t\t\t\t{$sql_extra} ", dbesc($parents_str));
            xchan_query($items, true, -1);
            $items = fetch_post_tags($items, true);
            $items = conv_sort($items, $ordering);
        } else {
            $items = array();
        }
    }
    // fake it
    $mode = 'network';
    $o .= conversation($a, $items, $mode, $update, $page_mode);
    if ($items && !$update) {
        $o .= alt_pager($a, count($items));
    }
    return $o;
}
Ejemplo n.º 18
0
function drop_items($items)
{
    $uid = 0;
    if (!local_channel() && !remote_channel()) {
        return;
    }
    if (count($items)) {
        foreach ($items as $item) {
            $owner = drop_item($item, false);
            if ($owner && !$uid) {
                $uid = $owner;
            }
        }
    }
    // multiple threads may have been deleted, send an expire notification
    if ($uid) {
        Zotlabs\Daemon\Master::Summon(array('Notifier', 'expire', $uid));
    }
}
Ejemplo n.º 19
0
/**
 * @brief
 *
 * If somebody arrives at our site using a zat, authenticate them
 *
 */
function zat_init()
{
    if (local_channel() || remote_channel()) {
        return;
    }
    $r = q("select * from atoken where atoken_token = '%s' limit 1", dbesc($_REQUEST['zat']));
    if ($r) {
        $xchan = atoken_xchan($r[0]);
        atoken_login($xchan);
    }
}
Ejemplo n.º 20
0
 function get()
 {
     if (!local_channel() && !remote_channel()) {
         return;
     }
     $item_id = argc() > 2 ? notags(trim(argv(2))) : 0;
     if (argv(1) === 'sub') {
         $activity = ACTIVITY_FOLLOW;
     } elseif (argv(1) === 'unsub') {
         $activity = ACTIVITY_UNFOLLOW;
     }
     $r = q("SELECT parent FROM item WHERE id = '%s'", dbesc($item_id));
     if ($r) {
         $r = q("select * from item where id = parent and id = %d limit 1", dbesc($r[0]['parent']));
     }
     if (!$item_id || !$r) {
         logger('subthread: no item ' . $item_id);
         return;
     }
     $item = $r[0];
     $owner_uid = $item['uid'];
     $observer = \App::get_observer();
     $ob_hash = $observer ? $observer['xchan_hash'] : '';
     if (!perm_is_allowed($owner_uid, $ob_hash, 'post_comments')) {
         return;
     }
     $sys = get_sys_channel();
     $owner_uid = $item['uid'];
     $owner_aid = $item['aid'];
     // if this is a "discover" item, (item['uid'] is the sys channel),
     // fallback to the item comment policy, which should've been
     // respected when generating the conversation thread.
     // Even if the activity is rejected by the item owner, it should still get attached
     // to the local discover conversation on this site.
     if ($owner_uid != $sys['channel_id'] && !perm_is_allowed($owner_uid, $observer['xchan_hash'], 'post_comments')) {
         notice(t('Permission denied') . EOL);
         killme();
     }
     $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($item['owner_xchan']));
     if ($r) {
         $thread_owner = $r[0];
     } else {
         killme();
     }
     $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($item['author_xchan']));
     if ($r) {
         $item_author = $r[0];
     } else {
         killme();
     }
     $mid = item_message_id();
     $post_type = $item['resource_type'] === 'photo' ? t('photo') : t('status');
     $links = array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item['plink']));
     $objtype = $item['resource_type'] === 'photo' ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE;
     $body = $item['body'];
     $obj = json_encode(array('type' => $objtype, 'id' => $item['mid'], 'parent' => $item['thr_parent'] ? $item['thr_parent'] : $item['parent_mid'], 'link' => $links, 'title' => $item['title'], 'content' => $item['body'], 'created' => $item['created'], 'edited' => $item['edited'], 'author' => array('name' => $item_author['xchan_name'], 'address' => $item_author['xchan_addr'], 'guid' => $item_author['xchan_guid'], 'guid_sig' => $item_author['xchan_guid_sig'], 'link' => array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item_author['xchan_url']), array('rel' => 'photo', 'type' => $item_author['xchan_photo_mimetype'], 'href' => $item_author['xchan_photo_m'])))));
     if (!intval($item['item_thread_top'])) {
         $post_type = 'comment';
     }
     if ($activity === ACTIVITY_FOLLOW) {
         $bodyverb = t('%1$s is following %2$s\'s %3$s');
     }
     if ($activity === ACTIVITY_UNFOLLOW) {
         $bodyverb = t('%1$s stopped following %2$s\'s %3$s');
     }
     $arr = array();
     $arr['mid'] = $mid;
     $arr['aid'] = $owner_aid;
     $arr['uid'] = $owner_uid;
     $arr['parent'] = $item['id'];
     $arr['parent_mid'] = $item['mid'];
     $arr['thr_parent'] = $item['mid'];
     $arr['owner_xchan'] = $thread_owner['xchan_hash'];
     $arr['author_xchan'] = $observer['xchan_hash'];
     $arr['item_origin'] = 1;
     $arr['item_notshown'] = 1;
     if (intval($item['item_wall'])) {
         $arr['item_wall'] = 1;
     } else {
         $arr['item_wall'] = 0;
     }
     $ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]';
     $alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]';
     $plink = '[zrl=' . z_root() . '/display/' . $item['mid'] . ']' . $post_type . '[/zrl]';
     $arr['body'] = sprintf($bodyverb, $alink, $ulink, $plink);
     $arr['verb'] = $activity;
     $arr['obj_type'] = $objtype;
     $arr['object'] = $obj;
     $arr['allow_cid'] = $item['allow_cid'];
     $arr['allow_gid'] = $item['allow_gid'];
     $arr['deny_cid'] = $item['deny_cid'];
     $arr['deny_gid'] = $item['deny_gid'];
     $post = item_store($arr);
     $post_id = $post['item_id'];
     $arr['id'] = $post_id;
     call_hooks('post_local_end', $arr);
     killme();
 }
Ejemplo n.º 21
0
function drop_items($items)
{
    $uid = 0;
    if (!local_channel() && !remote_channel()) {
        return;
    }
    if (count($items)) {
        foreach ($items as $item) {
            $owner = drop_item($item, false);
            if ($owner && !$uid) {
                $uid = $owner;
            }
        }
    }
    // multiple threads may have been deleted, send an expire notification
    if ($uid) {
        proc_run('php', "include/notifier.php", "expire", "{$uid}");
    }
}
Ejemplo n.º 22
0
function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/album/xxxxx (xxxxx is album name)
    // photos/name/image/xxxxx
    if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    $unsafe = array_key_exists('unsafe', $_REQUEST) && $_REQUEST['unsafe'] ? 1 : 0;
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'channel')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $ph = photo_factory('');
    $phototypes = $ph->supportedTypes();
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    $can_comment = perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'post_comments');
    if (argc() > 3) {
        $datatype = argv(2);
        $datum = argv(3);
    } else {
        if (argc() > 2) {
            $datatype = argv(2);
            $datum = '';
        } else {
            $datatype = 'summary';
        }
    }
    if (argc() > 4) {
        $cmd = argv(4);
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $owner_uid = $a->data['channel']['channel_id'];
    $owner_aid = $a->data['channel']['channel_account_id'];
    $observer = $a->get_observer();
    $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'write_storage');
    $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_storage');
    if (!$can_view) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid);
    $o = "";
    $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
    // tabs
    $_is_owner = local_channel() && local_channel() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['channel']['channel_address']);
    /**
     * Display upload form
     */
    if ($can_post) {
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        /* Show space usage */
        $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($a->data['channel']['channel_account_id']));
        $limit = service_class_fetch($a->data['channel']['channel_id'], 'photo_upload_limit');
        if ($limit !== false) {
            $usage_message = sprintf(t("%1\$.2f MB of %2\$.2f MB photo storage used."), $r[0]['total'] / 1024000, $limit / 1024000);
        } else {
            $usage_message = sprintf(t('%1$.2f MB photo storage used.'), $r[0]['total'] / 1024000);
        }
        if ($_is_owner) {
            $channel = $a->get_channel();
            $acl = new AccessList($channel);
            $channel_acl = $acl->get();
            $lockstate = $acl->is_private() ? 'lock' : 'unlock';
        }
        $aclselect = $_is_owner ? populate_acl($channel_acl, false) : '';
        $selname = $datum ? hex2bin($datum) : '';
        $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']);
        if (!$selname) {
            $def_album = get_pconfig($a->data['channel']['channel_id'], 'system', 'photo_path');
            if ($def_album) {
                $selname = filepath_macro($def_album);
                $albums['album'][] = array('text' => $selname);
            }
        }
        $tpl = get_markup_template('photos_upload.tpl');
        $upload_form = replace_macros($tpl, array('$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['channel']['channel_address'], '$newalbum_label' => t('Enter an album name'), '$newalbum_placeholder' => t('or select an existing album (doubleclick)'), '$visible' => array('visible', t('Create a status post for this upload'), 0, '', array(t('No'), t('Yes'))), '$albums' => $albums['albums'], '$selname' => $selname, '$permissions' => t('Permissions'), '$aclselect' => $aclselect, '$lockstate' => $lockstate, '$uploader' => $ret['addon_text'], '$default' => $ret['default_upload'] ? true : false, '$uploadurl' => $ret['post_url'], '$submit' => t('Submit')));
    }
    //
    // dispatch request
    //
    /*
     * Display a single photo album
     */
    if ($datatype === 'album') {
        if (strlen($datum)) {
            if (strlen($datum) & 1 || !ctype_xdigit($datum)) {
                notice(t('Album name could not be decoded') . EOL);
                logger('mod_photos: illegal album encoding: ' . $datum);
                $datum = '';
            }
        }
        $album = $datum ? hex2bin($datum) : '';
        $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' \n\t\t\tAND `scale` <= 4 and photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe));
        if (count($r)) {
            $a->set_pager_total(count($r));
            $a->set_pager_itemspage(60);
        } else {
            goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address']);
        }
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.scale, p.description, p.created FROM photo p INNER JOIN\n\t\t\t\t(SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY resource_id) ph \n\t\t\t\tON (p.resource_id = ph.resource_id AND p.scale = ph.scale)\n\t\t\tORDER BY created {$order} LIMIT %d OFFSET %d", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start']));
        //edit album name
        $album_edit = null;
        if ($album !== t('Profile Photos') && $album !== 'Profile Photos' && $album !== 'Contact Photos' && $album !== t('Contact Photos')) {
            if ($can_post) {
                if ($a->get_template_engine() === 'internal') {
                    $album_e = template_escape($album);
                } else {
                    $album_e = $album;
                }
                $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']);
                // @fixme - syncronise actions with DAV
                //				$edit_tpl = get_markup_template('album_edit.tpl');
                //				$album_edit = replace_macros($edit_tpl,array(
                //					'$nametext' => t('Enter a new album name'),
                //					'$name_placeholder' => t('or select an existing one (doubleclick)'),
                //					'$nickname' => $a->data['channel']['channel_address'],
                //					'$album' => $album_e,
                //					'$albums' => $albums['albums'],
                //					'$hexalbum' => bin2hex($album),
                //					'$submit' => t('Submit'),
                //					'$dropsubmit' => t('Delete Album')
                //				));
            }
        }
        if ($_GET['order'] === 'posted') {
            $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album));
        } else {
            $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($album) . '?f=&order=posted');
        }
        $photos = array();
        if (count($r)) {
            $twist = 'rotright';
            foreach ($r as $rr) {
                if ($twist == 'rotright') {
                    $twist = 'rotleft';
                } else {
                    $twist = 'rotright';
                }
                $ext = $phototypes[$rr['type']];
                $imgalt_e = $rr['filename'];
                $desc_e = $rr['description'];
                $imagelink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
                $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $imagelink, 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' . $ext, 'alt' => $imgalt_e, 'desc' => $desc_e, 'ext' => $ext, 'hash' => $rr['resource_id'], 'unknown' => t('Unknown'));
            }
        }
        if ($_REQUEST['aj']) {
            if ($photos) {
                $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos));
            } 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('photo_album.tpl');
            $o .= replace_macros($tpl, array('$photos' => $photos, '$album' => $album, '$album_edit' => array(t('Edit Album'), $album_edit), '$can_post' => $can_post, '$upload' => array(t('Upload'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload/' . bin2hex($album)), '$order' => $order, '$upload_form' => $upload_form, '$usage' => $usage_message));
        }
        if (!$photos && $_REQUEST['aj']) {
            $o .= '<div id="content-complete"></div>';
            echo $o;
            killme();
        }
        //		$o .= paginate($a);
        return $o;
    }
    /** 
     * Display one photo
     */
    if ($datatype === 'image') {
        // fetch image, item containing image, then comments
        $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' \n\t\t\t{$sql_extra} ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum));
        if (!$ph) {
            /* Check again - this time without specifying permissions */
            $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' LIMIT 1", intval($owner_uid), dbesc($datum));
            if ($ph) {
                notice(t('Permission denied. Access to this item may be restricted.') . EOL);
            } else {
                notice(t('Photo not available') . EOL);
            }
            return;
        }
        $prevlink = '';
        $nextlink = '';
        if ($_GET['order'] === 'posted') {
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }
        $prvnxt = q("SELECT `resource_id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 \n\t\t\t{$sql_extra} ORDER BY `created` {$order} ", dbesc($ph[0]['album']), intval($owner_uid));
        if (count($prvnxt)) {
            for ($z = 0; $z < count($prvnxt); $z++) {
                if ($prvnxt[$z]['resource_id'] == $ph[0]['resource_id']) {
                    $prv = $z - 1;
                    $nxt = $z + 1;
                    if ($prv < 0) {
                        $prv = count($prvnxt) - 1;
                    }
                    if ($nxt >= count($prvnxt)) {
                        $nxt = 0;
                    }
                    break;
                }
            }
            $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
            $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . ($_GET['order'] === 'posted' ? '?f=&order=posted' : '');
        }
        if (count($ph) == 1) {
            $hires = $lores = $ph[0];
        }
        if (count($ph) > 1) {
            if ($ph[1]['scale'] == 2) {
                // original is 640 or less, we can display it directly
                $hires = $lores = $ph[0];
            } else {
                $hires = $ph[0];
                $lores = $ph[1];
            }
        }
        $album_link = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']);
        $tools = Null;
        $lock = Null;
        if ($can_post && $ph[0]['uid'] == $owner_uid) {
            $tools = array('profile' => array($a->get_baseurl() . '/profile_photo/use/' . $ph[0]['resource_id'], t('Use as profile photo')));
        }
        // lockstate
        $lockstate = strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']) ? array('lock', t('Private Photo')) : array('unlock', Null);
        $a->page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n";
        if ($prevlink) {
            $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
        }
        if ($nextlink) {
            $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
        }
        $a->page['htmlhead'] .= '});</script>';
        if ($prevlink) {
            $prevlink = array($prevlink, t('Previous'));
        }
        $photo = array('href' => $a->get_baseurl() . '/photo/' . $hires['resource_id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title' => t('View Full Size'), 'src' => $a->get_baseurl() . '/photo/' . $lores['resource_id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis'));
        if ($nextlink) {
            $nextlink = array($nextlink, t('Next'));
        }
        // Do we have an item for this photo?
        $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' \n\t\t\t{$sql_extra} LIMIT 1", dbesc($datum));
        $map = null;
        if ($linked_items) {
            xchan_query($linked_items);
            $linked_items = fetch_post_tags($linked_items, true);
            $link_item = $linked_items[0];
            $item_normal = item_normal();
            $r = q("select * from item where parent_mid = '%s' \n\t\t\t\t{$item_normal} and uid = %d {$sql_extra} ", dbesc($link_item['mid']), intval($link_item['uid']));
            if ($r) {
                xchan_query($r);
                $r = fetch_post_tags($r, true);
                $r = conv_sort($r, 'commented');
            }
            $tags = array();
            if ($link_item['term']) {
                $cnt = 0;
                foreach ($link_item['term'] as $t) {
                    $tags[$cnt] = array(0 => format_term_for_display($t));
                    if ($can_post && $ph[0]['uid'] == $owner_uid) {
                        $tags[$cnt][1] = 'tagrm/drop/' . $link_item['id'] . '/' . bin2hex($t['term']);
                        //?f=&item=' . $link_item['id'];
                        $tags[$cnt][2] = t('Remove');
                    }
                    $cnt++;
                }
            }
            if (local_channel() && local_channel() == $link_item['uid']) {
                q("UPDATE `item` SET item_unseen = 0 WHERE parent = %d and uid = %d and item_unseen = 1", intval($link_item['parent']), intval(local_channel()));
            }
            if ($link_item['coord']) {
                $map = generate_map($link_item['coord']);
            }
        }
        //		logger('mod_photo: link_item' . print_r($link_item,true));
        // FIXME - remove this when we move to conversation module
        $r = $r[0]['children'];
        $edit = null;
        if ($can_post) {
            $album_e = $ph[0]['album'];
            $caption_e = $ph[0]['description'];
            $aclselect_e = $_is_owner ? populate_acl($ph[0]) : '';
            $albums = array_key_exists('albums', $a->data) ? $a->data['albums'] : photos_albums_list($a->data['channel'], $a->data['observer']);
            $_SESSION['album_return'] = bin2hex($ph[0]['album']);
            $edit = array('edit' => t('Edit photo'), 'id' => $link_item['id'], 'rotatecw' => t('Rotate CW (right)'), 'rotateccw' => t('Rotate CCW (left)'), 'albums' => $albums['albums'], 'album' => $album_e, 'newalbum_label' => t('Enter a new album name'), 'newalbum_placeholder' => t('or select an existing one (doubleclick)'), 'nickname' => $a->data['channel']['channel_address'], 'resource_id' => $ph[0]['resource_id'], 'capt_label' => t('Caption'), 'caption' => $caption_e, 'tag_label' => t('Add a Tag'), 'permissions' => t('Permissions'), 'aclselect' => $aclselect_e, 'lockstate' => $lockstate[0], 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com'), 'item_id' => count($linked_items) ? $link_item['id'] : 0, 'adult_enabled' => feature_enabled($owner_uid, 'adult_photo_flagging'), 'adult' => array('adult', t('Flag as adult in album view'), intval($ph[0]['is_nsfw']), ''), 'submit' => t('Submit'), 'delete' => t('Delete Photo'));
        }
        if (count($linked_items)) {
            $cmnt_tpl = get_markup_template('comment_item.tpl');
            $tpl = get_markup_template('photo_item.tpl');
            $return_url = $a->cmd;
            $like_tpl = get_markup_template('like_noshare.tpl');
            $likebuttons = '';
            if ($can_post || $can_comment) {
                $likebuttons = array('id' => $link_item['id'], 'likethis' => t("I like this (toggle)"), 'nolike' => t("I don't like this (toggle)"), 'share' => t('Share'), 'wait' => t('Please wait'));
            }
            $comments = '';
            if (!count($r)) {
                if ($can_post || $can_comment) {
                    $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => '', '$feature_encrypt' => false));
                }
            }
            $alike = array();
            $dlike = array();
            $like = '';
            $dislike = '';
            $conv_responses = array('like' => array('title' => t('Likes', 'title')), 'dislike' => array('title' => t('Dislikes', 'title')), 'agree' => array('title' => t('Agree', 'title')), 'disagree' => array('title' => t('Disagree', 'title')), 'abstain' => array('title' => t('Abstain', 'title')), 'attendyes' => array('title' => t('Attending', 'title')), 'attendno' => array('title' => t('Not attending', 'title')), 'attendmaybe' => array('title' => t('Might attend', 'title')));
            if ($r) {
                foreach ($r as $item) {
                    builtin_activity_puller($item, $conv_responses);
                }
                $like_count = x($alike, $link_item['mid']) ? $alike[$link_item['mid']] : '';
                $like_list = x($alike, $link_item['mid']) ? $alike[$link_item['mid'] . '-l'] : '';
                if (count($like_list) > MAX_LIKERS) {
                    $like_list_part = array_slice($like_list, 0, MAX_LIKERS);
                    array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
                } else {
                    $like_list_part = '';
                }
                $like_button_label = tt('Like', 'Likes', $like_count, 'noun');
                //if (feature_enabled($conv->get_profile_owner(),'dislike')) {
                $dislike_count = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid']] : '';
                $dislike_list = x($dlike, $link_item['mid']) ? $dlike[$link_item['mid'] . '-l'] : '';
                $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun');
                if (count($dislike_list) > MAX_LIKERS) {
                    $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
                    array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
                } else {
                    $dislike_list_part = '';
                }
                //}
                $like = isset($alike[$link_item['mid']]) ? format_like($alike[$link_item['mid']], $alike[$link_item['mid'] . '-l'], 'like', $link_item['mid']) : '';
                $dislike = isset($dlike[$link_item['mid']]) ? format_like($dlike[$link_item['mid']], $dlike[$link_item['mid'] . '-l'], 'dislike', $link_item['mid']) : '';
                // display comments
                foreach ($r as $item) {
                    $comment = '';
                    $template = $tpl;
                    $sparkle = '';
                    if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                        continue;
                    }
                    $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                    $profile_url = zid($item['author']['xchan_url']);
                    $sparkle = '';
                    $profile_name = $item['author']['xchan_name'];
                    $profile_avatar = $item['author']['xchan_photo_m'];
                    $profile_link = $profile_url;
                    $drop = '';
                    if ($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) {
                        $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
                    }
                    $name_e = $profile_name;
                    $title_e = $item['title'];
                    unobscure($item);
                    $body_e = prepare_text($item['body'], $item['mimetype']);
                    $comments .= replace_macros($template, array('$id' => $item['id'], '$mode' => 'photos', '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, '$sparkle' => $sparkle, '$title' => $title_e, '$body' => $body_e, '$ago' => relative_date($item['created']), '$indent' => $item['parent'] != $item['id'] ? ' comment' : '', '$drop' => $drop, '$comment' => $comment));
                }
                if ($can_post || $can_comment) {
                    $commentbox = replace_macros($cmnt_tpl, array('$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$ww' => ''));
                }
            }
            $paginate = paginate($a);
        }
        $album_e = array($album_link, $ph[0]['album']);
        $like_e = $like;
        $dislike_e = $dislike;
        $response_verbs = array('like');
        if (feature_enabled($owner_uid, 'dislike')) {
            $response_verbs[] = 'dislike';
        }
        $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
        $photo_tpl = get_markup_template('photo_view.tpl');
        $o .= replace_macros($photo_tpl, array('$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lockstate[1], '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, '$desc' => $ph[0]['description'], '$filename' => $ph[0]['filename'], '$unknown' => t('Unknown'), '$tag_hdr' => t('In This Photo:'), '$tags' => $tags, 'responses' => $responses, '$edit' => $edit, '$map' => $map, '$map_text' => t('Map'), '$likebuttons' => $likebuttons, '$like' => $like_e, '$dislike' => $dislike_e, '$like_count' => $like_count, '$like_list' => $like_list, '$like_list_part' => $like_list_part, '$like_button_label' => $like_button_label, '$like_modal_title' => t('Likes', 'noun'), '$dislike_modal_title' => t('Dislikes', 'noun'), '$dislike_count' => $dislike_count, '$dislike_list' => $dislike_list, '$dislike_list_part' => $dislike_list_part, '$dislike_button_label' => $dislike_button_label, '$modal_dismiss' => t('Close'), '$comments' => $comments, '$commentbox' => $commentbox, '$paginate' => $paginate));
        $a->data['photo_html'] = $o;
        return $o;
    }
    // Default - show recent photos with upload link (if applicable)
    //$o = '';
    $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' \n\t\tand photo_usage in ( %d, %d ) and is_nsfw = %d {$sql_extra} GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe));
    if (count($r)) {
        $a->set_pager_total(count($r));
        $a->set_pager_itemspage(60);
    }
    $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.album, p.scale, p.created FROM photo p INNER JOIN \n\t\t(SELECT resource_id, max(scale) scale FROM photo \n\t\t\tWHERE uid=%d AND album != '%s' AND album != '%s' \n\t\t\tAND photo_usage IN ( %d, %d ) and is_nsfw = %d {$sql_extra} group by resource_id) ph \n\t\tON (p.resource_id = ph.resource_id and p.scale = ph.scale) ORDER by p.created DESC LIMIT %d OFFSET %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc(t('Contact Photos')), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start']));
    $photos = array();
    if (count($r)) {
        $twist = 'rotright';
        foreach ($r as $rr) {
            if ($twist == 'rotright') {
                $twist = 'rotleft';
            } else {
                $twist = 'rotright';
            }
            $ext = $phototypes[$rr['type']];
            if ($a->get_template_engine() === 'internal') {
                $alt_e = template_escape($rr['filename']);
                $name_e = template_escape($rr['album']);
            } else {
                $alt_e = $rr['filename'];
                $name_e = $rr['album'];
            }
            $photos[] = array('id' => $rr['id'], 'twist' => ' ' . $twist . rand(2, 4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'], 'title' => t('View Photo'), 'src' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . ($rr['scale'] == 6 ? 4 : $rr['scale']) . '.' . $ext, 'alt' => $alt_e, 'album' => array('link' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album')));
        }
    }
    if ($_REQUEST['aj']) {
        if ($photos) {
            $o = replace_macros(get_markup_template('photosajax.tpl'), array('$photos' => $photos));
        } 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('photos_recent.tpl');
        $o .= replace_macros($tpl, array('$title' => t('Recent Photos'), '$can_post' => $can_post, '$upload' => array(t('Upload'), $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload'), '$photos' => $photos, '$upload_form' => $upload_form, '$usage' => $usage_message));
    }
    if (!$photos && $_REQUEST['aj']) {
        $o .= '<div id="content-complete"></div>';
        echo $o;
        killme();
    }
    //	paginate($a);
    return $o;
}
Ejemplo n.º 23
0
 function get()
 {
     if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     $observer = get_observer_hash();
     $globaldir = get_directory_setting($observer, 'globaldir');
     // override your personal global search pref if we're doing a navbar search of the directory
     if (intval($_REQUEST['navsearch'])) {
         $globaldir = 1;
     }
     $safe_mode = get_directory_setting($observer, 'safemode');
     $pubforums = get_directory_setting($observer, 'pubforums');
     $o = '';
     nav_set_selected('directory');
     if (x($_POST, 'search')) {
         $search = notags(trim($_POST['search']));
     } else {
         $search = x($_GET, 'search') ? notags(trim(rawurldecode($_GET['search']))) : '';
     }
     if (strpos($search, '=') && local_channel() && get_pconfig(local_channel(), 'feature', 'expert')) {
         $advanced = $search;
     }
     $keywords = $_GET['keywords'] ? $_GET['keywords'] : '';
     // Suggest channels if no search terms or keywords are given
     $suggest = local_channel() && x($_REQUEST, 'suggest') ? $_REQUEST['suggest'] : '';
     if ($suggest) {
         $r = suggestion_query(local_channel(), get_observer_hash());
         // Remember in which order the suggestions were
         $addresses = array();
         $common = array();
         $index = 0;
         foreach ($r as $rr) {
             $common[$rr['xchan_addr']] = $rr['total'];
             $addresses[$rr['xchan_addr']] = $index++;
         }
         // Build query to get info about suggested people
         $advanced = '';
         foreach (array_keys($addresses) as $address) {
             $advanced .= "address=\"{$address}\" ";
         }
         // Remove last space in the advanced query
         $advanced = rtrim($advanced);
     }
     $tpl = get_markup_template('directory_header.tpl');
     $dirmode = intval(get_config('system', 'directory_mode'));
     if ($dirmode == DIRECTORY_MODE_PRIMARY || $dirmode == DIRECTORY_MODE_STANDALONE) {
         $url = z_root() . '/dirsearch';
     }
     if (!$url) {
         $directory = find_upstream_directory($dirmode);
         if (!$directory || !array_key_exists('url', $directory) || !$directory['url']) {
             logger('CRITICAL: No directory server URL');
         }
         $url = $directory['url'] . '/dirsearch';
     }
     $token = get_config('system', 'realm_token');
     logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
     $contacts = array();
     if (local_channel()) {
         $x = q("select abook_xchan from abook where abook_channel = %d", intval(local_channel()));
         if ($x) {
             foreach ($x as $xx) {
                 $contacts[] = $xx['abook_xchan'];
             }
         }
     }
     if ($url) {
         $numtags = get_config('system', 'directorytags');
         $kw = intval($numtags) > 0 ? intval($numtags) : 50;
         if (get_config('system', 'disable_directory_keywords')) {
             $kw = 0;
         }
         $query = $url . '?f=&kw=' . $kw . ($safe_mode != 1 ? '&safe=' . $safe_mode : '');
         if ($token) {
             $query .= '&t=' . $token;
         }
         if (!$globaldir) {
             $query .= '&hub=' . \App::get_hostname();
         }
         if ($search) {
             $query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
         }
         if (strpos($search, '@')) {
             $query .= '&address=' . urlencode($search);
         }
         if ($keywords) {
             $query .= '&keywords=' . urlencode($keywords);
         }
         if ($advanced) {
             $query .= '&query=' . urlencode($advanced);
         }
         if (!is_null($pubforums)) {
             $query .= '&pubforums=' . intval($pubforums);
         }
         $directory_sort_order = get_config('system', 'directory_sort_order');
         if (!$directory_sort_order) {
             $directory_sort_order = 'date';
         }
         $sort_order = x($_REQUEST, 'order') ? $_REQUEST['order'] : $directory_sort_order;
         if ($sort_order) {
             $query .= '&order=' . urlencode($sort_order);
         }
         if (\App::$pager['page'] != 1) {
             $query .= '&p=' . \App::$pager['page'];
         }
         logger('mod_directory: query: ' . $query);
         $x = z_fetch_url($query);
         logger('directory: return from upstream: ' . print_r($x, true), LOGGER_DATA);
         if ($x['success']) {
             $t = 0;
             $j = json_decode($x['body'], true);
             if ($j) {
                 if ($j['results']) {
                     $entries = array();
                     $photo = 'thumb';
                     foreach ($j['results'] as $rr) {
                         $profile_link = chanlink_url($rr['url']);
                         $pdesc = $rr['description'] ? $rr['description'] . '<br />' : '';
                         $connect_link = local_channel() ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : '';
                         // Checking status is disabled ATM until someone checks the performance impact more carefully
                         //$online = remote_online_status($rr['address']);
                         $online = '';
                         if (in_array($rr['hash'], $contacts)) {
                             $connect_link = '';
                         }
                         $location = '';
                         if (strlen($rr['locale'])) {
                             $location .= $rr['locale'];
                         }
                         if (strlen($rr['region'])) {
                             if (strlen($rr['locale'])) {
                                 $location .= ', ';
                             }
                             $location .= $rr['region'];
                         }
                         if (strlen($rr['country'])) {
                             if (strlen($location)) {
                                 $location .= ', ';
                             }
                             $location .= $rr['country'];
                         }
                         $age = '';
                         if (strlen($rr['birthday'])) {
                             if (($years = age($rr['birthday'], 'UTC', '')) != 0) {
                                 $age = $years;
                             }
                         }
                         $page_type = '';
                         if ($rr['total_ratings']) {
                             $total_ratings = sprintf(tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']);
                         } else {
                             $total_ratings = '';
                         }
                         $profile = $rr;
                         if (x($profile, 'locale') == 1 || x($profile, 'region') == 1 || x($profile, 'postcode') == 1 || x($profile, 'country') == 1) {
                             $gender = x($profile, 'gender') == 1 ? t('Gender: ') . $profile['gender'] : False;
                         }
                         $marital = x($profile, 'marital') == 1 ? t('Status: ') . $profile['marital'] : False;
                         $homepage = x($profile, 'homepage') == 1 ? t('Homepage: ') : False;
                         $homepageurl = x($profile, 'homepage') == 1 ? $profile['homepage'] : '';
                         $hometown = x($profile, 'hometown') == 1 ? $profile['hometown'] : False;
                         $about = x($profile, 'about') == 1 ? bbcode($profile['about']) : False;
                         $keywords = x($profile, 'keywords') ? $profile['keywords'] : '';
                         $out = '';
                         if ($keywords) {
                             $keywords = str_replace(',', ' ', $keywords);
                             $keywords = str_replace('  ', ' ', $keywords);
                             $karr = explode(' ', $keywords);
                             if ($karr) {
                                 if (local_channel()) {
                                     $r = q("select keywords from profile where uid = %d and is_default = 1 limit 1", intval(local_channel()));
                                     if ($r) {
                                         $keywords = str_replace(',', ' ', $r[0]['keywords']);
                                         $keywords = str_replace('  ', ' ', $keywords);
                                         $marr = explode(' ', $keywords);
                                     }
                                 }
                                 foreach ($karr as $k) {
                                     if (strlen($out)) {
                                         $out .= ', ';
                                     }
                                     if ($marr && in_arrayi($k, $marr)) {
                                         $out .= '<strong>' . $k . '</strong>';
                                     } else {
                                         $out .= $k;
                                     }
                                 }
                             }
                         }
                         $entry = array('id' => ++$t, 'profile_link' => $profile_link, 'public_forum' => $rr['public_forum'], 'photo' => $rr['photo'], 'hash' => $rr['hash'], 'alttext' => $rr['name'] . (local_channel() || remote_channel() ? ' ' . $rr['address'] : ''), 'name' => $rr['name'], 'age' => $age, 'age_label' => t('Age:'), 'profile' => $profile, 'address' => $rr['address'], 'nickname' => substr($rr['address'], 0, strpos($rr['address'], '@')), 'location' => $location, 'location_label' => t('Location:'), 'gender' => $gender, 'total_ratings' => $total_ratings, 'viewrate' => true, 'canrate' => local_channel() ? true : false, 'pdesc' => $pdesc, 'pdesc_label' => t('Description:'), 'marital' => $marital, 'homepage' => $homepage, 'homepageurl' => linkify($homepageurl), 'hometown' => $hometown, 'hometown_label' => t('Hometown:'), 'about' => $about, 'about_label' => t('About:'), 'conn_label' => t('Connect'), 'forum_label' => t('Public Forum:'), 'connect' => $connect_link, 'online' => $online, 'kw' => $out ? t('Keywords: ') : '', 'keywords' => $out, 'ignlink' => $suggest ? z_root() . '/directory?ignore=' . $rr['hash'] : '', 'ignore_label' => t('Don\'t suggest'), 'common_friends' => $common[$rr['address']] ? intval($common[$rr['address']]) : '', 'common_label' => t('Common connections:'), 'common_count' => intval($common[$rr['address']]), 'safe' => $safe_mode);
                         $arr = array('contact' => $rr, 'entry' => $entry);
                         call_hooks('directory_item', $arr);
                         unset($profile);
                         unset($location);
                         if (!$arr['entry']) {
                             continue;
                         }
                         if ($sort_order == '' && $suggest) {
                             $entries[$addresses[$rr['address']]] = $arr['entry'];
                             // Use the same indexes as originally to get the best suggestion first
                         } else {
                             $entries[] = $arr['entry'];
                         }
                     }
                     ksort($entries);
                     // Sort array by key so that foreach-constructs work as expected
                     if ($j['keywords']) {
                         \App::$data['directory_keywords'] = $j['keywords'];
                     }
                     logger('mod_directory: entries: ' . print_r($entries, true), LOGGER_DATA);
                     if ($_REQUEST['aj']) {
                         if ($entries) {
                             $o = replace_macros(get_markup_template('directajax.tpl'), array('$entries' => $entries));
                         } else {
                             $o = '<div id="content-complete"></div>';
                         }
                         echo $o;
                         killme();
                     } else {
                         $maxheight = 94;
                         $dirtitle = $globaldir ? t('Global Directory') : t('Local Directory');
                         $o .= "<script> var page_query = '" . $_GET['q'] . "'; var extra_args = '" . extra_query_args() . "' ; divmore_height = " . intval($maxheight) . ";  </script>";
                         $o .= replace_macros($tpl, array('$search' => $search, '$desc' => t('Find'), '$finddsc' => t('Finding:'), '$safetxt' => htmlspecialchars($search, ENT_QUOTES, 'UTF-8'), '$entries' => $entries, '$dirlbl' => $suggest ? t('Channel Suggestions') : $dirtitle, '$submit' => t('Find'), '$next' => alt_pager($a, $j['records'], t('next page'), t('previous page')), '$sort' => t('Sort options'), '$normal' => t('Alphabetic'), '$reverse' => t('Reverse Alphabetic'), '$date' => t('Newest to Oldest'), '$reversedate' => t('Oldest to Newest'), '$suggest' => $suggest ? '&suggest=1' : ''));
                     }
                 } else {
                     if ($_REQUEST['aj']) {
                         $o = '<div id="content-complete"></div>';
                         echo $o;
                         killme();
                     }
                     if (\App::$pager['page'] == 1 && $j['records'] == 0 && strpos($search, '@')) {
                         goaway(z_root() . '/chanview/?f=&address=' . $search);
                     }
                     info(t("No entries (some entries may be hidden).") . EOL);
                 }
             }
         }
     }
     return $o;
 }
Ejemplo n.º 24
0
 function Verify($channel, $hubloc)
 {
     logger('auth request received from ' . $hubloc['hubloc_addr']);
     $this->remote = remote_channel();
     $this->remote_service_class = '';
     $this->remote_level = 0;
     $this->remote_hub = $hubloc['hubloc_url'];
     $this->dnt = 0;
     // check credentials and access
     // If they are already authenticated and haven't changed credentials,
     // we can save an expensive network round trip and improve performance.
     // Also check that they are coming from the same site as they authenticated with originally.
     $already_authed = remote_channel() && $hubloc['hubloc_hash'] == remote_channel() && $hubloc['hubloc_url'] === $_SESSION['remote_hub'] ? true : false;
     if ($this->delegate && $this->delegate !== $_SESSION['delegate_channel']) {
         $already_authed = false;
     }
     if ($already_authed) {
         return true;
     }
     if (local_channel()) {
         // tell them to logout if they're logged in locally as anything but the target remote account
         // in which case just shut up because they don't need to be doing this at all.
         if (\App::$channel['channel_hash'] == $hubloc['xchan_hash']) {
             return true;
         } else {
             logger('already authenticated locally as somebody else.');
             notice(t('Remote authentication blocked. You are logged into this site locally. Please logout and retry.') . EOL);
             if ($this->test) {
                 $this->Debug('already logged in locally with a conflicting identity.');
                 return false;
             }
         }
         return false;
     }
     // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the
     // site private key
     // The actual channel sending the packet ($c[0]) is not important, but this provides a
     // generic zot packet with a sender which can be verified
     $p = zot_build_packet($channel, $type = 'auth_check', array(array('guid' => $hubloc['hubloc_guid'], 'guid_sig' => $hubloc['hubloc_guid_sig'])), $hubloc['hubloc_sitekey'], $this->sec);
     $this->Debug('auth check packet created using sitekey ' . $hubloc['hubloc_sitekey']);
     $this->Debug('packet contents: ' . $p);
     $result = zot_zot($hubloc['hubloc_callback'], $p);
     if (!$result['success']) {
         logger('auth_check callback failed.');
         if ($this->test) {
             $this->Debug('auth check request to your site returned .' . print_r($result, true));
         }
         return false;
     }
     $j = json_decode($result['body'], true);
     if (!$j) {
         logger('auth_check json data malformed.');
         if ($this->test) {
             $this->Debug('json malformed: ' . $result['body']);
         }
         return false;
     }
     $this->Debug('auth check request returned .' . print_r($j, true));
     if (!$j['success']) {
         return false;
     }
     // legit response, but we do need to check that this wasn't answered by a man-in-middle
     if (!rsa_verify($this->sec . $hubloc['xchan_hash'], base64url_decode($j['confirm']), $hubloc['xchan_pubkey'])) {
         logger('final confirmation failed.');
         if ($this->test) {
             $this->Debug('final confirmation failed. ' . $sec . print_r($j, true) . print_r($hubloc, true));
         }
         return false;
     }
     if (array_key_exists('service_class', $j)) {
         $this->remote_service_class = $j['service_class'];
     }
     if (array_key_exists('level', $j)) {
         $this->remote_level = $j['level'];
     }
     if (array_key_exists('DNT', $j)) {
         $this->dnt = $j['DNT'];
     }
     // log them in
     if ($this->test) {
         // testing only - return the success result
         $this->test_results['success'] = true;
         $this->Debug('Authentication Success!');
         $this->Finalise();
     }
     $_SESSION['authenticated'] = 1;
     // check for delegation and if all is well, log them in locally with delegation restrictions
     $this->delegate_success = false;
     if ($this->delegate) {
         $r = q("select * from channel left join xchan on channel_hash = xchan_hash where xchan_addr = '%s' limit 1", dbesc($this->delegate));
         if ($r && intval($r[0]['channel_id'])) {
             $allowed = perm_is_allowed($r[0]['channel_id'], $hubloc['xchan_hash'], 'delegate');
             if ($allowed) {
                 $_SESSION['delegate_channel'] = $r[0]['channel_id'];
                 $_SESSION['delegate'] = $hubloc['xchan_hash'];
                 $_SESSION['account_id'] = intval($r[0]['channel_account_id']);
                 require_once 'include/security.php';
                 // this will set the local_channel authentication in the session
                 change_channel($r[0]['channel_id']);
                 $this->delegate_success = true;
             }
         }
     }
     if (!$this->delegate_success) {
         // normal visitor (remote_channel) login session credentials
         $_SESSION['visitor_id'] = $hubloc['xchan_hash'];
         $_SESSION['my_url'] = $hubloc['xchan_url'];
         $_SESSION['my_address'] = $this->address;
         $_SESSION['remote_service_class'] = $this->remote_service_class;
         $_SESSION['remote_level'] = $this->remote_level;
         $_SESSION['remote_hub'] = $this->remote_hub;
         $_SESSION['DNT'] = $this->dnt;
     }
     $arr = array('xchan' => $hubloc, 'url' => $this->desturl, 'session' => $_SESSION);
     call_hooks('magic_auth_success', $arr);
     \App::set_observer($hubloc);
     require_once 'include/security.php';
     \App::set_groups(init_groups_visitor($_SESSION['visitor_id']));
     info(sprintf(t('Welcome %s. Remote authentication successful.'), $hubloc['xchan_name']));
     logger('mod_zot: auth success from ' . $hubloc['xchan_addr']);
     $this->success = true;
     return true;
 }
Ejemplo n.º 25
0
function item_content(&$a)
{
    if (!local_channel() && !remote_channel()) {
        return;
    }
    require_once 'include/security.php';
    if (argc() == 3 && argv(1) === 'drop' && intval(argv(2))) {
        require_once 'include/items.php';
        $i = q("select id, uid, author_xchan, owner_xchan, source_xchan, item_restrict from item where id = %d limit 1", intval(argv(2)));
        if ($i) {
            $can_delete = false;
            $local_delete = false;
            if (local_channel() && local_channel() == $i[0]['uid']) {
                $local_delete = true;
            }
            $sys = get_sys_channel();
            if (is_site_admin() && $sys['channel_id'] == $i[0]['uid']) {
                $can_delete = true;
            }
            $ob_hash = get_observer_hash();
            if ($ob_hash && ($ob_hash === $i[0]['author_xchan'] || $ob_hash === $i[0]['owner_xchan'] || $ob_hash === $i[0]['source_xchan'])) {
                $can_delete = true;
            }
            if (!($can_delete || $local_delete)) {
                notice(t('Permission denied.') . EOL);
                return;
            }
            // if this is a different page type or it's just a local delete
            // but not by the item author or owner, do a simple deletion
            if ($i[0]['item_restrict'] || $local_delete && !$can_delete) {
                drop_item($i[0]['id']);
            } else {
                // complex deletion that needs to propagate and be performed in phases
                drop_item($i[0]['id'], true, DROPITEM_PHASE1);
                tag_deliver($i[0]['uid'], $i[0]['id']);
            }
        }
    }
}
Ejemplo n.º 26
0
function observer_prohibited($allow_account = false)
{
    if ($allow_account) {
        return get_config('system', 'block_public') && !get_account_id() && !remote_channel() ? true : false;
    }
    return get_config('system', 'block_public') && !local_channel() && !remote_channel() ? true : false;
}
Ejemplo n.º 27
0
function get_online_status($nick)
{
    $ret = array('result' => false);
    if (get_config('system', 'block_public') && !local_channel() && !remote_channel()) {
        return $ret;
    }
    $r = q("select channel_id, channel_hash from channel where channel_address = '%s' limit 1", dbesc(argv(1)));
    if ($r) {
        $hide = get_pconfig($r[0]['channel_id'], 'system', 'hide_online_status');
        if ($hide) {
            return $ret;
        }
        $x = q("select cp_status from chatpresence where cp_xchan = '%s' and cp_room = 0 limit 1", dbesc($r[0]['channel_hash']));
        if ($x) {
            $ret['result'] = $x[0]['cp_status'];
        }
    }
    return $ret;
}
Ejemplo n.º 28
0
 function get($update = 0, $load = false)
 {
     //	logger("mod-display: update = $update load = $load");
     $checkjs = new \Zotlabs\Web\CheckJS(1);
     if ($load) {
         $_SESSION['loadtime'] = datetime_convert();
     }
     if (intval(get_config('system', 'block_public')) && !local_channel() && !remote_channel()) {
         notice(t('Public access denied.') . EOL);
         return;
     }
     require_once "include/bbcode.php";
     require_once 'include/security.php';
     require_once 'include/conversation.php';
     require_once 'include/acl_selectors.php';
     require_once 'include/items.php';
     \App::$page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
     if (argc() > 1 && argv(1) !== 'load') {
         $item_hash = argv(1);
     }
     if ($_REQUEST['mid']) {
         $item_hash = $_REQUEST['mid'];
     }
     if (!$item_hash) {
         \App::$error = 404;
         notice(t('Item not found.') . EOL);
         return;
     }
     $observer_is_owner = false;
     if (local_channel() && !$update) {
         $channel = \App::get_channel();
         $channel_acl = 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']);
         $x = array('is_owner' => true, 'allow_location' => intval(get_pconfig($channel['channel_id'], 'system', 'use_browser_location')) ? '1' : '', 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], 'lockstate' => $group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '', 'visitor' => true, 'profile_uid' => local_channel(), 'return_path' => 'channel/' . $channel['channel_address'], 'expanded' => true, 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true);
         $o = '<div id="jot-popup">';
         $o .= status_editor($a, $x);
         $o .= '</div>';
     }
     // This page can be viewed by anybody so the query could be complicated
     // First we'll see if there is a copy of the item which is owned by us - if we're logged in locally.
     // If that fails (or we aren't logged in locally),
     // query an item in which the observer (if logged in remotely) has cid or gid rights
     // and if that fails, look for a copy of the post that has no privacy restrictions.
     // If we find the post, but we don't find a copy that we're allowed to look at, this fact needs to be reported.
     // find a copy of the item somewhere
     $target_item = null;
     $r = q("select id, uid, mid, parent_mid, item_type, item_deleted from item where mid like '%s' limit 1", dbesc($item_hash . '%'));
     if ($r) {
         $target_item = $r[0];
     }
     $r = null;
     if ($target_item['item_type'] == ITEM_TYPE_WEBPAGE) {
         $x = q("select * from channel where channel_id = %d limit 1", intval($target_item['uid']));
         $y = q("select * from item_id where uid = %d and service = 'WEBPAGE' and iid = %d limit 1", intval($target_item['uid']), intval($target_item['id']));
         if ($x && $y) {
             goaway(z_root() . '/page/' . $x[0]['channel_address'] . '/' . $y[0]['sid']);
         } else {
             notice(t('Page not found.') . EOL);
             return '';
         }
     }
     $simple_update = $update ? " AND item_unseen = 1 " : '';
     if ($update && $_SESSION['loadtime']) {
         $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime']) . "' ) ";
     }
     if ($load) {
         $simple_update = '';
     }
     if (!$update && !$load) {
         $o .= '<div id="live-display"></div>' . "\r\n";
         $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] . "; </script>\r\n";
         \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"), array('$baseurl' => z_root(), '$pgtype' => 'display', '$uid' => '0', '$gid' => '0', '$cid' => '0', '$cmin' => '0', '$cmax' => '99', '$star' => '0', '$liked' => '0', '$conv' => '0', '$spam' => '0', '$fh' => '0', '$nouveau' => '0', '$wall' => '0', '$page' => \App::$pager['page'] != 1 ? \App::$pager['page'] : 1, '$list' => x($_REQUEST, 'list') ? intval($_REQUEST['list']) : 0, '$search' => '', '$order' => '', '$file' => '', '$cats' => '', '$tags' => '', '$dend' => '', '$dbegin' => '', '$verb' => '', '$mid' => $item_hash));
     }
     $observer_hash = get_observer_hash();
     $item_normal = item_normal();
     $sql_extra = public_permissions_sql($observer_hash);
     if ($update && $load || $checkjs->disabled()) {
         $updateable = false;
         $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
         if ($load || $checkjs->disabled()) {
             $r = null;
             require_once 'include/identity.php';
             $sys = get_sys_channel();
             $sysid = $sys['channel_id'];
             if (local_channel()) {
                 $r = q("SELECT * from item\n\t\t\t\t\t\tWHERE uid = %d\n\t\t\t\t\t\tand mid = '%s'\n\t\t\t\t\t\t{$item_normal}\n\t\t\t\t\t\tlimit 1", intval(local_channel()), dbesc($target_item['parent_mid']));
                 if ($r) {
                     $updateable = true;
                 }
             }
             if ($r === null) {
                 // in case somebody turned off public access to sys channel content using permissions
                 // make that content unsearchable by ensuring the owner_xchan can't match
                 if (!perm_is_allowed($sysid, $observer_hash, 'view_stream')) {
                     $sysid = 0;
                 }
                 $r = q("SELECT * from item\n\t\t\t\t\t\tWHERE mid = '%s'\n\t\t\t\t\t\tAND (((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' \n\t\t\t\t\t\tAND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer_hash ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\t\tOR uid = %d )\n\t\t\t\t\t\t{$sql_extra} )\n\t\t\t\t\t\t{$item_normal}\n\t\t\t\t\t\tlimit 1", dbesc($target_item['parent_mid']), intval($sysid));
             }
         }
     } elseif ($update && !$load) {
         $r = null;
         require_once 'include/identity.php';
         $sys = get_sys_channel();
         $sysid = $sys['channel_id'];
         if (local_channel()) {
             $r = q("SELECT * from item\n\t\t\t\t\tWHERE uid = %d\n\t\t\t\t\tand mid = '%s'\n\t\t\t\t\t{$item_normal}\n\t\t\t\t\t{$simple_update}\n\t\t\t\t\tlimit 1", intval(local_channel()), dbesc($target_item['parent_mid']));
             if ($r) {
                 $updateable = true;
             }
         }
         if ($r === null) {
             // in case somebody turned off public access to sys channel content using permissions
             // make that content unsearchable by ensuring the owner_xchan can't match
             if (!perm_is_allowed($sysid, $observer_hash, 'view_stream')) {
                 $sysid = 0;
             }
             $r = q("SELECT * from item\n\t\t\t\t\tWHERE mid = '%s'\n\t\t\t\t\tAND (((( `item`.`allow_cid` = ''  AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' \n\t\t\t\t\tAND `item`.`deny_gid`  = '' AND item_private = 0 ) \n\t\t\t\t\tand owner_xchan in ( " . stream_perms_xchans($observer_hash ? PERMS_NETWORK | PERMS_PUBLIC : PERMS_PUBLIC) . " ))\n\t\t\t\t\tOR uid = %d )\n\t\t\t\t\t{$sql_extra} )\n\t\t\t\t\t{$item_normal}\n\t\t\t\t\t{$simple_update}\n\t\t\t\t\tlimit 1", dbesc($target_item['parent_mid']), intval($sysid));
         }
         $_SESSION['loadtime'] = datetime_convert();
     } else {
         $r = array();
     }
     if ($r) {
         $parents_str = ids_to_querystr($r, 'id');
         if ($parents_str) {
             $items = q("SELECT `item`.*, `item`.`id` AS `item_id` \n\t\t\t\t\tFROM `item`\n\t\t\t\t\tWHERE parent in ( %s ) {$item_normal} ", dbesc($parents_str));
             xchan_query($items);
             $items = fetch_post_tags($items, true);
             $items = conv_sort($items, 'created');
         }
     } else {
         $items = array();
     }
     if ($checkjs->disabled()) {
         $o .= conversation($a, $items, 'display', $update, 'traditional');
         if ($items[0]['title']) {
             \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title'];
         }
     } else {
         $o .= conversation($a, $items, 'display', $update, 'client');
     }
     if ($updateable) {
         $x = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d and parent = %d ", intval(local_channel()), intval($r[0]['parent']));
     }
     $o .= '<div id="content-complete"></div>';
     return $o;
     /*
     	elseif((! $update) && (!  {
     		
     		$r = q("SELECT `id`, item_flags FROM `item` WHERE `id` = '%s' OR `mid` = '%s' LIMIT 1",
     			dbesc($item_hash),
     			dbesc($item_hash)
     		);
     		if($r) {
     			if(intval($r[0]['item_deleted'])) {
     				notice( t('Item has been removed.') . EOL );
     			}
     			else {	
     				notice( t('Permission denied.') . EOL ); 
     			}
     		}
     		else {
     			notice( t('Item not found.') . EOL );
     		}
     
     	}
     */
 }
Ejemplo n.º 29
0
/**
 * remote post
 * 
 * https://yoursite/rpost?f=&title=&body=&remote_return=
 *
 * This can be called via either GET or POST, use POST for long body content as suhosin often limits GET parameter length
 *
 * f= placeholder, often required
 * title= Title of post
 * body= Body of post
 * url= URL which will be parsed and the results appended to the body
 * source= Source application
 * remote_return= absolute URL to return after posting is finished
 * type= choices are 'html' or 'bbcode', default is 'bbcode'
 *
 */
function rpost_content(&$a)
{
    $o = '';
    if (!local_channel()) {
        if (remote_channel()) {
            // redirect to your own site.
            // We can only do this with a GET request so you'll need to keep the text short or risk getting truncated
            // by the wretched beast called 'suhosin'. All the browsers now allow long GET requests, but suhosin
            // blocks them.
            $url = get_rpost_path($a->get_observer());
            // make sure we're not looping to our own hub
            if ($url && !stristr($url, $a->get_hostname())) {
                foreach ($_REQUEST as $key => $arg) {
                    $url .= '&' . $key . '=' . $arg;
                }
                goaway($url);
            }
        }
        // The login procedure is going to bugger our $_REQUEST variables
        // so save them in the session.
        if (array_key_exists('body', $_REQUEST)) {
            $_SESSION['rpost'] = $_REQUEST;
        }
        return login();
    }
    // If we have saved rpost session variables, but nothing in the current $_REQUEST, recover the saved variables
    if (!array_key_exists('body', $_REQUEST) && array_key_exists('rpost', $_SESSION)) {
        $_REQUEST = $_SESSION['rpost'];
        unset($_SESSION['rpost']);
    }
    if (array_key_exists('channel', $_REQUEST)) {
        $r = q("select channel_id from channel where channel_account_id = %d and channel_address = '%s' limit 1", intval(get_account_id()), dbesc($_REQUEST['channel']));
        if ($r) {
            require_once 'include/security.php';
            $change = change_channel($r[0]['channel_id']);
        }
    }
    if ($_REQUEST['remote_return']) {
        $_SESSION['remote_return'] = $_REQUEST['remote_return'];
    }
    if (argc() > 1 && argv(1) === 'return') {
        if ($_SESSION['remote_return']) {
            goaway($_SESSION['remote_return']);
        }
        goaway(z_root() . '/network');
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    if (array_key_exists('type', $_REQUEST) && $_REQUEST['type'] === 'html') {
        require_once 'include/html2bbcode.php';
        $_REQUEST['body'] = html2bbcode($_REQUEST['body']);
    }
    $channel = $a->get_channel();
    $channel_acl = 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']);
    if ($_REQUEST['url']) {
        $x = z_fetch_url(z_root() . '/parse_url?f=&url=' . urlencode($_REQUEST['url']));
        if ($x['success']) {
            $_REQUEST['body'] = $_REQUEST['body'] . $x['body'];
        }
    }
    $x = array('is_owner' => true, 'allow_location' => intval(get_pconfig($channel['channel_id'], 'system', 'use_browser_location')) ? '1' : '', 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], 'lockstate' => $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock', 'acl' => populate_acl($channel_acl), 'bang' => '', 'visitor' => true, 'profile_uid' => local_channel(), 'title' => $_REQUEST['title'], 'body' => $_REQUEST['body'], 'attachment' => $_REQUEST['attachment'], 'source' => x($_REQUEST, 'source') ? strip_tags($_REQUEST['source']) : '', 'return_path' => 'rpost/return');
    $editor = status_editor($a, $x);
    $o .= replace_macros(get_markup_template('edpost_head.tpl'), array('$title' => t('Edit post'), '$editor' => $editor));
    return $o;
}
Ejemplo n.º 30
0
function tagger_content(&$a)
{
    if (!local_channel() && !remote_channel()) {
        return;
    }
    $observer_hash = get_observer_hash();
    //strip html-tags
    $term = notags(trim($_GET['term']));
    //check if empty
    if (!$term) {
        return;
    }
    $item_id = argc() > 1 ? notags(trim(argv(1))) : 0;
    logger('tagger: tag ' . $term . ' item ' . $item_id);
    $r = q("SELECT * FROM item left join xchan on xchan_hash = author_xchan WHERE id = '%s' and uid = %d LIMIT 1", dbesc($item_id), intval(local_channel()));
    if (!$item_id || !$r) {
        logger('tagger: no item ' . $item_id);
        return;
    }
    $item = $r[0];
    $owner_uid = $item['uid'];
    switch ($item['resource_type']) {
        case 'photo':
            $targettype = ACTIVITY_OBJ_PHOTO;
            $post_type = t('photo');
            break;
        case 'event':
            $targgettype = ACTIVITY_OBJ_EVENT;
            $post_type = t('event');
            break;
        default:
            $targettype = ACTIVITY_OBJ_NOTE;
            $post_type = t('post');
            if ($item['mid'] != $item['parent_mid']) {
                $post_type = t('comment');
            }
            break;
    }
    $links = array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => z_root() . '/display/' . $item['mid']));
    $target = json_encode(array('type' => $targettype, 'id' => $item['mid'], 'link' => $links, 'title' => $item['title'], 'content' => $item['body'], 'created' => $item['created'], 'edited' => $item['edited'], 'author' => array('name' => $item['xchan_name'], 'address' => $item['xchan_addr'], 'guid' => $item['xchan_guid'], 'guid_sig' => $item['xchan_guid_sig'], 'link' => array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item['xchan_url']), array('rel' => 'photo', 'type' => $item['xchan_photo_mimetype'], 'href' => $item['xchan_photo_m'])))));
    $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n");
    $tagid = $a->get_baseurl() . '/search?tag=' . $term;
    $objtype = ACTIVITY_OBJ_TAGTERM;
    $obj = json_encode(array('type' => $objtype, 'id' => $tagid, 'link' => array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $tagid)), 'title' => $term, 'content' => $term));
    $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
    // saving here for reference
    // also check out x22d5 and x2317 and x0d6b and x0db8 and x24d0 and xff20 !!!
    $termlink = html_entity_decode('&#x22d5;') . '[zrl=' . $a->get_baseurl() . '/search?tag=' . urlencode($term) . ']' . $term . '[/zrl]';
    $channel = $a->get_channel();
    $arr = array();
    $arr['owner_xchan'] = $item['owner_xchan'];
    $arr['author_xchan'] = $channel['channel_hash'];
    $arr['item_flags'] = ITEM_ORIGIN;
    if ($item['item_flags'] & ITEM_WALL) {
        $arr['item_flags'] |= ITEM_WALL;
    }
    $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
    $alink = '[zrl=' . $item['xchan_url'] . ']' . $item['xchan_name'] . '[/zrl]';
    $plink = '[zrl=' . $item['plink'] . ']' . $post_type . '[/zrl]';
    $arr['body'] = sprintf($bodyverb, $ulink, $alink, $plink, $termlink);
    $arr['verb'] = ACTIVITY_TAG;
    $arr['tgt_type'] = $targettype;
    $arr['target'] = $target;
    $arr['obj_type'] = $objtype;
    $arr['object'] = $obj;
    $arr['parent_mid'] = $item['mid'];
    store_item_tag($item['uid'], $item['id'], TERM_OBJ_POST, TERM_HASHTAG, $term, $tagid);
    $ret = post_activity_item($arr);
    if ($ret['success']) {
        proc_run('php', 'include/notifier.php', 'tag', $ret['activity']['id']);
    }
    killme();
}