Ejemplo n.º 1
0
function pleio_api_get_messages($sent = 0, $search = "", $offset = 0)
{
    $total = 0;
    $list = array();
    $user = elgg_get_logged_in_user_entity();
    $user_id = $user !== false ? $user->guid : 0;
    $searchSql = "";
    $searchJoin = "";
    $subtype_id = get_subtype_id('object', 'messages');
    if (!$user) {
        return new ErrorResult($fail);
    }
    try {
        if ($search) {
            $search = sanitise_string($search);
            $searchSql = " AND (description LIKE '%%{$search}%%' OR title LIKE '%%{$search}%%' ";
            $sql = "select guid from " . get_config("dbprefix") . "users_entity where name like '%{$search}%' ";
            $users = get_data($sql);
            if (sizeof($users)) {
                $users = array_map(create_function('$user', 'return $user->guid;'), $users);
                $users = implode(",", $users);
                $searchSql .= " OR (msn2.string = '" . ($sent ? "toId" : "fromId") . "' AND msv2.string in ({$users})) ";
                $searchJoin = " INNER JOIN " . get_config("dbprefix") . "metadata n_table2 on e.guid = n_table2.entity_guid  \r\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . get_config("dbprefix") . "metastrings msn2 on n_table2.name_id = msn2.id  \r\n\t\t\t\t\t\t\t\t\t\tINNER JOIN " . get_config("dbprefix") . "metastrings msv2 on n_table2.value_id = msv2.id ";
            }
            $searchSql .= ")";
        }
        $offset = intval($offset);
        $sent_sql = $sent ? "fromId" : "toId";
        $sql = "SELECT %s \r\n\t\t\tFROM " . get_config("dbprefix") . "entities e\r\n\t\t\tINNER JOIN " . get_config("dbprefix") . "objects_entity o on e.guid = o.guid   \r\n\t\t\tINNER JOIN " . get_config("dbprefix") . "metadata n_table on e.guid = n_table.entity_guid  \r\n\t\t\tINNER JOIN " . get_config("dbprefix") . "metastrings msn on n_table.name_id = msn.id  \r\n\t\t\tINNER JOIN " . get_config("dbprefix") . "metastrings msv on n_table.value_id = msv.id\r\n\t\t\t{$searchJoin}\t\r\n\t\t\tWHERE e.owner_guid = %d\r\n\t\t\t{$searchSql} \r\n\t\t\tAND e.type = 'object' AND e.subtype = {$subtype_id}\r\n\t\t\tAND msn.string ='{$sent_sql}' AND msv.string = %d \r\n\t\t\tAND e.enabled = 'yes' ";
        $total = get_data_row(sprintf($sql, "COUNT(e.guid) AS cnt", $user_id, $user_id));
        $total = $total->cnt;
        $data = get_data(sprintf($sql, "DISTINCT e.*", $user_id, $user_id) . sprintf("ORDER BY e.time_created DESC LIMIT %d, 20", $offset));
        foreach ($data as $row) {
            $message = entity_row_to_elggstar($row);
            $export = pleio_api_export($message, array("time_created", "guid", "owner_guid", "container_guid", "site_guid", "title", "description"));
            $export = pleio_api_get_metadata($message->guid, $export);
            unset($export["msg"]);
            // filter links
            $export["description"] = strip_tags(trim(preg_replace("/\\w+:\\/\\/[\\w\\d\\.\\-_\\?=&;:#\\/]+/ism", "", $export["description"]), ": "));
            $u = false;
            if ($export["fromId"] == $user_id) {
                $u = get_entity($export["toId"]);
            } elseif ($export["toId"] == $user_id) {
                $u = get_entity($export["fromId"]);
            }
            $export["name"] = $u->name;
            if ($u instanceof ElggUser) {
                $u = pleio_api_format_user($u);
                $export["avatar"] = $u["avatar"];
            }
            $sender_and_reciever = false;
            if ($export["fromId"] == $export["toId"] && $export["fromId"] == $user_id) {
                foreach ($list as $e) {
                    if ($e["guid"] == $export["guid"] + 1 || $e["guid"] == $export["guid"] - 1) {
                        $sender_and_reciever = true;
                        $total--;
                    }
                }
            }
            if (!$sender_and_reciever) {
                $list[] = $export;
            }
        }
    } catch (Exception $ex) {
        return new ErrorResult(elgg_echo("error:default"));
    }
    return array("total" => $total, "list" => $list, "offset" => $offset);
}
Ejemplo n.º 2
0
function pleio_api_format_group(ElggGroup $group, $user_guid)
{
    $g = pleio_api_export($group, explode(",", "guid,owner_guid,site_guid,name,description"));
    $metadata = pleio_api_get_metadata($group->guid);
    if ($metadata["swordfish_group"]) {
        $g["swordfish"] = $metadata["swordfish_group"];
        $g["name"] .= " [SwordFish]";
    }
    $g["avatar"] = $metadata["icontime"] ? "1" : "0";
    $g["owner_name"] = get_entity($group->owner_guid)->name;
    $g["public"] = $group->membership == ACCESS_PUBLIC ? 1 : 0;
    $g["member"] = is_group_member($g["guid"], $user_guid) ? 1 : 0;
    $g["description"] = trim(strip_tags($g["description"]));
    $g["member_total"] = get_group_members($g["guid"], 0, 0, 0, true);
    $g["has_invitation"] = 0;
    $g["has_pending_membership_request"] = 0;
    if (!$g["member"]) {
        $g["has_invitation"] = check_entity_relationship($group->guid, 'invited', $user_guid) ? 1 : 0;
        $g["has_pending_membership_request"] = check_entity_relationship($user_guid, 'membership_request', $group->guid) ? 1 : 0;
    }
    return $g;
}