head.inc 8.63 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php

3
function system_get_language_code() {
4 5
    global $config;
    $code = "en-US"; // Set default code.
6

7 8 9 10 11
    // a language code, as per [RFC3066]
    if (isset($config['system']['language'])) {
        $language = $config['system']['language'];
        $code = str_replace("_", "-", $language);
    }
12

13
    return $code;
14 15
}

16 17 18 19 20 21 22
// link menu system
$menu = new OPNsense\Base\Menu\MenuSystem();

// add interfaces to "Interfaces" menu tab... kind of a hack, may need some improvement.
$cnf = OPNsense\Core\Config::getInstance();
$ifarr = array();
foreach ($cnf->object()->interfaces->children() as $key => $node) {
23
    $ifarr[$key] = !empty($node->descr) ? $node->descr->__toString() : strtoupper($key);
24 25 26 27 28 29 30 31 32 33 34 35 36
}
natcasesort($ifarr);
$ordid = 0;
foreach ($ifarr as $key => $descr) {
    $menu->appendItem('Interfaces', $key, array(
        'url' => '/interfaces.php?if=' . $key,
        'visiblename' => '[' . $descr . ']',
        'cssclass' => 'fa fa-sitemap',
        'order' => $ordid++,
    ));
}
unset($ifarr);
$menuSystem = $menu->getItems($_SERVER['REQUEST_URI']);
37 38 39

/* XXX workaround for dashboard */
if (!isset($menuBreadcrumbs)) {
40 41
    /* XXX generating breadcrumbs requires getItems() call */
    $menuBreadcrumbs = $menu->getBreadcrumbs();
42
}
43

44
$themename = htmlspecialchars(get_current_theme());
Ad Schellevis's avatar
Ad Schellevis committed
45

46
$pagetitle = gentitle(array_reverse($menuBreadcrumbs), ' | ');
47
$pagetitle .= sprintf(' | %s.%s', $config['system']['hostname'], $config['system']['domain']);
Ad Schellevis's avatar
Ad Schellevis committed
48

49
?><!doctype html>
50 51 52
<!--[if IE 8 ]><html lang="<?=system_get_language_code();?>" class="ie ie8 lte9 lte8 no-js"><![endif]-->
<!--[if IE 9 ]><html lang="<?=system_get_language_code();?>" class="ie ie9 lte9 no-js"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="<?=system_get_language_code();?>" class="no-js"><!--<![endif]-->
53 54 55 56 57 58 59 60 61 62 63 64 65
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta name="robots" content="index, follow, noodp, noydir" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="copyright" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />

    <title><?= $pagetitle ?></title>

    <!-- include (theme) style -->
66
    <link href="/ui/themes/<?= $themename ?>/build/css/main.css" media="screen, projection" rel="stylesheet">
67 68 69 70 71 72 73

    <!-- TODO: move to theme style -->
    <style>
      .menu-level-3-item {
        font-size: 90%;
        padding-left: 54px !important;
      }
74 75 76 77

      .typeahead {
        overflow: hidden;
      }
78 79 80
    </style>

    <!-- Favicon -->
81
    <link href="/ui/themes/<?= $themename ?>/build/images/favicon.png" rel="shortcut icon">
82 83

    <!-- Stylesheet for fancy select/dropdown -->
84
    <link rel="stylesheet" type="text/css" href="/ui/themes/<?= $themename ?>/build/css/bootstrap-select.css">
85 86

    <!-- bootstrap dialog -->
87
    <link href="/ui/themes/<?= $themename ?>/build/css/bootstrap-dialog.css" rel="stylesheet" type="text/css" />
88 89 90 91 92 93 94 95 96 97


    <!-- Font awesome -->
    <link rel="stylesheet" href="/ui/css/font-awesome.min.css">

    <!--[if lt IE 9]><script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script><![endif]-->

    <!-- nvd3 -->
    <link rel="stylesheet" href="/ui/css/nv.d3.css">

98
    <script>var theme = "<?= $themename ?>"; </script>
99 100

    <!-- JQuery -->
101
    <script type="text/javascript" src="/ui/js/jquery-1.12.0.min.js"></script>
102 103 104 105 106 107 108 109 110 111 112 113 114

    <!-- Ticker used for notices-->
    <script type="text/javascript" src="/javascript/ticker.js"></script>

    <!-- d3 -->
    <script type="text/javascript" src="/ui/js/d3.min.js"></script>

    <!-- nvd3 -->
    <script type="text/javascript" src="/ui/js/nv.d3.min.js"></script>

    <!-- append some helper functions to integrate into the legacy code -->
    <script type="text/javascript" src="/javascript/opnsense_legacy.js"></script>

115 116 117
    <!-- Bootstrap type ahead -->
    <script type="text/javascript" src="/ui/js/bootstrap3-typeahead.min.js"></script>

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
    <?php
    /*
     *  Find all javascript files that need to be included
     *  for this page ... from the arrays ... :)
     *  Coded by: Erik Kristensen
     */

    $dir  = trim(basename($_SERVER['SCRIPT_FILENAME'], '.php'));
    $path = '/usr/local/www/javascript/' . $dir . '/';
    if (is_dir($path)) {
      if ($dh = opendir($path)) {
        while (($file = readdir($dh)) !== false) {
          if (is_dir($file))
            continue;
          echo "\t<script type=\"text/javascript\" src=\"/javascript/{$dir}/{$file}\"></script>\n";
        }
        closedir($dh);
      }
    }

    ?>

    <script type="text/javascript">
    //<![CDATA[
    $( document ).ready(function() {
      $('[data-toggle="tooltip"]').tooltip();
      $("input").attr("autocomplete","off");
      // hide empty menu items
      $('#mainmenu > div > .collapse').each(function(){
        // cleanup empty second level menu containers
        $(this).find("div.collapse").each(function(){
          if ($(this).children().length == 0 ) {
              $("#mainmenu").find('[href="#'+$(this).attr('id')+'"]').remove();
              $(this).remove();
          }
        });

        // cleanup empty first level menu items
        if ($(this).children().length == 0) {
          $("#mainmenu").find('[href="#'+$(this).attr('id')+'"]').remove();
        }
      });

      // link showhelp class behavior
      $("a[class='showhelp']").click(function (event) {
        $("*[for='" + $(this).attr('id') + "']").toggleClass("hidden show");
        event.preventDefault();
      });

      // handle all help messages show/hide
      $('[id*="show_all_help"]').click(function(event) {
        $('[id*="show_all_help"]').toggleClass("fa-toggle-on fa-toggle-off");
        $('[id*="show_all_help"]').toggleClass("text-success text-danger");
        if ($('[id*="show_all_help"]').hasClass("fa-toggle-on")) {
          $('[for*="help_for"]').addClass("show");
          $('[for*="help_for"]').removeClass("hidden");
        } else {
          $('[for*="help_for"]').addClass("hidden");
          $('[for*="help_for"]').removeClass("show");
        }
        event.preventDefault();
      });

      // hide submenu items
      $('#mainmenu .list-group-item').click(function(){
        if($(this).attr('href').substring(0,1) == '#') {
            $('#mainmenu .list-group-item').each(function(){
                if ($(this).attr('aria-expanded') == 'true' && $(this).data('parent') != '#mainmenu') {
                  $("#"+$(this).attr('href').substring(1,999)).collapse('hide');
                }
            });
        }
      });
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

      // hook in live menu search
      $.ajax("/api/core/menu/search/", {
          type: 'get',
          cache: false,
          dataType: "json",
          data: {},
          success: function (data) {
              var menusearch_items = [];
              $.each(data,function(idx, menu_item){
                  if (menu_item.Url != "") {
                      menusearch_items.push({id:menu_item.Url, name:menu_item.breadcrumb});
                  }
              });
              $("#menu_search_box").typeahead({
                  source: menusearch_items,
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
                  matcher: function (item) {
                      var ar = this.query.trim()
                      if (ar == "") {
                          return false;
                      }
                      ar = ar.toLowerCase().split(/\s+/);
                      if (ar.length == 0) {
                          return false;
                      }
                      var it = this.displayText(item).toLowerCase();
                      for (var i = 0; i < ar.length; i++) {
                          if (it.indexOf(ar[i]) == -1) {
                              return false;
                          }
                      }
                      return true;
                  },
224
                  afterSelect: function(item){
225 226 227 228 229 230 231 232
                      // (re)load page
                      if (window.location.href.split("#")[0].indexOf(item.id.split("#")[0]) > -1 ) {
                          // same url, different hash marker
                          window.location.href = item.id;
                          window.location.reload();
                      } else {
                          window.location.href = item.id;
                      }
233 234 235 236
                  }
              });
          }
      });
237 238 239 240 241 242 243 244 245
      // change search input size on focus() to fit results
      $("#menu_search_box").focus(function(){
          $("#menu_search_box").css('width', '450px');
          $("#menu_messages").hide();
      });
      $("#menu_search_box").focusout(function(){
          $("#menu_search_box").css('width', '250px');
          $("#menu_messages").show();
      });
246 247 248
    });
    //]]>
    </script>
249
</head>