PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.30.5
Advanced Ads – Ad Manager & AdSense v1.30.5
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / admin / includes / class-shortcode-creator.php
advanced-ads / admin / includes Last commit date
ad-health-notices.php 5 years ago class-ad-groups-list.php 4 years ago class-ad-network-ad-importer.php 6 years ago class-ad-network-ad-unit.php 6 years ago class-ad-network.php 4 years ago class-ad-type.php 4 years ago class-admin-upgrades.php 4 years ago class-licenses.php 4 years ago class-list-filters.php 4 years ago class-menu.php 4 years ago class-meta-box.php 4 years ago class-notices.php 4 years ago class-options.php 6 years ago class-overview-widgets.php 4 years ago class-settings.php 4 years ago class-shortcode-creator.php 5 years ago notices.php 4 years ago shortcode-creator-l10n.php 5 years ago
class-shortcode-creator.php
245 lines
1 <?php
2 /**
3 * Shortcode generator for TinyMCE editor
4 */
5 class Advanced_Ads_Shortcode_Creator {
6 /**
7 * Instance of this class.
8 *
9 * @var object
10 */
11 protected static $instance = null;
12
13 /**
14 * Advanced_Ads_Shortcode_Creator constructor.
15 */
16 private function __construct() {
17 add_action( 'init', array( $this, 'init' ) );
18 }
19
20 /**
21 * Return an instance of this class.
22 *
23 * @return object A single instance of this class.
24 */
25 public static function get_instance() {
26 // If the single instance hasn't been set, set it now.
27 if ( null === self::$instance ) {
28 self::$instance = new self();
29 }
30
31 return self::$instance;
32 }
33
34 /**
35 * Call needed hooks and functions
36 */
37 public function init() {
38 $options = Advanced_Ads::get_instance()->options();
39
40 if ( 'true' !== get_user_option( 'rich_editing' )
41 || ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_place_ads' ) )
42 || defined( 'ADVANCED_ADS_DISABLE_SHORTCODE_BUTTON' )
43 || apply_filters( 'advanced-ads-disable-shortcode-button', false )
44 ) {
45 return;
46 }
47
48 add_action( 'wp_ajax_advads_content_for_shortcode_creator', array( $this, 'get_content_for_shortcode_creator' ) );
49
50 // @see self::hooks_exist
51 add_filter( 'mce_buttons', array( $this, 'register_buttons' ) );
52 add_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ) );
53 add_action( 'wp_tiny_mce_init', array( $this, 'print_shortcode_plugin' ) );
54 add_action( 'print_default_editor_scripts', array( $this, 'print_shortcode_plugin' ) );
55 }
56
57 /**
58 * Check if needed actions and filters have not been removed by a plugin.
59 *
60 * @return array
61 */
62 private function hooks_exist() {
63 if (
64 (
65 has_action( 'wp_tiny_mce_init', array( $this, 'print_shortcode_plugin' ) )
66 || has_action( 'print_default_editor_scripts', array( $this, 'print_shortcode_plugin' ) )
67 )
68 && has_filter( 'mce_buttons', array( $this, 'register_buttons' ) )
69 && has_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ) ) ) {
70 return true;
71 }
72 return false;
73 }
74
75 /**
76 * Print shortcode plugin inline.
77 *
78 * @param array|null $mce_settings TinyMCE settings array.
79 */
80 public function print_shortcode_plugin( $mce_settings = array() ) {
81 static $printed = null;
82
83 if ( $printed !== null ) {
84 return;
85 }
86
87 $printed = true;
88
89 // The `tinymce` argument of the `wp_editor()` function is set to `false`.
90 if ( empty( $mce_settings ) && ! ( doing_action( 'print_default_editor_scripts' ) && user_can_richedit() ) ) {
91 return;
92 }
93
94 if ( ! $this->hooks_exist() ) {
95 return;
96 }
97
98 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
99 echo "<script>\n"
100 . $this->get_l10n() . "\n"
101 . file_get_contents( ADVADS_BASE_PATH . 'admin/assets/js/shortcode.js' ) . "\n"
102 . "</script>\n";
103 // phpcs:enable
104 }
105
106 /**
107 * Get localization strings.
108 *
109 * @return string
110 */
111 private function get_l10n() {
112 static $script = null;
113
114 if ( null === $script ) {
115 include_once ADVADS_BASE_PATH . 'admin/includes/shortcode-creator-l10n.php';
116 $script = $strings;
117 }
118
119 return $script;
120 }
121
122 /**
123 * Add the plugin to the array of default TinyMCE plugins.
124 * We do not use the array of external TinyMCE plugins because we print the plugin file inline.
125 *
126 * @see self::admin_enqueue_scripts
127 *
128 * @param array $plugins An array of default TinyMCE plugins.
129 * @return array $plugins An array of default TinyMCE plugins.
130 */
131 public function tiny_mce_plugins( $plugins ) {
132 if ( ! $this->hooks_exist() ) {
133 return $plugins;
134 }
135
136 $plugins[] = 'advads_shortcode';
137 return $plugins;
138 }
139
140 /**
141 * Include the shortcode plugin inline to prevent it from being blocked by ad blockers.
142 */
143 public function admin_enqueue_scripts() {
144 // Add the localization.
145 include_once ADVADS_BASE_PATH . 'admin/includes/shortcode-creator-l10n.php';
146 $script = $strings . "\n";
147 // Add the plugin.
148 $script .= file_get_contents( ADVADS_BASE_PATH . 'admin/assets/js/shortcode.js' );
149
150 wp_add_inline_script( 'wp-tinymce', $script );
151 }
152
153 /**
154 * Add button to tinyMCE window
155 *
156 * @param array $buttons array with existing buttons.
157 *
158 * @return array
159 */
160 public function register_buttons( $buttons ) {
161 if ( ! $this->hooks_exist() ) {
162 return $buttons;
163 }
164 if ( ! is_array( $buttons ) ) {
165 $buttons = array();
166 }
167 $buttons[] = 'advads_shortcode_button';
168 return $buttons;
169 }
170
171 /**
172 * Prints html select field for shortcode creator
173 */
174 public function get_content_for_shortcode_creator() {
175 if ( ! ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) ) {
176 return;
177 }
178
179 $items = self::items_for_select(); ?>
180
181 <select id="advads-select-for-shortcode">
182 <option value=""><?php esc_html_e( '--empty--', 'advanced-ads' ); ?></option>
183 <?php if ( isset( $items['ads'] ) ) : ?>
184 <optgroup label="<?php esc_html_e( 'Ads', 'advanced-ads' ); ?>">
185 <?php foreach ( $items['ads'] as $_item_id => $_item_title ) : ?>
186 <option value="<?php echo esc_attr( $_item_id ); ?>"><?php echo esc_html( $_item_title ); ?></option>
187 <?php endforeach; ?>
188 </optgroup>
189 <?php endif; ?>
190 <?php if ( isset( $items['groups'] ) ) : ?>
191 <optgroup label="<?php esc_html_e( 'Ad Groups', 'advanced-ads' ); ?>">
192 <?php foreach ( $items['groups'] as $_item_id => $_item_title ) : ?>
193 <option value="<?php echo esc_attr( $_item_id ); ?>"><?php echo esc_html( $_item_title ); ?></option>
194 <?php endforeach; ?>
195 </optgroup>
196 <?php endif; ?>
197 <?php if ( isset( $items['placements'] ) ) : ?>
198 <optgroup label="<?php esc_html_e( 'Placements', 'advanced-ads' ); ?>">
199 <?php foreach ( $items['placements'] as $_item_id => $_item_title ) : ?>
200 <option value="<?php echo esc_attr( $_item_id ); ?>"><?php echo esc_html( $_item_title ); ?></option>
201 <?php endforeach; ?>
202 </optgroup>
203 <?php endif; ?>
204 </select>
205 <?php
206 exit();
207 }
208
209 /**
210 * Get items for item select field
211 *
212 * @return array $select items for select field.
213 */
214 public static function items_for_select() {
215 $select = array();
216 $model = Advanced_Ads::get_instance()->get_model();
217
218 // load all ads.
219 $ads = $model->get_ads(
220 array(
221 'orderby' => 'title',
222 'order' => 'ASC',
223 )
224 );
225 foreach ( $ads as $_ad ) {
226 $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
227 }
228
229 // load all ad groups.
230 $groups = $model->get_ad_groups();
231 foreach ( $groups as $_group ) {
232 $select['groups'][ 'group_' . $_group->term_id ] = $_group->name;
233 }
234
235 // load all placements.
236 $placements = $model->get_ad_placements_array();
237 ksort( $placements );
238 foreach ( $placements as $key => $_placement ) {
239 $select['placements'][ 'placement_' . $key ] = $_placement['name'];
240 }
241
242 return $select;
243 }
244 }
245