You are here

function _vkxp_get_node_images in VK CrossPoster 6.3

Same name and namespace in other branches
  1. 6 vkxp.module \_vkxp_get_node_images()
  2. 6.2 vkxp.module \_vkxp_get_node_images()
  3. 7.2 vkxp.module \_vkxp_get_node_images()
  4. 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.

1 call to _vkxp_get_node_images()
_vkxp_process_node in ./vkxp.module
Process node and send it to VK if needed.

File

./vkxp.module, line 170

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);

    // Try to get images from node object.
    $i = 0;
    $items = $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;
          }

          // Get real image path.
          if ($file = field_file_load($image['fid'])) {
            $images[] = '@' . realpath($file['filepath']);
          }
        }
      }
    }

    // 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;
}