/** * import function. * * @param mixed $file */ function import($array = array(), $columns = array('post_title')) { $this->imported = $this->skipped = 0; if (!is_array($array) || !sizeof($array)) { $this->footer(); die; } $rows = array_chunk($array, sizeof($columns)); foreach ($rows as $row) { $row = array_filter($row); if (empty($row)) { continue; } $meta = array(); foreach ($columns as $index => $key) { $meta[$key] = wpcm_array_value($row, $index); } $name = wpcm_array_value($meta, 'post_title'); if (!$name) { $this->skipped++; continue; } $args = array('post_type' => 'wpcm_staff', 'post_status' => 'publish', 'post_title' => $name); $id = wp_insert_post($args); // Flag as import update_post_meta($id, '_wpcm_import', 1); // Update positions $jobs = explode('|', wpcm_array_value($meta, 'wpcm_jobs')); wp_set_object_terms($id, $jobs, 'wpcm_jobs', false); // Update teams $teams = explode('|', wpcm_array_value($meta, 'wpcm_team')); wp_set_object_terms($id, $teams, 'wpcm_team', false); // Update seasons $seasons = explode('|', wpcm_array_value($meta, 'wpcm_season')); wp_set_object_terms($id, $seasons, 'wpcm_season', false); // Update date of birth update_post_meta($id, 'wpcm_dob', wpcm_array_value($meta, 'wpcm_dob')); // Update nationality $natl = trim(strtolower(wpcm_array_value($meta, 'wpcm_natl'))); if ($natl == '*') { $natl = ''; } update_post_meta($id, 'wpcm_natl', $natl); // Update email update_post_meta($id, '_wpcm_staff_email', wpcm_array_value($meta, 'wpcm_email')); // Update phone update_post_meta($id, '_wpcm_staff_phone', wpcm_array_value($meta, 'wpcm_phone')); $this->imported++; } // Show Result echo '<div class="updated settings-error below-h2"><p> ' . sprintf(__('Import complete - imported <strong>%s</strong> staff and skipped <strong>%s</strong>.', 'wp-club-manager'), $this->imported, $this->skipped) . ' </p></div>'; $this->import_end(); }
/** * import function. * * @param mixed $file */ function import($array = array(), $columns = array('post_title')) { $this->imported = $this->skipped = 0; if (!is_array($array) || !sizeof($array)) { $this->footer(); die; } $rows = array_chunk($array, sizeof($columns)); foreach ($rows as $row) { $row = array_filter($row); if (empty($row)) { continue; } $meta = array(); foreach ($columns as $index => $key) { $meta[$key] = wpcm_array_value($row, $index); } $name = wpcm_array_value($meta, 'post_title'); if (!$name) { $this->skipped++; continue; } $args = array('post_type' => 'wpcm_club', 'post_status' => 'publish', 'post_title' => $name); $id = wp_insert_post($args); // Flag as import update_post_meta($id, '_wpcm_import', 1); // Update competitions $comps = explode('|', wpcm_array_value($meta, 'wpcm_comp')); wp_set_object_terms($id, $comps, 'wpcm_comp', false); // Update teams $teams = explode('|', wpcm_array_value($meta, 'wpcm_team')); wp_set_object_terms($id, $teams, 'wpcm_team', false); // Update seasons $seasons = explode('|', wpcm_array_value($meta, 'wpcm_season')); wp_set_object_terms($id, $seasons, 'wpcm_season', false); // Update venues $venues = explode('|', wpcm_array_value($meta, 'wpcm_venue')); wp_set_object_terms($id, $venues, 'wpcm_venue', false); $this->imported++; } // Show Result echo '<div class="updated settings-error below-h2"><p> ' . sprintf(__('Import complete - imported <strong>%s</strong> clubs and skipped <strong>%s</strong>.', 'wp-club-manager'), $this->imported, $this->skipped) . ' </p></div>'; $this->import_end(); }
/** * Configure sport * * @access public * @return void */ public static function configure_sport($sport) { // Get array of taxonomies to insert $term_groups = wpcm_array_value($sport, 'terms', array()); foreach ($term_groups as $taxonomy => $terms) { // Find empty terms and destroy $allterms = get_terms($taxonomy, 'hide_empty=0'); foreach ($allterms as $term) { if ($term->count == 0) { wp_delete_term($term->term_id, $taxonomy); } } // Insert terms foreach ($terms as $term) { wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug'])); } } // Get array of taxonomies to insert $stats_labels = wpcm_array_value($sport, 'stats_labels'); // $data = wpcm_get_sport_presets(); // $stats_labels = $data[$sport]['stats_labels']; foreach ($stats_labels as $key => $value) { update_option('wpcm_show_stats_' . $key, 'yes'); } update_option('wpcm_primary_result', 0); }
/** * import function. * * @param mixed $file */ function import($array = array(), $columns = array('post_title')) { $this->imported = $this->skipped = 0; if (!is_array($array) || !sizeof($array)) { $this->footer(); die; } $rows = array_chunk($array, sizeof($columns)); $date_format = 'yyyy/mm/dd'; foreach ($rows as $row) { $row = array_filter($row); if (empty($row)) { continue; } $meta = array(); foreach ($columns as $index => $key) { $meta[$key] = wpcm_array_value($row, $index); } // Get home club ID $home_club = wpcm_array_value($meta, 'wpcm_home_club'); $home_object = get_page_by_title($home_club, OBJECT, 'wpcm_club'); if ($home_object) { $home_id = $home_object->ID; } else { // Create club if doesn't exist $home_id = wp_insert_post(array('post_type' => 'wpcm_club', 'post_status' => 'publish', 'post_title' => $home_club)); // Flag as import update_post_meta($home_id, '_wpcm_import', 1); } // Get away club ID $away_club = wpcm_array_value($meta, 'wpcm_away_club'); $away_object = get_page_by_title($away_club, OBJECT, 'wpcm_club'); if ($away_object) { $away_id = $away_object->ID; } else { // Create club if doesn't exist $away_id = wp_insert_post(array('post_type' => 'wpcm_club', 'post_status' => 'publish', 'post_title' => $away_club)); // Flag as import update_post_meta($away_id, '_wpcm_import', 1); } // Format date and time $date = wpcm_array_value($meta, 'post_date'); $time = wpcm_array_value($meta, 'post_time'); $date = str_replace('/', '-', trim($date)); $date_array = explode('-', $date); $date = substr(str_pad(wpcm_array_value($date_array, 0, '0000'), 4, '0', STR_PAD_LEFT), 0, 4) . '-' . substr(str_pad(wpcm_array_value($date_array, 1, '00'), 2, '0', STR_PAD_LEFT), 0, 2) . '-' . substr(str_pad(wpcm_array_value($date_array, 2, '00'), 2, '0', STR_PAD_LEFT), 0, 2); $date .= ' ' . trim($time); // Insert match data $args = array('post_type' => 'wpcm_match', 'post_status' => 'publish', 'post_date' => $date); $id = wp_insert_post($args); // Flag as import update_post_meta($id, '_wpcm_import', 1); // Update home club update_post_meta($id, 'wpcm_home_club', $home_id); // Update away club update_post_meta($id, 'wpcm_away_club', $away_id); // Update result $result = wpcm_array_value($meta, 'wpcm_result'); if ($result) { $scores = explode('-', wpcm_array_value($meta, 'wpcm_result')); $home_goals = trim($scores[0]); $away_goals = trim($scores[1]); $goals = array('total' => array('home' => $home_goals, 'away' => $away_goals)); if ($home_goals >= '0') { update_post_meta($id, 'wpcm_home_goals', $home_goals); } if ($away_goals >= '0') { update_post_meta($id, 'wpcm_away_goals', $away_goals); } if ($home_goals >= '0' && $away_goals >= '0') { update_post_meta($id, 'wpcm_goals', serialize($goals)); update_post_meta($id, 'wpcm_played', 1); } } // Update competitions $comps = wpcm_array_value($meta, 'wpcm_comp'); wp_set_object_terms($id, $comps, 'wpcm_comp', false); // Update seasons $seasons = wpcm_array_value($meta, 'wpcm_season'); wp_set_object_terms($id, $seasons, 'wpcm_season', false); // Update teams $teams = wpcm_array_value($meta, 'wpcm_team'); wp_set_object_terms($id, $teams, 'wpcm_team', false); if ($teams) { $team_terms = explode(',', $teams); foreach ($team_terms as $team_term) { $term = get_term_by('name', $team_term, 'wpcm_team'); $team_term_array[] = $term->term_id; } $team_ids = implode(',', $team_term_array); } update_post_meta($id, 'wpcm_team', $team_ids); // Update venues $venues = wpcm_array_value($meta, 'wpcm_venue'); wp_set_object_terms($id, $venues, 'wpcm_venue', false); $this->imported++; } // Show import result echo '<div class="updated settings-error below-h2"><p> ' . sprintf(__('Import complete - imported <strong>%s</strong> matches and skipped <strong>%s</strong>.', 'wp-club-manager'), $this->imported, $this->skipped) . ' </p></div>'; $this->import_end(); }
/** * Save meta box data */ public static function save($post_id, $post) { update_post_meta($post_id, '_wpcm_video', wpcm_array_value($_POST, '_wpcm_video', null)); }
/** * Import table function. * Adapted from https://wordpress.org/plugins/sportspress/ * * @access public * @param mixed $file * @return void */ function import_table($file) { global $wpdb; $this->imported = $this->skipped = 0; if (!is_file($file)) { echo '<p><strong>' . __('Sorry, there has been an error.', 'wp-club-manager') . '</strong><br />'; echo __('The file does not exist, please try again.', 'wp-club-manager') . '</p>'; $this->footer(); die; } ini_set('auto_detect_line_endings', '1'); if (($handle = fopen($file, "r")) !== FALSE) { $header = fgetcsv($handle, 0, $this->delimiter); if (sizeof($header) >= 1) { $action = 'admin.php?import=' . $this->import_page . '&step=2'; ?> <form enctype="multipart/form-data" id="import-upload-form" class="wpcm-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?> "> <table class="wp-list-table widefat fixed pages"> <thead> <tr> <?php foreach ($this->columns as $key => $label) { ?> <th scope="col" class="manage-column"> <?php $this->dropdown($key); ?> </th> <?php } ?> </tr> </thead> <tbody> <?php while (($row = fgetcsv($handle, 0, $this->delimiter)) !== FALSE) { ?> <tr> <?php $index = 0; foreach ($this->columns as $key => $label) { $value = wpcm_array_value($row, $index); ?> <td> <input type="text" class="widefat" value="<?php echo $value; ?> " name="wpcm_import[]"> </td> <?php $index++; } ?> </tr> <?php $this->imported++; } ?> <tr> <?php foreach ($this->columns as $key => $label) { ?> <td> <input type="text" class="widefat" name="wpcm_import[]"> </td> <?php } ?> </tr> </tbody> </table> <p class="alignright"> <?php printf(__('Displaying %s–%s of %s', 'wp-club-manager'), 1, $this->imported + 1, $this->imported + 1); ?> </p> <p class="submit"> <input type="submit" class="button button-primary" value="<?php echo esc_attr($this->import_label); ?> " /> </p> </form> <?php } else { echo '<p><strong>' . __('Sorry, there has been an error.', 'wp-club-manager') . '</strong><br />'; echo __('The CSV is invalid.', 'wp-club-manager') . '</p>'; $this->footer(); die; } fclose($handle); } }