Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
zahardev committed Apr 6, 2021
2 parents 01b253d + 241015e commit 775bc0e
Show file tree
Hide file tree
Showing 16 changed files with 3,736 additions and 2,436 deletions.
6 changes: 5 additions & 1 deletion assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ textarea#episode_embed_code {

#series_upload_image_button .dashicons {
vertical-align: middle;
}
}

#col-container .series-notice {
display: none;
}
10 changes: 3 additions & 7 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,17 @@ jQuery(document).ready(function($) {

});

$('#ss_podcasting_data_image_button').click(function() {
$.fn.ssp_upload_media_file( $(this), true );
});

$('#ss_podcasting_data_image_delete').click(function() {
$( '#ss_podcasting_data_image' ).val( '' );
$( '#ss_podcasting_data_image_preview' ).remove();
return false;
});

$( '#cover_image_button' ).click(function() {
$( '#cover_image_button, #ss_podcasting_data_image_button' ).click(function() {
var validateImageSize = function( attachment ) {
return attachment.width === attachment.height && attachment.width >= 300;
return attachment.width === attachment.height && attachment.width >= 1400 && attachment.width <= 3000;
}
var description = $( this ).siblings( '.description' );
var description = $( this ).parent().find( '.description' );
$.fn.ssp_upload_media_file( $(this), true, validateImageSize );
description.css( 'color', '' );

Expand Down
4,674 changes: 2,808 additions & 1,866 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seriously-simple-podcasting",
"version": "2.6.1",
"version": "2.6.2",
"main": "build/index.js",
"author": "CastosHQ",
"devDependencies": {
Expand Down
43 changes: 31 additions & 12 deletions php/classes/controllers/class-admin-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,35 @@
class Admin_Controller extends Controller {

/**
* @var object instance of Ajax_Handler
* @var Ajax_Handler
*/
protected $ajax_handler;

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

/**
* @var object instance of the Admin_Notices_Handler
* @var Admin_Notifications_Handler
*/
protected $admin_notices_handler;

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

/**
* @var Log_Helper
* */
protected $logger;

/**
* @var Cron_Controller
*/
protected $cron_controller;

/**
* Admin_Controller constructor.
*
Expand All @@ -69,8 +77,10 @@ public function bootstrap() {

$this->logger = new Log_Helper();

$this->cron_controller = new Cron_Controller();

if ( is_admin() ) {
$this->admin_notices_handler = new Admin_Notifications_Handler( $this->token );
$this->admin_notices_handler = ( new Admin_Notifications_Handler( $this->token ) )->bootstrap();
}

// Handle localisation.
Expand Down Expand Up @@ -117,8 +127,7 @@ public function bootstrap() {
add_action( 'save_post', array( $this, 'meta_box_save' ), 10, 1 );

// Update podcast details to Castos when a post is updated or saved
add_action( 'post_updated', array( $this, 'update_podcast_details' ), 10, 2 );
add_action( 'save_post', array( $this, 'update_podcast_details' ), 10, 2 );
add_action( 'save_post', array( $this, 'update_podcast_details' ), 20, 2 );

// Episode edit screen.
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ) );
Expand Down Expand Up @@ -1014,7 +1023,7 @@ public function custom_fields() {

$fields['cover_image'] = array(
'name' => __( 'Episode Image:', 'seriously-simple-podcasting' ),
'description' => __( 'Your podcast cover image - must be square (minimum size of 300x300 px).', 'seriously-simple-podcasting' ),
'description' => __( 'The podcast cover image should be between 1400x1400px and 3000x3000px in size and either .jpg or .png file format', 'seriously-simple-podcasting' ),
'type' => 'image',
'default' => '',
'section' => 'info',
Expand Down Expand Up @@ -1625,16 +1634,24 @@ public function update_podcast_details( $id, $post ) {
$response = $castos_handler->upload_podcast_to_podmotor( $post );

if ( 'success' === $response['status'] ) {
set_transient( $cache_key, true, 60 );
set_transient( $cache_key, true, 30 );
$podmotor_episode_id = $response['episode_id'];
if ( $podmotor_episode_id ) {
update_post_meta( $id, 'podmotor_episode_id', $podmotor_episode_id );
}
add_action( 'admin_notices', array( $this->admin_notices_handler, 'castos_api_episode_success' ) );
$this->admin_notices_handler->add_predefined_flash_notice(
Admin_Notifications_Handler::NOTICE_API_EPISODE_SUCCESS
);

// if uploading was scheduled before, lets unschedule it
delete_post_meta( $id, 'podmotor_schedule_upload' );
} else {
add_action( 'admin_notices', array( $this->admin_notices_handler, 'castos_api_error' ) );
// schedule uploading with a cronjob
update_post_meta( $id, 'podmotor_schedule_upload', true );
$this->admin_notices_handler->add_predefined_flash_notice(
Admin_Notifications_Handler::NOTICE_API_EPISODE_ERROR
);
}

}

/**
Expand Down Expand Up @@ -1878,6 +1895,8 @@ public function prevent_copy_meta() {
$exclusions = [
'podmotor_file_id',
'podmotor_episode_id',
'audio_file',
'enclosure'
];

foreach ( $exclusions as $exclusion ) {
Expand Down
74 changes: 74 additions & 0 deletions php/classes/controllers/class-cron-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace SeriouslySimplePodcasting\Controllers;

use SeriouslySimplePodcasting\Handlers\Castos_Handler;
use SeriouslySimplePodcasting\Helpers\Log_Helper;

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

/**
* SSP Episode Controller
*
* @package Seriously Simple Podcasting
*/
class Cron_Controller {
public function __construct() {
add_action( 'ssp_cron_hook', array( $this, 'upload_scheduled_episodes' ) );
add_action( 'admin_init', array( $this, 'schedule_events' ) );
}

public function schedule_events() {
if ( ! wp_next_scheduled( 'ssp_cron_hook' ) ) {
wp_schedule_event( time(), 'hourly', 'ssp_cron_hook' );
}
}

/**
* @return int Number of uploaded episodes
*/
public function upload_scheduled_episodes() {
$castos_handler = new Castos_Handler();
$uploaded = 0;
foreach ( $this->get_scheduled_episodes() as $episode ) {
$response = $castos_handler->upload_podcast_to_podmotor( $episode );

if ( 'success' === $response['status'] ) {
delete_post_meta( $episode->ID, 'podmotor_schedule_upload' );
$uploaded++;
}
}

if ( $uploaded ) {
$logger = new Log_Helper();
$logger->log( 'Cron: uploaded scheduled episodes', $uploaded );
}

return $uploaded;
}


/**
* @return array
*/
protected function get_scheduled_episodes() {
$args = array(
'post_type' => ssp_post_types(),
'orderby' => 'ID',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'podmotor_schedule_upload',
'value' => 1,
),
),
);

$query = new \WP_Query( $args );

return $query->get_posts();
}
}
Loading

0 comments on commit 775bc0e

Please sign in to comment.