<?php
  // Set up some convenience variables:
  $id = $this->driver->getUniqueId();
  $source = $this->driver->getSourceIdentifier();
  if (isset($this->list) && is_object($this->list)) {
    $list_id = $this->list->id;
    $user_id = $this->list->user_id;
  } else {
    $list_id = null;
    $user_id = $this->user ? $this->user->id : null;
  }
  // Thumbnail
  $coverDetails = $this->record($this->driver)->getCoverDetails('list-entry', 'medium', $this->recordLinker($this->results)->getUrl($this->driver));
  $cover = $coverDetails['html'];
  $thumbnail = false;
  $thumbnailAlignment = $this->record($this->driver)->getThumbnailAlignment('list');
  if ($cover):
    ob_start(); ?>
    <div class="media-<?=$thumbnailAlignment ?> <?=$this->escapeHtmlAttr($coverDetails['size'])?>">
      <?=$cover ?>
    </div>
    <?php $thumbnail = ob_get_contents(); ?>
  <?php ob_end_clean(); ?>
<?php endif; ?>
<div class="result<?php if($this->driver->supportsAjaxStatus()): ?> ajaxItem<?php endif ?>">
  <input type="hidden" value="<?=$this->escapeHtmlAttr($id) ?>" class="hiddenId"/>
  <input type="hidden" value="<?=$this->escapeHtmlAttr($source) ?>" class="hiddenSource"/>
  <?=$this->record($this->driver)->getCheckbox()?>
  <div class="media">
    <?php if ($thumbnail && $thumbnailAlignment == 'left'): ?>
      <?=$thumbnail ?>
    <?php endif; ?>
    <div class="media-body">
      <div class="result-body">
        <div class="resultItemLine1">
          <?php $missing = $this->driver instanceof \VuFind\RecordDriver\Missing; ?>
          <?php if (!$missing): ?><a href="<?=$this->recordLinker($this->results)->getUrl($this->driver)?>" class="getFull" data-view="<?=$this->params->getOptions()->getListViewOption() ?>"><?php endif; ?>
            <span class="title"><?=$this->record($this->driver)->getTitleHtml()?></span>
          <?php if (!$missing): ?></a><?php endif; ?>
        </div>

        <div class="resultItemLine2">
          <?php if($this->driver->isCollection()): ?>
            <?=implode('<br>', array_map(array($this, 'escapeHtml'), $this->driver->getSummary())); ?>
          <?php else: ?>
            <?php $summAuthors = $this->driver->getPrimaryAuthors(); if (!empty($summAuthors)): ?>
              <?=$this->transEsc('by')?>
              <?php $authorCount = count($summAuthors); foreach ($summAuthors as $i => $summAuthor): ?>
                <a href="<?=$this->record($this->driver)->getLink('author', $summAuthor)?>"><?=$this->escapeHtml($summAuthor)?></a><?=($i + 1 < $authorCount ? ';' : '') ?>
              <?php endforeach; ?>
            <?php endif; ?>

            <?php $journalTitle = $this->driver->getContainerTitle(); $summDate = $this->driver->getPublicationDates(); ?>
            <?php if (!empty($journalTitle)): ?>
              <?=!empty($summAuthor) ? '<br/>' : ''?>
              <?=/* TODO: handle highlighting more elegantly here */ $this->transEsc('Published in') . ' <a href="' . $this->record($this->driver)->getLink('journaltitle', str_replace(array('{{{{START_HILITE}}}}', '{{{{END_HILITE}}}}'), '', $journalTitle)) . '">' . $this->highlight($journalTitle) . '</a>';?>
              <?=!empty($summDate) ? ' (' . $this->escapeHtml($summDate[0]) . ')' : ''?>
            <?php elseif (!empty($summDate)): ?>
              <?=!empty($summAuthor) ? '<br/>' : ''?>
              <?=$this->transEsc('Published') . ' ' . $this->escapeHtml($summDate[0])?>
            <?php endif; ?>
            <?php $summInCollection = $this->driver->getContainingCollections(); if (false && !empty($summInCollection)): ?>
              <?php foreach ($summInCollection as $collId => $collText): ?>
                <div>
                  <b><?=$this->transEsc("in_collection_label")?></b>
                  <a class="collectionLinkText" href="<?=$this->url('collection', array('id' => $collId))?>?recordID=<?=urlencode($this->driver->getUniqueID())?>">
                    <?=$this->escapeHtml($collText)?>
                  </a>
                </div>
              <?php endforeach; ?>
            <?php endif; ?>
          <?php endif; ?>
        </div>

        <div class="last">
          <?php if(!$this->driver->isCollection()) {
              if ($snippet = $this->driver->getHighlightedSnippet()) {
                if (!empty($snippet['caption'])) {
                  echo '<strong>' . $this->transEsc($snippet['caption']) . ':</strong> ';
                }
                if (!empty($snippet['snippet'])) {
                  echo '<span class="quotestart">&#8220;</span>...' . $this->highlight($snippet['snippet']) . '...<span class="quoteend">&#8221;</span><br/>';
                }
              }
            } ?>

          <?php $listTags = ($this->usertags()->getMode() !== 'disabled') ? $this->driver->getTags(
              null === $list_id ? true : $list_id, // get tags for all lists if no single list is selected
              $user_id, 'tag'
             ) : array();
          ?>
          <?php if (count($listTags) > 0): ?>
            <strong><?=$this->transEsc('Your Tags')?>:</strong>
            <?php foreach ($listTags as $tag): ?>
              <a href="<?=$this->currentPath() . $results->getUrlQuery()->addFacet('tags', $tag->tag)?>"><?=$this->escapeHtml($tag->tag)?></a>
            <?php endforeach; ?>
            <br/>
          <?php endif; ?>
          <?php $listNotes = $this->driver->getListNotes($list_id, $user_id); ?>
          <?php if (count($listNotes) > 0): ?>
            <strong><?=$this->transEsc('Notes')?>:</strong>
            <?php if (count($listNotes) > 1): ?><br/><?php endif; ?>
            <?php foreach ($listNotes as $note): ?>
              <?=$this->escapeHtml($note)?><br/>
            <?php endforeach; ?>
          <?php endif; ?>

          <?php if (count($this->lists) > 0): ?>
              <strong><?=$this->transEsc('Saved in')?>:</strong>
              <?php $i=0;foreach($this->lists as $current): ?>
                  <a href="<?=$this->url('userList', array('id' => $current->id))?>"><?=$this->escapeHtml($current->title)?></a><?php if($i++ < count($this->lists)-1): ?>,<?php endif; ?>
              <?php endforeach; ?>
              <br/>
          <?php endif; ?>

          <div class="callnumAndLocation ajax-availability hidden">
            <?php if ($this->driver->supportsAjaxStatus()): ?>
              <strong class="hideIfDetailed"><?=$this->transEsc('Call Number')?>:</strong>
              <span class="callnumber ajax-availability hidden">
                <?=$this->transEsc('Loading')?>...<br/>
              </span>
              <strong><?=$this->transEsc('Located')?>:</strong>
              <span class="location ajax-availability hidden">
                <?=$this->transEsc('Loading')?>...
              </span>
              <div class="locationDetails"></div>
            <?php else: ?>
              <?php $summCallNo = $this->driver->getCallNumber(); if (!empty($summCallNo)): ?>
                <strong><?=$this->transEsc('Call Number')?>:</strong> <?=$this->escapeHtml($summCallNo)?>
              <?php endif; ?>
            <?php endif; ?>
          </div>

          <?php /* We need to find out if we're supposed to display an OpenURL link ($openUrlActive),
                but even if we don't plan to display the link, we still want to get the $openUrl
                value for use in generating a COinS (Z3988) tag -- see bottom of file.
              */
            $openUrl = $this->openUrl($this->driver, 'results');
            $openUrlActive = $openUrl->isActive();
            // Account for replace_other_urls setting
            $urls = $this->record($this->driver)->getLinkDetails($openUrlActive);

            if ($openUrlActive || !empty($urls)):
          ?>
            <?php if ($openUrlActive): ?>
              <br/>
              <?=$openUrl->renderTemplate()?>
            <?php endif;?>

            <?php if (!is_array($urls)) { $urls = array(); }
              if(!$this->driver->isCollection()):
                foreach ($urls as $current): ?>

          <?php if (strncmp("https://bibb-dspace.bibb.de/handle/BIBB", $current['url'], strlen("https://bibb-dspace.bibb.de/handle/BIBB")) == 0)    continue; ?>
          <?php if (strncmp("https://bibb-dspace.bibb.de/jspui/handle/BIBB", $current['url'], strlen("https://bibb-dspace.bibb.de/jspui/handle/BIBB")) == 0)    continue; ?>
          <?php if (strncmp($current['url'],"http://dispatch.opac.d-nb.de/", strlen("http://dispatch.opac.d-nb.de/")) == 0) : ?>
                <?php $title = $this->driver->getMainTitle(); ?>
                <?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'] = "https://nbn-resolving.org/" .urlencode($current['url']) ; ?>
                <?php $current['desc'] = "URN"; ?>
          <?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 (($start = strrpos($this->proxyUrl($current['url']), "(")) !== false) : ?>
             <a href="<?=$this->escapeHtmlAttr(trim(substr($this->proxyUrl($current['url']),0, $start-1)))?>" class="fulltext" target="new"><i class="fa fa-external-link" aria-hidden="true"></i> <?=($current['url'] == $current['desc']) ? $this->transEsc(trim(substr($this->proxyUrl($current['url']),$start+1,strlen($this->proxyUrl($current['url']))-($start+2)))) : $this->escapeHtml($current['desc'])?></a><br/>
          <?php endif; ?>

          <?php if (($start = strrpos($this->proxyUrl($current['url']), "[")) === false) : ?>
              <a href="<?=$this->escapeHtmlAttr($this->proxyUrl($current['url']))?>" class="fulltext" target="new"><i class="fa fa-external-link" aria-hidden="true"></i> <?=($current['url'] == $current['desc']) ? $this->transEsc('Get full text') : $this->escapeHtml($current['desc'])?></a><br/>
          <?php endif ; ?>
          <?php if (strlen($rightsImage))  : ?>
                <img src="<?= $rightsImage ?>" alt="License" style="zoom: 0.2" name="<?php echo $this->escapeHtmlAttr($this->driver->getUniqueID())?>"
 onmouseover="this.style.zoom='0.8'" onmouseout="this.style.zoom='0.2'" />
          <?php endif; ?>
                <?php endforeach; ?>
              <?php endif; ?>
            <?php endif; ?>
          <br/>

          <?=$this->record($this->driver)->getFormatList() ?>

          <?php if (!$openUrlActive && empty($urls) && $this->driver->supportsAjaxStatus()): ?>
            <span class="status ajax-availability hidden"><?=$this->transEsc('Loading')?>...</span>
            <br/><br/>
          <?php endif; ?>
          <?=$this->record($this->driver)->getPreviews()?>
        </div>
      </div>

      <div class="result-links hidden-print">
        <i class="fa fa-fw fa-edit" aria-hidden="true"></i> <a href="<?=$this->url('myresearch-edit')?>?id=<?=urlencode($id)?>&amp;source=<?=urlencode($source)?><?php if (!is_null($list_id)):?>&amp;list_id=<?=urlencode($list_id)?><?php endif; ?>" class="edit tool"><?=$this->transEsc('Edit')?></a><br/>
        <?php /* Use a different delete URL if we're removing from a specific list or the overall favorites: */
          $deleteUrl = null === $list_id
              ? $this->url('myresearch-favorites')
              : $this->url('userList', array('id' => $list_id));
          $deleteUrlGet = $deleteUrl . '?delete=' . urlencode($id) . '&amp;source=' . urlencode($source);

          $dLabel = 'delete-label-' . preg_replace('[\W]','-',$id);
        ?>
        <div class="dropdown">
          <i class="fa fa-fw fa-trash-o" aria-hidden="true"></i> <a class="dropdown-toggle" id="<?=$dLabel ?>" role="button" data-toggle="dropdown" data-target="#" href="<?=$deleteUrlGet ?>">
            <?=$this->transEsc('Delete') ?>
          </a>
          <ul class="dropdown-menu" role="menu" aria-labelledby="<?=$dLabel ?>">
            <li><a onClick="$.post('<?=$deleteUrl?>', {'delete':'<?=$this->escapeJs($id) ?>','source':'<?=$this->escapeJs($source) ?>','confirm':true},function(){location.reload(true)})" title="<?=$this->transEsc('confirm_delete_brief')?>"><?=$this->transEsc('confirm_dialog_yes')?></a></li>
            <li><a><?=$this->transEsc('confirm_dialog_no')?></a></li>
          </ul>
        </div>

        <?=$this->driver->supportsCoinsOpenUrl()?'<span class="Z3988" title="'.$this->escapeHtmlAttr($this->driver->getCoinsOpenUrl()).'"></span>':''?>
      </div>
    </div>
    <?php if ($thumbnail && $thumbnailAlignment == 'right'): ?>
      <?=$thumbnail ?>
    <?php endif; ?>
  </div>
</div>
