<?php

/**
 * vpanel-stack
 * https://git.stack-source.com/msb/vpanel-stack
 * Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
 * GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
 */

namespace Panel;

class Vhost extends \Panel {

  function beforeRoute($f3) {

    parent::beforeRoute($f3);

    if ($f3->exists('SESSION.domain')) {

      /* set base path for vhost links */
      if ($f3->get('NAV.mapping') == 'vhost') {
        $f3->set('NAV.vhostbase', preg_replace('/\/$/', '', $f3->get('BASE')));
      } elseif ($f3->get('NAV.mapping') == 'vpanel') {
        $f3->set('NAV.vhostbase', preg_replace('/\/$/', '', $f3->get('BASE') . '/Websites/' . $f3->get('SESSION.vhost')));
      }

    }

  }

}