From 1ff6f60bb1554b137e6845a722b3e1f2fc9c6e3d Mon Sep 17 00:00:00 2001
From: mtyczynski <mtyczynski@daracreative.ie>
Date: Thu, 5 Nov 2015 22:22:29 +0000
Subject: [PATCH] force Realex Redirect to provide as low markup as neeed to
 avoid crashed while redirecting back to the website

---
 .../contrib/commerce_realex/commerce_realex.module | 23 +++++++
 .../templates/html--commerce_realex.tpl.php        | 56 ++++++++++++++++
 .../templates/page--commerce_realex.tpl.php        | 78 ++++++++++++++++++++++
 3 files changed, 157 insertions(+)
 create mode 100644 public/sites/all/modules/contrib/commerce_realex/templates/html--commerce_realex.tpl.php
 create mode 100644 public/sites/all/modules/contrib/commerce_realex/templates/page--commerce_realex.tpl.php

diff --git a/public/sites/all/modules/contrib/commerce_realex/commerce_realex.module b/public/sites/all/modules/contrib/commerce_realex/commerce_realex.module
index c752699..9047e9c 100644
--- a/public/sites/all/modules/contrib/commerce_realex/commerce_realex.module
+++ b/public/sites/all/modules/contrib/commerce_realex/commerce_realex.module
@@ -344,3 +344,26 @@ class RealexParser {
 
 }
 
+
+/**
+ * When Realex Redirect method is in use alter theme registry and add custom template files 
+ * Implements hook_theme_registry_alter().
+ */
+function commerce_realex_theme_registry_alter(&$theme_registry) {
+    if( current_path() == 'commerce-realex/redirect/complete' ){
+      // Defined path to the current module.
+      $module_path = drupal_get_path('module', 'commerce_realex').'/templates';
+      // Find all .tpl.php files in this module's folder recursively.
+      $template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
+      // Iterate through all found template file objects.
+      foreach ($template_file_objects as $key => $template_file_object) {
+          // If the template has not already been overridden by a theme.
+          if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) {
+              // Alter the theme path and template elements.
+              $theme_registry[$key]['theme path'] = $module_path;
+              $theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object);
+              $theme_registry[$key]['type'] = 'module';
+          }
+      }
+    }
+}
diff --git a/public/sites/all/modules/contrib/commerce_realex/templates/html--commerce_realex.tpl.php b/public/sites/all/modules/contrib/commerce_realex/templates/html--commerce_realex.tpl.php
new file mode 100644
index 0000000..60549e7
--- /dev/null
+++ b/public/sites/all/modules/contrib/commerce_realex/templates/html--commerce_realex.tpl.php
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * @file
+ * Default theme implementation to display the basic html structure of a single
+ * Drupal page. This template is cleaned up, it is not rendering unnecessary styles and scripts to avoid crashed during Realex Redirect transaction.
+ *
+ * Variables:
+ * - $css: An array of CSS files for the current page.
+ * - $language: (object) The language the site is being displayed in.
+ *   $language->language contains its textual representation.
+ *   $language->dir contains the language direction. It will either be 'ltr' or 'rtl'.
+ * - $rdf_namespaces: All the RDF namespace prefixes used in the HTML document.
+ * - $grddl_profile: A GRDDL profile allowing agents to extract the RDF data.
+ * - $head_title: A modified version of the page title, for use in the TITLE
+ *   tag.
+ * - $head_title_array: (array) An associative array containing the string parts
+ *   that were used to generate the $head_title variable, already prepared to be
+ *   output as TITLE tag. The key/value pairs may contain one or more of the
+ *   following, depending on conditions:
+ *   - title: The title of the current page, if any.
+ *   - name: The name of the site.
+ *   - slogan: The slogan of the site, if any, and if there is no title.
+ * - $head: Markup for the HEAD section (including meta tags, keyword tags, and
+ *   so on).
+ * - $styles: Style tags necessary to import all CSS files for the page.
+ * - $scripts: Script tags necessary to load the JavaScript files and settings
+ *   for the page.
+ * - $page_top: Initial markup from any modules that have altered the
+ *   page. This variable should always be output first, before all other dynamic
+ *   content.
+ * - $page: The rendered page content.
+ * - $page_bottom: Final closing markup from any modules that have altered the
+ *   page. This variable should always be output last, after all other dynamic
+ *   content.
+ * - $classes String of classes that can be used to style contextually through
+ *   CSS.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_html()
+ * @see template_process()
+ *
+ * @ingroup themeable
+ */
+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
+  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>"<?php print $rdf_namespaces; ?>>
+
+<head profile="<?php print $grddl_profile; ?>">
+  <?php print $head; ?>
+  <title><?php print $head_title; ?></title>
+</head>
+    <body class="<?php print $classes; ?>" <?php print $attributes;?>>
+      <?php print render($page); ?>
+    </body>
+</html>
\ No newline at end of file
diff --git a/public/sites/all/modules/contrib/commerce_realex/templates/page--commerce_realex.tpl.php b/public/sites/all/modules/contrib/commerce_realex/templates/page--commerce_realex.tpl.php
new file mode 100644
index 0000000..23e629c
--- /dev/null
+++ b/public/sites/all/modules/contrib/commerce_realex/templates/page--commerce_realex.tpl.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ * @file
+ * Default theme implementation to display a single Drupal page.
+ *
+ * The doctype, html, head and body tags are not in this template. Instead they
+ * can be found in the html--commerce-realex.tpl.php template in this directory.
+ * his template is cleaned up, it is not rendering unnecessary regions to avoid crashed during Realex Redirect transaction.
+ * Available variables:
+ *
+ * General utility variables:
+ * - $base_path: The base URL path of the Drupal installation. At the very
+ *   least, this will always default to /.
+ * - $directory: The directory the template is located in, e.g. modules/system
+ *   or themes/bartik.
+ * - $is_front: TRUE if the current page is the front page.
+ * - $logged_in: TRUE if the user is registered and signed in.
+ * - $is_admin: TRUE if the user has permission to access administration pages.
+ *
+ * Site identity:
+ * - $front_page: The URL of the front page. Use this instead of $base_path,
+ *   when linking to the front page. This includes the language domain or
+ *   prefix.
+ * - $logo: The path to the logo image, as defined in theme configuration.
+ * - $site_name: The name of the site, empty when display has been disabled
+ *   in theme settings.
+ * - $site_slogan: The slogan of the site, empty when display has been disabled
+ *   in theme settings.
+ *
+ * Navigation:
+ * - $main_menu (array): An array containing the Main menu links for the
+ *   site, if they have been configured.
+ * - $secondary_menu (array): An array containing the Secondary menu links for
+ *   the site, if they have been configured.
+ * - $breadcrumb: The breadcrumb trail for the current page.
+ *
+ * Page content (in order of occurrence in the default page.tpl.php):
+ * - $title_prefix (array): An array containing additional output populated by
+ *   modules, intended to be displayed in front of the main title tag that
+ *   appears in the template.
+ * - $title: The page title, for use in the actual HTML content.
+ * - $title_suffix (array): An array containing additional output populated by
+ *   modules, intended to be displayed after the main title tag that appears in
+ *   the template.
+ * - $messages: HTML for status and error messages. Should be displayed
+ *   prominently.
+ * - $tabs (array): Tabs linking to any sub-pages beneath the current page
+ *   (e.g., the view and edit tabs when displaying a node).
+ * - $action_links (array): Actions local to the page, such as 'Add menu' on the
+ *   menu administration interface.
+ * - $feed_icons: A string of all feed icons for the current page.
+ * - $node: The node object, if there is an automatically-loaded node
+ *   associated with the page, and the node ID is the second argument
+ *   in the page's path (e.g. node/12345 and node/12345/revisions, but not
+ *   comment/reply/12345).
+ *
+ * Regions:
+ * - $page['help']: Dynamic help text, mostly for admin pages.
+ * - $page['highlighted']: Items for the highlighted content region.
+ * - $page['content']: The main content of the current page.
+ * - $page['sidebar_first']: Items for the first sidebar.
+ * - $page['sidebar_second']: Items for the second sidebar.
+ * - $page['header']: Items for the header region.
+ * - $page['footer']: Items for the footer region.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_page()
+ * @see template_process()
+ * @see html.tpl.php
+ *
+ * @ingroup themeable
+ */
+?>
+
+<div id="page-wrapper"><div id="page">
+  <?php print render($page['content']); ?>
+</div> <!-- /#page, /#page-wrapper -->
\ No newline at end of file
-- 
1.9.1

