/** * AJAX callback for movie update. * * @since 2.0 */ public function update_movie_callback() { wpmoly_check_ajax_referer('update-movie'); $movie_id = isset($_POST['movie_id']) && '' != $_POST['movie_id'] ? intval($_POST['movie_id']) : null; if (is_null($movie_id)) { wp_die(0); } $response = self::update_movie($movie_id); wpmoly_ajax_response($response, array(), wpmoly_create_nonce('update-movie')); }
/** * Upload an image and set it as featured image of the submitted * post. * * Extract params from $_POST values. Image URL and post ID are * required, title is optional. If no title is submitted file's * basename will be used as image name. * * Return the uploaded image ID to updated featured image preview * in editor. * * @since 1.0 */ public static function set_featured_image_callback() { wpmoly_check_ajax_referer('set-movie-poster'); $image = isset($_POST['image']) && '' != $_POST['image'] ? $_POST['image'] : null; $post_id = isset($_POST['post_id']) && '' != $_POST['post_id'] ? $_POST['post_id'] : null; $title = isset($_POST['title']) && '' != $_POST['title'] ? $_POST['title'] : null; $tmdb_id = isset($_POST['tmdb_id']) && '' != $_POST['tmdb_id'] ? $_POST['tmdb_id'] : null; if (1 != wpmoly_o('poster-featured')) { return new WP_Error('no_featured', __('Movie Posters as featured images option is deactivated. Update your settings to activate this.', 'wpmovielibrary')); } if (is_null($image) || is_null($post_id)) { return new WP_Error('invalid', __('An error occured when trying to import image: invalid data or Post ID.', 'wpmovielibrary')); } $response = self::set_image_as_featured($image, $post_id, $tmdb_id, $title); wpmoly_ajax_response($response); }
/** * Callback for Queued Movies Import. * * @since 1.0 */ public static function import_queued_movie_callback() { wpmoly_check_ajax_referer('import-queued-movies'); $post_id = isset($_POST['post_id']) && '' != $_POST['post_id'] ? $_POST['post_id'] : null; $response = self::import_queued_movie($post_id); wpmoly_ajax_response($response, array(), wpmoly_create_nonce('import-queued-movies')); }
/** * Handle an incoming ajax request (called from admin-ajax.php) * * Copy of parent::ajax_response() with minor editing to return the * pagination links along with rows. * * @since 1.0 */ function ajax_response() { $this->prepare_items(); extract($this->_args); extract($this->_pagination_args, EXTR_SKIP); ob_start(); if (!empty($_REQUEST['no_placeholder'])) { $this->display_rows(); } else { $this->display_rows_or_placeholder(); } $rows = ob_get_clean(); ob_start(); $this->print_column_headers($with_id = true, $cb_counter = 1); $headers = ob_get_clean(); ob_start(); $this->print_column_headers($with_id = false, $cb_counter = 2); $footers = ob_get_clean(); ob_start(); $this->pagination('top'); $pagination_top = ob_get_clean(); ob_start(); $this->pagination('bottom'); $pagination_bottom = ob_get_clean(); $response = array('rows' => $rows); $i18n = array(); $response['pagination']['top'] = $pagination_top; $response['pagination']['bottom'] = $pagination_bottom; $response['column_headers'] = $headers; $response['column_footers'] = $footers; if (isset($total_items)) { $response['total_items'] = $total_items; $i18n['total_items_i18n'] = sprintf(_n('1 item', '%s items', $total_items), number_format_i18n($total_items)); } if (isset($total_pages)) { $response['total_pages'] = $total_pages; $i18n['total_pages_i18n'] = number_format_i18n($total_pages); } wpmoly_ajax_response($response, $i18n); }
/** * Save metadata once they're collected. * * @since 2.0.3 */ public static function save_meta_callback() { $post_id = isset($_POST['post_id']) && '' != $_POST['post_id'] ? intval($_POST['post_id']) : null; $data = isset($_POST['data']) && '' != $_POST['data'] ? $_POST['data'] : null; if (is_null($post_id)) { return new WP_Error('invalid', __('Empty or invalid Post ID or Movie Details', 'wpmovielibrary')); } wpmoly_check_ajax_referer('save-movie-meta'); $response = self::save_movie_meta($post_id, $data); wpmoly_ajax_response($response, array(), wpmoly_create_nonce('save-movie-meta')); }
/** * Callback for WPMOLY_Import movie import method. * * Checks the AJAX nonce and calls import_movies() to * create import drafts of all movies passed through the list. * * @since 1.0 */ public static function import_movies_callback() { wpmoly_check_ajax_referer('import-movies-list'); $movies = isset($_POST['movies']) && '' != $_POST['movies'] ? esc_textarea($_POST['movies']) : null; $response = self::import_movies($movies); wpmoly_ajax_response($response, array(), wpmoly_create_nonce('import-movies-list')); }
/** * Search callback * * @since 1.0 */ public static function search_movie_callback() { wpmoly_check_ajax_referer('search-movies'); $type = isset($_GET['type']) && '' != $_GET['type'] ? $_GET['type'] : ''; $data = isset($_GET['data']) && '' != $_GET['data'] ? $_GET['data'] : ''; $lang = isset($_GET['lang']) && '' != $_GET['lang'] ? $_GET['lang'] : wpmoly_o('api-language'); $_id = isset($_GET['post_id']) && '' != $_GET['post_id'] ? $_GET['post_id'] : null; if ('' == $data || '' == $type) { return false; } if ('title' == $type) { $response = self::get_movie_by_title($data, $lang, $_id); } else { if ('id' == $type) { $response = self::get_movie_by_id($data, $lang, $_id); } } wpmoly_ajax_response($response); }
/** * Provide a plugin-wide, generic method for checking AJAX nonces. * * @since 1.0 * * @param string $action Action name for nonce */ function wpmoly_check_ajax_referer($action, $query_arg = false, $die = false) { if (!$query_arg) { $query_arg = 'nonce'; } $error = new WP_Error(); $check = check_ajax_referer('wpmoly-' . $action, $query_arg, $die); if ($check) { return true; } $error->add('invalid_nonce', __('Are you sure you want to do this?')); wpmoly_ajax_response($error, null, wpmoly_create_nonce($action)); }