/** * * onAjax action handler */ public static function onAjaxAction() { $slider = new RevSlider(); $slide = new RevSlide(); $operations = new RevSliderOperations(); $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); $nonce = self::getPostGetVar("nonce"); if (empty($nonce)) { $nonce = self::getPostGetVar("rs-nonce"); } try { //verify the nonce $isVerified = wp_verify_nonce($nonce, "revslider_actions"); if ($isVerified == false) { RevSliderFunctions::throwError("Wrong request"); } switch ($action) { case 'add_new_preset': if (!isset($data['settings']) || !isset($data['values'])) { self::ajaxResponseError(__('Missing values to add preset', 'revslider'), false); } $result = $operations->add_preset_setting($data); if ($result === true) { $presets = $operations->get_preset_settings(); self::ajaxResponseSuccess(__('Preset created', 'revslider'), array('data' => $presets)); } else { self::ajaxResponseError($result, false); } exit; break; case 'update_preset': if (!isset($data['name']) || !isset($data['values'])) { self::ajaxResponseError(__('Missing values to update preset', 'revslider'), false); } $result = $operations->update_preset_setting($data); if ($result === true) { $presets = $operations->get_preset_settings(); self::ajaxResponseSuccess(__('Preset created', 'revslider'), array('data' => $presets)); } else { self::ajaxResponseError($result, false); } exit; break; case 'remove_preset': if (!isset($data['name'])) { self::ajaxResponseError(__('Missing values to remove preset', 'revslider'), false); } $result = $operations->remove_preset_setting($data); if ($result === true) { $presets = $operations->get_preset_settings(); self::ajaxResponseSuccess(__('Preset deleted', 'revslider'), array('data' => $presets)); } else { self::ajaxResponseError($result, false); } exit; break; case "export_slider": $sliderID = self::getGetVar("sliderid"); $dummy = self::getGetVar("dummy"); $slider->initByID($sliderID); $slider->exportSlider($dummy); break; case "import_slider": $updateAnim = self::getPostGetVar("update_animations"); $updateNav = self::getPostGetVar("update_navigations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle(null, $updateAnim, $updateStatic, $updateNav); break; case "import_slider_slidersview": $viewBack = self::getViewUrl(self::VIEW_SLIDERS); $updateAnim = self::getPostGetVar("update_animations"); $updateNav = self::getPostGetVar("update_navigations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle($viewBack, $updateAnim, $updateStatic, $updateNav); break; case "import_slider_online_template_slidersview": $viewBack = self::getViewUrl(self::VIEW_SLIDERS); self::importSliderOnlineTemplateHandle($viewBack, 'true', 'none'); break; case "import_slide_online_template_slidersview": $redirect_id = esc_attr(self::getPostGetVar("redirect_id")); $viewBack = self::getViewUrl(self::VIEW_SLIDE, "id={$redirect_id}"); $slidenum = intval(self::getPostGetVar("slidenum")); $sliderid = intval(self::getPostGetVar("slider_id")); self::importSliderOnlineTemplateHandle($viewBack, 'true', 'none', array('slider_id' => $sliderid, 'slide_id' => $slidenum)); break; case "import_slider_template_slidersview": $viewBack = self::getViewUrl(self::VIEW_SLIDERS); $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderTemplateHandle($viewBack, $updateAnim, $updateStatic); break; case "import_slide_template_slidersview": $redirect_id = esc_attr(self::getPostGetVar("redirect_id")); $viewBack = self::getViewUrl(self::VIEW_SLIDE, "id={$redirect_id}"); $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); $slidenum = intval(self::getPostGetVar("slidenum")); $sliderid = intval(self::getPostGetVar("slider_id")); self::importSliderTemplateHandle($viewBack, $updateAnim, $updateStatic, array('slider_id' => $sliderid, 'slide_id' => $slidenum)); break; case "create_slider": $data = $operations->modifyCustomSliderParams($data); $newSliderID = $slider->createSliderFromOptions($data); self::ajaxResponseSuccessRedirect(__("Slider created", 'revslider'), self::getViewUrl(self::VIEW_SLIDE, 'id=new&slider=' . esc_attr($newSliderID))); //redirect to slide now break; case "update_slider": $data = $operations->modifyCustomSliderParams($data); $slider->updateSliderFromOptions($data); self::ajaxResponseSuccess(__("Slider updated", 'revslider')); break; case "delete_slider": case "delete_slider_stay": $isDeleted = $slider->deleteSliderFromData($data); if (is_array($isDeleted)) { $isDeleted = implode(', ', $isDeleted); self::ajaxResponseError(__("Template can't be deleted, it is still being used by the following Sliders: ", 'revslider') . $isDeleted); } else { if ($action == 'delete_slider_stay') { self::ajaxResponseSuccess(__("Slider deleted", 'revslider')); } else { self::ajaxResponseSuccessRedirect(__("Slider deleted", 'revslider'), self::getViewUrl(self::VIEW_SLIDERS)); } } break; case "duplicate_slider": $slider->duplicateSliderFromData($data); self::ajaxResponseSuccessRedirect(__("Success! Refreshing page...", 'revslider'), self::getViewUrl(self::VIEW_SLIDERS)); break; case "add_slide": case "add_bulk_slide": $numSlides = $slider->createSlideFromData($data); $sliderID = $data["sliderid"]; if ($numSlides == 1) { $responseText = __("Slide Created", 'revslider'); } else { $responseText = $numSlides . " " . __("Slides Created", 'revslider'); } $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id=new&slider={$sliderID}"); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "add_slide_fromslideview": $slideID = $slider->createSlideFromData($data, true); $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id={$slideID}"); $responseText = __("Slide Created, redirecting...", 'revslider'); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case 'copy_slide_to_slider': $slideID = isset($data['redirect_id']) ? $data['redirect_id'] : -1; if ($slideID === -1) { RevSliderFunctions::throwError(__('Missing redirect ID!', 'revslider')); } $return = $slider->copySlideToSlider($data); if ($return !== true) { RevSliderFunctions::throwError($return); } $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id={$slideID}"); $responseText = __("Slide copied to current Slider, redirecting...", 'revslider'); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "update_slide": $slide->updateSlideFromData($data); self::ajaxResponseSuccess(__("Slide updated", 'revslider')); break; case "update_static_slide": $slide->updateStaticSlideFromData($data); self::ajaxResponseSuccess(__("Static Global Layers updated", 'revslider')); break; case "delete_slide": case "delete_slide_stay": $isPost = $slide->deleteSlideFromData($data); if ($isPost) { $message = __("Post deleted", 'revslider'); } else { $message = __("Slide deleted", 'revslider'); } $sliderID = RevSliderFunctions::getVal($data, "sliderID"); if ($action == 'delete_slide_stay') { self::ajaxResponseSuccess($message); } else { self::ajaxResponseSuccessRedirect($message, self::getViewUrl(self::VIEW_SLIDE, "id=new&slider={$sliderID}")); } break; case "duplicate_slide": case "duplicate_slide_stay": $return = $slider->duplicateSlideFromData($data); if ($action == 'duplicate_slide_stay') { self::ajaxResponseSuccess(__("Slide duplicated", 'revslider'), array('id' => $return[1])); } else { self::ajaxResponseSuccessRedirect(__("Slide duplicated", 'revslider'), self::getViewUrl(self::VIEW_SLIDE, "id=new&slider=" . $return[0])); } break; case "copy_move_slide": case "copy_move_slide_stay": $sliderID = $slider->copyMoveSlideFromData($data); if ($action == 'copy_move_slide_stay') { self::ajaxResponseSuccess(__("Success!", 'revslider')); } else { self::ajaxResponseSuccessRedirect(__("Success! Refreshing page...", 'revslider'), self::getViewUrl(self::VIEW_SLIDE, "id=new&slider={$sliderID}")); } break; case "add_slide_to_template": $template = new RevSliderTemplate(); if (!isset($data['slideID']) || intval($data['slideID']) == 0) { RevSliderFunctions::throwError(__('No valid Slide ID given', 'revslider')); exit; } if (!isset($data['title']) || strlen(trim($data['title'])) < 3) { RevSliderFunctions::throwError(__('No valid title given', 'revslider')); exit; } if (!isset($data['settings']) || !isset($data['settings']['width']) || !isset($data['settings']['height'])) { RevSliderFunctions::throwError(__('No valid title given', 'revslider')); exit; } $return = $template->copySlideToTemplates($data['slideID'], $data['title'], $data['settings']); if ($return == false) { RevSliderFunctions::throwError(__('Could not save Slide as Template', 'revslider')); exit; } //get HTML for template section ob_start(); $rs_disable_template_script = true; //disable the script output of template selector file include RS_PLUGIN_PATH . 'admin/views/templates/template-selector.php'; $html = ob_get_contents(); ob_clean(); ob_end_clean(); self::ajaxResponseSuccess(__('Slide added to Templates', 'revslider'), array('HTML' => $html)); exit; break; break; case "get_static_css": $contentCSS = $operations->getStaticCss(); self::ajaxResponseData($contentCSS); break; case "get_dynamic_css": $contentCSS = $operations->getDynamicCss(); self::ajaxResponseData($contentCSS); break; case "insert_captions_css": $arrCaptions = $operations->insertCaptionsContentData($data); if ($arrCaptions !== false) { $db = new RevSliderDB(); $styles = $db->fetch(RevSliderGlobals::$table_css); $styles = RevSliderCssParser::parseDbArrayToCss($styles, "\n"); $styles = RevSliderCssParser::compress_css($styles); $custom_css = RevSliderOperations::getStaticCss(); $custom_css = RevSliderCssParser::compress_css($custom_css); $arrCSS = $operations->getCaptionsContentArray(); $arrCssStyles = RevSliderFunctions::jsonEncodeForClientSide($arrCSS); $arrCssStyles = $arrCSS; self::ajaxResponseSuccess(__("CSS saved", 'revslider'), array("arrCaptions" => $arrCaptions, 'compressed_css' => $styles . $custom_css, 'initstyles' => $arrCssStyles)); } RevSliderFunctions::throwError(__('CSS could not be saved', 'revslider')); exit; break; case "update_captions_css": $arrCaptions = $operations->updateCaptionsContentData($data); if ($arrCaptions !== false) { $db = new RevSliderDB(); $styles = $db->fetch(RevSliderGlobals::$table_css); $styles = RevSliderCssParser::parseDbArrayToCss($styles, "\n"); $styles = RevSliderCssParser::compress_css($styles); $custom_css = RevSliderOperations::getStaticCss(); $custom_css = RevSliderCssParser::compress_css($custom_css); $arrCSS = $operations->getCaptionsContentArray(); $arrCssStyles = RevSliderFunctions::jsonEncodeForClientSide($arrCSS); $arrCssStyles = $arrCSS; self::ajaxResponseSuccess(__("CSS saved", 'revslider'), array("arrCaptions" => $arrCaptions, 'compressed_css' => $styles . $custom_css, 'initstyles' => $arrCssStyles)); } RevSliderFunctions::throwError(__('CSS could not be saved', 'revslider')); exit; break; case "update_captions_advanced_css": $arrCaptions = $operations->updateAdvancedCssData($data); if ($arrCaptions !== false) { $db = new RevSliderDB(); $styles = $db->fetch(RevSliderGlobals::$table_css); $styles = RevSliderCssParser::parseDbArrayToCss($styles, "\n"); $styles = RevSliderCssParser::compress_css($styles); $custom_css = RevSliderOperations::getStaticCss(); $custom_css = RevSliderCssParser::compress_css($custom_css); $arrCSS = $operations->getCaptionsContentArray(); $arrCssStyles = RevSliderFunctions::jsonEncodeForClientSide($arrCSS); $arrCssStyles = $arrCSS; self::ajaxResponseSuccess(__("CSS saved", 'revslider'), array("arrCaptions" => $arrCaptions, 'compressed_css' => $styles . $custom_css, 'initstyles' => $arrCssStyles)); } RevSliderFunctions::throwError(__('CSS could not be saved', 'revslider')); exit; break; case "rename_captions_css": //rename all captions in all sliders with new handle if success $arrCaptions = $operations->renameCaption($data); $db = new RevSliderDB(); $styles = $db->fetch(RevSliderGlobals::$table_css); $styles = RevSliderCssParser::parseDbArrayToCss($styles, "\n"); $styles = RevSliderCssParser::compress_css($styles); $custom_css = RevSliderOperations::getStaticCss(); $custom_css = RevSliderCssParser::compress_css($custom_css); $arrCSS = $operations->getCaptionsContentArray(); $arrCssStyles = RevSliderFunctions::jsonEncodeForClientSide($arrCSS); $arrCssStyles = $arrCSS; self::ajaxResponseSuccess(__("Class name renamed", 'revslider'), array("arrCaptions" => $arrCaptions, 'compressed_css' => $styles . $custom_css, 'initstyles' => $arrCssStyles)); break; case "delete_captions_css": $arrCaptions = $operations->deleteCaptionsContentData($data); $db = new RevSliderDB(); $styles = $db->fetch(RevSliderGlobals::$table_css); $styles = RevSliderCssParser::parseDbArrayToCss($styles, "\n"); $styles = RevSliderCssParser::compress_css($styles); $custom_css = RevSliderOperations::getStaticCss(); $custom_css = RevSliderCssParser::compress_css($custom_css); $arrCSS = $operations->getCaptionsContentArray(); $arrCssStyles = RevSliderFunctions::jsonEncodeForClientSide($arrCSS); $arrCssStyles = $arrCSS; self::ajaxResponseSuccess(__("Style deleted!", 'revslider'), array("arrCaptions" => $arrCaptions, 'compressed_css' => $styles . $custom_css, 'initstyles' => $arrCssStyles)); break; case "update_static_css": $staticCss = $operations->updateStaticCss($data); $db = new RevSliderDB(); $styles = $db->fetch(RevSliderGlobals::$table_css); $styles = RevSliderCssParser::parseDbArrayToCss($styles, "\n"); $styles = RevSliderCssParser::compress_css($styles); $custom_css = RevSliderOperations::getStaticCss(); $custom_css = RevSliderCssParser::compress_css($custom_css); self::ajaxResponseSuccess(__("CSS saved", 'revslider'), array("css" => $staticCss, 'compressed_css' => $styles . $custom_css)); break; case "insert_custom_anim": $arrAnims = $operations->insertCustomAnim($data); //$arrCaptions = self::ajaxResponseSuccess(__("Animation saved", 'revslider'), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_custom_anim": $arrAnims = $operations->updateCustomAnim($data); self::ajaxResponseSuccess(__("Animation saved", 'revslider'), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_custom_anim_name": $arrAnims = $operations->updateCustomAnimName($data); self::ajaxResponseSuccess(__("Animation saved", 'revslider'), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "delete_custom_anim": $arrAnims = $operations->deleteCustomAnim($data); self::ajaxResponseSuccess(__("Animation deleted", 'revslider'), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_slides_order": $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess(__("Order updated", 'revslider')); break; case "change_slide_title": $slide->updateTitleByID($data); self::ajaxResponseSuccess(__('Title updated', 'revslider')); break; case "change_slide_image": $slide->updateSlideImageFromData($data); $sliderID = RevSliderFunctions::getVal($data, "slider_id"); self::ajaxResponseSuccessRedirect(__("Slide changed", 'revslider'), self::getViewUrl(self::VIEW_SLIDE, "id=new&slider={$sliderID}")); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; case "preview_slider": $sliderID = RevSliderFunctions::getPostGetVariable("sliderid"); $do_markup = RevSliderFunctions::getPostGetVariable("only_markup"); if ($do_markup == 'true') { $operations->previewOutputMarkup($sliderID); } else { $operations->previewOutput($sliderID); } break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); break; case "toggle_hero_slide": $currentHero = $slider->setHeroSlide($data); self::ajaxResponseSuccess(__('Slide is now the new active Hero Slide', 'revslider')); break; case "slide_lang_operation": $responseData = $slide->doSlideLangOperation($data); self::ajaxResponseData($responseData); break; case "update_general_settings": $operations->updateGeneralSettings($data); self::ajaxResponseSuccess(__("General settings updated", 'revslider')); break; case "update_posts_sortby": $slider->updatePostsSortbyFromData($data); self::ajaxResponseSuccess(__("Sortby updated", 'revslider')); break; case "replace_image_urls": $slider->replaceImageUrlsFromData($data); self::ajaxResponseSuccess(__("Image urls replaced", 'revslider')); break; case "reset_slide_settings": $slider->resetSlideSettings($data); self::ajaxResponseSuccess(__("Settings in all Slides changed", 'revslider')); break; case "activate_purchase_code": $result = false; if (!empty($data['code'])) { $result = $operations->checkPurchaseVerification($data); } else { RevSliderFunctions::throwError(__('The API key, the Purchase Code and the Username need to be set!', 'revslider')); exit; } if ($result) { self::ajaxResponseSuccessRedirect(__("Purchase Code Successfully Activated", 'revslider'), self::getViewUrl(self::VIEW_SLIDERS)); } else { RevSliderFunctions::throwError(__('Purchase Code is invalid', 'revslider')); } break; case "deactivate_purchase_code": $result = $operations->doPurchaseDeactivation($data); if ($result) { self::ajaxResponseSuccessRedirect(__("Successfully removed validation", 'revslider'), self::getViewUrl(self::VIEW_SLIDERS)); } else { RevSliderFunctions::throwError(__('Could not remove Validation!', 'revslider')); } break; case 'dismiss_notice': update_option('revslider-valid-notice', 'false'); self::ajaxResponseSuccess(__(".", 'revslider')); break; case 'dismiss_dynamic_notice': $notices_discarded = get_option('revslider-notices-dc', array()); $notices_discarded[] = esc_attr(trim($data['id'])); update_option('revslider-notices-dc', $notices_discarded); self::ajaxResponseSuccess(__(".", 'revslider')); break; case 'toggle_favorite': if (isset($data['id']) && intval($data['id']) > 0) { $return = self::toggle_favorite_by_id($data['id']); if ($return === true) { self::ajaxResponseSuccess(__('Setting Changed!', 'revslider')); } else { $error = $return; } } else { $error = __('No ID given', 'revslider'); } self::ajaxResponseError($error); break; case "subscribe_to_newsletter": if (isset($data['email']) && !empty($data['email'])) { $return = ThemePunch_Newsletter::subscribe($data['email']); if ($return !== false) { if (!isset($return['status']) || $return['status'] === 'error') { $error = isset($return['message']) && !empty($return['message']) ? $return['message'] : __('Invalid Email', 'revslider'); self::ajaxResponseError($error); } else { self::ajaxResponseSuccess(__("Success! Please check your Emails to finish the subscription", 'revslider'), $return); } } else { self::ajaxResponseError(__('Invalid Email/Could not connect to the Newsletter server', 'revslider')); } } else { self::ajaxResponseError(__('No Email given', 'revslider')); } break; case "unsubscribe_to_newsletter": if (isset($data['email']) && !empty($data['email'])) { $return = ThemePunch_Newsletter::unsubscribe($data['email']); if ($return !== false) { if (!isset($return['status']) || $return['status'] === 'error') { $error = isset($return['message']) && !empty($return['message']) ? $return['message'] : __('Invalid Email', 'revslider'); self::ajaxResponseError($error); } else { self::ajaxResponseSuccess(__("Success! Please check your Emails to finish the process", 'revslider'), $return); } } else { self::ajaxResponseError(__('Invalid Email/Could not connect to the Newsletter server', 'revslider')); } } else { self::ajaxResponseError(__('No Email given', 'revslider')); } break; case 'change_specific_navigation': $nav = new RevSliderNavigation(); $found = false; $navigations = $nav->get_all_navigations(); foreach ($navigations as $navig) { if ($data['id'] == $navig['id']) { $found = true; break; } } if ($found) { $nav->create_update_navigation($data, $data['id']); } else { $nav->create_update_navigation($data); } self::ajaxResponseSuccess(__('Navigation saved/updated', 'revslider'), array('navs' => $nav->get_all_navigations())); break; case 'change_navigations': $nav = new RevSliderNavigation(); $nav->create_update_full_navigation($data); self::ajaxResponseSuccess(__('Navigations updated', 'revslider'), array('navs' => $nav->get_all_navigations())); break; case 'delete_navigation': $nav = new RevSliderNavigation(); if (isset($data) && intval($data) > 0) { $return = $nav->delete_navigation($data); if ($return !== true) { self::ajaxResponseError($return); } else { self::ajaxResponseSuccess(__('Navigation deleted', 'revslider'), array('navs' => $nav->get_all_navigations())); } } self::ajaxResponseError(__('Wrong ID given', 'revslider')); break; case "get_facebook_photosets": if (!empty($data['url'])) { $facebook = new RevSliderFacebook(); $return = $facebook->get_photo_set_photos_options($data['url'], $data['album'], $data['app_id'], $data['app_secret']); if (!empty($return)) { self::ajaxResponseSuccess(__('Successfully fetched Facebook albums', 'revslider'), array('html' => implode(' ', $return))); } else { $error = __('Could not fetch Facebook albums', 'revslider'); self::ajaxResponseError($error); } } else { self::ajaxResponseSuccess(__('Cleared Albums', 'revslider'), array('html' => implode(' ', $return))); } break; case "get_flickr_photosets": if (!empty($data['url']) && !empty($data['key'])) { $flickr = new RevSliderFlickr($data['key']); $user_id = $flickr->get_user_from_url($data['url']); $return = $flickr->get_photo_sets($user_id, $data['count'], $data['set']); if (!empty($return)) { self::ajaxResponseSuccess(__('Successfully fetched flickr photosets', 'revslider'), array("data" => array('html' => implode(' ', $return)))); } else { $error = __('Could not fetch flickr photosets', 'revslider'); self::ajaxResponseError($error); } } else { if (empty($data['url']) && empty($data['key'])) { self::ajaxResponseSuccess(__('Cleared Photosets', 'revslider'), array('html' => implode(' ', $return))); } elseif (empty($data['url'])) { $error = __('No User URL - Could not fetch flickr photosets', 'revslider'); self::ajaxResponseError($error); } else { $error = __('No API KEY - Could not fetch flickr photosets', 'revslider'); self::ajaxResponseError($error); } } break; case "get_youtube_playlists": if (!empty($data['id'])) { $youtube = new RevSliderYoutube(trim($data['api']), trim($data['id'])); $return = $youtube->get_playlist_options($data['playlist']); self::ajaxResponseSuccess(__('Successfully fetched YouTube playlists', 'revslider'), array("data" => array('html' => implode(' ', $return)))); } else { $error = __('Could not fetch YouTube playlists', 'revslider'); self::ajaxResponseError($error); } break; case 'rs_get_store_information': global $wp_version; $code = get_option('revslider-code', ''); $shop_version = RevSliderTemplate::SHOP_VERSION; $validated = get_option('revslider-valid', 'false'); if ($validated == 'false') { $api_key = ''; $username = ''; $code = ''; } $rattr = array('code' => urlencode($code), 'product' => urlencode('revslider'), 'shop_version' => urlencode($shop_version), 'version' => urlencode(RevSliderGlobals::SLIDER_REVISION)); $request = wp_remote_post('http://templates.themepunch.tools/revslider/store.php', array('user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), 'body' => $rattr)); $response = ''; if (!is_wp_error($request)) { $response = json_decode(@$request['body'], true); } self::ajaxResponseData(array("data" => $response)); break; default: self::ajaxResponseError("wrong ajax action: {$action}"); break; } } catch (Exception $e) { $message = $e->getMessage(); if ($action == "preview_slide" || $action == "preview_slider") { echo $message; exit; } self::ajaxResponseError($message); } //it's an ajax action, so exit self::ajaxResponseError("No response output on {$action} action. please check with the developer."); exit; }
public static function onAjaxAction() { $slider = new RevSlider(); $slide = new RevSlide(); $operations = new RevOperations(); $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); //$nonce = self::getPostGetVar("nonce"); try { //verify the nonce // $isVerified = wp_verify_nonce($nonce, "revslider_actions"); // // if($isVerified == false) // UniteFunctionsRev::throwError("Wrong request"); switch ($action) { //start font case 'add_google_fonts': $f = new ThemePunch_Fonts(); $result = $f->add_new_font($data); if ($result === true) { self::ajaxResponseSuccessRedirect(__("Font successfully created!", REVSLIDER_TEXTDOMAIN), self::getViewUrl("sliders")); } else { self::ajaxResponseError($result, false); } break; case 'remove_google_fonts': if (!isset($data['handle'])) { self::ajaxResponseError(__('Font not found', REVSLIDER_TEXTDOMAIN), false); } $f = new ThemePunch_Fonts(); $result = $f->remove_font_by_handle($data['handle']); if ($result === true) { self::ajaxResponseSuccess(__("Font successfully removed!", REVSLIDER_TEXTDOMAIN), array('data' => $result)); } else { self::ajaxResponseError($result, false); } break; case 'edit_google_fonts': if (!isset($data['handle'])) { self::ajaxResponseError(__('No handle given', REVSLIDER_TEXTDOMAIN), false); } if (!isset($data['url'])) { self::ajaxResponseError(__('No parameters given', REVSLIDER_TEXTDOMAIN), false); } $f = new ThemePunch_Fonts(); $result = $f->edit_font_by_handle($data); if ($result === true) { self::ajaxResponseSuccess(__("Font successfully changed!", REVSLIDER_TEXTDOMAIN), array('data' => $result)); } else { self::ajaxResponseError($result, false); } break; //end font //end font case "export_slider": $sliderID = self::getGetVar("sliderid"); $dummy = self::getGetVar("dummy"); $slider->initByID($sliderID); $slider->exportSlider($dummy); break; case "import_slider": $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle(null, $updateAnim, $updateStatic); break; case "import_slider_slidersview": $viewBack = self::getViewUrl(self::VIEW_SLIDERS); $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle($viewBack, $updateAnim, $updateStatic); break; case "create_slider": self::requireSettings("slider_settings"); $settingsMain = self::getSettings("slider_main"); $settingsParams = self::getSettings("slider_params"); $data = $operations->modifyCustomSliderParams($data); //var_dump($settingsMain); $newSliderID = $slider->createSliderFromOptions($data, $settingsMain, $settingsParams); if ($newSliderID > 0) { self::ajaxResponseSuccessRedirect(__("The slider successfully created", REVSLIDER_TEXTDOMAIN), self::getViewUrl("sliders")); } break; case "update_slider": self::requireSettings("slider_settings"); $settingsMain = self::getSettings("slider_main"); $settingsParams = self::getSettings("slider_params"); $data = $operations->modifyCustomSliderParams($data); $slider->updateSliderFromOptions($data, $settingsMain, $settingsParams); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("Slider updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slider": $isDeleted = $slider->deleteSliderFromData($data); if (is_array($isDeleted)) { $isDeleted = implode(', ', $isDeleted); self::ajaxResponseError("Template can't be deleted, it is still being used by the following Sliders: " . $isDeleted); } else { self::ajaxResponseSuccessRedirect(__("The slider deleted", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); } break; case "duplicate_slider": $slider->duplicateSliderFromData($data); self::ajaxResponseSuccessRedirect(__("The duplicate successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); break; case "add_slide": $numSlides = $slider->createSlideFromData($data); $sliderID = $data["sliderid"]; if ($numSlides == 1) { $responseText = __("Slide Created", REVSLIDER_TEXTDOMAIN); } else { $responseText = $numSlides . " " . __("Slides Created", REVSLIDER_TEXTDOMAIN); } $urlRedirect = self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "add_slide_fromslideview": $slideID = $slider->createSlideFromData($data, true); $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id={$slideID}"); $responseText = __("Slide Created, redirecting...", REVSLIDER_TEXTDOMAIN); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "update_slide": require self::getSettingsFilePath("slide_settings"); $slide->updateSlideFromData($data, $slideSettings); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("Slide updated", REVSLIDER_TEXTDOMAIN)); break; case "update_static_slide": $slide->updateStaticSlideFromData($data); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("Static Layers updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slide": $isPost = $slide->deleteSlideFromData($data); if ($isPost) { $message = __("Post Deleted Successfully", REVSLIDER_TEXTDOMAIN); } else { $message = __("Slide Deleted Successfully", REVSLIDER_TEXTDOMAIN); } $sliderID = UniteFunctionsRev::getVal($data, "sliderID"); self::ajaxResponseSuccessRedirect($message, self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "duplicate_slide": $sliderID = $slider->duplicateSlideFromData($data); self::ajaxResponseSuccessRedirect(__("Slide Duplicated Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "copy_move_slide": $sliderID = $slider->copyMoveSlideFromData($data); self::ajaxResponseSuccessRedirect(__("The operation successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "get_static_css": sdsconfig::getgeneratecssfile(); $contentCSS = $operations->getStaticCss(); self::ajaxResponseData($contentCSS); break; case "get_dynamic_css": sdsconfig::getgeneratecssfile(); $contentCSS = $operations->getDynamicCss(); self::ajaxResponseData($contentCSS); break; case "insert_captions_css": $arrCaptions = $operations->insertCaptionsContentData($data); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "update_captions_css": $arrCaptions = $operations->updateCaptionsContentData($data); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "delete_captions_css": $arrCaptions = $operations->deleteCaptionsContentData($data); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("Style deleted succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "update_static_css": $staticCss = $operations->updateStaticCss($data); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("css" => $staticCss)); break; case "insert_custom_anim": $arrAnims = $operations->insertCustomAnim($data); //$arrCaptions = self::ajaxResponseSuccess(__("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_custom_anim": $arrAnims = $operations->updateCustomAnim($data); self::ajaxResponseSuccess(__("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "delete_custom_anim": $arrAnims = $operations->deleteCustomAnim($data); self::ajaxResponseSuccess(__("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_slides_order": $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess(__("Order updated successfully", REVSLIDER_TEXTDOMAIN)); break; case "change_slide_image": $slide->updateSlideImageFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "slider_id"); self::ajaxResponseSuccessRedirect(__("Slide Changed Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; // case "preview_slider": // $sliderID = UniteFunctionsRev::getPostGetVariable("sliderid"); // $operations->previewOutput($sliderID); // break; // case "preview_slider": // $sliderID = UniteFunctionsRev::getPostGetVariable("sliderid"); // $operations->previewOutput($sliderID); // break; case "preview_slider": $sliderID = UniteFunctionsRev::getPostGetVariable("sliderid"); $do_markup = UniteFunctionsRev::getPostGetVariable("only_markup"); if ($do_markup == 'true') { $operations->previewOutputMarkup($sliderID); } else { $operations->previewOutput($sliderID); } break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); break; case "slide_lang_operation": $responseData = $slide->doSlideLangOperation($data); self::ajaxResponseData($responseData); break; case "update_plugin": self::updatePlugin(self::DEFAULT_VIEW); break; case "update_text": self::updateSettingsText(); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("All files successfully updated", REVSLIDER_TEXTDOMAIN)); break; case "update_general_settings": $new_data = array(); // print_r($data); foreach ($data as $key => $value) { $new_data[$key] = $value; } $operations->updateGeneralSettings($new_data); // sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("General settings updated", REVSLIDER_TEXTDOMAIN)); break; case "update_posts_sortby": $slider->updatePostsSortbyFromData($data); self::ajaxResponseSuccess(__("Sortby updated", REVSLIDER_TEXTDOMAIN)); break; case "replace_image_urls": $slider->replaceImageUrlsFromData($data); self::ajaxResponseSuccess(__("Image urls replaced", REVSLIDER_TEXTDOMAIN)); break; case "reset_slide_settings": $slider->resetSlideSettings($data); sdsconfig::getgeneratecssfile(); self::ajaxResponseSuccess(__("Settings in all Slides changed", REVSLIDER_TEXTDOMAIN)); break; case 'delete_uploaded_image': self::delete_uploaded_file($data); break; case 'get_uploaded_images': self::get_uploaded_files_json(); break; case 'add_slider_pos_val': $newdata = array(); if (!empty($data)) { $k = array_keys($data); $k = preg_replace_callback('/\\[[0-9]+/', create_function('$match', 'return "";'), $k[0]); foreach ($data as $key => $arr) { $newdata[$k][] = $arr; } $data = $newdata; } sdsconfig::editSetting('revslideropencart', $data); self::ajaxResponseSuccess(__("Slider Position Save SuccessFully", REVSLIDER_TEXTDOMAIN)); break; default: self::ajaxResponseError("wrong ajax action: {$action} "); break; } } catch (Exception $e) { $message = $e->getMessage(); if ($action == "preview_slide" || $action == "preview_slider") { echo $message; exit; } self::ajaxResponseError($message); } //it's an ajax action, so exit //self::ajaxResponseError("No response output on <b> $action </b> action. please check with the developer."); exit; }
/** * * onAjax action handler */ public static function onAjaxAction() { $actionIndicator = self::getPostGetVar("action"); if ($actionIndicator != "uniterevolution_ajax_action") { return false; } $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); $nonce = self::getPostGetVar("nonce"); $slider = new RevSlider(); $slide = new RevSlide(); $operations = new RevOperations(); try { //verify the nonce $isVerified = wp_verify_nonce($nonce, "revslider_actions"); if ($isVerified == false) { UniteFunctionsRev::throwError("Wrong request"); } switch ($action) { case "export_slider": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); $sliderID = self::getGetVar("sliderid"); $dummy = self::getGetVar("dummy"); $slider->initByID($sliderID); $slider->exportSlider($dummy); break; case "import_slider": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle(null, $updateAnim, $updateStatic); break; case "import_slider_slidersview": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); $viewBack = self::getViewUrl(self::VIEW_SLIDERS); $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle($viewBack, $updateAnim, $updateStatic); break; case "create_slider": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); self::requireSettings("slider_settings"); $settingsMain = self::getSettings("slider_main"); $settingsParams = self::getSettings("slider_params"); $data = $operations->modifyCustomSliderParams($data); $newSliderID = $slider->createSliderFromOptions($data, $settingsMain, $settingsParams); self::ajaxResponseSuccessRedirect(__ug("The slider successfully created", REVSLIDER_TEXTDOMAIN), self::getViewUrl("sliders")); break; case "update_slider": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_SETTINGS); self::requireSettings("slider_settings"); $settingsMain = self::getSettings("slider_main"); $settingsParams = self::getSettings("slider_params"); $data = $operations->modifyCustomSliderParams($data); $slider->updateSliderFromOptions($data, $settingsMain, $settingsParams); self::ajaxResponseSuccess(__ug("Slider updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slider": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); $isDeleted = $slider->deleteSliderFromData($data); if (is_array($isDeleted)) { $isDeleted = implode(', ', $isDeleted); self::ajaxResponseError("Template can't be deleted, it is still being used by the following Sliders: " . $isDeleted); } else { self::ajaxResponseSuccessRedirect(__ug("The slider deleted", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); } break; case "duplicate_slider": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); $slider->duplicateSliderFromData($data); self::ajaxResponseSuccessRedirect(__ug("The duplicate successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); break; case "add_slide": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $numSlides = $slider->createSlideFromData($data); $sliderID = $data["sliderid"]; if ($numSlides == 1) { $responseText = __ug("Slide Created", REVSLIDER_TEXTDOMAIN); } else { $responseText = $numSlides . " " . __ug("Slides Created", REVSLIDER_TEXTDOMAIN); } $urlRedirect = self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "add_slide_fromslideview": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $slideID = $slider->createSlideFromData($data, true); $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id={$slideID}"); $responseText = __ug("Slide Created, redirecting...", REVSLIDER_TEXTDOMAIN); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "update_slide": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_EDIT_SLIDE); require self::getSettingsFilePath("slide_settings"); $slide->updateSlideFromData($data, $slideSettings); self::ajaxResponseSuccess(__ug("Slide updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slide": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $isPost = $slide->deleteSlideFromData($data); if ($isPost) { $message = __ug("Post Deleted Successfully", REVSLIDER_TEXTDOMAIN); } else { $message = __ug("Slide Deleted Successfully", REVSLIDER_TEXTDOMAIN); } $sliderID = UniteFunctionsRev::getVal($data, "sliderID"); self::ajaxResponseSuccessRedirect($message, self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "update_static_slide": $slide->updateStaticSlideFromData($data); self::ajaxResponseSuccess(__ug("Static Global Layers updated", REVSLIDER_TEXTDOMAIN)); break; case "duplicate_slide": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $sliderID = $slider->duplicateSlideFromData($data); self::ajaxResponseSuccessRedirect(__ug("Slide Duplicated Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "copy_move_slide": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $sliderID = $slider->copyMoveSlideFromData($data); self::ajaxResponseSuccessRedirect(__ug("The operation successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "get_static_css": $contentCSS = $operations->getStaticCss(); self::ajaxResponseData($contentCSS); break; case "get_dynamic_css": $contentCSS = $operations->getDynamicCss(); self::ajaxResponseData($contentCSS); break; case "insert_captions_css": $arrCaptions = $operations->insertCaptionsContentData($data); self::ajaxResponseSuccess(__ug("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "update_captions_css": $arrCaptions = $operations->updateCaptionsContentData($data); self::ajaxResponseSuccess(__ug("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "delete_captions_css": $arrCaptions = $operations->deleteCaptionsContentData($data); self::ajaxResponseSuccess(__ug("Style deleted succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "update_static_css": $staticCss = $operations->updateStaticCss($data); self::ajaxResponseSuccess(__ug("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("css" => $staticCss)); break; case "insert_custom_anim": $arrAnims = $operations->insertCustomAnim($data); //$arrCaptions = self::ajaxResponseSuccess(__ug("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_custom_anim": $arrAnims = $operations->updateCustomAnim($data); self::ajaxResponseSuccess(__ug("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "delete_custom_anim": $arrAnims = $operations->deleteCustomAnim($data); self::ajaxResponseSuccess(__ug("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_slides_order": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess(__ug("Order updated successfully", REVSLIDER_TEXTDOMAIN)); break; case "change_slide_image": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $slide->updateSlideImageFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "slider_id"); self::ajaxResponseSuccessRedirect(__ug("Slide Changed Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; case "preview_slider": $sliderID = UniteFunctionsRev::getPostGetVariable("sliderid"); $do_markup = UniteFunctionsRev::getPostGetVariable("only_markup"); if ($do_markup == 'true') { $operations->previewOutputMarkup($sliderID); } else { $operations->previewOutput($sliderID); } break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); break; case "slide_lang_operation": $responseData = $slide->doSlideLangOperation($data); self::ajaxResponseData($responseData); break; case "update_plugin": self::updatePlugin(self::DEFAULT_VIEW); break; case "update_text": self::updateSettingsText(); self::ajaxResponseSuccess(__ug("All files successfully updated", REVSLIDER_TEXTDOMAIN)); break; case "update_general_settings": $operations->updateGeneralSettings($data); self::ajaxResponseSuccess(__ug("General settings updated", REVSLIDER_TEXTDOMAIN)); break; case "update_posts_sortby": $slider->updatePostsSortbyFromData($data); self::ajaxResponseSuccess(__ug("Sortby updated", REVSLIDER_TEXTDOMAIN)); break; case "replace_image_urls": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDER_OPERATIONS); $slider->replaceImageUrlsFromData($data); self::ajaxResponseSuccess(__ug("Image urls replaced", REVSLIDER_TEXTDOMAIN)); break; case "reset_slide_settings": RevOperations::validatePermission(GlobalsRevSlider::PERMISSION_SLIDE_OPERATIONS); $slider->resetSlideSettings($data); self::ajaxResponseSuccess(__ug("Settings in all Slides changed", REVSLIDER_TEXTDOMAIN)); break; default: self::ajaxResponseError("wrong ajax action: {$action} "); break; } } catch (Exception $e) { $message = $e->getMessage(); if ($action == "preview_slide" || $action == "preview_slider") { echo $message; exit; } self::ajaxResponseError($message); } //it's an ajax action, so exit self::ajaxResponseError("No response output on <b> {$action} </b> action. please check with the developer."); exit; }
/** * * onAjax action handler */ public static function onAjaxAction() { $slider = new RevSlider(); $slide = new RevSlide(); $operations = new RevOperations(); $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); try { switch ($action) { case "export_slider": $sliderID = self::getGetVar("sliderid"); $slider->initByID($sliderID); $slider->exportSlider(); break; case "import_slider": self::importSliderHandle(); break; case "create_slider": $newSliderID = $slider->createSliderFromOptions($data); self::ajaxResponseSuccessRedirect("The slider successfully created", self::getViewUrl("sliders")); break; case "update_slider": $slider->updateSliderFromOptions($data); self::ajaxResponseSuccess("Slider updated"); break; case "delete_slider": $slider->deleteSliderFromData($data); self::ajaxResponseSuccessRedirect("The slider deleted", self::getViewUrl(self::VIEW_SLIDERS)); break; case "duplicate_slider": $slider->duplicateSliderFromData($data); self::ajaxResponseSuccessRedirect("The duplicate successfully, refreshing page...", self::getViewUrl(self::VIEW_SLIDERS)); break; case "add_slide": $slider->createSlideFromData($data); $sliderID = $data["sliderid"]; self::ajaxResponseSuccessRedirect("Slide Created", self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "update_slide": $slide->updateSlideFromData($data); self::ajaxResponseSuccess("Slide updated"); break; case "delete_slide": $slide->deleteSlideFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "sliderID"); self::ajaxResponseSuccessRedirect("Slide Deleted Successfully", self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "duplicate_slide": $sliderID = $slider->duplicateSlideFromData($data); self::ajaxResponseSuccessRedirect("Slide Duplicated Successfully", self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "get_captions_css": $contentCSS = $operations->getCaptionsContent(); self::ajaxResponseData($contentCSS); break; case "update_captions_css": $arrCaptions = $operations->updateCaptionsContentData($data); self::ajaxResponseSuccess("CSS file saved succesfully!", array("arrCaptions" => $arrCaptions)); break; case "restore_captions_css": $operations->restoreCaptionsCss(); $contentCSS = $operations->getCaptionsContent(); self::ajaxResponseData($contentCSS); break; case "update_slides_order": $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess("Order updated successfully"); break; case "change_slide_image": $slide->updateSlideImageFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "slider_id"); self::ajaxResponseSuccessRedirect("Slide Changed Successfully", self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; case "preview_slider": $sliderID = UniteFunctionsRev::getPostVariable("sliderid"); $operations->previewOutput($sliderID); break; default: self::ajaxResponseError("wrong ajax action: {$action} "); break; } } catch (Exception $e) { $message = $e->getMessage(); self::ajaxResponseError($message); } //it's an ajax action, so exit self::ajaxResponseError("No response output on <b> {$action} </b> action. please check with the developer."); exit; }
/** * * onAjax action handler */ public static function onAjaxAction() { $slider = new RevSlider(); $slide = new RevSlide(); $operations = new RevOperations(); $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); $nonce = self::getPostGetVar("nonce"); try { //verify the nonce $isVerified = wp_verify_nonce($nonce, "revslider_actions"); if ($isVerified == false) { UniteFunctionsRev::throwError("Wrong request"); } switch ($action) { case 'add_google_fonts': $f = new ThemePunch_Fonts(); $result = $f->add_new_font($data); if ($result === true) { self::ajaxResponseSuccess(__("Font successfully created!", REVSLIDER_TEXTDOMAIN), array('data' => $result, 'is_redirect' => true, 'redirect_url' => self::getFontsUrl())); } else { self::ajaxResponseError($result, false); } break; case 'remove_google_fonts': if (!isset($data['handle'])) { self::ajaxResponseError(__('Font not found', REVSLIDER_TEXTDOMAIN), false); } $f = new ThemePunch_Fonts(); $result = $f->remove_font_by_handle($data['handle']); if ($result === true) { self::ajaxResponseSuccess(__("Font successfully removed!", REVSLIDER_TEXTDOMAIN), array('data' => $result)); } else { self::ajaxResponseError($result, false); } break; case 'edit_google_fonts': if (!isset($data['handle'])) { self::ajaxResponseError(__('No handle given', REVSLIDER_TEXTDOMAIN), false); } if (!isset($data['url'])) { self::ajaxResponseError(__('No parameters given', REVSLIDER_TEXTDOMAIN), false); } $f = new ThemePunch_Fonts(); $result = $f->edit_font_by_handle($data); if ($result === true) { self::ajaxResponseSuccess(__("Font successfully changed!", REVSLIDER_TEXTDOMAIN), array('data' => $result)); } else { self::ajaxResponseError($result, false); } break; case "export_slider": $sliderID = self::getGetVar("sliderid"); $dummy = self::getGetVar("dummy"); $slider->initByID($sliderID); $slider->exportSlider($dummy); break; case "import_slider": $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle(null, $updateAnim, $updateStatic); break; case "import_slider_slidersview": $viewBack = self::getViewUrl(self::VIEW_SLIDERS); $updateAnim = self::getPostGetVar("update_animations"); $updateStatic = self::getPostGetVar("update_static_captions"); self::importSliderHandle($viewBack, $updateAnim, $updateStatic); break; case "create_slider": self::requireSettings("slider_settings"); $settingsMain = self::getSettings("slider_main"); $settingsParams = self::getSettings("slider_params"); $data = $operations->modifyCustomSliderParams($data); $newSliderID = $slider->createSliderFromOptions($data, $settingsMain, $settingsParams); self::ajaxResponseSuccessRedirect(__("The slider successfully created", REVSLIDER_TEXTDOMAIN), self::getViewUrl("sliders")); break; case "update_slider": self::requireSettings("slider_settings"); $settingsMain = self::getSettings("slider_main"); $settingsParams = self::getSettings("slider_params"); $data = $operations->modifyCustomSliderParams($data); $slider->updateSliderFromOptions($data, $settingsMain, $settingsParams); self::ajaxResponseSuccess(__("Slider updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slider": $isDeleted = $slider->deleteSliderFromData($data); if (is_array($isDeleted)) { $isDeleted = implode(', ', $isDeleted); self::ajaxResponseError("Template can't be deleted, it is still being used by the following Sliders: " . $isDeleted); } else { self::ajaxResponseSuccessRedirect(__("The slider deleted", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); } break; case "duplicate_slider": $slider->duplicateSliderFromData($data); self::ajaxResponseSuccessRedirect(__("The duplicate successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); break; case "add_slide": $numSlides = $slider->createSlideFromData($data); $sliderID = $data["sliderid"]; if ($numSlides == 1) { $responseText = __("Slide Created", REVSLIDER_TEXTDOMAIN); } else { $responseText = $numSlides . " " . __("Slides Created", REVSLIDER_TEXTDOMAIN); } $urlRedirect = self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "add_slide_fromslideview": $slideID = $slider->createSlideFromData($data, true); $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id={$slideID}"); $responseText = __("Slide Created, redirecting...", REVSLIDER_TEXTDOMAIN); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "update_slide": require self::getSettingsFilePath("slide_settings"); $slide->updateSlideFromData($data, $slideSettings); self::ajaxResponseSuccess(__("Slide updated", REVSLIDER_TEXTDOMAIN)); break; case "update_static_slide": $slide->updateStaticSlideFromData($data); self::ajaxResponseSuccess(__("Static Layers updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slide": $isPost = $slide->deleteSlideFromData($data); if ($isPost) { $message = __("Post Deleted Successfully", REVSLIDER_TEXTDOMAIN); } else { $message = __("Slide Deleted Successfully", REVSLIDER_TEXTDOMAIN); } $sliderID = UniteFunctionsRev::getVal($data, "sliderID"); self::ajaxResponseSuccessRedirect($message, self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "duplicate_slide": $sliderID = $slider->duplicateSlideFromData($data); self::ajaxResponseSuccessRedirect(__("Slide Duplicated Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "copy_move_slide": $sliderID = $slider->copyMoveSlideFromData($data); self::ajaxResponseSuccessRedirect(__("The operation successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "get_static_css": $contentCSS = $operations->getStaticCss(); self::ajaxResponseData($contentCSS); break; case "get_dynamic_css": $contentCSS = $operations->getDynamicCss(); self::ajaxResponseData($contentCSS); break; case "insert_captions_css": $arrCaptions = $operations->insertCaptionsContentData($data); self::ajaxResponseSuccess(__("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "update_captions_css": $arrCaptions = $operations->updateCaptionsContentData($data); self::ajaxResponseSuccess(__("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "delete_captions_css": $arrCaptions = $operations->deleteCaptionsContentData($data); self::ajaxResponseSuccess(__("Style deleted succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "update_static_css": $staticCss = $operations->updateStaticCss($data); self::ajaxResponseSuccess(__("CSS saved succesfully!", REVSLIDER_TEXTDOMAIN), array("css" => $staticCss)); break; case "insert_custom_anim": $arrAnims = $operations->insertCustomAnim($data); //$arrCaptions = self::ajaxResponseSuccess(__("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_custom_anim": $arrAnims = $operations->updateCustomAnim($data); self::ajaxResponseSuccess(__("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "delete_custom_anim": $arrAnims = $operations->deleteCustomAnim($data); self::ajaxResponseSuccess(__("Animation saved succesfully!", REVSLIDER_TEXTDOMAIN), $arrAnims); //,array("arrCaptions"=>$arrCaptions) break; case "update_slides_order": $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess(__("Order updated successfully", REVSLIDER_TEXTDOMAIN)); break; case "change_slide_image": $slide->updateSlideImageFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "slider_id"); self::ajaxResponseSuccessRedirect(__("Slide Changed Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; case "preview_slider": $sliderID = UniteFunctionsRev::getPostGetVariable("sliderid"); $do_markup = UniteFunctionsRev::getPostGetVariable("only_markup"); if ($do_markup == 'true') { $operations->previewOutputMarkup($sliderID); } else { $operations->previewOutput($sliderID); } break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); break; case "slide_lang_operation": $responseData = $slide->doSlideLangOperation($data); self::ajaxResponseData($responseData); break; case "update_plugin": self::updatePlugin(self::DEFAULT_VIEW); break; case "update_text": self::updateSettingsText(); self::ajaxResponseSuccess(__("All files successfully updated", REVSLIDER_TEXTDOMAIN)); break; case "update_general_settings": $operations->updateGeneralSettings($data); self::ajaxResponseSuccess(__("General settings updated", REVSLIDER_TEXTDOMAIN)); break; case "update_posts_sortby": $slider->updatePostsSortbyFromData($data); self::ajaxResponseSuccess(__("Sortby updated", REVSLIDER_TEXTDOMAIN)); break; case "replace_image_urls": $slider->replaceImageUrlsFromData($data); self::ajaxResponseSuccess(__("Image urls replaced", REVSLIDER_TEXTDOMAIN)); break; case "reset_slide_settings": $slider->resetSlideSettings($data); self::ajaxResponseSuccess(__("Settings in all Slides changed", REVSLIDER_TEXTDOMAIN)); break; case "activate_purchase_code": $result = false; if (!empty($data['username']) && !empty($data['api_key']) && !empty($data['code'])) { $result = $operations->checkPurchaseVerification($data); } else { UniteFunctionsRev::throwError(__('The API key, the Purchase Code and the Username need to be set!', REVSLIDER_TEXTDOMAIN)); exit; } if ($result) { self::ajaxResponseSuccessRedirect(__("Purchase Code Successfully Activated", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); } else { UniteFunctionsRev::throwError(__('Purchase Code is invalid', REVSLIDER_TEXTDOMAIN)); } break; case "deactivate_purchase_code": $result = $operations->doPurchaseDeactivation($data); if ($result) { self::ajaxResponseSuccessRedirect(__("Successfully removed validation", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); } else { UniteFunctionsRev::throwError(__('Could not remove Validation!', REVSLIDER_TEXTDOMAIN)); } break; case "dismiss_notice": update_option('revslider-valid-notice', 'false'); self::ajaxResponseSuccess(__(".", REVSLIDER_TEXTDOMAIN)); break; default: self::ajaxResponseError("wrong ajax action: {$action} "); break; } } catch (Exception $e) { $message = $e->getMessage(); if ($action == "preview_slide" || $action == "preview_slider") { echo $message; exit; } self::ajaxResponseError($message); } //it's an ajax action, so exit self::ajaxResponseError("No response output on <b> {$action} </b> action. please check with the developer."); exit; }
/** * * onAjax action handler */ public static function onAjaxAction() { $slider = new RevSlider(); $slide = new RevSlide(); $operations = new RevOperations(); $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); try { switch ($action) { case "export_slider": $sliderID = self::getGetVar("sliderid"); $slider->initByID($sliderID); $slider->exportSlider(); break; case "import_slider": self::importSliderHandle(); break; case "import_slider_slidersview": $viewBack = self::getViewUrl(self::VIEW_SLIDERS); self::importSliderHandle($viewBack); break; case "create_slider": $newSliderID = $slider->createSliderFromOptions($data); self::ajaxResponseSuccessRedirect(__("The slider successfully created", REVSLIDER_TEXTDOMAIN), self::getViewUrl("sliders")); break; case "update_slider": $slider->updateSliderFromOptions($data); self::ajaxResponseSuccess(__("Slider updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slider": $slider->deleteSliderFromData($data); self::ajaxResponseSuccessRedirect(__("The slider deleted", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); break; case "duplicate_slider": $slider->duplicateSliderFromData($data); self::ajaxResponseSuccessRedirect(__("The duplicate successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS)); break; case "add_slide": $numSlides = $slider->createSlideFromData($data); $sliderID = $data["sliderid"]; if ($numSlides == 1) { $responseText = __("Slide Created", REVSLIDER_TEXTDOMAIN); } else { $responseText = $numSlides . " " . __("Slides Created", REVSLIDER_TEXTDOMAIN); } $urlRedirect = self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "add_slide_fromslideview": $slideID = $slider->createSlideFromData($data, true); $urlRedirect = self::getViewUrl(self::VIEW_SLIDE, "id={$slideID}"); $responseText = __("Slide Created, redirecting...", REVSLIDER_TEXTDOMAIN); self::ajaxResponseSuccessRedirect($responseText, $urlRedirect); break; case "update_slide": $slide->updateSlideFromData($data); self::ajaxResponseSuccess(__("Slide updated", REVSLIDER_TEXTDOMAIN)); break; case "delete_slide": $slide->deleteSlideFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "sliderID"); self::ajaxResponseSuccessRedirect(__("Slide Deleted Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "duplicate_slide": $sliderID = $slider->duplicateSlideFromData($data); self::ajaxResponseSuccessRedirect(__("Slide Duplicated Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "copy_move_slide": $sliderID = $slider->copyMoveSlideFromData($data); self::ajaxResponseSuccessRedirect(__("The operation successfully, refreshing page...", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "get_captions_css": $contentCSS = $operations->getCaptionsContent(); self::ajaxResponseData($contentCSS); break; case "update_captions_css": $arrCaptions = $operations->updateCaptionsContentData($data); self::ajaxResponseSuccess(__("CSS file saved succesfully!", REVSLIDER_TEXTDOMAIN), array("arrCaptions" => $arrCaptions)); break; case "restore_captions_css": $operations->restoreCaptionsCss(); $contentCSS = $operations->getCaptionsContent(); self::ajaxResponseData($contentCSS); break; case "update_slides_order": $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess(__("Order updated successfully", REVSLIDER_TEXTDOMAIN)); break; case "change_slide_image": $slide->updateSlideImageFromData($data); $sliderID = UniteFunctionsRev::getVal($data, "slider_id"); self::ajaxResponseSuccessRedirect(__("Slide Changed Successfully", REVSLIDER_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}")); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; case "preview_slider": $sliderID = UniteFunctionsRev::getPostGetVariable("sliderid"); $operations->previewOutput($sliderID); break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); break; case "slide_lang_operation": $responseData = $slide->doSlideLangOperation($data); self::ajaxResponseData($responseData); break; case "update_plugin": self::updatePlugin(self::DEFAULT_VIEW); break; case "update_text": self::updateSettingsText(); self::ajaxResponseSuccess("All files successfully updated"); break; case "update_general_settings": $operations->updateGeneralSettings($data); self::ajaxResponseSuccess(__("General settings updated")); break; default: self::ajaxResponseError("wrong ajax action: {$action} "); break; } } catch (Exception $e) { $message = $e->getMessage(); self::ajaxResponseError($message); } //it's an ajax action, so exit self::ajaxResponseError("No response output on <b> {$action} </b> action. please check with the developer."); exit; }
/** * Import slider * @param $config * @throws Exception * @return array */ protected function importSlider($config) { global $wpdb; //we take name/alias/shortcode from file name $name = str_replace(array('revolution_slider_', '.txt'), '', basename($config)); $slider = new RevSlider(); try { $sliderId = $slider->createSliderFromOptions(array('main' => array('title' => $name, 'alias' => $name), 'params' => array())); } catch (Exception $e) { //already exists - let's leave it as is return; } //create a slider try { $slider->initByID($sliderId); //get content array $content = @file_get_contents($config); $arrSlider = @unserialize($content); if (empty($arrSlider)) { UniteFunctionsRev::throwError("Wrong export slider file format!"); } //update slider params $sliderParams = $arrSlider["params"]; $sliderParams["title"] = $name; $sliderParams["alias"] = $name; $sliderParams["shortcode"] = '[rev_slider ' . $name . ']'; if (isset($sliderParams["background_image"])) { $sliderParams["background_image"] = UniteFunctionsWPRev::getImageUrlFromPath($sliderParams["background_image"]); } $json_params = json_encode($sliderParams); $arrUpdate = array("params" => $json_params); $wpdb->update(GlobalsRevSlider::$table_sliders, $arrUpdate, array("id" => $sliderId)); //-------- Slides Handle ----------- //create all slides $arrSlides = $arrSlider["slides"]; foreach ($arrSlides as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; //convert params images: if (isset($params["image"])) { $params["image"] = UniteFunctionsWPRev::getImageUrlFromPath($params["image"]); } //convert layers images: foreach ($layers as $key => $layer) { if (isset($layer["image_url"])) { $layer["image_url"] = UniteFunctionsWPRev::getImageUrlFromPath($layer["image_url"]); $layers[$key] = $layer; } } //create new slide $arrCreate = array(); $arrCreate["slider_id"] = $sliderId; $arrCreate["slide_order"] = $slide["slide_order"]; $arrCreate["layers"] = json_encode($layers); $arrCreate["params"] = json_encode($params); $wpdb->insert(GlobalsRevSlider::$table_slides, $arrCreate); } } catch (Exception $e) { if (WP_DEBUG) { throw $e; } } }