<?xml version="1.0" encoding="UTF-8"?>
<plugin name="Group Legend" version_long="10204" version_human="1.2.4" author="invisionHQ" website="http://www.bbcode.it" update_check="http://bbcode.it/versions/plugins/bd4-group-legend/"><hooks/><settings><setting><key>bd_gl_visibleToGroups</key><default/></setting><setting><key>bd_gl_formatName</key><default>1</default></setting><setting><key>bd_gl_text</key><default/></setting><setting><key>bd_gl_groupSort</key><default/></setting><setting><key>bd_gl_globalPrefix</key><default/></setting><setting><key>bd_gl_globalSuffix</key><default/></setting><setting><key>bd_gl_linkSearch</key><default>1</default></setting></settings><settingsCode><![CDATA[//<?php

$groups = \IPS\Member\Group::groups();
$list = array_filter(explode( ',', \IPS\Settings::i()->bd_gl_groupSort ));

if (count($list)==0) {
    $i=0;
    $groupList=array();
    foreach($groups as $group) {
        $stackList[]  = array($group->get_name()=>$i);
        $groupList[]  = $group->get_name();
        $groupList_Id[]  = $group->g_id;
        $i++;
    }
}
else {
   foreach($groups as $group) {
       $groupList[]  = $group->get_name();
       $groupList_Id[]  = $group->g_id;
    }

    $stackList = array();
    foreach($list as $l) {
        $stackList[] = array_search($l, $groupList_Id);
    }
}

$form->addTab('bd_gl_tab_general');
$form->add( new \IPS\Helpers\Form\Select( 'bd_gl_visibleToGroups', \IPS\Settings::i()->bd_gl_visibleToGroups=='*' ? '*' : explode( ',', \IPS\Settings::i()->bd_gl_visibleToGroups ), TRUE, array( 'options' => $groups, 'parse' => 'normal', 'multiple' => true, 'unlimited' => '*', 'unlimitedLang' => 'everyone' ), NULL, NULL, NULL, 'bd_gl_visibleToGroups' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'bd_gl_linkSearch', \IPS\Settings::i()->bd_gl_linkSearch,TRUE));
$form->add( new \IPS\Helpers\Form\Editor( 'bd_gl_text', \IPS\Settings::i()->bd_gl_text, FALSE, array('app' => 'core', 'key' => 'Admin','autoSaveKey'=>'bd-group-legend-text')) );

$form->addTab('bd_gl_tab_grouplist');
$form->add( new \IPS\Helpers\Form\Stack( 'bd_gl_groupSort', $stackList , FALSE, array('stackFieldType'=>'Select','removeEmptyValues'=>false,'options' => $groupList)));

$form->addTab('bd_gl_tab_display');
$form->add( new \IPS\Helpers\Form\YesNo( 'bd_gl_formatName', \IPS\Settings::i()->bd_gl_formatName,TRUE));
$form->add( new \IPS\Helpers\Form\Text( 'bd_gl_globalPrefix', \IPS\Settings::i()->bd_gl_globalPrefix));
$form->add( new \IPS\Helpers\Form\Text( 'bd_gl_globalSuffix', \IPS\Settings::i()->bd_gl_globalSuffix));



if ( $values = $form->values(TRUE) )
{
    $finalOrder=explode( ',', $values['bd_gl_groupSort']);
    $order=array();
    foreach($finalOrder as $o) {
        $order[] = $groupList_Id[$o];
    }
    
    $values['bd_gl_groupSort']=implode(',',$order);

	$form->saveAsSettings($values);
	return TRUE;
}

return $form;]]></settingsCode><tasks/><widgets><widget key="bdGroupLegend" class="\IPS\Widget" restrict="sidebar,cms" default_area="" allow_reuse="" menu_style="menu" embeddable=""><![CDATA[<?php
/**
 * @brief		bdGroupLegend Widget
 * @author		<a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
 * @copyright	(c) 2001 - SVN_YYYY Invision Power Services, Inc.
 * @license		http://www.invisionpower.com/legal/standards/
 * @package		IPS Social Suite
 * @subpackage	bdGroupLegend
 * @since		21 Mar 2015
 * @version		SVN_VERSION_NUMBER
 */

namespace IPS\plugins\<{LOCATION}>\widgets;

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * bdGroupLegend Widget
 */
class _bdGroupLegend extends \IPS\Widget
{
	/**
	 * @brief	Widget Key
	 */
	public $key = 'bdGroupLegend';
	
	/**
	 * @brief	App
	 */
	public $app = 'core';
		
	/**
	 * @brief	Plugin
	 */
	public $plugin = '<{ID}>';
	
	/**
	 * Initialise this widget
	 *
	 * @return void
	 */ 
	public function init()
	{
		// Use this to perform any set up and to assign a template that is not in the following format:
		// $this->template( array( \IPS\Theme::i()->getTemplate( 'widgets', $this->app, 'front' ), $this->key ) );
		// For a plugin:
		// $this->template( array( \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' ), $this->key ) );
		
		
		parent::init();
        $this->template( array( \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' ), $this->key ) );
	}
	
	/**
	 * Specify widget configuration
	 *
	 * @param	null|\IPS\Helpers\Form	$form	Form object
	 * @return	null|\IPS\Helpers\Form
	 */
	public function configuration( &$form=null )
	{
 		if ( $form === null )
		{
	 		$form = new \IPS\Helpers\Form;
 		}

 		// $$form->add( new \IPS\Helpers\Form\XXXX( .... ) );
 		// return $form;
 	} 
 	
 	 /**
 	 * Ran before saving widget configuration
 	 *
 	 * @param	array	$values	Values from form
 	 * @return	array
 	 */
 	public function preConfig( $values )
 	{
 		return $values;
 	}

	/**
	 * Render a widget
	 *
	 * @return	string
	 */
	public function render()
	{
        if (\IPS\Settings::i()->bd_gl_visibleToGroups != '*' && !\IPS\Member::loggedIn()->inGroup(explode( ',',\IPS\Settings::i()->bd_gl_visibleToGroups)) ) {
			return "";
		}
        
        $selectedGroups  = (empty(\IPS\Settings::i()->bd_gl_groupSort) ? array() : explode( ',', \IPS\Settings::i()->bd_gl_groupSort ));
        $allGroups = \IPS\Member\Group::groups();

        $groupList=array();
        if (!empty($selectedGroups)) {
            foreach($selectedGroups as $g_id) {
                if (array_key_exists($g_id, $allGroups)) {
                    $groupList[]=$allGroups[$g_id];
                }
            }
        }
        else {
            $groupList = $allGroups;
        }

      return $this->output($groupList);  
	}
}]]></widget></widgets><htmlFiles><html filename="bdGroupLegend.phtml">PGlwczp0ZW1wbGF0ZSBwYXJhbWV0ZXJzPSIkZ3JvdXBzLCAkb3JpZW50YXRpb249J3ZlcnRpY2FsJyIgLz4NCg0KPGgzIGNsYXNzPSJpcHNUeXBlX3Jlc2V0IGlwc1dpZGdldF90aXRsZSI+e2xhbmc9J2Jsb2NrX2JkR3JvdXBMZWdlbmRfdGl0bGUnfTwvaDM+DQo8ZGl2IGNsYXNzPSdpcHNXaWRnZXRfaW5uZXIgaXBzUGFkJz4NCiAgICA8dWwgY2xhc3M9Imlwc0xpc3RfaW5saW5lIGlwc0xpc3RfY3N2IGlwc0xpc3Rfbm9TcGFjaW5nIj4gDQogICAgICAgIHt7Zm9yZWFjaCAkZ3JvdXBzIGFzICRncm91cH19DQogICAgICAgICAgICB7e2lmIGlzX29iamVjdCgkZ3JvdXApfX0NCiAgICAgICAgICAgICAgICA8bGk+PGEgaHJlZj0ie3tpZiBzZXR0aW5ncy5iZF9nbF9saW5rU2VhcmNofX17dXJsPSdhcHA9Y29yZSZtb2R1bGU9c2VhcmNoJmNvbnRyb2xsZXI9c2VhcmNoJnR5cGU9Y29yZV9tZW1iZXJzJmdyb3VwWyRncm91cC0+Z19pZF09MScgY3NyZj0ndHJ1ZSd9e3tlbHNlfX0je3tlbmRpZn19Ij57c2V0dGluZz0iYmRfZ2xfZ2xvYmFsUHJlZml4In17e2lmIHNldHRpbmdzLmJkX2dsX2Zvcm1hdE5hbWU9PXRydWV9fSRncm91cC0+Zm9ybWF0dGVkTmFtZXt7ZWxzZX19eyRncm91cC0+bmFtZX17e2VuZGlmfX17c2V0dGluZz0iYmRfZ2xfZ2xvYmFsU3VmZml4In08L2E+PC9saT4NCiAgICAgICAgICAgIHt7ZW5kaWZ9fQ0KICAgICAgICB7e2VuZGZvcmVhY2h9fQ0KICAgIDwvdWw+DQogICAgPGRpdiBjbGFzcz0naXBzVHlwZV9yaWNoVGV4dCBpcHNUeXBlX2NvbnRhaW5lZCc+e3NldHRpbmc9J2JkX2dsX3RleHQnfTwvZGl2Pg0KPC9kaXY+DQo=</html></htmlFiles><cssFiles/><jsFiles/><resourcesFiles/><lang><word key="block_bdGroupLegend_title" js="0">Group Legend</word><word key="block_bdGroupLegend" js="0">Group Legend Block</word><word key="block_bdGroupLegend_desc" js="0">Displays the list of member groups</word><word key="bd_gl_visibleToGroups" js="0">Block Visible To</word><word key="bd_gl_hideGroups" js="0">Remove Selected Groups</word><word key="bd_gl_formatName" js="0">Enable Group Name Formatting</word><word key="bd_gl_text" js="0">Text Under Legend</word><word key="bd_gl_groupSort" js="0">Group List</word><word key="bd_gl_tab_general" js="0">General</word><word key="bd_gl_tab_grouplist" js="0">Group List</word><word key="bd_gl_tab_display" js="0">Display</word><word key="bd_gl_globalPrefix" js="0">Global Prefix</word><word key="bd_gl_globalSuffix" js="0">Global Suffix</word><word key="bd_gl_linkSearch" js="0">Link Groups to Search</word></lang><versions><version long="10000" human="1.0.0"><![CDATA[//<?php


/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * Install Code
 */
class ips_plugins_setup_install
{
	/**
	 * ...
	 *
	 * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
	 */
	public function step1()
	{
		
	}
	
	// You can create as many additional methods (step2, step3, etc.) as is necessary.
	// Each step will be executed in a new HTTP request
}]]></version><version long="10100" human="1.1.0"/><version long="10200" human="1.2.0"/><version long="10201" human="1.2.1"/><version long="10202" human="1.2.2"><![CDATA[//<?php


/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * 1.2.2 Upgrade Code
 */
class ips_plugins_setup_upg_10202
{
	/**
	 * ...
	 *
	 * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
	 */
	public function step1()
	{
		
	}
	
	// You can create as many additional methods (step2, step3, etc.) as is necessary.
	// Each step will be executed in a new HTTP request
}]]></version><version long="10204" human="1.2.4"><![CDATA[//<?php


/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
	exit;
}

/**
 * 1.2.4 Upgrade Code
 */
class ips_plugins_setup_upg_10204
{
	/**
	 * ...
	 *
	 * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
	 */
	public function step1()
	{
		

		return TRUE;
	}
	
	// You can create as many additional methods (step2, step3, etc.) as is necessary.
	// Each step will be executed in a new HTTP request
}]]></version></versions></plugin>
