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

/* Class: CPSmilies
 * Description:
 *   Manages smilies
 */
class CPSmilies
{
	var $filename = 'cp_smilies.php';
	var $log_options = true;

	function install( &$result )
	{
		global $db;

		$db->query( "DROP TABLE IF EXISTS `w2l_smilies`" );
		$db->query( "CREATE TABLE `w2l_smilies` 
						( `smilie_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, 
						  `code` VARCHAR (10) NOT NULL, 
						  `image` VARCHAR (50) NOT NULL, 
						  PRIMARY KEY( `smilie_id` ) )" );

		$result = 'Smilies plugin installed sucessfully!';
		return 1;
	}

	function remove( &$result )
	{
		global $db;

		$db->query( "DROP TABLE `w2l_smilies`" ); 

		$result = 'Smilies plugin removed sucessfully!';
		return 1;
	}

	function config()
	{
		global $W2L, $output, $db;

		if( array_key_exists( 'add', $W2L->input ) )
		{
			$db->query( "INSERT INTO w2l_smilies VALUES( NULL, '{$W2L->input['code']}', '{$W2L->input['image']}' )" );

			$output->add( '<div class="message">Smilie added!</div>' );
		}
		else if( array_key_exists( 'delete', $W2L->input ) )
		{
			$db->query( "DELETE FROM w2l_smilies WHERE smilie_id={$W2L->input['s_id']}" );

			$output->add( '<div class="message">Smilie Removed!</div>' );
		}
		else if ( array_key_exists( 'edit', $W2L->input ) )
		{
			$output->add( "<form action='?Action=Installer&amp;M=Config&amp;name=Smilies&amp;s_id={$W2L->input['s_id']}&amp;doedit' method='Post'><b>Edit smilie</b><br /><br />" );

			$smilie = $db->query_fetch( "SELECT * FROM w2l_smilies WHERE smilie_id = {$W2L->input['s_id']}" );

			$output->add( "Code:<br /><input type='text' name='code' value='$smilie[code]'/><br /><br />" );
			$output->add( "Image: <img src='./Static/Smilies/$smilie[image]' alt='$smilie[code]' style='vertical-align:middle' /><br /><br />" );
			$output->add( '<input type="submit" value="Edit Smilie" /></form><br /><br />' );
		}
		else if ( array_key_exists( 'doedit', $W2L->input ) )
		{
			$db->query( "UPDATE w2l_smilies SET code = '{$W2L->input['code']}' WHERE smilie_id = {$W2L->input['s_id']}" );

			$output->add( '<div class="message">Smilie Edited!</div>' );
		}

		$output->add( '<b>Smilies:</b>' );
		$output->add( '<table width="50%" cellspacing="0" cellpadding="3" style="border: solid 1px black"><tr class="dark">
<td>Code</td>
<td>Smilie</td>
<td></td></tr>');

		$db->query( "SELECT * FROM w2l_smilies" );
		while( $s = $db->fetch_array() )
		{
			$output->add( "<tr><td class='bevel'>$s[code]</td>" );
			$output->add( "<td class='bevel'><img src='./Static/Smilies/$s[image]' alt='$s[code]'/></td>" );
			$output->add( "<td class='bevel' width='75'>" );
			$output->add( "<a href='?Action=Installer&amp;M=Config&amp;name=Smilies&amp;s_id=$s[smilie_id]&amp;edit'>Edit</a> -" );
			$output->add( "<a href='?Action=Installer&amp;M=Config&amp;name=Smilies&amp;s_id=$s[smilie_id]&amp;delete'>Delete</a></td></tr>" );
		}


		$output->add( '</table><br />' );

		$output->add( '<form action="?Action=Installer&amp;M=Config&amp;name=Smilies&amp;add" method="Post"><b>Add a new smilie</b><br /><br />' );
		$output->add( 'Code:<br /><input type="text" name="code" /><br />' );
		$output->add( 'Image:<br /><select name="image">' );

		$dir = opendir( './Static/Smilies/' );
        while( ( $file = readdir( $dir ) ) !== false ) 
        { 
			if( $file == '.' || $file == '..' )
				continue;

			if( substr( $file, -4 ) != '.gif' &&
				substr( $file, -4 ) != '.jpg' &&
				substr( $file, -4 ) != '.png' &&
				substr( $file, -5 ) != '.jpeg' )
                continue;

			$output->add( "<option value='$file'>$file</option>" );
        }
		closedir( $dir );

		$output->add( '</select><br /><br /><input type="submit" value="Add Smilie" /></form><br /><br />' );
	}

	function log_config()
	{
		global $output;

		$output->add( '<div class="error">There is no configuarion for this plugin</div><br />' );
	}
}

$cp_plugins['Smilies'] = new CPSmilies();

?>
Return current item: Write2Left