first commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
interface Brizy_Editor_Data_ProjectMergeStrategyInterface {
|
||||
public function merge( $projectData1, $projectData2 );
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Editor_Data_ProjectMergeStrategy {
|
||||
|
||||
/**
|
||||
* @param $version
|
||||
*
|
||||
* @return Brizy_Editor_Data_ProjectMergeStrategyInterface
|
||||
*/
|
||||
static public function getMergerInstance( $version ) {
|
||||
if ( version_compare( $version, '1.0.81' ) <= 0 ) {
|
||||
return new Brizy_Editor_Data_ProjectMerge81();
|
||||
}
|
||||
|
||||
return new Brizy_Editor_Data_ProjectMerge82();
|
||||
}
|
||||
|
||||
/**
|
||||
* This code needs to be updated if the project data will change.
|
||||
*
|
||||
* @param $version
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
static public function checkVersionCompatibility( $version ) {
|
||||
if ( version_compare( $version, '1.0.81' ) > 0 && version_compare( $version, BRIZY_VERSION ) <= 0 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
45
wp-content/plugins/brizy/editor/data/project-merge81.php
Normal file
45
wp-content/plugins/brizy/editor/data/project-merge81.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Editor_Data_ProjectMerge81 implements Brizy_Editor_Data_ProjectMergeStrategyInterface {
|
||||
|
||||
/**
|
||||
* @param $projectData1
|
||||
* @param $projectData2
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function merge( $projectData1, $projectData2 ) {
|
||||
// MERGE STYLES
|
||||
|
||||
// 1. merge extra fonts
|
||||
$projectData1->extraFonts = array_unique(
|
||||
array_merge(
|
||||
(array) ( isset( $projectData1->extraFonts ) ? $projectData1->extraFonts : array() ),
|
||||
(array) ( isset( $projectData2->extraFonts ) ? $projectData2->extraFonts : array() )
|
||||
)
|
||||
);
|
||||
|
||||
// 2. merge extra fonts styles
|
||||
if ( ! isset( $projectData1->styles ) ) {
|
||||
$projectData1->styles = (object) array( '_extraFontStyles' => array() );
|
||||
}
|
||||
|
||||
$projectData1->styles->_extraFontStyles = array_merge(
|
||||
(array) ( isset( $projectData1->styles->_extraFontStyles ) ? $projectData1->styles->_extraFontStyles : array() ),
|
||||
(array) ( isset( $projectData2->styles->_extraFontStyles ) ? $projectData2->styles->_extraFontStyles : array() )
|
||||
);
|
||||
|
||||
|
||||
$projectData1->styles->default = $projectData2->styles->default;
|
||||
|
||||
if ( $projectData2->styles && isset( $projectData2->styles->_selected ) ) {
|
||||
$selected = $projectData2->styles->_selected;
|
||||
$projectData1->styles->_selected = $selected;
|
||||
if ( $selected ) {
|
||||
$projectData1->styles->$selected = $projectData2->styles->$selected;
|
||||
}
|
||||
}
|
||||
|
||||
return $projectData1;
|
||||
}
|
||||
}
|
||||
91
wp-content/plugins/brizy/editor/data/project-merge82.php
Normal file
91
wp-content/plugins/brizy/editor/data/project-merge82.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Editor_Data_ProjectMerge82 implements Brizy_Editor_Data_ProjectMergeStrategyInterface {
|
||||
private function mergeFonts( $fonts, $newFonts, $key = "family" ) {
|
||||
$result = $fonts;
|
||||
|
||||
foreach ( $newFonts->data as $newFont ) {
|
||||
$exist = false;
|
||||
|
||||
foreach ( $fonts->data as $font ) {
|
||||
if ( $font->$key === $newFont->$key ) {
|
||||
$exist = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $exist ) {
|
||||
$result->data[] = $newFont;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function merge( $projectData1, $projectData2 ) {
|
||||
|
||||
$result = $projectData1;
|
||||
|
||||
// selected Kit
|
||||
$result->selectedKit = $projectData2->selectedKit;
|
||||
|
||||
// selected Style
|
||||
$result->selectedStyle = $projectData2->selectedStyle;
|
||||
|
||||
if ( ! isset( $result->styles ) ) {
|
||||
$result->styles = array();
|
||||
}
|
||||
|
||||
// merge styles
|
||||
foreach ( $projectData2->styles as $i => $style ) {
|
||||
foreach ( $result->styles as $j => $resultStyle ) {
|
||||
if ( $style->id === $resultStyle->id ) {
|
||||
$result->styles[ $j ] = $style;
|
||||
} else {
|
||||
$result->styles[] = $style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// extraFontStyles
|
||||
$result->extraFontStyles = array_merge(
|
||||
(array) ( $result->extraFontStyles ),
|
||||
(array) ( $projectData2->extraFontStyles )
|
||||
);
|
||||
|
||||
// font
|
||||
$result->font = $projectData2->font;
|
||||
|
||||
// fonts
|
||||
// fonts -> config
|
||||
$result->fonts->config = $this->mergeFonts( $result->fonts->config, $projectData2->fonts->config );
|
||||
|
||||
// fonts -> blocks
|
||||
if ( isset( $projectData2->fonts->blocks ) ) {
|
||||
if ( ! isset( $result->fonts->blocks ) ) {
|
||||
$result->fonts->blocks = $projectData2->fonts->blocks;
|
||||
} else {
|
||||
$result->fonts->blocks = $this->mergeFonts( $projectData2->fonts->blocks, $projectData2->fonts->blocks );
|
||||
}
|
||||
}
|
||||
|
||||
// fonts -> google
|
||||
if ( isset( $projectData2->fonts->google ) ) {
|
||||
if ( ! isset( $result->fonts->google ) ) {
|
||||
$result->fonts->google = $projectData2->fonts->google;
|
||||
} else {
|
||||
$result->fonts->google = $this->mergeFonts( $projectData2->fonts->google, $projectData2->fonts->google );
|
||||
}
|
||||
}
|
||||
|
||||
// fonts -> upload
|
||||
if ( isset( $projectData2->fonts->upload ) ) {
|
||||
if ( ! isset( $result->fonts->upload ) ) {
|
||||
$result->fonts->uploud = $projectData2->fonts->upload;
|
||||
} else {
|
||||
$result->fonts->upload = $this->mergeFonts( $projectData2->fonts->upload, $projectData2->fonts->upload, "id" );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user