Ejemplo n.º 1
0
function api_direct_messages_box(&$a, $type, $box)
{
    if (api_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // params
    $count = x($_GET, 'count') ? $_GET['count'] : 20;
    $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0;
    if ($page < 0) {
        $page = 0;
    }
    $start = $page * $count;
    $channel = $a->get_channel();
    $profile_url = $a->get_baseurl() . '/channel/' . $channel['channel_address'];
    if ($box == "sentbox") {
        $sql_extra = "`from_xchan`='" . dbesc($channel['channel_hash']) . "'";
    } elseif ($box == "conversation") {
        $sql_extra = "`parent_mid`='" . dbesc($_GET["uri"]) . "'";
    } elseif ($box == "all") {
        $sql_extra = "true";
    } elseif ($box == "inbox") {
        $sql_extra = "`from_xchan`!='" . dbesc($channel['channel_hash']) . "'";
    }
    $r = q("SELECT * FROM `mail` WHERE channel_id = %d AND {$sql_extra} ORDER BY created DESC LIMIT %d OFFSET %d", intval(api_user()), intval($count), intval($start));
    $ret = array();
    if ($r) {
        foreach ($r as $item) {
            if ($item['from_xchan'] == $channel['channel_hash']) {
                $sender = $user_info;
                $recipient = api_get_user($a, null, $item['to_xchan']);
            } else {
                $sender = api_get_user($a, null, $item['from_xchan']);
                $recipient = $user_info;
            }
            $ret[] = api_format_message($item, $recipient, $sender);
        }
    }
    $data = array('$messages' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
    }
    return api_apply_template("direct_messages", $type, $data);
}
Ejemplo n.º 2
0
function api_direct_messages_box(&$a, $type, $box)
{
    if (local_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // params
    $count = x($_GET, 'count') ? $_GET['count'] : 20;
    $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0;
    if ($page < 0) {
        $page = 0;
    }
    $start = $page * $count;
    if ($box == "sentbox") {
        $sql_extra = "`from-url`='%s'";
    } else {
        $sql_extra = "`from-url`!='%s'";
    }
    $r = q("SELECT * FROM `mail` WHERE uid=%d AND {$sql_extra} ORDER BY created DESC LIMIT %d,%d", intval(local_user()), dbesc($a->get_baseurl() . '/profile/' . $a->user['nickname']), intval($start), intval($count));
    $ret = array();
    foreach ($r as $item) {
        switch ($box) {
            case "inbox":
                $recipient = $user_info;
                $sender = api_get_user($a, $item['contact-id']);
                break;
            case "sentbox":
                $recipient = api_get_user($a, $item['contact-id']);
                $sender = $user_info;
                break;
        }
        $ret[] = array('id' => $item['id'], 'created_at' => api_date($item['created']), 'sender_id' => $sender['id'], 'sender_screen_name' => $sender['screen_name'], 'sender' => $sender, 'recipient_id' => $recipient['id'], 'recipient_screen_name' => $recipient['screen_name'], 'recipient' => $recipient, 'text' => $item['title'] . "\n" . strip_tags(bbcode($item['body'])));
    }
    $data = array('$messages' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
    }
    return api_apply_template("direct_messages", $type, $data);
}
Ejemplo n.º 3
0
function api_direct_messages_box(&$a, $type, $box)
{
    if (api_user() === false) {
        return false;
    }
    // params
    $count = x($_GET, 'count') ? $_GET['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;
    $user_id = x($_REQUEST, 'user_id') ? $_REQUEST['user_id'] : "";
    $screen_name = x($_REQUEST, 'screen_name') ? $_REQUEST['screen_name'] : "";
    //  caller user info
    unset($_REQUEST["user_id"]);
    unset($_GET["user_id"]);
    unset($_REQUEST["screen_name"]);
    unset($_GET["screen_name"]);
    $user_info = api_get_user($a);
    //$profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
    $profile_url = $user_info["url"];
    // pagination
    $start = $page * $count;
    // filters
    if ($box == "sentbox") {
        $sql_extra = "`mail`.`from-url`='" . dbesc($profile_url) . "'";
    } elseif ($box == "conversation") {
        $sql_extra = "`mail`.`parent-uri`='" . dbesc($_GET["uri"]) . "'";
    } elseif ($box == "all") {
        $sql_extra = "true";
    } elseif ($box == "inbox") {
        $sql_extra = "`mail`.`from-url`!='" . dbesc($profile_url) . "'";
    }
    if ($max_id > 0) {
        $sql_extra .= ' AND `mail`.`id` <= ' . intval($max_id);
    }
    if ($user_id != "") {
        $sql_extra .= ' AND `mail`.`contact-id` = ' . intval($user_id);
    } elseif ($screen_name != "") {
        $sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name) . "'";
    }
    $r = q("SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid`=%d AND {$sql_extra} AND `mail`.`id` > %d ORDER BY `mail`.`id` DESC LIMIT %d,%d", intval(api_user()), intval($since_id), intval($start), intval($count));
    $ret = array();
    foreach ($r as $item) {
        if ($box == "inbox" || $item['from-url'] != $profile_url) {
            $recipient = $user_info;
            $sender = api_get_user($a, normalise_link($item['contact-url']));
        } elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
            $recipient = api_get_user($a, normalise_link($item['contact-url']));
            $sender = $user_info;
        }
        $ret[] = api_format_messages($item, $recipient, $sender);
    }
    $data = array('$messages' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
    }
    return api_apply_template("direct_messages", $type, $data);
}
Ejemplo n.º 4
0
function api_direct_messages_box(&$a, $type, $box)
{
    if (api_user() === false) {
        return false;
    }
    $user_info = api_get_user($a);
    // params
    $count = x($_GET, 'count') ? $_GET['count'] : 20;
    $page = x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0;
    if ($page < 0) {
        $page = 0;
    }
    $start = $page * $count;
    $profile_url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
    if ($box == "sentbox") {
        $sql_extra = "`from-url`='" . dbesc($profile_url) . "'";
    } elseif ($box == "conversation") {
        $sql_extra = "`parent-uri`='" . dbesc($_GET["uri"]) . "'";
    } elseif ($box == "all") {
        $sql_extra = "true";
    } elseif ($box == "inbox") {
        $sql_extra = "`from-url`!='" . dbesc($profile_url) . "'";
    }
    $r = q("SELECT * FROM `mail` WHERE uid=%d AND {$sql_extra} ORDER BY created DESC LIMIT %d,%d", intval(api_user()), intval($start), intval($count));
    $ret = array();
    foreach ($r as $item) {
        if ($box == "inbox" || $item['from-url'] != $profile_url) {
            $recipient = $user_info;
            $sender = api_get_user($a, $item['contact-id']);
        } elseif ($box == "sentbox" || $item['from-url'] != $profile_url) {
            $recipient = api_get_user($a, $item['contact-id']);
            $sender = $user_info;
        }
        $ret[] = api_format_messages($item, $recipient, $sender);
    }
    $data = array('$messages' => $ret);
    switch ($type) {
        case "atom":
        case "rss":
            $data = api_rss_extra($a, $data, $user_info);
    }
    return api_apply_template("direct_messages", $type, $data);
}