<?php
/*
Plugin Name: Khanh's Content Adder
Version: 1.1
Plugin URI: http://ink.bur.st/index.php/2005/01/30/plugin-khanhs-content-adder/
Description: This plugin lets you add your own buttons to the Admin Panel.
Author: John Ha
Author URI: http://ink.bur.st
*/ 

/*
--------------------------------------------------------------------------------
Khanh's Content Adder - Add your own content (almost) anywhere you want!

Purpose
-------
Have you wanted to add an extra button to the Admin Panel or Quicktag toolbar?
Usually, you'd have to edit the core Wordpress files, or be limited to what and
where you can add stuff.

With KCA you can add HTML/Javascript anywhere there's an ID attribute defined.
Configuration is easy: Just upload, configure the plugin file with the content
you want, activate the plugin and you're done.

Intructions
-----------
1. Upload this file into the plugins directory.
2. Go to Admin Panel->Plugins->Plugin Editor->Edit this plugin file.
3. Follow the instructions where indicated (i.e. "Start editing here").
4. After making the changes you want, save the plugin file.
5. Activate plugin.
6. Refresh the Admin Panel page to see new content!

Note
----
- KCA has only been tested on version Wordpress 1.5-beta-1 2005-01-08,
	but should work fine on most versions.

- You can safetly delete any old posts belonging to KCA, since KCA does
	not use posts anymore.

Wishlist / To Do
----------------
- Ability to re-order content eg. sort order of buttons.
- Add content only when ID attribute exists within a page.
- Add content to any page depending on setting in post.

History
-------
0.0.1
	- Released
0.0.2
	- Moved data to a static page
	- Cleaned up code
	- Changed format of button data
	- Added access levels to admin button
	- Added Quicktag buttons with access levels
1.0
	- Changed plugin name to reflect plugin ability
	- Combined Quicktag and Admin Panel code
	- Can add any content where there's an ID attribute
1.1
	- Removed private post "kca-list"
	- All code and settings now in plugin file to prevent errors
		when post is displayed

--------------------------------------------------------------------------------
This code is licensed under the MIT License.
http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2005 John (Khanh) Ha (email: ink@bur.st)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to
do so, subject to the following conditions:

The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
*/

class kca {
	function add_content() {

		global $user_level;
		$bits = array (

// Start editing here **********************************************************

// Content Data 1
		array("adminmenu",
		"<li><a href='http://wordpress.org/'>Wordpress</a></li>",
		1),
// Content Data 2
		array("adminmenu",
		"<li><a href='http://ink.bur.st'>0ink</a></li>",
		1),
// Just uncomment the following, or copy, paste and edit these 3 lines as many
// times as you want to add more content.

//		array("wphead",	// ID
//		"Hi There!",	// Content
//		5),		// Level

/*
Explanation
-----------

ID:
	ID attribute name where you want your content added.
	Eg. "adminmenu" is the name of the DIV where the Admin Panel resides, while
	"ed_toolbar" is for quicktags.
	To find out more, just load the page that you want to add content, view
	the source and do a search for "ID=". Note the ID name and use it in KCA!

Content:
	The content you want added.

Level:
	The access level for your content.

Remember you can add any type of content. So if you insert this code...

		array("wphead",
		"Hi There!",
		5),

...it would be fine! Try it! You will see "Hi There!" above the Admin Panel.
*/

// Stop editing here ***********************************************************
		);

		$byte = array();
		$c = count($bits);

		for($i = 0; $i < $c; $i++) {
			if($user_level >= $bits[$i][2]) {
				$byte[$bits[$i][0]] .= $bits[$i][1];
			}
		}

		foreach($byte as $key=>$content) {
?>
<script language="JavaScript" type="text/javascript"><!--
	var kca_<?php echo $key; ?> = document.getElementById('<?php echo $key; ?>');
	if(kca_<?php echo $key; ?> != undefined) {
		kca_<?php echo $key; ?>.innerHTML += "<?php echo $content; ?>";
	}
//--></script>
<?php
		}
	}
}
add_action('admin_footer', array('kca', 'add_content'));
?>