function _vkxp_get_node_images in VK CrossPoster 7.2
Same name and namespace in other branches
- 6.3 vkxp.module \_vkxp_get_node_images()
- 6 vkxp.module \_vkxp_get_node_images()
- 6.2 vkxp.module \_vkxp_get_node_images()
- 7 vkxp.module \_vkxp_get_node_images()
Get images from node.
Parameters
$node: Node object that should be crossposted.
Return value
array Array with uploaded images.
2 calls to _vkxp_get_node_images()
- vkxp_post_to_wall_action in ./
vkxp.rules.inc - Action: Post node to VK wall.
- _vkxp_process_node in ./
vkxp.module - Process node and send it to VK if needed.
File
- ./
vkxp.module, line 227
Code
function _vkxp_get_node_images($node) {
$image_ids = '';
// Load image amount that should be sent to VK.
$image_amount = variable_get('vkxp_node_image_limit_' . $node->type, 0);
if ($image_amount) {
// Get node field name that contains image.
$field = variable_get('vkxp_node_image_field_' . $node->type, 0);
// Get image style if exists.
$image_style = variable_get('vkxp_node_image_field_style_' . $node->type, FALSE);
// Try to get images from node object.
$i = 0;
$items = field_get_items('node', $node, $field);
if (!empty($items) && is_array($items)) {
$images = array();
foreach ($items as $image) {
if (isset($image['fid'])) {
// If user set image limit we should check get only selected amount of images.
if ($i++ == $image_amount) {
break;
}
$file = file_load($image['fid']);
if ($image_style) {
$uri = vkxp_get_image_style_uri($image_style, $file);
}
else {
$uri = $file->uri;
}
// Get real image path.
$uri = drupal_realpath($uri);
// PHP version > 5.5.
if (function_exists('curl_file_create')) {
$images[] = curl_file_create($uri);
}
else {
$images[] = '@' . $uri;
}
}
}
}
// Upload images to vk server.
if (!empty($images)) {
$upload_url = _vkxp_get_upload_server();
$image_ids = _vkxp_upload_images($upload_url, $images);
}
}
return $image_ids;
}