Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
khawkins98 opened this issue Jun 9, 2016 · 0 comments
Open

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

khawkins98 opened this issue Jun 9, 2016 · 0 comments
Assignees

Comments

@khawkins98
Copy link
Contributor

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;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants