This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
footnotes/src/class/wysiwyg.php

104 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
/**
* Includes the Class to handle the WYSIWYG-Buttons.
*
* @filesource
* @package footnotes
* @since 1.5.0
*/
/**
* Handles the WSYIWYG-Buttons.
*
* @since 1.5.0
*/
2021-04-19 11:16:05 +00:00
class Footnotes_WYSIWYG {
/**
* Registers Button hooks.
*
* @since 1.5.0
2021-04-10 19:02:10 +00:00
*
* - Bugfix: Editor buttons: debug button by reverting name change in PHP file while JS file and HTML template remained unsynced, thanks to @gova bug report.
2021-04-10 19:02:10 +00:00
*
* @reporter @gova
* @link https://wordpress.org/support/topic/back-end-footnotes-not-working-400-bad-erro/
*
* @since 2.6.5
* @return void
*/
public static function register_hooks() {
2021-04-19 11:16:05 +00:00
add_filter( 'mce_buttons', array( 'Footnotes_WYSIWYG', 'new_visual_editor_button' ) );
add_action( 'admin_print_footer_scripts', array( 'Footnotes_WYSIWYG', 'new_plain_text_editor_button' ) );
2021-04-19 11:16:05 +00:00
add_filter( 'mce_external_plugins', array( 'Footnotes_WYSIWYG', 'include_scripts' ) );
// phpcs:disable
// 'footnotes_getTags' must match its instance in wysiwyg-editor.js.
// 'footnotes_getTags' must match its instance in editor-button.html.
2021-04-19 11:16:05 +00:00
add_action( 'wp_ajax_nopriv_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) );
add_action( 'wp_ajax_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) );
// phpcs:enable
}
/**
* Append a new Button to the WYSIWYG editor of Posts and Pages.
*
* @since 1.5.0
* @param array $p_arr_buttons pre defined Buttons from WordPress.
* @return array
*/
public static function new_visual_editor_button( $p_arr_buttons ) {
2021-04-19 11:16:05 +00:00
array_push( $p_arr_buttons, Footnotes_Config::C_STR_PLUGIN_NAME );
return $p_arr_buttons;
}
/**
* Add a new button to the plain text editor.
*
* @since 1.5.0
*/
public static function new_plain_text_editor_button() {
2021-04-19 11:16:05 +00:00
$l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_DASHBOARD, 'editor-button' );
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $l_obj_template->get_content();
// phpcs:enable
}
/**
* Includes the Plugins WYSIWYG editor script.
*
* @since 1.5.0
* @param array $p_arr_plugins Scripts to be included to the editor.
* @return array
*/
public static function include_scripts( $p_arr_plugins ) {
ci: improve linting, GitHub Actions workflows (#149) * release: release 2.7.2 * fix: urgent 2.7.3 release to fix fatal error * chore: remove un-needed setup script * ci: remove steps from pre-push command * chore: remove un-needed PHP-Commitizen config * chore: put image files in correct folders * chore: move GitHub image into `.github/` dir * fix: classic editor button * fix: call correct jQuery Tools file in dev env * docs: replace license with Markdown version * ci: clean up PHP linting commands If anyone has noticed me playing musical filepaths with these commands for a while, it's because I kept getting inconsistent results from the use of double-globs (i.e., `**`). However, I've finally figured out that this is because Composer is running these scripts in its own shell, so the double-glob that works when I run the command manually in my Terminal doesn't work when Composer runs it in its. * chore: lint PHP files * build: update JS linting standards * chore: lint JS file * build: add node-sass * build: add additional stylelint rules * chore: lint stylesheets with new rulesets * refactor: move ESLint settings to `package.json` * chore: move Prettier config to `package.json` It is not yet possible to move `.prettierignore` to `package.json` too, but this appears to be on the horizon; see [this Issue][prettier-issue]. [prettier-issue]: https://github.com/prettier/prettier/issues/3460 * fix: move WPML config into Plugin folder * chore: move Stylelint config into `package.json` * chore: remove unused `.distignore` It can always be re-added at a later date if it becomes useful. * chore: format file * build: add HTML linting * fix: add image alt tag * ci: clean up GitHub Actions workflows * fix: fix workflow * fix: fix indentation * ci: add YAML validation * chore: make valid * ci: add YAML validation * chore: lint code * ci: change dep install back to original * chore: lint license
2021-04-26 16:17:44 +00:00
$p_arr_plugins[ Footnotes_Config::C_STR_PLUGIN_NAME ] = plugins_url( 'js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', dirname( __FILE__ ) );
return $p_arr_plugins;
}
/**
* AJAX Callback function when the Footnotes Button is clicked. Either in the Plain text or Visual editor.
* Returns an JSON encoded array with the Footnotes start and end short code.
*
* @since 1.5.0
*/
public static function ajax_callback() {
// Get start and end tag for the footnotes short code.
2021-04-19 11:16:05 +00:00
$l_str_starting_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
$l_str_ending_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
2021-04-19 11:16:05 +00:00
$l_str_starting_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
$l_str_ending_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
}
ci: improve linting, GitHub Actions workflows (#149) * release: release 2.7.2 * fix: urgent 2.7.3 release to fix fatal error * chore: remove un-needed setup script * ci: remove steps from pre-push command * chore: remove un-needed PHP-Commitizen config * chore: put image files in correct folders * chore: move GitHub image into `.github/` dir * fix: classic editor button * fix: call correct jQuery Tools file in dev env * docs: replace license with Markdown version * ci: clean up PHP linting commands If anyone has noticed me playing musical filepaths with these commands for a while, it's because I kept getting inconsistent results from the use of double-globs (i.e., `**`). However, I've finally figured out that this is because Composer is running these scripts in its own shell, so the double-glob that works when I run the command manually in my Terminal doesn't work when Composer runs it in its. * chore: lint PHP files * build: update JS linting standards * chore: lint JS file * build: add node-sass * build: add additional stylelint rules * chore: lint stylesheets with new rulesets * refactor: move ESLint settings to `package.json` * chore: move Prettier config to `package.json` It is not yet possible to move `.prettierignore` to `package.json` too, but this appears to be on the horizon; see [this Issue][prettier-issue]. [prettier-issue]: https://github.com/prettier/prettier/issues/3460 * fix: move WPML config into Plugin folder * chore: move Stylelint config into `package.json` * chore: remove unused `.distignore` It can always be re-added at a later date if it becomes useful. * chore: format file * build: add HTML linting * fix: add image alt tag * ci: clean up GitHub Actions workflows * fix: fix workflow * fix: fix indentation * ci: add YAML validation * chore: make valid * ci: add YAML validation * chore: lint code * ci: change dep install back to original * chore: lint license
2021-04-26 16:17:44 +00:00
echo wp_json_encode(
array(
'start' => htmlspecialchars( $l_str_starting_tag ),
'end' => htmlspecialchars( $l_str_ending_tag ),
)
);
exit;
}
}