<?php
/*
Plugin Name: Quicktags Framework
Plugin URI: http://granades.com/2007/02/14/adding-quicktags-to-wordpress/
Description: Framework code that allows plugin authors to add buttons to the WordPress editor's Quicktags.
Version: 1.0
Author: Stephen Granade
Author URI: http://granades.com/
*/

////
// TinyMCE Editor Adjustments

// N.B. You can delete this entire section down to UI Elements if
// you're not going to add HTML-like tags to the editor for later
// filtering.

// Make sure the TinyMCE editor is okay with a new-fangled "pluggy"
// tag. You can delete this 

add_filter('mce_valid_elements''pluggy_mce_valid_elements'0);

function 
pluggy_mce_valid_elements($valid_elements) {
  
$valid_elements .= 'pluggy[width|height]';
  return 
$valid_elements;
}


////
// UI Elements

// Add javascript to generate a quicktag button. If the quicktag bar
// isn't available, instead put a link below the posting field entry.
function pluggy_quicktag_like_button() {
  
// Only add the javascript to post.php, post-new.php, page-new.php, or
  // bookmarklet.php pages
  
if (strpos($_SERVER['REQUEST_URI'], 'post.php') ||
      
strpos($_SERVER['REQUEST_URI'], 'post-new.php') || 
      
strpos($_SERVER['REQUEST_URI'], 'page-new.php') ||
      
strpos($_SERVER['REQUEST_URI'], 'bookmarklet.php')) {

    
// Print out the HTML/Javascript to add the button
?>

<div id="pluggy_link" style="margin-bottom:10px; display:none;">
<a href="#" onclick="return pluggy_open('tinymce=true')">Add a popup image</a>
</div>

<script type="text/javascript">
//<![CDATA[
var pluggy_toolbar = document.getElementById("ed_toolbar");

if (pluggy_toolbar) {
  var theButton = document.createElement('input');
  theButton.type = 'button';
  theButton.value = 'Pluggy';
  theButton.onclick = pluggy_button;
  theButton.className = 'ed_button';
  theButton.title = 'Pluggy!';
  theButton.id = 'ed_Pluggy';
  pluggy_toolbar.appendChild(theButton);
}
else {
  var pluggyLink = document.getElementById("pluggy_link");
  var pingBack = document.getElementById("pingback");
  if (pingBack == null)
    var pingBack = document.getElementById("post_pingback");
  if (pingBack == null) {
    var pingBack = document.getElementById("savepage");
    pingBack = pingBack.parentNode;
  }
  pingBack.parentNode.insertBefore(pluggyLink, pingBack);
  pluggyLink.style.display = 'block';


function pluggy_button(querystr) {
  alert("Pluggy!");
  return false;
}

//]]>
</script>
<?php
    
}
}

// Add the javascript-generating footer to all admin pages
add_filter('admin_footer''pluggy_quicktag_like_button');

?>