<?php
  $openUrl = $this->openUrl($this->driver, 'record');
  $openUrlActive = $openUrl->isActive();
  // Account for replace_other_urls setting
  $urls = $this->record($this->driver)->getLinkDetails($openUrlActive);
  $title = $this->driver->getMainTitle() ;
  $id   =  $this->driver->getUniqueID(); 
  $data = $this->driver->getRawData();
  $license =  $data['rightsuri'];
  $voevzlink = is_array($data['voevzlink']) ? $data['voevzlink'][0] : $data['voevzlink']; 
  $parts = explode("/", $license[0]);
  $rightsImage = $rightslink = '';
  if (isset($parts) && count($parts) > 1)   {
          $rightsImage = "/vufind/themes/bibb/images/".$parts[4].".png";
	  $rightsLink   = $license[0];
  }
  if (strlen($rightsLink == 0))  {
	$right = $data['license'][0];
	if (strcmp($right,"Urheberrecht") == 0 || strcmp($right,"Deutsches Urheberrecht") == 0)  {
		$rightsLink = "http://www.gesetze-im-internet.de/urhg"; 
		$rightsImage = "/vufind/themes/bibb_new/images/urheberrechtDe.png";
	}
  }

  $pos = strrpos($voevzlink, "(");
  if ($pos !== false)
	$voevzlink = substr($voevzlink,0, $pos); 


//  if ($title) $title = trim(strstr($title,":", true));

 
?>
<?php if (!empty($urls) || $openUrlActive): ?>
    <?php $extend =''; ?>
    <?php if (isset($data['extend'])) : ?>
        <?php $extend = "(" .$data['extend'][0] .")"; ?>
    <?php endif; ?>

  <?php foreach ($urls as $current): ?>
    <?php if (strncmp($current['url'],"https://bibb-dspace.bibb.de/handle", strlen("https://bibb-dspace.bibb.de/handle")) == 0) : ?>
        <?php continue; ?>
    <?endif ; ?>
    <?php if (strncmp($current['url'],"https://bibb-dspace.bibb.de/jspui/handle", strlen("https://bibb-dspace.bibb.de/jspui/handle")) == 0) : ?>
        <?php continue; ?>
    <?endif ; ?>

    <?php if (strncmp($current['url'],"https://bibb-dspace.bibb.de/rest/bitstreams", strlen("https://bibb-dspace.bibb.de/rest/bitstreams")) == 0) : ?>
	<?php if (isset ($voevzlink)) : ?> <?php $current['url'] = $voevzlink; ?> <?endif ; ?>
	<?php $current['desc'] = "Volltext"; ?>
	<?php if (($start = strrpos($current['url'], "(")) !== false) : ?>
        	<?php $current['desc'] = substr($current['url'],$start+1, strrpos($current['url'],")") - $start -1) ; ?>
	<?endif?>
	<?php $current['extend'] = $extend ; ?> 
    <?endif ; ?>


    <?php //Looking for "(" and ")" and separation of the link and the label MUST be located here!! ?>
    <?php if (($start = strrpos($current['url'], "(")) !== false) : ?>
        <?php $current['desc'] = substr($current['url'],$start+1, strrpos($current['url'],")") - $start -1) ; ?>
        <?php $current['url']  = trim(substr($current['url'],0, $start)); ?>
    <?php endif; ?>

    <?php if (($start = strrpos($current['url'], "[")) !== false) : ?>
        <?php $current['desc'] = substr($current['url'],$start+1, strrpos($current['url'],"]") - $start -1) ; ?>
        <?php $current['url']  = trim(substr($current['url'],0, $start)); ?>
    <?php endif; ?>

    <?php if (strncmp($current['url'],"www.bibb.de", strlen("www.bibb.de")) == 0) : ?>
	<?php $current['url'] = "https://" .$current['url']; ?>
    <?php endif; ?>

   <?php if (strncmp(strtolower($current['url']),"http://dx.doi.org/", strlen("http://dx.doi.org/")) == 0) : ?>
        <?php $current['url'] = "https://doi.org/" .urlencode(trim(substr($current['url'], strlen("http://dx.doi.org/")))) ; ?>
        <?php $current['desc'] = "DOI"; ?>
    <?php endif; ?>

   <?php if (strncmp(strtolower($current['url']),"doi:", strlen("doi:")) == 0) : ?>
        <?php $current['url'] = "https://doi.org/" .urlencode(trim(substr($current['url'], strlen("doi:")))) ; ?>
        <?php $current['desc'] = "DOI"; ?>
    <?php endif; ?>

   <?php if (strncmp($current['url'],"http://dispatch.opac.d-nb.de/", strlen("http://dispatch.opac.d-nb.de/")) == 0) : ?>
        <?php $current['url'] = "https://zdb-katalog.de/list.xhtml?t=" .urlencode("\"" .$title ."\"")  ."&key=tit" ; ?>
        <?php $current['desc'] = "\"" .$title ."\" in der ZDB"; ?>
    <?php endif; ?>

    <?php if (strncmp($current['url'],"urn:nbn:de:", strlen("urn:nbn:de:")) == 0) : ?>
	<?php $current['url'] = "http://nbn-resolving.org/" .urlencode($current['url']) ; ?>
	<?php $current['desc'] = "URN"; ?> 
    <?php endif; ?>

    <a href="<?=$this->escapeHtmlAttr(trim($this->proxyUrl($current['url'])))?>"><?=$this->escapeHtml($current['desc'])?></a> &nbsp; &nbsp; <span style="color: #14416b; font-size: 13px;"> <?= $current['extend']; ?></span> 

    <?php if (strlen($rightsImage))  : ?>
		<a href="<?= $rightsLink ?>"><img src="<?= $rightsImage ?>" alt="License" style="zoom: 0.2" name="<?php echo $this->escapeHtmlAttr($this->driver->getUniqueID()); ?>" onmouseover="this.style.zoom='0.22'" onmouseout="this.style.zoom='0.2'" /></a>
	  <?php $rightsImage = ''; ?>
    <?php endif; ?>
    <br />
    <a class="feedbackLink" style="color: #14416b; font-size: 13px;" data-lightbox href="<?=$this->url('feedback-home') ."?function=feedback&comments=Titel: " .urlencode($title) ." (ID: " .$id ."): Link ist nicht korrekt!" ?>"> <i class="fa fa-chain-broken" aria-hidden="true"></i> <?=$this->transEsc('Report broken link')?></a>
    <br />
  <?php endforeach; ?>
  <?php if ($openUrlActive): ?>
    <?=$openUrl->renderTemplate()?><br/>
  <?php endif; ?>
<?php endif; ?>
