PluginProbe
Wp-Insert / 2.6.0
Wp-Insert v2.6.0
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / includes / modules / core / units / module.php

module.php in Wp-Insert 2.6.0, at includes/modules/core/units/module.php

195 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /* Begin Include Files */
3 require_once __DIR__ . '/adunit.php';
4 require_once __DIR__ . '/adcode.php';
5 require_once __DIR__ . '/device-styles.php';
6 if ( ! class_exists( 'iriven\\GeoIPCountry' ) ) {
7 require_once __DIR__ . '/GeoIp/GeoIPCountry.php';
8 }
9 require_once __DIR__ . '/geo-targeting.php';
10 require_once __DIR__ . '/notes.php';
11 require_once __DIR__ . '/rules.php';
12 /* End Include Files */
13
14 /* Begin Add Assets */
15 add_action( 'wp_insert_modules_js', 'wp_insert_module_adform_js', 0 );
16 function wp_insert_module_adform_js() {
17 wp_register_script( 'wp-insert-module-adform-js', WP_INSERT_URL . 'includes/modules/core/units/js/module.js', [ 'wp-insert-js' ], WP_INSERT_VERSION . ( ( WP_INSERT_DEBUG ) ? wp_rand( 0, 9999 ) : '' ), true );
18 wp_enqueue_script( 'wp-insert-module-adform-js' );
19 }
20 /* End Add Assets */
21
22 /* Begin Get Admin Panel Card*/
23 function wp_insert_get_plugin_card( $title, $description, $type, $preTitle ) {
24 echo '<div class="plugin-card">';
25 echo '<div class="plugin-card-top">';
26 echo '<h4>' . esc_html( $title ) . '</h4>';
27 echo wp_kses_post( $description );
28 echo '</div>';
29 echo '<div class="plugin-card-bottom">';
30 $data = get_option( 'wp_insert_' . $type );
31 if ( isset( $data ) && is_array( $data ) ) {
32 foreach ( $data as $key => $value ) {
33 /* Begin Workaround for migrating old users to new system (can be removed in a later version) */
34 $title = $key;
35 if ( ! isset( $value['title'] ) || ( $value['title'] == '' ) ) {
36 switch ( $key ) {
37 case 'above':
38 $title = 'Above Post Content';
39 break;
40 case 'middle':
41 $title = 'Middle of Post Content';
42 break;
43 case 'below':
44 $title = 'Below Post Content';
45 break;
46 case 'left':
47 $title = 'To the Left of Post Content';
48 break;
49 case 'right':
50 $title = 'To the Right of Post Content';
51 break;
52 }
53 } else {
54 $title = $value['title'];
55 }
56 $title = sanitize_text_field( $title );
57 /* End Workaround for migrating old users to new system (can be removed in a later version) */
58 // Titles and keys are interpolated into inline JS handler arguments,
59 // so they are escaped for a JS string context, not just for HTML.
60 $jsTitle = esc_js( $title );
61 $jsKey = esc_js( $key );
62 $jsType = esc_js( $type );
63 echo '<p>';
64 echo '<a class="wp_insert_ad_unit_title" title="Edit Ad Unit" id="wp_insert_' . esc_attr( $type . '_ad_' . $key ) . '" href="javascript:;" data-pre-title="' . esc_attr( $preTitle ) . '" onclick="wp_insert_ads_click_handler(\'' . esc_attr( $jsType ) . '\', \'' . esc_attr( $jsKey ) . '\', \'' . esc_attr( $jsTitle ) . '\', false)">' . esc_html( $preTitle . ' : ' . $title ) . '</a>';
65 echo '<span class="dashicons dashicons-no wp_insert_delete_icon" title="Delete Ad Unit" onclick="wp_insert_ad_delete_handler(\'' . esc_attr( $jsType ) . '\', \'' . esc_attr( $jsKey ) . '\')"></span>';
66 echo '<span class="dashicons dashicons-format-gallery wp_insert_duplicate_icon" title="Duplicate Ad Unit" onclick="wp_insert_ads_click_handler(\'' . esc_attr( $jsType ) . '\', \'###DUPLICATE###' . esc_attr( $jsKey ) . '\', \'' . esc_attr( $jsTitle ) . ' Duplicate\', true)"></span>';
67 echo '</p>';
68 }
69 }
70 echo '<p style="text-align: center; padding: 20px 0 10px;"><a id="wp_insert_' . esc_attr( $type ) . '_ad_new" data-pre-title="' . esc_attr( $preTitle ) . '" href="#" class="button-secondary" onclick="wp_insert_ads_click_handler(\'' . esc_attr( esc_js( $type ) ) . '\', \'new\', \'Add New\', true)">Add New</a></p>';
71 echo '</div>';
72 echo '</div>';
73 }
74 /* End Get Admin Panel Card*/
75
76 /* Begin Get Ad Form */
77 function wp_insert_get_ad_form( $script = '' ) {
78 check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
79 if ( ! current_user_can( 'manage_options' ) ) {
80 wp_die( -1, 403 );
81 }
82 if ( isset( $_POST['wp_insert_identifier'] ) && isset( $_POST['wp_insert_type'] ) ) {
83 $type = sanitize_key( wp_unslash( $_POST['wp_insert_type'] ) );
84 if ( ! in_array( $type, wp_insert_get_ad_unit_types(), true ) ) {
85 wp_die( -1, 400 );
86 }
87 $requestIdentifier = sanitize_text_field( wp_unslash( $_POST['wp_insert_identifier'] ) );
88 $data = get_option( 'wp_insert_' . $type );
89
90 $identifier = substr( str_shuffle( str_repeat( 'abcdefghijklmnopqrstuvwxyz', 5 ) ), 0, 5 ) . uniqid();
91 $dataIdentifier = $identifier;
92 if ( strpos( $requestIdentifier, '###DUPLICATE###' ) !== false ) {
93 $dataIdentifier = sanitize_key( str_replace( '###DUPLICATE###', '', $requestIdentifier ) );
94 if ( isset( $data[ $dataIdentifier ] ) ) {
95 $data[ $dataIdentifier ]['title'] = ( $data[ $dataIdentifier ]['title'] ?? '' ) . ' (Duplicate)';
96 }
97 } elseif ( $requestIdentifier != 'new' ) {
98 $identifier = sanitize_key( $requestIdentifier );
99 $dataIdentifier = $identifier;
100 }
101
102 echo '<div class="wp_insert_popup_content_wrapper">';
103 $control = new smartlogixControls(
104 [
105 'optionIdentifier' => 'wp_insert_' . $type . '[' . $identifier . ']',
106 'values' => ( ( isset( $data[ $dataIdentifier ] ) && is_array( $data[ $dataIdentifier ] ) ) ? $data[ $dataIdentifier ] : [] ),
107 ]
108 );
109 $control->add_control(
110 [
111 'type' => 'ipCheckbox',
112 'className' => 'wp_insert_' . $type . '_status',
113 'optionName' => 'status',
114 ]
115 );
116 $control->add_control(
117 [
118 'type' => 'hidden',
119 'className' => 'wp_insert_' . $type . '_identifier',
120 'optionName' => 'identifier',
121 'value' => $identifier,
122 ]
123 );
124 wp_insert_echo_html( $control->HTML );
125 $control->clear_controls();
126 echo '<div id="wp_insert_' . esc_attr( $type . '_' . $identifier ) . '_accordion">';
127 $control = apply_filters( 'wp_insert_' . $type . '_form_accordion_tabs', $control, $identifier, $type );
128 echo '</div>';
129 echo '<script type="text/javascript">';
130 wp_insert_echo_html( $control->JS );
131 echo 'jQuery("#wp_insert_' . esc_js( $type . '_' . $identifier ) . '_accordion").accordion({ icons: { header: "ui-icon-circle-arrow-e", activeHeader: "ui-icon-circle-arrow-s" }, heightStyle: "auto" });';
132 if ( $script != '' ) {
133 // $script is a plugin-authored JS snippet (module.php literals only);
134 // the identifier substituted into it is sanitize_key()'d above.
135 wp_insert_echo_html( str_replace( '###IDENTIFIER###', $identifier, $script ) );
136 }
137 echo '</script>';
138 echo '</div>';
139 }
140 wp_die();
141 }
142 /* End Get Ad Form */
143
144 /* Begin Save Ad Data */
145 function wp_insert_save_ad_data() {
146 check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
147 if ( ! current_user_can( 'manage_options' ) ) {
148 wp_die( -1, 403 );
149 }
150 $type = ( isset( $_POST['wp_insert_type'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_type'] ) ) : '' );
151 $identifier = ( isset( $_POST['wp_insert_identifier'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_identifier'] ) ) : '' );
152 if ( ( $identifier != '' ) && in_array( $type, wp_insert_get_ad_unit_types(), true ) && ( isset( $_POST['wp_insert_parameters'] ) && is_array( $_POST['wp_insert_parameters'] ) ) ) {
153 $parameters = array_map( 'sanitize_key', wp_unslash( $_POST['wp_insert_parameters'] ) );
154 $data = get_option( 'wp_insert_' . $type );
155 if ( ! is_array( $data ) ) {
156 $data = [];
157 }
158 foreach ( $parameters as $parameter ) {
159 $field = str_replace( [ 'wp_insert_', $type . '_', $identifier . '_' ], '', $parameter );
160 // Ad code must reach the option table unmodified for unfiltered_html
161 // users; wp_insert_sanitize_ad_field() handles the per-field rules.
162 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
163 $data[ $identifier ][ $field ] = wp_insert_sanitize_ad_field( $field, ( ( isset( $_POST[ $parameter ] ) ) ? $_POST[ $parameter ] : '' ) );
164 }
165 update_option( 'wp_insert_' . $type, $data );
166
167 if ( function_exists( 'wp_insert_adstxt_adsense_admin_notice_reset' ) ) {
168 wp_insert_adstxt_adsense_admin_notice_reset();
169 }
170 }
171 wp_die();
172 }
173 /* End Save Ad Data */
174
175 /* Begin Delete Ad Data */
176 function wp_insert_delete_ad_data() {
177 check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
178 if ( ! current_user_can( 'manage_options' ) ) {
179 wp_die( -1, 403 );
180 }
181 $type = ( isset( $_POST['wp_insert_type'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_type'] ) ) : '' );
182 $identifier = ( isset( $_POST['wp_insert_identifier'] ) ? sanitize_key( wp_unslash( $_POST['wp_insert_identifier'] ) ) : '' );
183 if ( ( $identifier != '' ) && in_array( $type, wp_insert_get_ad_unit_types(), true ) ) {
184 $data = get_option( 'wp_insert_' . $type );
185 unset( $data[ $identifier ] );
186 update_option( 'wp_insert_' . $type, $data );
187
188 if ( function_exists( 'wp_insert_adstxt_adsense_admin_notice_reset' ) ) {
189 wp_insert_adstxt_adsense_admin_notice_reset();
190 }
191 }
192 wp_die();
193 }
194 /* End Delete Ad Data */
195