Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/addons.tar
Назад
wpml-page-builders/classes/OldPlugin.php 0000755 00000003332 14720415745 0014324 0 ustar 00 <?php namespace WPML\PB; /** * We had a first project of WPML Page Builders abandoned * some years before (last version v1.1.3), when we included the code inside ST, * and then in Core as composer package. * * This old plugin contains outdated code and we cannot afford * to have it running in parallel while the new version is also * embedded in Core. */ class OldPlugin { /** * @return bool */ public static function handle() { if ( defined( 'WPML_PAGE_BUILDERS_VERSION' ) && version_compare( constant( 'WPML_PAGE_BUILDERS_VERSION' ), '2', '<' ) ) { deactivate_plugins( 'wpml-page-builders/plugin.php' ); self::addNotice(); if ( ! wpml_is_cli() && wp_safe_redirect( $_SERVER['REQUEST_URI'], 302, 'wpml' ) ) { die; } return true; } return false; } private static function addNotice() { $text = '<h2>' . __( 'Update needed for WPML Page Builders plugin', 'wpml-page-builders' ) . '</h2>'; $text .= '<p>' . __( 'To prevent conflicts with WPML, we have deactivated your outdated WPML Page Builders plugin. Please update and reactivate it to continue receiving compatibility updates for your page builders as they become available.', 'wpml-page-builders' ) . '</p>'; $text .= '<p>' . __( 'You can still receive compatibility updates without WPML Page Builders as part of the WPML core plugin. However, keeping the standalone plugin allows you to receive these updates sooner and more often.', 'wpml-page-builders' ) . '</p>'; $notices = wpml_get_admin_notices(); $notice = $notices->create_notice( 'deactivated-notice', $text, __CLASS__ ); $notice->set_flash(); $notice->set_hideable( true ); $notice->set_css_class_types( [ 'notice-info' ] ); $notices->add_notice( $notice ); } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-job-links.php 0000755 00000002165 14720415745 0025072 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class JobLinks { /** @var JobFactory $job_factory */ private $job_factory; public function __construct( JobFactory $job_factory ) { $this->job_factory = $job_factory; } /** * @param array $job_ids * * @return \WPML\Collect\Support\Collection */ public function get( array $job_ids ) { return \wpml_collect( $job_ids )->map( function( $job_id ) { return $this->getJobEditLink( $job_id ); } )->filter(); } /** * @param int $job_id * * @return string|null */ private function getJobEditLink( $job_id ) { $job = $this->job_factory->get_translation_job( $job_id ); if ( ! $job || 'post_wp_block' !== $job->original_post_type ) { return null; } $job_edit_url = admin_url( 'admin.php?page=' . WPML_TM_FOLDER . '/menu/translations-queue.php&job_id=' . $job_id ); $job_edit_url = apply_filters( 'icl_job_edit_url', $job_edit_url, $job_id ); return '<a href="' . $job_edit_url . '" class="wpml-external-link" target="_blank">' . $job->title . '</a>'; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-basket-element.php 0000755 00000001610 14720415745 0026074 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class BasketElement { /** @var int */ private $element_id; /** @var string */ private $source_lang; /** @var array */ private $target_langs; /** * @param int $element_id * @param string $source_lang * @param array $target_languages */ public function __construct( $element_id, $source_lang, array $target_languages ) { $this->element_id = (int) $element_id; $this->source_lang = $source_lang; $this->target_langs = $target_languages; } /** * @return int */ public function get_element_id() { return $this->element_id; } /** * @return string */ public function get_element_type() { return 'post'; } /** * @return string */ public function get_source_lang() { return $this->source_lang; } /** * @return array */ public function get_target_langs() { return $this->target_langs; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-manage.php 0000755 00000005650 14720415745 0024434 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; abstract class Manage { /** @var Blocks */ protected $blocks; /** @var Translation */ protected $translation; public function __construct( Blocks $blocks, Translation $translation ) { $this->blocks = $blocks; $this->translation = $translation; } /** * @param \WPML\Collect\Support\Collection $blocks * * [ * (object) [ * 'block_id' => 1, * 'target_langs' => ['fr' => 1, 'de' => 1], * 'source_lang' => 'en', * ], * (object) [ * 'block_id' => 2, * 'target_langs' => ['de' => 1], * 'source_lang' => 'en', * ], * ] * * @return \WPML\Collect\Support\Collection */ protected function getBlockElementsToAdd( $blocks ) { return $blocks->map( [ $this, 'selectTargetLangs' ] ) ->reject( function( $block ) { return empty( $block->target_langs ); } ); } /** * @param \WPML\Collect\Support\Collection $post_elements * * @return \WPML\Collect\Support\Collection */ protected function getBlocksFromPostElements( \WPML\Collect\Support\Collection $post_elements ) { return $post_elements->map( [ $this, 'findBlocksInElement' ] ) ->flatten( 1 ) ->unique( 'block_id' ); } /** * @param \WPML_TM_Translation_Batch_Element|BasketElement|mixed $element * * @return array */ public function findBlocksInElement( $element ) { if ( ! $element instanceof \WPML_TM_Translation_Batch_Element && ! $element instanceof BasketElement ) { throw new \RuntimeException( '$element must be an instance of \WPML_TM_Translation_Batch_Element or Reusable_Blocks_Basket_Element.' ); } if ( $element->get_element_type() !== 'post' ) { return []; } return \wpml_collect( $this->blocks->getChildrenIdsFromPost( $element->get_element_id() ) ) ->map( function( $block_id ) use ( $element ) { return (object) [ 'block_id' => $block_id, 'source_lang' => $element->get_source_lang(), 'target_langs' => $element->get_target_langs(), ]; } )->toArray(); } /** * @param int $block_id * @param string $target_lang * * @return bool */ protected function requiresTranslation( $block_id, $target_lang ) { $needs_job = true; $translated_id = $this->translation->convertBlockId( $block_id, $target_lang ); if ( $translated_id !== $block_id ) { $needs_job = (bool) wpml_get_post_status_helper()->needs_update( $translated_id ); } return $needs_job; } /** * We will remove target langs that do not require a job * for the reusable block. * * @param \stdClass $block * * @return \stdClass */ public function selectTargetLangs( \stdClass $block ) { $block->target_langs = wpml_collect( $block->target_langs ) ->filter( function ( $unused, $target_lang ) use ( $block ) { return $this->requiresTranslation( $block->block_id, $target_lang ); } ) ->toArray(); return $block; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-manage-basket.php 0000755 00000005025 14720415745 0025677 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class ManageBasket extends Manage { /** @var Basket $translation_basket */ private $translation_basket; public function __construct( Blocks $blocks, Translation $translation, Basket $translation_basket ) { parent::__construct( $blocks, $translation ); $this->translation_basket = $translation_basket; } /** * @param array $data */ public function addBlocks( array $data ) { if ( ! isset( $data['post'], $data['translate_from'], $data['tr_action'] ) ) { return; } $post_elements = $this->extractAddedPostElements( $data ); $blocks = $this->getBlocksFromPostElements( $post_elements ); $blocks = $this->getBlockElementsToAdd( $blocks )->toArray(); if ( $blocks ) { $basket_portion = [ 'post' => [], 'source_language' => $data['translate_from'], 'target_languages' => array_keys( $data['tr_action'] ), ]; foreach ( $blocks as $block ) { $basket_portion['post'][ $block->block_id ] = [ 'from_lang' => $block->source_lang, 'to_langs' => $block->target_langs, 'auto_added' => true, // This is an optional flag we can use when displaying the basket ]; } $this->translation_basket->update_basket( $basket_portion ); } } /** * @param array $data * * @return \WPML\Collect\Support\Collection */ private function extractAddedPostElements( array $data ) { $source_lang = $data['translate_from']; $target_langs = \wpml_collect( $data['tr_action'] ) ->filter( function( $translate ) { return $translate; } ) ->map( function( $translate ) { return (int) $translate; } ) ->toArray(); return \wpml_collect( $data['post'] )->map( function( $item ) use ( $source_lang, $target_langs ) { if ( ! isset( $item['checked'], $item['type'] ) || 'post' !== $item['type'] ) { return null; } $target_langs = $this->filterTargetLangs( $target_langs, $item['checked'] ); if ( ! $target_langs ) { return null; } return new BasketElement( (int) $item['checked'], $source_lang, $target_langs ); } )->filter(); } /** * @param array $target_langs * @param int $post_id * * @return array */ private function filterTargetLangs( array $target_langs, $post_id ) { $post_source_lang = $this->translation->getSourceLang( $post_id ); return \wpml_collect( $target_langs )->reject( function( $unused, $target_lang ) use ( $post_source_lang ) { return $target_lang === $post_source_lang; } )->toArray(); } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/JobFactory.php 0000755 00000000607 14720415745 0024140 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class JobFactory { /** @var \WPML_Translation_Job_Factory|null $job_factory */ private $job_factory; public function get_translation_job( $job_id ) { if ( ! $this->job_factory ) { $this->job_factory = \WPML\Container\make( '\WPML_Translation_Job_Factory' ); } return $this->job_factory->get_translation_job( $job_id ); } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-manage-batch.php 0000755 00000001073 14720415745 0025506 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class ManageBatch extends Manage { public function addBlocks( \WPML_TM_Translation_Batch $batch ) { $blocks = $this->getBlocksFromPostElements( \wpml_collect( $batch->get_elements() ) ); $this->getBlockElementsToAdd( $blocks )->each( function( $block ) use ( $batch ) { $new_element = new \WPML_TM_Translation_Batch_Element( $block->block_id, 'post', $block->source_lang, $block->target_langs ); $batch->add_element( $new_element ); } ); return $batch; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-translation.php 0000755 00000002206 14720415745 0025534 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class Translation { const POST_TYPE = 'wp_block'; /** @var \SitePress $sitepress */ private $sitepress; /** * @param \SitePress $sitepress */ public function __construct( \SitePress $sitepress ) { $this->sitepress = $sitepress; } /** * @param array $block * @param null|string $lang * * @return array */ public function convertBlock( array $block, $lang = null ) { if ( Blocks::isReusable( $block ) ) { $block['attrs']['ref'] = $this->convertBlockId( $block['attrs']['ref'], $lang ); } return $block; } /** * @param int $block_id * @param string|null $lang * * @return int */ public function convertBlockId( $block_id, $lang = null ) { return $this->sitepress->get_object_id( $block_id, self::POST_TYPE, true, $lang ); } /** * @param int $post_id * * @return string|null */ public function getSourceLang( $post_id ) { $details = $this->sitepress->get_element_language_details( $post_id, 'post_' . get_post_type( $post_id ) ); return isset( $details->source_language_code ) ? $details->source_language_code : null; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/Basket.php 0000755 00000000647 14720415745 0023313 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class Basket { /** @var \WPML_Translation_Basket|null $translation_basket */ private $translation_basket = null; public function update_basket( $basket_portion ) { if ( ! $this->translation_basket ) { $this->translation_basket = \WPML\Container\make( '\WPML_Translation_Basket' ); } return $this->translation_basket->update_basket( $basket_portion ); } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-admin-integration.php 0000755 00000003545 14720415745 0026616 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; class AdminIntegration implements \WPML\PB\Gutenberg\Integration { /** @var ManageBatch $manage_batch */ private $manage_batch; /** @var ManageBasket $manage_basket */ private $manage_basket; /** @var Notice $notice */ private $notice; public function __construct( ManageBatch $manage_batch, ManageBasket $manage_basket, Notice $notice ) { $this->manage_batch = $manage_batch; $this->manage_basket = $manage_basket; $this->notice = $notice; } public function add_hooks() { /** * The reusable blocks are already added to the basket. * We don't want to automatically add it again if * the user manually removed it. */ if ( ! $this->isSubmittingBasket() ) { add_filter( 'wpml_send_jobs_batch', [ $this, 'addBlocksToBatch' ] ); add_action( 'wpml_added_translation_jobs', [ $this, 'notifyExtraJobsToTranslator' ] ); } add_action( 'wpml_tm_add_to_basket', [ $this, 'addBlocksToBasket' ] ); } private function isSubmittingBasket() { return isset( $_POST['action'] ) && 'send_basket_item' === $_POST['action']; } /** * Add reusable block elements that are used inside * the post elements already in the batch. * * @param \WPML_TM_Translation_Batch $batch * * @return \WPML_TM_Translation_Batch */ public function addBlocksToBatch( \WPML_TM_Translation_Batch $batch ) { return $this->manage_batch->addBlocks( $batch ); } /** * Add reusable blocks that are used in the * post items in the basket. * * @param array $data */ public function addBlocksToBasket( array $data ) { $this->manage_basket->addBlocks( $data ); } /** * @param array $added_jobs */ public function notifyExtraJobsToTranslator( array $added_jobs ) { if ( isset( $added_jobs['local'] ) ) { $this->notice->addJobsCreatedAutomatically( $added_jobs['local'] ); } } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-blocks.php 0000755 00000002152 14720415745 0024453 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; use WPML\FP\Obj; class Blocks { /** * @param array $block * * @return bool */ public static function isReusable( array $block ) { return 'core/block' === $block['blockName'] && isset( $block['attrs']['ref'] ) && is_numeric( $block['attrs']['ref'] ); } /** * @param array $block * * @return int */ public static function getReusableId( array $block ) { return (int) Obj::path( [ 'attrs', 'ref' ], $block ); } /** * We get block IDs recursively to find possible * nested reusable blocks. * * @param int $post_id * * @return array */ public function getChildrenIdsFromPost( $post_id ) { $post = get_post( $post_id ); if ( $post ) { $blocks = \wpml_collect( \WPML_Gutenberg_Integration::parse_blocks( $post->post_content ) ); return $blocks ->filter( [ self::class, 'isReusable' ] ) ->map( function( $block ) { $block_id = self::getReusableId( $block ); return array_merge( [ $block_id ], $this->getChildrenIdsFromPost( $block_id ) ); })->flatten()->toArray(); } return []; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-notice.php 0000755 00000003466 14720415745 0024470 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; use WPML\API\Sanitize; class Notice { /** @var \WPML_Notices $notices */ private $notices; /** @var JobLinks */ private $job_links; public function __construct( \WPML_Notices $notices, JobLinks $job_links ) { $this->notices = $notices; $this->job_links = $job_links; } public function addJobsCreatedAutomatically( array $job_ids ) { $job_links = $this->job_links->get( $job_ids ); if ( $job_links->isEmpty() ) { return; } $text = '<p>' . _n( 'We automatically created a translation job for the reusable block:', 'We automatically created translation jobs for the reusable blocks:', $job_links->count(), 'sitepress' ) . '</p>'; $text .= '<ul><li>' . implode( '</li><li>', $job_links->toArray() ) . '</li></ul>'; $notice = $this->notices->create_notice( 'automatic-jobs', $text, __CLASS__ ); $notice->set_flash( true ); $notice->set_restrict_to_screen_ids( $this->getRestrictScreenIDs() ); $notice->set_hideable( true ); $notice->set_css_class_types( 'notice-info' ); $this->notices->add_notice( $notice ); } /** * @return array */ private function getRestrictScreenIDs() { $screen_ids = [ 'post', 'edit-post' ]; /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */ $return_url = Sanitize::stringProp( 'return_url', $_GET ); if ( false !== $return_url ) { $query = wpml_parse_url( $return_url, PHP_URL_QUERY ); parse_str( $query, $params ); if ( isset( $params['post'] ) ) { $post_id = filter_var( $params['post'], FILTER_VALIDATE_INT ); $screen_ids = [ get_post_type( $post_id ) ]; } elseif ( isset( $params['post_type'] ) ) { $post_type = Sanitize::stringProp( 'post_type', $params ); $screen_ids = [ 'edit-' . $post_type ]; } } return $screen_ids; } } wpml-page-builders/classes/Integrations/Gutenberg/reusable-blocks/class-integration.php 0000755 00000002550 14720415745 0025523 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ReusableBlocks; use WPML\FP\Fns; class Integration implements \WPML\PB\Gutenberg\Integration { /** @var Translation $translation */ private $translation; public function __construct( Translation $translation ) { $this->translation = $translation; } public function add_hooks() { add_filter( 'render_block_data', [ $this, 'convertReusableBlock' ] ); add_filter( 'render_block', Fns::withoutRecursion( Fns::identity(), [ $this, 'reRenderInnerReusableBlock' ] ), 10, 2 ); } /** * Converts the block in the current language * * @param array $block * * @return array */ public function convertReusableBlock( array $block ) { return $this->translation->convertBlock( $block ); } /** * The filter hook `render_block_data` applies only for root blocks, * nested blocks are not passing through this hook. * That's why we need to re-render reusable nested blocks. * * @param string $blockContent * @param array $block * * @return string */ public function reRenderInnerReusableBlock( $blockContent, $block ) { $originalId = Blocks::getReusableId( $block ); if ( $originalId ) { $convertedBlock = $this->translation->convertBlock( $block ); if ( Blocks::getReusableId( $convertedBlock ) !== $originalId ) { return render_block( $convertedBlock ); } } return $blockContent; } } wpml-page-builders/classes/Integrations/Gutenberg/class-wpml-gutenberg-strings-registration.php 0000755 00000013720 14720415745 0027262 0 ustar 00 <?php class WPML_Gutenberg_Strings_Registration { /** @var WPML\PB\Gutenberg\StringsInBlock\StringsInBlock $strings_in_blocks */ private $strings_in_blocks; /** @var WPML_ST_String_Factory $string_factory */ private $string_factory; /** @var WPML_PB_Reuse_Translations $reuse_translations */ private $reuse_translations; /** @var WPML_PB_String_Translation $string_translation */ private $string_translation; /** @var int $string_location */ private $string_location; /** @var array $leftover_strings */ private $leftover_strings; /** @var WPML_Translate_Link_Targets $translate_link_targets */ private $translate_link_targets; /** @var callable $set_link_translations */ private $set_link_translations; public function __construct( WPML\PB\Gutenberg\StringsInBlock\StringsInBlock $strings_in_blocks, WPML_ST_String_Factory $string_factory, WPML_PB_Reuse_Translations $reuse_translations, WPML_PB_String_Translation $string_translation, WPML_Translate_Link_Targets $translate_link_targets, callable $set_link_translations ) { $this->strings_in_blocks = $strings_in_blocks; $this->string_factory = $string_factory; $this->reuse_translations = $reuse_translations; $this->string_translation = $string_translation; $this->translate_link_targets = $translate_link_targets; $this->set_link_translations = $set_link_translations; } /** * @param WP_Post $post * @param array $package_data */ public function register_strings( WP_Post $post, $package_data ) { do_action( 'wpml_start_string_package_registration', $package_data ); do_action( 'wpml_start_GB_register_strings', $post, $package_data ); $this->leftover_strings = $original_strings = $this->string_translation->get_package_strings( $package_data ); $this->string_location = 1; $this->register_blocks( WPML_Gutenberg_Integration::parse_blocks( $post->post_content ), $package_data, $post->ID ); $current_strings = $this->string_translation->get_package_strings( $package_data ); $this->reuse_translations->find_and_reuse_translations( $original_strings, $current_strings, $this->leftover_strings ); do_action( 'wpml_end_GB_register_strings', $post, $package_data ); do_action( 'wpml_delete_unused_package_strings', $package_data ); } /** * @param array $blocks * @param array $package_data */ public function register_strings_from_widget( array $blocks, array $package_data ) { do_action( 'wpml_start_string_package_registration', $package_data ); $this->leftover_strings = $original_strings = $this->string_translation->get_package_strings( $package_data ); $this->string_location = 1; $this->register_blocks( $blocks, $package_data, null ); $current_strings = $this->string_translation->get_package_strings( $package_data ); $this->reuse_translations->find_and_reuse_translations( $original_strings, $current_strings, $this->leftover_strings ); do_action( 'wpml_delete_unused_package_strings', $package_data ); } /** * @param array $blocks * @param array $package_data */ private function register_blocks( array $blocks, array $package_data, $post_id ) { foreach ( $blocks as $block ) { $block = WPML_Gutenberg_Integration::sanitize_block( $block ); $strings = $this->strings_in_blocks->find( $block ); if ( empty( $strings ) ) { if ( $post_id ) { apply_filters( 'wpml_pb_register_strings_in_content', false, $post_id, $block->innerHTML ); } } else { foreach ( $strings as $string ) { if( $post_id && apply_filters( 'wpml_pb_register_strings_in_content', false, $post_id, $string->value ) ) { continue; } if ( 'LINK' === $string->type && ! $this->translate_link_targets->is_internal_url( $string->value ) ) { $string->type = 'LINE'; } do_action( 'wpml_register_string', $string->value, $string->id, $package_data, $string->name, $string->type ); $this->update_string_location( $package_data, $string ); // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase if ( 'core/heading' === $block->blockName ) { // phpcs:enable $wrap_tag = (string) isset( $block->attrs['level'] ) ? $block->attrs['level'] : 2; $wrap_tag = 'h' . $wrap_tag; $this->update_wrap_tag( $package_data, $string, $wrap_tag ); } if ( 'LINK' === $string->type ) { $string_id = apply_filters( 'wpml_string_id_from_package', 0, $package_data, $string->id, $string->value ); call_user_func( $this->set_link_translations, $string_id ); } $this->remove_string_from_leftovers( $string->value ); } } if ( isset( $block->innerBlocks ) ) { $this->register_blocks( $block->innerBlocks, $package_data, $post_id ); } } } private function update_string_location( array $package_data, stdClass $string_data ) { $string_id = apply_filters( 'wpml_string_id_from_package', 0, $package_data, $string_data->id, $string_data->value ); $string = $this->string_factory->find_by_id( $string_id ); if ( $string_id ) { $string->set_location( $this->string_location ); $this->string_location++; } } /** * Update string wrap tag. * Used for SEO, can contain (h1...h6, etc.) * * @param array $package_data Package. * @param stdClass $string_data String in the package. * @param string $wrap_tag String wrap. */ private function update_wrap_tag( $package_data, stdClass $string_data, $wrap_tag ) { $string_id = apply_filters( 'wpml_string_id_from_package', 0, $package_data, $string_data->id, $string_data->value ); $string = $this->string_factory->find_by_id( $string_id ); if ( $string_id ) { $string->set_wrap_tag( $wrap_tag ); } } /** @var string $string_value */ private function remove_string_from_leftovers( $string_value ) { $string_hash = $this->string_translation->get_string_hash( $string_value ); if ( isset( $this->leftover_strings[ $string_hash ] ) ) { unset( $this->leftover_strings[ $string_hash ] ); } } } wpml-page-builders/classes/Integrations/Gutenberg/Widgets/Block/RegisterStrings.php 0000755 00000002147 14720415745 0024620 0 ustar 00 <?php namespace WPML\PB\Gutenberg\Widgets\Block; use WPML\FP\Fns; use WPML\FP\Logic; use WPML\FP\Lst; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\Container\make; use function WPML\FP\pipe; use function WPML\FP\spreadArgs; class RegisterStrings implements \IWPML_REST_Action, \WPML\PB\Gutenberg\Integration { public function add_hooks() { $registerStrings = Fns::memorize( function ( $oldValue, $newValue ) { $gutenbergIntegration = make( \WPML_Gutenberg_Integration::class ); $blocks = $this->getBlocks( $gutenbergIntegration, $newValue ); $gutenbergIntegration->register_strings_from_widget( $blocks, Strings::createPackage() ); } ); Hooks::onAction( 'update_option_widget_block', 10, 2 ) ->then( spreadArgs( $registerStrings ) ); } private function getBlocks( $gutenbergIntegration, $options ) { $getContent = Logic::ifElse( 'is_scalar', Fns::always( null ), Obj::prop( 'content' ) ); return wpml_collect( $options ) ->map( $getContent ) ->filter() ->unique() ->map( [ $gutenbergIntegration, 'parse_blocks' ] ) ->flatten( 1 ) ->toArray(); } } wpml-page-builders/classes/Integrations/Gutenberg/Widgets/Block/Strings.php 0000755 00000003241 14720415745 0023107 0 ustar 00 <?php namespace WPML\PB\Gutenberg\Widgets\Block; use WPML\Element\API\Languages; use WPML\FP\Maybe; use WPML\FP\Obj; use WPML\ST\TranslationFile\Manager; use function WPML\Container\make; use function WPML\FP\curryN; class Strings { const PACKAGE_KIND = 'Block'; const PACKAGE_KIND_SLUG = 'block'; const PACKAGE_NAME = 'widget'; const PACKAGE_TITLE = 'Widget'; const DOMAIN = self::PACKAGE_KIND_SLUG . '-' . self::PACKAGE_NAME; /** * @param string $locale * * @return array * @throws \WPML\Auryn\InjectionException */ public static function fromMo( $locale ) { $langCode = Languages::localeToCode( $locale ); $encode = curryN( 2, function ( $langCode, $value ) { return [ $langCode => [ 'value' => $value, 'status' => ICL_STRING_TRANSLATION_COMPLETE, ], ]; } ); return wpml_collect( self::loadStringsFromMOFile( self::DOMAIN, $locale ) ) ->map( Obj::path( [ 'translations', 0 ] ) ) ->filter() ->map( $encode( $langCode ) ) ->toArray(); } public static function loadStringsFromMOFile( $domain, $locale ) { return Maybe::of( Manager::getSubdir() . '/' . $domain . "-$locale.mo" ) ->filter( 'file_exists' ) ->map( function ( $file ) { $mo = make( \MO::class ); $mo->import_from_file( $file ); return $mo; } ) ->map( Obj::prop( 'entries' ) ) ->getOrElse( [] ); } public static function createPackage() { return [ 'kind' => self::PACKAGE_KIND, 'kind_slug' => self::PACKAGE_KIND_SLUG, 'name' => self::PACKAGE_NAME, 'title' => self::PACKAGE_TITLE, 'post_id' => null, ]; } } wpml-page-builders/classes/Integrations/Gutenberg/Widgets/Block/DisplayTranslation.php 0000755 00000001630 14720415745 0025302 0 ustar 00 <?php namespace WPML\PB\Gutenberg\Widgets\Block; use WPML\Element\API\Languages; use WPML\FP\Fns; use WPML\LIB\WP\Hooks; use function WPML\Container\make; use function WPML\FP\spreadArgs; class DisplayTranslation implements \IWPML_Frontend_Action, \WPML\PB\Gutenberg\Integration { /** * @see \WPML_Widgets_Support_Frontend::PRIORITY_AFTER_TRANSLATION_APPLIED */ const PRIORITY_BEFORE_REMOVE_BLOCK_MARKUP = -1; public function add_hooks() { $getStringsFromMOFile = Fns::memorize( [ Strings::class, 'fromMo' ] ); Hooks::onFilter( 'widget_block_content', self::PRIORITY_BEFORE_REMOVE_BLOCK_MARKUP ) ->then( spreadArgs( function ( $content ) use ( $getStringsFromMOFile ) { $strings = $getStringsFromMOFile( \get_locale() ); return make( \WPML_Gutenberg_Integration::class ) ->replace_strings_in_blocks( $content, $strings, Languages::getCurrentCode() ); } ) ); } } wpml-page-builders/classes/Integrations/Gutenberg/Widgets/Block/Search.php 0000755 00000000563 14720415745 0022667 0 ustar 00 <?php namespace WPML\PB\Gutenberg\Widgets\Block; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Search implements \IWPML_Frontend_Action, \WPML\PB\Gutenberg\Integration { public function add_hooks() { global $sitepress; Hooks::onFilter( 'render_block_core/search' ) ->then( spreadArgs( [ $sitepress, 'get_search_form_filter' ] ) ); } } wpml-page-builders/classes/Integrations/Gutenberg/XPath.php 0000755 00000002024 14720415745 0020040 0 ustar 00 <?php namespace WPML\PB\Gutenberg; use WPML\FP\Obj; class XPath { /** * If a sequence has only one element, we will wrap it * in order to have the same data shape as for multiple elements. * Also check for type attribute * * @param array|string $data * * @return array */ public static function normalize( $data ) { if ( isset( $data['attr'] ) ) { $data['value'] = array_merge( [ 'value' => $data['value'] ], $data['attr'] ); if ( isset( $data['value']['type'] ) ) { // @todo This IF will be redundant when I improve `over` function $data = Obj::over( Obj::lensPath( [ 'value', 'type' ] ), 'strtoupper', $data ); } unset( $data['attr'] ); } return $data; } /** * @param string|array $query * * @return array [query, type, label] */ public static function parse( $query ) { if ( is_array( $query ) ) { return [ $query['value'], isset( $query['type'] ) ? $query['type'] : '', isset( $query['label'] ) ? $query['label'] : '', ]; } return [ $query, '', '' ]; } } wpml-page-builders/classes/Integrations/Gutenberg/class-wpml-gutenberg-integration-factory.php 0000755 00000005064 14720415745 0027053 0 ustar 00 <?php use function WPML\Container\make; use function WPML\Container\share; class WPML_Gutenberg_Integration_Factory { /** @return \WPML\PB\Gutenberg\Integration_Composite */ public function create() { $integrations = new WPML\PB\Gutenberg\Integration_Composite(); $mainIntegration = $this->create_gutenberg_integration(); share( [ $mainIntegration ] ); $integrations->add( $mainIntegration ); if ( $this->should_translate_reusable_blocks() ) { $integrations->add( make( '\WPML\PB\Gutenberg\ReusableBlocks\Integration' ) ); if ( is_admin() ) { $integrations->add( make( '\WPML\PB\Gutenberg\ReusableBlocks\AdminIntegration' ) ); } } if ( ! is_admin() ) { $integrations->add( make( \WPML\PB\Gutenberg\Widgets\Block\DisplayTranslation::class ) ); $integrations->add( make( \WPML\PB\Gutenberg\Widgets\Block\Search::class ) ); $integrations->add( make( \WPML\PB\Gutenberg\Navigation\Frontend::class ) ); $integrations->add( make( \WPML\PB\Gutenberg\ConvertIdsInBlock\Hooks::class ) ); } $integrations->add( make( \WPML\PB\Gutenberg\Widgets\Block\RegisterStrings::class ) ); return $integrations; } /** * @return WPML_Gutenberg_Integration */ public function create_gutenberg_integration() { /** * @var SitePress $sitepress * @var wpdb $wpdb */ global $sitepress, $wpdb; $config_option = new WPML_Gutenberg_Config_Option(); $strings_in_block = $this->create_strings_in_block( $config_option ); $string_factory = new WPML_ST_String_Factory( $wpdb ); $strings_registration = new WPML_Gutenberg_Strings_Registration( $strings_in_block, $string_factory, new WPML_PB_Reuse_Translations( $string_factory ), new WPML_PB_String_Translation( $wpdb ), make( 'WPML_Translate_Link_Targets' ), WPML\PB\TranslateLinks::getTranslatorForString( $string_factory, $sitepress->get_active_languages() ) ); return new WPML_Gutenberg_Integration( $strings_in_block, $config_option, $strings_registration ); } private function create_strings_in_block( $config_option ) { $string_parsers = [ new WPML\PB\Gutenberg\StringsInBlock\HTML( $config_option ), new WPML\PB\Gutenberg\StringsInBlock\Attributes( $config_option ), ]; return new WPML\PB\Gutenberg\StringsInBlock\Collection( $string_parsers ); } /** @return bool */ private function should_translate_reusable_blocks() { /** @var SitePress $sitepress */ global $sitepress; return $sitepress->is_translated_post_type( WPML\PB\Gutenberg\ReusableBlocks\Translation::POST_TYPE ); } } wpml-page-builders/classes/Integrations/Gutenberg/Navigation/Frontend.php 0000755 00000001137 14720415745 0022676 0 ustar 00 <?php namespace WPML\PB\Gutenberg\Navigation; use WPML\FP\Obj; use WPML\FP\Relation; class Frontend implements \WPML\PB\Gutenberg\Integration { public function add_hooks() { add_filter( 'render_block_data', [ $this, 'translateNavigationId' ] ); } /** * @param array $data * * @return array */ public function translateNavigationId( $data ) { if ( Relation::propEq( 'blockName', 'core/navigation', $data ) && Obj::path( [ 'attrs', 'ref' ], $data ) ) { $data['attrs']['ref'] = apply_filters( 'wpml_object_id', $data['attrs']['ref'], 'wp_navigation', true ); } return $data; } } wpml-page-builders/classes/Integrations/Gutenberg/interface-integration.php 0000755 00000000136 14720415745 0023277 0 ustar 00 <?php namespace WPML\PB\Gutenberg; interface Integration { public function add_hooks(); } wpml-page-builders/classes/Integrations/Gutenberg/class-integration-composite.php 0000755 00000000576 14720415745 0024454 0 ustar 00 <?php namespace WPML\PB\Gutenberg; class Integration_Composite implements Integration { /** * @var Integration[] $integrations */ private $integrations; public function add( Integration $integration ) { $this->integrations[] = $integration; } public function add_hooks() { foreach ( $this->integrations as $integration ) { $integration->add_hooks(); } } } wpml-page-builders/classes/Integrations/Gutenberg/class-wpml-gutenberg-integration.php 0000755 00000023300 14720415745 0025377 0 ustar 00 <?php use WPML\FP\Fns; use WPML\FP\Str; /** * Class WPML_Gutenberg_Integration */ class WPML_Gutenberg_Integration implements \WPML\PB\Gutenberg\Integration { const PACKAGE_ID = 'Gutenberg'; const GUTENBERG_OPENING_START = '<!-- wp:'; const GUTENBERG_CLOSING_START = '<!-- /wp:'; const CLASSIC_BLOCK_NAME = 'core/classic-block'; /** * @var WPML\PB\Gutenberg\StringsInBlock\StringsInBlock */ private $strings_in_blocks; /** * @var WPML_Gutenberg_Config_Option */ private $config_option; /** * @var WPML_Gutenberg_Strings_Registration $strings_registration */ private $strings_registration; public function __construct( WPML\PB\Gutenberg\StringsInBlock\StringsInBlock $strings_in_block, WPML_Gutenberg_Config_Option $config_option, WPML_Gutenberg_Strings_Registration $strings_registration ) { $this->strings_in_blocks = $strings_in_block; $this->config_option = $config_option; $this->strings_registration = $strings_registration; } public function add_hooks() { add_filter( 'wpml_page_builder_support_required', array( $this, 'page_builder_support_required' ), 10, 1 ); add_action( 'wpml_page_builder_register_strings', array( $this, 'register_strings' ), 10, 2 ); add_action( 'wpml_page_builder_string_translated', array( $this, 'string_translated' ), 10, 5 ); add_filter( 'wpml_config_array', array( $this, 'wpml_config_filter' ) ); add_filter( 'wpml_pb_should_body_be_translated', array( $this, 'should_body_be_translated_filter' ), PHP_INT_MAX, 3 ); add_filter( 'wpml_get_translatable_types', array( $this, 'remove_package_strings_type_filter' ), 11 ); } /** * @param array $plugins * * @return array */ function page_builder_support_required( $plugins ) { $plugins[] = self::PACKAGE_ID; return $plugins; } /** * @param WP_Post $post * @param array $package_data */ function register_strings( WP_Post $post, $package_data ) { if ( $this->is_gutenberg_post( $post ) && self::PACKAGE_ID === $package_data['kind'] ) { $this->strings_registration->register_strings( $post, $package_data ); } } public function register_strings_from_widget( array $blocks, array $package_data ) { $this->strings_registration->register_strings_from_widget( $blocks, $package_data ); } /** * @param WP_Block_Parser_Block|array $block * * @return WP_Block_Parser_Block */ public static function sanitize_block( $block ) { if ( ! $block instanceof WP_Block_Parser_Block ) { if ( empty( $block['blockName'] ) ) { $block['blockName'] = self::CLASSIC_BLOCK_NAME; } $block = new WP_Block_Parser_Block( $block['blockName'], $block['attrs'], $block['innerBlocks'], $block['innerHTML'], $block['innerContent'] ); } return $block; } /** * @param string $package_kind * @param int $translated_post_id * @param WP_Post $original_post * @param array $string_translations * @param string $lang */ public function string_translated( $package_kind, $translated_post_id, $original_post, $string_translations, $lang ) { if ( self::PACKAGE_ID === $package_kind ) { $content = $this->replace_strings_in_blocks( $original_post->post_content, $string_translations, $lang ); wpml_update_escaped_post( [ 'ID' => $translated_post_id, 'post_content' => $content ], $lang ); } } /** * @param string $content * @param array $string_translations * @param string $lang * * @return string */ public function replace_strings_in_blocks( $content, $string_translations, $lang ) { $blocks = self::parse_blocks( $content ); $blocks = $this->update_block_translations( $blocks, $string_translations, $lang ); return Fns::reduce( Str::concat(), '', Fns::map( [ $this, 'render_block' ], $blocks ) ); } /** * @param array $blocks * @param array $string_translations * @param string $lang * * @return array */ private function update_block_translations( $blocks, $string_translations, $lang ) { foreach ( $blocks as &$block ) { $block = self::sanitize_block( $block ); $block = $this->strings_in_blocks->update( $block, $string_translations, $lang ); if ( isset( $block->innerBlocks ) ) { $block->innerBlocks = $this->update_block_translations( $block->innerBlocks, $string_translations, $lang ); } } return $blocks; } /** * @param array|WP_Block_Parser_Block $block * * @return string */ public static function render_block( $block ) { $content = ''; $block = self::sanitize_block( $block ); if ( self::CLASSIC_BLOCK_NAME !== $block->blockName ) { $block_content = self::render_inner_HTML( $block ); $block_type = preg_replace( '/^core\//', '', $block->blockName ); $block_attributes = ''; if ( self::has_non_empty_attributes( $block ) ) { $block_attributes = ' ' . json_encode( $block->attrs, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); } $content .= self::GUTENBERG_OPENING_START . $block_type . $block_attributes . ' '; if ( $block_content ) { $content .= '-->' . $block_content . self::GUTENBERG_CLOSING_START . $block_type . ' -->'; } else { $content .= '/-->'; } } else { $content = wpautop( $block->innerHTML ); } return $content; } public static function has_non_empty_attributes( WP_Block_Parser_Block $block ) { return (bool) ( (array) $block->attrs ); } /** * @param WP_Block_Parser_Block $block * * @return string */ private static function render_inner_HTML( $block ) { if ( isset ( $block->innerBlocks ) && count( $block->innerBlocks ) ) { if ( isset( $block->innerContent ) ) { $content = self::render_inner_HTML_with_innerContent( $block ); } else { $content = self::render_inner_HTML_with_guess_parts( $block ); } } else { $content = $block->innerHTML; } return $content; } /** * Since Gutenberg 4.2.0 and WP 5.0.0 we have a new * property WP_Block_Parser_Block::$innerContent which * provides the sequence of inner elements: * strings or null if it's an inner block. * * @see WP_Block_Parser_Block::$innerContent * * @param WP_Block_Parser_Block $block * * @return string */ private static function render_inner_HTML_with_innerContent( $block ) { $content = ''; $inner_block_index = 0; foreach ( $block->innerContent as $inner_content ) { if ( is_string( $inner_content ) ) { $content .= $inner_content; } else { $content .= self::render_block( $block->innerBlocks[ $inner_block_index ] ); $inner_block_index++; } } return $content; } /** * @param WP_Block_Parser_Block $block * * @return string */ private static function render_inner_HTML_with_guess_parts( $block ) { $inner_html_parts = self::guess_inner_HTML_parts( $block ); $content = $inner_html_parts[0]; foreach ( $block->innerBlocks as $inner_block ) { $content .= self::render_block( $inner_block ); } $content .= $inner_html_parts[1]; return $content; } /** * The gutenberg parser prior to version 4.2.0 (Gutenberg) and 5.0.0 (WP) * doesn't handle inner blocks correctly. * It should really return the HTML before and after the blocks * We're just guessing what it is here * The usual innerHTML would be: <div class="xxx"></div> * The columns block also includes new lines: <div class="xxx">\n\n</div> * So we try to split at ></ and also include white space and new lines between the tags * * @param WP_Block_Parser_Block $block * * @return array */ private static function guess_inner_HTML_parts( $block ) { $inner_HTML = $block->innerHTML; $parts = array( $inner_HTML, '' ); switch( $block->blockName ) { case 'core/media-text': $html_to_find = '<div class="wp-block-media-text__content">'; $pos = mb_strpos( $inner_HTML, $html_to_find ) + mb_strlen( $html_to_find ); $parts = array( mb_substr( $inner_HTML, 0, $pos ), mb_substr( $inner_HTML, $pos ) ); break; default: preg_match( '#>\s*</#', $inner_HTML, $matches ); if ( count( $matches ) === 1 ) { $parts = explode( $matches[0], $inner_HTML ); if ( count( $parts ) === 2 ) { $match_mid_point = 1 + ( mb_strlen( $matches[0] ) - 3 ) / 2; // This is the first ">" char plus half the remaining between the tags $parts[0] .= mb_substr( $matches[0], 0, $match_mid_point ); $parts[1] = mb_substr( $matches[0], $match_mid_point ) . $parts[1]; } } break; } return $parts; } /** * @param array $config_data * * @return array */ public function wpml_config_filter( $config_data ) { $this->config_option->update_from_config( $config_data ); return $config_data; } /** * @param bool $translate * @param WP_Post $post * @param string $context * * @return bool */ public function should_body_be_translated_filter( $translate, WP_Post $post, $context = '' ) { if ( 'translate_images_in_post_content' === $context && $this->is_gutenberg_post( $post ) ) { $translate = true; } return $translate; } /** * @param WP_Post $post * * @return bool */ private function is_gutenberg_post( WP_Post $post ) { return (bool) preg_match( '/' . self::GUTENBERG_OPENING_START . '/', $post->post_content ); } public static function parse_blocks( $content ) { global $wp_version; if ( version_compare( $wp_version, '5.0-beta1', '>=' ) ) { return parse_blocks( $content ); } else { // @phpstan-ignore-next-line return gutenberg_parse_blocks( $content ); } } /** * Remove Gutenberg (string package) from translation dashboard filters * * @param array $types * * @return mixed */ public function remove_package_strings_type_filter( $types ) { if ( array_key_exists( 'gutenberg', $types ) ) { unset( $types['gutenberg'] ); } return $types; } } wpml-page-builders/classes/Integrations/Gutenberg/IdsInBlock/Hooks.php 0000755 00000003741 14720415745 0022067 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ConvertIdsInBlock; use WPML\FP\Obj; use WPML\LIB\WP\Hooks as WpHooks; use WPML\PB\Gutenberg\Integration; use function WPML\FP\spreadArgs; class Hooks implements Integration { /** @var \WPML_Gutenberg_Config_Option $config */ private $config; public function __construct( \WPML_Gutenberg_Config_Option $config ) { $this->config = $config; } public function add_hooks() { if ( $this->config->get_ids_in_blocks() ) { WpHooks::onFilter( 'render_block_data', - PHP_INT_MAX ) ->then( spreadArgs( [ $this, 'filterIdsInBlock' ] ) ); } } /** * @param array $block * * @return array */ public function filterIdsInBlock( array $block ) { $blockConfig = $this->getBlockConfig( $block ); if ( $blockConfig ) { return ( new Composite( array_merge( $this->getBlockAttributesConverter( $blockConfig ), $this->getTagAttributesConverter( $blockConfig ) ) ) )->convert( $block ); } return $block; } /** * @param array $block * * @return null|array */ private function getBlockConfig( $block ) { return Obj::prop( Obj::prop( 'blockName', $block ), $this->config->get_ids_in_blocks() ); } /** * @param array $blockConfig * * @return BlockAttributes[] */ private function getBlockAttributesConverter( $blockConfig ) { $keyConfig = wpml_collect( (array) Obj::prop( 'key', $blockConfig ) ) ->map( function( $slug, $path ) { return [ 'path' => $path, 'slug' => $slug, ]; } ) ->toArray(); return $keyConfig ? [ new BlockAttributes( $keyConfig ) ] : []; } /** * @param array $blockConfig * * @return TagAttributes[] */ private function getTagAttributesConverter( $blockConfig ) { $xpathConfig = wpml_collect( (array) Obj::prop( 'xpath', $blockConfig ) ) ->map( function( $slug, $xpath ) { return [ 'xpath' => $xpath, 'slug' => $slug, ]; } ) ->toArray(); return $xpathConfig ? [ new TagAttributes( $xpathConfig ) ] : []; } } wpml-page-builders/classes/Integrations/Gutenberg/IdsInBlock/TagAttributes.php 0000755 00000002443 14720415745 0023564 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ConvertIdsInBlock; use WPML\FP\Fns; use WPML\FP\Obj; use WPML\PB\Gutenberg\StringsInBlock\DOMHandler\StandardBlock; use WPML\PB\Gutenberg\StringsInBlock\HTML; class TagAttributes extends Base { /** @var array $attributesToConvert */ private $attributesToConvert; public function __construct( array $attributesToConvert ) { $this->attributesToConvert = $attributesToConvert; } public function convert( array $block ) { $domHandler = new StandardBlock(); $dom = $domHandler->getDom( $block['innerHTML'] ); $xpath = new \DOMXPath( $dom ); foreach ( $this->attributesToConvert as $attributeConfig ) { $getConfig = Obj::prop( Fns::__, $attributeConfig ); $nodes = $xpath->query( $getConfig( 'xpath' ) ); if ( ! $nodes ) { continue; } foreach ( $nodes as $node ) { /** @var \DOMNode $node */ $ids = self::convertIds( $node->nodeValue, $getConfig( 'slug' ), $getConfig( 'type' ) ); $blockObject = \WPML_Gutenberg_Integration::sanitize_block( $block ); $block = (array) $domHandler->applyStringTranslations( $blockObject, $node, $ids, null ); $domHandler->setElementValue( $node, $ids ); } } list( $block['innerHTML'], ) = $domHandler->getFullInnerHTML( $dom->documentElement ); return $block; } } wpml-page-builders/classes/Integrations/Gutenberg/IdsInBlock/Composite.php 0000755 00000000612 14720415745 0022740 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ConvertIdsInBlock; class Composite extends Base { /** @var Base[] $converters */ private $converters; public function __construct( array $converters ) { $this->converters = $converters; } public function convert( array $block ) { foreach ( $this->converters as $converter ) { $block = $converter->convert( $block ); } return $block; } } wpml-page-builders/classes/Integrations/Gutenberg/IdsInBlock/BlockAttributes.php 0000755 00000004320 14720415745 0024077 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ConvertIdsInBlock; use WPML\FP\Fns; use WPML\FP\Lst; use WPML\FP\Obj; use WPML\FP\Str; use WPML\PB\Gutenberg\StringsInBlock\Attributes; class BlockAttributes extends Base { /** @var array $attributesToConvert */ private $attributesToConvert; public function __construct( array $attributesToConvert ) { $this->attributesToConvert = $attributesToConvert; } public function convert( array $block ) { if ( ! isset( $block['attrs'] ) ) { return $block; } foreach ( $this->attributesToConvert as $attributeConfig ) { $getConfig = Obj::prop( Fns::__, $attributeConfig ); $name = $getConfig( 'name' ); if ( $name ) { $block['attrs'] = self::convertByName( $block['attrs'], $name, $getConfig ); } elseif ( $getConfig( 'path' ) ) { $path = explode( '>', $getConfig( 'path' ) ); $block['attrs'] = self::convertByPath( $block['attrs'], $path, $getConfig ); } } return $block; } /** * @param array $attrs * @param string $name * @param callable $getConfig * * @return array */ private function convertByName( $attrs, $name, $getConfig ) { if ( isset( $attrs[ $name ] ) ) { $attrs[ $name ] = self::convertIds( $attrs[ $name ], $getConfig( 'slug' ), $getConfig( 'type' ) ); } return $attrs; } /** * @param array|string|int $attrs * @param array $path * @param callable $getConfig * * @return mixed */ private function convertByPath( $attrs, $path, $getConfig ) { $currentKey = reset( $path ); $nextPath = Lst::drop( 1, $path ); $hasWildCard = false !== strpos( $currentKey, '*' ); if ( $hasWildCard && is_array( $attrs ) ) { $regex = Attributes::getWildcardRegex( $currentKey ); foreach ( $attrs as $key => $attr ) { if ( Str::match( $regex, $key ) ) { $attrs[ $key ] = self::convertByPath( $attr, $nextPath, $getConfig ); } } } elseif ( $currentKey && isset( $attrs[ $currentKey ] ) ) { $attrs[ $currentKey ] = self::convertByPath( $attrs[ $currentKey ], $nextPath, $getConfig ); } elseif ( ! $nextPath && is_scalar( $attrs ) ) { $attrs = self::convertIds( $attrs, $getConfig( 'slug' ), $getConfig( 'type' ) ); } return $attrs; } } wpml-page-builders/classes/Integrations/Gutenberg/IdsInBlock/Base.php 0000755 00000002436 14720415745 0021656 0 ustar 00 <?php namespace WPML\PB\Gutenberg\ConvertIdsInBlock; use WPML\Convert\Ids; class Base { /** * @param array $block * * @return array */ public function convert( array $block ) { return $block; } /** * @see Ids::convert(), supports string lists with any separator. * * @param array|int|string $ids * @param string $elementSlug e.g. "page", "category", ... * @param string|null $elementType "post" or "taxonomy". * * @return array|int */ public static function convertIds( $ids, $elementSlug, $elementType = null ) { // In this context, it's probably better to always fall back to original. // But for backward compatibility, we'll decide that based on the translation mode // when the $elementType is explicitly passed. $fallbackToOriginal = $elementType ? self::isDisplayedAsTranslated( $elementSlug, $elementType ) : true; return Ids::convert( $ids, $elementSlug, $fallbackToOriginal ); } /** * @param string $slug * @param string $type * * @return bool */ private static function isDisplayedAsTranslated( $slug, $type ) { /** @var \SitePress $sitepress */ global $sitepress; return 'post' === $type ? $sitepress->is_display_as_translated_post_type( $slug ) : $sitepress->is_display_as_translated_taxonomy( $slug ); } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/class-collection.php 0000755 00000004035 14720415745 0025443 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock; class Collection implements StringsInBlock { /** @var StringsInBlock[] $parsers */ private $parsers = []; /** * @param StringsInBlock[] $parsers */ public function __construct( array $parsers ) { $this->parsers = $parsers; } /** * @param \WP_Block_Parser_Block $block * * @return array */ public function find( \WP_Block_Parser_Block $block ) { $strings = []; foreach ( $this->parsers as $parser ) { $strings = array_merge( $strings, $parser->find( $block ) ); } /** * String in block filter. * * When post with Gutenberg blocks is being send for translation * WPML parses blocks to find translatable strings. With this filter * you can register additional strings to be added to Translation * Package and then translated * * @param array $strings already found strings. * @param \WP_Block_Parser_Block $block block being parsed. */ return apply_filters( 'wpml_found_strings_in_block', $strings, $block ); } /** * @param \WP_Block_Parser_Block $block * @param array $string_translations * @param string $lang * * @return \WP_Block_Parser_Block */ public function update( \WP_Block_Parser_Block $block, array $string_translations, $lang ) { $originalInnerHTML = $block->innerHTML; foreach ( $this->parsers as $parser ) { $block = $parser->update( $block, $string_translations, $lang ); } if ( $originalInnerHTML !== $block->innerHTML ) { $block->attrs['translatedWithWPMLTM'] = '1'; } /** * Filter to allow replacing Block attributes when translated post with block is saved. * * @param \WP_Block_Parser_Block $block block being saved. * @param array $string_translations array with string translations for current String Package. * @param string $lang language of translated post/block. */ return apply_filters( 'wpml_update_strings_in_block', $block, $string_translations, $lang ); } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/class-attributes.php 0000755 00000014755 14720415745 0025510 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock; use WPML\FP\Obj; class Attributes extends Base { /** * @param \WP_Block_Parser_Block $block * * @return array */ public function find( \WP_Block_Parser_Block $block ) { $strings = []; $attrs = $this->getAttributes( $block ); if ( $attrs ) { $keys = $this->getKeyConfig( $block ); $strings = $this->findStringsRecursively( $attrs, $keys, $block ); } return $strings; } /** * @param array $attrs * @param array $config_keys * @param \WP_Block_Parser_Block $block * * @return array */ private function findStringsRecursively( array $attrs, array $config_keys, \WP_Block_Parser_Block $block ) { $strings = []; foreach ( $attrs as $attr_key => $attr_value ) { $matching_key = $this->getMatchingConfigKey( $attr_key, $config_keys ); if ( ! $matching_key ) { continue; } if ( $this->hasJsonEncoding( $attr_key, $config_keys ) ) { $attr_value = json_decode( urldecode( $attr_value ), true ); } if ( is_array( $attr_value ) ) { $children_config_keys = $this->getChildrenConfigKeys( $config_keys, $matching_key ); $strings = array_merge( $strings, $this->findStringsRecursively( $attr_value, $children_config_keys, $block ) ); } elseif ( ! is_numeric( $attr_value ) ) { $type = $this->get_attribute_string_type( $attr_value, $attr_key, $config_keys ); $string_id = $this->get_string_id( $block->blockName, $attr_value ); $label = isset( $config_keys[ $attr_key ]['label'] ) ? $config_keys[ $attr_key ]['label'] : $this->get_block_label( $block ); $strings[] = $this->build_string( $string_id, $label, $attr_value, $type ); } } return $strings; } /** * @param string $attr_value * @param string $attr_key * @param array $config_keys * * @return mixed */ private function get_attribute_string_type( $attr_value, $attr_key, $config_keys ) { $config_type = $config_keys[ $attr_key ]['type'] ?? null; if ( 'link' === $config_type ) { return \WPML_TM_Page_Builders::FIELD_STYLE_LINK; } return self::get_string_type( $attr_value ); } /** * @param string $attr_key * @param array $config_keys * * @return string|null */ private function getMatchingConfigKey( $attr_key, array $config_keys ) { if ( isset( $config_keys[ $attr_key ] ) ) { return $attr_key; } /** * If we don't find an exactly matching key, * we'll try to find a key with a wildcard or a regex. */ foreach ( $config_keys as $config_key => $key_attrs ) { if ( preg_match( $this->getRegex( $config_key, $key_attrs ), $attr_key ) ) { return $config_key; } } return null; } /** * @param array $config_keys * @param string $matching_key * * @return array */ private function getChildrenConfigKeys( array $config_keys, $matching_key ) { return isset( $config_keys[ $matching_key ]['children'] ) ? $config_keys[ $matching_key ]['children'] : $this->getMatchAllKey(); } /** * If the config key is not already a regex * we will replace the wildcard (*) and make it a valid regex. * * @param string $config_key * @param array $key_attrs * * @return string */ private function getRegex( $config_key, array $key_attrs ) { if ( $this->isRegex( $key_attrs ) ) { return $config_key; } return self::getWildcardRegex( $config_key ); } /** * @param string $config_key * * @return string */ public static function getWildcardRegex( $config_key ) { return '/^' . str_replace( '*', 'S+', preg_quote( $config_key, '/' ) ) . '$/'; } /** * @param array $key_attrs * * @return bool */ private function isRegex( array $key_attrs ) { return isset( $key_attrs['search-method'] ) && \WPML_Gutenberg_Config_Option::SEARCH_METHOD_REGEX === $key_attrs['search-method']; } /** * @param \WP_Block_Parser_Block $block * @param array $string_translations * @param string $lang * * @return \WP_Block_Parser_Block */ public function update( \WP_Block_Parser_Block $block, array $string_translations, $lang ) { $attrs = $this->getAttributes( $block ); if ( $attrs ) { $keys = $this->getKeyConfig( $block ); $block->attrs = $this->updateStringsRecursively( $attrs, $keys, $string_translations, $lang, $block->blockName ); } return $block; } /** * @param array $attrs * @param array $config_keys * @param array $translations * @param string $lang * @param string $block_name * * @return array */ public function updateStringsRecursively( array $attrs, array $config_keys, array $translations, $lang, $block_name ) { foreach ( $attrs as $attr_key => $attr_value ) { $matching_key = $this->getMatchingConfigKey( $attr_key, $config_keys ); if ( ! $matching_key ) { continue; } if ( $this->hasJsonEncoding( $attr_key, $config_keys ) ) { $attr_value = json_decode( urldecode( $attr_value ), true ); } if ( is_array( $attr_value ) ) { $children_config_keys = $this->getChildrenConfigKeys( $config_keys, $matching_key ); $attrs[ $attr_key ] = $this->updateStringsRecursively( $attr_value, $children_config_keys, $translations, $lang, $block_name ); } else { $string_id = $this->get_string_id( $block_name, $attr_value ); if ( isset( $translations[ $string_id ][ $lang ] ) && ICL_TM_COMPLETE === (int) $translations[ $string_id ][ $lang ]['status'] ) { $attrs[ $attr_key ] = $translations[ $string_id ][ $lang ]['value']; } } if ( $this->hasJsonEncoding( $attr_key, $config_keys ) ) { $attrs[ $attr_key ] = rawurlencode( wp_json_encode( $attrs[ $attr_key ] ) ); } } return $attrs; } /** * @param array $attr_key * @param array $config_keys * * @retrun bool */ private function hasJsonEncoding( $attr_key, $config_keys ) { return 'json' === Obj::path( [ $attr_key, 'encoding' ], $config_keys ); } /** * @param \WP_Block_Parser_Block $block * * @return array */ private function getAttributes( \WP_Block_Parser_Block $block ) { return is_array( $block->attrs ) && $block->blockName ? $block->attrs : []; } /** * @param \WP_Block_Parser_Block $block * * @return array */ private function getKeyConfig( \WP_Block_Parser_Block $block ) { $config = $this->get_block_config( $block, 'key' ); return $config ? $config : []; } /** * @return array */ private function getMatchAllKey() { return [ '*' => [ 'search-method' => \WPML_Gutenberg_Config_Option::SEARCH_METHOD_WILDCARD, ], ]; } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/interface-strings-in-block.php 0000755 00000000750 14720415745 0027330 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock; interface StringsInBlock { /** * @param \WP_Block_Parser_Block $block * * @return array */ public function find( \WP_Block_Parser_Block $block ); /** * @param \WP_Block_Parser_Block $block * @param array $string_translations * @param string $lang * * @return \WP_Block_Parser_Block */ public function update( \WP_Block_Parser_Block $block, array $string_translations, $lang ); } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/class-html.php 0000755 00000016654 14720415745 0024266 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock; use WPML\FP\Str; use WPML\FP\Obj; use WPML\PB\Gutenberg\StringsInBlock\DOMHandler\DOMHandle; use WPML\PB\Gutenberg\StringsInBlock\DOMHandler\HtmlBlock; use WPML\PB\Gutenberg\StringsInBlock\DOMHandler\StandardBlock; use WPML\PB\Gutenberg\StringsInBlock\DOMHandler\ListBlock; use WPML\PB\Gutenberg\StringsInBlock\DOMHandler\ListItemBlock; use WPML\PB\Gutenberg\XPath; class HTML extends Base { const LIST_BLOCK_NAME = 'core/list'; const LIST_ITEM_BLOCK_NAME = 'core/list-item'; const HTML_BLOCK_NAME = 'core/html'; /** * @param \WP_Block_Parser_Block $block * * @return array */ public function find( \WP_Block_Parser_Block $block ) { $strings = array(); $block_queries = $this->get_block_queries( $block ); if ( is_array( $block_queries ) && isset( $block->innerHTML ) ) { $dom_handle = $this->get_dom_handler( $block ); $xpath = $dom_handle->getDomxpath( $block->innerHTML ); foreach ( $block_queries as $blockQuery ) { list( $query, $definedType, $label ) = XPath::parse( $blockQuery ); $elements = $xpath->query( $query ); foreach ( $elements as $element ) { list( $text, $type ) = $dom_handle->getPartialInnerHTML( $element ); if ( $text ) { $string_id = $this->get_string_id( $block->blockName, $text ); $strings[] = $this->build_string( $string_id, $label ?: $this->get_block_label( $block ), $text, $definedType ? $definedType : $type ); } } } } else { $string_id = $this->get_block_string_id( $block ); if ( $string_id ) { $strings[] = $this->build_string( $string_id, $this->get_block_label( $block ), $block->innerHTML, 'VISUAL' ); } } return $strings; } /** * @param \WP_Block_Parser_Block $block * @param array $string_translations * @param string $lang * * @return \WP_Block_Parser_Block */ public function update( \WP_Block_Parser_Block $block, array $string_translations, $lang ) { $block_queries = $this->get_block_queries( $block ); if ( $block_queries && isset( $block->innerHTML ) ) { $dom_handle = $this->get_dom_handler( $block ); $dom = $dom_handle->getDom( $block->innerHTML ); $xpath = new \DOMXPath( $dom ); foreach ( $block_queries as $query ) { list( $query, ) = XPath::parse( $query ); $elements = $xpath->query( $query ); foreach ( $elements as $element ) { list( $text, ) = $dom_handle->getPartialInnerHTML( $element ); $translation = $this->getTranslation( $text, $lang, $block, $string_translations ); $block = $this->updateTranslationInBlock( $text, $this->apply_placeholders_for_html_entities( $translation ), $block, $element, $dom_handle ); } } $content = $dom_handle->getFullInnerHTML( $dom->documentElement ); $block->innerHTML = $this->restore_placeholders_for_html_entities( reset( $content ) ); } elseif ( isset( $block->blockName, $block->innerHTML ) && '' !== trim( $block->innerHTML ) ) { $translation = $this->getTranslation( $block->innerHTML, $lang, $block, $string_translations ); if ( $translation ) { $block->innerHTML = $translation; } } return $block; } /** * @param \WP_Block_Parser_Block $block * * @return null|string */ private function get_block_string_id( \WP_Block_Parser_Block $block ) { if ( isset( $block->blockName, $block->innerHTML ) && '' !== trim( $block->innerHTML ) ) { return $this->get_string_id( $block->blockName, $block->innerHTML ); } else { return null; } } /** * @param \WP_Block_Parser_Block $block * * @return array|null */ private function get_block_queries( \WP_Block_Parser_Block $block ) { return $this->get_block_config( $block, 'xpath' ); } /** * @param \WP_Block_Parser_Block $block * * @return ListBlock|StandardBlock|HtmlBlock */ private function get_dom_handler( \WP_Block_Parser_Block $block ) { $class = wpml_collect( [ self::LIST_BLOCK_NAME => ListBlock::class, self::HTML_BLOCK_NAME => HtmlBlock::class, self::LIST_ITEM_BLOCK_NAME => ListItemBlock::class, ] )->get( $block->blockName, StandardBlock::class ); return new $class(); } /** * @param string $text * @param string $translation * @param \WP_Block_Parser_Block $block * @param \DOMNode $element * @param DOMHandle $dom_handle * * @return \WP_Block_Parser_Block */ private function updateTranslationInBlock( $text, $translation, \WP_Block_Parser_Block $block, $element, $dom_handle ) { if ( $translation ) { $block = $dom_handle->applyStringTranslations( $block, $element, $translation, $text ); $dom_handle->setElementValue( $element, $translation ); } return $block; } private function getTranslation( $text, $lang, \WP_Block_Parser_Block $block, array $string_translations ) { $translationFromPageBuilder = apply_filters( 'wpml_pb_update_translations_in_content', $text, $lang ); if ( $translationFromPageBuilder === $text ) { $string_id = $this->get_string_id( $block->blockName, $text ); if ( (int) Obj::path( [ $string_id, $lang, 'status' ], $string_translations ) === ICL_TM_COMPLETE ) { return self::preserveNewLines( $text, $string_translations[ $string_id ][ $lang ]['value'] ); } else { return null; } } else { return $translationFromPageBuilder; } } private static function preserveNewLines( $original, $translation ) { $endsWith = function ( $find, $s ) { return Str::sub( - Str::len( $find ), $s ) === $find; // @phpstan-ignore-line }; if ( Str::startsWith( "\n", $original ) && ! Str::startsWith( "\n", $translation ) ) { $translation = "\n" . $translation; } if ( $endsWith( "\n", $original ) && ! $endsWith( "\n", $translation ) ) { $translation .= "\n"; } return $translation; } /** * HTML_ENTITY_PLACEHOLDERS * Some translations are applied using \DomHandler, which converts any HTML entity * back to it's character, i.e. ' becomes '. * At some places (like shortcode attributes) it breaks the attribute value, because * the delimter can use the same kind of quotes, i.e. [my attr='Some'value'] => broken. * To avoid this problem the HTML entities are replaced before parsing the content with * \DomDocument::loadHTML() and re-applied afterwards. */ const HTML_ENTITY_PLACEHOLDERS = [ ''' => 'WPML_PLACEHOLDER_APOS', '"' => 'WPML_PLACEHOLDER_QUOT', ]; /** * Replaces HTML entities with WPML entity placeholders in given $content. * See self::HTML_ENTITY_PLACEHOLDERS for affected entities. * * @param string $content * * @return string */ private function apply_placeholders_for_html_entities( $content ) { if ( empty( $content ) ) { return $content; } return str_replace( array_keys( self::HTML_ENTITY_PLACEHOLDERS ), array_values( self::HTML_ENTITY_PLACEHOLDERS ), $content ); } /** * Replaces WPML entity placeholders with HTML entities in given $content. * See self::HTML_ENTITY_PLACEHOLDERS for affected entities. * * @param string $content * * @return string */ private function restore_placeholders_for_html_entities( $content ) { if ( empty( $content ) ) { return $content; } return str_replace( array_values( self::HTML_ENTITY_PLACEHOLDERS ), array_keys( self::HTML_ENTITY_PLACEHOLDERS ), $content ); } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/class-base.php 0000755 00000005535 14720415745 0024230 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock; abstract class Base implements StringsInBlock { const LONG_STRING_LENGTH = 80; /** @var array */ private $block_types; /** @var \WPML_Gutenberg_Config_Option $config_option */ private $config_option; public function __construct( \WPML_Gutenberg_Config_Option $config_option ) { $this->config_option = $config_option; } /** * @param \WP_Block_Parser_Block $block * @param string $type e.g. `xpath` or `key` * * @return array|string|null */ protected function get_block_config( \WP_Block_Parser_Block $block, $type ) { if ( null === $this->block_types ) { $this->block_types = $this->config_option->get(); } if ( isset( $block->blockName, $this->block_types[ $block->blockName ][ $type ] ) ) { return $this->block_types[ $block->blockName ][ $type ]; } $namespace_config = $this->get_namespace_config( $block, $type ); if ( $namespace_config ) { return $namespace_config; } if ( $this->has_empty_config( $block ) ) { return []; } return null; } /** * @param \WP_Block_Parser_Block $block * * @return string */ protected function get_block_label( \WP_Block_Parser_Block $block ) { $label = $this->get_block_config( $block, 'label' ); if ( ! is_string( $label ) ) { $label = $block->blockName; } return $label; } /** * @param \WP_Block_Parser_Block $block * @param string $type * * @return array|null */ public function get_namespace_config( \WP_Block_Parser_Block $block, $type ) { if ( isset( $block->blockName ) ) { $block_name_arr = explode( '/', $block->blockName ); $block_namespace = reset( $block_name_arr ); if ( isset( $this->block_types[ $block_namespace ][ $type ] ) ) { return $this->block_types[ $block_namespace ][ $type ]; } } return null; } /** * @param \WP_Block_Parser_Block $block * * @return bool */ private function has_empty_config( \WP_Block_Parser_Block $block ) { return isset( $block->blockName, $this->block_types[ $block->blockName ] ); } /** * @param string $string * * @return string */ public static function get_string_type( $string ) { $type = 'LINE'; if ( strpos( $string, "\n" ) !== false || mb_strlen( $string ) > self::LONG_STRING_LENGTH ) { $type = 'AREA'; } if ( strpos( $string, '<' ) !== false ) { $type = 'VISUAL'; } return $type; } /** * @param string $id * @param string $name * @param string $text * @param string $type * * @return object */ protected function build_string( $id, $name, $text, $type ) { return (object) array( 'id' => $id, 'name' => $name, 'value' => $text, 'type' => $type, ); } /** * @param string $name * @param string $text * * @return string */ protected function get_string_id( $name, $text ) { return md5( $name . $text ); } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/dom-handler/list-block.php 0000755 00000002525 14720415745 0026444 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock\DOMHandler; class ListBlock extends DOMHandle { /** * @param \DOMNode $element * @param string $context * * @return string */ protected function getInnerHTMLFromChildNodes( \DOMNode $element, $context ) { $innerHTML = ""; $is_partial = self::INNER_HTML_PARTIAL === $context; $children = $element->childNodes; foreach ( $children as $child ) { if ( $is_partial && $this->isListNode( $child ) ) { continue; } $innerHTML .= $this->getAsHTML5( $child ); } if ( $is_partial ) { $innerHTML = trim( $innerHTML ); } return $innerHTML; } /** * @param \DOMNode $clone * @param \DOMNode $element */ protected function appendExtraChildNodes( \DOMNode $clone, \DOMNode $element ) { $child_list = $this->getChildList( $element ); if ( $child_list ) { $clone->appendChild( $child_list ); } } /** * @param \DOMNode $node * * @return \DOMNode|null */ private function getChildList( \DOMNode $node ) { foreach ( $node->childNodes as $child_node ) { if ( $this->isListNode( $child_node ) ) { return $child_node; } } return null; } /** * @param \DOMNode $node * * @return bool */ private function isListNode( \DOMNode $node ) { return isset( $node->tagName ) && in_array( $node->tagName, [ 'ul', 'ol' ], true ); } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/dom-handler/html-block.php 0000755 00000001142 14720415745 0026427 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock\DOMHandler; use function WPML\FP\pipe; class HtmlBlock extends StandardBlock { /** * @param \DOMNode $element * @param string $context * * @return array */ protected function getInnerHTML( \DOMNode $element, $context ) { $innerHTML = $element instanceof \DOMText ? $element->nodeValue : $this->getInnerHTMLFromChildNodes( $element, $context ); $cleanUp = pipe( 'html_entity_decode', [ $this, 'removeCdataFromStyleTag' ], [ $this, 'removeCdataFromScriptTag' ] ); return [ $cleanUp( $innerHTML ), 'AREA' ]; } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/dom-handler/dom-handle.php 0000755 00000013634 14720415745 0026414 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock\DOMHandler; use WPML\PB\Gutenberg\StringsInBlock\Base; use function WPML\FP\pipe; abstract class DOMHandle { const INNER_HTML_PARTIAL = 'partial'; const INNER_HTML_FULL = 'full'; /** * @param string $html * * @return \DOMXPath */ public function getDomxpath( $html ) { $dom = $this->getDom( $html ); return new \DOMXPath( $dom ); } /** * @param string $html * * @return \DOMDocument */ public function getDom( $html ) { $dom = new \DOMDocument(); \libxml_use_internal_errors( true ); $html = mb_encode_numericentity( $html, [ 0x80, 0x1FFFFF, 0, 0x1FFFFF ], 'UTF-8' ); $dom->loadHTML( '<div>' . $html . '</div>' ); \libxml_clear_errors(); // Remove doc type and <html> <body> wrappers. $dom->removeChild( $dom->doctype ); /** * $dom->firstChild->firstChild->firstChild is node that we are intersted in (without body tags). * $dom->firstChild Old node that we are replacing */ $dom->replaceChild( $dom->firstChild->firstChild->firstChild, $dom->firstChild ); return $dom; } /** * This is required when a block has innerBlocks and translatable content at the root. * Unfortunately we cannot use the DOM because we have only HTML extracts which * are not valid taken independently. * * {@internal * innerContent => [ * '<div><p>The title</p>', * null, * '\n\n', * null, * '</div>' * ]} * * @param \WP_Block_Parser_Block $block * @param \DOMNode $element * @param string $translation * @param string|null $originalValue * * @return \WP_Block_Parser_Block */ public function applyStringTranslations( \WP_Block_Parser_Block $block, \DOMNode $element, $translation, $originalValue = null ) { if ( empty( $block->innerContent ) || empty( $element->nodeValue ) ) { return $block; } if ( $element instanceof \DOMAttr ) { $search_value = preg_quote( esc_attr( $element->nodeValue ), '/' ); $search = '/(")(' . $search_value . ')(")/'; $translation = esc_attr( $translation ); } else { $replace_full_html_node_content = $element->childNodes->length > 0 && $originalValue; $search_value = preg_quote( $replace_full_html_node_content ? $originalValue : $element->nodeValue, '/' ); $search_value = str_replace( [ preg_quote( '<br>', '/' ), preg_quote( '<br/>', '/' ) ], '<br\/?>', $search_value ); $search = '/(>)(' . $search_value . ')(<)/'; } foreach ( $block->innerContent as &$inner_content ) { if ( $inner_content ) { $inner_content = preg_replace( $search, '${1}' . $translation . '${3}', $inner_content ); } } return $block; } /** * @param \DOMNode $element * @param string $context * * @return array */ protected function getInnerHTML( \DOMNode $element, $context ) { $innerHTML = $element instanceof \DOMText ? $element->nodeValue : $this->getInnerHTMLFromChildNodes( $element, $context ); $type = Base::get_string_type( $innerHTML ); if ( 'VISUAL' !== $type ) { $innerHTML = html_entity_decode( $innerHTML ); } $removeCdata = pipe( [ $this, 'removeCdataFromStyleTag' ], [ $this, 'removeCdataFromScriptTag' ] ); return [ $removeCdata( $innerHTML ), $type ]; } /** * @param \DOMNode $element * @param string $context * * @return string */ abstract protected function getInnerHTMLFromChildNodes( \DOMNode $element, $context ); /** * @param \DOMNode $element * * @return array */ public function getPartialInnerHTML( \DOMNode $element ) { return $this->getInnerHTML( $element, self::INNER_HTML_PARTIAL ); } /** * @param \DOMNode $element * * @return array */ public function getFullInnerHTML( \DOMNode $element ) { return $this->getInnerHTML( $element, self::INNER_HTML_FULL ); } /** * @param \DOMNode $element * @param string $value */ public function setElementValue( \DOMNode $element, $value ) { if ( $element instanceof \DOMAttr ) { // @phpstan-ignore-next-line $element->parentNode->setAttribute( $element->name, $value ); } elseif ( $element instanceof \DOMText ) { $clone = $this->cloneNodeWithoutChildren( $element ); $clone->nodeValue = $value; $element->parentNode->replaceChild( $clone, $element ); } else { $clone = $this->cloneNodeWithoutChildren( $element ); $fragment = $this->getDom( $value )->firstChild; // Skip the wrapping div. foreach ( $fragment->childNodes as $child ) { $clone->appendChild( $element->ownerDocument->importNode( $child, true ) ); } $this->appendExtraChildNodes( $clone, $element ); $element->parentNode->replaceChild( $clone, $element ); } } /** * @param \DOMNode $clone * @param \DOMNode $element */ abstract protected function appendExtraChildNodes( \DOMNode $clone, \DOMNode $element ); /** * @param \DOMNode $element * * @return \DOMNode */ private function cloneNodeWithoutChildren( \DOMNode $element ) { return $element->cloneNode( false ); } protected function getAsHTML5( \DOMNode $element ) { return str_replace( '--/>', '-->', strtr( $element->ownerDocument->saveXML( $element, LIBXML_NOEMPTYTAG ), [ '></area>' => '/>', '></base>' => '/>', '></br>' => '/>', '></col>' => '/>', '></embed>' => '/>', '></hr>' => '/>', '></img>' => '/>', '></input>' => '/>', '></link>' => '/>', '></meta>' => '/>', '></param>' => '/>', '></source>' => '/>', '></track>' => '/>', '></wbr>' => '/>', ] ) ); } public static function removeCdataFromStyleTag( $innerHTML ) { return preg_replace( '/<style(.*?)><!\\[CDATA\\[(.*?)\\]\\]><\\/style>/s', '<style$1>$2</style>', $innerHTML ); } public static function removeCdataFromScriptTag( $innerHTML ) { return preg_replace( '/<script(.*?)><!\\[CDATA\\[(.*?)\\]\\]><\\/script>/s', '<script$1>$2</script>', $innerHTML ); } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/dom-handler/list-item-block.php 0000755 00000003403 14720415745 0027374 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock\DOMHandler; class ListItemBlock extends StandardBlock { /** * @inheritDoc */ public function applyStringTranslations( \WP_Block_Parser_Block $block, \DOMNode $element, $translation, $originalValue = null) { // For List item elements that contain child nodes, we will just replace the translation from the original text. if ( $element instanceof \DOMElement && $element->childNodes->length > 0 ) { $originalValueVariations = $this->getOriginalVariationsForBrAndImgTags( $originalValue ); $block->innerHTML = str_replace( $originalValueVariations, $translation, $block->innerHTML ); foreach ( $block->innerContent as &$inner_content ) { if ( $inner_content ) { $inner_content = str_replace( $originalValueVariations, $translation, $inner_content ); } } return $block; } return parent::applyStringTranslations( $block, $element, $translation, $originalValue ); } /** * This will provide an array of possible searches to apply the translation. * It will make both versions of self-closing tags (with or without slash). * * @param string $originalValue * * @return array */ private function getOriginalVariationsForBrAndImgTags( $originalValue ) { $extractInsideBrOrImgTagsPattern = '/<(br[^>\/\s]*|img[^>]*[^>\/\s])(?:\s*\/)?\s*>/'; preg_match( $extractInsideBrOrImgTagsPattern, $originalValue, $matches ); if ( $matches ) { return array_unique( array_filter( [ $originalValue, preg_replace( $extractInsideBrOrImgTagsPattern, '<${1}/>', $originalValue ), // With self-closing tags. preg_replace( $extractInsideBrOrImgTagsPattern, '<${1}>', $originalValue ), // With no-self-closing tags. ] ) ); } return [ $originalValue ]; } } wpml-page-builders/classes/Integrations/Gutenberg/strings-in-block/dom-handler/standard-block.php 0000755 00000001126 14720415745 0027265 0 ustar 00 <?php namespace WPML\PB\Gutenberg\StringsInBlock\DOMHandler; class StandardBlock extends DOMHandle { /** * @param \DOMNode $element * @param string $context * * @return string */ protected function getInnerHTMLFromChildNodes( \DOMNode $element, $context ) { $innerHTML = ""; $children = $element->childNodes; foreach ( $children as $child ) { $innerHTML .= $this->getAsHTML5( $child ); } return $innerHTML; } /** * @param \DOMNode $clone * @param \DOMNode $element */ protected function appendExtraChildNodes( \DOMNode $clone, \DOMNode $element ) { } } wpml-page-builders/classes/Integrations/Gutenberg/class-wpml-gutenberg-config-option.php 0000755 00000020212 14720415745 0025626 0 ustar 00 <?php use WPML\FP\Obj; use WPML\PB\ConvertIds\Helper as ConvertIdsHelper; use WPML\PB\Gutenberg\XPath; /** * Class WPML_Gutenberg_Config_Option */ class WPML_Gutenberg_Config_Option { const OPTION = 'wpml-gutenberg-config'; const OPTION_IDS_IN_BLOCKS = 'wpml-gutenberg-config-ids-in-blocks'; const SEARCH_METHOD_WILDCARD = 'wildcards'; const SEARCH_METHOD_REGEX = 'regex'; /** * @param array $config_data */ public function update_from_config( $config_data ) { $blocks = []; $ids_in_blocks = []; if ( isset( $config_data['wpml-config']['gutenberg-blocks']['gutenberg-block'] ) ) { foreach ( $config_data['wpml-config']['gutenberg-blocks']['gutenberg-block'] as $block_config ) { $block_name = self::get_block_name( $block_config ); $blocks[ $block_name ] = []; if ( '1' === $block_config['attr']['translate'] ) { $blocks = $this->add_block_xpaths( $blocks, $block_config ); $blocks = $this->add_block_attribute_keys( $blocks, $block_config ); $blocks = $this->add_block_label( $blocks, $block_config ); if ( ! $blocks[ $block_name ] ) { unset( $blocks[ $block_name ] ); } } $ids_in_blocks = $this->add_ids_in_block_xpath( $ids_in_blocks, $block_config ); $ids_in_blocks = $this->add_ids_in_block_keys( $ids_in_blocks, $block_config ); } } update_option( self::OPTION, $blocks, 'no' ); update_option( self::OPTION_IDS_IN_BLOCKS, $ids_in_blocks, 'yes' ); } /** * @param array $block_config * * @return string|null */ public static function get_block_name( array $block_config ) { return Obj::path( [ 'attr', 'type' ], $block_config ); } /** * @param array $blocks * @param array $block_config * * @return array */ private function add_block_xpaths( array $blocks, array $block_config ) { if ( isset( $block_config['xpath'] ) ) { $block_name = self::get_block_name( $block_config ); $xpaths_config = []; foreach ( $this->normalize_key_data( $block_config['xpath'] ) as $xpaths ) { if ( self::is_string_type( Obj::path( [ 'attr', 'type' ], $xpaths ) ) ) { $xpaths = XPath::normalize( $xpaths ); $xpaths_config = array_merge( $xpaths_config, array_values( $xpaths ) ); } } if ( $xpaths_config ) { $blocks[ $block_name ]['xpath'] = $xpaths_config; } } return $blocks; } /** * @param array $ids_in_blocks * @param array $block_config * * @return array */ private function add_ids_in_block_xpath( array $ids_in_blocks, array $block_config ) { $xpaths = $this->normalize_key_data( (array) Obj::prop( 'xpath', $block_config ) ); foreach ( $xpaths as $xpath ) { $type = Obj::path( [ 'attr', 'type' ], $xpath ); if ( ConvertIdsHelper::isValidType( $type ) ) { $block_name = self::get_block_name( $block_config ); $value = Obj::path( [ 'value' ], $xpath ); $selected_type = ConvertIdsHelper::selectElementType( Obj::path( [ 'attr', 'sub-type' ], $xpath ), $type ); $ids_in_blocks[ $block_name ] = isset( $ids_in_blocks[ $block_name ] ) ? $ids_in_blocks[ $block_name ] : []; $ids_in_blocks[ $block_name ]['xpath'] = isset( $ids_in_blocks[ $block_name ]['xpath'] ) ? $ids_in_blocks[ $block_name ]['xpath'] : []; $ids_in_blocks[ $block_name ]['xpath'] = array_merge( $ids_in_blocks[ $block_name ]['xpath'], [ $value => $selected_type ] ); } } return $ids_in_blocks; } /** * @param array $blocks * @param array $block_config * * @return array */ private function add_block_attribute_keys( array $blocks, array $block_config ) { if ( isset( $block_config['key'] ) ) { $keys = $this->get_keys_recursively( $block_config['key'] ); $keys = $this->cleanup_to_include_key( $keys ); if ( $keys ) { $blocks[ self::get_block_name( $block_config ) ]['key'] = $keys; } } return $blocks; } /** * @param array $ids_in_blocks * @param array $block_config * * @return array */ private function add_ids_in_block_keys( array $ids_in_blocks, array $block_config ) { $keys_config = $this->find_convert_ids_key_recursively( $block_config ); if ( $keys_config ) { $block_name = self::get_block_name( $block_config ); $ids_in_blocks[ $block_name ] = isset( $ids_in_blocks[ $block_name ] ) ? $ids_in_blocks[ $block_name ] : []; $ids_in_blocks[ $block_name ]['key'] = isset( $ids_in_blocks[ $block_name ]['key'] ) ? $ids_in_blocks[ $block_name ]['key'] : []; $ids_in_blocks[ $block_name ]['key'] = array_merge( $ids_in_blocks[ $block_name ]['key'], $keys_config ); } return $ids_in_blocks; } private function find_convert_ids_key_recursively( array $config, array $path = [] ) { $current_keys = $this->normalize_key_data( (array) Obj::prop( 'key', $config ) ); $keys_config = []; if ( $current_keys ) { foreach ( $current_keys as $current_key ) { $current_name = Obj::path( [ 'attr', 'name' ], $current_key ); $current_path = array_merge( $path, [ $current_name ] ); $keys_config = array_merge( $keys_config, $this->find_convert_ids_key_recursively( $current_key, $current_path ) ); } } else { $type = Obj::path( [ 'attr', 'type' ], $config ); if ( ConvertIdsHelper::isValidType( $type ) ) { $path_to_key = implode( '>', $path ); $selected_type = ConvertIdsHelper::selectElementType( Obj::path( [ 'attr', 'sub-type' ], $config ), $type ); $keys_config[ $path_to_key ] = $selected_type; } } return $keys_config; } private function add_block_label( array $blocks, array $block_config ) { if ( isset( $block_config['attr']['label'] ) ) { $blocks[ self::get_block_name( $block_config ) ]['label'] = $block_config['attr']['label']; } return $blocks; } /** * @param array $keys_config * * @return array */ private function get_keys_recursively( array $keys_config ) { $final_config = array(); $keys_config = $this->normalize_key_data( $keys_config ); foreach ( $keys_config as $key_config ) { $partial_config = []; $type = Obj::pathOr( '', [ 'attr', 'type' ], $key_config ); if ( self::is_string_type( $type ) ) { $partial_config['to_include'] = true; if ( $type ) { $partial_config['type'] = $type; } } if ( isset( $key_config['attr']['search-method'] ) ) { $partial_config['search-method'] = $key_config['attr']['search-method']; } if ( isset( $key_config['attr']['label'] ) ) { $partial_config['label'] = $key_config['attr']['label']; } if ( isset( $key_config['attr']['encoding'] ) ) { $partial_config['encoding'] = $key_config['attr']['encoding']; } if ( isset( $key_config['key'] ) ) { $children = $this->get_keys_recursively( $key_config['key'] ); $valid_children = $this->filter_string_keys( $children ); if ( $valid_children ) { $partial_config['children'] = $valid_children; } else { unset( $partial_config['to_include'] ); } } if ( $partial_config ) { $final_config = array_merge( $final_config, [ $key_config['attr']['name'] => $partial_config ] ); } } return $final_config; } /** * @param array $keys * * @return array */ private function filter_string_keys( $keys ) { return wpml_collect( $keys ) ->filter( Obj::prop( 'to_include' ) ) ->toArray(); } /** * @param array $data * * @return array */ private function cleanup_to_include_key( $data ) { foreach ( $data as &$item ) { unset( $item['to_include'] ); if ( isset( $item['children'] ) ) { $item['children'] = $this->cleanup_to_include_key( $item['children'] ); } } return $data; } /** * If a sequence has only one element, we will wrap it * in order to have the same data shape as for multiple elements. * * @param array $data * * @return array */ private function normalize_key_data( array $data ) { return isset( $data['value'] ) ? array( $data ) : $data; } /** * @param string|null $type * * @return bool */ private static function is_string_type( $type ) { return ! ConvertIdsHelper::isValidType( $type ); } public function get() { return get_option( self::OPTION, array() ); } /** * @return array */ public function get_ids_in_blocks() { return get_option( self::OPTION_IDS_IN_BLOCKS, [] ); } } wpml-page-builders/classes/Integrations/Enfold/class-wpml-compatibility-theme-enfold.php 0000755 00000010217 14720415745 0025602 0 ustar 00 <?php use WPML\PB\Gutenberg\StringsInBlock\Base; /** * Class WPML_Compatibility_Theme_Enfold */ class WPML_Compatibility_Theme_Enfold { /** @var TranslationManagement */ private $translation_management; /** * @param TranslationManagement $translation_management */ public function __construct( TranslationManagement $translation_management ) { $this->translation_management = $translation_management; } public function init_hooks() { add_action( 'wp_insert_post', array( $this, 'wp_insert_post_action' ), 10, 2 ); add_filter( 'wpml_pb_before_replace_string_with_translation', array( $this, 'replace_single_quotes' ), 10, 2 ); add_filter( 'wpml_pb_shortcode_content_for_translation', array( $this, 'get_content_from_custom_field' ), 10, 2 ); add_action( 'icl_make_duplicate', array( $this, 'sync_duplicate' ), 10, 4 ); add_filter( 'wpml_pb_is_post_built_with_shortcodes', [ $this, 'isPostBuiltWithShortcodes' ], 10, 2 ); } /** * Enfold's page builder is keeping the content in the custom field "_aviaLayoutBuilderCleanData" (maybe to prevent the content * from being altered by another plugin). The standard post content will be displayed only if the field * "_aviaLayoutBuilder_active" or "_avia_builder_shortcode_tree" does not exist. * * "_aviaLayoutBuilder_active" and "_avia_builder_shortcode_tree" fields should be set to "copy" in wpml-config.xml. * * @param int $post_id * @param WP_Post $post */ public function wp_insert_post_action( $post_id, $post ) { if ( $this->is_using_standard_wp_editor() ) { return; } if ( wp_is_post_revision( $post_id ) ) { return; } $is_original = apply_filters( 'wpml_is_original_content', false, $post_id, 'post_' . $post->post_type ); if ( ! $is_original && $this->is_active( $post_id ) ) { update_post_meta( $post_id, '_aviaLayoutBuilderCleanData', $post->post_content ); } } /** * @param string $content * @param int $post_id * * @return string */ public function get_content_from_custom_field( $content, $post_id ) { if ( $this->is_active( $post_id ) ) { $content = str_replace( "\r\n", "\n", get_post_meta( $post_id, '_aviaLayoutBuilderCleanData', true ) ); } if ( 'VISUAL' !== Base::get_string_type( $content ) ) { $content = html_entity_decode( $content ); } return $content; } /** * @param int $master_post_id * @param string $lang * @param array $post_array * @param int $id */ function sync_duplicate( $master_post_id, $lang, $post_array, $id ) { if ( $this->is_active( $master_post_id ) ) { $data = get_post_meta( $master_post_id, '_aviaLayoutBuilderCleanData', true ); update_post_meta( $id, '_aviaLayoutBuilderCleanData', $data ); } } /** * @param int $post_id * * @return bool */ private function is_active( $post_id ) { $page_builder_active = get_post_meta( $post_id, '_aviaLayoutBuilder_active', true ); $page_builder_shortcode_tree = get_post_meta( $post_id, '_avia_builder_shortcode_tree', true ); return $page_builder_active && $page_builder_shortcode_tree !== ''; } /** * @return bool */ private function is_using_standard_wp_editor() { $doc_translation_method = isset( $this->translation_management->settings['doc_translation_method'] ) ? $this->translation_management->settings['doc_translation_method'] : ICL_TM_TMETHOD_MANUAL; return (string) ICL_TM_TMETHOD_MANUAL === (string) $doc_translation_method; } /** * Enfold/Avia replaces "'" with "’" in enfold/onfig-templatebuilder/avia-template-builder/assets/js/avia-builder.js:1312 * We just follow the same replacement pattern for string translations * * @param null|string $translation * @param bool $is_attribute * * @return null|string */ public function replace_single_quotes( $translation, $is_attribute ) { if ( $translation && $is_attribute ) { $translation = preg_replace( "/'/", '’', $translation ); } return $translation; } /** * @param bool $isBuiltWithShortcodes * @param WP_Post $post * * @return bool */ public function isPostBuiltWithShortcodes( $isBuiltWithShortcodes, \WP_Post $post ) { return $isBuiltWithShortcodes || $this->is_active( $post->ID ); } } wpml-page-builders/classes/Integrations/FusionBuilder/backend/Hooks.php 0000755 00000001066 14720415745 0022323 0 ustar 00 <?php namespace WPML\Compatibility\FusionBuilder\Backend; class Hooks implements \IWPML_Backend_Action, \IWPML_DIC_Action { public function add_hooks() { add_action( 'wp_update_nav_menu_item', [ $this, 'invalidateMegamenuHook' ], 1, 3 ); } public function invalidateMegamenuHook() { if ( wpml_is_ajax() && isset( $_REQUEST['action'] ) && 'icl_msync_confirm' === $_REQUEST['action'] ) { global $mega_menu_framework; remove_action( 'wp_update_nav_menu_item', [ $mega_menu_framework::$classes['menus'], 'save_custom_menu_style_fields' ], 10 ); } } } wpml-page-builders/classes/Integrations/FusionBuilder/FormContent.php 0000755 00000005644 14720415745 0022115 0 ustar 00 <?php namespace WPML\Compatibility\FusionBuilder; use WPML\FP\Maybe; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class FormContent implements \IWPML_Backend_Action, \IWPML_Frontend_Action { const CPT_FORM = 'fusion_form'; /** @var null|array $formOptionsInProcess */ private $formOptionsInProcess; public function add_hooks() { Hooks::onAction( 'init' )->then( [ $this, 'disableAvadaBuiltinShortcodeHooks' ] ); Hooks::onFilter( 'wpml_pb_shortcode_decode' )->then( spreadArgs( [ $this, 'decode' ] ) ); Hooks::onFilter( 'wpml_pb_shortcode_encode' )->then( spreadArgs( [ $this, 'encode' ] ) ); Hooks::onFilter( 'fusion_pre_shortcode_atts' )->then( spreadArgs( [ $this, 'convertForm' ] ) ); } /** * Avada's team tried to add WPML support for forms * but it's not working at all. We'll just make sure * to detach theirs filters. */ public function disableAvadaBuiltinShortcodeHooks() { if ( function_exists( 'fusion_library' ) && property_exists( fusion_library(), 'multilingual' ) ) { // @phpstan-ignore-line remove_filter( 'wpml_pb_shortcode_decode', [ fusion_library()->multilingual, 'wpml_pb_shortcode_decode_forms' ] ); // @phpstan-ignore-line remove_filter( 'wpml_pb_shortcode_encode', [ fusion_library()->multilingual, 'wpml_pb_shortcode_encode_forms' ] ); // @phpstan-ignore-line } } /** * Decodes form shortcodes. * * @param string|array $string * * @return array|string */ public function decode( $string ) { if ( ! $string || is_array( $string ) ) { return $string; } $decoded = json_decode( base64_decode( $string ) ); if ( JSON_ERROR_NONE === json_last_error() && is_array( $decoded ) ) { $this->formOptionsInProcess = $decoded; $parsed_strings = []; foreach ( $decoded as $item ) { $parsed_strings[] = [ 'value' => $item[1], 'translate' => ! ( empty( $item[1] ) || is_numeric( $item[1] ) ), ]; } return $parsed_strings; } return $string; } /** * Encodes form shortcodes. * * @param string|array $string * * @return string */ public function encode( $string ) { if ( is_array( $string ) && is_array( $this->formOptionsInProcess ) ) { $options = $this->formOptionsInProcess; $this->formOptionsInProcess = null; foreach ( $options as $key => $option ) { $options[ $key ][1] = $string[ $key ]; } return base64_encode( json_encode( $options ) ); } return $string; } /** * @param array $atts * * @return array */ public function convertForm( $atts ) { // $convertId :: string|int -> int $convertId = function( $id ) { return apply_filters( 'wpml_object_id', $id, self::CPT_FORM, true ); }; // $convertForm :: array -> array $convertForm = Obj::over( Obj::lensProp( 'form_post_id' ), $convertId ); return Maybe::just( $atts ) ->filter( Obj::prop( 'form_post_id' ) ) ->map( $convertForm ) ->getOrElse( $atts ); } } wpml-page-builders/classes/Integrations/FusionBuilder/frontend/Hooks.php 0000755 00000007344 14720415745 0022560 0 ustar 00 <?php namespace WPML\Compatibility\FusionBuilder\Frontend; use WPML\API\Sanitize; use WPML\Compatibility\FusionBuilder\BaseHooks; use WPML\FP\Obj; class Hooks extends BaseHooks implements \IWPML_Frontend_Action, \IWPML_DIC_Action { /** @var \SitePress */ private $sitepress; /** @var \WPML_Translation_Element_Factory */ private $elementFactory; public function __construct( \SitePress $sitepress, \WPML_Translation_Element_Factory $elementFactory ) { $this->sitepress = $sitepress; $this->elementFactory = $elementFactory; } public function add_hooks() { if ( $this->isFusionBuilderRequest() ) { // Add action at high priority, as Avada cleans all scripts at priority 100. add_action( 'wp_enqueue_scripts', [ $this, 'frontendScripts' ], PHP_INT_MAX ); } add_filter( 'nav_menu_link_attributes', [ $this, 'addMenuLinkCssClass' ], 10, 2 ); add_filter( 'fusion_get_all_meta', [ $this, 'translateOffCanvasConditionId' ] ); } public function frontendScripts() { $post_id = get_the_ID(); if ( ! $post_id ) { return; } $post_element = $this->elementFactory->create( $post_id, 'post' ); $is_original = ! $post_element->get_source_language_code(); if ( $is_original || ! ( class_exists( '\WPML_TM_Post_Edit_TM_Editor_Mode' ) && \WPML_TM_Post_Edit_TM_Editor_Mode::is_using_tm_editor( $this->sitepress, $post_id ) ) ) { return; } $message = sprintf( // translators: 1 and 2 are html <strong></strong> tags. __( '%1$sWarning:%2$s You are trying to add a translation using the Fusion Builder Live editor but your site is configured to use the WPML Translation Editor.', 'sitepress' ), '<strong>', '</strong>' ); $message = '<p>' . $message . '</p>'; $button = '<button>' . __( 'OK', 'sitepress' ) . '</button>'; $warning = '<div class="wpml-fusion-builder-live-edit-warning"><div class="wpml-message">' . $message . $button . '</div></div>'; $this->enqueue_style(); $this->enqueue_script(); $this->localize_script( [ 'warning' => $warning ] ); } private function isFusionBuilderRequest() { /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */ $builder_id = Sanitize::stringProp( 'builder_id', $_GET ); $builder = filter_input( INPUT_GET, 'builder', FILTER_VALIDATE_BOOLEAN ); return $builder && $builder_id; } /** * Adds required CSS class in menu links. This CSS class is used by * WPML_Fix_Links_In_Display_As_Translated_Content::fix_fallback_links() to skip fixing language switcher links. * * Notes: * - This is intended for themes that provide custom menu walkers. * - For this to work, the custom menu walker must call `nav_menu_link_attributes` filter. * * @param array $atts * @param mixed $item * * @return array */ public function addMenuLinkCssClass( $atts, $item ) { if ( 'wpml_ls_menu_item' === $item->type ) { $class = Obj::prop( 'class', $atts ); $atts['class'] = $class ? "$class wpml-ls-link" : 'wpml-ls-link'; } return $atts; } /** * @param array $data * @return array */ public function translateOffCanvasConditionId( $data ) { if ( is_array( $data ) && Obj::prop( 'layout_conditions', $data ) ) { $conditions = json_decode( Obj::prop( 'layout_conditions', $data ), true ); $result = []; foreach ( $conditions as $key => $condition ) { if ( 'specific_' === substr( $key, 0, 9 ) ) { list( $pattern, $id ) = explode( '|', $key, 2 ); $post_type = substr( $pattern, 9 ); $id = $this->sitepress->get_object_id( $id, $post_type, true ); $key = $pattern . '|' . $id; } $result[ $key ] = $condition; } $data = Obj::assoc( 'layout_conditions', wp_json_encode( $result ), $data ); } return $data; } } classes/Integrations/FusionBuilder/wpml-compatibility-plugin-fusion-hooks-factory.php 0000755 00000001631 14720415745 0031001 0 ustar 00 wpml-page-builders <?php class WPML_Compatibility_Plugin_Fusion_Hooks_Factory implements IWPML_Frontend_Action_Loader, IWPML_Backend_Action_Loader { public function create() { global $sitepress; $activeLanguages = $this->get_filtered_active_languages(); $postStatusDisplay = new WPML_Post_Status_Display( $activeLanguages ); unset( $activeLanguages[ $sitepress->get_current_language() ] ); return new WPML_Compatibility_Plugin_Fusion_Global_Element_Hooks( $sitepress, new WPML_Translation_Element_Factory( $sitepress ), new WPML_Custom_Columns( $sitepress ), $activeLanguages, $postStatusDisplay ); } /** * Get list of active languages. * * @return array */ private function get_filtered_active_languages() { global $sitepress; $activeLanguages = $sitepress->get_active_languages(); return apply_filters( 'wpml_active_languages_access', $activeLanguages, [ 'action' => 'edit' ] ); } } wpml-page-builders/classes/Integrations/FusionBuilder/Hooks/Editor.php 0000755 00000001234 14720415745 0022157 0 ustar 00 <?php namespace WPML\Compatibility\FusionBuilder\Hooks; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Editor implements \IWPML_Backend_Action { public function add_hooks() { Hooks::onFilter( 'wpml_pb_is_editing_translation_with_native_editor', 10, 2 ) ->then( spreadArgs( function( $isTranslationWithNativeEditor, $translatedPostId ) { return $isTranslationWithNativeEditor || ( Relation::propEq( 'action', 'fusion_app_save_post_content', $_POST ) && (int) Obj::prop( 'post_id', $_POST ) === $translatedPostId ); } ) ); } } wpml-page-builders/classes/Integrations/FusionBuilder/DynamicContent.php 0000755 00000005175 14720415745 0022575 0 ustar 00 <?php namespace WPML\Compatibility\FusionBuilder; use WPML\Compatibility\BaseDynamicContent; class DynamicContent extends BaseDynamicContent { /** @var array */ protected $positions = [ 'before', 'after', 'fallback' ]; /** * Sets $positions dynamic content to be translatable. * * @param string|array $string The decoded string so far. * @param string $encoding The encoding used. * * @return string|array */ public function decode_dynamic_content( $string, $encoding ) { if ( ! $string || is_array( $string ) ) { return $string; } if ( $this->is_dynamic_content( $string ) ) { $field = $this->decode_field( $string ); $decodedContent = [ 'element-content' => [ 'value' => $string, 'translate' => false, ], ]; foreach ( $this->positions as $position ) { if ( ! empty( $field[ $position ] ) ) { $decodedContent[ $position ] = [ 'value' => $field[ $position ], 'translate' => true, ]; } } return $decodedContent; } return $string; } /** * Rebuilds dynamic content with translated strings. * * @param string|array $string The field array or string. * @param string $encoding The encoding used. * * @return string */ public function encode_dynamic_content( $string, $encoding ) { if ( is_array( $string ) && isset( $string['element-content'] ) ) { $field = $this->decode_field( $string['element-content'] ); foreach ( $this->positions as $position ) { if ( isset( $string[ $position ] ) ) { $field[ $position ] = $string[ $position ]; } } return $this->encode_field( $field ); } return $string; } /** * Check if a certain field contains dynamic content. * * @param string $string The string to check. * * @return bool */ protected function is_dynamic_content( $string ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode return isset( json_decode( base64_decode( $string ), true )['element_content'] ); } /** * Decode a dynamic-content field. * * @param string $string The string to decode. * * @return array */ protected function decode_field( $string ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode return json_decode( base64_decode( $string ), true )['element_content']; } /** * Encode a dynamic-content field. * * @param array $field The field to encode. * * @return string */ protected function encode_field( $field ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode return base64_encode( wp_json_encode( [ 'element_content' => $field ] ) ); } } classes/Integrations/FusionBuilder/wpml-compatibility-plugin-fusion-global-element-hooks.php 0000755 00000014514 14720415745 0032225 0 ustar 00 wpml-page-builders <?php use WPML\API\Sanitize; use WPML\Compatibility\FusionBuilder\BaseHooks; class WPML_Compatibility_Plugin_Fusion_Global_Element_Hooks extends BaseHooks implements \IWPML_Action { const BEFORE_ADD_GLOBAL_ELEMENTS_PRIORITY = 5; const GLOBAL_SHORTCODE_START = '[fusion_global id="'; const ACTION = 'wpml_compatibility_fusion_get_template_translation_icons'; const LAYOUTS_SCREEN_ID = 'avada_page_avada-layouts'; const LAYOUTS_SCREEN_ID_BEFORE_V7 = 'fusion-builder_page_fusion-layouts'; const SECTIONS_SCREEN_ID = 'avada-layout-sections'; const SECTIONS_SCREEN_ID_BEFORE_V7 = 'fusion-builder_page_fusion-layout-sections'; /** @var IWPML_Current_Language */ private $current_language; /** @var WPML_Translation_Element_Factory */ private $element_factory; /** @var WPML_Custom_Columns */ private $custom_columns; /** @var WPML_Post_Status_Display */ private $postStatusDisplay; /** @var array */ private $activeLanguages; public function __construct( IWPML_Current_Language $current_language, WPML_Translation_Element_Factory $element_factory, WPML_Custom_Columns $custom_columns, array $activeLanguages, WPML_Post_Status_Display $postStatusDisplay ) { $this->current_language = $current_language; $this->element_factory = $element_factory; $this->custom_columns = $custom_columns; $this->activeLanguages = $activeLanguages; $this->postStatusDisplay = $postStatusDisplay; } public function add_hooks() { add_filter( 'content_edit_pre', [ $this, 'translate_global_element_ids' ], self::BEFORE_ADD_GLOBAL_ELEMENTS_PRIORITY ); add_filter( 'fusion_get_override', [ $this, 'fusion_get_override_filter' ] ); if ( is_admin() ) { add_filter( 'manage_fusion_element_posts_columns', [ $this, 'add_language_column_header' ] ); add_action( 'manage_fusion_element_custom_column', [ $this, 'add_language_column_content' ], 10, 2 ); add_filter( 'manage_fusion_tb_section_posts_columns', [ $this, 'add_language_column_header' ] ); add_action( 'manage_fusion_tb_section_custom_column', [ $this, 'add_language_column_content' ], 10, 2 ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_action( 'wp_ajax_' . self::ACTION, [ $this, 'get_template_translation_icons' ] ); } add_filter( 'wpml_ls_exclude_in_menu', [ $this, 'wpml_ls_exclude_in_menu_filter' ] ); } /** * @param bool $render * * @return bool */ public function wpml_ls_exclude_in_menu_filter( $render ) { // Nonce is checked by fusion builder plugin. // phpcs:ignore WordPress.Security.NonceVerification.Missing $action = isset( $_POST['action'] ) ? Sanitize::string( wp_unslash( $_POST['action'] ) ) : ''; if ( wp_doing_ajax() && 'fusion_app_partial_refresh' === $action ) { return false; } return $render; } public function translate_global_element_ids( $content ) { $pattern = '/' . preg_quote( self::GLOBAL_SHORTCODE_START, '[' ) . '([\d]+)"\]/'; return preg_replace_callback( $pattern, [ $this, 'replace_global_id' ], $content ); } private function replace_global_id( array $matches ) { $global_id = (int) $matches[1]; $element = $this->element_factory->create( $global_id, 'post' ); $translation = $element->get_translation( $this->current_language->get_current_language() ); if ( $translation ) { $global_id = $translation->get_element_id(); } return self::GLOBAL_SHORTCODE_START . $global_id . '"]'; } /** * Filter overrides. * * @param WP_Post|stdClass|false $override The override. * * @return WP_Post|stdClass|false */ public function fusion_get_override_filter( $override ) { if ( ! $override instanceof \WP_Post ) { return $override; } $id = apply_filters( 'wpml_object_id', $override->ID, $override->post_type, true ); return $id === $override->ID ? $override : get_post( $id ); } /** * @param array $columns * * @return array */ public function add_language_column_header( $columns ) { return $this->custom_columns->add_posts_management_column( $columns ); } public function enqueue_scripts() { $current_screen = get_current_screen(); $current_screen_id = $current_screen ? $current_screen->id : null; if ( ! ( self::isLayoutsScreen( $current_screen_id ) || self::isSectionsScreen( $current_screen_id ) ) ) { return; } $this->enqueue_style(); if ( ! self::isLayoutsScreen( $current_screen_id ) ) { return; } $this->enqueue_script(); $this->localize_script( [ 'url' => admin_url( 'admin-ajax.php' ), 'action' => self::ACTION, 'nonce' => wp_create_nonce( self::ACTION ), ] ); } /** * @param string $column_name * @param array|null $item */ public function add_language_column_content( $column_name, $item = null ) { $id = $item ? $item['id'] : null; $this->custom_columns->add_content_for_posts_management_column( $column_name, $id ); } public function get_template_translation_icons() { check_admin_referer( self::ACTION, 'nonce' ); $ids = isset( $_POST['ids'] ) ? Sanitize::string( wp_unslash( $_POST['ids'] ) ) : ''; $ids = empty( $ids ) ? [] : array_unique( array_map( 'intval', explode( ',', $ids ) ) ); $icons = []; foreach ( $ids as $id ) { $icons[ $id ] = ''; foreach ( $this->activeLanguages as $language_data ) { $icon_html = $this->postStatusDisplay->get_status_html( $id, $language_data['code'] ); $icon_html = str_replace( 'class="js-wpml-translate-link"', 'class="control js-wpml-translate-link"', $icon_html ); $icons[ $id ] .= $icon_html; } if ( ! empty( $icons[ $id ] ) ) { $icons[ $id ] = '<div class="wpml-template-translations">' . $icons[ $id ] . '</div>'; } } $flags_column = $this->custom_columns->get_flags_column(); $flags = ''; if ( ! empty( $icons ) && ! empty( $flags_column ) ) { $flags = '<div class="wpml-template-flags">' . $flags_column . '</div>'; } wp_send_json_success( [ 'icons' => $icons, 'flags' => $flags, ] ); } /** * @param string $screenId * * @return bool */ private static function isLayoutsScreen( $screenId ) { return in_array( $screenId, [ self::LAYOUTS_SCREEN_ID_BEFORE_V7, self::LAYOUTS_SCREEN_ID ], true ); } /** * @param string $screenId * * @return bool */ private static function isSectionsScreen( $screenId ) { return in_array( $screenId, [ self::SECTIONS_SCREEN_ID_BEFORE_V7, self::SECTIONS_SCREEN_ID ], true ); } } wpml-page-builders/classes/Integrations/FusionBuilder/abstracts/BaseHooks.php 0000755 00000002773 14720415745 0023523 0 ustar 00 <?php namespace WPML\Compatibility\FusionBuilder; abstract class BaseHooks { const HANDLE = 'wpml-compatibility-fusion'; const SCRIPT_SRC = '/dist/js/compatibility/fusion_builder/app.js'; const STYLE_SRC = '/res/css/compatibility/fusion_builder.css'; const OBJECT_NAME = 'WPML_COMPATIBILITY_FUSION'; protected function enqueue_style() { self::check_asset( self::STYLE_SRC ); wp_enqueue_style( self::HANDLE, self::get_url( self::STYLE_SRC ), [], ICL_SITEPRESS_VERSION ); } protected function enqueue_script() { self::check_asset( self::SCRIPT_SRC ); wp_enqueue_script( self::HANDLE, self::get_url( self::SCRIPT_SRC ), [], ICL_SITEPRESS_VERSION, true ); } protected function localize_script( $data ) { wp_localize_script( self::HANDLE, self::OBJECT_NAME, $data ); } /** * This class was originally located in WPML Core * and later moved to WPML Page Builders addons. * As we don't have needs to build JS/CSS assets * in the WPML Page Builder addon, and we want to keep * a simple build here, we'll keep the assets in Core * (where it's built). * * @param string $uri * * @throws \Exception */ private static function check_asset( $uri ) { $filepath = WPML_PLUGIN_PATH . $uri; if ( ! file_exists( $filepath ) ) { throw new \Exception( "The asset $filepath is missing in WPML Core" ); } } /** * @param string $uri * * @return string */ private static function get_url( $uri ) { return ICL_PLUGIN_URL . $uri; } } wpml-page-builders/classes/Integrations/Divi/WooShortcodes.php 0000755 00000001524 14720415745 0020573 0 ustar 00 <?php namespace WPML\Compatibility\Divi; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; use WPML\FP\Obj; class WooShortcodes implements \IWPML_Frontend_Action { const WOO_SHORTCODES = [ 'et_pb_wc_description', 'et_pb_wc_title', ]; public function add_hooks() { Hooks::onFilter( 'et_pb_module_shortcode_attributes', 10, 3 ) ->then( spreadArgs( [ $this, 'translateAttributes' ] ) ); } /** * @param array $shortcodeAttrs * @param array $attrs * @param string $slug * * @return array */ public function translateAttributes( $shortcodeAttrs, $attrs, $slug ) { if ( in_array( $slug, self::WOO_SHORTCODES, true ) && (int) Obj::prop( 'product', $shortcodeAttrs ) ) { $shortcodeAttrs['product'] = apply_filters( 'wpml_object_id', $shortcodeAttrs['product'], 'product', true ); } return $shortcodeAttrs; } } wpml-page-builders/classes/Integrations/Divi/dynamic-content.php 0000755 00000005332 14720415745 0021066 0 ustar 00 <?php namespace WPML\Compatibility\Divi; use WPML\Compatibility\BaseDynamicContent; class DynamicContent extends BaseDynamicContent { const ENCODED_CONTENT_START = '@ET-DC@'; const ENCODED_CONTENT_END = '@'; /** @var array */ protected $positions = [ 'before', 'after' ]; /** * Sets $positions dynamic content to be translatable. * * @param string $string The decoded string so far. * @param string $encoding The encoding used. * * @return string|array */ public function decode_dynamic_content( $string, $encoding ) { if ( $this->is_dynamic_content( $string ) ) { $field = $this->decode_field( $string ); $decodedContent = [ 'et-dynamic-content' => [ 'value' => $string, 'translate' => false, ], ]; foreach ( $this->positions as $position ) { if ( ! empty( $field['settings'][ $position ] ) ) { $decodedContent[ $position ] = [ 'value' => $field['settings'][ $position ], 'translate' => true, ]; } } return $decodedContent; } return $string; } /** * Rebuilds dynamic content with translated strings. * * @param string|array $string The field array or string. * @param string $encoding The encoding used. * * @return string */ public function encode_dynamic_content( $string, $encoding ) { if ( is_array( $string ) && isset( $string['et-dynamic-content'] ) ) { $field = $this->decode_field( $string['et-dynamic-content'] ); foreach ( $this->positions as $position ) { if ( isset( $string[ $position ] ) ) { $field['settings'][ $position ] = $string[ $position ]; } } return $this->encode_field( $field ); } return $string; } /** * Decode a dynamic-content field. * * @param string $string The string to decode. * * @return bool */ protected function is_dynamic_content( $string ) { return substr( $string, 0, strlen( self::ENCODED_CONTENT_START ) ) === self::ENCODED_CONTENT_START; } /** * Decode a dynamic-content field. * * @param string $string The string to decode. * * @return array */ protected function decode_field( $string ) { $start = strlen( self::ENCODED_CONTENT_START ); $end = strlen( self::ENCODED_CONTENT_END ); // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode return json_decode( base64_decode( substr( $string, $start, -$end ) ), true ); } /** * Encode a dynamic-content field. * * @param array $field The field to encode. * * @return string */ protected function encode_field( $field ) { // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode return self::ENCODED_CONTENT_START . base64_encode( wp_json_encode( $field ) ) . self::ENCODED_CONTENT_END; } } wpml-page-builders/classes/Integrations/Divi/TinyMCE.php 0000755 00000001327 14720415745 0017242 0 ustar 00 <?php namespace WPML\Compatibility\Divi; use WPML\FP\Obj; class TinyMCE implements \IWPML_Backend_Action { public function add_hooks() { if ( defined( 'WPML_TM_FOLDER' ) ) { add_filter( 'tiny_mce_before_init', [ $this, 'filterEditorAutoTags' ] ); } } /** * @param array $config * * @return array */ public function filterEditorAutoTags( $config ) { if ( did_action( 'admin_init' ) ) { $screen = get_current_screen(); $cteUrl = 'wpml_page_' . constant( 'WPML_TM_FOLDER' ) . '/menu/translations-queue'; if ( Obj::prop( 'id', $screen ) === $cteUrl ) { $config['wpautop'] = false; $config['indent'] = true; $config['tadv_noautop'] = true; } } return $config; } } wpml-page-builders/classes/Integrations/Divi/DoubleQuotes.php 0000755 00000002462 14720415745 0020406 0 ustar 00 <?php namespace WPML\Compatibility\Divi; /** * Divi replaces double quotes with %22 when saving shortcode attributes. * ATE needs valid HTML so we temporarily decode the double quotes. * When we receive the translation we undo the change. * * @package WPML\Compatibility\Divi */ class DoubleQuotes implements \IWPML_Backend_Action, \IWPML_Frontend_Action { public function add_hooks() { add_filter( 'wpml_pb_shortcode_decode', [ $this, 'decode' ], -PHP_INT_MAX, 2 ); add_filter( 'wpml_pb_shortcode_encode', [ $this, 'encode' ], PHP_INT_MAX, 2 ); } /** * @param string $string * @param string $encoding * * @return string */ public function decode( $string, $encoding ) { if ( self::canHaveDoubleQuotes( $string, $encoding ) ) { $string = str_replace( '%22', '"', $string ); } return $string; } /** * @param string $string * @param string $encoding * * @return string */ public function encode( $string, $encoding ) { if ( self::canHaveDoubleQuotes( $string, $encoding ) ) { $string = str_replace( '"', '%22', $string ); } return $string; } /** * @param string $string * @param string $encoding * * @return bool */ private static function canHaveDoubleQuotes( $string, $encoding ) { return is_string( $string ) && 'allow_html_tags' === $encoding; } } wpml-page-builders/classes/Integrations/Divi/Hooks/DomainsBackendEditor.php 0000755 00000003661 14720415745 0023071 0 ustar 00 <?php namespace WPML\Compatibility\Divi\Hooks; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; use WPML\PB\Helper\LanguageNegotiation; class DomainsBackendEditor implements \IWPML_Backend_Action { public function add_hooks() { if ( LanguageNegotiation::isUsingDomains() && self::isPostEditor() && self::getDomainByCurrentPostLanguage() !== $_SERVER['HTTP_HOST'] ) { Hooks::onAction( 'admin_notices' ) ->then( spreadArgs( [ $this, 'displayNotice' ] ) ); } } public function displayNotice() { $url = ( is_ssl() ? 'https://' : 'http://' ) . self::getDomainByCurrentPostLanguage() . $_SERVER['REQUEST_URI']; ?> <div class="notice notice-warning is-dismissible"> <p> <?php echo sprintf( // translators: placeholders are opening and closing <a> tag. esc_html__( "It is not possible to use Divi's backend builder to edit a post in a different language than your domain. Please use Divi's frontend builder to edit this post or %1\$s switch to the correct domain %2\$s to use the backend builder.", 'sitepress' ), sprintf( '<a href="%s">', esc_url( $url ) ), '</a>' ); ?> </p> <button type="button" class="notice-dismiss"> <span class="screen-reader-text">Dismiss this notice.</span> </button> </div> <?php } /** * @return bool */ private static function isPostEditor() { global $pagenow; return 'post.php' === $pagenow && self::getPostId(); } /** * @return int */ private static function getPostId() { /* phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification */ return (int) Obj::prop( 'post', $_GET ); } /** * @return string|null */ private static function getDomainByCurrentPostLanguage() { $postDetails = apply_filters( 'wpml_post_language_details', null, self::getPostId() ); $language = Obj::prop( 'language_code', $postDetails ); return LanguageNegotiation::getDomainByLanguage( $language ); } } wpml-page-builders/classes/Integrations/Divi/Hooks/Editor.php 0000755 00000001206 14720415745 0020277 0 ustar 00 <?php namespace WPML\Compatibility\Divi\Hooks; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Editor implements \IWPML_Backend_Action { public function add_hooks() { Hooks::onFilter( 'wpml_pb_is_editing_translation_with_native_editor', 10, 2 ) ->then( spreadArgs( function( $isTranslationWithNativeEditor, $translatedPostId ) { return $isTranslationWithNativeEditor || ( Relation::propEq( 'action', 'et_fb_ajax_save', $_POST ) && (int) Obj::prop( 'post_id', $_POST ) === $translatedPostId ); } ) ); } } wpml-page-builders/classes/Integrations/Divi/Hooks/GutenbergUpdate.php 0000755 00000001374 14720415745 0022144 0 ustar 00 <?php namespace WPML\Compatibility\Divi\Hooks; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class GutenbergUpdate implements \IWPML_Backend_Action { public function add_hooks() { Hooks::onFilter( 'wpml_pb_is_post_built_with_shortcodes', 10, 2 ) ->then( spreadArgs( [ $this, 'isPostBuiltWithShortcodes' ] ) ); } /** * @param string $builtWithShortcodes * @param \WP_Post $post * * @return bool */ public static function isPostBuiltWithShortcodes( $builtWithShortcodes, $post ) { return self::isDiviPost( $post->ID ) || $builtWithShortcodes; } /** * @param int $postId * * @return bool */ private static function isDiviPost( $postId ) { return 'on' === get_post_meta( $postId, '_et_pb_use_builder', true ); } } wpml-page-builders/classes/Integrations/Divi/class-wpml-compatibility-divi.php 0000755 00000020457 14720415745 0023661 0 ustar 00 <?php class WPML_Compatibility_Divi implements \IWPML_DIC_Action, \IWPML_Backend_Action, \IWPML_Frontend_Action { const REGEX_REMOVE_OPENING_PARAGRAPH = '/(<p>[\n\r]*)([\n\r]{1}\[\/et_)/m'; const REGEX_REMOVE_CLOSING_PARAGRAPH = '/(\[et_.*\][\n\r]{1})([\n\r]*<\/p>)/m'; /** @var SitePress */ private $sitepress; /** * @param SitePress $sitepress */ public function __construct( SitePress $sitepress ) { $this->sitepress = $sitepress; } public function add_hooks() { if ( $this->sitepress->is_setup_complete() ) { add_action( 'init', [ $this, 'load_resources_if_they_are_required' ], 10, 0 ); add_filter( 'et_builder_load_actions', [ $this, 'load_builder_for_ajax_actions' ] ); add_action( 'admin_init', [ $this, 'display_warning_notice' ], 10, 0 ); add_filter( 'wpml_pb_should_handle_content', [ $this, 'should_handle_shortcode_content' ], 10, 2 ); add_filter( 'wpml_pb_shortcode_content_for_translation', [ $this, 'cleanup_global_layout_content' ], 10, 2 ); add_filter( 'icl_job_elements', [ $this, 'remove_old_content_from_translation' ], 10, 2 ); add_filter( 'wpml_words_count_custom_fields_to_count', [ $this, 'remove_old_content_from_words_count' ], 10, 2 ); } } /** * @return bool */ private function is_standard_editor_used() { $tm_settings = $this->sitepress->get_setting( 'translation-management', [] ); return ! isset( $tm_settings['doc_translation_method'] ) || ICL_TM_TMETHOD_MANUAL === $tm_settings['doc_translation_method']; } public function display_warning_notice() { $notices = wpml_get_admin_notices(); if ( $this->is_standard_editor_used() ) { $notices->add_notice( new WPML_Compatibility_Divi_Notice() ); } elseif ( $notices->get_notice( WPML_Compatibility_Divi_Notice::ID, WPML_Compatibility_Divi_Notice::GROUP ) ) { $notices->remove_notice( WPML_Compatibility_Divi_Notice::GROUP, WPML_Compatibility_Divi_Notice::ID ); } } /** * These actions require the custom widget area to be initialized. * * @param array $actions * @return array */ public function load_builder_for_ajax_actions( $actions ) { $actions[] = 'save-widget'; $actions[] = 'widgets-order'; $actions[] = 'wpml-ls-save-settings'; return $actions; } public function load_resources_if_they_are_required() { if ( ! isset( $_GET['page'] ) || ! is_admin() ) { /* phpcs:ignore */ return; } $pages = [ self::get_duplication_action_page() ]; if ( self::is_tm_active() ) { $pages[] = self::get_translation_dashboard_page(); $pages[] = self::get_translation_editor_page(); } if ( self::is_sl_active() ) { $pages[] = self::get_sl_page(); } if ( in_array( $_GET['page'], $pages, true ) ) { /* phpcs:ignore */ $this->register_layouts(); } } private static function get_translation_dashboard_page() { return constant( 'WPML_TM_FOLDER' ) . '/menu/main.php'; } private static function get_translation_editor_page() { return constant( 'WPML_TM_FOLDER' ) . '/menu/translations-queue.php'; } private static function get_duplication_action_page() { return constant( 'WPML_PLUGIN_FOLDER' ) . '/menu/languages.php'; } private static function get_sl_page() { return 'wpml-sticky-links'; } private static function is_tm_active() { return defined( 'WPML_TM_FOLDER' ); } private static function is_sl_active() { return defined( 'WPML_STICKY_LINKS_VERSION' ); } private function register_layouts() { /** * @phpstan-ignore-next-line */ if ( function_exists( 'et_builder_should_load_framework' ) && ! et_builder_should_load_framework() ) { if ( function_exists( 'et_builder_register_layouts' ) ) { /** * @phpstan-ignore-next-line */ et_builder_register_layouts(); } else { $lib_file = ET_BUILDER_DIR . 'feature/Library.php'; if ( ! class_exists( 'ET_Builder_Library' ) && defined( 'ET_BUILDER_DIR' ) && file_exists( $lib_file ) ) { require_once $lib_file; } if ( class_exists( 'ET_Builder_Library' ) ) { ET_Builder_Library::instance(); } } } } /** * The global layout is not properly extracted from the page * because it adds <p> tags either not opened or not closed. * * See the global content below as an example: * * [et_pb_section prev_background_color="#000000" next_background_color="#000000"][et_pb_text] * * </p> * <p>Global text 1 EN5</p> * <p> * * [/et_pb_text][/et_pb_section] * * We also need to remove `prev_background` and `next_background` attributes which are added from the page. * * @param string $content * @param int $post_id */ public function cleanup_global_layout_content( $content, $post_id ) { if ( 'et_pb_layout' === get_post_type( $post_id ) ) { $content = preg_replace( self::REGEX_REMOVE_OPENING_PARAGRAPH, '$2', $content ); $content = preg_replace( self::REGEX_REMOVE_CLOSING_PARAGRAPH, '$1', $content ); $content = preg_replace( '/( prev_background_color="#[0-9a-f]*")/', '', $content ); $content = preg_replace( '/( next_background_color="#[0-9a-f]*")/', '', $content ); } return $content; } public function should_handle_shortcode_content( $handle_content, $shortcode ) { if ( strpos( $shortcode['tag'], 'et_' ) === 0 && strpos( $shortcode['attributes'], 'global_module=' ) !== false ) { // If a translatable attribute has been excluded from sync, we need to handle it. $handle_content = $this->is_excluded_from_sync( $shortcode ); } return $handle_content; } /** * Check if a global module has excluded any translatable text that we need to handle * * @param array $shortcode * { * @type string $tag. * @type string $content. * @type string $attributes. * } * @return bool */ private function is_excluded_from_sync( $shortcode ) { $handle_content = false; preg_match( '/global_module="([0-9]+)"/', $shortcode['attributes'], $matches ); $excluded = json_decode( get_post_meta( $matches[1], '_et_pb_excluded_global_options', true ), true ); if ( is_array( $excluded ) && count( $excluded ) > 0 ) { $attributes = $this->get_translatable_shortcode_attributes( $shortcode['tag'] ); foreach ( $excluded as $field ) { if ( in_array( $field, $attributes, true ) ) { $handle_content = true; break; } } } return $handle_content; } /** * Get a list of translatable attributes for a shortcode tag. * This includes the inner content and any attributes found in XML configuration. * * @param string $tag The shortcode tag. * @return array */ private function get_translatable_shortcode_attributes( $tag ) { $attributes = [ 'et_pb_content_field' ]; $settings = get_option( 'icl_st_settings', [] ); if ( ! isset( $settings['pb_shortcode'] ) ) { return $attributes; } foreach ( $settings['pb_shortcode'] as $setting ) { if ( $tag === $setting['tag']['value'] ) { foreach ( $setting['attributes'] as $attribute ) { if ( empty( $attribute['type'] ) ) { $attributes[] = $attribute['value']; } } break; } } return $attributes; } /** * Remove the `_et_pb_old_content` meta field from translation jobs, except for products. * * @param array $fields Array of fields to translate. * @param object $post_id The ID of the post being translated. * * @return array */ public function remove_old_content_from_translation( $fields, $post_id ) { // Bail out early if its a product. if ( 'product' === get_post_type( $post_id ) ) { return $fields; } // Search for the _et_pb_old_content element and empty it. $field_types = wp_list_pluck( $fields, 'field_type' ); $index = array_search( 'field-_et_pb_old_content-0', $field_types, true ); if ( false !== $index ) { $fields[ $index ]->field_data = ''; $fields[ $index ]->field_data_translated = ''; } return $fields; } /** * Remove the `_et_pb_old_content` meta field from words count, except for products. * * @param array $fields_to_count Array of custom fields to count. * @param object $post_id The ID of the post for which we are counting the words. * * @return array */ public function remove_old_content_from_words_count( $fields_to_count, $post_id ) { if ( 'product' !== get_post_type( $post_id ) ) { $index = array_search( '_et_pb_old_content', $fields_to_count, true ); if ( false !== $index ) { unset( $fields_to_count[ $index ] ); } } return $fields_to_count; } } wpml-page-builders/classes/Integrations/Divi/class-wpml-compatiblity-divi-notice.php 0000755 00000002367 14720415745 0024767 0 ustar 00 <?php class WPML_Compatibility_Divi_Notice extends WPML_Notice { const ID = 'wpml-compatibility-divi-editor-warning'; const GROUP = 'wpml-compatibility-divi'; public function __construct() { parent::__construct( self::ID, $this->get_message(), self::GROUP ); $this->set_dismissible( true ); $this->set_css_class_types( 'warning' ); } /** * @return string */ private function get_message() { $msg = esc_html_x( 'You are using DIVI theme, and you have chosen to use the standard editor for translating content.', 'Use Translation Editor notice 1/3', 'sitepress' ); $msg .= ' ' . esc_html_x( 'Some functionalities may not work properly. We encourage you to switch to use the Translation Editor.', 'Use Translation Editor notice 2/3', 'sitepress' ); $msg .= ' ' . sprintf( /* translators: %s will be replaced with a URL. */ esc_html_x( 'You can find more information here: %s', 'Use Translation Editor notice 2/3', 'sitepress' ), '<a href="https://wpml.org/errata/some-internal-taxonomies-will-be-missing-when-you-translate-divi-layouts/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore">Some internal taxonomies will be missing when you translate Divi layouts</a>' ); return $msg; } } wpml-page-builders/classes/Integrations/Divi/search.php 0000755 00000000462 14720415745 0017236 0 ustar 00 <?php namespace WPML\Compatibility\Divi; class Search implements \IWPML_Frontend_Action { public function add_hooks() { add_action( 'et_search_form_fields', [ $this, 'add_language_form_field' ] ); } public function add_language_form_field() { do_action( 'wpml_add_language_form_field' ); } } wpml-page-builders/classes/Integrations/Divi/theme-builder.php 0000755 00000006463 14720415745 0020526 0 ustar 00 <?php namespace WPML\Compatibility\Divi; use SitePress; class ThemeBuilder implements \IWPML_Action { /** @var SitePress */ private $sitepress; /** * @param SitePress $sitepress */ public function __construct( SitePress $sitepress ) { $this->sitepress = $sitepress; } /** * Add filters and actions. */ public function add_hooks() { if ( ! defined( 'ET_THEME_BUILDER_DIR' ) ) { return; } if ( $this->sitepress->is_setup_complete() ) { if ( is_admin() ) { add_action( 'init', [ $this, 'make_layouts_editable' ], 1000 ); // Before WPML_Sticky_Links::init. add_filter( 'wpml_document_view_item_link', [ $this, 'document_view_layout_link' ], 10, 5 ); } else { add_filter( 'get_post_metadata', [ $this, 'translate_layout_ids' ], 10, 4 ); } } } /** * Gets all post types that are layouts. */ private static function get_types() { return [ ET_THEME_BUILDER_HEADER_LAYOUT_POST_TYPE, ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE, ET_THEME_BUILDER_FOOTER_LAYOUT_POST_TYPE, ]; } /** * Access the global post types array to tweak the settings for layouts */ public function make_layouts_editable() { global $wp_post_types; foreach ( $this->get_types() as $type ) { $wp_post_types[ $type ]->show_ui = true; $wp_post_types[ $type ]->show_in_menu = false; $wp_post_types[ $type ]->_edit_link = 'post.php?post=%d'; } } /** * Translate theme builder layout ids in the frontend. * * @param string $value The layout id. * @param int $post_id The post it belongs to. * @param string $key The meta key we are handling. * @param bool $single Fetch a single row or an array. * @return string */ public function translate_layout_ids( $value, $post_id, $key, $single ) { if ( in_array( $key, [ '_et_header_layout_id', '_et_body_layout_id', '_et_footer_layout_id' ], true ) ) { /** * The `get_post_metadata` filter provides `null` as the initial `$value`. * When we return a different $value it is used directly, to avoid a second query. * This means that we have to get the original value first, removing ourselves so * we don't fall into an infinite loop. */ remove_filter( 'get_post_metadata', [ $this, 'translate_layout_ids' ], 10 ); $original_id = get_post_meta( $post_id, $key, true ); add_filter( 'get_post_metadata', [ $this, 'translate_layout_ids' ], 10, 4 ); $type = substr( $key, 1, -3 ); $value = $this->sitepress->get_object_id( $original_id, $type, true ); if ( ! $single ) { $value = [ $value ]; } } return $value; } /** * Remove the 'View' link because you can't view layouts alone. * * @param string $link The complete link. * @param string $text The text to link. * @param object $job The corresponding translation job. * @param string $prefix The prefix of the element type. * @param string $type The element type. * * @return string */ public function document_view_layout_link( $link, $text, $job, $prefix, $type ) { if ( 'post' === $prefix && $this->is_theme_layout( $type ) ) { $link = ''; } return $link; } /** * Check if a certain Type is a theme builder layout. * * @param string $type The type to check. * * @return bool */ private function is_theme_layout( $type ) { return in_array( $type, $this->get_types(), true ); } } wpml-page-builders/classes/Integrations/Divi/divi-options-encoding.php 0000755 00000003155 14720415745 0022203 0 ustar 00 <?php namespace WPML\Compatibility\Divi; class DiviOptionsEncoding implements \IWPML_Backend_Action, \IWPML_Frontend_Action { const CHARS_ENCODED = [ '%22', '%91', '%93' ]; const CHARS_DECODED = [ '"', '[', ']' ]; const DELIMITER = '_'; const TRANSLATABLE_KEYS = [ 'value', 'link_url', 'link_text' ]; public function add_hooks() { add_filter( 'wpml_pb_shortcode_decode', [ $this, 'decode_divi_options' ], 10, 2 ); add_filter( 'wpml_pb_shortcode_encode', [ $this, 'encode_divi_options' ], 10, 2 ); } public function decode_divi_options( $string, $encoding ) { if ( 'divi_options' === $encoding ) { $options = str_replace( self::CHARS_ENCODED, self::CHARS_DECODED, $string ); $options = json_decode( $options, true ); $string = []; foreach ( $options as $index => $option ) { foreach ( $option as $key => $value ) { $string[ $key . self::DELIMITER . $index ] = [ 'value' => $value, 'translate' => in_array( $key, self::TRANSLATABLE_KEYS, true ), ]; } } } return $string; } public function encode_divi_options( $string, $encoding ) { if ( 'divi_options' === $encoding ) { $output = []; foreach ( $string as $combined_key => $value ) { $parts = explode( self::DELIMITER, $combined_key ); $index = array_pop( $parts ); $key = implode( self::DELIMITER, $parts ); $output[ $index ][ $key ] = $value; } $output = wp_json_encode( $output, JSON_UNESCAPED_UNICODE ); $string = str_replace( self::CHARS_DECODED, self::CHARS_ENCODED, $output ); } return $string; } } wpml-page-builders/classes/Integrations/Divi/DisplayConditions.php 0000755 00000002416 14720415745 0021431 0 ustar 00 <?php namespace WPML\Compatibility\Divi; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; use WPML\FP\Obj; class DisplayConditions implements \IWPML_Frontend_Action { const BASE64_EMPTY_ARRAY = 'W10='; public function add_hooks() { Hooks::onFilter( 'et_pb_module_shortcode_attributes' ) ->then( spreadArgs( [ $this, 'translateAttributes' ] ) ); } /** * @param array $atts * @return array */ public function translateAttributes( $atts ) { $displayConditions = Obj::prop( 'display_conditions', $atts ); if ( $displayConditions && self::BASE64_EMPTY_ARRAY !== $displayConditions ) { /* phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode */ $conditions = json_decode( base64_decode( $atts['display_conditions'] ), true ); foreach ( $conditions as &$condition ) { if ( 'categoryPage' === $condition['condition'] ) { foreach ( $condition['conditionSettings']['categories'] as &$category ) { $category['value'] = (string) apply_filters( 'wpml_object_id', $category['value'], $category['groupSlug'] ); } } } /* phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode */ $atts['display_conditions'] = base64_encode( wp_json_encode( $conditions ) ); } return $atts; } } wpml-page-builders/classes/Integrations/Divi/theme-builder-factory.php 0000755 00000000510 14720415745 0022156 0 ustar 00 <?php namespace WPML\Compatibility\Divi; class ThemeBuilderFactory implements \IWPML_Deferred_Action_Loader, \IWPML_Backend_Action_Loader, \IWPML_Frontend_Action_Loader { public function get_load_action() { return 'init'; } public function create() { global $sitepress; return new ThemeBuilder( $sitepress ); } } wpml-page-builders/classes/Integrations/Divi/builder.php 0000755 00000001026 14720415745 0017414 0 ustar 00 <?php namespace WPML\Compatibility\Divi; class Builder implements \IWPML_Frontend_Action, \IWPML_Backend_Action, \IWPML_AJAX_Action { public function add_hooks() { add_filter( 'theme_locale', [ $this, 'switch_to_user_language' ] ); } public function switch_to_user_language( $locale ) { if ( isset( $_POST['action'] ) && ( 'et_fb_update_builder_assets' === $_POST['action'] ) ) { // phpcs:ignore WordPress.CSRF.NonceVerification $locale = get_user_locale(); switch_to_locale( $locale ); } return $locale; } } classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-update-translation.php 0000755 00000002007 14720415745 0030313 0 ustar 00 wpml-page-builders <?php /** * Class WPML_Beaver_Builder_Update_Translation */ class WPML_Beaver_Builder_Update_Translation extends WPML_Page_Builders_Update_Translation { /** @param array $data_array */ public function update_strings_in_modules( array &$data_array ) { foreach ( $data_array as &$data ) { if ( is_array( $data ) ) { $this->update_strings_in_modules( $data ); } elseif ( is_object( $data ) ) { if ( isset( $data->type, $data->node, $data->settings ) && 'module' === $data->type ) { $data->settings = $this->update_strings_in_node( $data->node, $data->settings ); } } } } /** * @param string $node_id * @param array $settings * * @return mixed */ public function update_strings_in_node( $node_id, $settings ) { $strings = $this->translatable_nodes->get( $node_id, $settings ); foreach ( $strings as $string ) { $translation = $this->get_translation( $string ); $settings = $this->translatable_nodes->update( $node_id, $settings, $translation ); } return $settings; } } wpml-page-builders/classes/Integrations/BeaverBuilder/TranslationJob/Hooks.php 0000755 00000004132 14720415745 0023623 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\TranslationJob; use WPML_Beaver_Builder_Data_Settings; class Hooks implements \IWPML_Backend_Action, \IWPML_Frontend_Action, \IWPML_DIC_Action { /** @var WPML_Beaver_Builder_Data_Settings $dataSettings */ private $dataSettings; public function __construct( WPML_Beaver_Builder_Data_Settings $dataSettings ) { $this->dataSettings = $dataSettings; } public function add_hooks() { add_filter( 'wpml_tm_translation_job_data', [ $this, 'filterFieldsByPageBuilderKind' ], PHP_INT_MAX, 2 ); } /** * @param array $translationPackage * @param \stdClass|\WP_Post $post * * @return array */ public function filterFieldsByPageBuilderKind( array $translationPackage, $post ) { if ( ! $this->isPostPackage( $translationPackage, $post ) ) { return $translationPackage; } if ( $this->dataSettings->is_handling_post( $post->ID ) ) { return $this->removeFieldsFromKind( $translationPackage, $post->ID, 'gutenberg' ); } /** * */ return $this->removeFieldsFromKind( $translationPackage, $post->ID, 'beaver-builder' ); } /** * @param array $translationPackage * @param \stdClass|\WP_Post $post * * @return bool */ private function isPostPackage( array $translationPackage, $post ) { return 'external' !== $translationPackage['type'] && isset( $post->ID ); } /** * @param array $translationPackage * @param int $postId * @param string $kindSlug * * @return array */ private function removeFieldsFromKind( array $translationPackage, $postId, $kindSlug ) { $packageIdToRemove = wpml_collect( apply_filters( 'wpml_st_get_post_string_packages', [], $postId ) ) ->pluck( 'ID', 'kind_slug' ) ->get( $kindSlug ); if ( $packageIdToRemove ) { $isFieldFromPackageToRemove = function( $value, $key ) use ( $packageIdToRemove ) { return preg_match( '/^package-string-' . $packageIdToRemove . '-/', $key ); }; $translationPackage['contents'] = wpml_collect( $translationPackage['contents'] ) ->reject( $isFieldFromPackageToRemove ) ->toArray(); } return $translationPackage; } } wpml-page-builders/classes/Integrations/BeaverBuilder/BeaverThemer/LocationHooks.php 0000755 00000005070 14720415745 0024736 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\BeaverThemer; use WPML\Convert\Ids; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class LocationHooks implements \IWPML_Backend_Action { const LAYOUT_CPT = 'fl-theme-layout'; const LOCATIONS_RULES_KEY = '_fl_theme_builder_locations'; const EXCLUSIONS_RULES_KEY = '_fl_theme_builder_exclusions'; public function add_hooks() { Hooks::onFilter( 'wpml_pb_copy_meta_field', 10, 4 ) ->then( spreadArgs( [ $this, 'translateLocationRulesMeta' ] ) ); } /** * @param mixed $copiedValue * @param int $translatedPostId * @param int $originalPostId * @param string $metaKey * * @return mixed */ public function translateLocationRulesMeta( $copiedValue, $translatedPostId, $originalPostId, $metaKey ) { if ( in_array( $metaKey, [ self::LOCATIONS_RULES_KEY, self::EXCLUSIONS_RULES_KEY ], true ) ) { $targetLang = self::getLayoutLanguage( $translatedPostId ); foreach ( $copiedValue as &$rule ) { $rule = $this->translateRule( $rule, $targetLang ); } } return $copiedValue; } /** * Translate IDs in locations rules. * * Location rules are an array of rules. Each rule is separated by (:). * General rules can be like: * 'general:site' * 'general:archive' * 'general:single' * 'general:404' * 'post:post' * 'post:page' * * This translates the cases for posts and taxonomies. Their rules can be like: * 'post:page:12' * 'post:post:taxonomy:category:45' * * @param string $rule * @param string $targetLangCode * * @return string */ private function translateRule( $rule, $targetLangCode ) { $parts = explode( ':', $rule ); if ( 3 === count( $parts ) ) { $rule = implode( ':', [ $parts[0], $parts[1], self::translateElement( $parts[2], $parts[1], $targetLangCode ) ] ); } elseif ( 5 === count( $parts ) ) { $rule = implode( ':', [ $parts[0], $parts[1], $parts[2], $parts[3], self::translateElement( $parts[4], $parts[3], $targetLangCode ) ] ); } return $rule; } /** * @param int $translatedPostId * * @return string|null */ private static function getLayoutLanguage( $translatedPostId ) { return apply_filters( 'wpml_element_language_code', null, [ 'element_id' => $translatedPostId, 'element_type' => self::LAYOUT_CPT, ] ); } /** * @param string $elementId * @param string $elementType * @param string $targetLangCode * * @return string */ private static function translateElement( $elementId, $elementType, $targetLangCode ) { return Ids::convert( $elementId, $elementType, true, $targetLangCode ); } } wpml-page-builders/classes/Integrations/BeaverBuilder/BeaverThemer/HooksFactory.php 0000755 00000000604 14720415745 0024573 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\BeaverThemer; class HooksFactory implements \IWPML_Backend_Action_Loader, \IWPML_Frontend_Action_Loader { public function create() { if ( self::isActive() ) { return [ new LocationHooks(), ]; } return null; } /** * @return bool */ public static function isActive() { return defined( 'FL_THEME_BUILDER_VERSION' ); } } classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-handle-custom-fields-factory.php 0000755 00000000431 14720415745 0032150 0 ustar 00 wpml-page-builders <?php class WPML_PB_Beaver_Builder_Handle_Custom_Fields_Factory implements IWPML_Backend_Action_Loader, IWPML_AJAX_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { return new WPML_PB_Handle_Custom_Fields( new WPML_Beaver_Builder_Data_Settings() ); } } classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-translatable-nodes.php 0000755 00000034725 14720415745 0030273 0 ustar 00 wpml-page-builders <?php /** * WPML_Beaver_Builder_Translatable_Nodes class file. * * @package wpml-page-builders-beaver-builder */ use WPML\PB\BeaverBuilder\Modules\ModuleWithItemsFromConfig; /** * Class WPML_Beaver_Builder_Translatable_Nodes */ class WPML_Beaver_Builder_Translatable_Nodes implements IWPML_Page_Builders_Translatable_Nodes { /** * Nodes to translate. * * @var array */ private $nodes_to_translate; /** * Get translatable node. * * @param string|int $node_id Node id. * @param stdClass $settings Node settings. * * @return WPML_PB_String[] */ public function get( $node_id, $settings ) { if ( ! $this->nodes_to_translate ) { $this->initialize_nodes_to_translate(); } $strings = array(); foreach ( $this->nodes_to_translate as $node_type => $node_data ) { if ( $this->conditions_ok( $node_data, $settings ) ) { foreach ( $node_data['fields'] as $field ) { $field_key = $field['field']; if ( isset( $settings->$field_key ) && trim( $settings->$field_key ) ) { $string = new WPML_PB_String( $settings->$field_key, $this->get_string_name( $node_id, $field, $settings ), $field['type'], $field['editor_type'], $this->get_wrap_tag( $settings ) ); $strings[] = $string; } } foreach ( $this->get_integration_instances( $node_data ) as $node ) { try { $strings = $node->get( $node_id, $settings, $strings ); // phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } catch ( Exception $e ) {} // phpcs:enable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } } } return $strings; } /** * Update translatable node. * * @param string $node_id Node id. * @param stdClass $settings Node settings. * @param WPML_PB_String $string String object. * * @return stdClass */ public function update( $node_id, $settings, WPML_PB_String $string ) { if ( ! $this->nodes_to_translate ) { $this->initialize_nodes_to_translate(); } foreach ( $this->nodes_to_translate as $node_type => $node_data ) { if ( $this->conditions_ok( $node_data, $settings ) ) { foreach ( $node_data['fields'] as $field ) { $field_key = $field['field']; if ( $this->get_string_name( $node_id, $field, $settings ) === $string->get_name() ) { $settings->$field_key = $string->get_value(); } } foreach ( $this->get_integration_instances( $node_data ) as $node ) { try { $node->update( $node_id, $settings, $string ); // phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } catch ( Exception $e ) {} // phpcs:enable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } } } return $settings; } /** * @param array $node_data * * @return WPML_Beaver_Builder_Module_With_Items[] */ private function get_integration_instances( array $node_data ) { $instances = []; if ( isset( $node_data['integration-class'] ) ) { try { $instances[] = new $node_data['integration-class'](); // phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } catch ( Exception $e ) {} // phpcs:enable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } if ( isset( $node_data['fields_in_item'] ) ) { foreach ( $node_data['fields_in_item'] as $item_of => $config ) { $instances[] = new ModuleWithItemsFromConfig( $item_of, $config ); } } return array_filter( $instances ); } /** * Get string name. * * @param string $node_id Node id. * @param array $field Page builder field. * @param stdClass $settings Node settings. * * @return string */ public function get_string_name( $node_id, $field, $settings ) { return $field['field'] . '-' . $settings->type . '-' . $node_id; } /** * Get wrap tag for string. * Used for SEO, can contain (h1...h6, etc.) * * @param stdClass $settings Field settings. * * @return string */ private function get_wrap_tag( $settings ) { if ( isset( $settings->type ) && 'heading' === $settings->type && isset( $settings->tag ) ) { return $settings->tag; } return ''; } /** * Check if node condition is ok. * * @param array $node_data Node data. * @param stdClass $settings Node settings. * * @return bool */ private function conditions_ok( $node_data, $settings ) { $conditions_meet = true; foreach ( $node_data['conditions'] as $field_key => $field_value ) { if ( ! isset( $settings->$field_key ) || $settings->$field_key !== $field_value ) { $conditions_meet = false; break; } } return $conditions_meet; } /** * @return array */ public static function get_nodes_to_translate() { return array( 'button' => array( 'conditions' => array( 'type' => 'button' ), 'fields' => array( array( 'field' => 'text', 'type' => __( 'Button: Text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'link', 'type' => __( 'Button: Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'heading' => array( 'conditions' => array( 'type' => 'heading' ), 'fields' => array( array( 'field' => 'heading', 'type' => __( 'Heading', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'link', 'type' => __( 'Heading: Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'html' => array( 'conditions' => array( 'type' => 'html' ), 'fields' => array( array( 'field' => 'html', 'type' => __( 'HTML', 'sitepress' ), 'editor_type' => 'VISUAL', ), ), ), 'photo' => array( 'conditions' => array( 'type' => 'photo' ), 'fields' => array( array( 'field' => 'link_url', 'type' => __( 'Photo: Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'rich-text' => array( 'conditions' => array( 'type' => 'rich-text' ), 'fields' => array( array( 'field' => 'text', 'type' => __( 'Text Editor', 'sitepress' ), 'editor_type' => 'VISUAL', ), ), ), 'accordion' => array( 'conditions' => array( 'type' => 'accordion' ), 'fields' => array(), 'integration-class' => 'WPML_Beaver_Builder_Accordion', ), 'pricing-table' => array( 'conditions' => array( 'type' => 'pricing-table' ), 'fields' => array(), 'integration-class' => 'WPML_Beaver_Builder_Pricing_Table', ), 'tabs' => array( 'conditions' => array( 'type' => 'tabs' ), 'fields' => array(), 'integration-class' => 'WPML_Beaver_Builder_Tab', ), 'callout' => array( 'conditions' => array( 'type' => 'callout' ), 'fields' => array( array( 'field' => 'title', 'type' => __( 'Callout: Heading', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'text', 'type' => __( 'Callout: Text', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'cta_text', 'type' => __( 'Callout: Call to action text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'link', 'type' => __( 'Callout: Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'contact-form' => array( 'conditions' => array( 'type' => 'contact-form' ), 'fields' => array( array( 'field' => 'name_placeholder', 'type' => __( 'Contact Form: Name Field Placeholder', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'subject_placeholder', 'type' => __( 'Contact Form: Subject Field Placeholder', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'email_placeholder', 'type' => __( 'Contact Form: Email Field Placeholder', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'phone_placeholder', 'type' => __( 'Contact Form: Phone Field Placeholder', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'message_placeholder', 'type' => __( 'Contact Form: Your Message Placeholder', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'terms_checkbox_text', 'type' => __( 'Contact Form: Checkbox Text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'terms_text', 'type' => __( 'Contact Form: Terms and Conditions', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'success_message', 'type' => __( 'Contact Form: Success Message', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'btn_text', 'type' => __( 'Contact Form: Button Text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'success_url', 'type' => __( 'Contact Form: Redirect Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'call-to-action' => array( 'conditions' => array( 'type' => 'cta' ), 'fields' => array( array( 'field' => 'title', 'type' => __( 'Call to Action: Heading', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'text', 'type' => __( 'Call to Action: Text', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'btn_text', 'type' => __( 'Call to Action: Button text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'btn_link', 'type' => __( 'Call to Action: Button link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'subscribe-form' => array( 'conditions' => array( 'type' => 'subscribe-form' ), 'fields' => array( array( 'field' => 'terms_checkbox_text', 'type' => __( 'Subscribe form: Checkbox Text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'terms_text', 'type' => __( 'Subscribe form: Terms and Conditions', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'custom_subject', 'type' => __( 'Subscribe form: Notification Subject', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'success_message', 'type' => __( 'Subscribe form: Success Message', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'btn_text', 'type' => __( 'Subscribe form: Button Text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'success_url', 'type' => __( 'Subscribe form: Redirect Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'content-slider' => array( 'conditions' => array( 'type' => 'content-slider' ), 'fields' => array(), 'integration-class' => 'WPML_Beaver_Builder_Content_Slider', ), 'icon' => array( 'conditions' => array( 'type' => 'icon' ), 'fields' => array( array( 'field' => 'text', 'type' => __( 'Icon: Text', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'link', 'type' => __( 'Icon: Link', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'icon-group' => array( 'conditions' => array( 'type' => 'icon-group' ), 'fields' => array(), 'integration-class' => 'WPML_Beaver_Builder_Icon_Group', ), 'map' => array( 'conditions' => array( 'type' => 'map' ), 'fields' => array( array( 'field' => 'address', 'type' => __( 'Map: Address', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), 'testimonials' => array( 'conditions' => array( 'type' => 'testimonials' ), 'fields' => array( array( 'field' => 'heading', 'type' => __( 'Testimonial: Heading', 'sitepress' ), 'editor_type' => 'LINE', ), ), 'integration-class' => 'WPML_Beaver_Builder_Testimonials', ), 'numbers' => array( 'conditions' => array( 'type' => 'numbers' ), 'fields' => array( array( 'field' => 'before_number_text', 'type' => __( 'Number Counter: Text before number', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'after_number_text', 'type' => __( 'Number Counter: Text after number', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'number_prefix', 'type' => __( 'Number Counter: Number Prefix', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'number_suffix', 'type' => __( 'Number Counter: Number Suffix', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), 'post-grid' => array( 'conditions' => array( 'type' => 'post-grid' ), 'fields' => array( array( 'field' => 'no_results_message', 'type' => __( 'Posts: No Results Message', 'sitepress' ), 'editor_type' => 'VISUAL', ), array( 'field' => 'more_btn_text', 'type' => __( 'Posts: Button Text', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'terms_list_label', 'type' => __( 'Posts: Terms Label', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'more_link_text', 'type' => __( 'Posts: More Link Text', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), 'post-slider' => array( 'conditions' => array( 'type' => 'post-slider' ), 'fields' => array( array( 'field' => 'more_link_text', 'type' => __( 'Posts Slider: More Link Text', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), ); } /** * Initialize translatable nodes. */ public function initialize_nodes_to_translate() { $this->nodes_to_translate = apply_filters( 'wpml_beaver_builder_modules_to_translate', self::get_nodes_to_translate() ); } } wpml-page-builders/classes/Integrations/BeaverBuilder/Hooks/Editor.php 0000755 00000001155 14720415745 0022122 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\Hooks; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Editor implements \IWPML_Frontend_Action { public function add_hooks() { Hooks::onFilter( 'wpml_pb_is_editing_translation_with_native_editor', 10, 2 ) ->then( spreadArgs( function( $isTranslationWithNativeEditor, $translatedPostId ) { return $isTranslationWithNativeEditor || ( Obj::path( [ 'fl_builder_data', 'action' ], $_POST ) === 'save_layout' && (int) Obj::path( [ 'fl_builder_data', 'post_id' ], $_POST ) === $translatedPostId ); } ) ); } } wpml-page-builders/classes/Integrations/BeaverBuilder/Hooks/Menu.php 0000755 00000001156 14720415745 0021601 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\Hooks; class Menu implements \IWPML_Frontend_Action { const TERM_TAXONOMY = 'nav_menu'; public function add_hooks() { add_filter( 'fl_builder_menu_module_core_menu', [ $this, 'adjustTranslatedMenu' ], 10, 2 ); } /** * @param string $menu * @param object $settings module settings object. * * @return string */ public function adjustTranslatedMenu( $menu, $settings ) { $targetMenuSlug = $settings->menu; $targetMenu = get_term_by( 'slug', $targetMenuSlug, self::TERM_TAXONOMY ); if ( $targetMenu ) { $menu = $targetMenu->slug; } return $menu; } } classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-pricing-table.php 0000755 00000002267 14720415745 0030675 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Pricing_Table extends WPML_Beaver_Builder_Module_With_Items { public function &get_items( $settings ) { return $settings->pricing_columns; } public function get_fields() { return array( 'title', 'button_text', 'button_url', 'features', 'price', 'duration' ); } protected function get_title( $field ) { switch ( $field ) { case 'title': return esc_html__( 'Pricing table: Title', 'sitepress' ); case 'button_text': return esc_html__( 'Pricing table: Button text', 'sitepress' ); case 'button_url': return esc_html__( 'Pricing table: Button link', 'sitepress' ); case 'features': return esc_html__( 'Pricing table: Feature', 'sitepress' ); case 'price': return esc_html__( 'Pricing table: Price', 'sitepress' ); case 'duration': return esc_html__( 'Pricing table: Duration', 'sitepress' ); default: return ''; } } protected function get_editor_type( $field ) { switch ( $field ) { case 'title': case 'button_text': case 'price': case 'duration': return 'LINE'; case 'button_url': return 'LINK'; case 'features': return 'VISUAL'; default: return ''; } } } classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-content-slider.php 0000755 00000001723 14720415745 0031103 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Content_Slider extends WPML_Beaver_Builder_Module_With_Items { public function &get_items( $settings ) { return $settings->slides; } public function get_fields() { return array( 'title', 'text', 'cta_text', 'link' ); } protected function get_title( $field ) { switch( $field ) { case 'title': return esc_html__( 'Content Slider: Slide heading', 'sitepress' ); case 'text': return esc_html__( 'Content Slider: Slide content', 'sitepress' ); case 'cta_text': return esc_html__( 'Content Slider: Slide call to action text', 'sitepress' ); case 'link': return esc_html__( 'Content Slider: Slide call to action link', 'sitepress' ); default: return ''; } } protected function get_editor_type( $field ) { switch( $field ) { case 'title': case 'cta_text': return 'LINE'; case 'link': return 'LINK'; case 'text': return 'VISUAL'; default: return ''; } } } classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-accordion.php 0000755 00000000544 14720415745 0030112 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Accordion extends WPML_Beaver_Builder_Module_With_Items { protected function get_title( $field ) { switch( $field ) { case 'label': return esc_html__( 'Accordion Item Label', 'sitepress' ); case 'content': return esc_html__( 'Accordion Item Content', 'sitepress' ); default: return ''; } } } classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-icon-group.php 0000755 00000001034 14720415745 0030226 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Icon_Group extends WPML_Beaver_Builder_Module_With_Items { public function &get_items( $settings ) { return $settings->icons; } public function get_fields() { return array( 'link' ); } protected function get_title( $field ) { switch ( $field ) { case 'link': return esc_html__( 'Icon link', 'sitepress' ); default: return ''; } } protected function get_editor_type( $field ) { switch ( $field ) { case 'link': return 'LINK'; default: return ''; } } } wpml-page-builders/classes/Integrations/BeaverBuilder/modules/ModuleWithItemsFromConfig.php 0000755 00000002275 14720415745 0026322 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\Modules; use WPML\FP\Fns; use WPML\FP\Lst; use WPML\FP\Obj; class ModuleWithItemsFromConfig extends \WPML_Beaver_Builder_Module_With_Items { /** @var array $fieldDefinitions */ private $fieldDefinitions = []; /** @var string $itemsField */ private $itemsField; /** * @param string $itemsField * @param array $config */ public function __construct( $itemsField, array $config ) { $this->itemsField = $itemsField; $this->init( $config ); } private function init( array $config ) { $keyByField = Fns::converge( Lst::zipObj(), [ Lst::pluck( 'field' ), Fns::identity() ] ); $this->fieldDefinitions = $keyByField( $config ); } /** * @inheritDoc */ public function get_title( $field ) { return Obj::path( [ $field, 'type' ], $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_fields() { return array_keys( $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_editor_type( $field ) { return Obj::path( [ $field, 'editor_type' ], $this->fieldDefinitions ); } /** * @inheritDoc */ public function &get_items( $settings ) { return $settings->{$this->itemsField}; } } classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-module-with-items.php 0000755 00000004642 14720415745 0031531 0 ustar 00 wpml-page-builders <?php /** * Class WPML_Beaver_Builder_Module_With_Items */ abstract class WPML_Beaver_Builder_Module_With_Items implements IWPML_Page_Builders_Module { /** * @param string $field * * @return string */ abstract protected function get_title( $field ); /** @return array */ protected function get_fields() { return array( 'label', 'content' ); } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'label': return 'LINE'; case 'content': return 'VISUAL'; default: return ''; } } /** * @param object $settings * * @return array */ protected function &get_items( $settings ) { return $settings->items; } /** * @param string|int $node_id * @param object $settings * @param WPML_PB_String[] $strings * * @return WPML_PB_String[] */ public function get( $node_id, $settings, $strings ) { foreach ( $this->get_items( $settings ) as $item ) { foreach( $this->get_fields() as $field ) { if ( is_array( $item->$field ) ) { foreach ( $item->$field as $key => $value ) { $strings[] = new WPML_PB_String( $value, $this->get_string_name( $node_id, $value, $field, $key ), $this->get_title( $field ), $this->get_editor_type( $field ) ); } } else { $strings[] = new WPML_PB_String( $item->$field, $this->get_string_name( $node_id, $item->$field, $field ), $this->get_title( $field ), $this->get_editor_type( $field ) ); } } } return $strings; } /** * @param string|int $node_id * @param object $settings * @param WPML_PB_String $string * * @return null */ public function update( $node_id, $settings, WPML_PB_String $string ) { foreach ( $this->get_items( $settings ) as &$item ) { foreach( $this->get_fields() as $field ) { if ( is_array( $item->$field ) ) { foreach ( $item->$field as $key => &$value ) { if ( $this->get_string_name( $node_id, $value, $field, $key ) == $string->get_name() ) { $value = $string->get_value(); } } } else { if ( $this->get_string_name( $node_id, $item->$field, $field ) == $string->get_name() ) { $item->$field = $string->get_value(); } } } } return null; } private function get_string_name( $node_id, $value, $type, $key = '' ) { return md5( $value ) . '-' . $type . $key . '-' . $node_id; } } classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-testimonials.php 0000755 00000001103 14720415745 0030654 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Testimonials extends WPML_Beaver_Builder_Module_With_Items { public function &get_items( $settings ) { return $settings->testimonials; } public function get_fields() { return array( 'testimonial' ); } protected function get_title( $field ) { switch( $field ) { case 'testimonial': return esc_html__( 'Testimonial content', 'sitepress' ); default: return ''; } } protected function get_editor_type( $field ) { switch( $field ) { case 'testimonial': return 'VISUAL'; default: return ''; } } } wpml-page-builders/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-tab.php 0000755 00000000522 14720415745 0026772 0 ustar 00 <?php class WPML_Beaver_Builder_Tab extends WPML_Beaver_Builder_Module_With_Items { protected function get_title( $field ) { switch( $field ) { case 'label': return esc_html__( 'Tab Item Label', 'sitepress' ); case 'content': return esc_html__( 'Tab Item Content', 'sitepress' ); default: return ''; } } } classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-data-settings-for-media.php 0000755 00000000274 14720415745 0031111 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Data_Settings_For_Media extends WPML_Beaver_Builder_Data_Settings { /** * @return array */ public function get_fields_to_copy() { return []; } } wpml-page-builders/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-register-strings.php0000755 00000005130 14720415745 0030067 0 ustar 00 <?php /** * Class WPML_Beaver_Builder_Register_Strings */ class WPML_Beaver_Builder_Register_Strings extends WPML_Page_Builders_Register_Strings { /** * @param array $data_array * @param array $package */ protected function register_strings_for_modules( array $data_array, array $package ) { foreach ( $data_array as $data ) { if ( is_array( $data ) ) { $data = $this->sort_modules_before_string_registration( $data ); $this->register_strings_for_modules( $data, $package ); } elseif ( is_object( $data ) ) { if ( isset( $data->type, $data->node, $data->settings ) && 'module' === $data->type && ! $this->is_embedded_global_module( $data ) ) { $this->register_strings_for_node( $data->node, $data->settings, $package ); } } } } /** * The modules are not in the order they appear on the page, * so we need to sort it before to register the strings. * * @param array $modules * * @return array */ private function sort_modules_before_string_registration( array $modules ) { if ( count( $modules ) > 1 ) { uasort( $modules, array( $this, 'sort_modules_by_position_only' ) ); return $this->sort_modules_by_parent_and_child( $modules ); } return $modules; } /** * We receive all modules as a flat tree and we need to reorder from: * - child A * - child A * - parent A * - child B * - parent B * - child B * - child C * * To: * - parent A * - child A * - child B * - parent B * - child A * - child B * - child C * * The relative positions are already sorted by `sort_modules_by_position_only` * * @param array $all_modules * @param string|null $parent_hash * @param array $sorted_modules * * @return array */ private function sort_modules_by_parent_and_child( array $all_modules, $parent_hash = null, array $sorted_modules = array() ){ foreach ( $all_modules as $hash => $module ) { if ( $module->parent === $parent_hash ) { $sorted_modules[ $hash ] = $module; unset( $all_modules[ $hash ] ); $sorted_modules = $this->sort_modules_by_parent_and_child( $all_modules, $module->node, $sorted_modules ); } } return $sorted_modules; } /** * @param stdClass $a * @param stdClass $b * * @return int */ private function sort_modules_by_position_only( stdClass $a, stdClass $b ) { return ( (int) $a->position < (int) $b->position ) ? -1 : 1; } /** * @param object $data * * @return bool */ private function is_embedded_global_module( $data ) { return ! empty( $data->template_node_id ) && isset( $data->node ) && $data->template_node_id !== $data->node; } } classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-update-media-factory.php 0000755 00000001517 14720415745 0031565 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Update_Media_Factory implements IWPML_PB_Media_Update_Factory { public function create() { global $sitepress; $media_translate = new WPML_Page_Builders_Media_Translate( new WPML_Translation_Element_Factory( $sitepress ), new WPML_Media_Image_Translate( $sitepress, new WPML_Media_Attachment_By_URL_Factory(), new \WPML\Media\Factories\WPML_Media_Attachment_By_URL_Query_Factory() ) ); return new WPML_Page_Builders_Update_Media( new WPML_Page_Builders_Update( new WPML_Beaver_Builder_Data_Settings_For_Media() ), new WPML_Translation_Element_Factory( $sitepress ), new WPML_Beaver_Builder_Media_Nodes_Iterator( new WPML_Beaver_Builder_Media_Node_Provider( $media_translate ) ), new WPML_Page_Builders_Media_Usage( $media_translate, new WPML_Media_Usage_Factory() ) ); } } classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-node-provider.php 0000755 00000002167 14720415745 0031415 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Media_Node_Provider { /** @var WPML_Page_Builders_Media_Translate $media_translate */ private $media_translate; /** @var WPML_Beaver_Builder_Media_Node[] */ private $nodes = array(); public function __construct( WPML_Page_Builders_Media_Translate $media_translate ) { $this->media_translate = $media_translate; } /** * @param string $type * * @return WPML_Beaver_Builder_Media_Node|null */ public function get( $type ) { if ( ! array_key_exists( $type, $this->nodes ) ) { switch ( $type ) { case 'photo': $node = new WPML_Beaver_Builder_Media_Node_Photo( $this->media_translate ); break; case 'gallery': $node = new WPML_Beaver_Builder_Media_Node_Gallery( $this->media_translate ); break; case 'content-slider': $node = new WPML_Beaver_Builder_Media_Node_Content_Slider( $this->media_translate ); break; case 'slideshow': $node = new WPML_Beaver_Builder_Media_Node_Slideshow( $this->media_translate ); break; default: $node = null; } $this->nodes[ $type ] = $node; } return $this->nodes[ $type ]; } } classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-gallery.php 0000755 00000001752 14720415745 0032671 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Media_Node_Gallery extends WPML_Beaver_Builder_Media_Node { public function translate( $node_data, $target_lang, $source_lang ) { foreach ( $node_data->photos as &$photo ) { $photo = $this->media_translate->translate_id( $photo, $target_lang ); } foreach ( $node_data->photo_data as &$photo_data ) { $translated_id = $this->media_translate->translate_id( $photo_data->id, $target_lang ); if ( $translated_id !== $photo_data->id ) { $translation_data = wp_prepare_attachment_for_js( $translated_id ); $photo_data->id = $translated_id; $photo_data->alt = $translation_data['alt']; $photo_data->caption = $translation_data['caption']; $photo_data->description = $translation_data['description']; $photo_data->title = $translation_data['title']; $photo_data->src = $translation_data['url']; $photo_data->link = $translation_data['url']; } } return $node_data; } } classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-photo.php 0000755 00000001102 14720415745 0032350 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Media_Node_Photo extends WPML_Beaver_Builder_Media_Node { public function translate( $node_data, $target_lang, $source_lang ) { $translated_id = $this->media_translate->translate_id( $node_data->photo, $target_lang ); if ( $translated_id !== $node_data->photo ) { $node_data->photo = $translated_id; $node_data->photo_src = $this->media_translate->translate_image_url( $node_data->photo_src, $target_lang, $source_lang ); $node_data->data = wp_prepare_attachment_for_js( $translated_id ); } return $node_data; } } classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node.php 0000755 00000000547 14720415745 0031235 0 ustar 00 wpml-page-builders <?php abstract class WPML_Beaver_Builder_Media_Node { /** @var WPML_Page_Builders_Media_Translate $media_translate */ protected $media_translate; public function __construct( WPML_Page_Builders_Media_Translate $media_translate ) { $this->media_translate = $media_translate; } abstract function translate( $node_data, $target_lang, $source_lang ); } classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-slideshow.php 0000755 00000002377 14720415745 0033237 0 ustar 00 wpml-page-builders <?php /** * @group media */ class WPML_Beaver_Builder_Media_Node_Slideshow extends WPML_Beaver_Builder_Media_Node { private $url_properties = array( 'largeURL', 'x3largeURL', 'thumbURL', ); public function translate( $node_data, $target_lang, $source_lang ) { if ( ! isset( $node_data->photos, $node_data->photo_data ) || ! is_array( $node_data->photos ) ) { return $node_data; } foreach ( $node_data->photos as &$photo ) { $photo = $this->media_translate->translate_id( $photo, $target_lang ); } foreach ( $node_data->photo_data as $photo_id => $photo_data ) { $translated_id = $this->media_translate->translate_id( $photo_id, $target_lang ); if ( $translated_id !== $photo_id ) { $translation_data = wp_prepare_attachment_for_js( $translated_id ); $photo_data->caption = $translation_data['caption']; foreach ( $this->url_properties as $property ) { if ( isset( $photo_data->{$property} ) && $photo_data->{$property} ) { $photo_data->{$property} = $this->media_translate->translate_image_url( $photo_data->{$property}, $target_lang, $source_lang ); } } $node_data->photo_data[ $translated_id ] = $photo_data; unset( $node_data->photo_data[ $photo_id ] ); } } return $node_data; } } Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-content-slider.php 0000755 00000001720 14720415745 0034157 0 ustar 00 wpml-page-builders/classes <?php class WPML_Beaver_Builder_Media_Node_Content_Slider extends WPML_Beaver_Builder_Media_Node { private $property_prefixes = array( 'bg_', // i.e. `bg_photo` for an ID or `bg_photo_src` for a URL 'fg_', 'r_', ); public function translate( $node_data, $target_lang, $source_lang ) { if ( ! isset( $node_data->slides ) || ! is_array( $node_data->slides ) ) { return $node_data; } foreach ( $node_data->slides as &$slide ) { foreach ( $this->property_prefixes as $prefix ) { $id_prop = $prefix . 'photo'; $src_prop = $prefix . 'photo_src'; if ( isset( $slide->{$id_prop} ) && $slide->{$id_prop} ) { $slide->{$id_prop} = $this->media_translate->translate_id( $slide->{$id_prop}, $target_lang ); } if ( isset( $slide->{$src_prop} ) && $slide->{$src_prop} ) { $slide->{$src_prop} = $this->media_translate->translate_image_url( $slide->{$src_prop}, $target_lang, $source_lang ); } } } return $node_data; } } classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-hooks-factory.php 0000755 00000000464 14720415745 0031426 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Media_Hooks_Factory implements IWPML_Backend_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { return new WPML_Page_Builders_Media_Hooks( new WPML_Beaver_Builder_Update_Media_Factory(), WPML_Beaver_Builder_Integration_Factory::SLUG ); } } classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-nodes-iterator.php 0000755 00000002422 14720415745 0031571 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Media_Nodes_Iterator implements IWPML_PB_Media_Nodes_Iterator { /** @var WPML_Beaver_Builder_Media_Node_Provider $node_provider */ private $node_provider; public function __construct( WPML_Beaver_Builder_Media_Node_Provider $node_provider ) { $this->node_provider = $node_provider; } /** * @param array $data_array * @param string $lang * @param string $source_lang * * @return array */ public function translate( $data_array, $lang, $source_lang ) { foreach ( $data_array as &$data ) { if ( is_array( $data ) ) { $data = $this->translate( $data, $lang, $source_lang ); } elseif ( is_object( $data ) && isset( $data->type ) && 'module' === $data->type && isset( $data->settings ) && isset( $data->settings->type ) ) { $data->settings = $this->translate_node( $data->settings, $lang, $source_lang ); } } return $data_array; } /** * @param stdClass $settings * @param string $lang * @param string $source_lang * * @return stdClass */ private function translate_node( $settings, $lang, $source_lang ) { $node = $this->node_provider->get( $settings->type ); if ( $node ) { $settings = $node->translate( $settings, $lang, $source_lang ); } return $settings; } } wpml-page-builders/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-data-settings.php 0000755 00000004153 14720415745 0027327 0 ustar 00 <?php use WPML\PB\BeaverBuilder\BeaverThemer\HooksFactory as BeaverThemer; class WPML_Beaver_Builder_Data_Settings implements IWPML_Page_Builders_Data_Settings { /** * @return string */ public function get_meta_field() { return '_fl_builder_data'; } /** * @return string */ public function get_node_id_field() { return 'node'; } /** * @return array */ public function get_fields_to_copy() { $fields = [ '_fl_builder_draft_settings', '_fl_builder_data_settings', '_fl_builder_enabled', ]; if ( BeaverThemer::isActive() ) { return array_merge( $fields, [ '_fl_theme_builder_locations', '_fl_theme_builder_exclusions', '_fl_theme_builder_edit_mode', ] ); } return $fields; } /** * @param array $data * * @return array */ public function convert_data_to_array( $data ) { return $data; } /** * @param array $data * * @return array */ public function prepare_data_for_saving( array $data ) { return $this->slash( $data ); } /** * @return string */ public function get_pb_name() { return 'Beaver builder'; } /** * @return array */ public function get_fields_to_save() { return array( '_fl_builder_data', '_fl_builder_draft' ); } public function add_hooks(){} /** * Adds slashes to data going into the database as WordPress * removes them when we save using update_metadata. This is done * to ensure slashes in user input aren't removed. * * Inspired by `\FLBuilderModel::slash_settings` * * @param mixed $data The data to slash. * * @return mixed The slashed data. */ private function slash( $data ) { if ( is_array( $data ) ) { foreach ( $data as $key => $val ) { $data[ $key ] = $this->slash( $val ); } } elseif ( is_object( $data ) ) { foreach ( $data as $key => $val ) { $data->$key = $this->slash( $val ); } } elseif ( is_string( $data ) ) { $data = wp_slash( $data ); } return $data; } /** * @param int $postId * * @return bool */ public function is_handling_post( $postId ) { return (bool) get_post_meta( $postId, '_fl_builder_enabled', true ); } } classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-integration-factory.php 0000755 00000002305 14720415745 0030466 0 ustar 00 wpml-page-builders <?php class WPML_Beaver_Builder_Integration_Factory { const SLUG = 'beaver-builder'; public function create() { $action_filter_loader = new WPML_Action_Filter_Loader(); $action_filter_loader->load( array( 'WPML_PB_Beaver_Builder_Handle_Custom_Fields_Factory', 'WPML_Beaver_Builder_Media_Hooks_Factory', \WPML\PB\BeaverBuilder\TranslationJob\Hooks::class, \WPML\PB\BeaverBuilder\Config\Factory::class, \WPML\PB\BeaverBuilder\Hooks\Editor::class, \WPML\PB\BeaverBuilder\Hooks\Menu::class, // BeaverThemer. \WPML\PB\BeaverBuilder\BeaverThemer\HooksFactory::class, ) ); $nodes = new WPML_Beaver_Builder_Translatable_Nodes(); $data_settings = new WPML_Beaver_Builder_Data_Settings(); $string_registration_factory = new WPML_String_Registration_Factory( $data_settings->get_pb_name() ); $string_registration = $string_registration_factory->create(); $register_strings = new WPML_Beaver_Builder_Register_Strings( $nodes, $data_settings, $string_registration ); $update_translation = new WPML_Beaver_Builder_Update_Translation( $nodes, $data_settings ); return new WPML_Page_Builders_Integration( $register_strings, $update_translation, $data_settings ); } } wpml-page-builders/classes/Integrations/BeaverBuilder/Config/Factory.php 0000755 00000000666 14720415745 0022433 0 ustar 00 <?php namespace WPML\PB\BeaverBuilder\Config; class Factory extends \WPML\PB\Config\Factory { const DATA = [ 'configRoot' => 'beaver-builder-widgets', 'defaultConditionKey' => 'type', 'pbKey' => 'beaver-builder', 'translatableWidgetsHook' => 'wpml_beaver_builder_modules_to_translate', ]; /** * @inheritDoc */ protected function getPbData( $key ) { return self::DATA[ $key ]; } } classes/Integrations/WPBakery/class-wpml-compatibility-plugin-visual-composer-grid-hooks.php 0000755 00000003477 14720415745 0032133 0 ustar 00 wpml-page-builders <?php class WPML_Compatibility_Plugin_Visual_Composer_Grid_Hooks implements IWPML_Action { /** @var IWPML_Current_Language $current_language */ private $current_language; /** @var WPML_Translation_Element_Factory $element_factory */ private $element_factory; public function __construct( IWPML_Current_Language $current_language, WPML_Translation_Element_Factory $element_factory ) { $this->current_language = $current_language; $this->element_factory = $element_factory; } public function add_hooks() { add_filter( 'wpml_pb_shortcode_decode', array( $this, 'vc_grid_link_decode' ), 10, 3 ); add_filter( 'vc_shortcode_content_filter', array( $this, 'vc_shortcode_content_filter' ) ); } /** * @param string|array $string * @param string $encoding * @param string $encoded_string * * @return string|array */ function vc_grid_link_decode( $string, $encoding, $encoded_string ) { if ( 'vc_link' === $encoding && empty( $string ) ) { return $encoded_string; } return $string; } /** * @param string $content * * @return string */ public function vc_shortcode_content_filter( $content ) { $pattern = '/(\[vc_basic_grid.*item=")([^"]*)(".*\])/'; return preg_replace_callback( $pattern, array( $this, 'replace_grid_id' ), $content ); } /** * @param array $matches * * @return string */ private function replace_grid_id( array $matches ) { $grid_id = (int) $matches[2]; if ( $grid_id > 0 ) { $before = $matches[1]; $after = $matches[3]; $element = $this->element_factory->create( $grid_id, 'post' ); $translation = $element->get_translation( $this->current_language->get_current_language() ); if ( $translation ) { $grid_id = $translation->get_element_id(); } return $before . $grid_id . $after; } return $matches[0]; } } wpml-page-builders/classes/Integrations/WPBakery/class-wpml-compatibility-plugin-visual-composer.php0000755 00000005403 14720415745 0030135 0 ustar 00 <?php /** * Class WPML_Compatibility_Plugin_Visual_Composer * * @author OnTheGoSystems */ class WPML_Compatibility_Plugin_Visual_Composer { /** @var WPML_Debug_BackTrace $debug_backtrace */ private $debug_backtrace; /** @var array $filters_to_restore */ private $filters_to_restore = array(); /** * WPML_Compatibility_Plugin_Visual_Composer constructor. * * @param WPML_Debug_BackTrace $debug_backtrace */ public function __construct( WPML_Debug_BackTrace $debug_backtrace ) { $this->debug_backtrace = $debug_backtrace; } public function add_hooks() { $this->prevent_registering_widget_strings_twice(); } private function prevent_registering_widget_strings_twice() { add_filter( 'widget_title', array( $this, 'suspend_vc_widget_translation' ), - PHP_INT_MAX ); add_filter( 'widget_text', array( $this, 'suspend_vc_widget_translation' ), - PHP_INT_MAX ); add_filter( 'widget_title', array( $this, 'restore_widget_translation' ), PHP_INT_MAX ); add_filter( 'widget_text', array( $this, 'restore_widget_translation' ), PHP_INT_MAX ); add_filter( 'wpml_pb_shortcode_encode', array( $this, 'vc_safe_encode' ), 10, 2 ); add_filter( 'wpml_pb_shortcode_decode', array( $this, 'vc_safe_decode' ), 10, 3 ); } /** * @param string $text * * @return string */ public function suspend_vc_widget_translation( $text ) { if ( $this->debug_backtrace->is_function_in_call_stack( 'vc_do_shortcode' ) && ! $this->debug_backtrace->is_function_in_call_stack( 'dynamic_sidebar', false ) ) { $filter = new stdClass(); $filter->hook = current_filter(); $filter->name = 'icl_sw_filters_' . $filter->hook; $filter->priority = has_filter( $filter->hook, $filter->name ); if ( false !== $filter->priority ) { remove_filter( $filter->hook, $filter->name, $filter->priority ); $this->filters_to_restore[] = $filter; } } return $text; } /** * @param string $text * * @return mixed */ public function restore_widget_translation( $text ) { foreach ( $this->filters_to_restore as $filter ) { add_filter( $filter->hook, $filter->name, $filter->priority ); } return $text; } function vc_safe_encode( $string, $encoding ) { if ( 'vc_safe' === $encoding ) { if ( is_array( $string ) ) { $string = implode( ',', $string ); } $string = '#E-8_' . base64_encode( rawurlencode( $string ) ); } return $string; } function vc_safe_decode( $string, $encoding, $encoded_string ) { if ( 'vc_safe' === $encoding ) { $values = rawurldecode( base64_decode( substr( $string, 5 ) ) ); $values = explode( ',', $values ); $string = array(); foreach ( $values as $index => $value ) { $string[ $index ] = array( 'value' => $value, 'translate' => true ); } } return $string; } } wpml-page-builders/classes/Integrations/WPBakery/Styles.php 0000755 00000004504 14720415745 0020046 0 ustar 00 <?php namespace WPML\Compatibility\WPBakery; use WPML\Element\API\PostTranslations; use WPML\FP\Fns; use WPML\FP\Maybe; use WPML_Custom_Field_Setting_Factory; use WPML_PB_Last_Translation_Edit_Mode; use function WPML\FP\partial; use function WPML\FP\partialRight; class Styles implements \IWPML_Frontend_Action, \IWPML_Backend_Action { const META_CUSTOM_CSS = [ '_wpb_shortcodes_custom_css', '_wpb_post_custom_css', ]; /** @var WPML_Custom_Field_Setting_Factory $metaSettingFactory */ private $metaSettingFactory; public function __construct( WPML_Custom_Field_Setting_Factory $metaSettingFactory ) { $this->metaSettingFactory = $metaSettingFactory; } public function add_hooks() { add_action( 'save_post', [ $this, 'copyCssFromOriginal' ] ); add_action( 'init', [ $this, 'adjustMetaSetting' ] ); } /** * @param int $postId */ public function copyCssFromOriginal( $postId ) { // $ifUsingTranslationEditor :: int -> bool $ifUsingTranslationEditor = [ WPML_PB_Last_Translation_Edit_Mode::class, 'is_translation_editor' ]; // $ifUsingWpBakery :: int -> bool $ifUsingWpBakery = partialRight( 'get_post_meta', '_wpb_vc_js_status', true ); // $copyCss:: int -> void $copyCss = function( $originalPostId ) use ( $postId ) { wpml_collect( self::META_CUSTOM_CSS )->map( function( $key ) use ( $postId, $originalPostId ) { $css = get_post_meta( $originalPostId, $key, true ); if ( $css ) { update_post_meta( $postId, $key, $css ); } } ); }; Maybe::of( $postId ) ->filter( $ifUsingTranslationEditor ) ->map( PostTranslations::getOriginalId() ) ->filter( $ifUsingWpBakery ) ->map( $copyCss ); } /** * As a general rule, we will copy the CSS meta field only once, so * it will work fine and independently if the translation is done * with the native WP editor. Otherwise, we will programmatically * copy the CSS meta to the translation. * * This adjustment code is required since we are changing the original * setting from "copy" to "copy_once" (it will also be updated on the * remote config file). */ public function adjustMetaSetting() { wpml_collect( self::META_CUSTOM_CSS )->map( function( $key ) { $metaSetting = $this->metaSettingFactory->post_meta_setting( $key ); if ( ! $metaSetting->is_unlocked() ) { $metaSetting->set_to_copy_once(); } } ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-db.php 0000755 00000000556 14720415745 0023471 0 ustar 00 <?php class WPML_Elementor_DB { /** * @var \Elementor\DB */ private $elementor_db; // @codingStandardsIgnoreLine public function __construct( \Elementor\DB $elementor_db ) { $this->elementor_db = $elementor_db; } /** * @param int $post_id */ public function save_plain_text( $post_id ) { $this->elementor_db->save_plain_text( $post_id ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-update-translation.php 0000755 00000002213 14720415745 0026712 0 ustar 00 <?php use WPML\PB\Elementor\Helper\Node; use WPML\PB\Elementor\Helper\StringFormat; class WPML_Elementor_Update_Translation extends WPML_Page_Builders_Update_Translation { /** @param array $data_array */ protected function update_strings_in_modules( array &$data_array ) { foreach ( $data_array as &$element ) { if ( Node::hasChildren( $element ) ) { $this->update_strings_in_modules( $element['elements'] ); } if ( Node::isTranslatable( $element ) ) { $element = $this->update_strings_in_node( $element[ $this->data_settings->get_node_id_field() ], $element ); } } } /** * @param int $node_id * @param array $settings * * @return array */ protected function update_strings_in_node( $node_id, $settings ) { $strings = $this->translatable_nodes->get( $node_id, $settings ); foreach ( $strings as $string ) { $translation = $this->get_translation( $string ); if ( StringFormat::useWpAutoP( $settings, $string ) ) { $translation->set_value( wpautop( $translation->get_value() ) ); } $settings = $this->translatable_nodes->update( $node_id, $settings, $translation ); } return $settings; } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-translatable-nodes.php 0000755 00000071541 14720415745 0026670 0 ustar 00 <?php use WPML\FP\Obj; use WPML\PB\Elementor\DynamicContent\Strings as DynamicContentStrings; use WPML\PB\Elementor\Modules\ModuleWithItemsFromConfig; /** * Class WPML_Elementor_Translatable_Nodes */ class WPML_Elementor_Translatable_Nodes implements IWPML_Page_Builders_Translatable_Nodes { const SETTINGS_FIELD = 'settings'; const TYPE = 'widgetType'; const DEFAULT_HEADING_TAG = 'h2'; const ELEMENT_TYPE = 'elType'; /** * @var array */ private $nodes_to_translate; /** * @param string|int $node_id Translatable node id. * @param array $element * * @return WPML_PB_String[] */ public function get( $node_id, $element ) { if ( ! $this->nodes_to_translate ) { $this->initialize_nodes_to_translate(); } $strings = array(); foreach ( $this->nodes_to_translate as $node_type => $node_data ) { if ( $this->conditions_ok( $node_data, $element ) ) { foreach ( $node_data['fields'] as $key => $field ) { $field_key = $field['field']; $pathInFlatField = array_merge( [ self::SETTINGS_FIELD ], self::get_partial_path( $field_key ) ); $string_value = Obj::pathOr( null, $pathInFlatField, $element ); if ( ! is_string( $string_value ) ) { $pathInArrayField = array_merge( [ self::SETTINGS_FIELD, $key ], self::get_partial_path( $field_key ) ); $string_value = Obj::pathOr( null, $pathInArrayField, $element ); } if ( $string_value ) { $strings[] = new WPML_PB_String( $string_value, $this->get_string_name( $node_id, $field, $element ), $field['type'], $field['editor_type'], $this->get_wrap_tag( $element ) ); } } foreach ( $this->get_integration_instances( $node_data ) as $instance ) { try { $strings = $instance->get( $node_id, $element, $strings ); } catch ( Exception $e ) {} } } } return DynamicContentStrings::filter( $strings, $node_id, $element ); } /** * @param string|int $node_id * @param array $element * @param WPML_PB_String $string * * @return array */ public function update( $node_id, $element, WPML_PB_String $string ) { if ( ! $this->nodes_to_translate ) { $this->initialize_nodes_to_translate(); } foreach ( $this->nodes_to_translate as $node_type => $node_data ) { if ( $this->conditions_ok( $node_data, $element ) ) { foreach ( $node_data['fields'] as $key => $field ) { $field_key = $field['field']; if ( $this->get_string_name( $node_id, $field, $element ) === $string->get_name() ) { $pathInFlatField = array_merge( [ self::SETTINGS_FIELD ], self::get_partial_path( $field_key ) ); $stringInFlatField = Obj::pathOr( null, $pathInFlatField, $element ); $pathInArrayField = array_merge( [ self::SETTINGS_FIELD, $key ], self::get_partial_path( $field_key ) ); $stringInArrayField = Obj::pathOr( null, $pathInArrayField, $element ); if ( is_string( $stringInFlatField ) ) { $element = Obj::assocPath( $pathInFlatField, $string->get_value(), $element ); } elseif ( is_string( $stringInArrayField ) ) { $element = Obj::assocPath( $pathInArrayField, $string->get_value(), $element ); } } } foreach ( $this->get_integration_instances( $node_data ) as $instance ) { try { $item = $instance->update( $node_id, $element, $string ); if ( $item ) { $element[ self::SETTINGS_FIELD ][ $instance->get_items_field() ][ $item['index'] ] = $item; } } catch ( Exception $e ) {} } } } return DynamicContentStrings::updateNode( $element, $string ); } /** * @param string $field * * @return string[] */ private static function get_partial_path( $field ) { return explode( '>', $field ); } /** * @param array $node_data * * @return WPML_Elementor_Module_With_Items[] */ private function get_integration_instances( $node_data ) { $instances = []; if ( isset( $node_data['integration-class'] ) ) { $integration_classes = $node_data['integration-class']; if ( ! is_array( $integration_classes ) ) { $integration_classes = [ $integration_classes ]; } foreach ( $integration_classes as $class_or_instance ) { if ( $class_or_instance instanceof \WPML_Elementor_Module_With_Items ) { $instances[] = $class_or_instance; } elseif ( class_exists( $class_or_instance ) ) { try { $instances[] = new $class_or_instance(); } catch ( Exception $e ) { } } } } if ( isset( $node_data['fields_in_item'] ) ) { foreach ( $node_data['fields_in_item'] as $item_of => $config ) { $instances[] = new ModuleWithItemsFromConfig( $item_of, $config ); } } return array_filter( $instances ); } /** * @param string $node_id * @param array $field * @param array $settings * * @return string */ public function get_string_name( $node_id, $field, $settings ) { $field_id = isset( $field['field_id'] ) ? $field['field_id'] : $field['field']; $type = isset( $settings[ self::TYPE ] ) ? $settings[ self::TYPE ] : $settings[ self::ELEMENT_TYPE ]; return $field_id . '-' . $type . '-' . $node_id; } /** * Get wrap tag for string. * Used for SEO, can contain (h1...h6, etc.) * * @param array $settings Field settings. * * @return string */ private function get_wrap_tag( $settings ) { if ( isset( $settings[ self::TYPE ] ) && 'heading' === $settings[ self::TYPE ] ) { $header_size = isset( $settings[ self::SETTINGS_FIELD ]['header_size'] ) ? $settings[ self::SETTINGS_FIELD ]['header_size'] : self::DEFAULT_HEADING_TAG; return $header_size; } return ''; } /** * @param array $node_data * @param array $element * * @return bool */ private function conditions_ok( $node_data, $element ) { $conditions_meet = true; foreach ( $node_data['conditions'] as $field_key => $field_value ) { if ( ! isset( $element[ $field_key ] ) || $element[ $field_key ] != $field_value ) { $conditions_meet = false; break; } } return $conditions_meet; } public static function get_nodes_to_translate() { return array( // Container for the flexbox layout. // It is not actually a widget but may have an URL to translate. 'container' => [ 'conditions' => [ self::ELEMENT_TYPE => 'container' ], 'fields' => [ 'link' => [ 'field' => 'url', 'type' => __( 'Container: Link URL', 'sitepress' ), 'editor_type' => 'LINK', ], ], ], // Everything below is a widget and has strings to translate. 'heading' => array( 'conditions' => array( self::TYPE => 'heading' ), 'fields' => array( array( 'field' => 'title', 'type' => __( 'Heading', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Heading: Link URL', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'text-editor' => array( 'conditions' => array( self::TYPE => 'text-editor' ), 'fields' => array( array( 'field' => 'editor', 'type' => __( 'Text editor', 'sitepress' ), 'editor_type' => 'VISUAL' ), ), ), 'icon' => array( 'conditions' => array( self::TYPE => 'icon' ), 'fields' => array( 'link' => array( 'field' => 'url', 'type' => __( 'Icon: Link URL', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'video' => array( 'conditions' => array( self::TYPE => 'video' ), 'fields' => array( array( 'field' => 'link', 'type' => __( 'Video: Link', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'vimeo_link', 'type' => __( 'Video: Vimeo link', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'youtube_url', 'type' => __( 'Video: Youtube URL', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'vimeo_url', 'type' => __( 'Video: Vimeo URL', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'dailymotion_url', 'type' => __( 'Video: DailyMotion URL', 'sitepress' ), 'editor_type' => 'LINE' ), 'hosted_url'=> array( 'field' => 'url', 'type' => __( 'Video: Self hosted', 'sitepress' ), 'editor_type' => 'LINE' ), 'external_url'=> array( 'field' => 'url', 'type' => __( 'Video: External hosted', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'login' => array( 'conditions' => array( self::TYPE => 'login' ), 'fields' => array( array( 'field' => 'button_text', 'type' => __( 'Login: Button text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'user_label', 'type' => __( 'Login: User label', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'user_placeholder', 'type' => __( 'Login: User placeholder', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'password_label', 'type' => __( 'Login: Password label', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'password_placeholder', 'type' => __( 'Login: Password placeholder', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'button' => array( 'conditions' => array( self::TYPE => 'button' ), 'fields' => array( array( 'field' => 'text', 'type' => __( 'Button', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Button: Link URL', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'html' => array( 'conditions' => array( self::TYPE => 'html' ), 'fields' => array( array( 'field' => 'html', 'type' => __( 'HTML', 'sitepress' ), 'editor_type' => 'AREA' ), ), ), 'image' => array( 'conditions' => array( self::TYPE => 'image' ), 'fields' => array( array( 'field' => 'caption', 'type' => __( 'Image: Caption', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Image: Link URL', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'alert' => array( 'conditions' => array( self::TYPE => 'alert' ), 'fields' => array( array( 'field' => 'alert_title', 'type' => __( 'Alert title', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'alert_description', 'type' => __( 'Alert description', 'sitepress' ), 'editor_type' => 'VISUAL' ), ), ), 'blockquote' => array( 'conditions' => array( self::TYPE => 'blockquote' ), 'fields' => array( array( 'field' => 'blockquote_content', 'type' => __( 'Blockquote: Content', 'sitepress' ), 'editor_type' => 'AREA', ), array( 'field' => 'tweet_button_label', 'type' => __( 'Blockquote: Tweet button label', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'testimonial' => array( 'conditions' => array( self::TYPE => 'testimonial' ), 'fields' => array( array( 'field' => 'testimonial_content', 'type' => __( 'Testimonial content', 'sitepress' ), 'editor_type' => 'VISUAL' ), array( 'field' => 'testimonial_name', 'type' => __( 'Testimonial name', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'testimonial_job', 'type' => __( 'Testimonial job', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'progress' => array( 'conditions' => array( self::TYPE => 'progress' ), 'fields' => array( array( 'field' => 'title', 'type' => __( 'Progress: Title', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'inner_text', 'type' => __( 'Progress: Inner text', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'counter' => array( 'conditions' => array( self::TYPE => 'counter' ), 'fields' => array( array( 'field' => 'starting_number', 'type' => __( 'Starting number', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'title', 'type' => __( 'Title', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'prefix', 'type' => __( 'Prefix', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'suffix', 'type' => __( 'Suffix', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'countdown' => array( 'conditions' => array( self::TYPE => 'countdown' ), 'fields' => array( array( 'field' => 'label_days', 'type' => __( 'Countdown: Label days', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'label_hours', 'type' => __( 'Countdown: Label hours', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'label_minutes', 'type' => __( 'Countdown: Label minutes', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'label_seconds', 'type' => __( 'Countdown: Label seconds', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'icon-box' => array( 'conditions' => array( self::TYPE => 'icon-box' ), 'fields' => array( array( 'field' => 'title_text', 'type' => __( 'Icon Box: Title text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'description_text', 'type' => __( 'Icon Box: Description text', 'sitepress' ), 'editor_type' => 'AREA' ), 'link' => array( 'field' => 'url', 'type' => __( 'Icon Box: Link', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'image-box' => array( 'conditions' => array( self::TYPE => 'image-box' ), 'fields' => array( array( 'field' => 'title_text', 'type' => __( 'Image Box: Title text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'description_text', 'type' => __( 'Image Box: Description text', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Image Box: Link', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'animated-headline' => array( 'conditions' => array( self::TYPE => 'animated-headline' ), 'fields' => array( array( 'field' => 'before_text', 'type' => __( 'Animated Headline: Before text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'highlighted_text', 'type' => __( 'Animated Headline: Highlighted text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'rotating_text', 'type' => __( 'Animated Headline: Rotating text', 'sitepress' ), 'editor_type' => 'AREA' ), array( 'field' => 'after_text', 'type' => __( 'Animated Headline: After text', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Animated Headline: Link URL', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'flip-box' => array( 'conditions' => array( self::TYPE => 'flip-box' ), 'fields' => array( array( 'field' => 'title_text_a', 'type' => __( 'Flip Box: Title text side A', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'description_text_a', 'type' => __( 'Flip Box: Description text side A', 'sitepress' ), 'editor_type' => 'AREA' ), array( 'field' => 'title_text_b', 'type' => __( 'Flip Box: Title text side B', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'description_text_b', 'type' => __( 'Flip Box: Description text side B', 'sitepress' ), 'editor_type' => 'AREA' ), array( 'field' => 'button_text', 'type' => __( 'Flip Box: Button text', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Flip Box: Button link', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'call-to-action' => array( 'conditions' => array( self::TYPE => 'call-to-action' ), 'fields' => array( array( 'field' => 'title', 'type' => __( 'Call to action: title', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'description', 'type' => __( 'Call to action: description', 'sitepress' ), 'editor_type' => 'VISUAL' ), array( 'field' => 'button', 'type' => __( 'Call to action: button', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'ribbon_title', 'type' => __( 'Call to action: ribbon title', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Call to action: link', 'sitepress' ), 'editor_type' => 'LINK' ), ), ), 'toggle' => array( 'conditions' => array( self::TYPE => 'toggle' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Toggle', ), 'accordion' => array( 'conditions' => array( self::TYPE => 'accordion' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Accordion', ), 'testimonial-carousel' => array( 'conditions' => array( self::TYPE => 'testimonial-carousel' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Testimonial_Carousel', ), 'tabs' => array( 'conditions' => array( self::TYPE => 'tabs' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Tabs', ), 'price-list' => array( 'conditions' => array( self::TYPE => 'price-list' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Price_List', ), 'icon-list' => array( 'conditions' => array( self::TYPE => 'icon-list' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Icon_List', ), 'slides' => array( 'conditions' => array( self::TYPE => 'slides' ), 'fields' => array(), 'integration-class' => 'WPML_Elementor_Slides', ), 'price-table' => array( 'conditions' => array( self::TYPE => 'price-table' ), 'fields' => array( array( 'field' => 'heading', 'type' => __( 'Price Table: Heading', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'sub_heading', 'type' => __( 'Price Table: Sub heading', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'period', 'type' => __( 'Price Table: Period', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'button_text', 'type' => __( 'Price Table: Button text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'footer_additional_info', 'type' => __( 'Price Table: Footer additional info', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'ribbon_title', 'type' => __( 'Price Table: Ribbon title', 'sitepress' ), 'editor_type' => 'LINE' ), 'link' => array( 'field' => 'url', 'type' => __( 'Price Table: Button link', 'sitepress' ), 'editor_type' => 'LINK' ), ), 'integration-class' => 'WPML_Elementor_Price_Table', ), 'form' => array( 'conditions' => array( self::TYPE => 'form' ), 'fields' => array( array( 'field' => 'form_name', 'type' => __( 'Form: name', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'button_text', 'type' => __( 'Form: Button text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'email_subject', 'type' => __( 'Form: Email subject', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'email_from_name', 'type' => __( 'Form: Email from name', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'email_content', 'type' => __( 'Form: Email Content', 'sitepress' ), 'editor_type' => 'AREA' ), array( 'field' => 'email_subject_2', 'type' => __( 'Form: Email subject 2', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'email_content_2', 'type' => __( 'Form: Email Content', 'sitepress' ), 'editor_type' => 'AREA' ), array( 'field' => 'success_message', 'type' => __( 'Form: Success message', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'error_message', 'type' => __( 'Form: Error message', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'required_message', 'type' => __( 'Form: Required message', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'invalid_message', 'type' => __( 'Form: Invalid message', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'required_field_message', 'type' => __( 'Form: Required message', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'redirect_to', 'type' => __( 'Form: Redirect to URL', 'sitepress' ), 'editor_type' => 'LINE' ), ), 'integration-class' => 'WPML_Elementor_Form', ), 'posts' => array( 'conditions' => array( self::TYPE => 'posts' ), 'fields' => array( array( 'field' => 'classic_read_more_text', 'type' => __( 'Posts: Classic Read more text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'pagination_prev_label', 'type' => __( 'Posts: Previous Label', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'pagination_next_label', 'type' => __( 'Posts: Next Label', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'cards_read_more_text', 'type' => __( 'Posts: Cards Read more text', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'menu-anchor' => array( 'conditions' => array( self::TYPE => 'menu-anchor' ), 'fields' => array( array( 'field' => 'anchor', 'type' => __( 'Menu Anchor', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'archive-posts' => array( 'conditions' => array( self::TYPE => 'archive-posts' ), 'fields' => array( array( 'field' => 'archive_cards_meta_separator', 'type' => __( 'Cards: Separator Between', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'archive_cards_read_more_text', 'type' => __( 'Cards: Read More Text', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'nothing_found_message', 'type' => __( 'Nothing Found Message', 'sitepress' ), 'editor_type' => 'AREA' ), array( 'field' => 'pagination_prev_label', 'type' => __( 'Previous Label', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'pagination_next_label', 'type' => __( 'Next Label', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'archive_classic_meta_separator', 'type' => __( 'Classic: Separator Between', 'sitepress' ), 'editor_type' => 'LINE' ), array( 'field' => 'archive_classic_read_more_text', 'type' => __( 'Classic: Read More Text', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'search-form' => array( 'conditions' => array( self::TYPE => 'search-form' ), 'fields' => array( array( 'field' => 'placeholder', 'type' => __( 'Placeholder', 'sitepress' ), 'editor_type' => 'LINE' ), ), ), 'post-navigation' => array( 'conditions' => array( self::TYPE => 'post-navigation' ), 'fields' => array( array( 'field' => 'prev_label', 'type' => __( 'Previous Label', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'next_label', 'type' => __( 'Next Label', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), 'divider' => array( 'conditions' => array( self::TYPE => 'divider' ), 'fields' => array( array( 'field' => 'text', 'type' => __( 'Divider Text', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), 'table-of-contents' => array( 'conditions' => array( self::TYPE => 'table-of-contents' ), 'fields' => array( array( 'field' => 'title', 'type' => __( 'Table of Contents - Title', 'sitepress' ), 'editor_type' => 'LINE', ), ), ), 'media-carousel' => [ 'conditions' => [ self::TYPE => 'media-carousel' ], 'fields' => [], 'integration-class' => [ '\WPML\PB\Elementor\Modules\MediaCarousel', ] ], 'lottie' => [ 'conditions' => [ self::TYPE => 'lottie' ], 'fields' => [ 'custom_link' => [ 'field' => 'url', 'type' => __( 'Lottie: Link URL', 'sitepress' ), 'editor_type' => 'LINK' ], ], ], 'author-box' => array( 'conditions' => array( self::TYPE => 'author-box' ), 'fields' => array( array( 'field' => 'author_name', 'type' => __( 'Author Name', 'sitepress' ), 'editor_type' => 'LINE', ), array( 'field' => 'author_bio', 'type' => __( 'Author Bio', 'sitepress' ), 'editor_type' => 'AREA', ), 'author_website' => array( 'field' => 'url', 'field_id' => 'author_website', 'type' => __( 'Author Link', 'sitepress' ), 'editor_type' => 'LINK', ), array( 'field' => 'link_text', 'type' => __( 'Archive Text', 'sitepress' ), 'editor_type' => 'LINE', ), 'posts_url' => array( 'field' => 'url', 'field_id' => 'posts_url', 'type' => __( 'Archive Button URL', 'sitepress' ), 'editor_type' => 'LINK', ), ), ), 'reviews' => array( 'conditions' => array( self::TYPE => 'reviews' ), 'fields' => [], 'integration-class' => [ '\WPML\PB\Elementor\Modules\Reviews', ] ), 'galleries' => array( 'conditions' => array( self::TYPE => 'gallery' ), 'fields' => array( array( 'field' => 'show_all_galleries_label', 'type' => __( 'All Gallery Label', 'sitepress' ), 'editor_type' => 'LINE' ), 'url' => array( 'field' => 'url', 'type' => __( 'Gallery custom link', 'sitepress' ), 'editor_type' => 'LINK' ), ), 'integration-class' => [ '\WPML\PB\Elementor\Modules\MultipleGallery', ] ), 'hotspot' => [ 'conditions' => [ self::TYPE => 'hotspot' ], 'fields' => [], 'integration-class' => [ \WPML\PB\Elementor\Modules\Hotspot::class, ], ], ); } public function initialize_nodes_to_translate() { $this->nodes_to_translate = apply_filters( 'wpml_elementor_widgets_to_translate', self::get_nodes_to_translate() ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-adjust-global-widget-id.php 0000755 00000011335 14720415745 0027504 0 ustar 00 <?php class WPML_Elementor_Adjust_Global_Widget_ID { /** @var IWPML_Page_Builders_Data_Settings */ private $elementor_settings; /** @var WPML_Translation_Element_Factory */ private $translation_element_factory; /** @var SitePress */ private $sitepress; /** @var string */ private $current_language; public function __construct( IWPML_Page_Builders_Data_Settings $elementor_settings, WPML_Translation_Element_Factory $translation_element_factory, SitePress $sitepress ) { $this->elementor_settings = $elementor_settings; $this->translation_element_factory = $translation_element_factory; $this->sitepress = $sitepress; } public function add_hooks() { add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'adjust_ids' ) ); add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'restore_current_language' ) ); add_action( 'elementor/frontend/the_content', array( $this, 'duplicate_css_class_with_original_id' ) ); if ( is_admin() ) { add_filter( 'wpml_should_use_display_as_translated_snippet', array( $this, 'should_use_display_as_translated_snippet' ), PHP_INT_MAX, 2 ); } } public function adjust_ids() { $this->current_language = $this->sitepress->get_current_language(); $post_id = absint( $_REQUEST['post'] ); // WPCS: sanitization ok. $post = $this->translation_element_factory->create_post( $post_id ); $language = $post->get_language_code(); $this->sitepress->switch_lang( $language ); $custom_field_data = get_post_meta( $post_id, $this->elementor_settings->get_meta_field() ); if ( ! $custom_field_data ) { return; } $custom_field_data = $this->elementor_settings->convert_data_to_array( $custom_field_data ); $custom_field_data_adjusted = $this->set_global_widget_id_for_language( $custom_field_data, $language ); if ( $custom_field_data_adjusted !== $custom_field_data ) { update_post_meta( $post_id, $this->elementor_settings->get_meta_field(), $this->elementor_settings->prepare_data_for_saving( $custom_field_data_adjusted ) ); // Update post date so Elementor doesn't use auto saved post $post_data = get_post( $post_id, ARRAY_A ); $post_data['post_date'] = current_time( 'mysql' ); $post_data['post_date_gmt'] = ''; wp_update_post( $post_data ); } } private function set_global_widget_id_for_language( $data_array, $language ) { foreach ( $data_array as &$data ) { if ( isset( $data['elType'] ) && 'widget' === $data['elType'] && 'global' === $data['widgetType'] ) { try { $widget_post = $this->translation_element_factory->create_post( $data['templateID'] ); if ( $widget_post->get_language_code() !== $language ) { $translation = $widget_post->get_translation( $language ); if ( $translation ) { $data['templateID'] = $translation->get_element_id(); } } } catch ( Exception $e ) { // Not much we can do if the elementor templateID is a non existing post } } $data['elements'] = $this->set_global_widget_id_for_language( $data['elements'], $language ); } return $data_array; } public function restore_current_language() { $this->sitepress->switch_lang( $this->current_language ); } /** * The snippet is a WHERE condition which is added to a DB query. * This will include the source element in the query results in case the element * does not exist in the current language. * * @see WPML_Query_Filter::display_as_translated_snippet * * @param bool $display_as_translated * @param array $post_types * * @return bool */ public function should_use_display_as_translated_snippet( $display_as_translated, $post_types ) { if ( isset( $_GET['action'] ) && 'elementor' === $_GET['action'] && in_array( 'elementor_library', array_keys( $post_types ), true ) ) { return true; } return $display_as_translated; } /** * @param string $content * * @return string */ public function duplicate_css_class_with_original_id( $content ) { $classPrefixes = wpml_collect( [ 'elementor-', 'elementor-global-', ] )->implode( '|' ); return preg_replace_callback( '/(class=".*(' . $classPrefixes . '))(\d+)/', array( $this, 'convert_id_to_original' ), $content ); } private function convert_id_to_original( array $matches ) { $class_prefix = $matches[2]; $id = (int)$matches[3]; $element = $this->translation_element_factory->create_post( $id ); $source = $element->get_source_element(); if ( $source ) { $new_class = $class_prefix . $source->get_id(); $search = $matches[0]; $replace = $search . ' ' . $new_class; $matches[0] = str_replace( $search, $replace, $matches[0] ); } return $matches[0]; } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-urls.php 0000755 00000004777 14720415745 0024102 0 ustar 00 <?php class WPML_Elementor_URLs implements IWPML_Action { /** @var WPML_Translation_Element_Factory */ private $element_factory; /** @var IWPML_URL_Converter_Strategy */ private $language_converter; /** @var IWPML_Current_Language */ private $current_language; public function __construct( WPML_Translation_Element_Factory $element_factory, IWPML_URL_Converter_Strategy $language_converter, IWPML_Current_Language $current_language ) { $this->element_factory = $element_factory; $this->language_converter = $language_converter; $this->current_language = $current_language; } public function add_hooks() { add_filter( 'elementor/document/urls/edit', array( $this, 'adjust_edit_with_elementor_url' ), 10, 2 ); add_filter( 'wpml_is_pagination_url_in_post', [ $this, 'is_pagination_url' ], 10, 3 ); add_filter( 'paginate_links', [ $this, 'fix_pagination_link_with_language_param' ], 10, 1 ); } public function adjust_edit_with_elementor_url( $url, $elementor_document ) { $post = $elementor_document->get_main_post(); $post_element = $this->element_factory->create_post( $post->ID ); $post_language = $post_element->get_language_code(); if ( ! $post_language ) { $post_language = $this->current_language->get_current_language(); } return $this->language_converter->convert_admin_url_string( $url, $post_language ); } /** * Check if the given URL is the pagination inside the post. * * @param bool $is_pagination_url_in_post * @param string $url URL to check * @param string $post_name Current post name * * @return bool */ public function is_pagination_url( $is_pagination_url_in_post, $url, $post_name ) { $post_name = preg_quote( $post_name, '/' ); return $is_pagination_url_in_post || ( WPML_Elementor_Data_Settings::is_edited_with_elementor( get_the_ID() ) && ( preg_match_all( "/{$post_name}\/([\d]*)\/$/", $url ) || preg_match_all( "/{$post_name}\/([\d]*)\/\?lang=([a-zA-Z_-]*)$/", $url ) ) ); } public function fix_pagination_link_with_language_param( $link ) { $post = get_post( get_the_ID() ); if ( $post && WPML_Elementor_Data_Settings::is_edited_with_elementor( $post->ID ) && preg_match_all( "/{$post->post_name}\/\?lang=([a-zA-Z_-]*)\/([\d]*)\/$/", $link ) ) { $link = $this->language_converter->convert_url_string( preg_replace( "/\?lang=([a-zA-Z_-]*)\//", '', $link ), $this->current_language->get_current_language() ); } return $link; } } wpml-page-builders/classes/Integrations/Elementor/DynamicContent/Strings.php 0000755 00000016604 14720415745 0023405 0 ustar 00 <?php namespace WPML\PB\Elementor\DynamicContent; use WPML\Collect\Support\Collection; use WPML_Elementor_Translatable_Nodes; use WPML_PB_String; class Strings { const KEY_SETTINGS = WPML_Elementor_Translatable_Nodes::SETTINGS_FIELD; const KEY_DYNAMIC = '__dynamic__'; const KEY_NODE_ID = 'id'; const KEY_ITEM_ID = '_id'; const SETTINGS_REGEX = '/settings="(.*?(?="]))/'; const NAME_PREFIX = 'dynamic'; const DELIMITER = '-'; const TRANSLATABLE_SETTINGS = [ 'before', 'after', 'fallback', 'video_url', 'shortcode', ]; /** * Remove the strings overwritten with dynamic content * and add the extra strings "before", "after" and "fallback". * * @param WPML_PB_String[] $strings * @param string $nodeId * @param array $element * * @return WPML_PB_String[] */ public static function filter( array $strings, $nodeId, array $element ) { $dynamicFields = self::getDynamicFields( $element ); $updateFromDynamicFields = function( WPML_PB_String $string ) use ( &$dynamicFields ) { $matchingField = $dynamicFields->first( function( Field $field ) use ( $string ) { return $field->isMatchingStaticString( $string ); } ); if ( $matchingField ) { return self::addBeforeAfterAndFallback( wpml_collect( [ $dynamicFields->pull( $dynamicFields->search( $matchingField ) ) ] ) ); } return $string; }; return wpml_collect( $strings ) ->map( $updateFromDynamicFields ) ->merge( self::addBeforeAfterAndFallback( $dynamicFields ) ) ->flatten() ->toArray(); } /** * @param array $element * * @return Collection */ private static function getDynamicFields( array $element ) { if ( self::isModuleWithItems( $element ) ) { return self::getDynamicFieldsForModuleWithItems( $element ); } elseif ( isset( $element[ self::KEY_SETTINGS ][ self::KEY_DYNAMIC ] ) ) { return self::getFields( $element[ self::KEY_SETTINGS ][ self::KEY_DYNAMIC ], $element[ self::KEY_NODE_ID ] ); } return wpml_collect(); } /** * @param array $element * * @return Collection */ private static function getDynamicFieldsForModuleWithItems( array $element ) { $isDynamic = function( $item ) { return isset( $item[ self::KEY_DYNAMIC ] ); }; $getFields = function( array $item ) use ( $element ) { return self::getFields( $item[ self::KEY_DYNAMIC ], $element[ self::KEY_NODE_ID ], $item[ self::KEY_ITEM_ID ] ); }; return wpml_collect( reset( $element[ self::KEY_SETTINGS ] ) ) ->filter( $isDynamic ) ->map( $getFields ) ->flatten(); } /** * @param array $data * @param string $nodeId * @param string $itemId * * @return Collection */ private static function getFields( array $data, $nodeId, $itemId = '' ) { $buildField = function( $tagValue, $tagKey ) use ( $nodeId, $itemId ) { return new Field( $tagValue, $tagKey, $nodeId, $itemId ); }; return wpml_collect( $data )->map( $buildField ); } /** * @param array $element * * @return bool */ private static function isModuleWithItems( array $element ) { if ( isset( $element[ self::KEY_SETTINGS ] ) ) { $firstSettingElement = reset( $element[ self::KEY_SETTINGS ] ); return is_array( $firstSettingElement ) && 0 === key( $firstSettingElement ); } return false; } /** * @param Collection $dynamicFields * * @return Collection */ private static function addBeforeAfterAndFallback( Collection $dynamicFields ) { $dynamicFieldToSettingStrings = function( Field $field ) { preg_match( self::SETTINGS_REGEX, $field->tagValue, $matches ); $isTranslatableSetting = function( $value, $settingField ) { return $value && is_string( $value ) && in_array( $settingField, self::TRANSLATABLE_SETTINGS, true ); }; $buildStringFromSetting = function( $value, $settingField ) use ( $field ) { return new WPML_PB_String( $value, self::getStringName( $field->nodeId, $field->itemId, $field->tagKey, $settingField ), sprintf( __( 'Dynamic content string: %s', 'sitepress' ), $field->tagKey ), 'LINE' ); }; return wpml_collect( isset( $matches[1] ) ? self::decodeSettings( $matches[1] ) : [] ) ->filter( $isTranslatableSetting ) ->map( $buildStringFromSetting ); }; return $dynamicFields->map( $dynamicFieldToSettingStrings ); } /** * @param array $element * @param WPML_PB_String $string * * @return array */ public static function updateNode( array $element, WPML_PB_String $string ) { $stringNameParts = explode( self::DELIMITER, $string->get_name() ); if ( count( $stringNameParts ) !== 5 || self::NAME_PREFIX !== $stringNameParts[0] ) { return $element; } list( , , $itemId, $dynamicField, $settingField ) = $stringNameParts; if ( $itemId && self::isModuleWithItems( $element ) ) { $element = self::updateNodeWithItems( $element, $string, $stringNameParts ); } elseif ( isset( $element[ self::KEY_SETTINGS ][ self::KEY_DYNAMIC ][ $dynamicField ] ) ) { $element[ self::KEY_SETTINGS ][ self::KEY_DYNAMIC ][ $dynamicField ] = self::replaceSettingString( $element[ self::KEY_SETTINGS ][ self::KEY_DYNAMIC ][ $dynamicField ], $string, $settingField ); } return $element; } /** * @param string $encodedSettings * @param WPML_PB_String $string * @param string $settingField * * @return string|null */ private static function replaceSettingString( $encodedSettings, WPML_PB_String $string, $settingField ) { $replace = function( array $matches ) use ( $string, $settingField ) { $settings = self::decodeSettings( $matches[1] ); $settings[ $settingField ] = $string->get_value(); $replace = urlencode( json_encode( $settings ) ); return str_replace( $matches[1], $replace, $matches[0] ); }; return preg_replace_callback( self::SETTINGS_REGEX, $replace, $encodedSettings ); } /** * @param array $element * @param WPML_PB_String $string * @param array $stringNameParts * * @return array */ private static function updateNodeWithItems( array $element, WPML_PB_String $string, array $stringNameParts ) { list( , , $itemId, $dynamicField, $settingField ) = $stringNameParts; $items = wpml_collect( reset( $element[ self::KEY_SETTINGS ] ) ); $mainKey = key( $element[ self::KEY_SETTINGS ] ); $replaceStringInItem = function( array $item ) use ( $itemId, $string, $dynamicField, $settingField ) { if ( isset( $item[ self::KEY_DYNAMIC ][ $dynamicField ], $item[ self::KEY_ITEM_ID ] ) && $item[ self::KEY_ITEM_ID ] === $itemId ) { $item[ self::KEY_DYNAMIC ][ $dynamicField ] = self::replaceSettingString( $item[ self::KEY_DYNAMIC ][ $dynamicField ], $string, $settingField ); } return $item; }; $element[ self::KEY_SETTINGS ][ $mainKey ] = $items->map( $replaceStringInItem )->toArray(); return $element; } /** * @param string $settingsString * * @return array */ private static function decodeSettings( $settingsString ) { return json_decode( urldecode( $settingsString ), true ); } /** * @param string $nodeId * @param string $itemId * @param string $tagKey * @param string $settingField * * @return string */ public static function getStringName( $nodeId, $itemId, $tagKey, $settingField ) { return self::NAME_PREFIX . self::DELIMITER . $nodeId . self::DELIMITER . $itemId . self::DELIMITER . $tagKey . self::DELIMITER . $settingField; } } wpml-page-builders/classes/Integrations/Elementor/DynamicContent/Field.php 0000755 00000002433 14720415745 0022772 0 ustar 00 <?php namespace WPML\PB\Elementor\DynamicContent; use WPML_PB_String; class Field { /** * e.g. '[elementor-tag id="cc0b6c6" name="post-title" settings="ENCODED_STRING"]' * * @var string $tagValue */ public $tagValue; /** * e.g. 'title' * * @var string $tagKey */ public $tagKey; /** * The node ID. * * @var string $nodeId */ public $nodeId; /** * The item ID inside the node with items. * * @var string $itemId */ public $itemId; /** * @param string $tagValue * @param string $tagKey * @param string $nodeId * @param string $itemId */ public function __construct( $tagValue, $tagKey, $nodeId, $itemId = '' ) { $this->tagValue = $tagValue; $this->tagKey = $tagKey; $this->nodeId = $nodeId; $this->itemId = $itemId; } /** * @see \WPML_Elementor_Translatable_Nodes::get_string_name() * @see \WPML_Elementor_Module_With_Items::get_string_name() * * @param WPML_PB_String $string * * @return bool */ public function isMatchingStaticString( WPML_PB_String $string ) { $pattern = '/^' . $this->tagKey . '-.*-' . $this->nodeId . '$/'; if ( $this->itemId ) { $pattern = '/^' . $this->tagKey . '-.*-' . $this->nodeId . '-' . $this->itemId . '$/'; } return (bool) preg_match( $pattern, $string->get_name() ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-db-factory.php 0000755 00000000743 14720415745 0025134 0 ustar 00 <?php class WPML_Elementor_DB_Factory { /** * @return null|WPML_Elementor_DB */ public function create() { $wpml_elementor_db = null; if ( version_compare( phpversion(), '5.3.0', '>=' ) && class_exists( '\Elementor\DB' ) ) { // @codingStandardsIgnoreLine $elementor_db = new \Elementor\DB(); if ( method_exists( $elementor_db, 'save_plain_text' ) ) { $wpml_elementor_db = new WPML_Elementor_DB( $elementor_db ); } } return $wpml_elementor_db; } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-urls-factory.php 0000755 00000000521 14720415745 0025526 0 ustar 00 <?php class WPML_Elementor_URLs_Factory implements IWPML_Backend_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { global $sitepress, $wpml_url_converter; return new WPML_Elementor_URLs( new WPML_Translation_Element_Factory( $sitepress ), $wpml_url_converter->get_strategy(), $sitepress ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-data-settings.php 0000755 00000006636 14720415745 0025660 0 ustar 00 <?php use WPML\PB\AutoUpdate\Settings as AutoUpdateSettings; use WPML\PB\Elementor\DataConvert; class WPML_Elementor_Data_Settings implements IWPML_Page_Builders_Data_Settings { const META_KEY_DATA = '_elementor_data'; const META_KEY_MODE = '_elementor_edit_mode'; /** * @var WPML_Elementor_DB|null */ private $elementor_db; public function __construct( WPML_Elementor_DB $elementor_db = null ) { $this->elementor_db = $elementor_db; } public function add_hooks() { add_filter( 'wpml_custom_field_values_for_post_signature', array( $this, 'add_data_custom_field_to_md5' ), 10, 2 ); add_filter( 'wpml_pb_copy_meta_field', array( $this, 'mark_css_field_as_empty' ), 10, 4 ); if ( $this->elementor_db ) { add_action( 'wpml_page_builder_string_translated', array( $this, 'save_post_body_as_plain_text' ), 11, 5 ); } } /** * @param array $value * @param int $translated_post_id * @param int $original_post_id * @param string $meta_key * * @return mixed */ public function mark_css_field_as_empty( $value, $translated_post_id, $original_post_id, $meta_key ) { if ( '_elementor_css' === $meta_key && is_array( $value ) ) { if ( ! isset( $value['status'] ) ) { $value = current( $value ); $value['status'] = ''; $value = array( $value ); } else { $value['status'] = ''; } } return $value; } public function save_post_body_as_plain_text( $type, $post_id, $original_post, $string_translations, $lang ) { if ( $this->is_handling_post( $post_id ) ) { $this->elementor_db->save_plain_text( $post_id ); } } /** * @return string */ public function get_meta_field() { return self::META_KEY_DATA; } /** * @return string */ public function get_node_id_field() { return 'id'; } /** * @return array */ public function get_fields_to_copy() { return [ '_elementor_version', self::META_KEY_MODE, '_elementor_css', '_elementor_template_type', '_elementor_template_widget_type', '_elementor_popup_display_settings', ]; } /** * @param array|string $data * * @return array */ public function convert_data_to_array( $data ) { return DataConvert::unserialize( $data ); } /** * @param array $data * * @return string */ public function prepare_data_for_saving( array $data ) { return DataConvert::serialize( $data ); } /** * @return string */ public function get_pb_name() { return 'Elementor'; } /** * @return array */ public function get_fields_to_save() { return array( '_elementor_data' ); } /** * @param array $custom_fields_values * @param int $post_id * * @return array */ public function add_data_custom_field_to_md5( array $custom_fields_values, $post_id ) { if ( AutoUpdateSettings::isEnabled() ) { unset( $custom_fields_values[ $this->get_meta_field() ] ); } else { $custom_fields_values[ $this->get_meta_field() ] = get_post_meta( $post_id, $this->get_meta_field(), true ); } return $custom_fields_values; } /** * @param int $postId * * @return bool */ public function is_handling_post( $postId ) { return (bool) get_post_meta( $postId, $this->get_meta_field(), true ) && self::is_edited_with_elementor( $postId ); } /** * @param int $postId * * @return bool */ public static function is_edited_with_elementor( $postId ) { return 'builder' === get_post_meta( $postId, self::META_KEY_MODE, true ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-translate-ids.php 0000755 00000011403 14720415745 0025647 0 ustar 00 <?php use WPML\FP\Obj; use WPML\FP\Str; use WPML\FP\Fns; use function WPML\FP\pipe; /** * Class WPML_Elementor_Translate_IDs */ class WPML_Elementor_Translate_IDs implements IWPML_Action { /** @var \WPML\Utils\DebugBackTrace */ private $debug_backtrace; /** * WPML_Elementor_Translate_IDs constructor. * * @param \WPML\Utils\DebugBackTrace $debug_backtrace */ public function __construct( \WPML\Utils\DebugBackTrace $debug_backtrace ) { $this->debug_backtrace = $debug_backtrace; } public function add_hooks() { add_filter( 'elementor/theme/get_location_templates/template_id', array( $this, 'translate_theme_location_template_id' ) ); add_filter( 'elementor/theme/get_location_templates/condition_sub_id', array( $this, 'translate_location_condition_sub_id' ), 10, 2 ); add_filter( 'elementor/documents/get/post_id', array( $this, 'translate_template_id', ) ); add_filter( 'elementor/frontend/builder_content_data', array( $this, 'translate_global_widget_ids' ), 10, 2 ); add_filter( 'elementor/frontend/builder_content_data', array( $this, 'translate_product_ids' ), 10, 2 ); } public function translate_theme_location_template_id( $template_id ) { return $this->translate_id( $template_id ); } /** * @param int|string $sub_id * @param array $parsed_condition * * @return int|string */ public function translate_location_condition_sub_id( $sub_id, $parsed_condition ) { /** * `$sub_name` gives a context for the `$sub_id`, it can be either: * - `child_of` * - `in_{taxonomy}` * - `in_{taxonomy}_children` * - `{post_type}` * - `{taxonomy}` */ $sub_name = isset( $parsed_condition['sub_name'] ) ? $parsed_condition['sub_name'] : null; if ( (int) $sub_id > 0 && $sub_name ) { $startsWith = Str::startsWith( Fns::__, $sub_name ); $getType = Str::pregReplace( Fns::__, '', $sub_name ); $findReplace = wpml_collect( [ 'in_' => '/^in_|_children$/', 'child_of_' => '/^child_of_/', 'any_child_of_' => '/^any_child_of_/', ] ); if ( 'child_of' === $sub_name ) { $element_type = get_post_type( $sub_id ); } else { $element_type = $findReplace ->filter( pipe( Fns::nthArg( 1 ), $startsWith ) ) ->map( $getType ) ->first( Fns::identity(), $sub_name ); } $sub_id = $this->translate_id( $sub_id, $element_type ); } return $sub_id; } public function translate_template_id( $template_id ) { if ( $this->is_WP_widget_call() || $this->is_shortcode_call() || $this->is_template_widget_call() ) { $template_id = $this->translate_id( $template_id ); } return $template_id; } private function is_WP_widget_call() { return $this->debug_backtrace->is_class_function_in_call_stack( 'ElementorPro\Modules\Library\WP_Widgets\Elementor_Library', 'widget' ); } private function is_shortcode_call() { return $this->debug_backtrace->is_class_function_in_call_stack( 'ElementorPro\Modules\Library\Classes\Shortcode', 'shortcode' ); } private function is_template_widget_call() { return $this->debug_backtrace->is_class_function_in_call_stack( 'ElementorPro\Modules\Library\Widgets\Template', 'render' ); } public function translate_global_widget_ids( $data_array, $post_id ) { foreach ( $data_array as &$data ) { if ( isset( $data['elType'] ) && 'widget' === $data['elType'] ) { if ( 'global' === $data['widgetType'] ) { $data['templateID'] = $this->translate_id( $data['templateID'] ); } elseif ( 'template' === $data['widgetType'] ) { $data['settings']['template_id'] = $this->translate_id( $data['settings']['template_id'] ); } } $data['elements'] = $this->translate_global_widget_ids( $data['elements'], $post_id ); } return $data_array; } /** * @param array $data_array * @param int $post_id * * @return array */ public function translate_product_ids( $data_array, $post_id ) { foreach ( $data_array as &$data ) { if ( Obj::prop( 'elType', $data ) === 'widget' && Obj::prop( 'widgetType', $data ) === 'wc-add-to-cart' && Obj::propOr( false, 'product_id', $data['settings'] ) ) { $data['settings']['product_id'] = $this->translate_id( $data['settings']['product_id'] ); } $data['elements'] = $this->translate_product_ids( $data['elements'], $post_id ); } return $data_array; } /** * @param int|string $element_id * @param string $element_type * * @return int */ private function translate_id( $element_id, $element_type = null ) { if ( ! $element_type || 'any_child_of' === $element_type ) { $element_type = get_post_type( $element_id ); } $translated_id = apply_filters( 'wpml_object_id', $element_id, $element_type, true ); if ( is_string( $element_id ) ) { $translated_id = (string) $translated_id; } return $translated_id; } } wpml-page-builders/classes/Integrations/Elementor/Hooks/WooCommerce.php 0000755 00000000652 14720415745 0022333 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Fns; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class WooCommerce implements \IWPML_Frontend_Action { public function add_hooks() { Hooks::onFilter( 'option_elementor_woocommerce_purchase_summary_page_id' ) ->then( spreadArgs( Fns::memorize( function( $pageId ) { return apply_filters( 'wpml_object_id', $pageId, 'page', true ); } ) ) ); } } wpml-page-builders/classes/Integrations/Elementor/Hooks/FormPopup.php 0000755 00000002500 14720415745 0022035 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class FormPopup implements \IWPML_Frontend_Action, \IWPML_AJAX_Action { public function add_hooks() { $isElementorFormAjaxSubmit = Relation::propEq( 'action', 'elementor_pro_forms_send_form' ); if ( $isElementorFormAjaxSubmit( $_POST ) ) { Hooks::onAction( 'elementor_pro/forms/new_record', 10, 2 ) ->then( spreadArgs( [ $this, 'convertFormPopupIdAjax' ] ) ); } } /** * @param \ElementorPro\Modules\Forms\Classes\Form_Record $record An instance of the form record. * @param \ElementorPro\Modules\Forms\Classes\Ajax_Handler $ajaxHandler An instance of the ajax handler. */ public function convertFormPopupIdAjax ( $record, $ajaxHandler ) { if ( Obj::path( [ 'data', 'popup', 'id' ], $ajaxHandler ) ) { $popup = Obj::path( [ 'data', 'popup'], $ajaxHandler ); $getCurrentLanguageFromPost = function () { return Obj::prop( 'language_code', apply_filters( 'wpml_post_language_details', null, sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) ) ); }; $popup['id'] = apply_filters( 'wpml_object_id', $popup['id'], get_post_type( $popup['id'] ), false, $getCurrentLanguageFromPost() ); $ajaxHandler->add_response_data( 'popup', $popup ); } } } wpml-page-builders/classes/Integrations/Elementor/Hooks/WordPressWidgets.php 0000755 00000000474 14720415745 0023375 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\LIB\WP\Hooks; class WordPressWidgets implements \IWPML_Backend_Action { public function add_hooks() { Hooks::onAction( 'wp_ajax_elementor_ajax' ) ->then( function() { add_filter( 'wpml_widget_language_selector_disable', '__return_true' ); } ); } } wpml-page-builders/classes/Integrations/Elementor/Hooks/LandingPages.php 0000755 00000006562 14720415745 0022456 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; use function WPML\FP\pipe; class LandingPages implements \IWPML_Frontend_Action, \IWPML_Backend_Action, \IWPML_DIC_Action { const POST_TYPE = 'e-landing-page'; const BACKUP_HOOK_PRIORITY = 11; /** @var \SitePress $sitepress */ private $sitepress; public function __construct( \SitePress $sitepress ) { $this->sitepress = $sitepress; } public function add_hooks() { if ( get_option( 'permalink_structure' ) ) { add_filter( 'post_type_link', [ $this, 'adjustLink' ], PHP_INT_MAX, 2 ); Hooks::onFilter( 'pre_handle_404', self::BACKUP_HOOK_PRIORITY, 2 ) ->then( spreadArgs( [ $this, 'backupQuery' ] ) ); } } /** * @see \Elementor\Modules\LandingPages\Module::remove_post_type_slug * * @param string $postUrl * @param \WP_Post $post * * @return string */ public function adjustLink( $postUrl, $post ) { if ( self::POST_TYPE !== $post->post_type || 'publish' !== $post->post_status ) { return $postUrl; } $homeUrl = get_home_url(); $urlParts = wp_parse_url( $homeUrl ); $urlParts['path'] = trailingslashit( Obj::prop( 'path', $urlParts ) ) . $post->post_name . '/'; $newPostUrl = http_build_url( null, $urlParts ); $postLangCode = $this->sitepress->get_language_for_element( $post->ID, 'post_' . self::POST_TYPE ); return $this->sitepress->convert_url( $newPostUrl, $postLangCode ); } /** * Backup and restore the global $wp_query that was overwritten by Elementor. * * In order for Elementor to treat landing pages(post_type: e-landing-page) as pages, it overwrites the global * $wp_query when using the /%category%/%postname%/ permalink structure. * WPML then resets the global $wp_query in SitePress::get_ls_languages() and this causes 404 errors on landing pages * and prevents editing them in the Elementor editor. * * In this case, we backup the global $wp_query when Elementor overwrites it on 'pre_handle_404' hook, and we restore * it after WPML resets it on 'wp_head' hook. * * @see \WPML_SEO_HeadLangs::head_langs() * @see \SitePress::get_ls_languages() * @see \Elementor\Modules\LandingPages\Module::handle_404 * * @param bool $value * @param \WP_Query $query * * @return bool */ public function backupQuery( $value, $query ) { global $wp_query; if ( $value ) { return $value; } // $wasModifiedByElementor :: \WP_Query -> bool $wasModifiedByElementor = pipe( Obj::prop( 'query' ), Relation::propEq( 'post_type', self::POST_TYPE ) ); // $hasPosts :: \WP_Query -> array $hasPosts = Obj::prop( 'posts' ); if ( $query->is_main_query() && empty( $query->posts ) && ! empty( $query->query['category_name'] ) && empty( $query->tax_query->table_aliases ) && $wasModifiedByElementor( $wp_query ) && $hasPosts( $wp_query ) ) { if ( apply_filters( 'wpml_sub_setting', 1, 'seo', 'head_langs' ) ) { $wpQueryBackup = clone $wp_query; $priority = (int) apply_filters( 'wpml_sub_setting', 1, 'seo', 'head_langs_priority' ); Hooks::onAction( 'wp_head', $priority + 1 ) ->then( function() use ( $wpQueryBackup ) { global $wp_query; $wp_query = $wpQueryBackup; //phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited } ); } } return false; } } wpml-page-builders/classes/Integrations/Elementor/Hooks/Templates.php 0000755 00000003175 14720415745 0022055 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\API\PostTypes; use WPML\Settings\PostType\Automatic; use WPML\Setup\Option; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Templates implements \IWPML_Frontend_Action, \IWPML_Backend_Action { const POST_TYPE = 'elementor_library'; /** * @return void */ public function add_hooks() { Hooks::onFilter( 'elementor/theme/conditions/cache/regenerate/query_args' ) ->then( spreadArgs( Obj::assoc( 'suppress_filters', true ) ) ); if ( \is_admin() && self::shouldUpdateTemplatesOption() ) { Hooks::onAction( 'init' ) ->then( [ self::class, 'setTemplatesAutomaticallyTranslatable' ] ); } } /** * @return bool */ private static function shouldUpdateTemplatesOption() { if ( ! Option::getTranslateEverything() ) { return false; } $templatesOptionIsUnlocked = apply_filters( 'wpml_sub_setting', false, 'custom_posts_unlocked_option', self::POST_TYPE ); if ( $templatesOptionIsUnlocked ) { return false; } $translatableOnlyPostTypes = PostTypes::getOnlyTranslatable(); if ( ! in_array( self::POST_TYPE, $translatableOnlyPostTypes, true ) ) { return true; } return false; } /** * @return void */ public static function setTemplatesAutomaticallyTranslatable() { $settingsHelper = wpml_load_settings_helper(); $settingsHelper->set_post_type_translatable( self::POST_TYPE ); // If the option is locked, WPML will overwrite its option to display_as_translated in WPML->Settings. $settingsHelper->set_post_type_translation_unlocked_option( self::POST_TYPE, true ); Automatic::set( self::POST_TYPE, true ); } } wpml-page-builders/classes/Integrations/Elementor/Hooks/GutenbergCleanup.php 0000755 00000004422 14720415745 0023345 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Fns; use WPML\FP\Logic; use WPML\FP\Maybe; use WPML\FP\Relation; use WPML\PB\Elementor\DataConvert; use WPML\PB\GutenbergCleanup\Package; use WPML_Elementor_Data_Settings; use function WPML\FP\curryN; use function WPML\FP\pipe; class GutenbergCleanup implements \IWPML_Backend_Action, \IWPML_Frontend_Action { public function add_hooks() { add_filter( 'update_post_metadata', Fns::withoutRecursion( Fns::identity(), [ $this, 'removeGutenbergFootprint' ] ), 10, 4 ); } /** * If we detect Gutenberg footprint in the Elementor data, * we'll remove it and delete the Gutenberg string package. * * @param null|bool $check * @param int $postId * @param string $metaKey * @param string $metaValue * * @return mixed */ public function removeGutenbergFootprint( $check, $postId, $metaKey, $metaValue ) { if ( WPML_Elementor_Data_Settings::META_KEY_DATA === $metaKey && WPML_Elementor_Data_Settings::is_edited_with_elementor( $postId ) ) { // $ifValueHasChanged :: string -> bool $ifValueHasChanged = pipe( Relation::equals( $metaValue ), Logic::not() ); // $update :: int -> string -> bool $update = curryN( 2, function( $postId, $meta ) { // Do not use update_post_meta, we need update meta for revisions too. update_metadata( 'post', $postId, WPML_Elementor_Data_Settings::META_KEY_DATA, $meta ); Package::delete( Package::get( $postId ) ); return true; } ); return Maybe::of( $metaValue ) ->map( [ DataConvert::class, 'unserialize' ] ) ->map( [ $this, 'removeBlockMetaInEditorWidget' ] ) ->map( [ DataConvert::class, 'serialize' ] ) ->filter( $ifValueHasChanged ) ->map( $update( $postId ) ) ->getOrElse( $check ); } return $check; } /** * @param array $data * * @return array */ public function removeBlockMetaInEditorWidget( array $data ) { foreach ( $data as &$element ) { if ( $element['elements'] ) { $element['elements'] = $this->removeBlockMetaInEditorWidget( $element['elements'] ); } elseif ( 'widget' === $element['elType'] && isset( $element['settings']['editor'] ) ) { $element['settings']['editor'] = preg_replace( '(<!--[^<]*-->)', '', $element['settings']['editor'] ); } } return $data; } } wpml-page-builders/classes/Integrations/Elementor/Hooks/CssCache.php 0000755 00000001540 14720415745 0021565 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class CssCache implements \IWPML_Frontend_Action, \IWPML_Backend_Action { const TEMPLATES_POST_TYPE = 'elementor_library'; /** * @return void */ public function add_hooks() { Hooks::onAction( 'wpml_translation_job_saved' ) ->then( spreadArgs( [ self::class, 'flushCache' ] ) ); } /** * @param int $postId * * @return void */ public static function flushCache( $postId ) { $post = get_post( $postId ); if ( self::TEMPLATES_POST_TYPE === Obj::prop( 'post_type', $post ) ) { try { $fileManager = \WPML\Container\make( \Elementor\Core\Files\Manager::class ); if ( $fileManager && method_exists( $fileManager, 'clear_cache' ) ) { $fileManager->clear_cache(); } } catch ( \Exception $e ) {} } } } wpml-page-builders/classes/Integrations/Elementor/Hooks/DynamicElements.php 0000755 00000006710 14720415745 0023176 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Obj; use WPML\PB\Elementor\Config\DynamicElements\Provider; use function WPML\FP\curryN; use function WPML\FP\spreadArgs; class DynamicElements implements \IWPML_Frontend_Action, \IWPML_DIC_Action { public function add_hooks() { add_filter( 'elementor/frontend/builder_content_data', [ $this, 'convert' ] ); } /** * @param array $data * * @return array */ public function convert( array $data ) { // $convertTag :: (curried) string -> string -> string -> string $convertTag = curryN( 3, [ __CLASS__, 'convertTag' ] ); // $assignConvertCallable :: (callable, callable, string|null, string|null) -> array $assignConvertCallable = function( $shouldConvert, $lens, $allowedTag = null, $idKey = null ) use ( $convertTag ) { if ( $allowedTag && $idKey ) { $convert = $convertTag( $allowedTag, $idKey ); } else { $convert = [ __CLASS__, 'convertId' ]; } return [ $shouldConvert, Obj::over( $lens, $convert ) ]; }; /** * Filter widget dynamic id conversion configuration. * * Gather conversion configuration for Elementor widget dynamic ids. * The id can be stored in a widget key, or in a shortcode string. * * @since 2.0.4 * * @param array $args { * @type array $configuration { * Conversion configuration. * * @type callable $shouldConvert Check if the widget should be converted. * @type callable $keyLens Lens to the key that holds the dynamic id. * @type string $tagName Optional. Shortcode name attribute. * @type string $idKey Optional. Id key in the shortcode's settings attribute. * } * } */ $converters = apply_filters( 'wpml_pb_elementor_widget_dynamic_id_converters', Provider::get() ); $converters = wpml_collect( $converters ) ->map( spreadArgs( $assignConvertCallable ) ) ->toArray(); return $this->applyConverters( $data, $converters ); } /** * @param array $data * @param array $converters * * @return array */ private function applyConverters( $data, $converters ) { foreach ( $data as &$item ) { foreach ( $converters as $converter ) { list( $shouldConvert, $convert ) = $converter; if ( $shouldConvert( $item ) ) { $item = $convert( $item ); } } $item['elements'] = $this->applyConverters( $item['elements'], $converters ); } return $data; } /** * @param string $allowedTag * @param string $idKey * @param string|null $tagString * * @return string|null */ public static function convertTag( $allowedTag, $idKey, $tagString ) { if ( ! $tagString ) { return $tagString; } preg_match( '/name="(.*?(?="))"/', $tagString, $tagNameMatch ); if ( ! $tagNameMatch || $tagNameMatch[1] !== $allowedTag ) { return $tagString; } return preg_replace_callback( '/settings="(.*?(?="]))/', function( array $matches ) use ( $idKey ) { $settings = json_decode( urldecode( $matches[1] ), true ); if ( ! isset( $settings[ $idKey ] ) ) { return $matches[0]; } $settings[ $idKey ] = self::convertId( $settings[ $idKey ] ); $replace = urlencode( json_encode( $settings ) ); return str_replace( $matches[1], $replace, $matches[0] ); }, $tagString ); } /** * @param int $elementId * * @return int */ public static function convertId( $elementId ) { return apply_filters( 'wpml_object_id', $elementId, get_post_type( $elementId ), true ); } } wpml-page-builders/classes/Integrations/Elementor/Hooks/Editor.php 0000755 00000001165 14720415745 0021342 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Editor implements \IWPML_Backend_Action { public function add_hooks() { Hooks::onFilter( 'wpml_pb_is_editing_translation_with_native_editor', 10, 2 ) ->then( spreadArgs( function( $isTranslationWithNativeEditor, $translatedPostId ) { return $isTranslationWithNativeEditor || ( (int) Obj::prop( 'editor_post_id', $_POST ) === $translatedPostId && Relation::propEq( 'action', 'elementor_ajax', $_POST ) ); } ) ); } } wpml-page-builders/classes/Integrations/Elementor/Hooks/DomainsWithMultisite.php 0000755 00000002427 14720415745 0024244 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; use WPML\PB\Helper\LanguageNegotiation; class DomainsWithMultisite implements \IWPML_Backend_Action { public function add_hooks() { if ( is_multisite() && LanguageNegotiation::isUsingDomains() ) { Hooks::onAction( 'elementor/editor/init' ) ->then( spreadArgs( [ $this, 'onElementorEditor' ] ) ); } } public function onElementorEditor() { $isCurrentLangDifferentThanDefault = apply_filters( 'wpml_current_language', null ) !== apply_filters( 'wpml_default_language', null ); if ( $isCurrentLangDifferentThanDefault ) { Hooks::onFilter( 'admin_url' ) ->then( spreadArgs( [ $this, 'filterUrl' ] ) ); } } /** * @param string $url The admin area URL. */ public function filterUrl( $url ) { $parsedUrl = wpml_parse_url( $url ); if ( is_array( $parsedUrl ) && ! empty( $parsedUrl['host'] ) ) { return http_build_url( Obj::assoc( 'host', $_SERVER['HTTP_HOST'], $parsedUrl ) ); } return $url; } private static function isUsingDomains() { return apply_filters( 'wpml_setting', [], 'language_domains' ) && constant( 'WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN' ) === (int) apply_filters( 'wpml_setting', 1, 'language_negotiation_type' ); } } wpml-page-builders/classes/Integrations/Elementor/Hooks/Frontend.php 0000755 00000002531 14720415745 0021671 0 ustar 00 <?php namespace WPML\PB\Elementor\Hooks; use WPML\FP\Fns; use WPML\FP\Str; class Frontend implements \IWPML_Frontend_Action { /** @var string */ const PERMALINKS_CATEGORY_PATTERN = '%category%'; /** * @return void */ public function add_hooks() { add_action( 'elementor_pro/search_form/after_input', [ $this, 'addLanguageFormField' ] ); if ( Str::includes( self::PERMALINKS_CATEGORY_PATTERN, get_option( 'permalink_structure' ) ) ) { add_filter( 'post_link_category', Fns::memorize( [ $this, 'fixLanguageSwitcherPermalink' ] ), 10, 3 ); } } public function addLanguageFormField() { do_action( 'wpml_add_language_form_field' ); } /** * @param \WP_Term $cat * @param \WP_Term[] $cats * @param \WP_Post $post * * @return \WP_Term */ public function fixLanguageSwitcherPermalink( $cat, $cats, $post ) { $postLang = apply_filters( 'wpml_element_language_code', null, [ 'element_id' => $post->ID, 'element_type' => $post->post_type, ] ); $catLang = apply_filters( 'wpml_element_language_code', null, [ 'element_id' => $cat->term_id, 'element_type' => $cat->taxonomy, ] ); if ( $postLang !== $catLang ) { $convertedCatId = apply_filters( 'wpml_object_id', $cat->term_id, $cat->taxonomy, true, $postLang ); return get_term( $convertedCatId, $cat->taxonomy ); } return $cat; } } wpml-page-builders/classes/Integrations/Elementor/modules/MultipleGallery.php 0000755 00000001260 14720415745 0023610 0 ustar 00 <?php /** * MulitpleGallery */ namespace WPML\PB\Elementor\Modules; class MultipleGallery extends \WPML_Elementor_Module_With_Items { protected function get_title( $field ) { switch ( $field ) { case 'gallery_title': return esc_html__( 'Gallery Title:', 'sitepress' ); default: return ''; } } public function get_fields() { return [ 'gallery_title' ]; } protected function get_editor_type( $field ) { if ( 'gallery_title' === $field ) { return 'LINE'; } return 'LINE'; } public function get_items_field() { return 'galleries'; } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-toggle.php 0000755 00000001560 14720415745 0026031 0 ustar 00 <?php /** * Class WPML_Elementor_Toggle */ class WPML_Elementor_Toggle extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'tabs'; } /** * @return array */ public function get_fields() { return array( 'tab_title', 'tab_content' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch( $field ) { case 'tab_title': return esc_html__( 'Toggle: Title', 'sitepress' ); case 'tab_content': return esc_html__( 'Toggle: Content', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'tab_title': return 'LINE'; case 'tab_content': return 'VISUAL'; default: return ''; } } } wpml-page-builders/classes/Integrations/Elementor/modules/ModuleWithItemsFromConfig.php 0000755 00000002602 14720415745 0025533 0 ustar 00 <?php namespace WPML\PB\Elementor\Modules; use WPML\FP\Obj; class ModuleWithItemsFromConfig extends \WPML_Elementor_Module_With_Items { /** @var array $fields */ private $fields = []; /** @var array $fieldDefinitions */ private $fieldDefinitions = []; /** @var string $itemsField */ private $itemsField; /** * @param string $itemsField * @param array $config */ public function __construct( $itemsField, array $config ) { $this->itemsField = $itemsField; $this->init( $config ); } private function init( array $config ) { foreach ( $config as $key => $fieldConfig ) { $field = Obj::prop( 'field', $fieldConfig ); $keyOf = is_string( $key ) ? $key : null; if ( $keyOf ) { $this->fields[ $keyOf ] = [ $field ]; } else { $this->fields[] = $field; } $this->fieldDefinitions[ $field ] = $fieldConfig; } } private function getFieldData( $field, $key ) { return Obj::path( [ $field, $key ], $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_title( $field ) { return $this->getFieldData( $field, 'type' ); } /** * @inheritDoc */ public function get_fields() { return $this->fields; } /** * @inheritDoc */ public function get_editor_type( $field ) { return $this->getFieldData( $field, 'editor_type' ); } /** * @inheritDoc */ public function get_items_field() { return $this->itemsField; } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-price-table.php 0000755 00000001312 14720415745 0026732 0 ustar 00 <?php /** * Class WPML_Elementor_Price_Table */ class WPML_Elementor_Price_Table extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'features_list'; } /** * @return array */ public function get_fields() { return array( 'item_text' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { if ( 'item_text' === $field ) { return esc_html__( 'Price table: text', 'sitepress' ); } return ''; } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { if ( 'item_text' === $field ) { return 'LINE'; } return ''; } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-form.php 0000755 00000003532 14720415745 0025514 0 ustar 00 <?php /** * Class WPML_Elementor_Form */ class WPML_Elementor_Form extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'form_fields'; } /** * @return array */ public function get_fields() { return [ 'field_label', 'placeholder', 'field_html', 'acceptance_text', 'field_options', 'step_next_label', 'step_previous_label', 'previous_button', 'next_button', ]; } /** * @param string $field * * @return string */ protected function get_title( $field ) { return wpml_collect( [ 'field_label' => esc_html__( 'Form: Field label', 'sitepress' ), 'placeholder' => esc_html__( 'Form: Field placeholder', 'sitepress' ), 'field_html' => esc_html__( 'Form: Field HTML', 'sitepress' ), 'acceptance_text' => esc_html__( 'Form: Acceptance Text', 'sitepress' ), 'field_options' => esc_html__( 'Form: Checkbox Options', 'sitepress' ), 'step_next_label' => esc_html__( 'Form: Step Next Label', 'sitepress' ), 'step_previous_label' => esc_html__( 'Form: Step Previous Label', 'sitepress' ), 'previous_button' => esc_html__( 'Form: Previous Button', 'sitepress' ), 'next_button' => esc_html__( 'Form: Next Button', 'sitepress' ), ] )->get( $field, '' ); } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { return wpml_collect( [ 'field_label' => 'LINE', 'placeholder' => 'LINE', 'field_html' => 'VISUAL', 'acceptance_text' => 'LINE', 'field_options' => 'AREA', 'step_next_label' => 'LINE', 'step_previous_label' => 'LINE', 'previous_button' => 'LINE', 'next_button' => 'LINE', ] )->get( $field, '' ); } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-accordion.php 0000755 00000001574 14720415745 0026516 0 ustar 00 <?php /** * Class WPML_Elementor_Accordion */ class WPML_Elementor_Accordion extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'tabs'; } /** * @return array */ public function get_fields() { return array( 'tab_title', 'tab_content' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch( $field ) { case 'tab_title': return esc_html__( 'Accordion: Title', 'sitepress' ); case 'tab_content': return esc_html__( 'Accordion: Content', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'tab_title': return 'LINE'; case 'tab_content': return 'VISUAL'; default: return ''; } } } wpml-page-builders/classes/Integrations/Elementor/modules/MediaCarousel.php 0000755 00000001345 14720415745 0023216 0 ustar 00 <?php namespace WPML\PB\Elementor\Modules; class MediaCarousel extends \WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'slides'; } /** * @return array */ public function get_fields() { return [ 'image_link_to' => [ 'url' ] ]; } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch ( $field ) { case 'url': return esc_html__( 'Media Carousel: link URL', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch ( $field ) { case 'url': return 'LINK'; default: return ''; } } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-module-with-items.php0000755 00000007704 14720415745 0030133 0 ustar 00 <?php use WPML\FP\Obj; /** * Class WPML_Elementor_Module_With_Items */ abstract class WPML_Elementor_Module_With_Items implements IWPML_Page_Builders_Module { /** * @param string $field * * @return string */ abstract protected function get_title( $field ); /** @return array */ abstract protected function get_fields(); /** * @param string $field * * @return string mixed */ abstract protected function get_editor_type( $field ); /** * @return string */ abstract public function get_items_field(); /** * @param string|int $node_id * @param array $element * @param WPML_PB_String[] $strings * * @return WPML_PB_String[] */ public function get( $node_id, $element, $strings ) { foreach ( $this->get_items( $element ) as $item ) { foreach( $this->get_fields() as $key => $field ) { if ( ! is_array( $field ) ) { if ( ! isset( $item[ $field ] ) ) { continue; } $strings[] = new WPML_PB_String( $item[ $field ], $this->get_string_name( $node_id, $item, $element, $field ), $this->get_title( $field ), $this->get_editor_type( $field ) ); } else { foreach ( $field as $inner_field ) { if ( ! isset( $item[ $key ][ $inner_field ] ) ) { continue; } $strings[] = new WPML_PB_String( $item[ $key ][ $inner_field ], $this->get_string_name( $node_id, $item, $element, $inner_field, $key ), $this->get_title( $inner_field ), $this->get_editor_type( $inner_field ) ); } } } } return $strings; } /** * @param int|string $node_id * @param mixed $element * @param WPML_PB_String $string * * @return mixed */ public function update( $node_id, $element, WPML_PB_String $string ) { foreach ( $this->get_items( $element ) as $key => $item ) { foreach( $this->get_fields() as $field_key => $field ) { if ( ! is_array( $field ) ) { if ( ! isset( $item[ $field ] ) ) { continue; } if ( $this->get_string_name( $node_id, $item, $element, $field ) === $string->get_name() ) { $item[ $field ] = $string->get_value(); $item['index'] = $key; return $item; } } else { foreach ( $field as $inner_field ) { if ( ! isset( $item[ $field_key ][ $inner_field ] ) ) { continue; } if ( $this->get_string_name( $node_id, $item, $element, $inner_field, $field_key ) === $string->get_name() ) { $item[ $field_key ][ $inner_field ] = $string->get_value(); $item['index'] = $key; return $item; } } } } } } /** * @param string $nodeId * @param array $item * @param array $element * @param string $field * @param string $key * * @return string */ private function get_string_name( $nodeId, $item, $element, $field = '', $key = '' ) { $widgetType = Obj::prop( 'widgetType', $element ); $itemId = Obj::prop( '_id', $item ); $name = $widgetType . '-' . $field . '-' . $nodeId . '-' . $itemId; /** * Filter a package string name. * * Could be used for repeater or nested fields with the same key. * * @since 2.0.5 * * @param string $name * @param array $args { * @type string $nodeId Elementor node id. * @type array $item The item that is being registered. * @type array $element The element that is being processed and registered. * @type string $field Optional. The item field that is being registered. * @type string $key Optional. The item field sub-key that is being registered. * } */ return apply_filters( "wpml_pb_elementor_register_string_name_$widgetType", $name, [ 'nodeId' => $nodeId, 'item' => $item, 'element' => $element, 'field' => $field, 'key' => $key, ] ); } /** * @param array $element * * @return mixed */ public function get_items( $element ) { return $element[ WPML_Elementor_Translatable_Nodes::SETTINGS_FIELD ][ $this->get_items_field() ]; } } wpml-page-builders/classes/Integrations/Elementor/modules/Reviews.php 0000755 00000002407 14720415745 0022125 0 ustar 00 <?php /** * Reviews */ namespace WPML\PB\Elementor\Modules; class Reviews extends \WPML_Elementor_Module_With_Items { protected function get_title( $field ) { switch ( $field ) { case 'content': return esc_html__( 'Comment Contents', 'sitepress' ); case 'name': return esc_html__( 'Commenter Name', 'sitepress' ); case 'title': return esc_html__( 'Comment Title', 'sitepress' ); case 'image': return esc_html__( 'Comment Image', 'sitepress' ); case 'url': return esc_html__( 'Comment Link', 'sitepress' ); default: return ''; } } public function get_fields() { return [ 'content', 'name', 'title', 'link' => [ 'field' => 'url' ] ]; } protected function get_editor_type( $field ) { if ( 'content' === $field ) { return 'LINE'; } if ( 'name' === $field ) { return 'LINE'; } if ( 'title' === $field ) { return 'LINE'; } if ( 'url' === $field ) { return 'LINK'; } return 'LINE'; } public function get_items_field() { return 'slides'; } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-slides.php 0000755 00000002163 14720415745 0026033 0 ustar 00 <?php /** * Class WPML_Elementor_Slides */ class WPML_Elementor_Slides extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'slides'; } /** * @return array */ public function get_fields() { return array( 'heading', 'description', 'button_text', 'link' => array( 'url' ) ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch( $field ) { case 'heading': return esc_html__( 'Slides: heading', 'sitepress' ); case 'description': return esc_html__( 'Slides: description', 'sitepress' ); case 'button_text': return esc_html__( 'Slides: button text', 'sitepress' ); case 'url': return esc_html__( 'Slides: link URL', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'heading': case 'button_text': return 'LINE'; case 'description': return 'VISUAL'; case 'url': return 'LINK'; default: return ''; } } } wpml-page-builders/classes/Integrations/Elementor/modules/Hotspot.php 0000755 00000002027 14720415745 0022137 0 ustar 00 <?php /** * Reviews */ namespace WPML\PB\Elementor\Modules; class Hotspot extends \WPML_Elementor_Module_With_Items { protected function get_title( $field ) { switch ( $field ) { case 'hotspot_label': return esc_html__( 'Hotspot: Label', 'sitepress' ); case 'hotspot_tooltip_content': return esc_html__( 'Hotspot: Content', 'sitepress' ); case 'url': return esc_html__( 'Hotspot: URL', 'sitepress' ); default: return ''; } } public function get_fields() { return [ 'hotspot_label', 'hotspot_tooltip_content', 'hotspot_link' => [ 'field' => 'url' ] ]; } protected function get_editor_type( $field ) { switch ( $field ) { case 'hotspot_label': return 'LINE'; case 'hotspot_tooltip_content': return 'VISUAL'; case 'url': return 'LINK'; default: return ''; } } public function get_items_field() { return 'hotspot'; } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-price-list.php 0000755 00000002045 14720415745 0026622 0 ustar 00 <?php /** * Class WPML_Elementor_Price_List */ class WPML_Elementor_Price_List extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'price_list'; } /** * @return array */ public function get_fields() { return array( 'title', 'item_description', 'link' => array( 'url' ) ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { if ( 'title' === $field ) { return esc_html__( 'Price list: title', 'sitepress' ); } if ( 'item_description' === $field ) { return esc_html__( 'Pricing list: description', 'sitepress' ); } if ( 'url' === $field ) { return esc_html__( 'Pricing list: link', 'sitepress' ); } return ''; } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { if ( 'title' === $field ) { return 'LINE'; } if ( 'url' === $field ) { return 'LINK'; } if ( 'item_description' === $field ) { return 'AREA'; } return ''; } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-tabs.php 0000755 00000001550 14720415745 0025500 0 ustar 00 <?php /** * Class WPML_Elementor_Tabs */ class WPML_Elementor_Tabs extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'tabs'; } /** * @return array */ public function get_fields() { return array( 'tab_title', 'tab_content' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch( $field ) { case 'tab_title': return esc_html__( 'Tabs: Title', 'sitepress' ); case 'tab_content': return esc_html__( 'Tabs: Content', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'tab_title': return 'LINE'; case 'tab_content': return 'VISUAL'; default: return ''; } } } classes/Integrations/Elementor/modules/class-wpml-elementor-testimonial-carousel.php 0000755 00000002010 14720415745 0030623 0 ustar 00 wpml-page-builders <?php /** * Class WPML_Elementor_Accordion */ class WPML_Elementor_Testimonial_Carousel extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'slides'; } /** * @return array */ public function get_fields() { return array( 'content', 'name', 'title' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch( $field ) { case 'content': return esc_html__( 'Testimonial Carousel: Content', 'sitepress' ); case 'name': return esc_html__( 'Testimonial Carousel: Name', 'sitepress' ); case 'title': return esc_html__( 'Testimonial Carousel: Title', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'name': return 'LINE'; case 'title': return 'LINE'; case 'content': return 'VISUAL'; default: return ''; } } } wpml-page-builders/classes/Integrations/Elementor/modules/class-wpml-elementor-icon-list.php 0000755 00000001551 14720415745 0026451 0 ustar 00 <?php /** * Class WPML_Elementor_Icon_List */ class WPML_Elementor_Icon_List extends WPML_Elementor_Module_With_Items { /** * @return string */ public function get_items_field() { return 'icon_list'; } /** * @return array */ public function get_fields() { return array( 'text', 'link' => array( 'url' ) ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { switch( $field ) { case 'text': return esc_html__( 'Icon List: Text', 'sitepress' ); case 'url': return esc_html__( 'Icon List: Link URL', 'sitepress' ); default: return ''; } } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { switch( $field ) { case 'text': return 'LINE'; case 'url': return 'LINK'; default: return ''; } } } classes/Integrations/Elementor/class-wpml-elementor-adjust-global-widget-id-factory.php 0000755 00000000753 14720415745 0031074 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Adjust_Global_Widget_ID_Factory implements IWPML_Backend_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { global $sitepress; $elementor_db_factory = new WPML_Elementor_DB_Factory(); $data_settings = new WPML_Elementor_Data_Settings( $elementor_db_factory->create() ); return new WPML_Elementor_Adjust_Global_Widget_ID( $data_settings, new WPML_Translation_Element_Factory( $sitepress ), $sitepress ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-register-strings.php 0000755 00000001210 14720415745 0026403 0 ustar 00 <?php use WPML\PB\Elementor\Helper\Node; /** * Class WPML_Elementor_Register_Strings */ class WPML_Elementor_Register_Strings extends WPML_Page_Builders_Register_Strings { /** * @param array $data_array * @param array $package */ protected function register_strings_for_modules( array $data_array, array $package ) { foreach ( $data_array as $data ) { if ( Node::isTranslatable( $data ) ) { $this->register_strings_for_node( $data[ $this->data_settings->get_node_id_field() ], $data, $package ); } if ( Node::hasChildren( $data ) ) { $this->register_strings_for_modules( $data['elements'], $package ); } } } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-pb-fix-maintenance-query.php 0000755 00000001026 14720415745 0025715 0 ustar 00 <?php class WPML_PB_Fix_Maintenance_Query implements IWPML_Frontend_Action { const AFTER_TEMPLATE_APPLY = 12; public function add_hooks() { add_action( 'template_redirect', array( $this, 'fix_global_query' ), self::AFTER_TEMPLATE_APPLY ); } public function fix_global_query() { if ( class_exists( '\Elementor\Maintenance_Mode' ) && isset( $GLOBALS['post']->ID ) && (int) \Elementor\Maintenance_Mode::get( 'template_id' ) === $GLOBALS['post']->ID ) { $GLOBALS['wp_the_query'] = $GLOBALS['wp_query']; } } } wpml-page-builders/classes/Integrations/Elementor/media/class-wpml-elementor-media-hooks-factory.php0000755 00000000445 14720415745 0030025 0 ustar 00 <?php class WPML_Elementor_Media_Hooks_Factory implements IWPML_Backend_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { return new WPML_Page_Builders_Media_Hooks( new WPML_Elementor_Update_Media_Factory(), WPML_Elementor_Integration_Factory::SLUG ); } } wpml-page-builders/classes/Integrations/Elementor/media/class-wpml-elementor-media-node-provider.php0000755 00000004510 14720415745 0030007 0 ustar 00 <?php use WPML\PB\Elementor\Media\Modules\Gallery; class WPML_Elementor_Media_Node_Provider { /** @var WPML_Page_Builders_Media_Translate $media_translate */ private $media_translate; /** @var WPML_Elementor_Media_Node[] */ private $nodes = array(); public function __construct( WPML_Page_Builders_Media_Translate $media_translate ) { $this->media_translate = $media_translate; } /** * @param string $type * * @return WPML_Elementor_Media_Node|null */ public function get( $type ) { if ( ! array_key_exists( $type, $this->nodes ) ) { switch ( $type ) { case 'image': $node = new WPML_Elementor_Media_Node_Image( $this->media_translate ); break; case 'slides': $node = new WPML_Elementor_Media_Node_Slides( $this->media_translate ); break; case 'call-to-action': $node = new WPML_Elementor_Media_Node_Call_To_Action( $this->media_translate ); break; case 'media-carousel': $node = new WPML_Elementor_Media_Node_Media_Carousel( $this->media_translate ); break; case 'image-box': $node = new WPML_Elementor_Media_Node_Image_Box( $this->media_translate ); break; case 'image-gallery': $node = new WPML_Elementor_Media_Node_Image_Gallery( $this->media_translate ); break; case 'gallery': $node = new Gallery( $this->media_translate ); break; case 'image-carousel': $node = new WPML_Elementor_Media_Node_Image_Carousel( $this->media_translate ); break; case 'wp-widget-media_image': $node = new WPML_Elementor_Media_Node_WP_Widget_Media_Image( $this->media_translate ); break; case 'wp-widget-media_gallery': $node = new WPML_Elementor_Media_Node_WP_Widget_Media_Gallery( $this->media_translate ); break; case 'all_nodes': $node = new \WPML\PB\Elementor\Media\Modules\AllNodes( $this->media_translate ); break; case 'video': $node = new \WPML\PB\Elementor\Media\Modules\Video( $this->media_translate ); break; case 'video-playlist': $node = new \WPML\PB\Elementor\Media\Modules\VideoPlaylist( $this->media_translate ); break; case 'hotspot': $node = new \WPML\PB\Elementor\Media\Modules\Hotspot( $this->media_translate ); break; default: $node = null; } $this->nodes[ $type ] = $node; } return $this->nodes[ $type ]; } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-media-carousel.php 0000755 00000000256 14720415745 0032443 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Media_Carousel extends WPML_Elementor_Media_Node_With_Slides { protected function get_image_property_name() { return 'image'; } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-call-to-action.php 0000755 00000000541 14720415745 0032354 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Call_To_Action extends WPML_Elementor_Media_Node { public function translate( $settings, $target_lang, $source_lang ) { foreach ( [ 'bg_image', 'graphic_image' ] as $property ) { $settings = $this->translate_image_property( $settings, $property, $target_lang, $source_lang ); } return $settings; } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-box.php 0000755 00000000253 14720415745 0031416 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Image_Box extends WPML_Elementor_Media_Node_With_Image_Property { protected function get_property_name() { return 'image'; } } wpml-page-builders/classes/Integrations/Elementor/media/modules/VideoPlaylist.php 0000755 00000001101 14720415745 0024336 0 ustar 00 <?php namespace WPML\PB\Elementor\Media\Modules; use WPML\FP\Obj; use function WPML\FP\partialRight; class VideoPlaylist extends \WPML_Elementor_Media_Node { public function translate( $settings, $target_lang, $source_lang ) { $thumbnailLens = Obj::lensProp( 'thumbnail' ); $convertImageArray = partialRight( [ $this, 'translate_image_array' ], $target_lang, $source_lang ); return Obj::assoc( 'tabs', wpml_collect( Obj::propOr( [], 'tabs', $settings ) ) ->map( Obj::over( $thumbnailLens, $convertImageArray ) ) ->toArray(), $settings ); } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image.php 0000755 00000001510 14720415745 0030625 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Image extends WPML_Elementor_Media_Node { /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return array */ public function translate( $settings, $target_lang, $source_lang ) { $settings = $this->translate_image_property( $settings, 'image', $target_lang, $source_lang ); $settings = $this->translate_image_property( $settings, '_background_image', $target_lang, $source_lang ); $settings = $this->translate_image_property( $settings, '_background_hover_image', $target_lang, $source_lang ); if ( ! isset( $settings['caption'] ) && isset( $settings['image']['id'] ) ) { $image_data = wp_prepare_attachment_for_js( $settings['image']['id'] ); $settings['caption'] = $image_data['caption']; } return $settings; } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-slides.php 0000755 00000000261 14720415745 0031030 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Slides extends WPML_Elementor_Media_Node_With_Slides { protected function get_image_property_name() { return 'background_image'; } } wpml-page-builders/classes/Integrations/Elementor/media/modules/Video.php 0000755 00000000276 14720415745 0022630 0 ustar 00 <?php namespace WPML\PB\Elementor\Media\Modules; class Video extends \WPML_Elementor_Media_Node_With_Image_Property { public function get_property_name() { return 'image_overlay'; } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-gallery.php 0000755 00000000264 14720415745 0032267 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Image_Gallery extends WPML_Elementor_Media_Node_With_Images_Property { protected function get_property_name() { return 'wp_gallery'; } } classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node.php 0000755 00000003242 14720415745 0031354 0 ustar 00 wpml-page-builders <?php abstract class WPML_Elementor_Media_Node { /** @var WPML_Page_Builders_Media_Translate $media_translate */ protected $media_translate; public function __construct( WPML_Page_Builders_Media_Translate $media_translate ) { $this->media_translate = $media_translate; } /** * @param array $settings * @param string $property * @param string $lang * @param string $source_lang * * @return mixed */ protected function translate_image_property( $settings, $property, $lang, $source_lang ) { if ( isset( $settings[ $property ] ) ) { $settings[ $property ] = $this->translate_image_array( $settings[ $property ], $lang, $source_lang ); } return $settings; } /** * @param array $settings * @param string $property * @param string $lang * @param string $source_lang * * @return mixed */ protected function translate_images_property( $settings, $property, $lang, $source_lang ) { if ( isset( $settings[ $property ] ) ) { foreach ( $settings[ $property ] as &$image ) { $image = $this->translate_image_array( $image, $lang, $source_lang ); } } return $settings; } /** * @param array $image * @param string $lang * @param string $source_lang * * @return mixed */ public function translate_image_array( $image, $lang, $source_lang ) { if ( isset( $image['id'] ) && $image['id'] ) { $image['id'] = $this->media_translate->translate_id( $image['id'], $lang ); } if ( isset( $image['url'] ) && $image['url'] ) { $image['url'] = $this->media_translate->translate_image_url( $image['url'], $lang, $source_lang ); } return $image; } abstract function translate( $settings, $target_lang, $source_lang ); } Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-slides.php 0000755 00000001234 14720415745 0033605 0 ustar 00 wpml-page-builders/classes <?php abstract class WPML_Elementor_Media_Node_With_Slides extends WPML_Elementor_Media_Node { /** @return string */ abstract protected function get_image_property_name(); /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return mixed */ public function translate( $settings, $target_lang, $source_lang ) { if ( ! isset( $settings['slides'] ) || ! is_array( $settings['slides'] ) ) { return $settings; } foreach ( $settings['slides'] as &$slide ) { $slide = $this->translate_image_property( $slide, $this->get_image_property_name(), $target_lang, $source_lang ); } return $settings; } } Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-image-property.php 0000755 00000000747 14720415745 0035276 0 ustar 00 wpml-page-builders/classes/Integrations <?php abstract class WPML_Elementor_Media_Node_With_Image_Property extends WPML_Elementor_Media_Node { /** @return string */ abstract protected function get_property_name(); /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return mixed */ public function translate( $settings, $target_lang, $source_lang ) { return $this->translate_image_property( $settings, $this->get_property_name(), $target_lang, $source_lang ); } } Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-images-property.php 0000755 00000000751 14720415745 0035454 0 ustar 00 wpml-page-builders/classes/Integrations <?php abstract class WPML_Elementor_Media_Node_With_Images_Property extends WPML_Elementor_Media_Node { /** @return string */ abstract protected function get_property_name(); /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return mixed */ public function translate( $settings, $target_lang, $source_lang ) { return $this->translate_images_property( $settings, $this->get_property_name(), $target_lang, $source_lang ); } } wpml-page-builders/classes/Integrations/Elementor/media/modules/AllNodes.php 0000755 00000001142 14720415745 0023254 0 ustar 00 <?php namespace WPML\PB\Elementor\Media\Modules; class AllNodes extends \WPML_Elementor_Media_Node { /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return array */ public function translate( $settings, $target_lang, $source_lang ) { $backgrounds = [ '_background_image', 'background_image', 'background_overlay_image', 'background_hover_image' ]; foreach ( $backgrounds as $background ) { $settings = $this->translate_image_property( $settings, $background , $target_lang, $source_lang ); } return $settings; } } wpml-page-builders/classes/Integrations/Elementor/media/modules/Hotspot.php 0000755 00000000274 14720415745 0023220 0 ustar 00 <?php namespace WPML\PB\Elementor\Media\Modules; class Hotspot extends \WPML_Elementor_Media_Node_With_Image_Property { protected function get_property_name() { return 'image'; } } wpml-page-builders/classes/Integrations/Elementor/media/modules/Gallery.php 0000755 00000002301 14720415745 0023150 0 ustar 00 <?php namespace WPML\PB\Elementor\Media\Modules; use WPML\FP\Obj; use function WPML\FP\compose; use function WPML\FP\partialRight; class Gallery extends \WPML_Elementor_Media_Node_With_Images_Property { protected function get_property_name() { return 'gallery'; } /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return mixed */ public function translate( $settings, $target_lang, $source_lang ) { if ( 'multiple' === Obj::propOr( null, 'gallery_type', $settings ) ) { return $this->translateMultipleGalleries( $settings, $target_lang, $source_lang ); } return parent::translate( $settings, $target_lang, $source_lang ); } /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return array */ private function translateMultipleGalleries( $settings, $target_lang, $source_lang ) { $multipleGalleriesLens = compose( Obj::lensMappedProp( 'galleries' ), Obj::lensMappedProp( 'multiple_gallery' ) ); $convertImageArray = partialRight( [ $this, 'translate_image_array' ], $target_lang, $source_lang ); return Obj::over( $multipleGalleriesLens, $convertImageArray, $settings ); } } classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-carousel.php 0000755 00000000264 14720415745 0032445 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Node_Image_Carousel extends WPML_Elementor_Media_Node_With_Images_Property { protected function get_property_name() { return 'carousel'; } } Integrations/Elementor/media/modules/class-wpml-elementor-media-node-wp-widget-media-image.php 0000755 00000001777 14720415745 0033626 0 ustar 00 wpml-page-builders/classes <?php class WPML_Elementor_Media_Node_WP_Widget_Media_Image extends WPML_Elementor_Media_Node { /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return mixed */ public function translate( $settings, $target_lang, $source_lang ) { if ( isset( $settings['wp']['attachment_id'] ) ) { $translated_id = $this->media_translate->translate_id( $settings['wp']['attachment_id'], $target_lang ); if ( $translated_id !== (int) $settings['wp']['attachment_id'] ) { $settings['wp']['attachment_id'] = $translated_id; $settings['wp']['url'] = $this->media_translate->translate_image_url( $settings['wp']['url'], $target_lang, $source_lang ); $image_data = wp_prepare_attachment_for_js( $translated_id ); $settings['wp']['caption'] = $image_data['caption']; $settings['wp']['alt'] = $image_data['alt']; $settings['wp']['image_title'] = $image_data['title']; } } return $settings; } } Integrations/Elementor/media/modules/class-wpml-elementor-media-node-wp-widget-media-gallery.php 0000755 00000001101 14720415745 0034160 0 ustar 00 wpml-page-builders/classes <?php class WPML_Elementor_Media_Node_WP_Widget_Media_Gallery extends WPML_Elementor_Media_Node { /** * @param array $settings * @param string $target_lang * @param string $source_lang * * @return array */ public function translate( $settings, $target_lang, $source_lang ) { if ( isset( $settings['wp']['ids'] ) ) { $ids = explode( ',', $settings['wp']['ids'] ); foreach ( $ids as &$id ) { $id = $this->media_translate->translate_id( (int) $id, $target_lang ); } $settings['wp']['ids'] = implode( ',', $ids ); } return $settings; } } classes/Integrations/Elementor/media/class-wpml-elementor-update-media-factory.php 0000755 00000002163 14720415745 0030104 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Update_Media_Factory implements IWPML_PB_Media_Update_Factory { /** @var WPML_Page_Builders_Media_Translate|null $media_translate */ private $media_translate; public function create() { global $sitepress; return new WPML_Page_Builders_Update_Media( new WPML_Page_Builders_Update( new WPML_Elementor_Data_Settings() ), new WPML_Translation_Element_Factory( $sitepress ), new WPML_Elementor_Media_Nodes_Iterator( new WPML_Elementor_Media_Node_Provider( $this->get_media_translate() ) ), new WPML_Page_Builders_Media_Usage( $this->get_media_translate(), new WPML_Media_Usage_Factory() ) ); } /** @return WPML_Page_Builders_Media_Translate */ private function get_media_translate() { global $sitepress; if ( ! $this->media_translate ) { $this->media_translate = new WPML_Page_Builders_Media_Translate( new WPML_Translation_Element_Factory( $sitepress ), new WPML_Media_Image_Translate( $sitepress, new WPML_Media_Attachment_By_URL_Factory(), new \WPML\Media\Factories\WPML_Media_Attachment_By_URL_Query_Factory() ) ); } return $this->media_translate; } } classes/Integrations/Elementor/media/class-wpml-elementor-media-nodes-iterator.php 0000755 00000003341 14720415745 0030113 0 ustar 00 wpml-page-builders <?php class WPML_Elementor_Media_Nodes_Iterator implements IWPML_PB_Media_Nodes_Iterator { /** @var WPML_Elementor_Media_Node_Provider $node_provider */ private $node_provider; public function __construct( WPML_Elementor_Media_Node_Provider $node_provider ) { $this->node_provider = $node_provider; } /** * @param array $data_array * @param string $lang * @param string $source_lang * * @return array */ public function translate( $data_array, $lang, $source_lang ) { foreach ( $data_array as &$node ) { if ( $this->is_parent_node( $node ) ) { $node['elements'] = $this->translate( $node['elements'], $lang, $source_lang ); } elseif ( $this->is_valid_media_node( $node ) ) { $node = $this->translate_node( $node, $lang, $source_lang ); } if ( isset( $node['settings'] ) ) { $node["settings"] = $this->node_provider->get( 'all_nodes' )->translate( $node['settings'], $lang, $source_lang ); } } return $data_array; } /** * @param array $node * * @return bool */ private function is_parent_node( $node ) { return isset( $node['elements'] ) && $node['elements']; } /** * @param array $node * * @return bool */ private function is_valid_media_node( $node ) { return isset( $node['elType'], $node['widgetType'], $node['settings'] ) && 'widget' === $node['elType']; } /** * @param stdClass $node_data * @param string $lang * @param string $source_lang * * @return stdClass */ private function translate_node( $node_data, $lang, $source_lang ) { $node = $this->node_provider->get( $node_data['widgetType'] ); if ( $node ) { $node_data['settings'] = $node->translate( $node_data['settings'], $lang, $source_lang ); } return $node_data; } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-translate-ids-factory.php 0000755 00000000315 14720415745 0027314 0 ustar 00 <?php class WPML_Elementor_Translate_IDs_Factory implements IWPML_Frontend_Action_Loader { public function create() { return new WPML_Elementor_Translate_IDs( new \WPML\Utils\DebugBackTrace() ); } } classes/Integrations/Elementor/class-wpml-elementor-pb-handle-custom-fields-factory.php 0000755 00000000626 14720415745 0031076 0 ustar 00 wpml-page-builders <?php class WPML_PB_Elementor_Handle_Custom_Fields_Factory implements IWPML_Backend_Action_Loader, IWPML_AJAX_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { $elementor_db_factory = new WPML_Elementor_DB_Factory(); $data_settings = new WPML_Elementor_Data_Settings( $elementor_db_factory->create() ); return new WPML_PB_Handle_Custom_Fields( $data_settings ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-woocommerce-hooks.php 0000755 00000001575 14720415745 0026546 0 ustar 00 <?php class WPML_Elementor_WooCommerce_Hooks { public function add_hooks() { add_filter( 'pre_get_posts', array( $this, 'do_not_suppress_filters_on_product_widget' ) ); add_filter( 'wcml_multi_currency_ajax_actions', [ $this, 'adjustCurrencyOnElementorCartFragments' ] ); } /** * @param WP_Query $query * * @return WP_Query */ public function do_not_suppress_filters_on_product_widget( WP_Query $query ) { if ( array_key_exists( 'post_type', $query->query_vars ) && 'product' === $query->query_vars['post_type'] && isset( $_POST['action'] ) && 'elementor_ajax' === $_POST['action'] ) { $query->query_vars['suppress_filters'] = false; } return $query; } /** * @param array $actions * * @return array */ public function adjustCurrencyOnElementorCartFragments( $actions ) { $actions[] = 'elementor_menu_cart_fragments'; return $actions; } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-woocommerce-hooks-factory.php0000755 00000000261 14720415745 0030202 0 ustar 00 <?php class WPML_Elementor_WooCommerce_Hooks_Factory implements IWPML_Backend_Action_Loader { public function create() { return new WPML_Elementor_WooCommerce_Hooks(); } } wpml-page-builders/classes/Integrations/Elementor/Config/Factory.php 0000755 00000000651 14720415745 0021644 0 ustar 00 <?php namespace WPML\PB\Elementor\Config; class Factory extends \WPML\PB\Config\Factory { const DATA = [ 'configRoot' => 'elementor-widgets', 'defaultConditionKey' => 'widgetType', 'pbKey' => 'elementor', 'translatableWidgetsHook' => 'wpml_elementor_widgets_to_translate', ]; /** * @inheritDoc */ protected function getPbData( $key ) { return self::DATA[ $key ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/WooProduct.php 0000755 00000002405 14720415745 0025422 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Fns; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\FP\Logic; class WooProduct { /** * @param string $widgetName * * @return callable(string): string */ private static function getConfig( $widgetName ) { $widgetConfig = wpml_collect( [ 'title' => [ 'dynamicKey' => 'title', 'widgetType' => 'heading', 'shortcodeName' => 'woocommerce-product-title-tag', ], 'short-description' => [ 'dynamicKey' => 'editor', 'widgetType' => 'text-editor', 'shortcodeName' => 'woocommerce-product-short-description-tag', ], ] )->get( $widgetName ); return Obj::prop( Fns::__, $widgetConfig ); } /** * @param string $widget * * @return array */ public static function get( $widget ) { $get = self::getConfig( $widget ); $widgetPath = [ 'settings', '__dynamic__', $get( 'dynamicKey' ) ]; // $isWooWidget :: array -> bool $isWooWidget = Logic::allPass( [ Relation::propEq( 'widgetType', $get( 'widgetType' ) ), Obj::path( $widgetPath ), ] ); // $widgetLens :: callable -> callable -> mixed $widgetLens = Obj::lensPath( $widgetPath ); return [ $isWooWidget, $widgetLens, $get( 'shortcodeName' ), 'product_id' ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/LoopGrid.php 0000755 00000000703 14720415745 0025033 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Logic; use WPML\FP\Obj; use WPML\FP\Relation; class LoopGrid { /** * @return array */ public static function get() { $loopIdPath = [ 'settings', 'template_id' ]; $hasLoop = Logic::allPass( [ Relation::propEq( 'widgetType', 'loop-grid' ), Obj::path( $loopIdPath ), ] ); $loopIdLens = Obj::lensPath( $loopIdPath ); return [ $hasLoop, $loopIdLens ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/Button.php 0000755 00000000606 14720415745 0024571 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Obj; use WPML\FP\Relation; class Button { /** * @return array */ public static function get() { $isButton = Relation::propEq( 'widgetType', 'button' ); $buttonLinkLens = Obj::lensPath( [ 'settings', '__dynamic__', 'link' ] ); return [ $isButton, $buttonLinkLens, 'internal-url', 'post_id' ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/FormPopup.php 0000755 00000000736 14720415745 0025251 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Logic; use WPML\FP\Obj; use WPML\FP\Relation; class FormPopup { /** * @return array */ public static function get() { $popupIdPath = [ 'settings', 'popup_action_popup_id' ]; $isFormWithPopup = Logic::allPass( [ Relation::propEq( 'widgetType', 'form' ), Obj::path( $popupIdPath ), ] ); $popupIdLens = Obj::lensPath( $popupIdPath ); return [ $isFormWithPopup, $popupIdLens ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/MegaMenu.php 0000755 00000000765 14720415745 0025022 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Obj; use WPML\FP\Relation; use function WPML\FP\compose; class MegaMenu { /** * @return array */ public static function get() { $isMenuItem = Relation::propEq( 'widgetType', 'mega-menu' ); $itemLinkLens = compose( Obj::lensProp( 'settings' ), Obj::lensMappedProp( 'menu_items' ), Obj::lensPath( [ '__dynamic__', 'item_link' ] ) ); return [ $isMenuItem, $itemLinkLens, 'internal-url', 'post_id' ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/LoopCarousel.php 0000755 00000001003 14720415745 0025715 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Logic; use WPML\FP\Obj; use WPML\FP\Relation; class LoopCarousel { /** * @return array */ public static function get() { $loopCarouselIdPath = [ 'settings', 'template_id' ]; $hasLoopCarousel = Logic::allPass( [ Relation::propEq( 'widgetType', 'loop-carousel' ), Obj::path( $loopCarouselIdPath ), ] ); $loopCarouselIdLens = Obj::lensPath( $loopCarouselIdPath ); return [ $hasLoopCarousel, $loopCarouselIdLens ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/Hotspot.php 0000755 00000001050 14720415745 0024750 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Obj; use WPML\FP\Relation; use function WPML\FP\compose; class Hotspot{ /** * @return array */ public static function get() { $isHotspot = Relation::propEq( 'widgetType', 'hotspot' ); // $hotspotLinksLens :: callable -> callable -> mixed $hotspotLinksLens = compose( Obj::lensProp( 'settings' ), Obj::lensMappedProp( 'hotspot' ), Obj::lensPath( [ '__dynamic__', 'hotspot_link' ] ) ); return [ $isHotspot, $hotspotLinksLens, 'popup', 'popup' ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/Popup.php 0000755 00000000766 14720415745 0024430 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\FP\Logic; class Popup { /** * @return array */ public static function get() { $popupPath = [ 'settings', '__dynamic__', 'link' ]; // $isDynamicLink :: array -> bool $isDynamicLink = Logic::allPass( [ Relation::propEq( 'elType', 'widget' ), Obj::path( $popupPath ), ] ); $lens = Obj::lensPath( $popupPath ); return [ $isDynamicLink, $lens, 'popup', 'popup' ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/IconList.php 0000755 00000001023 14720415745 0025034 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; use WPML\FP\Obj; use WPML\FP\Relation; use function WPML\FP\compose; class IconList { /** * @return array */ public static function get() { // $isIconList :: array -> bool $isIconList = Relation::propEq( 'widgetType', 'icon-list' ); $iconListLinksLens = compose( Obj::lensProp( 'settings' ), Obj::lensMappedProp( 'icon_list' ), Obj::lensPath( [ '__dynamic__', 'link' ] ) ); return [ $isIconList, $iconListLinksLens, 'popup', 'popup' ]; } } wpml-page-builders/classes/Integrations/Elementor/Config/DynamicElements/Provider.php 0000755 00000000663 14720415745 0025113 0 ustar 00 <?php namespace WPML\PB\Elementor\Config\DynamicElements; class Provider { /** * @return array */ public static function get() { return [ EssentialAddons\ContentTimeline::get(), LoopGrid::get(), LoopCarousel::get(), Hotspot::get(), Popup::get(), IconList::get(), FormPopup::get(), WooProduct::get( 'title' ), WooProduct::get( 'short-description' ), MegaMenu::get(), Button::get(), ]; } } classes/Integrations/Elementor/Config/DynamicElements/EssentialAddons/ContentTimeline.php 0000755 00000001443 14720415745 0031420 0 ustar 00 wpml-page-builders <?php namespace WPML\PB\Elementor\Config\DynamicElements\EssentialAddons; use WPML\FP\Obj; use WPML\FP\Relation; use function WPML\FP\compose; /** * @see https://essential-addons.com/elementor/docs/creative-elements/content-timeline/ */ class ContentTimeline { /** * @return array */ public static function get() { // $isEAContentTimeline :: array -> bool $isEAContentTimeline = Relation::propEq( 'widgetType', 'eael-content-timeline' ); // $contentTimelineLinksLens :: callable -> callable -> mixed $contentTimelineLinksLens = compose( Obj::lensProp( 'settings' ), Obj::lensMappedProp( 'eael_coustom_content_posts' ), Obj::lensPath( [ '__dynamic__', 'eael_read_more_text_link' ] ) ); return [ $isEAContentTimeline, $contentTimelineLinksLens, 'popup', 'popup' ]; } } wpml-page-builders/classes/Integrations/Elementor/DataConvert.php 0000755 00000002006 14720415745 0021236 0 ustar 00 <?php namespace WPML\PB\Elementor; class DataConvert { /** * @param array $data * * @return string */ public static function serialize( array $data ) { return wp_slash( wp_json_encode( $data ) ); } /** * @param array|string $data * * @return array */ public static function unserialize( $data ) { if ( self::isElementorArray( $data ) ) { return $data; } $value = is_array( $data ) ? $data[0] : $data; if ( self::isElementorArray( $value ) ) { return $value; } return self::unserializeString( $value ); } /** * @param string $string * * @return array */ private static function unserializeString( $string ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize return is_serialized( $string ) ? unserialize( $string ) : json_decode( $string, true ); } /** * @param mixed $data * * @return bool */ private static function isElementorArray( $data ) { return is_array( $data ) && count( $data ) > 0 && isset( $data[0]['id'] ); } } wpml-page-builders/classes/Integrations/Elementor/Helper/StringFormat.php 0000755 00000002227 14720415745 0022667 0 ustar 00 <?php namespace WPML\PB\Elementor\Helper; use WPML\FP\Obj; use WPML\FP\Str; class StringFormat { /** * @param array $settings * @param \WPML_PB_String $string * * @return bool */ public static function useWpAutoP( $settings, $string ) { return 'VISUAL' === $string->get_editor_type() && self::isOneLine( self::getOriginalString( $settings, $string ) ); } /** * @param string $content * * @return bool */ private static function isOneLine( $content ) { return ! Str::includes( PHP_EOL, $content ); } /** * @param array $settings * @param \WPML_PB_String $string * * @return string */ private static function getOriginalString( $settings, $string ) { if ( 'text-editor' === $settings['widgetType'] ) { return Obj::path( [ 'settings', 'editor' ], $settings ); } elseif ( 'hotspot' === $settings['widgetType'] ) { $items = Obj::path( [ 'settings', 'hotspot' ], $settings ); $found = wpml_collect( $items )->first( function( $item ) use ( $string ) { return Str::endsWith( $item['_id'], $string->get_name() ); }); return Obj::prop( 'hotspot_tooltip_content', $found ); } return ''; } } wpml-page-builders/classes/Integrations/Elementor/Helper/Node.php 0000755 00000000716 14720415745 0021136 0 ustar 00 <?php namespace WPML\PB\Elementor\Helper; class Node { /** * @param array $element * * @return bool */ public static function isTranslatable( $element ) { return isset( $element['elType'] ) && in_array( $element['elType'], [ 'widget', 'container' ], true ); } /** * @param array $element * * @return bool */ public static function hasChildren( $element ) { return isset( $element['elements'] ) && count( $element['elements'] ); } } wpml-page-builders/classes/Integrations/Elementor/class-wpml-elementor-integration-factory.php 0000755 00000003732 14720415745 0027073 0 ustar 00 <?php /** * Class WPML_Elementor_Integration_Factory */ class WPML_Elementor_Integration_Factory { const SLUG = 'elementor'; /** * @return WPML_Page_Builders_Integration */ public function create() { $action_filter_loader = new WPML_Action_Filter_Loader(); $action_filter_loader->load( array( 'WPML_Elementor_Translate_IDs_Factory', 'WPML_Elementor_URLs_Factory', 'WPML_Elementor_Adjust_Global_Widget_ID_Factory', 'WPML_PB_Elementor_Handle_Custom_Fields_Factory', 'WPML_Elementor_Media_Hooks_Factory', 'WPML_Elementor_WooCommerce_Hooks_Factory', \WPML\PB\Elementor\Hooks\WooCommerce::class, \WPML\PB\Elementor\LanguageSwitcher\LanguageSwitcher::class, \WPML\PB\Elementor\Hooks\DynamicElements::class, \WPML\PB\Elementor\Hooks\FormPopup::class, \WPML\PB\Elementor\Hooks\GutenbergCleanup::class, \WPML\PB\Elementor\Hooks\Frontend::class, \WPML\PB\Elementor\Hooks\DomainsWithMultisite::class, \WPML\PB\Elementor\Config\Factory::class, \WPML\PB\Elementor\Hooks\LandingPages::class, \WPML\PB\Elementor\Hooks\Editor::class, \WPML\PB\Elementor\Hooks\WordPressWidgets::class, \WPML\PB\Elementor\Hooks\Templates::class, \WPML\PB\Elementor\Hooks\CssCache::class, \WPML_PB_Fix_Maintenance_Query::class, ) ); $nodes = new WPML_Elementor_Translatable_Nodes(); $elementor_db_factory = new WPML_Elementor_DB_Factory(); $data_settings = new WPML_Elementor_Data_Settings( $elementor_db_factory->create() ); $string_registration_factory = new WPML_String_Registration_Factory( $data_settings->get_pb_name() ); $string_registration = $string_registration_factory->create(); $register_strings = new WPML_Elementor_Register_Strings( $nodes, $data_settings, $string_registration ); $update_translation = new WPML_Elementor_Update_Translation( $nodes, $data_settings ); return new WPML_Page_Builders_Integration( $register_strings, $update_translation, $data_settings ); } } wpml-page-builders/classes/Integrations/Elementor/LanguageSwitcher/LanguageSwitcher.php 0000755 00000001665 14720415745 0025526 0 ustar 00 <?php namespace WPML\PB\Elementor\LanguageSwitcher; use Elementor\Plugin; class LanguageSwitcher implements \IWPML_Backend_Action, \IWPML_Frontend_Action { public function add_hooks() { // @phpstan-ignore-next-line if ( version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) { add_action( 'elementor/widgets/register', [ $this, 'registerWidgets' ] ); } else { add_action( 'elementor/widgets/widgets_registered', [ $this, 'registerWidgetsDeprecated' ] ); } add_filter( 'wpml_custom_language_switcher_is_enabled', '__return_true' ); } /** * @return void */ public function registerWidgets() { // @phpstan-ignore-next-line Plugin::instance()->widgets_manager->register( new Widget() ); } /** * Deprecated since Elementor 3.5.0. * * @return void */ public function registerWidgetsDeprecated() { // @phpstan-ignore-next-line Plugin::instance()->widgets_manager->register_widget_type( new Widget() ); } } wpml-page-builders/classes/Integrations/Elementor/LanguageSwitcher/Widget.php 0000755 00000002633 14720415745 0023511 0 ustar 00 <?php namespace WPML\PB\Elementor\LanguageSwitcher; use Elementor\Widget_Base; class Widget extends Widget_Base { /** @var WidgetAdaptor $adaptor */ private $adaptor; public function __construct( $data = [], $args = null, WidgetAdaptor $adaptor = null ) { $this->adaptor = $adaptor ?: new WidgetAdaptor(); $this->adaptor->setTarget( $this ); parent::__construct( $data, $args ); } /** @return string */ public function get_name() { return $this->adaptor->getName(); } /** @return string */ public function get_title() { return $this->adaptor->getTitle(); } /** @return string */ public function get_icon() { return $this->adaptor->getIcon(); } /** @return array */ public function get_categories() { return $this->adaptor->getCategories(); } /** * Register controls. * * Used to add new controls to any element type. For example, external * developers use this method to register controls in a widget. * * Should be inherited and register new controls using `add_control()`, * `add_responsive_control()` and `add_group_control()`, inside control * wrappers like `start_controls_section()`, `start_controls_tabs()` and * `start_controls_tab()`. */ protected function register_controls() { $this->adaptor->registerControls(); } /** * Render element. * * Generates the final HTML on the frontend. */ protected function render() { $this->adaptor->render(); } } wpml-page-builders/classes/Integrations/Elementor/LanguageSwitcher/WidgetAdaptor.php 0000755 00000022615 14720415745 0025026 0 ustar 00 <?php namespace WPML\PB\Elementor\LanguageSwitcher; use Elementor\Controls_Manager; use Elementor\Group_Control_Typography; use Elementor\Core\Schemes\Color as SchemeColor; class WidgetAdaptor { /** @var Widget $widget */ private $widget; public function setTarget( Widget $widget ) { $this->widget = $widget; } /** @return string */ public function getName() { return 'wpml-language-switcher'; } /** @return string */ public function getTitle() { return __( 'WPML Language Switcher', 'sitepress' ); } /** @return string */ public function getIcon() { return 'fa fa-globe'; } /** @return array */ public function getCategories() { return [ 'general' ]; } /** * Register controls. * * Used to add new controls to any element type. For example, external * developers use this method to register controls in a widget. * * Should be inherited and register new controls using `add_control()`, * `add_responsive_control()` and `add_group_control()`, inside control * wrappers like `start_controls_section()`, `start_controls_tabs()` and * `start_controls_tab()`. */ public function registerControls() { //Content Tab $this->widget->start_controls_section( 'section_content', [ 'label' => __( 'Content', 'sitepress' ), 'type' => Controls_Manager::SECTION, 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->widget->add_control( 'style', [ 'label' => __('Language switcher type', 'sitepress'), 'type' => Controls_Manager::SELECT, 'default' => 'custom', 'options' => [ 'custom' => __( 'Custom', 'sitepress' ), 'footer' => __( 'Footer', 'sitepress' ), 'post_translations' => __( 'Post Translations', 'sitepress' ), ], ] ); $this->widget->add_control( 'display_flag', [ 'label' => __( 'Display Flag', 'sitepress' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 1, 'default' => 1, ] ); $this->widget->add_control( 'link_current', [ 'label' => __( 'Show Active Language - has to be ON with Dropdown', 'sitepress' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 1, 'default' => 1, 'conditions' => [ 'relation' => 'and', 'terms' => [ [ 'name' => 'style', 'operator' => '!=', 'value' => 'custom', ] ] ], ] ); $this->widget->add_control( 'native_language_name', [ 'label' => __( 'Native language name', 'sitepress' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 1, 'default' => 1, ] ); $this->widget->add_control( 'language_name_current_language', [ 'label' => __( 'Language name in current language', 'sitepress' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 1, 'default' => 1, ] ); $this->widget->end_controls_section(); $this->widget->start_controls_section( 'style_section', [ 'label' => __( 'Style', 'sitepress' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->widget->start_controls_tabs( 'style_tabs' ); $this->widget->start_controls_tab( 'style_normal_tab', [ 'label' => __( 'Normal', 'sitepress' ), ] ); $this->widget->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'switcher_typography', 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item', ] ); $this->widget->add_control( 'switcher_text_color', [ 'label' => __( 'Text Color', 'sitepress' ), 'type' => Controls_Manager::COLOR, 'scheme' => [ 'type' => SchemeColor::get_type(), 'value' => SchemeColor::COLOR_3, ], 'default' => '', 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a' => 'color: {{VALUE}}', ], ] ); $this->widget->add_control( 'switcher_bg_color', [ 'label' => __( 'Background Color', 'sitepress' ), 'type' => Controls_Manager::COLOR, 'default' => '', 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a' => 'background-color: {{VALUE}}', ], ] ); $this->widget->end_controls_tab(); $this->widget->start_controls_tab( 'style_hover_tab', [ 'label' => __( 'Hover', 'sitepress' ), ] ); $this->widget->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'switcher_hover_typography', 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item:hover, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item.wpml-ls-item__active, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item.highlighted, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item:focus', ] ); $this->widget->add_control( 'switcher_hover_color', [ 'label' => __( 'Text Color', 'sitepress' ), 'type' => Controls_Manager::COLOR, 'scheme' => [ 'type' => SchemeColor::get_type(), 'value' => SchemeColor::COLOR_4, ], 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a:hover, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a:focus, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown .wpml-ls-current-language:hover>a, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link:hover, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link.wpml-ls-link__active, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link.highlighted, {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link:focus' => 'color: {{VALUE}}', ], ] ); $this->widget->end_controls_tab(); $this->widget->end_controls_tabs(); $this->widget->end_controls_section(); $this->widget->start_controls_section( 'language_flag', [ 'label' => __( 'Language Flag', 'sitepress' ), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => [ 'display_flag' => [ 1 ], ], ] ); $this->widget->add_control( 'flag_margin', [ 'label' => __( 'Margin', 'sitepress' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%', 'em' ], 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-flag' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->widget->end_controls_section(); $this->widget->start_controls_section( 'post_translation_text', [ 'label' => __( 'Post Translation Text', 'sitepress' ), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => [ 'style' => [ 'post_translations' ], ], ] ); $this->widget->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'post_translation_typography', 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations', ] ); $this->widget->add_control( 'post_translation_color', [ 'label' => __( 'Text Color', 'sitepress' ), 'type' => Controls_Manager::COLOR, 'scheme' => [ 'type' => SchemeColor::get_type(), 'value' => SchemeColor::COLOR_3, ], 'default' => '', 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'color: {{VALUE}}', ], ] ); $this->widget->add_control( 'post_translation_bg_color', [ 'label' => __( 'Background Color', 'sitepress' ), 'type' => Controls_Manager::COLOR, 'default' => '', 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'background-color: {{VALUE}}', ], ] ); $this->widget->add_control( 'post_translation_padding', [ 'label' => __( 'Padding', 'sitepress' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%', 'em' ], 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->widget->add_control( 'post_translation_margin', [ 'label' => __( 'Margin', 'sitepress' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%', 'em' ], 'selectors' => [ '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->widget->end_controls_section(); } /** * Render element. * * Generates the final HTML on the frontend. */ public function render() { $settings = $this->widget->get_settings_for_display(); $this->widget->add_render_attribute('wpml-elementor-ls', 'class', [ 'wpml-elementor-ls', ]); $args = array( 'display_link_for_current_lang' => $settings['link_current'], 'flags' => $settings['display_flag'], 'native' => $settings['native_language_name'], 'translated' => $settings['language_name_current_language'], 'type' => $settings['style'], ); if ( 'custom' === $settings['style'] ) { //forcing in dropdown case $args['display_link_for_current_lang'] = 1; } echo "<div " . $this->widget->get_render_attribute_string('wpml-elementor-ls') . ">"; do_action('wpml_language_switcher', $args); echo "</div>"; } } wpml-page-builders/classes/Integrations/Cornerstone/class-wpml-cornerstone-register-strings.php 0000755 00000001116 14720415745 0027326 0 ustar 00 <?php use WPML\PB\Cornerstone\Utils; class WPML_Cornerstone_Register_Strings extends WPML_Page_Builders_Register_Strings { /** * @param array $data_array * @param array $package */ protected function register_strings_for_modules( array $data_array, array $package ) { foreach ( $data_array as $data ) { if ( isset( $data['_type'] ) && ! Utils::typeIsLayout( $data['_type'] ) ) { $this->register_strings_for_node( Utils::getNodeId( $data ), $data, $package ); } elseif ( is_array( $data ) ) { $this->register_strings_for_modules( $data, $package ); } } } } wpml-page-builders/classes/Integrations/Cornerstone/class-wpml-cornerstone-translatable-nodes.php 0000755 00000025102 14720415745 0027576 0 ustar 00 <?php /** * WPML_Cornerstone_Translatable_Nodes class file. * * @package wpml-page-builders-cornerstone */ use WPML\PB\Cornerstone\Modules\ModuleWithItemsFromConfig; use WPML\FP\Obj; /** * Class WPML_Cornerstone_Translatable_Nodes */ class WPML_Cornerstone_Translatable_Nodes implements IWPML_Page_Builders_Translatable_Nodes { const SETTINGS_FIELD = '_modules'; /** * Nodes to translate. * * @var array */ protected $nodes_to_translate; /** * Get translatable node. * * @param string|int $node_id Node id. * @param array $settings Node settings. * * @return WPML_PB_String[] */ public function get( $node_id, $settings ) { if ( ! $this->nodes_to_translate ) { $this->initialize_nodes_to_translate(); } $strings = array(); foreach ( $this->nodes_to_translate as $node_type => $node_data ) { if ( $this->conditions_ok( $node_data, $settings ) ) { foreach ( $node_data['fields'] as $field ) { $field_key = $field['field']; if ( isset( $settings[ $field_key ] ) && trim( $settings[ $field_key ] ) ) { $string = new WPML_PB_String( $settings[ $field_key ], $this->get_string_name( $node_id, $field, $settings ), $field['type'], $field['editor_type'], $this->get_wrap_tag( $settings ) ); $strings[] = $string; } } foreach ( $this->get_integration_instances( $node_data ) as $node ) { $strings = $node->get( $node_id, $settings, $strings ); } } } return $strings; } /** * Update translatable node. * * @param string $node_id Node id. * @param array $settings Node settings. * @param WPML_PB_String $string String object. * * @return array */ public function update( $node_id, $settings, WPML_PB_String $string ) { if ( ! $this->nodes_to_translate ) { $this->initialize_nodes_to_translate(); } foreach ( $this->nodes_to_translate as $node_type => $node_data ) { if ( $this->conditions_ok( $node_data, $settings ) ) { foreach ( $node_data['fields'] as $field ) { $field_key = $field['field']; if ( $this->get_string_name( $node_id, $field, $settings ) === $string->get_name() ) { $settings[ $field_key ] = $string->get_value(); } } foreach ( $this->get_integration_instances( $node_data ) as $node ) { $settings = $node->update( $node_id, $settings, $string ); } } } return $settings; } /** * @param array $node_data * * @return WPML_Cornerstone_Module_With_Items[] */ private function get_integration_instances( $node_data ) { $instances = []; if ( isset( $node_data['integration-class'] ) ) { try { $instances[] = new $node_data['integration-class'](); // phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } catch ( Exception $e ) {} // phpcs:enable Generic.CodeAnalysis.EmptyStatement.DetectedCatch } if ( isset( $node_data['fields_in_item'] ) ) { foreach ( $node_data['fields_in_item'] as $config ) { $instances[] = new ModuleWithItemsFromConfig( $config ); } } return $instances; } /** * Get string name. * * @param string $node_id Node id. * @param array $field Page builder field. * @param array $settings Node settings. * * @return string */ public function get_string_name( $node_id, $field, $settings ) { return $field['field'] . '-' . $settings['_type'] . '-' . $node_id; } /** * Get wrap tag for string. * Used for SEO, can contain (h1...h6, etc.) * * @param array $settings Field settings. * * @return string */ private function get_wrap_tag( $settings ) { if ( isset( $settings['_type'] ) && 'headline' === $settings['_type'] ) { return Obj::propOr( 'h1', 'text_tag', $settings ); } return ''; } /** * Check if node condition is ok. * * @param array $node_data Node data. * @param array $settings Node settings. * * @return bool */ private function conditions_ok( $node_data, $settings ) { $conditions_meet = true; foreach ( $node_data['conditions'] as $field_key => $field_value ) { if ( ! isset( $settings[ $field_key ] ) || $settings[ $field_key ] !== $field_value ) { $conditions_meet = false; break; } } return $conditions_meet; } /** * @return array[] */ public static function get_nodes_to_translate() { return [ 'card' => [ 'conditions' => [ '_type' => 'card' ], 'fields' => [ [ 'field' => 'card_front_text_content', 'type' => __( 'Card: front text content', 'sitepress' ), 'editor_type' => 'VISUAL', ], [ 'field' => 'card_back_text_content', 'type' => __( 'Card: back text content', 'sitepress' ), 'editor_type' => 'VISUAL', ], [ 'field' => 'anchor_text_primary_content', 'type' => __( 'Card: anchor text primary content', 'sitepress' ), 'editor_type' => 'VISUAL', ], [ 'field' => 'anchor_text_secondary_content', 'type' => __( 'Card: anchor text secondary content', 'sitepress' ), 'editor_type' => 'LINE', ], [ 'field' => 'anchor_href', 'type' => __( 'Card: anchor link', 'sitepress' ), 'editor_type' => 'LINK', ], ], ], 'alert' => [ 'conditions' => [ '_type' => 'alert' ], 'fields' => [ [ 'field' => 'alert_content', 'type' => __( 'Alert Content', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'text' => [ 'conditions' => [ '_type' => 'text' ], 'fields' => [ [ 'field' => 'text_content', 'type' => __( 'Text content', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'quote' => [ 'conditions' => [ '_type' => 'quote' ], 'fields' => [ [ 'field' => 'quote_content', 'type' => __( 'Quote content', 'sitepress' ), 'editor_type' => 'VISUAL', ], [ 'field' => 'quote_cite_content', 'type' => __( 'Quote: cite content', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'counter' => [ 'conditions' => [ '_type' => 'counter' ], 'fields' => [ [ 'field' => 'counter_number_prefix_content', 'type' => __( 'Counter: number prefix', 'sitepress' ), 'editor_type' => 'LINE', ], [ 'field' => 'counter_number_suffix_content', 'type' => __( 'Counter: number suffix', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'content-area' => [ 'conditions' => [ '_type' => 'content-area' ], 'fields' => [ [ 'field' => 'content', 'type' => __( 'Content Area: content', 'sitepress' ), 'editor_type' => 'AREA', ], ], ], 'breadcrumbs' => [ 'conditions' => [ '_type' => 'breadcrumbs' ], 'fields' => [ [ 'field' => 'breadcrumbs_home_label_text', 'type' => __( 'Breadcrumbs: home label text', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'audio' => [ 'conditions' => [ '_type' => 'audio' ], 'fields' => [ [ 'field' => 'audio_embed_code', 'type' => __( 'Audio: embed code', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'headline' => [ 'conditions' => [ '_type' => 'headline' ], 'fields' => [ [ 'field' => 'text_content', 'type' => __( 'Headline text content', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'content-area-off-canvas' => [ 'conditions' => [ '_type' => 'content-area-off-canvas' ], 'fields' => [ [ 'field' => 'off_canvas_content', 'type' => __( 'Canvas content', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'content-area-modal' => [ 'conditions' => [ '_type' => 'content-area-modal' ], 'fields' => [ [ 'field' => 'modal_content', 'type' => __( 'Modal content', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'content-area-dropdown' => [ 'conditions' => [ '_type' => 'content-area-dropdown' ], 'fields' => [ [ 'field' => 'dropdown_content', 'type' => __( 'Dropdown content', 'sitepress' ), 'editor_type' => 'VISUAL', ], ], ], 'button' => [ 'conditions' => [ '_type' => 'button' ], 'fields' => [ [ 'field' => 'anchor_text_primary_content', 'type' => __( 'Anchor text: primary content', 'sitepress' ), 'editor_type' => 'LINE', ], [ 'field' => 'anchor_text_secondary_content', 'type' => __( 'Anchor text: secondary content', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'video' => [ 'conditions' => [ '_type' => 'video' ], 'fields' => [ [ 'field' => 'video_embed_code', 'type' => __( 'Video: embed code', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'search-inline' => [ 'conditions' => [ '_type' => 'search-inline' ], 'fields' => [ [ 'field' => 'search_placeholder', 'type' => __( 'Search Inline: placeholder', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'search-modal' => [ 'conditions' => [ '_type' => 'search-modal' ], 'fields' => [ [ 'field' => 'search_placeholder', 'type' => __( 'Search Modal: placeholder', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'search-dropdown' => [ 'conditions' => [ '_type' => 'search-dropdown' ], 'fields' => [ [ 'field' => 'search_placeholder', 'type' => __( 'Search Dropdown: placeholder', 'sitepress' ), 'editor_type' => 'LINE', ], ], ], 'accordion' => [ 'conditions' => [ '_type' => 'accordion' ], 'fields' => [], 'integration-class' => 'WPML_Cornerstone_Accordion', ], 'tabs' => [ 'conditions' => [ '_type' => 'tabs' ], 'fields' => [], 'integration-class' => 'WPML_Cornerstone_Tabs', ], ]; } /** * Initialize translatable nodes. */ public function initialize_nodes_to_translate() { $this->nodes_to_translate = apply_filters( 'wpml_cornerstone_modules_to_translate', self::get_nodes_to_translate() ); } } classes/Integrations/Cornerstone/class-wpml-cornerstone-handle-custom-fields-factory.php 0000755 00000000423 14720415745 0031410 0 ustar 00 wpml-page-builders <?php class WPML_PB_Cornerstone_Handle_Custom_Fields_Factory implements IWPML_Backend_Action_Loader, IWPML_AJAX_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { return new WPML_PB_Handle_Custom_Fields( new WPML_Cornerstone_Data_Settings() ); } } wpml-page-builders/classes/Integrations/Cornerstone/Hooks/ShortcodeAttributes.php 0000755 00000001420 14720415745 0024456 0 ustar 00 <?php namespace WPML\PB\Cornerstone\Hooks; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class ShortcodeAttributes implements \IWPML_Frontend_Action { public function add_hooks() { Hooks::onFilter( 'shortcode_atts_cs_content', 10, 2 ) ->then( spreadArgs( [ self::class, 'restoreContentId' ] ) ); } /** * The `_p` key in $pairs is correctly set to the current (global) post, * but it's overwritten with shortcode attribute ID copied from the original. * * @see \Themeco\Cornerstone\Services\FrontEnd::render_content() * * @param array $out * @param array $pairs * * @return array */ public static function restoreContentId( $out, $pairs ) { if ( isset( $out['_p'], $pairs['_p'] ) ) { $out['_p'] = $pairs['_p']; } return $out; } } wpml-page-builders/classes/Integrations/Cornerstone/Hooks/Editor.php 0000755 00000002612 14720415745 0021707 0 ustar 00 <?php namespace WPML\PB\Cornerstone\Hooks; use WPML\FP\Cast; use WPML\FP\Maybe; use WPML\FP\Obj; use WPML\FP\Str; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Editor implements \IWPML_Frontend_Action { public function add_hooks() { Hooks::onFilter( 'wpml_pb_is_editing_translation_with_native_editor', 10, 2 ) ->then( spreadArgs( function( $isTranslationWithNativeEditor, $translatedPostId ) { return $isTranslationWithNativeEditor || ( Str::includes( 'themeco/data/save', Obj::prop( 'REQUEST_URI', $_SERVER ) ) && self::getEditedId() === $translatedPostId ); } ) ); } /** * @return int|null */ private static function getEditedId() { /** * @see \Cornerstone_Routing::process_params * $decodeCornerstoneData :: string -> array */ $decodeCornerstoneData = function( $data ) { $request = Obj::prop( 'request', $data ); if ( Obj::prop( 'gzip', $data ) ) { return (array) json_decode( gzdecode( base64_decode( $request, true ) ), true ); } return (array) $request; }; $key = version_compare( constant( 'CS_VERSION' ), '7.1.3', '>=' ) ? 'document' : 'builder'; $getId = Obj::path( [ 'requests', $key, 'id' ] ); return Maybe::fromNullable( \WP_REST_Server::get_raw_data() ) ->map( 'json_decode' ) ->map( $decodeCornerstoneData ) ->map( $getId ) ->map( Cast::toInt() ) ->getOrElse( null ); } } wpml-page-builders/classes/Integrations/Cornerstone/Hooks/Media.php 0000755 00000001670 14720415745 0021503 0 ustar 00 <?php namespace WPML\PB\Cornerstone\Hooks; use WPML\LIB\WP\Hooks; use function WPML\FP\spreadArgs; class Media implements \IWPML_Frontend_Action, \IWPML_Backend_Action, \IWPML_DIC_Action { /** * @var \WPML_Cornerstone_Data_Settings $dataSettings */ private $dataSettings; public function __construct( \WPML_Cornerstone_Data_Settings $dataSettings ) { $this->dataSettings = $dataSettings; } public function add_hooks() { Hooks::onFilter( 'wpml_pb_get_media_updaters', PHP_INT_MAX, 2 ) ->then( spreadArgs( [ $this, 'removeUpdaterIfNotHandledByCornerstone' ] ) ); } /** * @param \IWPML_PB_Media_Update[] $updaters * @param \WP_Post $post * * @return mixed */ public function removeUpdaterIfNotHandledByCornerstone( $updaters, $post ) { if ( ! $this->dataSettings->is_handling_post( $post->ID ) ) { unset( $updaters[ \WPML_Cornerstone_Integration_Factory::SLUG ] ); } return $updaters; } } wpml-page-builders/classes/Integrations/Cornerstone/modules/ModuleWithItemsFromConfig.php 0000755 00000001520 14720415745 0026100 0 ustar 00 <?php namespace WPML\PB\Cornerstone\Modules; use WPML\FP\Fns; use WPML\FP\Lst; use WPML\FP\Obj; class ModuleWithItemsFromConfig extends \WPML_Cornerstone_Module_With_Items { /** @var array $fieldDefinitions */ private $fieldDefinitions; public function __construct( array $config ) { $keyByField = Fns::converge( Lst::zipObj(), [ Lst::pluck( 'field' ), Fns::identity() ] ); $this->fieldDefinitions = $keyByField( $config ); } /** * @inheritDoc */ public function get_title( $field ) { return Obj::path( [ $field, 'type' ], $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_fields() { return array_keys( $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_editor_type( $field ) { return Obj::path( [ $field, 'editor_type' ], $this->fieldDefinitions ); } } classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-module-with-items.php 0000755 00000004214 14720415745 0030763 0 ustar 00 wpml-page-builders <?php /** * Class WPML_Cornerstone_Module_With_Items */ abstract class WPML_Cornerstone_Module_With_Items implements IWPML_Page_Builders_Module { const ITEMS_FIELD = WPML_Cornerstone_Translatable_Nodes::SETTINGS_FIELD; /** * @param string $field * * @return string */ abstract protected function get_title( $field ); /** @return array */ abstract protected function get_fields(); /** * @param string $field * * @return string */ abstract protected function get_editor_type( $field ); /** * @param array $settings * * @return array */ protected function get_items( $settings ) { return $settings[ self::ITEMS_FIELD ]; } /** * @param string|int $node_id * @param array $settings * @param WPML_PB_String[] $strings * * @return WPML_PB_String[] */ public function get( $node_id, $settings, $strings ) { foreach ( $this->get_items( $settings ) as $item ) { foreach ( $this->get_fields() as $field ) { if ( is_array( $item[ $field ] ) ) { foreach ( $item[ $field ] as $key => $value ) { $strings[] = new WPML_PB_String( $value, $this->get_string_name( $node_id, $value, $field, $key ), $this->get_title( $field ), $this->get_editor_type( $field ) ); } } else { $strings[] = new WPML_PB_String( $item[ $field ], $this->get_string_name( $node_id, $item[ $field ], $field ), $this->get_title( $field ), $this->get_editor_type( $field ) ); } } } return $strings; } /** * @param string|int $node_id * @param array $settings * @param WPML_PB_String $string * * @return array */ public function update( $node_id, $settings, WPML_PB_String $string ) { foreach ( $this->get_items( $settings ) as $key => $item ) { foreach ( $this->get_fields() as $field ) { if ( $this->get_string_name( $node_id, $item[ $field ], $field ) === $string->get_name() ) { $settings[ self::ITEMS_FIELD ][ $key ][ $field ] = $string->get_value(); } } } return $settings; } private function get_string_name( $node_id, $value, $type, $key = '' ) { return md5( $value ) . '-' . $type . $key . '-' . $node_id; } } wpml-page-builders/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-tabs.php 0000755 00000001313 14720415745 0026413 0 ustar 00 <?php class WPML_Cornerstone_Tabs extends WPML_Cornerstone_Module_With_Items { /** * @return array */ public function get_fields() { return array( 'tab_label_content', 'tab_content' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { if ( 'tab_label_content' === $field ) { return esc_html__( 'Tabs: label', 'sitepress' ); } if ( 'tab_content' === $field ) { return esc_html__( 'Tabs: content', 'sitepress' ); } return ''; } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { if ( 'tab_label_content' === $field ) { return 'LINE'; } else { return 'VISUAL'; } } } wpml-page-builders/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-accordion.php 0000755 00000001435 14720415745 0027430 0 ustar 00 <?php class WPML_Cornerstone_Accordion extends WPML_Cornerstone_Module_With_Items { /** * @return array */ public function get_fields() { return array( 'accordion_item_header_content', 'accordion_item_content' ); } /** * @param string $field * * @return string */ protected function get_title( $field ) { if ( 'accordion_item_header_content' === $field ) { return esc_html__( 'Accordion: header content', 'sitepress' ); } if ( 'accordion_item_content' === $field ) { return esc_html__( 'Accordion: content', 'sitepress' ); } return ''; } /** * @param string $field * * @return string */ protected function get_editor_type( $field ) { if ( 'accordion_item_header_content' === $field ) { return 'LINE'; } else { return 'VISUAL'; } } } wpml-page-builders/classes/Integrations/Cornerstone/class-wpml-cornerstone-integration-factory.php 0000755 00000002762 14720415745 0030013 0 ustar 00 <?php use function WPML\Container\make; class WPML_Cornerstone_Integration_Factory { const SLUG = 'cornerstone'; public function create() { $action_filter_loader = new WPML_Action_Filter_Loader(); $action_filter_loader->load( [ 'WPML_PB_Cornerstone_Handle_Custom_Fields_Factory', 'WPML_Cornerstone_Media_Hooks_Factory', \WPML\PB\Cornerstone\Config\Factory::class, \WPML\PB\Cornerstone\Styles\Hooks::class, \WPML\PB\Cornerstone\Hooks\Editor::class, \WPML\PB\Cornerstone\Hooks\ShortcodeAttributes::class, \WPML\PB\Cornerstone\Hooks\Media::class, ] ); $nodes = new WPML_Cornerstone_Translatable_Nodes(); $data_settings = new WPML_Cornerstone_Data_Settings(); $string_registration_factory = new WPML_String_Registration_Factory( $data_settings->get_pb_name() ); $string_registration = $string_registration_factory->create(); $factory = make( WPML_PB_Factory::class ); $strategy = make( WPML_PB_API_Hooks_Strategy::class, [ ':name' => $data_settings->get_pb_name() ] ); $strategy->set_factory( $factory ); $reuse_translation = make( WPML_PB_Reuse_Translations_By_Strategy::class, [ ':strategy' => $strategy ] ); $register_strings = new WPML_Cornerstone_Register_Strings( $nodes, $data_settings, $string_registration, $reuse_translation ); $update_translation = new WPML_Cornerstone_Update_Translation( $nodes, $data_settings ); return new WPML_Page_Builders_Integration( $register_strings, $update_translation, $data_settings ); } } wpml-page-builders/classes/Integrations/Cornerstone/Styles/Hooks.php 0000755 00000002321 14720415745 0021741 0 ustar 00 <?php namespace WPML\PB\Cornerstone\Styles; use WPML\FP\Fns; use WPML\FP\Logic; use WPML\FP\Maybe; use WPML\LIB\WP\Post; class Hooks implements \IWPML_Backend_Action, \IWPML_Frontend_Action, \IWPML_DIC_Action { const META_KEY_OLD = '_cs_generated_styles'; const META_KEY_V6 = '_cs_generated_tss'; /** @var callable $shouldInvalidateStyle */ private $shouldInvalidateStyles; /** * Hooks constructor. * * @param \WPML_PB_Last_Translation_Edit_Mode $lastEditMode * @param \WPML_Cornerstone_Data_Settings $dataSettings */ public function __construct( \WPML_PB_Last_Translation_Edit_Mode $lastEditMode, \WPML_Cornerstone_Data_Settings $dataSettings ) { $this->shouldInvalidateStyles = Logic::both( [ $dataSettings, 'is_handling_post' ], [ $lastEditMode, 'is_translation_editor' ] ); } public function add_hooks() { add_action( 'save_post', [ $this, 'invalidateStylesInTranslation' ] ); } /** * @param int $postId */ public function invalidateStylesInTranslation( $postId ) { Maybe::of( $postId ) ->filter( $this->shouldInvalidateStyles ) ->map( Fns::tap( Post::deleteMeta( Fns::__, self::META_KEY_V6 ) ) ) ->map( Fns::tap( Post::deleteMeta( Fns::__, self::META_KEY_OLD ) ) ); } } classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-hooks-factory.php 0000755 00000000452 14720415745 0030662 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Hooks_Factory implements IWPML_Backend_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { return new WPML_Page_Builders_Media_Hooks( new WPML_Cornerstone_Update_Media_Factory(), WPML_Cornerstone_Integration_Factory::SLUG ); } } classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-nodes-iterator.php 0000755 00000002452 14720415745 0031033 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Nodes_Iterator implements IWPML_PB_Media_Nodes_Iterator { const ITEMS_FIELD = WPML_Cornerstone_Module_With_Items::ITEMS_FIELD; /** @var WPML_Cornerstone_Media_Node_Provider $node_provider */ private $node_provider; public function __construct( WPML_Cornerstone_Media_Node_Provider $node_provider ) { $this->node_provider = $node_provider; } /** * @param array $data_array * @param string $lang * @param string $source_lang * * @return array */ public function translate( $data_array, $lang, $source_lang ) { foreach ( $data_array as $key => &$data ) { if ( isset( $data[ self::ITEMS_FIELD ] ) && $data[ self::ITEMS_FIELD ] ) { $data[ self::ITEMS_FIELD ] = $this->translate( $data[ self::ITEMS_FIELD ], $lang, $source_lang ); } elseif ( is_numeric( $key ) && isset( $data['_type'] ) ) { $data = $this->translate_node( $data, $lang, $source_lang ); } } return $data_array; } /** * @param stdClass $settings * @param string $lang * @param string $source_lang * * @return stdClass */ private function translate_node( $settings, $lang, $source_lang ) { $node = $this->node_provider->get( $settings['_type'] ); if ( $node ) { $settings = $node->translate( $settings, $lang, $source_lang ); } return $settings; } } classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-image.php 0000755 00000000253 14720415745 0031546 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Node_Image extends WPML_Cornerstone_Media_Node_With_URLs { protected function get_keys() { return array( 'image_src', ); } } Integrations/Cornerstone/media/modules/abstract/class-wpml-cornerstone-media-node-with-urls.php 0000755 00000001606 14720415745 0034230 0 ustar 00 wpml-page-builders/classes <?php abstract class WPML_Cornerstone_Media_Node_With_URLs extends WPML_Cornerstone_Media_Node { /** @return array */ abstract protected function get_keys(); /** * @param array $node_data * @param string $target_lang * @param string $source_lang * * @return array */ public function translate( $node_data, $target_lang, $source_lang ) { foreach ( $this->get_keys() as $key ) { if ( ! empty( $node_data[ $key ] ) ) { list( $attachment_id, $type ) = explode( ':', $node_data[ $key ], 2 ); if ( is_numeric( $attachment_id ) ) { $attachment_id = apply_filters( 'wpml_object_id', $attachment_id, 'attachment', true, $target_lang ); $node_data[ $key ] = $attachment_id . ':' . $type; } else { $node_data[ $key ] = $this->media_translate->translate_image_url( $node_data[ $key ], $target_lang, $source_lang ); } } } return $node_data; } } classes/Integrations/Cornerstone/media/modules/abstract/class-wpml-cornerstone-media-node.php 0000755 00000000737 14720415745 0032300 0 ustar 00 wpml-page-builders <?php abstract class WPML_Cornerstone_Media_Node { /** @var WPML_Page_Builders_Media_Translate $media_translate */ protected $media_translate; public function __construct( WPML_Page_Builders_Media_Translate $media_translate ) { $this->media_translate = $media_translate; } /** * @param array $node_data * @param string $target_lang * @param string $source_lang * * @return array */ abstract function translate( $node_data, $target_lang, $source_lang ); } Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-feature-box.php 0000755 00000000275 14720415745 0034330 0 ustar 00 wpml-page-builders/classes <?php class WPML_Cornerstone_Media_Node_Classic_Feature_Box extends WPML_Cornerstone_Media_Node_With_URLs { protected function get_keys() { return array( 'graphic_image', ); } } classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-promo.php 0000755 00000000257 14720415745 0033243 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Node_Classic_Promo extends WPML_Cornerstone_Media_Node_With_URLs { protected function get_keys() { return array( 'image', ); } } classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-card.php 0000755 00000000264 14720415745 0033016 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Node_Classic_Card extends WPML_Cornerstone_Media_Node_With_URLs { protected function get_keys() { return array( 'front_image', ); } } Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-creative-cta.php 0000755 00000000266 14720415745 0034456 0 ustar 00 wpml-page-builders/classes <?php class WPML_Cornerstone_Media_Node_Classic_Creative_CTA extends WPML_Cornerstone_Media_Node_With_URLs { protected function get_keys() { return array( 'image', ); } } classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-image.php 0000755 00000000255 14720415745 0033167 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Node_Classic_Image extends WPML_Cornerstone_Media_Node_With_URLs { protected function get_keys() { return array( 'src', ); } } classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-node-provider.php 0000755 00000002542 14720415745 0030651 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Media_Node_Provider { private $media_translate; private $nodes = array(); public function __construct( WPML_Page_Builders_Media_Translate $media_translate ) { $this->media_translate = $media_translate; } /** * @param string $type * * @return WPML_Cornerstone_Media_Node|null */ public function get( $type ) { if ( ! array_key_exists( $type, $this->nodes ) ) { $this->add( $type ); } return $this->nodes[ $type ]; } /** * @param string $type */ private function add( $type ) { switch ( $type ) { case 'image': $node = new WPML_Cornerstone_Media_Node_Image( $this->media_translate ); break; case 'classic:creative-cta': $node = new WPML_Cornerstone_Media_Node_Classic_Creative_CTA( $this->media_translate ); break; case 'classic:feature-box': $node = new WPML_Cornerstone_Media_Node_Classic_Feature_Box( $this->media_translate ); break; case 'classic:card': $node = new WPML_Cornerstone_Media_Node_Classic_Card( $this->media_translate ); break; case 'classic:image': $node = new WPML_Cornerstone_Media_Node_Classic_Image( $this->media_translate ); break; case 'classic:promo': $node = new WPML_Cornerstone_Media_Node_Classic_Promo( $this->media_translate ); break; default: $node = null; } $this->nodes[ $type ] = $node; } } classes/Integrations/Cornerstone/media/class-wpml-cornerstone-update-media-factory.php 0000755 00000002172 14720415745 0031022 0 ustar 00 wpml-page-builders <?php class WPML_Cornerstone_Update_Media_Factory implements IWPML_PB_Media_Update_Factory { /** @var WPML_Page_Builders_Media_Translate|null $media_translate */ private $media_translate; public function create() { global $sitepress; return new WPML_Page_Builders_Update_Media( new WPML_Page_Builders_Update( new WPML_Cornerstone_Data_Settings() ), new WPML_Translation_Element_Factory( $sitepress ), new WPML_Cornerstone_Media_Nodes_Iterator( new WPML_Cornerstone_Media_Node_Provider( $this->get_media_translate() ) ), new WPML_Page_Builders_Media_Usage( $this->get_media_translate(), new WPML_Media_Usage_Factory() ) ); } /** @return WPML_Page_Builders_Media_Translate */ private function get_media_translate() { global $sitepress; if ( ! $this->media_translate ) { $this->media_translate = new WPML_Page_Builders_Media_Translate( new WPML_Translation_Element_Factory( $sitepress ), new WPML_Media_Image_Translate( $sitepress, new WPML_Media_Attachment_By_URL_Factory(), new \WPML\Media\Factories\WPML_Media_Attachment_By_URL_Query_Factory() ) ); } return $this->media_translate; } } wpml-page-builders/classes/Integrations/Cornerstone/class-wpml-cornerstone-utils.php 0000755 00000001364 14720415745 0025160 0 ustar 00 <?php namespace WPML\PB\Cornerstone; class Utils { const MODULE_TYPE_PREFIX = 'classic:'; const LAYOUT_TYPES = [ 'bar', 'container', 'section', 'row', 'column', 'layout-row', 'layout-column', 'layout-grid', 'layout-cell', 'layout-div', ]; /** * @param array $data * @return string */ public static function getNodeId( $data ) { return md5( serialize( $data ) ); } /** * Check if the type is a layout type. * * @param string $type The type to check. * @return bool */ public static function typeIsLayout( $type ) { // Remove the classic prefix before checking. $type = preg_replace( '/^' . self::MODULE_TYPE_PREFIX . '/', '', $type ); return in_array( $type, self::LAYOUT_TYPES, true ); } } wpml-page-builders/classes/Integrations/Cornerstone/Config/Factory.php 0000755 00000000654 14720415745 0022216 0 ustar 00 <?php namespace WPML\PB\Cornerstone\Config; class Factory extends \WPML\PB\Config\Factory { const DATA = [ 'configRoot' => 'cornerstone-widgets', 'defaultConditionKey' => '_type', 'pbKey' => 'cornerstone', 'translatableWidgetsHook' => 'wpml_cornerstone_modules_to_translate', ]; /** * @inheritDoc */ protected function getPbData( $key ) { return self::DATA[ $key ]; } } wpml-page-builders/classes/Integrations/Cornerstone/class-wpml-cornerstone-data-settings.php 0000755 00000002447 14720415745 0026572 0 ustar 00 <?php class WPML_Cornerstone_Data_Settings implements IWPML_Page_Builders_Data_Settings { /** * @return string */ public function get_meta_field() { return '_cornerstone_data'; } /** * @return string */ public function get_node_id_field() { return '_type'; } /** * @return array */ public function get_fields_to_copy() { return array( '_cornerstone_settings', '_cornerstone_version', 'post_content' ); } /** * @param array $data * * @return array */ public function convert_data_to_array( $data ) { $converted_data = $data; if ( is_array( $data ) ) { $converted_data = $data[0]; } return json_decode( $converted_data, true ); } /** * @param array $data * * @return string */ public function prepare_data_for_saving( array $data ) { return wp_slash( wp_json_encode( $data ) ); } /** * @return string */ public function get_pb_name() { return 'Cornerstone'; } /** * @return array */ public function get_fields_to_save() { return array( '_cornerstone_data' ); } public function add_hooks() { } /** * @param int $postId * * @return bool */ public function is_handling_post( $postId ) { return get_post_meta( $postId, $this->get_meta_field(), true ) && ! get_post_meta( $postId, '_cornerstone_override', true ); } } wpml-page-builders/classes/Integrations/Cornerstone/class-wpml-cornerstone-update-translation.php 0000755 00000001703 14720415745 0027633 0 ustar 00 <?php use WPML\PB\Cornerstone\Utils; class WPML_Cornerstone_Update_Translation extends WPML_Page_Builders_Update_Translation { /** @param array $data_array */ public function update_strings_in_modules( array &$data_array ) { foreach ( $data_array as $key => &$data ) { if ( isset( $data['_type'] ) && ! Utils::typeIsLayout( $data['_type'] ) ) { $data = $this->update_strings_in_node( Utils::getNodeId( $data ), $data ); } elseif ( is_array( $data ) ) { $this->update_strings_in_modules( $data ); } } } /** * @param string $node_id * @param array $settings * * @return mixed */ protected function update_strings_in_node( $node_id, $settings ) { $strings = $this->translatable_nodes->get( $node_id, $settings ); foreach ( $strings as $string ) { $translation = $this->get_translation( $string ); $settings = $this->translatable_nodes->update( $node_id, $settings, $translation ); } return $settings; } } wpml-page-builders/classes/Integrations/SiteOrigin/TranslatableNodes.php 0000755 00000011634 14720415745 0022562 0 ustar 00 <?php namespace WPML\PB\SiteOrigin; use WPML\FP\Obj; use WPML\PB\SiteOrigin\Modules\ModuleWithItemsFromConfig; class TranslatableNodes implements \IWPML_Page_Builders_Translatable_Nodes { const SETTINGS_FIELD = 'panels_info'; const CHILDREN_FIELD = 'panels_data'; const WRAPPING_MODULES = [ 'SiteOrigin_Panels_Widgets_Layout', ]; /** * Nodes to translate. * * @var array */ private $translatableNodes; /** * Get translatable node. * * @param string|int $node_id Node id. * @param array $settings Node settings. * * @return \WPML_PB_String[] */ public function get( $node_id, $settings ) { $strings = []; foreach ( $this->getTranslatableNodes() as $node_data ) { if ( $this->conditions_ok( $node_data, $settings ) ) { foreach ( $node_data['fields'] as $field ) { $field_key = $field['field']; $pathInFlatField = self::get_partial_path( $field_key ); $string_value = Obj::path( $pathInFlatField, $settings ); if ( $string_value ) { $string = new \WPML_PB_String( $string_value, $this->get_string_name( $node_id, $field, $settings ), $field['type'], $field['editor_type'], $this->get_wrap_tag( $settings ) ); $strings[] = $string; } } foreach ( $this->get_integration_instances( $node_data ) as $node ) { $strings = $node->get( $node_id, $settings, $strings ); } } } return $strings; } /** * Update translatable node. * * @param string $node_id Node id. * @param array $settings Node settings. * @param \WPML_PB_String $string String object. * * @return mixed */ public function update( $node_id, $settings, \WPML_PB_String $string ) { foreach ( $this->getTranslatableNodes() as $node_data ) { if ( $this->conditions_ok( $node_data, $settings ) ) { foreach ( $node_data['fields'] as $field ) { $field_key = $field['field']; if ( $this->get_string_name( $node_id, $field, $settings ) === $string->get_name() ) { $pathInFlatField = self::get_partial_path( $field_key ); $stringInFlatField = Obj::path( $pathInFlatField, $settings ); if ( is_string( $stringInFlatField ) ) { $settings = Obj::assocPath( $pathInFlatField, $string->get_value(), $settings ); } } } foreach ( $this->get_integration_instances( $node_data ) as $node ) { list( $key, $item ) = $node->update( $node_id, $settings, $string ); if ( $item ) { if ( strpos( $key, '>' ) ) { $pathInFlatField = $node->get_field_path( $key ); } else { $pathInFlatField = self::get_partial_path( $node->get_items_field() ); $pathInFlatField[] = $key; } $settings = Obj::assocPath( $pathInFlatField, $item, $settings ); } } } } return $settings; } /** * @param string $field * * @return string[] */ private static function get_partial_path( $field ) { return explode( '>', $field ); } /** * @param array $node_data * * @return ModuleWithItemsFromConfig[] */ private function get_integration_instances( array $node_data ) { $instances = []; if ( isset( $node_data['fields_in_item'] ) ) { foreach ( $node_data['fields_in_item'] as $item_of => $config ) { $instances[] = new ModuleWithItemsFromConfig( $item_of, $config ); } } return array_filter( $instances ); } /** * Get string name. * * @param string $node_id Node id. * @param array $field Page builder field. * @param array $settings Node settings. * * @return string */ public function get_string_name( $node_id, $field, $settings ) { return $node_id . '-' . $settings[ self::SETTINGS_FIELD ]['id'] . '-' . $field['field']; } /** * Get wrap tag for string. * Used for SEO, can contain (h1...h6, etc.) * * @param array $settings Field settings. * * @return string */ private function get_wrap_tag( $settings ) { return ''; } /** * Check if node condition is ok. * * @param array $node_data Node data. * @param array $settings Node settings. * * @return bool */ private function conditions_ok( $node_data, $settings ) { $conditions_meet = true; foreach ( $node_data['conditions'] as $field_value ) { if ( $settings[ self::SETTINGS_FIELD ]['class'] !== $field_value ) { $conditions_meet = false; break; } } return $conditions_meet; } private function getTranslatableNodes() { if ( null === $this->translatableNodes ) { $this->translatableNodes = $this->initialize_nodes_to_translate(); } return $this->translatableNodes; } public function initialize_nodes_to_translate() { return apply_filters( 'wpml_siteorigin_modules_to_translate', [] ); } /** * @param array $module * * @return bool */ public static function isWrappingModule( $module ) { return isset( $module[ self::CHILDREN_FIELD ] ) && in_array( Obj::path( [ self::SETTINGS_FIELD, 'class' ], $module ), self::WRAPPING_MODULES, true ); } } wpml-page-builders/classes/Integrations/SiteOrigin/RegisterStrings.php 0000755 00000001262 14720415745 0022307 0 ustar 00 <?php namespace WPML\PB\SiteOrigin; class RegisterStrings extends \WPML_Page_Builders_Register_Strings { public function register_strings_for_modules( array $data_array, array $package ) { foreach ( $data_array as $data ) { if ( isset( $data[ TranslatableNodes::SETTINGS_FIELD ] ) ) { if ( TranslatableNodes::isWrappingModule( $data ) ) { $this->register_strings_for_modules( $data[ TranslatableNodes::CHILDREN_FIELD ], $package ); } else { $this->register_strings_for_node( $data[ TranslatableNodes::SETTINGS_FIELD ]['class'], $data, $package ); } } elseif ( is_array( $data ) ) { $this->register_strings_for_modules( $data, $package ); } } } } wpml-page-builders/classes/Integrations/SiteOrigin/UpdateTranslation.php 0000755 00000002122 14720415745 0022606 0 ustar 00 <?php namespace WPML\PB\SiteOrigin; class UpdateTranslation extends \WPML_Page_Builders_Update_Translation { /** @param array $data_array */ public function update_strings_in_modules( array &$data_array ) { foreach ( $data_array as &$data ) { if ( isset( $data[ TranslatableNodes::SETTINGS_FIELD ] ) ) { if ( TranslatableNodes::isWrappingModule( $data ) ) { $this->update_strings_in_modules( $data[ TranslatableNodes::CHILDREN_FIELD ] ); } else { $data = $this->update_strings_in_node( $data[ TranslatableNodes::SETTINGS_FIELD ]['class'], $data ); } } elseif ( is_array( $data ) ) { $this->update_strings_in_modules( $data ); } } } /** * @param string $node_id * @param array $settings * * @return mixed */ public function update_strings_in_node( $node_id, $settings ) { $strings = $this->translatable_nodes->get( $node_id, $settings ); foreach ( $strings as $string ) { $translation = $this->get_translation( $string ); $settings = $this->translatable_nodes->update( $node_id, $settings, $translation ); } return $settings; } } wpml-page-builders/classes/Integrations/SiteOrigin/DataSettings.php 0000755 00000004512 14720415745 0021544 0 ustar 00 <?php namespace WPML\PB\SiteOrigin; use WPML\FP\Obj; class DataSettings implements \IWPML_Page_Builders_Data_Settings { /** * @return string */ public function get_meta_field() { return 'panels_data'; } /** * @return string */ public function get_node_id_field() { return 'widget_id'; } /** * @return array */ public function get_fields_to_copy() { return []; } /** * @param array $data * * @return array */ public function convert_data_to_array( $data ) { return $data; } /** * @param array $data * * @return array */ public function prepare_data_for_saving( array $data ) { return $data; } /** * @return string */ public function get_pb_name() { return 'SiteOrigin'; } /** * @return array */ public function get_fields_to_save() { return [ $this->get_meta_field() ]; } public function add_hooks() { add_filter( 'pre_wpml_is_translated_taxonomy', [ $this, 'filterMenus' ], 10, 2 ); add_filter( 'siteorigin_panels_widgets', [ $this, 'removeWidgets' ] ); add_filter( 'siteorigin_panels_widget_form', [ $this, 'removeLanguageSelector' ] ); } /** * By letting WPML think `nav_menu` is translatable, it will filter out items in other languages. * To avoid interfeering with anything else, we do this only for the SiteOrigin menu widget. * * @param bool|null $result * @param string $tax * * @return bool|null */ public function filterMenus( $result, $tax ) { /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */ if ( is_admin() && 'nav_menu' === $tax && Obj::prop( 'action', $_REQUEST ) === 'so_panels_widget_form' ) { $result = true; } return $result; } /** * @param array $widgets * * @return array */ public function removeWidgets( $widgets ) { unset( $widgets['WPML_LS_Widget'], $widgets['WP_Widget_Text_Icl'] ); return $widgets; } /** * @param int $postId * * @return bool */ public function is_handling_post( $postId ) { return (bool) get_post_meta( $postId, $this->get_meta_field(), true ); } /** * @param string $form * * @return string */ public function removeLanguageSelector( $form ) { $form = preg_replace( '/<p>[\n\r\t]*<label for="wpml-language">.*<\/p>/s', '', $form, 1 ); $form = preg_replace( '/<select name="icl_language">.*<\/label>/s', '', $form, 1 ); return $form; } } wpml-page-builders/classes/Integrations/SiteOrigin/Factory.php 0000755 00000001244 14720415745 0020560 0 ustar 00 <?php namespace WPML\PB\SiteOrigin; class Factory { public function create() { $loader = new \WPML_Action_Filter_Loader(); $loader->load( [ HandleCustomFieldsFactory::class, Config\Factory::class, ] ); $nodes = new TranslatableNodes(); $dataSettings = new DataSettings(); $stringRegistrationFactory = new \WPML_String_Registration_Factory( $dataSettings->get_pb_name() ); $stringRegistration = $stringRegistrationFactory->create(); return new \WPML_Page_Builders_Integration( new RegisterStrings( $nodes, $dataSettings, $stringRegistration ), new UpdateTranslation( $nodes, $dataSettings ), $dataSettings ); } } wpml-page-builders/classes/Integrations/SiteOrigin/HandleCustomFieldsFactory.php 0000755 00000000503 14720415745 0024213 0 ustar 00 <?php namespace WPML\PB\SiteOrigin; class HandleCustomFieldsFactory implements \IWPML_Backend_Action_Loader, \IWPML_AJAX_Action_Loader, \IWPML_Frontend_Action_Loader { /** * @return \WPML_PB_Handle_Custom_Fields */ public function create() { return new \WPML_PB_Handle_Custom_Fields( new DataSettings() ); } } wpml-page-builders/classes/Integrations/SiteOrigin/Config/Factory.php 0000755 00000000651 14720415745 0021766 0 ustar 00 <?php namespace WPML\PB\SiteOrigin\Config; class Factory extends \WPML\PB\Config\Factory { const DATA = [ 'configRoot' => 'siteorigin-widgets', 'defaultConditionKey' => '_type', 'pbKey' => 'siteorigin', 'translatableWidgetsHook' => 'wpml_siteorigin_modules_to_translate', ]; /** * @inheritDoc */ protected function getPbData( $key ) { return self::DATA[ $key ]; } } wpml-page-builders/classes/Integrations/SiteOrigin/Modules/ModuleWithItems.php 0000755 00000004755 14720415745 0023656 0 ustar 00 <?php namespace WPML\PB\SiteOrigin\Modules; use WPML\FP\Obj; abstract class ModuleWithItems implements \IWPML_Page_Builders_Module { /** * @param string $field * * @return string */ abstract protected function get_title( $field ); /** @return array */ abstract protected function get_fields(); /** * @param string $field * * @return string */ abstract protected function get_editor_type( $field ); /** * @return string */ abstract public function get_items_field(); /** * @param mixed $settings * * @return array */ abstract public function get_items( $settings ); /** * @param string|int $node_id * @param mixed $settings * @param \WPML_PB_String[] $strings * * @return \WPML_PB_String[] */ public function get( $node_id, $settings, $strings ) { foreach ( $this->get_items( $settings ) as $key => $item ) { foreach( $this->get_fields() as $field ) { $pathInFlatField = explode( '>', $field ); $string_value = Obj::path( $pathInFlatField, $item ); if ( $string_value ) { $strings[] = new \WPML_PB_String( $string_value, $this->get_string_name( $node_id, $this->get_items_field(), $key, $field ), $this->get_title( $field ), $this->get_editor_type( $field ) ); } } } return $strings; } /** * @param string|int $node_id * @param mixed $element * @param \WPML_PB_String $string * * @return array */ public function update( $node_id, $element, \WPML_PB_String $string ) { foreach ( $this->get_items( $element ) as $key => $item ) { foreach( $this->get_fields() as $field ) { if ( $this->get_string_name( $node_id, $this->get_items_field(), $key, $field ) == $string->get_name() ) { $pathInFlatField = explode( '>', $field ); $stringInFlatField = Obj::path( $pathInFlatField, $item ); if ( is_string( $stringInFlatField ) ) { $item = Obj::assocPath( $pathInFlatField, $string->get_value(), $item ); } return [ $key, $item ]; } } } return [ null, null ]; } private function get_string_name( $node_id, $type, $key, $field ) { return $node_id . '-' . $type . '-' . $key . '-' . $field; } /** * @param string $key * * @return array */ public function get_field_path( $key ) { $path = $this->get_items_field(); if ( strpos( $path, '>' ) ) { list( $parent, $path ) = explode( '>', $path, 2 ); list( $x, $y ) = explode( '>', $key, 2 ); return [ $parent, $x, $path, $y ]; } else { return [ $path, $key ]; } } } wpml-page-builders/classes/Integrations/SiteOrigin/Modules/ModuleWithItemsFromConfig.php 0000755 00000003515 14720415745 0025621 0 ustar 00 <?php namespace WPML\PB\SiteOrigin\Modules; use WPML\FP\Fns; use WPML\FP\Lst; use WPML\FP\Obj; class ModuleWithItemsFromConfig extends ModuleWithItems { /** @var array $fieldDefinitions */ private $fieldDefinitions = []; /** @var string $itemsField */ private $itemsField; /** * @param string $itemsField * @param array $config */ public function __construct( $itemsField, array $config ) { $this->itemsField = $itemsField; $this->init( $config ); } private function init( array $config ) { $keyByField = Fns::converge( Lst::zipObj(), [ Lst::pluck( 'field' ), Fns::identity() ] ); $this->fieldDefinitions = $keyByField( $config ); } private function getFieldData( $field, $key ) { return Obj::path( [ $field, $key ], $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_title( $field ) { return $this->getFieldData( $field, 'type' ); } /** * @inheritDoc */ public function get_fields() { return array_keys( $this->fieldDefinitions ); } /** * @inheritDoc */ public function get_editor_type( $field ) { return $this->getFieldData( $field, 'editor_type' ); } /** * @inheritDoc */ public function get_items_field() { return $this->itemsField; } /** * @param array $settings * * @return array */ public function get_items( $settings ) { $path = $this->get_items_field(); $pathInFlatField = explode( '>', $path ); $items = Obj::path( $pathInFlatField, $settings ); if ( is_null( $items ) ) { list( $parent, $path ) = explode( '>', $path, 2 ); $settings = $settings[ $parent ]; $items = []; foreach ( $settings as $x => $setting ) { foreach ( $setting[ $path ] as $y => $item ) { $items = Obj::assocPath( [ $x . '>' . $y ], $item, $items ); } } } return $items; } } wpml-page-builders/classes/LegacyIntegration.php 0000755 00000005311 14720415745 0016036 0 ustar 00 <?php namespace WPML\PB; use function WPML\Container\make; class LegacyIntegration { public static function load() { /** @var \SitePress $sitepress */ global $sitepress; $integrationClasses = []; // WPBakery Page Builder (a.k.a. Visual Composer). if ( defined( 'WPB_VC_VERSION' ) ) { $wpml_visual_composer = new \WPML_Compatibility_Plugin_Visual_Composer( new \WPML_Debug_BackTrace( null, 12 ) ); $wpml_visual_composer->add_hooks(); $wpml_visual_composer_grid = new \WPML_Compatibility_Plugin_Visual_Composer_Grid_Hooks( $sitepress, new \WPML_Translation_Element_Factory( $sitepress ) ); $wpml_visual_composer_grid->add_hooks(); make( \WPML\Compatibility\WPBakery\Styles::class )->add_hooks(); } if ( defined( 'FUSION_BUILDER_VERSION' ) ) { $integrationClasses[] = \WPML_Compatibility_Plugin_Fusion_Hooks_Factory::class; $integrationClasses[] = \WPML\Compatibility\FusionBuilder\Frontend\Hooks::class; $integrationClasses[] = \WPML\Compatibility\FusionBuilder\Backend\Hooks::class; $integrationClasses[] = \WPML\Compatibility\FusionBuilder\DynamicContent::class; $integrationClasses[] = \WPML\Compatibility\FusionBuilder\FormContent::class; $integrationClasses[] = \WPML\Compatibility\FusionBuilder\Hooks\Editor::class; } if ( function_exists( 'avia_lang_setup' ) ) { // phpcs:disable WordPress.NamingConventions.ValidVariableName global $iclTranslationManagement; $enfold = new \WPML_Compatibility_Theme_Enfold( $iclTranslationManagement ); // phpcs:enable $enfold->init_hooks(); } if ( defined( 'ET_BUILDER_THEME' ) || defined( 'ET_BUILDER_PLUGIN_VERSION' ) ) { $integrationClasses[] = \WPML_Compatibility_Divi::class; $integrationClasses[] = \WPML\Compatibility\Divi\DynamicContent::class; $integrationClasses[] = \WPML\Compatibility\Divi\Search::class; $integrationClasses[] = \WPML\Compatibility\Divi\DiviOptionsEncoding::class; $integrationClasses[] = \WPML\Compatibility\Divi\ThemeBuilderFactory::class; $integrationClasses[] = \WPML\Compatibility\Divi\Builder::class; $integrationClasses[] = \WPML\Compatibility\Divi\TinyMCE::class; $integrationClasses[] = \WPML\Compatibility\Divi\DisplayConditions::class; $integrationClasses[] = \WPML\Compatibility\Divi\DoubleQuotes::class; $integrationClasses[] = \WPML\Compatibility\Divi\WooShortcodes::class; // @todo: replace with config - wpmlpb-275 $integrationClasses[] = \WPML\Compatibility\Divi\Hooks\Editor::class; $integrationClasses[] = \WPML\Compatibility\Divi\Hooks\DomainsBackendEditor::class; $integrationClasses[] = \WPML\Compatibility\Divi\Hooks\GutenbergUpdate::class; } $loader = new \WPML_Action_Filter_Loader(); $loader->load( $integrationClasses ); } } wpml-page-builders/classes/App.php 0000755 00000001704 14720415745 0013150 0 ustar 00 <?php namespace WPML\PB; class App { public static function run() { global $sitepress, $wpdb; LegacyIntegration::load(); if ( $sitepress->is_setup_complete() && has_action( 'wpml_before_init', 'load_wpml_st_basics' ) ) { if ( self::shouldLoadTMHooks() ) { $page_builder_hooks = new \WPML_TM_Page_Builders_Hooks( new \WPML_TM_Page_Builders( $sitepress ), $sitepress ); $page_builder_hooks->init_hooks(); } $app = new \WPML_Page_Builders_App( new \WPML_Page_Builders_Defined() ); $app->add_hooks(); new \WPML_PB_Loader( new \WPML_ST_Settings() ); } } /** * @return bool */ private static function shouldLoadTMHooks() { return defined( 'WPML_TM_VERSION' ) && ( is_admin() || ( defined( 'XMLRPC_REQUEST' ) && constant( 'XMLRPC_REQUEST' ) ) || wpml_is_rest_request() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ); } } wpml-page-builders/classes/Shared/Abstracts/BaseDynamicContent.php 0000755 00000003312 14720415745 0021273 0 ustar 00 <?php namespace WPML\Compatibility; use SitePress; abstract class BaseDynamicContent implements \IWPML_DIC_Action, \IWPML_Backend_Action, \IWPML_Frontend_Action { /** @var SitePress */ private $sitepress; /** * @param SitePress $sitepress */ public function __construct( SitePress $sitepress ) { $this->sitepress = $sitepress; } /** * Add filters and actions. */ public function add_hooks() { if ( $this->sitepress->is_setup_complete() ) { add_filter( 'wpml_pb_shortcode_decode', [ $this, 'decode_dynamic_content' ], 10, 2 ); add_filter( 'wpml_pb_shortcode_encode', [ $this, 'encode_dynamic_content' ], 10, 2 ); } } /** * Sets dynamic content to be translatable. * * @param string $string The decoded string so far. * @param string $encoding The encoding used. * * @return string|array */ abstract public function decode_dynamic_content( $string, $encoding ); /** * Rebuilds dynamic content with translated strings. * * @param string|array $string The field array or string. * @param string $encoding The encoding used. * * @return string */ abstract public function encode_dynamic_content( $string, $encoding ); /** * Check if a certain field contains dynamic content. * * @param string $string The string to check. * * @return bool */ abstract protected function is_dynamic_content( $string ); /** * Decode a dynamic-content field. * * @param string $string The string to decode. * * @return array */ abstract protected function decode_field( $string ); /** * Encode a dynamic-content field. * * @param array $field The field to encode. * * @return string */ abstract protected function encode_field( $field ); } wpml-page-builders/classes/Shared/Shutdown/Hooks.php 0000755 00000002434 14720415745 0016535 0 ustar 00 <?php namespace WPML\PB\Shutdown; class Hooks implements \IWPML_Frontend_Action, \IWPML_Backend_Action, \IWPML_DIC_Action { const PRIORITY_REGISTER_STRINGS = 10; const PRIORITY_SAVE_TRANSLATIONS_TO_POST = 20; const PRIORITY_TRANSLATE_MEDIA = 30; /** @var \WPML_PB_Integration $pbIntegration */ private $pbIntegration; public function __construct( \WPML_PB_Integration $pbIntegration ) { $this->pbIntegration = $pbIntegration; } public function add_hooks() { add_action( 'shutdown', [ $this, 'registerStrings' ], self::PRIORITY_REGISTER_STRINGS ); add_action( 'shutdown', [ $this->pbIntegration, 'save_translations_to_post' ], self::PRIORITY_SAVE_TRANSLATIONS_TO_POST ); add_action( 'shutdown', [ $this, 'translateMedias' ], self::PRIORITY_TRANSLATE_MEDIA ); } /** * This applies only on original posts. */ public function registerStrings() { foreach( $this->pbIntegration->get_save_post_queue() as $post ) { $this->pbIntegration->register_all_strings_for_translation( $post ); } } /** * This applies only on post translations. */ public function translateMedias() { if ( defined( 'WPML_MEDIA_VERSION' ) ) { foreach( $this->pbIntegration->get_save_post_queue() as $post ) { $this->pbIntegration->translate_media( $post ); } } } } wpml-page-builders/classes/Shared/Shortcode/AdjustIdsHooks.php 0000755 00000002737 14720415745 0020475 0 ustar 00 <?php namespace WPML\PB\Shortcode; use WPML\Convert\Ids; use WPML\FP\Fns; use WPML\FP\Obj; use WPML\LIB\WP\Hooks; use WPML_PB_Config_Import_Shortcode; use function WPML\FP\curryN; use function WPML\FP\spreadArgs; class AdjustIdsHooks implements \IWPML_Frontend_Action, \IWPML_DIC_Action { /** * @var WPML_PB_Config_Import_Shortcode $config */ private $config; public function __construct( WPML_PB_Config_Import_Shortcode $config ) { $this->config = $config; } public function add_hooks() { Hooks::onFilter( 'pre_do_shortcode_tag', - PHP_INT_MAX, 4 ) ->then( spreadArgs( Fns::withoutRecursion( Fns::identity(), [ $this, 'convertAttributeIds' ] ) ) ); } /** * @param false|string $bool * @param string $tag * @param array $attr * @param array $m * * @return false|string */ public function convertAttributeIds( $bool, $tag, $attr, $m ) { $tagConfig = $this->getConfig( $tag ); if ( $tagConfig ) { $convert = curryN( 2, function( $type, $arr ) { return $arr[1] . Ids::convert( $arr[2], $type, true ); } ); foreach ( $tagConfig as $attribute => $type ) { $convertTypeIds = $convert( $type ); $m = preg_replace_callback( '/(' . $attribute . '=[\"\']{1})([^\"\']+)/', $convertTypeIds, $m ); } return do_shortcode_tag( $m ); } return $bool; } /** * @param string $tag * * @return array|null */ private function getConfig( $tag ) { return Obj::prop( $tag, $this->config->get_id_settings() ); } } wpml-page-builders/classes/Shared/ConvertIds/Helper.php 0000755 00000001244 14720415745 0017134 0 ustar 00 <?php namespace WPML\PB\ConvertIds; use WPML\Convert\Ids; class Helper { const TYPE_POST_IDS = 'post-ids'; const TYPE_TAXONOMY_IDS = 'taxonomy-ids'; /** * @param string $type * * @return bool */ public static function isValidType( $type ) { return in_array( $type, [ self::TYPE_POST_IDS, self::TYPE_TAXONOMY_IDS ], true ); } /** * @param string|null $subtype * @param string|null $type * * @return string */ public static function selectElementType( $subtype, $type ) { return $subtype ?: wpml_collect( [ self::TYPE_POST_IDS => Ids::ANY_POST, self::TYPE_TAXONOMY_IDS => Ids::ANY_TERM, ] )->get( (string) $type, $type ); } } wpml-page-builders/classes/Shared/utilities/class-wpml-page-builders-page-built-with-built.php 0000755 00000001176 14720415745 0026574 0 ustar 00 <?php class WPML_Page_Builders_Page_Built { private $config; public function __construct( WPML_Config_Built_With_Page_Builders $config ) { $this->config = $config; } /** * @param WP_Post $post * * @return bool */ public function is_page_builder_page( WP_Post $post ) { $result = false; $config_data = $this->config->get(); if ( is_array( $config_data ) ) { foreach ( $config_data as $pattern ) { $result = (bool) preg_match_all( $pattern, $post->post_content, $matches ); if ( $result ) { break; } } } return apply_filters( 'wpml_pb_is_page_builder_page', $result, $post ); } } wpml-page-builders/classes/Shared/utilities/class-wpml-st-diff.php 0000755 00000003621 14720415745 0021265 0 ustar 00 <?php /** * Based on https://github.com/paulgb/simplediff/blob/master/php/simplediff.php */ class WPML_ST_Diff { /** * @param string[] $old_words * @param string[] $new_words * * @return array */ public static function diff( $old_words, $new_words ) { $matrix = array(); $max_length = 0; $old_max = null; $new_max = null; foreach ( $old_words as $old_index => $old_value ) { $new_keys = array_keys( $new_words, $old_value ); foreach ( $new_keys as $new_index ) { $matrix[ $old_index ][ $new_index ] = isset( $matrix[ $old_index - 1 ][ $new_index - 1 ] ) ? $matrix[ $old_index - 1 ][ $new_index - 1 ] + 1 : 1; if ( $matrix[ $old_index ][ $new_index ] > $max_length ) { $max_length = $matrix[ $old_index ][ $new_index ]; $old_max = $old_index + 1 - $max_length; $new_max = $new_index + 1 - $max_length; } } } if ( $max_length == 0 ) { return array( array( 'deleted' => $old_words, 'inserted' => $new_words ) ); } return array_merge( self::diff( array_slice( $old_words, 0, $old_max ), array_slice( $new_words, 0, $new_max ) ), array_slice( $new_words, $new_max, $max_length ), self::diff( array_slice( $old_words, $old_max + $max_length ), array_slice( $new_words, $new_max + $max_length ) ) ); } /** * @param string $old_text * @param string $new_text * * @return float|int */ public static function get_sameness_percent( $old_text, $new_text ) { $old_text = $old_text ? strip_tags( $old_text ) : $old_text; if ( $old_text ) { $new_text = strip_tags( $new_text ); $diff = self::diff( preg_split( '/[\s]+/', $old_text ), preg_split( '/[\s]+/', $new_text ) ); $common_length = 0; foreach ( $diff as $diff_data ) { if ( ! is_array( $diff_data ) ) { $common_length += strlen( $diff_data ); } } return ( $common_length * 100 ) / strlen( $old_text ); } else { return 0; } } } wpml-page-builders/classes/Shared/st/class-wpml-pb-loader.php 0000755 00000004734 14720415745 0020217 0 ustar 00 <?php use WPML\PB\Container\Config; use function WPML\Container\make; use function WPML\Container\share; class WPML_PB_Loader { public function __construct( WPML_ST_Settings $st_settings, $pb_integration = null // Only needed for testing ) { share( Config::getSharedClasses() ); do_action( 'wpml_load_page_builders_integration' ); $page_builder_strategies = array(); /** * This filter hook provide the API page builders names that need to be supported. * * For each PB name, we will create a dedicated strategy and a proper string package namespace. * * It's called in 2 places: * - `WPML_Page_Builders_Integration` for external plugins * - `WPML_Gutenberg_Integration` for WordPress Core block editor * * @param string[] $array Required plugin names (e.g. `Beaver Builder`, `Gutenberg`) */ $required = apply_filters( 'wpml_page_builder_support_required', array() ); foreach ( $required as $plugin ) { $page_builder_strategies[] = new WPML_PB_API_Hooks_Strategy( $plugin ); } $page_builder_config_import = new WPML_PB_Config_Import_Shortcode( $st_settings ); $page_builder_config_import->add_hooks(); if ( $page_builder_config_import->has_settings() ) { $strategy = new WPML_PB_Shortcode_Strategy( new WPML_Page_Builder_Settings() ); $strategy->add_shortcodes( $page_builder_config_import->get_settings() ); $page_builder_strategies[] = $strategy; if ( defined( 'WPML_MEDIA_VERSION' ) && $page_builder_config_import->get_media_settings() ) { $shortcodes_media_hooks = new WPML_Page_Builders_Media_Hooks( new WPML_Page_Builders_Media_Shortcodes_Update_Factory( $page_builder_config_import ), 'shortcodes' ); $shortcodes_media_hooks->add_hooks(); } } self::load_hooks(); if ( $page_builder_strategies ) { if ( $pb_integration ) { $factory = $pb_integration->get_factory(); } else { $factory = make( 'WPML_PB_Factory' ); $pb_integration = make( 'WPML_PB_Integration' ); } $pb_integration->add_hooks(); foreach ( $page_builder_strategies as $strategy ) { $strategy->set_factory( $factory ); $pb_integration->add_strategy( $strategy ); } } } private static function load_hooks() { $hooks = [ WPML_PB_Handle_Post_Body::class, WPML\PB\AutoUpdate\Hooks::class, WPML\PB\Shutdown\Hooks::class, WPML\PB\GutenbergCleanup\ShortcodeHooks::class, WPML\PB\Shortcode\AdjustIdsHooks::class, ]; make( WPML_Action_Filter_Loader::class )->load( $hooks ); } } wpml-page-builders/classes/Shared/st/class-wpml-pb-rescan.php 0000755 00000001431 14720415745 0020213 0 ustar 00 <?php class WPML_PB_Integration_Rescan { /** * @var WPML_PB_Integration */ private $integrator; /** * @param WPML_PB_Integration $integrator */ public function __construct( WPML_PB_Integration $integrator ) { $this->integrator = $integrator; } /** * Rescan post content if it does not contain packages * * @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmlst-958 * * @param array $translation_package * @param \WP_Post $post * * @return array */ public function rescan( array $translation_package, $post ) { $string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $post->ID ); if ( ! $string_packages ) { $this->integrator->register_all_strings_for_translation( $post ); } return $translation_package; } } wpml-page-builders/classes/Shared/st/class-wpml-pb-factory.php 0000755 00000005545 14720415745 0020421 0 ustar 00 <?php use function WPML\Container\make; class WPML_PB_Factory { /** @var wpdb */ private $wpdb; /** @var SitePress */ private $sitepress; private $string_translations = array(); public function __construct( wpdb $wpdb, SitePress $sitepress ) { $this->wpdb = $wpdb; $this->sitepress = $sitepress; } public function get_wpml_package( $package_id ) { return new WPML_Package( $package_id ); } public function get_string_translations( IWPML_PB_Strategy $strategy ) { $kind = $strategy->get_package_kind(); if ( ! array_key_exists( $kind, $this->string_translations ) ) { $this->string_translations[ $kind ] = new WPML_PB_String_Translation_By_Strategy( $this->wpdb, $this, $strategy ); } return $this->string_translations[ $kind ]; } public function get_shortcode_parser( WPML_PB_Shortcode_Strategy $strategy ) { return new WPML_PB_Shortcodes( $strategy ); } /** * @param WPML_PB_Shortcode_Strategy $strategy * @param bool $migration_mode * * @return WPML_PB_Register_Shortcodes */ public function get_register_shortcodes( WPML_PB_Shortcode_Strategy $strategy, $migration_mode = false ) { $string_factory = new WPML_ST_String_Factory( $this->wpdb ); $string_registration = new WPML_PB_String_Registration( $strategy, $string_factory, new WPML_ST_Package_Factory(), make( 'WPML_Translate_Link_Targets' ), WPML\PB\TranslateLinks::getTranslatorForString( $string_factory, $this->sitepress->get_active_languages() ), $migration_mode ); return new WPML_PB_Register_Shortcodes( $string_registration, $strategy, new WPML_PB_Shortcode_Encoding(), $migration_mode ? null : new WPML_PB_Reuse_Translations_By_Strategy( $strategy, $string_factory ) ); } public function get_update_post( $package_data, IWPML_PB_Strategy $strategy ) { return new WPML_PB_Update_Post( $this->wpdb, $this->sitepress, $package_data, $strategy ); } public function get_shortcode_content_updater( IWPML_PB_Strategy $strategy ) { return new WPML_PB_Update_Shortcodes_In_Content( $strategy, new WPML_PB_Shortcode_Encoding() ); } public function get_api_hooks_content_updater( IWPML_PB_Strategy $strategy ) { return new WPML_PB_Update_API_Hooks_In_Content( $strategy ); } public function get_package_strings_resave() { return new WPML_PB_Package_Strings_Resave( new WPML_ST_String_Factory( $this->wpdb ) ); } public function get_handle_post_body() { return new WPML_PB_Handle_Post_Body( new WPML_Page_Builders_Page_Built( new WPML_Config_Built_With_Page_Builders() ) ); } /** * @depecated Use the static methods instead of the instance. */ public function get_last_translation_edit_mode() { return new WPML_PB_Last_Translation_Edit_Mode(); } public function get_post_element( $post_id ) { $factory = new WPML_Translation_Element_Factory( $this->sitepress ); return $factory->create_post( $post_id ); } } wpml-page-builders/classes/Shared/st/class-wpml-pb-reuse-translations.php 0000755 00000012544 14720415745 0022611 0 ustar 00 <?php class WPML_PB_Reuse_Translations { /** @var WPML_ST_String_Factory $string_factory */ private $string_factory; /** @var array $original_strings */ private $original_strings; /** @var array $current_strings */ private $current_strings; public function __construct( WPML_ST_String_Factory $string_factory ) { $this->string_factory = $string_factory; } /** * We receive arrays of strings with this structure: * * array( * 'gf4544ds454sds542122sd' => array( * 'value' => 'The string value', * 'context' => 'the-string-context', * 'name' => 'the-string-name', * 'id' => 123, * 'package_id' => 123, * 'location' => 123, * ), * ) * * The key is the string hash. * * @param array[] $original_strings * @param array[] $current_strings * @param array[] $leftover_strings */ public function find_and_reuse_translations( array $original_strings, array $current_strings, array $leftover_strings ) { $this->original_strings = $original_strings; $this->current_strings = $current_strings; $new_strings = $this->find_new_strings(); $new_strings_to_update = $this->find_existing_strings_for_new_strings( $new_strings, $leftover_strings ); $this->reuse_translations( $new_strings_to_update ); } /** @return array */ private function find_new_strings() { $new_strings = array(); foreach ( $this->current_strings as $current_string ) { $found = false; foreach ( $this->original_strings as $original_string ) { if ( $current_string['id'] == $original_string['id'] ) { $found = true; break; } } if ( ! $found ) { $new_strings[ $current_string['id'] ] = 0; } } return $new_strings; } /** * @param int[] $new_strings * @param array[] $leftover_strings * * @return int[] */ private function find_existing_strings_for_new_strings( array $new_strings, array $leftover_strings ) { list( $new_strings, $leftover_strings ) = $this->find_by_location( $new_strings, $leftover_strings ); $new_strings = $this->find_by_similar_text( $new_strings, $leftover_strings ); return $new_strings; } /** * @param int[] $new_strings * @param array[] $leftover_strings * * @return array[] */ private function find_by_location( array $new_strings, array $leftover_strings ) { if ( ! $leftover_strings ) { return array( $new_strings, $leftover_strings ); } if ( ( count( $this->current_strings ) - count( $leftover_strings ) ) !== count( $this->original_strings ) ) { return array( $new_strings, $leftover_strings ); } foreach ( $leftover_strings as $key => $leftover_string ) { foreach ( $this->current_strings as $current_string ) { if ( isset( $new_strings[ $current_string['id'] ] ) ) { if ( $this->is_same_location_and_different_ids( $current_string, $leftover_string ) && $this->is_similar_text( $leftover_string['value'], $current_string['value'] ) ) { $new_strings[ $current_string['id'] ] = $leftover_string['id']; unset( $leftover_strings[ $key ] ); } } } } return array( $new_strings, $leftover_strings ); } /** * @param int[] $new_strings * @param array[] $leftover_strings * * @return int[] */ private function find_by_similar_text( array $new_strings, array $leftover_strings ) { if ( $leftover_strings ) { foreach ( $new_strings as $new_string_id => $old_string_id ) { if ( ! $old_string_id ) { $new_string = $this->string_factory->find_by_id( $new_string_id ); $new_string_value = $new_string->get_value(); foreach ( $leftover_strings as $key => $leftover_string ) { $leftover_string_id = $leftover_string['id']; $leftover_string = $this->string_factory->find_by_id( $leftover_string_id ); $leftover_string_value = $leftover_string->get_value(); if ( $this->is_similar_text( $leftover_string_value, $new_string_value ) ) { $new_strings[ $new_string_id ] = $leftover_string_id; unset( $leftover_strings[ $key ] ); } } } } } return $new_strings; } /** * @param array $current_string * @param array $leftover_string * * @return bool */ private function is_same_location_and_different_ids( array $current_string, array $leftover_string ) { return $current_string['location'] === $leftover_string['location'] && $current_string['id'] !== $leftover_string['id']; } /** * @param string $old_text * @param string $new_text * * @return bool */ private function is_similar_text( $old_text, $new_text ) { return WPML_ST_Diff::get_sameness_percent( $old_text, $new_text ) > 50; } /** * @param int[] $strings */ private function reuse_translations( array $strings ) { foreach ( $strings as $new_string_id => $old_string_id ) { if ( $old_string_id ) { $new_string = $this->string_factory->find_by_id( $new_string_id ); $old_string = $this->string_factory->find_by_id( $old_string_id ); $translations = $old_string->get_translations(); foreach ( $translations as $translation ) { $status = $translation->status == ICL_TM_COMPLETE ? ICL_TM_NEEDS_UPDATE : $translation->status; $new_string->set_translation( $translation->language, $translation->value, $status, $translation->translator_id, $translation->translation_service, $translation->batch_id ); } } } } } wpml-page-builders/classes/Shared/st/class-wpml-pb-string.php 0000755 00000002614 14720415745 0020252 0 ustar 00 <?php class WPML_PB_String { /** @var string $value */ private $value; /** @var string $name */ private $name; /** @var string $title */ private $title; /** @var string $editor_type */ private $editor_type; /** * String wrap tag. * * @var string $wrap_tag */ private $wrap_tag; /** * WPML_PB_String constructor. * * @param string $value String value. * @param string $name String name. * @param string $title String title. * @param string $editor_type Editor type used. * @param string $wrap_tag String wrap tag. */ public function __construct( $value, $name, $title, $editor_type, $wrap_tag = '' ) { $this->value = $value; $this->name = $name; $this->title = $title; $this->editor_type = $editor_type; $this->wrap_tag = $wrap_tag; } /** * @return string */ public function get_value() { return $this->value; } /** * @param string $value */ public function set_value( $value ) { $this->value = $value; } /** * @return string */ public function get_name() { return $this->name; } /** * @return string */ public function get_title() { return $this->title; } /** * @return string */ public function get_editor_type() { return $this->editor_type; } /** * Get string wrap tag. * * @return string */ public function get_wrap_tag() { return $this->wrap_tag; } } wpml-page-builders/classes/Shared/st/class-wpml-pb-string-translation.php 0000755 00000005346 14720415745 0022613 0 ustar 00 <?php class WPML_PB_String_Translation { /** @var wpdb $wpdb */ protected $wpdb; public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } /** * @param array $package_data * * @return array */ public function get_package_strings( array $package_data ) { $strings = array(); $package_id = $this->get_package_id( $package_data ); if ( $package_id ) { $sql_to_get_strings_with_package_id = $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->prefix}icl_strings s WHERE s.string_package_id=%d", $package_id ); $package_strings = $this->wpdb->get_results( $sql_to_get_strings_with_package_id ); if ( ! empty( $package_strings ) ) { foreach ( $package_strings as $string ) { $strings[ $this->get_string_hash( $string->value ) ] = array( 'value' => $string->value, 'context' => $string->context, 'name' => $string->name, 'id' => $string->id, 'package_id' => $package_id, 'location' => $string->location, ); } } } return $strings; } public function remove_string( array $string_data ) { icl_unregister_string( $string_data['context'], $string_data['name'] ); $field_type = 'package-string-' . $string_data['package_id'] . '-' . $string_data['id']; $job_id = $this->get_job_id( $field_type ); if ( ! $job_id || ! $this->is_job_in_progress( $job_id ) ) { $this->wpdb->delete( $this->wpdb->prefix . 'icl_translate', array( 'field_type' => $field_type ), array( '%s' ) ); } } /** * @param string $field_type * * @return string|null */ private function get_job_id( $field_type ) { return $this->wpdb->get_var( $this->wpdb->prepare( "SELECT MAX(job_id) FROM {$this->wpdb->prefix}icl_translate WHERE field_type = %s", $field_type ) ); } /** * @param int $job_id * * @return bool */ private function is_job_in_progress( $job_id ) { return ! (bool) $this->wpdb->get_var( $this->wpdb->prepare( "SELECT translated FROM {$this->wpdb->prefix}icl_translate_job WHERE job_id = %d", $job_id ) ); } /** * @param array $package_data * * @return bool */ private function get_package_id( array $package_data ) { $package_id = false; $sql_to_get_package_id = $this->wpdb->prepare( "SELECT s.ID FROM {$this->wpdb->prefix}icl_string_packages s WHERE s.kind=%s AND s.name=%s AND s.title=%s AND s.post_id=%s", $package_data['kind'], $package_data['name'], $package_data['title'], $package_data['post_id'] ); $result = $this->wpdb->get_row( $sql_to_get_package_id ); if ( isset( $result->ID ) ) { $package_id = $result->ID; } return $package_id; } /** * @param string $string_value * * @return string */ public function get_string_hash( $string_value ) { return md5( $string_value ); } } wpml-page-builders/classes/Shared/st/class-wpml-pb-string-registration.php 0000755 00000010400 14720415745 0022752 0 ustar 00 <?php /** * Class WPML_PB_String_Registration */ class WPML_PB_String_Registration { /** @var IWPML_PB_Strategy $strategy */ private $strategy; /** @var WPML_ST_String_Factory $string_factory */ private $string_factory; /** @var WPML_ST_Package_Factory $package_factory */ private $package_factory; /** @var WPML_Translate_Link_Targets $translate_link_targets */ private $translate_link_targets; /** @var callable $set_link_translations */ private $set_link_translations; /** @var bool $migration_mode */ private $migration_mode; /** * WPML_PB_String_Registration constructor. * * @param IWPML_PB_Strategy $strategy * @param WPML_ST_String_Factory $string_factory * @param WPML_ST_Package_Factory $package_factory * @param WPML_Translate_Link_Targets $translate_link_targets * @param callable $set_link_translations * @param bool $migration_mode */ public function __construct( IWPML_PB_Strategy $strategy, WPML_ST_String_Factory $string_factory, WPML_ST_Package_Factory $package_factory, WPML_Translate_Link_Targets $translate_link_targets, callable $set_link_translations, $migration_mode = false ) { $this->strategy = $strategy; $this->string_factory = $string_factory; $this->package_factory = $package_factory; $this->translate_link_targets = $translate_link_targets; $this->set_link_translations = $set_link_translations; $this->migration_mode = $migration_mode; } /** * @param int $post_id * @param string $content * @param string $name * * @return null|int */ public function get_string_id_from_package( $post_id, $content, $name = '' ) { $package_data = $this->strategy->get_package_key( $post_id ); $package = $this->package_factory->create( $package_data ); $string_name = $name ? $name : md5( $content ); $string_name = $package->sanitize_string_name( $string_name ); $string_value = $content; return apply_filters( 'wpml_string_id_from_package', null, $package, $string_name, $string_value ); } public function get_string_title( $string_id ) { return apply_filters( 'wpml_string_title_from_id', null, $string_id ); } /** * Register string. * * @param int $post_id Post Id. * @param string|mixed $content String content. * @param string $type String editor type. * @param string $title String title. * @param string $name String name. * @param int $location String location. * @param string $wrap_tag String wrap tag. * * @return null|integer $string_id */ public function register_string( $post_id, $content = '', $type = 'LINE', $title = '', $name = '', $location = 0, $wrap_tag = '' ) { $string_id = 0; if ( is_string( $content ) && trim( $content ) ) { $string_name = $name ? $name : md5( $content ); if ( $this->migration_mode ) { $string_id = $this->get_string_id_from_package( $post_id, $content, $string_name ); $this->update_string_data( $string_id, $location, $wrap_tag ); } else { if ( 'LINK' === $type && ! $this->translate_link_targets->is_internal_url( $content ) ) { $type = 'LINE'; } $string_value = $content; $package = $this->strategy->get_package_key( $post_id ); $string_title = $title ? $title : $string_value; do_action( 'wpml_register_string', $string_value, $string_name, $package, $string_title, $type ); $string_id = $this->get_string_id_from_package( $post_id, $content, $string_name ); $this->update_string_data( $string_id, $location, $wrap_tag ); if ( 'LINK' === $type ) { call_user_func( $this->set_link_translations, $string_id ); } } } return $string_id; } /** * Update string data: location and wrap tag. * Wrap tag is used for SEO significance, can contain values as h1 ... h6, etc. * * @param int $string_id String id. * @param string $location String location inside of the page builder content. * @param string $wrap_tag String wrap tag for SEO significance. */ private function update_string_data( $string_id, $location, $wrap_tag ) { $string = $this->string_factory->find_by_id( $string_id ); $string->set_location( $location ); $string->set_wrap_tag( $wrap_tag ); } } wpml-page-builders/classes/Shared/st/class-wpml-pb-update-post.php 0000755 00000003717 14720415745 0021216 0 ustar 00 <?php use \WPML\FP\Wrapper; use function \WPML\FP\invoke; class WPML_PB_Update_Post { private $package_data; /** @var IWPML_PB_Strategy $strategy */ private $strategy; /** @var wpdb $wpdb */ private $wpdb; /** @var SitePress $sitepress */ private $sitepress; public function __construct( $wpdb, $sitepress, $package_data, IWPML_PB_Strategy $strategy ) { $this->wpdb = $wpdb; $this->sitepress = $sitepress; $this->package_data = $package_data; $this->strategy = $strategy; } public function update() { $package = $this->package_data['package']; $original_post_id = $package->post_id; $post = get_post( $original_post_id ); $element_type = 'post_' . $post->post_type; $trid = $this->sitepress->get_element_trid( $original_post_id, $element_type ); $post_translations = $this->sitepress->get_element_translations( $trid, $element_type, false, true ); $languages = $this->package_data['languages']; $string_translations = $package->get_translated_strings( array() ); foreach ( $languages as $lang ) { if ( isset( $post_translations[ $lang ] ) ) { $this->update_post( $post_translations[ $lang ]->element_id, $post, $string_translations, $lang ); } } } /** * @param string $content * @param string $lang * * @return string */ public function update_content( $content, $lang ) { return Wrapper::of( $this->strategy ) ->map( invoke( 'get_content_updater' ) ) ->map( invoke( 'update_content' )->with( $content, $this->package_data['package']->get_translated_strings( [] ), $lang ) ) ->get(); } private function update_post( $translated_post_id, $original_post, $string_translations, $lang ) { $content_updater = $this->strategy->get_content_updater(); $content_updater->update( $translated_post_id, $original_post, $string_translations, $lang ); } } wpml-page-builders/classes/Shared/st/compatibility/class-wpml-page-builders-update-translation.php 0000755 00000003355 14720415745 0027560 0 ustar 00 <?php /** * Class WPML_Page_Builders_Update_Translation */ abstract class WPML_Page_Builders_Update_Translation extends WPML_Page_Builders_Update { const TRANSLATION_COMPLETE = 10; /** * @var IWPML_Page_Builders_Translatable_Nodes */ protected $translatable_nodes; private $string_translations; private $lang; public function __construct( IWPML_Page_Builders_Translatable_Nodes $translatable_nodes, IWPML_Page_Builders_Data_Settings $data_settings ) { $this->translatable_nodes = $translatable_nodes; parent::__construct( $data_settings ); } /** * @param int $translated_post_id * @param \WP_Post|stdClass $original_post * @param array $string_translations * @param string $lang */ public function update( $translated_post_id, $original_post, $string_translations, $lang ) { $this->string_translations = $string_translations; $this->lang = $lang; $converted_data = $this->get_converted_data( $original_post->ID ); $this->update_strings_in_modules( $converted_data ); $this->save( $translated_post_id, $original_post->ID, $converted_data ); } /** * @param WPML_PB_String $string * * @return WPML_PB_String */ protected function get_translation( WPML_PB_String $string ) { if ( array_key_exists( $string->get_name(), $this->string_translations ) && array_key_exists( $this->lang, $this->string_translations[ $string->get_name() ] ) ) { $translation = $this->string_translations[ $string->get_name() ][ $this->lang ]; $string->set_value( $translation['value'] ); } return $string; } abstract protected function update_strings_in_modules( array &$data_array ); abstract protected function update_strings_in_node( $node_id, $settings ); } wpml-page-builders/classes/Shared/st/compatibility/class-wpml-page-builders-update.php 0000755 00000003625 14720415745 0025224 0 ustar 00 <?php class WPML_Page_Builders_Update { /** @var IWPML_Page_Builders_Data_Settings */ protected $data_settings; public function __construct( IWPML_Page_Builders_Data_Settings $data_settings ) { $this->data_settings = $data_settings; } /** * @param int $post_id * * @return array */ public function get_converted_data( $post_id ) { $data = get_post_meta( $post_id, $this->data_settings->get_meta_field(), true ); return $this->data_settings->convert_data_to_array( $data ); } /** * @param int $post_id * @param int $original_post_id * @param array $converted_data */ public function save( $post_id, $original_post_id, $converted_data ) { $this->save_data( $post_id, $this->data_settings->get_fields_to_save(), $this->data_settings->prepare_data_for_saving( $converted_data ) ); $this->copy_meta_fields( $post_id, $original_post_id, $this->data_settings->get_fields_to_copy() ); } /** * @param int $post_id * @param array $fields * @param mixed $data */ private function save_data( $post_id, $fields, $data ) { foreach ( $fields as $field ) { update_post_meta( $post_id, $field, $data ); } } /** * @param int $translated_post_id * @param int $original_post_id * @param array $meta_fields */ private function copy_meta_fields( $translated_post_id, $original_post_id, $meta_fields ) { foreach ( $meta_fields as $meta_key ) { if ( 'post_content' === $meta_key ) { $original_post = get_post( $original_post_id ); wpml_update_escaped_post( [ 'ID' => $translated_post_id, 'post_content' => $original_post->post_content, ] ); } else { $value = get_post_meta( $original_post_id, $meta_key, true ); update_post_meta( $translated_post_id, $meta_key, apply_filters( 'wpml_pb_copy_meta_field', $value, $translated_post_id, $original_post_id, $meta_key ) ); } } } } wpml-page-builders/classes/Shared/st/compatibility/class-wpml-page-builders-defined.php 0000755 00000004377 14720415745 0025345 0 ustar 00 <?php /** * Class WPML_Page_Builders_Defined */ class WPML_Page_Builders_Defined { private $settings; public function __construct() { $this->init_settings(); } public function has( $page_builder ) { global $wp_version; if ( 'gutenberg' === $page_builder ) { if ( version_compare( $wp_version, '5.0-beta1', '>=' ) ) { return true; } } if ( ! empty( $this->settings[ $page_builder ]['constant'] ) ) { return defined( $this->settings[ $page_builder ]['constant'] ); } if ( ! empty( $this->settings[ $page_builder ]['function'] ) ) { return function_exists( $this->settings[ $page_builder ]['function'] ); } } /** * @param array $components * * @return array */ public function add_components( $components ) { if ( isset( $components['page-builders'] ) ) { foreach ( array( 'beaver-builder' => 'Beaver Builder', 'elementor' => 'Elementor', 'gutenberg' => 'Gutenberg', 'cornerstone' => 'Cornerstone', 'siteorigin' => 'SiteOrigin', ) as $key => $name ) { $components['page-builders'][ $key ] = array( 'name' => $name, 'constant' => isset( $this->settings[ $key ]['constant'] ) ? $this->settings[ $key ]['constant'] : null, 'function' => isset( $this->settings[ $key ]['function'] ) ? $this->settings[ $key ]['function'] : null, 'notices-display' => array( 'wpml-translation-editor', ), ); } } return $components; } public function init_settings() { $this->settings = array( 'beaver-builder' => array( 'constant' => 'FL_BUILDER_VERSION', 'factory' => 'WPML_Beaver_Builder_Integration_Factory', ), 'elementor' => array( 'constant' => 'ELEMENTOR_VERSION', 'factory' => 'WPML_Elementor_Integration_Factory', ), 'gutenberg' => array( 'constant' => 'GUTENBERG_VERSION', 'factory' => 'WPML_Gutenberg_Integration_Factory', ), 'cornerstone' => array( 'constant' => 'CS_VERSION', 'factory' => 'WPML_Cornerstone_Integration_Factory', ), 'siteorigin' => array( 'constant' => 'SITEORIGIN_PANELS_VERSION', 'factory' => \WPML\PB\SiteOrigin\Factory::class, ), ); } /** * @return array */ public function get_settings() { return $this->settings; } } wpml-page-builders/classes/Shared/st/compatibility/interface-iwpml-page-builders-module.php 0000755 00000000742 14720415745 0026230 0 ustar 00 <?php /** * Class IWPML_Page_Builders_Module */ interface IWPML_Page_Builders_Module { /** * @param string|int $node_id * @param mixed $element * @param WPML_PB_String[] $strings * * @return WPML_PB_String[] */ public function get( $node_id, $element, $strings ); /** * @param string|int $node_id * @param mixed $element * @param WPML_PB_String $string * * @return array|null */ public function update( $node_id, $element, WPML_PB_String $string ); } wpml-page-builders/classes/Shared/st/compatibility/class-wpml-page-builders-register-strings.php 0000755 00000005305 14720415745 0027252 0 ustar 00 <?php /** * Class WPML_Page_Builders_Register_Strings */ abstract class WPML_Page_Builders_Register_Strings { /** * @var IWPML_Page_Builders_Translatable_Nodes */ private $translatable_nodes; /** * @var IWPML_Page_Builders_Data_Settings */ protected $data_settings; /** * @var WPML_PB_String_Registration */ private $string_registration; /** @var WPML_PB_Reuse_Translations_By_Strategy|null $reuse_translations */ private $reuse_translations; /** @var int $string_location */ private $string_location; public function __construct( IWPML_Page_Builders_Translatable_Nodes $translatable_nodes, IWPML_Page_Builders_Data_Settings $data_settings, WPML_PB_String_Registration $string_registration, WPML_PB_Reuse_Translations_By_Strategy $reuse_translations = null ) { $this->data_settings = $data_settings; $this->translatable_nodes = $translatable_nodes; $this->string_registration = $string_registration; $this->reuse_translations = $reuse_translations; } /** * @param WP_Post $post * @param array $package */ public function register_strings( WP_Post $post, array $package ) { do_action( 'wpml_start_string_package_registration', $package ); $this->string_location = 1; if ( $this->data_settings->is_handling_post( $post->ID ) ) { if ( $this->reuse_translations ) { $existing_strings = $this->reuse_translations->get_strings( $post->ID ); $this->reuse_translations->set_original_strings( $existing_strings ); } $data = get_post_meta( $post->ID, $this->data_settings->get_meta_field(), false ); if ( $data ) { $converted = $this->data_settings->convert_data_to_array( $data ); if ( is_array( $converted ) ) { $this->register_strings_for_modules( $converted, $package ); } } if ( $this->reuse_translations ) { // @phpstan-ignore-next-line $this->reuse_translations->find_and_reuse( $post->ID, $existing_strings ); } } do_action( 'wpml_delete_unused_package_strings', $package ); } /** * @param string $node_id * @param mixed $element * @param array $package */ protected function register_strings_for_node( $node_id, $element, array $package ) { $strings = $this->translatable_nodes->get( $node_id, $element ); foreach ( $strings as $string ) { $this->string_registration->register_string( $package['post_id'], $string->get_value(), $string->get_editor_type(), $string->get_title(), $string->get_name(), $this->string_location, $string->get_wrap_tag() ); $this->string_location++; } } /** * @param array $data_array * @param array $package */ abstract protected function register_strings_for_modules( array $data_array, array $package ); } classes/Shared/st/compatibility/interface-iwpml-page-builders-translatable-nodes.php 0000755 00000001204 14720415745 0030440 0 ustar 00 wpml-page-builders <?php interface IWPML_Page_Builders_Translatable_Nodes { /** * @param string|int $node_id * @param array|stdClass $element * * @return WPML_PB_String[] */ public function get( $node_id, $element ); /** * @param string|int $node_id * @param array|stdClass $element * @param WPML_PB_String $string * * @return mixed */ public function update( $node_id, $element, WPML_PB_String $string ); /** * @param string $node_id * @param array $field * @param mixed $settings * * @return mixed */ public function get_string_name( $node_id, $field, $settings ); public function initialize_nodes_to_translate(); } wpml-page-builders/classes/Shared/st/compatibility/interface-iwpml-page-builders-data-settings.php 0000755 00000001426 14720415745 0027512 0 ustar 00 <?php /** * Interface IWPML_Page_Builders_Data_Settings */ interface IWPML_Page_Builders_Data_Settings { /** * @return string */ public function get_meta_field(); /** * @return string */ public function get_node_id_field(); /** * @return array */ public function get_fields_to_copy(); /** * @return array */ public function get_fields_to_save(); /** * @param mixed $data * * @return array */ public function convert_data_to_array( $data ); /** * @param array $data * * @return mixed */ public function prepare_data_for_saving( array $data ); /** * @return string */ public function get_pb_name(); public function add_hooks(); /** * @param int $postId * * @return bool */ public function is_handling_post( $postId ); } classes/Shared/st/strategy/api-hooks/class-wpml-pb-update-api-hooks-in-content.php 0000755 00000001364 14720415745 0027650 0 ustar 00 wpml-page-builders <?php class WPML_PB_Update_API_Hooks_In_Content { /** @var WPML_PB_API_Hooks_Strategy $strategy */ private $strategy; public function __construct( WPML_PB_API_Hooks_Strategy $strategy ) { $this->strategy = $strategy; } public function update( $translated_post_id, $original_post, $string_translations, $lang ) { do_action( 'wpml_page_builder_string_translated', $this->strategy->get_package_kind(), $translated_post_id, $original_post, $string_translations, $lang ); } /** * @param string $original_content * @param array $string_translations * @param string $lang * * @return string */ public function update_content( $original_content, $string_translations, $lang ) { return $original_content; } } wpml-page-builders/classes/Shared/st/strategy/api-hooks/class-wpml-pb-api-hooks-strategy.php 0000755 00000003237 14720415745 0026234 0 ustar 00 <?php class WPML_PB_API_Hooks_Strategy implements IWPML_PB_Strategy { /** @var WPML_PB_Factory $factory */ private $factory; private $name; public function __construct( $name ) { $this->name = $name; } /** * @param \WP_Post|stdClass $post */ public function register_strings( $post ) { do_action( 'wpml_page_builder_register_strings', $post, $this->get_package_key( $post->ID ) ); } /** * @param string|int $post_id * @param string $content * @param WPML\PB\Shortcode\StringCleanUp $stringCleanUp * * @return bool */ public function register_strings_in_content( $post_id, $content, WPML\PB\Shortcode\StringCleanUp $stringCleanUp ) { return false; } public function set_factory( $factory ) { $this->factory = $factory; } /** * @param int $page_id * * @return array */ public function get_package_key( $page_id ) { return array( 'kind' => $this->get_package_kind(), 'name' => $page_id, 'title' => 'Page Builder Page ' . $page_id, 'post_id' => $page_id, ); } public function get_package_kind() { return $this->name; } public function get_update_post( $package_data) { return $this->factory->get_update_post( $package_data, $this ); } public function get_content_updater() { return $this->factory->get_api_hooks_content_updater( $this ); } public function get_package_strings( $package_data ) { return $this->factory->get_string_translations( $this )->get_package_strings( $package_data ); } public function remove_string( $string_data ) { $this->factory->get_string_translations( $this )->remove_string( $string_data ); } public function migrate_location( $post_id, $post_content ) { } } wpml-page-builders/classes/Shared/st/strategy/shortcode/StringCleanUp.php 0000755 00000001661 14720415745 0022640 0 ustar 00 <?php namespace WPML\PB\Shortcode; use WPML\FP\Fns; class StringCleanUp { /* @var array */ private $existingStrings; /* @var \WPML_PB_Shortcode_Strategy */ private $shortcodeStrategy; /** * StringCleanUp constructor. * * @param int $postId * @param \WPML_PB_Shortcode_Strategy $shortcodeStrategy */ public function __construct( $postId, \WPML_PB_Shortcode_Strategy $shortcodeStrategy ) { $this->shortcodeStrategy = $shortcodeStrategy; $this->existingStrings = $shortcodeStrategy->get_package_strings( $shortcodeStrategy->get_package_key( $postId ) ); } /** * @return array */ public function get() { return $this->existingStrings; } /** * @param string $value */ public function remove( $value ) { unset( $this->existingStrings[ md5( $value ) ] ); } public function cleanUp() { Fns::each( [ $this->shortcodeStrategy, 'remove_string' ], $this->existingStrings ); } } wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-encoding.php 0000755 00000005361 14720415745 0026360 0 ustar 00 <?php /** * Class WPML_PB_Register_Shortcodes */ class WPML_PB_Shortcode_Encoding { const ENCODE_TYPES_BASE64 = 'base64'; const ENCODE_TYPES_VISUAL_COMPOSER_LINK = 'vc_link'; const ENCODE_TYPES_ENFOLD_LINK = 'av_link'; public function decode( $string, $encoding, $encoding_condition = '' ) { $encoded_string = $string; if ( $encoding_condition && ! $this->should_decode( $encoding_condition ) ) { return html_entity_decode( $string ); } switch ( $encoding ) { case self::ENCODE_TYPES_BASE64: $string = html_entity_decode( rawurldecode( base64_decode( strip_tags( $string ) ) ) ); break; case self::ENCODE_TYPES_VISUAL_COMPOSER_LINK: $parts = explode( '|', $string ); $string = array(); foreach ( $parts as $part ) { $data = explode( ':', $part ); if ( count( $data ) === 2 ) { if ( in_array( $data[0], array( 'url', 'title' ), true ) ) { $string[ $data[0] ] = array( 'value' => urldecode( $data[1] ), 'translate' => true ); } else { $string[ $data[0] ] = array( 'value' => urldecode( $data[1] ), 'translate' => false ); } } } break; case self::ENCODE_TYPES_ENFOLD_LINK: // Note: We can't handle 'lightbox' mode because we don't know how to re-encode it $link = explode( ',', $string, 2 ); if ( 'manually' === $link[0] ) { $string = $link[1]; } elseif ( post_type_exists( $link[0] ) ) { $string = get_permalink( $link[1] ); } elseif ( taxonomy_exists( $link[0] ) ) { $term_link = get_term_link( get_term( $link[1], $link[0] ) ); if ( ! is_wp_error( $term_link ) ) { $string = $term_link; } } break; } return apply_filters( 'wpml_pb_shortcode_decode', $string, $encoding, $encoded_string ); } public function encode( $string, $encoding ) { $decoded_string = $string; switch ( $encoding ) { case self::ENCODE_TYPES_BASE64: $string = base64_encode( $string ); break; case self::ENCODE_TYPES_VISUAL_COMPOSER_LINK: $output = ''; if ( is_array( $string ) ) { foreach ( $string as $key => $value ) { $output .= $key . ':' . rawurlencode( $value ) . '|'; } } $string = $output; break; case self::ENCODE_TYPES_ENFOLD_LINK: $link = explode( ',', $string, 2 ); if ( $link[0] !== 'lightbox' ) { $string = 'manually,' . $string; } break; } return apply_filters( 'wpml_pb_shortcode_encode', $string, $encoding, $decoded_string ); } /** * @param string $condition * * @return bool */ private function should_decode( $condition ) { preg_match( '/(?P<type>\w+):(?P<field>\w+)=(?P<value>\w+)/', $condition, $matches ); return 'option' === $matches['type'] && get_option( $matches['field'] ) === $matches['value']; } } wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-content-wrapper.php 0000755 00000020344 14720415745 0027720 0 ustar 00 <?php use WPML\FP\Logic; use WPML\FP\Maybe; use WPML\FP\Str; use WPML\LIB\WP\Gutenberg; use function WPML\FP\pipe; class WPML_PB_Shortcode_Content_Wrapper { const WRAPPER_SHORTCODE_NAME = 'wpml_string_wrapper'; /** @var string $content */ private $content; /** @var array $valid_shortcodes */ private $valid_shortcodes; /** @var array $shortcodes */ private $shortcodes = array(); /** @var array $content_array */ private $content_array; /** @var array $insert_wrapper */ private $insert_wrapper = array(); /** * @param string $content * @param array $valid_shortcodes */ public function __construct( $content, array $valid_shortcodes ) { $this->content = $content; $this->valid_shortcodes = $valid_shortcodes; } public function get_wrapped_content() { $this->split_content(); $this->parse_shortcodes(); $this->analyze_unwrapped_text(); $this->insert_wrappers(); return $this->content; } /** * This is a multibyte safe version of `str_split` */ private function split_content() { $length = mb_strlen( $this->content ); for ( $i = 0; $i < $length; $i++ ) { $this->content_array[] = mb_substr( $this->content, $i, 1 ); } } private function parse_shortcodes() { $close_bracket_position = false; $content_length = count( $this->content_array ); for ( $i = 0; $i < $content_length; $i++ ) { if ( false !== $close_bracket_position && $close_bracket_position >= $i ) { continue; } if ( '[' === $this->content_array[ $i ] ) { $close_bracket_position = $this->parse_shortcode( $i ); } } } /** * @param int $open_bracket_position * * @return int */ private function parse_shortcode( $open_bracket_position ) { $shortcode_name = $this->get_shortcode_name( $open_bracket_position ); $close_bracket_position = $this->get_shortcode_end( $open_bracket_position, $shortcode_name ); $is_closing = isset( $this->content_array[ $open_bracket_position + 1 ] ) && '/' === $this->content_array[ $open_bracket_position + 1 ]; if ( ! in_array( $shortcode_name, $this->valid_shortcodes, true ) ) { return $close_bracket_position; } if ( $is_closing ) { $shortcode_index = $this->find_last_opened_shortcode( $shortcode_name ); if ( null !== $shortcode_index ) { $this->shortcodes[ $shortcode_index ]['end'] = $close_bracket_position; $this->remove_nested_shortcodes_between( $this->shortcodes[ $shortcode_index ]['start'], $close_bracket_position ); } } else { $this->shortcodes[] = array( 'name' => $shortcode_name, 'start' => $open_bracket_position, 'end' => $close_bracket_position, ); } return $close_bracket_position; } /** * @param int $start * @param int $end */ private function remove_nested_shortcodes_between( $start, $end ) { foreach ( $this->shortcodes as $key => $shortcode ) { if ( $start < $shortcode['start'] && $end > $shortcode['end'] ) { unset( $this->shortcodes[ $key ] ); } } } private function analyze_unwrapped_text() { $next_unwrapped_text_start = 0; foreach ( $this->shortcodes as $shortcode ) { $unwrapped_text_start = $next_unwrapped_text_start; $unwrapped_text_end = $shortcode['start'] - 1; $next_unwrapped_text_start = $shortcode['end'] + 1; if ( $unwrapped_text_start < $unwrapped_text_end ) { $this->set_wrapper_positions( $unwrapped_text_start, $unwrapped_text_end ); } } $max_content_char_position = mb_strlen( $this->content ) - 1; // For unwrapped text closing the content. if ( $next_unwrapped_text_start < $max_content_char_position ) { $this->set_wrapper_positions( $next_unwrapped_text_start, $max_content_char_position ); } } /** * @param int $start * @param int $end */ private function set_wrapper_positions( $start, $end ) { $raw_chunk = mb_substr( $this->content, $start, $end - $start ); if ( '' === trim( $raw_chunk ) ) { // the chunk is an empty string, we don't need to wrap it. return; } $chunk_start = $this->get_wrapper_insert_position( $start, 'open' ); $unwrapped_text_end = $this->get_wrapper_insert_position( $end, 'close' ); $this->insert_wrapper[ $chunk_start ] = '[' . self::WRAPPER_SHORTCODE_NAME . ']'; $this->insert_wrapper[ $unwrapped_text_end ] = '[/' . self::WRAPPER_SHORTCODE_NAME . ']'; } /** * @param int $position * @param string $type * * @return int */ private function get_wrapper_insert_position( $position, $type ) { if ( 'close' === $type ) { $increment = - 1; } else { $increment = 1; } while ( isset( $this->content_array[ $position ] ) && in_array( $this->content_array[ $position ], array( "\n", "\r" ), true ) ) { $position = $position + $increment; } if ( 'close' === $type ) { $position++; } return $position; } /** * @param int $open_bracket_position * * @return string */ private function get_shortcode_name( $open_bracket_position ) { $char_position = $open_bracket_position + 1; $name = ''; while ( isset( $this->content_array[ $char_position ] ) && ( '' === $name || ! in_array( $this->content_array[ $char_position ], array( ' ', ']' ), true ) ) ) { if ( '/' !== $this->content_array[ $char_position ] ) { $name .= $this->content_array[ $char_position ]; } $char_position++; } return $name; } /** * @param int $open_bracket_position * @param string $shortcode_name * * @return int */ private function get_shortcode_end( $open_bracket_position, $shortcode_name ) { $char_position = $open_bracket_position + mb_strlen( $shortcode_name ); $is_in_quotes = false; while ( isset( $this->content_array[ $char_position ] ) && ( ']' !== $this->content_array[ $char_position ] || $is_in_quotes ) ) { if ( in_array( $this->content_array[ $char_position ], array( '"', "'" ), true ) ) { $is_in_quotes = ! $is_in_quotes; } $char_position++; } return $char_position; } /** * @param string $shortcode_name * * @return int|null */ private function find_last_opened_shortcode( $shortcode_name ) { $last_matching_index = null; foreach ( $this->shortcodes as $shortcode_index => $shortcode ) { if ( $shortcode['name'] === $shortcode_name ) { $last_matching_index = (int) $shortcode_index; } } return $last_matching_index; } private function insert_wrappers() { $offset = 0; foreach ( $this->insert_wrapper as $wrapper_position => $wrapper ) { $insert_position = $wrapper_position + $offset; $before = mb_substr( $this->content, 0, $insert_position ); $after = mb_substr( $this->content, $insert_position ); $this->content = $before . $wrapper . $after; $offset = $offset + mb_strlen( $wrapper ); } } /** * @param string $content * @param array $shortcodes * * @return string */ public static function maybeWrap( $content, array $shortcodes ) { $containsOneShortcode = pipe( Str::match( '/' . get_shortcode_regex( $shortcodes ) . '/s' ), Logic::isEmpty(), Logic::not() ); return Maybe::of( $content ) ->filter( Gutenberg::doesNotHaveBlock() ) ->filter( $containsOneShortcode ) ->filter( [ self::class, 'isStrippedContentDifferent' ] ) ->map( [ self::class, 'wrap' ] ) ->getOrElse( $content ); } /** * This will flag some regular text not wrapped in a shortcode. * e.g. "[foo] Some text not wrapped [bar]" * * @param string $content * * @return bool */ public static function isStrippedContentDifferent( $content ) { $content_with_stripped_shortcode = preg_replace( '/\[([\S]*)[^\]]*\][\s\S]*\[\/(\1)\]|\[[^\]]*\]/', '', $content ); $content_with_stripped_shortcode = trim( $content_with_stripped_shortcode ); return ! empty( $content_with_stripped_shortcode ) && trim( $content ) !== $content_with_stripped_shortcode; } /** * @param string $content * * @return string */ public static function wrap( $content ) { return '[' . self::WRAPPER_SHORTCODE_NAME . ']' . $content . '[/' . self::WRAPPER_SHORTCODE_NAME . ']'; } /** * @param string $content * * @return string */ public static function unwrap( $content ) { return str_replace( [ '[' . self::WRAPPER_SHORTCODE_NAME . ']', '[/' . self::WRAPPER_SHORTCODE_NAME . ']' ], '', $content ); } } wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-register-shortcodes.php 0000755 00000015476 14720415745 0026611 0 ustar 00 <?php use WPML\PB\Shortcode\StringCleanUp; /** * Class WPML_PB_Register_Shortcodes */ class WPML_PB_Register_Shortcodes { private $handle_strings; /** @var WPML_PB_Shortcode_Strategy $shortcode_strategy */ private $shortcode_strategy; /** @var WPML_PB_Shortcode_Encoding $encoding */ private $encoding; /** @var WPML_PB_Reuse_Translations_By_Strategy|null $reuse_translations */ private $reuse_translations; /** @var StringCleanUp|null */ private $existingStrings; /** @var int $location_index */ private $location_index; /** * @param WPML_PB_String_Registration $handle_strings * @param WPML_PB_Shortcode_Strategy $shortcode_strategy * @param WPML_PB_Shortcode_Encoding $encoding * @param WPML_PB_Reuse_Translations_By_Strategy|null $reuse_translations */ public function __construct( WPML_PB_String_Registration $handle_strings, WPML_PB_Shortcode_Strategy $shortcode_strategy, WPML_PB_Shortcode_Encoding $encoding, WPML_PB_Reuse_Translations_By_Strategy $reuse_translations = null ) { $this->handle_strings = $handle_strings; $this->shortcode_strategy = $shortcode_strategy; $this->encoding = $encoding; $this->reuse_translations = $reuse_translations; } /** * @param string|int $post_id * @param string $content * @param StringCleanUp $externalStringCleanUp * * @return bool */ public function register_shortcode_strings( $post_id, $content, StringCleanUp $externalStringCleanUp = null ) { $any_registered = false; $this->location_index = 1; $content = apply_filters( 'wpml_pb_shortcode_content_for_translation', $content, $post_id ); $content = WPML_PB_Shortcode_Content_Wrapper::maybeWrap( $content, $this->shortcode_strategy->get_shortcodes() ); $shortcode_parser = $this->shortcode_strategy->get_shortcode_parser(); $shortcodes = $shortcode_parser->get_shortcodes( $content ); $this->existingStrings = $externalStringCleanUp ?: new StringCleanUp( $post_id, $this->shortcode_strategy ); if ( $this->reuse_translations ) { $this->reuse_translations->set_original_strings( $this->existingStrings->get() ); } foreach ( $shortcodes as $shortcode ) { if ( $this->should_handle_content( $shortcode ) ) { $shortcode_content = $shortcode['content']; $encoding = $this->shortcode_strategy->get_shortcode_tag_encoding( $shortcode['tag'] ); $encoding_condition = $this->shortcode_strategy->get_shortcode_tag_encoding_condition( $shortcode['tag'] ); $type = $this->shortcode_strategy->get_shortcode_tag_type( $shortcode['tag'] ); $shortcode_content = $this->encoding->decode( $shortcode_content, $encoding, $encoding_condition ); $any_registered = $this->register_string( $post_id, $shortcode_content, $shortcode, 'content', $type ) || $any_registered; } $attributes = (array) shortcode_parse_atts( $shortcode['attributes'] ); $translatable_attributes = $this->shortcode_strategy->get_shortcode_attributes( $shortcode['tag'] ); if ( ! empty( $attributes ) ) { foreach ( $attributes as $attr => $attr_value ) { if ( in_array( $attr, $translatable_attributes, true ) ) { $encoding = $this->shortcode_strategy->get_shortcode_attribute_encoding( $shortcode['tag'], $attr ); $type = $this->shortcode_strategy->get_shortcode_attribute_type( $shortcode['tag'], $attr ); $attr_value = $this->encoding->decode( $attr_value, $encoding ); $any_registered = $this->register_string( $post_id, $attr_value, $shortcode, $attr, $type ) || $any_registered; } } } } if ( $this->reuse_translations ) { $this->reuse_translations->find_and_reuse( $post_id, $this->existingStrings->get() ); } if( ! $externalStringCleanUp ) { $this->existingStrings->cleanUp(); $this->mark_post_as_migrate_location_done( $post_id ); } return $any_registered; } /** * @param array $shortcode * * @return bool */ private function should_handle_content( $shortcode ) { $tag = $shortcode['tag']; $handle_content = ! ( $this->shortcode_strategy->get_shortcode_ignore_content( $tag ) || in_array( $this->shortcode_strategy->get_shortcode_tag_type( $tag ), array( 'media-url', 'media-ids', ), true ) ); /** * Allow page builders to override if the shortcode should be handled as a translatable string. * * @since 4.2 * @param bool $handle_content. * @param array $shortcode { * * @type string $tag. * @type string $content. * @type string $attributes. * } */ return apply_filters( 'wpml_pb_should_handle_content', $handle_content, $shortcode ); } function get_updated_shortcode_string_title( $string_id, $shortcode, $attribute ) { $title = $this->shortcode_strategy->get_shortcode_attribute_label( $shortcode['tag'], $attribute ); if ( $title ) { return $title; } $shortcode_attributes = []; $shortcode_tag = $shortcode['tag']; $current_title = $this->get_shortcode_string_title( $string_id ); if ( $current_title ) { $current_title_parts = explode( ':', $current_title ); $current_title_parts = array_map( 'trim', $current_title_parts ); if ( isset( $current_title_parts[1] ) ) { $shortcode_attributes = explode( ',', $current_title_parts[1] ); $shortcode_attributes = array_map( 'trim', $shortcode_attributes ); } } $shortcode_attributes[] = $attribute; sort( $shortcode_attributes ); $shortcode_attributes = array_unique( $shortcode_attributes ); return $shortcode_tag . ': ' . implode( ', ', $shortcode_attributes ); } function get_shortcode_string_title( $string_id ) { return $this->handle_strings->get_string_title( $string_id ); } public function register_string( $post_id, $content, $shortcode, $attribute, $editor_type ) { $string_id = 0; if ( is_array( $content ) ) { foreach ( $content as $key => $data ) { if ( $data['translate'] ) { $this->register_string( $post_id, $data['value'], $shortcode, $attribute . ' ' . $key, $editor_type ); } } } else { if ( $this->existingStrings ) { $this->existingStrings->remove( $content ); } try { $string_id = $this->handle_strings->get_string_id_from_package( $post_id, $content ); $string_title = $this->get_updated_shortcode_string_title( $string_id, $shortcode, $attribute ); $string_id = $this->handle_strings->register_string( $post_id, $content, $editor_type, $string_title, '', $this->location_index ); if ( $string_id ) { $this->location_index ++; } } catch ( Exception $exception ) { $string_id = 0; } } return $string_id !== 0; } /** * @param int $post_id */ private function mark_post_as_migrate_location_done( $post_id ) { update_post_meta( $post_id, WPML_PB_Integration::MIGRATION_DONE_POST_META, true ); } } wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-strategy.php 0000755 00000012206 14720415745 0026430 0 ustar 00 <?php use \WPML\LIB\WP\Gutenberg; use WPML\FP\Obj; class WPML_PB_Shortcode_Strategy implements IWPML_PB_Strategy { private $shortcodes = array( WPML_PB_Shortcode_Content_Wrapper::WRAPPER_SHORTCODE_NAME => array( 'encoding' => '', 'encoding-condition' => '', 'type' => '', 'ignore-content' => false, 'attributes' => array(), ), ); /** @var WPML_PB_Factory $factory */ private $factory; /** @var WPML_Page_Builder_Settings $page_builder_settings */ private $page_builder_settings; public function __construct( WPML_Page_Builder_Settings $page_builder_settings ) { $this->page_builder_settings = $page_builder_settings; } public function add_shortcodes( $shortcode_data ) { foreach ( $shortcode_data as $shortcode ) { $tag = $shortcode['tag']['value']; $is_raw_html = isset( $shortcode['tag']['raw-html'] ) && $shortcode['tag']['raw-html']; if ( $is_raw_html && ! $this->page_builder_settings->is_raw_html_translatable() ) { continue; } if ( ! in_array( $tag, $this->shortcodes ) ) { $this->shortcodes[ $tag ] = [ 'encoding' => $shortcode['tag']['encoding'], 'encoding-condition' => isset( $shortcode['tag']['encoding-condition'] ) ? $shortcode['tag']['encoding-condition'] : '', 'type' => isset( $shortcode['tag']['type'] ) ? $shortcode['tag']['type'] : '', 'ignore-content' => isset( $shortcode['tag']['ignore-content'] ) ? (bool) $shortcode['tag']['ignore-content'] : false, 'label' => isset( $shortcode['tag']['label'] ) ? $shortcode['tag']['label'] : '', 'attributes' => [], ]; } if ( isset( $shortcode['attributes'] ) ) { foreach ( $shortcode['attributes'] as $attribute ) { $this->shortcodes[ $tag ]['attributes'][ $attribute['value'] ] = $attribute; } } } } public function get_shortcodes() { return array_keys( $this->shortcodes ); } public function get_shortcode_attributes( $tag ) { return array_keys( $this->shortcodes[ $tag ]['attributes'] ); } public function get_shortcode_tag_encoding( $tag ) { return $this->shortcodes[ $tag ]['encoding']; } public function get_shortcode_tag_encoding_condition( $tag ) { return $this->shortcodes[ $tag ]['encoding-condition']; } public function get_shortcode_tag_type( $tag ) { if ( $this->shortcodes[ $tag ]['type'] ) { return strtoupper( $this->shortcodes[ $tag ]['type'] ); } return 'VISUAL'; } public function get_shortcode_ignore_content( $tag ) { return $this->shortcodes[ $tag ]['ignore-content']; } public function get_shortcode_attribute_encoding( $tag, $attribute ) { return $this->shortcodes[ $tag ]['attributes'][ $attribute ]['encoding']; } public function get_shortcode_attribute_type( $tag, $attribute ) { if ( $this->shortcodes[ $tag ]['attributes'][ $attribute ]['type'] ) { return strtoupper( $this->shortcodes[ $tag ]['attributes'][ $attribute ]['type'] ); } return 'LINE'; } public function get_shortcode_attribute_label( $tag, $attribute ) { $labelPath = 'content' === $attribute ? [ $tag, 'label' ] : [ $tag, 'attributes', $attribute, 'label' ]; return Obj::pathOr( '', $labelPath, $this->shortcodes ); } public function get_shortcode_parser() { return $this->factory->get_shortcode_parser( $this ); } /** * @param \WP_Post|stdClass $post */ public function register_strings( $post ) { if ( Gutenberg::doesNotHaveBlock( $post->post_content ) ) { $this->register_strings_in_content( $post->ID, $post->post_content, null ); } } /** * @param string|int $post_id * @param string $content * @param WPML\PB\Shortcode\StringCleanUp $stringCleanUp * * @return bool */ public function register_strings_in_content( $post_id, $content, WPML\PB\Shortcode\StringCleanUp $stringCleanUp = null ) { $register_shortcodes = $this->factory->get_register_shortcodes( $this ); return $register_shortcodes->register_shortcode_strings( $post_id, $content, $stringCleanUp ); } public function set_factory( $factory ) { $this->factory = $factory; } public function get_package_key( $page_id ) { return array( 'kind' => $this->get_package_kind(), 'name' => $page_id, 'title' => 'Page Builder Page ' . $page_id, 'post_id' => $page_id, ); } public function get_package_kind() { return 'Page Builder ShortCode Strings'; } public function get_update_post( $package_data ) { return $this->factory->get_update_post( $package_data, $this ); } public function get_content_updater() { return $this->factory->get_shortcode_content_updater( $this ); } public function get_package_strings( $package_data ) { return $this->factory->get_string_translations( $this )->get_package_strings( $package_data ); } public function remove_string( $string_data ) { return $this->factory->get_string_translations( $this )->remove_string( $string_data ); } /** * @param int $post_id * @param object $post_content */ public function migrate_location( $post_id, $post_content ) { $migrate_locations = $this->factory->get_register_shortcodes( $this, true ); $migrate_locations->register_shortcode_strings( $post_id, $post_content, null ); } } classes/Shared/st/strategy/shortcode/class-wpml-pb-update-shortcodes-in-content.php 0000755 00000017530 14720415745 0030235 0 ustar 00 wpml-page-builders <?php use WPML\LIB\WP\Gutenberg; class WPML_PB_Update_Shortcodes_In_Content { const LONG_STRING_THRESHOLD = 5000; /** @var WPML_PB_Shortcode_Strategy $strategy */ private $strategy; /** @var WPML_PB_Shortcode_Encoding $encoding */ private $encoding; private $new_content; private $string_translations; private $lang; public function __construct( WPML_PB_Shortcode_Strategy $strategy, WPML_PB_Shortcode_Encoding $encoding ) { $this->strategy = $strategy; $this->encoding = $encoding; } public function update( $translated_post_id, $original_post, $string_translations, $lang ) { if ( Gutenberg::hasBlock( $original_post->post_content ) ) { return; } $original_content = $original_post->post_content; $original_content = apply_filters( 'wpml_pb_shortcode_content_for_translation', $original_content, $original_post->ID ); $new_translation = $this->update_content( $original_content, $string_translations, $lang ); $translated_post = get_post( $translated_post_id ); $current_translation = isset( $translated_post->post_content ) ? $translated_post->post_content : ''; $current_translation = apply_filters( 'wpml_pb_shortcode_content_for_translation', $current_translation, $translated_post_id ); $translation_saved = apply_filters( 'wpml_pb_shortcodes_save_translation', false, $translated_post_id, $new_translation ); if ( ! $translation_saved ) { if ( $new_translation != $original_content || '' === $current_translation ) { wpml_update_escaped_post( [ 'ID' => $translated_post_id, 'post_content' => $new_translation, ] ); } } } public function update_content( $original_content, $string_translations, $lang ) { $original_content = WPML_PB_Shortcode_Content_Wrapper::maybeWrap( $original_content, $this->strategy->get_shortcodes() ); $this->new_content = $original_content; $this->string_translations = $string_translations; $this->lang = $lang; $shortcode_parser = $this->strategy->get_shortcode_parser(); $shortcodes = $shortcode_parser->get_shortcodes( $original_content ); foreach ( $shortcodes as $shortcode ) { $this->update_shortcodes( $shortcode ); $this->update_shortcode_attributes( $shortcode ); } return WPML_PB_Shortcode_Content_Wrapper::unwrap( $this->new_content ); } private function update_shortcodes( $shortcode_data ) { $encoding = $this->strategy->get_shortcode_tag_encoding( $shortcode_data['tag'] ); $translation = $this->get_translation( $shortcode_data['content'], $encoding ); $this->replace_string_with_translation( $shortcode_data['block'], $shortcode_data['content'], $translation ); } private function update_shortcode_attributes( $shortcode_data ) { $shortcode_attribute = $shortcode_data['attributes']; $attributes = (array) shortcode_parse_atts( $shortcode_attribute ); $translatable_attributes = $this->strategy->get_shortcode_attributes( $shortcode_data['tag'] ); if ( ! empty( $attributes ) ) { foreach ( $attributes as $attr => $attr_value ) { if ( in_array( $attr, $translatable_attributes, true ) ) { $encoding = $this->strategy->get_shortcode_attribute_encoding( $shortcode_data['tag'], $attr ); $translation = $this->get_translation( $attr_value, $encoding ); $translation = $this->filter_attribute_translation( $translation, $encoding ); $shortcode_attribute = $this->replace_string_with_translation( $shortcode_attribute, $attr_value, $translation, true, $attr ); } } } } private function replace_string_with_translation( $block, $original, $translation, $is_attribute = false, $attr = '' ) { $translation = apply_filters( 'wpml_pb_before_replace_string_with_translation', $translation, $is_attribute ); $used_wrapper = false; $new_block = $block; if ( $translation ) { if ( $this->is_string_too_long_for_regex( $original ) || $this->is_string_too_long_for_regex( $block ) ) { $block = WPML_PB_Shortcode_Content_Wrapper::unwrap( $block ); $new_block = str_replace( $original, $translation, $block ); $this->new_content = str_replace( $block, $new_block, $this->new_content ); } else { if ( $is_attribute && $attr ) { // Quotes needs to be converted to entities, otherwise they can match with // the shortcode attributes delimters and break the attributes. $translation = !empty( $translation ) ? str_replace( [ "'", '"' ], [ ''', '"' ], $translation ) : $translation; $pattern = '/' . $attr . '=(["\'])' . preg_quote( $original, '/' ) . '(["\'])/'; $replacement = $attr . '=${1}' . $this->escape_backward_reference_on_replacement_string( $translation ) . '${2}'; } else { $used_wrapper = false !== strpos( $new_block, '[' . WPML_PB_Shortcode_Content_Wrapper::WRAPPER_SHORTCODE_NAME . ']' ); $pattern = '/(]\s*)' . preg_quote( trim( $original ), '/' ) . '(\s*\[)/'; $replacement = '${1}' . $this->escape_backward_reference_on_replacement_string( trim( $translation ) ) . '${2}'; } $new_block = preg_replace( $pattern, $replacement, $block ); $block = WPML_PB_Shortcode_Content_Wrapper::unwrap( $block ); $new_block = WPML_PB_Shortcode_Content_Wrapper::unwrap( $new_block ); $replacement = $this->escape_backward_reference_on_replacement_string( $new_block ); if ( $used_wrapper ) { $this->new_content = $this->replace_content_without_delimiters( $block, $replacement ); } else { $this->new_content = preg_replace( '/' . preg_quote( $block, '/' ) . '/', $replacement, $this->new_content, 1 ); } } } return $new_block; } /** * We need to escape backward references that could be included in the replacement text * e.g. '$1999.each' => '$19' is considered as a backward reference * * @param string $string * * @return string */ private function escape_backward_reference_on_replacement_string( $string ) { return preg_replace( '/\$([\d]{1,2})/', '\\\$' . '${1}', $string ); } private function replace_content_without_delimiters( $block, $replacement ) { return preg_replace( '/(]\s*)' . preg_quote( $block, '/' ) . '(\s*\[)/', '${1}' . $replacement . '${2}', $this->new_content, 1 ); } /** * @param string $string * * @return bool */ private function is_string_too_long_for_regex( $string ) { return mb_strlen( $string ) > self::LONG_STRING_THRESHOLD; } private function get_translation( $original, $encoding = false ) { $decoded_original = $this->encoding->decode( $original, $encoding ); $translation = null; if ( is_array( $decoded_original ) ) { $translation = array(); foreach ( $decoded_original as $key => $data ) { if ( $data['translate'] ) { $translated_data = $this->get_translation( $data['value'], '' ); if ( $translated_data ) { $translation[ $key ] = $translated_data; } else { $translation[ $key ] = $data['value']; } } else { $translation[ $key ] = $data['value']; } } } else { $string_name = md5( $decoded_original ); if ( isset( $this->string_translations[ $string_name ][ $this->lang ] ) && $this->string_translations[ $string_name ][ $this->lang ]['status'] == ICL_TM_COMPLETE ) { $translation = $this->string_translations[ $string_name ][ $this->lang ]['value']; } } if ( $translation ) { $translation = $this->encoding->encode( $translation, $encoding ); } return $translation; } /** * @param string|null $translation * @param string $encoding * * @return string */ private function filter_attribute_translation( $translation, $encoding ) { if ( is_null( $translation ) ) { return ''; } if ( 'allow_html_tags' !== $encoding ) { $translation = htmlspecialchars( htmlspecialchars_decode( $translation ) ); } $translation = str_replace( array( '[', ']' ), array( '[', ']' ), $translation ); return $translation; } } wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-config-import-shortcode.php 0000755 00000016717 14720415745 0027356 0 ustar 00 <?php use WPML\Convert\Ids; use WPML\FP\Obj; use WPML\PB\ConvertIds\Helper as ConvertIdsHelper; class WPML_PB_Config_Import_Shortcode { const PB_SHORTCODE_SETTING = 'pb_shortcode'; const PB_MEDIA_SHORTCODE_SETTING = 'wpml_pb_media_shortcode'; const PB_IDS_SHORTCODE_SETTING = 'wpml_pb_ids_shortcode'; const TYPE_POST_IDS = 'post-ids'; const TYPE_TAXONOMY_IDS = 'taxonomy-ids'; /** @var WPML_ST_Settings $st_settings */ private $st_settings; public function __construct( WPML_ST_Settings $st_settings ) { $this->st_settings = $st_settings; } public function add_hooks() { add_filter( 'wpml_config_array', array( $this, 'wpml_config_filter' ) ); } public function wpml_config_filter( $config_data ) { $this->update_shortcodes_config( $config_data ); $this->update_ids_shortcodes_config( $config_data ); $this->update_media_shortcodes_config( $config_data ); return $config_data; } /** @param array $config_data */ private function update_shortcodes_config( $config_data ) { $old_shortcode_data = $this->get_settings(); $shortcode_data = array(); if ( isset ( $config_data['wpml-config']['shortcodes']['shortcode'] ) ) { foreach ( $config_data['wpml-config']['shortcodes']['shortcode'] as $data ) { $ignore_content = isset( $data['tag']['attr']['ignore-content'] ) && $data['tag']['attr']['ignore-content']; $attributes = array(); if ( isset( $data['attributes']['attribute'] ) ) { $data['attributes']['attribute'] = $this->convert_single_attribute_to_multiple_format( $data['attributes']['attribute'] ); foreach ( $data['attributes']['attribute'] as $attribute ) { if ( ! $this->is_string_attribute( $attribute ) ) { continue; } if ( ! empty( $attribute['value'] ) ) { $attribute_encoding = isset( $attribute['attr']['encoding'] ) ? $attribute['attr']['encoding'] : ''; $attribute_type = isset( $attribute['attr']['type'] ) ? $attribute['attr']['type'] : ''; $attribute_label = isset( $attribute['attr']['label'] ) ? $attribute['attr']['label'] : ''; $attributes[] = [ 'value' => $attribute['value'], 'encoding' => $attribute_encoding, 'type' => $attribute_type, 'label' => $attribute_label, ]; } } } if ( ! ( $ignore_content && empty( $attributes ) ) ) { $shortcode_data[] = [ 'tag' => [ 'value' => $data['tag']['value'], 'encoding' => isset( $data['tag']['attr']['encoding'] ) ? $data['tag']['attr']['encoding'] : '', 'encoding-condition' => isset( $data['tag']['attr']['encoding-condition'] ) ? $data['tag']['attr']['encoding-condition'] : '', 'type' => isset( $data['tag']['attr']['type'] ) ? $data['tag']['attr']['type'] : '', 'raw-html' => isset( $data['tag']['attr']['raw-html'] ) ? $data['tag']['attr']['raw-html'] : '', 'ignore-content' => $ignore_content, 'label' => isset( $data['tag']['attr']['label'] ) ? $data['tag']['attr']['label'] : '', ], 'attributes' => $attributes, ]; } } } if ( $shortcode_data != $old_shortcode_data ) { $this->st_settings->update_setting( self::PB_SHORTCODE_SETTING, $shortcode_data, true ); } } /** @param array $config_data */ private function update_media_shortcodes_config( $config_data ) { $old_shortcodes_data = $this->get_media_settings(); $shortcodes_data = array(); if ( isset ( $config_data['wpml-config']['shortcodes']['shortcode'] ) ) { foreach ( $config_data['wpml-config']['shortcodes']['shortcode'] as $data ) { $shortcode_data = array(); if ( isset( $data['attributes']['attribute'] ) ) { $attributes = array(); $data['attributes']['attribute'] = $this->convert_single_attribute_to_multiple_format( $data['attributes']['attribute'] ); foreach ( $data['attributes']['attribute'] as $attribute ) { if ( ! $this->is_media_attribute( $attribute ) ) { continue; } if ( ! empty( $attribute['value'] ) ) { $attribute_type = isset( $attribute['attr']['type'] ) ? $attribute['attr']['type'] : ''; $attributes[ $attribute['value'] ] = array( 'type' => $attribute_type ); } } if ( $attributes ) { $shortcode_data['attributes'] = $attributes; } } if ( isset( $data['tag']['attr']['type'] ) && $data['tag']['attr']['type'] === WPML_Page_Builders_Media_Shortcodes::TYPE_URL ) { $shortcode_data['content'] = array( 'type' => WPML_Page_Builders_Media_Shortcodes::TYPE_URL ); } if ( $shortcode_data ) { $shortcode_data['tag'] = array( 'name' => $data['tag']['value'] ); $shortcodes_data[] = $shortcode_data; } } } if ( $shortcodes_data != $old_shortcodes_data ) { update_option( self::PB_MEDIA_SHORTCODE_SETTING, $shortcodes_data, true ); } } /** @param array $config_data */ private function update_ids_shortcodes_config( $config_data ) { $old_shortcodes_data = $this->get_id_settings(); $shortcodes_data = []; if ( isset ( $config_data['wpml-config']['shortcodes']['shortcode'] ) ) { foreach ( $config_data['wpml-config']['shortcodes']['shortcode'] as $data ) { $attributes = []; if ( isset( $data['attributes']['attribute'] ) ) { $data['attributes']['attribute'] = $this->convert_single_attribute_to_multiple_format( $data['attributes']['attribute'] ); foreach ( $data['attributes']['attribute'] as $attribute ) { if ( ! $this->is_id_attribute( $attribute ) ) { continue; } if ( ! empty( $attribute['value'] ) ) { $attributes[ $attribute['value'] ] = ConvertIdsHelper::selectElementType( Obj::path( [ 'attr','sub-type' ], $attribute ), Obj::path( [ 'attr','type' ], $attribute ) ); } } } if ( $attributes ) { $tag_name = $data['tag']['value']; $shortcodes_data[ $tag_name ] = $attributes; } } } if ( $shortcodes_data != $old_shortcodes_data ) { update_option( self::PB_IDS_SHORTCODE_SETTING, $shortcodes_data, true ); } } /** * @param array $attribute * * @return bool */ private function is_string_attribute( array $attribute ) { return ! $this->is_id_attribute( $attribute ) && ! $this->is_media_attribute( $attribute ); } /** * @param array $attribute * * @return bool */ private function is_id_attribute( array $attribute ) { return ConvertIdsHelper::isValidType( Obj::path( [ 'attr', 'type' ], $attribute ) ); } private function is_media_attribute( array $attribute ) { $media_attribute_types = array( WPML_Page_Builders_Media_Shortcodes::TYPE_URL, WPML_Page_Builders_Media_Shortcodes::TYPE_IDS, ); return isset( $attribute['attr']['type'] ) && in_array( $attribute['attr']['type'], $media_attribute_types, true ); } private function convert_single_attribute_to_multiple_format( array $attribute ) { if ( ! is_numeric( key( $attribute ) ) ) { $attribute = array( $attribute ); } return $attribute; } public function get_settings() { return $this->st_settings->get_setting( self::PB_SHORTCODE_SETTING ); } public function get_media_settings() { return get_option( self::PB_MEDIA_SHORTCODE_SETTING, array() ); } /** * @return array */ public function get_id_settings() { return get_option( self::PB_IDS_SHORTCODE_SETTING, [] ); } public function has_settings() { $settings = $this->get_settings(); return ! empty( $settings ); } } wpml-page-builders/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcodes.php 0000755 00000004127 14720415745 0024756 0 ustar 00 <?php class WPML_PB_Shortcodes { /** @var WPML_PB_Shortcode_Strategy $shortcode_strategy */ private $shortcode_strategy; /** @var bool $is_wrapping_regular_text */ private $is_wrapping_regular_text = false; public function __construct( WPML_PB_Shortcode_Strategy $shortcode_strategy ) { $this->shortcode_strategy = $shortcode_strategy; } public function get_shortcodes( $content ) { $shortcodes = array(); $pattern = get_shortcode_regex( $this->shortcode_strategy->get_shortcodes() ); if ( preg_match_all( '/' . $pattern . '/s', $content, $matches ) && isset( $matches[5] ) && ! empty( $matches[5] ) ) { for ( $index = 0; $index < sizeof( $matches[0] ); $index ++ ) { $shortcode = array( 'block' => $matches[0][ $index ], 'tag' => $matches[2][ $index ], 'attributes' => $matches[3][ $index ], 'content' => $matches[5][ $index ], ); $nested_shortcodes = array(); if ( $shortcode['content'] ) { if ( $this->needs_wrapping_regular_text( $shortcode['content'] ) ) { $this->is_wrapping_regular_text = true; $shortcode['content'] = $this->wrap_regular_text( $shortcode['content'] ); } $nested_shortcodes = $this->get_shortcodes( $shortcode['content'] ); $this->is_wrapping_regular_text = false; if ( count( $nested_shortcodes ) ) { $shortcode['content'] = ''; } } if ( count( $nested_shortcodes ) ) { $shortcodes = array_merge( $shortcodes, $nested_shortcodes ); } $shortcodes[] = $shortcode; } } return $shortcodes; } /** * @param string $content * * @return string */ private function wrap_regular_text( $content ) { $wrapper = new WPML_PB_Shortcode_Content_Wrapper( $content, $this->shortcode_strategy->get_shortcodes() ); return $wrapper->get_wrapped_content(); } /** * @param string $content * * @return bool */ private function needs_wrapping_regular_text( $content ) { if ( $this->is_wrapping_regular_text ) { return false; } return WPML_PB_Shortcode_Content_Wrapper::isStrippedContentDifferent( $content ); } } wpml-page-builders/classes/Shared/st/strategy/interface-iwpml-pb-strategy.php 0000755 00000001521 14720415745 0023450 0 ustar 00 <?php interface IWPML_PB_Strategy { /** * @param \WP_Post|stdClass $post */ public function register_strings( $post ); /** * @param int $post_id * @param string $content * @param WPML\PB\Shortcode\StringCleanUp $stringCleanUp * * @return bool - true if strings were added. */ public function register_strings_in_content( $post_id, $content, WPML\PB\Shortcode\StringCleanUp $stringCleanUp ); /** * @param WPML_PB_Factory $factory * */ public function set_factory( $factory ); public function get_package_key( $page_id ); public function get_package_kind(); public function get_update_post( $package_data ); public function get_content_updater(); public function get_package_strings( $package_data ); public function remove_string( $string_data ); public function migrate_location( $post_id, $post_content ); } wpml-page-builders/classes/Shared/st/class-wpml-string-registration-factory.php 0000755 00000001326 14720415745 0024027 0 ustar 00 <?php use function WPML\Container\make; /** * Class WPML_String_Registration_Factory */ class WPML_String_Registration_Factory { private $pb_plugin_name; public function __construct( $pb_plugin_name ) { $this->pb_plugin_name = $pb_plugin_name; } /** * @return WPML_PB_String_Registration */ public function create() { global $sitepress; $string_factory = make( 'WPML_ST_String_Factory' ); return new WPML_PB_String_Registration( new WPML_PB_API_Hooks_Strategy( $this->pb_plugin_name ), $string_factory, new WPML_ST_Package_Factory(), make( 'WPML_Translate_Link_Targets' ), WPML\PB\TranslateLinks::getTranslatorForString( $string_factory, $sitepress->get_active_languages() ) ); } } wpml-page-builders/classes/Shared/st/class-wpml-pb-package-strings-resave.php 0000755 00000003136 14720415745 0023311 0 ustar 00 <?php class WPML_PB_Package_Strings_Resave { /** @var WPML_ST_String_Factory $string_factory */ private $string_factory; public function __construct( WPML_ST_String_Factory $string_factory ) { $this->string_factory = $string_factory; } /** * @param WPML_Post_Element $post_element * * @return WPML_Package[] */ public function from_element( WPML_Post_Element $post_element ) { if ( ! $post_element->get_source_element() ) { return array(); } $target_lang = $post_element->get_language_code(); $original_post_id = $post_element->get_source_element()->get_id(); /** @var WPML_Package[] $string_packages */ $string_packages = apply_filters( 'wpml_st_get_post_string_packages', array(), $original_post_id ); foreach ( $string_packages as $string_package ) { /** @var stdClass[] $strings */ $strings = $string_package->get_package_strings(); foreach ( $strings as $string ) { $this->resave_string_translation( $string->id, $target_lang ); } } return $string_packages; } /** * @param int $string_id * @param string $target_lang */ private function resave_string_translation( $string_id, $target_lang ) { $string = $this->string_factory->find_by_id( $string_id ); $translations = wp_list_filter( $string->get_translations(), array( 'language' => $target_lang ) ); if ( $translations ) { $translation = reset( $translations ); $string->set_translation( $target_lang, $translation->value, $translation->status, $translation->translator_id, $translation->translation_service, $translation->batch_id ); } } } wpml-page-builders/classes/Shared/st/class-wpml-pb-string-translation-by-strategy.php 0000755 00000006401 14720415745 0025054 0 ustar 00 <?php use WPML\PB\ShortCodesInGutenbergBlocks; class WPML_PB_String_Translation_By_Strategy extends WPML_PB_String_Translation { /** @var WPML_PB_Factory $factory */ private $factory; /** @var IWPML_PB_Strategy $strategy */ private $strategy; /** @var array $packages_to_update */ private $packages_to_update = array(); public function __construct( wpdb $wpdb, WPML_PB_Factory $factory, IWPML_PB_Strategy $strategy ) { $this->factory = $factory; $this->strategy = $strategy; parent::__construct( $wpdb ); } /** @param int $translated_string_id */ public function new_translation( $translated_string_id ) { list( $package_id, $string_id, $language ) = $this->get_package_for_translated_string( $translated_string_id ); if ( $package_id ) { $package = $this->factory->get_wpml_package( $package_id ); if ( $package->post_id ) { $strategyKind = $this->strategy->get_package_kind(); if ( $strategyKind === $package->kind ) { $this->add_package_to_update_list( $package, $language ); } ShortCodesInGutenbergBlocks::recordPackage( $this, $strategyKind, $package, $language ); } } } public function save_translations_to_post() { foreach ( $this->packages_to_update as $package_data ) { $package_data = ShortCodesInGutenbergBlocks::fixupPackage( $package_data ); if ( $package_data['package']->kind == $this->strategy->get_package_kind() ) { $update_post = $this->strategy->get_update_post( $package_data ); $update_post->update(); } } } /** * @param string $content * @param string $lang * * @return string */ public function update_translations_in_content( $content, $lang ) { foreach ( $this->packages_to_update as $package_data ) { if ( $package_data['package']->kind == $this->strategy->get_package_kind() ) { $update_post = $this->strategy->get_update_post( $package_data ); $content = $update_post->update_content( $content, $lang ); } } return $content; } /** * @param int $translated_string_id * * @return array */ private function get_package_for_translated_string( $translated_string_id ) { $sql = $this->wpdb->prepare( "SELECT s.string_package_id, s.id, t.language FROM {$this->wpdb->prefix}icl_strings s LEFT JOIN {$this->wpdb->prefix}icl_string_translations t ON s.id = t.string_id WHERE t.id = %d", $translated_string_id ); $result = $this->wpdb->get_row( $sql ); if ( $result ) { // @phpstan-ignore-next-line return array( $result->string_package_id, $result->id, $result->language ); } else { return array( null, null, null ); } } /** * @param WPML_Package $package * @param string $language */ public function add_package_to_update_list( WPML_Package $package, $language ) { if ( ! isset( $this->packages_to_update[ $package->ID ] ) ) { $this->packages_to_update[ $package->ID ] = array( 'package' => $package, 'languages' => array( $language ) ); } else { if ( ! in_array( $language, $this->packages_to_update[ $package->ID ]['languages'] ) ) { $this->packages_to_update[ $package->ID ]['languages'][] = $language; } } $this->packages_to_update = ShortCodesInGutenbergBlocks::normalizePackages( $this->packages_to_update ); } } wpml-page-builders/classes/Shared/st/class-wpml-page-builders-app.php 0000755 00000002416 14720415745 0021646 0 ustar 00 <?php /** * Class WPML_Page_Builders_App */ class WPML_Page_Builders_App { /** * @var WPML_Page_Builders_Defined */ private $page_builder_plugins; /** * WPML_Page_Builders_App constructor. * * @param WPML_Page_Builders_Defined $page_builder_plugins */ public function __construct( WPML_Page_Builders_Defined $page_builder_plugins ) { $this->page_builder_plugins = $page_builder_plugins; } public function add_hooks() { add_action( 'wpml_load_page_builders_integration', array( $this, 'load_integration' ) ); add_filter( 'wpml_integrations_components', array( $this, 'add_components' ), 10, 1 ); } public function load_integration() { if ( ! class_exists( 'WPML_ST_Package_Factory' ) ) { return; } $factories = array(); foreach ( $this->page_builder_plugins->get_settings() as $page_builder_id => $page_builder ) { if ( $this->page_builder_plugins->has( $page_builder_id ) ) { $current_factory = $page_builder['factory']; $factories[] = new $current_factory(); } } if ( $factories ) { foreach ( $factories as $factory ) { $integration = $factory->create(); $integration->add_hooks(); } } } public function add_components( $components ) { return $this->page_builder_plugins->add_components( $components ); } } wpml-page-builders/classes/Shared/st/TranslateLinks.php 0000755 00000001540 14720415745 0017220 0 ustar 00 <?php namespace WPML\PB; class TranslateLinks { /** * @param \WPML_ST_String_Factory $stringFactory * @param array $activeLanguages * * @return \Closure */ public static function getTranslatorForString( \WPML_ST_String_Factory $stringFactory, $activeLanguages ) { return function ( $string_id ) use ( $stringFactory, $activeLanguages ) { $string = $stringFactory->find_by_id( $string_id ); $sameStringLanguage = function ( $language ) use ( $string ) { return $language === $string->get_language(); }; $setTranslation = function ( $language ) use ( $string ) { $string->set_translation( $language, $string->get_value() ); }; \wpml_collect( $activeLanguages )->pluck( 'code' ) ->reject( $sameStringLanguage ) ->each( $setTranslation ); }; } } wpml-page-builders/classes/Shared/st/class-wpml-pb-reuse-translations-by-strategy.php 0000755 00000002047 14720415745 0025056 0 ustar 00 <?php class WPML_PB_Reuse_Translations_By_Strategy extends WPML_PB_Reuse_Translations { /** @var IWPML_PB_Strategy $strategy */ private $strategy; /** @var array $original_strings */ private $original_strings_by_strategy; public function __construct( IWPML_PB_Strategy $strategy, WPML_ST_String_Factory $string_factory ) { $this->strategy = $strategy; parent::__construct( $string_factory ); } /** @param array $strings */ public function set_original_strings( array $strings ) { $this->original_strings_by_strategy = $strings; } /** * @param int $post_id * @param array $leftover_strings */ public function find_and_reuse( $post_id, array $leftover_strings ) { $current_strings = $this->get_strings( $post_id ); $this->find_and_reuse_translations( $this->original_strings_by_strategy, $current_strings, $leftover_strings ); } /** * @param int $post_id * * @return array */ public function get_strings( $post_id ) { return $this->strategy->get_package_strings( $this->strategy->get_package_key( $post_id ) ); } } wpml-page-builders/classes/Shared/st/class-wpml-pb-integration.php 0000755 00000036217 14720415745 0021275 0 ustar 00 <?php use WPML\FP\Fns; use WPML\FP\Obj; use WPML\FP\Logic; use WPML\FP\Type; use WPML\FP\Str; use WPML\PB\Shortcode\StringCleanUp; use function WPML\FP\invoke; use function WPML\FP\partialRight; use function WPML\Container\make; /** * Class WPML_PB_Integration */ class WPML_PB_Integration { const MIGRATION_DONE_POST_META = '_wpml_location_migration_done'; /** @var SitePress */ private $sitepress; /** @var WPML_PB_Factory */ private $factory; /** @var bool */ private $new_translations_recieved = false; /** @var array */ private $save_post_queue = array(); /** @var bool */ private $is_registering_string = false; /** @var array */ private $strategies = array(); /** @var StringCleanUp[] */ private $stringCleanUp = []; /** * @var WPML_PB_Integration_Rescan */ private $rescan; /** @var array $media_updaters */ private $media_updaters = []; /** * WPML_PB_Integration constructor. * * @param SitePress $sitepress * @param WPML_PB_Factory $factory */ public function __construct( SitePress $sitepress, WPML_PB_Factory $factory ) { $this->sitepress = $sitepress; $this->factory = $factory; } /** * @param IWPML_PB_Strategy $strategy */ public function add_strategy( IWPML_PB_Strategy $strategy ) { $this->strategies[] = $strategy; } /** * @return WPML_PB_Integration_Rescan */ public function get_rescan() { if ( null === $this->rescan ) { $this->rescan = new WPML_PB_Integration_Rescan( $this ); } return $this->rescan; } /** * @param WPML_PB_Integration_Rescan $rescan */ public function set_rescan( WPML_PB_Integration_Rescan $rescan ) { $this->rescan = $rescan; } public function resave_post_translation_in_shutdown( WPML_Post_Element $post_element, $disallowed_in_shutdown = true ) { if ( ! $post_element->get_source_element() || ( did_action( 'shutdown' ) && $disallowed_in_shutdown ) || array_key_exists( $post_element->get_id(), $this->save_post_queue ) ) { return; } if ( WPML_PB_Last_Translation_Edit_Mode::is_native_editor( $post_element->get_id() ) ) { return; } $updated_packages = $this->factory->get_package_strings_resave()->from_element( $post_element ); if ( ! $updated_packages ) { $this->factory->get_handle_post_body()->copy( $post_element->get_id(), $post_element->get_source_element()->get_id(), array() ); } $this->with_strategies( function( IWPML_PB_Strategy $strategy ) use ( $updated_packages, $post_element ) { foreach ( $updated_packages as $package ) { $this->factory->get_string_translations( $strategy ) ->add_package_to_update_list( $package, $post_element->get_language_code() ); } } ); $this->new_translations_recieved = true; $this->queue_save_post_actions( $post_element->get_id(), $post_element->get_wp_object() ); } /** * @param int|string $post_id * @param \WP_Post $post */ public function queue_save_post_actions( $post_id, $post ) { $this->update_last_editor_mode( (int) $post_id ); $this->save_post_queue[ $post_id ] = $post; } /** * @return \WP_Post[] */ public function get_save_post_queue() { return $this->save_post_queue; } /** @param int $post_id */ private function update_last_editor_mode( $post_id ) { if ( ! $this->is_translation( $post_id ) ) { return; } if ( $this->is_editing_translation_with_native_editor( $post_id ) ) { WPML_PB_Last_Translation_Edit_Mode::set_native_editor( $post_id ); } else { WPML_PB_Last_Translation_Edit_Mode::set_translation_editor( $post_id ); } } /** * Due to the "translation auto-update" feature, an original update * can also trigger an update on the translations. * We need to make sure the globally edited post is matching with * the local one. * * @param int $translatedPostId * * @return bool */ private function is_editing_translation_with_native_editor( $translatedPostId ) { // $getPOST :: string -> mixed $getPOST = Obj::prop( Fns::__, $_POST ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification // $isQuickEditAction :: int -> bool $isQuickEditAction = function( $id ) use ( $getPOST ) { return wp_doing_ajax() && 'inline-save' === $getPOST( 'action' ) && $id === (int) $getPOST( 'post_ID' ); }; // $isSavingPostWithREST :: int -> bool $isSavingPostWithREST = function( $translatedPostId ) { if ( ! in_array( $_SERVER['REQUEST_METHOD'], [ 'POST', 'PUT', 'PATCH' ], true ) ) { return false; } $hasValidBase = Logic::complement( Logic::anyPass( [ Type::isNull(), Str::includes( '?P' ), Str::includes( '[' ), Str::includes( '(' ) ] ) ); $quoteComposedBase = Fns::unary( partialRight( 'preg_quote', '/' ) ); $postTypeSlugs = wpml_collect( get_post_types( [ 'show_in_rest' => true, ], 'objects' ) ) ->map( function( $postType ) { return Obj::prop( 'rest_base', $postType ) ?: Obj::prop( 'name', $postType ); } ) // Filter out variable bases, see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmlpb-450 ->filter( $hasValidBase ) ->map ( $quoteComposedBase ) ->implode( '|' ); preg_match( '/' . preg_quote( rest_get_url_prefix(), '/' ) . '\/wp\/v2\/(?:' . $postTypeSlugs . ')\/(\d+)/', $_SERVER['REQUEST_URI'], $matches ); $RESTPostId = (int) Obj::prop( 1, $matches ); return $RESTPostId === $translatedPostId; }; // $getGET :: string -> mixed $getGET = Obj::prop( Fns::__, $_GET ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification // $isBulkEditAction :: int -> bool $isBulkEditAction = function( $id ) use ( $getGET ) { $screenAction = 'edit-' . get_post_type( $id ); return $screenAction === $getGET( 'screen' ) && 'edit' === $getGET( 'action' ) && wpml_collect( (array) $getGET( 'post' ) ) ->map( \WPML\FP\Cast::toInt() ) ->contains( $id ); }; $isTranslationWithNativeEditor = ( 'editpost' === $getPOST( 'action' ) && (int) $getPOST( 'ID' ) === $translatedPostId ) || ( ( $isQuickEditAction( $translatedPostId ) || $isBulkEditAction( $translatedPostId ) ) && WPML_PB_Last_Translation_Edit_Mode::is_native_editor( $translatedPostId ) ) || $isSavingPostWithREST( $translatedPostId ); /** * This filter allows to override the result if a translation * is edited with a native editor, but not the WP one. * * @since WPML 4.5.0 * * @param bool $isTranslationWithNativeEditor * @param int $translatedPostId */ return apply_filters( 'wpml_pb_is_editing_translation_with_native_editor', $isTranslationWithNativeEditor, $translatedPostId ); } /** * @param int $postId * * @return bool */ private function is_translation( $postId ) { return (bool) $this->factory->get_post_element( $postId )->get_source_language_code(); } /** * @param WP_Post $post * @param bool $allowRegisteringPostTranslation Specifies if the string registration must be allowed for posts that are not original. */ public function register_all_strings_for_translation( $post, $allowRegisteringPostTranslation = false ) { if ( $post instanceof \WP_Post && $this->is_post_status_ok( $post ) && ( $allowRegisteringPostTranslation || $this->is_original_post( $post ) ) ) { $this->is_registering_string = true; $this->with_strategies( invoke( 'register_strings' )->with( $post ) ); $this->is_registering_string = false; } } /** * @param \WP_Post|\stdClass $post * * @return bool */ private function is_original_post( $post ) { return $post->ID == $this->sitepress->get_original_element_id( $post->ID, 'post_' . $post->post_type ); } /** * @param \WP_Post|\stdClass $post * * @return bool */ private function is_post_status_ok( $post ) { return ! in_array( $post->post_status, array( 'trash', 'auto-draft', 'inherit' ) ); } /** * Add all actions filters. */ public function add_hooks() { add_action( 'pre_post_update', array( $this, 'migrate_location' ) ); add_action( 'save_post', array( $this, 'queue_save_post_actions' ), PHP_INT_MAX, 2 ); add_action( 'wpml_pb_resave_post_translation', array( $this, 'resave_post_translation_in_shutdown' ), 10, 1 ); add_action( 'icl_st_add_string_translation', array( $this, 'new_translation' ), 10, 1 ); add_action( 'wpml_pb_finished_adding_string_translations', array( $this, 'process_pb_content_with_hidden_strings_only' ), 9, 2 ); add_action( 'wpml_pb_finished_adding_string_translations', array( $this, 'save_translations_to_post' ), 10 ); add_action( 'wpml_pro_translation_completed', array( $this, 'cleanup_strings_after_translation_completed' ), 10, 3 ); add_filter( 'wpml_tm_translation_job_data', array( $this, 'rescan' ), 9, 2 ); add_action( 'wpml_pb_register_all_strings_for_translation', [ $this, 'register_all_strings_for_translation' ] ); add_filter( 'wpml_pb_register_strings_in_content', [ $this, 'register_strings_in_content' ], 10, 3 ); add_filter( 'wpml_pb_update_translations_in_content', [ $this, 'update_translations_in_content'], 10, 2 ); add_action( 'wpml_start_GB_register_strings', [ $this, 'initialize_string_clean_up' ], 10, 1 ); add_action( 'wpml_end_GB_register_strings', [ $this, 'clean_up_strings' ], 10, 1 ); } /** * @param int $new_post_id * @param array $fields * @param stdClass $job */ public function cleanup_strings_after_translation_completed( $new_post_id, array $fields, stdClass $job ) { if ( 'post' === $job->element_type_prefix ) { $original_post = get_post( $job->original_doc_id ); $this->register_all_strings_for_translation( $original_post ); } } public function new_translation( $translated_string_id ) { if ( ! $this->is_registering_string ) { $this->with_strategies( function( $strategy ) use ( $translated_string_id ) { $this->factory->get_string_translations( $strategy )->new_translation( $translated_string_id ); } ); $this->new_translations_recieved = true; } } /** * @param callable $callable */ private function with_strategies( callable $callable ) { Fns::each( $callable, $this->strategies ); } /** * When a Page Builder content has only a "LINK" string, it's won't be part * of the translation job as it's automatically converted. * We need to add the package to the update list (by strategies). * * @param int $new_post_id * @param int $original_doc_id */ public function process_pb_content_with_hidden_strings_only( $new_post_id, $original_doc_id ) { if ( ! did_action( 'wpml_add_string_translation' ) && apply_filters( 'wpml_pb_is_page_builder_page', false, get_post( $new_post_id ) ) ) { $targetLang = $this->sitepress->get_language_for_element( $new_post_id, 'post_' . get_post_type( $new_post_id ) ); $addPackageToUpdateList = function( WPML_Package $package ) use ( $targetLang ) { $this->with_strategies( function( IWPML_PB_Strategy $strategy ) use ( $package, $targetLang ) { $this->factory ->get_string_translations( $strategy ) ->add_package_to_update_list( $package, $targetLang ); } ); }; $this->new_translations_recieved = wpml_collect( apply_filters( 'wpml_st_get_post_string_packages', [], $original_doc_id ) ) ->each( $addPackageToUpdateList ) ->isNotEmpty(); } } public function save_translations_to_post() { if ( $this->new_translations_recieved ) { $this->with_strategies( function( IWPML_PB_Strategy $strategy ) { $this->factory->get_string_translations( $strategy )->save_translations_to_post(); } ); $this->new_translations_recieved = false; } } /** * @param string $content * @param string $lang * * @return string */ public function update_translations_in_content( $content, $lang ) { $this->with_strategies( function ( IWPML_PB_Strategy $strategy ) use ( &$content, $lang ) { $content = $this->factory->get_string_translations( $strategy )->update_translations_in_content( $content, $lang ); } ); return $content; } /** * @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmlst-958 * @param array $translation_package * @param WP_Post|WPML_Package $post * * @return array */ public function rescan( array $translation_package, $post ) { if ( $post instanceof WP_Post ) { $translation_package = $this->get_rescan()->rescan( $translation_package, $post ); } return $translation_package; } /** * @param int $post_id */ public function migrate_location( $post_id ) { if ( $this->post_has_strings( $post_id ) && ! $this->is_migrate_location_done( $post_id ) ) { $wpdb = $this->sitepress->get_wpdb(); $post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_type, post_status, post_content FROM {$wpdb->posts} WHERE ID = %d", $post_id ) ); if ( $this->is_post_status_ok( $post ) && $this->is_original_post( $post ) ) { $this->with_strategies( invoke( 'migrate_location' )->with( $post_id, $post->post_content ) ); } $this->mark_migrate_location_done( $post_id ); } } /** * @param bool $registered * @param string|int $post_id * @param string $content * * @return bool */ public function register_strings_in_content( $registered, $post_id, $content ) { foreach ( $this->strategies as $strategy ) { $registered = $strategy->register_strings_in_content( $post_id, $content, $this->stringCleanUp[ $post_id ] ) || $registered; } return $registered; } public function get_factory() { return $this->factory; } public function initialize_string_clean_up( WP_Post $post ) { $shortcodeStrategy = make( WPML_PB_Shortcode_Strategy::class ); $shortcodeStrategy->set_factory( $this->factory ); $this->stringCleanUp[ $post->ID ] = new StringCleanUp( $post->ID, $shortcodeStrategy ); } public function clean_up_strings( WP_Post $post ) { $this->stringCleanUp[ $post->ID ]->cleanUp(); } /** * @param int $post_id * * @return bool */ private function post_has_strings( $post_id ) { $wpdb = $this->sitepress->get_wpdb(); $string_packages_table = $wpdb->prefix . 'icl_string_packages'; if ( $wpdb->get_var( "SHOW TABLES LIKE '$string_packages_table'" ) !== $string_packages_table ) { return false; } $string_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$string_packages_table} WHERE post_id = %d", $post_id) ); return $string_count > 0; } /** * @param int $post_id * * @return bool */ private function is_migrate_location_done( $post_id ) { return get_post_meta( $post_id, self::MIGRATION_DONE_POST_META, true ); } /** * @param int $post_id */ private function mark_migrate_location_done( $post_id ) { update_post_meta( $post_id, WPML_PB_Integration::MIGRATION_DONE_POST_META, true ); } /** * @param WP_Post $post */ public function translate_media( $post ) { if ( $this->is_post_status_ok( $post ) && ! $this->is_original_post( $post ) ) { foreach ( $this->get_media_updaters( $post ) as $updater ) { $updater->translate( $post ); } } } /** * @param \WP_Post $post * * @return IWPML_PB_Media_Update[] */ private function get_media_updaters( $post ) { if ( ! isset( $this->media_updaters[ $post->ID ] ) ) { /** * Gets all media updaters. * * @param IWPML_PB_Media_Update[] $media_updaters * @param \WP_Post $post */ $this->media_updaters[ $post->ID ] = apply_filters( 'wpml_pb_get_media_updaters', [], $post ); } return $this->media_updaters[ $post->ID ]; } } wpml-page-builders/classes/Shared/st/class-wpml-pb-last-translation-edit-mode.php 0000755 00000002321 14720415745 0024103 0 ustar 00 <?php class WPML_PB_Last_Translation_Edit_Mode { const POST_META_KEY = '_last_translation_edit_mode'; const NATIVE_EDITOR = 'native-editor'; const TRANSLATION_EDITOR = 'translation-editor'; /** * @param int $post_id * * @return bool */ public static function is_native_editor( $post_id ) { return self::get_last_mode( $post_id ) === self::NATIVE_EDITOR; } /** * @param int $post_id * * @return bool */ public static function is_translation_editor( $post_id ) { return self::get_last_mode( $post_id ) === self::TRANSLATION_EDITOR; } /** * @param int $post_id * * @return mixed */ private static function get_last_mode( $post_id ) { return get_post_meta( $post_id, self::POST_META_KEY, true ); } /** * @param int $post_id */ public static function set_native_editor( $post_id ) { self::set_mode( $post_id, self::NATIVE_EDITOR ); } /** * @param int $post_id */ public static function set_translation_editor( $post_id ) { self::set_mode( $post_id, self::TRANSLATION_EDITOR ); } /** * @param int $post_id * @param string $mode */ private static function set_mode( $post_id, $mode ) { update_post_meta( $post_id, self::POST_META_KEY, $mode ); } } wpml-page-builders/classes/Shared/st/class-wpml-st-pb-plugin.php 0000755 00000002616 14720415745 0020670 0 ustar 00 <?php class WPML_ST_PB_Plugin { function check_requirements() { if ( defined( 'WPML_PAGE_BUILDERS_VERSION' ) ) { add_action( 'admin_notices', array( $this, 'disable_old_pb_notice' ) ); } } function is_active() { return defined( 'WPML_PAGE_BUILDERS_VERSION' ); } function ask_to_deactivate() { add_action( 'admin_notices', array( $this, 'disable_old_pb_notice' ) ); } function disable_old_pb_notice() { $plugin_name = plugin_basename( WPML_PAGE_BUILDERS_PATH . '/plugin.php' ); $plugins_url = admin_url( '/plugins.php' ); $plugins_url = add_query_arg( array( 'action' => 'deactivate', 'plugin_status' => 'inactive', '_wpnonce' => urlencode( wp_create_nonce( 'deactivate-plugin_' . $plugin_name ) ), 'plugin' => urlencode( $plugin_name ), ), $plugins_url ); ?> <div class="message error"> <p> <?php esc_html_e( "The WPML Page Builders plugin that you're using is now part of WPML.", 'sitepress' ); ?> </p> <p> <?php esc_html_e( 'You need to deactivate the separate plugin.', 'sitepress' ); ?> </p> <p> <?php esc_html_e( 'No worries, the full functionality is preserved in WPML String Translation.', 'sitepress' ); ?> </p> <p> <a class="button-primary" href="<?php echo esc_url( $plugins_url ); ?>"><?php esc_html_e( 'Deactivate WPML Page Builders', 'sitepress' ); ?></a> </p> </div> <?php } } wpml-page-builders/classes/Shared/st/class-page-builder-integration.php 0000755 00000005125 14720415745 0022251 0 ustar 00 <?php /** * Class WPML_Page_Builders_Integration */ class WPML_Page_Builders_Integration { const STRINGS_TRANSLATED_PRIORITY = 10; /** @var WPML_Page_Builders_Register_Strings */ private $register_strings; /** @var WPML_Page_Builders_Update_Translation */ private $update_translation; /** @var IWPML_Page_Builders_Data_Settings */ private $data_settings; /** * WPML_Page_Builders_Integration constructor. * * @param WPML_Page_Builders_Register_Strings $register_strings * @param WPML_Page_Builders_Update_Translation $update_translation * @param IWPML_Page_Builders_Data_Settings $data_settings */ public function __construct( WPML_Page_Builders_Register_Strings $register_strings, WPML_Page_Builders_Update_Translation $update_translation, IWPML_Page_Builders_Data_Settings $data_settings ) { $this->register_strings = $register_strings; $this->update_translation = $update_translation; $this->data_settings = $data_settings; } public function add_hooks() { add_filter( 'wpml_page_builder_support_required', array( $this, 'support_required' ) ); add_action( 'wpml_page_builder_register_strings', array( $this, 'register_pb_strings' ), 10, 2 ); add_action( 'wpml_page_builder_string_translated', array( $this, 'update_translated_post' ), self::STRINGS_TRANSLATED_PRIORITY, 5 ); add_filter( 'wpml_get_translatable_types', array( $this, 'remove_shortcode_strings_type_filter' ), 12, 1 ); $this->data_settings->add_hooks(); } /** * @param array $page_builder_plugins * * @return array */ public function support_required( array $page_builder_plugins ) { $page_builder_plugins[] = $this->data_settings->get_pb_name(); return $page_builder_plugins; } /** * @param \WP_Post $post * @param array $package_key */ public function register_pb_strings( $post, $package_key ) { if ( $this->data_settings->get_pb_name() === $package_key['kind'] ) { $this->register_strings->register_strings( $post, $package_key ); } } /** * @param string $kind * @param int $translated_post_id * @param WP_Post $original_post * @param array $string_translations * @param string $lang */ public function update_translated_post( $kind, $translated_post_id, WP_Post $original_post, $string_translations, $lang ) { if ( $this->data_settings->get_pb_name() === $kind ) { $this->update_translation->update( $translated_post_id, $original_post, $string_translations, $lang ); } } public function remove_shortcode_strings_type_filter( $types ) { unset( $types[ sanitize_title_with_dashes( $this->data_settings->get_pb_name() ) ] ); return $types; } } wpml-page-builders/classes/Shared/st/ShortCodesInGutenbergBlocks.php 0000755 00000002733 14720415745 0021634 0 ustar 00 <?php namespace WPML\PB; use WPML\FP\Fns; /** * Class ShortCodesInGutenbergBlocks * @package WPML\PB * * This class is to handle an edge case when there is only one Gutenberg block * that contains one or more shortcodes. * In this case we need to force the Gutenberg processing as there will be * no Gutenberg strings and only shortcode strings. * */ class ShortCodesInGutenbergBlocks { const FORCED_GUTENBERG = 'Forced-Gutenberg'; public static function recordPackage( \WPML_PB_String_Translation_By_Strategy $strategy, $strategyKind, \WPML_Package $package, $language ) { if ( $strategyKind === 'Gutenberg' && $package->kind === 'Page Builder ShortCode Strings' ) { $package->kind = self::FORCED_GUTENBERG; $strategy->add_package_to_update_list( $package, $language ); } } public static function fixupPackage( $package_data ) { if ( $package_data['package']->kind === self::FORCED_GUTENBERG ) { $package_data['package']->kind = 'Gutenberg'; } return $package_data; } public static function normalizePackages( array $packagesToUpdate ) { if ( count( $packagesToUpdate ) > 1 ) { // If we have more than one package then we don't need to 'Force' it. // The normal Gutenberg package will update all translations correctly. $isForced = function ( $package ) { return $package['package']->kind !== self::FORCED_GUTENBERG; }; $packagesToUpdate = array_filter( $packagesToUpdate, $isForced ); } return $packagesToUpdate; } } wpml-page-builders/classes/Shared/tm/class-wpml-pb-handle-custom-fields.php 0000755 00000003412 14720415745 0022742 0 ustar 00 <?php class WPML_PB_Handle_Custom_Fields { protected $data_settings; public function __construct( IWPML_Page_Builders_Data_Settings $data_settings ) { $this->data_settings = $data_settings; } public function add_hooks() { add_filter( 'wpml_pb_is_page_builder_page', array( $this, 'is_page_builder_page_filter' ), 10, 2 ); add_action( 'wpml_pb_after_page_without_elements_post_content_copy', array( $this, 'copy_custom_fields' ), 10, 2 ); } /** * @param bool $is_page_builder_page * @param WP_Post $post * * @return bool */ public function is_page_builder_page_filter( $is_page_builder_page, WP_Post $post ) { if ( $this->data_settings->is_handling_post( $post->ID ) ) { $is_page_builder_page = true; } return $is_page_builder_page; } /** * @param int $new_post_id * @param int $original_post_id */ public function copy_custom_fields( $new_post_id, $original_post_id ) { $fields = array_merge( $this->data_settings->get_fields_to_copy(), $this->data_settings->get_fields_to_save() ); foreach ( $fields as $field ) { self::copy_field( $new_post_id, $original_post_id, $field ); } } /** * @param int $new_post_id * @param int $original_post_id * @param string $field */ public static function copy_field( $new_post_id, $original_post_id, $field ) { $original_field = get_post_meta( $original_post_id, $field, true ); if ( $original_field ) { update_post_meta( $new_post_id, $field, self::slash_json( $original_field ) ); } } /** * @param mixed $data * * @return mixed string */ public static function slash_json( $data ) { if ( ! is_string( $data ) ) { return $data; } json_decode( $data ); if ( json_last_error() === JSON_ERROR_NONE ) { return wp_slash( $data ); } return $data; } } wpml-page-builders/classes/Shared/tm/class-wpml-pb-handle-post-body.php 0000755 00000003036 14720415745 0022106 0 ustar 00 <?php class WPML_PB_Handle_Post_Body implements IWPML_Backend_Action, IWPML_Frontend_Action, IWPML_DIC_Action { private $page_builders_built; public function __construct( WPML_Page_Builders_Page_Built $page_builders_built ) { $this->page_builders_built = $page_builders_built; } public function add_hooks() { add_filter( 'wpml_pb_should_body_be_translated', array( $this, 'should_translate' ), 10, 3 ); add_action( 'wpml_pb_finished_adding_string_translations', array( $this, 'copy' ), 10, 3 ); } /** * @param int $translate * @param WP_Post $post * * @return int */ public function should_translate( $translate, WP_Post $post ) { return $this->page_builders_built->is_page_builder_page( $post ) ? 0 : $translate; } /** * @param int $new_post_id * @param int $original_post_id * @param array $fields */ public function copy( $new_post_id, $original_post_id, array $fields ) { $original_post = get_post( $original_post_id ); if ( $original_post && $this->page_builders_built->is_page_builder_page( $original_post ) && ! $this->job_has_packages( $fields ) ) { wpml_update_escaped_post( [ 'ID' => $new_post_id, 'post_content' => $original_post->post_content ] ); do_action( 'wpml_pb_after_page_without_elements_post_content_copy', $new_post_id, $original_post_id ); } } /** * @param array $fields * * @return bool */ private function job_has_packages( array $fields ) { foreach ( $fields as $key => $field ) { if ( 0 === strpos( $key, 'package' ) ) { return true; } } return false; } } wpml-page-builders/classes/Shared/tm/class-wpml-tm-page-builders.php 0000755 00000016273 14720415745 0021506 0 ustar 00 <?php class WPML_TM_Page_Builders { const PACKAGE_TYPE_EXTERNAL = 'external'; const TRANSLATION_COMPLETE = 10; const FIELD_STYLE_AREA = 'AREA'; const FIELD_STYLE_VISUAL = 'VISUAL'; const FIELD_STYLE_LINK = 'LINK'; /** @var SitePress $sitepress */ private $sitepress; /** @var \WPML_PB_Integration|null */ private $wpmlPbIntegration; /** * @param SitePress $sitepress * @param WPML_PB_Integration|null $wpmlPbIntegration */ public function __construct( SitePress $sitepress, \WPML_PB_Integration $wpmlPbIntegration = null ) { $this->sitepress = $sitepress; $this->wpmlPbIntegration = $wpmlPbIntegration; } /** * Filter translation job data. * * @param array $translation_package Translation package. * @param mixed $post Post. * @param bool $isOriginal If it's used as original post. * * @return array */ public function translation_job_data_filter( array $translation_package, $post, $isOriginal = false ) { if ( self::PACKAGE_TYPE_EXTERNAL !== $translation_package['type'] && isset( $post->ID ) ) { $post_element = new WPML_Post_Element( $post->ID, $this->sitepress ); $source_post_id = $post->ID; $job_lang_from = $post_element->get_language_code(); if ( ! $post_element->is_root_source() && $isOriginal && WPML_PB_Last_Translation_Edit_Mode::is_native_editor( $post->ID ) ) { $this->getWpmlPbIntegration()->register_all_strings_for_translation( $post, true ); $source_post_element = $post_element->get_translation( $job_lang_from ); } else { $source_post_element = $post_element->get_source_element(); } if ( $source_post_element ) { $source_post_id = $source_post_element->get_id(); } $job_source_is_not_post_source = $post->ID !== $source_post_id; $string_packages = apply_filters( 'wpml_st_get_post_string_packages', false, $source_post_id ); $translation_package['contents']['body']['translate'] = apply_filters( 'wpml_pb_should_body_be_translated', $translation_package['contents']['body']['translate'], $post ); if ( $string_packages ) { foreach ( $string_packages as $package_id => $string_package ) { /** * String package. * * @var WPML_Package $string_package */ $strings = $string_package->get_package_strings(); $string_translations = array(); if ( $job_source_is_not_post_source ) { $string_translations = $string_package->get_translated_strings( array() ); } foreach ( $strings as $string ) { if ( self::FIELD_STYLE_LINK !== $string->type ) { $string_value = $string->value; if ( isset( $string_translations[ $string->name ][ $job_lang_from ]['value'] ) ) { $string_value = $string_translations[ $string->name ][ $job_lang_from ]['value']; } $field_name = WPML_TM_Page_Builders_Field_Wrapper::generate_field_slug( $package_id, $string->id ); $translation_package['contents'][ $field_name ] = array( 'translate' => 1, // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode 'data' => base64_encode( $string_value ), // phpcs:enable 'wrap_tag' => WPML_TM_Page_Builders_Field_Wrapper::get_wrap_tag( $string ), 'format' => 'base64', ); } $translation_package['contents']['body']['translate'] = 0; } } } } return $translation_package; } /** * @param int $new_element_id * @param array $fields * @param stdClass $job */ public function pro_translation_completed_action( $new_element_id, array $fields, stdClass $job ) { if ( 'post' !== $job->element_type_prefix ) { return; } foreach ( $fields as $field_id => $field ) { $field_slug = isset( $field['field_type'] ) ? $field['field_type'] : $field_id; $wrapper = $this->create_field_wrapper( $field_slug ); $string_id = $wrapper->get_string_id(); if ( $string_id ) { do_action( 'wpml_add_string_translation', $string_id, $job->language_code, $field['data'], self::TRANSLATION_COMPLETE, $job->translator_id, $job->translation_service ); } } do_action( 'wpml_pb_finished_adding_string_translations', $new_element_id, $job->original_doc_id, $fields ); } /** * Adjust translation fields. * * @param array $fields Translation fields. * @param stdClass $job Translation job. * * @return array */ public function adjust_translation_fields_filter( array $fields, $job ) { foreach ( $fields as &$field ) { $wrapper = $this->create_field_wrapper( $field['field_type'] ); $type = $wrapper->get_string_type(); $string_title = $wrapper->get_string_title(); if ( $string_title ) { $field['title'] = $string_title; } if ( isset( $field['field_wrap_tag'] ) && $field['field_wrap_tag'] ) { $field['title'] = isset( $field['title'] ) ? $field['title'] : ''; $field['title'] .= ' (' . $field['field_wrap_tag'] . ')'; } if ( false !== $type ) { switch ( $type ) { case self::FIELD_STYLE_AREA: $field['field_style'] = '1'; break; case self::FIELD_STYLE_VISUAL: $field['field_style'] = '2'; break; default: $field['field_style'] = '0'; break; } } } return $fields; } /** * @param array $layout * * @return array */ public function job_layout_filter( array $layout ) { $string_groups = array(); foreach ( $layout as $k => $field ) { $wrapper = $this->create_field_wrapper( $field ); if ( $wrapper->is_valid() ) { $string_groups[ $wrapper->get_package_id() ][] = $field; unset( $layout[ $k ] ); } } foreach ( $string_groups as $string_package_id => $fields ) { $string_package = apply_filters( 'wpml_st_get_string_package', false, $string_package_id ); $section = array( 'field_type' => 'tm-section', 'title' => isset( $string_package->title ) ? $string_package->title : '', 'fields' => $fields, 'empty' => false, 'empty_message' => '', 'sub_title' => '', ); $layout[] = $section; } return array_values( $layout ); } /** * @param string $link * @param int $post_id * @param string $lang * @param int $trid * * @return string */ public function link_to_translation_filter( $link, $post_id, $lang, $trid ) { /* @var WPML_TM_Translation_Status $wpml_tm_translation_status */ global $wpml_tm_translation_status; $status = $wpml_tm_translation_status->filter_translation_status( null, $trid, $lang ); if ( $link && ICL_TM_NEEDS_UPDATE === $status ) { $args = array( 'update_needed' => 1, 'trid' => $trid, 'language_code' => $lang, ); $link = add_query_arg( $args, $link ); } return $link; } /** * @param string $field_slug * * @return WPML_TM_Page_Builders_Field_Wrapper */ public function create_field_wrapper( $field_slug ) { return new WPML_TM_Page_Builders_Field_Wrapper( $field_slug ); } /** * @return \WPML_PB_Integration * */ private function getWpmlPbIntegration() { if ( null === $this->wpmlPbIntegration ) { $this->wpmlPbIntegration = \WPML\Container\make( \WPML_PB_Integration::class ); } return $this->wpmlPbIntegration; } } wpml-page-builders/classes/Shared/tm/class-wpml-tm-page-builders-hooks.php 0000755 00000006222 14720415745 0022620 0 ustar 00 <?php class WPML_TM_Page_Builders_Hooks { /* @var WPML_TM_Page_Builders $worker */ private $worker; /** @var SitePress $sitepress */ private $sitepress; /** * WPML_TM_Page_Builders constructor. * * @param WPML_TM_Page_Builders $worker */ public function __construct( WPML_TM_Page_Builders $worker = null, SitePress $sitepress ) { $this->worker = $worker; $this->sitepress = $sitepress; } public function init_hooks() { add_filter( 'wpml_tm_translation_job_data', array( $this, 'translation_job_data_filter' ), 10, 3 ); add_action( 'wpml_pro_translation_completed', array( $this, 'pro_translation_completed_action' ), 10, 3 ); add_filter( 'wpml_tm_adjust_translation_fields', array( $this, 'adjust_translation_fields_filter' ), 10, 2 ); add_filter( 'wpml_tm_job_layout', array( $this, 'job_layout_filter' ) ); add_filter( 'wpml_link_to_translation', array( $this, 'link_to_translation_filter' ), 20, 4 ); add_filter( 'wpml_get_translatable_types', array( $this, 'remove_shortcode_strings_type_filter' ), 11); } /** * @param array $translation_package * @param mixed $post * @param bool $isOriginal * * @return array */ public function translation_job_data_filter( array $translation_package, $post, $isOriginal = false ) { $worker = $this->get_worker(); return $worker->translation_job_data_filter( $translation_package, $post, $isOriginal ); } /** * @param int $new_post_id * @param array $fields * @param stdClass $job */ public function pro_translation_completed_action( $new_post_id, array $fields, stdClass $job ) { $worker = $this->get_worker(); $worker->pro_translation_completed_action( $new_post_id, $fields, $job ); } /** * Filter translation fields. * * @param array $fields Translation fields. * @param stdClass $job Translation job. * * @return array */ public function adjust_translation_fields_filter( array $fields, $job ) { $worker = $this->get_worker(); $fields = $worker->adjust_translation_fields_filter( $fields, $job ); return $fields; } /** * @param array $layout * * @return array */ public function job_layout_filter( array $layout ) { $worker = $this->get_worker(); return $worker->job_layout_filter( $layout ); } /** * @param string $link * @param int $post_id * @param string $lang * @param int $trid * * @return string */ public function link_to_translation_filter( $link, $post_id, $lang, $trid ) { $worker = $this->get_worker(); return $worker->link_to_translation_filter( $link, $post_id, $lang, $trid ); } /** * Remove "Page Builder ShortCode Strings" from translation dashboard filters * * @param array $types * * @return mixed */ public function remove_shortcode_strings_type_filter( $types ) { if ( array_key_exists( 'page-builder-shortcode-strings', $types ) ) { unset( $types['page-builder-shortcode-strings'] ); } return $types; } /** * @return WPML_TM_Page_Builders */ private function get_worker() { if ( ! $this->worker ) { $this->worker = new WPML_TM_Page_Builders( $this->sitepress ); } return $this->worker; } } wpml-page-builders/classes/Shared/tm/class-wpml-tm-page-builders-field-wrapper.php 0000755 00000007625 14720415745 0024246 0 ustar 00 <?php /** * WPML_TM_Page_Builders_Field_Wrapper class file. * * @package wpml-page-builders */ /** * Class WPML_TM_Page_Builders_Field_Wrapper */ class WPML_TM_Page_Builders_Field_Wrapper { const SLUG_BASE = 'package-string-'; /** * Field slug. * * @var false|string */ private $field_slug; /** * Package id. * * @var string|false|null */ private $package_id; /** * String id. * * @var string|false|null */ private $string_id; /** * WPML_TM_Page_Builders_Field_Wrapper constructor. * * @param string $field_slug Field slug. */ public function __construct( $field_slug ) { $this->field_slug = $field_slug; } /** * Check if package is valid. * * @param bool $package_must_exist Demand existence of the package. * * @return bool */ public function is_valid( $package_must_exist = false ) { $result = $this->get_package_id() && $this->get_string_id(); if ( $result && $package_must_exist ) { $result = $this->get_package() !== null; } return $result; } /** * Get package id. * * @return false|string */ public function get_package_id() { if ( null === $this->package_id ) { $this->package_id = $this->extract_string_package_id( $this->field_slug ); } return $this->package_id; } /** * Get package. * * @return WPML_Package|null */ public function get_package() { if ( ! $this->get_package_id() ) { return null; } return apply_filters( 'wpml_st_get_string_package', false, $this->get_package_id() ); } /** * Get string id. * * @return false|string */ public function get_string_id() { if ( null === $this->string_id ) { $this->string_id = $this->extract_string_id( $this->field_slug ); } return $this->string_id; } /** * Get field slug. * * @return string */ public function get_field_slug() { return $this->field_slug; } /** * Get string type. * * @return false|string */ public function get_string_type() { $result = false; if ( $this->is_valid( true ) ) { $package_strings = $this->get_package()->get_package_strings(); if ( ! $package_strings ) { return false; } $package_strings = wp_list_pluck( $package_strings, 'type', 'id' ); $result = $package_strings[ $this->get_string_id() ]; } return $result; } /** * Get string wrap tag. * * @param stdClass $string WPML string. * * @return string */ public static function get_wrap_tag( $string ) { return isset( $string->wrap_tag ) ? $string->wrap_tag : ''; } /** * Generate field slug. * * @param int $package_id Package id. * @param int $string_id String id. * * @return string */ public static function generate_field_slug( $package_id, $string_id ) { return self::SLUG_BASE . $package_id . '-' . $string_id; } /** * Extract string id. * * @param string $field_slug Field slug. * * @return false|string */ private function extract_string_id( $field_slug ) { $result = false; if ( is_string( $field_slug ) && preg_match( '#^' . self::SLUG_BASE . '#', $field_slug ) ) { $result = preg_replace( '#^' . self::SLUG_BASE . '([0-9]+)-([0-9]+)$#', '$2', $field_slug, 1 ); } return is_numeric( $result ) ? $result : false; } /** * Extract string package id. * * @param string $field_slug Field slug. * * @return false|string */ private function extract_string_package_id( $field_slug ) { $result = false; if ( is_string( $field_slug ) && preg_match( '#^' . self::SLUG_BASE . '#', $field_slug ) ) { $result = preg_replace( '#^' . self::SLUG_BASE . '([0-9]+)-([0-9]+)$#', '$1', $field_slug, 1 ); } return is_numeric( $result ) ? $result : false; } /** * Get string title. * * @return string|bool */ public function get_string_title() { if ( null === $this->string_id ) { $this->string_id = $this->extract_string_id( $this->field_slug ); } return apply_filters( 'wpml_string_title_from_id', false, $this->string_id ); } } wpml-page-builders/classes/Shared/Container/Config.php 0000755 00000000250 14720415745 0016760 0 ustar 00 <?php namespace WPML\PB\Container; class Config { public static function getSharedClasses() { return [ '\WPML_PB_Factory', '\WPML_PB_Integration', ]; } } wpml-page-builders/classes/Shared/AutoUpdate/Hooks.php 0000755 00000010373 14720415745 0016776 0 ustar 00 <?php namespace WPML\PB\AutoUpdate; use WPML\FP\Fns; use WPML\FP\Logic; use WPML\FP\Lst; use WPML\FP\Maybe; use WPML\FP\Relation; use WPML\PB\Shutdown\Hooks as ShutdownHooks; use function WPML\FP\invoke; use function WPML\FP\partialRight; use function WPML\FP\pipe; class Hooks implements \IWPML_Backend_Action, \IWPML_Frontend_Action, \IWPML_DIC_Action { const HASH_SEP = '-'; /** @var \WPML_PB_Integration $pbIntegration */ private $pbIntegration; /** @var \WPML_Translation_Element_Factory $elementFactory */ private $elementFactory; /** @var \WPML_Page_Builders_Page_Built $pageBuilt */ private $pageBuilt; /** @var array $translationStatusesUpdaters */ private $translationStatusesUpdaters = []; public function __construct( \WPML_PB_Integration $pbIntegration, \WPML_Translation_Element_Factory $elementFactory, \WPML_Page_Builders_Page_Built $pageBuilt ) { $this->pbIntegration = $pbIntegration; $this->elementFactory = $elementFactory; $this->pageBuilt = $pageBuilt; } public function add_hooks() { if ( Settings::isEnabled() && $this->isTmLoaded() ) { add_filter( 'wpml_tm_delegate_translation_statuses_update', [ $this, 'enqueueTranslationStatusUpdate'], 10, 3 ); add_filter( 'wpml_tm_post_md5_content', [ $this, 'getMd5ContentFromPackageStrings' ], 10, 2 ); add_action( 'shutdown', [ $this, 'afterRegisterAllStringsInShutdown' ], ShutdownHooks::PRIORITY_REGISTER_STRINGS + 1 ); } } public function isTmLoaded() { return defined( 'WPML_TM_VERSION' ); } /** * @param bool $isDelegated * @param int $originalPostId * @param callable $statusesUpdater * * @return bool */ public function enqueueTranslationStatusUpdate( $isDelegated, $originalPostId, $statusesUpdater ) { $this->translationStatusesUpdaters[ $originalPostId ] = $statusesUpdater; return true; } /** * @param string $content * @param \WP_Post $post * * @return string */ public function getMd5ContentFromPackageStrings( $content, $post ) { // $joinPackageStringHashes :: \WPML_Package → string $joinPackageStringHashes = pipe( invoke( 'get_package_strings' )->with( true ), Lst::pluck( 'value' ), Lst::sort( Relation::gt() ), Lst::join( self::HASH_SEP ) ); return Maybe::of( $post->ID ) ->map( [ self::class, 'getPackages' ] ) ->map( Fns::map( $joinPackageStringHashes ) ) ->filter() ->map( Lst::join( self::HASH_SEP ) ) ->getOrElse( $content ); } /** * @param int $postId * * @return \WPML_Package[] */ public static function getPackages( $postId ) { return apply_filters( 'wpml_st_get_post_string_packages', [], $postId ); } /** * We need to update translation statuses after string registration * to make sure we build the content hash with the new strings. */ public function afterRegisterAllStringsInShutdown() { if ( $this->translationStatusesUpdaters ) { do_action( 'wpml_cache_clear' ); foreach ( $this->translationStatusesUpdaters as $originalPostId => $translationStatusesUpdater ) { if ( \get_post( $originalPostId ) ) { call_user_func( $translationStatusesUpdater ); $this->resaveTranslations( $originalPostId ); } } } } /** * @param int $postId */ private function resaveTranslations( $postId ) { if ( ! $this->isPageBuilder( $postId ) ) { return; } // $ifOriginal :: \WPML_Post_Element → bool $ifOriginal = pipe( invoke( 'get_source_language_code' ), Logic::not() ); // $ifCompleted :: \WPML_Post_Element → bool $ifCompleted = pipe( [ TranslationStatus::class, 'get' ], Relation::equals( ICL_TM_COMPLETE ) ); // $resaveElement :: \WPML_Post_Element → null $resaveElement = \WPML\FP\Fns::unary( partialRight( [ $this->pbIntegration, 'resave_post_translation_in_shutdown' ], false ) ); wpml_collect( $this->elementFactory->create_post( $postId )->get_translations() ) ->reject( $ifOriginal ) ->filter( $ifCompleted ) ->each( $resaveElement ); } /** * @param int $postId * * @return bool */ private function isPageBuilder( $postId ) { $isPbPostWithoutStrings = function( $postId ) { $post = get_post( $postId ); return $post instanceof \WP_Post && $this->pageBuilt->is_page_builder_page( $post ); }; return self::getPackages( $postId ) || $isPbPostWithoutStrings( $postId ); } } wpml-page-builders/classes/Shared/AutoUpdate/TranslationStatus.php 0000755 00000001007 14720415745 0021407 0 ustar 00 <?php namespace WPML\PB\AutoUpdate; use WPML\FP\Maybe; use WPML_Post_Element; use function WPML\Container\make; use function WPML\FP\invoke; class TranslationStatus { /** * @param WPML_Post_Element $element * * @return int|null */ public static function get( WPML_Post_Element $element ) { return Maybe::fromNullable( make( '\WPML_TM_Translation_Status' ) ) ->map( invoke( 'filter_translation_status' )->with( null, $element->get_trid(), $element->get_language_code() ) ) ->getOrElse( null ); } } wpml-page-builders/classes/Shared/AutoUpdate/Settings.php 0000755 00000000761 14720415745 0017513 0 ustar 00 <?php namespace WPML\PB\AutoUpdate; class Settings { /** * This is part of the "Translation Auto-Update" feature * The "Translation Auto-Update" feature will be released in the next major version. * We need a way for users to allow disabling it quickly, if necessary. * * @return bool */ public static function isEnabled() { if ( defined( 'WPML_TRANSLATION_AUTO_UPDATE_ENABLED' ) ) { return (bool) constant( 'WPML_TRANSLATION_AUTO_UPDATE_ENABLED' ); } return true; } } wpml-page-builders/classes/Shared/media/interface-iwpml-pb-media-update.php 0000755 00000000164 14720415745 0022736 0 ustar 00 <?php interface IWPML_PB_Media_Update { /** * @param WP_Post $post */ public function translate( $post ); } wpml-page-builders/classes/Shared/media/class-wpml-page-builders-media-usage.php 0000755 00000001405 14720415745 0023675 0 ustar 00 <?php class WPML_Page_Builders_Media_Usage { /** @var WPML_Page_Builders_Media_Translate $media_translate */ private $media_translate; /** @var WPML_Media_Usage_Factory $media_usage_factory */ private $media_usage_factory; public function __construct( WPML_Page_Builders_Media_Translate $media_translate, WPML_Media_Usage_Factory $media_usage_factory ) { $this->media_translate = $media_translate; $this->media_usage_factory = $media_usage_factory; } /** @param int $post_id */ public function update( $post_id ) { $media_ids = $this->media_translate->get_translated_ids(); foreach ( $media_ids as $media_id ) { $this->media_usage_factory->create( $media_id )->add_post( $post_id ); } $this->media_translate->reset_translated_ids(); } } wpml-page-builders/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes.php 0000755 00000007527 14720415745 0027136 0 ustar 00 <?php class WPML_Page_Builders_Media_Shortcodes { const TYPE_URL = 'media-url'; const TYPE_IDS = 'media-ids'; /** @var WPML_Page_Builders_Media_Translate $media_translate */ private $media_translate; /** @var string $target_lang */ private $target_lang; /** @var string $source_lang */ private $source_lang; /** @var array $config */ private $config; public function __construct( WPML_Page_Builders_Media_Translate $media_translate, array $config ) { $this->media_translate = $media_translate; $this->config = $config; } /** * @param string $content * * @return string */ public function translate( $content ) { foreach ( $this->config as $shortcode ) { $shortcode = $this->sanitize_shortcode( $shortcode ); $tag_name = isset( $shortcode['tag']['name'] ) ? $shortcode['tag']['name'] : ''; if ( ! empty( $shortcode['attributes'] ) ) { $content = $this->translate_attributes( $content, $tag_name, $shortcode['attributes'] ); } if ( ! empty( $shortcode['content'] ) ) { $content = $this->translate_content( $content, $tag_name, $shortcode['content'] ); } } return $content; } /** * @param string $content * * @return bool */ public function has_media_shortcode( $content ) { if ( false === strpos( $content, '[' ) ) { return false; }; foreach ( $this->config as $shortcode ) { $shortcode = $this->sanitize_shortcode( $shortcode ); $tag_name = isset( $shortcode['tag']['name'] ) ? $shortcode['tag']['name'] : ''; if ( $tag_name && false !== strpos( $content, '[' . $tag_name ) ) { return true; } } return false; } /** * @param array $shortcode * * @return array */ private function sanitize_shortcode( array $shortcode ) { $defaults = array( 'attributes' => null, ); return array_merge( $defaults, $shortcode ); } /** * @param string $content * @param string $tag * @param array $attributes * * @return string */ private function translate_attributes( $content, $tag, array $attributes ) { foreach ( $attributes as $attribute => $data ) { $pattern = '/(\[' . $tag . '(?: [^\]]* | )' . $attribute . '=(?:"|\'))([^"\']*)/'; $type = isset( $data['type'] ) ? $data['type'] : ''; $content = preg_replace_callback( $pattern, array( $this, $this->get_callback( $type ) ), $content ); } return $content; } /** * @param string $content * @param string $tag * @param array $data * * @return string */ private function translate_content( $content, $tag, array $data ) { $pattern = '/(\[(?:' . $tag . ')[^\]]*\])([^\[]+)/'; $type = isset( $data['type'] ) ? $data['type'] : ''; return preg_replace_callback( $pattern, array( $this, $this->get_callback( $type ) ), $content ); } /** * @param string $type * * @return string */ private function get_callback( $type ) { if ( self::TYPE_URL === $type ) { return 'replace_url_callback'; } return 'replace_ids_callback'; } /** * @param array $matches * * @return string */ private function replace_url_callback( array $matches ) { $translated_url = $this->media_translate->translate_image_url( $matches[2], $this->target_lang, $this->source_lang ); return $matches[1] . $translated_url; } /** * @param array $matches * * @return string */ private function replace_ids_callback( array $matches ) { $ids = explode( ',', $matches[2] ); foreach ( $ids as &$id ) { $id = $this->media_translate->translate_id( (int) $id, $this->target_lang ); } return $matches[1] . implode( ',', $ids ); } /** * @param string $target_lang * * @return self */ public function set_target_lang( $target_lang ) { $this->target_lang = $target_lang; return $this; } /** * @param string $source_lang * * @return self */ public function set_source_lang( $source_lang ) { $this->source_lang = $source_lang; return $this; } } classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes-update.php 0000755 00000003335 14720415745 0030330 0 ustar 00 wpml-page-builders <?php class WPML_Page_Builders_Media_Shortcodes_Update implements IWPML_PB_Media_Update { /** @var WPML_Translation_Element_Factory $element_factory */ private $element_factory; /** @var WPML_Page_Builders_Media_Shortcodes $media_shortcodes*/ private $media_shortcodes; /** @var WPML_Page_Builders_Media_Usage $media_usage */ private $media_usage; public function __construct( WPML_Translation_Element_Factory $element_factory, WPML_Page_Builders_Media_Shortcodes $media_shortcodes, WPML_Page_Builders_Media_Usage $media_usage ) { $this->element_factory = $element_factory; $this->media_shortcodes = $media_shortcodes; $this->media_usage = $media_usage; } /** * @param WP_Post $post */ public function translate( $post ) { if ( ! $this->media_shortcodes->has_media_shortcode( $post->post_content ) ) { return; } $element = $this->element_factory->create_post( $post->ID ); if ( ! $element->get_source_language_code() ) { return; } $post->post_content = $this->media_shortcodes->set_target_lang( $element->get_language_code() ) ->set_source_lang( $element->get_source_language_code() ) ->translate( $post->post_content ); $this->media_usage->update( $element->get_source_element()->get_id() ); /** * The function wp_update_post() can modify post tag. * The code below sends tags by IDs to prevent this. * * @see wpmlcore-5947 * @see https://core.trac.wordpress.org/ticket/45121 */ $tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) ); $postarr = array( 'ID' => $post->ID, 'post_content' => $post->post_content, 'tags_input' => $tag_ids, ); kses_remove_filters(); wpml_update_escaped_post( $postarr ); kses_init(); } } classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes-update-factory.php 0000755 00000003305 14720415745 0031772 0 ustar 00 wpml-page-builders <?php class WPML_Page_Builders_Media_Shortcodes_Update_Factory implements IWPML_PB_Media_Update_Factory { /** @var WPML_PB_Config_Import_Shortcode WPML_PB_Config_Import_Shortcode */ private $page_builder_config_import; /** @var WPML_Translation_Element_Factory|null $element_factory */ private $element_factory; /** @var WPML_Page_Builders_Media_Translate|null $media_translate */ private $media_translate; public function __construct( WPML_PB_Config_Import_Shortcode $page_builder_config_import ) { $this->page_builder_config_import = $page_builder_config_import; } public function create() { $media_shortcodes = new WPML_Page_Builders_Media_Shortcodes( $this->get_media_translate(), $this->page_builder_config_import->get_media_settings() ); return new WPML_Page_Builders_Media_Shortcodes_Update( $this->get_element_factory(), $media_shortcodes, new WPML_Page_Builders_Media_Usage( $this->get_media_translate(), new WPML_Media_Usage_Factory() ) ); } /** @return WPML_Translation_Element_Factory */ private function get_element_factory() { global $sitepress; if ( ! $this->element_factory ) { $this->element_factory = new WPML_Translation_Element_Factory( $sitepress ); } return $this->element_factory; } /** @return WPML_Page_Builders_Media_Translate */ private function get_media_translate() { global $sitepress; if ( ! $this->media_translate ) { $this->media_translate = new WPML_Page_Builders_Media_Translate( $this->get_element_factory(), new WPML_Media_Image_Translate( $sitepress, new WPML_Media_Attachment_By_URL_Factory(), new \WPML\Media\Factories\WPML_Media_Attachment_By_URL_Query_Factory() ) ); } return $this->media_translate; } } wpml-page-builders/classes/Shared/media/class-wpml-page-builders-media-hooks.php 0000755 00000003202 14720415745 0023711 0 ustar 00 <?php class WPML_Page_Builders_Media_Hooks implements IWPML_Action { /** @var IWPML_PB_Media_Update_Factory $media_update_factory */ private $media_update_factory; /** @var string $page_builder_slug */ private $page_builder_slug; /** * WPML_Page_Builders_Media_Hooks constructor. * * @param IWPML_PB_Media_Update_Factory $media_update_factory * @param string $page_builder_slug */ public function __construct( IWPML_PB_Media_Update_Factory $media_update_factory, $page_builder_slug ) { $this->media_update_factory = $media_update_factory; $this->page_builder_slug = $page_builder_slug; } public function add_hooks() { add_filter( 'wpml_pb_get_media_updaters', array( $this, 'add_media_updater' ) ); add_filter( 'wpml_media_content_for_media_usage', array( $this, 'add_package_strings_content' ), 10, 2 ); } /** * @param IWPML_PB_Media_Update[] $updaters * * @return IWPML_PB_Media_Update[] */ public function add_media_updater( $updaters ) { if ( ! array_key_exists( $this->page_builder_slug, $updaters ) ) { $updaters[ $this->page_builder_slug ] = $this->media_update_factory->create(); } return $updaters; } /** * @param string $content * @param WP_Post $post * * @return string */ public function add_package_strings_content( $content, $post ) { $packages = apply_filters( 'wpml_st_get_post_string_packages', array(), $post->ID ); /** @var WPML_Package[] $packages */ foreach ( $packages as $package ) { $strings = $package->get_package_strings(); foreach ( $strings as $string ) { $content .= PHP_EOL . $string->value; } } return $content; } } wpml-page-builders/classes/Shared/media/class-wpml-page-builders-update-media.php 0000755 00000003102 14720415745 0024047 0 ustar 00 <?php class WPML_Page_Builders_Update_Media implements IWPML_PB_Media_Update { /** @var WPML_Page_Builders_Update $pb_update */ private $pb_update; /** @var WPML_Translation_Element_Factory $element_factory */ private $element_factory; /** @var IWPML_PB_Media_Nodes_Iterator $node_iterator */ protected $node_iterator; /** @var WPML_Page_Builders_Media_Usage|null $media_usage */ protected $media_usage; public function __construct( WPML_Page_Builders_Update $pb_update, WPML_Translation_Element_Factory $element_factory, IWPML_PB_Media_Nodes_Iterator $node_iterator, WPML_Page_Builders_Media_Usage $media_usage = null ) { $this->pb_update = $pb_update; $this->element_factory = $element_factory; $this->node_iterator = $node_iterator; $this->media_usage = $media_usage; } /** * @param WP_Post $post */ public function translate( $post ) { $element = $this->element_factory->create_post( $post->ID ); $source_element = $element->get_source_element(); if ( ! $source_element ) { return; } $lang = $element->get_language_code(); $source_lang = $source_element->get_language_code(); $original_post_id = $source_element->get_id(); $converted_data = $this->pb_update->get_converted_data( $post->ID ); if ( ! $converted_data ) { return; } $converted_data = $this->node_iterator->translate( $converted_data, $lang, $source_lang ); $this->pb_update->save( $post->ID, $original_post_id, $converted_data ); if ( $this->media_usage ) { $this->media_usage->update( $original_post_id ); } } } wpml-page-builders/classes/Shared/media/class-wpml-page-builders-media-translate.php 0000755 00000005346 14720415745 0024576 0 ustar 00 <?php class WPML_Page_Builders_Media_Translate { /** @var WPML_Translation_Element_Factory $element_factory */ private $element_factory; /** @var WPML_Media_Image_Translate $image_translate */ protected $image_translate; /** @var array $translated_urls */ protected $translated_urls = array(); /** @var (WP_Post|null)[] $translated_posts */ protected $translated_posts = array(); /** @var array $translated_ids */ private $translated_ids = array(); public function __construct( WPML_Translation_Element_Factory $element_factory, WPML_Media_Image_Translate $image_translate ) { $this->element_factory = $element_factory; $this->image_translate = $image_translate; } /** * @param string $url * @param string $lang * @param string $source_lang * * @return string */ public function translate_image_url( $url, $lang, $source_lang ) { $key = $url . $lang . $source_lang; if ( ! array_key_exists( $key, $this->translated_urls ) ) { $this->translated_urls[ $key ] = $url; $attachment_id = $this->image_translate->get_attachment_id_by_url( $url, $source_lang ); if ( $attachment_id ) { $this->add_translated_id( $attachment_id ); $translated_url = $this->image_translate->get_translated_image_by_url( $url, $source_lang, $lang ); $this->translated_urls[ $key ] = $url; if ( $translated_url ) { $this->translated_urls[ $key ] = $translated_url; } } } return $this->translated_urls[ $key ]; } /** * @param int $id * @param string $lang * * @return int */ public function translate_id( $id, $lang ) { if ( (int) $id < 1 ) { return $id; } $this->add_translated_id( $id ); $translated_attachment = $this->get_translated_attachment( $id, $lang ); if ( isset( $translated_attachment->ID ) ) { return $translated_attachment->ID; } return $id; } /** * @param int $id * @param string $lang * * @return WP_Post|null */ private function get_translated_attachment( $id, $lang ) { $key = $id . $lang; if ( ! array_key_exists( $key, $this->translated_posts ) ) { $this->translated_posts[ $key ] = null; $element = $this->element_factory->create_post( $id ); $translation = $element->get_translation( $lang ); if ( $translation ) { $this->translated_posts[ $key ] = $translation->get_wp_object(); } } return $this->translated_posts[ $key ]; } /** @param int $id */ private function add_translated_id( $id ) { if ( ! in_array( $id, $this->translated_ids, true ) ) { $this->translated_ids[] = $id; } } public function reset_translated_ids() { $this->translated_ids = array(); } /** @return array */ public function get_translated_ids() { return $this->translated_ids; } } wpml-page-builders/classes/Shared/media/interface-iwpml-pb-media-update-factory.php 0000755 00000000165 14720415745 0024404 0 ustar 00 <?php interface IWPML_PB_Media_Update_Factory { /** @return IWPML_PB_Media_Update */ public function create(); } wpml-page-builders/classes/Shared/media/interface-iwpml-pb-media-nodes-iterator.php 0000755 00000000156 14720415745 0024414 0 ustar 00 <?php interface IWPML_PB_Media_Nodes_Iterator { public function translate( $data, $lang, $source_lang ); } wpml-page-builders/classes/Shared/Config/Hooks.php 0000755 00000002125 14720415745 0016124 0 ustar 00 <?php namespace WPML\PB\Config; use function WPML\FP\tap as tap; class Hooks implements \IWPML_Action { const PRIORITY_AFTER_DEFAULT = 20; /** @var Parser $parser */ private $parser; /** @var Storage $storage */ private $storage; /** @var string $translatableWidgetsHook */ private $translatableWidgetsHook; public function __construct( Parser $parser, Storage $storage, $translatableWidgetsHook ) { $this->parser = $parser; $this->storage = $storage; $this->translatableWidgetsHook = $translatableWidgetsHook; } public function add_hooks() { add_filter( 'wpml_config_array', tap( [ $this, 'extractConfig' ] ) ); add_filter( $this->translatableWidgetsHook , [ $this, 'extendTranslatableWidgets' ], self::PRIORITY_AFTER_DEFAULT ); } public function extractConfig( array $allConfig ) { $this->storage->update( $this->parser->extract( $allConfig ) ); } /** * @param array $widgets * * @return array */ public function extendTranslatableWidgets( array $widgets ) { return array_merge( $widgets, $this->storage->get() ); } } wpml-page-builders/classes/Shared/Config/Factory.php 0000755 00000001164 14720415745 0016452 0 ustar 00 <?php namespace WPML\PB\Config; use WPML\WP\OptionManager; abstract class Factory implements \IWPML_Backend_Action_Loader, \IWPML_Frontend_Action_Loader { /** * @return \IWPML_Action * @throws \Auryn\InjectionException */ public function create() { return new Hooks( new Parser( $this->getPbData( 'configRoot' ), $this->getPbData( 'defaultConditionKey' ) ), new Storage( new OptionManager(), $this->getPbData( 'pbKey' ) ), $this->getPbData( 'translatableWidgetsHook' ) ); } /** * @param string $key * * @return mixed */ abstract protected function getPbData( $key ); } wpml-page-builders/classes/Shared/Config/Storage.php 0000755 00000001160 14720415745 0016443 0 ustar 00 <?php namespace WPML\PB\Config; use WPML\WP\OptionManager; class Storage { const OPTION_GROUP = 'api-pb-config'; /** @var OptionManager $optionManager */ private $optionManager; /** @var string $pbKey */ private $pbKey; public function __construct( OptionManager $optionManager, $pbKey ) { $this->optionManager = $optionManager; $this->pbKey = $pbKey; } public function get() { return $this->optionManager->get( self::OPTION_GROUP, $this->pbKey, [] ); } public function update( array $pbConfig ) { $this->optionManager->set( self::OPTION_GROUP, $this->pbKey, $pbConfig, false ); } } wpml-page-builders/classes/Shared/Config/Parser.php 0000755 00000007437 14720415745 0016310 0 ustar 00 <?php namespace WPML\PB\Config; use WPML\FP\Fns; use WPML\FP\Lst; use WPML\FP\Maybe; use WPML\FP\Obj; class Parser { /** @var string $configRoot */ private $configRoot; /** @var string $defaultConditionKey */ private $defaultConditionKey; public function __construct( $configRoot, $defaultConditionKey ) { $this->configRoot = $configRoot; $this->defaultConditionKey = $defaultConditionKey; } /** * Receives a raw config array (from XML) and convert it into * a page builder configuration array. * * @see WPML_Elementor_Translatable_Nodes::get_nodes_to_translate() * * @param array $allConfig * * @return array */ public function extract( array $allConfig ) { $pbConfig = []; $allWidgets = Obj::pathOr( [], [ 'wpml-config', $this->configRoot, 'widget' ], $allConfig ); foreach ( $allWidgets as $widget ) { $widgetName = Obj::path( ['attr', 'name'], $widget ); $pbConfig[ $widgetName ] = [ 'conditions' => $this->parseConditions( $widget, $widgetName ), 'fields' => $this->parseFields( Obj::pathOr( [], ['fields', 'field'], $widget ) ), ]; $fieldsInItems = Obj::prop( 'fields-in-item', $widget ); if ( $fieldsInItems ) { $pbConfig[ $widgetName ]['fields_in_item'] = []; $fieldsInItems = $this->normalize( $fieldsInItems ); foreach ( $fieldsInItems as $fieldsInItem ) { $itemOf = Obj::path( [ 'attr', 'items_of' ], $fieldsInItem ); $pbConfig[ $widgetName ]['fields_in_item'][ $itemOf ] = $this->parseFields( Obj::propOr( [], 'field', $fieldsInItem ) ); } } $integrationClasses = $this->parseIntegrationClasses( $widget ); if ( $integrationClasses ) { $pbConfig[ $widgetName ]['integration-class'] = $integrationClasses; } } return $pbConfig; } /** * @param array $widget * @param string $widgetName * * @return array */ private function parseConditions( array $widget, $widgetName ) { $makePair = function( $condition ) { return [ Obj::pathOr( $this->defaultConditionKey, ['attr', 'key'], $condition ), $condition['value'] ]; }; return Maybe::fromNullable( Obj::path( ['conditions', 'condition'], $widget ) ) ->map( [ $this, 'normalize' ] ) ->map( Fns::map( $makePair ) ) ->map( Lst::fromPairs() ) ->getOrElse( [ $this->defaultConditionKey => $widgetName ] ); } /** * @param array $rawFields * * @return array */ private function parseFields( array $rawFields ) { $parsedFields = []; foreach ( $this->normalize( $rawFields ) as $field ) { $key = Obj::path( [ 'attr', 'key_of' ], $field ); $fieldId = Obj::path( [ 'attr', 'field_id' ], $field ); $parsedField = [ 'field' => $field['value'], 'type' => Obj::pathOr( $field['value'], [ 'attr', 'type' ], $field ), 'editor_type' => Obj::pathOr( 'LINE', [ 'attr', 'editor_type' ], $field ), ]; if ( $fieldId ) { $parsedField['field_id'] = $fieldId; } if ( $key ) { $parsedFields[ $key ] = $parsedField; } else { $parsedFields[] = $parsedField; } } return $parsedFields; } /** * @param array $widget * * @return array */ private function parseIntegrationClasses( array $widget ) { return Maybe::fromNullable( Obj::path( [ 'integration-classes', 'integration-class' ], $widget ) ) ->map( [ $this, 'normalize' ] ) ->map( Lst::pluck( 'value' ) ) ->getOrElse( [] ); } /** * If a sequence has only one element, we will wrap it * in order to have the same data shape as for multiple elements. * * @param array $partialConfig * * @return array */ public function normalize( array $partialConfig ) { $isAssocArray = count( array_filter( array_keys( $partialConfig ), 'is_string' ) ) > 0; return $isAssocArray ? [ $partialConfig ] : $partialConfig; } } wpml-page-builders/classes/Shared/Helper/LanguageNegotiation.php 0000755 00000002077 14720415745 0021005 0 ustar 00 <?php namespace WPML\PB\Helper; class LanguageNegotiation { /** * @return bool */ public static function isUsingDomains() { return apply_filters( 'wpml_setting', [], 'language_domains' ) && constant( 'WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN' ) === (int) apply_filters( 'wpml_setting', 1, 'language_negotiation_type' ); } /** * @param string $languageCode Language code. * * @retun string|null */ public static function getDomainByLanguage( $languageCode ) { return wpml_collect( self::getMappedDomains() )->first( function( $domain, $code ) use ( $languageCode ) { return $languageCode === $code; } ); } /** * @return array */ private static function getMappedDomains() { $defaultLanguage = apply_filters( 'wpml_default_language', null ); $homeUrl = apply_filters( 'wpml_permalink', get_home_url(), $defaultLanguage ); $defaultDomain = wp_parse_url( $homeUrl, PHP_URL_HOST ); $domains = apply_filters( 'wpml_setting', [], 'language_domains' ); $domains[ $defaultLanguage ] = $defaultDomain; return $domains; } } wpml-page-builders/classes/Shared/GutenbergCleanup/ShortcodeHooks.php 0000755 00000003215 14720415745 0022025 0 ustar 00 <?php namespace WPML\PB\GutenbergCleanup; use WPML\FP\Fns; use WPML\FP\Maybe; use WPML\FP\Obj; use WPML\LIB\WP\Gutenberg; use function WPML\FP\partialRight; use function WPML\FP\pipe; use function WPML\FP\tap as tap; class ShortcodeHooks implements \IWPML_Backend_Action { public function add_hooks() { add_action( 'wp_insert_post', Fns::withoutRecursion( Fns::noop(), [ $this, 'removeGutenbergFootprint' ] ), 10, 2 ); } /** * @param int $post_ID * @param \WP_Post|mixed $post */ public function removeGutenbergFootprint( $post_ID, $post ) { // $isWpPost :: mixed -> bool (wpmlcore-8575) $isWpPost = partialRight( 'is_a', \WP_Post::class ); // $isBuiltWithShortcodes :: \WP_Post -> bool $isBuiltWithShortcodes = function( \WP_Post $post ) { /** * @since WPML 4.4.9 * * @param bool false * @param \WP_Post $post */ return apply_filters( 'wpml_pb_is_post_built_with_shortcodes', false, $post ); }; // $hasGutenbergMetaData :: \WP_Post -> bool $hasGutenbergMetaData = pipe( Obj::prop( 'post_content' ), Gutenberg::hasBlock() ); // $removeHtmlComments :: \WP_Post -> \WP_Post $removeHtmlComments = tap( pipe( Obj::over( Obj::lensProp( 'post_content' ), Gutenberg::stripBlockData() ), 'wp_update_post' ) ); // $deleteGutenbergPackage :: \WP_Post -> void $deleteGutenbergPackage = pipe( Obj::prop( 'ID' ), [ Package::class, 'get' ], [ Package::class, 'delete' ] ); Maybe::of( $post ) ->filter( $isWpPost ) ->filter( $isBuiltWithShortcodes ) ->filter( $hasGutenbergMetaData ) ->map( $removeHtmlComments ) ->map( $deleteGutenbergPackage ); } } wpml-page-builders/classes/Shared/GutenbergCleanup/Package.php 0000755 00000001166 14720415745 0020425 0 ustar 00 <?php namespace WPML\PB\GutenbergCleanup; use WPML\FP\Relation; class Package { /** * @param int $postId * * @return \WPML_Package|null */ public static function get( $postId ) { // $isGbPackage :: \WPML_Package -> bool $isGbPackage = Relation::propEq( 'kind_slug', 'gutenberg' ); return wpml_collect( apply_filters( 'wpml_st_get_post_string_packages', [], $postId ) ) ->filter( $isGbPackage ) ->first(); } /** * @param \WPML_Package|null $package */ public static function delete( $package ) { if ( $package ) { do_action( 'wpml_delete_package', $package->name, $package->kind ); } } } wpml-page-builders/license.txt 0000755 00000104513 14720415745 0012447 0 ustar 00 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: <program> Copyright (C) <year> <name of author> This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>. wpml-page-builders/plugin.php 0000755 00000000432 14720415745 0012266 0 ustar 00 <?php /** * Plugin Name: WPML Page Builders * Description: Add full WPML support for most popular page builders. * Author: OnTheGoSystems * Author URI: http://www.onthegosystems.com * Version: 2.2.1 * Plugin Slug: wpml-page-builders */ require_once __DIR__ . '/loader.php'; wpml-page-builders/loader.php 0000755 00000002265 14720415745 0012244 0 ustar 00 <?php /** * WPML Page Builders can be installed as a standalone glue plugin, * but it also comes packaged with WPML Core. * * To include it on WPML Core, do as follows: * - Include this repository as a Composer dependency. * - Wait until plugins_loaded to include this loader.php file. * * This will ensure that the glue plugin can be used if available; * otherwise, this will ensure that the WPML plugin packing the newest version will push it. * * $wpml_page_builders_version must be increased on every new version of the glue plugin. * Also, having a negative priority ensures that the highest version number gets called first. */ /** * WARNING: INCREASE THIS LOADER VERSION ON EVERY NEW RELEASE. */ $wpml_page_builders_version = 23; add_action( 'init', function() use ( $wpml_page_builders_version ) { if ( defined( 'WPML_PAGE_BUILDERS_LOADED' ) ) { // A more recent version of WPML Page Builders is already active. return; } // Define WPML_PAGE_BUILDERS_LOADED so any older instance of WPML Page Builders is not loaded. define( 'WPML_PAGE_BUILDERS_LOADED', $wpml_page_builders_version ); require_once __DIR__ . '/app.php'; }, 1 - $wpml_page_builders_version ); wpml-page-builders/app.php 0000755 00000001314 14720415745 0011550 0 ustar 00 <?php if ( ! defined( 'WPML_PAGE_BUILDERS_LOADED' ) ) { throw new Exception( 'This file should be called from the loader only.' ); } require_once __DIR__ . '/classes/OldPlugin.php'; if ( WPML\PB\OldPlugin::handle() ) { return; } define( 'WPML_PAGE_BUILDERS_VERSION', '2.2.1' ); define( 'WPML_PAGE_BUILDERS_PATH', __DIR__ ); if ( ! class_exists( 'WPML_Core_Version_Check' ) ) { require_once WPML_PAGE_BUILDERS_PATH . '/vendor/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-core-version-check.php'; } if ( ! WPML_Core_Version_Check::is_ok( WPML_PAGE_BUILDERS_PATH . '/wpml-dependencies.json' ) ) { return; } require_once WPML_PAGE_BUILDERS_PATH . '/vendor/autoload.php'; \WPML\PB\App::run(); vendor/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-dependencies.php 0000755 00000027025 14720415745 0030532 0 ustar 00 wpml-page-builders <?php /* Module Name: WPML Dependency Check Module Description: This is not a plugin! This module must be included in other plugins (WPML and add-ons) to handle compatibility checks Author: OnTheGoSystems Author URI: http://www.onthegosystems.com/ Version: 2.1 */ /** @noinspection PhpUndefinedClassInspection */ class WPML_Dependencies { protected static $instance; private $admin_notice; private $current_product; private $current_version = array(); private $expected_versions = array(); private $installed_plugins = array(); private $invalid_plugins = array(); private $valid_plugins = array(); private $validation_results = array(); public $data_key = 'wpml_dependencies:'; public $needs_validation_key = 'wpml_dependencies:needs_validation'; private function __construct() { if ( null === self::$instance ) { $this->remove_old_admin_notices(); $this->init_hooks(); } } private function collect_data() { $active_plugins = wp_get_active_and_valid_plugins(); $this->init_bundle( $active_plugins ); foreach ( $active_plugins as $plugin ) { $this->add_installed_plugin( $plugin ); } } protected function remove_old_admin_notices() { if ( class_exists( 'WPML_Bundle_Check' ) ) { global $WPML_Bundle_Check; remove_action( 'admin_notices', array( $WPML_Bundle_Check, 'admin_notices_action' ) ); } } private function init_hooks() { add_action( 'init', array( $this, 'init_plugins_action' ) ); add_action( 'extra_plugin_headers', array( $this, 'extra_plugin_headers_action' ) ); add_action( 'admin_notices', array( $this, 'admin_notices_action' ) ); add_action( 'activated_plugin', array( $this, 'activated_plugin_action' ) ); add_action( 'deactivated_plugin', array( $this, 'deactivated_plugin_action' ) ); add_action( 'upgrader_process_complete', array( $this, 'upgrader_process_complete_action' ), 10, 2 ); add_action( 'load-plugins.php', array( $this, 'run_validation_on_plugins_page' ) ); } public function run_validation_on_plugins_page() { $this->reset_validation(); } public function activated_plugin_action() { $this->reset_validation(); } public function deactivated_plugin_action() { $this->reset_validation(); } public function upgrader_process_complete_action( $upgrader_object, $options ) { if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) { $this->reset_validation(); } } private function reset_validation() { update_option( $this->needs_validation_key, true ); $this->validate_plugins(); } private function flag_as_validated() { update_option( $this->needs_validation_key, false ); } private function needs_validation() { return get_option( $this->needs_validation_key ); } public function admin_notices_action() { $this->maybe_init_admin_notice(); if ( $this->admin_notice && ( is_admin() && ! $this->is_doing_ajax_cron_or_xmlrpc() ) ) { echo $this->admin_notice; } } private function is_doing_ajax_cron_or_xmlrpc() { return ( $this->is_doing_ajax() || $this->is_doing_cron() || $this->is_doing_xmlrpc() ); } private function is_doing_ajax() { return ( defined( 'DOING_AJAX' ) && DOING_AJAX ); } private function is_doing_cron() { return ( defined( 'DOING_CRON' ) && DOING_CRON ); } private function is_doing_xmlrpc() { return ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ); } public function extra_plugin_headers_action( array $extra_headers = array() ) { $new_extra_header = array( 'PluginSlug' => 'Plugin Slug', ); return array_merge( $new_extra_header, (array) $extra_headers ); } /** * @return WPML_Dependencies */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new WPML_Dependencies(); } return self::$instance; } public function get_plugins() { return $this->installed_plugins; } public function init_plugins_action() { if ( $this->needs_validation() && is_admin() && ! $this->is_doing_ajax_cron_or_xmlrpc() ) { $this->init_plugins(); $this->validate_plugins(); $this->flag_as_validated(); } } private function init_plugins() { if ( ! $this->installed_plugins ) { if ( ! function_exists( 'get_plugin_data' ) ) { /** @noinspection PhpIncludeInspection */ include_once ABSPATH . '/wp-admin/includes/plugin.php'; } if ( function_exists( 'get_plugin_data' ) ) { $this->collect_data(); } } update_option( $this->data_key . 'installed_plugins', $this->installed_plugins ); } private function init_bundle( array $active_plugins ) { foreach ( $active_plugins as $plugin_file ) { $filename = dirname( $plugin_file ) . '/wpml-dependencies.json'; if ( file_exists( $filename ) ) { $data = file_get_contents( $filename ); $bundle = json_decode( $data, true ); $this->set_expected_versions( $bundle ); } } } private function add_installed_plugin( $plugin ) { $data = get_plugin_data( $plugin ); $plugin_dir = realpath( dirname( $plugin ) ); $wp_plugin_dir = realpath( WP_PLUGIN_DIR ) . DIRECTORY_SEPARATOR; if ( false !== $plugin_dir && $wp_plugin_dir !== $plugin_dir ) { $plugin_folder = str_replace( $wp_plugin_dir, '', $plugin_dir ); $plugin_slug = $this->guess_plugin_slug( $data, $plugin_folder ); if ( $this->is_valid_plugin( $plugin_slug ) ) { $this->installed_plugins[ $plugin_slug ] = $data['Version']; } } } private function set_expected_versions( array $bundle ) { foreach ( $bundle as $plugin => $version ) { if ( ! array_key_exists( $plugin, $this->expected_versions ) ) { $this->expected_versions[ $plugin ] = $version; } else { if ( version_compare( $this->expected_versions[ $plugin ], $version, '<' ) ) { $this->expected_versions[ $plugin ] = $version; } } } } private function guess_plugin_slug( $plugin_data, $plugin_folder ) { $plugin_slug = null; $plugin_slug = $plugin_folder; if ( array_key_exists( 'Plugin Slug', $plugin_data ) && $plugin_data['Plugin Slug'] ) { $plugin_slug = $plugin_data['Plugin Slug']; } return $plugin_slug; } private function validate_plugins() { $validation_results = $this->get_plugins_validation(); $this->valid_plugins = array(); $this->invalid_plugins = array(); foreach ( $validation_results as $plugin => $validation_result ) { if ( true === $validation_result ) { $this->valid_plugins[] = $plugin; } else { $this->invalid_plugins[] = $plugin; } } update_option( $this->data_key . 'valid_plugins', $this->valid_plugins ); update_option( $this->data_key . 'invalid_plugins', $this->invalid_plugins ); update_option( $this->data_key . 'expected_versions', $this->expected_versions ); } public function get_plugins_validation() { foreach ( $this->installed_plugins as $plugin => $version ) { $this->current_product = $plugin; if ( $this->is_valid_plugin() ) { $this->current_version = $version; $validation_result = $this->is_plugin_version_valid(); $this->validation_results[ $plugin ] = $validation_result; } } return $this->validation_results; } private function is_valid_plugin( $product = false ) { $result = false; if ( ! $product ) { $product = $this->current_product; } if ( $product ) { $versions = $this->get_expected_versions(); $result = array_key_exists( $product, $versions ); } return $result; } public function is_plugin_version_valid() { $expected_version = $this->filter_version( $this->get_expected_product_version() ); return $expected_version ? version_compare( $this->filter_version( $this->current_version ), $expected_version, '>=' ) : null; } private function filter_version( $version ) { return preg_replace( '#[^\d.].*#', '', $version ); } public function get_expected_versions() { return $this->expected_versions; } private function get_expected_product_version( $product = false ) { $result = null; if ( ! $product ) { $product = $this->current_product; } if ( $product ) { $versions = $this->get_expected_versions(); $result = isset( $versions[ $product ] ) ? $versions[ $product ] : null; } return $result; } private function maybe_init_admin_notice() { $this->admin_notice = null; $this->installed_plugins = get_option( $this->data_key . 'installed_plugins', [] ); $this->invalid_plugins = get_option( $this->data_key . 'invalid_plugins', [] ); $this->expected_versions = get_option( $this->data_key . 'expected_versions', [] ); $this->valid_plugins = get_option( $this->data_key . 'valid_plugins', [] ); if ( $this->has_invalid_plugins() ) { $notice_paragraphs = array(); $notice_paragraphs[] = $this->get_invalid_plugins_report_header(); $notice_paragraphs[] = $this->get_invalid_plugins_report_list(); $notice_paragraphs[] = $this->get_invalid_plugins_report_footer(); $this->admin_notice = '<div class="error wpml-admin-notice">'; $this->admin_notice .= '<h3>' . __( 'WPML Update is Incomplete', 'sitepress' ) . '</h3>'; $this->admin_notice .= '<p>' . implode( '</p><p>', $notice_paragraphs ) . '</p>'; $this->admin_notice .= '</div>'; } } public function has_invalid_plugins() { return count( $this->invalid_plugins ); } private function get_invalid_plugins_report_header() { if ( $this->has_valid_plugins() ) { if ( count( $this->valid_plugins ) === 1 ) { $paragraph = __( 'You are running updated %s, but the following component is not updated:', 'sitepress' ); $paragraph = sprintf( $paragraph, '<strong>' . $this->valid_plugins[0] . '</strong>' ); } else { $paragraph = __( 'You are running updated %s and %s, but the following components are not updated:', 'sitepress' ); $first_valid_plugins = implode( ', ', array_slice( $this->valid_plugins, 0, - 1 ) ); $last_valid_plugin = array_slice( $this->valid_plugins, - 1 ); $paragraph = sprintf( $paragraph, '<strong>' . $first_valid_plugins . '</strong>', '<strong>' . $last_valid_plugin[0] . '</strong>' ); } } else { $paragraph = __( 'The following components are not updated:', 'sitepress' ); } return $paragraph; } private function get_invalid_plugins_report_list() { /* translators: %s: Version number */ $required_version = __( 'required version: %s', 'sitepress' ); $invalid_plugins_list = '<ul class="ul-disc">'; foreach ( $this->invalid_plugins as $invalid_plugin ) { $plugin_name_html = '<li data-installed-version="' . $this->installed_plugins[ $invalid_plugin ] . '">'; $required_version_string = ''; if ( isset( $this->expected_versions[ $invalid_plugin ] ) ) { $required_version_string = ' (' . sprintf( $required_version, $this->expected_versions[ $invalid_plugin ] ) . ')'; } $plugin_name_html .= $invalid_plugin . $required_version_string; $plugin_name_html .= '</li>'; $invalid_plugins_list .= $plugin_name_html; } $invalid_plugins_list .= '</ul>'; return $invalid_plugins_list; } private function get_invalid_plugins_report_footer() { $wpml_org_url = '<a href="https://wpml.org/account/" title="WPML.org account">' . __( 'WPML.org account', 'sitepress' ) . '</a>'; $notice_paragraph = __( 'Your site will not work as it should in this configuration', 'sitepress' ); $notice_paragraph .= ' '; $notice_paragraph .= __( 'Please update all components which you are using.', 'sitepress' ); $notice_paragraph .= ' '; $notice_paragraph .= sprintf( __( 'For WPML components you can receive updates from your %s or automatically, after you register WPML.', 'sitepress' ), $wpml_org_url ); return $notice_paragraph; } private function has_valid_plugins() { return $this->valid_plugins && count( $this->valid_plugins ); } } vendor/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-core-version-check.php 0000755 00000001236 14720415745 0031566 0 ustar 00 wpml-page-builders <?php class WPML_Core_Version_Check { public static function is_ok( $package_file_path ) { $is_ok = false; /** @var array $bundle */ $bundle = json_decode( file_get_contents( $package_file_path ), true ); if ( defined( 'ICL_SITEPRESS_VERSION' ) && is_array( $bundle ) ) { $core_version_stripped = ICL_SITEPRESS_VERSION; $dev_or_beta_pos = strpos( ICL_SITEPRESS_VERSION, '-' ); if ( $dev_or_beta_pos > 0 ) { $core_version_stripped = substr( ICL_SITEPRESS_VERSION, 0, $dev_or_beta_pos ); } if ( version_compare( $core_version_stripped, $bundle['sitepress-multilingual-cms'], '>=' ) ) { $is_ok = true; } } return $is_ok; } } vendor/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-php-version-check.php 0000755 00000004772 14720415745 0031435 0 ustar 00 wpml-page-builders <?php /** * WPML_PHP_Version_Check class file. * * @package WPML\LibDependencies */ if ( ! class_exists( 'WPML_PHP_Version_Check' ) ) { /** * Class WPML_PHP_Version_Check */ class WPML_PHP_Version_Check { /** * Required php version. * * @var string */ private $required_php_version; /** * Plugin name. * * @var string */ private $plugin_name; /** * Plugin file. * * @var string */ private $plugin_file; /** * Text domain. * * @var string */ private $text_domain; /** * WPML_PHP_Version_Check constructor. * * @param string $required_version Required php version. * @param string $plugin_name Plugin name. * @param string $plugin_file Plugin file. * @param string $text_domain Text domain. */ public function __construct( $required_version, $plugin_name, $plugin_file, $text_domain ) { $this->required_php_version = $required_version; $this->plugin_name = $plugin_name; $this->plugin_file = $plugin_file; $this->text_domain = $text_domain; } /** * Check php version. * * @return bool */ public function is_ok() { if ( version_compare( $this->required_php_version, phpversion(), '>' ) ) { add_action( 'admin_notices', array( $this, 'php_requirement_message' ) ); return false; } return true; } /** * Show notice with php requirement. */ public function php_requirement_message() { load_plugin_textdomain( $this->text_domain, false, dirname( plugin_basename( $this->plugin_file ) ) . '/locale' ); $errata_page_link = 'https://wpml.org/errata/parse-error-syntax-error-unexpected-t_class-and-other-errors-when-using-php-versions-older-than-5-6/'; // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralDomain /* translators: 1: Current PHP version number, 2: Plugin version, 3: Minimum required PHP version number */ $message = sprintf( __( 'Your server is running PHP version %1$s but %2$s requires at least %3$s.', $this->text_domain ), phpversion(), $this->plugin_name, $this->required_php_version ); $message .= '<br>'; /* translators: Link to errata page */ $message .= sprintf( __( 'You can find version of the plugin suitable for your environment <a href="%s">here</a>.', $this->text_domain ), $errata_page_link ); // phpcs:enable WordPress.WP.I18n.NonSingularStringLiteralDomain ?> <div class="message error"> <p> <?php echo wp_kses_post( $message ); ?> </p> </div> <?php } } } wpml-page-builders/vendor/composer/platform_check.php 0000755 00000001635 14720415745 0017103 0 ustar 00 <?php // platform_check.php @generated by Composer $issues = array(); if (!(PHP_VERSION_ID >= 50600)) { $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running ' . PHP_VERSION . '.'; } if ($issues) { if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } if (!ini_get('display_errors')) { if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); } elseif (!headers_sent()) { echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; } } trigger_error( 'Composer detected issues in your platform: ' . implode(' ', $issues), E_USER_ERROR ); } wpml-page-builders/vendor/composer/autoload_files.php 0000755 00000000374 14720415745 0017113 0 ustar 00 <?php // autoload_files.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( 'b45b351e6b6f7487d819961fef2fda77' => $vendorDir . '/jakeasmith/http_build_url/src/http_build_url.php', ); wpml-page-builders/vendor/composer/autoload_real.php 0000755 00000005105 14720415745 0016731 0 ustar 00 <?php // autoload_real.php @generated by Composer class ComposerAutoloaderInit6db28b495b608840254527e283111ebb { private static $loader; public static function loadClassLoader($class) { if ('Composer\Autoload\ClassLoader' === $class) { require __DIR__ . '/ClassLoader.php'; } } /** * @return \Composer\Autoload\ClassLoader */ public static function getLoader() { if (null !== self::$loader) { return self::$loader; } require __DIR__ . '/platform_check.php'; spl_autoload_register(array('ComposerAutoloaderInit6db28b495b608840254527e283111ebb', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); spl_autoload_unregister(array('ComposerAutoloaderInit6db28b495b608840254527e283111ebb', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; call_user_func(\Composer\Autoload\ComposerStaticInit6db28b495b608840254527e283111ebb::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { $loader->set($namespace, $path); } $map = require __DIR__ . '/autoload_psr4.php'; foreach ($map as $namespace => $path) { $loader->setPsr4($namespace, $path); } $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { $loader->addClassMap($classMap); } } $loader->register(true); if ($useStaticLoader) { $includeFiles = Composer\Autoload\ComposerStaticInit6db28b495b608840254527e283111ebb::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { composerRequire6db28b495b608840254527e283111ebb($fileIdentifier, $file); } return $loader; } } /** * @param string $fileIdentifier * @param string $file * @return void */ function composerRequire6db28b495b608840254527e283111ebb($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; require $file; } } wpml-page-builders/vendor/composer/autoload_static.php 0000755 00000123337 14720415745 0017305 0 ustar 00 <?php // autoload_static.php @generated by Composer namespace Composer\Autoload; class ComposerStaticInit6db28b495b608840254527e283111ebb { public static $files = array ( 'b45b351e6b6f7487d819961fef2fda77' => __DIR__ . '/..' . '/jakeasmith/http_build_url/src/http_build_url.php', ); public static $classMap = array ( 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 'IWPML_PB_Media_Nodes_Iterator' => __DIR__ . '/../..' . '/classes/Shared/media/interface-iwpml-pb-media-nodes-iterator.php', 'IWPML_PB_Media_Update' => __DIR__ . '/../..' . '/classes/Shared/media/interface-iwpml-pb-media-update.php', 'IWPML_PB_Media_Update_Factory' => __DIR__ . '/../..' . '/classes/Shared/media/interface-iwpml-pb-media-update-factory.php', 'IWPML_PB_Strategy' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/interface-iwpml-pb-strategy.php', 'IWPML_Page_Builders_Data_Settings' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/interface-iwpml-page-builders-data-settings.php', 'IWPML_Page_Builders_Module' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/interface-iwpml-page-builders-module.php', 'IWPML_Page_Builders_Translatable_Nodes' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/interface-iwpml-page-builders-translatable-nodes.php', 'WPML\\Compatibility\\BaseDynamicContent' => __DIR__ . '/../..' . '/classes/Shared/Abstracts/BaseDynamicContent.php', 'WPML\\Compatibility\\Divi\\Builder' => __DIR__ . '/../..' . '/classes/Integrations/Divi/builder.php', 'WPML\\Compatibility\\Divi\\DisplayConditions' => __DIR__ . '/../..' . '/classes/Integrations/Divi/DisplayConditions.php', 'WPML\\Compatibility\\Divi\\DiviOptionsEncoding' => __DIR__ . '/../..' . '/classes/Integrations/Divi/divi-options-encoding.php', 'WPML\\Compatibility\\Divi\\DoubleQuotes' => __DIR__ . '/../..' . '/classes/Integrations/Divi/DoubleQuotes.php', 'WPML\\Compatibility\\Divi\\DynamicContent' => __DIR__ . '/../..' . '/classes/Integrations/Divi/dynamic-content.php', 'WPML\\Compatibility\\Divi\\Hooks\\DomainsBackendEditor' => __DIR__ . '/../..' . '/classes/Integrations/Divi/Hooks/DomainsBackendEditor.php', 'WPML\\Compatibility\\Divi\\Hooks\\Editor' => __DIR__ . '/../..' . '/classes/Integrations/Divi/Hooks/Editor.php', 'WPML\\Compatibility\\Divi\\Hooks\\GutenbergUpdate' => __DIR__ . '/../..' . '/classes/Integrations/Divi/Hooks/GutenbergUpdate.php', 'WPML\\Compatibility\\Divi\\Search' => __DIR__ . '/../..' . '/classes/Integrations/Divi/search.php', 'WPML\\Compatibility\\Divi\\ThemeBuilder' => __DIR__ . '/../..' . '/classes/Integrations/Divi/theme-builder.php', 'WPML\\Compatibility\\Divi\\ThemeBuilderFactory' => __DIR__ . '/../..' . '/classes/Integrations/Divi/theme-builder-factory.php', 'WPML\\Compatibility\\Divi\\TinyMCE' => __DIR__ . '/../..' . '/classes/Integrations/Divi/TinyMCE.php', 'WPML\\Compatibility\\Divi\\WooShortcodes' => __DIR__ . '/../..' . '/classes/Integrations/Divi/WooShortcodes.php', 'WPML\\Compatibility\\FusionBuilder\\Backend\\Hooks' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/backend/Hooks.php', 'WPML\\Compatibility\\FusionBuilder\\BaseHooks' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/abstracts/BaseHooks.php', 'WPML\\Compatibility\\FusionBuilder\\DynamicContent' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/DynamicContent.php', 'WPML\\Compatibility\\FusionBuilder\\FormContent' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/FormContent.php', 'WPML\\Compatibility\\FusionBuilder\\Frontend\\Hooks' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/frontend/Hooks.php', 'WPML\\Compatibility\\FusionBuilder\\Hooks\\Editor' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/Hooks/Editor.php', 'WPML\\Compatibility\\WPBakery\\Styles' => __DIR__ . '/../..' . '/classes/Integrations/WPBakery/Styles.php', 'WPML\\PB\\App' => __DIR__ . '/../..' . '/classes/App.php', 'WPML\\PB\\AutoUpdate\\Hooks' => __DIR__ . '/../..' . '/classes/Shared/AutoUpdate/Hooks.php', 'WPML\\PB\\AutoUpdate\\Settings' => __DIR__ . '/../..' . '/classes/Shared/AutoUpdate/Settings.php', 'WPML\\PB\\AutoUpdate\\TranslationStatus' => __DIR__ . '/../..' . '/classes/Shared/AutoUpdate/TranslationStatus.php', 'WPML\\PB\\BeaverBuilder\\BeaverThemer\\HooksFactory' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/BeaverThemer/HooksFactory.php', 'WPML\\PB\\BeaverBuilder\\BeaverThemer\\LocationHooks' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/BeaverThemer/LocationHooks.php', 'WPML\\PB\\BeaverBuilder\\Config\\Factory' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/Config/Factory.php', 'WPML\\PB\\BeaverBuilder\\Hooks\\Editor' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/Hooks/Editor.php', 'WPML\\PB\\BeaverBuilder\\Hooks\\Menu' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/Hooks/Menu.php', 'WPML\\PB\\BeaverBuilder\\Modules\\ModuleWithItemsFromConfig' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\BeaverBuilder\\TranslationJob\\Hooks' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/TranslationJob/Hooks.php', 'WPML\\PB\\Config\\Factory' => __DIR__ . '/../..' . '/classes/Shared/Config/Factory.php', 'WPML\\PB\\Config\\Hooks' => __DIR__ . '/../..' . '/classes/Shared/Config/Hooks.php', 'WPML\\PB\\Config\\Parser' => __DIR__ . '/../..' . '/classes/Shared/Config/Parser.php', 'WPML\\PB\\Config\\Storage' => __DIR__ . '/../..' . '/classes/Shared/Config/Storage.php', 'WPML\\PB\\Container\\Config' => __DIR__ . '/../..' . '/classes/Shared/Container/Config.php', 'WPML\\PB\\ConvertIds\\Helper' => __DIR__ . '/../..' . '/classes/Shared/ConvertIds/Helper.php', 'WPML\\PB\\Cornerstone\\Config\\Factory' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/Config/Factory.php', 'WPML\\PB\\Cornerstone\\Hooks\\Editor' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/Hooks/Editor.php', 'WPML\\PB\\Cornerstone\\Hooks\\Media' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/Hooks/Media.php', 'WPML\\PB\\Cornerstone\\Hooks\\ShortcodeAttributes' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/Hooks/ShortcodeAttributes.php', 'WPML\\PB\\Cornerstone\\Modules\\ModuleWithItemsFromConfig' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\Cornerstone\\Styles\\Hooks' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/Styles/Hooks.php', 'WPML\\PB\\Cornerstone\\Utils' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-utils.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Button' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/Button.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\EssentialAddons\\ContentTimeline' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/EssentialAddons/ContentTimeline.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\FormPopup' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/FormPopup.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Hotspot' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/Hotspot.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\IconList' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/IconList.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\LoopCarousel' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/LoopCarousel.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\LoopGrid' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/LoopGrid.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\MegaMenu' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/MegaMenu.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Popup' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/Popup.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Provider' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/Provider.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\WooProduct' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/DynamicElements/WooProduct.php', 'WPML\\PB\\Elementor\\Config\\Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Config/Factory.php', 'WPML\\PB\\Elementor\\DataConvert' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/DataConvert.php', 'WPML\\PB\\Elementor\\DynamicContent\\Field' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/DynamicContent/Field.php', 'WPML\\PB\\Elementor\\DynamicContent\\Strings' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/DynamicContent/Strings.php', 'WPML\\PB\\Elementor\\Helper\\Node' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Helper/Node.php', 'WPML\\PB\\Elementor\\Helper\\StringFormat' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Helper/StringFormat.php', 'WPML\\PB\\Elementor\\Hooks\\CssCache' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/CssCache.php', 'WPML\\PB\\Elementor\\Hooks\\DomainsWithMultisite' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/DomainsWithMultisite.php', 'WPML\\PB\\Elementor\\Hooks\\DynamicElements' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/DynamicElements.php', 'WPML\\PB\\Elementor\\Hooks\\Editor' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/Editor.php', 'WPML\\PB\\Elementor\\Hooks\\FormPopup' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/FormPopup.php', 'WPML\\PB\\Elementor\\Hooks\\Frontend' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/Frontend.php', 'WPML\\PB\\Elementor\\Hooks\\GutenbergCleanup' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/GutenbergCleanup.php', 'WPML\\PB\\Elementor\\Hooks\\LandingPages' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/LandingPages.php', 'WPML\\PB\\Elementor\\Hooks\\Templates' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/Templates.php', 'WPML\\PB\\Elementor\\Hooks\\WooCommerce' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/WooCommerce.php', 'WPML\\PB\\Elementor\\Hooks\\WordPressWidgets' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/Hooks/WordPressWidgets.php', 'WPML\\PB\\Elementor\\LanguageSwitcher\\LanguageSwitcher' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/LanguageSwitcher/LanguageSwitcher.php', 'WPML\\PB\\Elementor\\LanguageSwitcher\\Widget' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/LanguageSwitcher/Widget.php', 'WPML\\PB\\Elementor\\LanguageSwitcher\\WidgetAdaptor' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/LanguageSwitcher/WidgetAdaptor.php', 'WPML\\PB\\Elementor\\Media\\Modules\\AllNodes' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/AllNodes.php', 'WPML\\PB\\Elementor\\Media\\Modules\\Gallery' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/Gallery.php', 'WPML\\PB\\Elementor\\Media\\Modules\\Hotspot' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/Hotspot.php', 'WPML\\PB\\Elementor\\Media\\Modules\\Video' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/Video.php', 'WPML\\PB\\Elementor\\Media\\Modules\\VideoPlaylist' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/VideoPlaylist.php', 'WPML\\PB\\Elementor\\Modules\\Hotspot' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/Hotspot.php', 'WPML\\PB\\Elementor\\Modules\\MediaCarousel' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/MediaCarousel.php', 'WPML\\PB\\Elementor\\Modules\\ModuleWithItemsFromConfig' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\Elementor\\Modules\\MultipleGallery' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/MultipleGallery.php', 'WPML\\PB\\Elementor\\Modules\\Reviews' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/Reviews.php', 'WPML\\PB\\GutenbergCleanup\\Package' => __DIR__ . '/../..' . '/classes/Shared/GutenbergCleanup/Package.php', 'WPML\\PB\\GutenbergCleanup\\ShortcodeHooks' => __DIR__ . '/../..' . '/classes/Shared/GutenbergCleanup/ShortcodeHooks.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\Base' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/IdsInBlock/Base.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\BlockAttributes' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/IdsInBlock/BlockAttributes.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\Composite' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/IdsInBlock/Composite.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\Hooks' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/IdsInBlock/Hooks.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\TagAttributes' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/IdsInBlock/TagAttributes.php', 'WPML\\PB\\Gutenberg\\Integration' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/interface-integration.php', 'WPML\\PB\\Gutenberg\\Integration_Composite' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/class-integration-composite.php', 'WPML\\PB\\Gutenberg\\Navigation\\Frontend' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/Navigation/Frontend.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\AdminIntegration' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-admin-integration.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Basket' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/Basket.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\BasketElement' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-basket-element.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Blocks' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-blocks.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Integration' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-integration.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\JobFactory' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/JobFactory.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\JobLinks' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-job-links.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Manage' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-manage.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\ManageBasket' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-manage-basket.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\ManageBatch' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-manage-batch.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Notice' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-notice.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Translation' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/reusable-blocks/class-translation.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\Attributes' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/class-attributes.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\Base' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/class-base.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\Collection' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/class-collection.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\DOMHandle' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/dom-handle.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\HtmlBlock' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/html-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\ListBlock' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/list-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\ListItemBlock' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/list-item-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\StandardBlock' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/standard-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\HTML' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/class-html.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\StringsInBlock' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/strings-in-block/interface-strings-in-block.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\DisplayTranslation' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/Widgets/Block/DisplayTranslation.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\RegisterStrings' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/Widgets/Block/RegisterStrings.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\Search' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/Widgets/Block/Search.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\Strings' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/Widgets/Block/Strings.php', 'WPML\\PB\\Gutenberg\\XPath' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/XPath.php', 'WPML\\PB\\Helper\\LanguageNegotiation' => __DIR__ . '/../..' . '/classes/Shared/Helper/LanguageNegotiation.php', 'WPML\\PB\\LegacyIntegration' => __DIR__ . '/../..' . '/classes/LegacyIntegration.php', 'WPML\\PB\\OldPlugin' => __DIR__ . '/../..' . '/classes/OldPlugin.php', 'WPML\\PB\\ShortCodesInGutenbergBlocks' => __DIR__ . '/../..' . '/classes/Shared/st/ShortCodesInGutenbergBlocks.php', 'WPML\\PB\\Shortcode\\AdjustIdsHooks' => __DIR__ . '/../..' . '/classes/Shared/Shortcode/AdjustIdsHooks.php', 'WPML\\PB\\Shortcode\\StringCleanUp' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/StringCleanUp.php', 'WPML\\PB\\Shutdown\\Hooks' => __DIR__ . '/../..' . '/classes/Shared/Shutdown/Hooks.php', 'WPML\\PB\\SiteOrigin\\Config\\Factory' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/Config/Factory.php', 'WPML\\PB\\SiteOrigin\\DataSettings' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/DataSettings.php', 'WPML\\PB\\SiteOrigin\\Factory' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/Factory.php', 'WPML\\PB\\SiteOrigin\\HandleCustomFieldsFactory' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/HandleCustomFieldsFactory.php', 'WPML\\PB\\SiteOrigin\\Modules\\ModuleWithItems' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/Modules/ModuleWithItems.php', 'WPML\\PB\\SiteOrigin\\Modules\\ModuleWithItemsFromConfig' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/Modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\SiteOrigin\\RegisterStrings' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/RegisterStrings.php', 'WPML\\PB\\SiteOrigin\\TranslatableNodes' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/TranslatableNodes.php', 'WPML\\PB\\SiteOrigin\\UpdateTranslation' => __DIR__ . '/../..' . '/classes/Integrations/SiteOrigin/UpdateTranslation.php', 'WPML\\PB\\TranslateLinks' => __DIR__ . '/../..' . '/classes/Shared/st/TranslateLinks.php', 'WPML_Beaver_Builder_Accordion' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-accordion.php', 'WPML_Beaver_Builder_Content_Slider' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-content-slider.php', 'WPML_Beaver_Builder_Data_Settings' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-data-settings.php', 'WPML_Beaver_Builder_Data_Settings_For_Media' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-data-settings-for-media.php', 'WPML_Beaver_Builder_Icon_Group' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-icon-group.php', 'WPML_Beaver_Builder_Integration_Factory' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-integration-factory.php', 'WPML_Beaver_Builder_Media_Hooks_Factory' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-hooks-factory.php', 'WPML_Beaver_Builder_Media_Node' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node.php', 'WPML_Beaver_Builder_Media_Node_Content_Slider' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-content-slider.php', 'WPML_Beaver_Builder_Media_Node_Gallery' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-gallery.php', 'WPML_Beaver_Builder_Media_Node_Photo' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-photo.php', 'WPML_Beaver_Builder_Media_Node_Provider' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-node-provider.php', 'WPML_Beaver_Builder_Media_Node_Slideshow' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-slideshow.php', 'WPML_Beaver_Builder_Media_Nodes_Iterator' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-nodes-iterator.php', 'WPML_Beaver_Builder_Module_With_Items' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-module-with-items.php', 'WPML_Beaver_Builder_Pricing_Table' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-pricing-table.php', 'WPML_Beaver_Builder_Register_Strings' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-register-strings.php', 'WPML_Beaver_Builder_Tab' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-tab.php', 'WPML_Beaver_Builder_Testimonials' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-testimonials.php', 'WPML_Beaver_Builder_Translatable_Nodes' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-translatable-nodes.php', 'WPML_Beaver_Builder_Update_Media_Factory' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-update-media-factory.php', 'WPML_Beaver_Builder_Update_Translation' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-update-translation.php', 'WPML_Compatibility_Divi' => __DIR__ . '/../..' . '/classes/Integrations/Divi/class-wpml-compatibility-divi.php', 'WPML_Compatibility_Divi_Notice' => __DIR__ . '/../..' . '/classes/Integrations/Divi/class-wpml-compatiblity-divi-notice.php', 'WPML_Compatibility_Plugin_Fusion_Global_Element_Hooks' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/wpml-compatibility-plugin-fusion-global-element-hooks.php', 'WPML_Compatibility_Plugin_Fusion_Hooks_Factory' => __DIR__ . '/../..' . '/classes/Integrations/FusionBuilder/wpml-compatibility-plugin-fusion-hooks-factory.php', 'WPML_Compatibility_Plugin_Visual_Composer' => __DIR__ . '/../..' . '/classes/Integrations/WPBakery/class-wpml-compatibility-plugin-visual-composer.php', 'WPML_Compatibility_Plugin_Visual_Composer_Grid_Hooks' => __DIR__ . '/../..' . '/classes/Integrations/WPBakery/class-wpml-compatibility-plugin-visual-composer-grid-hooks.php', 'WPML_Compatibility_Theme_Enfold' => __DIR__ . '/../..' . '/classes/Integrations/Enfold/class-wpml-compatibility-theme-enfold.php', 'WPML_Core_Version_Check' => __DIR__ . '/..' . '/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-core-version-check.php', 'WPML_Cornerstone_Accordion' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-accordion.php', 'WPML_Cornerstone_Data_Settings' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-data-settings.php', 'WPML_Cornerstone_Integration_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-integration-factory.php', 'WPML_Cornerstone_Media_Hooks_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-hooks-factory.php', 'WPML_Cornerstone_Media_Node' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/abstract/class-wpml-cornerstone-media-node.php', 'WPML_Cornerstone_Media_Node_Classic_Card' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-card.php', 'WPML_Cornerstone_Media_Node_Classic_Creative_CTA' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-creative-cta.php', 'WPML_Cornerstone_Media_Node_Classic_Feature_Box' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-feature-box.php', 'WPML_Cornerstone_Media_Node_Classic_Image' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-image.php', 'WPML_Cornerstone_Media_Node_Classic_Promo' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-promo.php', 'WPML_Cornerstone_Media_Node_Image' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-image.php', 'WPML_Cornerstone_Media_Node_Provider' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-node-provider.php', 'WPML_Cornerstone_Media_Node_With_URLs' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/modules/abstract/class-wpml-cornerstone-media-node-with-urls.php', 'WPML_Cornerstone_Media_Nodes_Iterator' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-nodes-iterator.php', 'WPML_Cornerstone_Module_With_Items' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-module-with-items.php', 'WPML_Cornerstone_Register_Strings' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-register-strings.php', 'WPML_Cornerstone_Tabs' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-tabs.php', 'WPML_Cornerstone_Translatable_Nodes' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-translatable-nodes.php', 'WPML_Cornerstone_Update_Media_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-update-media-factory.php', 'WPML_Cornerstone_Update_Translation' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-update-translation.php', 'WPML_Dependencies' => __DIR__ . '/..' . '/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-dependencies.php', 'WPML_Elementor_Accordion' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-accordion.php', 'WPML_Elementor_Adjust_Global_Widget_ID' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-adjust-global-widget-id.php', 'WPML_Elementor_Adjust_Global_Widget_ID_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-adjust-global-widget-id-factory.php', 'WPML_Elementor_DB' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-db.php', 'WPML_Elementor_DB_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-db-factory.php', 'WPML_Elementor_Data_Settings' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-data-settings.php', 'WPML_Elementor_Form' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-form.php', 'WPML_Elementor_Icon_List' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-icon-list.php', 'WPML_Elementor_Integration_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-integration-factory.php', 'WPML_Elementor_Media_Hooks_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/class-wpml-elementor-media-hooks-factory.php', 'WPML_Elementor_Media_Node' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node.php', 'WPML_Elementor_Media_Node_Call_To_Action' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-call-to-action.php', 'WPML_Elementor_Media_Node_Image' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image.php', 'WPML_Elementor_Media_Node_Image_Box' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-box.php', 'WPML_Elementor_Media_Node_Image_Carousel' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-carousel.php', 'WPML_Elementor_Media_Node_Image_Gallery' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-gallery.php', 'WPML_Elementor_Media_Node_Media_Carousel' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-media-carousel.php', 'WPML_Elementor_Media_Node_Provider' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/class-wpml-elementor-media-node-provider.php', 'WPML_Elementor_Media_Node_Slides' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-slides.php', 'WPML_Elementor_Media_Node_WP_Widget_Media_Gallery' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-wp-widget-media-gallery.php', 'WPML_Elementor_Media_Node_WP_Widget_Media_Image' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-wp-widget-media-image.php', 'WPML_Elementor_Media_Node_With_Image_Property' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-image-property.php', 'WPML_Elementor_Media_Node_With_Images_Property' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-images-property.php', 'WPML_Elementor_Media_Node_With_Slides' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-slides.php', 'WPML_Elementor_Media_Nodes_Iterator' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/class-wpml-elementor-media-nodes-iterator.php', 'WPML_Elementor_Module_With_Items' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-module-with-items.php', 'WPML_Elementor_Price_List' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-price-list.php', 'WPML_Elementor_Price_Table' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-price-table.php', 'WPML_Elementor_Register_Strings' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-register-strings.php', 'WPML_Elementor_Slides' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-slides.php', 'WPML_Elementor_Tabs' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-tabs.php', 'WPML_Elementor_Testimonial_Carousel' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-testimonial-carousel.php', 'WPML_Elementor_Toggle' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/modules/class-wpml-elementor-toggle.php', 'WPML_Elementor_Translatable_Nodes' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-translatable-nodes.php', 'WPML_Elementor_Translate_IDs' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-translate-ids.php', 'WPML_Elementor_Translate_IDs_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-translate-ids-factory.php', 'WPML_Elementor_URLs' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-urls.php', 'WPML_Elementor_URLs_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-urls-factory.php', 'WPML_Elementor_Update_Media_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/media/class-wpml-elementor-update-media-factory.php', 'WPML_Elementor_Update_Translation' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-update-translation.php', 'WPML_Elementor_WooCommerce_Hooks' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-woocommerce-hooks.php', 'WPML_Elementor_WooCommerce_Hooks_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-woocommerce-hooks-factory.php', 'WPML_Gutenberg_Config_Option' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-config-option.php', 'WPML_Gutenberg_Integration' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-integration.php', 'WPML_Gutenberg_Integration_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-integration-factory.php', 'WPML_Gutenberg_Strings_Registration' => __DIR__ . '/../..' . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-strings-registration.php', 'WPML_PB_API_Hooks_Strategy' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/api-hooks/class-wpml-pb-api-hooks-strategy.php', 'WPML_PB_Beaver_Builder_Handle_Custom_Fields_Factory' => __DIR__ . '/../..' . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-handle-custom-fields-factory.php', 'WPML_PB_Config_Import_Shortcode' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-config-import-shortcode.php', 'WPML_PB_Cornerstone_Handle_Custom_Fields_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-handle-custom-fields-factory.php', 'WPML_PB_Elementor_Handle_Custom_Fields_Factory' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-elementor-pb-handle-custom-fields-factory.php', 'WPML_PB_Factory' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-factory.php', 'WPML_PB_Fix_Maintenance_Query' => __DIR__ . '/../..' . '/classes/Integrations/Elementor/class-wpml-pb-fix-maintenance-query.php', 'WPML_PB_Handle_Custom_Fields' => __DIR__ . '/../..' . '/classes/Shared/tm/class-wpml-pb-handle-custom-fields.php', 'WPML_PB_Handle_Post_Body' => __DIR__ . '/../..' . '/classes/Shared/tm/class-wpml-pb-handle-post-body.php', 'WPML_PB_Integration' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-integration.php', 'WPML_PB_Integration_Rescan' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-rescan.php', 'WPML_PB_Last_Translation_Edit_Mode' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-last-translation-edit-mode.php', 'WPML_PB_Loader' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-loader.php', 'WPML_PB_Package_Strings_Resave' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-package-strings-resave.php', 'WPML_PB_Register_Shortcodes' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-register-shortcodes.php', 'WPML_PB_Reuse_Translations' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-reuse-translations.php', 'WPML_PB_Reuse_Translations_By_Strategy' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-reuse-translations-by-strategy.php', 'WPML_PB_Shortcode_Content_Wrapper' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-content-wrapper.php', 'WPML_PB_Shortcode_Encoding' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-encoding.php', 'WPML_PB_Shortcode_Strategy' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-strategy.php', 'WPML_PB_Shortcodes' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcodes.php', 'WPML_PB_String' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-string.php', 'WPML_PB_String_Registration' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-string-registration.php', 'WPML_PB_String_Translation' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-string-translation.php', 'WPML_PB_String_Translation_By_Strategy' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-string-translation-by-strategy.php', 'WPML_PB_Update_API_Hooks_In_Content' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/api-hooks/class-wpml-pb-update-api-hooks-in-content.php', 'WPML_PB_Update_Post' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-pb-update-post.php', 'WPML_PB_Update_Shortcodes_In_Content' => __DIR__ . '/../..' . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-update-shortcodes-in-content.php', 'WPML_PHP_Version_Check' => __DIR__ . '/..' . '/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-php-version-check.php', 'WPML_Page_Builders_App' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-page-builders-app.php', 'WPML_Page_Builders_Defined' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/class-wpml-page-builders-defined.php', 'WPML_Page_Builders_Integration' => __DIR__ . '/../..' . '/classes/Shared/st/class-page-builder-integration.php', 'WPML_Page_Builders_Media_Hooks' => __DIR__ . '/../..' . '/classes/Shared/media/class-wpml-page-builders-media-hooks.php', 'WPML_Page_Builders_Media_Shortcodes' => __DIR__ . '/../..' . '/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes.php', 'WPML_Page_Builders_Media_Shortcodes_Update' => __DIR__ . '/../..' . '/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes-update.php', 'WPML_Page_Builders_Media_Shortcodes_Update_Factory' => __DIR__ . '/../..' . '/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes-update-factory.php', 'WPML_Page_Builders_Media_Translate' => __DIR__ . '/../..' . '/classes/Shared/media/class-wpml-page-builders-media-translate.php', 'WPML_Page_Builders_Media_Usage' => __DIR__ . '/../..' . '/classes/Shared/media/class-wpml-page-builders-media-usage.php', 'WPML_Page_Builders_Page_Built' => __DIR__ . '/../..' . '/classes/Shared/utilities/class-wpml-page-builders-page-built-with-built.php', 'WPML_Page_Builders_Register_Strings' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/class-wpml-page-builders-register-strings.php', 'WPML_Page_Builders_Update' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/class-wpml-page-builders-update.php', 'WPML_Page_Builders_Update_Media' => __DIR__ . '/../..' . '/classes/Shared/media/class-wpml-page-builders-update-media.php', 'WPML_Page_Builders_Update_Translation' => __DIR__ . '/../..' . '/classes/Shared/st/compatibility/class-wpml-page-builders-update-translation.php', 'WPML_ST_Diff' => __DIR__ . '/../..' . '/classes/Shared/utilities/class-wpml-st-diff.php', 'WPML_ST_PB_Plugin' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-st-pb-plugin.php', 'WPML_String_Registration_Factory' => __DIR__ . '/../..' . '/classes/Shared/st/class-wpml-string-registration-factory.php', 'WPML_TM_Page_Builders' => __DIR__ . '/../..' . '/classes/Shared/tm/class-wpml-tm-page-builders.php', 'WPML_TM_Page_Builders_Field_Wrapper' => __DIR__ . '/../..' . '/classes/Shared/tm/class-wpml-tm-page-builders-field-wrapper.php', 'WPML_TM_Page_Builders_Hooks' => __DIR__ . '/../..' . '/classes/Shared/tm/class-wpml-tm-page-builders-hooks.php', ); public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { $loader->classMap = ComposerStaticInit6db28b495b608840254527e283111ebb::$classMap; }, null, ClassLoader::class); } } wpml-page-builders/vendor/composer/autoload_namespaces.php 0000755 00000000225 14720415745 0020123 0 ustar 00 <?php // autoload_namespaces.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( ); wpml-page-builders/vendor/composer/ClassLoader.php 0000755 00000037304 14720415745 0016320 0 ustar 00 <?php /* * This file is part of Composer. * * (c) Nils Adermann <naderman@naderman.de> * Jordi Boggiano <j.boggiano@seld.be> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Autoload; /** * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. * * $loader = new \Composer\Autoload\ClassLoader(); * * // register classes with namespaces * $loader->add('Symfony\Component', __DIR__.'/component'); * $loader->add('Symfony', __DIR__.'/framework'); * * // activate the autoloader * $loader->register(); * * // to enable searching the include path (eg. for PEAR packages) * $loader->setUseIncludePath(true); * * In this example, if you try to use a class in the Symfony\Component * namespace or one of its children (Symfony\Component\Console for instance), * the autoloader will first look for the class under the component/ * directory, and it will then fallback to the framework/ directory if not * found before giving up. * * This class is loosely based on the Symfony UniversalClassLoader. * * @author Fabien Potencier <fabien@symfony.com> * @author Jordi Boggiano <j.boggiano@seld.be> * @see https://www.php-fig.org/psr/psr-0/ * @see https://www.php-fig.org/psr/psr-4/ */ class ClassLoader { /** @var ?string */ private $vendorDir; // PSR-4 /** * @var array[] * @psalm-var array<string, array<string, int>> */ private $prefixLengthsPsr4 = array(); /** * @var array[] * @psalm-var array<string, array<int, string>> */ private $prefixDirsPsr4 = array(); /** * @var array[] * @psalm-var array<string, string> */ private $fallbackDirsPsr4 = array(); // PSR-0 /** * @var array[] * @psalm-var array<string, array<string, string[]>> */ private $prefixesPsr0 = array(); /** * @var array[] * @psalm-var array<string, string> */ private $fallbackDirsPsr0 = array(); /** @var bool */ private $useIncludePath = false; /** * @var string[] * @psalm-var array<string, string> */ private $classMap = array(); /** @var bool */ private $classMapAuthoritative = false; /** * @var bool[] * @psalm-var array<string, bool> */ private $missingClasses = array(); /** @var ?string */ private $apcuPrefix; /** * @var self[] */ private static $registeredLoaders = array(); /** * @param ?string $vendorDir */ public function __construct($vendorDir = null) { $this->vendorDir = $vendorDir; } /** * @return string[] */ public function getPrefixes() { if (!empty($this->prefixesPsr0)) { return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); } return array(); } /** * @return array[] * @psalm-return array<string, array<int, string>> */ public function getPrefixesPsr4() { return $this->prefixDirsPsr4; } /** * @return array[] * @psalm-return array<string, string> */ public function getFallbackDirs() { return $this->fallbackDirsPsr0; } /** * @return array[] * @psalm-return array<string, string> */ public function getFallbackDirsPsr4() { return $this->fallbackDirsPsr4; } /** * @return string[] Array of classname => path * @psalm-return array<string, string> */ public function getClassMap() { return $this->classMap; } /** * @param string[] $classMap Class to filename map * @psalm-param array<string, string> $classMap * * @return void */ public function addClassMap(array $classMap) { if ($this->classMap) { $this->classMap = array_merge($this->classMap, $classMap); } else { $this->classMap = $classMap; } } /** * Registers a set of PSR-0 directories for a given prefix, either * appending or prepending to the ones previously set for this prefix. * * @param string $prefix The prefix * @param string[]|string $paths The PSR-0 root directories * @param bool $prepend Whether to prepend the directories * * @return void */ public function add($prefix, $paths, $prepend = false) { if (!$prefix) { if ($prepend) { $this->fallbackDirsPsr0 = array_merge( (array) $paths, $this->fallbackDirsPsr0 ); } else { $this->fallbackDirsPsr0 = array_merge( $this->fallbackDirsPsr0, (array) $paths ); } return; } $first = $prefix[0]; if (!isset($this->prefixesPsr0[$first][$prefix])) { $this->prefixesPsr0[$first][$prefix] = (array) $paths; return; } if ($prepend) { $this->prefixesPsr0[$first][$prefix] = array_merge( (array) $paths, $this->prefixesPsr0[$first][$prefix] ); } else { $this->prefixesPsr0[$first][$prefix] = array_merge( $this->prefixesPsr0[$first][$prefix], (array) $paths ); } } /** * Registers a set of PSR-4 directories for a given namespace, either * appending or prepending to the ones previously set for this namespace. * * @param string $prefix The prefix/namespace, with trailing '\\' * @param string[]|string $paths The PSR-4 base directories * @param bool $prepend Whether to prepend the directories * * @throws \InvalidArgumentException * * @return void */ public function addPsr4($prefix, $paths, $prepend = false) { if (!$prefix) { // Register directories for the root namespace. if ($prepend) { $this->fallbackDirsPsr4 = array_merge( (array) $paths, $this->fallbackDirsPsr4 ); } else { $this->fallbackDirsPsr4 = array_merge( $this->fallbackDirsPsr4, (array) $paths ); } } elseif (!isset($this->prefixDirsPsr4[$prefix])) { // Register directories for a new namespace. $length = strlen($prefix); if ('\\' !== $prefix[$length - 1]) { throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; $this->prefixDirsPsr4[$prefix] = (array) $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( (array) $paths, $this->prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( $this->prefixDirsPsr4[$prefix], (array) $paths ); } } /** * Registers a set of PSR-0 directories for a given prefix, * replacing any others previously set for this prefix. * * @param string $prefix The prefix * @param string[]|string $paths The PSR-0 base directories * * @return void */ public function set($prefix, $paths) { if (!$prefix) { $this->fallbackDirsPsr0 = (array) $paths; } else { $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; } } /** * Registers a set of PSR-4 directories for a given namespace, * replacing any others previously set for this namespace. * * @param string $prefix The prefix/namespace, with trailing '\\' * @param string[]|string $paths The PSR-4 base directories * * @throws \InvalidArgumentException * * @return void */ public function setPsr4($prefix, $paths) { if (!$prefix) { $this->fallbackDirsPsr4 = (array) $paths; } else { $length = strlen($prefix); if ('\\' !== $prefix[$length - 1]) { throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; $this->prefixDirsPsr4[$prefix] = (array) $paths; } } /** * Turns on searching the include path for class files. * * @param bool $useIncludePath * * @return void */ public function setUseIncludePath($useIncludePath) { $this->useIncludePath = $useIncludePath; } /** * Can be used to check if the autoloader uses the include path to check * for classes. * * @return bool */ public function getUseIncludePath() { return $this->useIncludePath; } /** * Turns off searching the prefix and fallback directories for classes * that have not been registered with the class map. * * @param bool $classMapAuthoritative * * @return void */ public function setClassMapAuthoritative($classMapAuthoritative) { $this->classMapAuthoritative = $classMapAuthoritative; } /** * Should class lookup fail if not found in the current class map? * * @return bool */ public function isClassMapAuthoritative() { return $this->classMapAuthoritative; } /** * APCu prefix to use to cache found/not-found classes, if the extension is enabled. * * @param string|null $apcuPrefix * * @return void */ public function setApcuPrefix($apcuPrefix) { $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; } /** * The APCu prefix in use, or null if APCu caching is not enabled. * * @return string|null */ public function getApcuPrefix() { return $this->apcuPrefix; } /** * Registers this instance as an autoloader. * * @param bool $prepend Whether to prepend the autoloader or not * * @return void */ public function register($prepend = false) { spl_autoload_register(array($this, 'loadClass'), true, $prepend); if (null === $this->vendorDir) { return; } if ($prepend) { self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; } else { unset(self::$registeredLoaders[$this->vendorDir]); self::$registeredLoaders[$this->vendorDir] = $this; } } /** * Unregisters this instance as an autoloader. * * @return void */ public function unregister() { spl_autoload_unregister(array($this, 'loadClass')); if (null !== $this->vendorDir) { unset(self::$registeredLoaders[$this->vendorDir]); } } /** * Loads the given class or interface. * * @param string $class The name of the class * @return true|null True if loaded, null otherwise */ public function loadClass($class) { if ($file = $this->findFile($class)) { includeFile($file); return true; } return null; } /** * Finds the path to the file where the class is defined. * * @param string $class The name of the class * * @return string|false The path if found, false otherwise */ public function findFile($class) { // class map lookup if (isset($this->classMap[$class])) { return $this->classMap[$class]; } if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { return false; } if (null !== $this->apcuPrefix) { $file = apcu_fetch($this->apcuPrefix.$class, $hit); if ($hit) { return $file; } } $file = $this->findFileWithExtension($class, '.php'); // Search for Hack files if we are running on HHVM if (false === $file && defined('HHVM_VERSION')) { $file = $this->findFileWithExtension($class, '.hh'); } if (null !== $this->apcuPrefix) { apcu_add($this->apcuPrefix.$class, $file); } if (false === $file) { // Remember that this class does not exist. $this->missingClasses[$class] = true; } return $file; } /** * Returns the currently registered loaders indexed by their corresponding vendor directories. * * @return self[] */ public static function getRegisteredLoaders() { return self::$registeredLoaders; } /** * @param string $class * @param string $ext * @return string|false */ private function findFileWithExtension($class, $ext) { // PSR-4 lookup $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; $first = $class[0]; if (isset($this->prefixLengthsPsr4[$first])) { $subPath = $class; while (false !== $lastPos = strrpos($subPath, '\\')) { $subPath = substr($subPath, 0, $lastPos); $search = $subPath . '\\'; if (isset($this->prefixDirsPsr4[$search])) { $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); foreach ($this->prefixDirsPsr4[$search] as $dir) { if (file_exists($file = $dir . $pathEnd)) { return $file; } } } } } // PSR-4 fallback dirs foreach ($this->fallbackDirsPsr4 as $dir) { if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { return $file; } } // PSR-0 lookup if (false !== $pos = strrpos($class, '\\')) { // namespaced class name $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); } else { // PEAR-like class name $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; } if (isset($this->prefixesPsr0[$first])) { foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { if (0 === strpos($class, $prefix)) { foreach ($dirs as $dir) { if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { return $file; } } } } } // PSR-0 fallback dirs foreach ($this->fallbackDirsPsr0 as $dir) { if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { return $file; } } // PSR-0 include paths. if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { return $file; } return false; } } /** * Scope isolated include. * * Prevents access to $this/self from included files. * * @param string $file * @return void * @private */ function includeFile($file) { include $file; } wpml-page-builders/vendor/composer/LICENSE 0000755 00000002056 14720415745 0014414 0 ustar 00 Copyright (c) Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wpml-page-builders/vendor/composer/autoload_psr4.php 0000755 00000000217 14720415745 0016675 0 ustar 00 <?php // autoload_psr4.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( ); wpml-page-builders/vendor/composer/installed.php 0000755 00000003027 14720415745 0016076 0 ustar 00 <?php return array( 'root' => array( 'pretty_version' => '2.2.1', 'version' => '2.2.1.0', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'reference' => 'bb82b9de521a0be7492823797404e053721cb00d', 'name' => 'wpml/wpml-page-builders', 'dev' => false, ), 'versions' => array( 'jakeasmith/http_build_url' => array( 'pretty_version' => '1.0.1', 'version' => '1.0.1.0', 'type' => 'library', 'install_path' => __DIR__ . '/../jakeasmith/http_build_url', 'aliases' => array(), 'reference' => '93c273e77cb1edead0cf8bcf8cd2003428e74e37', 'dev_requirement' => false, ), 'wpml-shared/wpml-lib-dependencies' => array( 'pretty_version' => '0.1.6', 'version' => '0.1.6.0', 'type' => 'library', 'install_path' => __DIR__ . '/../wpml-shared/wpml-lib-dependencies', 'aliases' => array(), 'reference' => '723824a61bfec7dd535afcd7260fad50d8bfe6e8', 'dev_requirement' => false, ), 'wpml/wpml-page-builders' => array( 'pretty_version' => '2.2.1', 'version' => '2.2.1.0', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'reference' => 'bb82b9de521a0be7492823797404e053721cb00d', 'dev_requirement' => false, ), ), ); wpml-page-builders/vendor/composer/autoload_classmap.php 0000755 00000112410 14720415745 0017607 0 ustar 00 <?php // autoload_classmap.php @generated by Composer $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 'IWPML_PB_Media_Nodes_Iterator' => $baseDir . '/classes/Shared/media/interface-iwpml-pb-media-nodes-iterator.php', 'IWPML_PB_Media_Update' => $baseDir . '/classes/Shared/media/interface-iwpml-pb-media-update.php', 'IWPML_PB_Media_Update_Factory' => $baseDir . '/classes/Shared/media/interface-iwpml-pb-media-update-factory.php', 'IWPML_PB_Strategy' => $baseDir . '/classes/Shared/st/strategy/interface-iwpml-pb-strategy.php', 'IWPML_Page_Builders_Data_Settings' => $baseDir . '/classes/Shared/st/compatibility/interface-iwpml-page-builders-data-settings.php', 'IWPML_Page_Builders_Module' => $baseDir . '/classes/Shared/st/compatibility/interface-iwpml-page-builders-module.php', 'IWPML_Page_Builders_Translatable_Nodes' => $baseDir . '/classes/Shared/st/compatibility/interface-iwpml-page-builders-translatable-nodes.php', 'WPML\\Compatibility\\BaseDynamicContent' => $baseDir . '/classes/Shared/Abstracts/BaseDynamicContent.php', 'WPML\\Compatibility\\Divi\\Builder' => $baseDir . '/classes/Integrations/Divi/builder.php', 'WPML\\Compatibility\\Divi\\DisplayConditions' => $baseDir . '/classes/Integrations/Divi/DisplayConditions.php', 'WPML\\Compatibility\\Divi\\DiviOptionsEncoding' => $baseDir . '/classes/Integrations/Divi/divi-options-encoding.php', 'WPML\\Compatibility\\Divi\\DoubleQuotes' => $baseDir . '/classes/Integrations/Divi/DoubleQuotes.php', 'WPML\\Compatibility\\Divi\\DynamicContent' => $baseDir . '/classes/Integrations/Divi/dynamic-content.php', 'WPML\\Compatibility\\Divi\\Hooks\\DomainsBackendEditor' => $baseDir . '/classes/Integrations/Divi/Hooks/DomainsBackendEditor.php', 'WPML\\Compatibility\\Divi\\Hooks\\Editor' => $baseDir . '/classes/Integrations/Divi/Hooks/Editor.php', 'WPML\\Compatibility\\Divi\\Hooks\\GutenbergUpdate' => $baseDir . '/classes/Integrations/Divi/Hooks/GutenbergUpdate.php', 'WPML\\Compatibility\\Divi\\Search' => $baseDir . '/classes/Integrations/Divi/search.php', 'WPML\\Compatibility\\Divi\\ThemeBuilder' => $baseDir . '/classes/Integrations/Divi/theme-builder.php', 'WPML\\Compatibility\\Divi\\ThemeBuilderFactory' => $baseDir . '/classes/Integrations/Divi/theme-builder-factory.php', 'WPML\\Compatibility\\Divi\\TinyMCE' => $baseDir . '/classes/Integrations/Divi/TinyMCE.php', 'WPML\\Compatibility\\Divi\\WooShortcodes' => $baseDir . '/classes/Integrations/Divi/WooShortcodes.php', 'WPML\\Compatibility\\FusionBuilder\\Backend\\Hooks' => $baseDir . '/classes/Integrations/FusionBuilder/backend/Hooks.php', 'WPML\\Compatibility\\FusionBuilder\\BaseHooks' => $baseDir . '/classes/Integrations/FusionBuilder/abstracts/BaseHooks.php', 'WPML\\Compatibility\\FusionBuilder\\DynamicContent' => $baseDir . '/classes/Integrations/FusionBuilder/DynamicContent.php', 'WPML\\Compatibility\\FusionBuilder\\FormContent' => $baseDir . '/classes/Integrations/FusionBuilder/FormContent.php', 'WPML\\Compatibility\\FusionBuilder\\Frontend\\Hooks' => $baseDir . '/classes/Integrations/FusionBuilder/frontend/Hooks.php', 'WPML\\Compatibility\\FusionBuilder\\Hooks\\Editor' => $baseDir . '/classes/Integrations/FusionBuilder/Hooks/Editor.php', 'WPML\\Compatibility\\WPBakery\\Styles' => $baseDir . '/classes/Integrations/WPBakery/Styles.php', 'WPML\\PB\\App' => $baseDir . '/classes/App.php', 'WPML\\PB\\AutoUpdate\\Hooks' => $baseDir . '/classes/Shared/AutoUpdate/Hooks.php', 'WPML\\PB\\AutoUpdate\\Settings' => $baseDir . '/classes/Shared/AutoUpdate/Settings.php', 'WPML\\PB\\AutoUpdate\\TranslationStatus' => $baseDir . '/classes/Shared/AutoUpdate/TranslationStatus.php', 'WPML\\PB\\BeaverBuilder\\BeaverThemer\\HooksFactory' => $baseDir . '/classes/Integrations/BeaverBuilder/BeaverThemer/HooksFactory.php', 'WPML\\PB\\BeaverBuilder\\BeaverThemer\\LocationHooks' => $baseDir . '/classes/Integrations/BeaverBuilder/BeaverThemer/LocationHooks.php', 'WPML\\PB\\BeaverBuilder\\Config\\Factory' => $baseDir . '/classes/Integrations/BeaverBuilder/Config/Factory.php', 'WPML\\PB\\BeaverBuilder\\Hooks\\Editor' => $baseDir . '/classes/Integrations/BeaverBuilder/Hooks/Editor.php', 'WPML\\PB\\BeaverBuilder\\Hooks\\Menu' => $baseDir . '/classes/Integrations/BeaverBuilder/Hooks/Menu.php', 'WPML\\PB\\BeaverBuilder\\Modules\\ModuleWithItemsFromConfig' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\BeaverBuilder\\TranslationJob\\Hooks' => $baseDir . '/classes/Integrations/BeaverBuilder/TranslationJob/Hooks.php', 'WPML\\PB\\Config\\Factory' => $baseDir . '/classes/Shared/Config/Factory.php', 'WPML\\PB\\Config\\Hooks' => $baseDir . '/classes/Shared/Config/Hooks.php', 'WPML\\PB\\Config\\Parser' => $baseDir . '/classes/Shared/Config/Parser.php', 'WPML\\PB\\Config\\Storage' => $baseDir . '/classes/Shared/Config/Storage.php', 'WPML\\PB\\Container\\Config' => $baseDir . '/classes/Shared/Container/Config.php', 'WPML\\PB\\ConvertIds\\Helper' => $baseDir . '/classes/Shared/ConvertIds/Helper.php', 'WPML\\PB\\Cornerstone\\Config\\Factory' => $baseDir . '/classes/Integrations/Cornerstone/Config/Factory.php', 'WPML\\PB\\Cornerstone\\Hooks\\Editor' => $baseDir . '/classes/Integrations/Cornerstone/Hooks/Editor.php', 'WPML\\PB\\Cornerstone\\Hooks\\Media' => $baseDir . '/classes/Integrations/Cornerstone/Hooks/Media.php', 'WPML\\PB\\Cornerstone\\Hooks\\ShortcodeAttributes' => $baseDir . '/classes/Integrations/Cornerstone/Hooks/ShortcodeAttributes.php', 'WPML\\PB\\Cornerstone\\Modules\\ModuleWithItemsFromConfig' => $baseDir . '/classes/Integrations/Cornerstone/modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\Cornerstone\\Styles\\Hooks' => $baseDir . '/classes/Integrations/Cornerstone/Styles/Hooks.php', 'WPML\\PB\\Cornerstone\\Utils' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-utils.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Button' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/Button.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\EssentialAddons\\ContentTimeline' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/EssentialAddons/ContentTimeline.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\FormPopup' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/FormPopup.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Hotspot' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/Hotspot.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\IconList' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/IconList.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\LoopCarousel' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/LoopCarousel.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\LoopGrid' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/LoopGrid.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\MegaMenu' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/MegaMenu.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Popup' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/Popup.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\Provider' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/Provider.php', 'WPML\\PB\\Elementor\\Config\\DynamicElements\\WooProduct' => $baseDir . '/classes/Integrations/Elementor/Config/DynamicElements/WooProduct.php', 'WPML\\PB\\Elementor\\Config\\Factory' => $baseDir . '/classes/Integrations/Elementor/Config/Factory.php', 'WPML\\PB\\Elementor\\DataConvert' => $baseDir . '/classes/Integrations/Elementor/DataConvert.php', 'WPML\\PB\\Elementor\\DynamicContent\\Field' => $baseDir . '/classes/Integrations/Elementor/DynamicContent/Field.php', 'WPML\\PB\\Elementor\\DynamicContent\\Strings' => $baseDir . '/classes/Integrations/Elementor/DynamicContent/Strings.php', 'WPML\\PB\\Elementor\\Helper\\Node' => $baseDir . '/classes/Integrations/Elementor/Helper/Node.php', 'WPML\\PB\\Elementor\\Helper\\StringFormat' => $baseDir . '/classes/Integrations/Elementor/Helper/StringFormat.php', 'WPML\\PB\\Elementor\\Hooks\\CssCache' => $baseDir . '/classes/Integrations/Elementor/Hooks/CssCache.php', 'WPML\\PB\\Elementor\\Hooks\\DomainsWithMultisite' => $baseDir . '/classes/Integrations/Elementor/Hooks/DomainsWithMultisite.php', 'WPML\\PB\\Elementor\\Hooks\\DynamicElements' => $baseDir . '/classes/Integrations/Elementor/Hooks/DynamicElements.php', 'WPML\\PB\\Elementor\\Hooks\\Editor' => $baseDir . '/classes/Integrations/Elementor/Hooks/Editor.php', 'WPML\\PB\\Elementor\\Hooks\\FormPopup' => $baseDir . '/classes/Integrations/Elementor/Hooks/FormPopup.php', 'WPML\\PB\\Elementor\\Hooks\\Frontend' => $baseDir . '/classes/Integrations/Elementor/Hooks/Frontend.php', 'WPML\\PB\\Elementor\\Hooks\\GutenbergCleanup' => $baseDir . '/classes/Integrations/Elementor/Hooks/GutenbergCleanup.php', 'WPML\\PB\\Elementor\\Hooks\\LandingPages' => $baseDir . '/classes/Integrations/Elementor/Hooks/LandingPages.php', 'WPML\\PB\\Elementor\\Hooks\\Templates' => $baseDir . '/classes/Integrations/Elementor/Hooks/Templates.php', 'WPML\\PB\\Elementor\\Hooks\\WooCommerce' => $baseDir . '/classes/Integrations/Elementor/Hooks/WooCommerce.php', 'WPML\\PB\\Elementor\\Hooks\\WordPressWidgets' => $baseDir . '/classes/Integrations/Elementor/Hooks/WordPressWidgets.php', 'WPML\\PB\\Elementor\\LanguageSwitcher\\LanguageSwitcher' => $baseDir . '/classes/Integrations/Elementor/LanguageSwitcher/LanguageSwitcher.php', 'WPML\\PB\\Elementor\\LanguageSwitcher\\Widget' => $baseDir . '/classes/Integrations/Elementor/LanguageSwitcher/Widget.php', 'WPML\\PB\\Elementor\\LanguageSwitcher\\WidgetAdaptor' => $baseDir . '/classes/Integrations/Elementor/LanguageSwitcher/WidgetAdaptor.php', 'WPML\\PB\\Elementor\\Media\\Modules\\AllNodes' => $baseDir . '/classes/Integrations/Elementor/media/modules/AllNodes.php', 'WPML\\PB\\Elementor\\Media\\Modules\\Gallery' => $baseDir . '/classes/Integrations/Elementor/media/modules/Gallery.php', 'WPML\\PB\\Elementor\\Media\\Modules\\Hotspot' => $baseDir . '/classes/Integrations/Elementor/media/modules/Hotspot.php', 'WPML\\PB\\Elementor\\Media\\Modules\\Video' => $baseDir . '/classes/Integrations/Elementor/media/modules/Video.php', 'WPML\\PB\\Elementor\\Media\\Modules\\VideoPlaylist' => $baseDir . '/classes/Integrations/Elementor/media/modules/VideoPlaylist.php', 'WPML\\PB\\Elementor\\Modules\\Hotspot' => $baseDir . '/classes/Integrations/Elementor/modules/Hotspot.php', 'WPML\\PB\\Elementor\\Modules\\MediaCarousel' => $baseDir . '/classes/Integrations/Elementor/modules/MediaCarousel.php', 'WPML\\PB\\Elementor\\Modules\\ModuleWithItemsFromConfig' => $baseDir . '/classes/Integrations/Elementor/modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\Elementor\\Modules\\MultipleGallery' => $baseDir . '/classes/Integrations/Elementor/modules/MultipleGallery.php', 'WPML\\PB\\Elementor\\Modules\\Reviews' => $baseDir . '/classes/Integrations/Elementor/modules/Reviews.php', 'WPML\\PB\\GutenbergCleanup\\Package' => $baseDir . '/classes/Shared/GutenbergCleanup/Package.php', 'WPML\\PB\\GutenbergCleanup\\ShortcodeHooks' => $baseDir . '/classes/Shared/GutenbergCleanup/ShortcodeHooks.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\Base' => $baseDir . '/classes/Integrations/Gutenberg/IdsInBlock/Base.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\BlockAttributes' => $baseDir . '/classes/Integrations/Gutenberg/IdsInBlock/BlockAttributes.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\Composite' => $baseDir . '/classes/Integrations/Gutenberg/IdsInBlock/Composite.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\Hooks' => $baseDir . '/classes/Integrations/Gutenberg/IdsInBlock/Hooks.php', 'WPML\\PB\\Gutenberg\\ConvertIdsInBlock\\TagAttributes' => $baseDir . '/classes/Integrations/Gutenberg/IdsInBlock/TagAttributes.php', 'WPML\\PB\\Gutenberg\\Integration' => $baseDir . '/classes/Integrations/Gutenberg/interface-integration.php', 'WPML\\PB\\Gutenberg\\Integration_Composite' => $baseDir . '/classes/Integrations/Gutenberg/class-integration-composite.php', 'WPML\\PB\\Gutenberg\\Navigation\\Frontend' => $baseDir . '/classes/Integrations/Gutenberg/Navigation/Frontend.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\AdminIntegration' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-admin-integration.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Basket' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/Basket.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\BasketElement' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-basket-element.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Blocks' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-blocks.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Integration' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-integration.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\JobFactory' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/JobFactory.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\JobLinks' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-job-links.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Manage' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-manage.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\ManageBasket' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-manage-basket.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\ManageBatch' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-manage-batch.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Notice' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-notice.php', 'WPML\\PB\\Gutenberg\\ReusableBlocks\\Translation' => $baseDir . '/classes/Integrations/Gutenberg/reusable-blocks/class-translation.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\Attributes' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/class-attributes.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\Base' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/class-base.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\Collection' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/class-collection.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\DOMHandle' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/dom-handle.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\HtmlBlock' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/html-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\ListBlock' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/list-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\ListItemBlock' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/list-item-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\DOMHandler\\StandardBlock' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/dom-handler/standard-block.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\HTML' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/class-html.php', 'WPML\\PB\\Gutenberg\\StringsInBlock\\StringsInBlock' => $baseDir . '/classes/Integrations/Gutenberg/strings-in-block/interface-strings-in-block.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\DisplayTranslation' => $baseDir . '/classes/Integrations/Gutenberg/Widgets/Block/DisplayTranslation.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\RegisterStrings' => $baseDir . '/classes/Integrations/Gutenberg/Widgets/Block/RegisterStrings.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\Search' => $baseDir . '/classes/Integrations/Gutenberg/Widgets/Block/Search.php', 'WPML\\PB\\Gutenberg\\Widgets\\Block\\Strings' => $baseDir . '/classes/Integrations/Gutenberg/Widgets/Block/Strings.php', 'WPML\\PB\\Gutenberg\\XPath' => $baseDir . '/classes/Integrations/Gutenberg/XPath.php', 'WPML\\PB\\Helper\\LanguageNegotiation' => $baseDir . '/classes/Shared/Helper/LanguageNegotiation.php', 'WPML\\PB\\LegacyIntegration' => $baseDir . '/classes/LegacyIntegration.php', 'WPML\\PB\\OldPlugin' => $baseDir . '/classes/OldPlugin.php', 'WPML\\PB\\ShortCodesInGutenbergBlocks' => $baseDir . '/classes/Shared/st/ShortCodesInGutenbergBlocks.php', 'WPML\\PB\\Shortcode\\AdjustIdsHooks' => $baseDir . '/classes/Shared/Shortcode/AdjustIdsHooks.php', 'WPML\\PB\\Shortcode\\StringCleanUp' => $baseDir . '/classes/Shared/st/strategy/shortcode/StringCleanUp.php', 'WPML\\PB\\Shutdown\\Hooks' => $baseDir . '/classes/Shared/Shutdown/Hooks.php', 'WPML\\PB\\SiteOrigin\\Config\\Factory' => $baseDir . '/classes/Integrations/SiteOrigin/Config/Factory.php', 'WPML\\PB\\SiteOrigin\\DataSettings' => $baseDir . '/classes/Integrations/SiteOrigin/DataSettings.php', 'WPML\\PB\\SiteOrigin\\Factory' => $baseDir . '/classes/Integrations/SiteOrigin/Factory.php', 'WPML\\PB\\SiteOrigin\\HandleCustomFieldsFactory' => $baseDir . '/classes/Integrations/SiteOrigin/HandleCustomFieldsFactory.php', 'WPML\\PB\\SiteOrigin\\Modules\\ModuleWithItems' => $baseDir . '/classes/Integrations/SiteOrigin/Modules/ModuleWithItems.php', 'WPML\\PB\\SiteOrigin\\Modules\\ModuleWithItemsFromConfig' => $baseDir . '/classes/Integrations/SiteOrigin/Modules/ModuleWithItemsFromConfig.php', 'WPML\\PB\\SiteOrigin\\RegisterStrings' => $baseDir . '/classes/Integrations/SiteOrigin/RegisterStrings.php', 'WPML\\PB\\SiteOrigin\\TranslatableNodes' => $baseDir . '/classes/Integrations/SiteOrigin/TranslatableNodes.php', 'WPML\\PB\\SiteOrigin\\UpdateTranslation' => $baseDir . '/classes/Integrations/SiteOrigin/UpdateTranslation.php', 'WPML\\PB\\TranslateLinks' => $baseDir . '/classes/Shared/st/TranslateLinks.php', 'WPML_Beaver_Builder_Accordion' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-accordion.php', 'WPML_Beaver_Builder_Content_Slider' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-content-slider.php', 'WPML_Beaver_Builder_Data_Settings' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-data-settings.php', 'WPML_Beaver_Builder_Data_Settings_For_Media' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-data-settings-for-media.php', 'WPML_Beaver_Builder_Icon_Group' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-icon-group.php', 'WPML_Beaver_Builder_Integration_Factory' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-integration-factory.php', 'WPML_Beaver_Builder_Media_Hooks_Factory' => $baseDir . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-hooks-factory.php', 'WPML_Beaver_Builder_Media_Node' => $baseDir . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node.php', 'WPML_Beaver_Builder_Media_Node_Content_Slider' => $baseDir . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-content-slider.php', 'WPML_Beaver_Builder_Media_Node_Gallery' => $baseDir . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-gallery.php', 'WPML_Beaver_Builder_Media_Node_Photo' => $baseDir . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-photo.php', 'WPML_Beaver_Builder_Media_Node_Provider' => $baseDir . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-node-provider.php', 'WPML_Beaver_Builder_Media_Node_Slideshow' => $baseDir . '/classes/Integrations/BeaverBuilder/media/modules/class-wpml-beaver-builder-media-node-slideshow.php', 'WPML_Beaver_Builder_Media_Nodes_Iterator' => $baseDir . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-media-nodes-iterator.php', 'WPML_Beaver_Builder_Module_With_Items' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-module-with-items.php', 'WPML_Beaver_Builder_Pricing_Table' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-pricing-table.php', 'WPML_Beaver_Builder_Register_Strings' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-register-strings.php', 'WPML_Beaver_Builder_Tab' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-tab.php', 'WPML_Beaver_Builder_Testimonials' => $baseDir . '/classes/Integrations/BeaverBuilder/modules/class-wpml-beaver-builder-testimonials.php', 'WPML_Beaver_Builder_Translatable_Nodes' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-translatable-nodes.php', 'WPML_Beaver_Builder_Update_Media_Factory' => $baseDir . '/classes/Integrations/BeaverBuilder/media/class-wpml-beaver-builder-update-media-factory.php', 'WPML_Beaver_Builder_Update_Translation' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-update-translation.php', 'WPML_Compatibility_Divi' => $baseDir . '/classes/Integrations/Divi/class-wpml-compatibility-divi.php', 'WPML_Compatibility_Divi_Notice' => $baseDir . '/classes/Integrations/Divi/class-wpml-compatiblity-divi-notice.php', 'WPML_Compatibility_Plugin_Fusion_Global_Element_Hooks' => $baseDir . '/classes/Integrations/FusionBuilder/wpml-compatibility-plugin-fusion-global-element-hooks.php', 'WPML_Compatibility_Plugin_Fusion_Hooks_Factory' => $baseDir . '/classes/Integrations/FusionBuilder/wpml-compatibility-plugin-fusion-hooks-factory.php', 'WPML_Compatibility_Plugin_Visual_Composer' => $baseDir . '/classes/Integrations/WPBakery/class-wpml-compatibility-plugin-visual-composer.php', 'WPML_Compatibility_Plugin_Visual_Composer_Grid_Hooks' => $baseDir . '/classes/Integrations/WPBakery/class-wpml-compatibility-plugin-visual-composer-grid-hooks.php', 'WPML_Compatibility_Theme_Enfold' => $baseDir . '/classes/Integrations/Enfold/class-wpml-compatibility-theme-enfold.php', 'WPML_Core_Version_Check' => $vendorDir . '/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-core-version-check.php', 'WPML_Cornerstone_Accordion' => $baseDir . '/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-accordion.php', 'WPML_Cornerstone_Data_Settings' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-data-settings.php', 'WPML_Cornerstone_Integration_Factory' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-integration-factory.php', 'WPML_Cornerstone_Media_Hooks_Factory' => $baseDir . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-hooks-factory.php', 'WPML_Cornerstone_Media_Node' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/abstract/class-wpml-cornerstone-media-node.php', 'WPML_Cornerstone_Media_Node_Classic_Card' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-card.php', 'WPML_Cornerstone_Media_Node_Classic_Creative_CTA' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-creative-cta.php', 'WPML_Cornerstone_Media_Node_Classic_Feature_Box' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-feature-box.php', 'WPML_Cornerstone_Media_Node_Classic_Image' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-image.php', 'WPML_Cornerstone_Media_Node_Classic_Promo' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-classic-promo.php', 'WPML_Cornerstone_Media_Node_Image' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/class-wpml-cornerstone-media-node-image.php', 'WPML_Cornerstone_Media_Node_Provider' => $baseDir . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-node-provider.php', 'WPML_Cornerstone_Media_Node_With_URLs' => $baseDir . '/classes/Integrations/Cornerstone/media/modules/abstract/class-wpml-cornerstone-media-node-with-urls.php', 'WPML_Cornerstone_Media_Nodes_Iterator' => $baseDir . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-media-nodes-iterator.php', 'WPML_Cornerstone_Module_With_Items' => $baseDir . '/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-module-with-items.php', 'WPML_Cornerstone_Register_Strings' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-register-strings.php', 'WPML_Cornerstone_Tabs' => $baseDir . '/classes/Integrations/Cornerstone/modules/class-wpml-cornerstone-tabs.php', 'WPML_Cornerstone_Translatable_Nodes' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-translatable-nodes.php', 'WPML_Cornerstone_Update_Media_Factory' => $baseDir . '/classes/Integrations/Cornerstone/media/class-wpml-cornerstone-update-media-factory.php', 'WPML_Cornerstone_Update_Translation' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-update-translation.php', 'WPML_Dependencies' => $vendorDir . '/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-dependencies.php', 'WPML_Elementor_Accordion' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-accordion.php', 'WPML_Elementor_Adjust_Global_Widget_ID' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-adjust-global-widget-id.php', 'WPML_Elementor_Adjust_Global_Widget_ID_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-adjust-global-widget-id-factory.php', 'WPML_Elementor_DB' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-db.php', 'WPML_Elementor_DB_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-db-factory.php', 'WPML_Elementor_Data_Settings' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-data-settings.php', 'WPML_Elementor_Form' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-form.php', 'WPML_Elementor_Icon_List' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-icon-list.php', 'WPML_Elementor_Integration_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-integration-factory.php', 'WPML_Elementor_Media_Hooks_Factory' => $baseDir . '/classes/Integrations/Elementor/media/class-wpml-elementor-media-hooks-factory.php', 'WPML_Elementor_Media_Node' => $baseDir . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node.php', 'WPML_Elementor_Media_Node_Call_To_Action' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-call-to-action.php', 'WPML_Elementor_Media_Node_Image' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image.php', 'WPML_Elementor_Media_Node_Image_Box' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-box.php', 'WPML_Elementor_Media_Node_Image_Carousel' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-carousel.php', 'WPML_Elementor_Media_Node_Image_Gallery' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-image-gallery.php', 'WPML_Elementor_Media_Node_Media_Carousel' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-media-carousel.php', 'WPML_Elementor_Media_Node_Provider' => $baseDir . '/classes/Integrations/Elementor/media/class-wpml-elementor-media-node-provider.php', 'WPML_Elementor_Media_Node_Slides' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-slides.php', 'WPML_Elementor_Media_Node_WP_Widget_Media_Gallery' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-wp-widget-media-gallery.php', 'WPML_Elementor_Media_Node_WP_Widget_Media_Image' => $baseDir . '/classes/Integrations/Elementor/media/modules/class-wpml-elementor-media-node-wp-widget-media-image.php', 'WPML_Elementor_Media_Node_With_Image_Property' => $baseDir . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-image-property.php', 'WPML_Elementor_Media_Node_With_Images_Property' => $baseDir . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-images-property.php', 'WPML_Elementor_Media_Node_With_Slides' => $baseDir . '/classes/Integrations/Elementor/media/modules/abstract/class-wpml-elementor-media-node-with-slides.php', 'WPML_Elementor_Media_Nodes_Iterator' => $baseDir . '/classes/Integrations/Elementor/media/class-wpml-elementor-media-nodes-iterator.php', 'WPML_Elementor_Module_With_Items' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-module-with-items.php', 'WPML_Elementor_Price_List' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-price-list.php', 'WPML_Elementor_Price_Table' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-price-table.php', 'WPML_Elementor_Register_Strings' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-register-strings.php', 'WPML_Elementor_Slides' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-slides.php', 'WPML_Elementor_Tabs' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-tabs.php', 'WPML_Elementor_Testimonial_Carousel' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-testimonial-carousel.php', 'WPML_Elementor_Toggle' => $baseDir . '/classes/Integrations/Elementor/modules/class-wpml-elementor-toggle.php', 'WPML_Elementor_Translatable_Nodes' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-translatable-nodes.php', 'WPML_Elementor_Translate_IDs' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-translate-ids.php', 'WPML_Elementor_Translate_IDs_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-translate-ids-factory.php', 'WPML_Elementor_URLs' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-urls.php', 'WPML_Elementor_URLs_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-urls-factory.php', 'WPML_Elementor_Update_Media_Factory' => $baseDir . '/classes/Integrations/Elementor/media/class-wpml-elementor-update-media-factory.php', 'WPML_Elementor_Update_Translation' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-update-translation.php', 'WPML_Elementor_WooCommerce_Hooks' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-woocommerce-hooks.php', 'WPML_Elementor_WooCommerce_Hooks_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-woocommerce-hooks-factory.php', 'WPML_Gutenberg_Config_Option' => $baseDir . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-config-option.php', 'WPML_Gutenberg_Integration' => $baseDir . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-integration.php', 'WPML_Gutenberg_Integration_Factory' => $baseDir . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-integration-factory.php', 'WPML_Gutenberg_Strings_Registration' => $baseDir . '/classes/Integrations/Gutenberg/class-wpml-gutenberg-strings-registration.php', 'WPML_PB_API_Hooks_Strategy' => $baseDir . '/classes/Shared/st/strategy/api-hooks/class-wpml-pb-api-hooks-strategy.php', 'WPML_PB_Beaver_Builder_Handle_Custom_Fields_Factory' => $baseDir . '/classes/Integrations/BeaverBuilder/class-wpml-beaver-builder-handle-custom-fields-factory.php', 'WPML_PB_Config_Import_Shortcode' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-config-import-shortcode.php', 'WPML_PB_Cornerstone_Handle_Custom_Fields_Factory' => $baseDir . '/classes/Integrations/Cornerstone/class-wpml-cornerstone-handle-custom-fields-factory.php', 'WPML_PB_Elementor_Handle_Custom_Fields_Factory' => $baseDir . '/classes/Integrations/Elementor/class-wpml-elementor-pb-handle-custom-fields-factory.php', 'WPML_PB_Factory' => $baseDir . '/classes/Shared/st/class-wpml-pb-factory.php', 'WPML_PB_Fix_Maintenance_Query' => $baseDir . '/classes/Integrations/Elementor/class-wpml-pb-fix-maintenance-query.php', 'WPML_PB_Handle_Custom_Fields' => $baseDir . '/classes/Shared/tm/class-wpml-pb-handle-custom-fields.php', 'WPML_PB_Handle_Post_Body' => $baseDir . '/classes/Shared/tm/class-wpml-pb-handle-post-body.php', 'WPML_PB_Integration' => $baseDir . '/classes/Shared/st/class-wpml-pb-integration.php', 'WPML_PB_Integration_Rescan' => $baseDir . '/classes/Shared/st/class-wpml-pb-rescan.php', 'WPML_PB_Last_Translation_Edit_Mode' => $baseDir . '/classes/Shared/st/class-wpml-pb-last-translation-edit-mode.php', 'WPML_PB_Loader' => $baseDir . '/classes/Shared/st/class-wpml-pb-loader.php', 'WPML_PB_Package_Strings_Resave' => $baseDir . '/classes/Shared/st/class-wpml-pb-package-strings-resave.php', 'WPML_PB_Register_Shortcodes' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-register-shortcodes.php', 'WPML_PB_Reuse_Translations' => $baseDir . '/classes/Shared/st/class-wpml-pb-reuse-translations.php', 'WPML_PB_Reuse_Translations_By_Strategy' => $baseDir . '/classes/Shared/st/class-wpml-pb-reuse-translations-by-strategy.php', 'WPML_PB_Shortcode_Content_Wrapper' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-content-wrapper.php', 'WPML_PB_Shortcode_Encoding' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-encoding.php', 'WPML_PB_Shortcode_Strategy' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcode-strategy.php', 'WPML_PB_Shortcodes' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-shortcodes.php', 'WPML_PB_String' => $baseDir . '/classes/Shared/st/class-wpml-pb-string.php', 'WPML_PB_String_Registration' => $baseDir . '/classes/Shared/st/class-wpml-pb-string-registration.php', 'WPML_PB_String_Translation' => $baseDir . '/classes/Shared/st/class-wpml-pb-string-translation.php', 'WPML_PB_String_Translation_By_Strategy' => $baseDir . '/classes/Shared/st/class-wpml-pb-string-translation-by-strategy.php', 'WPML_PB_Update_API_Hooks_In_Content' => $baseDir . '/classes/Shared/st/strategy/api-hooks/class-wpml-pb-update-api-hooks-in-content.php', 'WPML_PB_Update_Post' => $baseDir . '/classes/Shared/st/class-wpml-pb-update-post.php', 'WPML_PB_Update_Shortcodes_In_Content' => $baseDir . '/classes/Shared/st/strategy/shortcode/class-wpml-pb-update-shortcodes-in-content.php', 'WPML_PHP_Version_Check' => $vendorDir . '/wpml-shared/wpml-lib-dependencies/src/dependencies/class-wpml-php-version-check.php', 'WPML_Page_Builders_App' => $baseDir . '/classes/Shared/st/class-wpml-page-builders-app.php', 'WPML_Page_Builders_Defined' => $baseDir . '/classes/Shared/st/compatibility/class-wpml-page-builders-defined.php', 'WPML_Page_Builders_Integration' => $baseDir . '/classes/Shared/st/class-page-builder-integration.php', 'WPML_Page_Builders_Media_Hooks' => $baseDir . '/classes/Shared/media/class-wpml-page-builders-media-hooks.php', 'WPML_Page_Builders_Media_Shortcodes' => $baseDir . '/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes.php', 'WPML_Page_Builders_Media_Shortcodes_Update' => $baseDir . '/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes-update.php', 'WPML_Page_Builders_Media_Shortcodes_Update_Factory' => $baseDir . '/classes/Shared/media/shortcodes/class-wpml-page-builders-media-shortcodes-update-factory.php', 'WPML_Page_Builders_Media_Translate' => $baseDir . '/classes/Shared/media/class-wpml-page-builders-media-translate.php', 'WPML_Page_Builders_Media_Usage' => $baseDir . '/classes/Shared/media/class-wpml-page-builders-media-usage.php', 'WPML_Page_Builders_Page_Built' => $baseDir . '/classes/Shared/utilities/class-wpml-page-builders-page-built-with-built.php', 'WPML_Page_Builders_Register_Strings' => $baseDir . '/classes/Shared/st/compatibility/class-wpml-page-builders-register-strings.php', 'WPML_Page_Builders_Update' => $baseDir . '/classes/Shared/st/compatibility/class-wpml-page-builders-update.php', 'WPML_Page_Builders_Update_Media' => $baseDir . '/classes/Shared/media/class-wpml-page-builders-update-media.php', 'WPML_Page_Builders_Update_Translation' => $baseDir . '/classes/Shared/st/compatibility/class-wpml-page-builders-update-translation.php', 'WPML_ST_Diff' => $baseDir . '/classes/Shared/utilities/class-wpml-st-diff.php', 'WPML_ST_PB_Plugin' => $baseDir . '/classes/Shared/st/class-wpml-st-pb-plugin.php', 'WPML_String_Registration_Factory' => $baseDir . '/classes/Shared/st/class-wpml-string-registration-factory.php', 'WPML_TM_Page_Builders' => $baseDir . '/classes/Shared/tm/class-wpml-tm-page-builders.php', 'WPML_TM_Page_Builders_Field_Wrapper' => $baseDir . '/classes/Shared/tm/class-wpml-tm-page-builders-field-wrapper.php', 'WPML_TM_Page_Builders_Hooks' => $baseDir . '/classes/Shared/tm/class-wpml-tm-page-builders-hooks.php', ); wpml-page-builders/vendor/composer/InstalledVersions.php 0000755 00000035217 14720415745 0017575 0 ustar 00 <?php /* * This file is part of Composer. * * (c) Nils Adermann <naderman@naderman.de> * Jordi Boggiano <j.boggiano@seld.be> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer; use Composer\Autoload\ClassLoader; use Composer\Semver\VersionParser; /** * This class is copied in every Composer installed project and available to all * * See also https://getcomposer.org/doc/07-runtime.md#installed-versions * * To require its presence, you can require `composer-runtime-api ^2.0` */ class InstalledVersions { /** * @var mixed[]|null * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null */ private static $installed; /** * @var bool|null */ private static $canGetVendors; /** * @var array[] * @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}> */ private static $installedByVendor = array(); /** * Returns a list of all package names which are present, either by being installed, replaced or provided * * @return string[] * @psalm-return list<string> */ public static function getInstalledPackages() { $packages = array(); foreach (self::getInstalled() as $installed) { $packages[] = array_keys($installed['versions']); } if (1 === \count($packages)) { return $packages[0]; } return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); } /** * Returns a list of all package names with a specific type e.g. 'library' * * @param string $type * @return string[] * @psalm-return list<string> */ public static function getInstalledPackagesByType($type) { $packagesByType = array(); foreach (self::getInstalled() as $installed) { foreach ($installed['versions'] as $name => $package) { if (isset($package['type']) && $package['type'] === $type) { $packagesByType[] = $name; } } } return $packagesByType; } /** * Checks whether the given package is installed * * This also returns true if the package name is provided or replaced by another package * * @param string $packageName * @param bool $includeDevRequirements * @return bool */ public static function isInstalled($packageName, $includeDevRequirements = true) { foreach (self::getInstalled() as $installed) { if (isset($installed['versions'][$packageName])) { return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); } } return false; } /** * Checks whether the given package satisfies a version constraint * * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: * * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') * * @param VersionParser $parser Install composer/semver to have access to this class and functionality * @param string $packageName * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package * @return bool */ public static function satisfies(VersionParser $parser, $packageName, $constraint) { $constraint = $parser->parseConstraints($constraint); $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); return $provided->matches($constraint); } /** * Returns a version constraint representing all the range(s) which are installed for a given package * * It is easier to use this via isInstalled() with the $constraint argument if you need to check * whether a given version of a package is installed, and not just whether it exists * * @param string $packageName * @return string Version constraint usable with composer/semver */ public static function getVersionRanges($packageName) { foreach (self::getInstalled() as $installed) { if (!isset($installed['versions'][$packageName])) { continue; } $ranges = array(); if (isset($installed['versions'][$packageName]['pretty_version'])) { $ranges[] = $installed['versions'][$packageName]['pretty_version']; } if (array_key_exists('aliases', $installed['versions'][$packageName])) { $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); } if (array_key_exists('replaced', $installed['versions'][$packageName])) { $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); } if (array_key_exists('provided', $installed['versions'][$packageName])) { $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); } return implode(' || ', $ranges); } throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); } /** * @param string $packageName * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present */ public static function getVersion($packageName) { foreach (self::getInstalled() as $installed) { if (!isset($installed['versions'][$packageName])) { continue; } if (!isset($installed['versions'][$packageName]['version'])) { return null; } return $installed['versions'][$packageName]['version']; } throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); } /** * @param string $packageName * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present */ public static function getPrettyVersion($packageName) { foreach (self::getInstalled() as $installed) { if (!isset($installed['versions'][$packageName])) { continue; } if (!isset($installed['versions'][$packageName]['pretty_version'])) { return null; } return $installed['versions'][$packageName]['pretty_version']; } throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); } /** * @param string $packageName * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference */ public static function getReference($packageName) { foreach (self::getInstalled() as $installed) { if (!isset($installed['versions'][$packageName])) { continue; } if (!isset($installed['versions'][$packageName]['reference'])) { return null; } return $installed['versions'][$packageName]['reference']; } throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); } /** * @param string $packageName * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. */ public static function getInstallPath($packageName) { foreach (self::getInstalled() as $installed) { if (!isset($installed['versions'][$packageName])) { continue; } return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; } throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); } /** * @return array * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string} */ public static function getRootPackage() { $installed = self::getInstalled(); return $installed[0]['root']; } /** * Returns the raw installed.php data for custom implementations * * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. * @return array[] * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} */ public static function getRawData() { @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); if (null === self::$installed) { // only require the installed.php file if this file is loaded from its dumped location, // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 if (substr(__DIR__, -8, 1) !== 'C') { self::$installed = include __DIR__ . '/installed.php'; } else { self::$installed = array(); } } return self::$installed; } /** * Returns the raw data of all installed.php which are currently loaded for custom implementations * * @return array[] * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}> */ public static function getAllRawData() { return self::getInstalled(); } /** * Lets you reload the static array from another file * * This is only useful for complex integrations in which a project needs to use * this class but then also needs to execute another project's autoloader in process, * and wants to ensure both projects have access to their version of installed.php. * * A typical case would be PHPUnit, where it would need to make sure it reads all * the data it needs from this class, then call reload() with * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure * the project in which it runs can then also use this class safely, without * interference between PHPUnit's dependencies and the project's dependencies. * * @param array[] $data A vendor/composer/installed.php data set * @return void * * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data */ public static function reload($data) { self::$installed = $data; self::$installedByVendor = array(); } /** * @return array[] * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}> */ private static function getInstalled() { if (null === self::$canGetVendors) { self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); } $installed = array(); if (self::$canGetVendors) { foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { if (isset(self::$installedByVendor[$vendorDir])) { $installed[] = self::$installedByVendor[$vendorDir]; } elseif (is_file($vendorDir.'/composer/installed.php')) { $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { self::$installed = $installed[count($installed) - 1]; } } } } if (null === self::$installed) { // only require the installed.php file if this file is loaded from its dumped location, // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 if (substr(__DIR__, -8, 1) !== 'C') { self::$installed = require __DIR__ . '/installed.php'; } else { self::$installed = array(); } } $installed[] = self::$installed; return $installed; } } wpml-page-builders/vendor/autoload.php 0000755 00000000262 14720415745 0014076 0 ustar 00 <?php // autoload.php @generated by Composer require_once __DIR__ . '/composer/autoload_real.php'; return ComposerAutoloaderInit6db28b495b608840254527e283111ebb::getLoader(); wpml-page-builders/vendor/jakeasmith/http_build_url/src/http_build_url.php 0000755 00000010753 14720415745 0023243 0 ustar 00 <?php /** * URL constants as defined in the PHP Manual under "Constants usable with * http_build_url()". * * @see http://us2.php.net/manual/en/http.constants.php#http.constants.url */ if (!defined('HTTP_URL_REPLACE')) { define('HTTP_URL_REPLACE', 1); } if (!defined('HTTP_URL_JOIN_PATH')) { define('HTTP_URL_JOIN_PATH', 2); } if (!defined('HTTP_URL_JOIN_QUERY')) { define('HTTP_URL_JOIN_QUERY', 4); } if (!defined('HTTP_URL_STRIP_USER')) { define('HTTP_URL_STRIP_USER', 8); } if (!defined('HTTP_URL_STRIP_PASS')) { define('HTTP_URL_STRIP_PASS', 16); } if (!defined('HTTP_URL_STRIP_AUTH')) { define('HTTP_URL_STRIP_AUTH', 32); } if (!defined('HTTP_URL_STRIP_PORT')) { define('HTTP_URL_STRIP_PORT', 64); } if (!defined('HTTP_URL_STRIP_PATH')) { define('HTTP_URL_STRIP_PATH', 128); } if (!defined('HTTP_URL_STRIP_QUERY')) { define('HTTP_URL_STRIP_QUERY', 256); } if (!defined('HTTP_URL_STRIP_FRAGMENT')) { define('HTTP_URL_STRIP_FRAGMENT', 512); } if (!defined('HTTP_URL_STRIP_ALL')) { define('HTTP_URL_STRIP_ALL', 1024); } if (!function_exists('http_build_url')) { /** * Build a URL. * * The parts of the second URL will be merged into the first according to * the flags argument. * * @param mixed $url (part(s) of) an URL in form of a string or * associative array like parse_url() returns * @param mixed $parts same as the first argument * @param int $flags a bitmask of binary or'ed HTTP_URL constants; * HTTP_URL_REPLACE is the default * @param array $new_url if set, it will be filled with the parts of the * composed url like parse_url() would return * @return string */ function http_build_url($url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new_url = array()) { is_array($url) || $url = parse_url($url); is_array($parts) || $parts = parse_url($parts); isset($url['query']) && is_string($url['query']) || $url['query'] = null; isset($parts['query']) && is_string($parts['query']) || $parts['query'] = null; $keys = array('user', 'pass', 'port', 'path', 'query', 'fragment'); // HTTP_URL_STRIP_ALL and HTTP_URL_STRIP_AUTH cover several other flags. if ($flags & HTTP_URL_STRIP_ALL) { $flags |= HTTP_URL_STRIP_USER | HTTP_URL_STRIP_PASS | HTTP_URL_STRIP_PORT | HTTP_URL_STRIP_PATH | HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT; } elseif ($flags & HTTP_URL_STRIP_AUTH) { $flags |= HTTP_URL_STRIP_USER | HTTP_URL_STRIP_PASS; } // Schema and host are alwasy replaced foreach (array('scheme', 'host') as $part) { if (isset($parts[$part])) { $url[$part] = $parts[$part]; } } if ($flags & HTTP_URL_REPLACE) { foreach ($keys as $key) { if (isset($parts[$key])) { $url[$key] = $parts[$key]; } } } else { if (isset($parts['path']) && ($flags & HTTP_URL_JOIN_PATH)) { if (isset($url['path']) && substr($parts['path'], 0, 1) !== '/') { // Workaround for trailing slashes $url['path'] .= 'a'; $url['path'] = rtrim( str_replace(basename($url['path']), '', $url['path']), '/' ) . '/' . ltrim($parts['path'], '/'); } else { $url['path'] = $parts['path']; } } if (isset($parts['query']) && ($flags & HTTP_URL_JOIN_QUERY)) { if (isset($url['query'])) { parse_str($url['query'], $url_query); parse_str($parts['query'], $parts_query); $url['query'] = http_build_query( array_replace_recursive( $url_query, $parts_query ) ); } else { $url['query'] = $parts['query']; } } } if (isset($url['path']) && $url['path'] !== '' && substr($url['path'], 0, 1) !== '/') { $url['path'] = '/' . $url['path']; } foreach ($keys as $key) { $strip = 'HTTP_URL_STRIP_' . strtoupper($key); if ($flags & constant($strip)) { unset($url[$key]); } } $parsed_string = ''; if (!empty($url['scheme'])) { $parsed_string .= $url['scheme'] . '://'; } if (!empty($url['user'])) { $parsed_string .= $url['user']; if (isset($url['pass'])) { $parsed_string .= ':' . $url['pass']; } $parsed_string .= '@'; } if (!empty($url['host'])) { $parsed_string .= $url['host']; } if (!empty($url['port'])) { $parsed_string .= ':' . $url['port']; } if (!empty($url['path'])) { $parsed_string .= $url['path']; } if (!empty($url['query'])) { $parsed_string .= '?' . $url['query']; } if (!empty($url['fragment'])) { $parsed_string .= '#' . $url['fragment']; } $new_url = $url; return $parsed_string; } } wpml-page-builders/vendor/jakeasmith/http_build_url/LICENSE 0000755 00000002070 14720415745 0017721 0 ustar 00 The MIT License (MIT) Copyright (c) 2015 Jake A. Smith Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wpml-page-builders/wpml-dependencies.json 0000755 00000000054 14720415745 0014555 0 ustar 00 { "sitepress-multilingual-cms": "4.5.9" }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0.04 |
proxy
|
phpinfo
|
Настройка