<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */
class NoCmsAnb extends CmsAnb
{
  
  public function rewriteUrl(URLParameterBasis $urlparam): string
  {

    if (SEARCHENGINE_FUNCTIONS) {
      
      $urlparameterLink = $urlparam->getStandardSeoLink();
    }
    else {
      $urlparameterLink = $urlparam->getStandardLink();
    }

    $kwurl = $this->getKuferWebUrl();
    $prefix = substr($kwurl, 0, strrpos($kwurl, '/'));

    $wb = '';
    if (SERVER_PFAD === '' || \StringOperations::strpos(SERVER_PFAD, 'webbasys/') !== false) {
      $wb = 'webbasys/';
      
    }

    $result = $prefix . '/' . $wb . $urlparameterLink;

    return $result;
  }

  public function getKuferWebUrl()
  {
    if (SERVER_PFAD !== '') {
      return str_replace('webbasys/index.php', '', SERVER_PFAD);
    } else {
      $urlhelper = URL::loadCurrent();
      $url = $urlhelper->getDirectory();

      return str_replace('webbasys', '', $url);
    }
  }

  public function includeJs(string $handle, string $jsPath): void
  {
    KwAssetCollector::getInstance()->includeJs($handle, $jsPath);
  }

  public function includeCss(string $handle, string $cssPath): void
  {
    KwAssetCollector::getInstance()->includeCss($handle, $cssPath);
  }

  public function getKursCanonicalLink($knr, $kursname): string
  {
    $allgSettings = \AllgSettingsAPI::getAllgSettings();
    if ($allgSettings->linkkursdetails != '') {
      $url = str_replace('{%k_id%}', $knr, $allgSettings->linkkursdetails);
    } else {
      $url = CleanOperations::cleanStringForHtml(INDEXSCRIPT . '?urlparameter=kathaupt' . URLPARAMETER_ZUWEISUNG
          . '11' . URLPARAMETER_TRENNZEICHEN . 'knr' . URLPARAMETER_ZUWEISUNG) . $knr . URLPARAMETER_TRENNZEICHEN;
      if (SEARCHENGINE_FUNCTIONS) {
        $url .= 'kursname' . URLPARAMETER_ZUWEISUNG . \StringOperations::cleanStringForUrl($kursname) . URLPARAMETER_TRENNZEICHEN;
      }
    }

    return \CleanOperations::cleanStringForHtml($url);
  }
}