Пример #1
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;
}
Пример #2
0
/download/<?php 
    release_slug();
    ?>
/" title="Free Download">Download</a></li>
					<li class="last buy disabled"><span class="buy">Buy</span></li>
				<?php 
}
?>
			</ul>
		<div class="clear"></div>
		</div> <!-- end div.artist_slug_info -->
	</div>
	<?php 
if (isset($wp_query->query_vars['artist_slug'])) {
    global $releases, $artist, $release;
    $releases = list_artist_releases($artist['artist_id']);
    foreach ($releases as $r => $value) {
        if (strcmp($release['release_title'], $value['release_title']) === 0) {
            unset($releases[$r]);
        }
    }
    ?>
 		<?php 
    if (count($releases) > 0) {
        ?>
 		<div class="mod">
 			<h3>Also by <?php 
        artist_name();
        ?>
</h3>
 			<ul class="albums-list">