Plugin Directory

Changeset 566171


Ignore:
Timestamp:
07/01/2012 07:48:16 PM (14 years ago)
Author:
two7s_clash
Message:

2.2

Location:
jetpack-easy-playlists
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • jetpack-easy-playlists/trunk/jetpack_easy_playlists.php

    r565420 r566171  
    44Plugin URI: http://www.jamesfishwick.com/software/auto-jetpack-playlist/
    55Description: A simple [audio] shortcode wrapper to generate playlists automatically from mp3s attached to your post/page. Requires Jetpack.
    6 Version: 2.1
     6Version: 2.2
    77Author: James Fishwick
    88Author URI: http://www.jamesfishwick.com/
    99License: GPL2
    1010*/
    11 /*  Copyright 2012  James Fishwick  (email : fishwick@gmail.com)
     11/*  Copyright 2012 James Fishwick fishwick@gmail.com
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    3535    $required_plugin = 'jetpack/jetpack.php';
    3636    $dependant_plugin = 'easy_jetpack_playlists/easy_jetpack_playlists.php';
     37   
     38   
    3739
    3840    // If this plugin is being activated
     
    8991            return implode( $separator, $string );
    9092        }
     93function var_to_str($in)
     94{
     95   if(is_bool($in))
     96   {
     97      if($in)
     98         return "true";
     99      else
     100         return "false";
     101   }
     102   else
     103      return $in;
     104}       
     105       
     106function is_mp3( $file ) {
     107        $extension = end( explode( ".", $file->guid ) );
     108        return ($extension == "mp3");
     109        }
    91110
     111function get_ID_by_slug($page_slug) {
     112    $page = get_page_by_path($page_slug);
     113    if ($page) {
     114        return $page->ID;
     115    } else {
     116        return null;
     117    }
     118}
     119       
    92120add_shortcode('jplaylist', 'easyjp_playlists');
    93121
    94122function easyjp_playlists( $atts ) {
    95                        
    96     if( class_exists( 'AudioShortcode' ) && method_exists( 'AudioShortcode', 'audio_shortcode' ) ) {
    97 
     123        //if( class_exists( 'AudioShortcode' ) && method_exists( 'AudioShortcode', 'audio_shortcode' ) ) {
     124        //if ( function_exists('Jetpack::get_active_modules') ) {
     125        if( in_array("shortcodes", Jetpack::get_active_modules()) ) {
     126       
    98127        // these will store location, and artist and title info for the player
    99128        $urls = $titles = $artists = array();
     129        $pidset = false;
    100130       
    101         // prepares attributes to be passed in the way [audio] wants them
     131       
     132        // from what post/page are we getting the attachments? -- pid att
     133        if ( isset($atts['pid']) ) {
     134            $pidset = true;
     135            $pid = $atts['pid'];
     136            unset( $atts['pid'] );
     137            $pid  = ( is_numeric($pid) ? $pid : url_to_postid($pid) );
     138           
     139           
     140        }
     141       
     142        else {
     143            $pid = get_the_ID();
     144        }
     145       
     146        // prepares attributes to be passed in the way [audio] wants them. To do: filter atts?
    102147        $results = array_implode('=',"|", $atts);
    103148       
    104         // gets all the audio attachments. To do: only return mp3s
     149        // gets all the audio attachments.
    105150        $attachments = get_children( array(
    106         'post_parent'    => get_the_ID(),
     151        'post_parent'    => $pid,
    107152        'post_type'      => 'attachment',
    108153        'numberposts'    => -1, // show all -1
    109154        'post_status'    => 'inherit',
    110         'post_mime_type' => 'audio',
     155        'post_mime_type' => 'audio/mpeg,',
    111156        'order'          => 'ASC',
    112157        'orderby'        => 'menu_order ASC'
    113158        ) );
    114159       
     160        $attachments = array_filter($attachments, "is_mp3"); // only mp3s can be used in playlists. filter out other audio (mime won't get this all right)
     161       
     162        if ($attachments) {
     163       
    115164        // push all the data in to the arryas
    116165        foreach ( $attachments as $attachment_id => $attachment ) {
     166       
    117167            array_push($urls, wp_get_attachment_url( $attachment_id )); // url of each mp3
    118168            array_push($titles, get_the_title($attachment_id)); // gets the title of the mp3. This is the literal title in the media library
     
    130180        $shortcode = '<!-- audio shortcode is [audio '.$comma_separated_urls.'|titles='.$comma_separated_titles.'|artists='.$comma_separated_artists.'|'.$results.'] -->';
    131181        return $playlist.PHP_EOL.$shortcode;
     182        }
     183       
     184        else {
     185        $jep_error_msg = "Sorry pal, no mp3s found for your playlist. ";
     186        if ($pidset) {$jep_error_msg .=" Check your page/post id?";}
     187        return "<p><strong style='color:red'>".$jep_error_msg."</strong></p>";
     188        }
     189       
    132190    }
    133191    else {
    134         return "<p><strong style='color:red'>Whoops, your playlist won't work without Jetpack!</strong></p>";
     192        return "<p><strong style='color:red'>Whoops, your playlist won't work without Jetpack's shortcode functionality!</strong></p>";
    135193    }
    136194}?>
  • jetpack-easy-playlists/trunk/readme.txt

    r565420 r566171  
    55Requires at least: 3.4
    66Tested up to: 3.4.1
    7 Stable tag: 2.1
     7Stable tag: 2.2
    88
    99Generate playlists automatically from mp3s attached to your post/page. Requires Jetpack.
     
    1111== Description ==
    1212
    13 
    1413Audio support in Wordpress makes me cry. No native player, the fields in the Media library seem wrong for audio, and let's not get into ID3 tag reading. The audio shortcode and player provided by Jetpack is a step in the right direction. However, the ability to directly create a player or playlist on a post/page from attached mp3s makes me sad again. Writing that shortcode is nasty business for anything beyond a file or two.
    1514
    16 And what about the [gallery] shortcode for images? So easy to round up all your attached pictures and display them all automagically. Why no love for audio?
     15And what about the [gallery] shortcode for images? So easy to round up all your attached pictures and display them all automagically. Why no love for [audio[?
    1716
    18 This plugin acts as a wrapper for Jetpack's [audio] shortcode. It rounds up all the mp3s attached to your post/page and adds them as a playlist in the Jetpack player. Simply attach your mp3s to your post/page and use the shortcode "[jplaylist]" where you want your playlist.
     17This plugin acts as a wrapper for Jetpack's [audio] shortcode. It rounds up all the mp3s attached to your post/page and adds them as a playlist in the Jetpack player. Simply attach your mp3s to your post/page and use the shortcode "[jplaylist]" where you want your playlist
     18
     19JEP supports all the options that [audio] does, and now allows you to call up attachments from other pages/posts.
    1920
    2021Requires [Jetpack](http://jetpack.me/).
    2122
    2223[Plugin Homepage](http://www.jamesfishwick.com/software/auto-jetpack-playlist/)
    23 
    24 **Updated to fix "unexpected $end" bug and to work with 3.4.
    2524
    2625
     
    5857[jplaylist bgcolor=000000|lefticon=00ff00|righticon=FF0000|animation=no|loop=yes]
    5958
     59= Can I use attachments from a different page/post? =
     60
     61Sure. You use the "pid" attribute with a post/page id or permalink slug.
     62
     63Examples:
     64
     65[jplaylist pid="173"]
     66[jplaylist pid="software/jetpack-easy-playlists/"]
     67
     68[More details](http://jamesfishwick.com/2012/jetpack-easy-playlists-update/)
     69
    6070= Can you support my favorite player WordPess player plugin xyz? =
    6171
     
    6777
    6878== Changelog ==
     79
     80= 2.2 =
     81* More robust check for Jetpack and shortcodes module to avoid future bugs ala http://jamesfishwick.com/2012/jetpack-easy-playlists-update/
     82* Filters out non-mp3 audio files
     83* You can call playlists from other posts with the "pid" attribute
     84* Smarter error messages
     85
     86= 2.1 =
     87* Cleaned up code and properly updated readme
    6988 
    7089= 2.0 =
Note: See TracChangeset for help on using the changeset viewer.