/** * * onAjax action handler */ public static function onAjaxAction() { $slider = new ShowBizSlider(); $slide = new BizSlide(); $templates = new ShowBizTemplate(); $operations = new BizOperations(); $wildcards = new ShowBizWildcards(); $action = self::getPostGetVar("client_action"); $data = self::getPostGetVar("data"); $nonce = self::getPostGetVar("nonce"); try { //verify the nonce $isVerified = wp_verify_nonce($nonce, "showbiz_actions"); if ($isVerified == false) { UniteFunctionsBiz::throwError("Wrong request"); } switch ($action) { case "update_general_settings": $operations->updateGeneralSettings($data); self::ajaxResponseSuccess(__("General settings updated", SHOWBIZ_TEXTDOMAIN)); break; 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, refreshing...", 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 = UniteFunctionsBiz::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 "update_slides_order": $slider->updateSlidesOrderFromData($data); self::ajaxResponseSuccess("Order updated successfully"); break; case "preview_slide": $operations->putSlidePreviewByData($data); break; case "preview_slider": $sliderID = UniteFunctionsBiz::getPostVariable("sliderid"); $operations->previewOutput($sliderID); break; case "preview_template": $templateID = UniteFunctionsBiz::getPostGetVariable("templateid"); $operations->previewTemplateOutput($templateID); break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); break; case "update_plugin": self::updateShowbizPlugin(); break; case "create_template": $templates->addFromData($data); self::ajaxResponseSuccess("Template Added Successfully"); break; case "delete_template": $templates->deleteFromData($data); self::ajaxResponseSuccess("Template Deleted Successfully"); break; case "duplicate_template": $templates->duplicateFromData($data); self::ajaxResponseSuccess("Template Duplicated Successfully"); break; case "get_template_content": $content = $templates->getContentFromData($data); $arrData = array("content" => $content); self::ajaxResponseData($arrData); break; case "get_template_css": $css = $templates->getCssFromData($data); $arrData = array("css" => $css); self::ajaxResponseData($arrData); break; case "update_template_content": $templates->updateContentFromData($data); self::ajaxResponseSuccess("Content Updated Successfully"); break; case "update_template_title": $templates->updateTitleFromData($data); self::ajaxResponseSuccess("Title Updated Successfully"); break; case "update_template_css": $templates->updateCssFromData($data); self::ajaxResponseSuccess("Css Updated Successfully"); break; case "restore_original_template": $templates->restoreOriginalFromData($data); self::ajaxResponseSuccess("Template Restored"); break; case "update_posts_sortby": $slider->updatePostsSortbyFromData($data); self::ajaxResponseSuccess("Sortby updated"); break; case "change_slide_image": $slide->updateSlideImageFromData($data); self::ajaxResponseSuccess("Image Changed"); break; case "add_wildcard": $response = $wildcards->addFromData($data); self::ajaxResponseSuccess("Added successfully", $response); break; case "remove_wildcard": $response = $wildcards->removeFromData($data); self::ajaxResponseSuccess("Removed successfully", $response); break; case "activate_purchase_code": $result = false; if (!empty($data['username']) && !empty($data['api_key']) && !empty($data['code'])) { $result = $operations->checkPurchaseVerification($data); } else { UniteFunctionsBiz::throwError(__('The API key, the Purchase Code and the Username need to be set!')); exit; } if ($result) { self::ajaxResponseSuccessRedirect(__("Purchase Code Successfully Activated"), self::getViewUrl(self::VIEW_SLIDERS)); } else { UniteFunctionsBiz::throwError(__('Purchase Code is invalid')); } break; case "deactivate_purchase_code": $result = $operations->doPurchaseDeactivation($data); if ($result) { self::ajaxResponseSuccessRedirect(__("Successfully removed validation"), self::getViewUrl(self::VIEW_SLIDERS)); } else { UniteFunctionsBiz::throwError(__('Could not remove Validation!')); } break; case "dismiss_notice": update_option('showbiz-valid-notice', 'false'); self::ajaxResponseSuccess(__(".")); 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; }