Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/translation-dashboard.tar
Назад
EncodedFieldsValidation/Validator.php 0000644 00000014514 14721702117 0013714 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard\EncodedFieldsValidation; use WPML\FP\Fns; use WPML\FP\Logic; use WPML\FP\Lst; use WPML\FP\Obj; use WPML\FP\Str; use WPML\LIB\WP\Post; use WPML\TM\TranslationDashboard\SentContentMessages; use function WPML\FP\invoke; use function WPML\FP\spreadArgs; class Validator { /** @var \WPML_Encoding_Validation */ private $encoding_validation; /** @var \WPML_Element_Translation_Package */ private $package_helper; /** @var SentContentMessages */ private $sentContentMessages; /** @var FieldTitle */ private $fieldTitle; /** @var \WPML_PB_Factory */ private $pbFactory; public function __construct( \WPML_Encoding_Validation $encoding_validation, \WPML_Element_Translation_Package $package_helper, SentContentMessages $sentContentMessages, FieldTitle $fieldTitle, \WPML_PB_Factory $pbFactory ) { $this->encoding_validation = $encoding_validation; $this->package_helper = $package_helper; $this->sentContentMessages = $sentContentMessages; $this->fieldTitle = $fieldTitle; $this->pbFactory = $pbFactory; } /** * $data may contain two keys: 'post' and 'package'. Each of them has the same shape: * [ * idOfElement1 => [ * checked: 1, * type: 'post', * ], * idOfElement2 => [ * type: 'post', * ], * ] and so on. * * If element has "checked" field, it means it has been selected for translation. * Therefore, if we want to filter it out from translation, we have to remove that field. * * The "validateTMDashboardInput" performs similar check for both "post" and "package" lists, * checks if their elements contains encoded fields and removes them from the list. * * @param array $data * * @return array */ public function validateTMDashboardInput( $data ) { $postInvalidElements = []; if ( isset( $data['post'] ) ) { $postInvalidElements = $this->findPostsWithEncodedFields( $this->getCheckedIds( 'post', $data ) ); $data = $this->excludeInvalidElements( 'post', $data, Lst::pluck( 'elementId', $postInvalidElements ) ); } $packageInvalidElements = []; if ( isset( $data['package'] ) ) { $packageInvalidElements = $this->findPackagesWithEncodedFields( $this->getCheckedIds( 'package', $data ) ); $data = $this->excludeInvalidElements( 'package', $data, Lst::pluck( 'elementId', $packageInvalidElements ) ); } $invalidElements = array_merge( $postInvalidElements, $packageInvalidElements ); if ( count( $invalidElements ) ) { // Display the error message only if there are invalid elements. $this->sentContentMessages->postsWithEncodedFieldsHasBeenSkipped( $invalidElements ); } return $data; } /** * Get list of ids of selected posts/packages * * @param 'post'|'package' $type * @param array $data * * @return [] */ private function getCheckedIds( $type, $data ) { return \wpml_collect( Obj::propOr( [], $type, $data ) ) ->filter( Obj::prop( 'checked' ) ) ->keys() ->toArray(); } /** * It removes "checked" property from the elements that have "encoded" fields. It means they will not be sent to translation. * * @param 'post'|'package' $type * @param array $data * @param int[] $ids * * @return array */ private function excludeInvalidElements( $type, $data, $invalidElementIds ) { return (array) Obj::over( Obj::lensProp( $type ), function ( $elements ) use ( $invalidElementIds ) { return \wpml_collect( $elements ) ->map( function ( $element, $elementId ) use ( $invalidElementIds ) { if ( Lst::includes( $elementId, $invalidElementIds ) ) { return Obj::removeProp( 'checked', $element ); } return $element; } ) ->toArray(); }, $data ); } /** * @param int[] $postIds * * @return ErrorEntry[] */ private function findPostsWithEncodedFields( $postIds ) { $appendPackage = function ( \WP_Post $post ) { $package = $this->package_helper->create_translation_package( $post->ID, true ); return [ $post, $package ]; }; $isFieldEncoded = function ( $field ) { $decodedFieldData = base64_decode( $field['data'] ); return array_key_exists( 'format', $field ) && 'base64' === $field['format'] && $this->encoding_validation->is_base64_with_100_chars_or_more( $decodedFieldData ); /** * @todo : we should handle not to block the whole job from being translated but instead we should exclude the problematic field from the job and send it to be translated without that field. * @todo check Youtrack ticket * @see : https://onthegosystems.myjetbrains.com/youtrack/issue/wpmldev-1694 */ }; $getInvalidFieldData = function ( $field, $slug ) { return [ 'title' => $this->fieldTitle->get( $slug ), 'content' => base64_decode( $field['data'] ), ]; }; $tryToGetError = function ( \WP_Post $post, $package ) use ( $isFieldEncoded, $getInvalidFieldData ) { $invalidFields = \wpml_collect( $package['contents'] ) ->filter( $isFieldEncoded ) ->map( $getInvalidFieldData ) ->values() ->toArray(); if ( $invalidFields ) { return new ErrorEntry( $post->ID, $package['title'], $invalidFields ); } return null; }; return \wpml_collect( $postIds ) ->map( Post::get() ) ->filter() ->map( $appendPackage ) ->map( spreadArgs( $tryToGetError ) ) ->filter() ->toArray(); } /** * @param int[] $packageIds * * @return ErrorEntry[] */ private function findPackagesWithEncodedFields( $packageIds ) { $getInvalidFieldData = function ( $field, $slug ) { return [ 'title' => $this->fieldTitle->get( $slug ), 'content' => $field, ]; }; /** * @param \WPML_Package $package * * @return ErrorEntry|null */ $tryToGetError = function ( $package ) use ( $getInvalidFieldData ) { $invalidFields = \wpml_collect( Obj::propOr( [], 'string_data', $package ) ) ->filter( [ $this->encoding_validation, 'is_base64_with_100_chars_or_more' ] ) ->map( $getInvalidFieldData ) ->values() ->toArray(); if ( $invalidFields ) { return new ErrorEntry( $package->ID, $package->title, $invalidFields ); } return null; }; return \wpml_collect( $packageIds ) ->map( function ( $packageId ) { return $this->pbFactory->get_wpml_package( $packageId ); } ) ->filter( Obj::prop( 'ID' ) ) ->map( $tryToGetError ) ->filter() ->toArray(); } } EncodedFieldsValidation/FieldTitle.php 0000644 00000000461 14721702117 0014010 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard\EncodedFieldsValidation; class FieldTitle { /** * @param string $slug * * @return string */ public function get( $slug ) { $string_slug = new \WPML_TM_Page_Builders_Field_Wrapper( $slug ); return (string) $string_slug->get_string_title(); } } EncodedFieldsValidation/ErrorEntry.php 0000644 00000001114 14721702117 0014072 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard\EncodedFieldsValidation; /** * @template field of array{title:string, content:string} */ class ErrorEntry { /** @var int ID of post or package */ public $elementId; /** @var string */ public $elementTitle; /** @var field[] */ public $fields; /** * @param int $elementId * @param string $elementTitle * @param field[] $fields */ public function __construct( $elementId, $elementTitle, $fields ) { $this->elementId = (int) $elementId; $this->elementTitle = $elementTitle; $this->fields = $fields; } } Endpoints/DisplayNeedSyncMessage.php 0000644 00000000732 14721702117 0013567 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard\Endpoints; use WPML\Collect\Support\Collection; use WPML\FP\Either; /** * It calls `new_duplicated_terms_filter` function which displays the admin notice informing about term taxonomies which have to be synced. */ class DisplayNeedSyncMessage { public function run( Collection $data ) { $postIds = $data->get( 'postIds', [] ); do_action( 'wpml_new_duplicated_terms', $postIds ); return Either::of( $postIds ); } } Endpoints/Duplicate.php 0000644 00000001264 14721702117 0011137 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard\Endpoints; use WPML\Collect\Support\Collection; use WPML\FP\Either; use WPML\FP\Fns; use WPML\FP\Lst; use function WPML\FP\spreadArgs; /** * It duplicates posts into specified languages. */ class Duplicate { public function run( Collection $data ) { global $sitepress; $postIds = $data->get( 'postIds' ); $languages = $data->get( 'languages' ); $pairs = Lst::xprod( $postIds, $languages ); $result = Fns::map( spreadArgs( function ( $postId, $languageCode ) use ( $sitepress ) { return [ $postId, $languageCode, $sitepress->make_duplicate( $postId, $languageCode ) ]; } ), $pairs ); return Either::of( $result ); } } SentContentMessages.php 0000644 00000007110 14721702117 0011212 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard; use WPML\TM\TranslationDashboard\EncodedFieldsValidation\ErrorEntry; use WPML\UIPage; class SentContentMessages { /** * @var null|array{message: string, description: string, type: string} */ private static $confirmation = null; /** @var ErrorEntry[]|null */ private static $encodedFieldErrorEntries = null; public function duplicate() { self::$confirmation = [ 'message' => '', 'description' => __( 'You successfully duplicated your content.', 'sitepress-multilingual-cms' ), 'type' => 'success', ]; } public function duplicateAndAutomatic() { self::$confirmation = [ 'message' => __( 'You successfully duplicated your content, and WPML is handling your translations for you.', 'sitepress-multilingual-cms' ), 'description' => __( 'Your translations will be ready soon. You can see the status of your automatic translations below or in the status bar at the top of WordPress admin.', 'sitepress-multilingual-cms' ), 'type' => 'success', 'automatic' => true, ]; } public function duplicateAndMyself() { self::$confirmation = [ 'message' => __( 'You successfully duplicated your content. What’s next for your translations?', 'sitepress-multilingual-cms' ), 'description' => sprintf( __( 'Go to the <a href="%s">Translations Queue</a> to translate it.', 'sitepress-multilingual-cms' ), UIPage::getTranslationQueue() ), 'type' => 'info', ]; } public function duplicateAndBasket() { self::$confirmation = [ 'message' => __( 'You successfully duplicated your content. What’s next for your translations?', 'sitepress-multilingual-cms' ), 'description' => sprintf( __( 'Go to the <a href="%s">Translation Basket</a> to decide who should translate your content', 'sitepress-multilingual-cms' ), UIPage::getTMBasket() ), 'type' => 'info', ]; } public function automatic() { self::$confirmation = [ 'message' => __( 'WPML is translating your content', 'sitepress-multilingual-cms' ), 'description' => __( 'Your translations will be ready soon. You can see the status of your automatic translations below or in the status bar at the top of WordPress admin.', 'sitepress-multilingual-cms' ), 'type' => 'success', 'automatic' => true, ]; } public function myself() { self::$confirmation = [ 'message' => __( 'You’ve queued up your content for translation. What’s next?', 'sitepress-multilingual-cms' ), 'description' => sprintf( __( 'Go to the <a href="%s">Translations Queue</a> to translate it.', 'sitepress-multilingual-cms' ), UIPage::getTranslationQueue() ), 'type' => 'info', ]; } public function basket() { self::$confirmation = [ 'message' => __( 'You added your translations to the basket. What’s next?', 'sitepress-multilingual-cms' ), 'description' => sprintf( __( 'Go to the <a href="%s">Translation Basket</a> to decide who should translate your content', 'sitepress-multilingual-cms' ), UIPage::getTMBasket() ), 'type' => 'info', ]; } /** * @param ErrorEntry[] $invalidElements */ public function postsWithEncodedFieldsHasBeenSkipped( array $invalidElements ) { self::$encodedFieldErrorEntries = $invalidElements; } /** * @return array{confirmMessage: null|array{message: string, description: string, type: string}, encodedFieldErrorEntries: null|ErrorEntry[]} */ public function get() { return [ 'confirmation' => self::$confirmation, 'encodedFieldErrorEntries' => self::$encodedFieldErrorEntries, ]; } } class-wpml-tm-parent-filter-ajax-factory.php 0000644 00000000362 14721702117 0015120 0 ustar 00 <?php class WPML_TM_Parent_Filter_Ajax_Factory implements IWPML_AJAX_Action_Loader { public function create() { global $sitepress, $wp_post_types; return new WPML_TM_Parent_Filter_Ajax( $sitepress, array_keys( $wp_post_types ) ); } } class-wpml-tm-parent-filter-ajax.php 0000644 00000003302 14721702117 0013450 0 ustar 00 <?php class WPML_TM_Parent_Filter_Ajax implements IWPML_Action { /** @var SitePress $sitepress */ private $sitepress; /** @var array $wp_post_types */ private $wp_post_types; public function __construct( SitePress $sitepress, array $wp_post_types ) { $this->sitepress = $sitepress; $this->wp_post_types = $wp_post_types; } public function add_hooks() { add_action( 'wp_ajax_icl_tm_parent_filter', array( $this, 'get_parents_dropdown' ) ); } public function get_parents_dropdown() { $current_language = $this->sitepress->get_current_language(); $request_post_type = filter_var( $_POST['type'], FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); $request_post_lang = filter_var( $_POST['from_lang'], FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); $request_post_parent_id = filter_var( $_POST['parent_id'], FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE ); $this->sitepress->switch_lang( $request_post_lang ); if ( in_array( $request_post_type, $this->wp_post_types ) ) { $html = wp_dropdown_pages( array( 'echo' => 0, 'name' => 'filter[parent_id]', 'selected' => $request_post_parent_id ?: 0, ) ); } else { $html = wp_dropdown_categories( array( 'echo' => 0, 'orderby' => 'name', 'name' => 'filter[parent_id]', 'selected' => $request_post_parent_id ?: 0, 'taxonomy' => $request_post_type, 'hide_if_empty' => true, ) ); } $this->sitepress->switch_lang( $current_language ); if ( ! $html ) { $html = esc_html__( 'None found', 'wpml-translation-management' ); } wp_send_json_success( array( 'html' => $html ) ); } } FiltersStorage.php 0000644 00000001071 14721702117 0010213 0 ustar 00 <?php namespace WPML\TM\TranslationDashboard; use WPML\API\Sanitize; use WPML\Element\API\Languages; use WPML\FP\Obj; class FiltersStorage { /** * @return array */ public static function get() { $result = []; $dashboard_filter = Sanitize::stringProp( 'wp-translation_dashboard_filter', $_COOKIE ); if ( $dashboard_filter ) { parse_str( $dashboard_filter, $result ); } return $result; } /** * @return string */ public static function getFromLanguage() { return Obj::propOr( Languages::getCurrentCode(), 'from_lang', self::get() ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка