13
13
if ( $ _SERVER ['SCRIPT_FILENAME ' ] == __FILE__ )
14
14
die ( 'Access denied. ' );
15
15
16
-
17
- define ('WP_DEBUG ' , true );
18
-
19
16
require_once ( dirname (__FILE__ ) . '/settings.php ' );
17
+ require_once ( dirname (__FILE__ ) . '/widget.php ' );
20
18
21
19
/**
22
20
* Description of awpp
23
21
*
24
22
* @author kwisatz
25
23
*/
26
- class Awpp {
27
-
28
- const PREFIX = 'awpp ' ;
29
-
24
+ class AWPP_Init {
25
+
26
+
30
27
public function __construct (){
31
28
// Admin menu
32
29
add_action ('admin_init ' , array ( 'AWPP_Settings ' , 'admin_init ' ));
33
- add_action ('admin_menu ' , array ( & $ this , 'add_menu ' ));
30
+ add_action ('admin_menu ' , array ( ' AWPP_Settings ' , 'add_menu ' ));
34
31
35
32
// Always? Cf. callback function comment
36
33
//add_action('wp_enqueue_scripts', array( &$this, 'loadResources'), 11); // that action doesn't seem to work
37
34
add_action ('wp ' , array ( &$ this , 'loadResources ' ), 11 );
38
35
add_action ('wp_head ' , array ( &$ this , 'outputHead ' ) );
39
36
40
37
// Widget
41
- add_action ('widgets_init ' , array (& $ this , 'register_awpp_widget ' ));
38
+ add_action ('widgets_init ' , array (' AWPP_Widget ' , 'register_awpp_widget ' ));
42
39
43
40
// Shortcodes http://codex.wordpress.org/Shortcode_API
44
- add_shortcode ( 'annuaire ' , array (&$ this , 'create_annuaire_list ' ) );
45
- add_shortcode ( 'annuaire-map ' , array ( &$ this , 'create_annuaire_map ' ) );
41
+ $ awpp_sc = new AWPP_Shortcode ;
42
+ add_shortcode ( 'annuaire ' , array ( $ awpp_sc , 'create_annuaire_list ' ) );
43
+ add_shortcode ( 'annuaire-map ' , array ( $ awpp_sc , 'create_annuaire_map ' ) );
46
44
}
47
45
48
46
public function activate (){
@@ -57,13 +55,56 @@ public function outputHead(){
57
55
print ('<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> ' );
58
56
}
59
57
58
+ /**
59
+ * Register and load javascript and stylesheet information
60
+ * @link http://codex.wordpress.org/Function_Reference/wp_register_script
61
+ */
62
+ public function loadResources () {
63
+ wp_register_script (
64
+ 'googleMapsAPI ' , // handle
65
+ 'http ' . ( is_ssl () ? 's ' : '' ) .'://maps.google.com/maps/api/js?key=AIzaSyD2s8HfAbcc2uaoZ1Nuf8zSwOV9sg5kONI&sensor=false ' , // src
66
+ array (), // deps
67
+ false , // ver
68
+ true // in_footer
69
+ );
70
+ wp_register_script (
71
+ 'awppScript ' , // handle
72
+ plugins_url ('awpp.js ' , __FILE__ ), // src
73
+ array ( 'googleMapsAPI ' , 'jquery ' ), // deps
74
+ false , // ver
75
+ true // in_footer
76
+ );
77
+ wp_register_style (
78
+ 'awppStyle ' , // handle
79
+ plugins_url ('awpp.css ' , __FILE__ ), // src
80
+ array (), // deps
81
+ false , // ver
82
+ 'all ' // media
83
+ );
84
+
85
+ // TODO only load when shortcode has been parsed
86
+ wp_enqueue_script ( 'googleMapsAPI ' );
87
+ wp_enqueue_script ( 'awppScript ' );
88
+
89
+ wp_enqueue_style ( 'awppStyle ' );
90
+ }
91
+
92
+ }
93
+
94
+ class AWPP_Shortcode {
95
+
96
+ const PREFIX = 'awpp ' ;
97
+
98
+ public function __construct (){
99
+
100
+ }
60
101
/*
61
102
* [annuaire-map] shortcode with region, type and content parameters
62
103
*/
63
104
public function create_annuaire_map ( $ attributes ){
64
105
$ options = get_option ('awpp_options ' );
65
106
$ geoData = null ;
66
-
107
+
67
108
extract (
68
109
shortcode_atts (
69
110
array (
@@ -105,15 +146,22 @@ public function create_annuaire_list( $attributes ){
105
146
'map ' => false ,
106
147
'width ' => $ options ['map_width ' ],
107
148
'height ' => $ options ['map_height ' ],
108
- 'center ' => $ options ['map_center ' ]
149
+ 'center ' => $ options ['map_center ' ],
150
+ 'photos ' => true ,
151
+ 'limit ' => 100
109
152
),
110
153
$ attributes )
111
154
);
112
155
113
156
$ data = $ this ->_getDataFromServer ( $ region , $ type , $ content );
114
157
$ output = '<div class="wrap"><div id="awpp_addresses"> ' ;
115
-
158
+ $ count = 0 ;
159
+
116
160
foreach ( $ data as $ entry ) {
161
+
162
+ if ( ++$ count > $ limit ) {
163
+ continue ;
164
+ }
117
165
118
166
$ title = strip_tags ( $ entry ->titre );
119
167
@@ -128,8 +176,14 @@ public function create_annuaire_list( $attributes ){
128
176
$ output .= ( $ entry ->fax ) ? '<br/>Fax: ' . $ entry ->fax : '' ;
129
177
$ output .= ( $ entry ->link ) ? '<br/><a href=" ' . $ entry ->link . '" target="_blank">Homepage</a> ' : '' ;
130
178
$ output .= '</div> ' ;
131
-
132
- if ( is_array ( $ entry ->photo ) && !empty ( $ entry ->photo [0 ] ) ) {
179
+
180
+ /*
181
+ * Only display photos if
182
+ * 1) they have been requested,
183
+ * 2) there is an array of photos and
184
+ * 3) the first element isn't empty
185
+ */
186
+ if ( $ photos && is_array ( $ entry ->photo ) && !empty ( $ entry ->photo [0 ] ) ) {
133
187
$ options = get_option ('awpp_options ' );
134
188
$ photo = trim ( strstr ( $ entry ->photo [0 ], 'http ' ) );
135
189
$ output .= '<div class="awpp_photo_block"> '
@@ -246,41 +300,7 @@ private function _getMapPlacemarks( $geoData ){
246
300
return $ placemarks ;
247
301
}
248
302
249
- /**
250
- * Register and load javascript and stylesheet information
251
- * @link http://codex.wordpress.org/Function_Reference/wp_register_script
252
- */
253
- public function loadResources () {
254
- wp_register_script (
255
- 'googleMapsAPI ' , // handle
256
- 'http ' . ( is_ssl () ? 's ' : '' ) .'://maps.google.com/maps/api/js?key=AIzaSyD2s8HfAbcc2uaoZ1Nuf8zSwOV9sg5kONI&sensor=false ' , // src
257
- array (), // deps
258
- false , // ver
259
- true // in_footer
260
- );
261
- wp_register_script (
262
- 'awppScript ' , // handle
263
- plugins_url ('awpp.js ' , __FILE__ ), // src
264
- array ( 'googleMapsAPI ' , 'jquery ' ), // deps
265
- false , // ver
266
- true // in_footer
267
- );
268
- wp_register_style (
269
- 'awppStyle ' , // handle
270
- plugins_url ('awpp.css ' , __FILE__ ), // src
271
- array (), // deps
272
- false , // ver
273
- 'all ' // media
274
- );
275
-
276
- // TODO only load when shortcode has been parsed
277
- wp_enqueue_script ( 'googleMapsAPI ' );
278
- wp_enqueue_script ( 'awppScript ' );
279
-
280
- wp_enqueue_style ( 'awppStyle ' );
281
- }
282
-
283
- private function _googleGeocode ( $ address ) {
303
+ private function _googleGeocode ( $ address ) {
284
304
$ geocodeResponse = wp_remote_get (
285
305
sprintf ( 'http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false ' ,
286
306
str_replace ( ' ' , '+ ' , $ address )
@@ -320,65 +340,13 @@ private function _googleGeocode( $address ) {
320
340
return array ( 'latitude ' => $ coordinates ->results [ 0 ]->geometry ->location ->lat ,
321
341
'longitude ' => $ coordinates ->results [ 0 ]->geometry ->location ->lng );
322
342
}
323
-
324
- /**
325
- * Register the widget class
326
- */
327
- public function register_awpp_widget (){
328
- register_widget ('Awpp_Widget ' );
329
- }
330
-
331
- public function add_menu (){
332
- add_options_page ('Annuaire Client Settings ' , 'Annuaire Client ' , 'manage_options ' , 'awpp ' , array ('AWPP_Settings ' , 'plugin_settings_page ' ));
333
- }
334
- }
335
-
336
- class Awpp_Widget extends WP_Widget {
337
-
338
- public function __construct () {
339
- parent ::__construct (
340
- 'awpp_widget ' , // Base ID
341
- 'Awpp Widget ' , // Name
342
- array ('description ' => __ ('Awpp widget ' ) ) // Args
343
- );
344
- }
345
-
346
- public function form ( $ instance ){
347
- if ( isset ( $ instance [ 'title ' ] ) ) {
348
- $ title = $ instance [ 'title ' ];
349
- } else {
350
- $ title = __ ( 'New title ' , 'text_domain ' );
351
- }
352
- print ('<p><label for=" ' . $ this ->get_field_id ('title ' ) . '" ' . _e ( "Title " ) . '</label> ' );
353
- print ('<input class="widefat" id=" ' . $ this ->get_field_id ( 'title ' )
354
- . '" name=" ' . $ this ->get_field_name ( 'title ' )
355
- . '" type="text" value=" ' . esc_attr ( $ title ) . '"/></p> ' );
356
- }
357
-
358
- public function update ( $ new_instance , $ old_instance ){
359
- $ instance = array ();
360
- $ instance ['title ' ] = strip_tags ( $ new_instance ['title ' ] );
361
- return $ instance ;
362
- }
363
-
364
- public function widget ( $ args , $ instance ){
365
- extract ( $ args );
366
- $ title = apply_filters ( 'widget_title ' , $ instance ['title ' ] );
367
- echo $ before_widget ;
368
- if ( ! empty ( $ title ) )
369
- echo $ before_title . $ title . $ after_title ;
370
- echo __ ( 'Hello, World! ' , 'text_domain ' );
371
- echo $ after_widget ;
372
- }
373
-
374
-
375
343
}
376
344
377
- if (class_exists ( 'awpp ' ) ){
378
- register_activation_hook (__FILE__ , array ('Awpp ' , 'activate ' ) );
379
- register_deactivation_hook (__FILE__ , array ('Awpp ' , 'deactivate ' ) );
345
+ if ( class_exists ( 'AWPP_Init ' ) ){
346
+ register_activation_hook (__FILE__ , array ('AWPP_Init ' , 'activate ' ) );
347
+ register_deactivation_hook (__FILE__ , array ('AWPP_Init ' , 'deactivate ' ) );
380
348
381
- $ awpp = new Awpp ;
349
+ $ awpp = new AWPP_Init ;
382
350
383
351
}
384
352
0 commit comments