public function at_admin_menu_options() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } global $at_functions, $at_tournament; $at_functions = new at_functions(); $at_tournament = new at_tournament(); $viewData = array(); echo $at_functions->at_get_template('admin_menu', $viewData); wp_enqueue_script(at_scripts); wp_enqueue_script(at_scripts_admin); wp_localize_script(at_scripts_admin, 'at_plugin_paths', $at_functions->getPaths()); wp_localize_script(at_scripts_admin, 'nonce', wp_create_nonce(ajax_nonce_string)); }
public function at_insert_voting_list($post) { global $wpdb, $post, $at_config, $at_functions, $at_entry, $current_user; // Determined post is published $published = $post->post_status == 'publish' ? true : false; // Get voting end datetime expiration from post meta $voting_expires = get_post_meta($post->ID, at_post_expires, true); $emptyViewData = array('published' => $published, 'voting_expired' => true, 'voting_expires' => $voting_expires, 'tournament_post' => false, 'voting_post' => $post, 'authors' => false, 'entry_posts' => false, 'votes' => false); // if post is not published, return blank viewData if (!$published) { $viewData = $blankViewData; } else { if (!empty($voting_expires) && $at_functions->at_ts_expired($voting_expires)) { $emptyViewData['voting_expired'] = true; $viewData = $blankViewData; } else { if (!isset($at_functions)) { $at_functions = new at_functions(); } if (!isset($at_entry)) { $at_entry = new at_entry(); } $tournament_post = get_post($post->post_parent); $tournament_id = $post->post_parent; $tournament_round = get_post_meta($tournament_post->ID, at_tournament_round, true); $query = 'SELECT * FROM ' . at_table_entries . ' WHERE ' . at_tournament_id . '=' . $tournament_id; $query .= ' AND ' . at_tournament_round . '=' . $tournament_round; $entries = $wpdb->get_results($wpdb->prepare($query, OBJECT)); if (!empty($entries)) { // create array of entry ids to query WordPress for entry posts $entries_array = array(); $entry_ids = array(); foreach ($entries as $key => $entry) { $entries_array[$entry->post_id] = $entry; $entry_ids[] = $entry->post_id; } $entry_posts = $at_entry->at_get_entry_posts($entry_ids); // create entry posts, authors, players arrays from $entry_posts object $entry_posts_array = array(); $entry_authors = array(); $unpublished_entries = ''; $players = array(); $mp3_links = array(); foreach ($entry_posts as $entry) { $entry_id = $entry->ID; $entry_data = $entries_array[$entry_id]; $entry_posts_array[$entry_id] = $entry; $entry_authors[] = $entry->post_author; $entry_path = $at_functions->get_entries_path($entry_data->user_id, $tournament_id, $tournament_round); $entry_url = $at_functions->get_entries_url($entry_data->user_id, $tournament_id, $tournament_round); $audio = array('src' => $entry_url . "/" . rawurlencode($entry_data->mp3File)); $mp3_links[$entry_id] = $entry_url . "/" . rawurlencode($entry_data->mp3File); $players[$entry_id] = wp_audio_shortcode($audio); // add htaccess file before instantiating player $htaccess_filepath = $entry_path . "/.htaccess"; if (!file_exists($htaccess_filepath)) { file_put_contents($htaccess_filepath, "order deny,allow\nallow from all") or exit('Failed to enable .htaccess: ' . $htaccess_filepath); } if ($entry->post_status == 'draft') { $unpublished_entries .= $entry->ID . ','; } } // if entries in draft status exist for this tournament round, publish them all! if (!empty($unpublished_entries)) { $unpublished_entries = trim($unpublished_entries, ','); $query = 'UPDATE ' . $wpdb->posts . ' SET post_status="publish" '; $query .= 'WHERE ' . $wpdb->posts . '.ID IN (' . $unpublished_entries . ')'; $wpdb->query($wpdb->prepare($query, OBJECT)); } $authors = get_users(array('include' => $entry_authors)); $authors_array = array(); foreach ($authors as $author) { $authors_array[$author->ID] = $author; } $vote_results = $at_entry->at_get_vote_data($current_user->ID, $tournament_id, $tournament_round); if (!empty($vote_results->vote_json)) { $vote_data = json_decode($vote_results->vote_json, true); } else { $vote_data = false; } $viewData = array('published' => true, 'voting_expired' => false, 'voting_expires' => $voting_expires, 'current_user' => $current_user, 'tournament_post' => $tournament_post, 'voting_post' => $post, 'authors' => $authors_array, 'vote_data' => $vote_data, 'mp3_links' => $mp3_links, 'entry_posts' => $entry_posts_array, 'players' => $players); if (is_user_logged_in()) { wp_enqueue_script('jqueryui'); wp_enqueue_script('jqueryui-touch-punch'); wp_enqueue_script(at_scripts_vote_list); $at_config->at_javascript_globals['votingPostId'] = $post->ID; $at_config->at_javascript_globals['pluginPaths'] = $at_functions->getPaths(); $at_config->at_javascript_globals['nonce'] = wp_create_nonce(ajax_nonce_string); } } } } return $at_functions->at_get_template('vote_list', $viewData); }