diff --git a/brizy.php b/brizy.php index 74b4254efa..5a81fe4455 100755 --- a/brizy.php +++ b/brizy.php @@ -5,7 +5,7 @@ * Plugin URI: https://brizy.io/ * Author: Brizy.io * Author URI: https://brizy.io/ - * Version: 2.4.43 + * Version: 2.4.41 * Text Domain: brizy * License: GPLv3 * Domain Path: /languages @@ -17,25 +17,24 @@ $_SERVER['HTTPS'] = 'on'; } -define('BRIZY_DEVELOPMENT', true); -define('BRIZY_LOG', false); -define('BRIZY_VERSION', '2.4.43'); +define('BRIZY_DEVELOPMENT', false ); +define('BRIZY_LOG', false ); +define('BRIZY_VERSION', '2.4.41'); define('BRIZY_MINIMUM_PRO_VERSION', '2.4.15'); -define('BRIZY_MINIMUM_COMPILER_VERSION', '282-wp'); -define('BRIZY_EDITOR_VERSION', BRIZY_DEVELOPMENT ? 'dev' : '282-wp'); -define('BRIZY_SYNC_VERSION', '282'); +define('BRIZY_EDITOR_VERSION', BRIZY_DEVELOPMENT ? 'dev' : '279-wp' ); +define('BRIZY_SYNC_VERSION', '279'); define('BRIZY_FILE', __FILE__); define('BRIZY_PLUGIN_BASE', plugin_basename(BRIZY_FILE)); define('BRIZY_PLUGIN_PATH', dirname(BRIZY_FILE)); define('BRIZY_PLUGIN_URL', rtrim(plugin_dir_url(BRIZY_FILE), "/")); define('BRIZY_MAX_REVISIONS_TO_KEEP', 30); -include_once rtrim(BRIZY_PLUGIN_PATH, "/").'/autoload.php'; -include_once rtrim(BRIZY_PLUGIN_PATH, "/").'/languages/main.php'; +include_once rtrim(BRIZY_PLUGIN_PATH, "/") . '/autoload.php'; +include_once rtrim(BRIZY_PLUGIN_PATH, "/") . '/languages/main.php'; if (BRIZY_DEVELOPMENT) { $dotenv = new \Symfony\Component\Dotenv\Dotenv('APP_ENV'); - $dotenv->load(__DIR__.'/.env'); + $dotenv->load(__DIR__ . '/.env'); } add_action('plugins_loaded', 'brizy_load'); @@ -119,7 +118,7 @@ function brizy_install() Brizy_Logger::install(); add_option('brizy-regenerate-permalinks', 1); do_action('brizy-activated'); - set_transient('brizy_admin_notice', true, 7200); + set_transient( 'brizy_admin_notice', true, 7200 ); } function brizy_clean() @@ -131,7 +130,7 @@ function brizy_clean() function brizy_load_text_domain() { - load_plugin_textdomain('brizy', false, dirname(plugin_basename(__FILE__)).'/languages'); + load_plugin_textdomain('brizy', false, dirname(plugin_basename(__FILE__)) . '/languages'); } new Brizy_Compatibilities_Init(); diff --git a/public/editor-client/src/api/index.ts b/public/editor-client/src/api/index.ts index 5d76e43fa6..4fae7c1966 100644 --- a/public/editor-client/src/api/index.ts +++ b/public/editor-client/src/api/index.ts @@ -1,10 +1,11 @@ import { Config, getConfig } from "@/config"; +import { DefaultBlock, PagesAPI } from "@/types/DefaultTemplate"; +import { ConfigDCItem } from "@/types/DynamicContent"; import { GlobalBlock } from "@/types/GlobalBlocks"; import { Page } from "@/types/Page"; import { Rule } from "@/types/PopupConditions"; import { Project } from "@/types/Project"; import { ResponseWithBody } from "@/types/Response"; -import { ConfigDCItem } from "@/types/DynamicContent"; import { CreateSavedBlock, CreateSavedLayout, @@ -15,6 +16,7 @@ import { } from "@/types/SavedBlocks"; import { ScreenshotData } from "@/types/Screenshots"; import { t } from "@/utils/i18n"; +import { Json } from "@brizy/readers"; import { Literal } from "../utils/types"; import { GetCollections, @@ -1206,3 +1208,35 @@ export const updateGlobalBlocks = async ( }; //#endregion + +// region Default Pages +export const getDefaultPages = async (): Promise<{ + blocks: PagesAPI[]; + categories: Record; +}> => { + const res = await fetch( + // temporary solution, wait until new API will come via config + "https://phplaravel-1109775-4184176.cloudwaysapps.com/api/get-pages-chunk" + ).then((r) => r.json()); + + return { + blocks: res.collections, + categories: res.categories + }; +}; + +export const getDefaultPage = async ( + slug: string +): Promise<{ + items: DefaultBlock[]; +}> => { + const data = await fetch( + // temporary solution, wait until new API will come via config + `https://j6dfq8pl41.b-cdn.net/api/get-page-data?page_slug=${slug}` + ).then((r) => r.json()); + + return Json.read(data[0].pageData) as { + items: DefaultBlock[]; + }; +}; +// endregion diff --git a/public/editor-client/src/defaultTemplates/index.ts b/public/editor-client/src/defaultTemplates/index.ts index 814be6be63..0224f53197 100644 --- a/public/editor-client/src/defaultTemplates/index.ts +++ b/public/editor-client/src/defaultTemplates/index.ts @@ -1,4 +1,4 @@ -import { Json } from "@brizy/readers"; +import { getDefaultPage, getDefaultPages } from "@/api"; import { Config } from "../config"; import { BlocksArray, @@ -21,7 +21,7 @@ import { } from "../types/DefaultTemplate"; import { t } from "../utils/i18n"; import { tempConverterKit } from "./tempComverters"; -import { convertPages, convertToCategories, fetchAllLayouts1 } from "./utils"; +import { convertPages, convertToCategories } from "./utils"; const defaultKits = ( config: Config @@ -298,16 +298,11 @@ const defaultPages = ( // @ts-expect-error: temporary solution, wait until new API will come via config const { layoutsUrl } = config.api.templates; const imageUrl = "https://cloud-1de12d.b-cdn.net/media/iW=1024&iH=1024/"; - const apiLayoutsUrl1 = - "https://phplaravel-1109775-4184176.cloudwaysapps.com/api"; - const apiPagesUrl = "https://j6dfq8pl41.b-cdn.net/api"; return { async getMeta(res, rej) { try { - const { blocks, categories } = await fetchAllLayouts1( - `${apiLayoutsUrl1}/get-pages-chunk` - ); + const { blocks, categories } = await getDefaultPages(); res({ blocks: convertPages(blocks, imageUrl), @@ -319,13 +314,7 @@ const defaultPages = ( }, async getData(res, rej, { slug }) { try { - const data = await fetch( - `${apiPagesUrl}/get-page-data?page_slug=${slug}` - ).then((r) => r.json()); - - const pageData = Json.read(data[0].pageData) as { - items: DefaultBlock[]; - }; + const pageData = await getDefaultPage(slug); res({ blocks: [...pageData.items] diff --git a/public/editor-client/src/defaultTemplates/utils.ts b/public/editor-client/src/defaultTemplates/utils.ts index 8a978f554f..aff9c498b5 100644 --- a/public/editor-client/src/defaultTemplates/utils.ts +++ b/public/editor-client/src/defaultTemplates/utils.ts @@ -1,148 +1,5 @@ -import { flatten, trim, uniq, upperFirst } from "lodash"; -import { - APIPopup, - BlockWithThumbs, - Categories, - Kit, - KitType, - LayoutsAPI, - PagesAPI, - PagesTemplate, - Style -} from "../types/DefaultTemplate"; -import { pipe } from "../utils/fp/pipe"; - -type CatTypes = Kit | APIPopup; - -export const getUniqueKitCategories = (collections: CatTypes[]): Categories[] => - pipe( - (collections: CatTypes[]) => - collections.map((collection: CatTypes) => collection.categories), - flatten, - uniq, - (cats) => - cats.map((cat) => ({ - title: upperFirst(cat), - slug: cat, - id: cat - })) - )(collections); - -export const getUniqueLayoutsCategories = ( - collections: LayoutsAPI[] | PagesAPI[] -): Categories[] => - pipe( - (collections: LayoutsAPI[] | PagesAPI[]) => - collections.map( - (collection: LayoutsAPI | PagesAPI) => collection.categories - ), - (cats: string[]) => cats.map((it) => it.split(",")), - flatten, - (cats: string[]) => cats.map(trim), - uniq, - (cats) => - cats.map((cat) => ({ - title: cat, - slug: cat, - id: cat - })) - )(collections); - -export const getUniqueKitTypes = (collections: Kit[]): KitType[] => - pipe( - (collections: Kit[]) => collections.map((collection) => collection.theme), - flatten, - uniq, - (uni) => - uni.map((u) => ({ - title: upperFirst(u), - id: u, - name: u, - icon: "nc-light" - })) - )(collections); - -export const converterKit = ( - kit: Kit[], - url: string, - kitId: string -): { - blocks: BlockWithThumbs[]; - categories: Categories[]; - types: KitType[]; -} => { - const categories = getUniqueKitCategories(kit); - const types = getUniqueKitTypes(kit); - - const blocks: BlockWithThumbs[] = kit.map( - ({ - slug, - categories, - pro, - thumbnail, - keywords, - thumbnailWidth, - thumbnailHeight - }) => ({ - id: slug, - cat: [categories], - title: slug, - type: types[0].name, - keywords: keywords ?? "", - thumbnailHeight, - thumbnailWidth, - thumbnailSrc: `${url}${thumbnail}`, - pro: pro === "yes", - kitId - }) - ); - - return { - blocks, - categories, - types - }; -}; - -export const converterPopup = ( - kit: APIPopup[], - url: string, - kitId: string -): { - blocks: BlockWithThumbs[]; - categories: Categories[]; -} => { - const categories = getUniqueKitCategories(kit); - - const blocks: BlockWithThumbs[] = kit.map( - ({ - id, - title, - categories, - pro, - thumbnail, - thumbnailWidth, - thumbnailHeight - }) => ({ - id: id, - cat: [categories], - title: title, - thumbnailHeight, - thumbnailWidth, - thumbnailSrc: `${url}${thumbnail}`, - pro: pro === "true", - keywords: "popup2", - position: 1, - type: 0, - kitId - }) - ); - - return { - blocks, - categories - }; -}; +import { trim, upperFirst } from "lodash"; +import { Categories, PagesAPI, PagesTemplate } from "../types/DefaultTemplate"; export const convertPages = ( collections: PagesAPI[], @@ -168,310 +25,6 @@ export const convertPages = ( } ); -export const getStyles = (): Array