Skip to content

Review logic at head of html.tpl.php #2

@khawkins98

Description

@khawkins98

There's probably a better way/home for this

<?php

  // Some useful custom EBI page variables
  $is_admin = (strpos($classes, 'role-administrator') !== FALSE || strpos($classes, 'user-1') !== FALSE);
  $is_authenticated = (strpos($classes, 'role-authenticated-user') !== FALSE || strpos($classes, 'user-1') !== FALSE);
  $is_prod = in_array($_SERVER['HTTP_HOST'], array('www.ebi.ac.uk', 'intranet.ebi.ac.uk', 'staff.ebi.ac.uk', 'content.ebi.ac.uk', 'tsc.ebi.ac.uk'), TRUE);

  // rabbit hole for disallowed pages
  if (!$is_authenticated && preg_match('#^/+(group/)#sm', request_uri())) {
    header("HTTP/1.0 404 Not Found");
    exit();
  }


// WE MIGHT NEED THIS, but let's not assume...
  function ebicompliance_tidy($buffer, $is_admin, $is_prod) {
    $local_server = str_replace('.', '\.', $_SERVER['HTTP_HOST']);
    // remove http protcol from: from www.ebi links
//    $buffer = preg_replace('#(href|src)\s*=\s*(["\'])https?:(//www\.ebi\.ac\.uk)#sm', '$1=$2$3', $buffer); 
//    $buffer = preg_replace('#(url)\s*\(\s*(["\']?)https?:(//www\.ebi\.ac\.uk)#sm', '$1($2$3', $buffer); 
    // remove protocol and domain from frontier links
    $buffer = preg_replace('#(href|src)\s*=\s*(["\'])(https?:)?//frontier\.ebi\.ac\.uk/?#sm', '$1=$2/', $buffer); 
//    $buffer = preg_replace('#(url)\s*\(\s*(["\']?)(https?:)?//frontier\.ebi\.ac\.uk/?#sm', '$1($2/', $buffer); 
    // remove http protcol from: from local domain links
    $buffer = preg_replace("#(href|src)\s*=\s*([\"'])https?:(//{$local_server})#sm", '$1=$2$3', $buffer); 
//    $buffer = preg_replace("#(url)\s*\(\s*([\"']?)https?:(//{$local_server})#sm", '$1($2$3', $buffer); 

    if (!$is_prod) {
      $buffer = str_replace('//www.ebi.ac.uk', '//wwwdev.ebi.ac.uk', $buffer);
    }
    $buffer = preg_replace('#(local|global)_(nav)#sm', '$1-$2', $buffer);
    $buffer = preg_replace('#(grid)-(\d+)#sm', '$1_$2', $buffer);

    if (strpos($buffer, 'key-not-found-in-xml') !== FALSE) {
      $buffer = ''; // clear original content
      drupal_not_found(); // display not found page
    }

    return $buffer;
  }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions