<?php
$email_filter = function ($email) { return str_replace( [ '@', '.' ], [ ' &lt;at&gt; ', ' &lt;dot&gt; ' ], $email ); };
$h1 = function ($text) {$t = substr(trim($text),0,50); return substr($t, 0,strrpos($t,' ')).'&hellip;'; };
$text = function ($t) {return trim( preg_replace('/<br>(\s*)?<br>/','<p>',str_replace(["\n"],['<br>'], preg_replace("/[\t\ ]{2,}/",' ',$t))) ); };
$this->page_title = 'Объявление №'.$this->ad->getId().' '.$h1($this->ad->getText());

require __DIR__ . '/inc/head.php';

ob_start();
?>
  <article>
    <h1 class="page-title"><?php echo $this->page_title; ?></h1>
    <a href="/" class="to-front">&larr;Главная</a>
    <header>
      <div>
        <span><i class="i-date"></i><?php echo $this->ad->getDate(); ?></span>
        <span><i class="i-user"></i><?php echo $this->ad->getUserName(); ?></span><br>
        <span><i class="i-email"></i><?php echo $email_filter($this->ad->getEmail()); ?></span>
        <?php
          if ( ! empty( $this->ad->getHomepage() ) ) {
            echo '<br><span><i class="i-homepage"></i><a href="' . $this->ad->getHomepage() . '" target="_blank">' . $this->ad->getHomepage() . '</a>';
          }
          ?>
      </div>
    </header>
    <p><?php echo $text( $this->ad->getText() ); ?>
  </article>
  <?php
$this->content = ob_get_contents();
ob_end_clean();

require __DIR__ . '/inc/body.php';