2009-08-24 07:41:30 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Theme Function: Moods
|
|
|
|
* Author: Philip M. Hofer (Frumph)
|
|
|
|
* Created: 08/22/2009
|
2009-08-24 07:47:38 +00:00
|
|
|
* Author Email: philip@frumph.net
|
|
|
|
* You may use this and adapt this code to anything you like however keep the author information retained in
|
|
|
|
* the appropriate files.
|
|
|
|
*
|
2009-08-24 07:41:30 +00:00
|
|
|
* Lets you set and make moods for your blog posts.
|
|
|
|
*
|
|
|
|
* Usage: if (function_exists('comicpress_show_mood_in_post')) comicpress_show_mood_in_post();
|
|
|
|
*
|
|
|
|
* Edit a post and it you will see the possible moods you can use, select one.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function comicpress_show_mood_in_post() {
|
2009-11-22 18:06:19 +00:00
|
|
|
global $post, $comicpress_options;
|
|
|
|
$moods_directory = $comicpress_options['moods_directory'];
|
2009-09-13 13:42:20 +00:00
|
|
|
if (!empty($moods_directory) && $moods_directory != 'none') {
|
|
|
|
$mood_file = get_post_meta( get_the_ID(), "mood", true );
|
2009-09-16 15:55:29 +00:00
|
|
|
if (!empty($mood_file) && $mood_file != '') {
|
|
|
|
$mood = explode(".", $mood);
|
|
|
|
$mood = reset($mood);
|
2009-11-06 02:56:36 +00:00
|
|
|
if ( !empty($mood_file) && file_exists(get_stylesheet_directory() . '/images/moods/'.$moods_directory.'/'.$mood_file) ) { ?>
|
|
|
|
<div class="post-mood post-<?php echo $mood; ?>"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/moods/<?php echo $moods_directory; ?>/<?php echo $mood_file; ?>" alt="<?php echo $mood; ?>" title="<?php echo $mood; ?>" /></div>
|
|
|
|
<?php } elseif (!empty($mood_file) && file_exists(get_template_directory() . '/images/moods/' .$moods_directory . '/' . $mood_file) ) { ?>
|
|
|
|
<div class="post-mood post-<?php echo $mood; ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/moods/<?php echo $moods_directory; ?>/<?php echo $mood_file; ?>" alt="<?php echo $mood; ?>" title="<?php echo $mood; ?>" /></div>
|
|
|
|
<?php }
|
2009-09-16 15:55:29 +00:00
|
|
|
}
|
2009-09-13 13:42:20 +00:00
|
|
|
}
|
2009-08-24 07:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function comicpress_showmood_edit_post() {
|
2009-11-22 18:06:19 +00:00
|
|
|
global $post, $comicpress_options;
|
|
|
|
$moods_directory = $comicpress_options['moods_directory'];
|
2009-09-13 13:42:20 +00:00
|
|
|
if (!empty($moods_directory) && $moods_directory != 'none') { ?>
|
2009-08-24 07:41:30 +00:00
|
|
|
<div class="inside" style="overflow: hidden">
|
2009-10-05 06:08:01 +00:00
|
|
|
<?php _e('Available Moods, you can set which mood images to use in the comicpress Options.','comicpress'); ?><br />
|
2009-08-24 07:41:30 +00:00
|
|
|
<br />
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$currentmood = get_post_meta( $post->ID, "mood", true );
|
2009-09-13 13:42:20 +00:00
|
|
|
|
|
|
|
if (empty($currentmood) || $currentmood == '' || $currentmood == null) {
|
2009-10-05 06:08:01 +00:00
|
|
|
$mood = __('none','comicpress');
|
2009-08-24 07:41:30 +00:00
|
|
|
} else {
|
|
|
|
$mood = explode(".", $currentmood);
|
|
|
|
$mood = reset($mood);
|
|
|
|
}
|
|
|
|
|
2009-11-06 02:56:36 +00:00
|
|
|
$count = 0;
|
|
|
|
$count = count($results = glob(get_stylesheet_directory() . '/images/moods/'.$moods_directory.'/*'));
|
|
|
|
if (!$count) {
|
|
|
|
$count = count($results = glob(get_template_directory() . '/images/moods/'.$moods_directory.'/*'));
|
|
|
|
$moods_uri = get_template_directory_uri();
|
|
|
|
} else {
|
|
|
|
$moods_uri = get_stylesheet_directory_uri();
|
|
|
|
}
|
2009-10-05 06:08:01 +00:00
|
|
|
echo $count .__(' moods are available.','comicpress').'<br />
|
|
|
|
'.__('Using Moods from directory: ','comicpress').$moods_directory.'<br />
|
|
|
|
'.__('Current Mood: ','comicpress').$mood.'<br /><br />';
|
2009-08-24 07:41:30 +00:00
|
|
|
if (!empty($results)) { ?>
|
2009-09-13 13:42:20 +00:00
|
|
|
<div style="float:left; margin-top: 70px; text-align: center; width: 68px; overflow: hidden;">
|
|
|
|
<label for="postmood-none" style="cursor:pointer;">
|
|
|
|
none
|
|
|
|
</label>
|
|
|
|
<br />
|
|
|
|
<input name="postmood" style="margin-top: 3px;" id="postmood-anger" type="radio" value="none" <?php if ( $mood == 'none' ) { echo " checked"; } ?> />
|
|
|
|
</div>
|
2009-08-24 07:41:30 +00:00
|
|
|
<?php foreach ($results as $file) {
|
|
|
|
$newmood_file = basename($file);
|
|
|
|
$newmood = explode(".", $newmood_file);
|
|
|
|
$newmood = $newmood[0]; ?>
|
2009-08-25 00:40:04 +00:00
|
|
|
<div style="float:left; margin-top: 10px; text-align: center; width: 68px; overflow: hidden;">
|
2009-09-13 13:42:20 +00:00
|
|
|
<label for="postmood-<?php echo $newmood; ?>" style="cursor:pointer;">
|
2009-11-06 02:56:36 +00:00
|
|
|
<img src="<?php echo $moods_uri; ?>/images/moods/<?php echo $moods_directory; ?>/<?php echo basename($file); ?>"><br />
|
2009-09-13 13:42:20 +00:00
|
|
|
<?php echo $newmood; ?>
|
|
|
|
</label>
|
|
|
|
<br />
|
|
|
|
<input name="postmood" style="margin-top: 3px;" id="postmood-<?php echo $newmood; ?>" type="radio" value="<?php echo $newmood_file; ?>"<?php if ( $mood == $newmood ) { echo " checked"; } ?> />
|
2009-08-24 07:41:30 +00:00
|
|
|
</div>
|
|
|
|
<?php }
|
|
|
|
} ?>
|
|
|
|
</div>
|
2009-09-13 13:42:20 +00:00
|
|
|
<?php }
|
|
|
|
}
|
2009-08-24 07:41:30 +00:00
|
|
|
|
2009-08-25 00:40:04 +00:00
|
|
|
|
2009-08-24 07:41:30 +00:00
|
|
|
function comicpress_handle_edit_post_mood_save($post_id) {
|
2009-11-22 18:06:19 +00:00
|
|
|
global $comicpress_options;
|
|
|
|
$moods_directory = $comicpress_options['moods_directory'];
|
2009-09-13 13:42:20 +00:00
|
|
|
if (!empty($moods_directory) && $moods_directory != 'none') {
|
|
|
|
if (empty($_POST['postmood']) || $_POST['postmood'] == 'none') {
|
|
|
|
$postmood = 'none';
|
|
|
|
} else {
|
|
|
|
$postmood = $_POST['postmood'];
|
|
|
|
}
|
|
|
|
update_post_meta($post_id, 'mood', $postmood);
|
2009-08-24 07:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-21 01:14:59 +00:00
|
|
|
function mood_admin_function() {
|
|
|
|
add_meta_box(
|
|
|
|
'mood-for-this-post',
|
|
|
|
__('Mood For This Post', 'comicpress'),
|
|
|
|
'comicpress_showmood_edit_post',
|
|
|
|
'post',
|
|
|
|
'normal',
|
|
|
|
'low'
|
|
|
|
);
|
|
|
|
}
|
2009-09-13 13:42:20 +00:00
|
|
|
|
2009-10-21 01:14:59 +00:00
|
|
|
add_action('admin_menu', 'mood_admin_function');
|
|
|
|
// add_action('edit_form_advanced', 'comicpress_showmood_edit_post', 5, 1);
|
2009-08-24 07:41:30 +00:00
|
|
|
add_action('save_post', 'comicpress_handle_edit_post_mood_save' ,5, 1);
|
|
|
|
?>
|