Beispiel #1
0
function zot_feed($uid, $observer_hash, $arr)
{
    $result = array();
    $mindate = null;
    $message_id = null;
    require_once 'include/security.php';
    if (array_key_exists('mindate', $arr)) {
        $mindate = datetime_convert('UTC', 'UTC', $arr['mindate']);
    }
    if (array_key_exists('message_id', $arr)) {
        $message_id = $arr['message_id'];
    }
    if (!$mindate) {
        $mindate = NULL_DATE;
    }
    $mindate = dbesc($mindate);
    logger('zot_feed: requested for uid ' . $uid . ' from observer ' . $observer_hash, LOGGER_DEBUG);
    if ($message_id) {
        logger('message_id: ' . $message_id, LOGGER_DEBUG);
    }
    if (!perm_is_allowed($uid, $observer_hash, 'view_stream')) {
        logger('zot_feed: permission denied.');
        return $result;
    }
    if (!is_sys_channel($uid)) {
        $sql_extra = item_permissions_sql($uid, $observer_hash);
    }
    $limit = " LIMIT 100 ";
    if ($mindate != NULL_DATE) {
        $sql_extra .= " and ( created > '{$mindate}' or changed > '{$mindate}' ) ";
    }
    if ($message_id) {
        $sql_extra .= " and mid = '" . dbesc($message_id) . "' ";
        $limit = '';
    }
    $items = array();
    /** @FIXME fix this part for PostgreSQL */
    if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
        return array();
    }
    if (is_sys_channel($uid)) {
        $r = q("SELECT parent, created, postopts from item\n\t\t\tWHERE uid != %d\n\t\t\tAND item_private = 0 AND item_restrict = 0 AND uid in (" . stream_perms_api_uids(PERMS_PUBLIC, 10, 1) . ")\n\t\t\tAND (item_flags &  %d) > 0\n\t\t\t{$sql_extra} GROUP BY parent ORDER BY created ASC {$limit}", intval($uid), intval(ITEM_WALL));
    } else {
        $r = q("SELECT parent, created, postopts from item\n\t\t\tWHERE uid = %d AND item_restrict = 0\n\t\t\tAND (item_flags &  %d) > 0\n\t\t\t{$sql_extra} GROUP BY parent ORDER BY created ASC {$limit}", intval($uid), intval(ITEM_WALL));
    }
    if ($r) {
        for ($x = 0; $x < count($r); $x++) {
            if (strpos($r[$x]['postopts'], 'nodeliver') !== false) {
                unset($r[$x]);
            }
        }
        $parents_str = ids_to_querystr($r, 'parent');
        $sys_query = is_sys_channel($uid) ? $sql_extra : '';
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item`\n\t\t\tWHERE `item`.`item_restrict` = 0\n\t\t\tAND `item`.`parent` IN ( %s ) {$sys_query} ", dbesc($parents_str));
    }
    if ($items) {
        xchan_query($items);
        $items = fetch_post_tags($items);
        require_once 'include/conversation.php';
        $items = conv_sort($items, 'ascending');
    } else {
        $items = array();
    }
    logger('zot_feed: number items: ' . count($items), LOGGER_DEBUG);
    foreach ($items as $item) {
        $result[] = encode_item($item);
    }
    return $result;
}
Beispiel #2
0
function zot_feed($uid, $observer_xchan, $mindate)
{
    $result = array();
    $mindate = datetime_convert('UTC', 'UTC', $mindate);
    if (!$mindate) {
        $mindate = NULL_DATE;
    }
    $mindate = dbesc($mindate);
    logger('zot_feed: ' . $uid);
    if (!perm_is_allowed($uid, $observer_xchan, 'view_stream')) {
        logger('zot_feed: permission denied.');
        return $result;
    }
    if (!is_sys_channel($uid)) {
        require_once 'include/security.php';
        $sql_extra = item_permissions_sql($uid);
    }
    if ($mindate != NULL_DATE) {
        $sql_extra .= " and ( created > '{$mindate}' or edited > '{$mindate}' ) ";
        $limit = "";
    } else {
        $limit = " limit 0, 50 ";
    }
    $items = array();
    if (is_sys_channel($uid)) {
        require_once 'include/security.php';
        $r = q("SELECT distinct parent from item\n\t\t\tWHERE uid != %d\n\t\t\tand uid in (" . stream_perms_api_uids(PERMS_PUBLIC) . ") AND item_restrict = 0 \n\t\t\tAND (item_flags &  %d) \n\t\t\tand item_private = 0 {$sql_extra} ORDER BY created ASC {$limit}", intval($uid), intval(ITEM_WALL));
    } else {
        $r = q("SELECT distinct parent from item\n\t\t\tWHERE uid = %d AND item_restrict = 0\n\t\t\tAND (item_flags &  %d) \n\t\t\t{$sql_extra} ORDER BY created ASC {$limit}", intval($uid), intval(ITEM_WALL));
    }
    if ($r) {
        $parents_str = ids_to_querystr($r, 'parent');
        $sys_query = is_sys_channel($uid) ? $sql_extra : '';
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` \n\t\t\tWHERE `item`.`item_restrict` = 0\n\t\t\tAND `item`.`parent` IN ( %s ) {$sys_query} ", dbesc($parents_str));
    }
    if ($items) {
        xchan_query($items);
        $items = fetch_post_tags($items);
        require_once 'include/conversation.php';
        $items = conv_sort($items, 'ascending');
    } else {
        $items = array();
    }
    logger('zot_feed: number items: ' . count($items), LOGGER_DEBUG);
    foreach ($items as $item) {
        $result[] = encode_item($item);
    }
    return $result;
}
Beispiel #3
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;
}
Beispiel #4
0
function zot_feed($uid, $observer_hash, $arr)
{
    $result = array();
    $mindate = null;
    $message_id = null;
    require_once 'include/security.php';
    if (array_key_exists('mindate', $arr)) {
        $mindate = datetime_convert('UTC', 'UTC', $arr['mindate']);
    }
    if (array_key_exists('message_id', $arr)) {
        $message_id = $arr['message_id'];
    }
    if (!$mindate) {
        $mindate = NULL_DATE;
    }
    $mindate = dbesc($mindate);
    logger('zot_feed: requested for uid ' . $uid . ' from observer ' . $observer_hash, LOGGER_DEBUG);
    if ($message_id) {
        logger('message_id: ' . $message_id, LOGGER_DEBUG);
    }
    if (!perm_is_allowed($uid, $observer_hash, 'view_stream')) {
        logger('zot_feed: permission denied.');
        return $result;
    }
    if (!is_sys_channel($uid)) {
        $sql_extra = item_permissions_sql($uid, $observer_hash);
    }
    $limit = " LIMIT 100 ";
    if ($mindate != NULL_DATE) {
        $sql_extra .= " and ( created > '{$mindate}' or changed > '{$mindate}' ) ";
    }
    if ($message_id) {
        $sql_extra .= " and mid = '" . dbesc($message_id) . "' ";
        $limit = '';
    }
    $items = array();
    /** @FIXME re-unite these SQL statements. There is no need for them to be separate. The mySQL is convoluted with misuse of group by. As it stands, there is a slight difference where the postgres version doesn't remove the duplicate parents up to 100. In practice this doesn't matter. It could be made to match behavior by adding "distinct on (parent) " to the front of the selection list, at a not-worth-it performance penalty (page temp results to disk). duplicates are still ignored in the in() clause, you just get less than 100 parents if there are many children. */
    if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
        $groupby = '';
    } else {
        $groupby = 'GROUP BY parent';
    }
    if (is_sys_channel($uid)) {
        $r = q("SELECT parent, created, postopts from item\n\t\t\tWHERE uid != %d\n\t\t\tAND item_private = 0 AND item_restrict = 0 AND uid in (" . stream_perms_api_uids(PERMS_PUBLIC, 10, 1) . ")\n\t\t\tAND (item_flags &  %d) > 0\n\t\t\t{$sql_extra} {$groupby} ORDER BY created ASC {$limit}", intval($uid), intval(ITEM_WALL));
    } else {
        $r = q("SELECT parent, created, postopts from item\n\t\t\tWHERE uid = %d AND item_restrict = 0\n\t\t\tAND (item_flags &  %d) > 0\n\t\t\t{$sql_extra} {$groupby} ORDER BY created ASC {$limit}", intval($uid), intval(ITEM_WALL));
    }
    if ($r) {
        for ($x = 0; $x < count($r); $x++) {
            if (strpos($r[$x]['postopts'], 'nodeliver') !== false) {
                unset($r[$x]);
            }
        }
        $parents_str = ids_to_querystr($r, 'parent');
        $sys_query = is_sys_channel($uid) ? $sql_extra : '';
        $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item`\n\t\t\tWHERE `item`.`item_restrict` = 0\n\t\t\tAND `item`.`parent` IN ( %s ) {$sys_query} ", dbesc($parents_str));
    }
    if ($items) {
        xchan_query($items);
        $items = fetch_post_tags($items);
        require_once 'include/conversation.php';
        $items = conv_sort($items, 'ascending');
    } else {
        $items = array();
    }
    logger('zot_feed: number items: ' . count($items), LOGGER_DEBUG);
    foreach ($items as $item) {
        $result[] = encode_item($item);
    }
    return $result;
}
Beispiel #5
0
function home_content(&$a, $update = 0, $load = false)
{
    $o = '';
    if ($load) {
        $_SESSION['loadtime'] = datetime_convert();
    }
    if (x($_SESSION, 'theme')) {
        unset($_SESSION['theme']);
    }
    if (x($_SESSION, 'mobile_theme')) {
        unset($_SESSION['mobile_theme']);
    }
    $splash = argc() > 1 && argv(1) === 'splash' ? true : false;
    if (get_config('system', 'projecthome')) {
        $o .= file_get_contents('assets/home.html');
        $a->page['template'] = 'full';
        $a->page['title'] = t('Red Matrix - &quot;The Network&quot;');
        return $o;
    }
    // Deprecated
    $channel_address = get_config("system", "site_channel");
    // See if the sys channel set a homepage
    if (!$channel_address) {
        require_once 'include/identity.php';
        $u = get_sys_channel();
        if ($u) {
            $u = array($u);
            // change to channel_id when below deprecated and skip the $u=...
            $channel_address = $u[0]['channel_address'];
        }
    }
    if ($channel_address) {
        $page_id = 'home';
        $u = q("select channel_id from channel where channel_address = '%s' limit 1", dbesc($channel_address));
        $r = q("select item.* from item left join item_id on item.id = item_id.iid\n\t\t\twhere item.uid = %d and sid = '%s' and service = 'WEBPAGE' and \n\t\t\titem_restrict = %d limit 1", intval($u[0]['channel_id']), dbesc($page_id), intval(ITEM_WEBPAGE));
        if ($r) {
            xchan_query($r);
            $r = fetch_post_tags($r, true);
            if ($r[0]['layout_mid']) {
                $l = q("select body from item where mid = '%s' and uid = %d limit 1", dbesc($r[0]['layout_mid']), intval($u[0]['channel_id']));
                if ($l) {
                    require_once 'include/comanche.php';
                    comanche_parser($a, $l[0]['body']);
                    $a->pdl = $l[0]['body'];
                }
            }
            $a->profile = array('profile_uid' => $u[0]['channel_id']);
            $a->profile_uid = $u[0]['channel_id'];
            $o .= prepare_page($r[0]);
            return $o;
        }
    }
    // Nope, we didn't find an item.  Let's see if there's any html
    if (file_exists('home.html')) {
        $o .= file_get_contents('home.html');
    } else {
        $sitename = get_config('system', 'sitename');
        if ($sitename) {
            $o .= '<h1>' . sprintf(t("Welcome to %s"), $sitename) . '</h1>';
        }
        if (intval(get_config('system', 'block_public')) && !local_channel() && !remote_channel()) {
            // If there's nothing special happening, just spit out a login box
            if (!$a->config['system']['no_login_on_homepage']) {
                $o .= login($a->config['system']['register_policy'] == REGISTER_CLOSED ? 0 : 1);
            }
            return $o;
        } else {
            if (get_config('system', 'disable_discover_tab')) {
                call_hooks('home_content', $o);
                return $o;
            }
            if (!$update) {
                $maxheight = get_config('system', 'home_divmore_height');
                if (!$maxheight) {
                    $maxheight = 75;
                }
                $o .= '<div id="live-home"></div>' . "\r\n";
                $o .= "<script> var profile_uid = " . (intval(local_channel()) ? local_channel() : -1) . "; 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' => 'home', '$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' => $a->pager['page'] != 1 ? $a->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 {
                $a->set_pager_itemspage(20);
                $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
            }
            require_once 'include/identity.php';
            if (get_config('system', 'site_firehose')) {
                require_once 'include/security.php';
                $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0  and (item_flags & " . intval(ITEM_WALL) . " ) > 0 ";
            } else {
                $sys = get_sys_channel();
                $uids = " and item.uid  = " . intval($sys['channel_id']) . " ";
                $a->data['firehose'] = intval($sys['channel_id']);
            }
            $page_mode = 'list';
            $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\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\t\tWHERE true {$uids} AND item.item_restrict = 0\n\t\t\t\t\t\tAND item.parent = item.id\n\t\t\t\t\t\tand ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)\n\t\t\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}\n\t\t\t\t\t\tORDER BY {$ordering} DESC {$pager_sql} ", intval(ABOOK_FLAG_BLOCKED));
                } elseif ($update) {
                    $r = q("SELECT distinct item.id AS item_id, {$ordering} FROM item\n\t\t\t\t\t\tleft join abook on item.author_xchan = abook.abook_xchan\n\t\t\t\t\t\tWHERE true {$uids} AND item.item_restrict = 0\n\t\t\t\t\t\tAND item.parent = item.id {$simple_update}\n\t\t\t\t\t\tand ((abook.abook_flags & %d) = 0 or abook.abook_flags is null)\n\t\t\t\t\t\t{$sql_extra3} {$sql_extra} {$sql_nets}", intval(ABOOK_FLAG_BLOCKED));
                    $_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\t\t\tWHERE true {$uids} AND item.item_restrict = 0\n\t\t\t\t\t\tAND item.parent IN ( %s )\n\t\t\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;
        }
        call_hooks('home_content', $o);
        return $o;
    }
    return $o;
}
Beispiel #6
0
Datei: api.php Projekt: Mauru/red
function api_statuses_public_timeline(&$a, $type)
{
    if (api_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // get last newtork messages
    // params
    $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 20;
    $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0;
    if ($page < 0) {
        $page = 0;
    }
    $since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0;
    $max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0;
    //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
    $start = $page * $count;
    //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
    if ($max_id > 0) {
        $sql_extra = 'AND `item`.`id` <= ' . intval($max_id);
    }
    require_once 'include/security.php';
    $r = q("select * from item where item_restrict = 0\n\t\t\tand allow_cid = ''  and allow_gid = ''\n\t\t\tand deny_cid  = ''  and deny_gid  = ''\n            and item_private = 0\n\t\t\tand uid in ( " . stream_perms_api_uids() . " )\n\t\t\t{$sql_extra}\n\t\t\tAND id > %d group by mid\n            order by received desc LIMIT %d, %d ", intval($since_id), intval($start), intval($count));
    xchan_query($r, true);
    $ret = api_format_items($r, $user_info);
    $data = array('$statuses' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
            break;
        case "as":
            $as = api_format_as($a, $ret, $user_info);
            $as['title'] = $a->config['sitename'] . " " . t('Public Timeline');
            $as['link']['url'] = $a->get_baseurl() . "/";
            return $as;
            break;
    }
    return api_apply_template("timeline", $type, $data);
}