Project

General

Profile

Download (1.78 KB) Statistics
| Branch: | Tag: | Revision:

root / drupal-module / auquotidien.theme.inc @ 0bb989f9

1
<?php
2

    
3
require_once "ProxyHandler.class.php";
4

    
5
function template_preprocess_auquotidien(&$variables) {
6
  $variables['message'] = check_markup(variable_get('auquotidien_message', ''),
7
                                       variable_get('auquotidien_message_format',
8
                                                    FILTER_FORMAT_DEFAULT));
9

    
10
  $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
11
  $link = $_SERVER['REQUEST_URI'];
12
  $base_root = url('<front>');
13

    
14
  if ($link == $base_root . 'auquotidien') {
15
    // missing slash
16
    header('Location: ' . $link . '/');
17
    return;
18
  }
19

    
20
  $proxied_url = substr($link, strlen($base_root . 'auquotidien'));
21

    
22
  $auquo_url = rtrim(variable_get('auquotidien_url', ''), '/');
23
  if ($auquo_url == '') {
24
    $variables['content'] = t('Not configured yet.');
25
    return;
26
  }
27

    
28
  $proxy = new ProxyHandler($base_root . 'auquotidien/', $auquo_url, $proxied_url);
29
  $proxy->setClientHeader('X-WCS-Iframe-Mode: true');
30
  $proxy->setClientHeader('X-WCS-Drupal-Mode: true');
31
  if ($GLOBALS['user']->uid != 0) {
32
    $proxy->setClientHeader('X-WCS-Drupal-User-Uid: ' .  $GLOBALS['user']->uid);
33
    $proxy->setClientHeader('X-WCS-Drupal-User-Name: ' .  $GLOBALS['user']->name);
34
    $proxy->setClientHeader('X-WCS-Drupal-User-Mail: ' .  $GLOBALS['user']->mail);
35
  }
36
  $proxy->execute();
37
  $proxy->close();
38
  if ($proxy->http_code == 404) {
39
    return drupal_not_found();
40
  }
41
  if ($proxy->http_code == 301 || $proxy->http_code == 302 || $proxy->http_code == 303) {
42
    if (trim($proxy->location) == 'Location:') {
43
      $proxy->location = 'Location: ' . $base_root . 'auquotidien/';
44
    }
45
    header($proxy->location);
46
    return;
47
  }
48

    
49
  preg_match('/(<div id="main-content">.*)<\/body>/s', $proxy->result, $re_content);
50
  $content = $re_content[1];
51

    
52
  $variables['content'] = $content;
53

    
54
}
55

    
56
?>
(8-8/9)