Added fieldset labels
Added fieldset labels

--- /dev/null
+++ b/send_custom_header.php
@@ -1,1 +1,149 @@
+<?php
+/**
+ * @package     send_custom_header.plugin
+ *
+ * @copyright   Copyright (C) 2013 B Tasker. All rights reserved.
+ * @license     GNU General Public License version 2 or later; see LICENSE.txt
+ */
 
+defined('_JEXEC') or die;
+
+
+/**
+ * Plugin to send a custom header if specific conditions are met
+ *
+ */
+class plgSystemsend_custom_header extends JPlugin
+{
+
+	protected $plugin;
+	protected $plgParams;
+	var $debug = array();
+
+
+	function __construct(&$subject, $config){
+	    parent::__construct ( $subject, $config );
+	    $this->plugin = JPluginHelper::getPlugin ( 'system', 'send_custom_header' );
+	    $this->plgParams = new JRegistry ( $this->plugin->params );
+	}
+
+
+	/**
+	 * Plugin to send a custom header if specific conditions are met
+	 *
+	 * @return void;
+	 */
+	public function onAfterRender()
+	{
+	    if ($this->processRules()){
+		  // OK, we're running so lets get and generate our headers
+		  $headers = explode(",",$this->plgParams->get('headerName',''));
+      
+		  foreach ($headers as $header){
+		      if (empty($header)){
+			continue;
+	 	      }
+		      $head = explode("=",$header);
+		      header( $head[0].": ".$head[1]);
+		  }
+
+
+		  // Now we do the same for cookies
+		  $cookies = explode(",",$this->plgParams->get('cookieVals',''));
+
+		  foreach ($cookies as $cookie){
+		      if (empty($cookie)){
+			continue;
+		      }
+		      $cook = explode("=",$cookie);
+		      setcookie($cook[0],$cook[1]);
+		  }
+
+	      }
+
+	      if ($this->plgParams->get('debugMode',0)){
+		  $this->sendDebug();
+	      }
+
+	      return true;
+
+	}
+
+
+
+	/** Process the rule set to see if we should be sending headers/cookies
+	*
+	*/
+	function processRules(){
+
+	      // Get the rules
+	      $alwaysComp = explode(",",$this->plgParams->get('alwaysRun',''));
+	      $neverComp = explode(",",$this->plgParams->get('neverRun',''));
+	      $alwaysURL = explode(",",$this->plgParams->get('alwaysURL',''));
+	      $neverURL = explode(",",$this->plgParams->get('neverURL',''));
+	      $when = $this->plgParams->get('sendWhen',1);
+	      $sslCons = $this->plgParams->get('runonSSL',2);
+	      
+
+
+	      // Get instances of classes
+	      $uri = JUri::getInstance();
+
+	      // Get the current state
+	      $app = JFactory::getApplication();
+	      $runon = $this->plgParams->get('runonAdmin',2);
+	      $isAdmin = $app->isAdmin();
+	      $user = JFactory::getUser();
+	      $currenturl = $uri->getPath();
+	      $currentcomp = JRequest::getVar('option');
+	      $isSSL = $uri->isSSL();
+
+	      // Obey the SSL Settings
+	      if ($isSSL && $sslCons == "0"){
+		$this->debug['Disabled-On-SSL'] = 'True';
+		return false;
+	      }elseif($isSSL && $sslCons == "1"){
+		$this->debug['Force-Enabled-On-SSL'] = 'True';
+		return true;
+	      }
+
+
+	      // If an always rule says to run, do so
+	      if (in_array($currenturl,$alwaysURL) || in_array($currentcomp,$alwaysComp)){
+		  $this->debug['Always-Rule-Applies'] = 'True';
+		  return true;
+	      }
+
+
+	      // Process the never rules (including back-end/front-end disablement)
+	      if (($isAdmin && $runon == '0') || (!$isAdmin && $runon == '1') || in_array($currenturl,$neverURL) || in_array($currentcomp,$neverComp)){
+			$this->debug['Never-Rule-Applies-On-SSL'] = 'True';
+			return false;	    
+	      }
+
+
+	      // Check the User based rule
+	      if ((!$when && $user->name) || ($when && !$user->name)){
+		  $this->debug['User-Login-State-Incorrect'] = 'True';
+		  // Either we're supposed to run when user logged in, and they're not, or vice-versa
+		  return false;
+	      }
+
+	      $this->debug['All-Rules-Satisfied'] = 'True';
+	      return true;
+
+	}
+
+
+	/** Push the contents of the Debug array as headers
+	*
+	*/
+	protected function sendDebug(){
+	  foreach($this->debug as $k=>$v){
+	    header('X-'.$k.": ".$v);
+	  }
+	}
+
+}
+
+

--- /dev/null
+++ b/send_custom_header.xml
@@ -1,1 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<extension version="3.0" type="plugin" group="system" method="upgrade">
+	<name>Send Custom Header</name>
+	<author>B Tasker</author>
+	<creationDate>August 2013</creationDate>
+	<copyright>Copyright (C) 2013 - B Tasker</copyright>
+	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
+	<authorEmail>custlibrary@bentasker.co.uk</authorEmail>
+	<authorUrl>www.bentasker.co.uk</authorUrl>
+	<version>1.0.1</version>
+	<description>Plugin to allow sending of a custom HTTP header if certain conditions are met</description>
+	<files>
+		<filename plugin="send_custom_header">send_custom_header.php</filename>
+	</files>
+	
+	<config>
+	  <fields name="params">
+		<fieldset name="basic">
+	  
+		
+		 
+		  <field name="headerName" type="textarea" label="Headers" description="Comma Seperated Key value pairs for headers to send" default="X-DONT-CACHE-ME=no-cache" />
+		  <!--<field name="headerContent" type="text" label="Header Content" default="True" />-->
+		  <field name="cookieVals" type="textarea" label="Cookies" description="Comma Seperated Key value pairs for cookies to set" default="JNoCache=True" />
 
+		  <field name="debugMode" type="list" label="Debug Mode" description="When enabled adds headers so you can see how the rules have been applied" >
+		    <option value="0">Off</option>
+		    <option value="1">On</option>
+		  </field>
+		  
+		</fieldset>
+		
+		<fieldset name="rules" label="Rules">
+		
+		  <field name="runonSSL" type="list" label="SSL Connections" default="2" description="How should SSL Connections be handled?">
+		  
+		    <option value="0">Never Run</option>
+		    <option value="1">Always Run</option>
+		    <option value="2">Obey Rules</option>
+		  
+		  </field>
+		
+		  <field name="runonAdmin" type="list" label="Run on" default="2" description="Can be overriden in Inclusion settings">
+		    <option value="0">Front-End Only</option>
+		    <option value="1">Back-End Only</option>
+		    <option value="2">Front and Back-End</option>
+		  </field>		
+		
+		  <field name="sendWhen" type="list" label="Send When" default="1" description="Can be overriden in Inclusion settings">
+		    <option value="1">User Logged In</option>
+		    <option value="0">User Not Logged In</option>
+		  </field>
+		
+		</fieldset>
+		
+		
+		<fieldset name="InclusionExclusion" label="Inclusion/Exclusion Settings">
+		  <field type="textarea" name="alwaysRun" label="Always run on" description="Always trigger in these components - Comma Seperated Component Names" default="com_users" />
+		  <field type="textarea" name="neverRun" label="Never run on" description="Never trigger in these components - Comma Seperated Component Names" default="" />
+		  <field type="textarea" name="alwaysURL" label="Always on URLs" description="Always run on these (relative) URLs - Comma Seperated" default="/administrator/,/administrator,/administrator/index.php" />
+		  <field type="textarea" name="neverURL" label="Never on URLs" description="Never run on these (relative) URLs - Comma Seperated" default="" />
+		</fieldset>
+		
+	  </fields>
+	</config>
+
+	
+</extension>
+