Example #1
0
function gigpress_show_related($content)
{
    global $is_excerpt, $wpdb, $gpo, $post;
    if ($is_excerpt == TRUE || !is_object($post)) {
        $is_excerpt = FALSE;
        return $content;
    } else {
        $shows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS . " AS s LEFT JOIN  " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE show_related = %d AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id ORDER BY show_date ASC,show_time ASC", $post->ID));
        if ($shows != FALSE) {
            ob_start();
            $count = 1;
            $total_shows = count($shows);
            foreach ($shows as $show) {
                $showdata = gigpress_prepare($show, 'related');
                include gigpress_template('related');
                $count++;
            }
            $giginfo = ob_get_clean();
            if ($gpo['related_position'] == "before") {
                $output = $giginfo . $content;
            } else {
                $output = $content . $giginfo;
            }
            return $output;
        } else {
            return $content;
        }
    }
}
function gigpress_show_related($args = array(), $content = '')
{
    global $is_excerpt, $wpdb, $gpo, $post;
    if ($is_excerpt == TRUE || !is_object($post)) {
        $is_excerpt = FALSE;
        return $content;
    } else {
        extract(shortcode_atts(array('scope' => 'all', 'sort' => 'asc'), $args));
        // Date conditionals based on scope
        switch ($scope) {
            case 'upcoming':
                $date_condition = ">= '" . GIGPRESS_NOW . "'";
                break;
            case 'past':
                $date_condition = "< '" . GIGPRESS_NOW . "'";
                break;
            case 'all':
                $date_condition = "!= ''";
        }
        $shows = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS . " AS s LEFT JOIN  " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE show_related = %d AND show_expire " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id ORDER BY show_date " . $sort . ",show_expire " . $sort . ",show_time " . $sort, $post->ID));
        if ($shows != FALSE) {
            ob_start();
            $count = 1;
            $total_shows = count($shows);
            foreach ($shows as $show) {
                $showdata = gigpress_prepare($show, 'related');
                include gigpress_template('related');
                $count++;
            }
            $giginfo = ob_get_clean();
            if ($gpo['related_position'] == "before") {
                $output = $giginfo . $content;
            } else {
                $output = $content . $giginfo;
            }
            return $output;
        } else {
            return $content;
        }
    }
}
Example #3
0
function gigpress_sidebar($filter = null)
{
    global $wpdb, $gpo;
    $further_where = $orderby = '';
    // Variables we need for conditionals
    // Check total number of artists
    $total_artists = $wpdb->get_var("SELECT count(*) from " . GIGPRESS_ARTISTS);
    // Check for sorting
    if (isset($filter['sort'])) {
        $sort = $filter['sort'];
    }
    // Scope
    switch ($filter['scope']) {
        case 'today':
            $date_condition = "show_expire >= '" . GIGPRESS_NOW . "' AND show_date <= '" . GIGPRESS_NOW . "'";
            if (!isset($sort)) {
                $sort = 'asc';
            }
            break;
        case 'past':
            $date_condition = "show_expire < '" . GIGPRESS_NOW . "'";
            if (!isset($sort)) {
                $sort = 'desc';
            }
            break;
        case 'all':
            $date_condition = "show_date != ''";
            if (!isset($sort)) {
                $sort = 'desc';
            }
            break;
        default:
            $date_condition = "show_expire >= '" . GIGPRESS_NOW . "'";
    }
    // Number of shows to list (per artist if grouping by artist)
    $limit = isset($filter['limit']) && is_numeric($filter['limit']) ? $wpdb->prepare('%d', $filter['limit']) : 5;
    // Whether or not to display tour grouings
    $show_tours = isset($filter['show_tours']) && $filter['show_tours'] == 'yes' ? 'yes' : FALSE;
    // Whether or not to group artists
    $group_artists = isset($filter['group_artists']) && $filter['group_artists'] == 'yes' ? 'yes' : FALSE;
    // Order in which to display artists if grouping
    $artist_order = isset($filter['artist_order']) && $filter['artist_order'] == 'custom' ? 'custom' : 'alphabetical';
    // Filtering by artist, tour, or venue?
    $artist = isset($filter['artist']) ? $filter['artist'] : FALSE;
    $tour = isset($filter['tour']) ? $filter['tour'] : FALSE;
    $venue = isset($filter['venue']) ? $filter['venue'] : FALSE;
    // Display feed links and link to more shows?
    $show_feeds = isset($filter['show_feeds']) && $filter['show_feeds'] == 'yes' ? 'yes' : FALSE;
    $link = isset($filter['link_text']) && !empty($gpo['shows_page']) ? wptexturize($filter['link_text']) : FALSE;
    // Establish the variable parts of the query
    if ($artist) {
        $further_where .= ' AND show_artist_id IN(' . $wpdb->prepare('%s', $artist) . ')';
    }
    if ($tour) {
        $further_where .= ' AND show_tour_id IN(' . $wpdb->prepare('%s', $tour) . ')';
    }
    if ($venue) {
        $further_where .= ' AND show_venue_id IN(' . $wpdb->prepare('%s', $venue) . ')';
    }
    if ($group_artists) {
        $orderby = 'a.artist_name ASC,';
    }
    $artist_order = $artist_order == 'custom' ? "artist_order ASC," : '';
    ob_start();
    // If we're grouping by artist, we'll unfortunately have to first get all artists
    // Then  make a query for each one. Looking for a better way to do this.
    if ($group_artists && !$tour && !$artist && !$venue && $total_artists > 1) {
        $artists = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " ORDER BY " . $artist_order . "artist_name ASC");
        foreach ($artists as $artist_group) {
            $shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS . " AS s LEFT JOIN  " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = " . $artist_group->artist_id . " AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_time " . $sort . " LIMIT " . $limit);
            if ($shows) {
                // For each artist group
                $some_results = TRUE;
                $current_tour = '';
                $i = 0;
                // Data for artist heading
                $showdata = array('artist' => wptexturize($artist_group->artist_name), 'artist_id' => $artist_group->artist_id);
                include gigpress_template('sidebar-artist-heading');
                include gigpress_template('sidebar-list-start');
                foreach ($shows as $show) {
                    // For each individual show
                    $showdata = gigpress_prepare($show, 'public');
                    // Close the previous tour if needed
                    if ($show_tours && $current_tour && $showdata['tour'] != $current_tour) {
                        include gigpress_template('sidebar-tour-end');
                    }
                    // Open the current tour if needed
                    if ($show_tours && $showdata['tour'] && $showdata['tour'] != $current_tour && !$tour) {
                        $current_tour = $showdata['tour'];
                        include gigpress_template('sidebar-tour-heading');
                    }
                    // Zero-out $current_tour
                    if (empty($showdata['tour'])) {
                        $current_tour = '';
                    }
                    // Prepare the class
                    $class = $i % 2 ? 'gigpress-alt ' : '';
                    $i++;
                    $class .= $showdata['tour'] && $show_tours ? 'gigpress-tour ' . $showdata['status'] : $showdata['status'];
                    // Display the show
                    include gigpress_template('sidebar-list');
                }
                // Close the current tour if needed
                if ($show_tours && $current_tour) {
                    include gigpress_template('sidebar-tour-end');
                }
                // Close the list
                include gigpress_template('sidebar-list-end');
            }
        }
        if ($some_results) {
            // After all artist groups
            // Display the list footer
            include gigpress_template('sidebar-list-footer');
        } else {
            // No shows from any artist
            include gigpress_template('sidebar-list-empty');
        }
    } else {
        // Not grouping by artists
        $shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS . " AS s LEFT JOIN  " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_time " . $sort . " LIMIT " . $limit);
        if ($shows) {
            $current_tour = '';
            $i = 0;
            include gigpress_template('sidebar-list-start');
            foreach ($shows as $show) {
                // For each individual show
                $showdata = gigpress_prepare($show, 'public');
                // Close the previous tour if needed
                if ($show_tours && $current_tour && $showdata['tour'] != $current_tour && !$tour) {
                    include gigpress_template('sidebar-tour-end');
                }
                // Open the current tour if needed
                if ($show_tours && $showdata['tour'] && $showdata['tour'] != $current_tour && !$tour) {
                    $current_tour = $showdata['tour'];
                    include gigpress_template('sidebar-tour-heading');
                }
                if (!$showdata['tour']) {
                    $current_tour = '';
                }
                // Prepare the class
                $class = $i % 2 ? 'gigpress-alt ' : '';
                $i++;
                $class .= $showdata['tour'] && $show_tours ? 'gigpress-tour ' . $showdata['status'] : $showdata['status'];
                // Display the show
                include gigpress_template('sidebar-list');
            }
            // Close the current tour if needed
            if ($show_tours && $current_tour && !$tour) {
                include gigpress_template('sidebar-tour-end');
            }
            // Close the list
            include gigpress_template('sidebar-list-end');
            // Display the list footer
            include gigpress_template('sidebar-list-footer');
        } else {
            // No shows from any artist
            include gigpress_template('sidebar-list-empty');
        }
    }
    echo '<!-- Generated by GigPress ' . GIGPRESS_VERSION . ' -->
	';
    return ob_get_clean();
}
function gigpress_shows($filter = null, $content = null)
{
    global $wpdb, $gpo;
    $further_where = $limit = '';
    extract(shortcode_atts(array('tour' => FALSE, 'artist' => FALSE, 'venue' => FALSE, 'limit' => FALSE, 'scope' => 'upcoming', 'sort' => FALSE, 'group_artists' => 'yes', 'artist_order' => 'custom', 'show_menu' => FALSE, 'show_menu_count' => FALSE, 'menu_sort' => FALSE, 'menu_title' => FALSE, 'year' => FALSE, 'month' => FALSE), $filter));
    $total_artists = $wpdb->get_var("SELECT count(*) from " . GIGPRESS_ARTISTS);
    // Date conditionals and sorting based on scope
    switch ($scope) {
        case 'upcoming':
            $date_condition = "show_expire >= '" . GIGPRESS_NOW . "'";
            if (empty($sort)) {
                $sort = 'asc';
            }
            break;
        case 'past':
            $date_condition = "show_expire < '" . GIGPRESS_NOW . "'";
            if (empty($sort)) {
                $sort = 'desc';
            }
            break;
        case 'today':
            $date_condition = "show_expire >= '" . GIGPRESS_NOW . "' AND show_date <= '" . GIGPRESS_NOW . "'";
            if (empty($sort)) {
                $sort = 'asc';
            }
            break;
        case 'all':
            $date_condition = "show_expire != ''";
            if (empty($sort)) {
                $sort = 'desc';
            }
            break;
    }
    // Artist, tour and venue filtering
    if ($artist) {
        $further_where .= ' AND show_artist_id = ' . $wpdb->prepare('%d', $artist);
    }
    if ($tour) {
        $further_where .= ' AND show_tour_id = ' . $wpdb->prepare('%d', $tour);
    }
    if ($venue) {
        $further_where .= ' AND show_venue_id = ' . $wpdb->prepare('%d', $venue);
    }
    // Date filtering
    // Query vars take precedence over function vars
    if (isset($_REQUEST['gpy'])) {
        $year = $_REQUEST['gpy'];
        if (isset($_REQUEST['gpm'])) {
            $month = $_REQUEST['gpm'];
        } else {
            unset($month);
        }
        $no_limit = TRUE;
    }
    // Validate year and date parameters
    if ($year || $month) {
        if ($year) {
            if (is_numeric($year) && strlen($year) == 4) {
                $year = round($year);
            } else {
                $year = date('Y', current_time('timestamp'));
            }
        } else {
            // We've only specified a month, so we'll assume the year is current
            $year = date('Y', current_time('timestamp'));
        }
        if ($month) {
            if ($month == 'current') {
                $month = date('m', current_time('timestamp'));
            } elseif (round($month) == 0) {
                // Probably using a month name
                $month = date('m', strtotime($month));
            } elseif (round($month) < 10) {
                // Make sure the month is padded through 09
                $month = str_pad($month, 2, 0, STR_PAD_LEFT);
            } elseif (round($month) < 13) {
                // Between 10 and 12 we're OK
                $month = $month;
            } else {
                // Bogus month value (not a string and > 12)
                // Sorry, bailing out. Your "month" will be ignored. Dink.
                $month = FALSE;
            }
            $start_month = $end_month = $month;
        }
        if (!$month) {
            $start_month = '01';
            $end_month = '12';
        }
        $start = $year . '-' . $start_month . '-01';
        $end = $year . '-' . $end_month . '-31';
        $further_where .= ' AND show_date BETWEEN ' . $wpdb->prepare('%s', $start) . ' AND ' . $wpdb->prepare('%s', $end);
    }
    $limit = $limit && !$no_limit ? ' LIMIT ' . $wpdb->prepare('%d', $limit) : '';
    $artist_order = $artist_order == 'custom' ? "artist_order ASC," : '';
    // With the new 'all' scope, we should probably have a third message option, but I'm too lazy
    // Really, there should just be one generic 'no shows' message. Oh well.
    $no_results_message = $scope == 'upcoming' ? wptexturize($gpo['noupcoming']) : wptexturize($gpo['nopast']);
    ob_start();
    // Are we showing our menu?
    if ($show_menu) {
        $menu_options = array();
        $menu_options['scope'] = $scope;
        $menu_options['type'] = $show_menu;
        if ($menu_title) {
            $menu_options['title'] = $menu_title;
        }
        if ($show_menu_count) {
            $menu_options['show_count'] = $show_menu_count;
        }
        if ($menu_sort) {
            $menu_options['sort'] = $menu_sort;
        }
        if ($artist) {
            $menu_options['artist'] = $artist;
        }
        if ($tour) {
            $menu_options['tour'] = $tour;
        }
        if ($venue) {
            $menu_options['venue'] = $venue;
        }
        include gigpress_template('before-menu');
        echo gigpress_menu($menu_options);
        include gigpress_template('after-menu');
    }
    // If we're grouping by artist, we'll unfortunately have to first get all artists
    // Then  make a query for each one. Looking for a better way to do this.
    if ($group_artists == 'yes' && !$artist && $total_artists > 1) {
        $artists = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " ORDER BY " . $artist_order . "artist_name ASC");
        foreach ($artists as $artist_group) {
            $shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS . " AS s LEFT JOIN  " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = " . $artist_group->artist_id . " AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time " . $sort . $limit);
            if ($shows) {
                // For each artist group
                $some_results = TRUE;
                $current_tour = '';
                $i = 0;
                $showdata = array('artist' => wptexturize($artist_group->artist_name), 'artist_id' => $artist_group->artist_id);
                include gigpress_template('shows-artist-heading');
                include gigpress_template('shows-list-start');
                foreach ($shows as $show) {
                    // For each individual show
                    $showdata = gigpress_prepare($show, 'public');
                    if ($showdata['tour'] && $showdata['tour'] != $current_tour && !$tour) {
                        $current_tour = $showdata['tour'];
                        include gigpress_template('shows-tour-heading');
                    }
                    $class = $showdata['status'];
                    ++$i;
                    $class .= $i % 2 ? '' : ' gigpress-alt';
                    if (!$showdata['tour'] && $current_tour) {
                        $current_tour = '';
                        $class .= ' divider';
                    }
                    $class .= $showdata['tour'] && !$tour ? ' gigpress-tour' : '';
                    include gigpress_template('shows-list');
                }
                include gigpress_template('shows-list-end');
            }
        }
        if ($some_results) {
            // After all artist groups
            include gigpress_template('shows-list-footer');
        } else {
            // No shows from any artist
            include gigpress_template('shows-list-empty');
        }
    } else {
        // Not grouping by artists
        $shows = $wpdb->get_results("\n\t\t\tSELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS . " AS s LEFT JOIN  " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . " ORDER BY s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time " . $sort . $limit);
        if ($shows) {
            $current_tour = '';
            $i = 0;
            include gigpress_template('shows-list-start');
            foreach ($shows as $show) {
                // For each individual show
                $showdata = gigpress_prepare($show, 'public');
                if ($showdata['tour'] && $showdata['tour'] != $current_tour && !$tour) {
                    $current_tour = $showdata['tour'];
                    include gigpress_template('shows-tour-heading');
                }
                $class = $showdata['status'];
                ++$i;
                $class .= $i % 2 ? '' : ' gigpress-alt';
                if (!$showdata['tour'] && $current_tour) {
                    $current_tour = '';
                    $class .= ' divider';
                }
                $class .= $showdata['tour'] && !$tour ? ' gigpress-tour' : '';
                include gigpress_template('shows-list');
            }
            include gigpress_template('shows-list-end');
            include gigpress_template('shows-list-footer');
        } else {
            // No shows to display
            include gigpress_template('shows-list-empty');
        }
    }
    echo '<!-- Generated by GigPress ' . GIGPRESS_VERSION . ' -->
	';
    return ob_get_clean();
}