/** * 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; }
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; }
/** * Created by IntelliJ IDEA. * User: mlui * Date: 2/12/2016 * Time: 11:32 AM * * * @param $context * @param int $limit * @param int $offset * @param $username * @return array * @throws InvalidParameterException */ function bookmark_get_posts($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 ($from_guid > 0) { $offset = $offset + getBookmarkGuidPosition($from_guid, $context, $loginUser); } if ($context == "all") { $params = array('type' => 'object', 'subtype' => 'bookmarks', 'full_view' => false, 'view_toggle_type' => false, 'no_results' => elgg_echo('bookmarks:none'), 'preload_owners' => true, 'distinct' => false, 'limit' => $limit, 'offset' => $offset); $bookmarks = elgg_get_entities($params); } else { if ($context == 'mine') { $params = array('type' => 'object', 'subtype' => 'bookmarks', 'container_guid' => $loginUser->guid, 'full_view' => false, 'view_toggle_type' => false, 'no_results' => elgg_echo('bookmarks:none'), 'preload_owners' => true, 'distinct' => false, 'limit' => $limit, 'offset' => $offset); $bookmarks = elgg_get_entities($params); } else { if ($context == 'friends') { $bookmarks = elgg_get_entities_from_relationship(array('type' => 'object', 'subtype' => 'bookmarks', 'full_view' => false, 'relationship' => 'friend', 'relationship_guid' => $loginUser->guid, 'relationship_join_on' => 'container_guid', 'no_results' => elgg_echo('bookmarks:none'), 'preload_owners' => true, 'limit' => $limit, 'offset' => $offset)); } else { $params = array('type' => 'object', 'subtype' => 'bookmarks', 'full_view' => false, 'view_toggle_type' => false, 'no_results' => elgg_echo('bookmarks:none'), 'preload_owners' => true, 'distinct' => false, 'limit' => $limit, 'offset' => $offset); $bookmarks = elgg_get_entities($params); } } } if ($bookmarks) { $return = array(); foreach ($bookmarks as $single) { $bookmark['guid'] = $single->guid; if ($single->title != null) { $bookmark['title'] = $single->title; } else { $bookmark['title'] = ''; } $bookmark['time_created'] = time_ago($single->time_created); if ($single->description != null) { if (strlen($single->description) > 300) { $entityString = substr(strip_tags($single->description), 0, 300); $bookmark['description'] = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...'; } else { $bookmark['description'] = strip_tags($single->description); } $bookmark['image_link'] = getImageLink($single->description); } else { $bookmark['description'] = ''; } $bookmark['address'] = $single->address; $bookmark['owner'] = getOwner($single->owner_guid); if ($single->tags == null) { $bookmark['tags'] = ''; } else { $bookmark['tags'] = implode(",", $single->tags); } $bookmark['like_count'] = likes_count_number_of_likes($single->guid); $bookmark['comment_count'] = api_get_image_comment_count($single->guid); $bookmark['like'] = checkLike($single->guid, $loginUser->guid); $return[] = $bookmark; } } else { $msg = elgg_echo('bookmarks:none'); throw new InvalidParameterException($msg); } return $return; }
/** * @param $guid * @param $username * @return array * @throws InvalidParameterException */ function file_get_file($guid, $username) { if (!$username) { $user = elgg_get_logged_in_user_entity(); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $site_url = get_config('wwwroot'); $single = get_entity($guid); if (!elgg_instanceof($single, 'object', 'file')) { exit; } $file['guid'] = $single->guid; $file['title'] = $single->title; if ($single->description == null) { $file['description'] = ''; } else { $file['description'] = strip_tags($single->description); } $owner = get_entity($single->owner_guid); $file['owner']['guid'] = $owner->guid; $file['owner']['name'] = $owner->name; $file['owner']['username'] = $owner->username; $file['owner']['avatar_url'] = getProfileIcon($owner); //$owner->getIconURL('small'); $file['container_guid'] = $single->container_guid; $file['access_id'] = $single->access_id; $file['time_created'] = time_ago($single->time_created); $file['time_updated'] = time_ago($single->time_updated); $file['last_action'] = time_ago($single->last_action); $file['MIMEType'] = $single->mimetype; $file['file_name'] = $single->originalfilename; $file['file_size'] = $single->getSize(); $simpletype = $single->simpletype; if ($simpletype == "image") { $file['file_icon'] = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $single->guid . '&size=smallthumb'; $file['file_icon_large'] = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $single->guid . '&size=largethumb'; $file['file_url'] = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $single->guid . '&size=original'; } else { $file['file_icon'] = getProfileIcon($owner); //$single->getIconURL('small'); $file['file_icon_large'] = getProfileIcon($single, 'large'); //$single->getIconURL('large'); $file['file_url'] = $site_url . 'services/api/rest/json/?method=file.get_post' . '&guid=' . $single->guid . '&size=' . $single->originalfilename; } $file['like_count'] = likes_count_number_of_likes($single->guid); $file['comment_count'] = api_get_image_comment_count($single->guid); $file['like'] = checkLike($single->guid, $user->guid); $return[] = $file; return $return; }