Find file
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (123 sloc) 5.1 KB
* Add metaboxes for an episode post.
* @package FanKit
// TODO: episode parser
// "the episode parser adds characters to episodes automatically,"
// "but if you'd like to manually mark the character as being in an episode"
// "simply check the box"
// - have episodes arranged by season
// - TODO:JS do accordion dealie with jQuery so we don't show like 7 seasons at once
// - one season at a time
// - "You may want to drag the name box up or on the side so you don't
// have to scroll down"
// 2 things, 2 boxes
* Add all metaboxes for an episode post.
* @todo mark characters that are in this episode (checkboxes)
function fk_add_episode_boxes(){
add_action('admin_menu', '_fk_episode_boxes');
* Show a little how-to intro message for episodes. Hooked by fk-boxes.php.
function fk_episode_notices(){
global $post;
$pre_ep_txt = '';
if( 0 === $post->ID ){
$pre_ep_txt = __('You are adding a new episode.');
} else {
$pre_ep_txt = __('You are editing an episode.');
$txt = $pre_ep_txt . ' ' . __("The post title is the episode title, and the post content is the episode description. To add more information, including a transcript, use the boxes below the writing area. To add an autogenerated quote post, do BLAHHH"); // FIXME
function _fk_episode_boxes(){
if( function_exists('add_meta_box')){
// Add a box where user specifies the season and episode number
add_meta_box('fk_episode_box_season_ep_num_id', __("TV Fan Kit - Season/Episode Number"), 'fk_episode_season_ep_num_box_cb', 'post', 'normal');
// Box for marking which characters appear in this episode
add_meta_box('fk_episode_box_characters_id', __("TV Fan Kit - Characters In This Episode"), 'fk_episode_characters_box_cb', 'post', 'normal');
// Add separate box for transcript, since it can be huge and user may want to drag it out of the way.
add_meta_box('fk_episode_box_transcript_id', __("TV Fan Kit - Episode Transcript"), 'fk_episode_transcript_box_cb', 'post', 'normal');
// Callback for episode season/ep_num metabox
function fk_episode_season_ep_num_box_cb(){
global $post, $fk_settings;
list($default_season, $default_ep_num) = fk_episode_get_season_ep_num($post->ID);
if( $default_season === false || $default_ep_num === false ){
$default_season = '';
$default_ep_num = '';
// Note that we may have episodes w/o season or ep_num, eg a post
// that was switched to episode from another type.
wp_nonce_field('fk_set_episode_info', 'fk_episode_info_nonce');
echo '<div class="form-wrap">';
printf('<label for="fk_season_id">%s:</label>', __('Season'));
echo '<input type="text" id="fk_season_id" name="fk_season" value="'.$default_season.'" size="10" tabindex="200" />';
printf('<label for="fk_ep_num_id">%s:</label>', __('Episode Number'));
echo '<input type="text" id="fk_ep_num_id" name="fk_ep_num" value="'.$default_ep_num.'" size="10" tabindex="201" />';
echo '</div>';
// Callback for metabox with characters who appear in this episode
function fk_episode_characters_box_cb(){
global $post, $fk_settings;
wp_nonce_field('fk_set_characters', 'fk_characters_nonce');
echo '<p>';
if( 0 === $post->ID ){
// New post so characters can't have been added yet.
$characters = array();
} else {
$characters = fk_episode_get_characters($post->ID);
$all_characters = fk_character_get_all(); // sorted by first name
echo '<p>' . __('If a character is not listed, you can <a href="'.$fk_settings->new_character_link.'">add it</a> then come back to this post.') . '</p>';
if( empty($characters) ){
_e("<p>No characters have been marked as appearing in this episode.</p>");
if( empty($all_characters) ){
printf(__('<p>No characters have been added. Maybe you want to <a href="%s">add one</a>?</p>'),
} else {
echo '<p>';
foreach( (array) $all_characters as $ch ){
$ch_id = $ch->character_id;
$checked = fk_character_appears_in($ch_id, $post->ID) ? ' checked="checked"' : '';
printf('<label><input type="checkbox" name="fk_characters[]" value="%1$s"%2$s /> %3$s</label>',
$ch_id, $checked, $ch->name);
printf(' (<a href="%s">'.__('view').'</a> '.__('or').
' <a href="%s">'.__('edit').'</a>)',
get_permalink($ch_id), get_edit_post_link($ch_id));
echo '<br />';
echo '</p>';
echo '</p>';
// Callback for transcript metabox
function fk_episode_transcript_box_cb(){
wp_nonce_field('fk_set_episode_transcript', 'fk_episode_transcript_nonce');
function fk_save_post_episode($post_id){
check_admin_referer('fk_set_characters', 'fk_characters_nonce');
check_admin_referer('fk_set_episode_info', 'fk_episode_info_nonce');
check_admin_referer('fk_set_episode_transcript', 'fk_episode_transcript_nonce');
$season = $_POST['fk_season'];
$ep_num = $_POST['fk_ep_num'];
$characters = $_POST['fk_characters']; // TODO
if( is_null($characters) ){
$characters = array();
if( fk_episode_exists($post_id) ){
fk_episode_edit($post_id, $season, $ep_num, $characters);
} else {
fk_episode_add($post_id, $season, $ep_num, $characters);
function fk_delete_post_episode($post_id){