Beispiel #1
0
 /**
  *
  * 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;
 }
 /**
  * get slides from posts
  */
 public function getSlidesFromStream($publishedOnly = false)
 {
     $slideTemplates = $this->getSlidesFromGallery($publishedOnly);
     $slideTemplates = RevSliderFunctions::assocToArray($slideTemplates);
     if (count($slideTemplates) == 0) {
         return array();
     }
     $arrPosts = array();
     $max_allowed = 999999;
     $sourceType = $this->getParam("source_type", "gallery");
     $additions = array('fb_type' => 'album');
     switch ($sourceType) {
         case "facebook":
             $facebook = new RevSliderFacebook($this->getParam('facebook-transient', '1200'));
             if ($this->getParam('facebook-type-source', 'timeline') == "album") {
                 $arrPosts = $facebook->get_photo_set_photos($this->getParam('facebook-album'), $this->getParam('facebook-count', 10), $this->getParam('facebook-app-id'), $this->getParam('facebook-app-secret'));
             } else {
                 $user_id = $facebook->get_user_from_url($this->getParam('facebook-page-url'));
                 $arrPosts = $facebook->get_photo_feed($user_id, $this->getParam('facebook-app-id'), $this->getParam('facebook-app-secret'), $this->getParam('facebook-count', 10));
                 $additions['fb_type'] = $this->getParam('facebook-type-source', 'timeline');
                 $additions['fb_user_id'] = $user_id;
             }
             if (!empty($arrPosts)) {
                 foreach ($arrPosts as $k => $p) {
                     if (!isset($p->status_type)) {
                         continue;
                     }
                     if (in_array($p->status_type, array("wall_post"))) {
                         unset($arrPosts[$k]);
                     }
                 }
             }
             $max_posts = $this->getParam('facebook-count', '25', self::FORCE_NUMERIC);
             $max_allowed = 25;
             break;
         case "twitter":
             $twitter = new RevSliderTwitter($this->getParam('twitter-consumer-key'), $this->getParam('twitter-consumer-secret'), $this->getParam('twitter-access-token'), $this->getParam('twitter-access-secret'), $this->getParam('twitter-transient', '1200'));
             $arrPosts = $twitter->get_public_photos($this->getParam('twitter-user-id'), $this->getParam('twitter-include-retweets'), $this->getParam('twitter-exclude-replies'), $this->getParam('twitter-count'), $this->getParam('twitter-image-only'));
             $max_posts = $this->getParam('twitter-count', '500', self::FORCE_NUMERIC);
             $max_allowed = 500;
             $additions['twitter_user'] = $this->getParam('twitter-user-id');
             break;
         case "instagram":
             $instagram = new RevSliderInstagram($this->getParam('instagram-access-token'), $this->getParam('instagram-transient', '1200'));
             $search_user_id = $this->getParam('instagram-user-id');
             $arrPosts = $instagram->get_public_photos($search_user_id, $this->getParam('instagram-count'));
             $max_posts = $this->getParam('instagram-count', '33', self::FORCE_NUMERIC);
             $max_allowed = 33;
             break;
         case "flickr":
             $flickr = new RevSliderFlickr($this->getParam('flickr-api-key'), $this->getParam('flickr-transient', '1200'));
             switch ($this->getParam('flickr-type')) {
                 case 'publicphotos':
                     $user_id = $flickr->get_user_from_url($this->getParam('flickr-user-url'));
                     $arrPosts = $flickr->get_public_photos($user_id, $this->getParam('flickr-count'));
                     break;
                 case 'gallery':
                     $gallery_id = $flickr->get_gallery_from_url($this->getParam('flickr-gallery-url'));
                     $arrPosts = $flickr->get_gallery_photos($gallery_id, $this->getParam('flickr-count'));
                     break;
                 case 'group':
                     $group_id = $flickr->get_group_from_url($this->getParam('flickr-group-url'));
                     $arrPosts = $flickr->get_group_photos($group_id, $this->getParam('flickr-count'));
                     break;
                 case 'photosets':
                     $arrPosts = $flickr->get_photo_set_photos($this->getParam('flickr-photoset'), $this->getParam('flickr-count'));
                     break;
             }
             $max_posts = $this->getParam('flickr-count', '99', self::FORCE_NUMERIC);
             break;
         case 'youtube':
             $channel_id = $this->getParam('youtube-channel-id');
             $youtube = new RevSliderYoutube($this->getParam('youtube-api'), $channel_id, $this->getParam('youtube-transient', '1200'));
             if ($this->getParam('youtube-type-source') == "playlist") {
                 $arrPosts = $youtube->show_playlist_videos($this->getParam('youtube-playlist'), $this->getParam('youtube-count'));
             } else {
                 $arrPosts = $youtube->show_channel_videos($this->getParam('youtube-count'));
             }
             $additions['yt_type'] = $this->getParam('youtube-type-source', 'channel');
             $max_posts = $this->getParam('youtube-count', '25', self::FORCE_NUMERIC);
             $max_allowed = 50;
             break;
         case 'vimeo':
             $vimeo = new RevSliderVimeo($this->getParam('vimeo-transient', '1200'));
             $vimeo_type = $this->getParam('vimeo-type-source');
             switch ($vimeo_type) {
                 case 'user':
                     $arrPosts = $vimeo->get_vimeo_videos($vimeo_type, $this->getParam('vimeo-username'));
                     break;
                 case 'channel':
                     $arrPosts = $vimeo->get_vimeo_videos($vimeo_type, $this->getParam('vimeo-channelname'));
                     break;
                 case 'group':
                     $arrPosts = $vimeo->get_vimeo_videos($vimeo_type, $this->getParam('vimeo-groupname'));
                     break;
                 case 'album':
                     $arrPosts = $vimeo->get_vimeo_videos($vimeo_type, $this->getParam('vimeo-albumid'));
                     break;
                 default:
                     break;
             }
             $additions['vim_type'] = $this->getParam('vimeo-type-source', 'user');
             $max_posts = $this->getParam('vimeo-count', '25', self::FORCE_NUMERIC);
             $max_allowed = 60;
             break;
         default:
             RevSliderFunctions::throwError("getSlidesFromStream error: This source type must be from stream.");
             break;
     }
     if ($max_posts < 0) {
         $max_posts *= -1;
     }
     $arrPosts = apply_filters('revslider_pre_mod_stream_data', $arrPosts, $sourceType, $this->id);
     while (count($arrPosts) > $max_posts || count($arrPosts) > $max_allowed) {
         array_pop($arrPosts);
     }
     $arrPosts = apply_filters('revslider_post_mod_stream_data', $arrPosts, $sourceType, $this->id);
     $arrSlides = array();
     $templateKey = 0;
     $numTemplates = count($slideTemplates);
     if (empty($arrPosts)) {
         RevSliderFunctions::throwError(__('Failed to load Stream', REVSLIDER_TEXTDOMAIN));
     }
     foreach ($arrPosts as $postData) {
         $slideTemplate = $slideTemplates[$templateKey];
         //advance the templates
         $templateKey++;
         if ($templateKey == $numTemplates) {
             $templateKey = 0;
         }
         $slide = new RevSlide();
         $slide->initByStreamData($postData, $slideTemplate, $this->id, $sourceType, $additions);
         $arrSlides[] = $slide;
     }
     $this->arrSlides = $arrSlides;
     return $arrSlides;
 }