Skip to content

Commit

Permalink
enhancements
Browse files Browse the repository at this point in the history
allow alternate chatper titles
allow stories to be author-exclusive
allow TOC/next/prev to show or not show on chapter pages
  • Loading branch information
christiespeich committed Jun 14, 2018
1 parent 0e02fd1 commit eb415ef
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 34 deletions.
8 changes: 4 additions & 4 deletions css/admin-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
padding: 0;
}

#cmb2-metabox-_mbds_story_meta_box .cmb-th {
width: 25%;
#cmb2-metabox-_mbds_story_meta_box .cmb-th, #cmb2-metabox-mbds_display .cmb-th {
width: 30%;
}

#cmb2-metabox-_mbds_story_meta_box .cmb-th+.cmb-td {
width: 73%;
#cmb2-metabox-_mbds_story_meta_box .cmb-th+.cmb-td, #cmb2-metabox-mbds_display .cmb-th+.cmb-td {
width: 67%;
}

#mbds_post_grid { list-style-type: none; margin: 10px; padding: 0; width: 60%; }
Expand Down
75 changes: 59 additions & 16 deletions includes/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,46 @@ function mbds_get_storyID_by_slug($story) {

}

function mbds_get_story_list() {
$posts = get_posts(array('posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => 'mbds_story',
));
$stories = array();
$stories['0'] = '';
foreach ($posts as $post) {
$stories[$post->ID] = $post->post_title;
}
wp_reset_postdata();
return apply_filters('mbds_story_list', $stories);
function mbds_get_story_list( $all_stories = false ) {

if ( $all_stories ) {
$posts = get_posts( array(
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => 'mbds_story',
) );
} else {

// get all stories for this author
$this_author = get_posts( array(
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => 'mbds_story',
'author' => get_current_user_id(),
) );

// get all stories not from this author that
// also allow other authors to contribute
$open_stories = get_posts( array(
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => 'mbds_story',
'meta_query' => array(array(
'key' => '_mbds_open_story',
'value' => 'yes',
)),
) );

$posts = array_merge ( $this_author, $open_stories );

}
$stories = array();
$stories['0'] = '';
foreach ($posts as $post) {
$stories[$post->ID] = $post->post_title;
}
wp_reset_postdata();
return apply_filters('mbds_story_list', $stories);
}

function mbds_get_story( $storyID ) {
Expand Down Expand Up @@ -175,11 +203,20 @@ function mbds_get_posts_list( $storyID ) {

$key = array_search($post->ID, $posts_list);
if ($key !== false) {
$alt_title = get_post_meta( $post->ID, '_mbds_alt_chapter_title', true );
if ( $alt_title != '' ) {
$title = $alt_title;
} else {
$title = $post->post_title;
}
$posts_list[$key] = array('ID' => $post->ID,
'title' => $post->post_title,
'title' => $title,
'link' => get_permalink($post->ID),
'order' => $key);
}



}

wp_reset_postdata();
Expand All @@ -203,8 +240,14 @@ function mbds_get_most_recent_post( $storyID) {
$posts = get_posts($post_args);
wp_reset_postdata();
if (count($posts)>0) {
$alt_title = get_post_meta( $posts[0]->ID, '_mbds_alt_chapter_title', true );
if ( $alt_title != '' ) {
$title = $alt_title;
} else {
$title = $posts[0]->post_title;
}
return array(array('ID' => $posts[0]->ID,
'title' => $posts[0]->post_title,
'title' => $title,
'link' => get_permalink($posts[0]->ID),
'order' => '0'));
} else {
Expand Down Expand Up @@ -301,8 +344,8 @@ function mbds_get_tax_terms_dropdown ($taxonomy, $selected) {



function mbds_get_stories_dropdown( $selected ) {
$stories = mbds_get_story_list();
function mbds_get_stories_dropdown( $selected, $all_stories = false ) {
$stories = mbds_get_story_list( $all_stories );
return apply_filters('mbds_stories_dropdown', mbds_output_dropdown( $stories, $selected));
}

Expand Down
30 changes: 30 additions & 0 deletions includes/updates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
// run after cpts have been registered
add_action( 'init', 'mbds_update_versions', 30 );
function mbds_update_versions() {

$current_version = get_option(MBDS_PLUGIN_VERSION_KEY);

if ($current_version == '') {
$current_version = '1.2.3';
}

if (version_compare($current_version, '1.3', '<')) {
// upgrade to 1.3 script
// add new retailers
mbds_upgrade_to_1_3();
}

update_option(MBDS_PLUGIN_VERSION_KEY, MBDS_PLUGIN_VERSION);

}

function mbds_upgrade_to_1_3() {
$stories = mbds_get_story_list( true );
foreach ( $stories as $story_id => $story ) {
if ( $story_id != 0 ) {
update_post_meta( $story_id, '_mbds_open_story', 'yes' );
}
}

}
57 changes: 46 additions & 11 deletions mooberry-story.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Mooberry Story
Plugin URI: http://www.mooberrydreams.com/products/mooberry-story
Description: Organizes multiple blog posts into a series. Make it easy for readers to find your stories, including older ones.
Version: 1.2.3
Version: 1.3
Author: Mooberry Dreams
Author URI: https://profiles.wordpress.org/mooberrydreams/
License: GPL2
Expand All @@ -29,7 +29,7 @@
define('MBDS_PLUGIN_DIR', plugin_dir_path( __FILE__ ));

define('MBDS_PLUGIN_VERSION_KEY', 'mbds_version');
define('MBDS_PLUGIN_VERSION', '1.2.3');
define('MBDS_PLUGIN_VERSION', '1.3');


//update checker
Expand All @@ -49,6 +49,7 @@
require_once dirname( __FILE__ ) . '/story.php';
require_once dirname( __FILE__ ) . '/post-meta-box.php';
require_once dirname( __FILE__ ) . '/includes/helper-functions.php';
require_once dirname( __FILE__ ) . '/includes/updates.php';
require_once dirname(__FILE__) . '/shortcodes.php';
require_once dirname(__FILE__) . '/widget-stories.php';
require_once dirname(__FILE__) . '/widget-posts.php';
Expand Down Expand Up @@ -235,20 +236,54 @@ function mbds_content($content) {

$storyID = get_post_meta($post->ID, '_mbds_story', true);
if ($storyID != '') {
$story_post_meta = get_post_meta( $storyID );
$toc_top = isset( $story_post_meta[ '_mbds_toc_top' ][0] ) ? $story_post_meta[ '_mbds_toc_top' ][0] == 'yes' : true;
$next_top = isset( $story_post_meta[ '_mbds_next_top' ][0] ) ? $story_post_meta[ '_mbds_next_top' ][0] == 'yes' : true;
$prev_top = isset( $story_post_meta[ '_mbds_prev_top' ][0] ) ? $story_post_meta[ '_mbds_prev_top' ][0] == 'yes' : true;

$toc_bottom = isset( $story_post_meta[ '_mbds_toc_bottom' ][0] ) ? $story_post_meta[ '_mbds_toc_bottom' ][0] == 'yes' : true;
$next_bottom = isset( $story_post_meta[ '_mbds_next_bottom' ][0] ) ? $story_post_meta[ '_mbds_next_bottom' ][0] == 'yes' : true;
$prev_bottom = isset( $story_post_meta[ '_mbds_prev_bottom' ][0] ) ? $story_post_meta[ '_mbds_prev_bottom' ][0] == 'yes' : true;


$story_text = $content;
$content = '';
$mbds_story = mbds_get_story($storyID);
$content = '[mbs_toc_link]';
$content .= '[mbs_prev][mbs_next]<br style="clear:both;">';
if ( $toc_top ) {
$content .= '[mbs_toc_link]';
}
if ( $prev_top ) {
$content .= '[mbs_prev]';
}
if ( $next_top) {
$content .= '[mbs_next]';
}
$content .= '<br style="clear:both;">';
$content .= '<h2 class="mbs_posts_title">';

if (isset($mbds_story['_mbds_include_posts_name'])) {
$content .= mbds_display_posts_name($mbds_story, $post->ID) . '<br>';
}

$content .= $post->post_title . '</h2>';

$alt_title = get_post_meta( $post->ID, '_mbds_alt_chapter_title', true );
if ( $alt_title != '' ) {
$title = $alt_title;
} else {
$title = $post->post_title;
}

$content .= $title . '</h2>';
$content .= '<div class="mbs_posts_text">' . $story_text . '</div>';
$content .= '[mbs_toc_link]';
$content .= '[mbs_prev][mbs_next]<br style="clear:both;">';
if ( $toc_bottom ) {
$content .= '[mbs_toc_link]';
}
if ( $prev_bottom ) {
$content .= '[mbs_prev]';
}
if ( $next_bottom) {
$content .= '[mbs_next]';
}
$content .= '<br style="clear:both;">';
}
}

Expand All @@ -275,10 +310,10 @@ function mbds_condition_filter_title($query){
// tc_title_text for theme Customizr
if($query === $wp_query){
add_filter( 'the_title', 'mbds_posts_title', 10, 2);
add_filter('tc_title_text', 'mbds_posts_title');
add_filter('tc_title_text', 'mbds_posts_title', 10, 2);
}else{
remove_filter('the_title','mbds_posts_title', 10, 2);
remove_filter('tc_title_text', 'mbds_posts_title');
remove_filter('the_title','mbds_posts_title', 10);
remove_filter('tc_title_text', 'mbds_posts_title', 10);
}
}

Expand Down
10 changes: 9 additions & 1 deletion post-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ function mbds_init_post_meta_box() {
'type' => 'select',
'options' => mbds_get_story_list(),

) ) );
) ) );

$post_meta_box->add_field( apply_filters( 'mbds_posts_chapter_title_field', array(
'name' => __('Alternative Chapter Title', 'mooberry-story' ),
'id' => $prefix . 'alt_chapter_title',
'type' => 'text',
'desc' => __('Use if you don\'t want the post title to be used as the title on the Table of Contents. Leave blank to use the post title above', 'mooberry-story'),
) ) );

/*
$post_meta_box->add_field( apply_filters('mbds_posts_summary_field', array(
'name' => __( 'Summary', 'mooberry-story' ),
Expand Down
5 changes: 5 additions & 0 deletions shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ function mbds_shortcode_toc( $attr, $content ) {
$html_output .= '<ul class="mbs_toc_list">';
$posts = mbds_get_posts_list( $storyID );
foreach ($posts as $each_post) {
$alt_title = get_post_meta( $each_post['ID'], '_mbds_alt_chapter_title', true );
if ( $alt_title != '' ) {
$post['title'] = $alt_title;
}

$html_output .= '<li><a href="' . $each_post['link'] . '">';
if (isset($mbds_story['_mbds_include_posts_name'])) {
$html_output .= '<span class="mbs_toc_item_posts_name">' . mbds_display_posts_name($mbds_story, $each_post['ID']) . ': </span>';
Expand Down
64 changes: 63 additions & 1 deletion story.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ function mbds_init_story_meta_box() {
// Start with an underscore to hide fields from custom fields list
$prefix = '_mbds_';

$yes_no = array(
'yes' => __('Yes', 'mooberry-story'),
'no' => __('No', 'mooberry-story'),
);

$story_meta_box = new_cmb2_box( apply_filters('mbds_story_meta_box', array(
'id' => $prefix . 'story_meta_box',
'title' => __( 'About the Story', 'mooberry-story' ),
Expand Down Expand Up @@ -39,7 +44,16 @@ function mbds_init_story_meta_box() {
'id' => $prefix . 'custom_type',
'type' => 'text',
) ) );



$story_meta_box->add_field( apply_filters( 'mbds_story_open_story_field', array(
'name' => __('Can other users add to this story?', 'mooberry-story'),
'id' => $prefix . 'open_story',
'type' => 'select',
'default' => 'no',
'options' => $yes_no,
) ) );

$story_meta_box->add_field( apply_filters('mbds_story_posts_name_field', array(
'name' => __( 'Posts Should Be Called', 'mooberry-story' ),
'id' => $prefix . 'posts_name',
Expand Down Expand Up @@ -108,8 +122,56 @@ function mbds_init_story_meta_box() {
'allow' => array( 'attachment' ) // limit to just attachments with array( 'attachment' )
)));

$story_display_meta_box = new_cmb2_box( apply_filters('mbds_story_display_meta_box', array(
'id' => 'mbds_display',
'title' => __('Story Display Settings', 'mooberry-story' ),
'object_types' => array( 'mbds_story', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
)));

$story_display_meta_box->add_field( apply_filters('mbds_story_prev_top', array(
'name' => __('Show Previous Chapter Link on top of page?', 'mooberry-story' ),
'id' => '_mbds_prev_top',
'type' => 'select',
'options' => $yes_no,
)));

$story_display_meta_box->add_field( apply_filters('mbds_story_next_top', array(
'name' => __('Show Next Chapter Link on top of page?', 'mooberry-story' ),
'id' => '_mbds_next_top',
'type' => 'select',
'options' => $yes_no,
)));

$story_display_meta_box->add_field( apply_filters('mbds_story_toc_top', array(
'name' => __('Show Table of Contents Link on top of page?', 'mooberry-story' ),
'id' => '_mbds_toc_top',
'type' => 'select',
'options' => $yes_no,
)));

$story_display_meta_box->add_field( apply_filters('mbds_story_prev_bottom', array(
'name' => __('Show Previous Chapter Link on bottom of page?', 'mooberry-story' ),
'id' => '_mbds_prev_bottom',
'type' => 'select',
'options' => $yes_no,
)));

$story_display_meta_box->add_field( apply_filters('mbds_story_next_bottom', array(
'name' => __('Show Next Chapter Link on bottom of page?', 'mooberry-story' ),
'id' => '_mbds_next_bottom',
'type' => 'select',
'options' => $yes_no,
)));

$story_display_meta_box->add_field( apply_filters('mbds_story_toc_bottom', array(
'name' => __('Show Table of Contents Link on bottom of page?', 'mooberry-story' ),
'id' => '_mbds_toc_bottom',
'type' => 'select',
'options' => $yes_no,
)));
}

add_action('add_meta_boxes_mbds_story', 'mbds_add_posts_meta_box');
Expand Down
2 changes: 1 addition & 1 deletion views/widget-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p>
<label id="<?php echo $this->get_field_id( 'mbds_pw_story' ); ?>_label" for="<?php echo $this->get_field_id( 'mbds_pw_story' ); ?>"><?php _e('Which story:', 'mooberry-story'); ?></label>
<select id="<?php echo $this->get_field_id('mbds_pw_story'); ?>" name="<?php echo $this->get_field_name('mbds_pw_story'); ?>" >
<?php echo mbds_get_stories_dropdown( $mbds_pw_story ); ?>
<?php echo mbds_get_stories_dropdown( $mbds_pw_story, true ); ?>
</select>
</p>
<p id="<?php echo $this->get_field_id( 'mbds_pw_count' ); ?>_p">
Expand Down

0 comments on commit eb415ef

Please sign in to comment.