コード例 #1
0
ファイル: gigpress_sidebar.php プロジェクト: alx/Tetalab
 function update($new_instance, $old_instance)
 {
     $instance = array();
     $allowed = array('title', 'limit', 'scope', 'show_tours', 'group_artists', 'artist_order', 'artist', 'tour', 'venue', 'show_feeds', 'link_text');
     foreach ($new_instance as $option => $value) {
         if (in_array($option, $allowed)) {
             if ($option == 'limit' && (!is_numeric($value) || $value === 0)) {
                 $instance['limit'] = 5;
             } else {
                 $instance[$option] = gigpress_db_in($value);
             }
         }
     }
     return $instance;
 }
コード例 #2
0
ファイル: handlers.php プロジェクト: Ashleyotero/oldest-old
function gigpress_import()
{
    // Deep breath
    global $wpdb, $gpo;
    // We've just uploaded a file to import
    check_admin_referer('gigpress-action');
    $upload = wp_upload_bits($_FILES['gp_import']['name'], null, file_get_contents($_FILES['gp_import']['tmp_name']));
    if (!$upload['error']) {
        // The file was uploaded, so let's try and parse the mofo
        require_once WP_PLUGIN_DIR . '/gigpress/lib/parsecsv.lib.php';
        // This is under MIT license, which ain't GNU, but was else is new? Don't tell on me!
        $csv = new parseCSV();
        $csv->parse($upload['file']);
        if ($csv->data) {
            // Looks like we parsed something
            $inserted = array();
            $skipped = array();
            $duplicates = array();
            foreach ($csv->data as $key => $show) {
                // Check to see if we have this artist
                $artist_exists = $wpdb->get_var("SELECT artist_id FROM " . GIGPRESS_ARTISTS . " WHERE artist_name = '" . mysql_real_escape_string($show['Artist']) . "'");
                if (!$artist_exists) {
                    // Can't find an artist with this name, so we'll have to create them
                    $new_artist = array('artist_name' => gigpress_db_in($show['Artist']));
                    $wpdb->insert(GIGPRESS_ARTISTS, $new_artist);
                    $show['artist_id'] = $wpdb->insert_id;
                } else {
                    $show['artist_id'] = $artist_exists;
                }
                if ($show['Tour']) {
                    // Check to see if we have this tour
                    $tour_exists = $wpdb->get_var("SELECT tour_id FROM " . GIGPRESS_TOURS . " WHERE tour_name = '" . mysql_real_escape_string($show['Tour']) . "' AND tour_status = 'active'");
                    if (!$tour_exists) {
                        // Can't find a tour with this name, so we'll have to create it
                        $order = $wpdb->get_var("SELECT count(*) FROM " . GIGPRESS_TOURS . " WHERE tour_status = 'active'");
                        $order++;
                        $new_tour = array('tour_name' => gigpress_db_in($show['Tour']));
                        $wpdb->insert(GIGPRESS_TOURS, $new_tour);
                        $show['tour_id'] = $wpdb->insert_id;
                    } else {
                        $show['tour_id'] = $tour_exists;
                    }
                }
                // Check to see if we have this venue
                $venue_exists = $wpdb->get_var("SELECT venue_id FROM " . GIGPRESS_VENUES . " WHERE venue_name = '" . mysql_real_escape_string($show['Venue']) . "' AND venue_city = '" . mysql_real_escape_string($show['City']) . "' AND venue_country = '" . mysql_real_escape_string($show['Country']) . "'");
                if (!$venue_exists) {
                    // Can't find a venue with this name, so we'll have to create it
                    $new_venue = array('venue_name' => gigpress_db_in($show['Venue']), 'venue_address' => gigpress_db_in($show['Address']), 'venue_city' => gigpress_db_in($show['City']), 'venue_country' => gigpress_db_in($show['Country']), 'venue_url' => gigpress_db_in($show['Venue URL']), 'venue_phone' => gigpress_db_in($show['Venue phone']));
                    $wpdb->insert(GIGPRESS_VENUES, $new_venue);
                    $show['venue_id'] = $wpdb->insert_id;
                } else {
                    $show['venue_id'] = $venue_exists;
                }
                if ($show['Time'] == FALSE) {
                    $show['Time'] = '00:00:01';
                }
                if ($wpdb->get_var("SELECT count(*) FROM " . GIGPRESS_SHOWS . " WHERE show_artist_id = " . $show['artist_id'] . " AND show_date = '" . $show['Date'] . "' AND show_time = '" . $show['Time'] . "' AND show_venue_id = " . $show['venue_id'] . " AND show_status != 'deleted'") > 0) {
                    // It's a duplicate, so log it and move on
                    $duplicates[] = $show;
                } else {
                    if ($show['End date'] == FALSE) {
                        $show['show_multi'] = 0;
                        $show['End date'] = $show['Date'];
                    } else {
                        $show['show_multi'] = 1;
                    }
                    $new_show = array('show_date' => $show['Date'], 'show_time' => $show['Time'], 'show_multi' => $show['show_multi'], 'show_expire' => $show['End date'], 'show_artist_id' => $show['artist_id'], 'show_venue_id' => $show['venue_id'], 'show_tour_id' => $show['tour_id'], 'show_ages' => gigpress_db_in($show['Admittance']), 'show_price' => gigpress_db_in($show['Price']), 'show_tix_url' => gigpress_db_in($show['Ticket URL']), 'show_tix_phone' => gigpress_db_in($show['Ticket phone']), 'show_notes' => gigpress_db_in($show['Notes'], FALSE), 'show_related' => '0');
                    // Are we importing related post IDs?
                    if (isset($_POST['include_related']) && ($_POST['include_related'] = 'y')) {
                        $new_show['show_related'] = $show['Related ID'];
                    }
                    $formats = array('%s', '%s', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d');
                    $import = $wpdb->insert(GIGPRESS_SHOWS, $new_show, $formats);
                    if ($import != FALSE) {
                        $inserted[] = $show;
                    } else {
                        $skipped[] = $show;
                    }
                }
            }
            // end foreach import
            if (!empty($skipped)) {
                echo '<h4 class="error">' . count($skipped) . ' ' . __("shows were skipped due to errors", "gigpress") . '.</h4>';
                echo '<ul class="ul-square">';
                foreach ($skipped as $key => $show) {
                    echo '<li>' . wptexturize($show['Artist']) . ' ' . __("in", "gigpress") . ' ' . wptexturize($show['City']) . ' ' . __("at", "gigpress") . ' ' . wptexturize($show['Venue']) . ' ' . __("on", "gigpress") . ' ' . mysql2date($gpo['date_format'], $show['Date']) . '</li>';
                }
                echo '</ul>';
            }
            if (!empty($duplicates)) {
                echo '<h4 class="error">' . count($duplicates) . ' ' . __("shows were skipped as they were deemed duplicates", "gigpress") . '.</h4>';
                echo '<ul class="ul-square">';
                foreach ($duplicates as $key => $show) {
                    echo '<li>' . wptexturize($show['Artist']) . ' ' . __("in", "gigpress") . ' ' . wptexturize($show['City']) . ' ' . __("at", "gigpress") . ' ' . wptexturize($show['Venue']) . ' ' . __("on", "gigpress") . ' ' . mysql2date($gpo['date_format'], $show['Date']) . '</li>';
                }
                echo '</ul>';
            }
            if (!empty($inserted)) {
                echo '<h4 class="updated">' . count($inserted) . ' ' . __("shows were successfully imported", "gigpress") . '.</h4>';
                echo '<ul class="ul-square">';
                foreach ($inserted as $key => $show) {
                    echo '<li>' . wptexturize($show['Artist']) . ' ' . __("in", "gigpress") . ' ' . wptexturize($show['City']) . ' ' . __("at", "gigpress") . ' ' . wptexturize($show['Venue']) . ' ' . __("on", "gigpress") . ' ' . mysql2date($gpo['date_format'], $show['Date']) . '</li>';
                }
                echo '</ul>';
            }
        } else {
            // The file uploaded, but there were no results from the parse
            echo '<div id="message" class="error fade"><p>' . __("Sorry, but there was an error parsing your file. Maybe double-check your formatting and file type?", "gigpress") . '.</p></div>';
        }
        // Bye-bye
        unlink($upload['file']);
    } else {
        // The upload failed
        echo '<div id="message" class="error fade"><p>' . __("Sorry, but there was an error uploading", "gigpress") . ' <strong>' . $_FILES['gp_import']['name'] . '</strong>: ' . $upload['error'] . '.</p></div>';
    }
}