Location: PHPKode > projects > Write2Left > Plugins/post_smilies.php
<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: post_smilies.php
| Description:
|   A plugin to add smilies to posts
| Created Aug-6-2003
+------------------------------------------------------
*/

if( !class_exists( 'PostSmilies' ) )
{
/* Class: PostSmilies
 * Description:
 *   Parses smilies
 */
class PostSmilies
{
	var $smilies = array();

	function PostSmilies()
	{
		global $db;

		$db->query( "SELECT * FROM w2l_smilies" );
		while( $s = $db->fetch_array() )
			$this->smilies[] = $s;
	}

	function initialize( $post_id, $extra )
	{
	}

	function filter_post( &$title, &$body, &$extended )
	{
		$url = substr( $_SERVER['PHP_SELF'], 0, strrpos( $_SERVER['PHP_SELF'], '/' ) + 1 ) . 'Static/Smilies/';

		foreach( $this->smilies as $s )
		{
			$body = str_replace( "<img src='$url$s[image]' alt='$s[code]'>", $s['code'], $body );
			$extended = str_replace( "<img src='$url$s[image]' alt='$s[code]'>", $s['code'], $extended );
		}
	}

	function filter_input( &$input )
	{
		if( $input['do_smilies'] != 0 )
		{
			$url = substr( $_SERVER['PHP_SELF'], 0, strrpos( $_SERVER['PHP_SELF'], '/' ) + 1 ) . 'Static/Smilies/';
			
			foreach( $this->smilies as $s )
			{
				$input['post_body'] = str_replace( trim( $s['code'] ), "<img src=\\'$url$s[image]\\' alt=\\'$s[code]\\'>", $input['post_body'] );
				$input['post_extended'] = str_replace( trim( $s['code'] ), "<img src=\\'$url$s[image]\\' alt=\\'$s[code]\\'>", $input['post_extended'] );
			}
		}
	}

	function get_inputs()
	{
	}

	function get_options()
	{
		global $W2L;

		$retval = '<input type="hidden" name="do_smilies" value="0" />';
		$retval .= '<input type="checkbox" name="do_smilies" value="1"';
		
		if( !array_key_exists( 'do_smilies', $W2L->input ) )
			$retval .= ' checked';
		else if( $W2L->input['do_smilies'] != 0 )
			$retval .= ' checked';

		$retval .= ' />Add graphical smilies<br />';
		
		return $retval;
	}

	function store_saved( &$input, $extra, $new_id )
	{
	}

	function update_saved( &$input, $extra )
	{
	}
}
}

$this->post_plugins[] = new PostSmilies();

?>
Return current item: Write2Left