1+ <?php
2+ /**
3+ * Google AdSense Ad Provider for Ad Code manager
4+ */
5+ class Google_AdSense_Async_ACM_Provider extends ACM_Provider {
6+ public $ crawler_user_agent = 'Mediapartners-Google ' ;
7+
8+ /**
9+ * Register default options for Google AdSense
10+ *
11+ * @uses apply_filters, parent::__construct
12+ * @return null
13+ */
14+ public function __construct () {
15+ // Default output HTML
16+ $ this ->output_html ='<div id="acm-ad-tag-%tag%"><script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
17+ <ins class="adsbygoogle"
18+ style="display:inline-block;width:%width%px;height:%height%px"
19+ data-ad-client="%publisher_id%";
20+ data-ad-slot="%tag_id%";
21+ ></ins>
22+ <script>
23+ (adsbygoogle = window.adsbygoogle || []).push({});
24+ </script></div> ' ;
25+
26+ // Default Ad Tag Ids (you will pass this in your shortcode or template tag)
27+ $ this ->ad_tag_ids = array (
28+ array (
29+ 'tag ' => '728x90_leaderboard ' ,
30+ 'url_vars ' => array (
31+ 'tag ' => '728x90_leaderboard ' ,
32+ 'height ' => '90 ' ,
33+ 'width ' => '728 ' ,
34+ ),
35+ 'enable_ui_mapping ' => true ,
36+ ),
37+ array (
38+ 'tag ' => '468x60_banner ' ,
39+ 'url_vars ' => array (
40+ 'tag ' => '468x60_banner ' ,
41+ 'height ' => '60 ' ,
42+ 'width ' => '468 ' ,
43+ ),
44+ 'enable_ui_mapping ' => true ,
45+ ),
46+ array (
47+ 'tag ' => '120x600_skyscraper ' ,
48+ 'url_vars ' => array (
49+ 'tag ' => '120x600_skyscraper ' ,
50+ 'height ' => '600 ' ,
51+ 'width ' => '120 ' ,
52+ ),
53+ 'enable_ui_mapping ' => true ,
54+ ),
55+ array (
56+ 'tag ' => '160x600_wideskyscraper ' ,
57+ 'url_vars ' => array (
58+ 'tag ' => '160x600_wideskyscraper ' ,
59+ 'height ' => '600 ' ,
60+ 'width ' => '160 ' ,
61+ ),
62+ 'enable_ui_mapping ' => true ,
63+ ),
64+ array (
65+ 'tag ' => '300x600_largeskyscraper ' ,
66+ 'url_vars ' => array (
67+ 'tag ' => '300x600_largeskyscraper ' ,
68+ 'height ' => '600 ' ,
69+ 'width ' => '300 ' ,
70+ ),
71+ 'enable_ui_mapping ' => true ,
72+ ),
73+ array (
74+ 'tag ' => '250x250_square ' ,
75+ 'url_vars ' => array (
76+ 'tag ' => '250x250_square ' ,
77+ 'height ' => '250 ' ,
78+ 'width ' => '250 ' ,
79+ ),
80+ 'enable_ui_mapping ' => true ,
81+ ),
82+ array (
83+ 'tag ' => '200x200_smallsquare ' ,
84+ 'url_vars ' => array (
85+ 'tag ' => '200x200_smallsquare ' ,
86+ 'height ' => '200 ' ,
87+ 'width ' => '200 ' ,
88+ ),
89+ 'enable_ui_mapping ' => true ,
90+ ),
91+ );
92+
93+ $ this ->ad_code_args = array (
94+ array (
95+ 'key ' => 'tag ' ,
96+ 'label ' => __ ( 'Tag ' , 'ad-code-manager ' ),
97+ 'editable ' => true ,
98+ 'required ' => true ,
99+ 'type ' => 'select ' ,
100+ 'options ' => array (
101+ // This is added later, through 'acm_ad_code_args' filter
102+ ),
103+ ),
104+ array (
105+ 'key ' => 'tag_id ' ,
106+ 'label ' => __ ( 'Tag ID ' , 'ad-code-manager ' ),
107+ 'editable ' => true ,
108+ 'required ' => true ,
109+ ),
110+ array (
111+ 'key ' => 'publisher_id ' ,
112+ 'label ' => __ ( 'Publisher ID ' , 'ad-code-manager ' ),
113+ 'editable ' => true ,
114+ 'required ' => true ,
115+ ),
116+ );
117+
118+ add_filter ( 'acm_ad_code_args ' , array ( $ this , 'filter_ad_code_args ' ) );
119+ add_filter ( 'acm_display_ad_codes_without_conditionals ' , '__return_true ' );
120+
121+ parent ::__construct ();
122+ }
123+
124+ /**
125+ * Register the 'tag's available for mapping in the UI
126+ */
127+ public function filter_ad_code_args ( $ ad_code_args ) {
128+ global $ ad_code_manager ;
129+
130+ foreach ( $ ad_code_args as $ tag => $ ad_code_arg ) {
131+
132+ if ( 'tag ' != $ ad_code_arg ['key ' ] )
133+ continue ;
134+
135+ // Get all of the tags that are registered, and provide them as options
136+ foreach ( (array )$ ad_code_manager ->ad_tag_ids as $ ad_tag ) {
137+ if ( isset ( $ ad_tag ['enable_ui_mapping ' ] ) && $ ad_tag ['enable_ui_mapping ' ] )
138+ $ ad_code_args [$ tag ]['options ' ][$ ad_tag ['tag ' ]] = $ ad_tag ['tag ' ];
139+ }
140+
141+ }
142+ return $ ad_code_args ;
143+ }
144+ }
145+
146+ /**
147+ * Google AdSense Async list table for Ad Code Manager
148+ */
149+ class Google_AdSense_Async_ACM_WP_List_Table extends ACM_WP_List_Table {
150+ /**
151+ * Register table settings
152+ *
153+ * @uses parent::__construct
154+ * @return null
155+ */
156+ public function __construct () {
157+ parent ::__construct ( array (
158+ 'singular ' => 'google_adsense_async_acm_wp_list_table ' ,
159+ 'plural ' => 'google_adsense_async_acm_wp_list_table ' ,
160+ 'ajax ' => true
161+ ) );
162+ }
163+
164+ /**
165+ * This is nuts and bolts of table representation
166+ */
167+ function get_columns ( $ columns = null ) {
168+ $ columns = array (
169+ 'cb ' => '<input type="checkbox" /> ' ,
170+ 'id ' => __ ( 'ID ' , 'ad-code-manager ' ),
171+ 'tag ' => __ ( 'Tag ' , 'ad-code-manager ' ),
172+ 'tag_id ' => __ ( 'Tag ID ' , 'ad-code-manager ' ),
173+ 'publisher_id ' => __ ( 'Publisher ID ' , 'ad-code-manager ' ),
174+ 'priority ' => __ ( 'Priority ' , 'ad-code-manager ' ),
175+ 'operator ' => __ ( 'Logical Operator ' , 'ad-code-manager ' ),
176+ 'conditionals ' => __ ( 'Conditionals ' , 'ad-code-manager ' ),
177+ );
178+ return parent ::get_columns ( $ columns );
179+ }
180+
181+ /**
182+ * Output the tag cell in the list table
183+ */
184+ function column_tag ( $ item ) {
185+ $ output = isset ( $ item ['tag ' ] ) ? esc_html ( $ item ['tag ' ] ) : esc_html ( $ item ['url_vars ' ]['tag ' ] );
186+ $ output .= $ this ->row_actions_output ( $ item );
187+ return $ output ;
188+ }
189+ }
0 commit comments