Skip to content

Commit

Permalink
Merge pull request #398 from TheCraigHewitt/feature/podtrac-integration
Browse files Browse the repository at this point in the history
Feature/podtrac integration
  • Loading branch information
jonathanbossenger authored Aug 13, 2019
2 parents d8425ec + b606fb7 commit 638310a
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 79 deletions.
89 changes: 17 additions & 72 deletions php/classes/controllers/class-admin-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ class Admin_Controller extends Controller {
*/
protected $ajax_handler;

/**
* @var object instance of Upgrade_Handler
*/
protected $upgrade_handler;

/**
* @var object instance of Feed_Controller
*/
protected $feed_controller;

/**
* Admin_Controller constructor.
*
* @param $file main plugin file
* @param $version plugin version
* @param $file string main plugin file
* @param $version string plugin version
*/
public function __construct( $file, $version ) {
parent::__construct( $file, $version );
Expand All @@ -48,6 +56,8 @@ public function bootstrap() {

$this->upgrade_handler = new Upgrade_Handler();

$this->feed_controller = new Feed_Controller( $this->file, $this->version );

// Handle localisation.
$this->load_plugin_textdomain();

Expand All @@ -56,12 +66,6 @@ public function bootstrap() {
// Regsiter podcast post type, taxonomies and meta fields.
add_action( 'init', array( $this, 'register_post_type' ), 11 );

// Register podcast feed.
add_action( 'init', array( $this, 'add_feed' ), 11 );

// Handle v1.x feed URL as well as feed URLs for default permalinks.
add_action( 'init', array( $this, 'redirect_old_feed' ), 11 );

// Setup custom permalink structures.
add_action( 'init', array( $this, 'setup_permastruct' ), 10 );

Expand Down Expand Up @@ -1233,15 +1237,6 @@ public function load_plugin_textdomain() {
load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
}

/**
* Register podcast feed
* @return void
*/
public function add_feed() {
$feed_slug = apply_filters( 'ssp_feed_slug', $this->token );
add_feed( $feed_slug, array( $this, 'feed_template' ) );
}

/**
* Hide RSS footer created by WordPress SEO from podcast RSS feed
*
Expand All @@ -1259,72 +1254,22 @@ public function hide_wp_seo_rss_footer( $include_footer = true ) {
}

/**
* Load feed template
* @return void
*/
public function feed_template() {
global $wp_query;

// Prevent 404 on feed
$wp_query->is_404 = false;

/**
* Fix the is_feed attribute on the old feed url structure
*/
if ( ! $wp_query->is_feed ) {
$wp_query->is_feed = true;
}

status_header( 200 );

$file_name = 'feed-podcast.php';

$user_template_file = apply_filters( 'ssp_feed_template_file', trailingslashit( get_stylesheet_directory() ) . $file_name );

// Any functions hooked in here must NOT output any data or else feed will break
do_action( 'ssp_before_feed' );

// Load user feed template if it exists, otherwise use plugin template
if ( file_exists( $user_template_file ) ) {
require( $user_template_file );
} else {
require( $this->template_path . $file_name );
}

// Any functions hooked in here must NOT output any data or else feed will break
do_action( 'ssp_after_feed' );

exit;
}

/**
* Redirect feed URLs created prior to v1.8 to ensure backwards compatibility
* @return void
*/
public function redirect_old_feed() {
if ( isset( $_GET['feed'] ) && in_array( $_GET['feed'], array( $this->token, 'itunes' ) ) ) {
$this->feed_template();
exit;
}
}

/**
* Flush rewrite rules on plugin acivation
* All plugin activation functionality
* @return void
*/
public function activate() {

// Setup all custom URL rules
$this->register_post_type();
$this->add_feed();
// Setup feed
$this->feed_controller->add_feed();
// Setup permalink structure
$this->setup_permastruct();

// Flush permalinks
flush_rewrite_rules( true );
}

/**
* Flush rewrite rules on plugin deacivation
* All plugin deactivation functionality
* @return void
*/
public function deactivate() {
Expand Down
2 changes: 2 additions & 0 deletions php/classes/controllers/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
exit;
}

// @todo maybe this should be a trait ?
/**
* Main controller class
*
Expand Down
110 changes: 110 additions & 0 deletions php/classes/controllers/class-feed-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace SeriouslySimplePodcasting\Controllers;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Feed Controller Class
*
* @author Jonathan Bossenger
* @category Class
* @package SeriouslySimplePodcasting/Controllers
* @since 1.20.7
*/
class Feed_Controller extends Controller {

public $feed_file_name = 'feed-podcast.php';

/**
* Admin_Controller constructor.
*
* @param $file main plugin file
* @param $version plugin version
*/
public function __construct( $file, $version ) {
parent::__construct( $file, $version );

$this->bootstrap();
}

/**
* Set up all hooks and filters for this class
*/
public function bootstrap() {
// Register podcast feed.
add_action( 'init', array( $this, 'add_feed' ), 11 );

// Handle v1.x feed URL as well as feed URLs for default permalinks.
add_action( 'init', array( $this, 'redirect_old_feed' ), 11 );
}

/**
* Register podcast feed
* @return void
*/
public function add_feed() {
$feed_slug = apply_filters( 'ssp_feed_slug', $this->token );
add_feed( $feed_slug, array( $this, 'render_podcast_feed' ) );
}

/**
* Redirect feed URLs created prior to v1.8 to ensure backwards compatibility
* @return void
*/
public function redirect_old_feed() {
if ( isset( $_GET['feed'] ) && in_array( $_GET['feed'], array( $this->token, 'itunes' ) ) ) {
$this->render_podcast_feed();
exit;
}
}

/**
* Render the podcast feed
* // @todo move all logic from feed template file to this method, at the very least
* @return void
*/
public function render_podcast_feed() {
global $wp_query;

// Prevent 404 on feed
$wp_query->is_404 = false;

/**
* Fix the is_feed attribute on the old feed url structure
*/
if ( ! $wp_query->is_feed ) {
$wp_query->is_feed = true;
}

$this->load_feed_template();

exit;

}

/**
* Loads the feed template file
*/
public function load_feed_template() {
status_header( 200 );

$user_template_file = apply_filters( 'ssp_feed_template_file', trailingslashit( get_stylesheet_directory() ) . $this->feed_file_name );

// Any functions hooked in here must NOT output any data or else feed will break
do_action( 'ssp_before_feed' );

// Load user feed template if it exists, otherwise use plugin template
if ( file_exists( $user_template_file ) ) {
require $user_template_file;
} else {
require $this->template_path . $this->feed_file_name;
}

// Any functions hooked in here must NOT output any data or else feed will break
do_action( 'ssp_after_feed' );
}
}
14 changes: 13 additions & 1 deletion php/classes/handlers/class-settings-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,27 @@ public function settings_fields() {
array(
'id' => 'consume_order',
'label' => __( 'Show Type', 'seriously-simple-podcasting' ),
// translators: placeholders are for help document link
'description' => sprintf( __( 'The order your podcast episodes will be listed. %1$sMore details here.%2$s', 'seriously-simple-podcasting' ), '<a href="' . esc_url( 'https://www.seriouslysimplepodcasting.com/ios-11-podcast-tags/' ) . '" target="' . wp_strip_all_tags( '_blank' ) . '">', '</a>' ),
'type' => 'select',
'options' => array(
'' => __( 'Please Select', 'seriously-simple-podcasting' ),
'episodic' => __( 'Episodic', 'seriously-simple-podcasting' ),
'serial' => __( 'Serial', 'seriously-simple-podcasting' )
'serial' => __( 'Serial', 'seriously-simple-podcasting' ),
),
'default' => '',
),
array(
'id' => 'media_prefix',
'label' => __( 'Media File Prefix', 'seriously-simple-podcasting' ),
// translators: placeholders are for help document link
'description' => sprintf( __( 'Enter your Podtrac, Chartable, or other media file prefix here. %1$sMore details here.%2$s', 'seriously-simple-podcasting' ), '<a href="' . esc_url( 'https://support.castos.com/article/95-adding-a-media-file-prefix-for-podtrac-chartable-and-other-tracking-services' ) . '" target="' . wp_strip_all_tags( '_blank' ) . '">', '</a>' ),
'type' => 'text',
'default' => '',
'placeholder' => __( 'https://dts.podtrac.com/redirect/mp3/', 'seriously-simple-podcasting' ),
'callback' => 'esc_url_raw',
'class' => 'regular-text',
),
array(
'id' => 'episode_description',
'label' => __( 'Episode description', 'seriously-simple-podcasting' ),
Expand Down
22 changes: 22 additions & 0 deletions php/includes/ssp-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,25 @@ function get_series_data_for_castos( $series_id ) {

}
}

if ( ! function_exists( 'parse_episode_url_with_media_prefix' ) ) {
/**
* Takes an episode url and appends the media prefix in front of it
*
* @param string $audio_file_url
* @param string $media_prefix
*
* @return string
*/
function parse_episode_url_with_media_prefix( $audio_file_url = '', $media_prefix = '' ) {
if ( empty( $media_prefix ) ) {
return $audio_file_url;
}
if ( empty( $audio_file_url ) ) {
return $audio_file_url;
}
$url_parts = wp_parse_url( $audio_file_url );

return $media_prefix . $url_parts['host'] . $url_parts['path'];
}
}
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: PodcastMotor, psykro, simondowdles, hlashbrooke, whyisjake
Tags: podcast, audio, video, vodcast, rss, mp3, mp4, feed, itunes, podcasting, media, stitcher, google play, playlist
Requires at least: 4.4
Tested up to: 5.2
Tested up to: 5.2.2
Requires PHP: 5.6
Stable tag: 1.20.7
Stable tag: 1.20.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -102,6 +102,10 @@ You can find complete user and developer documentation (along with the FAQs) on

== Changelog ==

= 1.20.8 =
* 2019-08-13
* [NEW] Added support for RSS Feed media file prefixing, to enable measuring services like Podtrac and Chartable

= 1.20.7 =
* 2019-07-31
* [UPDATE] Updated podcast categories to reflect Apple's [podcast category changes](https://podnews.net/press-release/apple-wwdc-2019-anno)
Expand Down
8 changes: 4 additions & 4 deletions seriously-simple-podcasting.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* Plugin Name: Seriously Simple Podcasting
* Version: 1.20.7
* Version: 1.20.8
* Plugin URI: https://www.castos.com/seriously-simple-podcasting
* Description: Podcasting the way it's meant to be. No mess, no fuss - just you and your content taking over the world.
* Author: Castos
* Author URI: https://www.castos.com/
* Requires PHP: 5.6
* Requires at least: 4.4
* Tested up to: 5.2
* Tested up to: 5.2.2
*
* Text Domain: seriously-simple-podcasting
*
Expand All @@ -26,7 +26,7 @@
use SeriouslySimplePodcasting\Controllers\Options_Controller;
use SeriouslySimplePodcasting\Rest\Rest_Api_Controller;

define( 'SSP_VERSION', '1.20.7' );
define( 'SSP_VERSION', '1.20.8' );
define( 'SSP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'SSP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );

Expand All @@ -47,7 +47,7 @@
/**
* @todo refactor these globals
* @todo the admin_controller should really be renamed, as it's not really 'admin' specific
* @todo alternatively the non admin specific functionality should be moved into it's own 'foundation' controller, perhaps even the parent controller
* @todo alternatively the non admin specific functionality should be moved into it's own 'foundation' controller, perhaps even the parent controller, or a trait
*/
global $ssp_admin, $ss_podcasting;
$ssp_admin = new Admin_Controller( __FILE__, SSP_VERSION );
Expand Down
Loading

0 comments on commit 638310a

Please sign in to comment.