/** * get_series_posts() - use to call up the list of posts in a supplied series id. The style of the outputted display is determined by the PostList template on the Series Options page in the WordPress admin. * AUTOTAG - is part of the postlist_template call [autotag option - "Display list of series on post pages" * @package Organize Series WordPress Plugin * @since 2.0 * * @uses is_single() - checks if this is a single post page being displayed. * @uses get_the_series() - returns the series ids of a post. * @uses get_option() - calls up the 'org_series_options' field from the _options table. * @uses get_objects_in_term() - WordPress core function for accessing the taxonomy tables and pulling up all the posts associated with the supplied taxonomy id and taxonomy. * @uses get_series_order() - Takes the array of posts in a series and returns it sorted by post order. * @uses series_post_title() - Finds and displays the title of a post that is part of the series. * @uses token_replace() - utility function to replace %tokens% in the template as set by the user in the series->options page. * * @param int $ser_ID The ID of the series we want to list the posts from. * @param bool|string $referral options are 'widget' | false. Indicates what the referring location for calling this function is. If 'widget' then widget specific code is applied. Defaults to false. * @param bool $display Indicates whether to return the post list (false) or to echo the post list (true). Defaults to false. * @param bool|string $serieswidg_title The title for a list of other posts in the series displayed in widget. * @return string The post list as a assembled string ready for display (if $display is false) */ function get_series_posts($ser_ID = array(), $referral = false, $display = false, $serieswidg_title = false) { global $post, $orgseries; if (is_single()) { $cur_id = $post->ID; } else { $cur_id = -1; } if (!is_single() && !isset($ser_ID)) { return false; } if (!empty($ser_ID)) { $ser_ID = is_array($ser_ID) ? $ser_ID : array($ser_ID); } if (!isset($ser_ID) || empty($ser_ID)) { $serarray = get_the_series(); if (!empty($serarray)) { foreach ($serarray as $series) { $ser_ID[] = $series->term_id; } } } $series_post = array(); $posts_in_series = array(); $settings = $orgseries->settings; $result = ''; foreach ($ser_ID as $ser) { $series_post = get_objects_in_term($ser, 'series'); $is_unpub_template = TRUE; $is_unpub_template = apply_filters('unpublished_post_template', $is_unpub_template); $posts_in_series = get_series_order($series_post, 0, $ser, FALSE, $is_unpub_template); if ('widget' == $referral) { if ($serieswidg_title != false) { $result .= '<h4>' . __($serieswidg_title, 'organize-series') . '</h4>'; } $result .= '<ul>'; } foreach ($posts_in_series as $seriespost) { $short_title = get_post_meta($seriespost['id'], SPOST_SHORTTITLE_KEY, true); if ($cur_id == $seriespost['id']) { if ('widget' == $referral) { $result .= '<li class="serieslist-current-li">' . series_post_title($seriespost['id'], true, $short_title) . '</li>'; } else { $result .= token_replace(stripslashes($settings['series_post_list_currentpost_template']), 'other', $seriespost['id'], $ser); } continue; } $post_status = get_post_status($seriespost['id']); if (in_array($post_status, array('publish', 'private'))) { if ('widget' == $referral) { $result .= '<li>' . series_post_title($seriespost['id']) . '</li>'; } else { $result .= token_replace(stripslashes($settings['series_post_list_post_template']), 'other', $seriespost['id'], $ser); } } else { $result .= apply_filters('unpublished_post_template', $settings, $seriespost, $ser); } } if ('widget' == $referral) { $result .= '</ul>'; } } if (!$display) { return $result; } else { echo $result; } }
/** NOTE: %postcontent% is NOT replaced with this function...it happens in the content filter function **/ function token_replace($replace, $referral = 'other', $id = 0, $ser_ID = 0) { global $post, $orgseries; $p_id = $id == 0 ? $post->ID : $id; $ser_id = $ser_ID == 0 ? $id : $ser_ID; //$p_id = (empty($post->ID) || $post->ID == '') ? $id : $post->ID; $settings = $orgseries->settings; $replace = apply_filters('pre_orgseries_token_replace', $replace, $referral, $id, $p_id, $ser_id); if ('post-list' == $referral) { $ser_width = $settings['series_icon_width_post_page']; } elseif ('latest_series' == $referral) { $ser_width = $settings['series_icon_width_latest_series']; } else { $ser_width = $settings['series_icon_width_series_page']; } if ('series-toc' == $referral || 'latest_series' == $referral) { $replace = str_replace('%total_posts_in_series%', wp_postlist_count($ser_id), $replace); } else { $replace = str_replace('%total_posts_in_series%', wp_postlist_count($ser_id), $replace); } if (stristr($replace, '%series_icon%')) { $replace = str_replace('%series_icon%', get_series_icon('fit_width=' . $ser_width . '&link=0&series=' . $ser_id . '&display=0'), $replace); } if (stristr($replace, '%series_icon_linked%')) { $replace = str_replace('%series_icon_linked%', get_series_icon('fit_width= ' . $ser_width . '&series=' . $ser_id . '&display=0'), $replace); } if (stristr($replace, '%series_title%')) { $replace = str_replace('%series_title%', the_series_title($ser_id, FALSE), $replace); } if (stristr($replace, '%series_title_linked%')) { $replace = str_replace('%series_title_linked%', the_series_title($ser_id), $replace); } if (stristr($replace, '%post_title_list%')) { $replace = str_replace('%post_title_list%', get_series_posts($id, $referral), $replace); } if (stristr($replace, '%post_title%')) { $replace = str_replace('%post_title%', series_post_title($id, FALSE), $replace); } if (stristr($replace, '%post_title_linked%')) { $replace = str_replace('%post_title_linked%', series_post_title($id), $replace); } if (stristr($replace, '%series_part%')) { $replace = str_replace('%series_part%', wp_series_part($p_id, $ser_id), $replace); } if (stristr($replace, '%series_description%')) { $replace = str_replace('%series_description%', series_description($ser_id), $replace); } if (stristr($replace, '%next_post%')) { $replace = str_replace('%next_post%', wp_series_nav($id), $replace); } if (stristr($replace, '%previous_post%')) { $replace = str_replace('%previous_post%', wp_series_nav($id, FALSE), $replace); } if (stristr($replace, '%next_post_custom%')) { $replace = str_replace('%next_post_custom%', wp_series_nav($id, TRUE, TRUE), $replace); } if (stristr($replace, '%previous_post_custom%')) { $replace = str_replace('%previous_post_custom%', wp_series_nav($id, FALSE, TRUE), $replace); } $replace = apply_filters('post_orgseries_token_replace', $replace, $referral, $id, $p_id, $ser_id); return $replace; }