/home/vianto5/cititower.mx/wp-content/plugins/ml-slider/admin/routes
Edit: /home/vianto5/cititower.mx/wp-content/plugins/ml-slider/admin/routes/api.php (51140B)
slideshows = new MetaSlider_Slideshows();
$this->themes = MetaSlider_Themes::get_instance();
}
/**
* Used to access the instance
*/
public static function get_instance()
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Register routes for admin ajax. Even if not used these can still be available.
*/
public function register_admin_ajax_hooks()
{
// Slideshows
add_action('wp_ajax_ms_get_slideshows', array(self::$instance, 'get_slideshows'));
add_action('wp_ajax_ms_list_slideshows', array(self::$instance, 'list_slideshows'));
add_action('wp_ajax_ms_get_single_slideshow', array(self::$instance, 'get_single_slideshow'));
add_action('wp_ajax_ms_get_legacy_slideshows', array(self::$instance, 'get_legacy_slideshows'));
add_action('wp_ajax_ms_get_preview', array(self::$instance, 'get_preview'));
add_action('wp_ajax_ms_delete_slideshow', array(self::$instance, 'delete_slideshow'));
add_action('wp_ajax_ms_duplicate_slideshow', array(self::$instance, 'duplicate_slideshow'));
add_action('wp_ajax_ms_save_slideshow', array(self::$instance, 'save_slideshow'));
add_action('wp_ajax_ms_search_slideshows', array(self::$instance, 'search_slideshows'));
add_action('wp_ajax_ms_export_slideshows', array(self::$instance, 'export_slideshows'));
add_action('wp_ajax_ms_import_slideshows', array(self::$instance, 'import_slideshows'));
// Themes
add_action('wp_ajax_ms_get_all_free_themes', array(self::$instance, 'get_all_free_themes'));
add_action('wp_ajax_ms_get_custom_themes', array(self::$instance, 'get_custom_themes'));
add_action('wp_ajax_ms_get_theme_customization', array(self::$instance, 'get_theme_customization'));
add_action('wp_ajax_ms_set_theme', array(self::$instance, 'set_theme'));
// Slides
add_action('wp_ajax_ms_import_images', array(self::$instance, 'import_images'));
add_action( 'wp_ajax_ms_import_others', array( self::$instance, 'import_others' ) );
// Settings
add_action('wp_ajax_ms_update_user_setting', array(self::$instance, 'save_user_setting'));
add_action('wp_ajax_ms_get_user_details', array(self::$instance, 'get_user_details'));
add_action('wp_ajax_ms_update_all_slideshow_settings', array(self::$instance, 'save_all_slideshow_settings'));
add_action('wp_ajax_ms_update_single_slideshow_setting', array(self::$instance, 'save_single_slideshow_setting'));
add_action('wp_ajax_ms_get_slideshow_default_settings', array(self::$instance, 'get_slideshow_default_settings'));
add_action('wp_ajax_ms_save_slideshow_default_settings', array(self::$instance, 'save_slideshow_default_settings'));
// Global settings
add_action('wp_ajax_ms_get_single_setting', array(self::$instance, 'get_single_setting'));
add_action('wp_ajax_ms_get_global_settings', array(self::$instance, 'get_global_settings'));
add_action('wp_ajax_ms_update_global_settings', array(self::$instance, 'save_global_settings'));
add_action('wp_ajax_ms_update_global_settings_single', array(self::$instance, 'save_global_settings_single'));
// Other
add_action('wp_ajax_set_tour_status', array(self::$instance, 'set_tour_status'));
add_action('wp_ajax_ms_get_image_ids_from_filenames', array(self::$instance, 'get_image_ids_from_file_name'));
/* Pro settings
* @since 3.62
*/
add_action('wp_ajax_ms_get_pro_settings', array(self::$instance, 'get_pro_settings'));
add_action('wp_ajax_ms_update_pro_settings', array(self::$instance, 'save_pro_settings'));
}
/**
* Helper function to verify access
*
* @return boolean
*/
public function can_access()
{
$capability = apply_filters('metaslider_capability', MetaSliderPlugin::DEFAULT_CAPABILITY_EDIT_SLIDES);
// Check for the nonce on the server (used by WP REST)
if (isset($_SERVER['HTTP_X_WP_NONCE']) && wp_verify_nonce(sanitize_key($_SERVER['HTTP_X_WP_NONCE']), 'wp_rest')) {
return current_user_can($capability);
}
// This is for when not using Axios (example: callout.php)
if (isset($_REQUEST['METASLIDER_NONCE']) && wp_verify_nonce(sanitize_key($_REQUEST['METASLIDER_NONCE']), 'metaslider_request')) {
return current_user_can($capability);
}
return false;
}
/**
* Helper function to return an access denied response
*/
public function deny_access()
{
wp_send_json_error(array(
'message' => __('Access denied. Sorry, you do not have permission to complete this task.', 'ml-slider')
), 401);
}
/**
* Helper function to get data from the request
* (supports rest & admin-ajax)
* Does not handle any validation
*
* @param object $request The request
* @param array $parameters The wanted parameters
* @return array
*/
public function get_request_data($request, $parameters)
{
$results = array();
foreach ($parameters as $param) {
if (method_exists($request, 'get_param')) {
$results[$param] = $request->get_param($param);
} else {
$results[$param] = isset($_REQUEST[$param]) ? stripslashes_deep(sanitize_text_field($_REQUEST[$param])) : null;
}
}
return $results;
}
/**
* Returns all slideshows
*
* @param object|null $request The request
*/
public function get_slideshows($request = null)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('page', 'count'));
$page = isset($data['page']) ? intval($data['page']) : 1;
$count = isset($data['count']) ? intval($data['count']) : 25;
$slideshows = $this->slideshows->get($count, $page);
$slideshows = array_map(array($this, 'get_slide_data'), $slideshows);
if (is_wp_error($slideshows)) {
wp_send_json_error(array(
'message' => $slideshows->get_error_message()
), 400);
}
wp_send_json_success($slideshows, 200);
}
/**
* Returns all slideshows
*
* @param object|null $request The request
*/
public function search_slideshows($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('term', 'count'));
$slideshows = $this->slideshows->search((string) $data['term'], (string) $data['count']);
$slideshows = array_map(array($this, 'get_slide_data'), $slideshows);
if (is_wp_error($slideshows)) {
wp_send_json_error(array(
'message' => $slideshows->get_error_message()
), 400);
}
wp_send_json_success($slideshows, 200);
}
/**
* Returns a list of all slideshows
*
* @param object|null $request The request
*/
public function list_slideshows($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$slideshows = $this->slideshows->get_all_slideshows();
if (is_wp_error($slideshows)) {
wp_send_json_error(array(
'message' => $slideshows->get_error_message()
), 400);
}
wp_send_json_success($slideshows, 200);
}
/**
* Returns a single slideshow
*
* @param object $request The request
*/
public function get_single_slideshow($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('id'));
$slideshow = $this->slideshows->get_single($data['id']);
$slideshow = array_map(array($this, 'get_slide_data'), $slideshow);
if (is_wp_error($slideshow)) {
wp_send_json_error(array(
'message' => $slideshow->get_error_message()
), 400);
}
wp_send_json_success($slideshow, 200);
}
/**
* Returns Nivo, Coin, Responsive Slideshows
*
* @param object|null $request The request
*/
public function get_legacy_slideshows($request = null)
{
if (!$this->can_access()) {
$this->deny_access();
}
$count_sliders = $this->slideshows->get_legacy_slideshows();
wp_send_json_success($count_sliders, 200);
}
/**
* Maps some slide data to the slideshow
*
* @param array $slideshow - a slideshow
*
* @return array
*/
private function get_slide_data($slideshow)
{
if (isset($slideshow['slides'])) {
foreach ($slideshow['slides'] as $order => $slide_id) {
$thumbnail_id = 'attachment' === get_post_type($slide_id) ? $slide_id : get_post_thumbnail_id($slide_id);
$thumbnail_data = wp_get_attachment_image_src($thumbnail_id);
unset($slideshow['slides'][$order]);
$slideshow['slides'][$order] = array(
'id' => $slide_id,
'thumbnail' => isset($thumbnail_data[0]) ? $thumbnail_data['0'] : '',
'post_excerpt' => get_post_field('post_excerpt', $slide_id),
'order' => $order,
'meta' => array()
);
foreach (get_post_meta($slide_id) as $metakey => $value) {
$slideshow['slides'][$order]['meta'][$metakey] = $value[0];
}
}
$slideshow['slides'] = array_values($slideshow['slides']);
}
return $slideshow;
}
/**
* Returns all custom themes
*/
public function get_custom_themes()
{
if (!$this->can_access()) {
$this->deny_access();
}
$themes = $this->themes->get_custom_themes();
if (is_wp_error($themes)) {
wp_send_json_error(array(
'message' => $themes->get_error_message()
), 400);
}
wp_send_json_success($themes, 200);
}
/**
* Returns theme customizations for a given slideshow
*
* @since 3.91
*/
public function get_theme_customization($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$manifest = array();
$data = $this->get_request_data($request, array('slideshow_id', 'theme', 'type'));
$slideshow_id = absint($data['slideshow_id']);
$folder = sanitize_text_field($data['theme']);
$type = sanitize_text_field($data['type']);
$settings = get_post_meta($slideshow_id, 'ml-slider_settings', true);
// If is not a free theme, maybe override $manifest path
if ($type !== 'free') {
/**
* Check if we have extra themes/ folders added from external sources,
* including MetaSlider Pro
*
* e.g.
* array(
* '/path/to/wp-content/plugins/ml-slider-pro/themes/',
* '/path/to/wp-content/themes/my-theme/ms-themes/'
* )
*/
$extra_themes = apply_filters('metaslider_extra_themes', array());
foreach ($extra_themes as $location) {
// Check if customize.php file that belongs to $folder as theme name (lowercase) exists
if (file_exists($customize_file = trailingslashit($location) . trailingslashit($folder) . 'customize.php')) {
// Get the data from customize.php files
$manifest = $this->themes->add_base_customize_settings_single(
$folder, $customize_file
);
break;
}
}
} else {
// Get the data from customize.php files
$manifest = $this->themes->add_base_customize_settings_single($folder);
}
$data = array(
'saved_settings' => isset($settings['theme_customize'])
&& is_array($settings['theme_customize'])
&& count($settings['theme_customize']) > 0
? $settings['theme_customize'] : false,
'manifest' => $manifest
);
if (is_wp_error($data)) {
wp_send_json_error(array(
'message' => $data->get_error_message()
), 400);
}
wp_send_json_success($data, 200);
}
/**
* Returns all themes
*/
public function get_all_free_themes()
{
if (!$this->can_access()) {
$this->deny_access();
}
$themes = $this->themes->get_all_free_themes();
if (is_wp_error($themes)) {
wp_send_json_error(array(
'message' => $themes->get_error_message()
), 400);
}
wp_send_json_success($themes, 200);
}
/**
* Sets a specific theme
*
* @param object $request The request
*/
public function set_theme($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshow_id', 'theme'));
$response = $this->themes->set(absint($data['slideshow_id']), (array) $data['theme']);
if (!$response) {
wp_send_json_error(array(
'message' => 'There was an issue while attempting to save the theme. Please refresh and try again.'
), 400);
}
// If we made it this far, return the theme data
wp_send_json_success((array) $data['theme'], 200);
}
/**
* Returns the preview HTML
*
* @param object $request The request
*/
public function get_preview($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshow_id', 'theme_id'));
// The theme id can be either a string or null, exit if it's something else
if (!is_null($data['theme_id']) && !is_string($data['theme_id'])) {
wp_send_json_error(array(
'message' => __('The request format was not valid.', 'ml-slider')
), 415);
}
// If the slideshow was deleted
$slideshow = get_post($data['slideshow_id']);
if ('publish' !== $slideshow->post_status) {
wp_send_json_error(array(
'message' => __('This slideshow is no longer available.', 'ml-slider')
), 410);
}
$html = $this->slideshows->preview(
absint($data['slideshow_id']),
$data['theme_id']
);
if (is_wp_error($html)) {
wp_send_json_error(array(
'message' => $html->get_error_message()
), 400);
}
wp_send_json_success($html, 200);
}
/**
* Duplicate a slideshow
*
* @param object $request The request
*/
public function duplicate_slideshow($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshow_id'));
$new_slideshow = $this->slideshows->duplicate(absint($data['slideshow_id']));
if (is_wp_error($new_slideshow)) {
wp_send_json_error(array(
'message' => $new_slideshow->get_error_message()
), 400);
}
wp_send_json_success($new_slideshow, 200);
}
/**
* Export slideshows
*
* @param object $request The request
*/
public function export_slideshows($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshow_ids'));
$export = $this->slideshows->export((array) json_decode($data['slideshow_ids'], true));
if (is_wp_error($export)) {
wp_send_json_error(array(
'message' => $export->get_error_message()
), 400);
}
if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
// @codingStandardsIgnoreLine
echo wp_json_encode($export, JSON_PRETTY_PRINT);
die;
}
wp_send_json($export, 200);
}
/**
* Import slideshows
*
* @param object $request The request
*/
public function import_slideshows($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshows'));
if (!$data['slideshows']) {
wp_send_json_error(array(
'message' => __('Nothing to import.', 'ml-slider')
), 400);
}
$status = $this->slideshows->import((array) json_decode($data['slideshows'], true));
if (is_wp_error($status)) {
wp_send_json_error(array(
'message' => $status->get_error_message()
), 400);
}
wp_send_json_success($status, 200);
}
/**
* Delete a slideshow
*
* @param object $request The request
*/
public function delete_slideshow($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshow_id', 'slider_id', 'nonce'));
// Validate nonce
if (! isset($data['nonce'])
|| empty($data['nonce'])
|| ! wp_verify_nonce(sanitize_key($data['nonce']), 'metaslider_delete_slider')
) {
wp_send_json_error(array(
'message' => 'There was an error. Invalid nonce token.'
), 400);
}
// Backwards compatability for slider_id param
$slideshow_id = is_null($data['slideshow_id']) ? $data['slider_id'] : $data['slideshow_id'];
// If the slideshow was deleted
$slideshow = get_post($slideshow_id);
if ('publish' !== $slideshow->post_status) {
wp_send_json_error(array(
'message' => __('This slideshow is no longer available.', 'ml-slider')
), 410);
}
// Confirm it's one of ours
if ('ml-slider' !== get_post_type($slideshow_id)) {
wp_send_json_error(array(
'message' => __('This was not a slideshow, so we cannot delete it.', 'ml-slider')
), 409);
}
$next_slideshow = $this->slideshows->delete(absint($slideshow_id));
if (is_wp_error($next_slideshow)) {
wp_send_json_error(array(
'message' => 'There was an issue while attempting delete the slideshow. Please refresh and try again.'
), 400);
}
wp_send_json_success($next_slideshow, 200);
}
/**
* Save a slideshow
*
* @param object $request The request
*/
public function save_slideshow($request)
{
if (!$this->can_access()) {
$this->deny_access();
}
$data = $this->get_request_data($request, array('slideshow_id', 'attachment', 'count'));
// If we are missing the count, then it's likely the payload was truncated
if (!$data['count'] && version_compare(phpversion(), '5.3.9', '>=')) {
// If the input vars count is close to the max allowed, assume that the data was truncated and inform the user to increase the value
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$current_vars = count($_POST, COUNT_RECURSIVE);
if (($current_vars + 50) > ini_get('max_input_vars')) { // phpcs:ignore PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
wp_send_json_error(array(
'current_input_vars' => $current_vars
), 400);
}
}
try {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if (isset($data['attachment'])) {
foreach ($data['attachment'] as $slide_id => $fields) {
$fields = $this->sanitize_files_array($fields);
$slide_id = (int)$slide_id;
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
do_action("metaslider_save_{$fields['type']}_slide", $slide_id, $data['slideshow_id'], $fields);
}
}
} catch (Exception $e) {
wp_send_json_error(array('message' => $e->getMessage()), 400);
}
wp_send_json_success('OK', 200);
}
private function sanitize_files_array($fields)
{
if (isset($fields['caption_source'])) {
$fields['caption_source'] = sanitize_text_field($fields['caption_source']);
}
if (isset($fields['post_excerpt'])) {
$fields['post_excerpt'] = $this->cleanup_content_kses( $fields['post_excerpt'] );
}
if (isset($fields['url'])) {
$fields['url'] = sanitize_url($fields['url']);
}
if (isset($fields['inherit_image_title'])) {
$fields['inherit_image_title'] = sanitize_text_field($fields['inherit_image_title']);
}
if (isset($fields['title'])) {
$fields['title'] = sanitize_text_field($fields['title']);
}
if (isset($fields['inherit_image_alt'])) {
$fields['inherit_image_alt'] = sanitize_text_field($fields['inherit_image_alt']);
}
if (isset($fields['alt'])) {
$fields['alt'] = sanitize_text_field($fields['alt']);
}
if (isset($fields['link-alt'])) {
$fields['link-alt'] = sanitize_text_field($fields['link-alt']);
}
if (isset($fields['crop_position'])) {
$fields['crop_position'] = sanitize_text_field($fields['crop_position']);
}
if (isset($fields['type'])) {
$fields['type'] = sanitize_text_field($fields['type']);
}
if (isset($fields['menu_order'])) {
$fields['menu_order'] = sanitize_text_field($fields['menu_order']);
}
if (isset($fields['new_window'])) {
$fields['new_window'] = sanitize_text_field($fields['new_window']);
}
if (isset($fields['hide_slide_smartphone'])) {
$fields['hide_slide_smartphone'] = sanitize_text_field($fields['hide_slide_smartphone']);
}
if (isset($fields['hide_slide_tablet'])) {
$fields['hide_slide_tablet'] = sanitize_text_field($fields['hide_slide_tablet']);
}
if (isset($fields['hide_slide_laptop'])) {
$fields['hide_slide_laptop'] = sanitize_text_field($fields['hide_slide_laptop']);
}
if (isset($fields['hide_slide_desktop'])) {
$fields['hide_slide_desktop'] = sanitize_text_field($fields['hide_slide_desktop']);
}
if (isset($fields['hide_caption_smartphone'])) {
$fields['hide_caption_smartphone'] = sanitize_text_field($fields['hide_caption_smartphone']);
}
if (isset($fields['hide_caption_tablet'])) {
$fields['hide_caption_tablet'] = sanitize_text_field($fields['hide_caption_tablet']);
}
if (isset($fields['hide_caption_laptop'])) {
$fields['hide_caption_laptop'] = sanitize_text_field($fields['hide_caption_laptop']);
}
if (isset($fields['hide_caption_desktop'])) {
$fields['hide_caption_desktop'] = sanitize_text_field($fields['hide_caption_desktop']);
}
return $fields;
}
/**
* Sanitize HTML and avoid rgb() color being stripped by wp_filter_post_kses
*
* @since 3.62
*
* @param html $content
*
* @return html
*/
public function cleanup_content_kses( $content ) {
// Remove any script tag instance
$content = preg_replace( '/