Beispiel #1
0
/**
 * Created by IntelliJ IDEA.
 * User: mlui
 * Date: 2/11/2016
 * Time: 4:40 PM
 */
function album_get_posts($context, $limit = 20, $offset = 0, $username)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
        throw new InvalidParameterException('registration:usernamenotvalid');
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    $loginUser = elgg_get_logged_in_user_entity();
    if ($context == "all") {
        $params = array('type' => 'object', 'subtype' => 'album', 'owner_guid' => NULL, 'limit' => $limit, 'offset' => $offset, 'full_view' => false, 'list_type' => 'gallery', 'gallery_class' => 'tidypics-gallery');
    } else {
        if ($context == 'mine') {
            $params = array('type' => 'object', 'subtype' => 'album', 'owner_guid' => $user->guid, 'limit' => $limit, 'offset' => $offset, 'full_view' => false, 'list_type' => 'gallery', 'gallery_class' => 'tidypics-gallery');
        } else {
            if ($context == 'friends') {
                if ($friends = $user->getFriends(array('limit' => false))) {
                    $friendguids = array();
                    foreach ($friends as $friend) {
                        $friendguids[] = $friend->getGUID();
                    }
                    $params = array('type' => 'object', 'subtype' => 'album', 'owner_guids' => $friendguids, 'limit' => $limit, 'offset' => $offset, 'full_view' => false, 'list_type' => 'gallery', 'gallery_class' => 'tidypics-gallery');
                }
            } else {
                $params = array('type' => 'object', 'subtype' => 'album', 'owner_guid' => NULL, 'limit' => $limit, 'offset' => $offset, 'full_view' => false, 'list_type' => 'gallery', 'gallery_class' => 'tidypics-gallery');
            }
        }
    }
    $albums = elgg_get_entities($params);
    $site_url = get_config('wwwroot');
    if ($albums) {
        $return = array();
        foreach ($albums as $single) {
            $album['guid'] = $single->guid;
            $album_cover = $single->getCoverImage();
            $file_name = $album_cover->getFilenameOnFilestore();
            $image_join_date = $album_cover->time_created;
            $position = strrpos($file_name, '/');
            $position = $position + 1;
            $icon_file_name = substr_replace($file_name, 'smallthumb', $position, 0);
            $image_icon_url = $site_url . 'services/api/rest/json/?method=image.get_post';
            $image_icon_url = $image_icon_url . '&joindate=' . $image_join_date . '&guid=' . $album_cover->guid . '&name=' . $icon_file_name;
            $image_url = $site_url . 'services/api/rest/json/?method=image.get_post';
            $image_url = $image_url . '&joindate=' . $image_join_date . '&guid=' . $album_cover->guid . '&name=' . $file_name;
            $album['cover_icon_url'] = $image_icon_url;
            $album['cover_image_url'] = $image_url;
            if ($single->title != null) {
                $album['title'] = $single->title;
            } else {
                $album['title'] = '';
            }
            $album['time_create'] = time_ago($single->time_created);
            if ($single->description != null) {
                if (strlen($single->description) > 300) {
                    $entityString = substr(strip_tags($single->description), 0, 300);
                    $album['description'] = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...';
                } else {
                    $album['description'] = strip_tags($single->description);
                }
            } else {
                $album['description'] = '';
            }
            $owner = get_entity($single->owner_guid);
            $album['owner']['guid'] = $owner->guid;
            $album['owner']['name'] = $owner->name;
            $album['owner']['username'] = $owner->username;
            $album['owner']['avatar_url'] = getProfileIcon($owner);
            //$owner->getIconURL('small');
            //            $photo['img_url'] = $img_url;
            $album['like_count'] = likes_count_number_of_likes($single->guid);
            $album['comment_count'] = api_get_image_comment_count($single->guid);
            $album['like'] = checkLike($single->guid, $loginUser->guid);
            $return[] = $album;
        }
    } else {
        $msg = elgg_echo('blog:none');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
Beispiel #2
0
/**
 * Created by IntelliJ IDEA.
 * User: mlui
 * Date: 2/12/2016
 * Time: 4:56 PM
 *
 *
 * @param $context
 * @param int $limit
 * @param int $offset
 * @param $username
 * @return array
 * @throws InvalidParameterException
 */
function group_get_list($context, $limit = 20, $offset = 0, $username, $from_guid)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
        throw new InvalidParameterException('registration:usernamenotvalid');
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    $loginUser = elgg_get_logged_in_user_entity();
    if ($context == "all") {
        $params = array('type' => 'group', 'full_view' => false, 'no_results' => elgg_echo('groups:none'), 'distinct' => false, 'limit' => $limit, 'offset' => $offset);
        $groups = elgg_get_entities($params);
    } else {
        if ($context == 'mine') {
            $params = array('type' => 'group', 'container_guid' => $loginUser->guid, 'full_view' => false, 'no_results' => elgg_echo('groups:none'), 'distinct' => false, 'limit' => $limit, 'offset' => $offset);
            $groups = elgg_get_entities($params);
        } else {
            if ($context == 'member') {
                $dbprefix = elgg_get_config('dbprefix');
                $groups = elgg_get_entities_from_relationship(array('type' => 'group', 'relationship' => 'member', 'relationship_guid' => $loginUser->guid, 'inverse_relationship' => false, 'full_view' => false, 'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"), 'order_by' => 'ge.name ASC', 'distinct' => false, 'limit' => $limit, 'offset' => $offset, 'no_results' => elgg_echo('groups:none')));
            } else {
                $params = array('type' => 'group', 'full_view' => false, 'no_results' => elgg_echo('groups:none'), 'distinct' => false, 'limit' => $limit, 'offset' => $offset);
                $groups = elgg_get_entities($params);
            }
        }
    }
    $site_url = get_config('wwwroot');
    if ($groups) {
        $return = array();
        foreach ($groups as $single) {
            $group['guid'] = $single->guid;
            if ($single->name != null) {
                $group['title'] = $single->name;
            } else {
                $group['title'] = '';
            }
            $group['time_create'] = time_ago($single->time_created);
            if ($single->description != null) {
                if (strlen($single->description) > 300) {
                    $entityString = substr(strip_tags($single->description), 0, 300);
                    $group['description'] = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...';
                } else {
                    $group['description'] = strip_tags($single->description);
                }
            } else {
                $group['description'] = '';
            }
            $group['access_id'] = $single->access_id;
            $group['members'] = sizeof($single->getMembers());
            $group['is_member'] = $single->isMember($user);
            $group['permission_public'] = $single->isPublicMembership();
            $group['content_access_mode'] = $single->getContentAccessMode();
            $icon = getProfileIcon($single, 'medium');
            //$single->getIconURL('medium');
            if (strpos($icon, 'graphics/defaultmedium.gif') !== FALSE) {
                $group['icon'] = $icon;
            } else {
                $group['icon'] = $site_url . 'services/api/rest/json/?method=group.get_icon&guid=' . $single->guid;
            }
            if ($single->getTags() == null) {
                $group['tags'] = '';
            } else {
                $group['tags'] = implode(",", $single->getTags());
                //$single->getTags();
            }
            $group['owner'] = getOwner($single->owner_guid);
            $return[] = $group;
        }
    } else {
        $msg = elgg_echo('groups:none');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
Beispiel #3
0
/**
 * @param $guid
 * @param $username
 * @param int $limit
 * @param int $offset
 * @return array
 * @throws InvalidParameterException
 */
function wire_get_comments($guid, $username, $limit = 20, $offset = 0)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    $options = array("metadata_name" => "wire_thread", "metadata_value" => $guid, "type" => "object", "subtype" => "thewire", "limit" => $limit, "offset" => $offset);
    $comments = get_elgg_comments($options, 'elgg_get_entities_from_metadata');
    $return = array();
    if ($comments) {
        foreach ($comments as $single) {
            $comment['guid'] = $single->guid;
            $comment['description'] = $single->description;
            $owner = get_entity($single->owner_guid);
            $comment['owner']['guid'] = $owner->guid;
            $comment['owner']['name'] = $owner->name;
            $comment['owner']['username'] = $owner->username;
            $comment['owner']['avatar_url'] = getProfileIcon($owner);
            //$owner->getIconURL('small');
            $comment['time_created'] = time_ago($single->time_created);
            $comment['like_count'] = likes_count_number_of_likes($single->guid);
            $comment['like'] = checkLike($single->guid, $user->guid);
            $return[] = $comment;
        }
    } else {
        $msg = elgg_echo('generic_comment:none');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
Beispiel #4
0
function getOwner($guid)
{
    $entity = get_entity($guid);
    $owner['guid'] = $guid;
    $owner['name'] = $entity->name;
    $owner['username'] = $entity->username;
    $owner['avatar_url'] = getProfileIcon($entity);
    //$entity->getIconURL('small');;
    return $owner;
}
Beispiel #5
0
/**
 * Web service to get sent messages
 *
 * @param int|string $limit (optional) default 10
 * @param int|string $offset (optional) default 0
 * @return array $mesage Array of files uploaded
 * @throws InvalidParameterException
 */
function messages_sent($limit = 10, $offset = 0)
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $params = array('type' => 'object', 'subtype' => 'messages', 'metadata_name' => 'fromId', 'metadata_value' => $user->guid, 'owner_guid' => $user->guid, 'offset' => $offset, 'limit' => $limit, 'full_view' => false);
    $list = elgg_get_entities_from_metadata($params);
    if ($list) {
        foreach ($list as $single) {
            $message['guid'] = $single->guid;
            $message['subject'] = $single->title;
            $user = get_entity($single->toId);
            $message['user']['guid'] = $user->guid;
            $message['user']['name'] = $user->name;
            $message['user']['username'] = $user->username;
            $message['user']['avatar_url'] = getProfileIcon($user);
            //$user->getIconURL('small');
            $message['timestamp'] = time_ago((int) $single->time_created);
            $message['description'] = $single->description;
            if ($single->readYet) {
                $message['read'] = "yes";
            } else {
                $message['read'] = "no";
            }
            $return[] = $message;
        }
    } else {
        $msg = elgg_echo('messages:nomessages');
        throw new InvalidParameterException($msg);
    }
    return $return;
}
Beispiel #6
0
function getRiverActivity($activities, $user, $login_user)
{
    $handle = array();
    $site_url = get_config('wwwroot');
    foreach ($activities as $activity) {
        $userEntity = get_entity($activity->subject_guid);
        $avatar_url = getProfileIcon($userEntity);
        $object_guid = $activity->object_guid;
        $entity = get_entity($object_guid);
        $activity_like = checkLike($activity->object_guid, $login_user->guid);
        $activity_comment_count = getCommentCount($activity);
        $activity_like_count = likes_count_number_of_likes($activity->object_guid);
        $entityString = "";
        $entityTxt = "";
        $icon_url = "";
        $img_url = "";
        $message_board = "";
        $container_entity = "";
        $batch_images = array();
        $isObject = false;
        if ($activity->subtype == "tidypics_batch") {
            $isObject = true;
            $batch_images = getBatchImages($activity->object_guid, $user->guid);
            if (sizeof($batch_images) > 1) {
                $entityTxt = "added the photos to the album";
                $album_guid = $batch_images[0]['container_guid'];
                $activity_like = checkLike($album_guid, $login_user->guid);
                $activity_comment_count = api_get_image_comment_count($album_guid);
                $activity_like_count = likes_count_number_of_likes($album_guid);
            } else {
                if (sizeof($batch_images) == 1) {
                    $activity_like_count = $batch_images[0]['like_count'];
                    $activity_comment_count = $batch_images[0]['comment_count'];
                    $activity_like = $batch_images[0]['like'];
                    $img = get_entity($batch_images[0]['guid']);
                    $original_file_name = $img->originalfilename;
                    $container_entity = get_entity($entity->container_guid);
                    if ($img->title != null) {
                        $entityTxt = "added the photo " . $img->title . " to the album " . $container_entity->title;
                    } else {
                        $entityTxt = "added the photo " . $original_file_name . " to the album " . $container_entity->title;
                    }
                    if ($img->description != null) {
                        if (strlen($img->description) > 300) {
                            $entityString = substr(strip_tags($img->description), 0, 300);
                            $entityString = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...';
                        } else {
                            $entityString = strip_tags($img->description);
                        }
                    } else {
                        $entityString = '';
                    }
                }
            }
        } else {
            if ($activity->action_type == "create" && $activity->subtype == "album") {
                $isObject = true;
                $album = get_entity($activity->object_guid);
                $entityTxt = "created a new photo album " . $album->title;
                $container_entity = get_entity($entity->container_guid);
                if ($container_entity->type == 'group') {
                    $entityTxt = $entityTxt . ' in the group ' . $container_entity->name;
                }
                $album_cover = $album->getCoverImage();
                $file_name = $album_cover->getFilenameOnFilestore();
                $image_join_date = $album_cover->time_created;
                $position = strrpos($file_name, '/');
                $position = $position + 1;
                $icon_file_name = substr_replace($file_name, 'largethumb', $position, 0);
                $image_icon_url = $site_url . 'services/api/rest/json/?method=image.get_post';
                $image_icon_url = $image_icon_url . '&joindate=' . $image_join_date . '&guid=' . $album_cover->guid . '&name=' . $icon_file_name;
                $image_icon_url = elgg_format_url($image_icon_url);
                $image_url = $site_url . 'services/api/rest/json/?method=image.get_post';
                $image_url = $image_url . '&joindate=' . $image_join_date . '&guid=' . $album_cover->guid . '&name=' . $file_name;
                $image_url = elgg_format_url($image_url);
                $batch_images[] = createAlbumCoverImage($album_cover, $image_join_date, $image_icon_url, $image_url, $user);
            } else {
                if ($activity->action_type == "friend" && $activity->subtype == "") {
                    $isObject = true;
                    $msg = "is now a friend with";
                    $friendEntity = get_entity($activity->object_guid);
                    $entityTxt = $msg . " " . $friendEntity->name;
                    $icon_url = getProfileIcon($friendEntity);
                    $icon_url = elgg_format_url($icon_url);
                    $img_url = getProfileIcon($friendEntity, 'master');
                    //$friendEntity->getIconURL('master');
                    if (strpos($img_url, 'user/defaultmaster.gif') !== false) {
                        $img_url = getProfileIcon($friendEntity, 'large');
                        //$friendEntity->getIconURL('large');
                    }
                    $img_url = elgg_format_url($img_url);
                } else {
                    if ($activity->action_type == "update" && $activity->view == 'river/user/default/profileiconupdate') {
                        $isObject = true;
                        $entityTxt = "has a new avatar";
                        $entityString = "";
                        $timeCreated = time_ago($activity->posted);
                        $batch_images[] = createProfileImageBatch($activity->object_guid, $timeCreated, $userEntity);
                    } else {
                        if ($activity->subtype == "comment" && $activity->action_type == "comment" && $activity->view == 'river/object/comment/album') {
                            $isObject = true;
                            $album_comment = get_entity($activity->object_guid);
                            $album_entity = '';
                            if ($album_comment) {
                                $album_entity = get_entity($album_comment->container_guid);
                            }
                            $entityTxt = 'comment on album ' . $album_entity->title;
                            $entityString = $album_comment->description;
                            $entityString = strip_tags($entityString);
                        } else {
                            if ($activity->subtype == "file" && $activity->action_type == "create" && $activity->view == 'river/object/file/create') {
                                $isObject = true;
                                $container_entity = get_entity($entity->container_guid);
                                if ($container_entity->type == 'group') {
                                    $entityTxt = 'uploaded the file ' . $entity->title . ' in the group ' . $container_entity->name;
                                } else {
                                    $entityTxt = 'uploaded the file ' . $entity->title;
                                }
                                if ($entity->description != null) {
                                    $entityString = $entity->description;
                                    $entityString = strip_tags($entityString);
                                } else {
                                    $entityString = $entity->title;
                                }
                                $simpletype = $entity->simpletype;
                                if ($simpletype == "image") {
                                    $activity->type = 'image';
                                    $icon_url = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $entity->guid . '&size=largethumb';
                                    $icon_url = elgg_format_url($icon_url);
                                    $img_url = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $entity->guid . '&size=original';
                                    $img_url = elgg_format_url($img_url);
                                } else {
                                    $activity->type = 'download';
                                    $icon_url = getProfileIcon($entity, 'large');
                                    //elgg_format_url($entity->getIconURL('large'));
                                    $img_url = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $entity->guid . '&size=' . $entity->originalfilename;
                                    $img_url = elgg_format_url($img_url);
                                }
                            } else {
                                if ($activity->subtype == "comment" && $activity->action_type == "comment" && $activity->view == 'river/object/comment/create') {
                                    $isObject = true;
                                    $file_entity = get_entity($activity->target_guid);
                                    if ($file_entity->title) {
                                        $entityTxt = 'comment on ' . $file_entity->title;
                                    } else {
                                        $entityTxt = 'comment on post';
                                    }
                                    $entityString = $entity->description;
                                    $entityString = strip_tags($entityString);
                                } else {
                                    if ($activity->action_type == "comment" && $activity->subtype == "comment" && $activity->view == 'river/object/comment/image') {
                                        $isObject = true;
                                        $image_entity = get_entity($activity->target_guid);
                                        $image_file_name = $image_entity->originalfilename;
                                        if ($image_file_name) {
                                            $entityTxt = 'comment on photo ' . $image_file_name;
                                        } else {
                                            $entityTxt = 'comment on post';
                                        }
                                        $entityString = $entity->description;
                                        $entityString = strip_tags($entityString);
                                    } else {
                                        if ($activity->action_type == "create" && $activity->subtype == "thewire" && $activity->view == 'river/object/thewire/create') {
                                            $isObject = true;
                                            $entityTxt = 'posted to the wire';
                                            $entityString = $entity->description;
                                            $entityString = strip_tags($entityString);
                                        } else {
                                            if ($activity->action_type == "create" && $activity->view == 'river/group/create') {
                                                $isObject = true;
                                                $entityTxt = 'created the group ' . $entity->name;
                                                $entityString = strip_tags($entity->description);
                                            } else {
                                                if ($activity->action_type == "join" && $activity->view == 'river/relationship/member/create') {
                                                    $isObject = true;
                                                    $entityTxt = 'joined the group ' . $entity->name;
                                                    $entityString = strip_tags($entity->description);
                                                } else {
                                                    if ($activity->action_type == "messageboard" && $activity->view == 'river/object/messageboard/create') {
                                                        $isObject = true;
                                                        $post_on_entity = get_entity($activity->object_guid);
                                                        $message_board = elgg_get_annotation_from_id($activity->annotation_id);
                                                        $entityTxt = 'posted on ' . $post_on_entity->name . '\'s message board';
                                                        $entityString = strip_tags($message_board->value);
                                                    } else {
                                                        if ($activity->action_type == "create" && $activity->view == 'river/object/blog/create' && $activity->subtype == 'blog') {
                                                            $isObject = true;
                                                            $container_entity = get_entity($entity->container_guid);
                                                            if ($container_entity->type == 'group') {
                                                                $entityTxt = 'published a blog post ' . $entity->title . ' in the group ' . $container_entity->name;
                                                            } else {
                                                                $entityTxt = 'published a blog post ' . $entity->title;
                                                            }
                                                            if ($entity->description != null) {
                                                                if (strlen($entity->description) > 300) {
                                                                    $entityString = substr(strip_tags($entity->description), 0, 300);
                                                                    $entityString = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...';
                                                                } else {
                                                                    $entityString = strip_tags($entity->description);
                                                                }
                                                            } else {
                                                                $entityString = '';
                                                            }
                                                        } else {
                                                            if ($activity->subtype == "bookmarks" && $activity->action_type == "create" && $activity->view == 'river/object/bookmarks/create') {
                                                                $isObject = true;
                                                                $entity = get_entity($activity->object_guid);
                                                                $container_entity = get_entity($entity->container_guid);
                                                                if ($container_entity->type == 'group') {
                                                                    $entityTxt = 'bookmarked ' . $entity->title . ' in the group ' . $container_entity->name;
                                                                } else {
                                                                    $entityTxt = 'bookmarked ' . $entity->title;
                                                                }
                                                                if ($entity->description != null) {
                                                                    $icon_url = getImageLink($entity->description);
                                                                    if (strlen($entity->description) > 300) {
                                                                        $entityString = substr(strip_tags($entity->description), 0, 300);
                                                                        $entityString = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...';
                                                                    } else {
                                                                        $entityString = $entity->description;
                                                                    }
                                                                } else {
                                                                    $entityString = '';
                                                                }
                                                                $entityString = strip_tags($entityString);
                                                                $img_url = $entity->address;
                                                            } else {
                                                                if ($activity->subtype == "discussion_reply" && $activity->action_type == "reply" && $activity->view == 'river/object/discussion_reply/create') {
                                                                    $isObject = true;
                                                                    $target_entity = get_entity($activity->target_guid);
                                                                    $entityTxt = 'replied on the discussion topic ' . $target_entity->title;
                                                                    $entityString = $entity->description;
                                                                    $entityString = strip_tags($entityString);
                                                                } else {
                                                                    if ($activity->subtype == "groupforumtopic" && $activity->action_type == "create" && $activity->view == 'river/object/groupforumtopic/create') {
                                                                        $isObject = true;
                                                                        $container_entity = get_entity($entity->container_guid);
                                                                        $entityTxt = 'added a new discussion topic ' . $entity->title . ' in the group ' . $container_entity->name;
                                                                        if ($entity->description != null) {
                                                                            if (strlen($entity->description) > 300) {
                                                                                $entityString = substr(strip_tags($entity->description), 0, 300);
                                                                                $entityString = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...';
                                                                            } else {
                                                                                $entityString = $entity->description;
                                                                            }
                                                                            $entityString = strip_tags($entityString);
                                                                        } else {
                                                                            $entityString = '';
                                                                        }
                                                                    } else {
                                                                        //$isObject = true;
                                                                        //$entityTxt = get_object_entity_as_row($activity->object_guid)->description;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if ($isObject) {
            $handle[] = array('id' => $activity->id, 'time' => time_ago($activity->posted), 'type' => $activity->type, 'sub_type' => $activity->subtype, 'action_type' => $activity->action_type, 'object_guid' => $activity->object_guid, 'subject_guid' => $activity->subject_guid, 'view' => $activity->view, 'string' => $entityString, 'txt' => $entityTxt, 'name' => $userEntity->name, 'username' => $userEntity->username, 'avatar_url' => $avatar_url, 'icon_url' => $icon_url, 'img_url' => $img_url, 'like_count' => $activity_like_count, 'like' => $activity_like, 'comment_count' => $activity_comment_count, 'batch_images' => $batch_images);
        }
    }
    return $handle;
}
Beispiel #7
0
/**
 * Web service to search members
 *
 * @param string $username - username
 *
 * @return array
 */
function user_search($username, $limit = 20, $offset = 0, $search_name)
{
    $db_prefix = elgg_get_config('dbprefix');
    $options = array('type' => 'user', 'full_view' => false, 'joins' => array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid"), 'wheres' => array("(u.name LIKE \"%{$search_name}%\" OR u.username LIKE \"%{$search_name}%\")"), 'offset' => (int) max(get_input('offset', 0), 0), 'limit' => (int) max(get_input('limit', 10), 0));
    $user = get_user_by_username($username);
    if ($user) {
        $results = get_elgg_list_members($options);
        if ($results) {
            foreach ($results as $result) {
                if ($result->get("enabled") == "yes") {
                    $friend_user = get_entity($result->get("guid"));
                    $member['guid'] = $result->get("guid");
                    $member['name'] = $result->get("name");
                    $member['username'] = $result->get("username");
                    $member['avatar_url'] = getProfileIcon($result);
                    //$result->getIconURL('small');
                    if ($friend_user->isFriendOf($user->guid)) {
                        $member['friend'] = 'FRIEND';
                    } else {
                        if ($friend_user->guid == $user->guid) {
                            $member['friend'] = 'SELF';
                        } else {
                            $member['friend'] = '';
                        }
                    }
                }
                $return[] = $member;
            }
        }
    }
    return $return;
}
Beispiel #8
0
/**
 * @param $guid
 * @param $username
 * @param int $limit
 * @param int $offset
 * @return array
 * @throws InvalidParameterException
 */
function file_get_comments($guid, $username, $limit = 20, $offset = 0)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    $comments = elgg_get_entities(array('type' => 'object', 'subtype' => 'comment', 'container_guid' => $guid, 'limit' => $limit, 'offset' => $offset));
    $return = array();
    if ($comments) {
        foreach ($comments as $single) {
            $comment['guid'] = $single->guid;
            $comment['description'] = strip_tags($single->description);
            $owner = get_entity($single->owner_guid);
            $comment['owner']['guid'] = $owner->guid;
            $comment['owner']['name'] = $owner->name;
            $comment['owner']['username'] = $owner->username;
            $comment['owner']['avatar_url'] = getProfileIcon($owner);
            //$owner->getIconURL('small');
            $comment['time_created'] = time_ago($single->time_created);
            $comment['like_count'] = likes_count_number_of_likes($single->guid);
            $comment['like'] = checkLike($single->guid, $user->guid);
            $return[] = $comment;
        }
    } else {
        $msg = elgg_echo('generic_comment:none');
        throw new InvalidParameterException($msg);
    }
    return $return;
}