You are here

function _vkxp_upload_images in VK CrossPoster 6

Same name and namespace in other branches
  1. 6.3 vkxp.module \_vkxp_upload_images()
  2. 6.2 vkxp.module \_vkxp_upload_images()
  3. 7.2 vkxp.module \_vkxp_upload_images()
  4. 7 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 with uploaded image IDs separated by comma. Example: photo312312_3123123,photo312312_3123124

1 call to _vkxp_upload_images()
vkxp_nodeapi in ./vkxp.module
Implementation of hook_nodeapi

File

./vkxp.module, line 251

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', '');
      }
      $save_result = vkxp_query('photos.saveWallPhoto', $params);

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