2021-04-26 22:57:04 +01:00
< ? php // phpcs:disable Squiz.Commenting.FileComment.Missing
2021-03-02 03:09:34 +00:00
/**
2021-04-26 22:57:04 +01:00
* File provides WYSIWYG editor integration .
2021-03-02 03:09:34 +00:00
*
2021-04-26 22:57:04 +01:00
* @ since 1.5 . 0
*
* @ package footnotes
* @ subpackage footnotes / admin
2021-03-02 03:09:34 +00:00
*/
/**
2021-03-03 18:58:03 +00:00
* Handles the WSYIWYG - Buttons .
2021-03-02 03:09:34 +00:00
*
* @ since 1.5 . 0
*/
2021-04-19 12:16:05 +01:00
class Footnotes_WYSIWYG {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
/**
2021-04-27 09:01:00 +01:00
* The ID of this plugin .
2021-02-23 16:44:18 +00:00
*
2021-04-27 09:01:00 +01:00
* @ since 2.8 . 0
* @ access private
* @ var string $plugin_name The ID of this plugin .
*/
private $plugin_name ;
/**
* Initialize the class and set its properties .
2021-03-03 18:58:03 +00:00
*
2021-04-27 09:01:00 +01:00
* @ since 2.8 . 0
* @ param string $plugin_name The name of this plugin .
2021-03-03 18:58:03 +00:00
*/
2021-04-27 09:01:00 +01:00
public function __construct ( $plugin_name ) {
2021-03-02 03:09:34 +00:00
2021-04-27 09:01:00 +01:00
$this -> plugin_name = $plugin_name ;
2021-03-02 03:09:34 +00:00
}
/**
* Append a new Button to the WYSIWYG editor of Posts and Pages .
*
* @ since 1.5 . 0
2021-04-19 12:15:17 +01:00
* @ param array $p_arr_buttons pre defined Buttons from WordPress .
2021-03-02 03:09:34 +00:00
* @ return array
*/
2021-04-19 12:15:17 +01:00
public static function new_visual_editor_button ( $p_arr_buttons ) {
2021-04-27 09:30:53 +01:00
array_push ( $p_arr_buttons , $this -> plugin_name );
2021-04-19 12:15:17 +01:00
return $p_arr_buttons ;
2021-03-02 03:09:34 +00:00
}
/**
* Add a new button to the plain text editor .
*
* @ since 1.5 . 0
*/
2021-03-03 18:58:03 +00:00
public static function new_plain_text_editor_button () {
2021-04-19 12:16:05 +01:00
$l_obj_template = new Footnotes_Template ( Footnotes_Template :: C_STR_DASHBOARD , 'editor-button' );
2021-03-03 18:58:03 +00:00
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
2021-04-19 12:15:17 +01:00
echo $l_obj_template -> get_content ();
2021-03-03 18:58:03 +00:00
// phpcs:enable
2021-03-02 03:09:34 +00:00
}
/**
* Includes the Plugins WYSIWYG editor script .
*
* @ since 1.5 . 0
2021-04-19 12:15:17 +01:00
* @ param array $p_arr_plugins Scripts to be included to the editor .
2021-03-02 03:09:34 +00:00
* @ return array
*/
2021-04-19 12:15:17 +01:00
public static function include_scripts ( $p_arr_plugins ) {
2021-04-27 09:30:53 +01:00
$p_arr_plugins [ $this -> plugin_name ] = plugins_url ( '/../admin/js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js' , __FILE__ );
2021-04-19 12:15:17 +01:00
return $p_arr_plugins ;
2021-03-02 03:09:34 +00:00
}
/**
* 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
*/
2021-03-03 18:58:03 +00:00
public static function ajax_callback () {
// Get start and end tag for the footnotes short code.
2021-04-19 12:16:05 +01: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 );
2021-04-19 12:15:17 +01:00
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
2021-04-19 12:16:05 +01: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 );
2021-03-02 03:09:34 +00:00
}
2021-04-26 17:15:48 +01:00
echo wp_json_encode (
2021-03-03 18:58:03 +00:00
array (
2021-04-19 12:15:17 +01:00
'start' => htmlspecialchars ( $l_str_starting_tag ),
'end' => htmlspecialchars ( $l_str_ending_tag ),
2021-03-03 18:58:03 +00:00
)
);
2021-03-02 03:09:34 +00:00
exit ;
}
}