Plugin built with support for sending data if a user is or isn't logged in
Plugin built with support for sending data if a user is or isn't logged in

--- /dev/null
+++ b/send_custom_header.php
@@ -1,1 +1,64 @@
+<?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;
+
+	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()
+	{
+
+	      
+	      $app = JFactory::getApplication();
+	      $runon = $this->plgParams->get('runonAdmin',2);
+	      $isAdmin = $app->isAdmin();
+
+	      // Don't run if we've been told not to run on the back-end, or the front-end
+	      if (($isAdmin && $runon == '0') || (!$isAdmin && $runon == '1')){
+		    return true;
+	      }
+
+
+	      $user = JFactory::getUser();
+	      $when = $this->plgParams->get('sendWhen',1);
+
+
+	      if (($when && $user->name) || (!$when && !$user->name)){
+		  // OK, we're running so lets get and generate our header
+		  header($this->plgParams->get('headerName','') .":".$this->plgParams->get('headerContent',''));
+	      }
+
+	}
+
+
+
+
+}
+
+

--- /dev/null
+++ b/send_custom_header.xml
@@ -1,1 +1,41 @@
+<?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="sendWhen" type="list" label="Send When" default="1">
+		    <option value="1">User Logged In</option>
+		    <option value="0">User Not Logged In</option>
+		  </field>
+		  
+		  <field name="headerName" type="text" label="Header Name" default="X-DONT-CACHE-ME" />
+		  <field name="headerContent" type="text" label="Header Content" default="True" />
+		  
+		  <field name="runonAdmin" type="list" label="Run on" default="2" >
+		    <option value="0">Front-End Only</option>
+		    <option value="1">Back-End Only</option>
+		    <option value="2">Front and Back-End</option>
+		  </field>
+		  
+		  
+		</fieldset>
+	  </fields>
+	</config>
 
+	
+</extension>
+