rendered paste body<?php
/*
Plugin Name: bbEmoticons
Plugin URI:
Description: A Clickable Smilies hack for bbPress. Thanks to kohaku and aka. Original WP Grins by Alex King.
Author: hiromasa
Author URI: http://hiromasa.zone.ne.jp/blog/
Version: 0.72
*/
/******************************************************************************
* bbEmoticons version 0.72
*
* A Clickable Smilies hack for bbPress.
*
* @Author hiromasa (http://hiromasa.zone.ne.jp/blog/)
* @Thanks kohaku (http://www.orioa.com/)
* aka (http://plasticdreams.org/)
* @Original WP Grins By Alex King
* (http://www.alexking.org/software/wordpress/)
* WordPress convert_smilies function and images
* (http://wordpress.org/)
*****************************************************************************/
/* Copyright 2006 hiromasa (email : webmaster@hiromasa.zone.ne.jp)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/******************************************************************************
* bbEmoticons
*
* @author hiromasa
* @version 0.72
*
*****************************************************************************/
class bbEmoticons {
var $bb_grins;
var $bb_smiliessearch = array();
var $bb_smiliesreplace = array();
/**
* The Constructor
*
* @param none
* @return none
*/
function bbEmoticons() {
if (isset($_GET['bb_grins_output'])) {
switch ($_GET['bb_grins_output']) {
case "javascript":
$this->outputGringJS();
}
exit(0);
}
$bb_smiliestrans = array(
':)' => '1.gif', #1 //Begin Yahoo
':(' => '2.gif', #2
';)' => '3.gif', #3
':D' => '4.gif', #4
# ',,)' => '5.gif', #5
# '>:-D<' => '6.gif', #6
':-/' => '7.gif', #7
':x' => '8.gif', #8
# ':#>' => '9.gif', #9
':P' => '10.gif', #10
# ':-*' => '11.gif', #11
# '=>((' => '12.gif', #12
':-O' => '13.gif', #13
# 'X(' => '14.gif', #14
':>' => '15.gif', #15
# 'B-)' => '16.gif', #16
# ':-S' => '17.gif', #17
# '#:-S' => '18.gif', #18
# '>:)' => '19.gif', #19
':((' => '20.gif', #20
':))' => '21.gif', #21
':|' => '22.gif', #22
'/:)' => '23.gif', #23
# '=>))' => '24.gif', #24
# 'O:)' => '25.gif', #25
# ':-B' => '26.gif', #26
# '=>,' => '27.gif', #27
# ':-c' => '101.gif',#28
# ':)' => '100.gif',#29
'~X(' => '102.gif',#30
# ':-h' => '103.gif',#31
# ':-t' => '104.gif',#32
# '8->' => '105.gif',#33
# 'I-|' => '28.gif', #34
'8-|' => '29.gif', #35
# 'L-)' => '30.gif', #36
# ':-G' => '31.gif', #37
# ':-$' => '32.gif', #38
# '[-(' => '33.gif', #39
# ':O)' => '34.gif', #40
# '8-}' => '35.gif', #41
# '<:-P' => '36.gif', #42
# '(:|' => '37.gif', #43
# '=>P~' => '38.gif', #44
':-?' => '39.gif', #45
'#-o' => '40.gif', #46
# '=>D>' => '41.gif', #47
':-SS' => '42.gif', #48
# '@-)' => '43.gif', #49
# ':^o' => '44.gif', #50
# ':-w' => '45.gif', #51
# ':-<' => '46.gif', #52
# '>:P' => '47.gif', #53
# '<):)' => '48.gif', #54
':-??' => '106.gif',#55
# '%-(' => '107.gif',#56
# ':@)' => '49.gif', #57
# '3:-O' => '50.gif', #58
# ':(|)' => '51.gif', #59
# '~:>' => '52.gif', #60
'@},-' => '53.gif', #61
# '%%' => '54.gif', #62
# '**=>=>' => '55.gif', #63
# '(~~)' => '56.gif', #64
'~O)' => '57.gif', #65
'*-:)' => '58.gif', #66
# '8-X' => '59.gif', #67
# '=>:)' => '60.gif', #68
# '>-)' => '61.gif', #69
# ':-L' => '62.gif', #70
# '[-O<' => '63.gif', #71
# '$-)' => '64.gif', #72
# ':-#' => '65.gif', #73
# 'b-(' => '66.gif', #74
# ':)>-' => '67.gif', #75
'[-X' => '68.gif', #76
# '\:D/' => '69.gif', #77
# '>:/' => '70.gif', #78
# ',))' => '71.gif', #79
# ':-@' => '76.gif', #80
# '^:)^' => '77.gif', #81
# ':-j' => '78.gif' #82
# '(*)' => '79.gif', #83
# 'o->' => '72.gif', #84
# 'o=>>' => '73.gif', #85
# 'o-+' => '74.gif', #86
# '(%)' => '75.gif', #87 //End Yahoo
# '<3' => 'heart.gif', #1
# ':(|)' => 'monkey.gif', #1
# '\m/' => 'rockout.gif', #1
':-o' => 'shocked.gif', #2
':D' => 'grin.gif', #3
':(' => 'frown.gif', #4
'x-(' => 'angry.gif', #5
'B-)' => 'cool.gif', #6
':-((' => 'cry.gif', #7
'=D' => 'equal_grin.gif', #8
';)' => 'wink.gif', #9
':-|' => 'straightface.gif', #10
'=)' => 'equal_smile.gif', #11
';^)' => 'nose_grin.gif', #12
';-)' => 'wink_big_nose.gif', #13
':-)' => 'wink_nose.gif', #14
':-/' => 'slant.gif', #15
':-P' => 'tongue.gif', #16
'>.<' => 'wince1.gif', #16
# '+/'\' => 'cowbell.gif', #16
'}:-)' => 'devil.gif', #16
);
foreach($bb_smiliestrans as $smiley => $img) {
$this->bb_smiliessearch[] = $smiley;
$smiley_masked = htmlspecialchars(trim($smiley), ENT_QUOTES);
$this->bb_smiliesreplace[] =
" <img src='" . bb_get_option('uri') .
"bb-images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";
}
$this->grins = '';
$smiled = array();
foreach ($bb_smiliestrans as $tag => $grin) {
if (!in_array($grin, $smiled)) {
$smiled[] = $grin;
$tag = str_replace(' ', '', $tag);
$this->grins .=
'<img src="'. bb_get_option('uri') .
'bb-images/smilies/'.$grin.'" alt="' .$tag .
'" onclick="grin(\' '.$tag.'\');"/> ';
}
}
}
/**
* post_text filter
*
* @param $text
* @return $output
*/
function convert_smilies($text) {
$prep_search = array_map('prepSmilies', $wp_smiliessearch);
$output = '';
$textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$stop = count($textarr);
for($i=0; $i<$stop; $i++) {
$content = $textarr[$i];
if((strlen($content) > 0) && ('<' != $content{0})) {
$content = preg_replace($prep_search, $wp_smiliesreplace, $content);
$this->bb_smiliessearch,
$this->bb_smiliesreplace,
$content);
}
$output .= $content;
}
return $output;
}
/**
* bb_grins action
*
* @param none
* @return none
*/
function bb_grins() {
echo '<div id="bb_grins">' . $this->grins . '</div>';
}
/**
* bb_head action
*
* @param none
* @return none
*/
function bb_grins_head() {
echo
'<script type="text/javascript" src="'. bb_get_option('uri') .
'my-plugins/bb-emoticons.php?bb_grins_output=javascript"></script>' .
"\n";
}
/**
* Output Grins JavaScript
*
* @param none
* @return none
*/
function outputGringJS() {
?>
function grin(tag) {
var myField;
if (document.getElementById('post_content') && document.getElementById('post_content').type == 'textarea') {
myField = document.getElementById('post_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();
}
}
<?php
}
}
/******************************************************************************
* - Define for bbPress interface
*****************************************************************************/
$bbemoticons = & new bbEmoticons();
bb_add_filter('post_text', array(&$bbemoticons, 'convert_smilies'));
//bb_head is not called always. :-)
//bb_add_action('bb_head', array(&$bbemoticons, 'bb_grins_head'));
bb_add_action('bb_feed_head', array(&$bbemoticons, 'bb_grins_head'));
bb_add_action('bb_grins', array(&$bbemoticons, 'bb_grins'));
function prepSmilies($string) {return "/(\s|^)".quotemeta(trim($string))."(\s|$)/";}?>