Esempio 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);
}
Esempio n. 2
0
function pleio_api_format_tweio($item)
{
    $e = pleio_api_export($item, explode(",", "guid,time_created,owner_guid,container_guid,site_guid,description,parent_guid,childs"));
    //				$parent = get_data_row (
    //						sprintf ( "select guid_two as guid from %sentity_relationships where relationship = 'parent' and guid_one = %d", get_config ( "dbprefix" ),
    //								$e ["guid"] ) );
    //				$e ["parent_guid"] = $parent ? intval ( $parent->guid ) : 0;
    $e["parent_guid"] = $e["parent_guid"] ? intval($e["parent_guid"]) : 0;
    $e["wire_thread"] = $item->wire_thread;
    $e["reply"] = $item->reply;
    $e["thread_id"] = $item->wire_thread && ($item->reply || $item->wire_thread == $e["guid"] && $e["childs"]) ? (string) $item->wire_thread : "0";
    $u = pleio_api_format_user(get_user($item->owner_guid));
    $e["name"] = $u["name"];
    $e["avatar"] = $u["avatar"];
    $e["likes_count"] = pleio_api_fetch_likes($item->guid);
    $e["liked"] = 0;
    if ($e["likes_count"]) {
        //$options = array ('guid' => $item->guid, 'annotation_name' => "likes", 'count' => 1, 'annotation_owner_guid' =>  $user->guid);
        //$anno = elgg_get_annotations ( $options );
        $e["liked"] = pleio_api_fetch_likes($item->guid, 1, 0, 0, $user->guid) > 0 ? 1 : 0;
    }
    return $e;
}