<?php
/*
Plugin Name: Extra Metas
Plugin URI: http://core.trac.wordpress.org/ticket/9657
Description: Extra Meta Links Test Plugin. Activate to add an additional Meta Links for testing. Needs a patched template.php to work.
Version: 0.1
Author: hakre
Author URI: http://codex.wordpress.org/User:Hakre
*/
/*  Copyright 2009 by the authors

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
 * extra-metas plugin class
 * 
 */
class pluginExtraMetas
{
	/**
	 * constructor
	 * 
	 * @return this
	 */
	function pluginExtraMetas() {
		// Add Hook for admin head		
		add_filter('admin_head', array($this, 'admin_head'));
		
		// Add Hook for adding extra meta links
		add_filter('screen_meta_extra_metas', array($this, 'screen_meta_extra_metas'), 10, 2);		
	}	
	
	/**
	 * admin_head hook function
	 *  
	 * @return void
	 */
	function admin_head() {
?>
<style type="text/css">
	/**
	 * Extra Metas Test Plugin (CSS)
	 *
	 * my additional styles (diverse color-xyz.css files need to be adopted) 
	 */
	#screen-meta-links div.screen-meta-toggle {
		background:transparent url(images/screen-options-left.gif) no-repeat scroll 0 0;
		float:right;
		font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
		height:22px;
		margin:0 6px 0 0;
		padding:0;
	}
	#screen-meta-links div.screen-meta-toggle a {
		background:transparent url(images/screen-options-right.gif) no-repeat scroll right bottom;
		color:#606060;
		display:block;
		font-size:10px;
		height:22px;
		line-height:22px;
		padding:0 16px 0 6px;
		text-decoration:none;		
		text-shadow:0 1px 0 rgba(255, 255, 255, 0.7);
		z-index:1;		
	}
	
	#screen-meta .screen-metas-wrap {
		background-color:#F1F1F1;
		border-color:#DFDFDF;
		-moz-border-radius-bottomleft:4px;
		-moz-border-radius-bottomright:0;
		-moz-border-radius-topleft:0;
		-moz-border-radius-topright:0;
		border-style:none solid solid;
		border-top:0 none;
		border-width:0 1px 1px;
		margin:0 15px;
		padding:8px 12px 12px;
	}
	
	#screen-meta .screen-metas-wrap h5 {
		font-size:13px;
		margin:8px 0;
	}
	
</style>
<script type="text/javascript">
/* <![CDATA[ */
	/**
	 * Extra Metas Test Plugin (javascript/jQuery)
	 */		
	jQuery(function($) 
	{
		$('#screen-meta-links div.screen-meta-toggle a').click(function() {

			var thisLink = $(this);
			var thisWrap = $(this).parent().get(0);
						
			var thisOpened = ($(this).css('background-image').substr($(this).css('background-image').length - 8) == '-up.gif)') ? true : false;
			
			// the simplest mission: handle own (wordpress default links should be added here as well).
			if ($(thisWrap).hasClass('screen-metas-link-wrap'))	{
				// clicked on one of 'ours'				
				// get thisMeta (the wrap that contains this meta stuff)
				var thisMeta = $('#' + $(thisWrap).attr('id').replace(/-link/, ''));
				// hide others
				if (!thisOpened) {					
					$('#contextual-help-link-wrap, #screen-options-link-wrap, .screen-metas-link-wrap').each(function(){
						if (this != thisWrap)
							$(this).addClass('invisible');
					});							
				}
				// slide in thisMeta
				$(thisMeta).slideToggle('fast', function(){
					if ( $(this).hasClass('screen-options-open') ) {
						// update me
						$(thisLink).css({'backgroundImage':'url("images/screen-options-right.gif")'});
						$(this).removeClass('screen-options-open');
						// show others						
						$('#contextual-help-link-wrap, #screen-options-link-wrap, .screen-metas-link-wrap').removeClass('invisible');
					} else {
						// update me
						$(thisLink).css({'backgroundImage':'url("images/screen-options-right-up.gif")'});
						$(this).addClass('screen-options-open');
					}
				});
			} else {
				// clicked on others: toggle all of our collection
				$('.screen-metas-link-wrap').toggleClass('invisible');
			}									
		});
	});
</script>
<?php 	
	}
	
	/**
	 * screen_meta_extra_metas hook function
	 * 
	 * @param  array  $extra_metas extra meta links array
	 * @param  string $screen      current screen
	 * @return array  filtered extra meta links array
	 */
	function screen_meta_extra_metas($extra_metas, $screen)
	{
		// sample everwhere additional link
		$extra_metas[] = array(__('Extra Meta Test'), '<h5>Test Content</h5><div>This is an Extra Meta Test content</div>');
		
		return $extra_metas;
	}
}

$oExtraMetas = new pluginExtraMetas();