| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
/** |
| 5 |
* Einzelne Buttons zum TinyMCE-Editor (WYSIWYG) hinzufügen |
| 6 |
* |
| 7 |
* @since 2.0.0 |
| 8 |
* @change 4.4.0 |
| 9 |
* |
| 10 |
* @param array $buttons Buttons [WordPress] |
| 11 |
* @return array $buttons Buttons [WordPress] |
| 12 |
*/ |
| 13 |
|
| 14 |
function wpAppbox_addSingleButtons( $buttons ) { |
| 15 |
global $wpAppbox_storeNames; |
| 16 |
$defaultOption = get_option( 'wpAppbox_defaultButton' ); |
| 17 |
if ( '0' == $defaultOption || '3' == $defaultOption ): |
| 18 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'amazonapps' ) || get_option('wpAppbox_buttonWYSIWYG_amazonapps') && get_option('wpAppbox_amaAPIuse') ) |
| 19 |
array_push( $buttons, 'wpAppbox_AmazonAppsButton' ); |
| 20 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'appstore' ) || get_option('wpAppbox_buttonWYSIWYG_appstore') ) |
| 21 |
array_push( $buttons, 'wpAppbox_AppStoreButton' ); |
| 22 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'chromewebstore' ) || get_option('wpAppbox_buttonWYSIWYG_chromewebstore') ) |
| 23 |
array_push( $buttons, 'wpAppbox_ChromeWebStoreButton' ); |
| 24 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'edgeaddons' ) || get_option('wpAppbox_buttonWYSIWYG_edgeaddons') ) |
| 25 |
array_push( $buttons, 'wpAppbox_EdgeAddOnsButton' ); |
| 26 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'fdroid' ) || get_option('wpAppbox_buttonWYSIWYG_fdroid') ) |
| 27 |
array_push( $buttons, 'wpAppbox_FDroidButton' ); |
| 28 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'firefoxaddon' ) || get_option('wpAppbox_buttonWYSIWYG_firefoxaddon') ) |
| 29 |
array_push( $buttons, 'wpAppbox_FirefoxAddonButton' ); |
| 30 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'googleplay' ) || get_option('wpAppbox_buttonWYSIWYG_googleplay') ) |
| 31 |
array_push( $buttons, 'wpAppbox_GooglePlayButton' ); |
| 32 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'microsoftstore' ) || get_option('wpAppbox_buttonWYSIWYG_microsoftstore') ) |
| 33 |
array_push( $buttons, 'wpAppbox_MicrosoftStoreButton' ); |
| 34 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'operaaddons' ) || get_option('wpAppbox_buttonWYSIWYG_operaaddons') ) |
| 35 |
array_push( $buttons, 'wpAppbox_OperaAddonsButton' ); |
| 36 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'snapcraft' ) || get_option('wpAppbox_buttonWYSIWYG_snapcraft') ) |
| 37 |
array_push( $buttons, 'wpAppbox_SnapcraftButton' ); |
| 38 |
if ( '0' == $defaultOption || ( isset( $forceSingle ) && $forceSingle == 'wordpress' ) || get_option('wpAppbox_buttonWYSIWYG_wordpress') ) |
| 39 |
array_push( $buttons, 'wpAppbox_WordPressButton' ); |
| 40 |
endif; |
| 41 |
return( $buttons ); |
| 42 |
} |
| 43 |
//--> See next: wpAppbox_addTheButtons(); |
| 44 |
|
| 45 |
|
| 46 |
/** |
| 47 |
* WP-Appbox-Button zum alten TinyMCE-Editor (WYSIWYG) hinzufügen |
| 48 |
* |
| 49 |
* @since 2.0.0 |
| 50 |
* @change 4.4.0 |
| 51 |
* |
| 52 |
* @param array $buttons Buttons [WordPress] |
| 53 |
* @return array $buttons Buttons [WordPress] |
| 54 |
*/ |
| 55 |
|
| 56 |
function wpAppbox_addCombinedButton( $buttons ) { |
| 57 |
global $wpAppbox_storeNames, $wpAppbox_combinedButton; |
| 58 |
$defaultOption = get_option( 'wpAppbox_defaultButton' ); |
| 59 |
if ( $defaultOption == '1' || $defaultOption == '3' ): |
| 60 |
$combinedButton = array(); |
| 61 |
$combinedButtonNames = array(); |
| 62 |
$combinedButtonIDs = array(); |
| 63 |
foreach ( $wpAppbox_storeNames as $storeID => $storeName ): |
| 64 |
if ( 'amazonapps' == $storeID && !get_option('wpAppbox_amaAPIuse') ) continue; |
| 65 |
if ( '1' == $defaultOption || get_option( 'wpAppbox_buttonAppbox_' . $storeID ) ): |
| 66 |
$combinedButtonNames[] = esc_attr( $storeName ); |
| 67 |
$combinedButtonIDs[] = esc_attr( $storeID ); |
| 68 |
endif; |
| 69 |
endforeach; |
| 70 |
if ( count( $combinedButtonNames ) == 1 && count( $combinedButtonIDs ) == 1 ): |
| 71 |
$forceSingle = $combinedButtonIDs[0]; |
| 72 |
elseif ( !empty( $combinedButtonNames) && !empty( $combinedButtonIDs ) ): |
| 73 |
$combinedButton['names'] = array_map( 'esc_attr', $combinedButtonNames ); |
| 74 |
$combinedButton['ids'] = array_map( 'esc_attr', $combinedButtonIDs ); |
| 75 |
endif; |
| 76 |
endif; |
| 77 |
if ( !empty( $combinedButton ) ): |
| 78 |
array_push( $buttons, 'wpAppbox_AppboxButton' ); |
| 79 |
$wpAppbox_combinedButton = $combinedButton; |
| 80 |
endif; |
| 81 |
return( $buttons ); |
| 82 |
} |
| 83 |
//--> See next: wpAppbox_addTheButtons(); |
| 84 |
|
| 85 |
|
| 86 |
/** |
| 87 |
* Die Buttons in die Toolbar einfügen (primary vs. advanced) |
| 88 |
* |
| 89 |
* @since 4.1.14 |
| 90 |
* @change n/a |
| 91 |
*/ |
| 92 |
|
| 93 |
function wpAppbox_addTheButtons() { |
| 94 |
if( !get_option('wpAppbox_advancedToolbar') ) { |
| 95 |
add_filter( 'mce_buttons', 'wpAppbox_addSingleButtons' ); |
| 96 |
add_filter( 'mce_buttons', 'wpAppbox_addCombinedButton' ); |
| 97 |
} |
| 98 |
else { |
| 99 |
add_filter( 'mce_buttons_2', 'wpAppbox_addSingleButtons' ); |
| 100 |
add_filter( 'mce_buttons_2', 'wpAppbox_addCombinedButton' ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
wpAppbox_addTheButtons(); |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Script für den WP-Appbox-Button in die HTML-Ausgabe einbetten |
| 109 |
* |
| 110 |
* @since 4.1.14 |
| 111 |
* @change 4.1.15 |
| 112 |
* |
| 113 |
* @param array $buttons Buttons [WordPress] |
| 114 |
*/ |
| 115 |
|
| 116 |
function wpAppbox_addCombinedButtonHTML() { |
| 117 |
global $wpAppbox_combinedButton; |
| 118 |
if( empty( $wpAppbox_combinedButton ) ) return; |
| 119 |
echo( '<script type="text/javascript"> |
| 120 |
var wpappbox_combined_button = '.json_encode( $wpAppbox_combinedButton ).'; |
| 121 |
</script>'); |
| 122 |
} |
| 123 |
|
| 124 |
add_action( 'admin_print_footer_scripts', 'wpAppbox_addCombinedButtonHTML' ); |
| 125 |
|
| 126 |
|
| 127 |
/** |
| 128 |
* Buttons zum TinyMCE-Editor (HTML-Ansicht) hinzufügen |
| 129 |
* |
| 130 |
* @since 2.0.0 |
| 131 |
* @change 4.4.6 |
| 132 |
* |
| 133 |
* @echo string Ausgabe des Scripts innerhalb TinyMCE |
| 134 |
*/ |
| 135 |
|
| 136 |
function wpAppbox_addButtonsHTML() { |
| 137 |
if ( !is_admin() ) return; |
| 138 |
global $wpAppbox_storeNames; |
| 139 |
$defaultOption = get_option('wpAppbox_defaultButton'); |
| 140 |
if ( $defaultOption == '2' || !wp_script_is( 'quicktags' ) ) return; |
| 141 |
wp_add_inline_script( |
| 142 |
'quicktags', |
| 143 |
"QTags.addButton( 'htmlx_appstore', 'Appbox: AppStore', '[appbox appstore appid]', '', '', 'AppStore' );" |
| 144 |
); |
| 145 |
foreach ( $wpAppbox_storeNames as $storeID => $storeName ): |
| 146 |
if ( 'amazonapps' == $storeID && !get_option('wpAppbox_amaAPIuse') ) continue; |
| 147 |
if ( get_option('wpAppbox_buttonHTML_' . $storeID) || $defaultOption == '0' ): |
| 148 |
wp_add_inline_script( |
| 149 |
'quicktags', |
| 150 |
"QTags.addButton( 'htmlx_" . esc_html( $storeID ) . "', 'Appbox: " . esc_html( $storeID ) . "', '[appbox " . esc_html( $storeID ) . " appid]', '', '', '" . esc_html( $storeName ) . "' );" |
| 151 |
); |
| 152 |
endif; |
| 153 |
endforeach; |
| 154 |
} |
| 155 |
add_action( 'wp_enqueue_scripts', 'wpAppbox_addButtonsHTML' ); |
| 156 |
|
| 157 |
|
| 158 |
/** |
| 159 |
* Registrierung des Plugins für TinyMCE |
| 160 |
* |
| 161 |
* @since 2.0.0 |
| 162 |
* @change 4.2.0 |
| 163 |
* |
| 164 |
* @param array $plugin_array Plugin-Array [WordPress] |
| 165 |
* @return array $plugin_array Plugin-Array [WordPress] |
| 166 |
*/ |
| 167 |
|
| 168 |
function wpAppbox_registerButtons( $plugin_array ) { |
| 169 |
global $wpAppbox_storeNames; |
| 170 |
$option = get_option('wpAppbox_defaultButton'); |
| 171 |
if ( '2' != $option ): |
| 172 |
foreach ( $wpAppbox_storeNames as $storeID => $storeName ): |
| 173 |
if ( 'amazonapps' == $storeID && !get_option('wpAppbox_amaAPIuse') ) continue; |
| 174 |
if ( get_option("wpAppbox_buttonAppbox_$storeID") ) $isCombined = true; |
| 175 |
endforeach; |
| 176 |
$plugin_array['wpAppbox_CombinedButton'] = plugins_url( "/../editor/tinymce/buttons.min.js?ver=" . WPAPPBOX_PLUGIN_VERSION, __FILE__ ); |
| 177 |
$plugin_array["wpAppboxSingle"] = plugins_url( "/../editor/tinymce/buttons.min.js?ver=" . WPAPPBOX_PLUGIN_VERSION, __FILE__ ); |
| 178 |
return( $plugin_array ); |
| 179 |
endif; |
| 180 |
} |
| 181 |
|
| 182 |
add_filter( 'mce_external_plugins', "wpAppbox_registerButtons" ); |
| 183 |
|
| 184 |
|
| 185 |
?> |