Source for file _smilies.plugin.php
Documentation is available at _smilies.plugin.php
* This file implements the Image Smilies Renderer plugin for b2evolution
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
* @author fplanque: Francois PLANQUE.
* @author gorgeb: Bertrand GORGE / EPISTEMA
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
* Text similes search array
$this->long_desc =
T_('This renderer will convert text smilies like :) to graphical icons.<br />
Optionally, it will also display a toolbar for quick insertion of smilies into a post.');
* Defaults for user specific settings: "Display toolbar"
'use_toolbar_default' =>
array(
'label' =>
T_( 'Use smilies toolbar' ),
'note' =>
T_( 'This is the default setting. Users can override it in their profile.' ),
'render_comments' =>
array( // fp> Note: this is not a default in this version, it's an 'always' :]
'label' =>
$this->T_('Render comments' ),
'note' =>
$this->T_('Check to also render smilies in comments.'),
// TODO (yabs) : Display these as images and individual inputs
'label' =>
$this->T_( 'Smiley list'),
'note' =>
sprintf( $this->T_( 'This is the list of smileys [one per line], in the format : char_sequence image_file // optional comment<br />
To disable a smiley, just add one or more spaces to the start of its setting<br />
You can add new smiley images by uploading the images to the %s folder.' ), '<span style="font-weight:bold">'.
$rsc_subdir.
'smilies/</span>' ),
'type' =>
'html_textarea', // allows smilies with "<" in them
:**: graysigh.gif // alternative: graysighw.gif
:??: grayconfused.gif // alternative: grayconfusedw.gif
:## grayupset.gif // alternative: grayupsetw.gif
:zz: graysleep.gif // alternative: graysleepw.gif
* Allowing the user to override the display of the toolbar.
'label' =>
T_( 'Use smilies toolbar' ),
'defaultvalue' =>
$this->Settings->get('use_toolbar_default'),
* Display a toolbar in admin
* @param array Associative array of parameters
* @return boolean did we display a toolbar?
* Event handler: Called when displaying editor toolbars.
* @param array Associative array of parameters
* @return boolean did we display a toolbar?
if( $this->Settings->get( 'render_comments' )
* Display the smiley toolbar
* @return boolean did we display a toolbar?
foreach( $this->smilies as $smiley )
if (!in_array($smiley[ 'image' ], $smiled))
$smiled[] =
$smiley[ 'image'];
$smiley[ 'code' ] =
str_replace(' ', '', $smiley[ 'code' ]);
$grins .=
'<img src="'.
$smiley[ 'image' ].
'" title="'.
$smiley[ 'code' ].
'" alt="'.
$smiley[ 'code' ]
.
'" class="top" onclick="grin(\''.
str_replace("'","\'",$smiley[ 'code' ]).
'\');" /> ';
print
('<div class="edit_toolbar">'.
$grins.
'</div>');
<script type="text/javascript">
if( typeof b2evo_Callbacks == 'object' )
{ // see if there's a callback registered that should handle this:
if( b2evo_Callbacks.trigger_callback("insert_raw_into_"+b2evoCanvas.id, tag) )
var myField = b2evoCanvas;
if (document.selection) {
sel = document.selection.createRange();
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myField.value.substring(endPos, myField.value.length);
myField.selectionStart = cursorPos;
myField.selectionEnd = cursorPos;
* @see Plugin::FilterCommentContent()
if( $this->Settings->get( 'render_comments' ) )
* @see Plugin::RenderItemAsHtml()
$this->InitSmilies(); // check smilies are already cached
if( ! isset
( $this->search ) )
{ // We haven't prepared the smilies yet
$tmpsmilies =
$this->smilies;
usort($tmpsmilies, array(&$this, 'smiliescmp'));
foreach( $tmpsmilies as $smiley )
$this->search[] =
$smiley[ 'code' ];
for ($i =
0; $i <
strlen($smiley[ 'code' ] ); $i++
)
$smiley_masked .=
'&#'.
ord(substr($smiley[ 'code' ], $i, 1)).
';';
// We don't use getimagesize() here until we have a mean
// to preprocess smilies. It takes up to much time when
// processing them at display time.
$this->replace[] =
'<img src="'.
$smiley[ 'image' ].
'" alt="'.
$smiley_masked.
'" class="middle" />';
// REPLACE: But only in non-HTML blocks, totally excluding <CODE>..</CODE> and <PRE>..</PRE>
$content =
& $params['data'];
// Lazy-check first, using stristr() (stripos() is only available since PHP5):
if( stristr( $content, '<code' ) !==
false ||
stristr( $content, '<pre' ) !==
false )
{ // Call ReplaceTagSafe() on everything outside <pre></pre> and <code></code>:
'~<(code|pre)[^>]*>.*?</\1>~is',
array( & $this, 'ReplaceTagSafe' ) );
{ // No CODE or PRE blocks, replace on the whole thing
* This callback gets called once after every tags+text chunk
* @return string Text with replaced smilies
return str_replace( $this->search, $this->replace, $text );
* Replace smilies in non-HTML-tag portions of the text.
* @uses callback_on_non_matching_blocks()
* sorts the smilies' array by length
* this is important if you want :)) to superseede :) for example
if( ($diff =
strlen( $b[ 'code' ] ) -
strlen( $a[ 'code' ] ) ) ==
0)
return strcmp( $a[ 'code' ], $b[ 'code' ] );
* Initiates the smiley array if not already initiated
* Attempts to use skin specific smileys where available
* - skins_adm/skin/rsc/smilies/
* Attempts to fallback to default smilies
* If no image file found the smiley is not added
* @return array of available smilies( code, image url )
if( isset
( $this->smilies ) )
{ // smilies are already cached
global $admin_skin, $adminskins_path, $adminskins_url, $rsc_path, $rsc_url, $skin, $skins_path, $skins_url;
// set the skin path/url and the default (rsc) path/url
$currentskin_path =
( is_admin_page() ?
$adminskins_path.
$admin_skin.
'/rsc' :
$skins_path.
$skin ).
'/smilies/';
$currentskin_url =
( is_admin_page() ?
$adminskins_url.
$admin_skin.
'/rsc' :
$skins_url.
$skin ).
'/smilies/';
$default_path =
$rsc_path.
'smilies/';
$default_url =
$rsc_url.
'smilies/';
$skin_has_smilies =
is_dir( $currentskin_path ); // check if skin has a /smilies/ folder
$this->smilies =
array();
foreach( $temp_list as $temp_smiley )
if( isset
( $a_smiley[0] ) and isset
( $a_smiley[1] ) )
// lets see if the file exists
$temp_img =
trim( $a_smiley[1] );
if( $skin_has_smilies &&
is_file( $currentskin_path.
$temp_img ) )
$temp_url =
$currentskin_url.
$temp_img; // skin has it's own smiley, use it
elseif ( is_file( $default_path.
$temp_img ) )
$temp_url =
$default_url.
$temp_img; // no skin image, but default smiley found so use it
$temp_url =
''; // no smiley image found, so don't add the smiley
$this->smilies[] =
array( 'code' =>
trim( $a_smiley[0] ),'image' =>
$temp_url );
// returns the relevant smiley parts (char_code, image_file)
return ( ( isset
( $smiley_parts[1] ) && isset
( $smiley_parts[2] ) ) ?
$smiley_parts[1].
'<->'.
$smiley_parts[2] :
'' );
* $Log: _smilies.plugin.php,v $
* Revision 1.31.2.11 2006/12/28 23:18:54 fplanque
* added plugin event for displaying comment form toolbars
* Revision 1.31.2.10 2006/12/27 09:41:12 yabs
* Removed b2evocanvas, minor other changes, clarified doc
* Revision 1.31.2.9 2006/12/26 03:18:51 fplanque
* assigned a few significant plugin groups
* Revision 1.31.2.8 2006/12/16 04:30:59 fplanque
* Revision 1.31.2.7 2006/12/03 08:27:35 yabs
* Removed user setting - render_comments
* Changed behaviour - render_comments_default used instead
* Added skintag to display toolbar ifsmilies in comments enabled - usersetting overrides toolbar default
* Other minor changes to code
* Revision 1.31.2.6 2006/11/27 19:12:50 fplanque
* 1.9 POT has gone public. No more unnecessary changes.
* 1.9.x language packs should work for ALL 1.9.x versions.
* Adding strings is okay. Removing strings/changing strings for fun is not OK.
* Revision 1.31.2.5 2006/11/27 00:32:56 blueyed
* Revision 1.31.2.4 2006/11/27 00:28:50 blueyed
* Revision 1.31.2.3 2006/11/04 19:55:12 fplanque
* Reinjected old Log blocks. Removing them from CVS was a bad idea -- especially since Daniel has decided branch 1.9 was his HEAD...
* Revision 1.31 2006/08/07 18:26:21 fplanque
* nuked obsolete smilies conf file
* Revision 1.30 2006/08/01 23:55:14 blueyed
* minor: doc; removed level of indentation
* Revision 1.29 2006/08/01 08:44:31 yabs
* Minor change - checks if skin has /smilies/ folder before start of checking for images
* Revision 1.28 2006/08/01 08:20:47 yabs
* Added ability for admin skins to override default smiley images
* Tidied up my previous code
* Revision 1.27 2006/07/31 16:19:04 yabs
* Moved settings to admin
* Added smilies in comments ( as user setting )
* Added ability for blog skins to override default smiley images
* These changes are a tad quick 'n' dirty, I'm working on a cleaner version and will commit soon
* Revision 1.26 2006/07/12 21:13:17 blueyed
* Javascript callback handler (e.g., for interaction of WYSIWYG editors with toolbar plugins)
* Revision 1.25 2006/07/10 20:19:30 blueyed
* Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.
* Revision 1.24 2006/07/07 21:26:49 blueyed
* Revision 1.23 2006/07/06 19:56:29 fplanque
* Revision 1.22 2006/06/16 21:30:57 fplanque
* Started clean numbering of plugin versions (feel free do add dots...)
* Revision 1.21 2006/05/30 20:26:59 blueyed
* Revision 1.20 2006/05/30 19:39:55 fplanque
* Revision 1.19 2006/04/24 20:16:08 blueyed
* Use callback_on_non_matching_blocks(); excluding PRE and CODE blocks
* Revision 1.18 2006/04/11 21:22:26 fplanque