[wp-hackers] wp_grins and 1.5 [signed]

John Ha [c] jqkh at yahoo.com.au
Thu Feb 3 19:55:28 GMT 2005


Do you mean by being able to use the plugin without changing any core files?
Here's my version:
--------
<?php
function wp_grins() {
 global $wpsmiliestrans;
 $grins = '';
 $smiled = array();
 foreach ($wpsmiliestrans as $tag => $grin) {
  if (!in_array($grin, $smiled)) {
   $smiled[] = $grin;
   $tag = str_replace(' ', '', $tag);
   $grins .= '<img
src="'.get_settings('siteurl').'/wp-images/smilies/'.$grin.'" alt="'.$tag.'"
onclick="grin(\''.$tag.'\');"/> ';
  }
 }
 ob_start();
// -------------- Important bit ----
 $grins = '<div id="wp_grins">' . $grins . '</div>';
 printf('<script language="javascript" type="text/javascript">
    var div = document.getElementById("quicktags");
    if (div != undefined) {
     div.innerHTML = div.innerHTML + \'%s\';
    }
    </script>', str_replace("'", "\'", $grins)
 );
// --------------------------------
?>
 <script language="javascript" type="text/javascript">

 function grin(tag) {
  var myField;
  if (document.getElementById('content') &&
document.getElementById('content').type == 'textarea') {
   myField = document.getElementById('content');
  }
  else if (document.getElementById('comment') &&
document.getElementById('comment').type == 'textarea') {
   myField = document.getElementById('comment');
  }
  else {
   return false;
  }
  if (document.selection) {
   myField.focus();
   sel = document.selection.createRange();
   sel.text = tag;
   myField.focus();
  }
  else if (myField.selectionStart || myField.selectionStart == '0') {
   var startPos = myField.selectionStart;
   var endPos = myField.selectionEnd;
   var cursorPos = endPos;
   myField.value = myField.value.substring(0, startPos)
        + tag
        + myField.value.substring(endPos, myField.value.length);
   cursorPos += tag.length;
   myField.focus();
   myField.selectionStart = cursorPos;
   myField.selectionEnd = cursorPos;
  }
  else {
   myField.value += tag;
   myField.focus();
  }
 }

 </script>

<?php
 ob_end_flush();
}

add_action('admin_footer', 'wp_grins');

?>
--------
I used javascript and DOM to do it (with help from Spelling Checker code).

Here's a plugin/template that let's you add more things to more places:

http://ink.bur.st/index.php/2005/01/30/plugin-khanhs-content-adder/

Hope that's what you were after.

Cheers,

John.
----- Original Message ----- 
From: "podz" <podz at tamba2.org.uk>
To: <hackers at wordpress.org>
Sent: Thursday, February 03, 2005 9:46 AM
Subject: [wp-hackers] wp_grins and 1.5 [u]


> Popular plugin / hack, and unless things have changed, for a user to add
> this to their 'write' screen involves altering a core file.
> Is there a neater way of doing this ?
>
> I am thinking of including this in the upgrade guide, hence my request.
>
> P.
>
>
> -- 
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.8.2 - Release Date: 1/28/2005
>
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers


-- 
---------------------[ Ciphire Signature ]----------------------
From: jqkh at yahoo.com.au signed email body (2518 characters)
Date: on 03 February 2005 at 19:55:33 UTC
To:   hackers at wordpress.org
----------------------------------------------------------------
: Ciphire has secured this email against identity theft.
: Free download at www.ciphire.com. The garbled lines
: below are the sender's verifiable digital signature.
----------------------------------------------------------------
00fAAAAAEAAAC1gQJC1gkAANYCAAIAAgACACBJjn9ye1b+7SYZyJRIXjptuOo9OD
kLMZ93/nmlDCpRdgEAICICtdIfh+UjJgkz546BqcMKTxEIBQeTLbcTFlM5YrWhqu
V/VloXxT+eRlvZLJ9be4PD9C0GqqXVGjprBUU72w==
------------------[ End Ciphire Signed Message ]----------------




More information about the hackers mailing list