Example #1
0
/**
 * Stream a whole release as xspf or m3u.
 *
 * @return void
 * @param string $release_slug The slug of the release to stream
 * @param string $stream_format The format of the streaming, either xspf or m3u
 **/
function stream_release($release_slug, $stream_format)
{
    global $wp_query, $release, $artist;
    global $tracks, $track, $current_track;
    if (empty($release_slug)) {
        return new WP_Error('ribcage-no-release-to-stream', __("You didn't specify a release to stream."));
        ribcage_404();
    }
    $release = get_release_by_slug($release_slug, TRUE, FALSE);
    if (is_wp_error($release)) {
        ribcage_404();
    }
    $artist['artist_name'] = get_artistname_by_id($release['release_artist']);
    if (is_wp_error($artist)) {
        ribcage_404();
    }
    $tracks = $release['release_tracks'];
    $track = $tracks[$current_track];
    if (is_wp_error($release)) {
        ribcage_404();
    }
    if ($stream_format == 'xspf') {
        $load = ribcage_load_template('./stream/xspf.php');
    } elseif ($stream_format == 'm3u') {
        $load = ribcage_load_template('stream/m3u.php');
    }
    if (is_wp_error($load)) {
        return $load;
    }
}
Example #2
0
function ribcage_donate_download_thanks()
{
    global $release, $artist, $wp_query;
    $release = get_release_by_slug($wp_query->query_vars['release_slug'], FALSE, FALSE);
    $artist = get_artist($release['release_artist']);
    $load = ribcage_load_template('download-thanks.php');
}
Example #3
0
/**
 * Displays thank you message to the user returning from PayPal
 *
 * @author Alex Andrews <*****@*****.**>
 * @return void
 */
function ribcage_donate_download_thanks()
{
    global $release, $artist, $wp_query;
    $release = get_release_by_slug($wp_query->query_vars['release_slug'], FALSE, FALSE);
    if (is_wp_error($release)) {
        ribcage_404();
    }
    $artist = get_artist($release['release_artist']);
    if (is_wp_error($artist)) {
        ribcage_404();
    }
    if ($release["release_slug"] === 'christmas-koto') {
        $load = ribcage_load_template('download-thanks-koto.php');
    } else {
        $load = ribcage_load_template('download-thanks.php');
    }
}
Example #4
0
/**
 * Runs the whole of Ribcage.
 * A filter on the template that tries to find out if we are on a Ribcage page and responds accordingly.
 *
 * @author Alex Andrews <*****@*****.**>
 * @return void
 */
function ribcage_init()
{
    global $wp_query;
    global $artists, $artist, $current_artist;
    global $releases, $release, $current_release;
    global $tracks, $track, $current_track;
    global $reviews, $review, $current_review;
    global $product;
    wp_enqueue_script('ribcage-player-popup', plugins_url('js/player.js', __FILE__), null, '3.0');
    // Add our streams.
    add_filter('wp_head', 'ribcage_release_feeds');
    if (is_ribcage_page() == 0) {
        return;
    }
    $GLOBALS['ribcage_page'] = TRUE;
    // Add our bits to the page title in the header ans elsewhere.
    add_filter('wp_title', 'ribcage_page_title', 10, 3);
    // Donate IPN from Paypal
    if (isset($wp_query->query_vars['ribcage_donate_ipn'])) {
        ribcage_donate_ipn();
    }
    // Artist Index
    if (isset($wp_query->query_vars['artist_index'])) {
        $artists = list_artists_blurb();
        $artist = $artists[$current_artist];
        $wp_query->query_vars['pagename'] = 'artists';
        $load = ribcage_load_template('artist-index.php');
    }
    // Individual Artist (including bio, contact et al)
    if (isset($wp_query->query_vars['artist_slug'])) {
        $artist = get_artist_by_slug($wp_query->query_vars['artist_slug']);
        if (is_wp_error($artist)) {
            ribcage_404();
        }
        $wp_query->query_vars['pagename'] = $wp_query->query_vars['artist_slug'];
        if (is_artist_page()) {
            switch ($wp_query->query_vars['artist_page']) {
                case 'press':
                    $releases = list_artist_releases($artist['artist_id'], TRUE);
                    $load = ribcage_load_template('press.php');
                    break;
                case 'bio':
                    $load = ribcage_load_template('bio.php');
                    break;
                case 'feed':
                    $releases = list_artist_releases($artist['artist_id']);
                    $load = ribcage_load_template('feeds/artist-rss2.php');
                    break;
                default:
                    $release = get_release_by_slug($wp_query->query_vars['artist_page']);
                    if (is_wp_error($release)) {
                        ribcage_404();
                    }
                    $tracks = $release['release_tracks'];
                    $reviews = $release['release_reviews'];
                    $load = ribcage_load_template('release.php');
            }
        } else {
            $releases = list_artist_releases($artist['artist_id']);
            $load = ribcage_load_template('artist.php');
        }
    }
    // Releases Index
    if (isset($wp_query->query_vars['release_index']) or isset($wp_query->query_vars['release_feed'])) {
        $releases = list_recent_releases_blurb();
        $artists = list_artists_blurb();
        $wp_query->query_vars['pagename'] = 'releases';
        if (isset($wp_query->query_vars['release_feed'])) {
            $load = ribcage_load_template('feeds/release-rss2.php');
        } else {
            $load = ribcage_load_template('release-index.php');
        }
    }
    // Downloads
    if (isset($wp_query->query_vars['ribcage_download'])) {
        // Download whole release.
        if (isset($wp_query->query_vars['release_slug']) && isset($wp_query->query_vars['format'])) {
            // Re-direct them to donate at Paypal
            if ($wp_query->query_vars['format'] == 'donate') {
                $release = get_release_by_slug($wp_query->query_vars['release_slug'], FALSE, FALSE);
                if (is_wp_error($release)) {
                    ribcage_404();
                }
                $artist = get_artist($release['release_artist']);
                if (is_wp_error($artist)) {
                    ribcage_404();
                }
                ribcage_donate();
            } else {
                if ($wp_query->query_vars['format'] == 'back') {
                    ribcage_donate_download_thanks();
                } else {
                    if ($wp_query->query_vars['format'] == 'skip') {
                        $release = get_release_by_slug($wp_query->query_vars['release_slug'], FALSE, FALSE);
                        if (is_wp_error($release)) {
                            ribcage_404();
                        }
                        $artist = get_artist($release['release_artist']);
                        if (is_wp_error($artist)) {
                            ribcage_404();
                        }
                        $load = ribcage_load_template('download.php');
                    } else {
                        $release = get_release_by_slug($wp_query->query_vars['release_slug'], FALSE, FALSE);
                        if (is_wp_error($release)) {
                            ribcage_404();
                        }
                        $artist = get_artist($release['release_artist']);
                        if (is_wp_error($artist)) {
                            ribcage_404();
                        }
                        $load = ribcage_load_template('post-download.php');
                    }
                }
            }
        } else {
            if (isset($wp_query->query_vars['track_slug'])) {
                $load = download_track($wp_query->query_vars['track_slug'], $wp_query->query_vars['format']);
            } else {
                if (isset($wp_query->query_vars['release_slug'])) {
                    $release = get_release_by_slug($wp_query->query_vars['release_slug'], FALSE, FALSE);
                    if (is_wp_error($release)) {
                        ribcage_404();
                    }
                    $artist = get_artist($release['release_artist']);
                    if (is_wp_error($artist)) {
                        ribcage_404();
                    }
                    // Special case for Matthew Jenning's Christmas Koto
                    if ($release["release_slug"] === 'christmas-koto') {
                        $load = ribcage_load_template('koto-nag.php');
                        die;
                    }
                    // If we haven't seen the user before, then nag them about the download.
                    if (!isset($_COOKIE["ask_donate"])) {
                        setcookie("ask_donate", "1", time() + 3600);
                        $load = ribcage_load_template('nag.php');
                    } else {
                        if (isset($_COOKIE["ask_donate"])) {
                            $random = rand(1, 8);
                            if ($random == 5) {
                                $load = ribcage_load_template('nag.php');
                            } else {
                                $load = ribcage_load_template('download.php');
                            }
                        }
                    }
                    // If the user has just got back from Paypal congratulate them on their brillance and given them
                    // the download. Maybe lower the chance of a nag?
                }
            }
        }
    }
    // Streams
    if (isset($wp_query->query_vars['ribcage_stream'])) {
        // Stream whole release.
        if (isset($wp_query->query_vars['release_slug'])) {
            $load = stream_release($wp_query->query_vars['release_slug'], $wp_query->query_vars['stream_format']);
        }
        // Stream individual track.
        if (isset($wp_query->query_vars['track_slug'])) {
            $load = stream_track($wp_query->query_vars['track_slug']);
        }
    }
    if (isset($wp_query->query_vars['ribcage_player'])) {
        if ($wp_query->query_vars['release_slug'] == 'stats') {
            ribcage_log_play();
        } else {
            $load = show_player($wp_query->query_vars['release_slug']);
        }
    }
    // Purchases
    if (isset($wp_query->query_vars['ribcage_buy']) && isset($wp_query->query_vars['ribcage_product_id'])) {
        // Lookup the item they are looking for in the database.
        $product = get_product($wp_query->query_vars['ribcage_product_id']);
        if (is_wp_error($product)) {
            ribcage_404();
        }
        // Some products are associated with releases, some are not.
        if (isset($product['product_related_release'])) {
            $release = get_release($product['product_related_release']);
            $artist = get_artist($release['release_artist']);
        }
        // Set this so the feeds at the bottom of the page show up for the artist.
        $wp_query->query_vars['artist_slug'] = true;
        if (isset($wp_query->query_vars['ribcage_buy_mode'])) {
            switch ($wp_query->query_vars['ribcage_buy_mode']) {
                // Send them to Paypal
                case 'go-ww':
                case 'go-uk':
                    ribcage_buy_process();
                    break;
                    // They just got back from Paypal and it was a success. Thank them for it.
                // They just got back from Paypal and it was a success. Thank them for it.
                case 'thanks':
                    $load = ribcage_load_template('thanks.php');
                    break;
                    // We are recieving an IPN ping from Paypal.
                // We are recieving an IPN ping from Paypal.
                case 'ipn':
                    ribcage_buy_ipn();
                    break;
                    // They cancelled.
                // They cancelled.
                case 'cancel':
                    echo "Cancelled";
                    break;
            }
        } else {
            $load = ribcage_load_template('buy.php');
        }
    }
    // Did we get an error by the end of all this? If so let the user know.
    if (is_wp_error($load)) {
        echo $load->get_error_message();
    }
    // Don't output anything else.
    die;
}
Example #5
0
 /**
  * Loads a Ribcage template for redirection. Adapted from original element of paypal.class
  *
  * @author Alex Andrews <*****@*****.**>
  * @return void
  */
 function submit_paypal_post()
 {
     $load = ribcage_load_template('paypal-redirect.php');
     if (is_wp_error($load)) {
         echo "We got an error loading up the template";
     }
 }
Example #6
0
/**
 * Returns a completed e-mail template for various applications.
 *
 * @author Alex Andrews <*****@*****.**>
 * @param string $filename Filename of the template below the ribcage-includes/email.
 * @return string The completed template.
 */
function ribcage_load_email_template($filename)
{
    ob_start();
    $load = ribcage_load_template('email/$filename.php');
    return ob_get_clean();
}