Skip to content

Commit

Permalink
Merge pull request #41 from WP-for-Church/dev
Browse files Browse the repository at this point in the history
Release 2.4.0
  • Loading branch information
Nikola Miljković authored Jun 3, 2017
2 parents 220da72 + 3d0fb45 commit 1633275
Show file tree
Hide file tree
Showing 33 changed files with 1,418 additions and 14,317 deletions.
3 changes: 3 additions & 0 deletions includes/CMB2/includes/CMB2_Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public static function array_insert( &$array, $new, $position ) {
* @return string URL to CMB2 resources
*/
public static function url( $path = '' ) {
// SM: Seems like CMB2 doesn't return a correct URL. This should fix it.
return str_replace( get_site_url(), '', SERMON_MANAGER_URL ) . 'includes/CMB2/' . $path;

if ( self::$url ) {
return self::$url . $path;
}
Expand Down
82 changes: 71 additions & 11 deletions includes/admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function wpfc_sermon_audio_validate( $new, $post_id, $field ) {
if ( $field['id'] != 'sermon_audio' ) {
return $new;
}
$audio = get_post_meta( $post_id, 'sermon_audio', 'true' );
$audio = get_post_meta( $post_id, 'sermon_audio', true );
// Stop if PowerPress plugin is active
// Solves conflict regarding enclosure field: http://wordpress.org/support/topic/breaks-blubrry-powerpress-plugin?replies=6
if ( defined( 'POWERPRESS_VERSION' ) ) {
Expand All @@ -84,8 +84,8 @@ function wpfc_sermon_audio_validate( $new, $post_id, $field ) {
// This will set the length of the enclosure automatically
do_enclose( $audio, $post_id );
// Set duration as post meta
$current = get_post_meta( $post_id, 'sermon_audio', 'true' );
$currentduration = get_post_meta( $post_id, '_wpfc_sermon_duration', 'true' );
$current = get_post_meta( $post_id, 'sermon_audio', true );
$currentduration = get_post_meta( $post_id, '_wpfc_sermon_duration', true );
// only grab if different (getting data from dropbox can be a bit slow)
if ( $new != '' && ( $new != $current || empty( $currentduration ) ) ) {
// get file data
Expand Down Expand Up @@ -183,7 +183,7 @@ function wpfc_sermon_edit_columns() {
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => __( 'Sermon Title', 'sermon-manager' ),
"preacher" => __( 'Preacher', 'sermon-manager' ),
"preacher" => __( \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher', 'sermon-manager' ),
"series" => __( 'Sermon Series', 'sermon-manager' ),
"topics" => __( 'Topics', 'sermon-manager' ),
"views" => __( 'Views', 'sermon-manager' ),
Expand All @@ -195,33 +195,63 @@ function wpfc_sermon_edit_columns() {
}

/**
* Return data for sermon data columns in edit.php
* Echo data for sermon data columns in edit.php
*
* @param string $column The column being requested
*
* @return void
*/
function wpfc_sermon_columns( $column ) {
global $post;

if ( empty( $post->ID ) ) {
echo 'Error. Can\'t find sermon ID.';

return;
}

switch ( $column ) {
case "preacher":
echo get_the_term_list( $post->ID, 'wpfc_preacher', '', ', ', '' );
$data = get_the_term_list( $post->ID, 'wpfc_preacher', '', ', ', '' );
break;
case "series":
echo get_the_term_list( $post->ID, 'wpfc_sermon_series', '', ', ', '' );
$data = get_the_term_list( $post->ID, 'wpfc_sermon_series', '', ', ', '' );
break;
case "topics":
echo get_the_term_list( $post->ID, 'wpfc_sermon_topics', '', ', ', '' );
$data = get_the_term_list( $post->ID, 'wpfc_sermon_topics', '', ', ', '' );

// Sometimes corrupted data gets cached, clearing the cache might help
if ( $data instanceof WP_Error ) {
if ( get_transient( 'wpfc_topics_cache_cleared' ) ) {
wp_cache_delete( $post->ID, 'wpfc_sermon_topics_relationships' );
$data = get_the_term_list( $post->ID, 'wpfc_sermon_topics', '', ', ', '' );
set_transient( 'wpfc_topics_cache_cleared', 1, 60 * 60 );
}
}

break;
case "views":
echo wpfc_entry_views_get( array( 'post_id' => $post->ID ) );
$data = wpfc_entry_views_get( array( 'post_id' => $post->ID ) );
break;
case "preached":
echo wpfc_sermon_date_filter();
$data = wpfc_sermon_date_filter( 0, '', $post );
break;
case "passage":
echo get_post_meta( $post->ID, 'bible_passage', true );
$data = get_post_meta( $post->ID, 'bible_passage', true );
break;
default:
$data = '';
}

if ( $data instanceof WP_Error ) {
echo '<strong>Error:</strong> ' . $data->get_error_message();

return;
}

echo $data;

return;
}

/**
Expand Down Expand Up @@ -409,3 +439,33 @@ function wpfc_taxonomy_short_description_shorten( $string, $max_length = 23, $ap

return $string;
}

/**
* Returns duration of an MP3 file
*
* @param string $mp3_url URL to the MP3 file
*
* @return string duration
*/
function wpfc_mp3_duration( $mp3_url ) {
if ( empty( $mp3_url ) ) {
return '';
}

if ( ! class_exists( 'getID3' ) ) {
require_once ABSPATH . 'wp-includes/ID3/getid3.php';
}

// create a temporary file for the MP3 file
$filename = tempnam( '/tmp', 'getid3' );

if ( file_put_contents( $filename, file_get_contents( $mp3_url ) ) ) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze( $filename );
unlink( $filename );
}

$duration = isset( $ThisFileInfo['playtime_string'] ) ? $ThisFileInfo['playtime_string'] : '';

return $duration;
}
7 changes: 4 additions & 3 deletions includes/fix-dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function render_warning() {
?>
<div class="notice notice-error is-dismissible">
<p><strong>Important!</strong> Sermon Manager needs to check dates of old sermons.
<a href="<?php echo admin_url( 'edit.php?post_type=wpfc_sermon&page=' . basename( SERMON_MANAGER_PATH ) . '/includes/options.php#sermon-options-dates-fix' ); ?>">Click
<a href="<?php echo admin_url( 'edit.php?post_type=wpfc_sermon&page=' . basename( SERMON_MANAGER_PATH ) . 'includes/options.php#sermon-options-dates-fix' ); ?>">Click
here</a> if you want to do it now.</p>
</div>
<?php
Expand All @@ -177,8 +177,9 @@ public function fix() {
?>
Checking for errors...
<?php
$dates = $this->getAllDates( true );
if ( $this->getDatesStats()['total'] < 1 ) {
$dates = $this->getAllDates( true );
$dates_stats = $this->getDatesStats();
if ( $dates_stats['total'] < 1 ) {
update_option( 'wpfc_sm_dates_total', count( $dates ) );
update_option( 'wpfc_sm_dates_remaining', count( $dates ) );
update_option( 'wpfc_sm_dates_fixed', 0 );
Expand Down
Loading

0 comments on commit 1633275

Please sign in to comment.