<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\KuferTools\Utils\WssField;


class WssFieldBasisWebLink extends WssField
{
  protected $linkTarget;

  
  public function __construct($pDatamodulColumn, $linkTarget = '')
  {
    parent::__construct($pDatamodulColumn);
    $this->linkTarget = $linkTarget;
  }

  protected function getFieldNichtBearbeitbar($datamodulWert, $isFormular, string $requestPrefix = '')
  {
    $result = \CleanOperations::cleanStringForHtml($this->getValue($datamodulWert, $isFormular));
    $matches = array();
    if (\preg_match('&^([a-z]+)://&', $result, $matches) === 1) {
      $target = $this->linkTarget === '' ? '' : ('target="' . \CleanOperations::cleanStringForHtml($this->linkTarget) . '"');
      $protocol = $matches[1] ?? '';
      if ($protocol === 'https' || $protocol === 'http') {
        
        
        $tagClasses = array('external-link'); 
        if ($protocol === 'http') {
          $tagClasses[] = 'external-link-unsecure';
        }

        return '<a class="' . \implode(' ', $tagClasses) . '" href="' . $result . '" rel="noopener noreferrer nofollow" ' . $target . '>'
          . $this->getLinkDescription($result)
          . '</a>';
      }
    }

    return $result;
  }

  protected function getLinkDescription($htmlLink)
  {
    return $htmlLink;
  }
}