# media_api

The media API contains all API methods for creating and retrieving media (files/photos/vtours) info.

Methods: media__

create($data) - Used to create a new media item:

create(array $data) : array

Returns: (array)

['media_error']['MEDIA NAME'] - FALSE - Returned on error. Key includes name of media file

['media_response']['MEDIA NAME'] - TEXT - Response text of what happened. Key includes name of media file.

Parameters:

$data (array)

Expects an array containing the following array keys:

$data['media_parent_id'] - This should be either the User ID or Listing ID that the media is to be associated with, whichever is applicable to ['media_type'].

$data['media_type'] - TEXT - Type of Media: 'listingsimages','listingsfiles','listingsvtours','userimages','usersfiles'

$data['media_data'] -  ARRAY media_data should be an array as follows, the key being the FILENAME for the media file, example "greenhouse.jpg".

$data['media_data']['FILENAME']['caption'] = TEXT - OPTIONAL used to set the media caption: "Your Caption goes here" .

$data['media_data']['FILENAME']['description'] = TEXT - OPTIONAL

  • used to set the media description: 'You description goes here" - .

$data['media_data']['FILENAME']['data'] = BINARY / URL - REQUIRED

  • This should be either the BINARY data for this media or a URL (link) to the media.

$data['media_data']['FILENAME']['remote'] = TRUE /FALSE - OPTIONAL If set to true the media will only be linked to and not downloaded. Only applies when the 'data' key contains a URL.

$data['media_data']['FILENAME']['rank'] - INT - OPTIONAL - Numeric ordering (rank) of the media. If left empty the media will be assigned the next (last) available rank.


delete($data) - Used to delete an existing media item.

delete(array $data) : array

Returns: (array)

['error'] - TRUE/FALSE - Error status of the delete request

['error_msg'] - TEXT - Error message returned (if ['error'] = TRUE).

['status_msg'] - TEXT - Success message (if successful)

['media_type'] - TEXT - Type of Media ('listingsimages','listingsfiles','listingsvtours','userimages','usersfiles')

['media_parent_id'] - INT - The numeric 'userdb_id' or 'listingsdb_id' of the item deleted, whichever is applicable to  the ['media_type'] defined.

Parameters:

$data (array)

Expects an array containing the following array keys:

$data['media_type'] - TEXT - Type of Media ('listingsimages','listingsfiles','listingsvtours','userimages','usersfiles')

$data['media_parent_id'] - INT-  This should be either the User ID or Listing ID that the media is associated with, whichever is applicable.

$data[media_object_id] - TEXT/EMPTY - Should be set to * (asterisk) for removing all items, or the numeric 'userdb_id' or 'listingsdb_id' of a specific media item whichever is applicable to  the ['media_type'] defined.

<?php

//deletes all user files for user_id #4

$result = $api->load_local_api('media__delete',array(

'media_type'=>'usersfiles',

'media_parent_id'=>4,

'media_object_id'=>'*'

));

// format and output the contents of the $result array so the keys

// and values can be seen.

echo '<pre>';

print_r($result);

echo '</pre>';

?>


read($data) - Used to retrieve OR listing photo information.

read(array $data) : array

Returns: (array)

['error'] - TRUE/FALSE - Error status of the read request

['error_msg'] - TEXT - Error message returned (if ['error'] = TRUE).

['media_object']  - ARRAY- Array of media item info as follows.

['media_object']['media_id'] - INT - listingsimages_ID the media item is assigned to.

['media_object']['media_rank'] - INT - Rank of media item

['media_object']['caption'] - TEXT - Media item caption

['media_object']['description'] - TEXT - Media item description

['media_object']['thumb_file_name'] - TEXT - Listing photo image thumbnail name. Will contain a URL if linked image

['media_object']['file_name'] TEXT - Listing image name. Will contain a URL if linked image

['media_object']['thumb_file_src'] - TEXT - URL to thumbnail photo.

['media_object']['file_src'] - TEXT - URL to primary photo.

['media_object']['thumb_width'] - INT - Width of listing photo thumbnail on disk (not applicable for linked photos)

['media_object']['thumb_height']  - INT - Height of listing photo thumbnail on disk  (not applicable for linked photos)

['media_object']['file_width']  - INT - Width of full size listing photo on disk  (not applicable for linked photos)

['media_object']['file_height'] - INT - Height of full size listing photo on disk  (not applicable for linked photos)

['media_object']['remote'] -  TRUE/FALSE - Location of the media file. TRUE = Remote FALSE = Local

['media_count'] - Number - Number of media_objects (images) returned

Parameters:

$data (array)

Expects an array containing the following array keys:

$data['media_parent_id'] - INT - The Listing ID or User ID that the media is associated with, whichever is applicable.

$data['media_type'] - TEXT - Type of Media: 'listingsimages', 'listingsfiles', 'userimages', 'usersfiles' (Last 3 types added in OR v3.3)

$data['media_output'] - TEXT - 'DATA' will return the raw binary data/image. 'URL' will return the link to the remote media. You may not get all expected images if using DATA mode and you have a mix of local and linked images, as remote images will not be returned.

$data['media_limit'] - INT - Optional value to limit the number of media results returned. If this option is not set, or is set to 0, all available media items will be returned. Setting this to 1 will return the first media item determined by the item's rank, 2 will return items rank #1 and #2 if present. (new in OR v3.3)

example:

<?php

//Call the API and get all photo image info excluding binary file data for Listing ID# 4

$result = $api->load_local_api('media__read',array(

'media_type'=>'listingsimages',

'media_parent_id'=>4,

'media_output'=>'URL'

));

if($result['error']){

//If an error occurs die and show the error msg;

die($result['error_msg']);

}

//No error so display the thumbnail images that were returned.

foreach($result['media_object'] as $obj){

echo '<img src="'.$obj['thumb_file_src'].'" width="'.$obj['thumb_width'].'" height="'.$obj['thumb_height'].'" /><br />';

}

//Call the API and return all uploaded file information for listing ID# 3

$result = $api->load_local_api('media__read',array(

'media_type'=>'listingsfiles',

'media_parent_id'=>3,

'media_output'=>'URL'

));

if($result['error']){

//If an error occurs die and show the error msg;

die($result['error_msg']);

}

echo '<pre>';

print_r($result);

echo '</pre>';

//Call the API and return all Agent photo info excluding binary file data for User ID# 3,

$result = $api->load_local_api('media__read',array(

'media_type'=>'userimages',

'media_parent_id'=>3,

'media_output'=>'URL'

));

if($result['error']){

//If an error occurs die and show the error msg;

die($result['error_msg']);

}

//No error so display the thumbnail images that were returned.

foreach($result['media_object'] as $obj){

echo '<img src="'.$obj['thumb_file_src'].'" width="'.$obj['thumb_width'].'" height="'.$obj['thumb_height'].'" /><br />';

}

echo '<pre>';

print_r($result);

echo '</pre>';

?>