<?php

/**
 * @param $dzsap
 * @param $playerAttributes
 * @param $playerid
 * @return string
 */
function dzsap_parse_items__button_download_generate($dzsap, $playerAttributes, $playerid){

  $download_link = '';


  $stringExtraHtml_leftContent = '';
  $download_link = dzsap_get_download_link($playerAttributes, $playerid);

  $download_str = ' <a rel="nofollow" target="_blank" href="' . $download_link . '" download class="btn-zoomsounds btn-zoomsounds-download"';


  if ($dzsap->mainoptions['register_to_download_opens_in_new_link'] == 'on') {
    $download_str .= ' target="_blank"';
  }

  $download_str .= '><span class="the-icon"><i class="fa fa-get-pocket"></i></span><span class="the-label">' . $dzsap->mainoptions['i18n_free_download'] . '</span></a>';


  $allow_download = true;


  if ($dzsap->mainoptions['allow_download_only_for_registered_users'] == 'on') {

    // dzstooltip-con" style="top:10px;"><span class="dzstooltip arrow-from-start transition-slidein arrow-bottom skin-black align-right" style="width: auto; white-space: nowrap;">Add to Cart</span>
    global $current_user;

//                        print_rr($current_user);


    if ($current_user->ID) {

      if ($dzsap->mainoptions['allow_download_only_for_registered_users_capability'] && $dzsap->mainoptions['allow_download_only_for_registered_users_capability'] != 'read') {
        if (current_user_can($dzsap->mainoptions['allow_download_only_for_registered_users_capability']) == false) {


          $allow_download = false;

        }
      }

    } else {

      $allow_download = false;
    }


  }
  if (current_user_can('manage_options')) {
    $allow_download = true;

  }

  if ($allow_download == false) {


    // -- download button


    $download_str = '<span href="' . $download_link . '" class="btn-zoomsounds btn-zoomsounds-download  dzstooltip-con "><span class="tooltip-indicator"><span class="the-icon"><i class="fa fa-get-pocket"></i></span><span class="the-label" style="opacity:0.5">' . $dzsap->mainoptions['i18n_free_download'] . '</span></span> <span class="dzstooltip arrow-from-start transition-slidein arrow-bottom talign-start style-rounded color-dark-light align-right" style="width: auto; white-space: nowrap;"><span class="dzstooltip--inner">' . $dzsap->mainoptions['i18n_register_to_download'] . '</span></span> </span>';
  }


  // data-playerid="'.$playerid.'"
  $stringExtraHtml_leftContent .= $download_str;
  return $stringExtraHtml_leftContent;
}