private function copyMoveSlide($slideID, $targetSliderID, $operation)
 {
     if ($operation == "move") {
         $targetSlider = new BannerRotator();
         $targetSlider->initByID($targetSliderID);
         $maxOrder = $targetSlider->getMaxOrder();
         $newOrder = $maxOrder + 1;
         $arrUpdate = array("slider_id" => $targetSliderID, "slide_order" => $newOrder);
         //Update children
         $arrChildren = $this->getArrSlideChildren($slideID);
         foreach ($arrChildren as $child) {
             $childID = $child->getID();
             $this->db->update(GlobalsBannerRotator::$table_slides, $arrUpdate, array("id" => $childID));
         }
         $this->db->update(GlobalsBannerRotator::$table_slides, $arrUpdate, array("id" => $slideID));
     } else {
         //In place of copy
         $newSlideID = $this->duplicateSlide($slideID);
         $this->duplicateChildren($slideID, $newSlideID);
         $this->copyMoveSlide($newSlideID, $targetSliderID, "move");
     }
 }
 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;
 }
    public function previewOutput($sliderID, $output = null)
    {
        if ($sliderID == "empty_output") {
            $this->loadingMessageOutput();
            exit;
        }
        if ($output == null) {
            $output = new BannerRotatorOutput();
        }
        $output->setPreviewMode();
        $slider = new BannerRotator();
        $slider->initByID($sliderID);
        $isWpmlExists = UniteWpmlBanner::isWpmlExists();
        $useWpml = $slider->getParam("useWpml", "false");
        $wpmlActive = false;
        if ($isWpmlExists && $useWpml == "true") {
            $wpmlActive = true;
            $arrLanguages = UniteWpmlBanner::getArrLanguages(false);
            //Set current lang to output
            $currentLang = UniteFunctionsBanner::getPostGetVariable("lang");
            if (empty($currentLang)) {
                $currentLang = UniteWpmlBanner::getCurrentLang();
            }
            if (empty($currentLang)) {
                $currentLang = $arrLanguages[0];
            }
            $output->setLang($currentLang);
            $selectLangChoose = UniteFunctionsBanner::getHTMLSelect($arrLanguages, $currentLang, "id='select_langs'", true);
        }
        //Put the output html
        $urlPlugin = BannerRotatorAdmin::$url_plugin;
        $urlPreviewPattern = UniteBaseClassBanner::$url_ajax_actions . "&client_action=preview_slider&sliderid={$sliderID}&lang=[lang]&nonce=[nonce]";
        $nonce = wp_create_nonce("bannerrotator_actions");
        $setBase = is_ssl() ? "https://" : "http://";
        ?>
				<html>
					<head>
						<link rel='stylesheet' href='<?php 
        echo $urlPlugin;
        ?>
css/banner-rotator.css' type='text/css' media='all' />
						<link rel='stylesheet' href='<?php 
        echo $urlPlugin;
        ?>
css/caption.css' type='text/css' media='all' />
						<script type='text/javascript' src='<?php 
        echo $setBase;
        ?>
ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
						<script type='text/javascript' src='<?php 
        echo $urlPlugin;
        ?>
js/jquery.flashblue-plugins.js'></script>
						<script type='text/javascript' src='<?php 
        echo $urlPlugin;
        ?>
js/jquery.banner-rotator.js'></script>
					</head>
					<body style="padding:0px;margin:0px;">
						<?php 
        if ($wpmlActive) {
            ?>
							<div style="margin-bottom:10px;text-align:center;">
							<?php 
            _e("Choose language");
            ?>
: <?php 
            echo $selectLangChoose;
            ?>
							</div>
							
							<script type="text/javascript">
								var g_previewPattern = '<?php 
            echo $urlPreviewPattern;
            ?>
';
								jQuery("#select_langs").change(function(){
									var lang = this.value;
									var nonce = "<?php 
            echo $nonce;
            ?>
";
									var pattern = g_previewPattern;
									var urlPreview = pattern.replace("[lang]",lang).replace("[nonce]",nonce);
									location.href = urlPreview;
								});
							</script>
						<?php 
        }
        ?>
						
						<?php 
        $output->putSliderBase($sliderID);
        ?>
					</body>
				</html>
			<?php 
        exit;
    }
Пример #4
0
<?php

$settingsMain = self::getSettings("slider_main");
$settingsParams = self::getSettings("slider_params");
$settingsSliderMain = new BannerRotatorSettingsProduct();
$settingsSliderParams = new UniteSettingsProductSidebarBanner();
//Check existing slider data
$sliderID = self::getGetVar("id");
if (!empty($sliderID)) {
    $slider = new BannerRotator();
    $slider->initByID($sliderID);
    //Get setting fields
    $settingsFields = $slider->getSettingsFields();
    $arrFieldsMain = $settingsFields["main"];
    $arrFieldsParams = $settingsFields["params"];
    //Set setting values from the slider
    $settingsMain->setStoredValues($arrFieldsParams);
    //Set custom type params values:
    $settingsMain = BannerRotatorSettingsProduct::setSettingsCustomValues($settingsMain, $arrFieldsParams);
    $settingsParams->setStoredValues($arrFieldsParams);
    //Update short code setting
    $shortcode = $slider->getShortcode();
    $settingsMain->updateSettingValue("shortcode", $shortcode);
    $linksEditSlides = self::getViewUrl(BannerRotatorAdmin::VIEW_SLIDES, "id={$sliderID}");
    $settingsSliderParams->init($settingsParams);
    $settingsSliderMain->init($settingsMain);
    $settingsSliderParams->isAccordion(true);
    require self::getPathTemplate("slider_edit");
} else {
    $settingsSliderParams->init($settingsParams);
    $settingsSliderMain->init($settingsMain);
 private function addLangFromData($data)
 {
     $sliderID = UniteFunctionsBanner::getVal($data, "sliderid");
     $slideID = UniteFunctionsBanner::getVal($data, "slideid");
     $lang = UniteFunctionsBanner::getVal($data, "lang");
     //duplicate slide
     $slider = new BannerRotator();
     $slider->initByID($sliderID);
     $newSlideID = $slider->duplicateSlide($slideID);
     //update new slide
     $this->initByID($newSlideID);
     $arrUpdate = array();
     $arrUpdate["lang"] = $lang;
     $arrUpdate["parentid"] = $slideID;
     $this->updateParamsInDB($arrUpdate);
     $urlIcon = UniteWpmlBanner::getFlagUrl($lang);
     $title = UniteWpmlBanner::getLangTitle($lang);
     $newSlide = new BannerSlide();
     $newSlide->initByID($slideID);
     $arrLangCodes = $newSlide->getArrChildLangCodes();
     $isAll = UniteWpmlBanner::isAllLangsInArray($arrLangCodes);
     $html = "<li>\n\t\t\t\t\t\t<img id=\"icon_lang_{$newSlideID}\" class=\"icon_slide_lang\" src=\"{$urlIcon}\" title=\"{$title}\" data-slideid=\"{$newSlideID}\" data-lang=\"{$lang}\">\n\t\t\t\t\t\t<div class=\"icon_lang_loader loader_round\" style=\"display:none\"></div>\t\t\t\t\t\t\t\t\n\t\t\t\t\t</li>";
     $response = array();
     $response["operation"] = "add";
     $response["isAll"] = $isAll;
     $response["html"] = $html;
     return $response;
 }