public function importSliderFromPost()
 {
     try {
         $sliderID = UniteFunctionsBanner::getPostVariable("sliderid");
         $sliderExists = !empty($sliderID);
         if ($sliderExists) {
             $this->initByID($sliderID);
         }
         $filepath = $_FILES["import_file"]["tmp_name"];
         if (file_exists($filepath) == false) {
             UniteFunctionsBanner::throwError("Import file not found!!!");
         }
         //Get content array
         $content = @file_get_contents($filepath);
         $arrSlider = @unserialize($content);
         if (empty($arrSlider)) {
             UniteFunctionsBanner::throwError("Wrong export slider file format!");
         }
         //Update slider params
         $sliderParams = $arrSlider["params"];
         if ($sliderExists) {
             $sliderParams["title"] = $this->arrParams["title"];
             $sliderParams["alias"] = $this->arrParams["alias"];
             $sliderParams["shortcode"] = $this->arrParams["shortcode"];
         }
         if (isset($sliderParams["backgroundImage"])) {
             $sliderParams["backgroundImage"] = UniteFunctionsWPBanner::getImageUrlFromPath($sliderParams["backgroundImage"]);
         }
         $json_params = json_encode($sliderParams);
         //Update slider or craete new
         if ($sliderExists) {
             $arrUpdate = array("params" => $json_params);
             $this->db->update(GlobalsBannerRotator::$table_sliders, $arrUpdate, array("id" => $sliderID));
         } else {
             //New slider
             $arrInsert = array();
             $arrInsert["params"] = $json_params;
             $arrInsert["title"] = UniteFunctionsBanner::getVal($sliderParams, "title", "Slider1");
             $arrInsert["alias"] = UniteFunctionsBanner::getVal($sliderParams, "alias", "slider1");
             $sliderID = $this->db->insert(GlobalsBannerRotator::$table_sliders, $arrInsert);
         }
         /************************
         			    - Slides handle -
         			************************/
         //Delete current slides
         if ($sliderExists) {
             $this->deleteAllSlides();
         }
         //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"] = UniteFunctionsWPBanner::getImageUrlFromPath($params["image"]);
             }
             //Convert layers images
             foreach ($layers as $key => $layer) {
                 if (isset($layer["image_url"])) {
                     $layer["image_url"] = UniteFunctionsWPBanner::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);
             $this->db->insert(GlobalsBannerRotator::$table_slides, $arrCreate);
         }
     } catch (Exception $e) {
         $errorMessage = $e->getMessage();
         return array("success" => false, "error" => $errorMessage, "sliderID" => $sliderID);
     }
     return array("success" => true, "sliderID" => $sliderID);
 }
 public static function onAjaxAction()
 {
     $slider = new BannerRotator();
     $slide = new BannerSlide();
     $operations = new BannerOperations();
     $action = self::getPostGetVar("client_action");
     $data = self::getPostGetVar("data");
     $nonce = self::getPostGetVar("nonce");
     try {
         //Verify the nonce
         $isVerified = wp_verify_nonce($nonce, "bannerrotator_actions");
         if ($isVerified == false) {
             UniteFunctionsBanner::throwError("Wrong request");
         }
         switch ($action) {
             case "export_slider":
                 $sliderID = self::getGetVar("sliderid");
                 $dummy = self::getGetVar("dummy");
                 $slider->initByID($sliderID);
                 $slider->exportSlider($dummy);
                 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", BANNERROTATOR_TEXTDOMAIN), self::getViewUrl("sliders"));
                 break;
             case "update_slider":
                 $slider->updateSliderFromOptions($data);
                 self::ajaxResponseSuccess(__("Slider updated", BANNERROTATOR_TEXTDOMAIN));
                 break;
             case "delete_slider":
                 $slider->deleteSliderFromData($data);
                 self::ajaxResponseSuccessRedirect(__("The slider deleted", BANNERROTATOR_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS));
                 break;
             case "duplicate_slider":
                 $slider->duplicateSliderFromData($data);
                 self::ajaxResponseSuccessRedirect(__("The duplicate successfully, refreshing page...", BANNERROTATOR_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDERS));
                 break;
             case "add_slide":
                 $numSlides = $slider->createSlideFromData($data);
                 $sliderID = $data["sliderid"];
                 if ($numSlides == 1) {
                     $responseText = __("Slide Created", BANNERROTATOR_TEXTDOMAIN);
                 } else {
                     $responseText = $numSlides . " " . __("Slides Created", BANNERROTATOR_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...", BANNERROTATOR_TEXTDOMAIN);
                 self::ajaxResponseSuccessRedirect($responseText, $urlRedirect);
                 break;
             case "update_slide":
                 $slide->updateSlideFromData($data);
                 self::ajaxResponseSuccess(__("Slide updated", BANNERROTATOR_TEXTDOMAIN));
                 break;
             case "delete_slide":
                 $slide->deleteSlideFromData($data);
                 $sliderID = UniteFunctionsBanner::getVal($data, "sliderID");
                 self::ajaxResponseSuccessRedirect(__("Slide Deleted Successfully", BANNERROTATOR_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"));
                 break;
             case "duplicate_slide":
                 $sliderID = $slider->duplicateSlideFromData($data);
                 self::ajaxResponseSuccessRedirect(__("Slide Duplicated Successfully", BANNERROTATOR_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"));
                 break;
             case "copy_move_slide":
                 $sliderID = $slider->copyMoveSlideFromData($data);
                 self::ajaxResponseSuccessRedirect(__("The operation successfully, refreshing page...", BANNERROTATOR_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!", BANNERROTATOR_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", BANNERROTATOR_TEXTDOMAIN));
                 break;
             case "change_slide_image":
                 $slide->updateSlideImageFromData($data);
                 $sliderID = UniteFunctionsBanner::getVal($data, "slider_id");
                 self::ajaxResponseSuccessRedirect(__("Slide Changed Successfully", BANNERROTATOR_TEXTDOMAIN), self::getViewUrl(self::VIEW_SLIDES, "id={$sliderID}"));
                 break;
             case "preview_slide":
                 $operations->putSlidePreviewByData($data);
                 break;
             case "preview_slider":
                 $sliderID = UniteFunctionsBanner::getPostVariable("sliderid");
                 $operations->previewOutput($sliderID);
                 break;
             case "toggle_slide_state":
                 $currentState = $slide->toggleSlideStateFromData($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;
 }