/** * * import slider from multipart form */ public function importSliderFromPost($updateAnim = true, $updateStatic = true) { try { $sliderID = UniteFunctionsRev::getPostVariable("sliderid"); $sliderExists = !empty($sliderID); if ($sliderExists) { $this->initByID($sliderID); } $filepath = $_FILES["import_file"]["tmp_name"]; if (file_exists($filepath) == false) { UniteFunctionsRev::throwError("Import file not found!!!"); } //check if zip file or fallback to old, if zip, check if all files exist $zip = new ZipArchive(); $importZip = $zip->open($filepath, ZIPARCHIVE::CREATE); if ($importZip === true) { //true or integer. If integer, its not a correct zip file //check if files all exist in zip $slider_export = $zip->getStream('slider_export.txt'); $custom_animations = $zip->getStream('custom_animations.txt'); $dynamic_captions = $zip->getStream('dynamic-captions.css'); $static_captions = $zip->getStream('static-captions.css'); if (!$slider_export) { UniteFunctionsRev::throwError("slider_export.txt does not exist!"); } //if(!$custom_animations) UniteFunctionsRev::throwError("custom_animations.txt does not exist!"); //if(!$dynamic_captions) UniteFunctionsRev::throwError("dynamic-captions.css does not exist!"); //if(!$static_captions) UniteFunctionsRev::throwError("static-captions.css does not exist!"); $content = ''; $animations = ''; $dynamic = ''; $static = ''; while (!feof($slider_export)) { $content .= fread($slider_export, 1024); } if ($custom_animations) { while (!feof($custom_animations)) { $animations .= fread($custom_animations, 1024); } } if ($dynamic_captions) { while (!feof($dynamic_captions)) { $dynamic .= fread($dynamic_captions, 1024); } } if ($static_captions) { while (!feof($static_captions)) { $static .= fread($static_captions, 1024); } } fclose($slider_export); if ($custom_animations) { fclose($custom_animations); } if ($dynamic_captions) { fclose($dynamic_captions); } if ($static_captions) { fclose($static_captions); } //check for images! } else { //check if fallback //get content array $content = @file_get_contents($filepath); } if ($importZip === true) { //we have a zip $db = new UniteDBRev(); //update/insert custom animations $animations = @unserialize($animations); if (!empty($animations)) { foreach ($animations as $key => $animation) { //$animation['id'], $animation['handle'], $animation['params'] $exist = $db->fetch(GlobalsRevSlider::$table_layer_anims, "handle = '" . $animation['handle'] . "'"); if (!empty($exist)) { //update the animation, get the ID if ($updateAnim == "true") { //overwrite animation if exists $arrUpdate = array(); $arrUpdate['params'] = stripslashes(json_encode(str_replace("'", '"', $animation['params']))); $db->update(GlobalsRevSlider::$table_layer_anims, $arrUpdate, array('handle' => $animation['handle'])); $id = $exist['0']['id']; } else { //insert with new handle $arrInsert = array(); $arrInsert["handle"] = 'copy_' . $animation['handle']; $arrInsert["params"] = stripslashes(json_encode(str_replace("'", '"', $animation['params']))); $id = $db->insert(GlobalsRevSlider::$table_layer_anims, $arrInsert); } } else { //insert the animation, get the ID $arrInsert = array(); $arrInsert["handle"] = $animation['handle']; $arrInsert["params"] = stripslashes(json_encode(str_replace("'", '"', $animation['params']))); $id = $db->insert(GlobalsRevSlider::$table_layer_anims, $arrInsert); } //and set the current customin-oldID and customout-oldID in slider params to new ID from $id $content = str_replace(array('customin-' . $animation['id'], 'customout-' . $animation['id']), array('customin-' . $id, 'customout-' . $id), $content); } dmp(__("animations imported!", REVSLIDER_TEXTDOMAIN)); } else { dmp(__("no custom animations found, if slider uses custom animations, the provided export may be broken...", REVSLIDER_TEXTDOMAIN)); } //overwrite/append static-captions.css if (!empty($static)) { if ($updateStatic == "true") { //overwrite file RevOperations::updateStaticCss($static); } else { //append $static_cur = RevOperations::getStaticCss(); $static = $static_cur . "\n" . $static; RevOperations::updateStaticCss($static); } } //overwrite/create dynamic-captions.css //parse css to classes $dynamicCss = UniteCssParserRev::parseCssToArray($dynamic); if (is_array($dynamicCss) && $dynamicCss !== false && count($dynamicCss) > 0) { foreach ($dynamicCss as $class => $styles) { //check if static style or dynamic style $class = trim($class); if (strpos($class, ':hover') === false && strpos($class, ':') !== false || strpos($class, " ") !== false || strpos($class, ".tp-caption") === false || (strpos($class, ".") === false || strpos($class, "#") !== false) || strpos($class, ">") !== false) { //.tp-caption>.imageclass or .tp-caption.imageclass>img or .tp-caption.imageclass .img continue; } //is a dynamic style if (strpos($class, ':hover') !== false) { $class = trim(str_replace(':hover', '', $class)); $arrInsert = array(); $arrInsert["hover"] = json_encode($styles); $arrInsert["settings"] = json_encode(array('hover' => 'true')); } else { $arrInsert = array(); $arrInsert["params"] = json_encode($styles); } //check if class exists $result = $db->fetch(GlobalsRevSlider::$table_css, "handle = '" . $class . "'"); if (!empty($result)) { //update $db->update(GlobalsRevSlider::$table_css, $arrInsert, array('handle' => $class)); } else { //insert $arrInsert["handle"] = $class; $db->insert(GlobalsRevSlider::$table_css, $arrInsert); } } dmp(__("dynamic styles imported!", REVSLIDER_TEXTDOMAIN)); } else { dmp(__("no dynamic styles found, if slider uses dynamic styles, the provided export may be broken...", REVSLIDER_TEXTDOMAIN)); } } $content = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $content); //clear errors in string $arrSlider = @unserialize($content); if (empty($arrSlider)) { UniteFunctionsRev::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["background_image"])) { $sliderParams["background_image"] = UniteFunctionsWPRev::getImageUrlFromPath($sliderParams["background_image"]); } $json_params = json_encode($sliderParams); //update slider or craete new if ($sliderExists) { $arrUpdate = array("params" => $json_params); $this->db->update(GlobalsRevSlider::$table_sliders, $arrUpdate, array("id" => $sliderID)); } else { //new slider $arrInsert = array(); $arrInsert["params"] = $json_params; $arrInsert["title"] = UniteFunctionsRev::getVal($sliderParams, "title", "Slider1"); $arrInsert["alias"] = UniteFunctionsRev::getVal($sliderParams, "alias", "slider1"); $sliderID = $this->db->insert(GlobalsRevSlider::$table_sliders, $arrInsert); } //-------- Slides Handle ----------- //delete current slides if ($sliderExists) { $this->deleteAllSlides(); } //create all slides $arrSlides = $arrSlider["slides"]; $alreadyImported = array(); foreach ($arrSlides as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; //convert params images: if (isset($params["image"])) { //import if exists in zip folder if (trim($params["image"]) !== '') { if ($importZip === true) { //we have a zip, check if exists $image = $zip->getStream('images/' . $params["image"]); if (!$image) { echo $params["image"] . ' not found!<br>'; } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]])) { $importImage = UniteFunctionsWPRev::import_media('zip://' . $filepath . "#" . 'images/' . $params["image"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]] = $importImage['path']; $params["image"] = $importImage['path']; } } else { $params["image"] = $alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]]; } } } } $params["image"] = UniteFunctionsWPRev::getImageUrlFromPath($params["image"]); } //convert layers images: foreach ($layers as $key => $layer) { if (isset($layer["image_url"])) { //import if exists in zip folder if (trim($layer["image_url"]) !== '') { if ($importZip === true) { //we have a zip, check if exists $image_url = $zip->getStream('images/' . $layer["image_url"]); if (!$image_url) { echo $layer["image_url"] . ' not found!<br>'; } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]])) { $importImage = UniteFunctionsWPRev::import_media('zip://' . $filepath . "#" . 'images/' . $layer["image_url"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]] = $importImage['path']; $layer["image_url"] = $importImage['path']; } } else { $layer["image_url"] = $alreadyImported['zip://' . $filepath . "#" . 'images/' . $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); $this->db->insert(GlobalsRevSlider::$table_slides, $arrCreate); } } catch (Exception $e) { $errorMessage = $e->getMessage(); return array("success" => false, "error" => $errorMessage, "sliderID" => $sliderID); } //update dynamic-captions.css RevOperations::updateDynamicCaptions(); return array("success" => true, "sliderID" => $sliderID); }
/** * * on save post meta. Update metaboxes data from post, add it to the post meta */ public static function onSavePost() { //protection against autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { $postID = UniteFunctionsRev::getPostVariable("ID"); return $postID; } $postID = UniteFunctionsRev::getPostVariable("ID"); if (empty($postID)) { return false; } foreach (self::$arrMetaBoxes as $box) { $content = UniteFunctionsRev::getVal($box, "content"); if (gettype($content) != "object") { continue; } $arrSettingNames = $content->getArrSettingNames(); foreach ($arrSettingNames as $name) { $value = UniteFunctionsRev::getPostVariable($name); update_post_meta($postID, $name, $value); } //end foreach settings } //end foreach meta }
/** * * 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; }
/** * * operate actions */ public function operate() { $this->operations = new HelperUniteOperationsRev(); $this->action = UniteFunctionsRev::getPostVariable("action"); if (empty($this->action)) { $this->action = UniteFunctionsRev::getPostVariable("client_action"); } $this->data = UniteFunctionsRev::getPostVariable("data", array()); try { switch ($this->action) { case "add_slide": $slideID = $this->operations->addSlideFromData($this->data); UniteFunctionsRev::ajaxResponseSuccess(""); break; case "update_slider_duplicate": $sliderID = $this->saveSlider(); $newSliderID = $this->operations->duplicateSlider($sliderID); UniteFunctionsRev::ajaxResponseData(array("newSliderID" => $newSliderID)); break; case "update_slider": $sliderID = $this->saveSlider(); UniteFunctionsRev::ajaxResponseData(array("sliderID" => $sliderID)); break; case "update_slide_close": case "update_slide_new": case "update_slide": $slideID = $this->saveSlide(); UniteFunctionsRev::ajaxResponseData(array("slideID" => $slideID)); break; case "update_slide_duplicate": $slideID = $this->saveSlide(); $newSlideID = $this->operations->duplicateSlide($slideID); UniteFunctionsRev::ajaxResponseData(array("slideID" => $newSlideID)); break; case "get_captions_css": $contentCSS = $this->operations->getCaptionsContent(); UniteFunctionsRev::ajaxResponseData($contentCSS); break; case "update_captions_css": $arrCaptions = $this->operations->updateCaptionsContentData($this->data); UniteFunctionsRev::ajaxResponseSuccess("CSS file saved succesfully!", array("arrCaptions" => $arrCaptions)); break; case "restore_captions_css": $this->operations->restoreCaptionsCss(); $contentCSS = $this->operations->getCaptionsContentOgirinal(); UniteFunctionsRev::ajaxResponseData($contentCSS); break; case "get_release_log": $content = HelperUniteRev::getReleaseLogContent(); UniteFunctionsRev::ajaxResponseData($content); break; case "preview_slide": $this->operations->putSlidePreviewByData($this->data); break; case "preview_slider": $sliderID = UniteFunctionsRev::getPostVariable("sliderid"); UniteFunctionsRev::validateNotEmpty($sliderID, "SliderID"); $this->operations->previewOutput($sliderID); break; case "update_items_order": $this->operations->updateSlidesOrderFromData($this->data); UniteFunctionsRev::ajaxResponseSuccess("order updated"); break; case "toggle_publish_state": //publish / unpublish item $newState = $this->operations->publishUnpublishItemFromData($this->data); UniteFunctionsRev::ajaxResponseSuccess("state updated", array("newstate" => $newState)); break; case "delete_slide": $this->operations->deleteSlideFromData($this->data); UniteFunctionsRev::ajaxResponseSuccess("Slide Deleted"); break; case "duplicate_slide": $this->operations->duplicateSlideFromData($this->data); UniteFunctionsRev::ajaxResponseSuccess("Slide Duplicated"); break; default: UniteFunctionsRev::ajaxResponseError("ajax action not found: " . $this->action); break; } } catch (Exception $e) { $message = $e->getMessage(); UniteFunctionsRev::ajaxResponseError($message); } exit; }
/** * * import slider from multipart form */ public function importSliderFromPost() { try { $sliderID = UniteFunctionsRev::getPostVariable("sliderid"); $this->initByID($sliderID); $filepath = $_FILES["import_file"]["tmp_name"]; if (file_exists($filepath) == false) { UniteFunctionsRev::throwError("Import file not found!!!"); } //get content array $content = @file_get_contents($filepath); $arrSlider = @unserialize($content); if (empty($arrSlider)) { UniteFunctionsRev::throwError("Wrong export slider file format!"); } //update slider params $sliderParams = $arrSlider["params"]; $sliderParams["title"] = $this->arrParams["title"]; $sliderParams["alias"] = $this->arrParams["alias"]; $sliderParams["shortcode"] = $this->arrParams["shortcode"]; if (isset($sliderParams["background_image"])) { $sliderParams["background_image"] = UniteFunctionsWPRev::getImageUrlFromPath($sliderParams["background_image"]); } $json_params = json_encode($sliderParams); $arrUpdate = array("params" => $json_params); $this->db->update(GlobalsRevSlider::$table_sliders, $arrUpdate, array("id" => $sliderID)); //-------- Slides Handle ----------- //delete current slides $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"] = 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); $this->db->insert(GlobalsRevSlider::$table_slides, $arrCreate); } } catch (Exception $e) { $errorMessage = $e->getMessage(); return array("success" => false, "error" => $errorMessage, "sliderID" => $sliderID); } return array("success" => true, "sliderID" => $sliderID); }
/** * * 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::getPostVariable("sliderid"); $operations->previewOutput($sliderID); break; case "toggle_slide_state": $currentState = $slide->toggleSlideStatFromData($data); self::ajaxResponseData(array("state" => $currentState)); 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 importSliderFromPost($updateAnim = true, $updateStatic = true) { try { $sliderID = UniteFunctionsRev::getPostVariable("sliderid"); $sliderExists = !empty($sliderID); if ($sliderExists) { $this->initByID($sliderID); } $filepath = $_FILES["import_file"]["tmp_name"]; if (file_exists($filepath) == false) { UniteFunctionsRev::throwError("Import file not found!!!"); } if (!class_exists("ZipArchive")) { $importZip = false; } else { $zip = new ZipArchive(); $importZip = $zip->open($filepath, ZIPARCHIVE::CREATE); } if ($importZip === true) { $slider_export = $zip->getStream('slider_export.txt'); $custom_animations = $zip->getStream('custom_animations.txt'); $dynamic_captions = $zip->getStream('dynamic-captions.css'); $static_captions = $zip->getStream('static-captions.css'); if (!$slider_export) { UniteFunctionsRev::throwError("slider_export.txt does not exist!"); } $content = ''; $animations = ''; $dynamic = ''; $static = ''; while (!feof($slider_export)) { $content .= fread($slider_export, 1024); } if ($custom_animations) { while (!feof($custom_animations)) { $animations .= fread($custom_animations, 1024); } } if ($dynamic_captions) { while (!feof($dynamic_captions)) { $dynamic .= fread($dynamic_captions, 1024); } } if ($static_captions) { while (!feof($static_captions)) { $static .= fread($static_captions, 1024); } } fclose($slider_export); if ($custom_animations) { fclose($custom_animations); } if ($dynamic_captions) { fclose($dynamic_captions); } if ($static_captions) { fclose($static_captions); } } else { $content = @file_get_contents($filepath); } if ($importZip === true) { $db = new UniteDBRev(); $animations = @unserialize($animations); if (!empty($animations)) { foreach ($animations as $key => $animation) { $exist = $db->fetch(GlobalsRevSlider::$table_layer_anims, "handle = '" . $animation['handle'] . "'"); if (!empty($exist)) { if ($updateAnim == "true") { $arrUpdate = array(); $arrUpdate['params'] = stripslashes(json_encode(str_replace("'", '"', $animation['params']))); $db->update(GlobalsRevSlider::$table_layer_anims, $arrUpdate, array('handle' => $animation['handle'])); $id = $exist['0']['id']; } else { $arrInsert = array(); $arrInsert["handle"] = 'copy_' . $animation['handle']; $arrInsert["params"] = stripslashes(json_encode(str_replace("'", '"', $animation['params']))); $id = $db->insert(GlobalsRevSlider::$table_layer_anims, $arrInsert); } } else { $arrInsert = array(); $arrInsert["handle"] = $animation['handle']; $arrInsert["params"] = stripslashes(json_encode(str_replace("'", '"', $animation['params']))); $id = $db->insert(GlobalsRevSlider::$table_layer_anims, $arrInsert); } $content = str_replace(array('customin-' . $animation['id'], 'customout-' . $animation['id']), array('customin-' . $id, 'customout-' . $id), $content); } dmp(__("animations imported!", REVSLIDER_TEXTDOMAIN)); } else { dmp(__("no custom animations found, if slider uses custom animations, the provided export may be broken...", REVSLIDER_TEXTDOMAIN)); } if (!empty($static)) { if ($updateStatic == "true") { RevOperations::updateStaticCss($static); } else { $static_cur = RevOperations::getStaticCss(); $static = $static_cur . "\n" . $static; RevOperations::updateStaticCss($static); } } $dynamicCss = UniteCssParserRev::parseCssToArray($dynamic); if (is_array($dynamicCss) && $dynamicCss !== false && count($dynamicCss) > 0) { foreach ($dynamicCss as $class => $styles) { $class = trim($class); if (strpos($class, ':hover') === false && strpos($class, ':') !== false || strpos($class, " ") !== false || strpos($class, ".tp-caption") === false || (strpos($class, ".") === false || strpos($class, "#") !== false) || strpos($class, ">") !== false) { continue; } if (strpos($class, ':hover') !== false) { $class = trim(str_replace(':hover', '', $class)); $arrInsert = array(); $arrInsert["hover"] = json_encode($styles); $arrInsert["settings"] = json_encode(array('hover' => 'true')); } else { $arrInsert = array(); $arrInsert["params"] = json_encode($styles); } $result = $db->fetch(GlobalsRevSlider::$table_css, "handle = '" . $class . "'"); if (!empty($result)) { $db->update(GlobalsRevSlider::$table_css, $arrInsert, array('handle' => $class)); } else { $arrInsert["handle"] = $class; $db->insert(GlobalsRevSlider::$table_css, $arrInsert); } } dmp(__("dynamic styles imported!", REVSLIDER_TEXTDOMAIN)); } else { dmp(__("no dynamic styles found, if slider uses dynamic styles, the provided export may be broken...", REVSLIDER_TEXTDOMAIN)); } } $content = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $content); $arrSlider = @unserialize($content); if (empty($arrSlider)) { UniteFunctionsRev::throwError("Wrong export slider file format! This could be caused because the ZipArchive extension is not enabled."); } $sliderParams = $arrSlider["params"]; if ($sliderExists) { $sliderParams["title"] = $this->arrParams["title"]; $sliderParams["alias"] = $this->arrParams["alias"]; } if (isset($sliderParams["background_image"])) { $sliderParams["background_image"] = UniteFunctionsWPRev::getImageUrlFromPath($sliderParams["background_image"]); } $json_params = json_encode($sliderParams); if ($sliderExists) { $arrUpdate = array("params" => $json_params); $this->db->update(GlobalsRevSlider::$table_sliders, $arrUpdate, array("id" => $sliderID)); } else { $arrInsert = array(); $arrInsert["params"] = $json_params; $arrInsert["title"] = UniteFunctionsRev::getVal($sliderParams, "title", "Slider1"); $arrInsert["alias"] = UniteFunctionsRev::getVal($sliderParams, "alias", "slider1"); $sliderID = $this->db->insert(GlobalsRevSlider::$table_sliders, $arrInsert); } if ($sliderExists) { $this->deleteAllSlides(); } $arrSlides = $arrSlider["slides"]; $alreadyImported = array(); foreach ($arrSlides as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; if (isset($params["image"])) { if (strpos($params["image"], 'http') !== false) { } else { if (trim($params["image"]) !== '') { if ($importZip === true) { $image = $zip->getStream('images/' . $params["image"]); if (!$image) { echo $params["image"] . __(' not found!<br>'); } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]])) { $importImage = UniteFunctionsWPRev::import_media('zip://' . $filepath . "#" . 'images/' . $params["image"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]] = $importImage['path']; $params["image"] = $importImage['path']; } } else { $params["image"] = $alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]]; } } } } $params["image"] = UniteFunctionsWPRev::getImageUrlFromPath($params["image"]); } } foreach ($layers as $key => $layer) { if (isset($layer["image_url"])) { if (trim($layer["image_url"]) !== '') { if (strpos($layer["image_url"], 'http') !== false) { } else { if ($importZip === true) { $image_url = $zip->getStream('images/' . $layer["image_url"]); if (!$image_url) { echo $layer["image_url"] . __(' not found!<br>'); } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]])) { $importImage = UniteFunctionsWPRev::import_media('zip://' . $filepath . "#" . 'images/' . $layer["image_url"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]] = $importImage['path']; $layer["image_url"] = $importImage['path']; } } else { $layer["image_url"] = $alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]]; } } } } } $layer["image_url"] = UniteFunctionsWPRev::getImageUrlFromPath($layer["image_url"]); $layers[$key] = $layer; } } $arrCreate = array(); $arrCreate["slider_id"] = $sliderID; $arrCreate["slide_order"] = $slide["slide_order"]; $my_layers = json_encode($layers); if (empty($my_layers)) { $my_layers = stripslashes(json_encode($layers)); } $my_params = json_encode($params); if (empty($my_params)) { $my_params = stripslashes(json_encode($params)); } $arrCreate["layers"] = $my_layers; $arrCreate["params"] = $my_params; $this->db->insert(GlobalsRevSlider::$table_slides, $arrCreate); } if (isset($arrSlider['static_slides']) && !empty($arrSlider['static_slides'])) { $static_slide = $arrSlider['static_slides']; foreach ($static_slide as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; if (isset($params["image"])) { if (strpos($params["image"], 'http') !== false) { } else { if (trim($params["image"]) !== '') { if ($importZip === true) { $image = $zip->getStream('images/' . $params["image"]); if (!$image) { echo $params["image"] . __(' not found!<br>'); } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]])) { $importImage = UniteFunctionsWPRev::import_media('zip://' . $filepath . "#" . 'images/' . $params["image"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]] = $importImage['path']; $params["image"] = $importImage['path']; } } else { $params["image"] = $alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]]; } } } } $params["image"] = UniteFunctionsWPRev::getImageUrlFromPath($params["image"]); } } foreach ($layers as $key => $layer) { if (isset($layer["image_url"])) { if (trim($layer["image_url"]) !== '') { if (strpos($layer["image_url"], 'http') !== false) { } else { if ($importZip === true) { $image_url = $zip->getStream('images/' . $layer["image_url"]); if (!$image_url) { echo $layer["image_url"] . __(' not found!<br>'); } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]])) { $importImage = UniteFunctionsWPRev::import_media('zip://' . $filepath . "#" . 'images/' . $layer["image_url"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]] = $importImage['path']; $layer["image_url"] = $importImage['path']; } } else { $layer["image_url"] = $alreadyImported['zip://' . $filepath . "#" . 'images/' . $layer["image_url"]]; } } } } } $layer["image_url"] = UniteFunctionsWPRev::getImageUrlFromPath($layer["image_url"]); $layers[$key] = $layer; } } $arrCreate = array(); $arrCreate["slider_id"] = $sliderID; $my_layers = json_encode($layers); if (empty($my_layers)) { $my_layers = stripslashes(json_encode($layers)); } $my_params = json_encode($params); if (empty($my_params)) { $my_params = stripslashes(json_encode($params)); } $arrCreate["layers"] = $my_layers; $arrCreate["params"] = $my_params; if ($sliderExists) { unset($arrCreate["slider_id"]); $this->db->update(GlobalsRevSlider::$table_static_slides, $arrCreate, array("slider_id" => $sliderID)); } else { $this->db->insert(GlobalsRevSlider::$table_static_slides, $arrCreate); } } } } catch (Exception $e) { $errorMessage = $e->getMessage(); return array("success" => false, "error" => $errorMessage, "sliderID" => $sliderID); } return array("success" => true, "sliderID" => $sliderID); }