From 8facda32095c1416bdf9f4abf69f671a70d4f170 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Wed, 24 Nov 2021 19:16:26 +0200 Subject: [PATCH 01/45] new: Made te fields optional for update blocks/popups/layouts --- admin/blocks/api.php | 121 ++++++++++++++++++++---------------------- admin/layouts/api.php | 43 +++++++-------- 2 files changed, 78 insertions(+), 86 deletions(-) diff --git a/admin/blocks/api.php b/admin/blocks/api.php index 767c7ad2e1..6340563de1 100644 --- a/admin/blocks/api.php +++ b/admin/blocks/api.php @@ -105,8 +105,8 @@ public function actionDownloadBlocks() { $items = array_filter( $items ); if ( count( $items ) == 0 ) { - $this->error( 404, __( 'There are no blocks to be archived', 'brizy' ) ); - } + $this->error( 404, __( 'There are no blocks to be archived', 'brizy')); + } $fontManager = new Brizy_Admin_Fonts_Manager(); $zip = new Brizy_Editor_Zip_Archiver( @@ -235,18 +235,13 @@ public function actionCreateGlobalBlock() { if ( $status == 'publish' && is_null( $compiledData ) ) { $this->error( 400, "The compiled data is missing" ); - } - - $bockManager = new Brizy_Admin_Blocks_Manager( Brizy_Admin_Blocks_Main::CP_GLOBAL ); - - /** - * @var Brizy_Editor_Block $block ; - */ - $block = $bockManager->createEntity( $this->param( 'uid' ), $status ); - $block->setMeta( stripslashes( $this->param( 'meta' ) ) ); - $block->set_editor_data( $editorData ); - $block->set_needs_compile( true ); - $block->setHtml( $html ); + }$bockManager = new Brizy_Admin_Blocks_Manager(Brizy_Admin_Blocks_Main::CP_GLOBAL); + /** + * @var Brizy_Editor_Block $block; + */$block = $bockManager->createEntity($this->param('uid'), $status); + $block->setMeta(stripslashes($this->param('meta'))); + $block->set_editor_data($editorData); + $block->set_needs_compile(true);$block->setHtml( $html ); if ( $status == 'publish' && $compiledData ) { @@ -256,7 +251,7 @@ public function actionCreateGlobalBlock() { $this->error( 400, "The compiled data is invalid" ); } - $block->set_encoded_compiled_html( $compiled['html'] ); + $block->set_encoded_compiled_html( $compiled['html'] ); $block->set_compiled_scripts( [ 'free' => $compiled['assets']['freeScripts'], 'pro' => ( isset( $compiled['assets']['proScripts'] ) ? $compiled['assets']['proScripts'] : [] ), @@ -272,14 +267,13 @@ public function actionCreateGlobalBlock() { } if ( $this->param( 'tags' ) ) { - $block->setTags( stripslashes( $this->param( 'tags' ) ) ); - } - if ( $position ) { - $block->setPosition( - Brizy_Editor_BlockPosition::createFromSerializedData( get_object_vars( json_decode( $position ) ) ) - ); - } + $block->setTags(stripslashes($this->param('tags'))); + }if ($position) { + $block->setPosition( + Brizy_Editor_BlockPosition::createFromSerializedData(get_object_vars(json_decode($position))) + ); + } // rules if ( $rulesData ) { @@ -428,8 +422,8 @@ public function actionUpdateGlobalBlocks() { } } - $bockManager = new Brizy_Admin_Blocks_Manager( Brizy_Admin_Blocks_Main::CP_GLOBAL ); - $blocks = $bockManager->getEntity( (array) $this->param( 'uid' ) ); + $bockManager = new Brizy_Admin_Blocks_Manager(Brizy_Admin_Blocks_Main::CP_GLOBAL); + $blocks = $bockManager->getEntity((array)$this->param('uid')); foreach ( (array) $this->param( 'uid' ) as $i => $uid ) { @@ -519,13 +513,15 @@ public function actionUpdateGlobalBlocks() { $block->save(); - do_action( 'brizy_global_block_updated', $block ); - } - } + do_action('brizy_global_block_updated', $block); + + } +} do_action( 'brizy_global_data_updated' ); - $this->success( [] ); + + $this->success([]); } catch ( Exception $exception ) { $this->error( 400, $exception->getMessage() ); @@ -554,24 +550,25 @@ public function actionDeleteGlobalBlock() { public function actionGetSavedBlocks() { $this->verifyNonce( self::nonce ); - try { - $fields = $this->param( 'fields' ) ? $this->param( 'fields' ) : []; - $bockManager = new Brizy_Admin_Blocks_Manager( Brizy_Admin_Blocks_Main::CP_SAVED ); - $blocks = $bockManager->getEntities( [ - 'paged' => (int) ( $this->param( 'page' ) ?: 1 ), - 'posts_per_page' => (int) ( $this->param( 'count' ) ?: - 1 ), - 'order' => $this->param( 'order' ) ?: 'ASC', - 'orderby' => $this->param( 'orderby' ) ?: 'ID', - ] ); - $blocks = apply_filters( 'brizy_get_saved_blocks', - $bockManager->createResponseForEntities( $blocks, $fields ), - $fields, - $bockManager ); - $this->success( $blocks ); - } catch ( Exception $exception ) { - $this->error( 400, $exception->getMessage() ); - } - } + try { + $fields = $this->param('fields') ? $this->param('fields') : []; + $bockManager = new Brizy_Admin_Blocks_Manager(Brizy_Admin_Blocks_Main::CP_SAVED); + $blocks = $bockManager->getEntities([ + 'paged' => (int)($this->param('page') ?: 1), + 'posts_per_page' => (int)($this->param('count') ?: -1), + 'order' => $this->param('order') ?: 'ASC', + 'orderby' => $this->param('orderby') ?: 'ID', + ]);$blocks = apply_filters( + 'brizy_get_saved_blocks', + $bockManager->createResponseForEntities($blocks, $fields), + $fields, + $bockManager + ); + $this->success($blocks); + } catch (Exception $exception) { + $this->error(400, $exception->getMessage()); + } + } public function actionGetSavedBlockByUid() { $this->verifyNonce( self::nonce ); @@ -618,20 +615,18 @@ public function actionCreateSavedBlock() { $this->error( 400, 'Invalid media data provided' ); } - try { - $bockManager = new Brizy_Admin_Blocks_Manager( Brizy_Admin_Blocks_Main::CP_SAVED ); - $block = $bockManager->createEntity( $this->param( 'uid' ) ); - $block->setMedia( stripslashes( $this->param( 'media' ) ) ); - $block->setMeta( stripslashes( $this->param( 'meta' ) ) ); - - if ( $this->param( 'title' ) ) { + try { + $bockManager = new Brizy_Admin_Blocks_Manager(Brizy_Admin_Blocks_Main::CP_SAVED); + $block = $bockManager->createEntity($this->param('uid')); + $block->setMedia(stripslashes($this->param('media'))); + $block->setMeta(stripslashes($this->param('meta'))); + if($this->param('title')){ $block->setTitle( stripslashes( $this->param( 'title' ) ) ); } if ( $this->param( 'tags' ) ) { - $block->setTags( stripslashes( $this->param( 'tags' ) ) ); - } - $block->set_editor_data( $this->sanitizeJson(stripslashes( $this->param( 'data' ) ) )); + $block->setTags(stripslashes($this->param('tags'))); + }$block->set_editor_data( $this->sanitizeJson(stripslashes( $this->param( 'data' ) ) )); $block->set_needs_compile( true ); //$block->setCloudUpdateRequired( true ); $block->save(); @@ -688,13 +683,13 @@ public function actionUpdateSavedBlock() { } - if ( (int) $this->param( 'is_autosave' ) ) { - $block->save( 1 ); - } else { - $block->save(); - do_action( 'brizy_saved_block_updated', $block ); - do_action( 'brizy_global_data_updated' ); - } + if ((int)$this->param('is_autosave')) { + $block->save(1); + } else { + $block->save(); + do_action('brizy_saved_block_updated', $block); + do_action('brizy_global_data_updated'); + } Brizy_Editor_Block::cleanClassCache(); diff --git a/admin/layouts/api.php b/admin/layouts/api.php index 7dbf5c7593..8ba803a919 100644 --- a/admin/layouts/api.php +++ b/admin/layouts/api.php @@ -41,13 +41,13 @@ protected function getRequestNonce() protected function initializeApiActions() { - $pref = 'wp_ajax_' . Brizy_Editor::prefix(); - add_action($pref . self::DOWNLOAD_LAYOUTS, array($this, 'actionDownloadLayouts')); - add_action($pref . self::GET_LAYOUT_BY_UID_ACTION, array($this, 'actionGetLayoutByUid')); - add_action($pref . self::GET_LAYOUTS_ACTION, array($this, 'actionGetLayouts')); - add_action($pref . self::CREATE_LAYOUT_ACTION, array($this, 'actionCreateLayout')); - add_action($pref . self::UPDATE_LAYOUT_ACTION, array($this, 'actionUpdateLayout')); - add_action($pref . self::DELETE_LAYOUT_ACTION, array($this, 'actionDeleteLayout')); + $pref = 'wp_ajax_'.Brizy_Editor::prefix(); + add_action($pref.self::DOWNLOAD_LAYOUTS, array($this, 'actionDownloadLayouts')); + add_action($pref.self::GET_LAYOUT_BY_UID_ACTION, array($this, 'actionGetLayoutByUid')); + add_action($pref.self::GET_LAYOUTS_ACTION, array($this, 'actionGetLayouts')); + add_action($pref.self::CREATE_LAYOUT_ACTION, array($this, 'actionCreateLayout')); + add_action($pref.self::UPDATE_LAYOUT_ACTION, array($this, 'actionUpdateLayout')); + add_action($pref.self::DELETE_LAYOUT_ACTION, array($this, 'actionDeleteLayout')); } public function actionDownloadLayouts() @@ -77,26 +77,26 @@ public function actionDownloadLayouts() return null; }, $explode); - $items = array_filter($items); + $items = array_filter($items); if (count($items) == 0) { $this->error(404, __('There are no layouts to be archived')); } - $zipPath = "Layout-" . date(DATE_ATOM) . ".zip"; + $zipPath = "Layout-".date(DATE_ATOM).".zip"; $fontManager = new Brizy_Admin_Fonts_Manager(); - $zip = new Brizy_Editor_Zip_Archiver( + $zip = new Brizy_Editor_Zip_Archiver( Brizy_Editor_Project::get(), $fontManager, BRIZY_SYNC_VERSION ); - $zipPath = $zip->createZip($items, $zipPath); + $zipPath = $zip->createZip($items, $zipPath); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/octet-stream"); - header("Content-Disposition: attachment; filename=\"" . basename($zipPath) . "\";"); + header("Content-Disposition: attachment; filename=\"".basename($zipPath)."\";"); header("Content-Transfer-Encoding: binary"); echo file_get_contents($zipPath); @@ -143,18 +143,19 @@ public function actionGetLayouts() $layoutManager = new Brizy_Admin_Layouts_Manager(); $fields = $this->param('fields') ? $this->param('fields') : []; - $layouts = $layoutManager->getEntities( - [ + + $layouts = $layoutManager->getEntities([ 'paged' => (int)($this->param('page') ?: 1), 'posts_per_page' => (int)($this->param('count') ?: -1), 'order' => $this->param('order') ?: 'ASC', 'orderby' => $this->param('orderby') ?: 'ID' - ] - ); - $layouts = apply_filters('brizy_get_layouts', + ]); + $layouts = apply_filters( + 'brizy_get_layouts', $layoutManager->createResponseForEntities($layouts, $fields), $fields, - $layoutManager); + $layoutManager + ); $this->success($layouts); } catch (Exception $exception) { @@ -200,17 +201,13 @@ public function actionCreateLayout() $layout->setGlobalStyles(stripslashes($this->param('globalStyles'))); $layout->set_editor_data($editorData); $layout->set_needs_compile(true); - if ($this->param('title')) { $layout->setTitle(stripslashes($this->param('title'))); } if ($this->param('tags')) { $layout->setTags(stripslashes($this->param('tags'))); - } - - - //$layout->setCloudUpdateRequired( true ); + }//$layout->setCloudUpdateRequired( true ); $layout->setDataVersion(1); $layout->save(); From 87d0a5285ca719ff699d51cf215e016afc8a7a21 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 1 Dec 2021 14:34:31 +0200 Subject: [PATCH 02/45] new: html changes in page.html.twig issue: #16367 --- public/views/page.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/views/page.php b/public/views/page.php index 2a77b49316..3f7858dbc3 100755 --- a/public/views/page.php +++ b/public/views/page.php @@ -10,7 +10,7 @@ - + From eebc0dcfe3064d0522c3901b6929f8a97bfb677f Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 1 Dec 2021 11:45:24 +0200 Subject: [PATCH 03/45] new: Added title and tags for block/layouts/popups --- admin/blocks/api.php | 22 ++++++++++++++-------- admin/layouts/api.php | 18 ++++++++++++------ editor/entity.php | 2 +- editor/popup.php | 2 +- editor/post.php | 39 ++++++++++++++++++++------------------- editor/zip/archiver.php | 3 ++- 6 files changed, 50 insertions(+), 36 deletions(-) diff --git a/admin/blocks/api.php b/admin/blocks/api.php index 6340563de1..726b01d045 100644 --- a/admin/blocks/api.php +++ b/admin/blocks/api.php @@ -236,9 +236,11 @@ public function actionCreateGlobalBlock() { if ( $status == 'publish' && is_null( $compiledData ) ) { $this->error( 400, "The compiled data is missing" ); }$bockManager = new Brizy_Admin_Blocks_Manager(Brizy_Admin_Blocks_Main::CP_GLOBAL); - /** - * @var Brizy_Editor_Block $block; - */$block = $bockManager->createEntity($this->param('uid'), $status); + + /** + * @var Brizy_Editor_Block $block; + */ + $block = $bockManager->createEntity($this->param('uid'), $status); $block->setMeta(stripslashes($this->param('meta'))); $block->set_editor_data($editorData); $block->set_needs_compile(true);$block->setHtml( $html ); @@ -251,7 +253,7 @@ public function actionCreateGlobalBlock() { $this->error( 400, "The compiled data is invalid" ); } - $block->set_encoded_compiled_html( $compiled['html'] ); + $block->set_encoded_compiled_html( $compiled['html'] ); $block->set_compiled_scripts( [ 'free' => $compiled['assets']['freeScripts'], 'pro' => ( isset( $compiled['assets']['proScripts'] ) ? $compiled['assets']['proScripts'] : [] ), @@ -269,7 +271,9 @@ public function actionCreateGlobalBlock() { if ( $this->param( 'tags' ) ) { $block->setTags(stripslashes($this->param('tags'))); - }if ($position) { + } + + if ($position) { $block->setPosition( Brizy_Editor_BlockPosition::createFromSerializedData(get_object_vars(json_decode($position))) ); @@ -620,13 +624,15 @@ public function actionCreateSavedBlock() { $block = $bockManager->createEntity($this->param('uid')); $block->setMedia(stripslashes($this->param('media'))); $block->setMeta(stripslashes($this->param('meta'))); + if($this->param('title')){ $block->setTitle( stripslashes( $this->param( 'title' ) ) ); } if ( $this->param( 'tags' ) ) { - $block->setTags(stripslashes($this->param('tags'))); - }$block->set_editor_data( $this->sanitizeJson(stripslashes( $this->param( 'data' ) ) )); + } + + $block->set_editor_data( $this->sanitizeJson(stripslashes( $this->param( 'data' ) ) )); $block->set_needs_compile( true ); //$block->setCloudUpdateRequired( true ); $block->save(); @@ -683,7 +689,7 @@ public function actionUpdateSavedBlock() { } - if ((int)$this->param('is_autosave')) { + if ((int)$this->param('is_autosave')) { $block->save(1); } else { $block->save(); diff --git a/admin/layouts/api.php b/admin/layouts/api.php index 8ba803a919..3110c8d821 100644 --- a/admin/layouts/api.php +++ b/admin/layouts/api.php @@ -201,13 +201,19 @@ public function actionCreateLayout() $layout->setGlobalStyles(stripslashes($this->param('globalStyles'))); $layout->set_editor_data($editorData); $layout->set_needs_compile(true); - if ($this->param('title')) { - $layout->setTitle(stripslashes($this->param('title'))); - } - if ($this->param('tags')) { - $layout->setTags(stripslashes($this->param('tags'))); - }//$layout->setCloudUpdateRequired( true ); + if($this->param('title')) + { + $layout->setTitle(stripslashes($this->param('title'))); + } + + if($this->param('tags')) + { + $layout->setTags(stripslashes($this->param('tags'))); + } + + + //$layout->setCloudUpdateRequired( true ); $layout->setDataVersion(1); $layout->save(); diff --git a/editor/entity.php b/editor/entity.php index 8ee0b94fc3..35e5022c1a 100644 --- a/editor/entity.php +++ b/editor/entity.php @@ -200,7 +200,7 @@ abstract protected function loadInstanceData(); /** * @return mixed */ - abstract public function createResponse( $fields = array(), $context=Brizy_Editor_Editor_Editor::EDITOR_CONTEXT ); + abstract public function createResponse( $fields = array() , $context=Brizy_Editor_Editor_Editor::EDITOR_CONTEXT ); /** * Save post data and and trigger post update diff --git a/editor/popup.php b/editor/popup.php index 9a0823c827..1615b81136 100644 --- a/editor/popup.php +++ b/editor/popup.php @@ -1,4 +1,4 @@ - $this->getWpPostId(), - 'post_title' => $this->getTitle(), - 'post_content' => $this->getPostContent($createRevision), + 'post_title' => $this->getTitle(), + 'post_content' => $this->getPostContent($createRevision), ]; $this->deleteOldAutosaves($this->getWpPostId()); @@ -805,15 +805,15 @@ protected function loadInstanceData() //$storageData = $storage->get_storage(); $storage_post = $storage->get($this->getObjectKey(), false); - $this->setTitle(get_the_title($this->getWpPostId())); + $this->setTitle( get_the_title( $this->getWpPostId() ) ); - // check for deprecated forms of posts - if ($storage_post instanceof self) { - $this->set_editor_data($storage_post->editor_data); - $this->set_needs_compile(true); - $this->save(); - } else { - if (is_array($storage_post)) { + // check for deprecated forms of posts + if ( $storage_post instanceof self ) { + $this->set_editor_data( $storage_post->editor_data ); + $this->set_needs_compile( true ); + $this->save(); + } else { + if ( is_array( $storage_post ) ) { if (isset($storage_post['compiled_html'])) { $this->set_encoded_compiled_html($storage_post['compiled_html']); @@ -864,7 +864,8 @@ protected function loadInstanceData() protected function populateAutoSavedData($autosave) { $autosave->setTitle($this->getTitle()); - $autosave->set_template($this->get_template()); + $autosave->setTitle( $this->getTitle() ); + $autosave->set_template($this->get_template()); $autosave->set_editor_data($this->get_editor_data()); $autosave->set_editor_version($this->get_editor_version()); $autosave->set_needs_compile(true); diff --git a/editor/zip/archiver.php b/editor/zip/archiver.php index c480abe3b8..94ac58a30a 100644 --- a/editor/zip/archiver.php +++ b/editor/zip/archiver.php @@ -88,7 +88,8 @@ public function addEntityToZip(ZipArchive $z, Brizy_Editor_Zip_ArchiveItem $item $block = $item->getPost(); $data = array( 'class' => get_class($block), - 'title' => $block->getTitle(), + 'title' => $block->getTitle(), + 'title' => $block->getTitle(), 'meta' => $block->getMeta(), 'media' => $block->getMedia(), 'data' => $block->get_editor_data(true), From d98397a723b9c66ca041b2134a92775d47f8a20d Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 6 Dec 2021 15:02:44 +0200 Subject: [PATCH 04/45] new: Added filter to be able to change the story rewrite slug --- admin/stories/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/stories/main.php b/admin/stories/main.php index fdc9aa0929..db67a9bb1b 100644 --- a/admin/stories/main.php +++ b/admin/stories/main.php @@ -59,7 +59,7 @@ static public function registerCustomPosts() 'public' => true, 'description' => __bt( 'brizy', 'Brizy' ) . ' ' . __( 'stories', 'brizy' ) . '.', 'show_in_menu' => Brizy_Admin_Settings::menu_slug(), - 'rewrite' => [ 'slug' => self::CP_STORY ], + 'rewrite' => [ 'slug' => apply_filters('brizy_story_rewrite_slug',self::CP_STORY) ], 'capability_type' => 'page', 'exclude_from_search' => true, 'supports' => [ 'title', 'post_content', 'revisions' ], From e7981586cecbe85af873835c9d0ceea73602bb13 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Tue, 7 Dec 2021 11:18:15 +0200 Subject: [PATCH 05/45] fix: decode the htmlentity encoded title and tags --- editor/entity.php | 2 +- editor/post-tags-aware.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/editor/entity.php b/editor/entity.php index 35e5022c1a..a90fe0e28c 100644 --- a/editor/entity.php +++ b/editor/entity.php @@ -360,7 +360,7 @@ public function getUid() { } public function getTitle() { - return $this->getWpPost()->post_title; + return html_entity_decode($this->getWpPost()->post_title); } public function setTitle( $title ) { diff --git a/editor/post-tags-aware.php b/editor/post-tags-aware.php index df3fb7c5c9..cbcf390121 100644 --- a/editor/post-tags-aware.php +++ b/editor/post-tags-aware.php @@ -11,7 +11,7 @@ trait Brizy_Editor_PostTagsAware { * @return string */ public function getTags() { - return $this->tags; + return html_entity_decode($this->tags); } /** From e9e2a81113f4c9fea4c5dc92bc923427ce9aa661 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Mon, 17 Jan 2022 11:14:10 +0200 Subject: [PATCH 06/45] new: Added ignore dc placeholder issue: #16516 --- content/placeholders/ignore-dc.php | 40 +++++++++++++++++++++++++++++ content/providers/free-provider.php | 1 + 2 files changed, 41 insertions(+) create mode 100644 content/placeholders/ignore-dc.php diff --git a/content/placeholders/ignore-dc.php b/content/placeholders/ignore-dc.php new file mode 100644 index 0000000000..64a1da7c31 --- /dev/null +++ b/content/placeholders/ignore-dc.php @@ -0,0 +1,40 @@ +setLabel($label); + $this->setPlaceholder('brizy_dc_ignore_dc'); + $this->setDisplay($display); + $this->setGroup($group); + } + + /** + * @param ContextInterface $context + * @param ContentPlaceholder $placeholder + * + * @return mixed + */ + public function getValue(ContextInterface $context, ContentPlaceholder $placeholder) + { + return $placeholder->getContent(); + } +} \ No newline at end of file diff --git a/content/providers/free-provider.php b/content/providers/free-provider.php index 5dada2446a..6adbcfb65e 100644 --- a/content/providers/free-provider.php +++ b/content/providers/free-provider.php @@ -250,6 +250,7 @@ function ( $context, $contentPlaceholder ) { return do_shortcode( '[woocommerce_order_tracking]' ); } ) ); + $this->registerPlaceholder( new Brizy_Content_Placeholders_IgnoreDc('') ); $this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( __( 'WooCommerce Notices', 'brizy' ), From 09b908b0309efbd568c5a379184d707d8764cf9e Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 19 Jan 2022 12:17:33 +0200 Subject: [PATCH 07/45] new: Added simple post aware and fixed few placeholders --- content/placeholders/simple-post-aware.php | 45 +++ content/providers/free-provider.php | 352 +++++++++------------ 2 files changed, 197 insertions(+), 200 deletions(-) create mode 100644 content/placeholders/simple-post-aware.php diff --git a/content/placeholders/simple-post-aware.php b/content/placeholders/simple-post-aware.php new file mode 100644 index 0000000000..0a4b38417a --- /dev/null +++ b/content/placeholders/simple-post-aware.php @@ -0,0 +1,45 @@ +getAttribute('post_id'); + + if ($postId) { + $newContext = Brizy_Content_ContextFactory::createContext( + $context->getProject(), + null, + get_post($postId), + null, + false + ); + + return parent::getValue($newContext, $contentPlaceholder); + } + + if ( ! $context->getWpPost()) { + return; + } + + return parent::getValue($context, $contentPlaceholder); + } + + /** + * @return mixed|string + */ + protected function getOptionValue() + { + return $this->getReplacePlaceholder(); + } +} \ No newline at end of file diff --git a/content/providers/free-provider.php b/content/providers/free-provider.php index 6adbcfb65e..b9322cd388 100644 --- a/content/providers/free-provider.php +++ b/content/providers/free-provider.php @@ -5,252 +5,212 @@ class Brizy_Content_Providers_FreeProvider extends Brizy_Content_Providers_AbstractProvider { public function __construct() { - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( - 'Internal Display Block By User Role', - 'display_by_roles', - function ( Brizy_Content_Context $context, ContentPlaceholder $contentPlaceholder ) { + $this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( 'Internal Display Block By User Role', 'display_by_roles', function ( Brizy_Content_Context $context, ContentPlaceholder $contentPlaceholder ) { - $attrs = $contentPlaceholder->getAttributes(); + $attrs = $contentPlaceholder->getAttributes(); - if ( ! empty( $attrs['roles'] ) ) { - $roles = explode( ',', $attrs['roles'] ); - $userRoles = (array) wp_get_current_user()->roles; + if ( ! empty( $attrs['roles'] ) ) { + $roles = explode( ',', $attrs['roles'] ); + $userRoles = (array) wp_get_current_user()->roles; - if ( in_array( 'logged', $roles ) && is_user_logged_in() ) { - $userRoles[] = 'logged'; - } + if ( in_array( 'logged', $roles ) && is_user_logged_in() ) { + $userRoles[] = 'logged'; + } - if ( Brizy_Editor_User::is_user_allowed() ) { + if ( Brizy_Editor_User::is_user_allowed() ) { - if ( ! empty( $_GET['role'] ) ) { + if ( ! empty( $_GET['role'] ) ) { + + if ( $_GET['role'] === 'default' ) { + $roles[] = 'default'; + $userRoles[] = 'default'; + } else { + $userRoles = []; - if ( $_GET['role'] === 'default' ) { + if ( $_GET['role'] == 'not_logged' ) { + + if ( in_array( 'not_logged', $roles ) ) { $roles[] = 'default'; $userRoles[] = 'default'; - } else { - $userRoles = []; - - if ( $_GET['role'] == 'not_logged' ) { - - if ( in_array( 'not_logged', $roles ) ) { - $roles[] = 'default'; - $userRoles[] = 'default'; - } - } else { - $userRoles[] = $_GET['role']; - } } + } else { + $userRoles[] = $_GET['role']; } } + } + } - if ( in_array( 'not_logged', $roles ) ) { + if ( in_array( 'not_logged', $roles ) ) { - $roles = array_diff( $roles, [ 'not_logged' ] ); + $roles = array_diff( $roles, [ 'not_logged' ] ); - if ( is_user_logged_in() ) { - if ( ! array_intersect( $roles, $userRoles ) ) { - return ''; - } - } - } else { - if ( ! array_intersect( $roles, $userRoles ) ) { - return ''; - } + if ( is_user_logged_in() ) { + if ( ! array_intersect( $roles, $userRoles ) ) { + return ''; } } + } else { + if ( ! array_intersect( $roles, $userRoles ) ) { + return ''; + } + } + } - $replacer = new \BrizyPlaceholders\Replacer( $context->getProvider() ); + $replacer = new \BrizyPlaceholders\Replacer( $context->getProvider() ); - return $replacer->replacePlaceholders( $contentPlaceholder->getContent(), $context ); - } - ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_ImageTitleAttribute( 'Internal Title Attributes', 'brizy_dc_image_title' ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_ImageAltAttribute( __( 'Internal Alt Attributes', 'brizy' ), 'brizy_dc_image_alt' ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_UniquePageUrl( __( 'Uniquer page url', 'brizy' ), 'brizy_dc_current_page_unique_url' ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( __( 'WP Language', 'brizy' ), 'brizy_dc_page_language', get_locale() ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( 'Ajax Url', 'brizy_dc_ajax_url', admin_url( 'admin-ajax.php' ) ) - ); - $this->registerPlaceholder( new Brizy_Content_Placeholders_Permalink() ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_sidebar', function ( $context, $contentPlaceholder ) { + return $replacer->replacePlaceholders( $contentPlaceholder->getContent(), $context ); + } + ) + );$this->registerPlaceholder( new Brizy_Content_Placeholders_ImageTitleAttribute( 'Internal Title Attributes', 'brizy_dc_image_title' ) + );$this->registerPlaceholder( new Brizy_Content_Placeholders_ImageAltAttribute( __( 'Internal Alt Attributes', 'brizy' ), 'brizy_dc_image_alt' ) + );$this->registerPlaceholder( new Brizy_Content_Placeholders_UniquePageUrl( __( 'Uniquer page url', 'brizy' ), 'brizy_dc_current_page_unique_url' ) + );$this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( __( 'WP Language', 'brizy' ), 'brizy_dc_page_language', get_locale() ) ); + $this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( 'Ajax Url', 'brizy_dc_ajax_url', admin_url( 'admin-ajax.php' ) ) + );$this->registerPlaceholder( new Brizy_Content_Placeholders_SimplePostAware('Permalink', 'brizy_dc_permalink',function ( $context, $contentPlaceholder ) { + return get_permalink( (int)$context->getWpPost()->ID ); + }) ); + $this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( '', 'editor_sidebar', function ( $context, $contentPlaceholder ) { - $attrs = $contentPlaceholder->getAttributes(); + $attrs = $contentPlaceholder->getAttributes(); - $id = isset( $attrs['sidebarId'] ) ? $attrs['sidebarId'] : null; + $id = isset( $attrs['sidebarId'] ) ? $attrs['sidebarId'] : null; - if ( $id ) { - ob_start(); + if ( $id ) { + ob_start(); - dynamic_sidebar( $id ); + dynamic_sidebar( $id ); - return ob_get_clean(); - } + return ob_get_clean(); + } - return ''; - } ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_navigation', function ( $context, $contentPlaceholder ) { + return ''; + } ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_navigation', function ( $context, $contentPlaceholder ) { + + $attrs = $contentPlaceholder->getAttributes(); - $attrs = $contentPlaceholder->getAttributes(); + return $attrs['menuId'] ? wp_nav_menu( array( 'menu' => $attrs['menuId'], 'echo' => false ) ) : ''; + } ) - return $attrs['menuId'] ? wp_nav_menu( array( 'menu' => $attrs['menuId'], 'echo' => false ) ) : ''; - } ) ); $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_post_field', function ( $context, $contentPlaceholder ) { + new Brizy_Content_Placeholders_SimplePostAware( '', 'editor_post_field', function ( $context, $contentPlaceholder ) { - $attrs = $contentPlaceholder->getAttributes(); + $attrs = $contentPlaceholder->getAttributes(); - $post = ( $context = Brizy_Content_ContextFactory::getGlobalContext() ) ? $context->getWpPost() : get_post(); + $post = $context->getWpPost(); - if ( ! $post || ! isset( $attrs['property'] ) ) { - return ''; - } + if ( ! $post || ! isset( $attrs['property'] ) ) { + return ''; + } - return $this->filterData( $attrs['property'], $post ); - } ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_post_info', function () { - - $post = ( $context = Brizy_Content_ContextFactory::getGlobalContext() ) ? $context->getWpPost() : get_post(); - - if ( $post ) { - $commentsCount = get_approved_comments( $post->ID, [ 'count' => true ] ); - $params = []; - $params['author'] = get_the_author_meta( 'display_name', $post->post_author ); - $params['date'] = get_the_date( '', $post ); - $params['time'] = get_the_time( '', $post ); - $params['comments'] = sprintf( - _n( '%s comment', '%s comments', $commentsCount, 'brizy' ), - number_format_i18n( $commentsCount ) - ); - - return Brizy_Editor_View::get( BRIZY_PLUGIN_PATH . '/public/views/post-info', $params ); - } + return $this->filterData( $attrs['property'], $post ); + } ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_post_info', function ( $context, $contentPlaceholder ) { - return ''; - } ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_posts', function ( $context, $contentPlaceholder ) { + $post = $context->getWpPost(); - $atts = $contentPlaceholder->getAttributes(); + if ( $post ) { + $commentsCount = get_approved_comments( $post->ID, [ 'count' => true ] ); + $params = []; - // shortcode to use in page: {{editor_posts posts_per_page="5" category="1,2" orderby="date" order="DESC" columns="1" display_date="1" display_author="1"}} + $params['author'] = get_the_author_meta( 'display_name', $post->post_author ); + $params['date'] = get_the_date( '', $post ); + $params['time'] = get_the_time( '', $post ); + $params['comments'] = sprintf( _n( '%s comment', '%s comments', $commentsCount, 'brizy' ), number_format_i18n( $commentsCount ) ); - // this array is used as default values for displayPosts - $extra_atts = array( - "columns" => 1, - "display_date" => 1, - "display_author" => 1, - ); + return Brizy_Editor_View::get(BRIZY_PLUGIN_PATH . '/public/views/post-info', $params); + } - $extra_atts = array_merge( $extra_atts, $atts ); + return ''; + } ) - $posts = $this->getPosts( $atts ); + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_posts', function ( $context, $contentPlaceholder ) { - return $this->displayPosts( $posts, $extra_atts ); - } ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( - __( 'Product Page', 'brizy' ), - 'editor_product_page', - function ( $context, $contentPlaceholder ) { + $atts = $contentPlaceholder->getAttributes(); + + // shortcode to use in page: {{editor_posts posts_per_page="5" category="1,2" orderby="date" order="DESC" columns="1" display_date="1" display_author="1"}} - $atts = $contentPlaceholder->getAttributes(); + // this array is used as default values for displayPosts + $extra_atts = array( + "columns" => 1, + "display_date" => 1, + "display_author" => 1, + ); + + $extra_atts = array_merge( $extra_atts, $atts ); + + $posts = $this->getPosts( $atts ); + + return $this->displayPosts( $posts, $extra_atts ); + } ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( __( 'Product Page', 'brizy' ), + 'editor_product_page', function ( $context, $contentPlaceholder ) { + + $atts = $contentPlaceholder->getAttributes(); // if ( ! empty( $atts['id'] ) ) { // $product_data = get_post( $atts['id'] ); // $product = ! empty( $product_data ) && in_array( $product_data->post_type, [ 'product', 'product_variation' ] ) ? wc_setup_product_data( $product_data ) : false; // } - if ( empty( $atts['itemId'] ) && current_user_can( 'manage_options' ) ) { - return __( 'Please set a valid product', 'brizy' ); - } + if ( empty( $atts['itemId'] ) && current_user_can( 'manage_options' ) ) { + return __( 'Please set a valid product', 'brizy' ); + } - $this->setScriptDependency( - 'brizy-preview', - [ 'zoom', 'photoswipe', 'flexslider', 'wc-single-product' ] - ); + $this->setScriptDependency( 'brizy-preview', [ 'zoom', 'photoswipe', 'flexslider', 'wc-single-product' ] ); - // Avoid infinite loop. There's a call of the function the_content() in the woocommerce/single-product/tabs/description.php - remove_filter( 'the_content', [ Brizy_Admin_Templates::instance(), 'filterPageContent' ], - 12000 ); + // Avoid infinite loop. There's a call of the function the_content() in the woocommerce/single-product/tabs/description.php + remove_filter( 'the_content', [ Brizy_Admin_Templates::instance(), 'filterPageContent' ], - 12000 ); - $html = do_shortcode( '[product_page id="' . $atts['itemId'] . '"]' ); + $html = do_shortcode( '[product_page id="' . $atts['itemId'] . '"]' ); - add_filter( 'the_content', [ Brizy_Admin_Templates::instance(), 'filterPageContent' ], - 12000 ); + add_filter( 'the_content', [ Brizy_Admin_Templates::instance(), 'filterPageContent' ], - 12000 ); - return $html; - } - ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( - 'Products Page', - 'editor_product_products', - function ( $context, $contentPlaceholder ) { + return $html; + } - $atts = $contentPlaceholder->getAttributes(); + ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( 'Products Page', 'editor_product_products', function ( $context, $contentPlaceholder ) { - $shortcodeAttributes = []; + $atts = $contentPlaceholder->getAttributes(); - if ( isset( $atts['limit'] ) ) { - $shortcodeAttributes[] = sprintf( "limit=\"%d\"", (int) $atts['limit'] ); - } - if ( isset( $atts['columns'] ) ) { - $shortcodeAttributes[] = sprintf( "columns=\"%d\"", (int) $atts['columns'] ); - } - if ( isset( $atts['category'] ) ) { - $shortcodeAttributes[] = sprintf( "category=\"%s\"", $atts['category'] ); - } - if ( isset( $atts['orderby'] ) ) { - $shortcodeAttributes[] = sprintf( "orderby=\"%s\"", $atts['orderby'] ); - } - if ( isset( $atts['order'] ) ) { - $shortcodeAttributes[] = sprintf( "order=\"%s\"", $atts['order'] ); - } + $shortcodeAttributes = []; - $shortcodeAttributes = implode( ' ', $shortcodeAttributes ); + if ( isset( $atts['limit'] ) ) { + $shortcodeAttributes[] = sprintf( "limit=\"%d\"", (int) $atts['limit'] ); + } + if ( isset( $atts['columns'] ) ) { + $shortcodeAttributes[] = sprintf( "columns=\"%d\"", (int) $atts['columns'] ); + } + if ( isset( $atts['category'] ) ) { + $shortcodeAttributes[] = sprintf( "category=\"%s\"", $atts['category'] ); + } + if ( isset( $atts['orderby'] ) ) { + $shortcodeAttributes[] = sprintf( "orderby=\"%s\"", $atts['orderby'] ); + } + if ( isset( $atts['order'] ) ) { + $shortcodeAttributes[] = sprintf( "order=\"%s\"", $atts['order'] ); + } - return do_shortcode( '[products ' . $shortcodeAttributes . ' ]' ); - } - ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_product_default_cart', function () { - return do_shortcode( '[woocommerce_cart]' ); - } ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_product_checkout', function () { - return do_shortcode( '[woocommerce_checkout]' ); - } ) - ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_product_my_account', function () { - return do_shortcode( '[woocommerce_my_account]' ); - } ) + $shortcodeAttributes = implode( ' ', $shortcodeAttributes ); + + return do_shortcode( '[products ' . $shortcodeAttributes . ' ]' ); + } + ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_product_default_cart', function () { + return do_shortcode( '[woocommerce_cart]' ); + } ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_product_checkout', function () { + return do_shortcode( '[woocommerce_checkout]' );} ) ); - $this->registerPlaceholder( - new Brizy_Content_Placeholders_Simple( '', 'editor_product_order_tracking', function () { - return do_shortcode( '[woocommerce_order_tracking]' ); - } ) + $this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_product_my_account', function () { + return do_shortcode( '[woocommerce_my_account]' ); + } ) + );$this->registerPlaceholder(new Brizy_Content_Placeholders_Simple( '', 'editor_product_order_tracking', function () { + return do_shortcode( '[woocommerce_order_tracking]' );} ) ); - $this->registerPlaceholder( new Brizy_Content_Placeholders_IgnoreDc('') ); + $this->registerPlaceholder( new Brizy_Content_Placeholders_IgnoreDc('') ); $this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( __( 'WooCommerce Notices', 'brizy' ), @@ -261,14 +221,12 @@ function () { return wc_print_notices( true ); } - return ""; + return ""; }, self::CONFIG_KEY_TEXT ) ); - } - - private function filterData( $property, $post ) { + }private function filterData( $property, $post ) { switch ( $property ) { case 'post_title': return get_the_title( $post ); @@ -388,10 +346,7 @@ private function displayPosts( $posts, $extra_atts ) { @@ -413,10 +368,7 @@ private function getPostExcerpt( $post ) { if ( count( $words ) > $excerpt_length ) { array_pop( $words ); - $the_excerpt = implode( - ' ', - $words - ); // put in excerpt only the number of word that is set in $excerpt_length + $the_excerpt = implode( ' ', $words ); // put in excerpt only the number of word that is set in $excerpt_length } return $the_excerpt; From 09a8f09f25aba0314d7160cb6c6d8edf68abf2df Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Sat, 20 Feb 2021 11:57:59 +0200 Subject: [PATCH 08/45] Upodated editor build branch --- .github/.build-env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.build-env b/.github/.build-env index 8226cbc437..969f3ea23f 100644 --- a/.github/.build-env +++ b/.github/.build-env @@ -1,4 +1,4 @@ BUILD_ENVIRONMENT=develop FREE_BRANCH=develop PRO_BRANCH=develop -EDITOR_BRANCH=dev \ No newline at end of file +EDITOR_BRANCH=improved/docker From 37123d8bea49b98808c16de73a74ac3edd3b38b5 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Sun, 21 Feb 2021 21:28:21 +0200 Subject: [PATCH 09/45] Added post action to delete the context folder --- .github/.build-env | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/.build-env b/.github/.build-env index 969f3ea23f..a5e67b68d3 100644 --- a/.github/.build-env +++ b/.github/.build-env @@ -1,4 +1,4 @@ -BUILD_ENVIRONMENT=develop -FREE_BRANCH=develop -PRO_BRANCH=develop -EDITOR_BRANCH=improved/docker +BUILD_ENVIRONMENT=master +FREE_BRANCH=master +PRO_BRANCH=master +EDITOR_BRANCH=master From e52b4616a36466c128ed0f85994cb3cdaa260e7b Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 10 Jun 2021 16:10:22 +0300 Subject: [PATCH 10/45] fix: Added additional data about the post in editor config. issue: #14426 --- editor/editor/editor.php | 49 +++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/editor/editor/editor.php b/editor/editor/editor.php index 443398e9ad..8a1276f981 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -111,7 +111,8 @@ public function getClientConfig($context) */ public function config($context = self::COMPILE_CONTEXT) { - do_action('brizy_create_editor_config_before'); + do_action('brizy_create_editor_config_before') + ; $cachePostId = ($this->post ? $this->post->getWpPostId() : 0).'_'.$context; if (isset(self::$config[$cachePostId])) { @@ -239,7 +240,7 @@ public function config($context = self::COMPILE_CONTEXT) do_action('brizy_create_editor_config_after'); - return self::$config[$cachePostId]; + return self::$config[$cachePostId] ; } private function addUIConfig($config, $context) @@ -977,6 +978,25 @@ private function addLoopSourcesConfig($config, $isTemplate, $wp_post_id, $contex }, $sources); return $config; + } + + private function addGlobalBlocksData( $config ) { + + $postTaxonomies = get_post_taxonomies( $wp_post_id = (int) $config['wp']['page'] ); + $postTerms = []; + foreach ( $postTaxonomies as $tax ) { + $postTerms = array_merge( $postTerms, wp_get_post_terms( $wp_post_id, $tax ) ); + } + + $postTermsByKeys = []; + foreach ( $postTerms as $term ) { + $postTermsByKeys[ $term->term_id ] = $term; + } + + $config['wp']['post_terms'] = $postTerms; + $config['wp']['post_term_parents'] = array_diff_key($this->getAllParents($postTermsByKeys),$postTermsByKeys); + $config['wp']['post_author'] = (int)$this->post->getWpPost()->post_author; + return $config; } private function addLoopSourcesClientConfig($config, $isTemplate, $wp_post_id, $context) @@ -985,10 +1005,7 @@ private function addLoopSourcesClientConfig($config, $isTemplate, $wp_post_id, $ $config['collectionTypes'] = $sources; return $config; - } - - private function addGlobalBlocksData($config) - { + }private function addGlobalBlocksData($config) { $postTaxonomies = get_post_taxonomies($wp_post_id = (int)$config['wp']['page']); $postTerms = []; @@ -1481,6 +1498,7 @@ private function parseSize($size) } + private function getOneArchiveLink($args = '') { global $wpdb, $wp_locale; @@ -1635,20 +1653,19 @@ private function getTemplateRuleMatches($isTemplate, $wpPostId, $templateRules) 'values' => $rule->getEntityValues(), ); } - $ruleMatches[] = array( + $ruleMatches[] = array( 'type' => Brizy_Admin_Rule::TYPE_INCLUDE, 'group' => Brizy_Admin_Rule::BRIZY_TEMPLATE, 'entityType' => $this->post->getWpPost()->post_type, 'values' => array($wpPostId), - ); - } else { - $ruleMatches[] = array( - 'type' => Brizy_Admin_Rule::TYPE_INCLUDE, - 'group' => Brizy_Admin_Rule::POSTS, - 'entityType' => $this->post->getWpPost()->post_type, - 'values' => array($wpPostId), - ); - } + );} else { + $ruleMatches[] = array( + 'type' => Brizy_Admin_Rule::TYPE_INCLUDE, + 'group' => Brizy_Admin_Rule::POSTS, + 'entityType' => $this->post->getWpPost()->post_type, + 'values' => array( $wpPostId ), + ); + } return $ruleMatches; } From e5cde63e81cc5143935b4aada7e59fff3e41f19c Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Fri, 9 Oct 2020 11:08:40 +0300 Subject: [PATCH 11/45] feat: Filters for post loops For more details see #11810 --- admin/abstract-api.php | 10 +++- admin/main.php | 1 - compatibilities/polylang.php | 2 +- config.php | 36 +++++++++++++ content/context-factory.php | 14 +++--- content/context.php | 77 +++++++++++++++++++++++++++- content/main-processor.php | 18 +++++++ content/placeholder-extractor.php | 21 ++++++-- content/placeholder-provider.php | 4 +- content/placeholder-replacer.php | 27 +++++++--- content/providers/free-provider.php | 4 +- editor/api.php | 78 +++++++++++++++-------------- editor/filters/api.php | 17 +++++++ public/main.php | 1 + 14 files changed, 247 insertions(+), 63 deletions(-) create mode 100644 editor/filters/api.php diff --git a/admin/abstract-api.php b/admin/abstract-api.php index baf46fa4b7..aa466d8ad0 100644 --- a/admin/abstract-api.php +++ b/admin/abstract-api.php @@ -40,6 +40,14 @@ protected function verifyNonce( $action ) { } } + protected function addAjaxAction($action,$callable) { + add_action( 'wp_ajax_' . Brizy_Editor::prefix($action), $callable ); + } + + protected function addNoPrivAjaxAction($action,$callable) { + add_action( 'wp_ajax_nopriv_' . Brizy_Editor::prefix($action), $callable ); + } + /** * @param int|string $name * @@ -67,4 +75,4 @@ protected function error( $code, $message ) { protected function success( $data ) { wp_send_json_success( $data ); } -} \ No newline at end of file +} diff --git a/admin/main.php b/admin/main.php index 6ac2f4ac90..d92fe018d0 100755 --- a/admin/main.php +++ b/admin/main.php @@ -490,7 +490,6 @@ private function enable_brizy_for_post( $p ) { wp_update_post( $p ); } do_action( 'brizy_before_enabled_for_post', $p ); - $post->enable_editor(); $post->set_template( Brizy_Config::BRIZY_BLANK_TEMPLATE_FILE_NAME ); $post->set_plugin_version( BRIZY_VERSION ); diff --git a/compatibilities/polylang.php b/compatibilities/polylang.php index 994286e533..345b7863a9 100644 --- a/compatibilities/polylang.php +++ b/compatibilities/polylang.php @@ -5,7 +5,7 @@ class Brizy_Compatibilities_Polylang { public function __construct() { - add_action( 'brizy_post_loop_args', [ $this, 'post_loop_args' ] ); + add_filter( 'brizy_post_loop_args', [ $this, 'post_loop_args' ] ); add_filter( 'pll_home_url_white_list', [ $this, 'home_url_white_list' ] ); } diff --git a/config.php b/config.php index ec55fd4402..b5ffad9a52 100755 --- a/config.php +++ b/config.php @@ -107,3 +107,39 @@ static public function getTermsOfServiceUrl() { return apply_filters( 'brizy_config_terms_of_service_url', self::TERMS_OF_SERVICE_URL ); } } + + +/* + * // input +{{ filter_option + type="input" + dataSource="manual" +}} + +// range +{{ filter_option + type="range" + dataSource="manual" +}} + +// radio +{{ filter_option + type="radio" + dataSource="manual|query" + matchQuery="entity=taxonomy&entityName=category&valueMatch[property]=name&valueMatch[value]=string&valueMatch[operation]=in|like|<|>|<=|>=|<>|=" +}} + +// checkboxes posts by property match +{{ filter_option + type="checkbox" + dataSource="manual|query" + matchQuery="entity=post&entityName=page&orderBy=name&order=ASC&valueMatch[property]=post_title&valueMatch[value]=Page&valueMatch[operation]=in|like|<|>|<=|>=|<>|=" +}} + +// checkboxes posts by meta match +{{ filter_option + type="checkbox" + dataSource="manual|query" + matchQuery="entity=post&entityName=page&valueMatch[meta]=metaName&valueMatch[value]=Page&valueMatch[operation]=in|like|<|>|<=|>=|<>|=" +}} +*/ diff --git a/content/context-factory.php b/content/context-factory.php index a8070924bf..1b31b8120a 100644 --- a/content/context-factory.php +++ b/content/context-factory.php @@ -17,16 +17,16 @@ class Brizy_Content_ContextFactory * * @return Brizy_Content_Context */ - static public function createContext($project = null, $wp_post = null, $isLoop = false) + static public function createContext($project = null, $wp_post = null, $parentContext = false) { - $context = self::getContext($project, $wp_post); + $context = new Brizy_Content_Context($project, null, $wp_post, null, $parentContext ); - if ($isLoop) { - return apply_filters('brizy_loop_context_create', $context, $wp_post); - } + if ($wp_post) { + $context->setAuthor( $wp_post->post_author ); + } - return apply_filters('brizy_context_create', $context, $wp_post); - } + return apply_filters( 'brizy_context_create', $context ); + } static public function createEmptyContext() { diff --git a/content/context.php b/content/context.php index 9295d24529..44b44daec1 100644 --- a/content/context.php +++ b/content/context.php @@ -5,7 +5,12 @@ class Brizy_Content_Context implements ContextInterface { - private $data = array(); + protected $data = array(); + + /** + * @var Brizy_Content_ContentPlaceholder[] + */ + protected $placeholders = []; /** * @param $name @@ -81,4 +86,72 @@ public function __construct($project = null, $wp_post = null) $this->setWpPost($wp_post); $this->setEntity($wp_post); } -} \ No newline at end of file + + /** + * @return array + */ + public function getPlaceholders() { + return $this->placeholders; + } + + /** + * @param array $placeholders + * + * @return Brizy_Content_Context + */ + public function setPlaceholders( array $placeholders ) { + $this->placeholders = $placeholders; + + return $this; + } + + /** + * @param $id + * + * @return Brizy_Content_ContentPlaceholder|null + */ + public function getPlaceholderById( $id ) { + + $results = $this->getPlaceholdersByAttrValue( 'id', $id ); + + return isset( $results[0] ) ? $results[0] : null; + } + + /** + * @param $key + * @param $value + * + * @return Brizy_Content_ContentPlaceholder|null + * @throws Exception + */ + public function getPlaceholdersByAttrValue( $key, $value ) { + + $results = []; + if ( isset( $this->placeholders ) ) { + foreach ( $this->placeholders as $placeholder ) { + if ( $placeholder->getAttr( $key ) === $value ) { + $results[] = $placeholder; + } + } + } + + return $results; + } + + /** + * @param $attributes + * @return Brizy_Content_ContentPlaceholder|null + */ + public function getPlaceholderByAttrValues( $attributes ) { + + if ( isset( $this->placeholders ) ) { + foreach ( $this->placeholders as $placeholder ) { + if ( count(array_intersect($placeholder->getAttributes(),$attributes))==count($attributes) ) { + return $placeholder; + } + } + } + + return null; + } +} diff --git a/content/main-processor.php b/content/main-processor.php index 1329b15215..6b12bf5721 100644 --- a/content/main-processor.php +++ b/content/main-processor.php @@ -31,6 +31,24 @@ public function __construct( Brizy_Content_Context $context ) { $this->processors[] = new Brizy_Editor_Asset_MediaProcessor(); $this->processors = apply_filters( 'brizy_content_processors', $this->processors, $context ); + + /* CODE BEFORE REBASE. + $urlBuilder = new Brizy_Editor_UrlBuilder( $context->getProject(), $context->getWpPost() ? $context->getWpPost()->ID : null ); + $asset_storage = new Brizy_Editor_Asset_AssetProxyStorage( $urlBuilder ); + $media_storage = new Brizy_Editor_Asset_MediaProxyStorage( $urlBuilder ); + + $this->processors[] = new Brizy_Editor_Asset_AssetProxyProcessor( $asset_storage ); + $this->processors[] = new Brizy_Editor_Asset_MediaAssetProcessor( $media_storage ); + $this->processors[] = new Brizy_Editor_Asset_SvgAssetProcessor( ); + + $this->processors = apply_filters( 'brizy_content_processors', $this->processors, $context ); + + array_unshift( $this->processors, + new Brizy_Editor_Asset_DomainProcessor(), + new Brizy_Content_ShortcodeToPlaceholderProcessor(), + new Brizy_Content_DynamicContentProcessor() + ); + */ } /** diff --git a/content/placeholder-extractor.php b/content/placeholder-extractor.php index 3528a6adf6..62c7d0fafb 100644 --- a/content/placeholder-extractor.php +++ b/content/placeholder-extractor.php @@ -27,7 +27,7 @@ public function __construct($provider) private static function getPlaceholderRegexExpression() { - return "/(?{{\s*(?.+?)(?(?:\s+)((?:\w+\s*=\s*(?:'|\"|\"|\')(?:.[^\"']*|)(?:'|\"|\"|\')\s*)*))?}}(?:(?.*?){{\s*end_(\g{placeholderName})\s*}})?)/ims";; + return "/(?{{\s*(?.+?)\s*(?(?:\s+)((?:\w+(?:\[(?:\w+)?\])?\s*=\s*(?:'|\"|\"|\')(?:.[^\"']*|)(?:'|\"|\"|\')\s*)*))?}}(?:(?.*?){{\s*end_(\g{placeholderName})\s*}})?)/ims"; } public static function stripPlaceholders($content) @@ -96,11 +96,24 @@ private function getPlaceholderAttributes($attributeString) $attrString = trim($attributeString); $attrMatches = array(); $attributes = array(); - preg_match_all("/(\w+)\s*=\s*(?'|\"|\"|\')(.*?)(\g{quote})/mi", $attrString, $attrMatches); + preg_match_all("/((?\w+)(?\[(?\w+)?\])?)\s*=\s*(?'|\"|\"|\')(?.*?)(\g{quote})/mi", $attrString, $attrMatches); if (isset($attrMatches[0]) && is_array($attrMatches[0])) { - foreach ($attrMatches[1] as $i => $name) { - $attributes[$name] = $attrMatches[3][$i]; + foreach ($attrMatches[0] as $i => $attStr) { + $attrName = $attrMatches['attr_name'][$i]; + $attrValue = urldecode($attrMatches['attr_value'][$i]); + $isArray = $attrMatches['array'][$i]!=''; + $arrayKey = $attrMatches['array_key'][$i]; + // check if the attribute is an array + if($isArray) + { + if($arrayKey) + $attributes[$attrName][$arrayKey] = $attrValue; + else + $attributes[$attrName][] = $attrValue; + } else { + $attributes[$attrName] = $attrValue; + } } } diff --git a/content/placeholder-provider.php b/content/placeholder-provider.php index 43d0fb8916..7e58bdc0f1 100644 --- a/content/placeholder-provider.php +++ b/content/placeholder-provider.php @@ -35,12 +35,12 @@ public function __construct($context = null) */ public function getPlaceholders() { - $out = array(); + if (self::$cache_all_placeholders) { return self::$cache_all_placeholders; } - + $out = []; foreach ($this->providers as $provider) { $out = array_merge($out, $provider->getPlaceholders()); } diff --git a/content/placeholder-replacer.php b/content/placeholder-replacer.php index 063f123f36..2c7b11ade9 100644 --- a/content/placeholder-replacer.php +++ b/content/placeholder-replacer.php @@ -19,9 +19,12 @@ class Brizy_Content_PlaceholderReplacer { * * @param $context * @param $placeholderProvider + * @param $extractor */ - public function __construct( $context, $placeholderProvider ) { + public function __construct( $context, $placeholderProvider, $extractor ) { + $this->context = $context; $this->placeholderProvider = $placeholderProvider; + $this->placeholderExtractor = $extractor; } /** @@ -31,37 +34,47 @@ public function __construct( $context, $placeholderProvider ) { * * @return string|string[] */ - public function getContent( $placeholders, $content, $context= null) { + public function getContent( $content) { $toReplace = array(); $toReplaceWithValues = array(); + list( $placeholders, $acontent ) = $this->placeholderExtractor->extract( $content ); - if(!$context) + if(!$this->context) { - $context = Brizy_Content_ContextFactory::createEmptyContext(); + $this->context = Brizy_Content_ContextFactory::createEmptyContext(); } + // set the placeholders found at this level + $this->context->setPlaceholders($placeholders); + + if ( $placeholders ) { foreach ( $placeholders as $contentPlaceholder ) { try { $placeholder = $this->placeholderProvider->getPlaceholder( $contentPlaceholder->getName() ); if ( $placeholder ) { $toReplace[] = $contentPlaceholder->getUid(); - $toReplaceWithValues[] = $placeholder->getValue( $context , $contentPlaceholder ); + $toReplaceWithValues[] = $placeholder->getValue( $this->context , $contentPlaceholder ); } else { $toReplace[] = $contentPlaceholder->getPlaceholder(); $toReplaceWithValues[] = ''; } } catch ( Exception $e ) { + + if (defined('WP_DEBUG') && true === WP_DEBUG) { + var_dump($e); + } + continue; } } } - $content = str_replace( $toReplace, $toReplaceWithValues, $content ); + $acontent = str_replace( $toReplace, $toReplaceWithValues, $acontent ); - return $content; + return $acontent; } } diff --git a/content/providers/free-provider.php b/content/providers/free-provider.php index b9322cd388..e54adf4763 100644 --- a/content/providers/free-provider.php +++ b/content/providers/free-provider.php @@ -5,7 +5,9 @@ class Brizy_Content_Providers_FreeProvider extends Brizy_Content_Providers_AbstractProvider { public function __construct() { - $this->registerPlaceholder( new Brizy_Content_Placeholders_Simple( 'Internal Display Block By User Role', 'display_by_roles', function ( Brizy_Content_Context $context, ContentPlaceholder $contentPlaceholder ) { + $this->registerPlaceholder( + + new Brizy_Content_Placeholders_Simple( 'Internal Display Block By User Role', 'display_by_roles', function( Brizy_Content_Context $context, ContentPlaceholder $contentPlaceholder ) { $attrs = $contentPlaceholder->getAttributes(); diff --git a/editor/api.php b/editor/api.php index 841c5287f2..95770a8240 100755 --- a/editor/api.php +++ b/editor/api.php @@ -21,7 +21,8 @@ class Brizy_Editor_API extends Brizy_Admin_AbstractApi { const AJAX_REMOVE_LOCK = '_remove_lock'; const AJAX_HEARTBEAT = '_heartbeat'; const AJAX_TAKE_OVER = '_take_over'; - const AJAX_JWT_TOKEN = '_multipass_create'; + const AJAX_DOWNLOAD_MEDIA = '_download_media'; + const AJAX_JWT_TOKEN = '_multipass_create'; const AJAX_UPDATE_MENU_DATA = '_update_menu_data'; const AJAX_UPDATE_EDITOR_META_DATA = '_update_editor_meta_data'; const AJAX_UPDATE_MENU_ITEM_DATA = '_update_menu_item_data'; @@ -69,35 +70,35 @@ protected function initializeApiActions() { return; } - $p = 'wp_ajax_' . Brizy_Editor::prefix(); - add_action( $p . self::AJAX_REMOVE_LOCK, array( $this, 'removeProjectLock' ) ); - add_action( $p . self::AJAX_HEARTBEAT, array( $this, 'heartbeat' ) ); - add_action( $p . self::AJAX_TAKE_OVER, array( $this, 'takeOver' ) ); - add_action( $p . self::AJAX_GET, array( $this, 'get_item' ) ); - add_action( $p . self::AJAX_GET_POST_INFO, array( $this, 'get_post_info' ) ); - add_action( $p . self::AJAX_UPDATE, array( $this, 'update_item' ) ); - add_action( $p . self::AJAX_GET_PROJECT, array( $this, 'get_project' ) ); - add_action( $p . self::AJAX_SET_PROJECT, array( $this, 'set_project' ) ); - add_action( $p . self::AJAX_LOCK_PROJECT, array( $this, 'lock_project' ) ); - add_action( $p . self::AJAX_SIDEBARS, array( $this, 'get_sidebars' ) ); - add_action( $p . self::AJAX_SHORTCODE_CONTENT, array( $this, 'shortcode_content' ) ); - add_action( $p . self::AJAX_PLACEHOLDER_CONTENT, array( $this, 'placeholder_content' ) ); - add_action( $p . self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholders_content' ) ); - add_action( $p . self::AJAX_GET_POST_OBJECTS, array( $this, 'get_post_objects' ) ); - add_action( $p . self::AJAX_SEARCH_POST, array( $this, 'search_post' ) ); - add_action( $p . self::AJAX_GET_MENU_LIST, array( $this, 'get_menu_list' ) ); - add_action( $p . self::AJAX_GET_TERMS, array( $this, 'get_terms' ) ); - add_action( $p . self::AJAX_GET_USERS, array( $this, 'get_users' ) ); - add_action( $p . self::AJAX_GET_TERMS_BY, array( $this, 'get_terms_by' ) ); - add_action( $p . self::AJAX_MEDIA_METAKEY, array( $this, 'get_media_key' ) ); - add_action( $p . self::AJAX_CREATE_ATTACHMENT_UID, array( $this, 'get_attachment_key' ) ); - add_action( $p . self::AJAX_SET_FEATURED_IMAGE, array( $this, 'set_featured_image' ) ); - add_action( $p . self::AJAX_SET_IMAGE_FOCAL_PT, array( $this, 'set_featured_image_focal_point' ) ); - add_action( $p . self::AJAX_TIMESTAMP, array( $this, 'timestamp' ) ); - add_action( $p . self::AJAX_SET_TEMPLATE_TYPE, array( $this, 'setTemplateType' ) ); - add_action( $p . self::AJAX_GET_POST_TAXONOMIES, array( $this, 'addPostTaxonomies' ) ); - add_action( $p . self::AJAX_GET_DYNAMIC_CONTENT, array( $this, 'addDynamicContent' ) ); - add_action( $p . 'nopriv_' . Brizy_Editor::prefix( self::AJAX_TIMESTAMP ), array( $this, 'timestamp' ) ); + $this->addAjaxAction( self::AJAX_REMOVE_LOCK, array( $this, 'removeProjectLock' ) ); + $this->addAjaxAction( self::AJAX_HEARTBEAT, array( $this, 'heartbeat' ) ); + $this->addAjaxAction( self::AJAX_TAKE_OVER, array( $this, 'takeOver' ) ); + $this->addAjaxAction( self::AJAX_GET, array( $this, 'get_item' ) ); + $this->addAjaxAction( self::AJAX_GET_POST_INFO, array( $this, 'get_post_info' ) ); + $this->addAjaxAction( self::AJAX_UPDATE, array( $this, 'update_item' ) ); + $this->addAjaxAction( self::AJAX_GET_PROJECT, array( $this, 'get_project' ) ); + $this->addAjaxAction( self::AJAX_SET_PROJECT, array( $this, 'set_project' ) ); + $this->addAjaxAction( self::AJAX_LOCK_PROJECT, array( $this, 'lock_project' ) ); + $this->addAjaxAction( self::AJAX_SIDEBARS, array( $this, 'get_sidebars' ) ); + $this->addAjaxAction( self::AJAX_SHORTCODE_CONTENT, array( $this, 'shortcode_content' ) ); + $this->addAjaxAction( self::AJAX_PLACEHOLDER_CONTENT, array( $this, 'placeholder_content' ) ); + $this->addAjaxAction( self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholders_content' ) ); + $this->addAjaxAction( self::AJAX_GET_POST_OBJECTS, array( $this, 'get_post_objects' ) ); + $this->addAjaxAction( self::AJAX_SEARCH_POST, array( $this, 'search_post' ) ); + $this->addAjaxAction( self::AJAX_GET_MENU_LIST, array( $this, 'get_menu_list' ) ); + $this->addAjaxAction( self::AJAX_GET_TERMS, array( $this, 'get_terms' ) ); + $this->addAjaxAction( self::AJAX_GET_USERS, array( $this, 'get_users' ) ); + $this->addAjaxAction( self::AJAX_GET_TERMS_BY, array( $this, 'get_terms_by' ) ); + $this->addAjaxAction( self::AJAX_MEDIA_METAKEY, array( $this, 'get_media_key' ) ); + $this->addAjaxAction( self::AJAX_CREATE_ATTACHMENT_UID, array( $this, 'get_attachment_key' ) ); + $this->addAjaxAction( self::AJAX_SET_FEATURED_IMAGE, array( $this, 'set_featured_image' ) ); + $this->addAjaxAction( self::AJAX_SET_IMAGE_FOCAL_PT, array( $this, 'set_featured_image_focal_point' ) ); + $this->addAjaxAction( self::AJAX_TIMESTAMP, array( $this, 'timestamp' ) ); + $this->addAjaxAction( self::AJAX_SET_TEMPLATE_TYPE, array( $this, 'setTemplateType' ) ); + $this->addAjaxAction( self::AJAX_GET_POST_TAXONOMIES, array( $this, 'addPostTaxonomies' ) ); + $this->addAjaxAction( self::AJAX_GET_DYNAMIC_CONTENT, array( $this, 'addDynamicContent' ) ); + $this->addAjaxAction( self::AJAX_DOWNLOAD_MEDIA, array( $this, 'download_media' ) ); + $this->addNoPrivAjaxAction( Brizy_Editor::prefix( self::AJAX_TIMESTAMP ), array($this, 'timestamp')); } @@ -620,13 +621,16 @@ private function getPostSample( $templateId ) { ], ]; - $values = $rule->getEntityValues(); - $posts = []; - if ( empty( $values[0] ) ) { - // For All condition - $posts = get_posts( $args ); - } else { - $filter = $values[0]; + $values = $rule->getEntityValues(); + $posts = []; + if (empty($values[0])) { + // For All condition + $posts = get_posts($args); + + } else { + + + $filter = $values[0]; if ( is_numeric( $filter ) ) { $args['post__in'] = [ $filter ]; diff --git a/editor/filters/api.php b/editor/filters/api.php new file mode 100644 index 0000000000..dd5dfdf2b5 --- /dev/null +++ b/editor/filters/api.php @@ -0,0 +1,17 @@ +addAjaxAction( self::AJAX_FILTER, array( $this, 'removeProjectLock' ) ); + } + + protected function getRequestNonce() { + return $this->param( 'hash' ); + } +} diff --git a/public/main.php b/public/main.php index 941b079194..bf89d35661 100755 --- a/public/main.php +++ b/public/main.php @@ -1,5 +1,6 @@ Date: Fri, 2 Apr 2021 10:40:06 +0300 Subject: [PATCH 12/45] .... --- brizy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brizy.php b/brizy.php index 74b4254efa..706d578cd3 100755 --- a/brizy.php +++ b/brizy.php @@ -134,4 +134,4 @@ function brizy_load_text_domain() load_plugin_textdomain('brizy', false, dirname(plugin_basename(__FILE__)).'/languages'); } -new Brizy_Compatibilities_Init(); +new Brizy_Compatibilities_Init(); \ No newline at end of file From 15551334d74754ad31d7bfd2998c29da59cb5a69 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 28 Apr 2021 15:09:46 +0300 Subject: [PATCH 13/45] ... --- content/context.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/context.php b/content/context.php index 44b44daec1..b52d9e8ef0 100644 --- a/content/context.php +++ b/content/context.php @@ -129,7 +129,7 @@ public function getPlaceholdersByAttrValue( $key, $value ) { $results = []; if ( isset( $this->placeholders ) ) { foreach ( $this->placeholders as $placeholder ) { - if ( $placeholder->getAttr( $key ) === $value ) { + if ( $placeholder->getAttr( $key ) == $value ) { $results[] = $placeholder; } } From 59de4d0d2ac2185be084ffc7da9137cdf0bb0752 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 29 Apr 2021 15:50:18 +0300 Subject: [PATCH 14/45] feat: added nested filters --- content/context.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/context.php b/content/context.php index b52d9e8ef0..b7edc5c780 100644 --- a/content/context.php +++ b/content/context.php @@ -126,6 +126,8 @@ public function getPlaceholderById( $id ) { */ public function getPlaceholdersByAttrValue( $key, $value ) { + if(is_null($value)) return null; + $results = []; if ( isset( $this->placeholders ) ) { foreach ( $this->placeholders as $placeholder ) { From 6afee0b9624a83af0625eaab3535eaac3a768cd5 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 29 Jul 2021 14:52:15 +0300 Subject: [PATCH 15/45] fix: changes after rebase --- content/context.php | 52 ++++++++++++++++--------------- content/placeholder-replacer.php | 1 - content/placeholders/abstract.php | 2 +- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/content/context.php b/content/context.php index b7edc5c780..b4ac31505a 100644 --- a/content/context.php +++ b/content/context.php @@ -1,5 +1,6 @@ data[$key] = $value; } - /** - * BrizyPro_Content_Context constructor. - * - * @param $project - * @param $wp_post - */ - public function __construct($project = null, $wp_post = null) - { - $this->setProject($project); - $this->setWpPost($wp_post); - $this->setEntity($wp_post); + /** + * BrizyPro_Content_Context constructor. + * + * @param $project + * @param $wp_post + */ + public function __construct($project, $brizy_post, $wp_post, $contentHtml, $parentContext = null ) { + $this->setProject( $project ); + $this->setWpPost( $wp_post ); + $this->setParentContext( $parentContext ); + $this->setEntity($wp_post); + } + + public function afterExtract($contentPlaceholders, $instancePlaceholders, $contentAfterExtractor) { + $this->setPlaceholders($contentPlaceholders); } /** @@ -105,11 +110,10 @@ public function setPlaceholders( array $placeholders ) { return $this; } - /** - * @param $id - * - * @return Brizy_Content_ContentPlaceholder|null - */ + /** + * @param $id + * @return mixed|null + */ public function getPlaceholderById( $id ) { $results = $this->getPlaceholdersByAttrValue( 'id', $id ); @@ -117,13 +121,11 @@ public function getPlaceholderById( $id ) { return isset( $results[0] ) ? $results[0] : null; } - /** - * @param $key - * @param $value - * - * @return Brizy_Content_ContentPlaceholder|null - * @throws Exception - */ + /** + * @param $key + * @param $value + * @return array|null + */ public function getPlaceholdersByAttrValue( $key, $value ) { if(is_null($value)) return null; @@ -131,7 +133,7 @@ public function getPlaceholdersByAttrValue( $key, $value ) { $results = []; if ( isset( $this->placeholders ) ) { foreach ( $this->placeholders as $placeholder ) { - if ( $placeholder->getAttr( $key ) == $value ) { + if ( $placeholder->getAttribute( $key ) == $value ) { $results[] = $placeholder; } } diff --git a/content/placeholder-replacer.php b/content/placeholder-replacer.php index 2c7b11ade9..a30aa448d7 100644 --- a/content/placeholder-replacer.php +++ b/content/placeholder-replacer.php @@ -48,7 +48,6 @@ public function getContent( $content) { // set the placeholders found at this level $this->context->setPlaceholders($placeholders); - if ( $placeholders ) { foreach ( $placeholders as $contentPlaceholder ) { try { diff --git a/content/placeholders/abstract.php b/content/placeholders/abstract.php index b17c2bdba6..30465295e4 100644 --- a/content/placeholders/abstract.php +++ b/content/placeholders/abstract.php @@ -69,7 +69,7 @@ public function support($placeholderName) public function shouldFallbackValue($value, ContextInterface $context, ContentPlaceholder $placeholder) { - return empty($value); + return is_null($value) || $value==""; } public function getFallbackValue(ContextInterface $context, ContentPlaceholder $placeholder) From 1781bb0e2a3834c8495d5940d50938e9f0592d1a Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 27 Oct 2021 15:26:24 +0300 Subject: [PATCH 16/45] ... --- content/context.php | 12 +++++++---- editor/editor/editor.php | 45 ---------------------------------------- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/content/context.php b/content/context.php index b4ac31505a..9d33973b66 100644 --- a/content/context.php +++ b/content/context.php @@ -88,10 +88,6 @@ public function __construct($project, $brizy_post, $wp_post, $contentHtml, $pare $this->setEntity($wp_post); } - public function afterExtract($contentPlaceholders, $instancePlaceholders, $contentAfterExtractor) { - $this->setPlaceholders($contentPlaceholders); - } - /** * @return array */ @@ -139,6 +135,10 @@ public function getPlaceholdersByAttrValue( $key, $value ) { } } + if($context = $this->getParentContext()) { + $results = array_merge($results,$context->getPlaceholdersByAttrValue($key, $value)); + } + return $results; } @@ -156,6 +156,10 @@ public function getPlaceholderByAttrValues( $attributes ) { } } + if($context = $this->getParentContext()) { + return $context->getPlaceholderByAttrValues($attributes); + } + return null; } } diff --git a/editor/editor/editor.php b/editor/editor/editor.php index 8a1276f981..79ebe87392 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -1004,54 +1004,9 @@ private function addLoopSourcesClientConfig($config, $isTemplate, $wp_post_id, $ $sources = $this->getPostLoopSources($isTemplate, $wp_post_id, $context); $config['collectionTypes'] = $sources; - return $config; - }private function addGlobalBlocksData($config) { - - $postTaxonomies = get_post_taxonomies($wp_post_id = (int)$config['wp']['page']); - $postTerms = []; - foreach ($postTaxonomies as $tax) { - $postTerms = array_merge($postTerms, wp_get_post_terms($wp_post_id, $tax)); - } - - $postTermsByKeys = []; - foreach ($postTerms as $term) { - $postTermsByKeys[$term->term_id] = $term; - } - - $config['wp']['postTerms'] = $postTerms; - $config['wp']['postTermParents'] = array_values( - array_diff_key($this->getAllParents($postTermsByKeys), $postTermsByKeys) - ); - $config['wp']['postAuthor'] = (int)$this->post->getWpPost()->post_author; - return $config; } - /** - * @return object - */ - private function get_page_attachments() - { - global $wpdb; - $query = $wpdb->prepare( - "SELECT - pm.* - FROM - {$wpdb->prefix}postmeta pm - JOIN {$wpdb->prefix}postmeta pm2 ON pm2.post_id=pm.post_id AND pm2.meta_key='brizy_post_uid' AND pm2.meta_value=%s - WHERE pm.meta_key='brizy_attachment_uid' - GROUP BY pm.post_id", - $this->post->getUid() - ); - - $results = $wpdb->get_results($query); - $attachment_data = array(); - foreach ($results as $row) { - $attachment_data[$row->meta_value] = true; - } - - return (object)$attachment_data; - } /** * @return array|null From a93a177b222ad2c3929f654f827eba51eae94d69 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 29 Nov 2021 14:12:39 +0200 Subject: [PATCH 17/45] fix: placehodersContent action --- editor/api.php | 17 +++---- editor/editor/editor.php | 100 +++++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 60 deletions(-) diff --git a/editor/api.php b/editor/api.php index 95770a8240..aa7757aff6 100755 --- a/editor/api.php +++ b/editor/api.php @@ -83,6 +83,7 @@ protected function initializeApiActions() { $this->addAjaxAction( self::AJAX_SHORTCODE_CONTENT, array( $this, 'shortcode_content' ) ); $this->addAjaxAction( self::AJAX_PLACEHOLDER_CONTENT, array( $this, 'placeholder_content' ) ); $this->addAjaxAction( self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholders_content' ) ); + $this->addAjaxAction( self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholder_content' ) ); $this->addAjaxAction( self::AJAX_GET_POST_OBJECTS, array( $this, 'get_post_objects' ) ); $this->addAjaxAction( self::AJAX_SEARCH_POST, array( $this, 'search_post' ) ); $this->addAjaxAction( self::AJAX_GET_MENU_LIST, array( $this, 'get_menu_list' ) ); @@ -542,16 +543,12 @@ public function placeholder_content() { $contents[] = apply_filters( 'brizy_content', $placeholder, Brizy_Editor_Project::get(), $post ); } - $this->success( - array( - 'placeholders' => $contents, - ) - ); - } catch ( Exception $exception ) { - Brizy_Logger::instance()->exception( $exception ); - $this->error( $exception->getCode(), $exception->getMessage() ); - } - } + $this->success(array('placeholders' => $contents)); + } catch (Exception $exception) { + Brizy_Logger::instance()->exception($exception); + $this->error($exception->getCode(), $exception->getMessage()); + } + } public function placeholders_content() { global $post, $wp_query; diff --git a/editor/editor/editor.php b/editor/editor/editor.php index 79ebe87392..0c118f363e 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -1744,50 +1744,50 @@ public function getApiActions($config = [], $context = null) $actions = array( 'hash' => wp_create_nonce(Brizy_Editor_API::nonce), 'url' => set_url_scheme(admin_url('admin-ajax.php')), - 'heartBeat' => $pref.Brizy_Editor_API::AJAX_HEARTBEAT, - 'takeOver' => $pref.Brizy_Editor_API::AJAX_TAKE_OVER, - 'lockProject' => $pref.Brizy_Editor_API::AJAX_LOCK_PROJECT, - 'removeLock' => $pref.Brizy_Editor_API::AJAX_REMOVE_LOCK, - 'getPage' => $pref.Brizy_Editor_API::AJAX_GET, - 'getPostInfo' => $pref.Brizy_Editor_API::AJAX_GET_POST_INFO, - 'updatePage' => $pref.Brizy_Editor_API::AJAX_UPDATE, - 'getProject' => $pref.Brizy_Editor_API::AJAX_GET_PROJECT, - 'setProject' => $pref.Brizy_Editor_API::AJAX_SET_PROJECT, - 'setProjectMeta' => $pref.Brizy_Editor_API::AJAX_UPDATE_EDITOR_META_DATA, - 'getGlobalBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_GLOBAL_BLOCKS_ACTION, - 'createGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_GLOBAL_BLOCK_ACTION, - 'updateGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCK_ACTION, - 'updateGlobalBlocks' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCKS_ACTION, - 'deleteGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_GLOBAL_BLOCK_ACTION, - 'getRuleGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_GROUP_LIST, - 'getLayoutByUid' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUT_BY_UID_ACTION, - 'getLayoutList' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUTS_ACTION, - 'createLayout' => $pref.Brizy_Admin_Layouts_Api::CREATE_LAYOUT_ACTION, - 'updateLayout' => $pref.Brizy_Admin_Layouts_Api::UPDATE_LAYOUT_ACTION, - 'deleteLayout' => $pref.Brizy_Admin_Layouts_Api::DELETE_LAYOUT_ACTION, - 'cloudSignIn' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNIN_ACTION, - 'cloudSignUp' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNUP_ACTION, - 'cloudSignOut' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNOUT_ACTION, - 'cloudSyncAllowed' => $pref.Brizy_Admin_Cloud_Api::AJAX_SYNC_ALLOWED, - 'cloudResetPassword' => $pref.Brizy_Admin_Cloud_Api::AJAX_RESET_PASSWORD_ACTION, - 'cloudSync' => $pref.Brizy_Admin_Cloud_Api::AJAX_TRIGGER_SYNC_ACTION, - 'createRule' => $pref.Brizy_Admin_Rules_Api::CREATE_RULE_ACTION, - 'createRules' => $pref.Brizy_Admin_Rules_Api::CREATE_RULES_ACTION, - 'updateRules' => $pref.Brizy_Admin_Rules_Api::UPDATE_RULES_ACTION, - 'deleteRule' => $pref.Brizy_Admin_Rules_Api::DELETE_RULE_ACTION, - 'getRuleList' => $pref.Brizy_Admin_Rules_Api::LIST_RULE_ACTION, - 'updateBlockPositions' => $pref.Brizy_Admin_Blocks_Api::UPDATE_POSITIONS_ACTION, - 'getSavedBlockByUid' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCK_ACTION, - 'getSavedBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCKS_ACTION, - 'createSavedBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_SAVED_BLOCK_ACTION, - 'updateSavedBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_SAVED_BLOCK_ACTION, - 'deleteSavedBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_SAVED_BLOCK_ACTION, - 'downloadBlocks' => $pref.Brizy_Admin_Blocks_Api::DOWNLOAD_BLOCKS, - 'uploadBlocks' => $pref.Brizy_Admin_Blocks_Api::UPLOAD_BLOCKS, - 'downloadLayouts' => $pref.Brizy_Admin_Layouts_Api::DOWNLOAD_LAYOUTS, - 'uploadLayouts' => $pref.Brizy_Admin_Layouts_Api::UPLOAD_LAYOUTS, - 'media' => $pref.Brizy_Editor_API::AJAX_MEDIA, - 'getMediaUid' => $pref.Brizy_Editor_API::AJAX_MEDIA_METAKEY, + 'heartBeat' => $pref.Brizy_Editor_API::AJAX_HEARTBEAT, + 'takeOver' => $pref.Brizy_Editor_API::AJAX_TAKE_OVER, + 'lockProject' => $pref.Brizy_Editor_API::AJAX_LOCK_PROJECT, + 'removeLock' => $pref.Brizy_Editor_API::AJAX_REMOVE_LOCK, + 'getPage' => $pref.Brizy_Editor_API::AJAX_GET, + 'getPostInfo' => $pref.Brizy_Editor_API::AJAX_GET_POST_INFO, + 'updatePage' => $pref.Brizy_Editor_API::AJAX_UPDATE, + 'getProject' => $pref.Brizy_Editor_API::AJAX_GET_PROJECT, + 'setProject' => $pref.Brizy_Editor_API::AJAX_SET_PROJECT, + 'setProjectMeta' => $pref.Brizy_Editor_API::AJAX_UPDATE_EDITOR_META_DATA, + 'getGlobalBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_GLOBAL_BLOCKS_ACTION, + 'createGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_GLOBAL_BLOCK_ACTION, + 'updateGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCK_ACTION, + 'updateGlobalBlocks' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCKS_ACTION, + 'deleteGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_GLOBAL_BLOCK_ACTION, + 'getRuleGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_GROUP_LIST, + 'getLayoutByUid' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUT_BY_UID_ACTION, + 'getLayoutList' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUTS_ACTION, + 'createLayout' => $pref.Brizy_Admin_Layouts_Api::CREATE_LAYOUT_ACTION, + 'updateLayout' => $pref.Brizy_Admin_Layouts_Api::UPDATE_LAYOUT_ACTION, + 'deleteLayout' => $pref.Brizy_Admin_Layouts_Api::DELETE_LAYOUT_ACTION, + 'cloudSignIn' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNIN_ACTION, + 'cloudSignUp' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNUP_ACTION, + 'cloudSignOut' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNOUT_ACTION, + 'cloudSyncAllowed' => $pref.Brizy_Admin_Cloud_Api::AJAX_SYNC_ALLOWED, + 'cloudResetPassword' => $pref.Brizy_Admin_Cloud_Api::AJAX_RESET_PASSWORD_ACTION, + 'cloudSync' => $pref.Brizy_Admin_Cloud_Api::AJAX_TRIGGER_SYNC_ACTION, + 'createRule' => $pref.Brizy_Admin_Rules_Api::CREATE_RULE_ACTION, + 'createRules' => $pref.Brizy_Admin_Rules_Api::CREATE_RULES_ACTION, + 'updateRules' => $pref.Brizy_Admin_Rules_Api::UPDATE_RULES_ACTION, + 'deleteRule' => $pref.Brizy_Admin_Rules_Api::DELETE_RULE_ACTION, + 'getRuleList' => $pref.Brizy_Admin_Rules_Api::LIST_RULE_ACTION, + 'updateBlockPositions' => $pref.Brizy_Admin_Blocks_Api::UPDATE_POSITIONS_ACTION, + 'getSavedBlockByUid' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCK_ACTION, + 'getSavedBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCKS_ACTION, + 'createSavedBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_SAVED_BLOCK_ACTION, + 'updateSavedBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_SAVED_BLOCK_ACTION, + 'deleteSavedBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_SAVED_BLOCK_ACTION, + 'downloadBlocks' => $pref.Brizy_Admin_Blocks_Api::DOWNLOAD_BLOCKS, + 'uploadBlocks' => $pref.Brizy_Admin_Blocks_Api::UPLOAD_BLOCKS, + 'downloadLayouts' => $pref.Brizy_Admin_Layouts_Api::DOWNLOAD_LAYOUTS, + 'uploadLayouts' => $pref.Brizy_Admin_Layouts_Api::UPLOAD_LAYOUTS, + 'media' => $pref.Brizy_Editor_API::AJAX_MEDIA, + 'getMediaUid' => $pref.Brizy_Editor_API::AJAX_MEDIA_METAKEY, 'getAttachmentUid' => $pref.Brizy_Editor_API::AJAX_CREATE_ATTACHMENT_UID, 'getServerTimeStamp' => $pref.Brizy_Editor_API::AJAX_TIMESTAMP, 'createBlockScreenshot' => $pref.Brizy_Editor_BlockScreenshotApi::AJAX_CREATE_BLOCK_SCREENSHOT, @@ -1796,7 +1796,7 @@ public function getApiActions($config = [], $context = null) 'shortcodeContent' => $pref.Brizy_Editor_API::AJAX_SHORTCODE_CONTENT, 'placeholderContent' => $pref.Brizy_Editor_API::AJAX_PLACEHOLDER_CONTENT, 'placeholdersContent' => $pref.Brizy_Editor_API::AJAX_PLACEHOLDERS_CONTENT, - 'getPostTaxonomies' => $pref.Brizy_Editor_API::AJAX_GET_POST_TAXONOMIES, + 'getPostTaxonomies' => $pref.Brizy_Editor_API::AJAX_GET_POST_TAXONOMIES, 'getMenus' => $pref.Brizy_Editor_API::AJAX_GET_MENU_LIST, 'getTerms' => $pref.Brizy_Editor_API::AJAX_GET_TERMS, 'getTermsBy' => $pref.Brizy_Editor_API::AJAX_GET_TERMS_BY, @@ -1826,11 +1826,11 @@ public function getApiActions($config = [], $context = null) 'rulePostsGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_POSTS_GROUP_LIST, 'ruleArchiveGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_ARCHIVE_GROUP_LIST, 'ruleTemplateGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_TEMPLATE_GROUP_LIST, - 'symbolCreate' => $pref.Brizy_Admin_Symbols_Api::CREATE_ACTION, - 'symbolUpdate' => $pref.Brizy_Admin_Symbols_Api::UPDATE_ACTION, - 'symbolDelete' => $pref.Brizy_Admin_Symbols_Api::DELETE_ACTION, - 'symbolList' => $pref.Brizy_Admin_Symbols_Api::LIST_ACTION, - 'getDynamicContentPlaceholders' => $pref.Brizy_Editor_API::AJAX_GET_DYNAMIC_CONTENT, + 'symbolCreate' => $pref.Brizy_Admin_Symbols_Api::CREATE_ACTION, + 'symbolUpdate' => $pref.Brizy_Admin_Symbols_Api::UPDATE_ACTION, + 'symbolDelete' => $pref.Brizy_Admin_Symbols_Api::DELETE_ACTION, + 'symbolList' => $pref.Brizy_Admin_Symbols_Api::LIST_ACTION, + 'getDynamicContentPlaceholders' => $pref.Brizy_Editor_API::AJAX_GET_DYNAMIC_CONTENT, ); return $actions; From 9a531c5898c8cf0746aff935dd7f56027a90fe30 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 29 Nov 2021 16:08:18 +0200 Subject: [PATCH 18/45] fix: fixed get placeholders content action --- editor/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/api.php b/editor/api.php index aa7757aff6..0fb2032616 100755 --- a/editor/api.php +++ b/editor/api.php @@ -83,7 +83,7 @@ protected function initializeApiActions() { $this->addAjaxAction( self::AJAX_SHORTCODE_CONTENT, array( $this, 'shortcode_content' ) ); $this->addAjaxAction( self::AJAX_PLACEHOLDER_CONTENT, array( $this, 'placeholder_content' ) ); $this->addAjaxAction( self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholders_content' ) ); - $this->addAjaxAction( self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholder_content' ) ); + $this->addAjaxAction( self::AJAX_PLACEHOLDERS_CONTENT, array( $this, 'placeholders_content' ) ); $this->addAjaxAction( self::AJAX_GET_POST_OBJECTS, array( $this, 'get_post_objects' ) ); $this->addAjaxAction( self::AJAX_SEARCH_POST, array( $this, 'search_post' ) ); $this->addAjaxAction( self::AJAX_GET_MENU_LIST, array( $this, 'get_menu_list' ) ); From 0e2a9d3993a08b5434e647e62c5ca1d038483ac8 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 14 Feb 2022 14:50:47 +0200 Subject: [PATCH 19/45] new: filter placeholder content ... --- editor/filters/api.php | 46 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/editor/filters/api.php b/editor/filters/api.php index dd5dfdf2b5..b8e11bcaa0 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -2,16 +2,58 @@ class Brizy_Editor_Filters_Api extends Brizy_Admin_AbstractApi { - const AJAX_FILTER = 'asss'; + const nonce = 'brizy-api'; + const AJAX_FILTER_PLACEHOLDERS_CONTENT = '_filter_placeholders_content'; protected function initializeApiActions() { if ( ! Brizy_Editor_User::is_user_allowed() ) { return; } - $this->addAjaxAction( self::AJAX_FILTER, array( $this, 'removeProjectLock' ) ); + $this->addAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); } protected function getRequestNonce() { return $this->param( 'hash' ); } + + public function filterPlaceholdersContent() { + $this->verifyNonce(self::nonce); + + if(empty($postId = $this->param('post_id'))) { + $this->error(400, 'Please provide the post id'); + } + + if(empty($postLoopId = $this->param('post_loop_id'))) { + $this->error(400, 'Please provide the post loop id'); + } + + if(empty($placeholders = $this->param('placeholders'))) { + $this->error(400, 'Please provide the placeholders param'); + } + + $brizyPost = Brizy_Editor_Post::get($postId); + $postContent = $this->getBrizyPostContent(Brizy_Editor_Project::get(), $brizyPost); + + } + + private function getBrizyPostContent(Brizy_Editor_Project $project,Brizy_Editor_Post $post) { + $project = Brizy_Editor_Project::get(); + + if (!$post->get_compiled_html()) { + $compiled_html_body = $post->get_compiled_html_body(); + $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); + $post->set_needs_compile(true)->saveStorage(); + } else { + $compiled_page = $post->get_compiled_page(); + $content = $compiled_page->get_body(); + } + + return apply_filters( + 'brizy_content', + $content, + $project, + $post->getWpPost(), + 'body' + ); + } } From daa0c4b9e27b09f70b3a7089aa7fb7f0815e22af Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Tue, 15 Feb 2022 10:22:54 +0200 Subject: [PATCH 20/45] new: filter placeholder content --- editor.php | 1 + editor/editor/editor.php | 7 ++++--- editor/filters/api.php | 30 ++++++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/editor.php b/editor.php index 0d3c64c3f2..e110ba0297 100755 --- a/editor.php +++ b/editor.php @@ -332,6 +332,7 @@ private function loadEditorApi( $post, $user ) { new Brizy_Editor_RestExtend(); new Brizy_Editor_API( $post ); new Brizy_Editor_BlockScreenshotApi( $post ); + new Brizy_Editor_Filters_Api( ); Brizy_Editor_Accounts_Api::_init(); } diff --git a/editor/editor/editor.php b/editor/editor/editor.php index 0c118f363e..bf711d1639 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -1826,12 +1826,13 @@ public function getApiActions($config = [], $context = null) 'rulePostsGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_POSTS_GROUP_LIST, 'ruleArchiveGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_ARCHIVE_GROUP_LIST, 'ruleTemplateGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_TEMPLATE_GROUP_LIST, - 'symbolCreate' => $pref.Brizy_Admin_Symbols_Api::CREATE_ACTION, + 'symbolCreate' => $pref.Brizy_Admin_Symbols_Api::CREATE_ACTION, 'symbolUpdate' => $pref.Brizy_Admin_Symbols_Api::UPDATE_ACTION, 'symbolDelete' => $pref.Brizy_Admin_Symbols_Api::DELETE_ACTION, 'symbolList' => $pref.Brizy_Admin_Symbols_Api::LIST_ACTION, - 'getDynamicContentPlaceholders' => $pref.Brizy_Editor_API::AJAX_GET_DYNAMIC_CONTENT, - ); + 'getDynamicContentPlaceholders' => $pref.Brizy_Editor_API::AJAX_GET_DYNAMIC_CONTENT, + 'filterPlaceholderContents' => $pref . Brizy_Editor_Filters_Api::AJAX_FILTER_PLACEHOLDERS_CONTENT, + ); return $actions; } diff --git a/editor/filters/api.php b/editor/filters/api.php index b8e11bcaa0..d2285c8487 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -23,17 +23,39 @@ public function filterPlaceholdersContent() { $this->error(400, 'Please provide the post id'); } - if(empty($postLoopId = $this->param('post_loop_id'))) { - $this->error(400, 'Please provide the post loop id'); - } - if(empty($placeholders = $this->param('placeholders'))) { $this->error(400, 'Please provide the placeholders param'); } + $placeholderContents = []; $brizyPost = Brizy_Editor_Post::get($postId); $postContent = $this->getBrizyPostContent(Brizy_Editor_Project::get(), $brizyPost); + $placeholderProvider = new Brizy_Content_PlaceholderProvider(); + $context = new Brizy_Content_Context(Brizy_Editor_Project::get(),$brizyPost,$brizyPost->getWpPost(),''); + $context->setProvider( $placeholderProvider ); + $extractor = new \BrizyPlaceholders\Extractor( $placeholderProvider ); + + /** + * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders; + */ + list( $contentPlaceholders, $placeholderInstances, $newPostContent ) = $extractor->extract( $postContent ); + $context->setPlaceholders($contentPlaceholders); + + foreach( $placeholders as $placeholderId) { + /** + * @var \BrizyPlaceholders\ContentPlaceholder $placeholder; + */ + $placeholder = $context->getPlaceholderById($placeholderId); + /** + * @var Brizy_Content_Placeholders_Abstract $placeholderInstance; + */ + $placeholderInstance = $placeholderProvider->getPlaceholderSupportingName($placeholder->getName()); + $placeholderContents[$placeholderId] = $placeholderInstance->getValue($context,$placeholder); + } + + + $this->success(['placeholders'=>$placeholderContents]); } private function getBrizyPostContent(Brizy_Editor_Project $project,Brizy_Editor_Post $post) { From 9f0a8acaba3aa2bb5d9a8a5bde26a1c6b1336081 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 17 Feb 2022 09:41:04 +0200 Subject: [PATCH 21/45] fix: made the filter placeholder content action public --- editor.php | 3 ++- editor/filters/api.php | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/editor.php b/editor.php index e110ba0297..4e02c8c234 100755 --- a/editor.php +++ b/editor.php @@ -328,11 +328,12 @@ public function registerCustomPostTemplates() { */ private function loadEditorApi( $post, $user ) { try { + new Brizy_Editor_Filters_Api( ); + if ( Brizy_Editor_User::is_user_allowed() ) { new Brizy_Editor_RestExtend(); new Brizy_Editor_API( $post ); new Brizy_Editor_BlockScreenshotApi( $post ); - new Brizy_Editor_Filters_Api( ); Brizy_Editor_Accounts_Api::_init(); } diff --git a/editor/filters/api.php b/editor/filters/api.php index d2285c8487..fa2f741bae 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -6,10 +6,7 @@ class Brizy_Editor_Filters_Api extends Brizy_Admin_AbstractApi { const AJAX_FILTER_PLACEHOLDERS_CONTENT = '_filter_placeholders_content'; protected function initializeApiActions() { - if ( ! Brizy_Editor_User::is_user_allowed() ) { - return; - } - $this->addAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); + $this->addNoPrivAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); } protected function getRequestNonce() { @@ -17,7 +14,6 @@ protected function getRequestNonce() { } public function filterPlaceholdersContent() { - $this->verifyNonce(self::nonce); if(empty($postId = $this->param('post_id'))) { $this->error(400, 'Please provide the post id'); @@ -47,6 +43,9 @@ public function filterPlaceholdersContent() { * @var \BrizyPlaceholders\ContentPlaceholder $placeholder; */ $placeholder = $context->getPlaceholderById($placeholderId); + + if(!$placeholder) continue; + /** * @var Brizy_Content_Placeholders_Abstract $placeholderInstance; */ From a9014194bef30ff2b53fc394d98ead4da71ce0f3 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 17 Feb 2022 10:49:51 +0200 Subject: [PATCH 22/45] fix: fixed the content parsed for filter placeholders --- editor/filters/api.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/editor/filters/api.php b/editor/filters/api.php index fa2f741bae..1595f34d38 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -7,6 +7,7 @@ class Brizy_Editor_Filters_Api extends Brizy_Admin_AbstractApi { protected function initializeApiActions() { $this->addNoPrivAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); + $this->addAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); } protected function getRequestNonce() { @@ -69,12 +70,6 @@ private function getBrizyPostContent(Brizy_Editor_Project $project,Brizy_Editor_ $content = $compiled_page->get_body(); } - return apply_filters( - 'brizy_content', - $content, - $project, - $post->getWpPost(), - 'body' - ); + return $content; } } From 541471abe18b13c51ecac4400d70e054f23618d5 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 18 May 2022 16:49:04 +0300 Subject: [PATCH 23/45] fix: added page placeholders in context --- content/dynamic-content-processor.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/content/dynamic-content-processor.php b/content/dynamic-content-processor.php index 309d7e4e83..7374928cde 100644 --- a/content/dynamic-content-processor.php +++ b/content/dynamic-content-processor.php @@ -18,6 +18,15 @@ public function process( $content, Brizy_Content_Context $context ) { $context->setProvider( $placeholderProvider ); + // load all page placeholders + $postContent = $this->getBrizyPostContent($context->getProject(), Brizy_Editor_Post::get($context->getWpPost())); + /** + * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders; + */ + list( $contentPlaceholders, $placeholderInstances, $newPostContent ) = $extractor->extract( $postContent ); + $context->setPlaceholders($contentPlaceholders); + + list( $contentPlaceholders, $placeholderInstances, $content ) = $extractor->extract( $content ); $replacer = new Replacer( $placeholderProvider ); @@ -26,4 +35,20 @@ public function process( $content, Brizy_Content_Context $context ) { return $content; } + + + private function getBrizyPostContent(Brizy_Editor_Project $project,Brizy_Editor_Post $post) { + $project = Brizy_Editor_Project::get(); + + if (!$post->get_compiled_html()) { + $compiled_html_body = $post->get_compiled_html_body(); + $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); + $post->set_needs_compile(true)->saveStorage(); + } else { + $compiled_page = $post->get_compiled_page(); + $content = $compiled_page->get_body(); + } + + return $content; + } } From a2dee0920165feab53b1e5c18f6aae377328ce67 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 19 May 2022 15:31:19 +0300 Subject: [PATCH 24/45] fix: added placeholders in context --- editor/post.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/editor/post.php b/editor/post.php index bad079cf42..1a33ac40fc 100755 --- a/editor/post.php +++ b/editor/post.php @@ -329,7 +329,9 @@ private function getPostContent($noFilters) $this->get_compiled_html() ); - $replacer = new \BrizyPlaceholders\Replacer($placeholderProvider); + $context->setPlaceholders($placeholders); + + $replacer = new \BrizyPlaceholders\Replacer($placeholderProvider); $content = $replacer->replaceWithExtractedData($placeholders, $placeholderInstances, $content, $context); $content = $extractor->stripPlaceholders($content); From 71dd5a12ceb2ece6e638186bb0d16c0152cefcae Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Fri, 20 May 2022 15:49:47 +0300 Subject: [PATCH 25/45] fix: optimized dynamic content processor --- content/dynamic-content-processor.php | 72 ++++++++++++++++----------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/content/dynamic-content-processor.php b/content/dynamic-content-processor.php index 7374928cde..9383cc27e2 100644 --- a/content/dynamic-content-processor.php +++ b/content/dynamic-content-processor.php @@ -3,50 +3,64 @@ use BrizyPlaceholders\Extractor; use BrizyPlaceholders\Replacer; -class Brizy_Content_DynamicContentProcessor implements Brizy_Editor_Content_ProcessorInterface { +class Brizy_Content_DynamicContentProcessor implements Brizy_Editor_Content_ProcessorInterface +{ - /** - * @param string $content - * @param Brizy_Content_Context $context - * - * @return mixed - */ - public function process( $content, Brizy_Content_Context $context ) { + /** + * @param string $content + * @param Brizy_Content_Context $context + * + * @return mixed + */ + public function process($targetContent, Brizy_Content_Context $context) + { - $placeholderProvider = new Brizy_Content_PlaceholderProvider( $context ); - $extractor = new Extractor( $placeholderProvider ); + $placeholderProvider = new Brizy_Content_PlaceholderProvider($context); + $extractor = new Extractor($placeholderProvider); - $context->setProvider( $placeholderProvider ); + $context->setProvider($placeholderProvider); - // load all page placeholders - $postContent = $this->getBrizyPostContent($context->getProject(), Brizy_Editor_Post::get($context->getWpPost())); - /** - * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders; - */ - list( $contentPlaceholders, $placeholderInstances, $newPostContent ) = $extractor->extract( $postContent ); - $context->setPlaceholders($contentPlaceholders); + list($contentPlaceholders, $placeholderInstances, $content) = $extractor->extract($targetContent); + if (count($contentPlaceholders) > 0) { + $context->setPlaceholders($contentPlaceholders); - list( $contentPlaceholders, $placeholderInstances, $content ) = $extractor->extract( $content ); + // load all page placeholders + $postContent = $this->getBrizyPostContent( + $context->getProject(), + Brizy_Editor_Post::get($context->getWpPost()) + ); + if ($targetContent != $postContent) { + /** + * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders ; + */ + list($newContentPlaceholders, $placeholderInstances, $newPostContent) = $extractor->extract($postContent); - $replacer = new Replacer( $placeholderProvider ); + $context->setPlaceholders(array_merge($contentPlaceholders,$newContentPlaceholders)); + } - $content = $replacer->replaceWithExtractedData( $contentPlaceholders, $placeholderInstances, $content, $context ); - - return $content; - } + $replacer = new Replacer($placeholderProvider); + $content = $replacer->replaceWithExtractedData( + $contentPlaceholders, + $placeholderInstances, + $content, + $context + ); + } + return $content; + } - private function getBrizyPostContent(Brizy_Editor_Project $project,Brizy_Editor_Post $post) { - $project = Brizy_Editor_Project::get(); - if (!$post->get_compiled_html()) { + private function getBrizyPostContent(Brizy_Editor_Project $project, Brizy_Editor_Post $post) + { + if ( ! $post->get_compiled_html()) { $compiled_html_body = $post->get_compiled_html_body(); - $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); + $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); $post->set_needs_compile(true)->saveStorage(); } else { $compiled_page = $post->get_compiled_page(); - $content = $compiled_page->get_body(); + $content = $compiled_page->get_body(); } return $content; From c30e6b3caf78d93a90dfce2605a52332e795eb88 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 23 May 2022 08:36:24 +0300 Subject: [PATCH 26/45] ... --- content/context.php | 138 ++++++++++++++++---------- content/dynamic-content-processor.php | 2 +- editor/filters/api.php | 28 +++--- 3 files changed, 100 insertions(+), 68 deletions(-) diff --git a/content/context.php b/content/context.php index 9d33973b66..cfabafa4f5 100644 --- a/content/context.php +++ b/content/context.php @@ -8,10 +8,11 @@ class Brizy_Content_Context implements ContextInterface protected $data = array(); - /** - * @var ContentPlaceholder[] - */ - protected $placeholders = []; + /** + * @var ContentPlaceholder[] + */ + protected $placeholders = []; + /** * @param $name @@ -22,7 +23,7 @@ class Brizy_Content_Context implements ContextInterface public function __call($name, $arguments) { $method = substr($name, 0, 3); - $key = substr($name, 3); + $key = substr($name, 3); switch ($method) { case 'set': @@ -56,7 +57,7 @@ protected function get($name) public function afterExtract($contentPlaceholders, $instancePlaceholders, $contentAfterExtractor) { - $this->setPlaceholders($contentPlaceholders); + $this->setPlaceholders(array_merge( $this->getPlaceholders(),$contentPlaceholders )); } @@ -75,88 +76,115 @@ protected function set($key, $value) return $this->data[$key] = $value; } - /** - * BrizyPro_Content_Context constructor. - * - * @param $project - * @param $wp_post - */ - public function __construct($project, $brizy_post, $wp_post, $contentHtml, $parentContext = null ) { - $this->setProject( $project ); - $this->setWpPost( $wp_post ); - $this->setParentContext( $parentContext ); - $this->setEntity($wp_post); + /** + * BrizyPro_Content_Context constructor. + * + * @param $project + * @param $wp_post + */ + public function __construct($project, $brizy_post, $wp_post, $contentHtml, $parentContext = null) + { + $this->setProject($project); + $this->setWpPost($wp_post); + $this->setParentContext($parentContext); + $this->setEntity($wp_post); } - /** - * @return array - */ - public function getPlaceholders() { - return $this->placeholders; - } + /** + * @return array + */ + public function getPlaceholders() + { + return $this->placeholders; + } - /** - * @param array $placeholders - * - * @return Brizy_Content_Context - */ - public function setPlaceholders( array $placeholders ) { - $this->placeholders = $placeholders; + /** + * @param array $placeholders + * + * @return Brizy_Content_Context + */ + public function setPlaceholders(array $placeholders) + { + $this->placeholders = $placeholders; - return $this; - } + return $this; + } /** * @param $id + * * @return mixed|null */ - public function getPlaceholderById( $id ) { + public function getPlaceholderById($id) + { - $results = $this->getPlaceholdersByAttrValue( 'id', $id ); + $results = $this->getPlaceholdersByAttrValue('id', $id); - return isset( $results[0] ) ? $results[0] : null; - } + return isset($results[0]) ? $results[0] : null; + } /** * @param $key * @param $value + * * @return array|null */ - public function getPlaceholdersByAttrValue( $key, $value ) { + public function getPlaceholdersByAttrValue($key, $value) + { - if(is_null($value)) return null; + if (is_null($value)) { + return null; + } - $results = []; - if ( isset( $this->placeholders ) ) { - foreach ( $this->placeholders as $placeholder ) { - if ( $placeholder->getAttribute( $key ) == $value ) { - $results[] = $placeholder; - } - } - } + $results = []; + if (isset($this->placeholders)) { + foreach ($this->placeholders as $placeholder) { + if ($placeholder->getAttribute($key) == $value) { + $results[] = $placeholder; + } + } + } - if($context = $this->getParentContext()) { - $results = array_merge($results,$context->getPlaceholdersByAttrValue($key, $value)); + if ($context = $this->getParentContext()) { + $results = array_merge($results, $context->getPlaceholdersByAttrValue($key, $value)); } - return $results; - } + return $results; + } + + /** + * @return array + */ + public function getProvider() + { + if ($provider = $this->get('Provider')) { + return $provider; + } + + if ($parentContext = $this->getParentContext()) { + return $parentContext->getProvider(); + } + + return null; + } /** * @param $attributes + * * @return Brizy_Content_ContentPlaceholder|null */ - public function getPlaceholderByAttrValues( $attributes ) { + public function getPlaceholderByAttrValues($attributes) + { - if ( isset( $this->placeholders ) ) { - foreach ( $this->placeholders as $placeholder ) { - if ( count(array_intersect($placeholder->getAttributes(),$attributes))==count($attributes) ) { + if (isset($this->placeholders)) { + foreach ($this->placeholders as $placeholder) { + if (count(array_intersect($placeholder->getAttributes(), $attributes)) == count($attributes)) { return $placeholder; } } } - if($context = $this->getParentContext()) { + if ($context = $this->getParentContext()) { return $context->getPlaceholderByAttrValues($attributes); } diff --git a/content/dynamic-content-processor.php b/content/dynamic-content-processor.php index 9383cc27e2..97120c3600 100644 --- a/content/dynamic-content-processor.php +++ b/content/dynamic-content-processor.php @@ -36,7 +36,7 @@ public function process($targetContent, Brizy_Content_Context $context) */ list($newContentPlaceholders, $placeholderInstances, $newPostContent) = $extractor->extract($postContent); - $context->setPlaceholders(array_merge($contentPlaceholders,$newContentPlaceholders)); + $context->afterExtract($newContentPlaceholders, $placeholderInstances, $newPostContent); } $replacer = new Replacer($placeholderProvider); diff --git a/editor/filters/api.php b/editor/filters/api.php index 1595f34d38..821c7d60f9 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -40,18 +40,22 @@ public function filterPlaceholdersContent() { $context->setPlaceholders($contentPlaceholders); foreach( $placeholders as $placeholderId) { - /** - * @var \BrizyPlaceholders\ContentPlaceholder $placeholder; - */ - $placeholder = $context->getPlaceholderById($placeholderId); - - if(!$placeholder) continue; - - /** - * @var Brizy_Content_Placeholders_Abstract $placeholderInstance; - */ - $placeholderInstance = $placeholderProvider->getPlaceholderSupportingName($placeholder->getName()); - $placeholderContents[$placeholderId] = $placeholderInstance->getValue($context,$placeholder); + try { + /** + * @var \BrizyPlaceholders\ContentPlaceholder $placeholder; + */ + $placeholder = $context->getPlaceholderById($placeholderId); + + if(!$placeholder) continue; + + /** + * @var Brizy_Content_Placeholders_Abstract $placeholderInstance; + */ + $placeholderInstance = $placeholderProvider->getPlaceholderSupportingName($placeholder->getName()); + $placeholderContents[$placeholderId] = $placeholderInstance->getValue($context,$placeholder); + } catch (\Exception $e) { + $placeholderContents[$placeholderId] = null; + } } From 7b5ada33e65f746ef6011e8688fde93119bc0587 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 23 May 2022 13:28:38 +0300 Subject: [PATCH 27/45] fix: dynamic content processor --- editor/api.php | 94 +++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/editor/api.php b/editor/api.php index 0fb2032616..21156451a2 100755 --- a/editor/api.php +++ b/editor/api.php @@ -22,7 +22,7 @@ class Brizy_Editor_API extends Brizy_Admin_AbstractApi { const AJAX_HEARTBEAT = '_heartbeat'; const AJAX_TAKE_OVER = '_take_over'; const AJAX_DOWNLOAD_MEDIA = '_download_media'; - const AJAX_JWT_TOKEN = '_multipass_create'; + const AJAX_JWT_TOKEN = '_multipass_create'; const AJAX_UPDATE_MENU_DATA = '_update_menu_data'; const AJAX_UPDATE_EDITOR_META_DATA = '_update_editor_meta_data'; const AJAX_UPDATE_MENU_ITEM_DATA = '_update_menu_item_data'; @@ -136,10 +136,8 @@ public function addDynamicContent() { $provider = new Brizy_Content_PlaceholderProvider( $context ); $placeholders = $provider->getGroupedPlaceholdersForApiResponse(); - return $this->success( $placeholders ); - } - - public function lock_project() { + return $this->success($placeholders); + }public function lock_project() { $this->verifyNonce( self::nonce ); if ( Brizy_Editor::get()->checkIfProjectIsLocked() === false ) { @@ -323,12 +321,10 @@ public function set_project() { throw new Exception( '', 400 ); } - if (!$compiledStyles) { + if (!$compiledStyles) { Brizy_Logger::instance()->error('Invalid project styles provided', ['compiled' => $compiledStyles]); throw new Exception('', 400); - } - - if ( ! $dataVersion ) { + }if (!$dataVersion ) { Brizy_Logger::instance()->error( 'No data version provided', [ 'data' => $dataVersion ] ); throw new Exception( '', 400 ); } @@ -337,10 +333,10 @@ public function set_project() { $project->setDataAsJson( $meta ); $project->setDataVersion( $dataVersion ); + if ( (int) $this->param( 'is_autosave' ) === 1 ) { $project->save( 1 ); - } else { - $project->setCompiledStyles( $compiledStyles ); + } else {$project->setCompiledStyles( $compiledStyles ); $project->set_compiler(Brizy_Editor_Entity::COMPILER_BROWSER ); $project->save(); $project->savePost(); @@ -454,15 +450,14 @@ public function update_item() { // there is no need to make it true as we already receive the compiled html from editor $this->post->set_needs_compile( false ); $this->post->set_compiler( Brizy_Editor_Entity::COMPILER_BROWSER ); - } - - if ( $atemplate ) { + }if ( $atemplate ) { $this->post->set_template( $atemplate ); } if ( $data ) { $this->post->set_editor_data( $data ); $this->post->set_editor_version( BRIZY_EDITOR_VERSION ); + } $this->post->getWpPost()->post_status = $status; @@ -472,7 +467,6 @@ public function update_item() { } else { $this->post->setDataVersion( $dataVersion ); $this->post->setLastUserEdited( get_current_user_id() ); - $this->post->save( 0 ); $this->post->savePost( true ); } @@ -543,28 +537,30 @@ public function placeholder_content() { $contents[] = apply_filters( 'brizy_content', $placeholder, Brizy_Editor_Project::get(), $post ); } - $this->success(array('placeholders' => $contents)); - } catch (Exception $exception) { - Brizy_Logger::instance()->exception($exception); - $this->error($exception->getCode(), $exception->getMessage()); - } - } + $this->success( array( 'placeholders' => $contents ) ); + } catch ( Exception $exception ) { + Brizy_Logger::instance()->exception( $exception ); + $this->error( $exception->getCode(), $exception->getMessage() ); + } + } public function placeholders_content() { global $post, $wp_query; - try { - $this->verifyNonce( self::nonce ); - $posts = $this->param( 'p' ); - $contents = []; - foreach ( $posts as $postId => $placeholders ) { - $post = $this->getPostSample( $postId ); - $contents[ $postId ] = []; - if ( $post instanceof WP_Post ) { - setup_postdata( $post ); - $wp_query->is_single = true; - } - foreach ( $placeholders as $placeholder ) { + $this->verifyNonce( self::nonce ); + $posts = $this->param( 'p' ); + $contents = []; + foreach ( $posts as $postId => $placeholders ) { + + $post = $this->getPostSample( $postId ); + $contents[ $postId ] = []; + + if ( $post instanceof WP_Post ) { + setup_postdata( $post ); + $wp_query->is_single = true; + } + foreach ( $placeholders as $placeholder ) { + try { $placeholder = stripslashes( $placeholder ); $contents[ $postId ][] = apply_filters( 'brizy_content', @@ -572,13 +568,19 @@ public function placeholders_content() { Brizy_Editor_Project::get(), $post ); + } catch ( Exception $exception ) { + Brizy_Logger::instance()->exception( $exception ); + continue; } } - $this->success( array( 'placeholders' => $contents ) ); - } catch ( Exception $exception ) { - Brizy_Logger::instance()->exception( $exception ); - $this->error( $exception->getCode(), $exception->getMessage() ); + + } + $this->success( + array( + 'placeholders' => $contents) + ); + } private function getPostSample( $templateId ) { @@ -618,16 +620,13 @@ private function getPostSample( $templateId ) { ], ]; - $values = $rule->getEntityValues(); - $posts = []; - if (empty($values[0])) { - // For All condition - $posts = get_posts($args); - - } else { - - - $filter = $values[0]; + $values = $rule->getEntityValues(); + $posts = []; + if ( empty( $values[0] ) ) { + // For All condition + $posts = get_posts( $args ); + } else { + $filter = $values[0]; if ( is_numeric( $filter ) ) { $args['post__in'] = [ $filter ]; @@ -685,6 +684,7 @@ private function getPostSample( $templateId ) { $wp_query->is_tax = true; } + return array_pop( $terms ); case Brizy_Admin_Rule::WOO_SHOP_PAGE : From 1494fa2b361d890f8e7ba8fd59abc40dc151e19f Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 23 May 2022 13:28:55 +0300 Subject: [PATCH 28/45] fix: dynamic content processor --- content/dynamic-content-processor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/dynamic-content-processor.php b/content/dynamic-content-processor.php index 97120c3600..8086cd426f 100644 --- a/content/dynamic-content-processor.php +++ b/content/dynamic-content-processor.php @@ -34,9 +34,9 @@ public function process($targetContent, Brizy_Content_Context $context) /** * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders ; */ - list($newContentPlaceholders, $placeholderInstances, $newPostContent) = $extractor->extract($postContent); + list($newContentPlaceholders, $newPlaceholderInstances, $newPostContent) = $extractor->extract($postContent); - $context->afterExtract($newContentPlaceholders, $placeholderInstances, $newPostContent); + $context->afterExtract($newContentPlaceholders, $newPlaceholderInstances, $newPostContent); } $replacer = new Replacer($placeholderProvider); From 97de8fe45f1b9249c063ff0331d9b2f7a75547b1 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 9 Jun 2022 15:54:09 +0300 Subject: [PATCH 29/45] fix: compile page when asking for a placeholder html --- content/dynamic-content-processor.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/content/dynamic-content-processor.php b/content/dynamic-content-processor.php index 8086cd426f..8062e16792 100644 --- a/content/dynamic-content-processor.php +++ b/content/dynamic-content-processor.php @@ -54,13 +54,18 @@ public function process($targetContent, Brizy_Content_Context $context) private function getBrizyPostContent(Brizy_Editor_Project $project, Brizy_Editor_Post $post) { + if($post->get_needs_compile()) + { + $post->compile_page(); + } + if ( ! $post->get_compiled_html()) { $compiled_html_body = $post->get_compiled_html_body(); $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); $post->set_needs_compile(true)->saveStorage(); } else { $compiled_page = $post->get_compiled_page(); - $content = $compiled_page->get_body(); + $content = $compiled_page->getBody(); } return $content; From e1e42709ce279207f780244a8c4fb212d0f8ca91 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Mon, 13 Jun 2022 17:09:24 +0300 Subject: [PATCH 30/45] fix: small fix when wrong placeholder id is required --- editor/filters/api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/editor/filters/api.php b/editor/filters/api.php index 821c7d60f9..7f2993d527 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -46,7 +46,10 @@ public function filterPlaceholdersContent() { */ $placeholder = $context->getPlaceholderById($placeholderId); - if(!$placeholder) continue; + if(!$placeholder) { + $placeholderContents[$placeholderId] = ''; + continue; + } /** * @var Brizy_Content_Placeholders_Abstract $placeholderInstance; From d93b931567f94d12c2ca65576ccca2f0a95717a6 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 23 Jun 2022 09:53:03 +0300 Subject: [PATCH 31/45] fix: use $_REQUEST instead if $_POST --- editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor.php b/editor.php index 4e02c8c234..806f74f625 100755 --- a/editor.php +++ b/editor.php @@ -419,7 +419,7 @@ function currentPostId() { $pid = (int) $_REQUEST['page_id']; } elseif ( isset( $_REQUEST['post_ID'] ) ) { - $pid = (int) $_POST['post_ID']; + $pid = (int) $_REQUEST['post_ID']; } elseif ( isset( $_REQUEST['id'] ) ) { $pid = (int) $_REQUEST['id']; From 88c3cd9b752b4f1c8b315b1cb370f84e160b8a0f Mon Sep 17 00:00:00 2001 From: Viorel Date: Tue, 26 Jul 2022 10:52:46 +0300 Subject: [PATCH 32/45] Fix: #19185 - Fix condition modal editor by global rules --- admin/rules/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/rules/api.php b/admin/rules/api.php index bc9f2cd528..da4529362c 100644 --- a/admin/rules/api.php +++ b/admin/rules/api.php @@ -342,7 +342,7 @@ public function getGroupList() { $groups = []; - if ( $templateType == 'single' || $templateType == 'single_product' || $context == 'popup-rules' || $context == 'global-block-rules' ) { + if ($templateType == 'single' || $templateType == 'single_product' || $context == 'popup-rules' || $context == 'global-block-rules' ) { $groups[] = array( 'title' => 'Main Content', 'value' => Brizy_Admin_Rule::POSTS, @@ -360,7 +360,7 @@ public function getGroupList() { ) : null; } - if ( $templateType == 'archive' || $templateType == 'product_archive' || $context == 'popup-rules' || $context == 'global-block-rules' ) { + if ($templateType == 'archive' || $templateType == 'product_archive' || $context == 'popup-rules' || $context == 'global-block-rules' ) { $archiveItems = array_map( $closure, $this->getArchivesList( Brizy_Admin_Rule::ARCHIVE, $templateType ) ); $taxonomyItems = array_map( $closure, $this->getTaxonomyList( Brizy_Admin_Rule::TAXONOMY, $templateType ) ); From a8ceccd48143fea8ca65ceef6df994358050b3a1 Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Tue, 9 Aug 2022 16:00:54 +0300 Subject: [PATCH 33/45] fix: filter refactoring --- content/placeholders/abstract.php | 2 +- editor/filters/api.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/content/placeholders/abstract.php b/content/placeholders/abstract.php index 30465295e4..e835975a7b 100644 --- a/content/placeholders/abstract.php +++ b/content/placeholders/abstract.php @@ -69,7 +69,7 @@ public function support($placeholderName) public function shouldFallbackValue($value, ContextInterface $context, ContentPlaceholder $placeholder) { - return is_null($value) || $value==""; + return is_null($value) || $value===""; } public function getFallbackValue(ContextInterface $context, ContentPlaceholder $placeholder) diff --git a/editor/filters/api.php b/editor/filters/api.php index 7f2993d527..a8435cfaf6 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -28,7 +28,7 @@ public function filterPlaceholdersContent() { $brizyPost = Brizy_Editor_Post::get($postId); $postContent = $this->getBrizyPostContent(Brizy_Editor_Project::get(), $brizyPost); - $placeholderProvider = new Brizy_Content_PlaceholderProvider(); + $placeholderProvider = new Brizy_Content_PlaceholderProvider(); $context = new Brizy_Content_Context(Brizy_Editor_Project::get(),$brizyPost,$brizyPost->getWpPost(),''); $context->setProvider( $placeholderProvider ); $extractor = new \BrizyPlaceholders\Extractor( $placeholderProvider ); From a781d410d96a54b1b284a02f304285d02126a42f Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Thu, 22 Sep 2022 09:48:44 +0300 Subject: [PATCH 34/45] fix: Config values in dev mode 2 --- config.dev.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.dev.php b/config.dev.php index 3d989b063c..d56a1b256e 100755 --- a/config.dev.php +++ b/config.dev.php @@ -48,7 +48,7 @@ class Brizy_Config { const CLOUD_LAYOUTS = '/api/layouts'; const CLOUD_SCREENSHOT = '/screenshot/%s'; const CLOUD_SCREENSHOTS = '/api/screenshots'; - const CLOUD_CUSTOM_FILES = '/api/custom_files'; + const CLOUD_CUSTOM_FILES = '/api/custom_files'; const WP_HTTP_TIMEOUT = 600; From ebb63375c3c34ebc86cd2abe25fc3ff87b67369e Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Fri, 7 Oct 2022 11:57:37 +0300 Subject: [PATCH 35/45] fix: Context factor --- content/context-factory.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/content/context-factory.php b/content/context-factory.php index 1b31b8120a..0bedc353ed 100644 --- a/content/context-factory.php +++ b/content/context-factory.php @@ -17,16 +17,16 @@ class Brizy_Content_ContextFactory * * @return Brizy_Content_Context */ - static public function createContext($project = null, $wp_post = null, $parentContext = false) + static public function createContext($project= null, $wp_post = null, $parentContext = false) { - $context = new Brizy_Content_Context($project, null, $wp_post, null, $parentContext ); + $context = new Brizy_Content_Context($project, null, $wp_post, null, $parentContext); if ($wp_post) { - $context->setAuthor( $wp_post->post_author ); - } + $context->setAuthor($wp_post->post_author); + } - return apply_filters( 'brizy_context_create', $context ); - } + return apply_filters('brizy_context_create', $context, $wp_post); + } static public function createEmptyContext() { @@ -58,7 +58,7 @@ private static function getContext($project, $wp_post) { $context = new Brizy_Content_Context($project, $wp_post); - if ($wp_post instanceof WP_Post) { + if ($wp_postinstanceof WP_Post) { $context->setAuthor($wp_post->post_author); } From 377ddca68e7a35bd2c17aafaab4e01233f7dc21e Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Tue, 18 Jul 2023 10:09:45 +0300 Subject: [PATCH 36/45] fix: small fixes after rebase. --- content/context-factory.php | 4 +- editor/editor/editor.php | 178 ++++++++++++++++++------------------ 2 files changed, 89 insertions(+), 93 deletions(-) diff --git a/content/context-factory.php b/content/context-factory.php index 0bedc353ed..d4e33aa854 100644 --- a/content/context-factory.php +++ b/content/context-factory.php @@ -17,7 +17,7 @@ class Brizy_Content_ContextFactory * * @return Brizy_Content_Context */ - static public function createContext($project= null, $wp_post = null, $parentContext = false) + static public function createContext($project = null, $wp_post = null, $parentContext = false) { $context = new Brizy_Content_Context($project, null, $wp_post, null, $parentContext); @@ -58,7 +58,7 @@ private static function getContext($project, $wp_post) { $context = new Brizy_Content_Context($project, $wp_post); - if ($wp_postinstanceof WP_Post) { + if ($wp_post instanceof WP_Post) { $context->setAuthor($wp_post->post_author); } diff --git a/editor/editor/editor.php b/editor/editor/editor.php index bf711d1639..0eb69dcbec 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -111,8 +111,7 @@ public function getClientConfig($context) */ public function config($context = self::COMPILE_CONTEXT) { - do_action('brizy_create_editor_config_before') - ; + do_action('brizy_create_editor_config_before'); $cachePostId = ($this->post ? $this->post->getWpPostId() : 0).'_'.$context; if (isset(self::$config[$cachePostId])) { @@ -212,10 +211,9 @@ public function config($context = self::COMPILE_CONTEXT) 'editorVersion' => BRIZY_EDITOR_VERSION, 'imageSizes' => $this->getImgSizes(), 'moduleGroups' => [], - 'l10n' => $this->getTexts(), + 'l10n' => $this->getTexts(), 'membership' => true, - 'elements' => [ 'image' => [ 'zoom' => true ], 'video'=>[ 'types'=>['youtube','vimeo','url'] ] ], - ); + 'elements' => [ 'image' => [ 'zoom' => true ], 'video'=>[ 'types'=>['youtube','vimeo','url'] ] ],); $manager = new Brizy_Editor_Accounts_ServiceAccountManager(Brizy_Editor_Project::get()); if (!$this->isPopup($config) && !$this->isStory($config)) { @@ -240,7 +238,7 @@ public function config($context = self::COMPILE_CONTEXT) do_action('brizy_create_editor_config_after'); - return self::$config[$cachePostId] ; + return self::$config[$cachePostId]; } private function addUIConfig($config, $context) @@ -576,7 +574,7 @@ private function addContentDefaults($config, $context) ], ], ], - 'AssetsPosts' => [ + 'AssetsPosts' => [ '_version' => 3, 'type' => 'posts', 'source' => 'post', @@ -918,8 +916,7 @@ private function getPostLoopSources($isTemplate, $wp_post_id, $context) if ($template_type == Brizy_Admin_Templates::TYPE_ARCHIVE || $template_type == Brizy_Admin_Templates::TYPE_PRODUCT_ARCHIVE) { $templateTypeArchive = true; } - - $rule_manager = new Brizy_Admin_Rules_Manager(); + $rule_manager = new Brizy_Admin_Rules_Manager(); $template_rules = $rule_manager->getRules($wp_post_id); $isSearchTemplate = $this->isSearchTemplate($template_rules); } @@ -952,7 +949,6 @@ private function getPostLoopSources($isTemplate, $wp_post_id, $context) foreach ($types as $type) { $typeObj = get_post_type_object($type); - $typeDto = [ 'name' => $typeObj->name, 'label' => $typeObj->label, @@ -964,7 +960,7 @@ private function getPostLoopSources($isTemplate, $wp_post_id, $context) return $result; } - private function addLoopSourcesConfig($config, $isTemplate, $wp_post_id, $context) + private function addLoopSourcesConfig($config, $isTemplate, $wp_post_id, $context) { $sources = $this->getPostLoopSources($isTemplate, $wp_post_id, $context); @@ -978,28 +974,30 @@ private function addLoopSourcesConfig($config, $isTemplate, $wp_post_id, $contex }, $sources); return $config; - } + } - private function addGlobalBlocksData( $config ) { + private function addGlobalBlocksData($config) + { - $postTaxonomies = get_post_taxonomies( $wp_post_id = (int) $config['wp']['page'] ); - $postTerms = []; - foreach ( $postTaxonomies as $tax ) { - $postTerms = array_merge( $postTerms, wp_get_post_terms( $wp_post_id, $tax ) ); - } + $postTaxonomies = get_post_taxonomies($wp_post_id = (int)$config['wp']['page']); + $postTerms = []; + foreach ($postTaxonomies as $tax) { + $postTerms = array_merge($postTerms, wp_get_post_terms($wp_post_id, $tax)); + } - $postTermsByKeys = []; - foreach ( $postTerms as $term ) { - $postTermsByKeys[ $term->term_id ] = $term; - } + $postTermsByKeys = []; + foreach ($postTerms as $term) { + $postTermsByKeys[$term->term_id] = $term; + } - $config['wp']['post_terms'] = $postTerms; - $config['wp']['post_term_parents'] = array_diff_key($this->getAllParents($postTermsByKeys),$postTermsByKeys); + $config['wp']['post_terms'] = $postTerms; + $config['wp']['post_term_parents'] = array_diff_key($this->getAllParents($postTermsByKeys), $postTermsByKeys); $config['wp']['post_author'] = (int)$this->post->getWpPost()->post_author; return $config; } - private function addLoopSourcesClientConfig($config, $isTemplate, $wp_post_id, $context) + + private function addLoopSourcesClientConfig($config, $isTemplate, $wp_post_id, $context) { $sources = $this->getPostLoopSources($isTemplate, $wp_post_id, $context); $config['collectionTypes'] = $sources; @@ -1453,9 +1451,9 @@ private function parseSize($size) } - private function getOneArchiveLink($args = '') - { + + { global $wpdb, $wp_locale; $defaults = array( @@ -1608,19 +1606,20 @@ private function getTemplateRuleMatches($isTemplate, $wpPostId, $templateRules) 'values' => $rule->getEntityValues(), ); } - $ruleMatches[] = array( + $ruleMatches[] = array( 'type' => Brizy_Admin_Rule::TYPE_INCLUDE, 'group' => Brizy_Admin_Rule::BRIZY_TEMPLATE, 'entityType' => $this->post->getWpPost()->post_type, 'values' => array($wpPostId), - );} else { - $ruleMatches[] = array( - 'type' => Brizy_Admin_Rule::TYPE_INCLUDE, - 'group' => Brizy_Admin_Rule::POSTS, - 'entityType' => $this->post->getWpPost()->post_type, - 'values' => array( $wpPostId ), - ); - } + ); + } else { + $ruleMatches[] = array( + 'type' => Brizy_Admin_Rule::TYPE_INCLUDE, + 'group' => Brizy_Admin_Rule::POSTS, + 'entityType' => $this->post->getWpPost()->post_type, + 'values' => array($wpPostId), + ); + } return $ruleMatches; } @@ -1693,7 +1692,6 @@ private function getTemplateType($template_rules) return ''; } - private function isSearchTemplate($template_rules) { foreach ($template_rules as $rule) { @@ -1713,9 +1711,7 @@ private function isSearchTemplate($template_rules) } return false; - } - - /** + }/** * @return array */ public function getProjectStatus() @@ -1744,50 +1740,50 @@ public function getApiActions($config = [], $context = null) $actions = array( 'hash' => wp_create_nonce(Brizy_Editor_API::nonce), 'url' => set_url_scheme(admin_url('admin-ajax.php')), - 'heartBeat' => $pref.Brizy_Editor_API::AJAX_HEARTBEAT, - 'takeOver' => $pref.Brizy_Editor_API::AJAX_TAKE_OVER, - 'lockProject' => $pref.Brizy_Editor_API::AJAX_LOCK_PROJECT, - 'removeLock' => $pref.Brizy_Editor_API::AJAX_REMOVE_LOCK, - 'getPage' => $pref.Brizy_Editor_API::AJAX_GET, - 'getPostInfo' => $pref.Brizy_Editor_API::AJAX_GET_POST_INFO, - 'updatePage' => $pref.Brizy_Editor_API::AJAX_UPDATE, - 'getProject' => $pref.Brizy_Editor_API::AJAX_GET_PROJECT, - 'setProject' => $pref.Brizy_Editor_API::AJAX_SET_PROJECT, - 'setProjectMeta' => $pref.Brizy_Editor_API::AJAX_UPDATE_EDITOR_META_DATA, - 'getGlobalBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_GLOBAL_BLOCKS_ACTION, - 'createGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_GLOBAL_BLOCK_ACTION, - 'updateGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCK_ACTION, - 'updateGlobalBlocks' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCKS_ACTION, - 'deleteGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_GLOBAL_BLOCK_ACTION, - 'getRuleGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_GROUP_LIST, - 'getLayoutByUid' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUT_BY_UID_ACTION, - 'getLayoutList' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUTS_ACTION, - 'createLayout' => $pref.Brizy_Admin_Layouts_Api::CREATE_LAYOUT_ACTION, - 'updateLayout' => $pref.Brizy_Admin_Layouts_Api::UPDATE_LAYOUT_ACTION, - 'deleteLayout' => $pref.Brizy_Admin_Layouts_Api::DELETE_LAYOUT_ACTION, - 'cloudSignIn' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNIN_ACTION, - 'cloudSignUp' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNUP_ACTION, - 'cloudSignOut' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNOUT_ACTION, - 'cloudSyncAllowed' => $pref.Brizy_Admin_Cloud_Api::AJAX_SYNC_ALLOWED, - 'cloudResetPassword' => $pref.Brizy_Admin_Cloud_Api::AJAX_RESET_PASSWORD_ACTION, - 'cloudSync' => $pref.Brizy_Admin_Cloud_Api::AJAX_TRIGGER_SYNC_ACTION, - 'createRule' => $pref.Brizy_Admin_Rules_Api::CREATE_RULE_ACTION, - 'createRules' => $pref.Brizy_Admin_Rules_Api::CREATE_RULES_ACTION, - 'updateRules' => $pref.Brizy_Admin_Rules_Api::UPDATE_RULES_ACTION, - 'deleteRule' => $pref.Brizy_Admin_Rules_Api::DELETE_RULE_ACTION, - 'getRuleList' => $pref.Brizy_Admin_Rules_Api::LIST_RULE_ACTION, - 'updateBlockPositions' => $pref.Brizy_Admin_Blocks_Api::UPDATE_POSITIONS_ACTION, - 'getSavedBlockByUid' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCK_ACTION, - 'getSavedBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCKS_ACTION, - 'createSavedBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_SAVED_BLOCK_ACTION, - 'updateSavedBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_SAVED_BLOCK_ACTION, - 'deleteSavedBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_SAVED_BLOCK_ACTION, - 'downloadBlocks' => $pref.Brizy_Admin_Blocks_Api::DOWNLOAD_BLOCKS, - 'uploadBlocks' => $pref.Brizy_Admin_Blocks_Api::UPLOAD_BLOCKS, - 'downloadLayouts' => $pref.Brizy_Admin_Layouts_Api::DOWNLOAD_LAYOUTS, - 'uploadLayouts' => $pref.Brizy_Admin_Layouts_Api::UPLOAD_LAYOUTS, - 'media' => $pref.Brizy_Editor_API::AJAX_MEDIA, - 'getMediaUid' => $pref.Brizy_Editor_API::AJAX_MEDIA_METAKEY, + 'heartBeat' => $pref.Brizy_Editor_API::AJAX_HEARTBEAT, + 'takeOver' => $pref.Brizy_Editor_API::AJAX_TAKE_OVER, + 'lockProject' => $pref.Brizy_Editor_API::AJAX_LOCK_PROJECT, + 'removeLock' => $pref.Brizy_Editor_API::AJAX_REMOVE_LOCK, + 'getPage' => $pref.Brizy_Editor_API::AJAX_GET, + 'getPostInfo' => $pref.Brizy_Editor_API::AJAX_GET_POST_INFO, + 'updatePage' => $pref.Brizy_Editor_API::AJAX_UPDATE, + 'getProject' => $pref.Brizy_Editor_API::AJAX_GET_PROJECT, + 'setProject' => $pref.Brizy_Editor_API::AJAX_SET_PROJECT, + 'setProjectMeta' => $pref.Brizy_Editor_API::AJAX_UPDATE_EDITOR_META_DATA, + 'getGlobalBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_GLOBAL_BLOCKS_ACTION, + 'createGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_GLOBAL_BLOCK_ACTION, + 'updateGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCK_ACTION, + 'updateGlobalBlocks' => $pref.Brizy_Admin_Blocks_Api::UPDATE_GLOBAL_BLOCKS_ACTION, + 'deleteGlobalBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_GLOBAL_BLOCK_ACTION, + 'getRuleGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_GROUP_LIST, + 'getLayoutByUid' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUT_BY_UID_ACTION, + 'getLayoutList' => $pref.Brizy_Admin_Layouts_Api::GET_LAYOUTS_ACTION, + 'createLayout' => $pref.Brizy_Admin_Layouts_Api::CREATE_LAYOUT_ACTION, + 'updateLayout' => $pref.Brizy_Admin_Layouts_Api::UPDATE_LAYOUT_ACTION, + 'deleteLayout' => $pref.Brizy_Admin_Layouts_Api::DELETE_LAYOUT_ACTION, + 'cloudSignIn' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNIN_ACTION, + 'cloudSignUp' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNUP_ACTION, + 'cloudSignOut' => $pref.Brizy_Admin_Cloud_Api::AJAX_SIGNOUT_ACTION, + 'cloudSyncAllowed' => $pref.Brizy_Admin_Cloud_Api::AJAX_SYNC_ALLOWED, + 'cloudResetPassword' => $pref.Brizy_Admin_Cloud_Api::AJAX_RESET_PASSWORD_ACTION, + 'cloudSync' => $pref.Brizy_Admin_Cloud_Api::AJAX_TRIGGER_SYNC_ACTION, + 'createRule' => $pref.Brizy_Admin_Rules_Api::CREATE_RULE_ACTION, + 'createRules' => $pref.Brizy_Admin_Rules_Api::CREATE_RULES_ACTION, + 'updateRules' => $pref.Brizy_Admin_Rules_Api::UPDATE_RULES_ACTION, + 'deleteRule' => $pref.Brizy_Admin_Rules_Api::DELETE_RULE_ACTION, + 'getRuleList' => $pref.Brizy_Admin_Rules_Api::LIST_RULE_ACTION, + 'updateBlockPositions' => $pref.Brizy_Admin_Blocks_Api::UPDATE_POSITIONS_ACTION, + 'getSavedBlockByUid' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCK_ACTION, + 'getSavedBlockList' => $pref.Brizy_Admin_Blocks_Api::GET_SAVED_BLOCKS_ACTION, + 'createSavedBlock' => $pref.Brizy_Admin_Blocks_Api::CREATE_SAVED_BLOCK_ACTION, + 'updateSavedBlock' => $pref.Brizy_Admin_Blocks_Api::UPDATE_SAVED_BLOCK_ACTION, + 'deleteSavedBlock' => $pref.Brizy_Admin_Blocks_Api::DELETE_SAVED_BLOCK_ACTION, + 'downloadBlocks' => $pref.Brizy_Admin_Blocks_Api::DOWNLOAD_BLOCKS, + 'uploadBlocks' => $pref.Brizy_Admin_Blocks_Api::UPLOAD_BLOCKS, + 'downloadLayouts' => $pref.Brizy_Admin_Layouts_Api::DOWNLOAD_LAYOUTS, + 'uploadLayouts' => $pref.Brizy_Admin_Layouts_Api::UPLOAD_LAYOUTS, + 'media' => $pref.Brizy_Editor_API::AJAX_MEDIA, + 'getMediaUid' => $pref.Brizy_Editor_API::AJAX_MEDIA_METAKEY, 'getAttachmentUid' => $pref.Brizy_Editor_API::AJAX_CREATE_ATTACHMENT_UID, 'getServerTimeStamp' => $pref.Brizy_Editor_API::AJAX_TIMESTAMP, 'createBlockScreenshot' => $pref.Brizy_Editor_BlockScreenshotApi::AJAX_CREATE_BLOCK_SCREENSHOT, @@ -1796,7 +1792,7 @@ public function getApiActions($config = [], $context = null) 'shortcodeContent' => $pref.Brizy_Editor_API::AJAX_SHORTCODE_CONTENT, 'placeholderContent' => $pref.Brizy_Editor_API::AJAX_PLACEHOLDER_CONTENT, 'placeholdersContent' => $pref.Brizy_Editor_API::AJAX_PLACEHOLDERS_CONTENT, - 'getPostTaxonomies' => $pref.Brizy_Editor_API::AJAX_GET_POST_TAXONOMIES, + 'getPostTaxonomies' => $pref.Brizy_Editor_API::AJAX_GET_POST_TAXONOMIES, 'getMenus' => $pref.Brizy_Editor_API::AJAX_GET_MENU_LIST, 'getTerms' => $pref.Brizy_Editor_API::AJAX_GET_TERMS, 'getTermsBy' => $pref.Brizy_Editor_API::AJAX_GET_TERMS_BY, @@ -1826,13 +1822,13 @@ public function getApiActions($config = [], $context = null) 'rulePostsGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_POSTS_GROUP_LIST, 'ruleArchiveGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_ARCHIVE_GROUP_LIST, 'ruleTemplateGroupList' => $pref.Brizy_Admin_Rules_Api::RULE_TEMPLATE_GROUP_LIST, - 'symbolCreate' => $pref.Brizy_Admin_Symbols_Api::CREATE_ACTION, - 'symbolUpdate' => $pref.Brizy_Admin_Symbols_Api::UPDATE_ACTION, - 'symbolDelete' => $pref.Brizy_Admin_Symbols_Api::DELETE_ACTION, - 'symbolList' => $pref.Brizy_Admin_Symbols_Api::LIST_ACTION, - 'getDynamicContentPlaceholders' => $pref.Brizy_Editor_API::AJAX_GET_DYNAMIC_CONTENT, + 'symbolCreate' => $pref.Brizy_Admin_Symbols_Api::CREATE_ACTION, + 'symbolUpdate' => $pref.Brizy_Admin_Symbols_Api::UPDATE_ACTION, + 'symbolDelete' => $pref.Brizy_Admin_Symbols_Api::DELETE_ACTION, + 'symbolList' => $pref.Brizy_Admin_Symbols_Api::LIST_ACTION, + 'getDynamicContentPlaceholders' => $pref.Brizy_Editor_API::AJAX_GET_DYNAMIC_CONTENT, 'filterPlaceholderContents' => $pref . Brizy_Editor_Filters_Api::AJAX_FILTER_PLACEHOLDERS_CONTENT, - ); + ); return $actions; } From 7fea1b95bd5b6608f843377ed40d93224fc35855 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Wed, 19 Jul 2023 10:21:03 +0300 Subject: [PATCH 37/45] fix: added filters in module groups --- editor/editor/module-groups/essential-provider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/editor/editor/module-groups/essential-provider.php b/editor/editor/module-groups/essential-provider.php index 53db677b0f..8682eab3bb 100644 --- a/editor/editor/module-groups/essential-provider.php +++ b/editor/editor/module-groups/essential-provider.php @@ -21,7 +21,8 @@ public function collect( $context ) { "Line", "MenuSimple", "Menu", - "Search" + "Search", + "Filters" ], 300 ), ]; } From e07f8013dbe5b5966a14d2b0878ce0022f036472 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Tue, 1 Aug 2023 13:15:10 +0300 Subject: [PATCH 38/45] fix: added a new method in context to find by name and id --- content/context.php | 22 +++++-- editor/filters/api.php | 144 ++++++++++++++++++++++------------------- 2 files changed, 94 insertions(+), 72 deletions(-) diff --git a/content/context.php b/content/context.php index cfabafa4f5..a04492a246 100644 --- a/content/context.php +++ b/content/context.php @@ -23,7 +23,7 @@ class Brizy_Content_Context implements ContextInterface public function __call($name, $arguments) { $method = substr($name, 0, 3); - $key = substr($name, 3); + $key = substr($name, 3); switch ($method) { case 'set': @@ -57,7 +57,7 @@ protected function get($name) public function afterExtract($contentPlaceholders, $instancePlaceholders, $contentAfterExtractor) { - $this->setPlaceholders(array_merge( $this->getPlaceholders(),$contentPlaceholders )); + $this->setPlaceholders(array_merge($this->getPlaceholders(), $contentPlaceholders)); } @@ -87,8 +87,8 @@ public function __construct($project, $brizy_post, $wp_post, $contentHtml, $pare $this->setProject($project); $this->setWpPost($wp_post); $this->setParentContext($parentContext); - $this->setEntity($wp_post); - } + $this->setEntity($wp_post); + } /** * @return array @@ -117,12 +117,23 @@ public function setPlaceholders(array $placeholders) */ public function getPlaceholderById($id) { - $results = $this->getPlaceholdersByAttrValue('id', $id); return isset($results[0]) ? $results[0] : null; } + public function getPlaceholderByNameAndId($name, $id) + { + if (isset($this->placeholders)) { + foreach ($this->placeholders as $placeholder) { + if ($placeholder->getName() == $name && $placeholder->getAttribute('id') == $id) { + return $placeholder; + } + } + } + return null; + } + /** * @param $key * @param $value @@ -131,7 +142,6 @@ public function getPlaceholderById($id) */ public function getPlaceholdersByAttrValue($key, $value) { - if (is_null($value)) { return null; } diff --git a/editor/filters/api.php b/editor/filters/api.php index a8435cfaf6..290544e27c 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -1,82 +1,94 @@ addNoPrivAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); - $this->addAjaxAction( self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( $this, 'filterPlaceholdersContent' ) ); - } + protected function initializeApiActions() + { + $this->addNoPrivAjaxAction(self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array($this, 'filterPlaceholdersContent')); + $this->addAjaxAction(self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array($this, 'filterPlaceholdersContent')); + } - protected function getRequestNonce() { - return $this->param( 'hash' ); - } + protected function getRequestNonce() + { + return $this->param('hash'); + } - public function filterPlaceholdersContent() { + public function filterPlaceholdersContent() + { - if(empty($postId = $this->param('post_id'))) { - $this->error(400, 'Please provide the post id'); - } + if (empty($postId = $this->param('post_id'))) { + $this->error(400, 'Please provide the post id'); + } - if(empty($placeholders = $this->param('placeholders'))) { - $this->error(400, 'Please provide the placeholders param'); - } + if (empty($placeholders = $this->param('placeholders'))) { + $this->error(400, 'Please provide the placeholders param'); + } - $placeholderContents = []; - $brizyPost = Brizy_Editor_Post::get($postId); - $postContent = $this->getBrizyPostContent(Brizy_Editor_Project::get(), $brizyPost); + $placeholderContents = []; + $brizyPost = Brizy_Editor_Post::get($postId); + $postContent = $this->getBrizyPostContent(Brizy_Editor_Project::get(), $brizyPost); $placeholderProvider = new Brizy_Content_PlaceholderProvider(); - $context = new Brizy_Content_Context(Brizy_Editor_Project::get(),$brizyPost,$brizyPost->getWpPost(),''); - $context->setProvider( $placeholderProvider ); - $extractor = new \BrizyPlaceholders\Extractor( $placeholderProvider ); - - /** - * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders; - */ - list( $contentPlaceholders, $placeholderInstances, $newPostContent ) = $extractor->extract( $postContent ); - $context->setPlaceholders($contentPlaceholders); - - foreach( $placeholders as $placeholderId) { - try { - /** - * @var \BrizyPlaceholders\ContentPlaceholder $placeholder; - */ - $placeholder = $context->getPlaceholderById($placeholderId); - - if(!$placeholder) { + $context = new Brizy_Content_Context(Brizy_Editor_Project::get(), $brizyPost, $brizyPost->getWpPost(), ''); + $context->setProvider($placeholderProvider); + $extractor = new \BrizyPlaceholders\Extractor($placeholderProvider); + + /** + * @var \BrizyPlaceholders\ContentPlaceholder[] $contentPlaceholders ; + */ + list($contentPlaceholders, $placeholderInstances, $newPostContent) = $extractor->extract($postContent); + $context->setPlaceholders($contentPlaceholders); + + foreach ($placeholders as $placeholderId) { + try { + /** + * @var \BrizyPlaceholders\ContentPlaceholder $placeholder ; + */ + $cleanId = str_replace(['-tag', '-pag'], '', $placeholderId); + if (strpos($placeholderId, "-tag") !== false) { + $placeholder = $context->getPlaceholderByNameAndId("brizy_dc_post_loop_tags", $cleanId); + } elseif (strpos($placeholderId, "-pag") !== false) { + $placeholder = $context->getPlaceholderByNameAndId("brizy_dc_post_loop_pagination", $cleanId); + } else { + $placeholder = $context->getPlaceholderById($placeholderId); + } + + if (!$placeholder) { $placeholderContents[$placeholderId] = ''; continue; } - /** - * @var Brizy_Content_Placeholders_Abstract $placeholderInstance; - */ - $placeholderInstance = $placeholderProvider->getPlaceholderSupportingName($placeholder->getName()); - $placeholderContents[$placeholderId] = $placeholderInstance->getValue($context,$placeholder); - } catch (\Exception $e) { - $placeholderContents[$placeholderId] = null; - } - } - - - $this->success(['placeholders'=>$placeholderContents]); - } - - private function getBrizyPostContent(Brizy_Editor_Project $project,Brizy_Editor_Post $post) { - $project = Brizy_Editor_Project::get(); - - if (!$post->get_compiled_html()) { - $compiled_html_body = $post->get_compiled_html_body(); - $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); - $post->set_needs_compile(true)->saveStorage(); - } else { - $compiled_page = $post->get_compiled_page(); - $content = $compiled_page->get_body(); - } - - return $content; - } + /** + * @var Brizy_Content_Placeholders_Abstract $placeholderInstance ; + */ + $placeholderInstance = $placeholderProvider->getPlaceholderSupportingName($placeholder->getName()); + $placeholderContents[$placeholderId] = $placeholderInstance->getValue($context, $placeholder); + } catch (\Exception $e) { + $placeholderContents[$placeholderId] = null; + } + } + + + $this->success(['placeholders' => $placeholderContents]); + } + + private function getBrizyPostContent(Brizy_Editor_Project $project, Brizy_Editor_Post $post) + { + $project = Brizy_Editor_Project::get(); + + if (!$post->get_compiled_html()) { + $compiled_html_body = $post->get_compiled_html_body(); + $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body); + $post->set_needs_compile(true)->saveStorage(); + } else { + $compiled_page = $post->get_compiled_page(); + $content = $compiled_page->get_body(); + } + + return $content; + } } From 1cedf0950bf9a38cf2baf2295af7d04cacaa6ec1 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Thu, 3 Aug 2023 11:35:15 +0300 Subject: [PATCH 39/45] fix: removed notion of -tag and -pag logic from api --- editor/filters/api.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/editor/filters/api.php b/editor/filters/api.php index 290544e27c..004be87e04 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -48,14 +48,7 @@ public function filterPlaceholdersContent() /** * @var \BrizyPlaceholders\ContentPlaceholder $placeholder ; */ - $cleanId = str_replace(['-tag', '-pag'], '', $placeholderId); - if (strpos($placeholderId, "-tag") !== false) { - $placeholder = $context->getPlaceholderByNameAndId("brizy_dc_post_loop_tags", $cleanId); - } elseif (strpos($placeholderId, "-pag") !== false) { - $placeholder = $context->getPlaceholderByNameAndId("brizy_dc_post_loop_pagination", $cleanId); - } else { - $placeholder = $context->getPlaceholderById($placeholderId); - } + $placeholder = $context->getPlaceholderById($placeholderId); if (!$placeholder) { $placeholderContents[$placeholderId] = ''; From daba9c31c261d394c555ec01c770d414cc57a84c Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Wed, 23 Aug 2023 09:43:44 +0300 Subject: [PATCH 40/45] new: added filter placeholders url in config. --- editor/editor/editor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/editor/editor/editor.php b/editor/editor/editor.php index 0eb69dcbec..ebc13652ba 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -168,6 +168,7 @@ public function config($context = self::COMPILE_CONTEXT) 'pluginSettings' => admin_url('admin.php?page='.Brizy_Admin_Settings::menu_slug()), 'dashboardNavMenu' => admin_url('nav-menus.php'), 'customFile' => home_url('?'.Brizy_Editor::prefix('_attachment').'='), + 'filterPlaceholders'=> home_url("/wp-admin/admin-ajax.php?action=".Brizy_Editor::prefix('_filter_placeholders_content')) ), 'form' => array( 'submitUrl' => '{{brizy_dc_ajax_url}}?action='.Brizy_Editor::prefix( From 3c1ed7c2574e14d9a8c0c9a49a0f7f0a5963d626 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Thu, 21 Sep 2023 15:05:46 +0300 Subject: [PATCH 41/45] new: added editor client config filter --- editor/editor/editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor/editor/editor.php b/editor/editor/editor.php index ebc13652ba..9af12a6c02 100755 --- a/editor/editor/editor.php +++ b/editor/editor/editor.php @@ -96,12 +96,13 @@ public function getClientConfig($context) ]; $config = $this->getApiConfigFields($config, $context); - $config = $this->addLoopSourcesClientConfig( + $config = $this->addLoopSourcesClientConfig( $config, $mode === 'template', $this->post->getWpPostId(), $context ); + $config = apply_filters('brizy_client_config', $config, $context); return $config; } @@ -1735,7 +1736,6 @@ public function getProjectStatus() */ public function getApiActions($config = [], $context = null) { - $pref = Brizy_Editor::prefix(); $actions = array( From 4a41c943c887e54f1578b8b866d1d652f23f6468 Mon Sep 17 00:00:00 2001 From: Artur Gunca Date: Wed, 11 Oct 2023 10:46:38 +0300 Subject: [PATCH 42/45] Filters From Api --- .../src/Elements/Filters/index.ts | 37 ++++++ .../src/Elements/Filters/utils.ts | 105 ++++++++++++++++ public/editor-client/src/api/index.ts | 37 ++++++ public/editor-client/src/config.ts | 6 + public/editor-client/src/index.ts | 13 ++ public/editor-client/src/types/Filters.ts | 112 ++++++++++++++++++ public/editor-client/src/types/global.d.ts | 2 + .../editor-client/src/utils/reader/array.ts | 12 ++ 8 files changed, 324 insertions(+) create mode 100644 public/editor-client/src/Elements/Filters/index.ts create mode 100644 public/editor-client/src/Elements/Filters/utils.ts create mode 100644 public/editor-client/src/types/Filters.ts create mode 100644 public/editor-client/src/utils/reader/array.ts diff --git a/public/editor-client/src/Elements/Filters/index.ts b/public/editor-client/src/Elements/Filters/index.ts new file mode 100644 index 0000000000..310303ea3e --- /dev/null +++ b/public/editor-client/src/Elements/Filters/index.ts @@ -0,0 +1,37 @@ +import { getFields } from "../../api"; +import { Filters } from "../../types/Filters"; +import { t } from "../../utils/i18n"; +import { converter, parseFields } from "./utils"; + +export const handler: Filters["handler"] = async (res, rej, data) => { + try { + const result = await getFields(data); + + const convertedValue = converter(result); + + res(convertedValue ?? []); + } catch (e) { + rej(t("Failed to load sources")); + } +}; + +export const possibleValues: Filters["possibleValues"] = async ( + res, + rej, + { type, search, optionSource, postId, loopAttributes } +) => { + try { + const result = await getFields({ postId, loopAttributes }); + + const convertPossibleValues = parseFields( + result, + optionSource, + type, + search + ); + + res(convertPossibleValues ?? []); + } catch (e) { + rej(t("Failed to load sources")); + } +}; diff --git a/public/editor-client/src/Elements/Filters/utils.ts b/public/editor-client/src/Elements/Filters/utils.ts new file mode 100644 index 0000000000..985c4c3b57 --- /dev/null +++ b/public/editor-client/src/Elements/Filters/utils.ts @@ -0,0 +1,105 @@ +import { + Choice, + FilterFieldsData, + fromStringQueryTypeSource, + isChoiceArray, + isPossibleValueArray, + PossibleValue, + QueryTypeSource +} from "../../types/Filters"; +import { isAllValuesValid } from "../../utils/reader/array"; + +export const createQueryTypeSource = ( + query: string, + type: string, + source: string, + filterBy: string +): QueryTypeSource | undefined => + fromStringQueryTypeSource(`${query}|||${type}|||${source}|||${filterBy}`); + +export const converter = (data: FilterFieldsData): Choice[] => { + const arr = Object.values(data).reduce((acc: Choice[], cur) => { + const field = cur.map((item) => { + return { + value: + createQueryTypeSource( + getQuery(item.filterQuery, item.optionQuery, item.optionSource), + item.type, + item.optionSource, + item.filterBy + ) ?? "", + title: item.label + }; + }); + return [...acc, ...field]; + }, []); + + return arr ?? []; +}; + +export const getQuery = ( + filterQuery: string, + optionQuery: string, + optionSource: string +): string => filterQuery || optionQuery || `metaKey=${optionSource}`; + +export const parseFields = ( + data: FilterFieldsData, + optionSource: string, + type: string, + search?: string +): Choice[] => { + const allItem = { value: "all", title: type === "inc" ? "All" : "None" }; + + const selectedItem = Object.values(data).reduce((acc, cur) => { + const field = cur.filter((item) => item.optionQuery === optionSource); + + return [...acc, ...field]; + }, [])[0]; + + if (selectedItem.optionSource === "tax") { + const parsedValues: PossibleValue[] = isPossibleValueArray( + selectedItem.possibleValues + ) + ? selectedItem.possibleValues + : []; + const items: Choice[] = parsedValues.map((it) => ({ + value: it.term_id, + title: it.name + })); + + if (search) { + return [ + allItem, + ...items.filter((it) => + it.title.toLocaleLowerCase().includes(search.toLocaleLowerCase()) + ) + ]; + } + + if (isAllValuesValid(items)) { + return [allItem, ...items]; + } + } + + if (selectedItem.optionSource === "meta") { + const items = isChoiceArray(selectedItem.possibleValues) + ? selectedItem.possibleValues + : []; + + if (search) { + return [ + allItem, + ...items.filter((it) => + it.title.toLocaleLowerCase().includes(search.toLocaleLowerCase()) + ) + ]; + } + + if (isAllValuesValid(items)) { + return [allItem, ...items]; + } + } + + return [allItem]; +}; diff --git a/public/editor-client/src/api/index.ts b/public/editor-client/src/api/index.ts index b53628f339..195d409cae 100644 --- a/public/editor-client/src/api/index.ts +++ b/public/editor-client/src/api/index.ts @@ -1262,3 +1262,40 @@ export const updateGlobalBlocks = async ( }; //#endregion + +//#region FiltersFields + +export const getFields = async (data: { + postId: string; + loopAttributes: string; +}) => { + try { + const config = getConfig(); + + if (!config) { + throw new Error(t("Invalid __BRZ_PLUGIN_ENV__")); + } + + const { editorVersion, url, hash, actions } = config; + + const body = new URLSearchParams({ + hash, + version: editorVersion, + action: actions.filterFields, + ...data + }); + + const result = await request(url, { + method: "POST", + body + }); + + const r = await result.json(); + + return r.data; + } catch (e) { + throw new Error(t("Fail to load fields!")); + } +}; + +//#endregion diff --git a/public/editor-client/src/config.ts b/public/editor-client/src/config.ts index 9176f937e6..56b9635fd0 100644 --- a/public/editor-client/src/config.ts +++ b/public/editor-client/src/config.ts @@ -52,6 +52,8 @@ interface Actions { heartBeat: string; takeOver: string; getFonts: string; + + filterFields: string; } interface ProjectStatus { @@ -282,6 +284,10 @@ const actionsReader = parseStrict({ getFonts: pipe( mPipe(Obj.readKey("getFonts"), Str.read), throwOnNullish("Invalid actions: getFonts") + ), + filterFields: pipe( + mPipe(Obj.readKey("filterFields"), Str.read), + throwOnNullish("Invalid actions: filterFields") ) }); diff --git a/public/editor-client/src/index.ts b/public/editor-client/src/index.ts index acb8f5ed65..bb30cb1a2a 100644 --- a/public/editor-client/src/index.ts +++ b/public/editor-client/src/index.ts @@ -12,6 +12,7 @@ import { defaultPopups, defaultStories } from "./defaultTemplates"; +import { handler as filters, possibleValues } from "./Elements/Filters"; import { placeholderData, placeholders } from "./dynamicContent"; import { handler as posts } from "./Elements/Posts"; import { uploadedFonts } from "./fonts"; @@ -90,8 +91,20 @@ if (window.__VISUAL_CONFIG__) { // Elements if (window.__VISUAL_CONFIG__.elements) { set(window.__VISUAL_CONFIG__.elements, ["posts", "handler"], posts); + set(window.__VISUAL_CONFIG__.elements, ["filters", "handler"], filters); + set( + window.__VISUAL_CONFIG__.elements, + ["filters", "possibleValues"], + possibleValues + ); } else { set(window.__VISUAL_CONFIG__, ["elements", "posts", "handler"], posts); + set(window.__VISUAL_CONFIG__, ["elements", "filters", "handler"], filters); + set( + window.__VISUAL_CONFIG__, + ["elements", "filters", "possibleValues"], + possibleValues + ); } // Dynamic Content diff --git a/public/editor-client/src/types/Filters.ts b/public/editor-client/src/types/Filters.ts new file mode 100644 index 0000000000..92c41592c9 --- /dev/null +++ b/public/editor-client/src/types/Filters.ts @@ -0,0 +1,112 @@ +import { pass } from "fp-utilities"; +import { Literal } from "../utils/types"; +import { NewType } from "./NewType"; +import { Response } from "./Response"; + +export type Choice = { title: string; value: Literal }; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const isChoice = (values: any): values is Choice => { + return typeof values === "object" && "title" in values && "value" in values; +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const isChoiceArray = (arr: any): arr is Choice[] => { + if (!Array.isArray(arr)) return false; + for (const item of arr) { + if (!isChoice(item)) return false; + } + return true; +}; + +export type QueryTypeSource = NewType; + +export const isQueryTypeSource = (s: string): s is QueryTypeSource => + s.split("|||").length === 3; + +export const fromStringQueryTypeSource = pass(isQueryTypeSource); + +interface FieldsCommon { + filterQuery: string; + label: string; + optionQuery: string; + optionSource: string; + filterBy: string; + type: string; +} + +export interface FilterField extends FieldsCommon { + possibleValues: PossibleValue[] | Choice[]; +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const isPossibleValue = (values: any): values is PossibleValue => { + return ( + typeof values === "object" && + "count" in values && + "description" in values && + "filter" in values && + "name" in values && + "parent" in values && + "slug" in values && + "taxonomy" in values && + "term_group" in values && + "term_id" in values && + "term_taxonomy_id" in values + ); +}; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const isPossibleValueArray = (arr: any): arr is PossibleValue[] => { + if (!Array.isArray(arr)) return false; + for (const item of arr) { + if (!isPossibleValue(item)) return false; + } + return true; +}; + +export type PossibleValue = { + count: number; + description: string; + filter: string; + name: string; + parent: number; + slug: string; + taxonomy: string; + term_group: number; + term_id: number; + term_taxonomy_id: number; +}; + +export type FilterFieldsData = { + fields: FilterField[]; + taxonomies: FilterField[]; + metaFields: FilterField[]; + authors: FilterField[]; +}; + +export interface FiltersHandlerArgs { + postId: string; + loopAttributes: string; +} + +export interface FiltersValuesArgs { + postId: string; + loopAttributes: string; + optionSource: string; + type: string; + search?: string; +} + +export interface Filters { + handler: ( + res: Response, + rej: Response, + args: FiltersHandlerArgs + ) => void; + possibleValues: ( + res: Response, + rej: Response, + data: FiltersValuesArgs + ) => void; +} diff --git a/public/editor-client/src/types/global.d.ts b/public/editor-client/src/types/global.d.ts index 65d1c87534..7bfa81fee2 100644 --- a/public/editor-client/src/types/global.d.ts +++ b/public/editor-client/src/types/global.d.ts @@ -21,6 +21,7 @@ import { AddMediaData, AddMediaGallery } from "./Media"; import { OnChange } from "./OnChange"; import { PopupConditions } from "./PopupConditions"; import { Posts } from "./Posts"; +import { Filters } from "./Filters"; import { Data } from "./Publish"; import { SavedBlocks, SavedLayouts, SavedPopups } from "./SavedBlocks"; import { Screenshots } from "./Screenshots"; @@ -185,6 +186,7 @@ export interface VISUAL_CONFIG { elements?: { posts: Posts; + filters: Filters; }; //#endregion diff --git a/public/editor-client/src/utils/reader/array.ts b/public/editor-client/src/utils/reader/array.ts new file mode 100644 index 0000000000..86786f4894 --- /dev/null +++ b/public/editor-client/src/utils/reader/array.ts @@ -0,0 +1,12 @@ +import { isT } from "fp-utilities"; +import { Reader } from "./types"; + +export const read: Reader> = (v) => { + if (Array.isArray(v)) { + return v; + } + + return undefined; +}; + +export const isAllValuesValid = (arr: Array) => arr.every(isT); From 0579de46e49333e4851d9e10d2693ec4a6289389 Mon Sep 17 00:00:00 2001 From: Artur Gunca Date: Wed, 23 Aug 2023 14:53:44 +0300 Subject: [PATCH 43/45] moved to API from editor --- .../src/Elements/filters/index.ts | 134 ++++++++++++++++++ public/editor-client/src/api/index.ts | 2 +- 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 public/editor-client/src/Elements/filters/index.ts diff --git a/public/editor-client/src/Elements/filters/index.ts b/public/editor-client/src/Elements/filters/index.ts new file mode 100644 index 0000000000..554333b32c --- /dev/null +++ b/public/editor-client/src/Elements/filters/index.ts @@ -0,0 +1,134 @@ +import { getFields } from "../../api"; +import { + Choice, + FilterFieldsData, + Filters, + PossibleValue, + QueryTypeSource +} from "../../types/Filters"; +import { t } from "../../utils/i18n"; + +export const handler: Filters["handler"] = async (res, rej, data) => { + try { + const result = await getFields(data); + + const convertedValue = converter(result); + + res(convertedValue ?? []); + } catch (e) { + rej(t("Failed to load sources")); + } +}; + +export const possibleValues: Filters["possibleValues"] = async ( + res, + rej, + { type, search, optionSource, postId, loopAttributes } +) => { + try { + const result = await getFields({ postId, loopAttributes }); + + const convertPossibleValues = parseFields( + result, + optionSource, + type, + search + ); + + res(convertPossibleValues ?? []); + } catch (e) { + rej(t("Failed to load sources")); + } +}; + +const createQueryTypeSource = ( + query: string, + type: string, + source: string, + filterBy: string +): QueryTypeSource => { + return `${query}|||${type}|||${source}|||${filterBy}` as QueryTypeSource; +}; + +const converter = (data: FilterFieldsData): Choice[] => { + const arr = Object.values(data).reduce((acc: Choice[], cur) => { + const field = cur.map((item) => { + return { + value: createQueryTypeSource( + item.filterQuery + ? item.filterQuery + : item.optionQuery + ? item.optionQuery + : `metaKey=${item.optionSource}`, + item.type, + item.optionSource, + item.filterBy + ), + title: item.label + }; + }); + return [...acc, ...field]; + }, []); + + return arr ?? []; +}; + +const parseFields = ( + data: FilterFieldsData, + optionSource: string, + type: string, + search?: string +): Choice[] => { + const allItem = { value: "all", title: type === "inc" ? "All" : "None" }; + + const selectedItem = Object.values(data).reduce((acc, cur) => { + const field = cur.filter((item) => item.optionQuery === optionSource); + + return [...acc, ...field]; + }, [])[0]; + + if (selectedItem.optionSource === "tax") { + const items: Choice[] = ( + selectedItem.possibleValues as PossibleValue[] + ).map((it: PossibleValue) => ({ + value: it.term_id, + title: it.name + })); + + if (search) { + return [ + allItem, + ...items.filter((it) => + it.title.toLocaleLowerCase().includes(search.toLocaleLowerCase()) + ) + ]; + } + + if (checkNotNullOrUndefinedValues(items)) { + return [allItem, ...items]; + } + } + + if (selectedItem.optionSource === "meta") { + const items = selectedItem.possibleValues as Choice[]; + + if (search) { + return [ + allItem, + ...items.filter((it) => + it.title.toLocaleLowerCase().includes(search.toLocaleLowerCase()) + ) + ]; + } + + if (checkNotNullOrUndefinedValues(items)) { + return [allItem, ...items]; + } + } + + return [allItem]; +}; + +function checkNotNullOrUndefinedValues(arr: unknown[]) { + return arr.every((value) => value !== null && value !== undefined); +} diff --git a/public/editor-client/src/api/index.ts b/public/editor-client/src/api/index.ts index 195d409cae..661f32bd21 100644 --- a/public/editor-client/src/api/index.ts +++ b/public/editor-client/src/api/index.ts @@ -1281,7 +1281,7 @@ export const getFields = async (data: { const body = new URLSearchParams({ hash, version: editorVersion, - action: actions.filterFields, + action: actions.filterFields ?? "brizy_filter_fields", ...data }); From fd78f375cb9187fa9066b58502f165f6f0612a5b Mon Sep 17 00:00:00 2001 From: Artur Gunka Date: Thu, 11 Apr 2024 14:30:07 +0300 Subject: [PATCH 44/45] fixes for filters sources --- .../src/Elements/filters/index.ts | 134 ------------------ public/editor-client/src/index.ts | 6 +- public/editor-client/src/types/Filters.ts | 2 +- 3 files changed, 4 insertions(+), 138 deletions(-) delete mode 100644 public/editor-client/src/Elements/filters/index.ts diff --git a/public/editor-client/src/Elements/filters/index.ts b/public/editor-client/src/Elements/filters/index.ts deleted file mode 100644 index 554333b32c..0000000000 --- a/public/editor-client/src/Elements/filters/index.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { getFields } from "../../api"; -import { - Choice, - FilterFieldsData, - Filters, - PossibleValue, - QueryTypeSource -} from "../../types/Filters"; -import { t } from "../../utils/i18n"; - -export const handler: Filters["handler"] = async (res, rej, data) => { - try { - const result = await getFields(data); - - const convertedValue = converter(result); - - res(convertedValue ?? []); - } catch (e) { - rej(t("Failed to load sources")); - } -}; - -export const possibleValues: Filters["possibleValues"] = async ( - res, - rej, - { type, search, optionSource, postId, loopAttributes } -) => { - try { - const result = await getFields({ postId, loopAttributes }); - - const convertPossibleValues = parseFields( - result, - optionSource, - type, - search - ); - - res(convertPossibleValues ?? []); - } catch (e) { - rej(t("Failed to load sources")); - } -}; - -const createQueryTypeSource = ( - query: string, - type: string, - source: string, - filterBy: string -): QueryTypeSource => { - return `${query}|||${type}|||${source}|||${filterBy}` as QueryTypeSource; -}; - -const converter = (data: FilterFieldsData): Choice[] => { - const arr = Object.values(data).reduce((acc: Choice[], cur) => { - const field = cur.map((item) => { - return { - value: createQueryTypeSource( - item.filterQuery - ? item.filterQuery - : item.optionQuery - ? item.optionQuery - : `metaKey=${item.optionSource}`, - item.type, - item.optionSource, - item.filterBy - ), - title: item.label - }; - }); - return [...acc, ...field]; - }, []); - - return arr ?? []; -}; - -const parseFields = ( - data: FilterFieldsData, - optionSource: string, - type: string, - search?: string -): Choice[] => { - const allItem = { value: "all", title: type === "inc" ? "All" : "None" }; - - const selectedItem = Object.values(data).reduce((acc, cur) => { - const field = cur.filter((item) => item.optionQuery === optionSource); - - return [...acc, ...field]; - }, [])[0]; - - if (selectedItem.optionSource === "tax") { - const items: Choice[] = ( - selectedItem.possibleValues as PossibleValue[] - ).map((it: PossibleValue) => ({ - value: it.term_id, - title: it.name - })); - - if (search) { - return [ - allItem, - ...items.filter((it) => - it.title.toLocaleLowerCase().includes(search.toLocaleLowerCase()) - ) - ]; - } - - if (checkNotNullOrUndefinedValues(items)) { - return [allItem, ...items]; - } - } - - if (selectedItem.optionSource === "meta") { - const items = selectedItem.possibleValues as Choice[]; - - if (search) { - return [ - allItem, - ...items.filter((it) => - it.title.toLocaleLowerCase().includes(search.toLocaleLowerCase()) - ) - ]; - } - - if (checkNotNullOrUndefinedValues(items)) { - return [allItem, ...items]; - } - } - - return [allItem]; -}; - -function checkNotNullOrUndefinedValues(arr: unknown[]) { - return arr.every((value) => value !== null && value !== undefined); -} diff --git a/public/editor-client/src/index.ts b/public/editor-client/src/index.ts index bb30cb1a2a..660a710099 100644 --- a/public/editor-client/src/index.ts +++ b/public/editor-client/src/index.ts @@ -12,13 +12,13 @@ import { defaultPopups, defaultStories } from "./defaultTemplates"; -import { handler as filters, possibleValues } from "./Elements/Filters"; import { placeholderData, placeholders } from "./dynamicContent"; +import { handler as filters, possibleValues } from "./Elements/Filters"; import { handler as posts } from "./Elements/Posts"; import { uploadedFonts } from "./fonts"; -import { heartBeat } from "./heartBeat"; -import {globalBlocks } from "./globalBlocks/blocks"; +import { globalBlocks } from "./globalBlocks/blocks"; import { globalPopups } from "./globalBlocks/popups"; +import { heartBeat } from "./heartBeat"; import { addMedia } from "./media/addMedia"; import { addMediaGallery } from "./media/addMediaGallery"; import { onChange } from "./onChange"; diff --git a/public/editor-client/src/types/Filters.ts b/public/editor-client/src/types/Filters.ts index 92c41592c9..3a4102e21f 100644 --- a/public/editor-client/src/types/Filters.ts +++ b/public/editor-client/src/types/Filters.ts @@ -22,7 +22,7 @@ export const isChoiceArray = (arr: any): arr is Choice[] => { export type QueryTypeSource = NewType; export const isQueryTypeSource = (s: string): s is QueryTypeSource => - s.split("|||").length === 3; + s.split("|||").length === 4; export const fromStringQueryTypeSource = pass(isQueryTypeSource); From a9e2a2f2071fa62dd384a2a8434309147cfb9313 Mon Sep 17 00:00:00 2001 From: Zaharia Alexandru Date: Thu, 18 Apr 2024 15:59:03 +0300 Subject: [PATCH 45/45] fix: brizy_filter_placeholders_content action --- admin/blocks/main.php | 2 +- content/placeholder-wrapper-processor.php | 50 +++++++++++++++++++++++ editor/filters/api.php | 20 ++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 content/placeholder-wrapper-processor.php diff --git a/admin/blocks/main.php b/admin/blocks/main.php index b648c71f50..1518b7a486 100644 --- a/admin/blocks/main.php +++ b/admin/blocks/main.php @@ -372,7 +372,7 @@ private function findReferencedInPage($wpPost) return []; } - $context = Brizy_Content_ContextFactory::createContext(Brizy_Editor_Project::get(), $wpPost); + $context = Brizy_Content_ContextFactory::createContext(Brizy_Editor_Project::get(), $wpPost->getWpPost()); $placeholderProvider = new Brizy_Content_Providers_GlobalBlockProvider($context); $extractor = new \BrizyPlaceholders\Extractor($placeholderProvider); diff --git a/content/placeholder-wrapper-processor.php b/content/placeholder-wrapper-processor.php new file mode 100644 index 0000000000..916295acc7 --- /dev/null +++ b/content/placeholder-wrapper-processor.php @@ -0,0 +1,50 @@ +context = $context; + $this->processors[] = new Brizy_Content_ReferencedGlobalBlockProcessor(); // collect all referenced blocks + $this->processors[] = new Brizy_Content_BlocksProcessor(); // inserts the global blocks and popups referenced + $this->processors[] = new Brizy_Content_WrapperToPlaceholderProcessor(); + } + + /** + * @param $content + * + * @return string + */ + public function process($content) + { + foreach ($this->processors as $processor) { + $content = $processor->process($content, $this->context); + } + + return $content; + } + + /** + * @param Brizy_Content_Context $context + */ + public function setContext($context) + { + $this->context = $context; + } +} diff --git a/editor/filters/api.php b/editor/filters/api.php index 004be87e04..3ed7a58371 100644 --- a/editor/filters/api.php +++ b/editor/filters/api.php @@ -8,7 +8,10 @@ class Brizy_Editor_Filters_Api extends Brizy_Admin_AbstractApi protected function initializeApiActions() { - $this->addNoPrivAjaxAction(self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array($this, 'filterPlaceholdersContent')); + $this->addNoPrivAjaxAction(self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array( + $this, + 'filterPlaceholdersContent', + )); $this->addAjaxAction(self::AJAX_FILTER_PLACEHOLDERS_CONTENT, array($this, 'filterPlaceholdersContent')); } @@ -32,6 +35,18 @@ public function filterPlaceholdersContent() $brizyPost = Brizy_Editor_Post::get($postId); $postContent = $this->getBrizyPostContent(Brizy_Editor_Project::get(), $brizyPost); +// $postContent = apply_filters( +// 'brizy_content', +// $postContent, +// Brizy_Editor_Project::get(), +// $brizyPost->getWpPost() +// ); + + $context = Brizy_Content_ContextFactory::createContext(Brizy_Editor_Project::get(), $brizyPost->getWpPost()); + $mainProcessor = new Brizy_Content_PlaceholderWrapperProcessor($context); + $postContent = $mainProcessor->process($postContent); + + $placeholderProvider = new Brizy_Content_PlaceholderProvider(); $context = new Brizy_Content_Context(Brizy_Editor_Project::get(), $brizyPost, $brizyPost->getWpPost(), ''); $context->setProvider($placeholderProvider); @@ -71,8 +86,11 @@ public function filterPlaceholdersContent() private function getBrizyPostContent(Brizy_Editor_Project $project, Brizy_Editor_Post $post) { + return $post->get_compiled_html(); + $project = Brizy_Editor_Project::get(); + if (!$post->get_compiled_html()) { $compiled_html_body = $post->get_compiled_html_body(); $content = Brizy_SiteUrlReplacer::restoreSiteUrl($compiled_html_body);