PluginProbe
Wp-Insert / trunk
Wp-Insert vtrunk
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 / adstxt / module.php

module.php in Wp-Insert trunk, at includes/modules/core/adstxt/module.php

189 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once __DIR__ . '/adsense.php';
3
4 /* Begin Add Assets */
5 add_action( 'wp_insert_modules_js', 'wp_insert_module_adstxt_js', 0 );
6 function wp_insert_module_adstxt_js() {
7 wp_register_script( 'wp-insert-module-adstxt-js', WP_INSERT_URL . 'includes/modules/core/adstxt/js/module.js', [ 'wp-insert-js' ], WP_INSERT_VERSION . ( ( WP_INSERT_DEBUG ) ? wp_rand( 0, 9999 ) : '' ), true );
8 wp_enqueue_script( 'wp-insert-module-adstxt-js' );
9 }
10 /* End Add Assets */
11
12 /* Begin Add Card in Admin Panel */
13 add_action( 'wp_insert_plugin_card', 'wp_insert_adstxt_plugin_card', 100 );
14 function wp_insert_adstxt_plugin_card() {
15 echo '<div class="plugin-card adstxt-card">';
16 echo '<div class="plugin-card-top">';
17 echo '<h4>Authorized Digital Sellers / ads.txt</h4>';
18 echo '<p>Authorized Digital Sellers, or ads.txt, is an <a href="https://iabtechlab.com/">IAB</a> initiative to improve transparency in programmatic advertising.</p>';
19 echo '<p>You can easily manage your ads.txt from within Wp-Insert, providing confidence to brands they are buying authentic publisher inventory, protect you from counterfiet inventory and might even lead to higher monetization for your ad invertory.</p>';
20 echo '</div>';
21 echo '<div class="plugin-card-bottom">';
22 if ( wp_insert_adstxt_file_exists() ) {
23 echo '<a id="wp_insert_adstxt_generate" href="javascript:;" class="button button-primary">Modify ads.txt</a>';
24 } else {
25 echo '<a id="wp_insert_adstxt_generate" href="javascript:;" class="button button-primary">Generate ads.txt</a>';
26 }
27 echo '</div>';
28 echo '</div>';
29 }
30 /* End Add Card in Admin Panel */
31
32 /* Begin Create Ads.txt */
33 add_action( 'wp_ajax_wp_insert_adstxt_generate_form_get_content', 'wp_insert_adstxt_generate_form_get_content' );
34 function wp_insert_adstxt_generate_form_get_content() {
35 check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
36 echo '<div class="wp_insert_popup_content_wrapper">';
37 echo '<div id="wp_insert_adstxt_accordion">';
38 $control = new smartlogixControls();
39 echo '<h3>ads.txt Content</h3>';
40 echo '<div>';
41 $control->add_control(
42 [
43 'type' => 'textarea',
44 'id' => 'wp_insert_adstxt_content',
45 'name' => 'wp_insert_adstxt_content',
46 'style' => 'height: 220px;',
47 'value' => wp_insert_adstxt_get_content(),
48 'helpText' => 'You can directly edit the entries here or you can use the entry generator below to quickly create new entries',
49 ]
50 );
51 $control->create_section( 'ads.txt Content' );
52 wp_insert_echo_html( $control->HTML );
53 $control->clear_controls();
54 echo '</div>';
55 echo '<h3>Entry Generator</h3>';
56 echo '<div>';
57 $control->add_control(
58 [
59 'type' => 'text',
60 'id' => 'wp_insert_adstxt_new_entry_domain',
61 'name' => 'wp_insert_adstxt_new_entry_domain',
62 'label' => 'Domain name of the advertising system <small style="font-size: 10px;">(Required)</small>',
63 'value' => '',
64 'helpText' => 'For Google Adsense Use "google.com"; for other networks, contact your service provider for values.',
65 ]
66 );
67 $control->add_control(
68 [
69 'type' => 'text',
70 'id' => 'wp_insert_adstxt_new_entry_pid',
71 'name' => 'wp_insert_adstxt_new_entry_pid',
72 'label' => 'Publisher’s Account ID <small style="font-size: 10px;">(Required)</small>',
73 'value' => '',
74 'helpText' => 'For Google Adsense Use your Publisher ID "pub-xxxxxxxxxxxxxxxx"; for other networks, contact your service provider for values.',
75 ]
76 );
77 $control->add_control(
78 [
79 'type' => 'select',
80 'id' => 'wp_insert_adstxt_new_entry_type',
81 'name' => 'wp_insert_adstxt_new_entry_type',
82 'label' => 'Type of Account / Relationship <small style="font-size: 10px;">(Required)</small>',
83 'value' => '',
84 'options' => [
85 [
86 'text' => 'Direct',
87 'value' => 'DIRECT',
88 ],
89 [
90 'text' => 'Reseller',
91 'value' => 'RESELLER',
92 ],
93 ],
94 'helpText' => 'For Google Adsense select "Reseller"; for other networks, contact your service provider for values.',
95 ]
96 );
97 $control->add_control(
98 [
99 'type' => 'text',
100 'id' => 'wp_insert_adstxt_new_entry_certauthority',
101 'name' => 'wp_insert_adstxt_new_entry_certauthority',
102 'label' => 'Certification Authority ID',
103 'value' => '',
104 'helpText' => 'Contact your service provider for values.',
105 ]
106 );
107 $control->HTML .= '<p><input id="wp_insert_adstxt_add_entry" onclick="wp_insert_adstxt_add_entry()" type="button" value="Add Entry" class="button button-primary" /></p>';
108 $control->create_section( 'Entry Generator' );
109 wp_insert_echo_html( $control->HTML );
110 echo '</div>';
111 echo '</div>';
112 echo '<script type="text/javascript">';
113 wp_insert_echo_html( $control->JS );
114 echo 'jQuery("#wp_insert_adstxt_accordion").accordion({ icons: { header: "ui-icon-circle-arrow-e", activeHeader: "ui-icon-circle-arrow-s" }, heightStyle: "fill" });';
115 echo '</script>';
116 echo '</div>';
117 wp_die();
118 }
119 /* End Create Ads.txt */
120
121 /* Begin Update Ads.txt */
122 add_action( 'wp_ajax_wp_insert_adstxt_generate_form_save_action', 'wp_insert_adstxt_generate_form_save_action' );
123 function wp_insert_adstxt_generate_form_save_action() {
124 check_ajax_referer( 'wp-insert', 'wp_insert_nonce' );
125 $content = ( ( isset( $_POST['wp_insert_adstxt_content'] ) ) ? sanitize_textarea_field( wp_unslash( $_POST['wp_insert_adstxt_content'] ) ) : '' );
126 $output = wp_insert_adstxt_updation_failed_message( $content );
127 $output .= '<script type="text/javascript">';
128 $output .= 'jQuery(".ui-dialog-buttonset").find("button").first().hide();';
129 $output .= '</script>';
130
131 if ( wp_insert_adstxt_update_content( $content ) ) {
132 echo '###SUCCESS###';
133 } else {
134 wp_insert_echo_html( $output );
135 }
136 wp_die();
137 }
138 /* End Update Ads.txt */
139
140 /* Begin Common Functions */
141 function wp_insert_adstxt_file_exists() {
142 if ( file_exists( trailingslashit( get_home_path() ) . 'ads.txt' ) ) {
143 return true;
144 }
145 return false;
146 }
147
148 function wp_insert_adstxt_get_content() {
149 if ( wp_insert_adstxt_file_exists() ) {
150 global $wp_filesystem;
151 if ( ! $wp_filesystem ) {
152 require_once ABSPATH . 'wp-admin/includes/file.php';
153 WP_Filesystem();
154 }
155 $contents = $wp_filesystem->get_contents( trailingslashit( get_home_path() ) . 'ads.txt' );
156 return ( false === $contents ) ? '' : $contents;
157 }
158 return '';
159 }
160
161 function wp_insert_adstxt_update_content( $content ) {
162 wp_insert_adstxt_adsense_admin_notice_reset();
163 if ( get_filesystem_method() === 'direct' ) {
164 $creds = request_filesystem_credentials( site_url() . '/wp-admin/', '', false, false, [] );
165 if ( ! WP_Filesystem( $creds ) ) {
166 return false;
167 }
168 global $wp_filesystem;
169 if ( ! $wp_filesystem->put_contents( trailingslashit( get_home_path() ) . 'ads.txt', $content, FS_CHMOD_FILE ) ) {
170 return false;
171 }
172 } else {
173 return false;
174 }
175 return true;
176 }
177
178 function wp_insert_adstxt_updation_failed_message( $content ) {
179 $output = '<div class="wp_insert_popup_content_wrapper">';
180 $output .= '<p>Auto Creation / Updation of ads.txt failed due to access permission restrictions on the server.</p>';
181 $output .= '<p>You have to manually upload the file using your Host\'s File manager or your favourite FTP program</p>';
182 $output .= '<p>ads.txt should be located in the root of your server. After manually uploading the file click <a href="' . site_url() . '/ads.txt">here</a> to check if its accessible from the correct location</p>';
183 $output .= '<textarea style="display: none;" id="wp_insert_adstxt_content">' . esc_textarea( $content ) . '</textarea>';
184 $output .= '<p><a onclick="wp_insert_adstxt_content_download()" class="button button-primary" href="javascript:;">Download ads.txt</a></p>';
185 $output .= '</div>';
186 return $output;
187 }
188 /* End Common Functions */
189