File: _smilies.toolbar.php

package info (click to toggle)
b2evolution 0.9.2-3
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 12,976 kB
  • ctags: 5,460
  • sloc: php: 58,989; sh: 298; makefile: 36
file content (136 lines) | stat: -rw-r--r-- 3,065 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
 * This file implements the Image Smilies Toolbar plugin for b2evolution
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package plugins
 */
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );

/**
 * Includes:
 */
require_once dirname(__FILE__).'/../toolbar.class.php';

/**
 * @package plugins
 */
class smilies_Toolbarplugin extends ToolbarPlugin
{
	/**
	 * Should be toolbar be displayed?
	 */
	var $display = false;

	var $code = 'b2evSmil';
	var $name = 'Smilies';
	var $priority = 70;
	var $short_desc;
	var $long_desc;

	/**
	 * Smiley definitions
	 *
	 * @access private
	 */
	var $smilies;

	/**
	 * Path to images
	 *
	 * @access private
	 */
	var $smilies_path;


	/**
	 * Constructor
	 *
	 * {@internal smilies_Toolbarplugin::smilies_Toolbarplugin(-)}} 
	 */
	function smilies_Toolbarplugin()
	{
		$this->short_desc = T_('One click smilies inserting');
		$this->long_desc = T_('No description available');

		require dirname(__FILE__). '/../_smilies.conf.php';
	}


	/**
	 * Display the toolbar
	 *
	 * {@internal smilies_Toolbarplugin::render(-)}} 
	 */
	function display()
	{	
		if( !$this->display )
		{	// We don't want to show this toolbar
			return false;
		}

		$grins = '';
		$smiled = array();
		foreach( $this->smilies as $smiley => $grin )
		{
			if (!in_array($grin, $smiled))
			{
				$smiled[] = $grin;
				$smiley = str_replace(' ', '', $smiley);
				$grins .= '<img src="'. $this->smilies_path. '/'. $grin. '" alt="'. $smiley.
									'" class="top" onclick="grin(\''. str_replace("'","\'",$smiley). '\');"/> ';
			}
		}
	
		print('<div class="edit_toolbar">'. $grins. '</div>');
		ob_start();
		?>
		<script type="text/javascript">
		function grin(tag)
		{
			var myField;
			if (document.getElementById('content') && document.getElementById('content').type == 'textarea') {
				myField = document.getElementById('content');
			}
			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
		$grins = ob_get_contents();
		ob_end_clean();
		print($grins);
	}
}

// Register the plugin:
$this->register( new smilies_Toolbarplugin() );

?>