From 615b38fefa01ef485501393a0168473d5ebafe4a Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Wed, 7 Mar 2012 17:50:38 +0000
Subject: [PATCH] Add support to the WdnTemplate for setting
 UNL_Templates::$options via application.ini Use unl.templates.options.* to
 set these options.

---
 library/Unl/Application.php             | 50 +++++++++++++++++++++++++
 library/Unl/View/Helper/WdnTemplate.php |  6 +++
 2 files changed, 56 insertions(+)
 create mode 100644 library/Unl/Application.php

diff --git a/library/Unl/Application.php b/library/Unl/Application.php
new file mode 100644
index 0000000..758bbd6
--- /dev/null
+++ b/library/Unl/Application.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Currently a helper class for accessing the Zend_Application instance.
+ * @author tsteiner
+ */
+class Unl_Application
+{
+    /**
+     * Attempts to return the current application's configuration.
+     * If we're not running as a Zend_Application an empty array is returned.
+     * 
+     * @return array
+     */
+    static public function getOptions()
+    {
+        $application = self::getInstance();
+        if (!$application) {
+            return array();
+        }
+        
+        return $application->getOptions();
+    }
+    
+    /**
+     * Attempts to return the current Zend_Application instance.
+     * If we're not running as a Zend_Application, NULL is returned.
+     * 
+     * @return Zend_Application
+     */
+    static public function getInstance()
+    {
+        if (!class_exists('Zend_Controller_Front')) {
+            return NULL;
+        }
+        
+        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
+        if (!$bootstrap instanceof Zend_Application_Bootstrap_BootstrapAbstract) {
+            return NULL;
+        }
+        
+        $application = $bootstrap->getApplication();
+        
+        if (!$application instanceof Zend_Application) {
+            return NULL;
+        }
+        
+        return $application;
+    }
+}
diff --git a/library/Unl/View/Helper/WdnTemplate.php b/library/Unl/View/Helper/WdnTemplate.php
index 6f6fb3b..05c25bd 100644
--- a/library/Unl/View/Helper/WdnTemplate.php
+++ b/library/Unl/View/Helper/WdnTemplate.php
@@ -57,6 +57,12 @@ class Unl_View_Helper_WdnTemplate extends Zend_View_Helper_Abstract
         
         require_once 'UNL/Templates.php';
         Unl_Templates::$options['version'] = UNL_Templates::VERSION3;
+        
+        $config = Unl_Application::getOptions();
+        if (isset($config['unl']['templates']['options']) && is_array($config['unl']['templates']['options'])) {
+            UNL_Templates::$options = array_merge(UNL_Templates::$options, $config['unl']['templates']['options']);
+        }
+        
         $template = UNL_Templates::factory($layout->template, array('sharedcodepath' => 'sharedcode'));
         
         $template->titlegraphic = '<h1>' . $layout->siteTitle . '</h1>';
-- 
GitLab