You are here

function _vkxp_get_node_images in VK CrossPoster 7

Same name and namespace in other branches
  1. 6.3 vkxp.module \_vkxp_get_node_images()
  2. 6 vkxp.module \_vkxp_get_node_images()
  3. 6.2 vkxp.module \_vkxp_get_node_images()
  4. 7.2 vkxp.module \_vkxp_get_node_images()

Get images from selected imagefield.

Parameters

$node: Node object that should be crossposted.

Return value

array Array with images for uploading.

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

File

./vkxp.module, line 293

Code

function _vkxp_get_node_images($node) {
  $images = array();

  // Load image amount that should be sent to vk.com.
  $image_amount = variable_get('vkxp_' . $node->type . '_image_amount', 0);
  if ($image_amount) {

    // Get node field name that contains image.
    $field = variable_get('vkxp_' . $node->type . '_image_field', '');

    // Try to get images from node object.
    $i = 0;
    $items = field_get_items('node', $node, $field);
    if (!empty($items) && is_array($items)) {
      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.
          $uri = file_load($image['fid'])->uri;
          $images[] = '@' . drupal_realpath($uri);
        }
      }
    }
  }
  return $images;
}