public function at_insert_submit_entry() { global $post, $at_functions, $at_entry; if (is_user_logged_in()) { get_currentuserinfo(); } $published = $post->post_status == 'publish' ? true : false; // Get submit end datetime expiration from post meta $submit_expires = get_post_meta($post->ID, at_post_expires, true); // if timestamp exists and is less than current time, submit has expired if (!empty($submit_expires) && $at_functions->at_ts_pending($submit_expires)) { $submit_expired = false; } else { $submit_expired = true; } if ($submit_expired || !$published || !is_user_logged_in()) { if (!is_user_logged_in()) { echo '<div class="alert alert-success"><p><a href="' . wp_registration_url() . '">Register</a> now to submit your entry in this tournament!</p>'; echo '<p>Already a member? <a href="' . wp_login_url() . '">Login</a> to continue.</p></div>'; } $viewData = array('published' => $published, 'expired' => $submit_expired, 'post_expires' => $submit_expires, 'submit_post_id' => 0, 'notes_options' => array('media_buttons' => false, 'textarea_rows' => 15)); } else { wp_enqueue_script('simpleAjaxUploader'); wp_enqueue_script('id3'); wp_enqueue_script('bootstrap3'); wp_enqueue_script(at_scripts); wp_enqueue_script(at_scripts_submit_entry); wp_localize_script(at_scripts_submit_entry, 'at_plugin_paths', $at_functions->getPaths()); wp_localize_script(at_scripts_submit_entry, 'nonce', wp_create_nonce(ajax_nonce_string)); $at_config->at_javascript_globals['at_plugin_paths'] = $at_functions->getPaths(); if (!isset($at_entry)) { $at_entry = new at_entry(); } $current_user = wp_get_current_user(); // Get user object $tournament = get_post($post->post_parent); // Get tournament object from $post parent $tournament_round = get_post_meta($tournament->ID, at_tournament_round, true); // Get tournament round from tournament post meta $entry_data = $at_entry->at_get_entry_data(NULL, $current_user->ID, $tournament->ID, $tournament_round); // Get entry data from user id, tournament id & tournament round $title_text = 'Enter Title or Load from MP3'; $notes_text = 'Enter Comments or Notes'; if (!empty($entry_data)) { $entry_post = get_post($entry_data->post_id); // Get entry post from entry data id if (!empty($entry_data->zipFile)) { $zip_file = $entry_data->zipFile; } if (!empty($entry_data->mp3File)) { $mp3_file = $entry_data->mp3File; } if (!empty($entry_post->post_title)) { $title_text = $entry_post->post_title; } if (!empty($entry_post->post_content)) { $notes_text = $entry_post->post_content; } $viewData = array('published' => true, 'post_expires' => $submit_expires, 'submit_post_id' => $post->ID, 'entry_data' => $entry_data, 'uploadPrefix' => at_random_filename_prefix, 'zip_file' => $zip_file, 'mp3_file' => $mp3_file, 'titleText' => $title_text, 'notesText' => $notes_text, 'notes_options' => array('media_buttons' => false, 'textarea_rows' => 15)); } else { $viewData = array('published' => true, 'post_expires' => $submit_expires, 'submit_post_id' => $post->ID, 'entry_data' => false, 'uploadPrefix' => at_random_filename_prefix, 'zip_file' => false, 'mp3_file' => false, 'titleText' => $title_text, 'notesText' => $notes_text, 'notes_options' => array('media_buttons' => false, 'textarea_rows' => 15)); } } // if ( ! mycred_exclude_user( $current_user->ID ) ) { // // Add points and save the current year as ref_id // mycred_add( // 'submitted_entry', // $current_user->ID, // 1, // 'Submitted Entry', // 'submitted_entry', // date( 'y' ) // //,'at_entries' // ); // } // if $post_expires is not empty and expiration time has passed if (!$submit_expired) { $submit_end = new DateTime($submit_expires, $at_config->wp_timezone); $submit_end_date = $submit_end->format('F jS, Y'); $submit_end_time = $submit_end->format('g:m:s A T'); } return $at_functions->at_get_template('submit_entry', $viewData); }
public function at_insert_prev_next_entries($entry_post) { if ($entry_post->post_status === 'draft') { return false; } if (!isset($at_entry)) { $at_entry = new at_entry($this->at_config); } $tournament = get_post($entry_post->post_parent); $tournament_round = get_post_meta($tournament->ID, at_tournament_round, true); // Get tournament round from tournament post meta $entries = $at_entry->at_get_entry_data(NULL, NULL, $tournament->ID, $tournament_round); // $random_entry = $entries[ array_rand( $entries ) ]; // $random_entry_link = get_permalink( $random_entry->post_id ); // find previous and next entries for ($i = 0; $i < count($entries); $i++) { if ($entries[$i]->post_id == $entry_post->ID) { $prev_entry = $entries[$i - 1]; $next_entry = $entries[$i + 1]; if (!empty($prev_entry)) { // Remove filter to add player to title $this->at_remove_filter_title(); $prev_title = get_the_title($prev_entry->post_id); // Restore filter to add player to title $this->at_add_filter_title(); $prev_link = get_permalink($prev_entry->post_id); } else { $prev_entry = false; } if (!empty($next_entry)) { // Remove filter to add player to title $this->at_remove_filter_title(); $next_title = get_the_title($next_entry->post_id); // Restore filter to add player to title $this->at_add_filter_title(); $next_link = get_permalink($next_entry->post_id); } else { $next_entry = false; } break; } } $prev_next_html .= '<div id="entry-navigation">'; if ($prev_entry) { $prev_next_html .= '<a href="' . $prev_link . '" class="prev-entry"><span class="glyphicon glyphicon-backward"></span>' . $prev_title . '</a>'; } if ($next_entry) { $prev_next_html .= '<a href="' . $next_link . '" class="next-entry">' . $next_title . '<span class="glyphicon glyphicon-forward"></span></a>'; } $prev_next_html .= '</div>'; return $prev_next_html; }
public function at_get_tournament_status($tournament_id) { global $at_config, $at_functions, $at_entry; if (!$at_entry) { $at_entry = new at_entry(); } $tournament_round = get_post_meta($tournament_id, at_tournament_round, true); $status = array('message' => 'Error', 'end_date_time' => false); $category_ids = array(); $categories = get_terms(array('category'), array('hide_empty' => 0)); $now_time = current_time('timestamp', 1); foreach ($categories as $category) { switch ($category->slug) { case at_post_type_submit_page: $category_ids['submit'] = $category->term_id; break; case at_post_type_voting_page: $category_ids['voting'] = $category->term_id; break; case at_post_type_results_page: $category_ids['results'] = $category->term_id; break; } } $args = array('posts_per_page' => 3, 'post_type' => at_post_type_tournament, 'cat' => implode(',', $category_ids), 'post_parent' => $tournament_id, 'post_status' => array('draft', 'future', 'publish')); $posts = get_posts($args); if (empty($posts)) { return false; } foreach ($posts as $post) { switch ($post->post_name) { case 'submit': $submit_post = $post; break; case 'voting': $voting_post = $post; break; case 'results': $results_post = $post; break; } } $submit_post_time = date_create_from_format('Y-m-d H:i:s', $submit_post->post_date, $at_config->wp_timezone); // if submit is not published and submit post date is in future // then status is Beginning Soon if ($submit_post->post_status !== 'publish' || $submit_post_time->format('U') > $now_time) { $status['status'] = at_status_pending; $status['message'] = 'Starting Soon'; $status['end_date_time'] = $submit_post->post_date; return $status; } $submit_expires = get_post_meta($submit_post->ID, at_post_expires, true); $submit_expires_time = date_create_from_format('Y-m-d H:i:s', $submit_expires, $at_config->wp_timezone); // if submit is published, // submit post date is past, // submit expiration is in future and voting is not published // then status is Open Entry if ($submit_post->post_status == 'publish' && $submit_post_time->format('U') < $now_time && $submit_expires_time->format('U') > $now_time && $voting_post->post_status !== 'publish') { $status['status'] = at_status_submitting; $status['message'] = 'Open Entry'; $status['end_date_time'] = $submit_expires; $total_entries = $at_entry->at_get_entry_data(null, null, $tournament_id, $tournament_round); if (!empty($total_entries)) { $status['total_entries'] = count($total_entries); } return $status; } // if submit is expired, // voting is not published // then status is Pending Voting if ($submit_expires_time->format('U') < $now_time && $voting_post->post_status !== 'publish') { $status['status'] = at_status_pending_voting; $status['message'] = 'Voting Soon'; $status['end_date_time'] = $voting_post->post_date; $total_entries = $at_entry->at_get_entry_data(null, null, $tournament_id, $tournament_round); if (!empty($total_entries)) { $status['total_entries'] = count($total_entries); } return $status; } $voting_expires = get_post_meta($voting_post->ID, at_post_expires, true); $voting_post_time = date_create_from_format('Y-m-d H:i:s', $voting_post->post_date, $at_config->wp_timezone); $voting_expires_time = date_create_from_format('Y-m-d H:i:s', $voting_expires, $at_config->wp_timezone); // if voting is published, voting date is past and voting expiration is in future // then status is Voting if ($voting_post->post_status == 'publish' && $voting_post_time->format('U') < $now_time && $voting_expires_time->format('U') > $now_time) { $status['status'] = at_status_voting; $status['message'] = 'Voting'; $status['end_date_time'] = $voting_expires; $total_votes = $this->at_get_votes($tournament_id, $tournament_round); if (!empty($total_votes)) { $status['total_votes'] = count($total_votes); } return $status; } $results_post_time = date_create_from_format('Y-m-d H:i:s', $results_post->post_date, $at_config->wp_timezone); // if voting is expired, results is not published and results dat is in future // then status is Results Pending if ($voting_expires_time->format('U') < $now_time && $results_post->post_status !== 'publish') { $status['status'] = at_status_pending_results; $status['message'] = 'Results Pending'; $status['end_date_time'] = $results_post->post_date; $total_votes = $this->at_get_votes($tournament_id, $tournament_round); if (!empty($total_votes)) { $status['total_votes'] = count($total_votes); } return $status; } // if voting is expired, results is published and results post date is past // then status is Results if ($voting_expires_time->format('U') < $now_time && $results_post->post_status == 'publish' && $results_post_time->format('U') < $now_time) { $status['status'] = at_status_results; $status['message'] = 'Results Available'; $status['end_date_time'] = $results_post->post_date; $total_votes = $this->at_get_votes($tournament_id, $tournament_round); if (!empty($total_votes)) { $status['total_votes'] = count($total_votes); } return $status; } // Return Tournament Status array return $status; }