So here is the error msg"
"Parse error: parse error, unexpected $end in F:\Wamp\www\blog\wp-content\plugins\custom-smileys.php on line 518"
Below is the php code from the file (sorry I am not proficient in php coding so I don't know it is really the coding problem or not but the same file works at the web host server):
<?php
// Initialize
csm_init();
// Initialization function
function csm_init() {
global $wpdb;
// Add hooks
add_action("admin_menu", csm_add_pages); // Admin CP
add_filter("the_content", csm_convert); // Post content
add_filter("comment_text", csm_convert); // Comment
// Use docking box whenever u want
if ( get_option("csm_dbx"
== true ) {
add_action("dbx_post_sidebar", csm_add_box); // DBX box
if ( get_option("rich_editing"
== true ) {
update_option("rich_editing", false);
}
}
// Disable built-in smileys support, if needed
if ( get_option("use_smilies"
== 1 ) {
update_option("use_smilies", 0);
}
// Run the installer, if needed
if ( csm_first_run_detected() && !get_option("csm_remove"
) {
csm_install();
} else if ( get_option("csm_remove"
== 1 ) {
update_option("csm_remove", 2);
} else {
delete_option("csm_remove"
;
}
}
// Detect first run
function csm_first_run_detected() {
global $wpdb, $table_prefix;
$tableExists = false;
$tables = $wpdb->get_results("show tables;"
;
foreach( $tables as $table ) {
foreach( $table as $value ) {
if( $value == "{$table_prefix}smileys" ) {
return false;
}
}
}
return true;
}
// Install Custom smileys
function csm_install() {
global $wpdb, $table_prefix;
$updated = false;
// Add some options
update_option('csm_path', 'yahoo'); // Path to smileys directory
update_option('csm_dbx', false); // Docking box
update_option('csm_ext', 'gif'); // Smileys' default extension
update_option('csm_spl', '5'); // Smileys per line
// Detect old version
$tableExists = false;
$tables = $wpdb->get_results("show tables;"
;
foreach( $tables as $table ) {
foreach( $table as $value ) {
if( $value == "qa_smileys" ) {
$wpdb->query("RENAME TABLE `qa_smileys` TO `{$table_prefix}smileys`"
;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` DROP `ID`"
;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` CHANGE `Name` `File` VARCHAR( 25 ) NOT NULL"
;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` ADD PRIMARY KEY ( `File` )"
;
$wpdb->query("ALTER TABLE `{$table_prefix}smileys` CHANGE `Value` `Emot` VARCHAR( 10 ) NOT NULL"
;
delete_option("qa_path"
;
delete_option("qa_extension"
;
delete_option("qa_spl"
;
$updated = true;
break;
}
}
}
if ( !$updated ) {
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$table_prefix}smileys` (`File` VARCHAR(25) NOT NULL, `Emot` VARCHAR(10) NOT NULL, PRIMARY KEY(`File`));"
;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo1', '
');"
;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo2', '
');"
;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo3', '
');"
;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo4', '
');"
;
$wpdb->query("INSERT INTO `{$table_prefix}smileys` (`File`, `Emot`) VALUES ('yahoo5', ';
');"
;
}
}
// Uninstall Custom Smileys, completely
function csm_uninstall() {
global $wpdb, $table_prefix;
$wpdb->query("DROP TABLE `{$table_prefix}smileys`"
;
delete_option("csm_path"
;
delete_option("csm_dbx"
;
delete_option("csm_ext"
;
delete_option("csm_spl"
;
echo '<div id="message" class="updated fade"><p>Table <b>dropped</b>. Please click <a href="../wp-admin/plugins.php?action=deactivate&plugin=custom-smileys.php">here</a> to deactivate Custom Smileys.</p></div>';
}
// Add Manage smileys and smileys Options page to Admin Panel
function csm_add_pages() {
add_management_page("Custom Smileys", "Custom Smileys", 8, __FILE__, "csm_management_page"
;
add_options_page("Custom Smileys", "Custom Smileys", 8, __FILE__, "csm_options_page"
;
}
// Convert emoticons to graphics on display - same as the default filter
function csm_convert($text) {
global $wpdb, $table_prefix;
// Get emoticons from DB, order by length
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY length(Emot) DESC"
;
// Find and Replace
foreach ( $result as $object ) {
$find[] = $object->Emot;
$replace[] = "<img src=\"" . get_option("siteurl"
. "/wp-includes/images/" . get_option("csm_path"
. "/" . $object->File . "." . get_option("csm_ext"
. "\" class=\"wp-smiley\" />";
}
$output = "";
// HTML loop taken from texturize function, could possible be consolidated
$textarr = preg_split("/(<.*>
/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
$stop = count($textarr); // loop stuff
for ( $i = 0; $i < $stop; $i++ ) {
$content = $textarr[$i];
if ( (strlen($content) > 0) && ('<' != $content{0}) ) { // If it's not a tag
$content = str_replace($find, $replace, $content);
}
$output .= $content;
}
return $output;
}
// Check if a file is an image or not
function csm_is_image($file, $extension = "gif"
{
return ( strpos($file, "." . $extension) !== false );
}
// Remove extension of a file
function csm_remove_ext($file) {
$ext = strrchr($file, "."
;
if($ext !== false) {
$file = substr($file, 0, -strlen($ext));
}
return $file;
}
// Smileys Manager
function csm_management_page() {
global $wpdb, $table_prefix;
// Check if emoticons are updated or not
if ( $_POST["Update"] ) {
$okay = true;
// Check if there are any duplicated fields or not
$count = array();
foreach ( $_POST as $field => $value ) {
if ( $count[$value] != "" && $value != ""
{
$okay = false;
}
$count[$value] = $field;
}
// If not, update the DB
if ( $okay ) {
foreach ( $_POST as $field => $value ) {
if ( $field != "Update" && trim($value) != "" ) {
$wpdb->query("REPLACE INTO `{$table_prefix}smileys` VALUES ('$field', '$value')"
;
}
}
echo '<div id="message" class="updated fade"><p><b>smileys updated.</b></p></div>';
} else {
echo '<div id="message" class="updated fade"><p><b>Duplicated emoticons detected.</b> Please correct them before continuing.</p></div>';
}
}
?>
<div class="wrap">
<h2>Custom Smileys Manager</h2>
<form method="POST">
<table>
<?php
// Initialize
$path = get_option("csm_path"
;
$handle = opendir("../wp-includes/images/" . $path);
$count = 0;
// Get emoticons from DB
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY `File`"
;
foreach ( $result as $object ) {
$emot[$object->File] = $object->Emot;
}
// Draw table
echo "<tr>";
while ( ($file = readdir($handle)) !== false ) {
if ( $file != "." && $file != ".." && csm_is_image($file, get_option("csm_ext"
) ) {
$count ++;
$smileys[] = $file;
if ( ($count % get_option("csm_spl"
== 1) && ($count > 1) ) {
echo "</tr><tr>";
}
$filename = csm_remove_ext($file);
$output = "<td align=\"center\"><img src=\"../wp-includes/images/$path/$file\" class=\"wp-smiley\" /></td>";
$output .= "<td><input type=\"text\" id=\"$filename\" name=\"$filename\" size=\"8\" maxlength=\"10\" value=\"$emot[$filename]\"/></td>";
echo $output;
}
}
?>
</table>
<p class="submit">
<input type="submit" name="Update" value="Update »" />
</p>
</form>
</div>
<?php
}
// Smileys Control Panel
function csm_options_page() {
// Check if preferences are updated or not
if ( $_POST["Update"] ) {
$updated = false;
if ( get_option("csm_path"
!= $_POST["Path"] ) {
update_option("csm_path", $_POST["Path"]);
$updated = true;
}
if ( get_option("csm_dbx"
!= $_POST["DBX"] ) {
update_option("csm_dbx", $_POST["DBX"]);
$updated = true;
}
if ( get_option("csm_ext"
!= $_POST["Ext"] ) {
update_option("csm_ext", $_POST["Ext"]);
$updated = true;
}
if ( get_option("csm_spl"
!= trim($_POST["SPL"]) ) {
if ( $_POST["SPL"] > 0 ) {
update_option("csm_spl", trim($_POST["SPL"]));
$updated = true;
}
}
if ( $updated ) {
echo '<div id="message" class="updated fade"><p><b>Preferences updated.</b> Click <a href="../wp-admin/edit.php?page=custom-smileys.php">here</a> if you want to go to Smileys Management page.</p></div>';
} else {
echo '<div id="message" class="updated fade"><p><b>No changes made.</b> Click <a href="../wp-admin/edit.php?page=custom-smileys.php">here</a> if you want to go to Smileys Management page.</p></div>';
}
}
// Check if user is about to uninstall Custom smileys or not
if ( $_POST["Uninstall"] ) {
update_option("csm_remove", 1);
csm_uninstall();
}
?>
<div class="wrap">
<h2>Preferences</h2>
<form method="POST">
<table class="optiontable">
<tr valign="top">
<th scope="row">
Smileys directory:
</th>
<td>
<select name="Path">
<?php
$selected = get_option("csm_path"
;
if ( $handle = opendir("../wp-includes/images"
) {
while ( ($file = readdir($handle)) !== false ) {
if ( strpos($file, "."
=== false ) {
if ( $selected == $file ) {
echo "<option name=\"$file\" selected=\"selected\" value=\"$file\">$file</option>";
} else {
echo "<option name=\"$file\" value=\"$file\">$file</option>";
}
}
}
}
?>
</select>
<br />
Smileys' directory (below <b>wp-includes/images</b>
</td>
</tr>
<tr valign="top">
<th scope="row">
Default extension:
</th>
<td>
<select name="Ext">
<?php
$ext = array("gif", "jpg", "png"
;
$selected = get_option("csm_ext"
;
foreach ( $ext as $value) {
if ( $selected == $value ) {
echo "<option name=\"$value\" selected=\"selected\" value=\"$value\">$value</option>";
} else {
echo "<option name=\"$value\" value=\"$value\">$value</option>";
}
}
?>
</select>
<br />
Smileys' default extension
</td>
</tr>
<tr valign="top">
<th scope="row">
Smileys per line:
</th>
<td>
<input type="text" name="SPL" value="<?php echo get_option("csm_spl"
; ?>" />
<br />
Number of smileys displayed on each line in the management page (e.g. "5"
</td>
</tr>
<tr valign="top">
<th scope="row">
Docking Box:
</th>
<td>
<?php
if ( get_option("csm_dbx"
== true ) {
?>
<input name="DBX" type="checkbox" id="DBX" value="true" checked="checked" />
<?php
} else {
?>
<input name="DBX" type="checkbox" id="DBX" value="true" />
<?php
}
?>
Add a docking box to Write page
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Update" value="Update Preferences »" />
</p>
</form>
</div>
<div class="wrap">
<h2>Usage</h2>
<form method="POST">
<table class="optiontable">
<tr valign="top">
<th scope="row">
Docking Box
</th>
<td>
In order to use Custom Smileys' docking box, you <b>must</b> uncheck the box that says "<b>Use the visual rich editor when writing</b>". This setting is located <a href="../wp-admin/profile.php">here</a>.
</td>
</tr>
<tr valign="top">
<th scope="row">
Comment Form
</th>
<td>
Clickable smileys can also be integrated into your Comment form by pasting the following code into your <b>comments.php</b> file, just before the comment form begins:<br />
<p><textarea cols="100%" rows="7">
<?php
$code = <<<HERE
<!-- Clickable smileys start here -->
<?php
if ( function_exists(csm_comment_form) ) {
csm_comment_form();
}
?>
<!-- Clickable smileys end here -->
HERE;
echo htmlspecialchars($code);
?>
</textarea></p>
</td>
</tr>
<tr valign="top">
<th scope="row">
Smileys Formatting
</th>
<td>
Custom Smileys uses <b>wp-smiley</b> class to format your smileys. CSS example:
<p><textarea cols="100%" rows="6">
<?php
$code = <<<HERE
.wp-smiley {
border: 0pt none;
margin: 0px;
padding: 0px;
vertical-align: middle;
}
HERE;
echo htmlspecialchars($code);
?>
</textarea></p>
Just put these lines in your <b>style.css</b> file and you're all set.
</td>
</tr>
</table>
</form>
</div>
<div class="wrap">
<h2>Uninstallation</h2>
<form method="POST">
<table class="optiontable">
<tr valign="top">
<th scope="row">
<input type="submit" name="Uninstall" value="Uninstall Custom smileys" onclick="return confirm('Are you sure you wish to remove Custom Smileys completely?');" />
</th>
<td>
Click this button if you want to REMOVE Custom Smileys completely. Remember that this action CAN NOT be reversed.
</td>
</tr>
</table>
</form>
</div>
<?php
}
// Add clickable smileys to Comment form
function csm_comment_form() {
global $wpdb, $table_prefix;
// Get emoticons from DB & Display clickable smileys
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY `File`"
;
foreach ( $result as $object ) {
if ( file_exists("./wp-includes/images/" . get_option("csm_path"
. "/" . $object->File . "." . get_option("csm_ext"
) ) {
echo "<img src=\"" . get_option("siteurl"
. "/wp-includes/images/" . get_option("csm_path"
. "/" . $object->File . "." . get_option("csm_ext"
. "\" class=\"wp-smiley\" onclick=\"document.getElementById('comment').value += ' {$object->Emot}';\" /> ";
}
}
}
// Add docking box
function csm_add_box() {
global $wpdb, $table_prefix;
?>
<fieldset id="customsmileysbox" class="dbx-box">
<h3 class="dbx-handle">Custom Smileys</h3>
<div class="dbx-content">
<?php
$result = $wpdb->get_results("SELECT * FROM `{$table_prefix}smileys` ORDER BY `File`"
;
$count = 0;
foreach ( $result as $object ) {
if ( file_exists("../wp-includes/images/" . get_option("csm_path"
. "/" . $object->File . "." . get_option("csm_ext"
) ) {
$count ++;
if ( $count > 1 && $count % get_option("csm_spl"
== 1 ) {
echo "<br />";
}
echo "<img src=\"" . get_option("siteurl"
. "/wp-includes/images/" . get_option("csm_path"
. "/" . $object->File . "." . get_option("csm_ext"
. "\" class=\"wp-smiley\" onclick=\"document.getElementById('content').value += ' {$object->Emot}';\" /> ";
}
}
?>
</div>
</fieldset>
<?
}
?>