/** * 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; }
/** * @param $guid * @param $username * @param int $limit * @param int $offset * @return array * @throws InvalidParameterException */ function bookmark_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)); 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; }
/** * @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; }
function getBatchImages($id, $user_guid) { // Get images related to this batch $results = elgg_get_entities_from_relationship(array('relationship' => 'belongs_to_batch', 'relationship_guid' => $id, 'inverse_relationship' => true, 'type' => 'object', 'subtype' => 'image', 'offset' => 0)); $site_url = get_config('wwwroot'); if ($results) { foreach ($results as $result) { if ($result->enabled == "yes") { $file_name = $result->getFilenameOnFilestore(); $image_owner_guid_entity = $result->getOwnerEntity(); $image_owner_guid = $image_owner_guid_entity->guid; $image_owner_join_date = $image_owner_guid_entity->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_owner_join_date . '&guid=' . $image_owner_guid . '&name=' . $icon_file_name; $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_owner_join_date . '&guid=' . $image_owner_guid . '&name=' . $file_name; $img_url = elgg_format_url($image_url); $image['guid'] = $result->guid; $image['container_guid'] = $result->container_guid; $image['title'] = $result->title; $image['time_create'] = $image_owner_join_date; $image['owner_guid'] = $result->owner_guid; $image['icon_url'] = $icon_url; $image['img_url'] = $img_url; $image['like_count'] = likes_count_number_of_likes($result->guid); $image['comment_count'] = api_get_image_comment_count($result->guid); $image['like'] = checkLike($result->guid, $user_guid); } $return[] = $image; } } return $return; }