function clcs_options_admin_page() { global $wpsmiliestrans, $clcs_options; if ($_POST['update-options']) { $updated = false; $is_illegal_dir = false; if (get_option('cs_list') != $_POST['list']) { update_option('cs_list', $_POST['list']); $updated = true; } if (array_key_exists('use-action-comment-form', $_POST)) { $clcs_options = get_option('clcs_options'); if ($clcs_options['use_action_comment_form'] == 0) { $updated = true; } $clcs_options['use_action_comment_form'] = 1; update_option('clcs_options', $clcs_options); } else { $clcs_options = get_option('clcs_options'); if ($clcs_options['use_action_comment_form'] == 1) { $updated = true; } $clcs_options['use_action_comment_form'] = 0; update_option('clcs_options', $clcs_options); } if (array_key_exists('comment_textarea', $_POST)) { $clcs_options = get_option('clcs_options'); if ($_POST['comment_textarea'] != $clcs_options['comment_textarea']) { $clcs_options['comment_textarea'] = $_POST['comment_textarea']; update_option('clcs_options', $clcs_options); $updated = true; } } if (array_key_exists('popup_win_width', $_POST)) { $clcs_options = get_option('clcs_options'); if (!array_key_exists('popup_win_width', $clcs_options)) { $clcs_options['popup_win_width'] = 0; } if ($_POST['popup_win_width'] != $clcs_options['popup_win_width']) { $clcs_options['popup_win_width'] = $_POST['popup_win_width']; update_option('clcs_options', $clcs_options); $updated = true; } } if (array_key_exists('popup_win_height', $_POST)) { $clcs_options = get_option('clcs_options'); if (!array_key_exists('popup_win_height', $clcs_options)) { $clcs_options['popup_win_height'] = 0; } if ($_POST['popup_win_height'] != $clcs_options['popup_win_height']) { $clcs_options['popup_win_height'] = $_POST['popup_win_height']; update_option('clcs_options', $clcs_options); $updated = true; } } if (array_key_exists('smilies_path', $_POST)) { $clcs_options = get_option('clcs_options'); if (is_dir(ABSPATH . $_POST['smilies_path'])) { if ($_POST['smilies_path'] != $clcs_options['smilies_path']) { $clcs_options['smilies_path'] = $_POST['smilies_path']; update_option('clcs_options', $clcs_options); $updated = true; } } else { $is_illegal_dir = true; } } if ($updated) { $clcs_message = __('Preferences updated.', 'custom_smilies'); } else { $clcs_message = __('No changes made.', 'custom_smilies'); } if ($is_illegal_dir) { $clcs_message .= __(' The path of smilies that you want to set is illegal.', 'custom_smilies'); } echo '<div id="message" class="updated fade"><p><b>' . $clcs_message . '</b></p></div>'; } $clcs_options = get_option('clcs_options'); if (!is_array($clcs_options)) { $clcs_options = array(); } // show all or show undefined? $su = $_GET['su'] === '1'; if ($_POST['update-smilies']) { // save smilies to file and refresh $wpsmiliestrans $wpsmiliestrans = cs_save_smilies($_POST); echo '<div id="message" class="updated fade"><p><strong>' . __('Your smilies have been updated.', 'custom_smilies') . '</strong></p></div>'; } // $smilies: 1|gif, 2|gif, etc // $old_smilies: :D, :(, etc $smilies = cs_get_all_smilies(); $old_smilies = cs_load_existing_smilies(); ?> <div class="wrap"> <h2><?php _e('Manage Smilies', 'custom_smilies'); ?> </h2> <p> <?php echo $su ? '<a href="' . wp_nonce_url(CLCSOPTURL . '&su=0') . '">' . __('Display all smilies', 'custom_smilies') . '</a>' : '<a href="' . wp_nonce_url(CLCSOPTURL . '&su=1') . '">' . __('Display undefined smilies only', 'custom_smilies') . '</a>'; ?> </p> <p align="right"><?php _e('Please note that your smilies cannot contain any of these characters: \' " \\', 'custom_smilies'); ?> </p> <form id="manage-smilies-form" method="POST" action="" name="manage-smilies-form"> <input type="hidden" name="page" value="custom-smilies.php" /> <table class="widefat" style="text-align:center"> <thead> <tr> <th scope="col"> <div style="text-align: center;"><?php _e('Smilie', 'custom_smilies'); ?> </div> </th> <th scope="col"> <div style="text-align: center;"><?php _e('What to type', 'custom_smilies'); ?> </div> </th> <th scope="col"> <div style="text-align: center;"><?php _e('Smilie', 'custom_smilies'); ?> </div> </th> <th scope="col"> <div style="text-align: center;"><?php _e('What to type', 'custom_smilies'); ?> </div> </th> <th scope="col"> <div style="text-align: center;"><?php _e('Smilie', 'custom_smilies'); ?> </div> </th> <th scope="col"> <div style="text-align: center;"><?php _e('What to type', 'custom_smilies'); ?> </div> </th> </tr> </thead> <tbody> <?php if (is_array($smilies)) { foreach ($smilies as $smilie) { // 1|gif => 1.gif $smilie_name = str_replace('.', '|', $smilie); if ($su && $old_smilies[$smilie] != '') { // show undefined only ?> <input type="hidden" name="<?php echo $smilie_name; ?> " value="<?php echo $old_smilies[$smilie]; ?> " style="text-align:center" /> <?php continue; } // highlight even rows $class = $count % 6 == 0 ? 'alternate' : ''; // row starts if ($count % 3 == 0) { ?> <tr class="<?php echo $class; ?> "> <?php } ?> <td><img src="<?php echo clcs_get_smilies_path(); ?> /<?php echo $smilie; ?> " /></td> <td><input type="text" name="<?php echo $smilie_name; ?> " value="<?php echo $old_smilies[$smilie]; ?> " style="text-align:center" /></td> <?php // row ends if ($count % 3 == 2) { ?> </tr> <?php } $count++; } } ?> </tbody> </table> <p class="submit"> <input type="submit" value="<?php _e('Update', 'custom_smilies'); ?> " name="update-smilies"/> </p> </form> <h2><?php _e('Smilies Options', 'custom_smilies'); ?> </h2> <form id="smilies-options-form" method="POST" action="" name="smilies-options-form"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Display these smilies above the comment form by default:', 'custom_smilies'); ?> </th> <td> <input type="text" value="<?php echo get_option('cs_list'); ?> " name="list" style="width:95%"><br /> <?php _e('Put your smilies here, separated by comma. Example: <b>:D, :), :wink:, :(</b>', 'custom_smilies'); ?> <br /> <?php _e('Leave this field blank if you want to display all smilies.', 'custom_smilies'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('The name of the input box for comment:', 'custom_smilies'); ?> </th> <td> <input type="text" value="<?php if (array_key_exists('comment_textarea', $clcs_options)) { echo $clcs_options['comment_textarea']; } ?> " name="comment_textarea" style="width:95%"><br /> <?php _e('If you find Custom Smilies can't be used in your theme, there is a different id for comment input in your theme. So you could enter the id here.', 'custom_smilies'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('The path of the smilies:', 'custom_smilies'); ?> </th> <td> <input type="text" value="<?php if (array_key_exists('smilies_path', $clcs_options)) { echo $clcs_options['smilies_path']; } ?> " name="smilies_path" style="width:95%"><br /> <?php _e('This is relative to the WordPress directory. Default is "/wp-includes/images/smilies".', 'custom_smilies'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Popup window width:', 'custom_smilies'); ?> </th> <td> <input type="text" value="<?php if (array_key_exists('popup_win_width', $clcs_options)) { echo $clcs_options['popup_win_width']; } else { echo '0'; } ?> " name="popup_win_width" style="width:30%"> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Popup window height:', 'custom_smilies'); ?> </th> <td> <input type="text" value="<?php if (array_key_exists('popup_win_height', $clcs_options)) { echo $clcs_options['popup_win_height']; } else { echo '0'; } ?> " name="popup_win_height" style="width:30%"> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Other options:', 'custom_smilies'); ?> </th> <td> <fieldset> <label for="use-action-comment-form"> <input id="use-action-comment-form" type="checkbox" name="use-action-comment-form" value="1"<?php if (array_key_exists('use_action_comment_form', $clcs_options) && $clcs_options['use_action_comment_form'] == 1) { echo ' checked="checked"'; } ?> /> <?php _e('Use the action named comment_form in comments.php if your theme support it. So you don't need to add cs_print_smilies() in comments.php manually.', 'custom_smilies'); ?> </label> </fieldset> </td> </tr> </table> <p class="submit"> <input type="submit" value="<?php _e('Update Options', 'custom_smilies'); ?> " name="update-options"/> </p> </form> </div> <?php }
function cs_manage_smilies() { global $wpsmiliestrans; // show all or show undefined? $su = $_GET['su'] === '1'; if ($_POST['update-smilies']) { // save smilies to file and refresh $wpsmiliestrans $wpsmiliestrans = cs_save_smilies($_POST); echo '<div id="message" class="updated fade"><p><strong>Your smilies have been updated.</strong></p></div>'; } // $smilies: 1|gif, 2|gif, etc // $old_smilies: :D, :(, etc $smilies = cs_get_all_smilies(); $old_smilies = cs_load_existing_smilies(); ?> <div class="wrap"> <h2>Manage Smilies</h2> <p> <?php echo $su ? '<a href="?page=custom-smilies.php&su=0">Display all smilies</a>' : '<a href="?page=custom-smilies.php&su=1">Display undefined smilies only</a>'; ?> </p> <p align="right">Please note that your smilies cannot contain any of these characters: ' " \</p> <form id="manage-smilies-form" method="POST" action="" name="manage-smilies-form"> <input type="hidden" name="page" value="custom-smilies.php" /> <table class="widefat" style="text-align:center"> <thead> <tr> <th scope="col"> <div style="text-align: center;">Smilie</div> </th> <th scope="col"> <div style="text-align: center;">What to type</div> </th> <th scope="col"> <div style="text-align: center;">Smilie</div> </th> <th scope="col"> <div style="text-align: center;">What to type</div> </th> <th scope="col"> <div style="text-align: center;">Smilie</div> </th> <th scope="col"> <div style="text-align: center;">What to type</div> </th> </tr> </thead> <tbody> <?php if (is_array($smilies)) { foreach ($smilies as $smilie) { // 1|gif => 1.gif $smilie_name = str_replace('.', '|', $smilie); if ($su && $old_smilies[$smilie] != '') { // show undefined only ?> <input type="hidden" name="<?php echo $smilie_name; ?> " value="<?php echo $old_smilies[$smilie]; ?> " style="text-align:center" /> <?php continue; } // highlight even rows $class = $count % 6 == 0 ? 'alternate' : ''; // row starts if ($count % 3 == 0) { ?> <tr class="<?php echo $class; ?> "> <?php } ?> <td><img src="../wp-includes/images/smilies/<?php echo $smilie; ?> " /></td> <td><input type="text" name="<?php echo $smilie_name; ?> " value="<?php echo $old_smilies[$smilie]; ?> " style="text-align:center" /></td> <?php // row ends if ($count % 3 == 2) { ?> </tr> <?php } $count++; } } ?> </tbody> </table> <p class="submit"> <input type="submit" value="Update »" name="update-smilies"/> </p> </form> </div> <?php }