function filterall($tag, $arg=NULL) { // this one doesn't return the result, so it's safe to use with the new 'all' filter if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); $args = func_get_args(); $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$tag, 'args'=>array_slice($args, 1)); }
function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg, $qcount, $qtime, $production_status; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug or TXP_DEBUG === 1) { dmp($q); } $start = getmicrotime(); $result = $method($q, $DB->link); $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (txpinterface === 'admin' or @$production_status == 'debug' or @$production_status == 'testing')) { $caller = $production_status == 'debug' ? n . join("\n", get_caller()) : ''; trigger_error(mysql_error() . n . $q . $caller, E_USER_WARNING); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg, $qcount, $qtime, $production_status; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug or TXP_DEBUG === 1) { dmp($q); dmp(mysql_error()); // dmp(debug_backtrace()); } $start = getmicrotime(); $result = $method($q, $DB->link); $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (@$production_status == 'debug' or @$production_status == 'test')) { trigger_error(mysql_error() . n . $q, E_USER_ERROR); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
/** * Test dump(). * * @return void */ public function testDump() { $beans = R::dispense('bean', 2); $beans[0]->name = 'hello'; $beans[1]->name = 'world'; $array = R::dump($beans); asrt(is_array($array), TRUE); foreach ($array as $item) { asrt(is_string($item), TRUE); } $beans[1]->name = 'world, and a very long string that should be shortened'; $array = R::dump($beans); asrt(is_array($array), TRUE); asrt(strpos($array[1], '...'), 35); //just to get 100% test cov, we dont need to test this dmp($beans); pass(); //test wrong input asrt(is_array(R::dump(NULL)), TRUE); asrt(count(R::dump(NULL)), 0); asrt(is_array(R::dump('')), TRUE); asrt(count(R::dump('')), 0); asrt(is_array(R::dump(1)), TRUE); asrt(count(R::dump(1)), 0); asrt(is_array(R::dump(TRUE)), TRUE); asrt(count(R::dump(FALSE)), 0); }
function safe_query($q = '', $debug = '') { global $DB, $txpcfg, $qcount, $qtime, $production_status; if ($debug) { dmp($q); } if (txpinterface === 'admin' or @$production_status != 'live') { $debug = true; } $r = $DB->query($q, $debug); return $r; /* if (!$q) return false; if ($debug or TXP_DEBUG === 1) { dmp($q); dmp(db_lasterror()); // dmp(debug_backtrace()); } $start = getmicrotime(); $result = db_query($q,$DB->link); $time = sprintf('%02.6f', getmicrotime() - $start); @$qtime += $time; @$qcount++; if ($result === false and (txpinterface === 'admin' or @$production_status == 'debug' or @$production_status == 'testing')) { $caller = ($production_status == 'debug') ? n . join("\n", get_caller()) : ''; trigger_error(db_lasterror() . n . $q . $caller, E_USER_WARNING); } trace_add("[SQL ($time): $q]"); if(!$result) return false; return $result; */ }
function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug) { dmp($q); dmp(mysql_error()); } $result = $method($q, $DB->link); if (!$result) { return false; } return $result; }
public function initialize($credentials) { if (!function_exists('curl_init')) { throw new Exception('stripe needs the CURL PHP extension.'); } dmp($credentials); $this->type = $credentials->type; $this->name = $credentials->name; $this->mode = $credentials->mode; $this->TRANSACTION_KEY = $credentials->fields['transaction_key']; $this->SECRET_KEY = $credentials->fields['secret_key']; Stripe::setApiKey($this->TRANSACTION_KEY); Stripe::setApiVersion("2014-11-05"); if (trim($credentials->mode) == 'test') { $this->AUTHORIZENET_SANDBOX = 'true'; } else { $this->AUTHORIZENET_SANDBOX = 'false'; } }
function safe_query($q = '', $debug = '', $unbuf = '') { global $DB, $txpcfg, $qcount, $production_status; $method = !$unbuf ? 'mysql_query' : 'mysql_unbuffered_query'; if (!$q) { return false; } if ($debug or TXP_DEBUG === 1) { dmp($q); dmp(mysql_error()); // dmp(debug_backtrace()); } $result = $method($q, $DB->link); @$qcount++; if ($result === false and (@$production_level == 'debug' or @$production_level == 'test')) { trigger_error(mysql_error() . n . $q, E_USER_ERROR); } if (!$result) { return false; } return $result; }
function process($name, $phone, $amount, $receipt) { $this->response_arr = array('RESULT' => 0, 'RESPONCE' => '', 'id' => 0); try { $pesa = new PLUSPEOPLE\PesaPi\PesaPi(); $transactions = $pesa->locateByReceipt($receipt); dmp($transactions[0]); if (count($transactions) == 0) { $this->response_arr = array('RESULT' => '1', 'RESPONCE' => 'Pending, Incoming Mobile Money Transaction Not found '); throw new Exception('Pending, Incoming Mobile Money Transaction Not found '); } else { $transaction = $transactions[0]; if ($transaction->getPhonenumber() != $phone) { $this->response_arr = array('RESULT' => '8', 'RESPONCE' => 'Invalid phone'); throw new Exception('Invalid phone'); } else { if ($transaction->getName() != $name) { $this->response_arr = array('RESULT' => '7', 'RESPONCE' => 'Invalid name'); throw new Exception('Invalid name'); } else { if ($transaction->getAmount() < $amount) { $this->response_arr = array('RESULT' => '3', 'RESPONCE' => 'Pending, Incoming Mobile Money Transaction Not found '); throw new Exception('Pending, Incoming Mobile Money Transaction Not found'); } else { if ($transaction->getAmount() > $amount) { $this->response_arr = array('RESULT' => '4', 'RESPONCE' => 'Pending, Incoming Mobile Money Transaction Not found '); throw new Exception('Pending, Incoming Mobile Money Transaction Not found'); } } } } $this->response_arr['id'] = $transaction->getId(); } } catch (Exception $e) { throw $e; } return $this->response_arr; }
/** * Save custom rates by quick setup * If a rate belongs to a month that have no custom rates defined, all custom rates for that month are generated based on default rate * * @param unknown_type $data */ function quickSetup($data) { dmp($data); for ($d = strtotime($data["start_date"]); $d <= strtotime($data["end_date"]);) { $dayString = date("Y-m-d", $d); $table = $this->getTable(); $rateObj = $table->getRateDetails($data["rate_id"], $dayString); if (!isset($rateObj)) { $month = date("m", $d); $year = date("Y", $d); $this->saveDefaultRates($data["rate_id"], $month, $year); $table = $this->getTable(); $rateObj = $table->getRateDetails($data["rate_id"], $dayString); } $weekDay = date("N", $d); if (!in_array($weekDay, $data["week_day"])) { $d = strtotime(date('Y-m-d', $d) . ' + 1 day '); continue; } if (isset($data["price"]) && strlen($data["price"]) > 0) { $rateObj->price = $data["price"]; } if (isset($data["availability"]) && strlen($data["availability"]) > 0) { $rateObj->availability = $data["availability"]; } if (isset($data["min_days"]) && strlen($data["min_days"]) > 0) { $rateObj->min_days = $data["min_days"]; } if (isset($data["max_days"]) && strlen($data["max_days"]) > 0) { $rateObj->max_days = $data["max_days"]; } if (isset($data["child_price"]) && strlen($data["child_price"]) > 0) { $rateObj->child_price = $data["child_price"]; } $this->saveRate($rateObj); $d = strtotime(date('Y-m-d', $d) . ' + 1 day '); } return true; }
/** * * import slideer handle (not ajax response) */ private static function importSliderHandle() { dmp("importing slider setings and data..."); $slider = new RevSlider(); $response = $slider->importSliderFromPost(); $sliderID = $response["sliderID"]; $viewBack = self::getViewUrl(self::VIEW_SLIDER, "id=" . $sliderID); if (empty($sliderID)) { $viewBack = self::getViewUrl(self::VIEW_SLIDERS); } //handle error if ($response["success"] == false) { $message = $response["error"]; dmp("<b>Error: " . $message . "</b>"); echo UniteFunctionsRev::getHtmlLink($viewBack, "Go Back"); } else { //handle success, js redirect. dmp("Slider Import Success, redirecting..."); echo "<script>location.href='{$viewBack}'</script>"; } exit; }
/** * * require settings file, the filename without .php */ protected static function requireSettings($settingsFile) { try { require self::$path_plugin . "settings/{$settingsFile}.php"; } catch (Exception $e) { echo "<br><br>Settings ({$settingsFile}) Error: <b>" . $e->getMessage() . "</b>"; dmp($e->getTraceAsString()); } }
/** * * get all defined constants list with values. */ public static function printDefinedConstants() { $arr = get_defined_constants(true); $arrUser = $arr["user"]; dmp($arrUser); exit; }
function testPatchApply() { dmp()->Match_Distance = 1000; dmp()->Match_Threshold = 0.5; dmp()->Patch_DeleteThreshold = 0.5; // Exact match. $patches = dmp()->patch_make("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog."); $results = dmp()->patch_apply($patches, "The quick brown fox jumps over the lazy dog."); assertEquivalent(array("That quick brown fox jumped over a lazy dog.", array(true, true)), $results); // Partial match. $results = dmp()->patch_apply($patches, "The quick red rabbit jumps over the tired tiger."); assertEquivalent(array("That quick red rabbit jumped over a tired tiger.", array(true, true)), $results); // Failed match. $results = dmp()->patch_apply($patches, "I am the very model of a modern major general."); assertEquivalent(array("I am the very model of a modern major general.", array(false, false)), $results); // Big delete, small change. $patches = dmp()->patch_make('x1234567890123456789012345678901234567890123456789012345678901234567890y', 'xabcy'); $results = dmp()->patch_apply($patches, 'x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y'); assertEquivalent(array('xabcy', array(true, true)), $results); // Big delete, big change 1. $patches = dmp()->patch_make('x1234567890123456789012345678901234567890123456789012345678901234567890y', 'xabcy'); $results = dmp()->patch_apply($patches, 'x12345678901234567890---------------++++++++++---------------12345678901234567890y'); assertEquivalent(array('xabc12345678901234567890---------------++++++++++---------------12345678901234567890y', array(false, true)), $results); // Big delete, big change 2. dmp()->Patch_DeleteThreshold = 0.6; $patches = dmp()->patch_make('x1234567890123456789012345678901234567890123456789012345678901234567890y', 'xabcy'); $results = dmp()->patch_apply($patches, 'x12345678901234567890---------------++++++++++---------------12345678901234567890y'); assertEquivalent(array('xabcy', array(true, true)), $results); dmp()->Patch_DeleteThreshold = 0.5; // Compensate for failed patch. dmp()->Match_Threshold = 0.0; dmp()->Match_Distance = 0; $patches = dmp()->patch_make('abcdefghijklmnopqrstuvwxyz--------------------1234567890', 'abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890'); $results = dmp()->patch_apply($patches, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890'); assertEquivalent(array('ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890', array(false, true)), $results); dmp()->Match_Threshold = 0.5; dmp()->Match_Distance = 1000; // No side effects. $patches = dmp()->patch_make('', 'test'); $patchstr = dmp()->patch_toText($patches); dmp()->patch_apply($patches, ''); assertEquals($patchstr, dmp()->patch_toText($patches)); // No side effects with major delete. $patches = dmp()->patch_make('The quick brown fox jumps over the lazy dog.', 'Woof'); $patchstr = dmp()->patch_toText($patches); dmp()->patch_apply($patches, 'The quick brown fox jumps over the lazy dog.'); assertEquals($patchstr, dmp()->patch_toText($patches)); // Edge exact match. $patches = dmp()->patch_make('', 'test'); $results = dmp()->patch_apply($patches, ''); assertEquivalent(array('test', array(true)), $results); // Near edge exact match. $patches = dmp()->patch_make('XY', 'XtestY'); $results = dmp()->patch_apply($patches, 'XY'); assertEquivalent(array('XtestY', array(true)), $results); // Edge partial match. $patches = dmp()->patch_make('y', 'y123'); $results = dmp()->patch_apply($patches, 'x'); assertEquivalent(array('x123', array(true)), $results); }
function query($q = '', $debug = '') { global $qcount, $qtime; if (!$q) { return false; } $start = getmicrotime(); $result = $this->DB->do_query($q, $this->DB->link); if ($debug or $this->_debug) { dmp($q, $result); } $time = sprintf('%02.6f', getmicrotime() - $start); @($qtime += $time); @$qcount++; if ($result === false and (txpinterface === 'admin' or !is_production_status('live'))) { $caller = is_production_status('debug') ? n . join("\n", get_caller()) : ''; trigger_error($this->DB->lasterror() . n . $q . $caller, E_USER_WARNING); } trace_add("[SQL ({$time}): {$q}]"); if (!$result) { return false; } return $result; }
/** * * get url contents */ public static function getUrlContents($url, $arrPost = array(), $method = "post", $debug = false) { $ch = curl_init(); $timeout = 0; $strPost = ''; foreach ($arrPost as $key => $value) { if (!empty($strPost)) { $strPost .= "&"; } $value = urlencode($value); $strPost .= "{$key}={$value}"; } //set curl options if (strtolower($method) == "post") { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost); } else { //get $url .= "?" . $strPost; } //remove me //Functions::addToLogFile(SERVICE_LOG_SERVICE, "url", $url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $headers = array(); $headers[] = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"; $headers[] = "Accept-Charset:utf-8;q=0.7,*;q=0.7"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if ($debug == true) { dmp($url); dmp($response); exit; } if ($response == false) { throw new Exception("getUrlContents Request failed"); } curl_close($ch); return $response; }
/** * * Enter description here ... */ protected static function updatePlugin($viewBack = false) { $linkBack = self::getViewUrl($viewBack); $htmlLinkBack = UniteFunctionsRev::getHtmlLink($linkBack, "Go Back"); //check if css table exist, if not, we need to verify that the current captions.css can be parsed if (UniteFunctionsWPRev::isDBTableExists(GlobalsRevSlider::TABLE_CSS_NAME)) { $captions = RevOperations::getCaptionsCssContentArray(); if ($captions === false) { $message = "CSS parse error! Please make sure your captions.css is valid CSS before updating the plugin!"; echo "<div style='color:#B80A0A;font-size:18px;'><b>Update Error: </b> {$message}</div><br>"; echo $htmlLinkBack; exit; } } $zip = new UniteZipRev(); try { if (function_exists("unzip_file") == false) { if (UniteZipRev::isZipExists() == false) { UniteFunctionsRev::throwError("The ZipArchive php extension not exists, can't extract the update file. Please turn it on in php ini."); } } dmp("Update in progress..."); $arrFiles = UniteFunctionsRev::getVal($_FILES, "update_file"); if (empty($arrFiles)) { UniteFunctionsRev::throwError("Update file don't found."); } $filename = UniteFunctionsRev::getVal($arrFiles, "name"); if (empty($filename)) { UniteFunctionsRev::throwError("Update filename not found."); } $fileType = UniteFunctionsRev::getVal($arrFiles, "type"); /* $fileType = strtolower($fileType); if($fileType != "application/zip") UniteFunctionsRev::throwError("The file uploaded is not zip."); */ $filepathTemp = UniteFunctionsRev::getVal($arrFiles, "tmp_name"); if (file_exists($filepathTemp) == false) { UniteFunctionsRev::throwError("Can't find the uploaded file."); } //crate temp folder UniteFunctionsRev::checkCreateDir(self::$path_temp); //create the update folder $pathUpdate = self::$path_temp . "update_extract/"; UniteFunctionsRev::checkCreateDir($pathUpdate); //remove all files in the update folder if (is_dir($pathUpdate)) { $arrNotDeleted = UniteFunctionsRev::deleteDir($pathUpdate, false); if (!empty($arrNotDeleted)) { $strNotDeleted = print_r($arrNotDeleted, true); UniteFunctionsRev::throwError("Could not delete those files from the update folder: {$strNotDeleted}"); } } //copy the zip file. $filepathZip = $pathUpdate . $filename; $success = move_uploaded_file($filepathTemp, $filepathZip); if ($success == false) { UniteFunctionsRev::throwError("Can't move the uploaded file here: " . $filepathZip . "."); } if (function_exists("unzip_file") == true) { WP_Filesystem(); $response = unzip_file($filepathZip, $pathUpdate); } else { $zip->extract($filepathZip, $pathUpdate); } //get extracted folder $arrFolders = UniteFunctionsRev::getFoldersList($pathUpdate); if (empty($arrFolders)) { UniteFunctionsRev::throwError("The update folder is not extracted"); } if (count($arrFolders) > 1) { UniteFunctionsRev::throwError("Extracted folders are more then 1. Please check the update file."); } //get product folder $productFolder = $arrFolders[0]; if (empty($productFolder)) { UniteFunctionsRev::throwError("Wrong product folder."); } if ($productFolder != self::$dir_plugin) { UniteFunctionsRev::throwError("The update folder don't match the product folder, please check the update file."); } $pathUpdateProduct = $pathUpdate . $productFolder . "/"; //check some file in folder to validate it's the real one: $checkFilepath = $pathUpdateProduct . $productFolder . ".php"; if (file_exists($checkFilepath) == false) { UniteFunctionsRev::throwError("Wrong update extracted folder. The file: " . $checkFilepath . " not found."); } //copy the plugin without the captions file. //$pathOriginalPlugin = $pathUpdate."copy/"; $pathOriginalPlugin = self::$path_plugin; $arrBlackList = array(); $arrBlackList[] = "rs-plugin/css/captions.css"; $arrBlackList[] = "rs-plugin/css/dynamic-captions.css"; $arrBlackList[] = "rs-plugin/css/static-captions.css"; UniteFunctionsRev::copyDir($pathUpdateProduct, $pathOriginalPlugin, "", $arrBlackList); //delete the update UniteFunctionsRev::deleteDir($pathUpdate); dmp("Updated Successfully, redirecting..."); echo "<script>location.href='{$linkBack}'</script>"; } catch (Exception $e) { $message = $e->getMessage(); $message .= " <br> Please update the plugin manually via the ftp"; echo "<div style='color:#B80A0A;font-size:18px;'><b>Update Error: </b> {$message}</div><br>"; echo $htmlLinkBack; exit; } }
function adi_menu($atts) { global $s, $out, $sort, $menu_id, $parent_class, $active_class, $exclude, $sections, $default_title, $default_first, $clone_title, $include_default, $class, $link_span, $list_id, $list_id_prefix, $active_li_class; extract(lAtts(array('active_class' => 'active_class', 'active_li_class' => '', 'class' => 'section_list', 'include_default' => '1', 'default_title' => 'Home', 'exclude' => '', 'sections' => '', 'sort' => 'NULL', 'menu_id' => 'mainmenu', 'parent_class' => 'menuparent', 'default_first' => '1', 'clone_title' => 'Summary', 'link_span' => '0', 'list_id' => '0', 'list_id_prefix' => 'menu_', 'debug' => '0'), $atts)); $default_title = trim($default_title); $clone_title = trim($clone_title); if (empty($clone_title)) { // don't want it to be empty $clone_title = 'Summary'; } $sections = trim($sections); // menu not output if sections = " " $sort = trim($sort); // MySQL error if sort = " " // set sort to database order by default empty($sort) ? $sort = 'NULL' : ($sort = doSlash($sort)); /* adi_menu - main procedure */ $section_list = adi_menu_section_list(FALSE); $hierarchy = adi_menu_hierarchy($section_list, '', 0); if ($debug) { echo "SECTION LIST<br/>"; dmp($section_list); echo "HIERARCHY<br/>"; dmp($hierarchy); } $out = adi_menu_markup($hierarchy, 0); return doWrap($out, '', ''); }
function save_click_info($arr_click_info, $timeshift = 0) { // User-agent parser require_once _TRACK_LIB_PATH . "/ua-parser/uaparser.php"; $parser = new UAParser(); // WURFL mobile database global $wurflManager; if ($timeshift != 0) { $click_date = date("Y-m-d H:i:s", strtotime($arr_click_info[0]) + $timeshift); } else { $click_date = $arr_click_info[0]; } $click_day = current(explode(' ', $click_date)); $click_hour = get_hour_by_date($click_date); $click_ip = $arr_click_info[1]; // Get geo from IP $geo_data = get_geodata($click_ip); $click_country = $geo_data['country']; $click_state = $geo_data['state']; $click_city = $geo_data['city']; $click_region = $geo_data['region']; $click_isp = $geo_data['isp']; // Get info from user agent $click_user_agent = $arr_click_info[2]; // Set empty initial values $is_mobile_device = false; $is_tablet = false; $is_phone = false; $brand_name = ''; $model_name = ''; $model_extra_info = ''; $device_os = ''; $device_os_version = ''; $device_browser = ''; $device_browser_version = ''; if (extension_loaded('xmlreader')) { $requestingDevice = $wurflManager->getDeviceForUserAgent($click_user_agent); $is_wireless = $requestingDevice->getCapability('is_wireless_device') == 'true'; $is_tablet = $requestingDevice->getCapability('is_tablet') == 'true'; $is_mobile_device = $is_wireless || $is_tablet; // Use WURFL database info for mobile devices only if ($is_mobile_device) { $is_phone = $requestingDevice->getCapability('can_assign_phone_number') == 'true'; $brand_name = $requestingDevice->getCapability('brand_name'); $model_name = $requestingDevice->getCapability('model_name'); $model_extra_info = $requestingDevice->getCapability('model_extra_info'); $device_os = $requestingDevice->getCapability('device_os'); $device_os_version = $requestingDevice->getCapability('device_os_version'); $device_browser = $requestingDevice->getCapability('mobile_browser'); $device_browser_version = $requestingDevice->getCapability('mobile_browser_version'); } else { // Use UAParser to get click info $result = $parser->parse($click_user_agent); $device_browser = $result->ua->family; $device_browser_version = $result->ua->toVersionString; $device_os = $result->os->family; $device_os_version = $result->os->toVersionString; } } $click_referer = $arr_click_info[3]; $click_link_name = $arr_click_info[4]; $click_link_source = $arr_click_info[5]; // Allow to use - as campaign/ads delimiter $link_ads_name = $arr_click_info[6]; if (strpos($link_ads_name, '-') !== false) { $click_link_campaign = current(explode('-', $link_ads_name)); $click_link_ads = substr($link_ads_name, strpos($link_ads_name, '-') + 1); } else { $click_link_campaign = $link_ads_name; $click_link_ads = ''; } $click_subid = $arr_click_info[7]; $click_subaccount = $arr_click_info[8]; $click_rule_id = $arr_click_info[9]; $click_out_id = $arr_click_info[10]; $click_is_unique = $arr_click_info[11]; $click_param1 = $arr_click_info[12]; $click_param2 = $arr_click_info[13]; $click_param3 = $arr_click_info[14]; $click_param4 = $arr_click_info[15]; $click_param5 = $arr_click_info[16]; // Parse get string if (!empty($arr_click_info[17])) { parse_str($arr_click_info[17], $click_get_params); } else { $click_get_params = array(); } if (!empty($_GET['debug'])) { dmp($arr_click_info); //die(); } $sql_click_params = array(); // Save this source params global $source_config; /* to_log('src', $click_link_source); to_log('src', $source_config); to_log('src', $click_get_params); */ $i = 1; // Source config exists if (array_key_exists($click_link_source, $source_config) and array_key_exists('params', $source_config[$click_link_source])) { // Выбираем именованные параметры из того, что пришло foreach ($source_config[$click_link_source]['params'] as $param_name => $param_info) { if (empty($param_info['url'])) { continue; } // "виртуальный" параметр, он определяется не ссылкой, а через другие параметры, см ниже if (array_key_exists($param_name, $click_get_params)) { $param_value = $click_get_params[$param_name]; if ($param_info['url'] == $param_value) { $param_value = ''; } // Пришло site_id={site_id}, то есть значение пустое $sql_click_params[] = "click_param_name{$i}='" . _str($param_name) . "', click_param_value{$i}='" . _str($param_value) . "'"; // Adwords передает в одном параметре и то что это спецразмещение и то, что это реклама в сайдбаре и сразу же позицию объявления. Поэтому мы разбиваем это значение на два параметра, Размещение (если t - Спецразмещение, если s - Реклама справа, если o или что-то другое - Не определено) и Позиция (где выводим значения как есть, то есть 1t1, 1s2 и т.д.) // Пример "виртуального параметра" if ($click_link_source == 'adwords' and $param_name == 'adposition') { $i++; $position_type = 0; if (strstr($param_value, 's') !== false) { $position_type = 's'; } if (strstr($param_value, 't') !== false) { $position_type = 't'; } $sql_click_params[] = "click_param_name{$i}='position_type', click_param_value{$i}='" . _str($position_type) . "'"; } // Поисковые слова Яндекса if ($click_link_source == 'yadirect' and $param_name == 'ad_id') { $i++; // 17 - для прямых ссылок, 3 - для обычных $referer = empty($arr_click_info[3]) ? $arr_click_info[17] : $arr_click_info[3]; $sql_click_params[] = "click_param_name{$i}='text', click_param_value{$i}='" . _str(parse_search_refer($referer)) . "'"; } unset($click_get_params[$param_name]); // Параметр отработан, убираем его чтобы остались только пользовательские } $i++; } // Удаляем параметры из чёрной списка (для трекеров, которые шлют нам много лишнего) if (isset($source_config[$click_link_source]['rapams_ignore'])) { foreach ($source_config[$click_link_source]['rapams_ignore'] as $param_name) { unset($click_get_params[$param_name]); } } // Удаляем дополнительные параметры "прямого перехода" $direct_params = array('utm_source', 'rule_name', 'utm_campaign'); foreach ($direct_params as $param_name) { unset($click_get_params[$param_name]); } /* foreach($click_get_params as $param_name => $param_value) { if(!empty($source_config[$click_link_source]['params'][$param_name]['n'])) { //$i = $source_config[$click_link_source]['params'][$param_name]['n'] + 5; $sql_click_params[]="click_param_name{$i}='"._str($param_name)."', click_param_value{$i}='"._str($param_value)."'"; // Adwords передает в одном параметре и то что это спецразмещение и то, что это реклама в сайдбаре и сразу же позицию объявления. Поэтому мы разбиваем это значение на два параметра, Размещение (если t - Спецразмещение, если s - Реклама справа, если o или что-то другое - Не определено) и Позиция (где выводим значения как есть, то есть 1t1, 1s2 и т.д.) if($click_link_source == 'adwords' and $param_name == 'adposition') { $position_type = 0; if(strstr($param_value, 's') !== false) { $position_type = 's'; } if(strstr($param_value, 't') !== false) { $position_type = 't'; } $sql_click_params[]="click_param_name10='position_type', click_param_value10='"._str($position_type)."'"; } unset($click_get_params[$param_name]); } } */ } // Пользовательские параметры $is_connected = false; $connected_subid = ''; foreach ($click_get_params as $param_name => $param_value) { if ($param_name == '_subid') { $pattern = '/\\d{14}x\\d{5}/'; preg_match_all($pattern, $param_value, $subids); foreach ($subids[0] as $t_key => $t_subid) { if ($t_subid != '') { $is_connected = true; $connected_subid = $t_subid; } break; } continue; } $sql_click_params[] = "click_param_name{$i}='" . _str($param_name) . "', click_param_value{$i}='" . _str($param_value) . "'"; $i++; // Maximum 15 get parameters allowed if ($i > 15) { break; } } $sql_click_params = implode(', ', $sql_click_params); if (strlen($sql_click_params) > 0) { $sql_click_params = ", {$sql_click_params}"; } // Click from landing page if ($is_connected) { // Get parent click id $sql = "select id from tbl_clicks where subid='" . _str($connected_subid) . "' limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if ($row['id'] > 0) { $parent_id = $row['id']; $sql = "update tbl_clicks set is_parent=1 where id='" . _str($parent_id) . "'"; mysql_query($sql); } else { $parent_id = 0; } } $sql = "insert ignore into tbl_clicks SET\n\t\t\t\tdate_add='" . _str($click_date) . "', \n\t\t\t\tdate_add_day='" . _str($click_day) . "', \n\t\t\t\tdate_add_hour='" . _str($click_hour) . "', \n\t\t\t\tuser_ip='" . _str($click_ip) . "', \n\t\t\t\tuser_agent='" . _str($click_user_agent) . "', \n\t\t\t\tuser_os='" . _str($device_os) . "', \n\t\t\t\tuser_os_version='" . _str($device_os_version) . "', \t\t\t\t\n\t\t\t\tuser_platform='" . _str($brand_name) . "', \n\t\t\t\tuser_platform_info='" . _str($model_name) . "', \t\t\n\t\t\t\tuser_platform_info_extra='" . _str($model_extra_info) . "',\t\t\t\n\t\t\t\tuser_browser='" . _str($device_browser) . "', \n\t\t\t\tuser_browser_version='" . _str($device_browser_version) . "',\t\t\t\t\t\n\t\t\t\tis_mobile_device='" . _str($is_mobile_device) . "', \n\t\t\t\tis_phone='" . _str($is_phone) . "', \t\t\n\t\t\t\tis_tablet='" . _str($is_tablet) . "', \t\t\t\t\t\n\t\t\t\tcountry='" . _str($click_country) . "', \n\t\t\t\tstate='" . _str($click_state) . "', \n\t\t\t\tcity='" . _str($click_city) . "', \n\t\t\t\tregion='" . _str($click_region) . "', \n\t\t\t\tisp='" . _str($click_isp) . "', \n\t\t\t\trule_id='" . _str($click_rule_id) . "', \n\t\t\t\tout_id='" . _str($click_out_id) . "', \n\t\t\t\tsubid='" . _str($click_subid) . "', \n\t\t\t\tis_connected='" . _str($is_connected) . "', \n\t\t\t\tis_unique='" . _str($click_is_unique) . "', \n\t\t\t\tparent_id='" . _str($parent_id) . "', \n\t\t\t\tsubaccount='" . _str($click_subaccount) . "', \n\t\t\t\tsource_name='" . _str($click_link_source) . "', \n\t\t\t\tcampaign_name='" . _str($click_link_campaign) . "', \n\t\t\t\tads_name='" . _str($click_link_ads) . "', \n\t\t\t\treferer='" . _str($click_referer) . "', \n\t\t\t\tsearch_string='', \n\t\t\t\tcampaign_param1='" . _str($click_param1) . "', \n\t\t\t\tcampaign_param2='" . _str($click_param2) . "', \n\t\t\t\tcampaign_param3='" . _str($click_param3) . "', \n\t\t\t\tcampaign_param4='" . _str($click_param4) . "', \n\t\t\t\tcampaign_param5='" . _str($click_param5) . "'\n\t\t\t\t{$sql_click_params}"; //echo $sql . '<br />'; echo $click_subid . ' '; mysql_query($sql); // or die($sql . '<br >' . mysql_error()); }
$arrIDs = explode(",", $ids); $arrItems = UniteFunctionsWPUG::getArrItemsFromAttachments($arrIDs); //output gallery $objItems = new UniteGalleryItems(); $arrUniteItems = $objItems->getItemsFromArray($arrItems); $content = HelperUG::outputGallery($alias, null, "alias", $arrUniteItems); return $content; } add_filter('post_gallery', 'unitegallery_postgallery', 60, 4); //------------------------------------------------------------- // add another size add_image_size("ug_big", 768, 768); //------------------------------------------------------------- if (is_admin()) { //load admin part require_once $currentFolder . "/unitegallery_admin.php"; require_once $currentFolder . "/inc_php/framework/provider/provider_admin.class.php"; $UGproductAdmin = new UniteProviderAdminUG($mainFilepath); } else { //load front part require_once $currentFolder . "/inc_php/framework/provider/provider_front.class.php"; $UGproductFront = new UniteProviderFrontUG($mainFilepath); } } catch (Exception $e) { $message = $e->getMessage(); $trace = $e->getTraceAsString(); echo "Unite Gallery Error: <b>" . $message . "</b>"; if (GlobalsUG::SHOW_TRACE == true) { dmp($trace); } }
/** * * Update Plugin */ public static function updatePlugin() { try { //verify nonce: $nonce = UniteFunctionsUG::getPostVariable("nonce"); $isVerified = wp_verify_nonce($nonce, "unitegallery_actions"); if ($isVerified == false) { UniteFunctionsUG::throwError("Security error"); } $linkBack = HelperUG::getGalleriesView(); $htmlLinkBack = UniteFunctionsUG::getHtmlLink($linkBack, "Go Back"); //check if zip exists $zip = new UniteZipUG(); if (function_exists("unzip_file") == false) { if (UniteZipUG::isZipExists() == false) { UniteFunctionsUG::throwError("The ZipArchive php extension not exists, can't extract the update file. Please turn it on in php ini."); } } dmp("Update in progress..."); $arrFiles = UniteFunctionsUG::getVal($_FILES, "update_file"); if (empty($arrFiles)) { UniteFunctionsUG::throwError("Update file don't found."); } $filename = UniteFunctionsUG::getVal($arrFiles, "name"); if (empty($filename)) { UniteFunctionsIG::throwError("Update filename not found."); } $fileType = UniteFunctionsUG::getVal($arrFiles, "type"); $fileType = strtolower($fileType); $arrMimeTypes = array(); $arrMimeTypes[] = "application/zip"; $arrMimeTypes[] = "application/x-zip"; $arrMimeTypes[] = "application/x-zip-compressed"; $arrMimeTypes[] = "application/octet-stream"; $arrMimeTypes[] = "application/x-compress"; $arrMimeTypes[] = "application/x-compressed"; $arrMimeTypes[] = "multipart/x-zip"; if (in_array($fileType, $arrMimeTypes) == false) { UniteFunctionsUG::throwError("The file uploaded is not zip."); } $filepathTemp = UniteFunctionsUG::getVal($arrFiles, "tmp_name"); if (file_exists($filepathTemp) == false) { UniteFunctionsUG::throwError("Can't find the uploaded file."); } //crate temp folder $pathTemp = GlobalsUG::$pathPlugin . "temp/"; UniteFunctionsUG::checkCreateDir($pathTemp); //create the update folder $pathUpdate = $pathTemp . "update_extract/"; UniteFunctionsUG::checkCreateDir($pathUpdate); if (!is_dir($pathUpdate)) { UniteFunctionsUG::throwError("Could not create temp extract path"); } //remove all files in the update folder $arrNotDeleted = UniteFunctionsUG::deleteDir($pathUpdate, false); if (!empty($arrNotDeleted)) { $strNotDeleted = print_r($arrNotDeleted, true); UniteFunctionsUG::throwError("Could not delete those files from the update folder: {$strNotDeleted}"); } //copy the zip file. $filepathZip = $pathUpdate . $filename; $success = move_uploaded_file($filepathTemp, $filepathZip); if ($success == false) { UniteFunctionsUG::throwError("Can't move the uploaded file here: " . $filepathZip . "."); } //extract files: if (function_exists("unzip_file") == true) { WP_Filesystem(); $response = unzip_file($filepathZip, $pathUpdate); } else { $zip->extract($filepathZip, $pathUpdate); } //check for internal zip in case that cocecanyon original zip was uploaded self::updatePlugin_checkUnpackInnerZip($pathUpdate, $filename); //get extracted folder $arrFolders = UniteFunctionsUG::getDirList($pathUpdate); if (empty($arrFolders)) { UniteFunctionsUG::throwError("The update folder is not extracted"); } //get product folder $productFolder = null; if (count($arrFolders) == 1) { $productFolder = $arrFolders[0]; } else { foreach ($arrFolders as $folder) { if ($folder != "documentation") { $productFolder = $folder; } } } if (empty($productFolder)) { UniteFunctionsUG::throwError("Wrong product folder."); } $pathUpdateProduct = $pathUpdate . $productFolder . "/"; //check some file in folder to validate it's the real one: $checkFilepath = $pathUpdateProduct . "unitegallery.php"; if (file_exists($checkFilepath) == false) { UniteFunctionsUG::throwError("Wrong update extracted folder. The file: " . $checkFilepath . " not found."); } //copy the plugin without the captions file. $pathOriginalPlugin = GlobalsUG::$pathPlugin; $arrBlackList = array(); UniteFunctionsUG::copyDir($pathUpdateProduct, $pathOriginalPlugin, "", $arrBlackList); //delete the update UniteFunctionsUG::deleteDir($pathUpdate); //change folder to original (if updated to full version) if ($productFolder == "unitegallery") { $pathRename = str_replace("unite-gallery-lite", "unitegallery", $pathOriginalPlugin); if ($pathRename != $pathOriginalPlugin) { $success = @rename($pathOriginalPlugin, $pathRename); if ($success == true) { //activate plugin $pluginFile = $pathRename . "unitegallery.php"; if (file_exists($pluginFile)) { $activateSuccess = UniteFunctionsWPUG::activatePlugin($pluginFile); if ($activateSuccess == false) { $linkBack = admin_url("plugins.php"); } //link to plugin activate } } } } dmp("Updated Successfully, redirecting..."); echo "<script>location.href='{$linkBack}'</script>"; } catch (Exception $e) { //remove all files in the update folder UniteFunctionsUG::deleteDir($pathUpdate); $message = $e->getMessage(); $message .= " <br> Please update the plugin manually via the ftp"; echo "<div style='color:#B80A0A;font-size:18px;'><b>Update Error: </b> {$message}</div><br>"; echo $htmlLinkBack; exit; } }
/** * * put inline error message in a box. */ private function putErrorMessage($message, $trace) { ?> <div style="width:800px;height:300px;margin-bottom:10px;border:1px solid black;overflow:auto;"> <div style="padding-top:40px;color:red;font-size:16px;text-align:center;"> ShowBiz Error: <?php echo $message; ?> </div> <br> <?php if (!empty($trace)) { dmp($trace); } ?> </div> <?php }
/** * * 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); }
/** * * import slider from multipart form */ public function importSliderFromPost($updateAnim = true, $updateStatic = true, $exactfilepath = false, $is_template = false, $single_slide = false, $updateNavigation = true) { try { $sliderID = RevSliderFunctions::getPostVariable("sliderid"); $sliderExists = !empty($sliderID); if ($sliderExists) { $this->initByID($sliderID); } if ($exactfilepath !== false) { $filepath = $exactfilepath; } else { switch ($_FILES['import_file']['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_NO_FILE: RevSliderFunctions::throwError(__('No file sent.', 'revslider')); case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: RevSliderFunctions::throwError(__('Exceeded filesize limit.', 'revslider')); default: break; } $filepath = $_FILES["import_file"]["tmp_name"]; } if (file_exists($filepath) == false) { RevSliderFunctions::throwError(__('Import file not found!!!', 'revslider')); } $importZip = false; WP_Filesystem(); global $wp_filesystem; $upload_dir = wp_upload_dir(); $d_path = $upload_dir['basedir'] . '/rstemp/'; $unzipfile = unzip_file($filepath, $d_path); if (is_wp_error($unzipfile)) { define('FS_METHOD', 'direct'); //lets try direct. WP_Filesystem(); //WP_Filesystem() needs to be called again since now we use direct ! //@chmod($filepath, 0775); $unzipfile = unzip_file($filepath, $d_path); if (is_wp_error($unzipfile)) { $d_path = RS_PLUGIN_PATH . 'rstemp/'; $unzipfile = unzip_file($filepath, $d_path); if (is_wp_error($unzipfile)) { $f = basename($filepath); $d_path = str_replace($f, '', $filepath); $unzipfile = unzip_file($filepath, $d_path); } } } if (!is_wp_error($unzipfile)) { $importZip = true; //raus damit.. //read all files needed $content = $wp_filesystem->exists($d_path . 'slider_export.txt') ? $wp_filesystem->get_contents($d_path . 'slider_export.txt') : ''; if ($content == '') { RevSliderFunctions::throwError(__('slider_export.txt does not exist!', 'revslider')); } $animations = $wp_filesystem->exists($d_path . 'custom_animations.txt') ? $wp_filesystem->get_contents($d_path . 'custom_animations.txt') : ''; $dynamic = $wp_filesystem->exists($d_path . 'dynamic-captions.css') ? $wp_filesystem->get_contents($d_path . 'dynamic-captions.css') : ''; $static = $wp_filesystem->exists($d_path . 'static-captions.css') ? $wp_filesystem->get_contents($d_path . 'static-captions.css') : ''; $navigations = $wp_filesystem->exists($d_path . 'navigation.txt') ? $wp_filesystem->get_contents($d_path . 'navigation.txt') : ''; $uid_check = $wp_filesystem->exists($d_path . 'info.cfg') ? $wp_filesystem->get_contents($d_path . 'info.cfg') : ''; $version_check = $wp_filesystem->exists($d_path . 'version.cfg') ? $wp_filesystem->get_contents($d_path . 'version.cfg') : ''; if ($is_template !== false) { if ($uid_check != $is_template) { return array("success" => false, "error" => __('Please select the correct zip file, checksum failed!', 'revslider')); } } else { //someone imported a template base Slider, check if it is existing in Base Sliders, if yes, check if it was imported if ($uid_check !== '') { $tmpl = new RevSliderTemplate(); $tmpl_slider = $tmpl->getThemePunchTemplateSliders(); foreach ($tmpl_slider as $tp_slider) { if (!isset($tp_slider['installed'])) { continue; } if ($tp_slider['uid'] == $uid_check) { $is_template = $uid_check; break; } } } } $db = new RevSliderDB(); //update/insert custom animations $animations = @unserialize($animations); if (!empty($animations)) { foreach ($animations as $key => $animation) { //$animation['id'], $animation['handle'], $animation['params'] $exist = $db->fetch(RevSliderGlobals::$table_layer_anims, $db->prepare("handle = %s", array($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(RevSliderGlobals::$table_layer_anims, $arrUpdate, array('handle' => $animation['handle'])); $anim_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']))); $anim_id = $db->insert(RevSliderGlobals::$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']))); $anim_id = $db->insert(RevSliderGlobals::$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-' . $anim_id . '"', 'customout-' . $anim_id . '"'), $content); } dmp(__("animations imported!", 'revslider')); } //overwrite/append static-captions.css if (!empty($static)) { if ($updateStatic == "true") { //overwrite file RevSliderOperations::updateStaticCss($static); } elseif ($updateStatic == 'none') { //do nothing } else { //append $static_cur = RevSliderOperations::getStaticCss(); $static = $static_cur . "\n" . $static; RevSliderOperations::updateStaticCss($static); } } //overwrite/create dynamic-captions.css //parse css to classes $dynamicCss = RevSliderCssParser::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, ',') !== false && strpos($class, '.tp-caption') !== false) { //we have something like .tp-caption.redclass, .redclass $class_t = explode(',', $class); foreach ($class_t as $k => $cl) { if (strpos($cl, '.tp-caption') !== false) { $class = $cl; } } } 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); $arrInsert["settings"] = ''; } //check if class exists $result = $db->fetch(RevSliderGlobals::$table_css, $db->prepare("handle = %s", array($class))); if (!empty($result)) { //update $db->update(RevSliderGlobals::$table_css, $arrInsert, array('handle' => $class)); } else { //insert $arrInsert["handle"] = $class; $db->insert(RevSliderGlobals::$table_css, $arrInsert); } } dmp(__("dynamic styles imported!", 'revslider')); } //update/insert custom animations $navigations = @unserialize($navigations); if (!empty($navigations)) { foreach ($navigations as $key => $navigation) { $exist = $db->fetch(RevSliderGlobals::$table_navigation, $db->prepare("handle = %s", array($navigation['handle']))); unset($navigation['id']); $rh = $navigation["handle"]; if (!empty($exist)) { //create new navigation, get the ID if ($updateNavigation == "true") { //overwrite navigation if exists unset($navigation['handle']); $db->update(RevSliderGlobals::$table_navigation, $navigation, array('handle' => $rh)); } else { //insert with new handle $navigation["handle"] = $navigation['handle'] . '-' . date('is'); $navigation["name"] = $navigation['name'] . '-' . date('is'); $content = str_replace($rh . '"', $navigation["handle"] . '"', $content); $navigation["css"] = str_replace('.' . $rh, '.' . $navigation["handle"], $navigation["css"]); //change css class to the correct new class $navi_id = $db->insert(RevSliderGlobals::$table_navigation, $navigation); } } else { $navi_id = $db->insert(RevSliderGlobals::$table_navigation, $navigation); } } dmp(__("navigations imported!", 'revslider')); } } else { $message = $unzipfile->get_error_message(); $wp_filesystem->delete($d_path, true); return array("success" => false, "error" => $message); } //$content = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $content); //clear errors in string //deprecated in newest php version $content = preg_replace_callback('!s:(\\d+):"(.*?)";!', array('RevSliderSlider', 'clear_error_in_string'), $content); //clear errors in string $arrSlider = @unserialize($content); if (empty($arrSlider)) { $wp_filesystem->delete($d_path, true); RevSliderFunctions::throwError(__('Wrong export slider file format! Please make sure that the uploaded file is either a zip file with a correct slider_export.txt in the root of it or an valid slider_export.txt file.', 'revslider')); } //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"] = RevSliderFunctionsWP::getImageUrlFromPath($sliderParams["background_image"]); } $import_statics = true; if (isset($sliderParams['enable_static_layers'])) { if ($sliderParams['enable_static_layers'] == 'off') { $import_statics = false; } unset($sliderParams['enable_static_layers']); } $sliderParams['version'] = $version_check; $json_params = json_encode($sliderParams); //update slider or create new if ($sliderExists) { $arrUpdate = array("params" => $json_params); $this->db->update(RevSliderGlobals::$table_sliders, $arrUpdate, array("id" => $sliderID)); } else { //new slider $arrInsert = array(); $arrInsert['params'] = $json_params; //check if Slider with title and/or alias exists, if yes change both to stay unique $arrInsert['title'] = RevSliderFunctions::getVal($sliderParams, 'title', 'Slider1'); $arrInsert['alias'] = RevSliderFunctions::getVal($sliderParams, 'alias', 'slider1'); if ($is_template === false) { //we want to stay at the given alias if we are a template $talias = $arrInsert['alias']; $ti = 1; while ($this->isAliasExistsInDB($talias)) { //set a new alias and title if its existing in database $talias = $arrInsert['alias'] . $ti; $ti++; } if ($talias !== $arrInsert['alias']) { $sliderParams['title'] = $talias; $sliderParams['alias'] = $talias; $arrInsert['title'] = $talias; $arrInsert['alias'] = $talias; $json_params = json_encode($sliderParams); $arrInsert['params'] = $json_params; } } if ($is_template !== false) { //add that we are an template $arrInsert['type'] = 'template'; $sliderParams['uid'] = $is_template; $json_params = json_encode($sliderParams); $arrInsert['params'] = $json_params; } $sliderID = $this->db->insert(RevSliderGlobals::$table_sliders, $arrInsert); } //-------- Slides Handle ----------- //delete current slides if ($sliderExists) { $this->deleteAllSlides(); } //create all slides $arrSlides = $arrSlider["slides"]; $alreadyImported = array(); //$content_url = content_url(); $upload_dir = wp_upload_dir(); $content_url = $upload_dir['baseurl'] . '/revslider/assets/svg/'; //wpml compatibility $slider_map = array(); foreach ($arrSlides as $sl_key => $slide) { $params = $slide["params"]; $layers = $slide["layers"]; $settings = isset($slide["settings"]) ? $slide["settings"] : ''; //convert params images: if ($importZip === true) { //we have a zip, check if exists //remove image_id as it is not needed in import if (isset($params['image_id'])) { unset($params['image_id']); } if (isset($params["image"])) { $params["image"] = RevSliderBase::check_file_in_zip($d_path, $params["image"], $sliderParams["alias"], $alreadyImported); $params["image"] = RevSliderFunctionsWP::getImageUrlFromPath($params["image"]); } if (isset($params["background_image"])) { $params["background_image"] = RevSliderBase::check_file_in_zip($d_path, $params["background_image"], $sliderParams["alias"], $alreadyImported); $params["background_image"] = RevSliderFunctionsWP::getImageUrlFromPath($params["background_image"]); } if (isset($params["slide_thumb"])) { $params["slide_thumb"] = RevSliderBase::check_file_in_zip($d_path, $params["slide_thumb"], $sliderParams["alias"], $alreadyImported); $params["slide_thumb"] = RevSliderFunctionsWP::getImageUrlFromPath($params["slide_thumb"]); } if (isset($params["show_alternate_image"])) { $params["show_alternate_image"] = RevSliderBase::check_file_in_zip($d_path, $params["show_alternate_image"], $sliderParams["alias"], $alreadyImported); $params["show_alternate_image"] = RevSliderFunctionsWP::getImageUrlFromPath($params["show_alternate_image"]); } if (isset($params['background_type']) && $params['background_type'] == 'html5') { if (isset($params['slide_bg_html_mpeg']) && $params['slide_bg_html_mpeg'] != '') { $params['slide_bg_html_mpeg'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $params["slide_bg_html_mpeg"], $sliderParams["alias"], $alreadyImported, true)); } if (isset($params['slide_bg_html_webm']) && $params['slide_bg_html_webm'] != '') { $params['slide_bg_html_webm'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $params["slide_bg_html_webm"], $sliderParams["alias"], $alreadyImported, true)); } if (isset($params['slide_bg_html_ogv']) && $params['slide_bg_html_ogv'] != '') { $params['slide_bg_html_ogv'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $params["slide_bg_html_ogv"], $sliderParams["alias"], $alreadyImported, true)); } } } //convert layers images: foreach ($layers as $key => $layer) { //import if exists in zip folder if ($importZip === true) { //we have a zip, check if exists if (isset($layer["image_url"])) { $layer["image_url"] = RevSliderBase::check_file_in_zip($d_path, $layer["image_url"], $sliderParams["alias"], $alreadyImported); $layer["image_url"] = RevSliderFunctionsWP::getImageUrlFromPath($layer["image_url"]); } if (isset($layer['type']) && ($layer['type'] == 'video' || $layer['type'] == 'audio')) { $video_data = isset($layer['video_data']) ? (array) $layer['video_data'] : array(); if (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] == 'html5') { if (isset($video_data['urlPoster']) && $video_data['urlPoster'] != '') { $video_data['urlPoster'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlPoster"], $sliderParams["alias"], $alreadyImported)); } if (isset($video_data['urlMp4']) && $video_data['urlMp4'] != '') { $video_data['urlMp4'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlMp4"], $sliderParams["alias"], $alreadyImported, true)); } if (isset($video_data['urlWebm']) && $video_data['urlWebm'] != '') { $video_data['urlWebm'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlWebm"], $sliderParams["alias"], $alreadyImported, true)); } if (isset($video_data['urlOgv']) && $video_data['urlOgv'] != '') { $video_data['urlOgv'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlOgv"], $sliderParams["alias"], $alreadyImported, true)); } } elseif (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] != 'html5') { //video cover image if ($video_data['video_type'] == 'audio') { if (isset($video_data['urlAudio']) && $video_data['urlAudio'] != '') { $video_data['urlAudio'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlAudio"], $sliderParams["alias"], $alreadyImported, true)); } } else { if (isset($video_data['previewimage']) && $video_data['previewimage'] != '') { $video_data['previewimage'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["previewimage"], $sliderParams["alias"], $alreadyImported)); } } } $layer['video_data'] = $video_data; } if (isset($layer['type']) && $layer['type'] == 'svg') { if (isset($layer['svg']) && isset($layer['svg']->src)) { if (strpos($layer['svg']->src, 'revslider-whiteboard-addon') !== false) { $layer['svg']->src = content_url() . $layer['svg']->src; } else { $layer['svg']->src = str_replace('/plugins/revslider/public/assets/assets/svg/', '', $content_url . $layer['svg']->src); } } } } $layer['text'] = stripslashes($layer['text']); $layers[$key] = $layer; } $arrSlides[$sl_key]['layers'] = $layers; //create new slide $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)); } $my_settings = json_encode($settings); if (empty($my_settings)) { $my_settings = stripslashes(json_encode($settings)); } $arrCreate["layers"] = $my_layers; $arrCreate["params"] = $my_params; $arrCreate["settings"] = $my_settings; $last_id = $this->db->insert(RevSliderGlobals::$table_slides, $arrCreate); if (isset($slide['id'])) { $slider_map[$slide['id']] = $last_id; } } //change for WPML the parent IDs if necessary if (!empty($slider_map)) { foreach ($arrSlides as $sl_key => $slide) { if (isset($slide['params']['parentid']) && isset($slider_map[$slide['params']['parentid']])) { $update_id = $slider_map[$slide['id']]; $parent_id = $slider_map[$slide['params']['parentid']]; $arrCreate = array(); $arrCreate["params"] = $slide['params']; $arrCreate["params"]['parentid'] = $parent_id; $my_params = json_encode($arrCreate["params"]); if (empty($my_params)) { $my_params = stripslashes(json_encode($arrCreate["params"])); } $arrCreate["params"] = $my_params; $this->db->update(RevSliderGlobals::$table_slides, $arrCreate, array("id" => $update_id)); } $did_change = false; foreach ($slide['layers'] as $key => $value) { if (isset($value['layer_action'])) { if (isset($value['layer_action']->jump_to_slide) && !empty($value['layer_action']->jump_to_slide)) { $value['layer_action']->jump_to_slide = (array) $value['layer_action']->jump_to_slide; foreach ($value['layer_action']->jump_to_slide as $jtsk => $jtsval) { if (isset($slider_map[$jtsval])) { $slide['layers'][$key]['layer_action']->jump_to_slide[$jtsk] = $slider_map[$jtsval]; $did_change = true; } } } } $link_slide = RevSliderFunctions::getVal($value, 'link_slide', false); if ($link_slide != false && $link_slide !== 'nothing') { //link to slide/scrollunder is set, move it to actions if (!isset($slide['layers'][$key]['layer_action'])) { $slide['layers'][$key]['layer_action'] = new stdClass(); } switch ($link_slide) { case 'link': $link = RevSliderFunctions::getVal($value, 'link'); $link_open_in = RevSliderFunctions::getVal($value, 'link_open_in'); $slide['layers'][$key]['layer_action']->action = array('a' => 'link'); $slide['layers'][$key]['layer_action']->link_type = array('a' => 'a'); $slide['layers'][$key]['layer_action']->image_link = array('a' => $link); $slide['layers'][$key]['layer_action']->link_open_in = array('a' => $link_open_in); unset($slide['layers'][$key]['link']); unset($slide['layers'][$key]['link_open_in']); case 'next': $slide['layers'][$key]['layer_action']->action = array('a' => 'next'); break; case 'prev': $slide['layers'][$key]['layer_action']->action = array('a' => 'prev'); break; case 'scroll_under': $scrollunder_offset = RevSliderFunctions::getVal($value, 'scrollunder_offset'); $slide['layers'][$key]['layer_action']->action = array('a' => 'scroll_under'); $slide['layers'][$key]['layer_action']->scrollunder_offset = array('a' => $scrollunder_offset); unset($slide['layers'][$key]['scrollunder_offset']); break; default: //its an ID, so its a slide ID $slide['layers'][$key]['layer_action']->action = array('a' => 'jumpto'); $slide['layers'][$key]['layer_action']->jump_to_slide = array('a' => $slider_map[$link_slide]); break; } $slide['layers'][$key]['layer_action']->tooltip_event = array('a' => 'click'); unset($slide['layers'][$key]['link_slide']); $did_change = true; } if ($did_change === true) { $arrCreate = array(); $my_layers = json_encode($slide['layers']); if (empty($my_layers)) { $my_layers = stripslashes(json_encode($layers)); } $arrCreate['layers'] = $my_layers; $this->db->update(RevSliderGlobals::$table_slides, $arrCreate, array("id" => $slider_map[$slide['id']])); } } } } //check if static slide exists and import if (isset($arrSlider['static_slides']) && !empty($arrSlider['static_slides']) && $import_statics) { $static_slide = $arrSlider['static_slides']; foreach ($static_slide as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; $settings = isset($slide["settings"]) ? $slide["settings"] : ''; //remove image_id as it is not needed in import if (isset($params['image_id'])) { unset($params['image_id']); } //convert params images: if (isset($params["image"])) { //import if exists in zip folder if (strpos($params["image"], 'http') !== false) { } else { if (trim($params["image"]) !== '') { if ($importZip === true) { //we have a zip, check if exists $image = $wp_filesystem->exists($d_path . 'images/' . $params["image"]); if (!$image) { echo $params["image"] . __(' not found!<br>', 'revslider'); } else { if (!isset($alreadyImported['images/' . $params["image"]])) { $importImage = RevSliderFunctionsWP::import_media($d_path . 'images/' . $params["image"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['images/' . $params["image"]] = $importImage['path']; $params["image"] = $importImage['path']; } } else { $params["image"] = $alreadyImported['images/' . $params["image"]]; } } } } $params["image"] = RevSliderFunctionsWP::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 (strpos($layer["image_url"], 'http') !== false) { } else { if ($importZip === true) { //we have a zip, check if exists $image_url = $wp_filesystem->exists($d_path . 'images/' . $layer["image_url"]); if (!$image_url) { echo $layer["image_url"] . __(' not found!<br>'); } else { if (!isset($alreadyImported['images/' . $layer["image_url"]])) { $importImage = RevSliderFunctionsWP::import_media($d_path . 'images/' . $layer["image_url"], $sliderParams["alias"] . '/'); if ($importImage !== false) { $alreadyImported['images/' . $layer["image_url"]] = $importImage['path']; $layer["image_url"] = $importImage['path']; } } else { $layer["image_url"] = $alreadyImported['images/' . $layer["image_url"]]; } } } } } $layer["image_url"] = RevSliderFunctionsWP::getImageUrlFromPath($layer["image_url"]); } $layer['text'] = stripslashes($layer['text']); if (isset($layer['type']) && ($layer['type'] == 'video' || $layer['type'] == 'audio')) { $video_data = isset($layer['video_data']) ? (array) $layer['video_data'] : array(); if (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] == 'html5') { if (isset($video_data['urlPoster']) && $video_data['urlPoster'] != '') { $video_data['urlPoster'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlPoster"], $sliderParams["alias"], $alreadyImported)); } if (isset($video_data['urlMp4']) && $video_data['urlMp4'] != '') { $video_data['urlMp4'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlMp4"], $sliderParams["alias"], $alreadyImported, true)); } if (isset($video_data['urlWebm']) && $video_data['urlWebm'] != '') { $video_data['urlWebm'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlWebm"], $sliderParams["alias"], $alreadyImported, true)); } if (isset($video_data['urlOgv']) && $video_data['urlOgv'] != '') { $video_data['urlOgv'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlOgv"], $sliderParams["alias"], $alreadyImported, true)); } } elseif (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] != 'html5') { //video cover image if ($video_data['video_type'] == 'audio') { if (isset($video_data['urlAudio']) && $video_data['urlAudio'] != '') { $video_data['urlAudio'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["urlAudio"], $sliderParams["alias"], $alreadyImported, true)); } } else { if (isset($video_data['previewimage']) && $video_data['previewimage'] != '') { $video_data['previewimage'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($d_path, $video_data["previewimage"], $sliderParams["alias"], $alreadyImported)); } } } $layer['video_data'] = $video_data; } if (isset($layer['type']) && $layer['type'] == 'svg') { if (isset($layer['svg']) && isset($layer['svg']->src)) { $layer['svg']->src = str_replace('/plugins/revslider/public/assets/assets/svg/', '', $content_url . $layer['svg']->src); } } if (isset($layer['layer_action'])) { if (isset($layer['layer_action']->jump_to_slide) && !empty($layer['layer_action']->jump_to_slide)) { foreach ($layer['layer_action']->jump_to_slide as $jtsk => $jtsval) { if (isset($slider_map[$jtsval])) { $layer['layer_action']->jump_to_slide[$jtsk] = $slider_map[$jtsval]; } } } } $link_slide = RevSliderFunctions::getVal($layer, 'link_slide', false); if ($link_slide != false && $link_slide !== 'nothing') { //link to slide/scrollunder is set, move it to actions if (!isset($layer['layer_action'])) { $layer['layer_action'] = new stdClass(); } switch ($link_slide) { case 'link': $link = RevSliderFunctions::getVal($layer, 'link'); $link_open_in = RevSliderFunctions::getVal($layer, 'link_open_in'); $layer['layer_action']->action = array('a' => 'link'); $layer['layer_action']->link_type = array('a' => 'a'); $layer['layer_action']->image_link = array('a' => $link); $layer['layer_action']->link_open_in = array('a' => $link_open_in); unset($layer['link']); unset($layer['link_open_in']); case 'next': $layer['layer_action']->action = array('a' => 'next'); break; case 'prev': $layer['layer_action']->action = array('a' => 'prev'); break; case 'scroll_under': $scrollunder_offset = RevSliderFunctions::getVal($value, 'scrollunder_offset'); $layer['layer_action']->action = array('a' => 'scroll_under'); $layer['layer_action']->scrollunder_offset = array('a' => $scrollunder_offset); unset($layer['scrollunder_offset']); break; default: //its an ID, so its a slide ID $layer['layer_action']->action = array('a' => 'jumpto'); $layer['layer_action']->jump_to_slide = array('a' => $slider_map[$link_slide]); break; } $layer['layer_action']->tooltip_event = array('a' => 'click'); unset($layer['link_slide']); $did_change = true; } $layers[$key] = $layer; } //create new slide $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)); } $my_settings = json_encode($settings); if (empty($my_settings)) { $my_settings = stripslashes(json_encode($settings)); } $arrCreate["layers"] = $my_layers; $arrCreate["params"] = $my_params; $arrCreate["settings"] = $my_settings; if ($sliderExists) { unset($arrCreate["slider_id"]); $this->db->update(RevSliderGlobals::$table_static_slides, $arrCreate, array("slider_id" => $sliderID)); } else { $this->db->insert(RevSliderGlobals::$table_static_slides, $arrCreate); } } } $c_slider = new RevSliderSlider(); $c_slider->initByID($sliderID); //check to convert styles to latest versions RevSliderPluginUpdate::update_css_styles(); //set to version 5 RevSliderPluginUpdate::add_animation_settings_to_layer($c_slider); //set to version 5 RevSliderPluginUpdate::add_style_settings_to_layer($c_slider); //set to version 5 RevSliderPluginUpdate::change_settings_on_layers($c_slider); //set to version 5 RevSliderPluginUpdate::add_general_settings($c_slider); //set to version 5 RevSliderPluginUpdate::change_general_settings_5_0_7($c_slider); //set to version 5.0.7 RevSliderPluginUpdate::change_layers_svg_5_2_5_4($c_slider); //set to version 5.2.5.4 $cus_js = $c_slider->getParam('custom_javascript', ''); if (strpos($cus_js, 'revapi') !== false) { if (preg_match_all('/revapi[0-9]*/', $cus_js, $results)) { if (isset($results[0]) && !empty($results[0])) { foreach ($results[0] as $replace) { $cus_js = str_replace($replace, 'revapi' . $sliderID, $cus_js); } } $c_slider->updateParam(array('custom_javascript' => $cus_js)); } } if ($is_template !== false) { //duplicate the slider now, as we just imported the "template" if ($single_slide !== false) { //add now one Slide to the current Slider $mslider = new RevSlider(); //change slide_id to correct, as it currently is just a number beginning from 0 as we did not have a correct slide ID yet. $i = 0; $changed = false; foreach ($slider_map as $value) { if ($i == $single_slide['slide_id']) { $single_slide['slide_id'] = $value; $changed = true; break; } $i++; } if ($changed) { $return = $mslider->copySlideToSlider($single_slide); } else { return array("success" => false, "error" => __('could not find correct Slide to copy, please try again.', 'revslider'), "sliderID" => $sliderID); } } else { $mslider = new RevSlider(); $title = RevSliderFunctions::getVal($sliderParams, 'title', 'slider1'); $talias = $title; $ti = 1; while ($this->isAliasExistsInDB($talias)) { //set a new alias and title if its existing in database $talias = $title . $ti; $ti++; } $mslider->duplicateSliderFromData(array('sliderid' => $sliderID, 'title' => $talias)); } } $wp_filesystem->delete($d_path, true); } catch (Exception $e) { $errorMessage = $e->getMessage(); if (isset($d_path)) { $wp_filesystem->delete($d_path, true); } return array("success" => false, "error" => $errorMessage, "sliderID" => $sliderID); } return array("success" => true, "sliderID" => $sliderID); }
/** * * import slider handle (not ajax response) */ private static function importSliderTemplateHandle($viewBack = null, $updateAnim = true, $updateStatic = true, $single_slide = false) { dmp(__("importing template slider settings and data...", 'revslider')); $uid = esc_attr(RevSliderFunctions::getPostVariable('uid')); if ($uid == '') { dmp(__("ID missing, something went wrong. Please try again!", 'revslider')); echo RevSliderFunctions::getHtmlLink($viewBack, __("Go Back", 'revslider')); exit; } //check if the filename is correct //import to templates, then duplicate Slider $slider = new RevSlider(); $response = $slider->importSliderFromPost($updateAnim, $updateStatic, false, $uid, $single_slide); if ($single_slide === false) { if (empty($viewBack)) { $sliderID = $response["sliderID"]; $viewBack = self::getViewUrl(self::VIEW_SLIDER, "id=" . $sliderID); if (empty($sliderID)) { $viewBack = self::getViewUrl(self::VIEW_SLIDERS); } } } //handle error if ($response["success"] == false) { $message = $response["error"]; dmp("<b>Error: " . $message . "</b>"); echo RevSliderFunctions::getHtmlLink($viewBack, __("Go Back", 'revslider')); } else { //handle success, js redirect. dmp(__("Slider Import Success, redirecting...", 'revslider')); echo "<script>location.href='{$viewBack}'</script>"; } exit; }
/** * print all globals variables */ public static function printVars() { $methods = get_class_vars("GlobalsUG"); dmp($methods); exit; }
/** * * import slideer handle (not ajax response) */ private static function importSliderHandle($viewBack = null, $updateAnim = true, $updateStatic = true) { dmp(__("importing slider setings and data...", REVSLIDER_TEXTDOMAIN)); $slider = new RevSlider(); $response = $slider->importSliderFromPost($updateAnim, $updateStatic); $sliderID = $response["sliderID"]; if (empty($viewBack)) { $viewBack = self::getViewUrl(self::VIEW_SLIDER, "id=" . $sliderID); if (empty($sliderID)) { $viewBack = self::getViewUrl(self::VIEW_SLIDERS); } } //handle error if ($response["success"] == false) { $message = $response["error"]; dmp("<b>Error: " . $message . "</b>"); echo UniteFunctionsRev::getHtmlLink($viewBack, __("Go Back", REVSLIDER_TEXTDOMAIN)); } else { //handle success, js redirect. dmp(__("Slider Import Success, redirecting...", REVSLIDER_TEXTDOMAIN)); sdsconfig::getgeneratecssfile(); echo "<script>location.href='{$viewBack}'</script>"; } exit; }
function dmp_filter($a) { dmp($a); return $a; }
/** * * draw custom setting */ protected function drawCustom($setting) { dmp($setting); exit; }
/** * * import slider from multipart form */ public function importSliderFromPost($updateAnim = true, $updateStatic = true, $exactfilepath = false, $is_template = false, $single_slide = false) { try { $sliderID = RevSliderFunctions::getPostVariable("sliderid"); $sliderExists = !empty($sliderID); if ($sliderExists) { $this->initByID($sliderID); } if ($exactfilepath !== false) { $filepath = $exactfilepath; } else { switch ($_FILES['import_file']['error']) { case UPLOAD_ERR_OK: break; case UPLOAD_ERR_NO_FILE: RevSliderFunctions::throwError(__('No file sent.', REVSLIDER_TEXTDOMAIN)); case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: RevSliderFunctions::throwError(__('Exceeded filesize limit.', REVSLIDER_TEXTDOMAIN)); default: break; } $filepath = $_FILES["import_file"]["tmp_name"]; } if (file_exists($filepath) == false) { RevSliderFunctions::throwError("Import file not found!!!"); } //check if zip file or fallback to old, if zip, check if all files exist if (!class_exists("ZipArchive")) { $importZip = false; } else { $zip = new ZipArchive(); $importZip = $zip->open($filepath, ZIPARCHIVE::CREATE); } // Added by ThemeFuzz ( Stefan ) if ($importZip === 0 || !$zip->getStream('slider_export.txt')) { if (!$zip->getStream('slider_export.txt')) { $upload_dir = wp_upload_dir(); $new_path = $upload_dir['basedir'] . '/' . $_FILES['import_file']['name']; move_uploaded_file($_FILES["import_file"]["tmp_name"], $new_path); $importZip = $zip->open($new_path, ZIPARCHIVE::CREATE); } } if ($is_template !== false && $importZip !== true) { return array("success" => false, "error" => __('Please select the correct zip file', REVSLIDER_TEXTDOMAIN)); } 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'); $uid_file = $zip->getStream('info.cfg'); $uid_check = ''; if ($uid_file) { while (!feof($uid_file)) { $uid_check .= fread($uid_file, 1024); } } if ($is_template !== false) { if ($uid_check != $is_template) { return array("success" => false, "error" => __('Please select the correct zip file, checksum failed!', REVSLIDER_TEXTDOMAIN)); } } else { //someone imported a template base Slider, check if it is existing in Base Sliders, if yes, check if it was imported if ($uid_check !== '') { $tmpl = new RevSliderTemplate(); $tmpl_slider = $tmpl->getThemePunchTemplateSliders(); foreach ($tmpl_slider as $tp_slider) { if (!isset($tp_slider['installed'])) { continue; } if ($tp_slider['uid'] == $uid_check) { $is_template = $uid_check; break; } } } } if (!$slider_export) { RevSliderFunctions::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); } //check for images! } else { //check if fallback //get content array $content = @file_get_contents($filepath); } if ($importZip === true) { //we have a zip $db = new RevSliderDB(); //update/insert custom animations $animations = @unserialize($animations); if (!empty($animations)) { foreach ($animations as $key => $animation) { //$animation['id'], $animation['handle'], $animation['params'] $exist = $db->fetch(RevSliderGlobals::$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(RevSliderGlobals::$table_layer_anims, $arrUpdate, array('handle' => $animation['handle'])); $anim_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']))); $anim_id = $db->insert(RevSliderGlobals::$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']))); $anim_id = $db->insert(RevSliderGlobals::$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-' . $anim_id . '"', 'customout-' . $anim_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 RevSliderOperations::updateStaticCss($static); } elseif ($updateStatic == 'none') { //do nothing } else { //append $static_cur = RevSliderOperations::getStaticCss(); $static = $static_cur . "\n" . $static; RevSliderOperations::updateStaticCss($static); } } //overwrite/create dynamic-captions.css //parse css to classes $dynamicCss = RevSliderCssParser::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, ',') !== false && strpos($class, '.tp-caption') !== false) { //we have something like .tp-caption.redclass, .redclass $class_t = explode(',', $class); foreach ($class_t as $k => $cl) { if (strpos($cl, '.tp-caption') !== false) { $class = $cl; } } } 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); $arrInsert["settings"] = ''; } //check if class exists $result = $db->fetch(RevSliderGlobals::$table_css, "handle = '" . $class . "'"); if (!empty($result)) { //update $db->update(RevSliderGlobals::$table_css, $arrInsert, array('handle' => $class)); } else { //insert $arrInsert["handle"] = $class; $db->insert(RevSliderGlobals::$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 //deprecated in newest php version $content = preg_replace_callback('!s:(\\d+):"(.*?)";!', array('RevSlider', 'clear_error_in_string'), $content); //clear errors in string $arrSlider = @unserialize($content); if (empty($arrSlider)) { RevSliderFunctions::throwError("Wrong export slider file format! This could be caused because the ZipArchive extension is not enabled."); } //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"] = RevSliderFunctionsWP::getImageUrlFromPath($sliderParams["background_image"]); } $import_statics = true; if (isset($sliderParams['enable_static_layers'])) { if ($sliderParams['enable_static_layers'] == 'off') { $import_statics = false; } unset($sliderParams['enable_static_layers']); } $json_params = json_encode($sliderParams); //update slider or create new if ($sliderExists) { $arrUpdate = array("params" => $json_params); $this->db->update(RevSliderGlobals::$table_sliders, $arrUpdate, array("id" => $sliderID)); } else { //new slider $arrInsert = array(); $arrInsert['params'] = $json_params; //check if Slider with title and/or alias exists, if yes change both to stay unique $arrInsert['title'] = RevSliderFunctions::getVal($sliderParams, 'title', 'Slider1'); $arrInsert['alias'] = RevSliderFunctions::getVal($sliderParams, 'alias', 'slider1'); if ($is_template === false) { //we want to stay at the given alias if we are a template $talias = $arrInsert['alias']; $ti = 1; while ($this->isAliasExistsInDB($talias)) { //set a new alias and title if its existing in database $talias = $arrInsert['alias'] . $ti; $ti++; } if ($talias !== $arrInsert['alias']) { $arrInsert['title'] = $talias; $arrInsert['alias'] = $talias; } } if ($is_template !== false) { //add that we are an template $arrInsert['type'] = 'template'; } $sliderID = $this->db->insert(RevSliderGlobals::$table_sliders, $arrInsert); } //-------- Slides Handle ----------- //delete current slides if ($sliderExists) { $this->deleteAllSlides(); } //create all slides $arrSlides = $arrSlider["slides"]; $alreadyImported = array(); //wpml compatibility $slider_map = array(); foreach ($arrSlides as $sl_key => $slide) { $params = $slide["params"]; $layers = $slide["layers"]; $settings = @$slide["settings"]; //convert params images: if ($importZip === true) { //we have a zip, check if exists if (isset($params["image"])) { $params["image"] = RevSliderBase::check_file_in_zip($zip, $params["image"], $filepath, $sliderParams["alias"], $alreadyImported); $params["image"] = RevSliderFunctionsWP::getImageUrlFromPath($params["image"]); } if (isset($params["background_image"])) { $params["background_image"] = RevSliderBase::check_file_in_zip($zip, $params["background_image"], $filepath, $sliderParams["alias"], $alreadyImported); $params["background_image"] = RevSliderFunctionsWP::getImageUrlFromPath($params["background_image"]); } if (isset($params["slide_thumb"])) { $params["slide_thumb"] = RevSliderBase::check_file_in_zip($zip, $params["slide_thumb"], $filepath, $sliderParams["alias"], $alreadyImported); $params["slide_thumb"] = RevSliderFunctionsWP::getImageUrlFromPath($params["slide_thumb"]); } if (isset($params["show_alternate_image"])) { $params["show_alternate_image"] = RevSliderBase::check_file_in_zip($zip, $params["show_alternate_image"], $filepath, $sliderParams["alias"], $alreadyImported); $params["show_alternate_image"] = RevSliderFunctionsWP::getImageUrlFromPath($params["show_alternate_image"]); } if (isset($params['background_type']) && $params['background_type'] == 'html5') { if (isset($params['slide_bg_html_mpeg']) && $params['slide_bg_html_mpeg'] != '') { $params['slide_bg_html_mpeg'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $params["slide_bg_html_mpeg"], $filepath, $sliderParams["alias"], $alreadyImported, true)); } if (isset($params['slide_bg_html_webm']) && $params['slide_bg_html_webm'] != '') { $params['slide_bg_html_webm'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $params["slide_bg_html_webm"], $filepath, $sliderParams["alias"], $alreadyImported, true)); } if (isset($params['slide_bg_html_ogv']) && $params['slide_bg_html_ogv'] != '') { $params['slide_bg_html_ogv'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $params["slide_bg_html_ogv"], $filepath, $sliderParams["alias"], $alreadyImported, true)); } } } //convert layers images: foreach ($layers as $key => $layer) { //import if exists in zip folder if ($importZip === true) { //we have a zip, check if exists if (isset($layer["image_url"])) { $layer["image_url"] = RevSliderBase::check_file_in_zip($zip, $layer["image_url"], $filepath, $sliderParams["alias"], $alreadyImported); $layer["image_url"] = RevSliderFunctionsWP::getImageUrlFromPath($layer["image_url"]); } if (isset($layer['type']) && $layer['type'] == 'video') { $video_data = isset($layer['video_data']) ? (array) $layer['video_data'] : array(); if (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] == 'html5') { if (isset($video_data['urlPoster']) && $video_data['urlPoster'] != '') { $video_data['urlPoster'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $video_data["urlPoster"], $filepath, $sliderParams["alias"], $alreadyImported)); } if (isset($video_data['urlMp4']) && $video_data['urlMp4'] != '') { $video_data['urlMp4'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $video_data["urlMp4"], $filepath, $sliderParams["alias"], $alreadyImported, true)); } if (isset($video_data['urlWebm']) && $video_data['urlWebm'] != '') { $video_data['urlWebm'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $video_data["urlWebm"], $filepath, $sliderParams["alias"], $alreadyImported, true)); } if (isset($video_data['urlOgv']) && $video_data['urlOgv'] != '') { $video_data['urlOgv'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $video_data["urlOgv"], $filepath, $sliderParams["alias"], $alreadyImported, true)); } } elseif (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] != 'html5') { //video cover image if (isset($video_data['previewimage']) && $video_data['previewimage'] != '') { $video_data['previewimage'] = RevSliderFunctionsWP::getImageUrlFromPath(RevSliderBase::check_file_in_zip($zip, $video_data["previewimage"], $filepath, $sliderParams["alias"], $alreadyImported)); } } $layer['video_data'] = $video_data; } } $layer['text'] = stripslashes($layer['text']); $layers[$key] = $layer; } $arrSlides[$sl_key]['layers'] = $layers; //create new slide $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)); } $my_settings = json_encode($settings); if (empty($my_settings)) { $my_settings = stripslashes(json_encode($settings)); } $arrCreate["layers"] = $my_layers; $arrCreate["params"] = $my_params; $arrCreate["settings"] = $my_settings; $last_id = $this->db->insert(RevSliderGlobals::$table_slides, $arrCreate); if (isset($slide['id'])) { $slider_map[$slide['id']] = $last_id; } } //change for WPML the parent IDs if necessary if (!empty($slider_map)) { foreach ($arrSlides as $sl_key => $slide) { if (isset($slide['params']['parentid']) && isset($slider_map[$slide['params']['parentid']])) { $update_id = $slider_map[$slide['id']]; $parent_id = $slider_map[$slide['params']['parentid']]; $arrCreate = array(); $arrCreate["params"] = $slide['params']; $arrCreate["params"]['parentid'] = $parent_id; $my_params = json_encode($arrCreate["params"]); if (empty($my_params)) { $my_params = stripslashes(json_encode($arrCreate["params"])); } $arrCreate["params"] = $my_params; $this->db->update(RevSliderGlobals::$table_slides, $arrCreate, array("id" => $update_id)); } $did_change = false; foreach ($slide['layers'] as $key => $value) { if (isset($value['layer_action'])) { if (isset($value['layer_action']->jump_to_slide) && !empty($value['layer_action']->jump_to_slide)) { $value['layer_action']->jump_to_slide = (array) $value['layer_action']->jump_to_slide; foreach ($value['layer_action']->jump_to_slide as $jtsk => $jtsval) { if (isset($slider_map[$jtsval])) { $slide['layers'][$key]['layer_action']->jump_to_slide[$jtsk] = $slider_map[$jtsval]; $did_change = true; } } } } $link_slide = RevSliderFunctions::getVal($value, 'link_slide', false); if ($link_slide != false && $link_slide !== 'nothing') { //link to slide/scrollunder is set, move it to actions if (!isset($slide['layers'][$key]['layer_action'])) { $slide['layers'][$key]['layer_action'] = new stdClass(); } switch ($link_slide) { case 'link': $link = RevSliderFunctions::getVal($value, 'link'); $link_open_in = RevSliderFunctions::getVal($value, 'link_open_in'); $slide['layers'][$key]['layer_action']->action = array('a' => 'link'); $slide['layers'][$key]['layer_action']->link_type = array('a' => 'a'); $slide['layers'][$key]['layer_action']->image_link = array('a' => $link); $slide['layers'][$key]['layer_action']->link_open_in = array('a' => $link_open_in); unset($slide['layers'][$key]['link']); unset($slide['layers'][$key]['link_open_in']); case 'next': $slide['layers'][$key]['layer_action']->action = array('a' => 'next'); break; case 'prev': $slide['layers'][$key]['layer_action']->action = array('a' => 'prev'); break; case 'scroll_under': $scrollunder_offset = RevSliderFunctions::getVal($value, 'scrollunder_offset'); $slide['layers'][$key]['layer_action']->action = array('a' => 'scroll_under'); $slide['layers'][$key]['layer_action']->scrollunder_offset = array('a' => $scrollunder_offset); unset($slide['layers'][$key]['scrollunder_offset']); break; default: //its an ID, so its a slide ID $slide['layers'][$key]['layer_action']->action = array('a' => 'jumpto'); $slide['layers'][$key]['layer_action']->jump_to_slide = array('a' => $slider_map[$link_slide]); break; } $slide['layers'][$key]['layer_action']->tooltip_event = array('a' => 'click'); unset($slide['layers'][$key]['link_slide']); $did_change = true; } if ($did_change === true) { $arrCreate = array(); $my_layers = json_encode($slide['layers']); if (empty($my_layers)) { $my_layers = stripslashes(json_encode($layers)); } $arrCreate['layers'] = $my_layers; $this->db->update(RevSliderGlobals::$table_slides, $arrCreate, array("id" => $slider_map[$slide['id']])); } } } } //check if static slide exists and import if (isset($arrSlider['static_slides']) && !empty($arrSlider['static_slides']) && $import_statics) { $static_slide = $arrSlider['static_slides']; foreach ($static_slide as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; $settings = @$slide["settings"]; //convert params images: if (isset($params["image"])) { //import if exists in zip folder if (strpos($params["image"], 'http') !== false) { } else { 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>', REVSLIDER_TEXTDOMAIN); } else { if (!isset($alreadyImported['zip://' . $filepath . "#" . 'images/' . $params["image"]])) { $importImage = RevSliderFunctionsWP::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"] = RevSliderFunctionsWP::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 (strpos($layer["image_url"], 'http') !== false) { } else { 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 = RevSliderFunctionsWP::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"] = RevSliderFunctionsWP::getImageUrlFromPath($layer["image_url"]); $layer['text'] = stripslashes($layer['text']); } if (isset($layer['layer_action'])) { if (isset($layer['layer_action']->jump_to_slide) && !empty($layer['layer_action']->jump_to_slide)) { foreach ($layer['layer_action']->jump_to_slide as $jtsk => $jtsval) { if (isset($slider_map[$jtsval])) { $layer['layer_action']->jump_to_slide[$jtsk] = $slider_map[$jtsval]; } } } } $link_slide = RevSliderFunctions::getVal($value, 'link_slide', false); if ($link_slide != false && $link_slide !== 'nothing') { //link to slide/scrollunder is set, move it to actions if (!isset($layer['layer_action'])) { $layer['layer_action'] = new stdClass(); } switch ($link_slide) { case 'link': $link = RevSliderFunctions::getVal($value, 'link'); $link_open_in = RevSliderFunctions::getVal($value, 'link_open_in'); $layer['layer_action']->action = array('a' => 'link'); $layer['layer_action']->link_type = array('a' => 'a'); $layer['layer_action']->image_link = array('a' => $link); $layer['layer_action']->link_open_in = array('a' => $link_open_in); unset($layer['link']); unset($layer['link_open_in']); case 'next': $layer['layer_action']->action = array('a' => 'next'); break; case 'prev': $layer['layer_action']->action = array('a' => 'prev'); break; case 'scroll_under': $scrollunder_offset = RevSliderFunctions::getVal($value, 'scrollunder_offset'); $layer['layer_action']->action = array('a' => 'scroll_under'); $layer['layer_action']->scrollunder_offset = array('a' => $scrollunder_offset); unset($layer['scrollunder_offset']); break; default: //its an ID, so its a slide ID $layer['layer_action']->action = array('a' => 'jumpto'); $layer['layer_action']->jump_to_slide = array('a' => $slider_map[$link_slide]); break; } $layer['layer_action']->tooltip_event = array('a' => 'click'); unset($layer['link_slide']); $did_change = true; } $layers[$key] = $layer; } //create new slide $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)); } $my_settings = json_encode($settings); if (empty($my_settings)) { $my_settings = stripslashes(json_encode($settings)); } $arrCreate["layers"] = $my_layers; $arrCreate["params"] = $my_params; $arrCreate["settings"] = $my_settings; if ($sliderExists) { unset($arrCreate["slider_id"]); $this->db->update(RevSliderGlobals::$table_static_slides, $arrCreate, array("slider_id" => $sliderID)); } else { $this->db->insert(RevSliderGlobals::$table_static_slides, $arrCreate); } } } $c_slider = new RevSliderSlider(); $c_slider->initByID($sliderID); //check to convert styles to latest versions RevSliderPluginUpdate::update_css_styles(); //set to version 5 RevSliderPluginUpdate::add_animation_settings_to_layer($c_slider); //set to version 5 RevSliderPluginUpdate::add_style_settings_to_layer($c_slider); //set to version 5 RevSliderPluginUpdate::change_settings_on_layers($c_slider); //set to version 5 RevSliderPluginUpdate::add_general_settings($c_slider); //set to version 5 $cus_js = $c_slider->getParam('custom_javascript', ''); if (strpos($cus_js, 'revapi') !== false) { if (preg_match_all('/revapi[0-9]*./', $cus_js, $results)) { if (isset($results[0]) && !empty($results[0])) { foreach ($results[0] as $replace) { $cus_js = str_replace($replace, 'revapi' . $sliderID . '.', $cus_js); } } $c_slider->updateParam(array('custom_javascript' => $cus_js)); } } if ($is_template !== false) { //duplicate the slider now, as we just imported the "template" if ($single_slide !== false) { //add now one Slide to the current Slider $mslider = new RevSlider(); //change slide_id to correct, as it currently is just a number beginning from 0 as we did not have a correct slide ID yet. $i = 0; $changed = false; foreach ($slider_map as $value) { if ($i == $single_slide['slide_id']) { $single_slide['slide_id'] = $value; $changed = true; break; } $i++; } if ($changed) { $return = $mslider->copySlideToSlider($single_slide); } else { return array("success" => false, "error" => __('could not find correct Slide to copy, please try again.', REVSLIDER_TEXTDOMAIN), "sliderID" => $sliderID); } } else { $mslider = new RevSlider(); $title = RevSliderFunctions::getVal($sliderParams, 'title', 'slider1'); $talias = $title; $ti = 1; while ($this->isAliasExistsInDB($talias)) { //set a new alias and title if its existing in database $talias = $title . $ti; $ti++; } $mslider->duplicateSliderFromData(array('sliderid' => $sliderID, 'title' => $talias)); } } } catch (Exception $e) { $errorMessage = $e->getMessage(); return array("success" => false, "error" => $errorMessage, "sliderID" => $sliderID); } return array("success" => true, "sliderID" => $sliderID); }