required_wp_version, esc_html( $wp_version ) ); echo ''; printf( __( 'Please upgrade your WordPress installation or download an older version of the plugin.', 'tinymce-advanced' ), 'https://wordpress.org/plugins/tinymce-advanced/advanced/#download-previous-link' ); ?>
tags inside the classic block :-( // $data is slashed... if ( strpos( $content, '
' ) !== false ) { $content = str_replace( '
', '
', $content ); } $data['post_content'] = $content; return $data; } // Excerpts can be generated from classic paragraph blocks public function excerpt_add_allowed_blocks( $allowed_blocks ) { // Make sure a plugin doesn't pass the wrong type here... $allowed_blocks = (array) $allowed_blocks; $allowed_blocks[] = 'tadv/classic-paragraph'; return $allowed_blocks; } public function mce_external_plugins( $mce_plugins ) { if ( ! is_array( $this->options ) ) { $this->load_settings(); } if ( $this->is_disabled() ) { return $mce_plugins; } if ( ! is_array( $this->plugins ) ) { $this->plugins = array(); } $this->plugins[] = 'wptadv'; if ( $this->check_user_setting( 'menubar' ) || $this->check_user_setting( 'menubar_block' ) ) { $this->plugins = array_merge( $this->plugins, $this->required_menubar_plugins ); } $this->plugins = array_intersect( $this->plugins, $this->get_all_plugins() ); $plugin_url = plugins_url( 'mce/', __FILE__ ); $mce_plugins = (array) $mce_plugins; $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; foreach ( $this->plugins as $plugin ) { $mce_plugins["$plugin"] = $plugin_url . $plugin . "/plugin{$suffix}.js"; } return $mce_plugins; } public function tiny_mce_plugins( $plugins ) { if ( $this->is_disabled() ) { return $plugins; } if ( in_array( 'image', $this->used_buttons, true ) && ! in_array( 'image', $plugins, true ) ) { $plugins[] = 'image'; } if ( ( in_array( 'rtl', $this->used_buttons, true ) || in_array( 'ltr', $this->used_buttons, true ) ) && ! in_array( 'directionality', (array) $plugins, true ) ) { $plugins[] = 'directionality'; } return $plugins; } private function parse_buttons( $toolbar_id = false, $buttons = false ) { if ( $toolbar_id && ! $buttons && ! empty( $_POST[$toolbar_id] ) ) $buttons = $_POST[$toolbar_id]; if ( is_array( $buttons ) ) { $_buttons = array_map( array( @$this, 'filter_name' ), $buttons ); return implode( ',', array_filter( $_buttons ) ); } return ''; } private function filter_name( $str ) { if ( empty( $str ) || ! is_string( $str ) ) return ''; // Button names return preg_replace( '/[^a-z0-9_]/i', '', $str ); } private function sanitize_settings( $settings ) { $_settings = array(); if ( ! is_array( $settings ) ) { return $_settings; } foreach( $settings as $name => $value ) { $name = preg_replace( '/[^a-z0-9_]+/', '', $name ); if ( strpos( $name, 'toolbar_' ) === 0 ) { $_settings[$name] = $this->parse_buttons( false, explode( ',', $value ) ); } else if ( 'options' === $name || 'plugins' === $name || 'disabled_plugins' === $name ) { $_settings[$name] = preg_replace( '/[^a-z0-9_,]+/', '', $value ); } } return $_settings; } /** * Validare array of settings against a whitelist. * * @param array $settings The settings. * @param array $checklist The whitelist. * @return string The validated settings CSV. */ private function validate_settings( $settings, $checklist ) { if ( empty( $settings ) ) { return ''; } elseif ( is_string( $settings ) ) { $settings = explode( ',', $settings ); } elseif ( ! is_array( $settings ) ) { return ''; } $_settings = array(); foreach ( $settings as $value ) { if ( in_array( $value, $checklist, true ) ) { $_settings[] = $value; } } return implode( ',', $_settings ); } private function save_settings( $all_settings = null ) { $settings = $user_settings = array(); $default_settings = $this->get_default_user_settings(); if ( empty( $this->buttons_filter ) ) { $this->get_all_buttons(); } if ( ! empty( $all_settings['settings'] ) ) { $user_settings = $all_settings['settings']; } for ( $i = 1; $i < 6; $i++ ) { $toolbar_name = ( $i < 5 ) ? 'toolbar_' . $i : 'toolbar_classic_block'; if ( ! empty( $user_settings[ $toolbar_name ] ) ) { $toolbar = explode( ',', $user_settings[ $toolbar_name ] ); } elseif ( ! empty( $_POST[ $toolbar_name ] ) && is_array( $_POST[ $toolbar_name ] ) ) { $toolbar = $_POST[ $toolbar_name ]; } else { $toolbar = array(); } if ( $i > 1 && in_array( 'wp_adv', $toolbar, true ) ) { $toolbar = array_diff( $toolbar, array( 'wp_adv' ) ); } $settings[ $toolbar_name ] = $this->validate_settings( $toolbar, $this->buttons_filter ); } if ( ! empty( $user_settings['options'] ) ) { $options = explode( ',', $user_settings['options'] ); } elseif ( ! empty( $_POST['options'] ) && is_array( $_POST['options'] ) ) { $options = $_POST['options']; if ( ! empty( $_POST['richtext_buttons'] ) && $_POST['richtext_buttons'] === 'no' ) { $options[] = 'disable_richtext_buttons'; } } else { $options = array(); } $settings['options'] = $this->validate_settings( $options, $this->get_all_user_options() ); if ( ! empty( $user_settings['plugins'] ) ) { $plugins = explode( ',', $user_settings['plugins'] ); } else { $plugins = array(); } if ( ! empty( $settings['options']['menubar'] ) || ! empty( $settings['options']['menubar_block'] ) ) { $plugins = array_merge( $plugins, $this->required_menubar_plugins ); } // Merge the submitted plugins with plugins needed for the buttons. $this->user_settings = $settings; $this->load_settings(); $plugins = $this->get_plugins( $plugins ); $settings['plugins'] = $this->validate_settings( $plugins, $this->get_all_plugins() ); $this->user_settings = $settings; $this->load_settings(); // Save the new settings. update_option( 'tadv_settings', $settings ); if ( ! is_multisite() || current_user_can( 'manage_sites' ) ) { $this->save_admin_settings( $all_settings ); } } private function save_admin_settings( $all_settings = null ) { $admin_settings = $save_admin_settings = array(); if ( ! empty( $all_settings['admin_settings'] ) ) { $admin_settings = $all_settings['admin_settings']; } if ( ! empty( $admin_settings ) ) { if ( ! empty( $admin_settings['options'] ) ) { $save_admin_settings['options'] = $this->validate_settings( $admin_settings['options'], $this->get_all_admin_options() ); } else { $save_admin_settings['options'] = ''; } $disabled_editors = array_intersect( $this->get_editor_locations(), explode( ',', $admin_settings['disabled_editors'] ) ); } elseif ( isset( $_POST['tadv-save'] ) ) { if ( ! empty( $_POST['admin_options'] ) && is_array( $_POST['admin_options'] ) ) { $save_admin_settings['options'] = $this->validate_settings( $_POST['admin_options'], $this->get_all_admin_options() ); } if ( ! empty( $_POST['tadv_enable_at'] ) && is_array( $_POST['tadv_enable_at'] ) ) { $tadv_enable_at = $_POST['tadv_enable_at']; } else { $tadv_enable_at = array(); } $disabled_editors = array_diff( $this->get_editor_locations(), $tadv_enable_at ); } else { return; } $save_admin_settings['disabled_editors'] = implode( ',', $disabled_editors ); $this->admin_settings = $save_admin_settings; update_option( 'tadv_admin_settings', $save_admin_settings ); } private function import_from_file() { if ( empty( $_FILES['tadv-import']['name'] ) ) { return 1; } $file_type = wp_check_filetype( $_FILES['tadv-import']['name'], array( 'json' => 'application/json' ) ); if ( $file_type['ext'] !== 'json' ) { return 1; } $settings = @file_get_contents( $_FILES['tadv-import']['tmp_name'] ); if ( empty( $settings ) ) { return 2; } $settings = json_decode( $settings, true ); if ( ! is_array( $settings ) ) { return 3; } $this->save_settings( $settings ); return 0; } public function import_export_settings_file() { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( isset( $_POST['tadv-import-file'] ) && isset( $_POST['tadv-import-settings-nonce'] ) && wp_verify_nonce( $_POST['tadv-import-settings-nonce'], 'tadv-import-settings' ) ) { $err = $this->import_from_file(); $url = admin_url( 'options-general.php?page=tinymce-advanced' ); $url = add_query_arg( 'tadv-import-file-complete', $err, $url ); wp_safe_redirect( $url ); exit; } elseif ( isset( $_POST['tadv-export-settings'] ) && isset( $_POST['tadv-export-settings-nonce'] ) && wp_verify_nonce( $_POST['tadv-export-settings-nonce'], 'tadv-export-settings' ) ) { $this->load_settings(); $output = array( 'settings' => $this->user_settings ); // TODO: only admin || SA $output['admin_settings'] = $this->admin_settings; $sitename = get_bloginfo( 'name' ); if ( mb_strlen( $sitename ) > 100 ) { $sitename = mb_substr( $sitename, 0, 100 ); } $sitename = preg_replace( '/[ \.-]+/', '-', $sitename ); $date = date( 'Y-m-d' ); $filename = sanitize_file_name( $sitename . '-TMA-settings-' . $date . '.json' ); nocache_headers(); header( 'Content-Type: application/json; charset=utf-8' ); header( "Content-Disposition: attachment; filename=$filename" ); echo wp_json_encode( $output ); exit; } } public function settings_page() { if ( ! defined( 'TADV_ADMIN_PAGE' ) ) { define( 'TADV_ADMIN_PAGE', true ); } include_once( plugin_dir_path( __FILE__ ) . 'tadv_admin.php' ); } public function add_menu() { $page_title = __( 'Advanced Editor Tools', 'tinymce-advanced' ); $menu_item_label = __( 'Advanced Editor Tools', 'tinymce-advanced' ); add_options_page( $page_title, $menu_item_label, 'manage_options', 'tinymce-advanced', array( $this, 'settings_page' ) ); } /** * Add a link to the settings page */ public function add_settings_link( $links, $file ) { if ( strrpos( $file, '/tinymce-advanced.php' ) === ( strlen( $file ) - 21 ) && current_user_can( 'manage_options' ) ) { $settings_link = sprintf( '%s', admin_url( 'options-general.php?page=tinymce-advanced' ), __( 'Settings', 'tinymce-advanced' ) ); $links = (array) $links; $links['tma_settings_link'] = $settings_link; } return $links; } } new Advanced_Editor_Tools; endif;