/** * 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; }
/** * Manages products - adds, edits, deletes products. * * @return void */ function ribcage_manage_products() { global $wpdb; global $products, $product; global $releases, $release; global $artist; // Security check if (isset($_REQUEST['_wpnonce'])) { if (wp_verify_nonce($nonce, 'ribcage_manage_releases')) { die("Security check failed."); } } $nonce = wp_create_nonce('ribcage_manage_products'); if (isset($_REQUEST['ribcage_action']) && $_REQUEST['ribcage_action']) { array_pop($_POST); $post_keys = array_keys($_POST); $post_vals = array_values($_POST); $string_keys = implode($post_keys, ","); $string_vals = "'" . implode($post_vals, "','") . "'"; $wpdb->show_errors(); switch ($_REQUEST['ribcage_action']) { case 'add': // Do we have all the fields we need to add something? if ($_POST['product_name'] == null) { $product = $_POST; ribcage_edit_product_form('Sorry you missed the name of your product.'); return; } elseif ($_POST['product_cost'] == null) { $product = $_POST; ribcage_edit_product_form("Sorry you didn't set a cost for your product."); return; } elseif ($_POST['product_description'] == null) { $product = $_POST; ribcage_edit_product_form("Sorry you didn't write a description for your product."); return; } elseif (!is_numeric($_POST['product_cost'])) { $product = $_POST; ribcage_edit_product_form("Sorry but that isn't a number for the cost of the product."); return; } // Do we already have a physical product for this release? if ($_POST['product_related_release']) { $sql = "SELECT release_physical FROM " . $wpdb->releases . " WHERE release_id = " . $_POST['product_related_release']; $check = $wpdb->get_row($sql, ARRAY_A); if ($check['release_physical'] == 1) { $product = $_POST; ribcage_edit_product_form("Sorry but that release already has a physical product associated with it."); return; } } $sql = "INSERT INTO " . $wpdb->products . "\n\t\t\t\t\t\t({$string_keys})\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$string_vals})"; $results = $wpdb->query($sql); $wpdb->hide_errors(); // Update our _ribcage_releases data with the correct details if we are relating this to a release. if ($_POST['product_related_release']) { $sql = "SELECT product_id FROM " . $wpdb->products . " ORDER BY product_id DESC LIMIT 0,1"; $product = $wpdb->get_row($sql, ARRAY_A); $sql = "UPDATE " . $wpdb->releases . " SET release_physical = 1, release_physical_cat_no ='" . $product['product_id'] . "' WHERE release_id = " . $_POST['product_related_release']; $results = $wpdb->query($sql); } $message = ' added'; break; case 'edit': ribcage_edit_product_form(); return; break; case 'edited': // Do we have all the fields we need to add something? if ($_POST['product_name'] == null) { $product = $_POST; ribcage_edit_product_form('Sorry you missed the name of your product.'); return; } elseif ($_POST['product_cost'] == null) { $product = $_POST; ribcage_edit_product_form("Sorry you didn't set a price for your product."); return; } elseif ($_POST['product_description'] == null) { $product = $_POST; ribcage_edit_product_form("Sorry you didn't set a price for your product."); return; } elseif (!is_numeric($_POST['product_cost'])) { $product = $_POST; ribcage_edit_product_form("Sorry but that isn't a number for the cost of the product."); return; } $product_before = get_product($_REQUEST['product']); $sql = "UPDATE " . $wpdb->prefix . "ribcage_products\n\t\t\t\t\t\tSET "; $i = 0; foreach ($post_keys as $field) { $sql .= $field . "='" . $post_vals[$i] . "', "; $i++; } $sql .= " product_id = " . $_REQUEST['product'] . " \n\t\t\t\t\t\tWHERE product_id = " . $_REQUEST['product']; $results = $wpdb->query($sql); $wpdb->hide_errors(); // Update our _ribcage_releases data if we have changed the associated product. if ($product_before['product_related_release'] != $_REQUEST['product_related_release']) { // Delete it from our previous holder of the release. $sql = "UPDATE " . $wpdb->prefix . "ribcage_releases SET release_physical = 0, release_physical_cat_no = 0 WHERE release_id = " . $product_before['product_related_release']; $results = $wpdb->query($sql); // Add it to the current holder of the release. $sql = "UPDATE " . $wpdb->prefix . "ribcage_releases SET release_physical = 1, release_physical_cat_no ='" . $_REQUEST['product'] . "' WHERE release_id = " . $_POST['product_related_release']; $results = $wpdb->query($sql); } $message = ' updated'; break; case 'delete': $product_before = get_product($_REQUEST['product']); delete_product($_REQUEST['product']); $sql = "UPDATE " . $wpdb->prefix . "ribcage_releases SET release_physical = 0, release_physical_cat_no = 0 WHERE release_id = " . $product_before['product_related_release']; $results = $wpdb->query($sql); $message = " deleted"; break; } if (isset($message)) { echo '<div id="message" class="updated fade"><p><strong>Product ' . $message . '.</strong></p></div>'; } } register_column_headers('ribcage-manage-products', array('cb' => '<input type="checkbox" />', 'product_name' => 'Product', 'local_downloads' => 'Related To Release')); $products = list_products(); ?> <div class="wrap"> <div id="icon-plugins" class="icon32"><br /></div> <h2>Manage Products</h2> <form action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?> " method="post" id="ribcage_manage_products" name="manage_artists"> <table class="widefat post fixed" cellspacing="0"> <thead> <tr> <?php print_column_headers('ribcage-manage-products'); ?> </tr> </thead> <tfoot> <tr> <?php print_column_headers('ribcage-manage-products', FALSE); ?> </tr> </tfoot> <tbody> <?php while (have_products()) { the_product(); ?> <?php $release = get_release($product['product_related_release']); ?> <?php $artist['artist_name'] = get_artistname_by_id($release['release_artist']); ?> <?php echo $alt % 2 ? '<tr valign="top" class="">' : '<tr valign="top" class="alternate">'; ++$alt; ?> <th scope="row" class="check-column"><input type="checkbox" name="productcheck[]" value="2" /></th> <td class="column-name"><strong><a class="row-title" href="?page=manage_products&ribcage_action=edit&product=<?php product_id(); ?> &_wpnonce=<?php echo $nonce; ?> " title="<?php product_name(); ?> " ><?php product_name(); ?> </strong></a><br /><div class="row-actions"><span class='edit'><a href="?page=manage_products&ribcage_action=edit&product=<?php product_id(); ?> &_wpnonce=<?php echo $nonce; ?> ">Edit</a> | </span><span class='delete'><a class='submitdelete' href="?page=manage_products&ribcage_action=delete&product=<?php product_id(); ?> &_wpnonce=<?php echo $nonce; ?> " onclick="if ( confirm('You are about to delete the product \'<?php product_name(); ?> \'\n \'Cancel\' to stop, \'OK\' to delete.') ) { return true;}return false;">Delete</a></span></div></td> <?php if ($product['product_related_release']) { ?> <td class="column-name"><?php artist_name(); ?> - <?php release_title(); ?> </td> <?php } else { ?> <td class="column-name">None.</td> <?php } ?> </tr> <?php } ?> </tbody> </table> </form> </div> <?php }
/** * Add a review of a specific release. * * @return void */ function ribcage_manage_reviews() { global $releases, $release, $artist, $tracks, $track; $release = get_release($_REQUEST['release'], false, true); $reviews = $release['release_reviews']; $artist['artist_name'] = get_artistname_by_id($release['release_artist']); ?> <div class="wrap"> <h2>Manage Reviews of <?php artist_name(); ?> - <?php release_title(); ?> </h2> <?php if (count($reviews) == 0) { echo "<p>No reviews yet. Why not add one now?</p>"; } else { register_column_headers('ribcage-manage-reviews', array('cb' => '<input type="checkbox" />', 'review_' => 'Reviewer')); echo "<pre>" . print_r($reviews) . "</pre>"; } ?> <h3>Add a review</h3> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="review_url">Review URL</label></th> <td><input type="text" name="review_url" value="" class="regular-text code"/><span class="description">The URL of the review, if the review is online.</span> </td> </tr> <tr valign="top"> <th scope="row"><label for="review_url">Publication</label></th> <td><input type="text" name="review_url" value="" class="regular-text code"/><span class="description">The name of the publication that reviewed the release</span> </td> </tr> </table> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="Add Review" /> </p> </form> </div> <?php }
/** * Lists the releases of an artist specified by their artist_id * * @author Alex Andrews <*****@*****.**> * @param int $artist_id The artist ID of the artist you which to retrieve the releases of. * @param bool $forthcoming Should we include forthcoming releases (true), or simply those whose release date is passed (false)? * @return array Associative array with the details of the artist in it. */ function list_artist_releases($artist_id, $forthcoming = FALSE) { global $wpdb; if ($forthcoming == TRUE) { $releases = $wpdb->get_results("SELECT release_id FROM {$wpdb->ribcage_releases} WHERE release_artist = {$artist_id} ORDER BY release_id DESC", ARRAY_A); } else { $now_date = gmdate('Y-m-d'); $releases = $wpdb->get_results("SELECT release_id FROM {$wpdb->ribcage_releases} WHERE release_artist = {$artist_id} AND release_date <= '{$now_date}' ORDER BY release_id DESC", ARRAY_A); } if (isset($releases)) { foreach ($releases as $release) { $return[] = get_release($release['release_id']); } } return $return; }