settings
5 years ago
adsense-account.php
1 year ago
adsense-ad-parameters.php
5 months ago
adsense-report.php
3 years ago
auto-ads-video.php
6 years ago
borlabs-cookie-auto-ads-warning.php
3 years ago
connect-adsense.php
1 year ago
external-ads-adsense.php
6 years ago
external-ads-links.php
1 year ago
external-ads-list.php
1 year ago
adsense-ad-parameters.php
199 lines
| 1 | <?php // phpcs:ignoreFile |
| 2 | |
| 3 | /** |
| 4 | * Renders the AdSense ad parameters metabox on the ad edit page. |
| 5 | * |
| 6 | * @package AdvancedAds |
| 7 | * @author Advanced Ads <info@wpadvancedads.com> |
| 8 | * |
| 9 | * @var string $unit_type The type of the AdSense unit, e.g. 'responsive'. |
| 10 | * @var string $unit_resize The value of the resize option. |
| 11 | * @var string $unit_id The client ID. |
| 12 | * @var string $unit_code The slot ID. |
| 13 | * @var string $unit_pubid The publisher ID which differs if there comes a different it from the content. |
| 14 | * @var string $json_content The content as JSON. |
| 15 | * @var string $pub_id The publisher ID. |
| 16 | * @var Advanced_Ads_Ad_Type_Adsense $ad The AdSense Ad type. |
| 17 | * @var string $pub_id_errors A string with error messages. |
| 18 | * @var string $content The content. |
| 19 | * @var array $extra_params Filterable extra params that can be passed. |
| 20 | */ |
| 21 | |
| 22 | if ( ! defined( 'WPINC' ) ) { |
| 23 | die(); |
| 24 | } |
| 25 | $is_responsive = 'responsive' === $unit_type; |
| 26 | $is_link_responsive_unit = 'link-responsive' === $unit_type; |
| 27 | $is_matched_content = 'matched-content' === $unit_type; |
| 28 | $use_manual_css = 'manual' === $unit_resize; |
| 29 | if ( $is_responsive || $is_link_responsive_unit || $is_matched_content ) { |
| 30 | echo '<style> #advanced-ads-ad-parameters-size {display: none;} </style>'; |
| 31 | } |
| 32 | |
| 33 | $MAPI = Advanced_Ads_AdSense_MAPI::get_instance(); |
| 34 | $use_user_app = Advanced_Ads_AdSense_MAPI::use_user_app(); |
| 35 | |
| 36 | $use_paste_code = true; |
| 37 | $use_paste_code = apply_filters( 'advanced-ads-gadsense-use-pastecode', $use_paste_code ); |
| 38 | |
| 39 | $db = Advanced_Ads_AdSense_Data::get_instance(); |
| 40 | $adsense_id = trim( $db->get_adsense_id() ); |
| 41 | $sizing_array = $db->get_responsive_sizing(); |
| 42 | |
| 43 | $gadsense_options = $db->get_options(); |
| 44 | $mapi_options = Advanced_Ads_AdSense_MAPI::get_option(); |
| 45 | $mapi_nonce = wp_create_nonce( 'advads-mapi' ); |
| 46 | $has_token = Advanced_Ads_AdSense_MAPI::has_token( $adsense_id ); |
| 47 | $quota = $MAPI->get_quota(); |
| 48 | |
| 49 | $mapi_ad_codes = $mapi_options['ad_codes']; |
| 50 | $mapi_ad_codes['length'] = count( $mapi_ad_codes ); |
| 51 | ?> |
| 52 | <?php if ( $has_token ) : ?> |
| 53 | <script type="text/javascript"> |
| 54 | if ( 'undefined' == typeof window.AdsenseMAPI ) { |
| 55 | var AdsenseMAPI = {}; |
| 56 | } |
| 57 | AdsenseMAPI.hasToken = true; |
| 58 | AdsenseMAPI.nonce = '<?php echo $mapi_nonce ?>'; |
| 59 | //AdsenseMAPI.codes = <?php echo json_encode( $mapi_ad_codes ) ?>; |
| 60 | AdsenseMAPI.quota = <?php echo json_encode( $quota ) ?>; |
| 61 | AdsenseMAPI.pubId = '<?php echo $pub_id ?>'; |
| 62 | AdsenseMAPI.adStatus = '<?php echo $ad->get_status() ?>'; |
| 63 | AdsenseMAPI.unsupportedUnits = <?php echo wp_json_encode( $mapi_options['unsupported_units'] ); ?>; |
| 64 | </script> |
| 65 | <?php endif; ?> |
| 66 | |
| 67 | <script type="text/javascript"> |
| 68 | if ( 'undefined' === typeof gadsenseData ) { |
| 69 | window.gadsenseData = {}; |
| 70 | } |
| 71 | gadsenseData['pubId'] = '<?php echo $adsense_id; ?>'; |
| 72 | gadsenseData['msg'] = { |
| 73 | unknownAd: '<?php esc_attr_e( "The ad details couldn't be retrieved from the ad code", 'advanced-ads' ); ?>', |
| 74 | pubIdMismatch: '<?php esc_attr_e( 'Warning: The AdSense account from this code does not match the one set in the Advanced Ads options.', 'advanced-ads' ); ?>' |
| 75 | }; |
| 76 | </script> |
| 77 | |
| 78 | <input type="hidden" id="advads-ad-content-adsense" name="advanced_ad[content]" value="<?php echo esc_attr( $json_content ); ?>"/> |
| 79 | <input type="hidden" name="unit_id" id="unit_id" value="<?php echo esc_attr( $unit_id ); ?>"/> |
| 80 | <?php if ( $use_paste_code ) : ?> |
| 81 | <div class="advads-adsense-code" style="display: none;"> |
| 82 | <p class="description"><?php _e( 'Copy the ad code from your AdSense account, paste it into the area below and click on <em>Get details</em>.', 'advanced-ads' ); ?></p> |
| 83 | <textarea rows="10" cols="40" class="advads-adsense-content"></textarea> |
| 84 | <button class="button button-primary advads-adsense-submit-code"><?php _e( 'Get details', 'advanced-ads' ); ?></button> |
| 85 | <button class="button button-secondary advads-adsense-close-code"><?php _e( 'cancel', 'advanced-ads' ); ?></button> |
| 86 | <?php if ( ! $has_token ) : ?> |
| 87 | <a style="vertical-align:sub;font-weight:600;font-style:italic;" href="<?php echo admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ?>"><?php _e( 'connect to your AdSense account', 'advanced-ads' ) ?></a> |
| 88 | <?php endif; ?> |
| 89 | <div id="pastecode-msg"></div> |
| 90 | </div> |
| 91 | <?php if ( $has_token && Advanced_Ads_Checks::php_version_minimum() ) { |
| 92 | Advanced_Ads_AdSense_Admin::get_mapi_ad_selector(); |
| 93 | } |
| 94 | |
| 95 | // the network variable needs to be set for the view to work! |
| 96 | $network = Advanced_Ads_Network_Adsense::get_instance(); |
| 97 | include( ADVADS_ABSPATH . '/modules/gadsense/admin/views/external-ads-links.php' ); |
| 98 | ?> |
| 99 | <?php endif; ?> |
| 100 | <p id="adsense-ad-param-error"></p> |
| 101 | <?php ob_start(); ?> |
| 102 | <label class="label"><?php _e( 'Ad Slot ID', 'advanced-ads' ); ?></label> |
| 103 | <div> |
| 104 | <input type="text" name="unit-code" id="unit-code" value="<?php echo $unit_code; ?>"/> |
| 105 | <input type="hidden" name="advanced_ad[output][adsense-pub-id]" id="advads-adsense-pub-id" value="<?php echo esc_attr( $unit_pubid ); ?>"/> |
| 106 | <?php if ( $unit_pubid ) : ?> |
| 107 | <?php /* translators: %s is the publisher ID. */ |
| 108 | printf( __( 'Publisher ID: %s', 'advanced-ads' ), $unit_pubid ); ?> |
| 109 | <?php endif; ?> |
| 110 | <p id="advads-pubid-in-slot" class="advads-notice-inline advads-error" |
| 111 | <?php echo ! ( 0 === strpos( $pub_id, 'pub-' ) && false !== strpos( $unit_code, substr( $pub_id, 4 ) ) ) ? 'style="display:none"' : ''; ?> |
| 112 | ><?php _e( 'The ad slot ID is either a number or empty and not the same as the publisher ID.', 'advanced-ads' ) ?></p> |
| 113 | </div> |
| 114 | <hr/> |
| 115 | <?php |
| 116 | $unit_code_markup = ob_get_clean(); |
| 117 | echo apply_filters( 'advanced-ads-gadsense-unit-code-markup', $unit_code_markup, $unit_code ); |
| 118 | if ( $pub_id_errors ) : ?> |
| 119 | <p> |
| 120 | <span class="advads-notice-inline advads-error"> |
| 121 | <?php echo $pub_id_errors; ?> |
| 122 | </span> |
| 123 | <?php /* translators: %s the setting page link */ |
| 124 | printf( __( 'Please <a href="%s" target="_blank">change it here</a>.', 'advanced-ads' ), admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ); ?> |
| 125 | </p> |
| 126 | <?php endif; ?> |
| 127 | <label class="label" id="unit-type-block"><?php _e( 'Type', 'advanced-ads' ); ?></label> |
| 128 | <div> |
| 129 | <select name="unit-type" id="unit-type"> |
| 130 | <option value="normal" <?php selected( $unit_type, 'normal' ); ?>><?php _e( 'Fixed Size', 'advanced-ads' ); ?></option> |
| 131 | <option value="responsive" <?php selected( $unit_type, 'responsive' ); ?>><?php _e( 'Responsive', 'advanced-ads' ); ?></option> |
| 132 | <option value="matched-content" <?php selected( $unit_type, 'matched-content' ); ?>><?php esc_html_e( 'Multiplex', 'advanced-ads' ); ?></option> |
| 133 | <?php if ( $unit_type === 'link' ) : ?> |
| 134 | <option value="link" <?php selected( $unit_type, 'link' ); ?>><?php _e( 'Link ads', 'advanced-ads' ); ?></option> |
| 135 | <?php endif; ?> |
| 136 | <?php if ( $unit_type === 'link-responsive' ) : ?> |
| 137 | <option value="link-responsive" <?php selected( $unit_type, 'link-responsive' ); ?>><?php _e( 'Link ads (Responsive)', 'advanced-ads' ); ?></option> |
| 138 | <?php endif; ?> |
| 139 | <option value="in-article" <?php selected( $unit_type, 'in-article' ); ?>><?php _e( 'In-article', 'advanced-ads' ); ?></option> |
| 140 | <option value="in-feed" <?php selected( $unit_type, 'in-feed' ); ?>><?php _e( 'In-feed', 'advanced-ads' ); ?></option> |
| 141 | </select> |
| 142 | <a href="https://wpadvancedads.com/google-adsense-ad-formats/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-ad-types" class="advads-manual-link" target="_blank"><?php esc_html_e( 'Manual', 'advanced-ads' ); ?></a> |
| 143 | </div> |
| 144 | <?php if ( in_array( $unit_type, [ 'link', 'link-responsive' ], true ) ) : ?> |
| 145 | <p class="advads-message-warning"><?php esc_html_e( 'Google AdSense deprecated Link Units. Please choose another type.', 'advanced-ads' ); ?> |
| 146 | <a href="https://wpadvancedads.com/adsense-link-units/" target="_blank" rel="noopener"> |
| 147 | <?php esc_html_e( 'Learn more', 'advanced-ads' ); ?> |
| 148 | </a> |
| 149 | </p> |
| 150 | <?php endif; ?> |
| 151 | <hr/> |
| 152 | <label class="label" <?php if ( ! $is_responsive || 2 > count( $sizing_array ) ) { |
| 153 | echo 'style="display: none;"'; |
| 154 | } ?> id="resize-label"><?php _e( 'Resizing', 'advanced-ads' ); ?></label> |
| 155 | <div <?php if ( ! $is_responsive || 2 > count( $sizing_array ) ) { |
| 156 | echo 'style="display: none;"'; |
| 157 | } ?>> |
| 158 | <select name="ad-resize-type" id="ad-resize-type"> |
| 159 | <?php foreach ( $sizing_array as $key => $desc ) : ?> |
| 160 | <option value="<?php echo $key; ?>" <?php selected( $key, $unit_resize ); ?>><?php echo $desc; ?></option> |
| 161 | <?php endforeach; ?> |
| 162 | </select> |
| 163 | </div> |
| 164 | <hr> |
| 165 | <label class="label advads-adsense-layout" <?php if ( 'in-feed' !== $unit_type ) { |
| 166 | echo 'style="display: none;"'; |
| 167 | } ?> id="advads-adsense-layout"><?php _e( 'Layout', 'advanced-ads' ); ?></label> |
| 168 | <div <?php if ( 'in-feed' !== $unit_type ) { |
| 169 | echo 'style="display: none;"'; |
| 170 | } ?>> |
| 171 | <input name="ad-layout" id="ad-layout" value="<?php echo isset( $layout ) ? $layout : ''; ?>"/> |
| 172 | </div> |
| 173 | <hr> |
| 174 | <label class="label advads-adsense-layout-key" <?php if ( 'in-feed' !== $unit_type ) { |
| 175 | echo 'style="display: none;"'; |
| 176 | } ?> id="advads-adsense-layout-key"><?php _e( 'Layout-Key', 'advanced-ads' ); ?></label> |
| 177 | <div <?php if ( 'in-feed' !== $unit_type ) { |
| 178 | echo 'style="display: none;"'; |
| 179 | } ?>> |
| 180 | <input type="text" name="ad-layout-key" id="ad-layout-key" value="<?php echo $layout_key ?? ''; ?>"/> |
| 181 | </div> |
| 182 | <hr/> |
| 183 | <label class="label clearfix-before" <?php if ( ! $is_responsive ) { |
| 184 | echo 'style="display: none;"'; |
| 185 | } ?>><?php _e( 'Clearfix', 'advanced-ads' ); ?></label> |
| 186 | <div class="clearfix-before" <?php if ( ! $is_responsive ) { |
| 187 | echo 'style="display: none;"'; |
| 188 | } ?>> |
| 189 | <input type="hidden" name="advanced_ad[output][clearfix_before]" value="0" /> |
| 190 | <input type="checkbox" name="advanced_ad[output][clearfix_before]" value="1" <?php checked( ! empty( $options['clearfix_before'] ), true ); ?> /> |
| 191 | <p class="description inline"> |
| 192 | <?php _e( 'Enable this if responsive ads cover something on your site.', 'advanced-ads' ); ?> |
| 193 | </p> |
| 194 | </div> |
| 195 | <hr class="clearfix-before" <?php if ( ! $is_responsive ) { |
| 196 | echo 'style="display: none;"'; |
| 197 | } ?> /> |
| 198 | <?php do_action( 'advanced-ads-gadsense-extra-ad-param', $extra_params, $content, $ad ); |
| 199 |