You are here

function _vkxp_upload_images in VK CrossPoster 7

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

Upload and save images to vk server.

Parameters

$upload_url: Url of upload server.

$images: Array of images to upload.

Return value

string Uploaded image IDs separated by comma. Example: photo312312_3123123,photo312312_3123124.

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

File

./vkxp.module, line 366

Code

function _vkxp_upload_images($upload_url, $images) {

  // Array with saved image IDs.
  $image_ids = array();
  foreach ($images as $image) {

    // Upload photo.
    $upload_result = vkxp_query('', array(
      'photo' => $image,
    ), $upload_url);

    // If photo was uploaded it should be saved.
    if ($upload_result['server'] && $upload_result['photo'] && $upload_result['hash']) {
      $params = array();
      $params['access_token'] = variable_get('vkxp_access_token', '');
      $params['server'] = $upload_result['server'];
      $params['photo'] = $upload_result['photo'];
      $params['hash'] = $upload_result['hash'];
      if (variable_get('vkxp_wall_owner', 'group') == 'group') {
        $params['gid'] = variable_get('vkxp_group_id', '');
      }
      else {
        $params['uid'] = variable_get('vkxp_group_id', '');
      }

      // Upload query to vk.com.
      $save_result = vkxp_query('photos.saveWallPhoto', $params);

      // If image was successfully saved it returns photo ID in format 'photoXXXXXXX_XXXXXXX'.
      if (isset($save_result['response'][0]['id'])) {
        $image_ids[] = $save_result['response'][0]['id'];
      }
    }
  }
  return !empty($image_ids) ? implode(',', $image_ids) : '';
}