Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/smart-sl.../Nextend/SmartSli.../BackupSl...
File: ImportSlider.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
namespace Nextend\SmartSlider3\BackupSlider;
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
use Nextend\Framework\Cache\StoreImage;
[6] Fix | Delete
use Nextend\Framework\Data\Data;
[7] Fix | Delete
use Nextend\Framework\Filesystem\Filesystem;
[8] Fix | Delete
use Nextend\Framework\Image\ImageManager;
[9] Fix | Delete
use Nextend\Framework\Misc\Zip\Reader;
[10] Fix | Delete
use Nextend\Framework\Model\StorageSectionManager;
[11] Fix | Delete
use Nextend\Framework\Notification\Notification;
[12] Fix | Delete
use Nextend\Framework\Pattern\MVCHelperTrait;
[13] Fix | Delete
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
[14] Fix | Delete
use Nextend\Framework\Url\Url;
[15] Fix | Delete
use Nextend\SmartSlider3\Application\Model\ModelGenerator;
[16] Fix | Delete
use Nextend\SmartSlider3\Application\Model\ModelSliders;
[17] Fix | Delete
use Nextend\SmartSlider3\Application\Model\ModelSlides;
[18] Fix | Delete
use Nextend\SmartSlider3\Renderable\Component\ComponentCol;
[19] Fix | Delete
use Nextend\SmartSlider3\Renderable\Component\ComponentContent;
[20] Fix | Delete
use Nextend\SmartSlider3\Renderable\Component\ComponentLayer;
[21] Fix | Delete
use Nextend\SmartSlider3\Renderable\Component\ComponentRow;
[22] Fix | Delete
use Nextend\SmartSlider3\Slider\SliderType\SliderTypeFactory;
[23] Fix | Delete
use Nextend\SmartSlider3\Widget\WidgetGroupFactory;
[24] Fix | Delete
[25] Fix | Delete
class ImportSlider {
[26] Fix | Delete
[27] Fix | Delete
use MVCHelperTrait;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* @var BackupData
[31] Fix | Delete
*/
[32] Fix | Delete
private $backup;
[33] Fix | Delete
private $imageTranslation = array();
[34] Fix | Delete
private $sectionTranslation = array();
[35] Fix | Delete
[36] Fix | Delete
private $sliderId = 0;
[37] Fix | Delete
[38] Fix | Delete
private $replace = false;
[39] Fix | Delete
[40] Fix | Delete
public function __construct($MVCHelper) {
[41] Fix | Delete
[42] Fix | Delete
$this->setMVCHelper($MVCHelper);
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
public function enableReplace() {
[46] Fix | Delete
$this->replace = true;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
public function import($filePathOrData, $groupID = 0, $imageImportMode = 'clone', $linkedVisuals = 1, $isFilePath = true) {
[50] Fix | Delete
if (!$isFilePath) {
[51] Fix | Delete
$tmp = Filesystem::tempnam();
[52] Fix | Delete
file_put_contents($tmp, $filePathOrData);
[53] Fix | Delete
$filePathOrData = $tmp;
[54] Fix | Delete
}
[55] Fix | Delete
$importData = Reader::read($filePathOrData);
[56] Fix | Delete
if (!$isFilePath) {
[57] Fix | Delete
@unlink($tmp);
[58] Fix | Delete
}
[59] Fix | Delete
if (!is_array($importData)) {
[60] Fix | Delete
Notification::error(n2_('The importing failed at the unzipping part.'));
[61] Fix | Delete
[62] Fix | Delete
return false;
[63] Fix | Delete
} else if (!isset($importData['data'])) {
[64] Fix | Delete
if (array_key_exists("slider.ss2", $importData)) {
[65] Fix | Delete
Notification::error(n2_('You can\'t import sliders from Smart Slider 2.'));
[66] Fix | Delete
} else if (empty($importData)) {
[67] Fix | Delete
Notification::error(n2_('Export file corrupted! Slider data is missing.'));
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
return false;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
[74] Fix | Delete
$parser = new Serialize\Parser;
[75] Fix | Delete
if (!$parser->isValidData($importData['data'])) {
[76] Fix | Delete
return false;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
$this->backup = unserialize($importData['data']);
[80] Fix | Delete
[81] Fix | Delete
if (!empty($this->backup->slider['type']) && $this->backup->slider['type'] == 'group') {
[82] Fix | Delete
// Groups can not be imported into groups
[83] Fix | Delete
$groupID = 0;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
$this->sectionTranslation = array();
[87] Fix | Delete
$this->importVisuals($this->backup->visuals, $linkedVisuals);
[88] Fix | Delete
[89] Fix | Delete
[90] Fix | Delete
$sliderModel = new ModelSliders($this);
[91] Fix | Delete
[92] Fix | Delete
[93] Fix | Delete
if ($this->replace) {
[94] Fix | Delete
$this->sliderId = $sliderModel->replace($this->backup->slider, $groupID);
[95] Fix | Delete
} else {
[96] Fix | Delete
$this->sliderId = $sliderModel->import($this->backup->slider, $groupID);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if (!$this->sliderId) {
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
switch ($imageImportMode) {
[104] Fix | Delete
case 'clone':
[105] Fix | Delete
$images = isset($importData['images']) ? $importData['images'] : array();
[106] Fix | Delete
$imageStore = new StoreImage('slider' . $this->sliderId, true);
[107] Fix | Delete
foreach ($images as $file => $content) {
[108] Fix | Delete
$localImage = $imageStore->makeCache($file, $content);
[109] Fix | Delete
if ($localImage) {
[110] Fix | Delete
$this->imageTranslation[$file] = ResourceTranslator::urlToResource(Url::pathToUri($localImage));
[111] Fix | Delete
} else {
[112] Fix | Delete
$this->imageTranslation[$file] = $file;
[113] Fix | Delete
}
[114] Fix | Delete
if (!$this->imageTranslation[$file]) {
[115] Fix | Delete
$this->imageTranslation[$file] = array_search($file, $this->backup->imageTranslation);
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
break;
[119] Fix | Delete
case 'update':
[120] Fix | Delete
$keys = array_keys($this->backup->NextendImageHelper_Export);
[121] Fix | Delete
$values = array_values($this->backup->NextendImageHelper_Export);
[122] Fix | Delete
foreach ($this->backup->imageTranslation as $image => $value) {
[123] Fix | Delete
$this->imageTranslation[$value] = str_replace($keys, $values, $image);
[124] Fix | Delete
}
[125] Fix | Delete
break;
[126] Fix | Delete
default:
[127] Fix | Delete
break;
[128] Fix | Delete
}
[129] Fix | Delete
if (!empty($this->backup->slider['thumbnail'])) {
[130] Fix | Delete
$sliderModel->setThumbnail($this->sliderId, $this->fixImage($this->backup->slider['thumbnail']));
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
foreach ($this->backup->NextendImageManager_ImageData as $image => $data) {
[134] Fix | Delete
$data['tablet']['image'] = $this->fixImage($data['tablet']['image']);
[135] Fix | Delete
$data['mobile']['image'] = $this->fixImage($data['mobile']['image']);
[136] Fix | Delete
$fixedImage = $this->fixImage($image);
[137] Fix | Delete
if (!ImageManager::hasImageData($fixedImage)) {
[138] Fix | Delete
ImageManager::addImageData($this->fixImage($image), $data);
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
if (empty($this->backup->slider['type'])) {
[143] Fix | Delete
$this->backup->slider['type'] = 'simple';
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
[147] Fix | Delete
if ($this->backup->slider['type'] == 'group') {
[148] Fix | Delete
/**
[149] Fix | Delete
* Import the sliders for the group!
[150] Fix | Delete
*/
[151] Fix | Delete
foreach ($importData['sliders'] as $k => $slider) {
[152] Fix | Delete
$import = new self($this);
[153] Fix | Delete
if ($this->replace) {
[154] Fix | Delete
$import->enableReplace();
[155] Fix | Delete
}
[156] Fix | Delete
$import->import($slider, $this->sliderId, $imageImportMode, $linkedVisuals, false);
[157] Fix | Delete
}
[158] Fix | Delete
} else {
[159] Fix | Delete
[160] Fix | Delete
unset($importData);
[161] Fix | Delete
[162] Fix | Delete
$sliderType = SliderTypeFactory::getType($this->backup->slider['type']);
[163] Fix | Delete
$sliderType->import($this, $this->backup->slider);
[164] Fix | Delete
[165] Fix | Delete
[166] Fix | Delete
$enabledWidgets = array();
[167] Fix | Delete
$widgetGroups = WidgetGroupFactory::getGroups();
[168] Fix | Delete
[169] Fix | Delete
$params = $this->backup->slider['params'];
[170] Fix | Delete
foreach ($widgetGroups as $groupName => $group) {
[171] Fix | Delete
$widgetName = $params->get('widget' . $groupName);
[172] Fix | Delete
if ($widgetName && $widgetName != 'disabled') {
[173] Fix | Delete
$widget = $group->getWidget($widgetName);
[174] Fix | Delete
if ($widget) {
[175] Fix | Delete
$enabledWidgets[$groupName] = $widget;
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
foreach ($enabledWidgets as $k => $widget) {
[181] Fix | Delete
$params->fillDefault($widget->getDefaults());
[182] Fix | Delete
[183] Fix | Delete
$widget->prepareImport($this, $params);
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
[187] Fix | Delete
$sliderModel->importUpdate($this->sliderId, $params);
[188] Fix | Delete
[189] Fix | Delete
$generatorTranslation = array();
[190] Fix | Delete
$generatorModel = new ModelGenerator($this);
[191] Fix | Delete
foreach ($this->backup->generators as $generator) {
[192] Fix | Delete
$generatorTranslation[$generator['id']] = $generatorModel->import($generator);
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
[196] Fix | Delete
$slidesModel = new ModelSlides($this);
[197] Fix | Delete
for ($i = 0; $i < count($this->backup->slides); $i++) {
[198] Fix | Delete
$slide = $this->backup->slides[$i];
[199] Fix | Delete
$slide['params'] = new Data($slide['params'], true);
[200] Fix | Delete
$slide['thumbnail'] = $this->fixImage($slide['thumbnail']);
[201] Fix | Delete
$slide['params']->set('backgroundImage', $this->fixImage($slide['params']->get('backgroundImage')));
[202] Fix | Delete
$slide['params']->set('ligthboxImage', $this->fixImage($slide['params']->get('ligthboxImage')));
[203] Fix | Delete
[204] Fix | Delete
if ($slide['params']->has('link')) {
[205] Fix | Delete
// Compatibility fix for the old SS3 import files
[206] Fix | Delete
$slide['params']->set('link', $this->fixLightbox($slide['params']->get('link')));
[207] Fix | Delete
}
[208] Fix | Delete
if ($slide['params']->has('href')) {
[209] Fix | Delete
$slide['params']->set('href', $this->fixLightbox($slide['params']->get('href')));
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
$layers = json_decode($slide['slide'], true);
[213] Fix | Delete
[214] Fix | Delete
$this->prepareLayers($layers);
[215] Fix | Delete
[216] Fix | Delete
$slide['slide'] = $layers;
[217] Fix | Delete
[218] Fix | Delete
if (isset($generatorTranslation[$slide['generator_id']])) {
[219] Fix | Delete
$slide['generator_id'] = $generatorTranslation[$slide['generator_id']];
[220] Fix | Delete
}
[221] Fix | Delete
$slidesModel->import($slide, $this->sliderId);
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
return $this->sliderId;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* @param array $layers
[230] Fix | Delete
*/
[231] Fix | Delete
public function prepareLayers(&$layers) {
[232] Fix | Delete
for ($i = 0; $i < count($layers); $i++) {
[233] Fix | Delete
[234] Fix | Delete
if (isset($layers[$i]['type'])) {
[235] Fix | Delete
switch ($layers[$i]['type']) {
[236] Fix | Delete
case 'content':
[237] Fix | Delete
ComponentContent::prepareImport($this, $layers[$i]);
[238] Fix | Delete
break;
[239] Fix | Delete
case 'row':
[240] Fix | Delete
ComponentRow::prepareImport($this, $layers[$i]);
[241] Fix | Delete
break;
[242] Fix | Delete
case 'col':
[243] Fix | Delete
ComponentCol::prepareImport($this, $layers[$i]);
[244] Fix | Delete
break;
[245] Fix | Delete
case 'group':
[246] Fix | Delete
$this->prepareLayers($layers[$i]['layers']);
[247] Fix | Delete
break;
[248] Fix | Delete
default:
[249] Fix | Delete
ComponentLayer::prepareImport($this, $layers[$i]);
[250] Fix | Delete
}
[251] Fix | Delete
} else {
[252] Fix | Delete
ComponentLayer::prepareImport($this, $layers[$i]);
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
public function fixImage($image) {
[258] Fix | Delete
if (isset($this->backup->imageTranslation[$image]) && isset($this->imageTranslation[$this->backup->imageTranslation[$image]])) {
[259] Fix | Delete
return $this->imageTranslation[$this->backup->imageTranslation[$image]];
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
return $image;
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
public function fixSection($idOrRaw) {
[266] Fix | Delete
if (isset($this->sectionTranslation[$idOrRaw])) {
[267] Fix | Delete
return $this->sectionTranslation[$idOrRaw];
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
return $idOrRaw;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
public function fixLightbox($url) {
[274] Fix | Delete
preg_match('/^([a-zA-Z]+)\[(.*)]/', $url, $matches);
[275] Fix | Delete
if (!empty($matches) && $matches[1] == 'lightbox') {
[276] Fix | Delete
$data = json_decode($matches[2]);
[277] Fix | Delete
if ($data) {
[278] Fix | Delete
$newImages = array();
[279] Fix | Delete
foreach ($data->urls as $image) {
[280] Fix | Delete
$newImages[] = $this->fixImage($image);
[281] Fix | Delete
}
[282] Fix | Delete
$data->urls = $newImages;
[283] Fix | Delete
$url = 'lightbox[' . json_encode($data) . ']';
[284] Fix | Delete
}
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
return $url;
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
private function importVisuals($records, $linkedVisuals) {
[291] Fix | Delete
if (count($records)) {
[292] Fix | Delete
if (!$linkedVisuals) {
[293] Fix | Delete
foreach ($records as $record) {
[294] Fix | Delete
$this->sectionTranslation[$record['id']] = $record['value'];
[295] Fix | Delete
}
[296] Fix | Delete
} else {
[297] Fix | Delete
$sets = array();
[298] Fix | Delete
foreach ($records as $record) {
[299] Fix | Delete
$storage = StorageSectionManager::getStorage($record['application']);
[300] Fix | Delete
if (!isset($sets[$record['application'] . '_' . $record['section']])) {
[301] Fix | Delete
$sets[$record['application'] . '_' . $record['section']] = $storage->add($record['section'] . 'set', '', $this->backup->slider['title']);
[302] Fix | Delete
}
[303] Fix | Delete
$this->sectionTranslation[$record['id']] = $storage->add($record['section'], $sets[$record['application'] . '_' . $record['section']], $record['value']);
[304] Fix | Delete
}
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
}
[309] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function