Pinterest "Pin It" Button - Version 2.0.7

Version Description

  • Tested with WordPress 4.0.
  • Button will now pin full size image instead of thumbnail.
Download this release

Release Info

Developer pderksen
Plugin Icon 128x128 Pinterest "Pin It" Button
Version 2.0.7
Comparing to
See all releases

Code changes from version 2.0.6 to 2.0.7

assets/icon-128x128.png ADDED
Binary file
assets/icon-256x256.png ADDED
Binary file
assets/icon-external-link.gif DELETED
Binary file
class-pinterest-pin-it-button.php CHANGED
@@ -1,447 +1,461 @@
1
- <?php
2
-
3
- /**
4
- * Main Pinterest_Pin_It_Button class
5
- *
6
- * @package PIB
7
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
- */
9
-
10
- // Exit if accessed directly.
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit;
13
- }
14
-
15
- class Pinterest_Pin_It_Button {
16
-
17
- /**
18
- * Plugin version, used for cache-busting of style and script file references.
19
- *
20
- * @since 2.0.0
21
- *
22
- * @var string
23
- */
24
-
25
- /**************************************
26
- * UPDATE VERSION HERE
27
- * and main plugin file header comments
28
- * and README.txt changelog
29
- **************************************/
30
-
31
- protected $version = '2.0.6';
32
-
33
- /**
34
- * Unique identifier for your plugin.
35
- *
36
- * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
37
- * match the Text Domain file header in the main plugin file.
38
- *
39
- * @since 2.0.0
40
- *
41
- * @var string
42
- */
43
- protected $plugin_slug = 'pinterest-pin-it-button';
44
-
45
- /**
46
- * Instance of this class.
47
- *
48
- * @since 2.0.0
49
- *
50
- * @var object
51
- */
52
- protected static $instance = null;
53
-
54
- /**
55
- * Slug of the plugin screen.
56
- *
57
- * @since 2.0.0
58
- *
59
- * @var string
60
- */
61
- protected $plugin_screen_hook_suffix = null;
62
-
63
- /**
64
- * Initialize the plugin by setting localization, filters, and administration functions.
65
- *
66
- * @since 2.0.0
67
- */
68
-
69
- /**
70
- * Initialize main plugin functions and add appropriate hooks/filter calls
71
- *
72
- * @since 2.0.0
73
- *
74
- */
75
- private function __construct() {
76
- // Setup constants.
77
- $this->setup_constants();
78
-
79
- // Run our upgrade checks first and update our version option.
80
- if( ! get_option( 'pib_upgrade_has_run' ) ) {
81
- add_action( 'init', array( $this, 'upgrade_plugin' ), 0 );
82
- update_option( 'pib_version', $this->version );
83
- }
84
-
85
- // Include required files.
86
- add_action( 'init', array( $this, 'includes' ), 1 );
87
-
88
- // Add the options page and menu item.
89
- add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
90
-
91
- // Enqueue admin styles and scripts.
92
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
93
-
94
- // Enqueue public style and scripts.
95
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
96
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
97
-
98
- // Add admin notice after plugin activation. Also check if should be hidden.
99
- add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
100
-
101
- // Add Post Meta stuff.
102
- add_action( 'add_meta_boxes', array( $this, 'display_post_meta') );
103
- add_action( 'save_post', array( $this, 'save_meta_data') );
104
-
105
- // Add plugin listing "Settings" action link.
106
- add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . $this->plugin_slug . '.php' ), array( $this, 'settings_link' ) );
107
-
108
- // Check WP version
109
- add_action( 'admin_init', array( $this, 'check_wp_version' ) );
110
- }
111
-
112
- /**
113
- * Make sure user has the minimum required version of WordPress installed to use the plugin
114
- *
115
- * @since 1.0.0
116
- */
117
- public function check_wp_version() {
118
- global $wp_version;
119
- $required_wp_version = '3.6.1';
120
-
121
- if ( version_compare( $wp_version, $required_wp_version, '<' ) ) {
122
- deactivate_plugins( PIB_MAIN_FILE );
123
- wp_die( sprintf( __( $this->get_plugin_title() . ' requires WordPress version <strong>' . $required_wp_version . '</strong> to run properly. ' .
124
- 'Please update WordPress before reactivating this plugin. <a href="%s">Return to Plugins</a>.', 'pib' ), get_admin_url( '', 'plugins.php' ) ) );
125
- }
126
- }
127
-
128
- /**
129
- * Return an instance of this class.
130
- *
131
- * @since 2.0.0
132
- *
133
- * @return object A single instance of this class.
134
- */
135
- public static function get_instance() {
136
- // If the single instance hasn't been set, set it now.
137
- if ( null == self::$instance ) {
138
- self::$instance = new self;
139
- }
140
-
141
- return self::$instance;
142
- }
143
-
144
- /**
145
- * Setup plugin constants.
146
- *
147
- * @since 2.0.0
148
- */
149
- public function setup_constants() {
150
- // Plugin slug.
151
- if ( ! defined( 'PIB_PLUGIN_SLUG' ) ) {
152
- define( 'PIB_PLUGIN_SLUG', $this->plugin_slug );
153
- }
154
-
155
- // Plugin version.
156
- if ( ! defined( 'PIB_VERSION' ) ) {
157
- define( 'PIB_VERSION', $this->version );
158
- }
159
-
160
- // Plugin title.
161
- if ( ! defined( 'PIB_PLUGIN_TITLE' ) ) {
162
- define( 'PIB_PLUGIN_TITLE', $this->get_plugin_title() );
163
- }
164
-
165
- // Plugin folder URL.
166
- if ( ! defined( 'PIB_PLUGIN_URL' ) ) {
167
- define( 'PIB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
168
- }
169
-
170
- if( ! defined( 'PINPLUGIN_BASE_URL' ) ) {
171
- define( 'PINPLUGIN_BASE_URL', 'http://pinplugins.com/' );
172
- }
173
- }
174
-
175
- /**
176
- * Fired when the plugin is activated.
177
- *
178
- * @since 2.0.0
179
- */
180
- public static function activate() {
181
- update_option( 'pib_show_admin_install_notice', 1 );
182
- }
183
-
184
- /**
185
- * Run upgrade plugin process.
186
- *
187
- * @since 2.0.0
188
- */
189
- public function upgrade_plugin() {
190
- include_once( 'includes/upgrade-plugin.php' );
191
- }
192
-
193
- /**
194
- * Include required files (admin and frontend).
195
- *
196
- * @since 2.0.0
197
- */
198
- public function includes() {
199
- // Load global options.
200
- global $pib_options;
201
-
202
- // Include the file to register all of the plugin settings.
203
- include_once( 'includes/register-settings.php' );
204
-
205
- // Load global options settings.
206
- $pib_options = pib_get_settings();
207
-
208
- // Include widgets file if on widgets admin or public.
209
- include_once( dirname( __FILE__ ) . '/includes/widgets.php' );
210
-
211
- // Other common includes.
212
- include_once( 'includes/misc-functions.php' );
213
-
214
- // Admin-only includes.
215
- if ( is_admin() ) {
216
- include_once( 'includes/admin-notices.php' );
217
- } else {
218
- // Frontend-only includes.
219
- include_once( 'includes/shortcodes.php' );
220
- include_once( 'views/public.php' );
221
- }
222
- }
223
-
224
- /**
225
- * Return localized base plugin title.
226
- *
227
- * @since 2.0.0
228
- *
229
- * @return string
230
- */
231
- public static function get_plugin_title() {
232
- return __( 'Pinterest "Pin It" Button Lite', 'pib' );
233
- }
234
-
235
- /**
236
- * Enqueue admin-specific style sheets for this plugin's admin pages only.
237
- *
238
- * @since 2.0.0
239
- *
240
- * @return null Return early if no settings page is registered.
241
- */
242
- public function enqueue_admin_styles() {
243
-
244
- if ( $this->viewing_this_plugin() ) {
245
- // Plugin admin CSS. Tack on plugin version.
246
- wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
247
- }
248
- }
249
-
250
- /**
251
- * Enqueue public-facing style sheets.
252
- *
253
- * @since 2.0.0
254
- */
255
- public function enqueue_styles() {
256
- global $pib_options;
257
-
258
- if( ! in_array( 'no_buttons', pib_render_button() ) ) {
259
- // Check to see if setting to disable is true first.
260
- if ( empty( $pib_options['disable_css'] ) ) {
261
- wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'css/public.css', __FILE__ ), array(), $this->version );
262
- }
263
- }
264
-
265
- }
266
-
267
- /**
268
- * Enqueues public-facing script files.
269
- *
270
- * @since 2.0.0
271
- */
272
- public function enqueue_scripts() {
273
- global $pib_options;
274
-
275
- if( ! in_array( 'no_buttons', pib_render_button() ) ) {
276
- // If this option is empty then it means we can load the pinit.js, otherwise do not load it
277
- if( empty( $pib_options['no_pinit_js'] ) ) {
278
- // Enqueue Pinterest JS plugin boilerplate style. Don't tack on plugin version.
279
- // We DO NOT include the plugin slug here. This is so that this can be uniform across all of our plugins
280
- wp_enqueue_script( 'pinterest-pinit-js', '//assets.pinterest.com/js/pinit.js', array(), null, true );
281
- }
282
- }
283
- }
284
-
285
- /**
286
- * Register the administration menu for this plugin into the WordPress Dashboard menu.
287
- *
288
- * @since 2.0.0
289
- */
290
- public function add_plugin_admin_menu() {
291
- // Add main menu item
292
- $this->plugin_screen_hook_suffix[] = add_menu_page(
293
- $this->get_plugin_title() . __( ' Settings', 'pib' ),
294
- __( 'Pin It Button', 'pib' ),
295
- 'manage_options',
296
- $this->plugin_slug,
297
- array( $this, 'display_plugin_admin_page' ),
298
- plugins_url( 'assets/pinterest-icon-16.png', __FILE__ )
299
- );
300
-
301
- // Add Help submenu page
302
- $this->plugin_screen_hook_suffix[] = add_submenu_page(
303
- $this->plugin_slug,
304
- $this->get_plugin_title() . __( ' Help', 'pib' ),
305
- __( 'Help', 'pib' ),
306
- 'manage_options',
307
- $this->plugin_slug . '_help',
308
- array( $this, 'display_admin_help_page' )
309
- );
310
- }
311
-
312
- /**
313
- * Render the admin pages for this plugin.
314
- *
315
- * @since 2.0.0
316
- */
317
- public function display_plugin_admin_page() {
318
- include_once( 'views/admin.php' );
319
- }
320
-
321
- public function display_admin_help_page() {
322
- include_once( 'views/admin-help.php' );
323
- }
324
-
325
- /**
326
- * Render the post meta for this plugin.
327
- *
328
- * @since 2.0.0
329
- */
330
- public function display_post_meta() {
331
- // Add the meta boxes for both posts and pages
332
- add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'post', 'advanced', 'high');
333
- add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'page', 'advanced', 'high');
334
-
335
- // function to output the HTML for meta box
336
- function add_meta_form( $post ) {
337
-
338
- wp_nonce_field( basename( __FILE__ ), 'pib_meta_nonce' );
339
-
340
- include_once( 'views/post-meta-display.php' );
341
- }
342
- }
343
-
344
- /**
345
- * Save the post meta for this plugin.
346
- *
347
- * @since 2.0.0
348
- *
349
- * @param int $post_id
350
- * @return int $post_id
351
- */
352
- public function save_meta_data( $post_id ) {
353
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
354
- return $post_id;
355
-
356
- // An array to hold all of our post meta ids so we can run them through a loop
357
- $post_meta_fields = array(
358
- 'pib_url_of_webpage',
359
- 'pib_url_of_img',
360
- 'pib_description'
361
- );
362
-
363
- $post_meta_fields = apply_filters( 'pib_post_meta_fields', $post_meta_fields );
364
-
365
- // Record sharing disable
366
-
367
- if ( current_user_can( 'edit_post', $post_id ) ) {
368
- if ( isset( $_POST['pib_sharing_status_hidden'] ) ) {
369
- if ( !isset( $_POST['pib_enable_post_sharing'] ) ) {
370
- update_post_meta( $post_id, 'pib_sharing_disabled', 1 );
371
- }
372
- else {
373
- delete_post_meta( $post_id, 'pib_sharing_disabled' );
374
- }
375
-
376
- // Loop through our array and make sure it is posted and not empty in order to update it, otherwise we delete it
377
- foreach ( $post_meta_fields as $pmf ) {
378
- if ( isset( $_POST[$pmf] ) && !empty( $_POST[$pmf] ) ) {
379
- update_post_meta( $post_id, $pmf, sanitize_text_field( stripslashes( $_POST[$pmf] ) ) );
380
- } else {
381
- delete_post_meta( $post_id, $pmf );
382
- }
383
- }
384
- }
385
- }
386
-
387
-
388
- return $post_id;
389
- }
390
-
391
- /**
392
- * Add Settings action link to left of existing action links on plugin listing page.
393
- *
394
- * @since 2.0.0
395
- *
396
- * @param array $links Default plugin action links.
397
- * @return array $links Amended plugin action links.
398
- */
399
- public function settings_link( $links ) {
400
- $setting_link = sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', $this->plugin_slug, admin_url( 'admin.php' ) ), __( 'Settings', 'pib' ) );
401
- array_unshift( $links, $setting_link );
402
-
403
- return $links;
404
- }
405
-
406
- /**
407
- * Check if viewing one of this plugin's admin pages.
408
- *
409
- * @since 2.0.0
410
- *
411
- * @return bool
412
- */
413
- private function viewing_this_plugin() {
414
- if ( ! isset( $this->plugin_screen_hook_suffix ) )
415
- return false;
416
-
417
- $screen = get_current_screen();
418
-
419
- if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) )
420
- return true;
421
- else
422
- return false;
423
- }
424
-
425
- /**
426
- * Show notice after plugin install/activate in admin dashboard until user acknowledges.
427
- * Also check if user chooses to hide it.
428
- *
429
- * @since 2.0.0
430
- */
431
- public function admin_install_notice() {
432
- // Exit all of this is stored value is false/0 or not set.
433
- if ( false == get_option( 'pib_show_admin_install_notice' ) )
434
- return;
435
-
436
- // Delete stored value if "hide" button click detected (custom querystring value set to 1).
437
- // or if on a PIB admin page. Then exit.
438
- if ( ! empty( $_REQUEST['pib-dismiss-install-nag'] ) || $this->viewing_this_plugin() ) {
439
- delete_option( 'pib_show_admin_install_notice' );
440
- return;
441
- }
442
-
443
- // At this point show install notice. Show it only on the plugin screen.
444
- if( get_current_screen()->id == 'plugins' )
445
- include_once( 'views/admin-install-notice.php' );
446
- }
447
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Main Pinterest_Pin_It_Button class
5
+ *
6
+ * @package PIB
7
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
+ */
9
+
10
+ // Exit if accessed directly.
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ class Pinterest_Pin_It_Button {
16
+
17
+ /**
18
+ * Plugin version, used for cache-busting of style and script file references.
19
+ *
20
+ * @since 2.0.0
21
+ *
22
+ * @var string
23
+ */
24
+
25
+ /**************************************
26
+ * UPDATE VERSION HERE
27
+ * and main plugin file header comments
28
+ * and README.txt changelog
29
+ **************************************/
30
+
31
+ protected $version = '2.0.7';
32
+
33
+ /**
34
+ * Unique identifier for your plugin.
35
+ *
36
+ * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
37
+ * match the Text Domain file header in the main plugin file.
38
+ *
39
+ * @since 2.0.0
40
+ *
41
+ * @var string
42
+ */
43
+ protected $plugin_slug = 'pinterest-pin-it-button';
44
+
45
+ /**
46
+ * Instance of this class.
47
+ *
48
+ * @since 2.0.0
49
+ *
50
+ * @var object
51
+ */
52
+ protected static $instance = null;
53
+
54
+ /**
55
+ * Slug of the plugin screen.
56
+ *
57
+ * @since 2.0.0
58
+ *
59
+ * @var string
60
+ */
61
+ protected $plugin_screen_hook_suffix = null;
62
+
63
+ /**
64
+ * Initialize the plugin by setting localization, filters, and administration functions.
65
+ *
66
+ * @since 2.0.0
67
+ */
68
+
69
+ /**
70
+ * Initialize main plugin functions and add appropriate hooks/filter calls
71
+ *
72
+ * @since 2.0.0
73
+ *
74
+ */
75
+ private function __construct() {
76
+ // Setup constants.
77
+ $this->setup_constants();
78
+
79
+ // Run our upgrade checks first and update our version option.
80
+ if( ! get_option( 'pib_upgrade_has_run' ) ) {
81
+ add_action( 'init', array( $this, 'upgrade_plugin' ), 0 );
82
+ update_option( 'pib_version', $this->version );
83
+ }
84
+
85
+ // Include required files.
86
+ add_action( 'init', array( $this, 'includes' ), 1 );
87
+
88
+ // Add the options page and menu item.
89
+ add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 2 );
90
+
91
+ // Enqueue admin styles and scripts.
92
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
93
+
94
+ // Enqueue public style and scripts.
95
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
96
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
97
+
98
+ // Add admin notice after plugin activation. Also check if should be hidden.
99
+ add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
100
+
101
+ // Add Post Meta stuff.
102
+ add_action( 'add_meta_boxes', array( $this, 'display_post_meta') );
103
+ add_action( 'save_post', array( $this, 'save_meta_data') );
104
+
105
+ // Add plugin listing "Settings" action link.
106
+ add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . $this->plugin_slug . '.php' ), array( $this, 'settings_link' ) );
107
+
108
+ // Check WP version
109
+ add_action( 'admin_init', array( $this, 'check_wp_version' ) );
110
+ }
111
+
112
+ /**
113
+ * Make sure user has the minimum required version of WordPress installed to use the plugin
114
+ *
115
+ * @since 1.0.0
116
+ */
117
+ public function check_wp_version() {
118
+ global $wp_version;
119
+ $required_wp_version = '3.6.1';
120
+
121
+ if ( version_compare( $wp_version, $required_wp_version, '<' ) ) {
122
+ deactivate_plugins( PIB_MAIN_FILE );
123
+ wp_die( sprintf( __( $this->get_plugin_title() . ' requires WordPress version <strong>' . $required_wp_version . '</strong> to run properly. ' .
124
+ 'Please update WordPress before reactivating this plugin. <a href="%s">Return to Plugins</a>.', 'pib' ), get_admin_url( '', 'plugins.php' ) ) );
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Return an instance of this class.
130
+ *
131
+ * @since 2.0.0
132
+ *
133
+ * @return object A single instance of this class.
134
+ */
135
+ public static function get_instance() {
136
+ // If the single instance hasn't been set, set it now.
137
+ if ( null == self::$instance ) {
138
+ self::$instance = new self;
139
+ }
140
+
141
+ return self::$instance;
142
+ }
143
+
144
+ /**
145
+ * Setup plugin constants.
146
+ *
147
+ * @since 2.0.0
148
+ */
149
+ public function setup_constants() {
150
+ // Plugin slug.
151
+ if ( ! defined( 'PIB_PLUGIN_SLUG' ) ) {
152
+ define( 'PIB_PLUGIN_SLUG', $this->plugin_slug );
153
+ }
154
+
155
+ // Plugin version.
156
+ if ( ! defined( 'PIB_VERSION' ) ) {
157
+ define( 'PIB_VERSION', $this->version );
158
+ }
159
+
160
+ // Plugin title.
161
+ if ( ! defined( 'PIB_PLUGIN_TITLE' ) ) {
162
+ define( 'PIB_PLUGIN_TITLE', $this->get_plugin_title() );
163
+ }
164
+
165
+ // Plugin folder URL.
166
+ if ( ! defined( 'PIB_PLUGIN_URL' ) ) {
167
+ define( 'PIB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
168
+ }
169
+
170
+ if( ! defined( 'PINPLUGIN_BASE_URL' ) ) {
171
+ define( 'PINPLUGIN_BASE_URL', 'http://pinplugins.com/' );
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Fired when the plugin is activated.
177
+ *
178
+ * @since 2.0.0
179
+ */
180
+ public static function activate() {
181
+ update_option( 'pib_show_admin_install_notice', 1 );
182
+ }
183
+
184
+ /**
185
+ * Run upgrade plugin process.
186
+ *
187
+ * @since 2.0.0
188
+ */
189
+ public function upgrade_plugin() {
190
+ include_once( 'includes/upgrade-plugin.php' );
191
+ }
192
+
193
+ /**
194
+ * Include required files (admin and frontend).
195
+ *
196
+ * @since 2.0.0
197
+ */
198
+ public function includes() {
199
+ // Load global options.
200
+ global $pib_options;
201
+
202
+ // Include the file to register all of the plugin settings.
203
+ include_once( 'includes/register-settings.php' );
204
+
205
+ // Include simplehtmldom
206
+ if( ! class_exists( 'simple_html_dom_node' ) ) {
207
+ include_once( 'includes/simple_html_dom.php' );
208
+ }
209
+
210
+ // Load global options settings.
211
+ $pib_options = pib_get_settings();
212
+
213
+ // Include widgets file if on widgets admin or public.
214
+ include_once( dirname( __FILE__ ) . '/includes/widgets.php' );
215
+
216
+ // Other common includes.
217
+ include_once( 'includes/misc-functions.php' );
218
+
219
+ // Admin-only includes.
220
+ if ( is_admin() ) {
221
+ include_once( 'includes/admin-notices.php' );
222
+ } else {
223
+ // Frontend-only includes.
224
+ include_once( 'includes/shortcodes.php' );
225
+ include_once( 'views/public.php' );
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Return localized base plugin title.
231
+ *
232
+ * @since 2.0.0
233
+ *
234
+ * @return string
235
+ */
236
+ public static function get_plugin_title() {
237
+ return __( 'Pinterest "Pin It" Button Lite', 'pib' );
238
+ }
239
+
240
+ /**
241
+ * Enqueue admin-specific style sheets for this plugin's admin pages only.
242
+ *
243
+ * @since 2.0.0
244
+ *
245
+ * @return null Return early if no settings page is registered.
246
+ */
247
+ public function enqueue_admin_styles() {
248
+
249
+ if ( $this->viewing_this_plugin() ) {
250
+ // Plugin admin CSS. Tack on plugin version.
251
+ wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Enqueue public-facing style sheets.
257
+ *
258
+ * @since 2.0.0
259
+ */
260
+ public function enqueue_styles() {
261
+ global $pib_options;
262
+
263
+ if( ! in_array( 'no_buttons', pib_render_button() ) ) {
264
+ // Check to see if setting to disable is true first.
265
+ if ( empty( $pib_options['disable_css'] ) ) {
266
+ wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'css/public.css', __FILE__ ), array(), $this->version );
267
+ }
268
+ }
269
+
270
+ }
271
+
272
+ /**
273
+ * Enqueues public-facing script files.
274
+ *
275
+ * @since 2.0.0
276
+ */
277
+ public function enqueue_scripts() {
278
+ global $pib_options;
279
+
280
+ if( ! in_array( 'no_buttons', pib_render_button() ) ) {
281
+ // If this option is empty then it means we can load the pinit.js, otherwise do not load it
282
+ if( empty( $pib_options['no_pinit_js'] ) ) {
283
+ // Enqueue Pinterest JS plugin boilerplate style. Don't tack on plugin version.
284
+ // We DO NOT include the plugin slug here. This is so that this can be uniform across all of our plugins
285
+ wp_enqueue_script( 'pinterest-pinit-js', '//assets.pinterest.com/js/pinit.js', array(), null, true );
286
+ }
287
+ }
288
+ }
289
+
290
+ /**
291
+ * Register the administration menu for this plugin into the WordPress Dashboard menu.
292
+ *
293
+ * @since 2.0.0
294
+ */
295
+ public function add_plugin_admin_menu() {
296
+ // Add main menu item
297
+ $this->plugin_screen_hook_suffix[] = add_menu_page(
298
+ $this->get_plugin_title() . ' ' . __( 'Settings', 'pib' ),
299
+ __( 'Pin It Button', 'pib' ),
300
+ 'manage_options',
301
+ $this->plugin_slug,
302
+ array( $this, 'display_plugin_admin_page' ),
303
+ plugins_url( 'assets/pinterest-icon-16.png', __FILE__ )
304
+ );
305
+
306
+ $this->plugin_screen_hook_suffix[] = add_submenu_page(
307
+ $this->plugin_slug,
308
+ $this->get_plugin_title() . ' ' . __( 'Settings', 'pib' ),
309
+ __( 'Settings', 'pib' ),
310
+ 'manage_options',
311
+ $this->plugin_slug,
312
+ array( $this, 'display_plugin_admin_page' )
313
+ );
314
+
315
+ // Add Help submenu page
316
+ $this->plugin_screen_hook_suffix[] = add_submenu_page(
317
+ $this->plugin_slug,
318
+ $this->get_plugin_title() . __( ' Help', 'pib' ),
319
+ __( 'Help', 'pib' ),
320
+ 'manage_options',
321
+ $this->plugin_slug . '_help',
322
+ array( $this, 'display_admin_help_page' )
323
+ );
324
+ }
325
+
326
+ /**
327
+ * Render the admin pages for this plugin.
328
+ *
329
+ * @since 2.0.0
330
+ */
331
+ public function display_plugin_admin_page() {
332
+ include_once( 'views/admin.php' );
333
+ }
334
+
335
+ public function display_admin_help_page() {
336
+ include_once( 'views/admin-help.php' );
337
+ }
338
+
339
+ /**
340
+ * Render the post meta for this plugin.
341
+ *
342
+ * @since 2.0.0
343
+ */
344
+ public function display_post_meta() {
345
+ // Add the meta boxes for both posts and pages
346
+ add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'post', 'advanced', 'high');
347
+ add_meta_box('pib-meta', '"Pin It" Button Settings', 'add_meta_form', 'page', 'advanced', 'high');
348
+
349
+ // function to output the HTML for meta box
350
+ function add_meta_form( $post ) {
351
+
352
+ wp_nonce_field( basename( __FILE__ ), 'pib_meta_nonce' );
353
+
354
+ include_once( 'views/post-meta-display.php' );
355
+ }
356
+ }
357
+
358
+ /**
359
+ * Save the post meta for this plugin.
360
+ *
361
+ * @since 2.0.0
362
+ *
363
+ * @param int $post_id
364
+ * @return int $post_id
365
+ */
366
+ public function save_meta_data( $post_id ) {
367
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
368
+ return $post_id;
369
+
370
+ // An array to hold all of our post meta ids so we can run them through a loop
371
+ $post_meta_fields = array(
372
+ 'pib_url_of_webpage',
373
+ 'pib_url_of_img',
374
+ 'pib_description'
375
+ );
376
+
377
+ $post_meta_fields = apply_filters( 'pib_post_meta_fields', $post_meta_fields );
378
+
379
+ // Record sharing disable
380
+
381
+ if ( current_user_can( 'edit_post', $post_id ) ) {
382
+ if ( isset( $_POST['pib_sharing_status_hidden'] ) ) {
383
+ if ( !isset( $_POST['pib_enable_post_sharing'] ) ) {
384
+ update_post_meta( $post_id, 'pib_sharing_disabled', 1 );
385
+ }
386
+ else {
387
+ delete_post_meta( $post_id, 'pib_sharing_disabled' );
388
+ }
389
+
390
+ // Loop through our array and make sure it is posted and not empty in order to update it, otherwise we delete it
391
+ foreach ( $post_meta_fields as $pmf ) {
392
+ if ( isset( $_POST[$pmf] ) && !empty( $_POST[$pmf] ) ) {
393
+ update_post_meta( $post_id, $pmf, sanitize_text_field( stripslashes( $_POST[$pmf] ) ) );
394
+ } else {
395
+ delete_post_meta( $post_id, $pmf );
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+
402
+ return $post_id;
403
+ }
404
+
405
+ /**
406
+ * Add Settings action link to left of existing action links on plugin listing page.
407
+ *
408
+ * @since 2.0.0
409
+ *
410
+ * @param array $links Default plugin action links.
411
+ * @return array $links Amended plugin action links.
412
+ */
413
+ public function settings_link( $links ) {
414
+ $setting_link = sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', $this->plugin_slug, admin_url( 'admin.php' ) ), __( 'Settings', 'pib' ) );
415
+ array_unshift( $links, $setting_link );
416
+
417
+ return $links;
418
+ }
419
+
420
+ /**
421
+ * Check if viewing one of this plugin's admin pages.
422
+ *
423
+ * @since 2.0.0
424
+ *
425
+ * @return bool
426
+ */
427
+ private function viewing_this_plugin() {
428
+ if ( ! isset( $this->plugin_screen_hook_suffix ) )
429
+ return false;
430
+
431
+ $screen = get_current_screen();
432
+
433
+ if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) )
434
+ return true;
435
+ else
436
+ return false;
437
+ }
438
+
439
+ /**
440
+ * Show notice after plugin install/activate in admin dashboard until user acknowledges.
441
+ * Also check if user chooses to hide it.
442
+ *
443
+ * @since 2.0.0
444
+ */
445
+ public function admin_install_notice() {
446
+ // Exit all of this is stored value is false/0 or not set.
447
+ if ( false == get_option( 'pib_show_admin_install_notice' ) )
448
+ return;
449
+
450
+ // Delete stored value if "hide" button click detected (custom querystring value set to 1).
451
+ // or if on a PIB admin page. Then exit.
452
+ if ( ! empty( $_REQUEST['pib-dismiss-install-nag'] ) || $this->viewing_this_plugin() ) {
453
+ delete_option( 'pib_show_admin_install_notice' );
454
+ return;
455
+ }
456
+
457
+ // At this point show install notice. Show it only on the plugin screen.
458
+ if( get_current_screen()->id == 'plugins' )
459
+ include_once( 'views/admin-install-notice.php' );
460
+ }
461
+ }
css/admin.css CHANGED
@@ -1,57 +1,48 @@
1
- /* This stylesheet is used to style the admin option form of the plugin. */
2
-
3
- #icon-pinterest-32 {
4
- background: transparent url('../assets/pinterest-icon-32.png') no-repeat;
5
- }
6
-
7
- /* This icon is taken from the Flat Social Media Icons from Designmodo at
8
- * http://designmodo.com/flat-social-icons/
9
- */
10
- a.pib-external-link {
11
- background: transparent url('../assets/icon-external-link.gif') center right no-repeat;
12
- padding-right: 17px;
13
- }
14
-
15
- /* Layout the page similar to the built-in post edit screen. */
16
- #pib-settings {
17
- margin-right: 310px;
18
- }
19
-
20
- #pib-settings-content {
21
- width: 100%;
22
- float: left;
23
- }
24
-
25
- #pib-settings-sidebar {
26
- float: right;
27
- margin-top: 9px;
28
- margin-right: -310px;
29
- width: 290px;
30
- }
31
-
32
- #pib-settings-sidebar .centered {
33
- text-align: center;
34
- }
35
-
36
- #pib-settings-sidebar .button-large {
37
- font-size: 17px;
38
- line-height: 30px;
39
- height: 32px;
40
- }
41
-
42
- #pib-settings-sidebar .last-blurb {
43
- font-size: 17px;
44
- }
45
-
46
- /* postbox overrides */
47
- #pib-settings-sidebar .sidebar-container .postbox .inside,
48
- #pib-settings-sidebar .sidebar-container .postbox .inside ul {
49
- margin-bottom: 0;
50
- }
51
-
52
- /* Admin pages styles */
53
- .pib-checkbox-label, .pib-radio-label {
54
- line-height: 1.4em;
55
- margin: .25em 0 .5em!important;
56
- display: block;
57
- }
1
+ /* This stylesheet is used to style the admin option form of the plugin. */
2
+
3
+ #icon-pinterest-32 {
4
+ background: transparent url('../assets/pinterest-icon-32.png') no-repeat;
5
+ }
6
+
7
+ /* Layout the page similar to the built-in post edit screen. */
8
+ #pib-settings {
9
+ margin-right: 310px;
10
+ }
11
+
12
+ #pib-settings-content {
13
+ width: 100%;
14
+ float: left;
15
+ }
16
+
17
+ #pib-settings-sidebar {
18
+ float: right;
19
+ margin-right: -310px;
20
+ width: 290px;
21
+ }
22
+
23
+ #pib-settings-sidebar .centered {
24
+ text-align: center;
25
+ }
26
+
27
+ #pib-settings-sidebar .button-large {
28
+ font-size: 17px;
29
+ line-height: 30px;
30
+ height: 32px;
31
+ }
32
+
33
+ #pib-settings-sidebar .last-blurb {
34
+ font-size: 17px;
35
+ }
36
+
37
+ /* postbox overrides */
38
+ #pib-settings-sidebar .sidebar-container .postbox .inside,
39
+ #pib-settings-sidebar .sidebar-container .postbox .inside ul {
40
+ margin-bottom: 0;
41
+ }
42
+
43
+ /* Admin pages styles */
44
+ .pib-checkbox-label,
45
+ .pib-radio-label {
46
+ margin: .25em 0 .5em !important;
47
+ display: block;
48
+ }
 
 
 
 
 
 
 
 
 
css/public.css CHANGED
@@ -1,58 +1,58 @@
1
- /* This stylesheet is used to style the public view of the plugin. */
2
-
3
- /* Pinterest "Pin It" Button Public CSS */
4
-
5
- /* Styles for the Pin It Button wrapper DIV */
6
- div.pin-it-btn-wrapper,
7
- div.pin-it-btn-wrapper-shortcode,
8
- div.pin-it-btn-wrapper-widget {
9
- }
10
-
11
- div.pin-it-btn-wrapper {
12
- padding-bottom: 10px;
13
- position: relative;
14
- clear: both;
15
- }
16
-
17
- div.pin-it-btn-wrapper a,
18
- div.pin-it-btn-wrapper a:hover,
19
- div.pin-it-btn-wrapper-shortcode a,
20
- div.pin-it-btn-wrapper-shortcode a:hover,
21
- div.pin-it-btn-wrapper-widget a,
22
- div.pin-it-btn-wrapper-widget a:hover {
23
- background: none;
24
- border: 0;
25
- text-decoration: none;
26
- width: auto;
27
- margin: 0;
28
- max-width: none;
29
- padding: 0;
30
- -webkit-box-shadow: 0 0 0;
31
- box-shadow: 0 0 0;
32
- -webkit-border-radius: 0;
33
- border-radius: 0;
34
- }
35
-
36
- /* Latest "clearfix" utility class from Bootstrap 3 */
37
- .pib-clearfix:before,
38
- .pib-clearfix:after {
39
- display: table;
40
- content: " ";
41
- }
42
-
43
- .pib-clearfix:after {
44
- clear: both;
45
- }
46
-
47
- /* Align left/right/center options */
48
- .pib-align-left {
49
- text-align: left;
50
- }
51
-
52
- .pib-align-right {
53
- text-align: right;
54
- }
55
-
56
- .pib-align-center {
57
- text-align: center;
58
- }
1
+ /* This stylesheet is used to style the public view of the plugin. */
2
+
3
+ /* Pinterest "Pin It" Button Public CSS */
4
+
5
+ /* Styles for the Pin It Button wrapper DIV */
6
+ div.pin-it-btn-wrapper,
7
+ div.pin-it-btn-wrapper-shortcode,
8
+ div.pin-it-btn-wrapper-widget {
9
+ }
10
+
11
+ div.pin-it-btn-wrapper {
12
+ padding-bottom: 10px;
13
+ position: relative;
14
+ clear: both;
15
+ }
16
+
17
+ div.pin-it-btn-wrapper a,
18
+ div.pin-it-btn-wrapper a:hover,
19
+ div.pin-it-btn-wrapper-shortcode a,
20
+ div.pin-it-btn-wrapper-shortcode a:hover,
21
+ div.pin-it-btn-wrapper-widget a,
22
+ div.pin-it-btn-wrapper-widget a:hover {
23
+ background: none;
24
+ border: 0;
25
+ text-decoration: none;
26
+ width: auto;
27
+ margin: 0;
28
+ max-width: none;
29
+ padding: 0;
30
+ -webkit-box-shadow: 0 0 0;
31
+ box-shadow: 0 0 0;
32
+ -webkit-border-radius: 0;
33
+ border-radius: 0;
34
+ }
35
+
36
+ /* Latest "clearfix" utility class from Bootstrap 3 */
37
+ .pib-clearfix:before,
38
+ .pib-clearfix:after {
39
+ display: table;
40
+ content: " ";
41
+ }
42
+
43
+ .pib-clearfix:after {
44
+ clear: both;
45
+ }
46
+
47
+ /* Align left/right/center options */
48
+ .pib-align-left {
49
+ text-align: left;
50
+ }
51
+
52
+ .pib-align-right {
53
+ text-align: right;
54
+ }
55
+
56
+ .pib-align-center {
57
+ text-align: center;
58
+ }
includes/admin-notices.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
-
3
- /**
4
- * Admin settings page update notices.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- /**
17
- * Register admin notices that are used when plugin settings are saved
18
- *
19
- * @since 2.0.0
20
- */
21
- function pib_register_admin_notices() {
22
-
23
- global $pib_vars;
24
-
25
- // The first check will show message if general tab is updated. The additional check is if the plugin page is first clicked on and the 'tab' has not been set yet.
26
- $is_pib_settings_page = strpos( ( isset( $_GET['page'] ) ? $_GET['page'] : '' ), 'pinterest-pin-it-button' );
27
-
28
- if ( ( isset( $_GET['tab'] ) && 'general' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] )
29
- || ( !isset( $_GET['tab'] ) && $is_pib_settings_page !== false && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) ) {
30
- add_settings_error( 'pib-notices', 'pib-general-updated', __( 'General settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
31
- }
32
-
33
- if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'post_visibility' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
34
- add_settings_error( 'pib-notices', 'pib-post_visibility-updated', __( 'Post Visibility settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
35
- }
36
-
37
- if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'styles' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
38
- add_settings_error( 'pib-notices', 'pib-styles-updated', __( 'Styles settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
39
- }
40
-
41
- if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'advanced' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
42
- add_settings_error( 'pib-notices', 'pib-advanced-updated', __( 'Advanced settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
43
- }
44
-
45
- settings_errors( 'pib-notices' );
46
- }
47
-
48
- add_action( 'admin_notices', 'pib_register_admin_notices' );
1
+ <?php
2
+
3
+ /**
4
+ * Admin settings page update notices.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Register admin notices that are used when plugin settings are saved
18
+ *
19
+ * @since 2.0.0
20
+ */
21
+ function pib_register_admin_notices() {
22
+
23
+ global $pib_vars;
24
+
25
+ // The first check will show message if general tab is updated. The additional check is if the plugin page is first clicked on and the 'tab' has not been set yet.
26
+ $is_pib_settings_page = strpos( ( isset( $_GET['page'] ) ? $_GET['page'] : '' ), 'pinterest-pin-it-button' );
27
+
28
+ if ( ( isset( $_GET['tab'] ) && 'general' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] )
29
+ || ( !isset( $_GET['tab'] ) && $is_pib_settings_page !== false && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) ) {
30
+ add_settings_error( 'pib-notices', 'pib-general-updated', __( 'General settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
31
+ }
32
+
33
+ if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'post_visibility' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
34
+ add_settings_error( 'pib-notices', 'pib-post_visibility-updated', __( 'Post Visibility settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
35
+ }
36
+
37
+ if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'styles' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
38
+ add_settings_error( 'pib-notices', 'pib-styles-updated', __( 'Styles settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
39
+ }
40
+
41
+ if ( ( $is_pib_settings_page !== false ) && ( isset( $_GET['tab'] ) && 'advanced' == $_GET['tab'] ) && ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ) ) {
42
+ add_settings_error( 'pib-notices', 'pib-advanced-updated', __( 'Advanced settings updated. ' . $pib_vars['cache_message'], 'pib' ), 'updated' );
43
+ }
44
+
45
+ settings_errors( 'pib-notices' );
46
+ }
47
+
48
+ add_action( 'admin_notices', 'pib_register_admin_notices' );
includes/hooks-examples.php CHANGED
@@ -1,112 +1,112 @@
1
- <?php
2
-
3
- /*************************
4
- * FILTER HOOKS
5
- ************************/
6
-
7
- // Exit if accessed directly.
8
- if ( ! defined( 'ABSPATH' ) ) {
9
- exit;
10
- }
11
-
12
- /**
13
- * Modifies the HTML output of the shortcode button
14
- *
15
- * @since 2.0.3
16
- */
17
- function test_pib_shortcode_html( $html ) {
18
- return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
19
- }
20
- //add_filter( 'pib_shortcode_html', 'test_pib_shortcode_html' );
21
-
22
-
23
- /**
24
- * Used to modify the widget HTML
25
- *
26
- * @since 2.0.3
27
- */
28
- function test_pib_widget_html( $html ) {
29
- return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
30
- }
31
- //add_filter( 'pib_widget_html', 'test_pib_widget_html' );
32
-
33
-
34
- /**
35
- * Used to modify the regular button HTML
36
- *
37
- * @since 2.0.3
38
- */
39
- function test_pib_button_html( $html ) {
40
- return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
41
- }
42
- //add_filter( 'pib_button_html', 'test_pib_button_html' );
43
-
44
-
45
- /**
46
- * Outputs additional HTML before the PIB shortcode
47
- *
48
- * @since 2.0.3
49
- */
50
- function test_pib_shortcode_before( $before_html ) {
51
- return $before_html . '<p>Before</p>';
52
- }
53
- //add_filter( 'pib_shortcode_before', 'test_pib_shortcode_before' );
54
-
55
-
56
- /**
57
- * Outputs additional HTML after the PIB shortcode
58
- *
59
- * @since 2.0.3
60
- */
61
- function test_pib_shortcode_after() {
62
- return $after_html . '<p>After</p>';
63
- }
64
- //add_filter( 'pib_shortcode_after', 'test_pib_shortcode_after' );
65
-
66
-
67
- /**
68
- * Outputs additional HTML before the default button
69
- *
70
- * @since 2.0.3
71
- */
72
- function test_pib_button_before( $before_html ) {
73
- return '<p>Button Before</p>';
74
- }
75
- add_filter( 'pib_button_before', 'test_pib_button_before' );
76
-
77
-
78
- /**
79
- * Outputs additional HTML after the default button
80
- *
81
- * @since 2.0.3
82
- */
83
- function test_pib_button_after( $after_html ) {
84
- return '<p>Button After</p>';
85
- }
86
- add_filter( 'pib_button_after', 'test_pib_button_after' );
87
-
88
-
89
- /*************************
90
- * ACTION HOOKS
91
- ************************/
92
-
93
- /**
94
- * Outputs additional HTML after the default button
95
- *
96
- * @since 2.0.3
97
- */
98
- function test_pib_widget_before() {
99
- echo '<p>Widget Before</p>';
100
- }
101
- add_action( 'pib_widget_before', 'test_pib_widget_before' );
102
-
103
-
104
- /**
105
- * Outputs additional HTML after the default button
106
- *
107
- * @since 2.0.3
108
- */
109
- function test_pib_widget_after() {
110
- echo '<p>Widget After</p>';
111
- }
112
- add_action( 'pib_widget_after', 'test_pib_widget_after' );
1
+ <?php
2
+
3
+ /*************************
4
+ * FILTER HOOKS
5
+ ************************/
6
+
7
+ // Exit if accessed directly.
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ /**
13
+ * Modifies the HTML output of the shortcode button
14
+ *
15
+ * @since 2.0.3
16
+ */
17
+ function test_pib_shortcode_html( $html ) {
18
+ return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
19
+ }
20
+ //add_filter( 'pib_shortcode_html', 'test_pib_shortcode_html' );
21
+
22
+
23
+ /**
24
+ * Used to modify the widget HTML
25
+ *
26
+ * @since 2.0.3
27
+ */
28
+ function test_pib_widget_html( $html ) {
29
+ return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
30
+ }
31
+ //add_filter( 'pib_widget_html', 'test_pib_widget_html' );
32
+
33
+
34
+ /**
35
+ * Used to modify the regular button HTML
36
+ *
37
+ * @since 2.0.3
38
+ */
39
+ function test_pib_button_html( $html ) {
40
+ return '<div style="border: 5px solid #f00; padding: 15px;">' . $html . '</div>';
41
+ }
42
+ //add_filter( 'pib_button_html', 'test_pib_button_html' );
43
+
44
+
45
+ /**
46
+ * Outputs additional HTML before the PIB shortcode
47
+ *
48
+ * @since 2.0.3
49
+ */
50
+ function test_pib_shortcode_before( $before_html ) {
51
+ return $before_html . '<p>Before</p>';
52
+ }
53
+ //add_filter( 'pib_shortcode_before', 'test_pib_shortcode_before' );
54
+
55
+
56
+ /**
57
+ * Outputs additional HTML after the PIB shortcode
58
+ *
59
+ * @since 2.0.3
60
+ */
61
+ function test_pib_shortcode_after() {
62
+ return $after_html . '<p>After</p>';
63
+ }
64
+ //add_filter( 'pib_shortcode_after', 'test_pib_shortcode_after' );
65
+
66
+
67
+ /**
68
+ * Outputs additional HTML before the default button
69
+ *
70
+ * @since 2.0.3
71
+ */
72
+ function test_pib_button_before( $before_html ) {
73
+ return '<p>Button Before</p>';
74
+ }
75
+ add_filter( 'pib_button_before', 'test_pib_button_before' );
76
+
77
+
78
+ /**
79
+ * Outputs additional HTML after the default button
80
+ *
81
+ * @since 2.0.3
82
+ */
83
+ function test_pib_button_after( $after_html ) {
84
+ return '<p>Button After</p>';
85
+ }
86
+ add_filter( 'pib_button_after', 'test_pib_button_after' );
87
+
88
+
89
+ /*************************
90
+ * ACTION HOOKS
91
+ ************************/
92
+
93
+ /**
94
+ * Outputs additional HTML after the default button
95
+ *
96
+ * @since 2.0.3
97
+ */
98
+ function test_pib_widget_before() {
99
+ echo '<p>Widget Before</p>';
100
+ }
101
+ add_action( 'pib_widget_before', 'test_pib_widget_before' );
102
+
103
+
104
+ /**
105
+ * Outputs additional HTML after the default button
106
+ *
107
+ * @since 2.0.3
108
+ */
109
+ function test_pib_widget_after() {
110
+ echo '<p>Widget After</p>';
111
+ }
112
+ add_action( 'pib_widget_after', 'test_pib_widget_after' );
includes/misc-functions.php CHANGED
@@ -1,193 +1,193 @@
1
- <?php
2
-
3
- /**
4
- * Misc functions to use throughout the plugin.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
-
17
- /*
18
- * Reusable variables
19
- *
20
- * @since 2.0.3
21
- */
22
- global $pib_vars;
23
-
24
- $pib_vars['cache_message'] = 'If you have caching enabled please empty it before viewing your changes.';
25
- $pib_vars['post_meta_message'] = '';
26
-
27
-
28
- /**
29
- * Google Analytics campaign URL.
30
- *
31
- * @since 2.0.0
32
- *
33
- * @param string $base_url Plain URL to navigate to
34
- * @param string $source GA "source" tracking value
35
- * @param string $medium GA "medium" tracking value
36
- * @param string $campaign GA "campaign" tracking value
37
- * @return string $url Full Google Analytics campaign URL
38
- */
39
- function pib_ga_campaign_url( $base_url, $source, $medium, $campaign ) {
40
- // $source is always 'pib_lite_2' for Pit It Button Lite 2.x
41
- // $medium examples: 'sidebar_link', 'banner_image'
42
-
43
- $url = add_query_arg( array(
44
- 'utm_source' => $source,
45
- 'utm_medium' => $medium,
46
- 'utm_campaign' => $campaign
47
- ), $base_url );
48
-
49
- return $url;
50
- }
51
-
52
- /**
53
- * Render RSS items from pinplugins.com in unordered list.
54
- * http://codex.wordpress.org/Function_Reference/fetch_feed
55
- *
56
- * @since 2.0.0
57
- */
58
- function pib_rss_news() {
59
- // Get RSS Feed(s).
60
- include_once( ABSPATH . WPINC . '/feed.php' );
61
-
62
- // Get a SimplePie feed object from the specified feed source.
63
- $rss = fetch_feed( PINPLUGIN_BASE_URL . 'feed/' );
64
-
65
- if ( ! is_wp_error( $rss ) ) {
66
- // Checks that the object is created correctly.
67
- // Figure out how many total items there are, but limit it to 5.
68
- $maxitems = $rss->get_item_quantity( 3 );
69
-
70
- // Build an array of all the items, starting with element 0 (first element).
71
- $rss_items = $rss->get_items( 0, $maxitems );
72
- }
73
- ?>
74
-
75
- <ul>
76
- <?php if ($maxitems == 0): ?>
77
- <li><?php _e( 'No items.', 'pib' ); ?></li>
78
- <?php else: ?>
79
- <?php
80
- // Loop through each feed item and display each item as a hyperlink.
81
- foreach ( $rss_items as $item ): ?>
82
- <?php $post_url = add_query_arg( array(
83
-
84
- // Google Analytics campaign URL
85
- 'utm_source' => 'pib_lite_2',
86
- 'utm_medium' => 'sidebar_link',
87
- 'utm_campaign' => 'blog_post_link'
88
-
89
- ), esc_url( $item->get_permalink() ) ); ?>
90
-
91
- <li>
92
- <div class="dashicons dashicons-arrow-right-alt2"></div>
93
- <a href="<?php echo $post_url; ?>" target="_blank" class="pib-external-link"><?php echo esc_html( $item->get_title() ); ?></a>
94
- </li>
95
- <?php endforeach; ?>
96
- <?php endif; ?>
97
- </ul>
98
-
99
- <?php
100
- }
101
-
102
- /**
103
- * Check if the WooCommerce plugin is active.
104
- *
105
- * @since 2.0.0
106
- *
107
- * @return boolean
108
- */
109
- function pib_is_woo_commerce_active() {
110
- return class_exists( 'WooCommerce' );
111
-
112
- /*
113
- * Could also do:
114
- * if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
115
- *
116
- * References:
117
- * http://docs.woothemes.com/document/create-a-plugin/
118
- * http://www.wpmayor.com/articles/how-to-check-whether-a-plugin-is-active/
119
- * http://pippinsplugins.com/checking-dependent-plugin-active/
120
- */
121
- }
122
-
123
- /**
124
- * Check if the Article Rich Pins plugin is active.
125
- *
126
- * @since 2.0.2
127
- *
128
- * @return boolean
129
- */
130
- function pib_is_article_rich_pins_active() {
131
- return class_exists( 'Article_Rich_Pins' );
132
- }
133
-
134
- /**
135
- * Check if the WooCommerce Rich Pins plugin is active.
136
- *
137
- * @since 2.0.2
138
- *
139
- * @return boolean
140
- */
141
- function pib_is_wc_rich_pins_active() {
142
- return class_exists( 'WooCommerce_Rich_Pins' );
143
- }
144
-
145
-
146
- /**
147
- * Check if we should render the Pinterest button
148
- *
149
- * @since 2.0.2
150
- *
151
- * @return boolean
152
- */
153
- function pib_render_button() {
154
- global $pib_options, $post;
155
-
156
- $return = array();
157
-
158
- //Determine if button displayed on current page from main admin settings
159
- if (
160
- ( is_home() && ( ! empty( $pib_options['post_page_types']['display_home_page'] ) ) ) ||
161
- ( is_front_page() && ( ! empty( $pib_options['post_page_types']['display_front_page'] ) ) ) ||
162
- ( is_single() && ( ! empty( $pib_options['post_page_types']['display_posts'] ) ) ) ||
163
- ( is_page() && ( ! empty( $pib_options['post_page_types']['display_pages'] ) ) && !is_front_page() ) ||
164
-
165
- //archive pages besides categories (tag, author, date, search)
166
- //http://codex.wordpress.org/Conditional_Tags
167
- ( is_archive() && ( ! empty( $pib_options['post_page_types']['display_archives'] ) ) &&
168
- ( is_tag() || is_author() || is_date() || is_search() || is_category() )
169
- )
170
- ) {
171
- // Make sure the button is enabled for this post via post meta setting
172
- if( ! ( get_post_meta( $post->ID, 'pib_sharing_disabled', 1 ) ) ) {
173
- $return[] = 'button';
174
- }
175
-
176
- }
177
-
178
- // Check if a shortcode exists
179
- if( has_shortcode( $post->post_content, 'pinit' ) ) {
180
- $return[] = 'shortcode';
181
- }
182
-
183
- // Check if there is a widget
184
- if( is_active_widget( false, false, 'pib_button', true ) ) {
185
- $return[] = 'widget';
186
- }
187
-
188
- if( empty( $return ) ) {
189
- $return[] = 'no_buttons';
190
- }
191
-
192
- return $return;
193
- }
1
+ <?php
2
+
3
+ /**
4
+ * Misc functions to use throughout the plugin.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+
17
+ /*
18
+ * Reusable variables
19
+ *
20
+ * @since 2.0.3
21
+ */
22
+ global $pib_vars;
23
+
24
+ $pib_vars['cache_message'] = 'If you have caching enabled please empty it before viewing your changes.';
25
+ $pib_vars['post_meta_message'] = '';
26
+
27
+
28
+ /**
29
+ * Google Analytics campaign URL.
30
+ *
31
+ * @since 2.0.0
32
+ *
33
+ * @param string $base_url Plain URL to navigate to
34
+ * @param string $source GA "source" tracking value
35
+ * @param string $medium GA "medium" tracking value
36
+ * @param string $campaign GA "campaign" tracking value
37
+ * @return string $url Full Google Analytics campaign URL
38
+ */
39
+ function pib_ga_campaign_url( $base_url, $source, $medium, $campaign ) {
40
+ // $source is always 'pib_lite_2' for Pit It Button Lite 2.x
41
+ // $medium examples: 'sidebar_link', 'banner_image'
42
+
43
+ $url = add_query_arg( array(
44
+ 'utm_source' => $source,
45
+ 'utm_medium' => $medium,
46
+ 'utm_campaign' => $campaign
47
+ ), $base_url );
48
+
49
+ return $url;
50
+ }
51
+
52
+ /**
53
+ * Render RSS items from pinplugins.com in unordered list.
54
+ * http://codex.wordpress.org/Function_Reference/fetch_feed
55
+ *
56
+ * @since 2.0.0
57
+ */
58
+ function pib_rss_news() {
59
+ // Get RSS Feed(s).
60
+ include_once( ABSPATH . WPINC . '/feed.php' );
61
+
62
+ // Get a SimplePie feed object from the specified feed source.
63
+ $rss = fetch_feed( PINPLUGIN_BASE_URL . 'feed/' );
64
+
65
+ if ( ! is_wp_error( $rss ) ) {
66
+ // Checks that the object is created correctly.
67
+ // Figure out how many total items there are, but limit it to 5.
68
+ $maxitems = $rss->get_item_quantity( 3 );
69
+
70
+ // Build an array of all the items, starting with element 0 (first element).
71
+ $rss_items = $rss->get_items( 0, $maxitems );
72
+ }
73
+ ?>
74
+
75
+ <ul>
76
+ <?php if ($maxitems == 0): ?>
77
+ <li><?php _e( 'No items.', 'pib' ); ?></li>
78
+ <?php else: ?>
79
+ <?php
80
+ // Loop through each feed item and display each item as a hyperlink.
81
+ foreach ( $rss_items as $item ): ?>
82
+ <?php $post_url = add_query_arg( array(
83
+
84
+ // Google Analytics campaign URL
85
+ 'utm_source' => 'pib_lite_2',
86
+ 'utm_medium' => 'sidebar_link',
87
+ 'utm_campaign' => 'blog_post_link'
88
+
89
+ ), esc_url( $item->get_permalink() ) ); ?>
90
+
91
+ <li>
92
+ <div class="dashicons dashicons-arrow-right-alt2"></div>
93
+ <a href="<?php echo $post_url; ?>" target="_blank"><?php echo esc_html( $item->get_title() ); ?></a>
94
+ </li>
95
+ <?php endforeach; ?>
96
+ <?php endif; ?>
97
+ </ul>
98
+
99
+ <?php
100
+ }
101
+
102
+ /**
103
+ * Check if the WooCommerce plugin is active.
104
+ *
105
+ * @since 2.0.0
106
+ *
107
+ * @return boolean
108
+ */
109
+ function pib_is_woo_commerce_active() {
110
+ return class_exists( 'WooCommerce' );
111
+
112
+ /*
113
+ * Could also do:
114
+ * if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
115
+ *
116
+ * References:
117
+ * http://docs.woothemes.com/document/create-a-plugin/
118
+ * http://www.wpmayor.com/articles/how-to-check-whether-a-plugin-is-active/
119
+ * http://pippinsplugins.com/checking-dependent-plugin-active/
120
+ */
121
+ }
122
+
123
+ /**
124
+ * Check if the Article Rich Pins plugin is active.
125
+ *
126
+ * @since 2.0.2
127
+ *
128
+ * @return boolean
129
+ */
130
+ function pib_is_article_rich_pins_active() {
131
+ return class_exists( 'Article_Rich_Pins' );
132
+ }
133
+
134
+ /**
135
+ * Check if the WooCommerce Rich Pins plugin is active.
136
+ *
137
+ * @since 2.0.2
138
+ *
139
+ * @return boolean
140
+ */
141
+ function pib_is_wc_rich_pins_active() {
142
+ return class_exists( 'WooCommerce_Rich_Pins' );
143
+ }
144
+
145
+
146
+ /**
147
+ * Check if we should render the Pinterest button
148
+ *
149
+ * @since 2.0.2
150
+ *
151
+ * @return boolean
152
+ */
153
+ function pib_render_button() {
154
+ global $pib_options, $post;
155
+
156
+ $return = array();
157
+
158
+ //Determine if button displayed on current page from main admin settings
159
+ if (
160
+ ( is_home() && ( ! empty( $pib_options['post_page_types']['display_home_page'] ) ) ) ||
161
+ ( is_front_page() && ( ! empty( $pib_options['post_page_types']['display_front_page'] ) ) ) ||
162
+ ( is_single() && ( ! empty( $pib_options['post_page_types']['display_posts'] ) ) ) ||
163
+ ( is_page() && ( ! empty( $pib_options['post_page_types']['display_pages'] ) ) && !is_front_page() ) ||
164
+
165
+ //archive pages besides categories (tag, author, date, search)
166
+ //http://codex.wordpress.org/Conditional_Tags
167
+ ( is_archive() && ( ! empty( $pib_options['post_page_types']['display_archives'] ) ) &&
168
+ ( is_tag() || is_author() || is_date() || is_search() || is_category() )
169
+ )
170
+ ) {
171
+ // Make sure the button is enabled for this post via post meta setting
172
+ if( ! ( get_post_meta( $post->ID, 'pib_sharing_disabled', 1 ) ) ) {
173
+ $return[] = 'button';
174
+ }
175
+
176
+ }
177
+
178
+ // Check if a shortcode exists
179
+ if( has_shortcode( $post->post_content, 'pinit' ) ) {
180
+ $return[] = 'shortcode';
181
+ }
182
+
183
+ // Check if there is a widget
184
+ if( is_active_widget( false, false, 'pib_button', true ) ) {
185
+ $return[] = 'widget';
186
+ }
187
+
188
+ if( empty( $return ) ) {
189
+ $return[] = 'no_buttons';
190
+ }
191
+
192
+ return $return;
193
+ }
includes/register-settings.php CHANGED
@@ -1,539 +1,539 @@
1
- <?php
2
-
3
- /**
4
- * Register all settings needed for the Settings API.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- /**
17
- * Main function to register all of the plugin settings
18
- *
19
- * @since 2.0.0
20
- */
21
- function pib_register_settings() {
22
- $pib_settings = array(
23
-
24
- /* General Settings */
25
- 'general' => array(
26
- 'button_type' => array(
27
- 'id' => 'button_type',
28
- 'name' => __( 'Button Type', 'pib' ),
29
- 'desc' => '',
30
- 'type' => 'radio',
31
- 'std' => 'no',
32
- 'options' => array(
33
- 'user_selects_image' => __( 'User selects image from popup (any image)', 'pib' ),
34
- 'image_selected' => __( 'Image is pre-selected (one image -- defaults to first image in post)', 'pib' )
35
- )
36
- ),
37
- 'count_layout' => array(
38
- 'id' => 'count_layout',
39
- 'name' => __( 'Pin Count', 'pib' ),
40
- 'desc' => '',
41
- 'type' => 'select',
42
- 'options' => array(
43
- 'none' => __( 'Not Shown', 'pib' ),
44
- 'horizontal' => __( 'Beside the Button', 'pib' ),
45
- 'vertical' => __( 'Above the Button', 'pib' )
46
- )
47
- ),
48
- 'show_zero_count' => array(
49
- 'id' => 'show_zero_count',
50
- 'name' => '',
51
- 'desc' => __( 'Show count bubble when there are zero pins.', 'pib' ),
52
- 'type' => 'checkbox'
53
- ),
54
- 'data_pin_size' => array(
55
- 'id' => 'data_pin_size',
56
- 'name' => __( 'Button Size', 'pib' ),
57
- 'desc' => '',
58
- 'type' => 'select',
59
- 'options' => array(
60
- 'small' => __( 'Small', 'pib' ),
61
- 'large' => __( 'Large', 'pib' )
62
- )
63
- ),
64
- 'data_pin_shape' => array(
65
- 'id' => 'data_pin_shape',
66
- 'name' => __( 'Button Shape', 'pib' ),
67
- 'desc' => '',
68
- 'type' => 'select',
69
- 'options' => array(
70
- 'rectangular' => __( 'Rectangular', 'pib' ),
71
- 'circular' => __( 'Circular', 'pib' )
72
- )
73
- ),
74
- 'data_pin_color' => array(
75
- 'id' => 'data_pin_color',
76
- 'name' => __( 'Button Color', 'pib' ),
77
- 'desc' => __( 'Color ignored if button shape is <strong>Circular</strong>.', 'pib' ),
78
- 'type' => 'select',
79
- 'options' => array(
80
- 'gray' => __( 'Gray', 'pib' ),
81
- 'red' => __( 'Red', 'pib' ),
82
- 'white' => __( 'White', 'pib' )
83
- )
84
- ),
85
- 'uninstall_save_settings' => array(
86
- 'id' => 'uninstall_save_settings',
87
- 'name' => __( 'Save Settings', 'pib' ),
88
- 'desc' => __( 'Save your settings when uninstalling this plugin. Useful when upgrading or re-installing.', 'pib' ),
89
- 'type' => 'checkbox'
90
- )
91
- ),
92
-
93
- /* Post Visibility Settings */
94
- 'post_visibility' => array(
95
- 'post_page_types' => array(
96
- 'id' => 'post_page_types',
97
- 'name' => __( 'Post/Page Types', 'pib' ),
98
- 'desc' => __( 'You may individually hide the "Pin It" button per post/page. This field is located towards the bottom of the post/page edit screen.', 'pib' ),
99
- 'type' => 'multicheck',
100
- 'options' => array(
101
- 'display_home_page' => __( 'Home Page (or latest posts page)', 'pib' ),
102
- 'display_front_page' => __( 'Front Page (different from Home Page only if set in Settings > Reading)', 'pib' ),
103
- 'display_posts' => __( 'Individual Posts', 'pib' ),
104
- 'display_pages' => __( 'Individual Pages (WordPress static pages)', 'pib' ),
105
- 'display_archives' => __( 'Archive Pages (includes Category, Tag, Author, and date-based pages)', 'pib' )
106
- )
107
- ),
108
- 'post_page_placement' => array(
109
- 'id' => 'post_page_placement',
110
- 'name' => __( 'Post/Page Placement', 'pib' ),
111
- 'desc' => __( 'Only the button style <strong>"Image is pre-selected"</strong> will use the individual post URL when a visitor pins from a post excerpt.', 'pib' ) . '<br />' .
112
- sprintf( __( 'Go to Appearance &rarr; <a href="%s">Widgets</a> to add a "Pin It" button to your sidebar or other widget area.', 'pib' ), admin_url( 'widgets.php' ) ),
113
- 'type' => 'multicheck',
114
- 'options' => array(
115
- 'display_above_content' => __( 'Above Content', 'pib' ),
116
- 'display_below_content' => __( 'Below Content', 'pib' ),
117
- 'display_on_post_excerpts' => __( 'Include in Post Excerpts', 'pib' )
118
- )
119
- )
120
- ),
121
-
122
- /* Styles Settings */
123
- 'styles' => array(
124
- 'custom_css' => array(
125
- 'id' => 'custom_css',
126
- 'name' => __( 'Custom CSS', 'pib' ),
127
- 'desc' => __( 'Custom CSS can be used to override other CSS style rules.', 'pib' ) . '<br />' .
128
- sprintf( __( 'Visit the <a href="%s">Help Section</a> for CSS override examples.', 'pib' ), add_query_arg( 'page', PIB_PLUGIN_SLUG . '_help', admin_url( 'admin.php' ) ) ),
129
- 'type' => 'textarea'
130
- ),
131
- 'remove_div' => array(
132
- 'id' => 'remove_div',
133
- 'name' => __( 'Remove DIV Container', 'pib' ),
134
- 'desc' => __( 'Remove DIV tag surrounding regular button', 'pib' ) . '(<code>' . htmlspecialchars( '<div class="pin-it-btn-wrapper"></div>' ) . '</code>)',
135
- 'type' => 'checkbox'
136
- ),
137
- 'disable_css' => array(
138
- 'id' => 'disable_css',
139
- 'name' => __( 'Disable CSS File Reference', 'pib' ),
140
- 'desc' => __( 'Advanced. Will prevent the plugin\'s CSS file from being referenced. Custom CSS above will still be included.', 'pib' ),
141
- 'type' => 'checkbox'
142
- )
143
- ),
144
-
145
- /* Advanced Settings */
146
- 'advanced' => array(
147
- 'no_pinit_js' => array(
148
- 'id' => 'no_pinit_js',
149
- 'name' => __( 'Disable <code>pinit.js</code>', 'pib' ),
150
- 'desc' => __( 'Disable output of <code>pinit.js</code>, the JavaScript file for all widgets from Pinterest.', 'pib' ) .
151
- '<p class="description">' . __( 'Check this option if you have <code>pinit.js</code> referenced in another plugin, widget or your theme. ' .
152
- 'Ouputting <code>pinit.js</code> more than once on a page can cause conflicts.', 'pib' ) . '</p>',
153
- 'type' => 'checkbox'
154
- )
155
- )
156
- );
157
-
158
- /* If the options do not exist then create them for each section */
159
- if ( false == get_option( 'pib_settings_general' ) ) {
160
- add_option( 'pib_settings_general' );
161
- }
162
-
163
- if ( false == get_option( 'pib_settings_post_visibility' ) ) {
164
- add_option( 'pib_settings_post_visibility' );
165
- }
166
-
167
- if ( false == get_option( 'pib_settings_styles' ) ) {
168
- add_option( 'pib_settings_styles' );
169
- }
170
-
171
- if( false == get_option( 'pib_settings_advanced' ) ){
172
- add_option( 'pib_settings_advanced' );
173
- }
174
-
175
- /* Add the General Settings section */
176
- add_settings_section(
177
- 'pib_settings_general',
178
- __( 'General Settings', 'pib' ),
179
- '__return_false',
180
- 'pib_settings_general'
181
- );
182
-
183
- foreach ( $pib_settings['general'] as $option ) {
184
- add_settings_field(
185
- 'pib_settings_general[' . $option['id'] . ']',
186
- $option['name'],
187
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
188
- 'pib_settings_general',
189
- 'pib_settings_general',
190
- pib_get_settings_field_args( $option, 'general' )
191
- );
192
- }
193
-
194
- /* Add the Post Visibility Settings section */
195
- add_settings_section(
196
- 'pib_settings_post_visibility',
197
- __( 'Post Visibility Settings', 'pib' ),
198
- '__return_false',
199
- 'pib_settings_post_visibility'
200
- );
201
-
202
- foreach ( $pib_settings['post_visibility'] as $option ) {
203
- add_settings_field(
204
- 'pib_settings_post_visibility[' . $option['id'] . ']',
205
- $option['name'],
206
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
207
- 'pib_settings_post_visibility',
208
- 'pib_settings_post_visibility',
209
- pib_get_settings_field_args( $option, 'post_visibility' )
210
- );
211
- }
212
-
213
- /* Add the Styles Settings section */
214
- add_settings_section(
215
- 'pib_settings_styles',
216
- __( 'Style Settings', 'pib' ),
217
- '__return_false',
218
- 'pib_settings_styles'
219
- );
220
-
221
- foreach ( $pib_settings['styles'] as $option ) {
222
- add_settings_field(
223
- 'pib_settings_styles[' . $option['id'] . ']',
224
- $option['name'],
225
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
226
- 'pib_settings_styles',
227
- 'pib_settings_styles',
228
- pib_get_settings_field_args( $option, 'styles' )
229
- );
230
- }
231
-
232
- /* Add the Advanced Settings section */
233
- add_settings_section(
234
- 'pib_settings_advanced',
235
- __( 'Advanced Settings', 'pib' ),
236
- '__return_false',
237
- 'pib_settings_advanced'
238
- );
239
-
240
- foreach ( $pib_settings['advanced'] as $option ) {
241
- add_settings_field(
242
- 'pib_settings_advanced[' . $option['id'] . ']',
243
- $option['name'],
244
- function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
245
- 'pib_settings_advanced',
246
- 'pib_settings_advanced',
247
- pib_get_settings_field_args( $option, 'advanced' )
248
- );
249
- }
250
-
251
- /* Register all settings or we will get an error when trying to save */
252
- register_setting( 'pib_settings_general', 'pib_settings_general', 'pib_settings_sanitize' );
253
- register_setting( 'pib_settings_post_visibility', 'pib_settings_post_visibility', 'pib_settings_sanitize' );
254
- register_setting( 'pib_settings_styles', 'pib_settings_styles', 'pib_settings_sanitize' );
255
- register_setting( 'pib_settings_advanced', 'pib_settings_advanced', 'pib_settings_sanitize' );
256
-
257
- }
258
- add_action( 'admin_init', 'pib_register_settings' );
259
-
260
- /*
261
- * Return generic add_settings_field $args parameter array.
262
- *
263
- * @since 2.0.0
264
- *
265
- * @param string $option Single settings option key.
266
- * @param string $section Section of settings apge.
267
- * @return array $args parameter to use with add_settings_field call.
268
- */
269
- function pib_get_settings_field_args( $option, $section ) {
270
- $settings_args = array(
271
- 'id' => $option['id'],
272
- 'desc' => $option['desc'],
273
- 'name' => $option['name'],
274
- 'section' => $section,
275
- 'size' => isset( $option['size'] ) ? $option['size'] : null,
276
- 'options' => isset( $option['options'] ) ? $option['options'] : '',
277
- 'std' => isset( $option['std'] ) ? $option['std'] : ''
278
- );
279
-
280
- // Link label to input using 'label_for' argument if text, textarea, password, select, or variations of.
281
- // Just add to existing settings args array if needed.
282
- if ( in_array( $option['type'], array( 'text', 'select', 'textarea', 'password', 'number' ) ) ) {
283
- $settings_args = array_merge( $settings_args, array( 'label_for' => 'pib_settings_' . $section . '[' . $option['id'] . ']' ) );
284
- }
285
-
286
- return $settings_args;
287
- }
288
-
289
- /*
290
- * Radio button callback function
291
- *
292
- * @since 2.0.0
293
- *
294
- */
295
- function pib_radio_callback( $args ) {
296
- global $pib_options;
297
-
298
- // Return empty string if no options.
299
- if ( empty( $args['options'] ) ) {
300
- echo '';
301
- return;
302
- }
303
-
304
- $html = "\n";
305
-
306
- foreach ( $args['options'] as $key => $option ) {
307
- $checked = false;
308
-
309
- if ( isset( $pib_options[ $args['id'] ] ) && $pib_options[ $args['id'] ] == $key )
310
- $checked = true;
311
- elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $pib_options[ $args['id'] ] ) )
312
- $checked = true;
313
-
314
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-radio-label">';
315
- $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>' . "\n";
316
- $html .= $option . '</label>';
317
- }
318
-
319
- // Render and style description text underneath if it exists.
320
- if ( ! empty( $args['desc'] ) )
321
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
322
-
323
- echo $html;
324
- }
325
-
326
- /*
327
- * Single checkbox callback function
328
- *
329
- * @since 2.0.0
330
- *
331
- */
332
- function pib_checkbox_callback( $args ) {
333
- global $pib_options;
334
-
335
- $checked = isset( $pib_options[$args['id']] ) ? checked( 1, $pib_options[$args['id']], false ) : '';
336
- $html = "\n" . '<input type="checkbox" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="1" ' . $checked . '/>' . "\n";
337
-
338
- // Render description text directly to the right in a label if it exists.
339
- if ( ! empty( $args['desc'] ) )
340
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
341
-
342
- echo $html;
343
- }
344
-
345
- /*
346
- * Multiple checkboxes callback function
347
- *
348
- * @since 2.0.0
349
- *
350
- */
351
- function pib_multicheck_callback( $args ) {
352
- global $pib_options;
353
-
354
- // Return empty string if no options.
355
- if ( empty( $args['options'] ) ) {
356
- echo '';
357
- return;
358
- }
359
-
360
- $html = "\n";
361
-
362
- foreach ( $args['options'] as $key => $option ) {
363
- if ( isset( $pib_options[$args['id']][$key] ) ) { $enabled = $option; } else { $enabled = NULL; }
364
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-checkbox-label">';
365
- $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="checkbox" value="' . $option . '" ' . checked($option, $enabled, false) . '/>' . "\n";
366
- $html .= $option . '</label>';
367
- }
368
-
369
- // Render and style description text underneath if it exists.
370
- if ( ! empty( $args['desc'] ) )
371
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
372
-
373
- echo $html;
374
- }
375
-
376
- /*
377
- * Select box callback function
378
- *
379
- * @since 2.0.0
380
- *
381
- */
382
- function pib_select_callback( $args ) {
383
- global $pib_options;
384
-
385
- // Return empty string if no options.
386
- if ( empty( $args['options'] ) ) {
387
- echo '';
388
- return;
389
- }
390
-
391
- $html = "\n" . '<select id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"/>' . "\n";
392
-
393
- foreach ( $args['options'] as $option => $name ) :
394
- $selected = isset( $pib_options[$args['id']] ) ? selected( $option, $pib_options[$args['id']], false ) : '';
395
- $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>' . "\n";
396
- endforeach;
397
-
398
- $html .= '</select>' . "\n";
399
-
400
- // Render and style description text underneath if it exists.
401
- if ( ! empty( $args['desc'] ) )
402
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
403
-
404
- echo $html;
405
- }
406
-
407
- /*
408
- * Textarea callback function
409
- *
410
- * @since 2.0.0
411
- *
412
- */
413
- function pib_textarea_callback( $args ) {
414
- global $pib_options;
415
-
416
- if ( isset( $pib_options[ $args['id'] ] ) )
417
- $value = $pib_options[ $args['id'] ];
418
- else
419
- $value = isset( $args['std'] ) ? $args['std'] : '';
420
-
421
- // Ignoring size at the moment.
422
- $html = "\n" . '<textarea class="large-text" cols="50" rows="10" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']">' . esc_textarea( $value ) . '</textarea>' . "\n";
423
-
424
- // Render and style description text underneath if it exists.
425
- if ( ! empty( $args['desc'] ) )
426
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
427
-
428
- echo $html;
429
- }
430
-
431
- /**
432
- * Number callback function
433
- *
434
- * @since 2.0.0
435
- *
436
- */
437
- function pib_number_callback( $args ) {
438
- global $pib_options;
439
-
440
- if ( isset( $pib_options[ $args['id'] ] ) )
441
- $value = $pib_options[ $args['id'] ];
442
- else
443
- $value = isset( $args['std'] ) ? $args['std'] : '';
444
-
445
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
446
- $html = "\n" . '<input type="number" class="' . $size . '-text" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" step="1" value="' . esc_attr( $value ) . '"/>' . "\n";
447
-
448
- // Render description text directly to the right in a label if it exists.
449
- if ( ! empty( $args['desc'] ) )
450
- $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
451
-
452
- echo $html;
453
- }
454
-
455
- /**
456
- * Textbox callback function
457
- * Valid built-in size CSS class values:
458
- * small-text, regular-text, large-text
459
- *
460
- * @since 2.0.0
461
- *
462
- */
463
- function pib_text_callback( $args ) {
464
- global $pib_options;
465
-
466
- if ( isset( $pib_options[ $args['id'] ] ) )
467
- $value = $pib_options[ $args['id'] ];
468
- else
469
- $value = isset( $args['std'] ) ? $args['std'] : '';
470
-
471
- $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : '';
472
- $html = "\n" . '<input type="text" class="' . $size . '" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>' . "\n";
473
-
474
- // Render and style description text underneath if it exists.
475
- if ( ! empty( $args['desc'] ) )
476
- $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
477
-
478
- echo $html;
479
- }
480
-
481
- /*
482
- * Function we can use to sanitize the input data and return it when saving options
483
- *
484
- * @since 2.0.0
485
- *
486
- */
487
- function pib_settings_sanitize( $input ) {
488
- add_settings_error( 'pib-notices', '', '', '' );
489
- return $input;
490
- }
491
-
492
- /*
493
- * Default callback function if correct one does not exist
494
- *
495
- * @since 2.0.0
496
- *
497
- */
498
- function pib_missing_callback( $args ) {
499
- printf( __( 'The callback function used for the <strong>%s</strong> setting is missing.', 'pib' ), $args['id'] );
500
- }
501
-
502
- /*
503
- * Function used to return an array of all of the plugin settings
504
- *
505
- * @since 2.0.0
506
- *
507
- */
508
- function pib_get_settings() {
509
-
510
- // If this is the first time running we need to set the defaults
511
- if ( !get_option( 'pib_upgrade_has_run' ) ) {
512
-
513
- // set default post visibility options
514
- $post_visibility = get_option( 'pib_settings_post_visibility' );
515
- $post_visibility['post_page_types']['display_home_page'] = 1;
516
- $post_visibility['post_page_types']['display_posts'] = 1;
517
- $post_visibility['post_page_placement']['display_below_content'] = 1;
518
-
519
- update_option( 'pib_settings_post_visibility', $post_visibility );
520
-
521
- // set default general settings options
522
- $general = get_option( 'pib_settings_general' );
523
- $general['button_type'] = 'user_selects_image';
524
- $general['count_layout'] = 'none';
525
- $general['uninstall_save_settings'] = 1;
526
-
527
- update_option( 'pib_settings_general', $general );
528
-
529
- // add an option to let us know the initial settings have been run and we don't run them again
530
- add_option( 'pib_upgrade_has_run', 1 );
531
- }
532
-
533
- $general_settings = is_array( get_option( 'pib_settings_general' ) ) ? get_option( 'pib_settings_general' ) : array();
534
- $post_visibility_settings = is_array( get_option( 'pib_settings_post_visibility' ) ) ? get_option( 'pib_settings_post_visibility' ) : array();
535
- $style_settings = is_array( get_option( 'pib_settings_styles' ) ) ? get_option( 'pib_settings_styles' ) : array();
536
- $advanced_settings = is_array( get_option( 'pib_settings_advanced' ) ) ? get_option( 'pib_settings_advanced' ) : array();
537
-
538
- return array_merge( $general_settings, $post_visibility_settings, $style_settings, $advanced_settings );
539
- }
1
+ <?php
2
+
3
+ /**
4
+ * Register all settings needed for the Settings API.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Main function to register all of the plugin settings
18
+ *
19
+ * @since 2.0.0
20
+ */
21
+ function pib_register_settings() {
22
+ $pib_settings = array(
23
+
24
+ /* General Settings */
25
+ 'general' => array(
26
+ 'button_type' => array(
27
+ 'id' => 'button_type',
28
+ 'name' => __( 'Button Type', 'pib' ),
29
+ 'desc' => '',
30
+ 'type' => 'radio',
31
+ 'std' => 'no',
32
+ 'options' => array(
33
+ 'user_selects_image' => __( 'User selects image from popup (any image)', 'pib' ),
34
+ 'image_selected' => __( 'Image is pre-selected (one image -- defaults to first image in post)', 'pib' )
35
+ )
36
+ ),
37
+ 'count_layout' => array(
38
+ 'id' => 'count_layout',
39
+ 'name' => __( 'Pin Count', 'pib' ),
40
+ 'desc' => '',
41
+ 'type' => 'select',
42
+ 'options' => array(
43
+ 'none' => __( 'Not Shown', 'pib' ),
44
+ 'horizontal' => __( 'Beside the Button', 'pib' ),
45
+ 'vertical' => __( 'Above the Button', 'pib' )
46
+ )
47
+ ),
48
+ 'show_zero_count' => array(
49
+ 'id' => 'show_zero_count',
50
+ 'name' => '',
51
+ 'desc' => __( 'Show count bubble when there are zero pins.', 'pib' ),
52
+ 'type' => 'checkbox'
53
+ ),
54
+ 'data_pin_size' => array(
55
+ 'id' => 'data_pin_size',
56
+ 'name' => __( 'Button Size', 'pib' ),
57
+ 'desc' => '',
58
+ 'type' => 'select',
59
+ 'options' => array(
60
+ 'small' => __( 'Small', 'pib' ),
61
+ 'large' => __( 'Large', 'pib' )
62
+ )
63
+ ),
64
+ 'data_pin_shape' => array(
65
+ 'id' => 'data_pin_shape',
66
+ 'name' => __( 'Button Shape', 'pib' ),
67
+ 'desc' => '',
68
+ 'type' => 'select',
69
+ 'options' => array(
70
+ 'rectangular' => __( 'Rectangular', 'pib' ),
71
+ 'circular' => __( 'Circular', 'pib' )
72
+ )
73
+ ),
74
+ 'data_pin_color' => array(
75
+ 'id' => 'data_pin_color',
76
+ 'name' => __( 'Button Color', 'pib' ),
77
+ 'desc' => __( 'Color ignored if button shape is <strong>Circular</strong>.', 'pib' ),
78
+ 'type' => 'select',
79
+ 'options' => array(
80
+ 'gray' => __( 'Gray', 'pib' ),
81
+ 'red' => __( 'Red', 'pib' ),
82
+ 'white' => __( 'White', 'pib' )
83
+ )
84
+ ),
85
+ 'uninstall_save_settings' => array(
86
+ 'id' => 'uninstall_save_settings',
87
+ 'name' => __( 'Save Settings', 'pib' ),
88
+ 'desc' => __( 'Save your settings when uninstalling this plugin. Useful when upgrading or re-installing.', 'pib' ),
89
+ 'type' => 'checkbox'
90
+ )
91
+ ),
92
+
93
+ /* Post Visibility Settings */
94
+ 'post_visibility' => array(
95
+ 'post_page_types' => array(
96
+ 'id' => 'post_page_types',
97
+ 'name' => __( 'Post/Page Types', 'pib' ),
98
+ 'desc' => __( 'You may individually hide the "Pin It" button per post/page. This field is located towards the bottom of the post/page edit screen.', 'pib' ),
99
+ 'type' => 'multicheck',
100
+ 'options' => array(
101
+ 'display_home_page' => __( 'Home Page (or latest posts page)', 'pib' ),
102
+ 'display_front_page' => __( 'Front Page (different from Home Page only if set in Settings > Reading)', 'pib' ),
103
+ 'display_posts' => __( 'Individual Posts', 'pib' ),
104
+ 'display_pages' => __( 'Individual Pages (WordPress static pages)', 'pib' ),
105
+ 'display_archives' => __( 'Archive Pages (includes Category, Tag, Author, and date-based pages)', 'pib' )
106
+ )
107
+ ),
108
+ 'post_page_placement' => array(
109
+ 'id' => 'post_page_placement',
110
+ 'name' => __( 'Post/Page Placement', 'pib' ),
111
+ 'desc' => __( 'Only the button style <strong>"Image is pre-selected"</strong> will use the individual post URL when a visitor pins from a post excerpt.', 'pib' ) . '<br />' .
112
+ sprintf( __( 'Go to Appearance &rarr; <a href="%s">Widgets</a> to add a "Pin It" button to your sidebar or other widget area.', 'pib' ), admin_url( 'widgets.php' ) ),
113
+ 'type' => 'multicheck',
114
+ 'options' => array(
115
+ 'display_above_content' => __( 'Above Content', 'pib' ),
116
+ 'display_below_content' => __( 'Below Content', 'pib' ),
117
+ 'display_on_post_excerpts' => __( 'Include in Post Excerpts', 'pib' )
118
+ )
119
+ )
120
+ ),
121
+
122
+ /* Styles Settings */
123
+ 'styles' => array(
124
+ 'custom_css' => array(
125
+ 'id' => 'custom_css',
126
+ 'name' => __( 'Custom CSS', 'pib' ),
127
+ 'desc' => __( 'Custom CSS can be used to override other CSS style rules.', 'pib' ) . '<br />' .
128
+ sprintf( __( 'Visit the <a href="%s">Help Section</a> for CSS override examples.', 'pib' ), add_query_arg( 'page', PIB_PLUGIN_SLUG . '_help', admin_url( 'admin.php' ) ) ),
129
+ 'type' => 'textarea'
130
+ ),
131
+ 'remove_div' => array(
132
+ 'id' => 'remove_div',
133
+ 'name' => __( 'Remove DIV Container', 'pib' ),
134
+ 'desc' => __( 'Remove DIV tag surrounding regular button', 'pib' ) . '(<code>' . htmlspecialchars( '<div class="pin-it-btn-wrapper"></div>' ) . '</code>)',
135
+ 'type' => 'checkbox'
136
+ ),
137
+ 'disable_css' => array(
138
+ 'id' => 'disable_css',
139
+ 'name' => __( 'Disable CSS File Reference', 'pib' ),
140
+ 'desc' => __( 'Advanced. Will prevent the plugin\'s CSS file from being referenced. Custom CSS above will still be included.', 'pib' ),
141
+ 'type' => 'checkbox'
142
+ )
143
+ ),
144
+
145
+ /* Advanced Settings */
146
+ 'advanced' => array(
147
+ 'no_pinit_js' => array(
148
+ 'id' => 'no_pinit_js',
149
+ 'name' => __( 'Disable <code>pinit.js</code>', 'pib' ),
150
+ 'desc' => __( 'Disable output of <code>pinit.js</code>, the JavaScript file for all widgets from Pinterest.', 'pib' ) .
151
+ '<p class="description">' . __( 'Check this option if you have <code>pinit.js</code> referenced in another plugin, widget or your theme. ' .
152
+ 'Ouputting <code>pinit.js</code> more than once on a page can cause conflicts.', 'pib' ) . '</p>',
153
+ 'type' => 'checkbox'
154
+ )
155
+ )
156
+ );
157
+
158
+ /* If the options do not exist then create them for each section */
159
+ if ( false == get_option( 'pib_settings_general' ) ) {
160
+ add_option( 'pib_settings_general' );
161
+ }
162
+
163
+ if ( false == get_option( 'pib_settings_post_visibility' ) ) {
164
+ add_option( 'pib_settings_post_visibility' );
165
+ }
166
+
167
+ if ( false == get_option( 'pib_settings_styles' ) ) {
168
+ add_option( 'pib_settings_styles' );
169
+ }
170
+
171
+ if( false == get_option( 'pib_settings_advanced' ) ){
172
+ add_option( 'pib_settings_advanced' );
173
+ }
174
+
175
+ /* Add the General Settings section */
176
+ add_settings_section(
177
+ 'pib_settings_general',
178
+ __( 'General Settings', 'pib' ),
179
+ '__return_false',
180
+ 'pib_settings_general'
181
+ );
182
+
183
+ foreach ( $pib_settings['general'] as $option ) {
184
+ add_settings_field(
185
+ 'pib_settings_general[' . $option['id'] . ']',
186
+ $option['name'],
187
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
188
+ 'pib_settings_general',
189
+ 'pib_settings_general',
190
+ pib_get_settings_field_args( $option, 'general' )
191
+ );
192
+ }
193
+
194
+ /* Add the Post Visibility Settings section */
195
+ add_settings_section(
196
+ 'pib_settings_post_visibility',
197
+ __( 'Post Visibility Settings', 'pib' ),
198
+ '__return_false',
199
+ 'pib_settings_post_visibility'
200
+ );
201
+
202
+ foreach ( $pib_settings['post_visibility'] as $option ) {
203
+ add_settings_field(
204
+ 'pib_settings_post_visibility[' . $option['id'] . ']',
205
+ $option['name'],
206
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
207
+ 'pib_settings_post_visibility',
208
+ 'pib_settings_post_visibility',
209
+ pib_get_settings_field_args( $option, 'post_visibility' )
210
+ );
211
+ }
212
+
213
+ /* Add the Styles Settings section */
214
+ add_settings_section(
215
+ 'pib_settings_styles',
216
+ __( 'Style Settings', 'pib' ),
217
+ '__return_false',
218
+ 'pib_settings_styles'
219
+ );
220
+
221
+ foreach ( $pib_settings['styles'] as $option ) {
222
+ add_settings_field(
223
+ 'pib_settings_styles[' . $option['id'] . ']',
224
+ $option['name'],
225
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
226
+ 'pib_settings_styles',
227
+ 'pib_settings_styles',
228
+ pib_get_settings_field_args( $option, 'styles' )
229
+ );
230
+ }
231
+
232
+ /* Add the Advanced Settings section */
233
+ add_settings_section(
234
+ 'pib_settings_advanced',
235
+ __( 'Advanced Settings', 'pib' ),
236
+ '__return_false',
237
+ 'pib_settings_advanced'
238
+ );
239
+
240
+ foreach ( $pib_settings['advanced'] as $option ) {
241
+ add_settings_field(
242
+ 'pib_settings_advanced[' . $option['id'] . ']',
243
+ $option['name'],
244
+ function_exists( 'pib_' . $option['type'] . '_callback' ) ? 'pib_' . $option['type'] . '_callback' : 'pib_missing_callback',
245
+ 'pib_settings_advanced',
246
+ 'pib_settings_advanced',
247
+ pib_get_settings_field_args( $option, 'advanced' )
248
+ );
249
+ }
250
+
251
+ /* Register all settings or we will get an error when trying to save */
252
+ register_setting( 'pib_settings_general', 'pib_settings_general', 'pib_settings_sanitize' );
253
+ register_setting( 'pib_settings_post_visibility', 'pib_settings_post_visibility', 'pib_settings_sanitize' );
254
+ register_setting( 'pib_settings_styles', 'pib_settings_styles', 'pib_settings_sanitize' );
255
+ register_setting( 'pib_settings_advanced', 'pib_settings_advanced', 'pib_settings_sanitize' );
256
+
257
+ }
258
+ add_action( 'admin_init', 'pib_register_settings' );
259
+
260
+ /*
261
+ * Return generic add_settings_field $args parameter array.
262
+ *
263
+ * @since 2.0.0
264
+ *
265
+ * @param string $option Single settings option key.
266
+ * @param string $section Section of settings apge.
267
+ * @return array $args parameter to use with add_settings_field call.
268
+ */
269
+ function pib_get_settings_field_args( $option, $section ) {
270
+ $settings_args = array(
271
+ 'id' => $option['id'],
272
+ 'desc' => $option['desc'],
273
+ 'name' => $option['name'],
274
+ 'section' => $section,
275
+ 'size' => isset( $option['size'] ) ? $option['size'] : null,
276
+ 'options' => isset( $option['options'] ) ? $option['options'] : '',
277
+ 'std' => isset( $option['std'] ) ? $option['std'] : ''
278
+ );
279
+
280
+ // Link label to input using 'label_for' argument if text, textarea, password, select, or variations of.
281
+ // Just add to existing settings args array if needed.
282
+ if ( in_array( $option['type'], array( 'text', 'select', 'textarea', 'password', 'number' ) ) ) {
283
+ $settings_args = array_merge( $settings_args, array( 'label_for' => 'pib_settings_' . $section . '[' . $option['id'] . ']' ) );
284
+ }
285
+
286
+ return $settings_args;
287
+ }
288
+
289
+ /*
290
+ * Radio button callback function
291
+ *
292
+ * @since 2.0.0
293
+ *
294
+ */
295
+ function pib_radio_callback( $args ) {
296
+ global $pib_options;
297
+
298
+ // Return empty string if no options.
299
+ if ( empty( $args['options'] ) ) {
300
+ echo '';
301
+ return;
302
+ }
303
+
304
+ $html = "\n";
305
+
306
+ foreach ( $args['options'] as $key => $option ) {
307
+ $checked = false;
308
+
309
+ if ( isset( $pib_options[ $args['id'] ] ) && $pib_options[ $args['id'] ] == $key )
310
+ $checked = true;
311
+ elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $pib_options[ $args['id'] ] ) )
312
+ $checked = true;
313
+
314
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-radio-label">';
315
+ $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>' . "\n";
316
+ $html .= $option . '</label>';
317
+ }
318
+
319
+ // Render and style description text underneath if it exists.
320
+ if ( ! empty( $args['desc'] ) )
321
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
322
+
323
+ echo $html;
324
+ }
325
+
326
+ /*
327
+ * Single checkbox callback function
328
+ *
329
+ * @since 2.0.0
330
+ *
331
+ */
332
+ function pib_checkbox_callback( $args ) {
333
+ global $pib_options;
334
+
335
+ $checked = isset( $pib_options[$args['id']] ) ? checked( 1, $pib_options[$args['id']], false ) : '';
336
+ $html = "\n" . '<input type="checkbox" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="1" ' . $checked . '/>' . "\n";
337
+
338
+ // Render description text directly to the right in a label if it exists.
339
+ if ( ! empty( $args['desc'] ) )
340
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
341
+
342
+ echo $html;
343
+ }
344
+
345
+ /*
346
+ * Multiple checkboxes callback function
347
+ *
348
+ * @since 2.0.0
349
+ *
350
+ */
351
+ function pib_multicheck_callback( $args ) {
352
+ global $pib_options;
353
+
354
+ // Return empty string if no options.
355
+ if ( empty( $args['options'] ) ) {
356
+ echo '';
357
+ return;
358
+ }
359
+
360
+ $html = "\n";
361
+
362
+ foreach ( $args['options'] as $key => $option ) {
363
+ if ( isset( $pib_options[$args['id']][$key] ) ) { $enabled = $option; } else { $enabled = NULL; }
364
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" class="pib-checkbox-label">';
365
+ $html .= '<input name="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" id="pib_settings_' . $args['section'] . '[' . $args['id'] . '][' . $key . ']" type="checkbox" value="' . $option . '" ' . checked($option, $enabled, false) . '/>' . "\n";
366
+ $html .= $option . '</label>';
367
+ }
368
+
369
+ // Render and style description text underneath if it exists.
370
+ if ( ! empty( $args['desc'] ) )
371
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
372
+
373
+ echo $html;
374
+ }
375
+
376
+ /*
377
+ * Select box callback function
378
+ *
379
+ * @since 2.0.0
380
+ *
381
+ */
382
+ function pib_select_callback( $args ) {
383
+ global $pib_options;
384
+
385
+ // Return empty string if no options.
386
+ if ( empty( $args['options'] ) ) {
387
+ echo '';
388
+ return;
389
+ }
390
+
391
+ $html = "\n" . '<select id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"/>' . "\n";
392
+
393
+ foreach ( $args['options'] as $option => $name ) :
394
+ $selected = isset( $pib_options[$args['id']] ) ? selected( $option, $pib_options[$args['id']], false ) : '';
395
+ $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>' . "\n";
396
+ endforeach;
397
+
398
+ $html .= '</select>' . "\n";
399
+
400
+ // Render and style description text underneath if it exists.
401
+ if ( ! empty( $args['desc'] ) )
402
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
403
+
404
+ echo $html;
405
+ }
406
+
407
+ /*
408
+ * Textarea callback function
409
+ *
410
+ * @since 2.0.0
411
+ *
412
+ */
413
+ function pib_textarea_callback( $args ) {
414
+ global $pib_options;
415
+
416
+ if ( isset( $pib_options[ $args['id'] ] ) )
417
+ $value = $pib_options[ $args['id'] ];
418
+ else
419
+ $value = isset( $args['std'] ) ? $args['std'] : '';
420
+
421
+ // Ignoring size at the moment.
422
+ $html = "\n" . '<textarea class="large-text" cols="50" rows="10" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']">' . esc_textarea( $value ) . '</textarea>' . "\n";
423
+
424
+ // Render and style description text underneath if it exists.
425
+ if ( ! empty( $args['desc'] ) )
426
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
427
+
428
+ echo $html;
429
+ }
430
+
431
+ /**
432
+ * Number callback function
433
+ *
434
+ * @since 2.0.0
435
+ *
436
+ */
437
+ function pib_number_callback( $args ) {
438
+ global $pib_options;
439
+
440
+ if ( isset( $pib_options[ $args['id'] ] ) )
441
+ $value = $pib_options[ $args['id'] ];
442
+ else
443
+ $value = isset( $args['std'] ) ? $args['std'] : '';
444
+
445
+ $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
446
+ $html = "\n" . '<input type="number" class="' . $size . '-text" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" step="1" value="' . esc_attr( $value ) . '"/>' . "\n";
447
+
448
+ // Render description text directly to the right in a label if it exists.
449
+ if ( ! empty( $args['desc'] ) )
450
+ $html .= '<label for="pib_settings_' . $args['section'] . '[' . $args['id'] . ']"> ' . $args['desc'] . '</label>' . "\n";
451
+
452
+ echo $html;
453
+ }
454
+
455
+ /**
456
+ * Textbox callback function
457
+ * Valid built-in size CSS class values:
458
+ * small-text, regular-text, large-text
459
+ *
460
+ * @since 2.0.0
461
+ *
462
+ */
463
+ function pib_text_callback( $args ) {
464
+ global $pib_options;
465
+
466
+ if ( isset( $pib_options[ $args['id'] ] ) )
467
+ $value = $pib_options[ $args['id'] ];
468
+ else
469
+ $value = isset( $args['std'] ) ? $args['std'] : '';
470
+
471
+ $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : '';
472
+ $html = "\n" . '<input type="text" class="' . $size . '" id="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" name="pib_settings_' . $args['section'] . '[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>' . "\n";
473
+
474
+ // Render and style description text underneath if it exists.
475
+ if ( ! empty( $args['desc'] ) )
476
+ $html .= '<p class="description">' . $args['desc'] . '</p>' . "\n";
477
+
478
+ echo $html;
479
+ }
480
+
481
+ /*
482
+ * Function we can use to sanitize the input data and return it when saving options
483
+ *
484
+ * @since 2.0.0
485
+ *
486
+ */
487
+ function pib_settings_sanitize( $input ) {
488
+ add_settings_error( 'pib-notices', '', '', '' );
489
+ return $input;
490
+ }
491
+
492
+ /*
493
+ * Default callback function if correct one does not exist
494
+ *
495
+ * @since 2.0.0
496
+ *
497
+ */
498
+ function pib_missing_callback( $args ) {
499
+ printf( __( 'The callback function used for the <strong>%s</strong> setting is missing.', 'pib' ), $args['id'] );
500
+ }
501
+
502
+ /*
503
+ * Function used to return an array of all of the plugin settings
504
+ *
505
+ * @since 2.0.0
506
+ *
507
+ */
508
+ function pib_get_settings() {
509
+
510
+ // If this is the first time running we need to set the defaults
511
+ if ( !get_option( 'pib_upgrade_has_run' ) ) {
512
+
513
+ // set default post visibility options
514
+ $post_visibility = get_option( 'pib_settings_post_visibility' );
515
+ $post_visibility['post_page_types']['display_home_page'] = 1;
516
+ $post_visibility['post_page_types']['display_posts'] = 1;
517
+ $post_visibility['post_page_placement']['display_below_content'] = 1;
518
+
519
+ update_option( 'pib_settings_post_visibility', $post_visibility );
520
+
521
+ // set default general settings options
522
+ $general = get_option( 'pib_settings_general' );
523
+ $general['button_type'] = 'user_selects_image';
524
+ $general['count_layout'] = 'none';
525
+ $general['uninstall_save_settings'] = 1;
526
+
527
+ update_option( 'pib_settings_general', $general );
528
+
529
+ // add an option to let us know the initial settings have been run and we don't run them again
530
+ add_option( 'pib_upgrade_has_run', 1 );
531
+ }
532
+
533
+ $general_settings = is_array( get_option( 'pib_settings_general' ) ) ? get_option( 'pib_settings_general' ) : array();
534
+ $post_visibility_settings = is_array( get_option( 'pib_settings_post_visibility' ) ) ? get_option( 'pib_settings_post_visibility' ) : array();
535
+ $style_settings = is_array( get_option( 'pib_settings_styles' ) ) ? get_option( 'pib_settings_styles' ) : array();
536
+ $advanced_settings = is_array( get_option( 'pib_settings_advanced' ) ) ? get_option( 'pib_settings_advanced' ) : array();
537
+
538
+ return array_merge( $general_settings, $post_visibility_settings, $style_settings, $advanced_settings );
539
+ }
includes/shortcodes.php CHANGED
@@ -1,113 +1,113 @@
1
- <?php
2
-
3
- /**
4
- * Define plugin shortcodes.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- /**
17
- * Function to process [pinit] shortcodes
18
- *
19
- * @since 2.0.0
20
- */
21
- function pib_pinit_shortcode( $attr ) {
22
- global $pib_options;
23
- global $post;
24
- $postID = $post->ID;
25
-
26
- /*
27
- For URL, image URL and Description, use in order:
28
- 1) attribute value
29
- 2) custom fields for post
30
- 3) inherit from post: permalink, first image, post title
31
- */
32
-
33
- extract( shortcode_atts( array(
34
- 'count' => 'none',
35
- 'url' => '',
36
- 'image_url' => '',
37
- 'description' => '',
38
- 'align' => 'none',
39
- 'remove_div' => false,
40
- 'button_type' => 'any',
41
- 'size' => 'small',
42
- 'color' => 'gray',
43
- 'shape' => 'rectangular',
44
- 'always_show_count' => 'false'
45
- ), $attr ) );
46
-
47
- if ( empty( $url ) ) {
48
- $url = get_post_meta( $postID, 'pib_url_of_webpage', true);
49
-
50
- if ( empty( $url ) ) {
51
- $url = get_permalink( $postID );
52
- }
53
- }
54
-
55
- if ( empty( $image_url ) ) {
56
- $image_url = get_post_meta( $postID, 'pib_url_of_img', true);
57
-
58
- if ( empty( $image_url ) ) {
59
- //Get url of img and compare width and height
60
- $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
61
-
62
- if ( ! ( 0 == $output || false == $output ) ) {
63
- $image_url = $matches [1] [0];
64
- } else {
65
- $image_url = '';
66
- }
67
- }
68
- }
69
-
70
- if ( empty( $description ) ) {
71
- $description = get_post_meta( $postID, 'pib_description', true);
72
-
73
- if ( empty( $description ) ) {
74
- $description = get_the_title( $postID );
75
- }
76
- }
77
-
78
- // set button_type to a correct parameter to be passed
79
- $button_type = ( $button_type == 'one' ? 'image_selected' : 'user_selects_image' );
80
-
81
- $base_btn = pib_button_base( $button_type, $url, $image_url, $description, $count, $size, $color, $shape, $always_show_count );
82
-
83
- //Don't wrap with div or set float class if "remove div" is checked
84
- if ( $remove_div ) {
85
- $html = $base_btn;
86
- }
87
- else {
88
- //Surround with div tag
89
- $align_class = '';
90
-
91
- if ( 'left' == $align ) {
92
- $align_class = 'pib-align-left';
93
- }
94
- elseif ( 'right' == $align ) {
95
- $align_class = 'pib-align-right';
96
- }
97
- elseif ( 'center' == $align ) {
98
- $align_class = 'pib-align-center';
99
- }
100
-
101
- $html = '<div class="pin-it-btn-wrapper-shortcode ' . $align_class . '">' . $base_btn . '</div>';
102
- }
103
-
104
- $before_html = '';
105
- $after_html ='';
106
-
107
- $before_html = apply_filters( 'pib_shortcode_before', $before_html );
108
- $html = apply_filters( 'pib_shortcode_html' , $html );
109
- $after_html = apply_filters( 'pib_shortcode_after', $after_html );
110
-
111
- return $before_html . $html . $after_html;
112
- }
113
- add_shortcode( 'pinit', 'pib_pinit_shortcode' );
1
+ <?php
2
+
3
+ /**
4
+ * Define plugin shortcodes.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Function to process [pinit] shortcodes
18
+ *
19
+ * @since 2.0.0
20
+ */
21
+ function pib_pinit_shortcode( $attr ) {
22
+ global $pib_options;
23
+ global $post;
24
+ $postID = $post->ID;
25
+
26
+ /*
27
+ For URL, image URL and Description, use in order:
28
+ 1) attribute value
29
+ 2) custom fields for post
30
+ 3) inherit from post: permalink, first image, post title
31
+ */
32
+
33
+ extract( shortcode_atts( array(
34
+ 'count' => 'none',
35
+ 'url' => '',
36
+ 'image_url' => '',
37
+ 'description' => '',
38
+ 'align' => 'none',
39
+ 'remove_div' => false,
40
+ 'button_type' => 'any',
41
+ 'size' => 'small',
42
+ 'color' => 'gray',
43
+ 'shape' => 'rectangular',
44
+ 'always_show_count' => 'false'
45
+ ), $attr ) );
46
+
47
+ if ( empty( $url ) ) {
48
+ $url = get_post_meta( $postID, 'pib_url_of_webpage', true);
49
+
50
+ if ( empty( $url ) ) {
51
+ $url = get_permalink( $postID );
52
+ }
53
+ }
54
+
55
+ if ( empty( $image_url ) ) {
56
+ $image_url = get_post_meta( $postID, 'pib_url_of_img', true);
57
+
58
+ if ( empty( $image_url ) ) {
59
+ //Get url of img and compare width and height
60
+ $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
61
+
62
+ if ( ! ( 0 == $output || false == $output ) ) {
63
+ $image_url = $matches [1] [0];
64
+ } else {
65
+ $image_url = '';
66
+ }
67
+ }
68
+ }
69
+
70
+ if ( empty( $description ) ) {
71
+ $description = get_post_meta( $postID, 'pib_description', true);
72
+
73
+ if ( empty( $description ) ) {
74
+ $description = get_the_title( $postID );
75
+ }
76
+ }
77
+
78
+ // set button_type to a correct parameter to be passed
79
+ $button_type = ( $button_type == 'one' ? 'image_selected' : 'user_selects_image' );
80
+
81
+ $base_btn = pib_button_base( $button_type, $url, $image_url, $description, $count, $size, $color, $shape, $always_show_count );
82
+
83
+ //Don't wrap with div or set float class if "remove div" is checked
84
+ if ( $remove_div ) {
85
+ $html = $base_btn;
86
+ }
87
+ else {
88
+ //Surround with div tag
89
+ $align_class = '';
90
+
91
+ if ( 'left' == $align ) {
92
+ $align_class = 'pib-align-left';
93
+ }
94
+ elseif ( 'right' == $align ) {
95
+ $align_class = 'pib-align-right';
96
+ }
97
+ elseif ( 'center' == $align ) {
98
+ $align_class = 'pib-align-center';
99
+ }
100
+
101
+ $html = '<div class="pin-it-btn-wrapper-shortcode ' . $align_class . '">' . $base_btn . '</div>';
102
+ }
103
+
104
+ $before_html = '';
105
+ $after_html ='';
106
+
107
+ $before_html = apply_filters( 'pib_shortcode_before', $before_html );
108
+ $html = apply_filters( 'pib_shortcode_html' , $html );
109
+ $after_html = apply_filters( 'pib_shortcode_after', $after_html );
110
+
111
+ return $before_html . $html . $after_html;
112
+ }
113
+ add_shortcode( 'pinit', 'pib_pinit_shortcode' );
includes/simple_html_dom.php ADDED
@@ -0,0 +1,1721 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Website: http://sourceforge.net/projects/simplehtmldom/
4
+ * Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/)
5
+ * Contributions by:
6
+ * Yousuke Kumakura (Attribute filters)
7
+ * Vadim Voituk (Negative indexes supports of "find" method)
8
+ * Antcs (Constructor with automatically load contents either text or file/url)
9
+ *
10
+ * all affected sections have comments starting with "PaperG"
11
+ *
12
+ * Paperg - Added case insensitive testing of the value of the selector.
13
+ * Paperg - Added tag_start for the starting index of tags - NOTE: This works but not accurately.
14
+ * This tag_start gets counted AFTER \r\n have been crushed out, and after the remove_noice calls so it will not reflect the REAL position of the tag in the source,
15
+ * it will almost always be smaller by some amount.
16
+ * We use this to determine how far into the file the tag in question is. This "percentage will never be accurate as the $dom->size is the "real" number of bytes the dom was created from.
17
+ * but for most purposes, it's a really good estimation.
18
+ * Paperg - Added the forceTagsClosed to the dom constructor. Forcing tags closed is great for malformed html, but it CAN lead to parsing errors.
19
+ * Allow the user to tell us how much they trust the html.
20
+ * Paperg add the text and plaintext to the selectors for the find syntax. plaintext implies text in the innertext of a node. text implies that the tag is a text node.
21
+ * This allows for us to find tags based on the text they contain.
22
+ * Create find_ancestor_tag to see if a tag is - at any level - inside of another specific tag.
23
+ * Paperg: added parse_charset so that we know about the character set of the source document.
24
+ * NOTE: If the user's system has a routine called get_last_retrieve_url_contents_content_type availalbe, we will assume it's returning the content-type header from the
25
+ * last transfer or curl_exec, and we will parse that and use it in preference to any other method of charset detection.
26
+ *
27
+ * Found infinite loop in the case of broken html in restore_noise. Rewrote to protect from that.
28
+ * PaperG (John Schlick) Added get_display_size for "IMG" tags.
29
+ *
30
+ * Licensed under The MIT License
31
+ * Redistributions of files must retain the above copyright notice.
32
+ *
33
+ * @author S.C. Chen <me578022@gmail.com>
34
+ * @author John Schlick
35
+ * @author Rus Carroll
36
+ * @version 1.5 ($Rev: 196 $)
37
+ * @package PlaceLocalInclude
38
+ * @subpackage simple_html_dom
39
+ */
40
+
41
+ /**
42
+ * All of the Defines for the classes below.
43
+ * @author S.C. Chen <me578022@gmail.com>
44
+ */
45
+ define('HDOM_TYPE_ELEMENT', 1);
46
+ define('HDOM_TYPE_COMMENT', 2);
47
+ define('HDOM_TYPE_TEXT', 3);
48
+ define('HDOM_TYPE_ENDTAG', 4);
49
+ define('HDOM_TYPE_ROOT', 5);
50
+ define('HDOM_TYPE_UNKNOWN', 6);
51
+ define('HDOM_QUOTE_DOUBLE', 0);
52
+ define('HDOM_QUOTE_SINGLE', 1);
53
+ define('HDOM_QUOTE_NO', 3);
54
+ define('HDOM_INFO_BEGIN', 0);
55
+ define('HDOM_INFO_END', 1);
56
+ define('HDOM_INFO_QUOTE', 2);
57
+ define('HDOM_INFO_SPACE', 3);
58
+ define('HDOM_INFO_TEXT', 4);
59
+ define('HDOM_INFO_INNER', 5);
60
+ define('HDOM_INFO_OUTER', 6);
61
+ define('HDOM_INFO_ENDSPACE',7);
62
+ define('DEFAULT_TARGET_CHARSET', 'UTF-8');
63
+ define('DEFAULT_BR_TEXT', "\r\n");
64
+ define('DEFAULT_SPAN_TEXT', " ");
65
+ define('MAX_FILE_SIZE', 600000);
66
+ // helper functions
67
+ // -----------------------------------------------------------------------------
68
+ // get html dom from file
69
+ // $maxlen is defined in the code as PHP_STREAM_COPY_ALL which is defined as -1.
70
+ function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
71
+ {
72
+ // We DO force the tags to be terminated.
73
+ $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
74
+ // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done.
75
+ $contents = file_get_contents($url, $use_include_path, $context, $offset);
76
+ // Paperg - use our own mechanism for getting the contents as we want to control the timeout.
77
+ //$contents = retrieve_url_contents($url);
78
+ if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
79
+ {
80
+ return false;
81
+ }
82
+ // The second parameter can force the selectors to all be lowercase.
83
+ $dom->load($contents, $lowercase, $stripRN);
84
+ return $dom;
85
+ }
86
+
87
+ // get html dom from string
88
+ function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
89
+ {
90
+ $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
91
+ if (empty($str) || strlen($str) > MAX_FILE_SIZE)
92
+ {
93
+ $dom->clear();
94
+ return false;
95
+ }
96
+ $dom->load($str, $lowercase, $stripRN);
97
+ return $dom;
98
+ }
99
+
100
+ // dump html dom tree
101
+ function dump_html_tree($node, $show_attr=true, $deep=0)
102
+ {
103
+ $node->dump($node);
104
+ }
105
+
106
+
107
+ /**
108
+ * simple html dom node
109
+ * PaperG - added ability for "find" routine to lowercase the value of the selector.
110
+ * PaperG - added $tag_start to track the start position of the tag in the total byte index
111
+ *
112
+ * @package PlaceLocalInclude
113
+ */
114
+ class simple_html_dom_node
115
+ {
116
+ public $nodetype = HDOM_TYPE_TEXT;
117
+ public $tag = 'text';
118
+ public $attr = array();
119
+ public $children = array();
120
+ public $nodes = array();
121
+ public $parent = null;
122
+ // The "info" array - see HDOM_INFO_... for what each element contains.
123
+ public $_ = array();
124
+ public $tag_start = 0;
125
+ private $dom = null;
126
+
127
+ function __construct($dom)
128
+ {
129
+ $this->dom = $dom;
130
+ $dom->nodes[] = $this;
131
+ }
132
+
133
+ function __destruct()
134
+ {
135
+ $this->clear();
136
+ }
137
+
138
+ function __toString()
139
+ {
140
+ return $this->outertext();
141
+ }
142
+
143
+ // clean up memory due to php5 circular references memory leak...
144
+ function clear()
145
+ {
146
+ $this->dom = null;
147
+ $this->nodes = null;
148
+ $this->parent = null;
149
+ $this->children = null;
150
+ }
151
+
152
+ // dump node's tree
153
+ function dump($show_attr=true, $deep=0)
154
+ {
155
+ $lead = str_repeat(' ', $deep);
156
+
157
+ echo $lead.$this->tag;
158
+ if ($show_attr && count($this->attr)>0)
159
+ {
160
+ echo '(';
161
+ foreach ($this->attr as $k=>$v)
162
+ echo "[$k]=>\"".$this->$k.'", ';
163
+ echo ')';
164
+ }
165
+ echo "\n";
166
+
167
+ if ($this->nodes)
168
+ {
169
+ foreach ($this->nodes as $c)
170
+ {
171
+ $c->dump($show_attr, $deep+1);
172
+ }
173
+ }
174
+ }
175
+
176
+
177
+ // Debugging function to dump a single dom node with a bunch of information about it.
178
+ function dump_node($echo=true)
179
+ {
180
+
181
+ $string = $this->tag;
182
+ if (count($this->attr)>0)
183
+ {
184
+ $string .= '(';
185
+ foreach ($this->attr as $k=>$v)
186
+ {
187
+ $string .= "[$k]=>\"".$this->$k.'", ';
188
+ }
189
+ $string .= ')';
190
+ }
191
+ if (count($this->_)>0)
192
+ {
193
+ $string .= ' $_ (';
194
+ foreach ($this->_ as $k=>$v)
195
+ {
196
+ if (is_array($v))
197
+ {
198
+ $string .= "[$k]=>(";
199
+ foreach ($v as $k2=>$v2)
200
+ {
201
+ $string .= "[$k2]=>\"".$v2.'", ';
202
+ }
203
+ $string .= ")";
204
+ } else {
205
+ $string .= "[$k]=>\"".$v.'", ';
206
+ }
207
+ }
208
+ $string .= ")";
209
+ }
210
+
211
+ if (isset($this->text))
212
+ {
213
+ $string .= " text: (" . $this->text . ")";
214
+ }
215
+
216
+ $string .= " HDOM_INNER_INFO: '";
217
+ if (isset($node->_[HDOM_INFO_INNER]))
218
+ {
219
+ $string .= $node->_[HDOM_INFO_INNER] . "'";
220
+ }
221
+ else
222
+ {
223
+ $string .= ' NULL ';
224
+ }
225
+
226
+ $string .= " children: " . count($this->children);
227
+ $string .= " nodes: " . count($this->nodes);
228
+ $string .= " tag_start: " . $this->tag_start;
229
+ $string .= "\n";
230
+
231
+ if ($echo)
232
+ {
233
+ echo $string;
234
+ return;
235
+ }
236
+ else
237
+ {
238
+ return $string;
239
+ }
240
+ }
241
+
242
+ // returns the parent of node
243
+ // If a node is passed in, it will reset the parent of the current node to that one.
244
+ function parent($parent=null)
245
+ {
246
+ // I am SURE that this doesn't work properly.
247
+ // It fails to unset the current node from it's current parents nodes or children list first.
248
+ if ($parent !== null)
249
+ {
250
+ $this->parent = $parent;
251
+ $this->parent->nodes[] = $this;
252
+ $this->parent->children[] = $this;
253
+ }
254
+
255
+ return $this->parent;
256
+ }
257
+
258
+ // verify that node has children
259
+ function has_child()
260
+ {
261
+ return !empty($this->children);
262
+ }
263
+
264
+ // returns children of node
265
+ function children($idx=-1)
266
+ {
267
+ if ($idx===-1)
268
+ {
269
+ return $this->children;
270
+ }
271
+ if (isset($this->children[$idx])) return $this->children[$idx];
272
+ return null;
273
+ }
274
+
275
+ // returns the first child of node
276
+ function first_child()
277
+ {
278
+ if (count($this->children)>0)
279
+ {
280
+ return $this->children[0];
281
+ }
282
+ return null;
283
+ }
284
+
285
+ // returns the last child of node
286
+ function last_child()
287
+ {
288
+ if (($count=count($this->children))>0)
289
+ {
290
+ return $this->children[$count-1];
291
+ }
292
+ return null;
293
+ }
294
+
295
+ // returns the next sibling of node
296
+ function next_sibling()
297
+ {
298
+ if ($this->parent===null)
299
+ {
300
+ return null;
301
+ }
302
+
303
+ $idx = 0;
304
+ $count = count($this->parent->children);
305
+ while ($idx<$count && $this!==$this->parent->children[$idx])
306
+ {
307
+ ++$idx;
308
+ }
309
+ if (++$idx>=$count)
310
+ {
311
+ return null;
312
+ }
313
+ return $this->parent->children[$idx];
314
+ }
315
+
316
+ // returns the previous sibling of node
317
+ function prev_sibling()
318
+ {
319
+ if ($this->parent===null) return null;
320
+ $idx = 0;
321
+ $count = count($this->parent->children);
322
+ while ($idx<$count && $this!==$this->parent->children[$idx])
323
+ ++$idx;
324
+ if (--$idx<0) return null;
325
+ return $this->parent->children[$idx];
326
+ }
327
+
328
+ // function to locate a specific ancestor tag in the path to the root.
329
+ function find_ancestor_tag($tag)
330
+ {
331
+ global $debugObject;
332
+ if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }
333
+
334
+ // Start by including ourselves in the comparison.
335
+ $returnDom = $this;
336
+
337
+ while (!is_null($returnDom))
338
+ {
339
+ if (is_object($debugObject)) { $debugObject->debugLog(2, "Current tag is: " . $returnDom->tag); }
340
+
341
+ if ($returnDom->tag == $tag)
342
+ {
343
+ break;
344
+ }
345
+ $returnDom = $returnDom->parent;
346
+ }
347
+ return $returnDom;
348
+ }
349
+
350
+ // get dom node's inner html
351
+ function innertext()
352
+ {
353
+ if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
354
+ if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
355
+
356
+ $ret = '';
357
+ foreach ($this->nodes as $n)
358
+ $ret .= $n->outertext();
359
+ return $ret;
360
+ }
361
+
362
+ // get dom node's outer text (with tag)
363
+ function outertext()
364
+ {
365
+ global $debugObject;
366
+ if (is_object($debugObject))
367
+ {
368
+ $text = '';
369
+ if ($this->tag == 'text')
370
+ {
371
+ if (!empty($this->text))
372
+ {
373
+ $text = " with text: " . $this->text;
374
+ }
375
+ }
376
+ $debugObject->debugLog(1, 'Innertext of tag: ' . $this->tag . $text);
377
+ }
378
+
379
+ if ($this->tag==='root') return $this->innertext();
380
+
381
+ // trigger callback
382
+ if ($this->dom && $this->dom->callback!==null)
383
+ {
384
+ call_user_func_array($this->dom->callback, array($this));
385
+ }
386
+
387
+ if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER];
388
+ if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
389
+
390
+ // render begin tag
391
+ if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]])
392
+ {
393
+ $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup();
394
+ } else {
395
+ $ret = "";
396
+ }
397
+
398
+ // render inner text
399
+ if (isset($this->_[HDOM_INFO_INNER]))
400
+ {
401
+ // If it's a br tag... don't return the HDOM_INNER_INFO that we may or may not have added.
402
+ if ($this->tag != "br")
403
+ {
404
+ $ret .= $this->_[HDOM_INFO_INNER];
405
+ }
406
+ } else {
407
+ if ($this->nodes)
408
+ {
409
+ foreach ($this->nodes as $n)
410
+ {
411
+ $ret .= $this->convert_text($n->outertext());
412
+ }
413
+ }
414
+ }
415
+
416
+ // render end tag
417
+ if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0)
418
+ $ret .= '</'.$this->tag.'>';
419
+ return $ret;
420
+ }
421
+
422
+ // get dom node's plain text
423
+ function text()
424
+ {
425
+ if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];
426
+ switch ($this->nodetype)
427
+ {
428
+ case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
429
+ case HDOM_TYPE_COMMENT: return '';
430
+ case HDOM_TYPE_UNKNOWN: return '';
431
+ }
432
+ if (strcasecmp($this->tag, 'script')===0) return '';
433
+ if (strcasecmp($this->tag, 'style')===0) return '';
434
+
435
+ $ret = '';
436
+ // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL.
437
+ // NOTE: This indicates that there is a problem where it's set to NULL without a clear happening.
438
+ // WHY is this happening?
439
+ if (!is_null($this->nodes))
440
+ {
441
+ foreach ($this->nodes as $n)
442
+ {
443
+ $ret .= $this->convert_text($n->text());
444
+ }
445
+
446
+ // If this node is a span... add a space at the end of it so multiple spans don't run into each other. This is plaintext after all.
447
+ if ($this->tag == "span")
448
+ {
449
+ $ret .= $this->dom->default_span_text;
450
+ }
451
+
452
+
453
+ }
454
+ return $ret;
455
+ }
456
+
457
+ function xmltext()
458
+ {
459
+ $ret = $this->innertext();
460
+ $ret = str_ireplace('<![CDATA[', '', $ret);
461
+ $ret = str_replace(']]>', '', $ret);
462
+ return $ret;
463
+ }
464
+
465
+ // build node's text with tag
466
+ function makeup()
467
+ {
468
+ // text, comment, unknown
469
+ if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);
470
+
471
+ $ret = '<'.$this->tag;
472
+ $i = -1;
473
+
474
+ foreach ($this->attr as $key=>$val)
475
+ {
476
+ ++$i;
477
+
478
+ // skip removed attribute
479
+ if ($val===null || $val===false)
480
+ continue;
481
+
482
+ $ret .= $this->_[HDOM_INFO_SPACE][$i][0];
483
+ //no value attr: nowrap, checked selected...
484
+ if ($val===true)
485
+ $ret .= $key;
486
+ else {
487
+ switch ($this->_[HDOM_INFO_QUOTE][$i])
488
+ {
489
+ case HDOM_QUOTE_DOUBLE: $quote = '"'; break;
490
+ case HDOM_QUOTE_SINGLE: $quote = '\''; break;
491
+ default: $quote = '';
492
+ }
493
+ $ret .= $key.$this->_[HDOM_INFO_SPACE][$i][1].'='.$this->_[HDOM_INFO_SPACE][$i][2].$quote.$val.$quote;
494
+ }
495
+ }
496
+ $ret = $this->dom->restore_noise($ret);
497
+ return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>';
498
+ }
499
+
500
+ // find elements by css selector
501
+ //PaperG - added ability for find to lowercase the value of the selector.
502
+ function find($selector, $idx=null, $lowercase=false)
503
+ {
504
+ $selectors = $this->parse_selector($selector);
505
+ if (($count=count($selectors))===0) return array();
506
+ $found_keys = array();
507
+
508
+ // find each selector
509
+ for ($c=0; $c<$count; ++$c)
510
+ {
511
+ // The change on the below line was documented on the sourceforge code tracker id 2788009
512
+ // used to be: if (($levle=count($selectors[0]))===0) return array();
513
+ if (($levle=count($selectors[$c]))===0) return array();
514
+ if (!isset($this->_[HDOM_INFO_BEGIN])) return array();
515
+
516
+ $head = array($this->_[HDOM_INFO_BEGIN]=>1);
517
+
518
+ // handle descendant selectors, no recursive!
519
+ for ($l=0; $l<$levle; ++$l)
520
+ {
521
+ $ret = array();
522
+ foreach ($head as $k=>$v)
523
+ {
524
+ $n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k];
525
+ //PaperG - Pass this optional parameter on to the seek function.
526
+ $n->seek($selectors[$c][$l], $ret, $lowercase);
527
+ }
528
+ $head = $ret;
529
+ }
530
+
531
+ foreach ($head as $k=>$v)
532
+ {
533
+ if (!isset($found_keys[$k]))
534
+ $found_keys[$k] = 1;
535
+ }
536
+ }
537
+
538
+ // sort keys
539
+ ksort($found_keys);
540
+
541
+ $found = array();
542
+ foreach ($found_keys as $k=>$v)
543
+ $found[] = $this->dom->nodes[$k];
544
+
545
+ // return nth-element or array
546
+ if (is_null($idx)) return $found;
547
+ else if ($idx<0) $idx = count($found) + $idx;
548
+ return (isset($found[$idx])) ? $found[$idx] : null;
549
+ }
550
+
551
+ // seek for given conditions
552
+ // PaperG - added parameter to allow for case insensitive testing of the value of a selector.
553
+ protected function seek($selector, &$ret, $lowercase=false)
554
+ {
555
+ global $debugObject;
556
+ if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }
557
+
558
+ list($tag, $key, $val, $exp, $no_key) = $selector;
559
+
560
+ // xpath index
561
+ if ($tag && $key && is_numeric($key))
562
+ {
563
+ $count = 0;
564
+ foreach ($this->children as $c)
565
+ {
566
+ if ($tag==='*' || $tag===$c->tag) {
567
+ if (++$count==$key) {
568
+ $ret[$c->_[HDOM_INFO_BEGIN]] = 1;
569
+ return;
570
+ }
571
+ }
572
+ }
573
+ return;
574
+ }
575
+
576
+ $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0;
577
+ if ($end==0) {
578
+ $parent = $this->parent;
579
+ while (!isset($parent->_[HDOM_INFO_END]) && $parent!==null) {
580
+ $end -= 1;
581
+ $parent = $parent->parent;
582
+ }
583
+ $end += $parent->_[HDOM_INFO_END];
584
+ }
585
+
586
+ for ($i=$this->_[HDOM_INFO_BEGIN]+1; $i<$end; ++$i) {
587
+ $node = $this->dom->nodes[$i];
588
+
589
+ $pass = true;
590
+
591
+ if ($tag==='*' && !$key) {
592
+ if (in_array($node, $this->children, true))
593
+ $ret[$i] = 1;
594
+ continue;
595
+ }
596
+
597
+ // compare tag
598
+ if ($tag && $tag!=$node->tag && $tag!=='*') {$pass=false;}
599
+ // compare key
600
+ if ($pass && $key) {
601
+ if ($no_key) {
602
+ if (isset($node->attr[$key])) $pass=false;
603
+ } else {
604
+ if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false;
605
+ }
606
+ }
607
+ // compare value
608
+ if ($pass && $key && $val && $val!=='*') {
609
+ // If they have told us that this is a "plaintext" search then we want the plaintext of the node - right?
610
+ if ($key == "plaintext") {
611
+ // $node->plaintext actually returns $node->text();
612
+ $nodeKeyValue = $node->text();
613
+ } else {
614
+ // this is a normal search, we want the value of that attribute of the tag.
615
+ $nodeKeyValue = $node->attr[$key];
616
+ }
617
+ if (is_object($debugObject)) {$debugObject->debugLog(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue);}
618
+
619
+ //PaperG - If lowercase is set, do a case insensitive test of the value of the selector.
620
+ if ($lowercase) {
621
+ $check = $this->match($exp, strtolower($val), strtolower($nodeKeyValue));
622
+ } else {
623
+ $check = $this->match($exp, $val, $nodeKeyValue);
624
+ }
625
+ if (is_object($debugObject)) {$debugObject->debugLog(2, "after match: " . ($check ? "true" : "false"));}
626
+
627
+ // handle multiple class
628
+ if (!$check && strcasecmp($key, 'class')===0) {
629
+ foreach (explode(' ',$node->attr[$key]) as $k) {
630
+ // Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form.
631
+ if (!empty($k)) {
632
+ if ($lowercase) {
633
+ $check = $this->match($exp, strtolower($val), strtolower($k));
634
+ } else {
635
+ $check = $this->match($exp, $val, $k);
636
+ }
637
+ if ($check) break;
638
+ }
639
+ }
640
+ }
641
+ if (!$check) $pass = false;
642
+ }
643
+ if ($pass) $ret[$i] = 1;
644
+ unset($node);
645
+ }
646
+ // It's passed by reference so this is actually what this function returns.
647
+ if (is_object($debugObject)) {$debugObject->debugLog(1, "EXIT - ret: ", $ret);}
648
+ }
649
+
650
+ protected function match($exp, $pattern, $value) {
651
+ global $debugObject;
652
+ if (is_object($debugObject)) {$debugObject->debugLogEntry(1);}
653
+
654
+ switch ($exp) {
655
+ case '=':
656
+ return ($value===$pattern);
657
+ case '!=':
658
+ return ($value!==$pattern);
659
+ case '^=':
660
+ return preg_match("/^".preg_quote($pattern,'/')."/", $value);
661
+ case '$=':
662
+ return preg_match("/".preg_quote($pattern,'/')."$/", $value);
663
+ case '*=':
664
+ if ($pattern[0]=='/') {
665
+ return preg_match($pattern, $value);
666
+ }
667
+ return preg_match("/".$pattern."/i", $value);
668
+ }
669
+ return false;
670
+ }
671
+
672
+ protected function parse_selector($selector_string) {
673
+ global $debugObject;
674
+ if (is_object($debugObject)) {$debugObject->debugLogEntry(1);}
675
+
676
+ // pattern of CSS selectors, modified from mootools
677
+ // Paperg: Add the colon to the attrbute, so that it properly finds <tag attr:ibute="something" > like google does.
678
+ // Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check.
679
+ // Notice the \[ starting the attbute? and the @? following? This implies that an attribute can begin with an @ sign that is not captured.
680
+ // This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression.
681
+ // farther study is required to determine of this should be documented or removed.
682
+ // $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
683
+ $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
684
+ preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER);
685
+ if (is_object($debugObject)) {$debugObject->debugLog(2, "Matches Array: ", $matches);}
686
+
687
+ $selectors = array();
688
+ $result = array();
689
+ //print_r($matches);
690
+
691
+ foreach ($matches as $m) {
692
+ $m[0] = trim($m[0]);
693
+ if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue;
694
+ // for browser generated xpath
695
+ if ($m[1]==='tbody') continue;
696
+
697
+ list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false);
698
+ if (!empty($m[2])) {$key='id'; $val=$m[2];}
699
+ if (!empty($m[3])) {$key='class'; $val=$m[3];}
700
+ if (!empty($m[4])) {$key=$m[4];}
701
+ if (!empty($m[5])) {$exp=$m[5];}
702
+ if (!empty($m[6])) {$val=$m[6];}
703
+
704
+ // convert to lowercase
705
+ if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);}
706
+ //elements that do NOT have the specified attribute
707
+ if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;}
708
+
709
+ $result[] = array($tag, $key, $val, $exp, $no_key);
710
+ if (trim($m[7])===',') {
711
+ $selectors[] = $result;
712
+ $result = array();
713
+ }
714
+ }
715
+ if (count($result)>0)
716
+ $selectors[] = $result;
717
+ return $selectors;
718
+ }
719
+
720
+ function __get($name) {
721
+ if (isset($this->attr[$name]))
722
+ {
723
+ return $this->convert_text($this->attr[$name]);
724
+ }
725
+ switch ($name) {
726
+ case 'outertext': return $this->outertext();
727
+ case 'innertext': return $this->innertext();
728
+ case 'plaintext': return $this->text();
729
+ case 'xmltext': return $this->xmltext();
730
+ default: return array_key_exists($name, $this->attr);
731
+ }
732
+ }
733
+
734
+ function __set($name, $value) {
735
+ switch ($name) {
736
+ case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value;
737
+ case 'innertext':
738
+ if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value;
739
+ return $this->_[HDOM_INFO_INNER] = $value;
740
+ }
741
+ if (!isset($this->attr[$name])) {
742
+ $this->_[HDOM_INFO_SPACE][] = array(' ', '', '');
743
+ $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;
744
+ }
745
+ $this->attr[$name] = $value;
746
+ }
747
+
748
+ function __isset($name) {
749
+ switch ($name) {
750
+ case 'outertext': return true;
751
+ case 'innertext': return true;
752
+ case 'plaintext': return true;
753
+ }
754
+ //no value attr: nowrap, checked selected...
755
+ return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]);
756
+ }
757
+
758
+ function __unset($name) {
759
+ if (isset($this->attr[$name]))
760
+ unset($this->attr[$name]);
761
+ }
762
+
763
+ // PaperG - Function to convert the text from one character set to another if the two sets are not the same.
764
+ function convert_text($text)
765
+ {
766
+ global $debugObject;
767
+ if (is_object($debugObject)) {$debugObject->debugLogEntry(1);}
768
+
769
+ $converted_text = $text;
770
+
771
+ $sourceCharset = "";
772
+ $targetCharset = "";
773
+
774
+ if ($this->dom)
775
+ {
776
+ $sourceCharset = strtoupper($this->dom->_charset);
777
+ $targetCharset = strtoupper($this->dom->_target_charset);
778
+ }
779
+ if (is_object($debugObject)) {$debugObject->debugLog(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);}
780
+
781
+ if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0))
782
+ {
783
+ // Check if the reported encoding could have been incorrect and the text is actually already UTF-8
784
+ if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))
785
+ {
786
+ $converted_text = $text;
787
+ }
788
+ else
789
+ {
790
+ $converted_text = iconv($sourceCharset, $targetCharset, $text);
791
+ }
792
+ }
793
+
794
+ // Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
795
+ if ($targetCharset == 'UTF-8')
796
+ {
797
+ if (substr($converted_text, 0, 3) == "\xef\xbb\xbf")
798
+ {
799
+ $converted_text = substr($converted_text, 3);
800
+ }
801
+ if (substr($converted_text, -3) == "\xef\xbb\xbf")
802
+ {
803
+ $converted_text = substr($converted_text, 0, -3);
804
+ }
805
+ }
806
+
807
+ return $converted_text;
808
+ }
809
+
810
+ /**
811
+ * Returns true if $string is valid UTF-8 and false otherwise.
812
+ *
813
+ * @param mixed $str String to be tested
814
+ * @return boolean
815
+ */
816
+ static function is_utf8($str)
817
+ {
818
+ $c=0; $b=0;
819
+ $bits=0;
820
+ $len=strlen($str);
821
+ for($i=0; $i<$len; $i++)
822
+ {
823
+ $c=ord($str[$i]);
824
+ if($c > 128)
825
+ {
826
+ if(($c >= 254)) return false;
827
+ elseif($c >= 252) $bits=6;
828
+ elseif($c >= 248) $bits=5;
829
+ elseif($c >= 240) $bits=4;
830
+ elseif($c >= 224) $bits=3;
831
+ elseif($c >= 192) $bits=2;
832
+ else return false;
833
+ if(($i+$bits) > $len) return false;
834
+ while($bits > 1)
835
+ {
836
+ $i++;
837
+ $b=ord($str[$i]);
838
+ if($b < 128 || $b > 191) return false;
839
+ $bits--;
840
+ }
841
+ }
842
+ }
843
+ return true;
844
+ }
845
+ /*
846
+ function is_utf8($string)
847
+ {
848
+ //this is buggy
849
+ return (utf8_encode(utf8_decode($string)) == $string);
850
+ }
851
+ */
852
+
853
+ /**
854
+ * Function to try a few tricks to determine the displayed size of an img on the page.
855
+ * NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types.
856
+ *
857
+ * @author John Schlick
858
+ * @version April 19 2012
859
+ * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out.
860
+ */
861
+ function get_display_size()
862
+ {
863
+ global $debugObject;
864
+
865
+ $width = -1;
866
+ $height = -1;
867
+
868
+ if ($this->tag !== 'img')
869
+ {
870
+ return false;
871
+ }
872
+
873
+ // See if there is aheight or width attribute in the tag itself.
874
+ if (isset($this->attr['width']))
875
+ {
876
+ $width = $this->attr['width'];
877
+ }
878
+
879
+ if (isset($this->attr['height']))
880
+ {
881
+ $height = $this->attr['height'];
882
+ }
883
+
884
+ // Now look for an inline style.
885
+ if (isset($this->attr['style']))
886
+ {
887
+ // Thanks to user gnarf from stackoverflow for this regular expression.
888
+ $attributes = array();
889
+ preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER);
890
+ foreach ($matches as $match) {
891
+ $attributes[$match[1]] = $match[2];
892
+ }
893
+
894
+ // If there is a width in the style attributes:
895
+ if (isset($attributes['width']) && $width == -1)
896
+ {
897
+ // check that the last two characters are px (pixels)
898
+ if (strtolower(substr($attributes['width'], -2)) == 'px')
899
+ {
900
+ $proposed_width = substr($attributes['width'], 0, -2);
901
+ // Now make sure that it's an integer and not something stupid.
902
+ if (filter_var($proposed_width, FILTER_VALIDATE_INT))
903
+ {
904
+ $width = $proposed_width;
905
+ }
906
+ }
907
+ }
908
+
909
+ // If there is a width in the style attributes:
910
+ if (isset($attributes['height']) && $height == -1)
911
+ {
912
+ // check that the last two characters are px (pixels)
913
+ if (strtolower(substr($attributes['height'], -2)) == 'px')
914
+ {
915
+ $proposed_height = substr($attributes['height'], 0, -2);
916
+ // Now make sure that it's an integer and not something stupid.
917
+ if (filter_var($proposed_height, FILTER_VALIDATE_INT))
918
+ {
919
+ $height = $proposed_height;
920
+ }
921
+ }
922
+ }
923
+
924
+ }
925
+
926
+ // Future enhancement:
927
+ // Look in the tag to see if there is a class or id specified that has a height or width attribute to it.
928
+
929
+ // Far future enhancement
930
+ // Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width
931
+ // Note that in this case, the class or id will have the img subselector for it to apply to the image.
932
+
933
+ // ridiculously far future development
934
+ // If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page.
935
+
936
+ $result = array('height' => $height,
937
+ 'width' => $width);
938
+ return $result;
939
+ }
940
+
941
+ // camel naming conventions
942
+ function getAllAttributes() {return $this->attr;}
943
+ function getAttribute($name) {return $this->__get($name);}
944
+ function setAttribute($name, $value) {$this->__set($name, $value);}
945
+ function hasAttribute($name) {return $this->__isset($name);}
946
+ function removeAttribute($name) {$this->__set($name, null);}
947
+ function getElementById($id) {return $this->find("#$id", 0);}
948
+ function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}
949
+ function getElementByTagName($name) {return $this->find($name, 0);}
950
+ function getElementsByTagName($name, $idx=null) {return $this->find($name, $idx);}
951
+ function parentNode() {return $this->parent();}
952
+ function childNodes($idx=-1) {return $this->children($idx);}
953
+ function firstChild() {return $this->first_child();}
954
+ function lastChild() {return $this->last_child();}
955
+ function nextSibling() {return $this->next_sibling();}
956
+ function previousSibling() {return $this->prev_sibling();}
957
+ function hasChildNodes() {return $this->has_child();}
958
+ function nodeName() {return $this->tag;}
959
+ function appendChild($node) {$node->parent($this); return $node;}
960
+
961
+ }
962
+
963
+ /**
964
+ * simple html dom parser
965
+ * Paperg - in the find routine: allow us to specify that we want case insensitive testing of the value of the selector.
966
+ * Paperg - change $size from protected to public so we can easily access it
967
+ * Paperg - added ForceTagsClosed in the constructor which tells us whether we trust the html or not. Default is to NOT trust it.
968
+ *
969
+ * @package PlaceLocalInclude
970
+ */
971
+ class simple_html_dom
972
+ {
973
+ public $root = null;
974
+ public $nodes = array();
975
+ public $callback = null;
976
+ public $lowercase = false;
977
+ // Used to keep track of how large the text was when we started.
978
+ public $original_size;
979
+ public $size;
980
+ protected $pos;
981
+ protected $doc;
982
+ protected $char;
983
+ protected $cursor;
984
+ protected $parent;
985
+ protected $noise = array();
986
+ protected $token_blank = " \t\r\n";
987
+ protected $token_equal = ' =/>';
988
+ protected $token_slash = " />\r\n\t";
989
+ protected $token_attr = ' >';
990
+ // Note that this is referenced by a child node, and so it needs to be public for that node to see this information.
991
+ public $_charset = '';
992
+ public $_target_charset = '';
993
+ protected $default_br_text = "";
994
+ public $default_span_text = "";
995
+
996
+ // use isset instead of in_array, performance boost about 30%...
997
+ protected $self_closing_tags = array('img'=>1, 'br'=>1, 'input'=>1, 'meta'=>1, 'link'=>1, 'hr'=>1, 'base'=>1, 'embed'=>1, 'spacer'=>1);
998
+ protected $block_tags = array('root'=>1, 'body'=>1, 'form'=>1, 'div'=>1, 'span'=>1, 'table'=>1);
999
+ // Known sourceforge issue #2977341
1000
+ // B tags that are not closed cause us to return everything to the end of the document.
1001
+ protected $optional_closing_tags = array(
1002
+ 'tr'=>array('tr'=>1, 'td'=>1, 'th'=>1),
1003
+ 'th'=>array('th'=>1),
1004
+ 'td'=>array('td'=>1),
1005
+ 'li'=>array('li'=>1),
1006
+ 'dt'=>array('dt'=>1, 'dd'=>1),
1007
+ 'dd'=>array('dd'=>1, 'dt'=>1),
1008
+ 'dl'=>array('dd'=>1, 'dt'=>1),
1009
+ 'p'=>array('p'=>1),
1010
+ 'nobr'=>array('nobr'=>1),
1011
+ 'b'=>array('b'=>1),
1012
+ 'option'=>array('option'=>1),
1013
+ );
1014
+
1015
+ function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
1016
+ {
1017
+ if ($str)
1018
+ {
1019
+ if (preg_match("/^http:\/\//i",$str) || is_file($str))
1020
+ {
1021
+ $this->load_file($str);
1022
+ }
1023
+ else
1024
+ {
1025
+ $this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);
1026
+ }
1027
+ }
1028
+ // Forcing tags to be closed implies that we don't trust the html, but it can lead to parsing errors if we SHOULD trust the html.
1029
+ if (!$forceTagsClosed) {
1030
+ $this->optional_closing_array=array();
1031
+ }
1032
+ $this->_target_charset = $target_charset;
1033
+ }
1034
+
1035
+ function __destruct()
1036
+ {
1037
+ $this->clear();
1038
+ }
1039
+
1040
+ // load html from string
1041
+ function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
1042
+ {
1043
+ global $debugObject;
1044
+
1045
+ // prepare
1046
+ $this->prepare($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);
1047
+ // strip out comments
1048
+ $this->remove_noise("'<!--(.*?)-->'is");
1049
+ // strip out cdata
1050
+ $this->remove_noise("'<!\[CDATA\[(.*?)\]\]>'is", true);
1051
+ // Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037
1052
+ // Script tags removal now preceeds style tag removal.
1053
+ // strip out <script> tags
1054
+ $this->remove_noise("'<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>'is");
1055
+ $this->remove_noise("'<\s*script\s*>(.*?)<\s*/\s*script\s*>'is");
1056
+ // strip out <style> tags
1057
+ $this->remove_noise("'<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>'is");
1058
+ $this->remove_noise("'<\s*style\s*>(.*?)<\s*/\s*style\s*>'is");
1059
+ // strip out preformatted tags
1060
+ $this->remove_noise("'<\s*(?:code)[^>]*>(.*?)<\s*/\s*(?:code)\s*>'is");
1061
+ // strip out server side scripts
1062
+ $this->remove_noise("'(<\?)(.*?)(\?>)'s", true);
1063
+ // strip smarty scripts
1064
+ $this->remove_noise("'(\{\w)(.*?)(\})'s", true);
1065
+
1066
+ // parsing
1067
+ while ($this->parse());
1068
+ // end
1069
+ $this->root->_[HDOM_INFO_END] = $this->cursor;
1070
+ $this->parse_charset();
1071
+
1072
+ // make load function chainable
1073
+ return $this;
1074
+
1075
+ }
1076
+
1077
+ // load html from file
1078
+ function load_file()
1079
+ {
1080
+ $args = func_get_args();
1081
+ $this->load(call_user_func_array('file_get_contents', $args), true);
1082
+ // Throw an error if we can't properly load the dom.
1083
+ if (($error=error_get_last())!==null) {
1084
+ $this->clear();
1085
+ return false;
1086
+ }
1087
+ }
1088
+
1089
+ // set callback function
1090
+ function set_callback($function_name)
1091
+ {
1092
+ $this->callback = $function_name;
1093
+ }
1094
+
1095
+ // remove callback function
1096
+ function remove_callback()
1097
+ {
1098
+ $this->callback = null;
1099
+ }
1100
+
1101
+ // save dom as string
1102
+ function save($filepath='')
1103
+ {
1104
+ $ret = $this->root->innertext();
1105
+ if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX);
1106
+ return $ret;
1107
+ }
1108
+
1109
+ // find dom node by css selector
1110
+ // Paperg - allow us to specify that we want case insensitive testing of the value of the selector.
1111
+ function find($selector, $idx=null, $lowercase=false)
1112
+ {
1113
+ return $this->root->find($selector, $idx, $lowercase);
1114
+ }
1115
+
1116
+ // clean up memory due to php5 circular references memory leak...
1117
+ function clear()
1118
+ {
1119
+ foreach ($this->nodes as $n) {$n->clear(); $n = null;}
1120
+ // This add next line is documented in the sourceforge repository. 2977248 as a fix for ongoing memory leaks that occur even with the use of clear.
1121
+ if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null;}
1122
+ if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);}
1123
+ if (isset($this->root)) {$this->root->clear(); unset($this->root);}
1124
+ unset($this->doc);
1125
+ unset($this->noise);
1126
+ }
1127
+
1128
+ function dump($show_attr=true)
1129
+ {
1130
+ $this->root->dump($show_attr);
1131
+ }
1132
+
1133
+ // prepare HTML data and init everything
1134
+ protected function prepare($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
1135
+ {
1136
+ $this->clear();
1137
+
1138
+ // set the length of content before we do anything to it.
1139
+ $this->size = strlen($str);
1140
+ // Save the original size of the html that we got in. It might be useful to someone.
1141
+ $this->original_size = $this->size;
1142
+
1143
+ //before we save the string as the doc... strip out the \r \n's if we are told to.
1144
+ if ($stripRN) {
1145
+ $str = str_replace("\r", " ", $str);
1146
+ $str = str_replace("\n", " ", $str);
1147
+
1148
+ // set the length of content since we have changed it.
1149
+ $this->size = strlen($str);
1150
+ }
1151
+
1152
+ $this->doc = $str;
1153
+ $this->pos = 0;
1154
+ $this->cursor = 1;
1155
+ $this->noise = array();
1156
+ $this->nodes = array();
1157
+ $this->lowercase = $lowercase;
1158
+ $this->default_br_text = $defaultBRText;
1159
+ $this->default_span_text = $defaultSpanText;
1160
+ $this->root = new simple_html_dom_node($this);
1161
+ $this->root->tag = 'root';
1162
+ $this->root->_[HDOM_INFO_BEGIN] = -1;
1163
+ $this->root->nodetype = HDOM_TYPE_ROOT;
1164
+ $this->parent = $this->root;
1165
+ if ($this->size>0) $this->char = $this->doc[0];
1166
+ }
1167
+
1168
+ // parse html content
1169
+ protected function parse()
1170
+ {
1171
+ if (($s = $this->copy_until_char('<'))==='')
1172
+ {
1173
+ return $this->read_tag();
1174
+ }
1175
+
1176
+ // text
1177
+ $node = new simple_html_dom_node($this);
1178
+ ++$this->cursor;
1179
+ $node->_[HDOM_INFO_TEXT] = $s;
1180
+ $this->link_nodes($node, false);
1181
+ return true;
1182
+ }
1183
+
1184
+ // PAPERG - dkchou - added this to try to identify the character set of the page we have just parsed so we know better how to spit it out later.
1185
+ // NOTE: IF you provide a routine called get_last_retrieve_url_contents_content_type which returns the CURLINFO_CONTENT_TYPE from the last curl_exec
1186
+ // (or the content_type header from the last transfer), we will parse THAT, and if a charset is specified, we will use it over any other mechanism.
1187
+ protected function parse_charset()
1188
+ {
1189
+ global $debugObject;
1190
+
1191
+ $charset = null;
1192
+
1193
+ if (function_exists('get_last_retrieve_url_contents_content_type'))
1194
+ {
1195
+ $contentTypeHeader = get_last_retrieve_url_contents_content_type();
1196
+ $success = preg_match('/charset=(.+)/', $contentTypeHeader, $matches);
1197
+ if ($success)
1198
+ {
1199
+ $charset = $matches[1];
1200
+ if (is_object($debugObject)) {$debugObject->debugLog(2, 'header content-type found charset of: ' . $charset);}
1201
+ }
1202
+
1203
+ }
1204
+
1205
+ if (empty($charset))
1206
+ {
1207
+ $el = $this->root->find('meta[http-equiv=Content-Type]',0);
1208
+ if (!empty($el))
1209
+ {
1210
+ $fullvalue = $el->content;
1211
+ if (is_object($debugObject)) {$debugObject->debugLog(2, 'meta content-type tag found' . $fullvalue);}
1212
+
1213
+ if (!empty($fullvalue))
1214
+ {
1215
+ $success = preg_match('/charset=(.+)/', $fullvalue, $matches);
1216
+ if ($success)
1217
+ {
1218
+ $charset = $matches[1];
1219
+ }
1220
+ else
1221
+ {
1222
+ // If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1
1223
+ if (is_object($debugObject)) {$debugObject->debugLog(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');}
1224
+ $charset = 'ISO-8859-1';
1225
+ }
1226
+ }
1227
+ }
1228
+ }
1229
+
1230
+ // If we couldn't find a charset above, then lets try to detect one based on the text we got...
1231
+ if (empty($charset))
1232
+ {
1233
+ // Have php try to detect the encoding from the text given to us.
1234
+ $charset = mb_detect_encoding($this->root->plaintext . "ascii", $encoding_list = array( "UTF-8", "CP1252" ) );
1235
+ if (is_object($debugObject)) {$debugObject->debugLog(2, 'mb_detect found: ' . $charset);}
1236
+
1237
+ // and if this doesn't work... then we need to just wrongheadedly assume it's UTF-8 so that we can move on - cause this will usually give us most of what we need...
1238
+ if ($charset === false)
1239
+ {
1240
+ if (is_object($debugObject)) {$debugObject->debugLog(2, 'since mb_detect failed - using default of utf-8');}
1241
+ $charset = 'UTF-8';
1242
+ }
1243
+ }
1244
+
1245
+ // Since CP1252 is a superset, if we get one of it's subsets, we want it instead.
1246
+ if ((strtolower($charset) == strtolower('ISO-8859-1')) || (strtolower($charset) == strtolower('Latin1')) || (strtolower($charset) == strtolower('Latin-1')))
1247
+ {
1248
+ if (is_object($debugObject)) {$debugObject->debugLog(2, 'replacing ' . $charset . ' with CP1252 as its a superset');}
1249
+ $charset = 'CP1252';
1250
+ }
1251
+
1252
+ if (is_object($debugObject)) {$debugObject->debugLog(1, 'EXIT - ' . $charset);}
1253
+
1254
+ return $this->_charset = $charset;
1255
+ }
1256
+
1257
+ // read tag info
1258
+ protected function read_tag()
1259
+ {
1260
+ if ($this->char!=='<')
1261
+ {
1262
+ $this->root->_[HDOM_INFO_END] = $this->cursor;
1263
+ return false;
1264
+ }
1265
+ $begin_tag_pos = $this->pos;
1266
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1267
+
1268
+ // end tag
1269
+ if ($this->char==='/')
1270
+ {
1271
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1272
+ // This represents the change in the simple_html_dom trunk from revision 180 to 181.
1273
+ // $this->skip($this->token_blank_t);
1274
+ $this->skip($this->token_blank);
1275
+ $tag = $this->copy_until_char('>');
1276
+
1277
+ // skip attributes in end tag
1278
+ if (($pos = strpos($tag, ' '))!==false)
1279
+ $tag = substr($tag, 0, $pos);
1280
+
1281
+ $parent_lower = strtolower($this->parent->tag);
1282
+ $tag_lower = strtolower($tag);
1283
+
1284
+ if ($parent_lower!==$tag_lower)
1285
+ {
1286
+ if (isset($this->optional_closing_tags[$parent_lower]) && isset($this->block_tags[$tag_lower]))
1287
+ {
1288
+ $this->parent->_[HDOM_INFO_END] = 0;
1289
+ $org_parent = $this->parent;
1290
+
1291
+ while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)
1292
+ $this->parent = $this->parent->parent;
1293
+
1294
+ if (strtolower($this->parent->tag)!==$tag_lower) {
1295
+ $this->parent = $org_parent; // restore origonal parent
1296
+ if ($this->parent->parent) $this->parent = $this->parent->parent;
1297
+ $this->parent->_[HDOM_INFO_END] = $this->cursor;
1298
+ return $this->as_text_node($tag);
1299
+ }
1300
+ }
1301
+ else if (($this->parent->parent) && isset($this->block_tags[$tag_lower]))
1302
+ {
1303
+ $this->parent->_[HDOM_INFO_END] = 0;
1304
+ $org_parent = $this->parent;
1305
+
1306
+ while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)
1307
+ $this->parent = $this->parent->parent;
1308
+
1309
+ if (strtolower($this->parent->tag)!==$tag_lower)
1310
+ {
1311
+ $this->parent = $org_parent; // restore origonal parent
1312
+ $this->parent->_[HDOM_INFO_END] = $this->cursor;
1313
+ return $this->as_text_node($tag);
1314
+ }
1315
+ }
1316
+ else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower)
1317
+ {
1318
+ $this->parent->_[HDOM_INFO_END] = 0;
1319
+ $this->parent = $this->parent->parent;
1320
+ }
1321
+ else
1322
+ return $this->as_text_node($tag);
1323
+ }
1324
+
1325
+ $this->parent->_[HDOM_INFO_END] = $this->cursor;
1326
+ if ($this->parent->parent) $this->parent = $this->parent->parent;
1327
+
1328
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1329
+ return true;
1330
+ }
1331
+
1332
+ $node = new simple_html_dom_node($this);
1333
+ $node->_[HDOM_INFO_BEGIN] = $this->cursor;
1334
+ ++$this->cursor;
1335
+ $tag = $this->copy_until($this->token_slash);
1336
+ $node->tag_start = $begin_tag_pos;
1337
+
1338
+ // doctype, cdata & comments...
1339
+ if (isset($tag[0]) && $tag[0]==='!') {
1340
+ $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until_char('>');
1341
+
1342
+ if (isset($tag[2]) && $tag[1]==='-' && $tag[2]==='-') {
1343
+ $node->nodetype = HDOM_TYPE_COMMENT;
1344
+ $node->tag = 'comment';
1345
+ } else {
1346
+ $node->nodetype = HDOM_TYPE_UNKNOWN;
1347
+ $node->tag = 'unknown';
1348
+ }
1349
+ if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
1350
+ $this->link_nodes($node, true);
1351
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1352
+ return true;
1353
+ }
1354
+
1355
+ // text
1356
+ if ($pos=strpos($tag, '<')!==false) {
1357
+ $tag = '<' . substr($tag, 0, -1);
1358
+ $node->_[HDOM_INFO_TEXT] = $tag;
1359
+ $this->link_nodes($node, false);
1360
+ $this->char = $this->doc[--$this->pos]; // prev
1361
+ return true;
1362
+ }
1363
+
1364
+ if (!preg_match("/^[\w-:]+$/", $tag)) {
1365
+ $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');
1366
+ if ($this->char==='<') {
1367
+ $this->link_nodes($node, false);
1368
+ return true;
1369
+ }
1370
+
1371
+ if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
1372
+ $this->link_nodes($node, false);
1373
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1374
+ return true;
1375
+ }
1376
+
1377
+ // begin tag
1378
+ $node->nodetype = HDOM_TYPE_ELEMENT;
1379
+ $tag_lower = strtolower($tag);
1380
+ $node->tag = ($this->lowercase) ? $tag_lower : $tag;
1381
+
1382
+ // handle optional closing tags
1383
+ if (isset($this->optional_closing_tags[$tag_lower]) )
1384
+ {
1385
+ while (isset($this->optional_closing_tags[$tag_lower][strtolower($this->parent->tag)]))
1386
+ {
1387
+ $this->parent->_[HDOM_INFO_END] = 0;
1388
+ $this->parent = $this->parent->parent;
1389
+ }
1390
+ $node->parent = $this->parent;
1391
+ }
1392
+
1393
+ $guard = 0; // prevent infinity loop
1394
+ $space = array($this->copy_skip($this->token_blank), '', '');
1395
+
1396
+ // attributes
1397
+ do
1398
+ {
1399
+ if ($this->char!==null && $space[0]==='')
1400
+ {
1401
+ break;
1402
+ }
1403
+ $name = $this->copy_until($this->token_equal);
1404
+ if ($guard===$this->pos)
1405
+ {
1406
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1407
+ continue;
1408
+ }
1409
+ $guard = $this->pos;
1410
+
1411
+ // handle endless '<'
1412
+ if ($this->pos>=$this->size-1 && $this->char!=='>') {
1413
+ $node->nodetype = HDOM_TYPE_TEXT;
1414
+ $node->_[HDOM_INFO_END] = 0;
1415
+ $node->_[HDOM_INFO_TEXT] = '<'.$tag . $space[0] . $name;
1416
+ $node->tag = 'text';
1417
+ $this->link_nodes($node, false);
1418
+ return true;
1419
+ }
1420
+
1421
+ // handle mismatch '<'
1422
+ if ($this->doc[$this->pos-1]=='<') {
1423
+ $node->nodetype = HDOM_TYPE_TEXT;
1424
+ $node->tag = 'text';
1425
+ $node->attr = array();
1426
+ $node->_[HDOM_INFO_END] = 0;
1427
+ $node->_[HDOM_INFO_TEXT] = substr($this->doc, $begin_tag_pos, $this->pos-$begin_tag_pos-1);
1428
+ $this->pos -= 2;
1429
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1430
+ $this->link_nodes($node, false);
1431
+ return true;
1432
+ }
1433
+
1434
+ if ($name!=='/' && $name!=='') {
1435
+ $space[1] = $this->copy_skip($this->token_blank);
1436
+ $name = $this->restore_noise($name);
1437
+ if ($this->lowercase) $name = strtolower($name);
1438
+ if ($this->char==='=') {
1439
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1440
+ $this->parse_attr($node, $name, $space);
1441
+ }
1442
+ else {
1443
+ //no value attr: nowrap, checked selected...
1444
+ $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;
1445
+ $node->attr[$name] = true;
1446
+ if ($this->char!='>') $this->char = $this->doc[--$this->pos]; // prev
1447
+ }
1448
+ $node->_[HDOM_INFO_SPACE][] = $space;
1449
+ $space = array($this->copy_skip($this->token_blank), '', '');
1450
+ }
1451
+ else
1452
+ break;
1453
+ } while ($this->char!=='>' && $this->char!=='/');
1454
+
1455
+ $this->link_nodes($node, true);
1456
+ $node->_[HDOM_INFO_ENDSPACE] = $space[0];
1457
+
1458
+ // check self closing
1459
+ if ($this->copy_until_char_escape('>')==='/')
1460
+ {
1461
+ $node->_[HDOM_INFO_ENDSPACE] .= '/';
1462
+ $node->_[HDOM_INFO_END] = 0;
1463
+ }
1464
+ else
1465
+ {
1466
+ // reset parent
1467
+ if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node;
1468
+ }
1469
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1470
+
1471
+ // If it's a BR tag, we need to set it's text to the default text.
1472
+ // This way when we see it in plaintext, we can generate formatting that the user wants.
1473
+ // since a br tag never has sub nodes, this works well.
1474
+ if ($node->tag == "br")
1475
+ {
1476
+ $node->_[HDOM_INFO_INNER] = $this->default_br_text;
1477
+ }
1478
+
1479
+ return true;
1480
+ }
1481
+
1482
+ // parse attributes
1483
+ protected function parse_attr($node, $name, &$space)
1484
+ {
1485
+ // Per sourceforge: http://sourceforge.net/tracker/?func=detail&aid=3061408&group_id=218559&atid=1044037
1486
+ // If the attribute is already defined inside a tag, only pay atetntion to the first one as opposed to the last one.
1487
+ if (isset($node->attr[$name]))
1488
+ {
1489
+ return;
1490
+ }
1491
+
1492
+ $space[2] = $this->copy_skip($this->token_blank);
1493
+ switch ($this->char) {
1494
+ case '"':
1495
+ $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;
1496
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1497
+ $node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('"'));
1498
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1499
+ break;
1500
+ case '\'':
1501
+ $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_SINGLE;
1502
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1503
+ $node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('\''));
1504
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1505
+ break;
1506
+ default:
1507
+ $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;
1508
+ $node->attr[$name] = $this->restore_noise($this->copy_until($this->token_attr));
1509
+ }
1510
+ // PaperG: Attributes should not have \r or \n in them, that counts as html whitespace.
1511
+ $node->attr[$name] = str_replace("\r", "", $node->attr[$name]);
1512
+ $node->attr[$name] = str_replace("\n", "", $node->attr[$name]);
1513
+ // PaperG: If this is a "class" selector, lets get rid of the preceeding and trailing space since some people leave it in the multi class case.
1514
+ if ($name == "class") {
1515
+ $node->attr[$name] = trim($node->attr[$name]);
1516
+ }
1517
+ }
1518
+
1519
+ // link node's parent
1520
+ protected function link_nodes(&$node, $is_child)
1521
+ {
1522
+ $node->parent = $this->parent;
1523
+ $this->parent->nodes[] = $node;
1524
+ if ($is_child)
1525
+ {
1526
+ $this->parent->children[] = $node;
1527
+ }
1528
+ }
1529
+
1530
+ // as a text node
1531
+ protected function as_text_node($tag)
1532
+ {
1533
+ $node = new simple_html_dom_node($this);
1534
+ ++$this->cursor;
1535
+ $node->_[HDOM_INFO_TEXT] = '</' . $tag . '>';
1536
+ $this->link_nodes($node, false);
1537
+ $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1538
+ return true;
1539
+ }
1540
+
1541
+ protected function skip($chars)
1542
+ {
1543
+ $this->pos += strspn($this->doc, $chars, $this->pos);
1544
+ $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1545
+ }
1546
+
1547
+ protected function copy_skip($chars)
1548
+ {
1549
+ $pos = $this->pos;
1550
+ $len = strspn($this->doc, $chars, $pos);
1551
+ $this->pos += $len;
1552
+ $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1553
+ if ($len===0) return '';
1554
+ return substr($this->doc, $pos, $len);
1555
+ }
1556
+
1557
+ protected function copy_until($chars)
1558
+ {
1559
+ $pos = $this->pos;
1560
+ $len = strcspn($this->doc, $chars, $pos);
1561
+ $this->pos += $len;
1562
+ $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
1563
+ return substr($this->doc, $pos, $len);
1564
+ }
1565
+
1566
+ protected function copy_until_char($char)
1567
+ {
1568
+ if ($this->char===null) return '';
1569
+
1570
+ if (($pos = strpos($this->doc, $char, $this->pos))===false) {
1571
+ $ret = substr($this->doc, $this->pos, $this->size-$this->pos);
1572
+ $this->char = null;
1573
+ $this->pos = $this->size;
1574
+ return $ret;
1575
+ }
1576
+
1577
+ if ($pos===$this->pos) return '';
1578
+ $pos_old = $this->pos;
1579
+ $this->char = $this->doc[$pos];
1580
+ $this->pos = $pos;
1581
+ return substr($this->doc, $pos_old, $pos-$pos_old);
1582
+ }
1583
+
1584
+ protected function copy_until_char_escape($char)
1585
+ {
1586
+ if ($this->char===null) return '';
1587
+
1588
+ $start = $this->pos;
1589
+ while (1)
1590
+ {
1591
+ if (($pos = strpos($this->doc, $char, $start))===false)
1592
+ {
1593
+ $ret = substr($this->doc, $this->pos, $this->size-$this->pos);
1594
+ $this->char = null;
1595
+ $this->pos = $this->size;
1596
+ return $ret;
1597
+ }
1598
+
1599
+ if ($pos===$this->pos) return '';
1600
+
1601
+ if ($this->doc[$pos-1]==='\\') {
1602
+ $start = $pos+1;
1603
+ continue;
1604
+ }
1605
+
1606
+ $pos_old = $this->pos;
1607
+ $this->char = $this->doc[$pos];
1608
+ $this->pos = $pos;
1609
+ return substr($this->doc, $pos_old, $pos-$pos_old);
1610
+ }
1611
+ }
1612
+
1613
+ // remove noise from html content
1614
+ // save the noise in the $this->noise array.
1615
+ protected function remove_noise($pattern, $remove_tag=false)
1616
+ {
1617
+ global $debugObject;
1618
+ if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }
1619
+
1620
+ $count = preg_match_all($pattern, $this->doc, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
1621
+
1622
+ for ($i=$count-1; $i>-1; --$i)
1623
+ {
1624
+ $key = '___noise___'.sprintf('% 5d', count($this->noise)+1000);
1625
+ if (is_object($debugObject)) { $debugObject->debugLog(2, 'key is: ' . $key); }
1626
+ $idx = ($remove_tag) ? 0 : 1;
1627
+ $this->noise[$key] = $matches[$i][$idx][0];
1628
+ $this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0]));
1629
+ }
1630
+
1631
+ // reset the length of content
1632
+ $this->size = strlen($this->doc);
1633
+ if ($this->size>0)
1634
+ {
1635
+ $this->char = $this->doc[0];
1636
+ }
1637
+ }
1638
+
1639
+ // restore noise to html content
1640
+ function restore_noise($text)
1641
+ {
1642
+ global $debugObject;
1643
+ if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }
1644
+
1645
+ while (($pos=strpos($text, '___noise___'))!==false)
1646
+ {
1647
+ // Sometimes there is a broken piece of markup, and we don't GET the pos+11 etc... token which indicates a problem outside of us...
1648
+ if (strlen($text) > $pos+15)
1649
+ {
1650
+ $key = '___noise___'.$text[$pos+11].$text[$pos+12].$text[$pos+13].$text[$pos+14].$text[$pos+15];
1651
+ if (is_object($debugObject)) { $debugObject->debugLog(2, 'located key of: ' . $key); }
1652
+
1653
+ if (isset($this->noise[$key]))
1654
+ {
1655
+ $text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+16);
1656
+ }
1657
+ else
1658
+ {
1659
+ // do this to prevent an infinite loop.
1660
+ $text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key . substr($text, $pos+16);
1661
+ }
1662
+ }
1663
+ else
1664
+ {
1665
+ // There is no valid key being given back to us... We must get rid of the ___noise___ or we will have a problem.
1666
+ $text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY' . substr($text, $pos+11);
1667
+ }
1668
+ }
1669
+ return $text;
1670
+ }
1671
+
1672
+ // Sometimes we NEED one of the noise elements.
1673
+ function search_noise($text)
1674
+ {
1675
+ global $debugObject;
1676
+ if (is_object($debugObject)) { $debugObject->debugLogEntry(1); }
1677
+
1678
+ foreach($this->noise as $noiseElement)
1679
+ {
1680
+ if (strpos($noiseElement, $text)!==false)
1681
+ {
1682
+ return $noiseElement;
1683
+ }
1684
+ }
1685
+ }
1686
+ function __toString()
1687
+ {
1688
+ return $this->root->innertext();
1689
+ }
1690
+
1691
+ function __get($name)
1692
+ {
1693
+ switch ($name)
1694
+ {
1695
+ case 'outertext':
1696
+ return $this->root->innertext();
1697
+ case 'innertext':
1698
+ return $this->root->innertext();
1699
+ case 'plaintext':
1700
+ return $this->root->text();
1701
+ case 'charset':
1702
+ return $this->_charset;
1703
+ case 'target_charset':
1704
+ return $this->_target_charset;
1705
+ }
1706
+ }
1707
+
1708
+ // camel naming conventions
1709
+ function childNodes($idx=-1) {return $this->root->childNodes($idx);}
1710
+ function firstChild() {return $this->root->first_child();}
1711
+ function lastChild() {return $this->root->last_child();}
1712
+ function createElement($name, $value=null) {return @str_get_html("<$name>$value</$name>")->first_child();}
1713
+ function createTextNode($value) {return @end(str_get_html($value)->nodes);}
1714
+ function getElementById($id) {return $this->find("#$id", 0);}
1715
+ function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}
1716
+ function getElementByTagName($name) {return $this->find($name, 0);}
1717
+ function getElementsByTagName($name, $idx=-1) {return $this->find($name, $idx);}
1718
+ function loadFile() {$args = func_get_args();$this->load_file($args);}
1719
+ }
1720
+
1721
+ ?>
includes/upgrade-plugin.php CHANGED
@@ -1,114 +1,114 @@
1
- <?php
2
-
3
- /**
4
- * Run the upgrade process from version 1.x of the plugin to current.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- // Need to first check if there is currently a version option stored to compare it later
17
- if ( ! get_option( 'pib_version' ) ) {
18
- add_option( 'pib_version', $this->version );
19
- } else {
20
- add_option( 'pib_old_version', get_option( 'pib_version' ) );
21
- }
22
-
23
- // If this option exists then the plugin is before version 2.0.0
24
- if ( get_option( 'pib_options' ) ) {
25
- add_option( 'pib_old_version', '1.4.3' );
26
- update_option( 'pib_upgrade_has_run', 1 );
27
- }
28
-
29
- // Only if the old version is less than the new version do we run our upgrade code.
30
- if ( version_compare( get_option( 'pib_old_version' ), $this->version, '<' ) ) {
31
- // need to update pib_upgrade_has_run so that we don;t load the defaults in too
32
- update_option( 'pib_upgrade_has_run', 1 );
33
- pib_do_all_upgrades();
34
- } else {
35
- // Delete our holder for the old version of PIB.
36
- delete_option( 'pib_old_version' );
37
- }
38
-
39
- /**
40
- * Check and run through all necessary upgrades
41
- *
42
- * @since 2.0.0
43
- */
44
- function pib_do_all_upgrades() {
45
-
46
- $current_version = get_option( 'pib_old_version' );
47
-
48
- // if less than version 2 then upgrade
49
- if ( version_compare( $current_version, '2.0.0', '<' ))
50
- pib_v2_upgrade();
51
-
52
- delete_option( 'pib_old_version' );
53
-
54
- }
55
-
56
- /**
57
- * Run all needed upgrades for users coming from pre-2.0.0
58
- *
59
- * @since 2.0.0
60
- */
61
- function pib_v2_upgrade() {
62
- // Add code here to transfer all the options to new tab layout
63
-
64
- // Need to decipher which Post Visibility settings to update so we will use an array
65
- $page_placement = array( 'display_above_content', 'display_below_content', 'display_on_post_excerpts' );
66
-
67
- if ( get_option('pib_options' ) ) {
68
- $old_options = get_option( 'pib_options' );
69
-
70
- // get the new options so we can update them accordingly
71
- $general_options = get_option( 'pib_settings_general' );
72
- $post_visibility_options = get_option( 'pib_settings_post_visibility' );
73
- $style_options = get_option( 'pib_settings_styles' );
74
-
75
- // Do I need to add the new options here if they don't exist?
76
-
77
- foreach ($old_options as $key => $value) {
78
-
79
- if ( 'custom_css' == $key || 'remove_div' == $key ) {
80
- // Add to styles settings
81
- $style_options[$key] = $value;
82
-
83
- } else if ( ! ( false === strrpos( $key, 'display' ) ) ) {
84
- // Add to Post Visibility settings
85
-
86
- // With the new options we have these setup as nested arrays so we need to check which one we are adding to
87
- if ( in_array( $key, $page_placement ) ) {
88
- $post_visibility_options['post_page_placement'][$key] = $value;
89
- } else {
90
- $post_visibility_options['post_page_types'][$key] = $value;
91
- }
92
-
93
- } else {
94
- // Add to General Settings
95
- // we are changing 'button_style' to 'button_type' going forward
96
- if( 'button_style' == $key ) {
97
- $general_options['button_type'] = $value;
98
- } else {
99
- $general_options[$key] = $value;
100
- }
101
- }
102
-
103
- // add update options here
104
- update_option( 'pib_settings_general', $general_options );
105
- update_option( 'pib_settings_post_visibility', $post_visibility_options );
106
- update_option( 'pib_settings_styles', $style_options );
107
-
108
- // Delete old options
109
- delete_option( 'pib_options' );
110
- delete_option( 'pib_hide_pointer' );
111
- }
112
- }
113
- }
114
- pib_do_all_upgrades();
1
+ <?php
2
+
3
+ /**
4
+ * Run the upgrade process from version 1.x of the plugin to current.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ // Need to first check if there is currently a version option stored to compare it later
17
+ if ( ! get_option( 'pib_version' ) ) {
18
+ add_option( 'pib_version', $this->version );
19
+ } else {
20
+ add_option( 'pib_old_version', get_option( 'pib_version' ) );
21
+ }
22
+
23
+ // If this option exists then the plugin is before version 2.0.0
24
+ if ( get_option( 'pib_options' ) ) {
25
+ add_option( 'pib_old_version', '1.4.3' );
26
+ update_option( 'pib_upgrade_has_run', 1 );
27
+ }
28
+
29
+ // Only if the old version is less than the new version do we run our upgrade code.
30
+ if ( version_compare( get_option( 'pib_old_version' ), $this->version, '<' ) ) {
31
+ // need to update pib_upgrade_has_run so that we don;t load the defaults in too
32
+ update_option( 'pib_upgrade_has_run', 1 );
33
+ pib_do_all_upgrades();
34
+ } else {
35
+ // Delete our holder for the old version of PIB.
36
+ delete_option( 'pib_old_version' );
37
+ }
38
+
39
+ /**
40
+ * Check and run through all necessary upgrades
41
+ *
42
+ * @since 2.0.0
43
+ */
44
+ function pib_do_all_upgrades() {
45
+
46
+ $current_version = get_option( 'pib_old_version' );
47
+
48
+ // if less than version 2 then upgrade
49
+ if ( version_compare( $current_version, '2.0.0', '<' ))
50
+ pib_v2_upgrade();
51
+
52
+ delete_option( 'pib_old_version' );
53
+
54
+ }
55
+
56
+ /**
57
+ * Run all needed upgrades for users coming from pre-2.0.0
58
+ *
59
+ * @since 2.0.0
60
+ */
61
+ function pib_v2_upgrade() {
62
+ // Add code here to transfer all the options to new tab layout
63
+
64
+ // Need to decipher which Post Visibility settings to update so we will use an array
65
+ $page_placement = array( 'display_above_content', 'display_below_content', 'display_on_post_excerpts' );
66
+
67
+ if ( get_option('pib_options' ) ) {
68
+ $old_options = get_option( 'pib_options' );
69
+
70
+ // get the new options so we can update them accordingly
71
+ $general_options = get_option( 'pib_settings_general' );
72
+ $post_visibility_options = get_option( 'pib_settings_post_visibility' );
73
+ $style_options = get_option( 'pib_settings_styles' );
74
+
75
+ // Do I need to add the new options here if they don't exist?
76
+
77
+ foreach ($old_options as $key => $value) {
78
+
79
+ if ( 'custom_css' == $key || 'remove_div' == $key ) {
80
+ // Add to styles settings
81
+ $style_options[$key] = $value;
82
+
83
+ } else if ( ! ( false === strrpos( $key, 'display' ) ) ) {
84
+ // Add to Post Visibility settings
85
+
86
+ // With the new options we have these setup as nested arrays so we need to check which one we are adding to
87
+ if ( in_array( $key, $page_placement ) ) {
88
+ $post_visibility_options['post_page_placement'][$key] = $value;
89
+ } else {
90
+ $post_visibility_options['post_page_types'][$key] = $value;
91
+ }
92
+
93
+ } else {
94
+ // Add to General Settings
95
+ // we are changing 'button_style' to 'button_type' going forward
96
+ if( 'button_style' == $key ) {
97
+ $general_options['button_type'] = $value;
98
+ } else {
99
+ $general_options[$key] = $value;
100
+ }
101
+ }
102
+
103
+ // add update options here
104
+ update_option( 'pib_settings_general', $general_options );
105
+ update_option( 'pib_settings_post_visibility', $post_visibility_options );
106
+ update_option( 'pib_settings_styles', $style_options );
107
+
108
+ // Delete old options
109
+ delete_option( 'pib_options' );
110
+ delete_option( 'pib_hide_pointer' );
111
+ }
112
+ }
113
+ }
114
+ pib_do_all_upgrades();
includes/widgets.php CHANGED
@@ -1,261 +1,261 @@
1
- <?php
2
-
3
- /**
4
- * Represents the view for the widget component of the plugin.
5
- *
6
- * @package PIB
7
- * @subpackage Includes
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- /**
17
- * Class functions for the Pin It Button widgets
18
- *
19
- * @since 2.0.0
20
- */
21
- class PIB_Widget extends WP_Widget {
22
-
23
- /**
24
- * Initialize the widget
25
- *
26
- * @since 2.0.0
27
- */
28
- public function __construct() {
29
- parent::__construct(
30
- 'pib_button',
31
- __( 'Pinterest "Pin It" Button', 'pib' ),
32
- array(
33
- 'classname' => 'pib-clearfix', // Wrap widget with "clear fix" CSS trick.
34
- 'description' => __( 'Add a Pinterest "Pin It" button to any widget area.', 'pib' )
35
- ),
36
- // Widen widget admin area.
37
- array( 'width' => 400 )
38
- );
39
- }
40
-
41
- /**
42
- * Public facing widget code
43
- *
44
- * @since 2.0.0
45
- */
46
- public function widget( $args, $instance ) {
47
- global $pib_options;
48
- extract( $args );
49
-
50
- $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
51
-
52
- $pib_url_of_webpage_widget = $instance['pib_url_of_webpage_widget'];
53
-
54
- //Set URL to home page if button style is "user selects image"
55
- if ( empty( $pib_url_of_webpage_widget ) && ( $pib_options['button_type'] == 'user_selects_image' ) ) {
56
- $pib_url_of_webpage_widget = get_home_url();
57
- }
58
-
59
- $pib_url_of_img_widget = $instance['pib_url_of_img_widget'];
60
- $pib_description_widget = $instance['pib_description_widget'];
61
- $count_layout = empty( $instance['count_layout'] ) ? 'none' : $instance['count_layout'];
62
- $align = empty( $instance['button_align'] ) ? 'none' : $instance['button_align'];
63
- $pib_remove_div = (bool) $instance['remove_div'];
64
- $button_type = empty ( $instance['button_type'] ) ? 'user_selects_image' : $instance['button_type'];
65
- $size = ( ! empty( $instance['size'] ) ? $instance['size'] : 'small' );
66
- $color = ( ! empty( $instance['color'] ) ? $instance['color'] : 'gray' );
67
- $shape = ( ! empty( $instance['shape'] ) ? $instance['shape'] : 'rectangular' );
68
-
69
- // If the button type is set for users to select image then we need to overwrite any values from the widget that are used
70
- // for displaying a a pre-selected image. These are not erased from the widget, but are just overwritten here.
71
- if ( 'user_selects_image' == $button_type ) {
72
- $pib_url_of_webpage_widget = '';
73
- $pib_url_of_img_widget = '';
74
- $pib_description_widget = '';
75
- }
76
-
77
- $base_btn = pib_button_base( $button_type, $pib_url_of_webpage_widget, $pib_url_of_img_widget, $pib_description_widget, $count_layout, $size, $color, $shape );
78
-
79
- echo $before_widget;
80
-
81
- if ( ! empty( $title ) ) {
82
- echo $before_title . $title . $after_title;
83
- }
84
-
85
- if ( $pib_remove_div ) {
86
- $html = $base_btn;
87
- }
88
- else {
89
-
90
- $align_class = '';
91
-
92
- if ( 'left' == $align ) {
93
- $align_class = 'pib-align-left';
94
- }
95
- elseif ( 'right' == $align ) {
96
- $align_class = 'pib-align-right';
97
- }
98
- elseif ( 'center' == $align ) {
99
- $align_class = 'pib-align-center';
100
- }
101
-
102
- // Surround with div tag
103
- $html = '<div class="pin-it-btn-wrapper-widget ' . $align_class . '">' . $base_btn . '</div>';
104
- }
105
-
106
- do_action( 'pib_widget_before' );
107
-
108
- echo apply_filters( 'pib_widget_html', $html );
109
-
110
- do_action( 'pib_widget_after' );
111
-
112
- echo $after_widget;
113
- }
114
-
115
- /**
116
- * Update the widget settings from user input
117
- *
118
- * @since 2.0.0
119
- */
120
- public function update( $new_instance, $old_instance ) {
121
- $instance = $old_instance;
122
-
123
- $instance['title'] = strip_tags($new_instance['title']);
124
- $instance['pib_url_of_webpage_widget'] = strip_tags( $new_instance['pib_url_of_webpage_widget'] );
125
- $instance['pib_url_of_img_widget'] = strip_tags( $new_instance['pib_url_of_img_widget'] );
126
- $instance['pib_description_widget'] = strip_tags( $new_instance['pib_description_widget'] );
127
- $instance['count_layout'] = $new_instance['count_layout'];
128
- $instance['button_align'] = $new_instance['align'];
129
- $instance['remove_div'] = ( $new_instance['remove_div'] ? 1 : 0 );
130
- $instance['button_type'] = $new_instance['button_type'];
131
- $instance['size'] = $new_instance['size'];
132
- $instance['color'] = $new_instance['color'];
133
- $instance['shape'] = $new_instance['shape'];
134
-
135
- return $instance;
136
- }
137
-
138
- /**
139
- * Display widget settings in admin
140
- *
141
- * @since 2.0.0
142
- */
143
- public function form( $instance ) {
144
- global $pib_options;
145
-
146
- $default = array(
147
- 'title' => '',
148
- 'count_layout' => 'none',
149
- 'button_type' => 'user_selects_image',
150
- 'pib_url_of_webpage_widget' => '',
151
- 'pib_url_of_img_widget' => '',
152
- 'pib_description_widget' => '',
153
- 'button_align' => 'none',
154
- 'remove_div' => 0,
155
- 'size' => 'small',
156
- 'color' => 'gray',
157
- 'shape' => 'rectangular'
158
- );
159
-
160
- $instance = wp_parse_args( (array) $instance, $default );
161
-
162
- $title = strip_tags($instance['title']);
163
- $pib_url_of_webpage_widget = strip_tags( $instance['pib_url_of_webpage_widget'] );
164
- $pib_url_of_img_widget = strip_tags( $instance['pib_url_of_img_widget'] );
165
- $pib_description_widget = strip_tags( $instance['pib_description_widget'] );
166
- $pib_button_type_widget = $instance['button_type'];
167
- ?>
168
-
169
- <p>
170
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title (optional)', 'pib' ); ?>:</label>
171
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
172
- </p>
173
- <p>
174
- <label for="<?php echo $this->get_field_id( 'count_layout' ); ?>"><?php _e( 'Pin Count:', 'pib' ); ?></label>
175
- <select name="<?php echo $this->get_field_name( 'count_layout' ); ?>" id="<?php echo $this->get_field_id( 'count_layout' ); ?>">
176
- <option value="none" <?php selected( $instance['count_layout'], 'none' ); ?>><?php _e( 'Not Shown', 'pib' ); ?></option>
177
- <option value="horizontal" <?php selected( $instance['count_layout'], 'horizontal' ); ?>><?php _e( 'Beside the Button', 'pib' ); ?></option>
178
- <option value="vertical" <?php selected( $instance['count_layout'], 'vertical' ); ?>><?php _e( 'Above the Button', 'pib' ); ?></option>
179
- </select>
180
- </p>
181
-
182
- <p>
183
- <label for="<?php echo $this->get_field_id( 'size' ); ?>"><?php _e( 'Size:', 'pib' ); ?></label>
184
- <select name="<?php echo $this->get_field_name( 'size' ); ?>" id="<?php echo $this->get_field_id( 'size' ); ?>">
185
- <option value="small" <?php selected( $instance['size'], 'small' ); ?>><?php _e( 'Small', 'pib' ); ?></option>
186
- <option value="large" <?php selected( $instance['size'], 'large' ); ?>><?php _e( 'Large', 'pib' ); ?></option>
187
- </select>
188
- </p>
189
-
190
- <p>
191
- <label for="<?php echo $this->get_field_id( 'shape' ); ?>"><?php _e( 'Shape:', 'pib' ); ?></label>
192
- <select name="<?php echo $this->get_field_name( 'shape' ); ?>" id="<?php echo $this->get_field_id( 'shape' ); ?>">
193
- <option value="rectangular" <?php selected( $instance['shape'], 'rectangular' ); ?>><?php _e( 'Rectangular', 'pib' ); ?></option>
194
- <option value="circular" <?php selected( $instance['shape'], 'circular' ); ?>><?php _e( 'Circular', 'pib' ); ?></option>
195
- </select>
196
- </p>
197
-
198
- <p>
199
- <label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color:', 'pib' ); ?></label>
200
- <select name="<?php echo $this->get_field_name( 'color' ); ?>" id="<?php echo $this->get_field_id( 'color' ); ?>">
201
- <option value="gray" <?php selected( $instance['color'], 'gray' ); ?>><?php _e( 'Gray', 'pib' ); ?></option>
202
- <option value="red" <?php selected( $instance['color'], 'red' ); ?>><?php _e( 'Red', 'pib' ); ?></option>
203
- <option value="white" <?php selected( $instance['color'], 'white' ); ?>><?php _e( 'White', 'pib' ); ?></option>
204
- </select>
205
- </p>
206
-
207
- <p>
208
- Button Type:
209
- </p>
210
- <p>
211
- <input class="pib-widget-toggle" type="radio" name="<?php echo $this->get_field_name( 'button_type' ); ?>" value="user_selects_image" id="<?php echo $this->get_field_id( 'user_selects_image' ); ?>" <?php checked( $pib_button_type_widget, 'user_selects_image' ); ?> />
212
- <label for="<?php echo $this->get_field_id( 'user_selects_image' ); ?>"><?php _e( 'User selects image from popup (any image)', 'pib' ); ?></label>
213
- </p>
214
- <p>
215
- <input class="pib-widget-toggle pib-widget-pre-selected" type="radio" name="<?php echo $this->get_field_name( 'button_type' ); ?>" value="image_selected" id="<?php echo $this->get_field_id( 'image_selected' ); ?>" <?php checked( $pib_button_type_widget, 'image_selected' ); ?> />
216
- <label for="<?php echo $this->get_field_id( 'image_selected' ); ?>"><?php _e( 'Image is pre-selected (one image -- defaults to first image in post)', 'pib' ); ?></label>
217
- </p>
218
-
219
- <p class="description">
220
- <?php _e( 'These 3 text fields will be used only if the button type is "image pre-selected".', 'pib' ); ?>
221
- </p>
222
-
223
- <div class="pib-widget-text-fields">
224
- <p>
225
- <label for="<?php echo $this->get_field_id( 'pib_url_of_webpage_widget' ); ?>"><?php _e( 'URL of the web page to be pinned', 'pib' ); ?>:</label>
226
- <input class="widefat" id="<?php echo $this->get_field_id( 'pib_url_of_webpage_widget' ); ?>" name="<?php echo $this->get_field_name( 'pib_url_of_webpage_widget' ); ?>"
227
- type="text" value="<?php echo esc_attr( $pib_url_of_webpage_widget ); ?>" />
228
- </p>
229
- <p>
230
- <label for="<?php echo $this->get_field_id( 'pib_url_of_img_widget' ); ?>"><?php _e( 'URL of the image to be pinned', 'pib' ); ?>:</label>
231
- <input class="widefat" id="<?php echo $this->get_field_id( 'pib_url_of_img_widget' ); ?>" name="<?php echo $this->get_field_name( 'pib_url_of_img_widget' ); ?>"
232
- type="text" value="<?php echo esc_attr( $pib_url_of_img_widget ); ?>" />
233
- </p>
234
- <p>
235
- <label for="<?php echo $this->get_field_id( 'pib_description_widget' ); ?>"><?php _e( 'Description of the pin (optional)', 'pib' ); ?>:</label>
236
- <input class="widefat" id="<?php echo $this->get_field_id( 'pib_description_widget' ); ?>" name="<?php echo $this->get_field_name( 'pib_description_widget' ); ?>"
237
- type="text" value="<?php echo esc_attr( $pib_description_widget ); ?>" />
238
- </p>
239
- </div>
240
-
241
- <p>
242
- <label for="<?php echo $this->get_field_id( 'align' ); ?>"><?php _e( 'Alignment', 'pib' ); ?>:</label>
243
- <select name="<?php echo $this->get_field_name( 'align' ); ?>" id="<?php echo $this->get_field_id( 'align' ); ?>">
244
- <option value="none" <?php selected( $instance['button_align'], 'none' ); ?>><?php _e( 'None', 'pib' ); ?></option>
245
- <option value="left" <?php selected( $instance['button_align'], 'left' ); ?>><?php _e( 'Left', 'pib' ); ?></option>
246
- <option value="right" <?php selected( $instance['button_align'], 'right' ); ?>><?php _e( 'Right', 'pib' ); ?></option>
247
- <option value="center" <?php selected( $instance['button_align'], 'center' ); ?>><?php _e( 'Center', 'pib' ); ?></option>
248
- </select>
249
- </p>
250
-
251
- <p>
252
- <input class="checkbox" <?php checked($instance['remove_div'], true) ?> id="<?php echo $this->get_field_id( 'remove_div' ); ?>"
253
- name="<?php echo $this->get_field_name( 'remove_div' ); ?>" type="checkbox"/>
254
- <label for="<?php echo $this->get_field_id( 'remove_div' ); ?>">
255
- <?php _e( 'Remove div tag surrounding this widget button. Also removes alignment setting.', 'pib' ); ?>
256
- </label>
257
- </p>
258
- <?php
259
- }
260
- }
261
- add_action( 'widgets_init', create_function( '', 'register_widget("PIB_Widget");' ) );
1
+ <?php
2
+
3
+ /**
4
+ * Represents the view for the widget component of the plugin.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Includes
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Class functions for the Pin It Button widgets
18
+ *
19
+ * @since 2.0.0
20
+ */
21
+ class PIB_Widget extends WP_Widget {
22
+
23
+ /**
24
+ * Initialize the widget
25
+ *
26
+ * @since 2.0.0
27
+ */
28
+ public function __construct() {
29
+ parent::__construct(
30
+ 'pib_button',
31
+ __( 'Pinterest "Pin It" Button', 'pib' ),
32
+ array(
33
+ 'classname' => 'pib-clearfix', // Wrap widget with "clear fix" CSS trick.
34
+ 'description' => __( 'Add a Pinterest "Pin It" button to any widget area.', 'pib' )
35
+ ),
36
+ // Widen widget admin area.
37
+ array( 'width' => 400 )
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Public facing widget code
43
+ *
44
+ * @since 2.0.0
45
+ */
46
+ public function widget( $args, $instance ) {
47
+ global $pib_options;
48
+ extract( $args );
49
+
50
+ $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
51
+
52
+ $pib_url_of_webpage_widget = $instance['pib_url_of_webpage_widget'];
53
+
54
+ //Set URL to home page if button style is "user selects image"
55
+ if ( empty( $pib_url_of_webpage_widget ) && ( $pib_options['button_type'] == 'user_selects_image' ) ) {
56
+ $pib_url_of_webpage_widget = get_home_url();
57
+ }
58
+
59
+ $pib_url_of_img_widget = $instance['pib_url_of_img_widget'];
60
+ $pib_description_widget = $instance['pib_description_widget'];
61
+ $count_layout = empty( $instance['count_layout'] ) ? 'none' : $instance['count_layout'];
62
+ $align = empty( $instance['button_align'] ) ? 'none' : $instance['button_align'];
63
+ $pib_remove_div = (bool) $instance['remove_div'];
64
+ $button_type = empty ( $instance['button_type'] ) ? 'user_selects_image' : $instance['button_type'];
65
+ $size = ( ! empty( $instance['size'] ) ? $instance['size'] : 'small' );
66
+ $color = ( ! empty( $instance['color'] ) ? $instance['color'] : 'gray' );
67
+ $shape = ( ! empty( $instance['shape'] ) ? $instance['shape'] : 'rectangular' );
68
+
69
+ // If the button type is set for users to select image then we need to overwrite any values from the widget that are used
70
+ // for displaying a a pre-selected image. These are not erased from the widget, but are just overwritten here.
71
+ if ( 'user_selects_image' == $button_type ) {
72
+ $pib_url_of_webpage_widget = '';
73
+ $pib_url_of_img_widget = '';
74
+ $pib_description_widget = '';
75
+ }
76
+
77
+ $base_btn = pib_button_base( $button_type, $pib_url_of_webpage_widget, $pib_url_of_img_widget, $pib_description_widget, $count_layout, $size, $color, $shape );
78
+
79
+ echo $before_widget;
80
+
81
+ if ( ! empty( $title ) ) {
82
+ echo $before_title . $title . $after_title;
83
+ }
84
+
85
+ if ( $pib_remove_div ) {
86
+ $html = $base_btn;
87
+ }
88
+ else {
89
+
90
+ $align_class = '';
91
+
92
+ if ( 'left' == $align ) {
93
+ $align_class = 'pib-align-left';
94
+ }
95
+ elseif ( 'right' == $align ) {
96
+ $align_class = 'pib-align-right';
97
+ }
98
+ elseif ( 'center' == $align ) {
99
+ $align_class = 'pib-align-center';
100
+ }
101
+
102
+ // Surround with div tag
103
+ $html = '<div class="pin-it-btn-wrapper-widget ' . $align_class . '">' . $base_btn . '</div>';
104
+ }
105
+
106
+ do_action( 'pib_widget_before' );
107
+
108
+ echo apply_filters( 'pib_widget_html', $html );
109
+
110
+ do_action( 'pib_widget_after' );
111
+
112
+ echo $after_widget;
113
+ }
114
+
115
+ /**
116
+ * Update the widget settings from user input
117
+ *
118
+ * @since 2.0.0
119
+ */
120
+ public function update( $new_instance, $old_instance ) {
121
+ $instance = $old_instance;
122
+
123
+ $instance['title'] = strip_tags($new_instance['title']);
124
+ $instance['pib_url_of_webpage_widget'] = strip_tags( $new_instance['pib_url_of_webpage_widget'] );
125
+ $instance['pib_url_of_img_widget'] = strip_tags( $new_instance['pib_url_of_img_widget'] );
126
+ $instance['pib_description_widget'] = strip_tags( $new_instance['pib_description_widget'] );
127
+ $instance['count_layout'] = $new_instance['count_layout'];
128
+ $instance['button_align'] = $new_instance['align'];
129
+ $instance['remove_div'] = ( $new_instance['remove_div'] ? 1 : 0 );
130
+ $instance['button_type'] = $new_instance['button_type'];
131
+ $instance['size'] = $new_instance['size'];
132
+ $instance['color'] = $new_instance['color'];
133
+ $instance['shape'] = $new_instance['shape'];
134
+
135
+ return $instance;
136
+ }
137
+
138
+ /**
139
+ * Display widget settings in admin
140
+ *
141
+ * @since 2.0.0
142
+ */
143
+ public function form( $instance ) {
144
+ global $pib_options;
145
+
146
+ $default = array(
147
+ 'title' => '',
148
+ 'count_layout' => 'none',
149
+ 'button_type' => 'user_selects_image',
150
+ 'pib_url_of_webpage_widget' => '',
151
+ 'pib_url_of_img_widget' => '',
152
+ 'pib_description_widget' => '',
153
+ 'button_align' => 'none',
154
+ 'remove_div' => 0,
155
+ 'size' => 'small',
156
+ 'color' => 'gray',
157
+ 'shape' => 'rectangular'
158
+ );
159
+
160
+ $instance = wp_parse_args( (array) $instance, $default );
161
+
162
+ $title = strip_tags($instance['title']);
163
+ $pib_url_of_webpage_widget = strip_tags( $instance['pib_url_of_webpage_widget'] );
164
+ $pib_url_of_img_widget = strip_tags( $instance['pib_url_of_img_widget'] );
165
+ $pib_description_widget = strip_tags( $instance['pib_description_widget'] );
166
+ $pib_button_type_widget = $instance['button_type'];
167
+ ?>
168
+
169
+ <p>
170
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title (optional)', 'pib' ); ?>:</label>
171
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
172
+ </p>
173
+ <p>
174
+ <label for="<?php echo $this->get_field_id( 'count_layout' ); ?>"><?php _e( 'Pin Count:', 'pib' ); ?></label>
175
+ <select name="<?php echo $this->get_field_name( 'count_layout' ); ?>" id="<?php echo $this->get_field_id( 'count_layout' ); ?>">
176
+ <option value="none" <?php selected( $instance['count_layout'], 'none' ); ?>><?php _e( 'Not Shown', 'pib' ); ?></option>
177
+ <option value="horizontal" <?php selected( $instance['count_layout'], 'horizontal' ); ?>><?php _e( 'Beside the Button', 'pib' ); ?></option>
178
+ <option value="vertical" <?php selected( $instance['count_layout'], 'vertical' ); ?>><?php _e( 'Above the Button', 'pib' ); ?></option>
179
+ </select>
180
+ </p>
181
+
182
+ <p>
183
+ <label for="<?php echo $this->get_field_id( 'size' ); ?>"><?php _e( 'Size:', 'pib' ); ?></label>
184
+ <select name="<?php echo $this->get_field_name( 'size' ); ?>" id="<?php echo $this->get_field_id( 'size' ); ?>">
185
+ <option value="small" <?php selected( $instance['size'], 'small' ); ?>><?php _e( 'Small', 'pib' ); ?></option>
186
+ <option value="large" <?php selected( $instance['size'], 'large' ); ?>><?php _e( 'Large', 'pib' ); ?></option>
187
+ </select>
188
+ </p>
189
+
190
+ <p>
191
+ <label for="<?php echo $this->get_field_id( 'shape' ); ?>"><?php _e( 'Shape:', 'pib' ); ?></label>
192
+ <select name="<?php echo $this->get_field_name( 'shape' ); ?>" id="<?php echo $this->get_field_id( 'shape' ); ?>">
193
+ <option value="rectangular" <?php selected( $instance['shape'], 'rectangular' ); ?>><?php _e( 'Rectangular', 'pib' ); ?></option>
194
+ <option value="circular" <?php selected( $instance['shape'], 'circular' ); ?>><?php _e( 'Circular', 'pib' ); ?></option>
195
+ </select>
196
+ </p>
197
+
198
+ <p>
199
+ <label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color:', 'pib' ); ?></label>
200
+ <select name="<?php echo $this->get_field_name( 'color' ); ?>" id="<?php echo $this->get_field_id( 'color' ); ?>">
201
+ <option value="gray" <?php selected( $instance['color'], 'gray' ); ?>><?php _e( 'Gray', 'pib' ); ?></option>
202
+ <option value="red" <?php selected( $instance['color'], 'red' ); ?>><?php _e( 'Red', 'pib' ); ?></option>
203
+ <option value="white" <?php selected( $instance['color'], 'white' ); ?>><?php _e( 'White', 'pib' ); ?></option>
204
+ </select>
205
+ </p>
206
+
207
+ <p>
208
+ Button Type:
209
+ </p>
210
+ <p>
211
+ <input class="pib-widget-toggle" type="radio" name="<?php echo $this->get_field_name( 'button_type' ); ?>" value="user_selects_image" id="<?php echo $this->get_field_id( 'user_selects_image' ); ?>" <?php checked( $pib_button_type_widget, 'user_selects_image' ); ?> />
212
+ <label for="<?php echo $this->get_field_id( 'user_selects_image' ); ?>"><?php _e( 'User selects image from popup (any image)', 'pib' ); ?></label>
213
+ </p>
214
+ <p>
215
+ <input class="pib-widget-toggle pib-widget-pre-selected" type="radio" name="<?php echo $this->get_field_name( 'button_type' ); ?>" value="image_selected" id="<?php echo $this->get_field_id( 'image_selected' ); ?>" <?php checked( $pib_button_type_widget, 'image_selected' ); ?> />
216
+ <label for="<?php echo $this->get_field_id( 'image_selected' ); ?>"><?php _e( 'Image is pre-selected (one image -- defaults to first image in post)', 'pib' ); ?></label>
217
+ </p>
218
+
219
+ <p class="description">
220
+ <?php _e( 'These 3 text fields will be used only if the button type is "image pre-selected".', 'pib' ); ?>
221
+ </p>
222
+
223
+ <div class="pib-widget-text-fields">
224
+ <p>
225
+ <label for="<?php echo $this->get_field_id( 'pib_url_of_webpage_widget' ); ?>"><?php _e( 'URL of the web page to be pinned', 'pib' ); ?>:</label>
226
+ <input class="widefat" id="<?php echo $this->get_field_id( 'pib_url_of_webpage_widget' ); ?>" name="<?php echo $this->get_field_name( 'pib_url_of_webpage_widget' ); ?>"
227
+ type="text" value="<?php echo esc_attr( $pib_url_of_webpage_widget ); ?>" />
228
+ </p>
229
+ <p>
230
+ <label for="<?php echo $this->get_field_id( 'pib_url_of_img_widget' ); ?>"><?php _e( 'URL of the image to be pinned', 'pib' ); ?>:</label>
231
+ <input class="widefat" id="<?php echo $this->get_field_id( 'pib_url_of_img_widget' ); ?>" name="<?php echo $this->get_field_name( 'pib_url_of_img_widget' ); ?>"
232
+ type="text" value="<?php echo esc_attr( $pib_url_of_img_widget ); ?>" />
233
+ </p>
234
+ <p>
235
+ <label for="<?php echo $this->get_field_id( 'pib_description_widget' ); ?>"><?php _e( 'Description of the pin (optional)', 'pib' ); ?>:</label>
236
+ <input class="widefat" id="<?php echo $this->get_field_id( 'pib_description_widget' ); ?>" name="<?php echo $this->get_field_name( 'pib_description_widget' ); ?>"
237
+ type="text" value="<?php echo esc_attr( $pib_description_widget ); ?>" />
238
+ </p>
239
+ </div>
240
+
241
+ <p>
242
+ <label for="<?php echo $this->get_field_id( 'align' ); ?>"><?php _e( 'Alignment', 'pib' ); ?>:</label>
243
+ <select name="<?php echo $this->get_field_name( 'align' ); ?>" id="<?php echo $this->get_field_id( 'align' ); ?>">
244
+ <option value="none" <?php selected( $instance['button_align'], 'none' ); ?>><?php _e( 'None', 'pib' ); ?></option>
245
+ <option value="left" <?php selected( $instance['button_align'], 'left' ); ?>><?php _e( 'Left', 'pib' ); ?></option>
246
+ <option value="right" <?php selected( $instance['button_align'], 'right' ); ?>><?php _e( 'Right', 'pib' ); ?></option>
247
+ <option value="center" <?php selected( $instance['button_align'], 'center' ); ?>><?php _e( 'Center', 'pib' ); ?></option>
248
+ </select>
249
+ </p>
250
+
251
+ <p>
252
+ <input class="checkbox" <?php checked($instance['remove_div'], true) ?> id="<?php echo $this->get_field_id( 'remove_div' ); ?>"
253
+ name="<?php echo $this->get_field_name( 'remove_div' ); ?>" type="checkbox"/>
254
+ <label for="<?php echo $this->get_field_id( 'remove_div' ); ?>">
255
+ <?php _e( 'Remove div tag surrounding this widget button. Also removes alignment setting.', 'pib' ); ?>
256
+ </label>
257
+ </p>
258
+ <?php
259
+ }
260
+ }
261
+ add_action( 'widgets_init', create_function( '', 'register_widget("PIB_Widget");' ) );
pinterest-pin-it-button.php CHANGED
@@ -1,47 +1,47 @@
1
- <?php
2
-
3
- /**
4
- * Pinterest "Pin It" Button Lite
5
- *
6
- * @package PIB
7
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
- * @license GPL-2.0+
9
- * @link http://pinplugins.com
10
- * @copyright 2011-2014 Phil Derksen
11
- *
12
- * @wordpress-plugin
13
- * Plugin Name: Pinterest "Pin It" Button Lite
14
- * Plugin URI: http://pinplugins.com/pin-it-button-pro/
15
- * Description: Add a Pinterest "Pin It" Button to your site and get your visitors to start pinning your awesome content!
16
- * Version: 2.0.6
17
- * Author: Phil Derksen
18
- * Author URI: http://philderksen.com
19
- * License: GPL-2.0+
20
- * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
21
- * GitHub Plugin URI: https://github.com/pderksen/WP-Pinterest-Pin-It-Button
22
- */
23
-
24
- // Exit if accessed directly.
25
- if ( ! defined( 'ABSPATH' ) ) {
26
- exit;
27
- }
28
-
29
- if ( ! defined( 'PIB_MAIN_FILE' ) ) {
30
- define( 'PIB_MAIN_FILE', __FILE__ );
31
- }
32
-
33
- // Run a check for Pro first since these 2 plugins cannot be installed at the same time to avoid issues and crashes
34
- if ( ! class_exists( 'Pinterest_Pin_It_Button_Pro' ) ) {
35
- if ( ! class_exists( 'Pinterest_Pin_It_Button' ) ) {
36
- require_once( plugin_dir_path( __FILE__ ) . 'class-pinterest-pin-it-button.php' );
37
- }
38
-
39
- // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
40
- register_activation_hook( __FILE__, array( 'Pinterest_Pin_It_Button', 'activate' ) );
41
-
42
- Pinterest_Pin_It_Button::get_instance();
43
-
44
- } else {
45
- echo "You already have Pinterest Pin It Button Pro installed. To downgrade please deactivate and delete the Pro plugin first.";
46
- die();
47
- }
1
+ <?php
2
+
3
+ /**
4
+ * Pinterest "Pin It" Button Lite
5
+ *
6
+ * @package PIB
7
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
+ * @license GPL-2.0+
9
+ * @link http://pinplugins.com
10
+ * @copyright 2011-2014 Phil Derksen
11
+ *
12
+ * @wordpress-plugin
13
+ * Plugin Name: Pinterest "Pin It" Button Lite
14
+ * Plugin URI: http://pinplugins.com/pin-it-button-pro/
15
+ * Description: Add a Pinterest "Pin It" Button to your site and get your visitors to start pinning your awesome content!
16
+ * Version: 2.0.7
17
+ * Author: Phil Derksen
18
+ * Author URI: http://philderksen.com
19
+ * License: GPL-2.0+
20
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
21
+ * GitHub Plugin URI: https://github.com/pderksen/WP-Pinterest-Pin-It-Button
22
+ */
23
+
24
+ // Exit if accessed directly.
25
+ if ( ! defined( 'ABSPATH' ) ) {
26
+ exit;
27
+ }
28
+
29
+ if ( ! defined( 'PIB_MAIN_FILE' ) ) {
30
+ define( 'PIB_MAIN_FILE', __FILE__ );
31
+ }
32
+
33
+ // Run a check for Pro first since these 2 plugins cannot be installed at the same time to avoid issues and crashes
34
+ if ( ! class_exists( 'Pinterest_Pin_It_Button_Pro' ) ) {
35
+ if ( ! class_exists( 'Pinterest_Pin_It_Button' ) ) {
36
+ require_once( plugin_dir_path( __FILE__ ) . 'class-pinterest-pin-it-button.php' );
37
+ }
38
+
39
+ // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
40
+ register_activation_hook( __FILE__, array( 'Pinterest_Pin_It_Button', 'activate' ) );
41
+
42
+ Pinterest_Pin_It_Button::get_instance();
43
+
44
+ } else {
45
+ echo "You already have Pinterest Pin It Button Pro installed. To downgrade please deactivate and delete the Pro plugin first.";
46
+ die();
47
+ }
readme.txt CHANGED
@@ -1,278 +1,283 @@
1
- === Pinterest "Pin It" Button ===
2
- Contributors: pderksen, nickyoung87
3
- Tags: pinterest, pin it button, social, social media, image, images, photo, photos, pinterest pin it button, pin it, social button
4
- Requires at least: 3.6.1
5
- Tested up to: 3.9
6
- Stable tag: trunk
7
- License: GPLv2 or later
8
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
-
10
- Add a Pinterest "Pin It" Button to your site and get your visitors to start pinning your awesome content!
11
-
12
- == Description ==
13
-
14
- Add a simple Pinterest "Pin It" Button to your posts in 2 minutes!
15
-
16
- No need to copy and paste code throughout your WordPress site.
17
-
18
- ###"Pin It" Button Lite Features###
19
-
20
- * Let the reader select an image when pinning.
21
- * Pre-select an image for the reader to pin.
22
- * Default to the first image in the post.
23
- * Specify a specific image to pin per post.
24
- * Pick from official "Pin It" button colors and sizes.
25
- * Hide the "Pin It" button on specific posts and pages.
26
- * Add a "Pin It" button to your sidebar or footer as a widget.
27
- * Place "Pin It" buttons anywhere using shortcodes.
28
-
29
- ###Pro Version Features###
30
-
31
- * Add "Pin It" buttons on image hover (in any corner).
32
- * Add a "Pin It" button under each image.
33
- * Pick from 30 custom "Pin It" button designs.
34
- * Upload your own custom "Pin It" buttons.
35
- * Twitter, Facebook, Google+ & LinkedIn sharing buttons included.
36
- * Option to pin featured images.
37
- * Show or hide on custom post types.
38
- * WooCommerce compatibility.
39
- * Customer support and automatic updates.
40
-
41
- [Start Getting Pinned Like Crazy with "Pin It" Button Pro!](http://pinplugins.com/pin-it-button-pro/?utm_source=wordpress_org&utm_medium=link&utm_campaign=pin_it_button_lite)
42
-
43
- ###A Few Stats on Pinterest###
44
-
45
- * Pinterest has [70 million users](http://thenextweb.com/socialmedia/2013/07/10/semiocast-pinterest-now-has-70-million-users-and-is-steadily-gaining-momentum-outside-the-us/)
46
- * There are over [½ million verified business accounts on Pinterest](http://searchenginewatch.com/article/2282835/Pinterest-Tops-70-Million-Users-30-Pinned-Repinned-or-Liked-in-June-Study)
47
- * Pinterest has over [2.5 billion average monthly pageviews](http://readwrite.com/2013/05/09/why-pinterest-could-be-worth-far-more-than-25-billion)
48
- * Pinterest users spend an average of [98 minutes per month on Pinterest](http://rismedia.com/2013-05-23/pinterest-should-it-be-a-part-of-your-marketing-plan/)
49
- * The average amount per order that derives from Pinterest traffic is between [$140 and $180](http://www.richrelevance.com/blog/2013/04/direct-marketing-news-infographic-the-rising-king-of-social-sales/)
50
- * Pinterest Drives More Traffic to Publishers Than [Twitter, LinkedIn, Reddit Combined](http://mashable.com/2013/10/15/pinterest-referral-traffic/)
51
-
52
- ###Raves on the Interwebs###
53
-
54
- * "If you want complete (and easy) control over your Pin It button, you should definitely take a look..." -- [The Next Web](http://thenextweb.com/socialmedia/2012/03/04/20-awesome-tools-which-will-have-you-pinteresting-like-a-pro/)
55
- * "The Pinterest 'Pin It' Button is a painless solution for bloggers just getting started with this social network." -- [WP Jedi](http://www.wpjedi.com/pinterest-pin-it-button-for-wordpress/)
56
- * "This is the plugin that I found works best on my marketing blog for photographers." -- [ProBlogger](http://www.problogger.net/archives/2013/03/05/heavyweight-help-the-complete-guide-to-getting-started-on-pinterest/)
57
- * "If you want to make it easy for Pinterest users to pin your articles, consider using this 'Pin It' button plugin." -- [WP Tavern](http://www.wptavern.com/pin-it-is-the-new-bookmark)
58
- * "Discovery of the Week" -- [Social Media Examiner](http://www.socialmediaexaminer.com/pinterest-marketing-what-marketers-need-to-know-to-succeed/)
59
- * "If you're looking for something simple and obtrusive, the Pinterest 'Pin It' Button will suit you." -- [WPMU.org](http://wpmu.org/pinterest-plugins-wordpress/)
60
-
61
- [See a "Pin It" Button Pro Demo](http://bruisesandbandaids.com/2011/newborn-photography-props/) (shows off the share bar and image hover features)
62
-
63
- [Setup an Eye-Catching Button in Minutes with "Pin It" Button Pro!](http://pinplugins.com/pin-it-button-pro/?utm_source=wordpress_org&utm_medium=link&utm_campaign=pin_it_button_lite)
64
-
65
- This plugin (as well as the Pro version) is in full compliance with the [official "Pin It" button developer guidelines](http://developers.pinterest.com/pin_it/).
66
-
67
- This plugin utilizes the code output from the [official "Pin It" button widget builder](http://business.pinterest.com/widget-builder/#do_pin_it_button).
68
-
69
- [Follow this project on Github](https://github.com/pderksen/WP-Pinterest-Pin-It-Button).
70
-
71
- == Installation ==
72
-
73
- You can install this plugin one of three ways:
74
-
75
- = 1. Admin Search =
76
- 1. In your Admin, go to menu Plugins > Add.
77
- 1. Search for `Pin It Button`.
78
- 1. Find the plugin that's labeled `Pinterest "Pin It" Button` with "Pin It" in quotes.
79
- 1. Look for the author name `Phil Derksen` on the plugin.
80
- 1. Click to install.
81
- 1. Activate the plugin.
82
- 1. A new menu item `Pin It Button` will appear in your Admin.
83
-
84
- = 2. Download & Upload =
85
- 1. Download the plugin (a zip file) on the right column of this page.
86
- 1. In your Admin, go to menu Plugins > Add.
87
- 1. Select the tab "Upload".
88
- 1. Upload the .zip file you just downloaded.
89
- 1. Activate the plugin.
90
- 1. A new menu item `Pin It Button` will appear in your Admin.
91
-
92
- = 3. FTP Upload =
93
- 1. Download the plugin (.zip file) on the right column of this page.
94
- 1. Unzip the zip file contents.
95
- 1. Upload the `pinterest-pin-it-button` folder to the `/wp-content/plugins/` directory of your site.
96
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
97
- 1. A new menu item `Pin It Button` will appear in your Admin.
98
-
99
- == Frequently Asked Questions ==
100
-
101
- = General Troubleshooting =
102
-
103
- If the "Pin It" button doesn't get triggered on click (and your browser is redirected to a pinterest.com URL), please make sure that there is not extra code that is hijacking the click event (for example, a Google Analytics onclick event).
104
-
105
- A popular known plugin that does this is **Google Analytics for WordPress**. Try unchecking one or both of these options: 1) Track outbound clicks & downloads, 2) Check Advanced Settings, then make sure "Track outbound clicks as pageviews" is un-checked.
106
-
107
- Your theme must implement **wp_footer()** in the footer.php file, otherwise JavaScript will not load correctly. You can test if this is the issue by switching to a WordPress stock theme such as twenty-twelve temporarily.
108
-
109
- [Visit the complete knowledgebase](http://pinplugins.com/pin-it-button-faq?utm_source=wordpress_org&utm_medium=link&utm_campaign=pin_it_button_lite) for additional help and troubleshooting tips.
110
-
111
- CSS styling and shortcode help available within the plugin admin.
112
-
113
- == Screenshots ==
114
-
115
- 1. Button display with count bubble beside
116
- 2. Button display with count bubble above
117
- 3. General button settings
118
- 4. Post visibility and placement settings
119
- 5. Style/CSS settings
120
- 6. Widget settings
121
- 7. Individual post (post meta) settings
122
-
123
- == Changelog ==
124
-
125
- = 2.0.6 =
126
-
127
- * More fixes to special characters rendering HTML codes incorrectly in pin descriptions.
128
-
129
- = 2.0.5 =
130
-
131
- * Fixed a bug with shortcode buttons not enqueueing CSS & JS correctly.
132
- * Fixed a bug with some characters (such as single quotes) rendering HTML codes in the pin description.
133
-
134
- = 2.0.4 =
135
-
136
- * Various performance enhancements.
137
-
138
- = 2.0.3 =
139
-
140
- * Added action and filter hooks for extensibility.
141
- * Fixed a bug with upgrade code being called multiple times.
142
- * Removed PressTrends integration.
143
- * Tested up to WordPress 3.9.
144
-
145
- = 2.0.2 =
146
-
147
- * Added options for colors, sizes and shapes based on Pinterest's official widget builder.
148
- * Added an option to show count bubble even for zero count pins.
149
- * Minor bug fixes.
150
- * Tested up to WordPress 3.8.
151
-
152
- = 2.0.1 =
153
-
154
- * Added an option to disable Pinterest's pinit.js JavaScript to avoid conflicts with other Pinterest plugins, themes and custom code (on new "Advanced" tab).
155
- * Tested up to WordPress 3.7.
156
-
157
- = 2.0.0 =
158
-
159
- * Tested up to WordPress 3.6.1.
160
- * Now in full compliance with current "Pin It" button developer guidelines at <http://developers.pinterest.com/pin_it/>.
161
- * More extensive Help section, which was moved to a separate submenu item.
162
- * Updated CSS & JS output so they're much more "light weight" which should improve performance.
163
- * Removed all references to "!important" in the public CSS to allow for more control of styles.
164
- * Implemented more standards from the WordPress Settings API. Settings pages should be more maintainable going forward.
165
- * Settings pages now using tabs to break up functionality.
166
- * Can now specify button type for shortcode and widget. No longer inherits from main settings.
167
- * Fixed so button now shows up on category pages.
168
- * Added is_main_query() check for "the_content" filter.
169
- * Removed show/hide button options on category edit screen (conflicted with post/page visibility changes).
170
- * Optional Presstrends anonymous usage tracking.
171
-
172
- = 1.4.3 =
173
-
174
- * Fixed bug where Create Pin popup wasn't working in some cases.
175
-
176
- = 1.4.2 =
177
-
178
- * Tested with WordPress 3.5.
179
- * Added: Option to save settings upon plugin uninstall.
180
- * Changed: Removed "Always show pin count" option as it's no longer supported by Pinterest.
181
- * Changed: Iframe option removed as it's no longer supported by Pinterest.
182
- * Changed: Moved some JavaScript files to load in the footer rather than the header to improve page speed load and compatibility with Pinterest code. Theme must implement wp_footer() to function properly.
183
- * Fixed: Count="vertical" shortcode fixed.
184
- * Fixed: Updated button CSS/styles to improve compatibility with more themes.
185
- * Fixed: Checks theme support for post thumbnails and adds if needed.
186
- * Fixed: Various minor bug fixes.
187
-
188
- = 1.4.1 =
189
-
190
- * Fixed: Various shortcode fixes.
191
- * Fixed: Moved some JavaScript files that were loaded in the footer to now load in the header to improve compatibility with themes not implementing wp_footer().
192
- * Fixed: Updated button CSS/styles to improve compatibility with more themes.
193
-
194
- = 1.4.0 =
195
-
196
- * Changed/Fixed: Iframe removed when button set to "User selects image". Fixes security issues and display errors on some web hosts.
197
- * Added: Displays new features available if upgrading "Pin It" Button Pro
198
-
199
- = 1.3.1 =
200
-
201
- * Changed: Modified button JavaScript to be in line with Pinterest's current button embed JavaScript
202
- * Changed: Split up internal code files for easier maintenance and updates
203
- * Fixed: Shortcode -- If the attributes "url", "image_url" and/or "description" aren't specified, it will try and use the post's custom page url, image url and/or description if found. If not found it will default to the post's url, first image in post and post title.
204
- * Fixed: Changed the way defaults are set upon install so it shouldn't override previous settings
205
- * Fixed: Uninstall now removes custom post meta fields
206
-
207
- = 1.3.0 =
208
-
209
- * Added: Added a Pin Count option (horizontal or vertical)
210
- * Added: Added new button style where image is pre-selected (like official Pinterest button)
211
- * Added: Added fields for specifying URL, image URL and description for new button style **image pre-selected**
212
- * Added: Added float option for alignment (none, left or right) to widget and shortcode
213
- * Added: Shortcode -- Can now remove div tag wrapper
214
- * Added: Widget -- Can now remove div tag wrapper
215
- * Changed: Moved "Follow" button widget to separate plugin: [Pinterest "Follow" Button](http://wordpress.org/extend/plugins/pinterest-follow-button/)
216
- * Changed: Both button styles now embed iframe (like official Pinterest button)
217
- * Changed: External JavaScript now loads in footer for better performance
218
- * Fixed: Fixed bug where front page was still showing button even when Front Page was unchecked
219
- * Fixed: Fixed bug where some settings weren't saved when upgrading the plugin
220
- * Fixed: Fixed bug where tag, author, date and search archive pages were not displaying the button
221
-
222
- = 1.2.1 =
223
-
224
- * Fixed: Fixed bug with hiding posts/pages/categories when upgrading from a previous version
225
-
226
- = 1.2.0 =
227
-
228
- * Added: Added option to hide button per page/post
229
- * Added: Added option to hide button per category
230
- * Added: Added widget to display "Pin It" button
231
- * Added: Added widget to display "Follow" on Pinterest button
232
- * Fixed: Fixed CSS where some blogs weren't displaying the button properly
233
-
234
- = 1.1.3 =
235
-
236
- * Added: Added option to hide button on individual posts and pages (on post/page editing screen)
237
-
238
- = 1.1.2 =
239
-
240
- * Fixed: Removed use of session state storing for now as it caused errors for some
241
-
242
- = 1.1.1 =
243
-
244
- * Fixed: Updated jQuery coding method to avoid JavaScript conflicts with other plugins and themes some were getting
245
-
246
- = 1.1.0 =
247
-
248
- * Added: Added custom CSS area for advanced layout and styling
249
- * Added: Added checkbox option to remove the button's surrounding `<div>` tag
250
- * Added: Button image and style updated to match Pinterest's current embed code
251
- * Fixed: Changed the way the button click is called to solve pinning issues in Internet Explorer
252
-
253
- = 1.0.2 =
254
-
255
- * Added: Added checkbox option to display/hide button on post excerpts
256
- * Fixed: "Pin It" links generated by the shortcode should not show up when viewing the post in RSS readers
257
-
258
- = 1.0.1 =
259
-
260
- * Added: Added checkbox option to display/hide button on "front page" (sometimes different than home page)
261
-
262
- = 1.0.0 =
263
-
264
- * Added: Added checkbox options to select what types of pages the button should appear on
265
- * Added: Display options above and below content are now checkboxes (one or both can be selected)
266
- * Added: Added shortcode [pinit] to display button within content
267
-
268
- = 0.1.2 =
269
-
270
- * Changed: Moved javascript that fires on button click to a separate file
271
-
272
- = 0.1.1 =
273
-
274
- * Fixed style sheet reference
275
-
276
- = 0.1.0 =
277
-
278
- * Initial release
 
 
 
 
 
1
+ === Pinterest "Pin It" Button ===
2
+ Contributors: pderksen, nickyoung87
3
+ Tags: pinterest, pin it button, social, social media, image, images, photo, photos, pinterest pin it button, pin it, social button
4
+ Requires at least: 3.7.4
5
+ Tested up to: 4.0
6
+ Stable tag: trunk
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Add a Pinterest "Pin It" Button to your site and get your visitors to start pinning your awesome content!
11
+
12
+ == Description ==
13
+
14
+ Add a simple Pinterest "Pin It" Button to your posts in 2 minutes!
15
+
16
+ No need to copy and paste code throughout your WordPress site.
17
+
18
+ ###"Pin It" Button Lite Features###
19
+
20
+ * Let the reader select an image when pinning.
21
+ * Pre-select an image for the reader to pin.
22
+ * Default to the first image in the post.
23
+ * Specify a specific image to pin per post.
24
+ * Pick from official "Pin It" button colors and sizes.
25
+ * Hide the "Pin It" button on specific posts and pages.
26
+ * Add a "Pin It" button to your sidebar or footer as a widget.
27
+ * Place "Pin It" buttons anywhere using shortcodes.
28
+
29
+ ###Pro Version Features###
30
+
31
+ * Add "Pin It" buttons on image hover (in any corner).
32
+ * Add a "Pin It" button under each image.
33
+ * Pick from 30 custom "Pin It" button designs.
34
+ * Upload your own custom "Pin It" buttons.
35
+ * Twitter, Facebook, Google+ & LinkedIn sharing buttons included.
36
+ * Option to pin featured images.
37
+ * Show or hide on custom post types.
38
+ * WooCommerce compatibility.
39
+ * Customer support and automatic updates.
40
+
41
+ [Start Getting Pinned Like Crazy with "Pin It" Button Pro!](http://pinplugins.com/pin-it-button-pro/?utm_source=wordpress_org&utm_medium=link&utm_campaign=pin_it_button_lite)
42
+
43
+ ###A Few Stats on Pinterest###
44
+
45
+ * Pinterest has [70 million users](http://thenextweb.com/socialmedia/2013/07/10/semiocast-pinterest-now-has-70-million-users-and-is-steadily-gaining-momentum-outside-the-us/)
46
+ * There are over [½ million verified business accounts on Pinterest](http://searchenginewatch.com/article/2282835/Pinterest-Tops-70-Million-Users-30-Pinned-Repinned-or-Liked-in-June-Study)
47
+ * Pinterest has over [2.5 billion average monthly pageviews](http://readwrite.com/2013/05/09/why-pinterest-could-be-worth-far-more-than-25-billion)
48
+ * Pinterest users spend an average of [98 minutes per month on Pinterest](http://rismedia.com/2013-05-23/pinterest-should-it-be-a-part-of-your-marketing-plan/)
49
+ * The average amount per order that derives from Pinterest traffic is between [$140 and $180](http://www.richrelevance.com/blog/2013/04/direct-marketing-news-infographic-the-rising-king-of-social-sales/)
50
+ * Pinterest Drives More Traffic to Publishers Than [Twitter, LinkedIn, Reddit Combined](http://mashable.com/2013/10/15/pinterest-referral-traffic/)
51
+
52
+ ###Raves on the Interwebs###
53
+
54
+ * "If you want complete (and easy) control over your Pin It button, you should definitely take a look..." -- [The Next Web](http://thenextweb.com/socialmedia/2012/03/04/20-awesome-tools-which-will-have-you-pinteresting-like-a-pro/)
55
+ * "The Pinterest 'Pin It' Button is a painless solution for bloggers just getting started with this social network." -- [WP Jedi](http://www.wpjedi.com/pinterest-pin-it-button-for-wordpress/)
56
+ * "This is the plugin that I found works best on my marketing blog for photographers." -- [ProBlogger](http://www.problogger.net/archives/2013/03/05/heavyweight-help-the-complete-guide-to-getting-started-on-pinterest/)
57
+ * "If you want to make it easy for Pinterest users to pin your articles, consider using this 'Pin It' button plugin." -- [WP Tavern](http://www.wptavern.com/pin-it-is-the-new-bookmark)
58
+ * "Discovery of the Week" -- [Social Media Examiner](http://www.socialmediaexaminer.com/pinterest-marketing-what-marketers-need-to-know-to-succeed/)
59
+ * "If you're looking for something simple and obtrusive, the Pinterest 'Pin It' Button will suit you." -- [WPMU.org](http://wpmu.org/pinterest-plugins-wordpress/)
60
+
61
+ [See a "Pin It" Button Pro Demo](http://bruisesandbandaids.com/2011/newborn-photography-props/) (shows off the share bar and image hover features)
62
+
63
+ [Setup an Eye-Catching Button in Minutes with "Pin It" Button Pro!](http://pinplugins.com/pin-it-button-pro/?utm_source=wordpress_org&utm_medium=link&utm_campaign=pin_it_button_lite)
64
+
65
+ This plugin (as well as the Pro version) is in full compliance with the [official "Pin It" button developer guidelines](http://developers.pinterest.com/pin_it/).
66
+
67
+ This plugin utilizes the code output from the [official "Pin It" button widget builder](http://business.pinterest.com/widget-builder/#do_pin_it_button).
68
+
69
+ [Follow this project on Github](https://github.com/pderksen/WP-Pinterest-Pin-It-Button).
70
+
71
+ == Installation ==
72
+
73
+ You can install this plugin one of three ways:
74
+
75
+ = 1. Admin Search =
76
+ 1. In your Admin, go to menu Plugins > Add.
77
+ 1. Search for `Pin It Button`.
78
+ 1. Find the plugin that's labeled `Pinterest "Pin It" Button` with "Pin It" in quotes.
79
+ 1. Look for the author name `Phil Derksen` on the plugin.
80
+ 1. Click to install.
81
+ 1. Activate the plugin.
82
+ 1. A new menu item `Pin It Button` will appear in your Admin.
83
+
84
+ = 2. Download & Upload =
85
+ 1. Download the plugin (a zip file) on the right column of this page.
86
+ 1. In your Admin, go to menu Plugins > Add.
87
+ 1. Select the tab "Upload".
88
+ 1. Upload the .zip file you just downloaded.
89
+ 1. Activate the plugin.
90
+ 1. A new menu item `Pin It Button` will appear in your Admin.
91
+
92
+ = 3. FTP Upload =
93
+ 1. Download the plugin (.zip file) on the right column of this page.
94
+ 1. Unzip the zip file contents.
95
+ 1. Upload the `pinterest-pin-it-button` folder to the `/wp-content/plugins/` directory of your site.
96
+ 1. Activate the plugin through the 'Plugins' menu in WordPress.
97
+ 1. A new menu item `Pin It Button` will appear in your Admin.
98
+
99
+ == Frequently Asked Questions ==
100
+
101
+ = General Troubleshooting =
102
+
103
+ If the "Pin It" button doesn't get triggered on click (and your browser is redirected to a pinterest.com URL), please make sure that there is not extra code that is hijacking the click event (for example, a Google Analytics onclick event).
104
+
105
+ A popular known plugin that does this is **Google Analytics for WordPress**. Try unchecking one or both of these options: 1) Track outbound clicks & downloads, 2) Check Advanced Settings, then make sure "Track outbound clicks as pageviews" is un-checked.
106
+
107
+ Your theme must implement **wp_footer()** in the footer.php file, otherwise JavaScript will not load correctly. You can test if this is the issue by switching to a WordPress stock theme such as twenty-twelve temporarily.
108
+
109
+ [Visit the complete knowledgebase](http://pinplugins.com/pin-it-button-faq?utm_source=wordpress_org&utm_medium=link&utm_campaign=pin_it_button_lite) for additional help and troubleshooting tips.
110
+
111
+ CSS styling and shortcode help available within the plugin admin.
112
+
113
+ == Screenshots ==
114
+
115
+ 1. Button display with count bubble beside
116
+ 2. Button display with count bubble above
117
+ 3. General button settings
118
+ 4. Post visibility and placement settings
119
+ 5. Style/CSS settings
120
+ 6. Widget settings
121
+ 7. Individual post (post meta) settings
122
+
123
+ == Changelog ==
124
+
125
+ = 2.0.7 =
126
+
127
+ * Tested with WordPress 4.0.
128
+ * Button will now pin full size image instead of thumbnail.
129
+
130
+ = 2.0.6 =
131
+
132
+ * More fixes to special characters rendering HTML codes incorrectly in pin descriptions.
133
+
134
+ = 2.0.5 =
135
+
136
+ * Fixed a bug with shortcode buttons not enqueueing CSS & JS correctly.
137
+ * Fixed a bug with some characters (such as single quotes) rendering HTML codes in the pin description.
138
+
139
+ = 2.0.4 =
140
+
141
+ * Various performance enhancements.
142
+
143
+ = 2.0.3 =
144
+
145
+ * Added action and filter hooks for extensibility.
146
+ * Fixed a bug with upgrade code being called multiple times.
147
+ * Removed PressTrends integration.
148
+ * Tested up to WordPress 3.9.
149
+
150
+ = 2.0.2 =
151
+
152
+ * Added options for colors, sizes and shapes based on Pinterest's official widget builder.
153
+ * Added an option to show count bubble even for zero count pins.
154
+ * Minor bug fixes.
155
+ * Tested up to WordPress 3.8.
156
+
157
+ = 2.0.1 =
158
+
159
+ * Added an option to disable Pinterest's pinit.js JavaScript to avoid conflicts with other Pinterest plugins, themes and custom code (on new "Advanced" tab).
160
+ * Tested up to WordPress 3.7.
161
+
162
+ = 2.0.0 =
163
+
164
+ * Tested up to WordPress 3.6.1.
165
+ * Now in full compliance with current "Pin It" button developer guidelines at <http://developers.pinterest.com/pin_it/>.
166
+ * More extensive Help section, which was moved to a separate submenu item.
167
+ * Updated CSS & JS output so they're much more "light weight" which should improve performance.
168
+ * Removed all references to "!important" in the public CSS to allow for more control of styles.
169
+ * Implemented more standards from the WordPress Settings API. Settings pages should be more maintainable going forward.
170
+ * Settings pages now using tabs to break up functionality.
171
+ * Can now specify button type for shortcode and widget. No longer inherits from main settings.
172
+ * Fixed so button now shows up on category pages.
173
+ * Added is_main_query() check for "the_content" filter.
174
+ * Removed show/hide button options on category edit screen (conflicted with post/page visibility changes).
175
+ * Optional Presstrends anonymous usage tracking.
176
+
177
+ = 1.4.3 =
178
+
179
+ * Fixed bug where Create Pin popup wasn't working in some cases.
180
+
181
+ = 1.4.2 =
182
+
183
+ * Tested with WordPress 3.5.
184
+ * Added: Option to save settings upon plugin uninstall.
185
+ * Changed: Removed "Always show pin count" option as it's no longer supported by Pinterest.
186
+ * Changed: Iframe option removed as it's no longer supported by Pinterest.
187
+ * Changed: Moved some JavaScript files to load in the footer rather than the header to improve page speed load and compatibility with Pinterest code. Theme must implement wp_footer() to function properly.
188
+ * Fixed: Count="vertical" shortcode fixed.
189
+ * Fixed: Updated button CSS/styles to improve compatibility with more themes.
190
+ * Fixed: Checks theme support for post thumbnails and adds if needed.
191
+ * Fixed: Various minor bug fixes.
192
+
193
+ = 1.4.1 =
194
+
195
+ * Fixed: Various shortcode fixes.
196
+ * Fixed: Moved some JavaScript files that were loaded in the footer to now load in the header to improve compatibility with themes not implementing wp_footer().
197
+ * Fixed: Updated button CSS/styles to improve compatibility with more themes.
198
+
199
+ = 1.4.0 =
200
+
201
+ * Changed/Fixed: Iframe removed when button set to "User selects image". Fixes security issues and display errors on some web hosts.
202
+ * Added: Displays new features available if upgrading "Pin It" Button Pro
203
+
204
+ = 1.3.1 =
205
+
206
+ * Changed: Modified button JavaScript to be in line with Pinterest's current button embed JavaScript
207
+ * Changed: Split up internal code files for easier maintenance and updates
208
+ * Fixed: Shortcode -- If the attributes "url", "image_url" and/or "description" aren't specified, it will try and use the post's custom page url, image url and/or description if found. If not found it will default to the post's url, first image in post and post title.
209
+ * Fixed: Changed the way defaults are set upon install so it shouldn't override previous settings
210
+ * Fixed: Uninstall now removes custom post meta fields
211
+
212
+ = 1.3.0 =
213
+
214
+ * Added: Added a Pin Count option (horizontal or vertical)
215
+ * Added: Added new button style where image is pre-selected (like official Pinterest button)
216
+ * Added: Added fields for specifying URL, image URL and description for new button style **image pre-selected**
217
+ * Added: Added float option for alignment (none, left or right) to widget and shortcode
218
+ * Added: Shortcode -- Can now remove div tag wrapper
219
+ * Added: Widget -- Can now remove div tag wrapper
220
+ * Changed: Moved "Follow" button widget to separate plugin: [Pinterest "Follow" Button](http://wordpress.org/extend/plugins/pinterest-follow-button/)
221
+ * Changed: Both button styles now embed iframe (like official Pinterest button)
222
+ * Changed: External JavaScript now loads in footer for better performance
223
+ * Fixed: Fixed bug where front page was still showing button even when Front Page was unchecked
224
+ * Fixed: Fixed bug where some settings weren't saved when upgrading the plugin
225
+ * Fixed: Fixed bug where tag, author, date and search archive pages were not displaying the button
226
+
227
+ = 1.2.1 =
228
+
229
+ * Fixed: Fixed bug with hiding posts/pages/categories when upgrading from a previous version
230
+
231
+ = 1.2.0 =
232
+
233
+ * Added: Added option to hide button per page/post
234
+ * Added: Added option to hide button per category
235
+ * Added: Added widget to display "Pin It" button
236
+ * Added: Added widget to display "Follow" on Pinterest button
237
+ * Fixed: Fixed CSS where some blogs weren't displaying the button properly
238
+
239
+ = 1.1.3 =
240
+
241
+ * Added: Added option to hide button on individual posts and pages (on post/page editing screen)
242
+
243
+ = 1.1.2 =
244
+
245
+ * Fixed: Removed use of session state storing for now as it caused errors for some
246
+
247
+ = 1.1.1 =
248
+
249
+ * Fixed: Updated jQuery coding method to avoid JavaScript conflicts with other plugins and themes some were getting
250
+
251
+ = 1.1.0 =
252
+
253
+ * Added: Added custom CSS area for advanced layout and styling
254
+ * Added: Added checkbox option to remove the button's surrounding `<div>` tag
255
+ * Added: Button image and style updated to match Pinterest's current embed code
256
+ * Fixed: Changed the way the button click is called to solve pinning issues in Internet Explorer
257
+
258
+ = 1.0.2 =
259
+
260
+ * Added: Added checkbox option to display/hide button on post excerpts
261
+ * Fixed: "Pin It" links generated by the shortcode should not show up when viewing the post in RSS readers
262
+
263
+ = 1.0.1 =
264
+
265
+ * Added: Added checkbox option to display/hide button on "front page" (sometimes different than home page)
266
+
267
+ = 1.0.0 =
268
+
269
+ * Added: Added checkbox options to select what types of pages the button should appear on
270
+ * Added: Display options above and below content are now checkboxes (one or both can be selected)
271
+ * Added: Added shortcode [pinit] to display button within content
272
+
273
+ = 0.1.2 =
274
+
275
+ * Changed: Moved javascript that fires on button click to a separate file
276
+
277
+ = 0.1.1 =
278
+
279
+ * Fixed style sheet reference
280
+
281
+ = 0.1.0 =
282
+
283
+ * Initial release
uninstall.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
-
3
- /**
4
- * Fired when the plugin is uninstalled.
5
- *
6
- * @package PIB
7
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
- */
9
-
10
- // If uninstall not called from WordPress, then exit.
11
- if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) )
12
- exit;
13
-
14
- // Legacy category option not used anymore. Delete either way.
15
- delete_option( 'pib_category_fields_option' );
16
-
17
- $general = get_option( 'pib_settings_general' );
18
-
19
- // If the the option to save settings is checked then do nothing, otherwise delete all options and post meta
20
- if ( ! empty( $general['uninstall_save_settings'] ) ) {
21
- // Do nothing
22
- } else {
23
-
24
- // Lite
25
- // Delete options
26
- delete_option( 'pib_settings_general' );
27
- delete_option( 'pib_settings_post_visibility' );
28
- delete_option( 'pib_settings_styles' );
29
- delete_option( 'pib_settings_misc' );
30
- delete_option( 'pib_upgrade_has_run' );
31
- delete_option( 'pib_version' );
32
- delete_option( 'pib_show_admin_install_notice' );
33
- delete_option( 'pib_settings_advanced' );
34
-
35
- // Delete widget options
36
- delete_option( 'widget_pib_button' );
37
-
38
- // Delete post meta
39
- delete_post_meta_by_key( 'pib_sharing_disabled' );
40
- delete_post_meta_by_key( 'pib_url_of_webpage' );
41
- delete_post_meta_by_key( 'pib_url_of_img' );
42
- delete_post_meta_by_key( 'pib_description' );
43
-
44
- // Pro
45
- // Delete ALL Pro settings and keys
46
- delete_option( 'pib_settings_image_hover' );
47
- delete_option( 'pib_settings_image_misc' );
48
- delete_option( 'pib_settings_share_bar' );
49
- delete_option( 'pib_settings_support' );
50
- delete_option( 'pib_sharebar_buttons' );
51
-
52
-
53
- // Pro Misc options
54
- delete_option( 'pib_edd_sl_license_active' );
55
- delete_option( 'pib_lite_deactivation_notice' );
56
-
57
- // Pro post meta options
58
- delete_post_meta_by_key( 'pib_utm_meta' );
59
- delete_post_meta_by_key( 'pib_override_hover_description' );
60
- delete_post_meta_by_key( 'pib_override_below_description' );
61
  }
1
+ <?php
2
+
3
+ /**
4
+ * Fired when the plugin is uninstalled.
5
+ *
6
+ * @package PIB
7
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
8
+ */
9
+
10
+ // If uninstall not called from WordPress, then exit.
11
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) )
12
+ exit;
13
+
14
+ // Legacy category option not used anymore. Delete either way.
15
+ delete_option( 'pib_category_fields_option' );
16
+
17
+ $general = get_option( 'pib_settings_general' );
18
+
19
+ // If the the option to save settings is checked then do nothing, otherwise delete all options and post meta
20
+ if ( ! empty( $general['uninstall_save_settings'] ) ) {
21
+ // Do nothing
22
+ } else {
23
+
24
+ // Lite
25
+ // Delete options
26
+ delete_option( 'pib_settings_general' );
27
+ delete_option( 'pib_settings_post_visibility' );
28
+ delete_option( 'pib_settings_styles' );
29
+ delete_option( 'pib_settings_misc' );
30
+ delete_option( 'pib_upgrade_has_run' );
31
+ delete_option( 'pib_version' );
32
+ delete_option( 'pib_show_admin_install_notice' );
33
+ delete_option( 'pib_settings_advanced' );
34
+
35
+ // Delete widget options
36
+ delete_option( 'widget_pib_button' );
37
+
38
+ // Delete post meta
39
+ delete_post_meta_by_key( 'pib_sharing_disabled' );
40
+ delete_post_meta_by_key( 'pib_url_of_webpage' );
41
+ delete_post_meta_by_key( 'pib_url_of_img' );
42
+ delete_post_meta_by_key( 'pib_description' );
43
+
44
+ // Pro
45
+ // Delete ALL Pro settings and keys
46
+ delete_option( 'pib_settings_image_hover' );
47
+ delete_option( 'pib_settings_image_misc' );
48
+ delete_option( 'pib_settings_share_bar' );
49
+ delete_option( 'pib_settings_support' );
50
+ delete_option( 'pib_sharebar_buttons' );
51
+
52
+
53
+ // Pro Misc options
54
+ delete_option( 'pib_edd_sl_license_active' );
55
+ delete_option( 'pib_lite_deactivation_notice' );
56
+
57
+ // Pro post meta options
58
+ delete_post_meta_by_key( 'pib_utm_meta' );
59
+ delete_post_meta_by_key( 'pib_override_hover_description' );
60
+ delete_post_meta_by_key( 'pib_override_below_description' );
61
  }
views/admin-help.php CHANGED
@@ -1,236 +1,236 @@
1
- <?php
2
-
3
- /**
4
- * Represents the view for the administration page "Help".
5
- *
6
- * @package PIB
7
- * @subpackage Views
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- ?>
17
-
18
- <div class="wrap">
19
-
20
- <div id="pib-settings">
21
- <div id="pib-settings-content">
22
-
23
- <h2><img src="<?php echo PIB_PLUGIN_URL; ?>assets/pinterest-icon-32.png" style="vertical-align: bottom;" /> <?php echo esc_html( get_admin_page_title() ); ?></h2>
24
-
25
- <p>
26
- <?php _e( 'Plugin version', 'pib' ); ?>: <strong><?php echo PIB_VERSION; ?></strong>
27
- </p>
28
-
29
- <h3 class="title"><?php _e( 'Shortcode Options', 'pib' ); ?></h3>
30
-
31
- <p>
32
- <?php _e( 'Use the shortcode', 'pib' ); ?> <code>[pinit]</code> <?php _e( 'to display the button within your content.', 'pib' ); ?>
33
- </p>
34
- <p>
35
- <?php _e( 'Use the function', 'pib' ); ?> <code><?php echo htmlentities( '<?php echo do_shortcode(\'[pinit]\'); ?>' ); ?></code>
36
- <?php _e( 'to display within template or theme files.', 'pib' ); ?>
37
- </p>
38
-
39
- <h4><?php _e( 'Available Attributes (Lite & Pro)', 'pib' ); ?></h4>
40
-
41
- <table class="widefat importers" cellspacing="0">
42
- <thead>
43
- <tr>
44
- <th><?php _e( 'Attribute', 'pib' ); ?></th>
45
- <th><?php _e( 'Description', 'pib' ); ?></th>
46
- <th><?php _e( 'Choices', 'pib' ); ?></th>
47
- <th><?php _e( 'Default', 'pib' ); ?></th>
48
- </tr>
49
- </thead>
50
- <tbody>
51
- <tr>
52
- <td>button_type</td>
53
- <td><?php _e( '"Pin It" button behavior type', 'pib' ); ?></td>
54
- <td>any (user selects images), one (image is pre-selected)</td>
55
- <td>any</td>
56
- </tr>
57
- <tr>
58
- <td>count</td>
59
- <td><?php _e( 'Where to show the pin count bubble', 'pib' ); ?></td>
60
- <td>none, horizontal (beside), vertical (above)</td>
61
- <td>none</td>
62
- </tr>
63
- <tr>
64
- <td>url</td>
65
- <td><?php _e( 'URL of the web page to be pinned. Must be specified if used on home or index page.', 'pib' ); ?></td>
66
- <td><?php _e( 'Any valid web page URL', 'pib' ); ?></td>
67
- <td><?php _e( 'Current post/page URL', 'pib' ); ?></td>
68
- </tr>
69
- <tr>
70
- <td>image_url</td>
71
- <td><?php _e( 'URL of the image to be pinned', 'pib' ); ?></td>
72
- <td><?php _e( 'Any valid image URL', 'pib' ); ?></td>
73
- <td><?php _e( 'First image in post/page', 'pib' ); ?></td>
74
- </tr>
75
- <tr>
76
- <td>description</td>
77
- <td><?php _e( 'Description of the pin. Ignored if button_type="any"', 'pib' ); ?></td>
78
- <td><?php _e( 'Any string of text', 'pib' ); ?></td>
79
- <td>Post/page title</td>
80
- </tr>
81
- <tr>
82
- <td>size</td>
83
- <td><?php _e( '"Pin It" button size', 'pib' ); ?></td>
84
- <td>small, large</td>
85
- <td>small</td>
86
- </tr>
87
- <tr>
88
- <td>shape</td>
89
- <td><?php _e( '"Pin It" button shape', 'pib' ); ?></td>
90
- <td>rectangular, circular</td>
91
- <td>rectangular</td>
92
- </tr>
93
- <tr>
94
- <td>color</td>
95
- <td><?php _e( '"Pin It" button color', 'pib' ); ?></td>
96
- <td>gray, red, white</td>
97
- <td>gray</td>
98
- </tr>
99
- <tr>
100
- <td>align</td>
101
- <td><?php _e( 'Adds CSS to align button', 'pib' ); ?></td>
102
- <td>none, left, right, center</td>
103
- <td>none</td>
104
- </tr>
105
- <tr>
106
- <td>remove_div</td>
107
- <td><?php _e( 'If true removes surrounding div tag', 'pib' ); ?></td>
108
- <td>true, false</td>
109
- <td>false</td>
110
- </tr>
111
- <tr>
112
- <td>always_show_count</td>
113
- <td><?php _e( 'Will always show the count bubble, even for pages with zero pins', 'pib' ); ?></td>
114
- <td>true, false</td>
115
- <td>false</td>
116
- </tr>
117
- </tbody>
118
- </table>
119
-
120
- <h4><?php _e( 'Available Attributes (Pro Only)', 'pib' ); ?></h4>
121
-
122
- <table class="widefat importers" cellspacing="0">
123
- <thead>
124
- <tr>
125
- <th><?php _e( 'Attribute', 'pib' ); ?></th>
126
- <th><?php _e( 'Description', 'pib' ); ?></th>
127
- <th><?php _e( 'Choices', 'pib' ); ?></th>
128
- <th><?php _e( 'Default', 'pib' ); ?></th>
129
- </tr>
130
- </thead>
131
- <tbody>
132
- <tr>
133
- <td>social_buttons</td>
134
- <td><?php _e( 'If true will show other social sharing buttons (the share bar). Must be enabled in main settings. Inherits alignment and other styles from main settings.', 'pib' ); ?></td>
135
- <td>true, false</td>
136
- <td>false</td>
137
- </tr>
138
- <tr>
139
- <td>use_featured_image</td>
140
- <td><?php _e( 'If true and "image is pre-selected" is enabled, will default to post\'s featured image.', 'pib' ); ?></td>
141
- <td>true, false</td>
142
- <td>false</td>
143
- </tr>
144
- </tbody>
145
- </table>
146
-
147
- <h4><?php _e( 'Shortcode Examples', 'pib' ); ?></h4>
148
-
149
- <ul class="ul-disc">
150
- <li><code>[pinit count="horizontal" button_type="one"]</code></li>
151
- <li><code>[pinit count="vertical" url="http://www.mysite.com" image_url="http://www.mysite.com/myimage.jpg" description="This is a description of my image." align="right"]</code></li>
152
- <li><strong><?php _e( 'Pro only' ); ?>:</strong> <code>[pinit social_buttons="true" use_featured_image="true" count="horizontal"]</code></li>
153
- </ul>
154
-
155
- <h3 class="title"><?php _e( 'CSS Style Overrides', 'pib' ); ?></h3>
156
-
157
- <p>
158
- <?php _e( 'This plugin outputs a CSS file in an attempt to keep basic "Pin It" button styling intact.', 'pib' ); ?>
159
- <?php _e( 'To override the CSS styles you may add your own CSS to the plugin\'s "Custom CSS" box or in your theme files.', 'pib' ); ?>
160
- <?php _e( 'No !important tags are used in this plugin\'s CSS, but note that the embed code from Pinterest also renders some CSS (which may include !important tags).', 'pib' ); ?>
161
- </p>
162
-
163
- <h4><?php _e( 'Available CSS classes (Lite & Pro)', 'pib' ); ?></h4>
164
-
165
- <ul class="ul-disc">
166
- <li><code>div.pin-it-btn-wrapper</code> - <?php _e( 'Regular button container', 'pib' ); ?></li>
167
- <li><code>div.pin-it-btn-wrapper a</code> - <?php _e( 'Regular button link tag', 'pib' ); ?></li>
168
- <li><code>div.pin-it-btn-wrapper-shortcode</code> - <?php _e( 'Shortcode button container', 'pib' ); ?></li>
169
- <li><code>div.pin-it-btn-wrapper-shortcode a</code> - <?php _e( 'Shortcode button link tag', 'pib' ); ?></li>
170
- <li><code>div.pin-it-btn-wrapper-widget</code> - <?php _e( 'Widget button container', 'pib' ); ?></li>
171
- <li><code>div.pin-it-btn-wrapper-widget a</code> - <?php _e( 'Widget button link tag', 'pib' ); ?></li>
172
- </ul>
173
-
174
- <p>
175
- <?php _e( 'There is also a <code>span</code> element nested inside the "Pin It" button <code>a</code> tag which contains the count bubble.', 'pib' ); ?>
176
- </p>
177
-
178
- <h4><?php _e( 'Available CSS classes (Pro Only)', 'pib' ); ?></h4>
179
-
180
- <ul class="ul-disc">
181
- <li><code>a.pib-hover-btn-link</code> - <?php _e( 'Hover button link tag', 'pib' ); ?></li>
182
- <li><code>div.pib-img-under-wrapper</code> - <?php _e( 'Below image button container', 'pib' ); ?></li>
183
- <li><code>div.pib-img-under-wrapper a</code> - <?php _e( 'Below image button link tag', 'pib' ); ?></li>
184
-
185
- <li><code>div.pib-sharebar</code> - <?php _e( 'Share bar container', 'pib' ); ?></li>
186
- <li><code>li.pib-sharebar-pinterest</code> - <?php _e( 'Share bar: Pin It button container', 'pib' ); ?></li>
187
- <li><code>li.pib-sharebar-facebook-share</code> - <?php _e( 'Share bar: Facebook Share button container', 'pib' ); ?></li>
188
- <li><code>li.pib-sharebar-facebook</code> - <?php _e( 'Share bar: Facebook Like button container', 'pib' ); ?></li>
189
- <li><code>li.pib-sharebar-twitter</code> - <?php _e( 'Share bar: Tweet button container', 'pib' ); ?></li>
190
- <li><code>li.pib-sharebar-gplus-share</code> - <?php _e( 'Share bar: Google+ Share button container', 'pib' ); ?></li>
191
- <li><code>li.pib-sharebar-gplus</code> - <?php _e( 'Share bar: Google +1 button container', 'pib' ); ?></li>
192
- <li><code>li.pib-sharebar-linkedin</code> - <?php _e( 'Share bar: LinkedIn Share button container', 'pib' ); ?></li>
193
- </ul>
194
-
195
- <h4><?php _e( 'CSS Style Override Examples', 'pib' ); ?></h4>
196
-
197
- <ul class="ul-disc">
198
- <li><code>div.pin-it-btn-wrapper { padding-bottom: 50px; }</code> - <?php _e( 'Increase space under button', 'pib' ); ?></li>
199
- <li><code>div.pin-it-btn-wrapper a { border: 1px solid red; }</code> - <?php _e( 'Add red border around button', 'pib' ); ?></li>
200
- <li><code>div.pin-it-btn-wrapper-widget a { border: 1px solid red; }</code> - <?php _e( 'Add red border around widget button', 'pib' ); ?></li>
201
- </ul>
202
-
203
- <h3 class="title"><?php _e( 'Individual Post/Page Overrides', 'pib' ); ?></h3>
204
-
205
- <p>
206
- <?php _e( 'You may individually override what website address (URL), image and description will be pinned for each post or page.', 'pib' ); ?>
207
- <?php _e( 'These fields are located towards the bottom of the post/page edit screen.', 'pib' ); ?>
208
- </p>
209
-
210
- <p>
211
- <?php printf( __( 'Need more widgets? Check out our free <a href="%s">Pinterest Widgets</a> plugin.', 'pib' ),
212
- add_query_arg( array(
213
- 'tab' => 'search',
214
- 'type' => 'term',
215
- 's' => urlencode('pinterest widgets')
216
- ), admin_url( 'plugin-install.php' ) )
217
- ); ?>
218
- </p>
219
- <p>
220
- <?php printf( __( 'Visit the <a href="%s" target="_blank">Knowledgebase</a> for additional help.', 'pib' ), PINPLUGIN_BASE_URL . 'support' ); ?>
221
- </p>
222
-
223
- </div><!-- #pib-settings-content -->
224
-
225
- <?php // Always show sidebar on help page. Different for Lite & Pro. ?>
226
-
227
- <div id="pib-settings-sidebar">
228
- <?php if ( class_exists( 'Pinterest_Pin_It_Button_Pro' ) ): ?>
229
- <?php include( 'admin-sidebar-pro.php' ); ?>
230
- <?php else: ?>
231
- <?php include( 'admin-sidebar.php' ); ?>
232
- <?php endif; ?>
233
- </div>
234
- </div>
235
-
236
- </div><!-- .wrap -->
1
+ <?php
2
+
3
+ /**
4
+ * Represents the view for the administration page "Help".
5
+ *
6
+ * @package PIB
7
+ * @subpackage Views
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ ?>
17
+
18
+ <div class="wrap">
19
+
20
+ <div id="pib-settings">
21
+ <div id="pib-settings-content">
22
+
23
+ <h2><img src="<?php echo PIB_PLUGIN_URL; ?>assets/pinterest-icon-32.png" style="vertical-align: bottom;" /> <?php echo esc_html( get_admin_page_title() ); ?></h2>
24
+
25
+ <p>
26
+ <?php _e( 'Plugin version', 'pib' ); ?>: <strong><?php echo PIB_VERSION; ?></strong>
27
+ </p>
28
+
29
+ <h3 class="title"><?php _e( 'Shortcode Options', 'pib' ); ?></h3>
30
+
31
+ <p>
32
+ <?php _e( 'Use the shortcode', 'pib' ); ?> <code>[pinit]</code> <?php _e( 'to display the button within your content.', 'pib' ); ?>
33
+ </p>
34
+ <p>
35
+ <?php _e( 'Use the function', 'pib' ); ?> <code><?php echo htmlentities( '<?php echo do_shortcode(\'[pinit]\'); ?>' ); ?></code>
36
+ <?php _e( 'to display within template or theme files.', 'pib' ); ?>
37
+ </p>
38
+
39
+ <h4><?php _e( 'Available Attributes (Lite & Pro)', 'pib' ); ?></h4>
40
+
41
+ <table class="widefat importers" cellspacing="0">
42
+ <thead>
43
+ <tr>
44
+ <th><?php _e( 'Attribute', 'pib' ); ?></th>
45
+ <th><?php _e( 'Description', 'pib' ); ?></th>
46
+ <th><?php _e( 'Choices', 'pib' ); ?></th>
47
+ <th><?php _e( 'Default', 'pib' ); ?></th>
48
+ </tr>
49
+ </thead>
50
+ <tbody>
51
+ <tr>
52
+ <td>button_type</td>
53
+ <td><?php _e( '"Pin It" button behavior type', 'pib' ); ?></td>
54
+ <td>any (user selects images), one (image is pre-selected)</td>
55
+ <td>any</td>
56
+ </tr>
57
+ <tr>
58
+ <td>count</td>
59
+ <td><?php _e( 'Where to show the pin count bubble', 'pib' ); ?></td>
60
+ <td>none, horizontal (beside), vertical (above)</td>
61
+ <td>none</td>
62
+ </tr>
63
+ <tr>
64
+ <td>url</td>
65
+ <td><?php _e( 'URL of the web page to be pinned. Must be specified if used on home or index page.', 'pib' ); ?></td>
66
+ <td><?php _e( 'Any valid web page URL', 'pib' ); ?></td>
67
+ <td><?php _e( 'Current post/page URL', 'pib' ); ?></td>
68
+ </tr>
69
+ <tr>
70
+ <td>image_url</td>
71
+ <td><?php _e( 'URL of the image to be pinned', 'pib' ); ?></td>
72
+ <td><?php _e( 'Any valid image URL', 'pib' ); ?></td>
73
+ <td><?php _e( 'First image in post/page', 'pib' ); ?></td>
74
+ </tr>
75
+ <tr>
76
+ <td>description</td>
77
+ <td><?php _e( 'Description of the pin. Ignored if button_type="any"', 'pib' ); ?></td>
78
+ <td><?php _e( 'Any string of text', 'pib' ); ?></td>
79
+ <td>Post/page title</td>
80
+ </tr>
81
+ <tr>
82
+ <td>size</td>
83
+ <td><?php _e( '"Pin It" button size', 'pib' ); ?></td>
84
+ <td>small, large</td>
85
+ <td>small</td>
86
+ </tr>
87
+ <tr>
88
+ <td>shape</td>
89
+ <td><?php _e( '"Pin It" button shape', 'pib' ); ?></td>
90
+ <td>rectangular, circular</td>
91
+ <td>rectangular</td>
92
+ </tr>
93
+ <tr>
94
+ <td>color</td>
95
+ <td><?php _e( '"Pin It" button color', 'pib' ); ?></td>
96
+ <td>gray, red, white</td>
97
+ <td>gray</td>
98
+ </tr>
99
+ <tr>
100
+ <td>align</td>
101
+ <td><?php _e( 'Adds CSS to align button', 'pib' ); ?></td>
102
+ <td>none, left, right, center</td>
103
+ <td>none</td>
104
+ </tr>
105
+ <tr>
106
+ <td>remove_div</td>
107
+ <td><?php _e( 'If true removes surrounding div tag', 'pib' ); ?></td>
108
+ <td>true, false</td>
109
+ <td>false</td>
110
+ </tr>
111
+ <tr>
112
+ <td>always_show_count</td>
113
+ <td><?php _e( 'Will always show the count bubble, even for pages with zero pins', 'pib' ); ?></td>
114
+ <td>true, false</td>
115
+ <td>false</td>
116
+ </tr>
117
+ </tbody>
118
+ </table>
119
+
120
+ <h4><?php _e( 'Available Attributes (Pro Only)', 'pib' ); ?></h4>
121
+
122
+ <table class="widefat importers" cellspacing="0">
123
+ <thead>
124
+ <tr>
125
+ <th><?php _e( 'Attribute', 'pib' ); ?></th>
126
+ <th><?php _e( 'Description', 'pib' ); ?></th>
127
+ <th><?php _e( 'Choices', 'pib' ); ?></th>
128
+ <th><?php _e( 'Default', 'pib' ); ?></th>
129
+ </tr>
130
+ </thead>
131
+ <tbody>
132
+ <tr>
133
+ <td>social_buttons</td>
134
+ <td><?php _e( 'If true will show other social sharing buttons (the share bar). Must be enabled in main settings. Inherits alignment and other styles from main settings.', 'pib' ); ?></td>
135
+ <td>true, false</td>
136
+ <td>false</td>
137
+ </tr>
138
+ <tr>
139
+ <td>use_featured_image</td>
140
+ <td><?php _e( 'If true and "image is pre-selected" is enabled, will default to post\'s featured image.', 'pib' ); ?></td>
141
+ <td>true, false</td>
142
+ <td>false</td>
143
+ </tr>
144
+ </tbody>
145
+ </table>
146
+
147
+ <h4><?php _e( 'Shortcode Examples', 'pib' ); ?></h4>
148
+
149
+ <ul class="ul-disc">
150
+ <li><code>[pinit count="horizontal" button_type="one"]</code></li>
151
+ <li><code>[pinit count="vertical" url="http://www.mysite.com" image_url="http://www.mysite.com/myimage.jpg" description="This is a description of my image." align="right"]</code></li>
152
+ <li><strong><?php _e( 'Pro only' ); ?>:</strong> <code>[pinit social_buttons="true" use_featured_image="true" count="horizontal"]</code></li>
153
+ </ul>
154
+
155
+ <h3 class="title"><?php _e( 'CSS Style Overrides', 'pib' ); ?></h3>
156
+
157
+ <p>
158
+ <?php _e( 'This plugin outputs a CSS file in an attempt to keep basic "Pin It" button styling intact.', 'pib' ); ?>
159
+ <?php _e( 'To override the CSS styles you may add your own CSS to the plugin\'s "Custom CSS" box or in your theme files.', 'pib' ); ?>
160
+ <?php _e( 'No !important tags are used in this plugin\'s CSS, but note that the embed code from Pinterest also renders some CSS (which may include !important tags).', 'pib' ); ?>
161
+ </p>
162
+
163
+ <h4><?php _e( 'Available CSS classes (Lite & Pro)', 'pib' ); ?></h4>
164
+
165
+ <ul class="ul-disc">
166
+ <li><code>div.pin-it-btn-wrapper</code> - <?php _e( 'Regular button container', 'pib' ); ?></li>
167
+ <li><code>div.pin-it-btn-wrapper a</code> - <?php _e( 'Regular button link tag', 'pib' ); ?></li>
168
+ <li><code>div.pin-it-btn-wrapper-shortcode</code> - <?php _e( 'Shortcode button container', 'pib' ); ?></li>
169
+ <li><code>div.pin-it-btn-wrapper-shortcode a</code> - <?php _e( 'Shortcode button link tag', 'pib' ); ?></li>
170
+ <li><code>div.pin-it-btn-wrapper-widget</code> - <?php _e( 'Widget button container', 'pib' ); ?></li>
171
+ <li><code>div.pin-it-btn-wrapper-widget a</code> - <?php _e( 'Widget button link tag', 'pib' ); ?></li>
172
+ </ul>
173
+
174
+ <p>
175
+ <?php _e( 'There is also a <code>span</code> element nested inside the "Pin It" button <code>a</code> tag which contains the count bubble.', 'pib' ); ?>
176
+ </p>
177
+
178
+ <h4><?php _e( 'Available CSS classes (Pro Only)', 'pib' ); ?></h4>
179
+
180
+ <ul class="ul-disc">
181
+ <li><code>a.pib-hover-btn-link</code> - <?php _e( 'Hover button link tag', 'pib' ); ?></li>
182
+ <li><code>div.pib-img-under-wrapper</code> - <?php _e( 'Below image button container', 'pib' ); ?></li>
183
+ <li><code>div.pib-img-under-wrapper a</code> - <?php _e( 'Below image button link tag', 'pib' ); ?></li>
184
+
185
+ <li><code>div.pib-sharebar</code> - <?php _e( 'Share bar container', 'pib' ); ?></li>
186
+ <li><code>li.pib-sharebar-pinterest</code> - <?php _e( 'Share bar: Pin It button container', 'pib' ); ?></li>
187
+ <li><code>li.pib-sharebar-facebook-share</code> - <?php _e( 'Share bar: Facebook Share button container', 'pib' ); ?></li>
188
+ <li><code>li.pib-sharebar-facebook</code> - <?php _e( 'Share bar: Facebook Like button container', 'pib' ); ?></li>
189
+ <li><code>li.pib-sharebar-twitter</code> - <?php _e( 'Share bar: Tweet button container', 'pib' ); ?></li>
190
+ <li><code>li.pib-sharebar-gplus-share</code> - <?php _e( 'Share bar: Google+ Share button container', 'pib' ); ?></li>
191
+ <li><code>li.pib-sharebar-gplus</code> - <?php _e( 'Share bar: Google +1 button container', 'pib' ); ?></li>
192
+ <li><code>li.pib-sharebar-linkedin</code> - <?php _e( 'Share bar: LinkedIn Share button container', 'pib' ); ?></li>
193
+ </ul>
194
+
195
+ <h4><?php _e( 'CSS Style Override Examples', 'pib' ); ?></h4>
196
+
197
+ <ul class="ul-disc">
198
+ <li><code>div.pin-it-btn-wrapper { padding-bottom: 50px; }</code> - <?php _e( 'Increase space under button', 'pib' ); ?></li>
199
+ <li><code>div.pin-it-btn-wrapper a { border: 1px solid red; }</code> - <?php _e( 'Add red border around button', 'pib' ); ?></li>
200
+ <li><code>div.pin-it-btn-wrapper-widget a { border: 1px solid red; }</code> - <?php _e( 'Add red border around widget button', 'pib' ); ?></li>
201
+ </ul>
202
+
203
+ <h3 class="title"><?php _e( 'Individual Post/Page Overrides', 'pib' ); ?></h3>
204
+
205
+ <p>
206
+ <?php _e( 'You may individually override what website address (URL), image and description will be pinned for each post or page.', 'pib' ); ?>
207
+ <?php _e( 'These fields are located towards the bottom of the post/page edit screen.', 'pib' ); ?>
208
+ </p>
209
+
210
+ <p>
211
+ <?php printf( __( 'Need more widgets? Check out our free <a href="%s">Pinterest Widgets</a> plugin.', 'pib' ),
212
+ add_query_arg( array(
213
+ 'tab' => 'search',
214
+ 'type' => 'term',
215
+ 's' => urlencode('pinterest widgets')
216
+ ), admin_url( 'plugin-install.php' ) )
217
+ ); ?>
218
+ </p>
219
+ <p>
220
+ <?php printf( __( 'Visit the <a href="%s" target="_blank">Knowledgebase</a> for additional help.', 'pib' ), PINPLUGIN_BASE_URL . 'support' ); ?>
221
+ </p>
222
+
223
+ </div><!-- #pib-settings-content -->
224
+
225
+ <?php // Always show sidebar on help page. Different for Lite & Pro. ?>
226
+
227
+ <div id="pib-settings-sidebar">
228
+ <?php if ( class_exists( 'Pinterest_Pin_It_Button_Pro' ) ): ?>
229
+ <?php include( 'admin-sidebar-pro.php' ); ?>
230
+ <?php else: ?>
231
+ <?php include( 'admin-sidebar.php' ); ?>
232
+ <?php endif; ?>
233
+ </div>
234
+ </div>
235
+
236
+ </div><!-- .wrap -->
views/admin-install-notice.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
-
3
- /**
4
- * Show notice after plugin install/activate in admin dashboard until user acknowledges.
5
- *
6
- * @package PIB
7
- * @subpackage Views
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- ?>
17
-
18
- <style>
19
- #pib-install-notice .button-primary,
20
- #pib-install-notice .button-secondary {
21
- margin-left: 15px;
22
- }
23
- </style>
24
-
25
- <div id="pib-install-notice" class="updated">
26
- <p>
27
- <?php echo $this->get_plugin_title() . __( ' is now installed.', 'pib' ); ?>
28
- <a href="<?php echo add_query_arg( 'page', $this->plugin_slug, admin_url( 'admin.php' ) ); ?>" class="button-primary"><?php _e( 'Setup your Pin It button now', 'pib' ); ?></a>
29
- <a href="<?php echo add_query_arg( 'pib-dismiss-install-nag', 1 ); ?>" class="button-secondary"><?php _e( 'Hide this', 'pib' ); ?></a>
30
- </p>
31
- </div>
1
+ <?php
2
+
3
+ /**
4
+ * Show notice after plugin install/activate in admin dashboard until user acknowledges.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Views
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ ?>
17
+
18
+ <style>
19
+ #pib-install-notice .button-primary,
20
+ #pib-install-notice .button-secondary {
21
+ margin-left: 15px;
22
+ }
23
+ </style>
24
+
25
+ <div id="pib-install-notice" class="updated">
26
+ <p>
27
+ <?php echo $this->get_plugin_title() . __( ' is now installed.', 'pib' ); ?>
28
+ <a href="<?php echo add_query_arg( 'page', $this->plugin_slug, admin_url( 'admin.php' ) ); ?>" class="button-primary"><?php _e( 'Setup your Pin It button now', 'pib' ); ?></a>
29
+ <a href="<?php echo add_query_arg( 'pib-dismiss-install-nag', 1 ); ?>" class="button-secondary"><?php _e( 'Hide this', 'pib' ); ?></a>
30
+ </p>
31
+ </div>
views/admin-sidebar.php CHANGED
@@ -1,152 +1,150 @@
1
- <?php
2
-
3
- /**
4
- * Sidebar portion of the administration dashboard view (and subpages).
5
- *
6
- * @package PIB
7
- * @subpackage Views
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
- ?>
16
-
17
- <!-- Use some built-in WP admin theme styles. -->
18
- <div class="sidebar-container metabox-holder">
19
-
20
- <div class="postbox">
21
- <h3 class="wp-ui-primary"><span><?php _e( 'Need More Options?', 'pib' ); ?></span></h3>
22
- <div class="inside">
23
- <div class="main">
24
- <ul>
25
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Add "Pin It" buttons on image hover', 'pib' ); ?></li>
26
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Add "Pin It" buttons under images', 'pib' ); ?></li>
27
- <li><div class="dashicons dashicons-yes"></div> <?php _e( '30 custom "Pin It" button designs', 'pib' ); ?></li>
28
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Upload your own button designs', 'pib' ); ?></li>
29
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Twitter, Facebook & G+ buttons', 'pib' ); ?></li>
30
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Use with featured images', 'pib' ); ?></li>
31
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Use with custom post types', 'pib' ); ?></li>
32
-
33
- <?php if ( pib_is_woo_commerce_active() ): ?>
34
- <div class="dashicons dashicons-yes"></div> <?php _e( 'WooCommerce support', 'pib' ); ?></li>
35
- <?php endif; ?>
36
-
37
- <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Customer support & auto updates', 'pib' ); ?></li>
38
- </ul>
39
-
40
- <p class="last-blurb centered">
41
- <?php _e( 'Get all of these and more with Pinterest "Pin It" Button Pro!', 'pib' ); ?>
42
- </p>
43
-
44
- <div class="centered">
45
- <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'pin-it-button-pro/', 'pib_lite_2', 'sidebar_link', 'pro_upgrade' ); ?>"
46
- class="button-primary button-large" target="_blank">
47
- <?php _e( 'Upgrade to Pro Now', 'pib' ); ?></a>
48
- </div>
49
-
50
- </div>
51
- </div>
52
- </div>
53
- </div>
54
-
55
- <?php if ( pib_is_woo_commerce_active() ): // Check if WooCommerce is active to show WC Rich Pins promo. ?>
56
-
57
- <?php if ( ! pib_is_wc_rich_pins_active() ): // If WooCommerce Rich Pins is already active don't show. ?>
58
-
59
- <div class="sidebar-container metabox-holder">
60
- <div class="postbox">
61
- <h3 class="wp-ui-primary"><span><?php _e( 'WooCommerce Rich Pins', 'pib' ); ?></span></h3>
62
- <div class="inside">
63
- <div class="main">
64
- <p>
65
- <?php _e( 'Running a WooCommerce store and want to give your product pins a boost? There\'s a plugin for that.', 'pib' ); ?>
66
- </p>
67
- <div class="centered">
68
- <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'plugins/product-rich-pins-for-woocommerce/', 'pib_lite_2', 'sidebar_link', 'wc_rich_pins' ); ?>"
69
- class="button-primary" target="_blank">
70
- <?php _e( 'Check out Rich Pins for WooCommerce', 'pib' ); ?>
71
- </a>
72
- </div>
73
- </div>
74
- </div>
75
- </div>
76
- </div>
77
-
78
- <?php endif; // End WooCommerce Rich Pins check ?>
79
-
80
- <?php else: // If not running WooCommerce show Article Rich Pins promo. ?>
81
-
82
- <?php if ( ! pib_is_article_rich_pins_active() ): // Unless of course Article Rich Pins is already active. ?>
83
-
84
- <div class="sidebar-container metabox-holder">
85
- <div class="postbox">
86
- <h3 class="wp-ui-primary"><span><?php _e( 'Article Rich Pins', 'pib' ); ?></span></h3>
87
- <div class="inside">
88
- <div class="main">
89
- <p>
90
- <?php _e( 'Want give your pins a boost with <strong>Article Rich Pins</strong>? There\'s a plugin for that.', 'pib' ); ?>
91
- </p>
92
- <div class="centered">
93
- <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'plugins/article-rich-pins/', 'pib_lite_2', 'sidebar_link', 'article_rich_pins' ); ?>"
94
- class="button-primary" target="_blank">
95
- <?php _e( 'Check out Article Rich Pins', 'pib' ); ?>
96
- </a>
97
- </div>
98
- </div>
99
- </div>
100
- </div>
101
- </div>
102
-
103
- <?php endif; // End Article Rich Pins check ?>
104
-
105
- <?php endif; // End WooCommerce check ?>
106
-
107
- <div class="sidebar-container metabox-holder">
108
- <div class="postbox">
109
- <div class="inside">
110
- <p>
111
- <?php _e( 'Help us get noticed (and boost our egos) with a rating and short review.', 'pib' ); ?>
112
- </p>
113
- <div class="centered">
114
- <a href="http://wordpress.org/support/view/plugin-reviews/pinterest-pin-it-button" class="button-primary" target="_blank">
115
- <?php _e( 'Rate this plugin on WordPress.org', 'pib' ); ?></a>
116
- </div>
117
- </div>
118
- </div>
119
- </div>
120
-
121
- <div class="sidebar-container metabox-holder">
122
- <div class="postbox">
123
- <div class="inside">
124
- <ul>
125
- <li>
126
- <div class="dashicons dashicons-arrow-right-alt2"></div>
127
- <a href="<?php echo add_query_arg( 'page', PIB_PLUGIN_SLUG . '_help', admin_url( 'admin.php' ) ); ?>">
128
- <?php _e( 'Shortcode & CSS Help', 'pib' ); ?></a>
129
- </li>
130
- <li>
131
- <div class="dashicons dashicons-arrow-right-alt2"></div>
132
- <a href="http://wordpress.org/support/plugin/pinterest-pin-it-button" target="_blank">
133
- <?php _e( 'Community Support Forums', 'pib' ); ?></a>
134
- </li>
135
- <li>
136
- <div class="dashicons dashicons-arrow-right-alt2"></div>
137
- <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'support', 'pib_lite_2', 'sidebar_link', 'support' ); ?>" target="_blank">
138
- <?php _e( 'Knowledgebase', 'pib' ); ?></a>
139
- </li>
140
- </ul>
141
- </div>
142
- </div>
143
- </div>
144
-
145
- <div class="sidebar-container metabox-holder">
146
- <div class="postbox">
147
- <h3><?php _e( 'Recent News from pinplugins.com', 'pib' ); ?></h3>
148
- <div class="inside">
149
- <?php pib_rss_news(); ?>
150
- </div>
151
- </div>
152
- </div>
1
+ <?php
2
+
3
+ /**
4
+ * Sidebar portion of the administration dashboard view (and subpages).
5
+ *
6
+ * @package PIB
7
+ * @subpackage Views
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+ ?>
16
+
17
+ <!-- Use some built-in WP admin theme styles. -->
18
+ <div class="sidebar-container metabox-holder">
19
+ <div class="postbox">
20
+ <h3 class="wp-ui-primary"><span><?php _e( 'Need More Options?', 'pib' ); ?></span></h3>
21
+ <div class="inside">
22
+ <div class="main">
23
+ <ul>
24
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Add "Pin It" buttons on image hover', 'pib' ); ?></li>
25
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Add "Pin It" buttons under images', 'pib' ); ?></li>
26
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( '30 custom "Pin It" button designs', 'pib' ); ?></li>
27
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Upload your own button designs', 'pib' ); ?></li>
28
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Twitter, Facebook & G+ buttons', 'pib' ); ?></li>
29
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Use with featured images', 'pib' ); ?></li>
30
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Use with custom post types', 'pib' ); ?></li>
31
+
32
+ <?php if ( pib_is_woo_commerce_active() ): ?>
33
+ <div class="dashicons dashicons-yes"></div> <?php _e( 'WooCommerce support', 'pib' ); ?></li>
34
+ <?php endif; ?>
35
+
36
+ <li><div class="dashicons dashicons-yes"></div> <?php _e( 'Automatic updates & email support', 'pib' ); ?></li>
37
+ </ul>
38
+
39
+ <p class="last-blurb centered">
40
+ <?php _e( 'Get all of these and more with Pinterest "Pin It" Button Pro!', 'pib' ); ?>
41
+ </p>
42
+
43
+ <div class="centered">
44
+ <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'pin-it-button-pro/', 'pib_lite_2', 'sidebar_link', 'pro_upgrade' ); ?>"
45
+ class="button-primary button-large" target="_blank">
46
+ <?php _e( 'Upgrade to Pro Now', 'pib' ); ?></a>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+
53
+ <?php if ( pib_is_woo_commerce_active() ): // Check if WooCommerce is active to show WC Rich Pins promo. ?>
54
+
55
+ <?php if ( ! pib_is_wc_rich_pins_active() ): // If WooCommerce Rich Pins is already active don't show. ?>
56
+
57
+ <div class="sidebar-container metabox-holder">
58
+ <div class="postbox">
59
+ <h3 class="wp-ui-primary"><span><?php _e( 'WooCommerce Rich Pins', 'pib' ); ?></span></h3>
60
+ <div class="inside">
61
+ <div class="main">
62
+ <p>
63
+ <?php _e( 'Running a WooCommerce store and want to give your product pins a boost? There\'s a plugin for that.', 'pib' ); ?>
64
+ </p>
65
+ <div class="centered">
66
+ <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'plugins/product-rich-pins-for-woocommerce/', 'pib_lite_2', 'sidebar_link', 'wc_rich_pins' ); ?>"
67
+ class="button-primary" target="_blank">
68
+ <?php _e( 'Check out Rich Pins for WooCommerce', 'pib' ); ?>
69
+ </a>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+
76
+ <?php endif; // End WooCommerce Rich Pins check ?>
77
+
78
+ <?php else: // If not running WooCommerce show Article Rich Pins promo. ?>
79
+
80
+ <?php if ( ! pib_is_article_rich_pins_active() ): // Unless of course Article Rich Pins is already active. ?>
81
+
82
+ <div class="sidebar-container metabox-holder">
83
+ <div class="postbox">
84
+ <h3 class="wp-ui-primary"><span><?php _e( 'Article Rich Pins', 'pib' ); ?></span></h3>
85
+ <div class="inside">
86
+ <div class="main">
87
+ <p>
88
+ <?php _e( 'Want give your pins a boost with <strong>Article Rich Pins</strong>? There\'s a plugin for that.', 'pib' ); ?>
89
+ </p>
90
+ <div class="centered">
91
+ <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'plugins/article-rich-pins/', 'pib_lite_2', 'sidebar_link', 'article_rich_pins' ); ?>"
92
+ class="button-primary" target="_blank">
93
+ <?php _e( 'Check out Article Rich Pins', 'pib' ); ?>
94
+ </a>
95
+ </div>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </div>
100
+
101
+ <?php endif; // End Article Rich Pins check ?>
102
+
103
+ <?php endif; // End WooCommerce check ?>
104
+
105
+ <div class="sidebar-container metabox-holder">
106
+ <div class="postbox">
107
+ <div class="inside">
108
+ <p>
109
+ <?php _e( 'Now accepting 5-star reviews! It only takes seconds and means a lot.', 'pib' ); ?>
110
+ </p>
111
+ <div class="centered">
112
+ <a href="http://wordpress.org/support/view/plugin-reviews/pinterest-pin-it-button" class="button-primary" target="_blank">
113
+ <?php _e( 'Rate this Plugin Now', 'pib' ); ?></a>
114
+ </div>
115
+ </div>
116
+ </div>
117
+ </div>
118
+
119
+ <div class="sidebar-container metabox-holder">
120
+ <div class="postbox">
121
+ <div class="inside">
122
+ <ul>
123
+ <li>
124
+ <div class="dashicons dashicons-arrow-right-alt2"></div>
125
+ <a href="<?php echo add_query_arg( 'page', PIB_PLUGIN_SLUG . '_help', admin_url( 'admin.php' ) ); ?>">
126
+ <?php _e( 'Shortcode & CSS Help', 'pib' ); ?></a>
127
+ </li>
128
+ <li>
129
+ <div class="dashicons dashicons-arrow-right-alt2"></div>
130
+ <a href="http://wordpress.org/support/plugin/pinterest-pin-it-button" target="_blank">
131
+ <?php _e( 'Community Support Forums', 'pib' ); ?></a>
132
+ </li>
133
+ <li>
134
+ <div class="dashicons dashicons-arrow-right-alt2"></div>
135
+ <a href="<?php echo pib_ga_campaign_url( PINPLUGIN_BASE_URL . 'support', 'pib_lite_2', 'sidebar_link', 'support' ); ?>" target="_blank">
136
+ <?php _e( 'Knowledgebase', 'pib' ); ?></a>
137
+ </li>
138
+ </ul>
139
+ </div>
140
+ </div>
141
+ </div>
142
+
143
+ <div class="sidebar-container metabox-holder">
144
+ <div class="postbox">
145
+ <h3><?php _e( 'Recent News from pinplugins.com', 'pib' ); ?></h3>
146
+ <div class="inside">
147
+ <?php pib_rss_news(); ?>
148
+ </div>
149
+ </div>
150
+ </div>
 
 
views/admin.php CHANGED
@@ -1,76 +1,76 @@
1
- <?php
2
-
3
- /**
4
- * Represents the view for the administration dashboard.
5
- *
6
- * This includes the header, options, and other information that should provide
7
- * The User Interface to the end user.
8
- *
9
- * @package PIB
10
- * @subpackage Views
11
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
12
- */
13
-
14
- // Exit if accessed directly.
15
- if ( ! defined( 'ABSPATH' ) ) {
16
- exit;
17
- }
18
-
19
- global $pib_options;
20
- $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
21
-
22
- // Additional div containers and CSS classes to keep fluid layout with right sidebar.
23
- ?>
24
-
25
- <div class="wrap">
26
-
27
- <div id="pib-settings">
28
- <div id="pib-settings-content">
29
-
30
-
31
- <h2><img src="<?php echo PIB_PLUGIN_URL; ?>assets/pinterest-icon-32.png" style="vertical-align: bottom;" /> <?php echo esc_html( get_admin_page_title() ); ?></h2>
32
-
33
- <h2 class="nav-tab-wrapper">
34
- <a href="<?php echo add_query_arg( 'tab', 'general', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
35
- <?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>"><?php _e( 'General', 'pib' ); ?></a>
36
- <a href="<?php echo add_query_arg( 'tab', 'post_visibility', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
37
- <?php echo $active_tab == 'post_visibility' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Post Visibility', 'pib' ); ?></a>
38
- <a href="<?php echo add_query_arg( 'tab', 'styles', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
39
- <?php echo $active_tab == 'styles' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Styles', 'pib' ); ?></a>
40
- <a href="<?php echo add_query_arg( 'tab', 'advanced', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
41
- <?php echo $active_tab == 'advanced' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Advanced', 'pib' ); ?></a>
42
- </h2>
43
-
44
- <div id="tab_container">
45
-
46
- <form method="post" action="options.php">
47
- <?php
48
- if ( $active_tab == 'general' ) {
49
- settings_fields( 'pib_settings_general' );
50
- do_settings_sections( 'pib_settings_general' );
51
- } elseif ( $active_tab == 'post_visibility' ) {
52
- settings_fields( 'pib_settings_post_visibility' );
53
- do_settings_sections( 'pib_settings_post_visibility' );
54
- } elseif ( $active_tab == 'styles' ) {
55
- settings_fields( 'pib_settings_styles' );
56
- do_settings_sections( 'pib_settings_styles' );
57
- } elseif ( $active_tab == 'advanced' ) {
58
- settings_fields( 'pib_settings_advanced' );
59
- do_settings_sections( 'pib_settings_advanced' );
60
- } else {
61
- // Do nothing
62
- }
63
-
64
- submit_button();
65
- ?>
66
- </form>
67
- </div><!-- #tab_container-->
68
-
69
- </div><!-- #pib-settings-content -->
70
-
71
- <div id="pib-settings-sidebar">
72
- <?php include( 'admin-sidebar.php' ); ?>
73
- </div>
74
- </div>
75
-
76
- </div><!-- .wrap -->
1
+ <?php
2
+
3
+ /**
4
+ * Represents the view for the administration dashboard.
5
+ *
6
+ * This includes the header, options, and other information that should provide
7
+ * The User Interface to the end user.
8
+ *
9
+ * @package PIB
10
+ * @subpackage Views
11
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
12
+ */
13
+
14
+ // Exit if accessed directly.
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit;
17
+ }
18
+
19
+ global $pib_options;
20
+ $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
21
+
22
+ // Additional div containers and CSS classes to keep fluid layout with right sidebar.
23
+ ?>
24
+
25
+ <div class="wrap">
26
+
27
+ <div id="pib-settings">
28
+ <div id="pib-settings-content">
29
+
30
+
31
+ <h2><img src="<?php echo PIB_PLUGIN_URL; ?>assets/pinterest-icon-32.png" style="vertical-align: bottom;" /> <?php echo esc_html( get_admin_page_title() ); ?></h2>
32
+
33
+ <h2 class="nav-tab-wrapper">
34
+ <a href="<?php echo add_query_arg( 'tab', 'general', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
35
+ <?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>"><?php _e( 'General', 'pib' ); ?></a>
36
+ <a href="<?php echo add_query_arg( 'tab', 'post_visibility', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
37
+ <?php echo $active_tab == 'post_visibility' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Post Visibility', 'pib' ); ?></a>
38
+ <a href="<?php echo add_query_arg( 'tab', 'styles', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
39
+ <?php echo $active_tab == 'styles' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Styles', 'pib' ); ?></a>
40
+ <a href="<?php echo add_query_arg( 'tab', 'advanced', remove_query_arg( 'settings-updated' )); ?>" class="nav-tab
41
+ <?php echo $active_tab == 'advanced' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Advanced', 'pib' ); ?></a>
42
+ </h2>
43
+
44
+ <div id="tab_container">
45
+
46
+ <form method="post" action="options.php">
47
+ <?php
48
+ if ( $active_tab == 'general' ) {
49
+ settings_fields( 'pib_settings_general' );
50
+ do_settings_sections( 'pib_settings_general' );
51
+ } elseif ( $active_tab == 'post_visibility' ) {
52
+ settings_fields( 'pib_settings_post_visibility' );
53
+ do_settings_sections( 'pib_settings_post_visibility' );
54
+ } elseif ( $active_tab == 'styles' ) {
55
+ settings_fields( 'pib_settings_styles' );
56
+ do_settings_sections( 'pib_settings_styles' );
57
+ } elseif ( $active_tab == 'advanced' ) {
58
+ settings_fields( 'pib_settings_advanced' );
59
+ do_settings_sections( 'pib_settings_advanced' );
60
+ } else {
61
+ // Do nothing
62
+ }
63
+
64
+ submit_button();
65
+ ?>
66
+ </form>
67
+ </div><!-- #tab_container-->
68
+
69
+ </div><!-- #pib-settings-content -->
70
+
71
+ <div id="pib-settings-sidebar">
72
+ <?php include( 'admin-sidebar.php' ); ?>
73
+ </div>
74
+ </div>
75
+
76
+ </div><!-- .wrap -->
views/post-meta-display.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
-
3
- /**
4
- * Post Meta Display
5
- *
6
- * @package PIB
7
- * @subpackage Views
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
- global $pib_options, $post, $pib_vars;
17
-
18
- $button_type_display = ( $pib_options['button_type'] == 'user_selects_image' ) ? __( 'User selects image', 'pib' ) : __( 'Image pre-selected', 'pib' );
19
-
20
- $pib_sharing_checked = get_post_meta( $post->ID, 'pib_sharing_disabled', true );
21
- $pib_url_of_webpage = get_post_meta( $post->ID, 'pib_url_of_webpage', true);
22
- $pib_url_of_img = get_post_meta( $post->ID, 'pib_url_of_img', true);
23
- $pib_description = get_post_meta( $post->ID, 'pib_description', true);
24
- ?>
25
-
26
- <p>
27
- <?php _e( 'Individual post or page-level button settings will only take affect if the "Pin It" button type set in the main settings is <strong>"image pre-selected"</strong>.', 'pib' ); ?>
28
- </p>
29
- <p>
30
- <?php _e( 'Current button type:', 'pib' ) ?> <strong><?php echo $button_type_display; ?></strong>
31
- </p>
32
- <?php if ( $pib_options['button_type'] == 'user_selects_image' ): ?>
33
- <p>
34
- <strong style="color: red;"><?php _e( 'The below settings will not take affects unless the button type is changed. ', 'pib' ); ?></strong>
35
- <?php echo sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', PIB_PLUGIN_SLUG, admin_url( 'admin.php' ) ), __( 'Go to "Pin It" Button Settings', 'pib' ) ); ?>
36
- </p>
37
- <?php endif; ?>
38
- <p>
39
- <label for="pib_url_of_webpage"><?php _e( 'URL of the web page to be pinned', 'pib' ); ?>:</label><br />
40
- <input type="text" class="widefat" name="pib_url_of_webpage" id="pib_url_of_webpage" value="<?php echo esc_attr( $pib_url_of_webpage ); ?>" /><br/>
41
- <span class="description"><?php _e( 'Defaults to current post/page URL if left blank.', 'pib' ); ?></span>
42
- </p>
43
- <p>
44
- <label for="pib_url_of_img"><?php _e( 'URL of the image to be pinned', 'pib' ); ?>:</label><br />
45
- <input type="text" class="widefat" name="pib_url_of_img" id="pib_url_of_img" value="<?php echo esc_attr( $pib_url_of_img ); ?>" /><br/>
46
- <span class="description"><?php _e( 'Defaults to first image in post if left blank.', 'pib' ); ?></span>
47
- </p>
48
- <p>
49
- <label for="pib_description"><?php _e( 'Description of the pin', 'pib' ); ?>:</label><br />
50
- <input type="text" class="widefat" name="pib_description" id="pib_description" value="<?php echo esc_attr( $pib_description ); ?>" /><br/>
51
- <span class="description"><?php _e( 'Defaults to post title if left blank.', 'pib' ); ?></span>
52
- </p>
53
- <p>
54
- <input type="checkbox" name="pib_enable_post_sharing" id="pib_enable_post_sharing" <?php checked( empty( $pib_sharing_checked ) || ($pib_sharing_checked === false) ); ?> />
55
- <label for="pib_enable_post_sharing"><?php _e( 'Show "Pin It" button ' . $pib_vars['post_meta_message'] . ' on this post/page', 'pib' ); ?></label>
56
- </p>
57
- <p class="description">
58
- <?php _e( 'If checked displays the button ' . $pib_vars['post_meta_message'] . ' for this post (if Individual Posts selected) or this page (if Individual Pages selected) in the main "Pin It" button settings.', 'pib' ); ?>
59
- </p>
60
- <p class="description">
61
- <?php _e( 'If unchecked the button ' . $pib_vars['post_meta_message'] . ' will always be hidden for this post/page.', 'pib' ); ?>
62
- </p>
63
-
64
- <?php
65
- // Now using an action to easily add more post meta options
66
- do_action( 'pib_post_meta_options' );
67
- ?>
68
-
69
- <input type="hidden" name="pib_sharing_status_hidden" value="1" />
1
+ <?php
2
+
3
+ /**
4
+ * Post Meta Display
5
+ *
6
+ * @package PIB
7
+ * @subpackage Views
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ global $pib_options, $post, $pib_vars;
17
+
18
+ $button_type_display = ( $pib_options['button_type'] == 'user_selects_image' ) ? __( 'User selects image', 'pib' ) : __( 'Image pre-selected', 'pib' );
19
+
20
+ $pib_sharing_checked = get_post_meta( $post->ID, 'pib_sharing_disabled', true );
21
+ $pib_url_of_webpage = get_post_meta( $post->ID, 'pib_url_of_webpage', true);
22
+ $pib_url_of_img = get_post_meta( $post->ID, 'pib_url_of_img', true);
23
+ $pib_description = get_post_meta( $post->ID, 'pib_description', true);
24
+ ?>
25
+
26
+ <p>
27
+ <?php _e( 'Individual post or page-level button settings will only take affect if the "Pin It" button type set in the main settings is <strong>"image pre-selected"</strong>.', 'pib' ); ?>
28
+ </p>
29
+ <p>
30
+ <?php _e( 'Current button type:', 'pib' ) ?> <strong><?php echo $button_type_display; ?></strong>
31
+ </p>
32
+ <?php if ( $pib_options['button_type'] == 'user_selects_image' ): ?>
33
+ <p>
34
+ <strong style="color: red;"><?php _e( 'The below settings will not take affects unless the button type is changed. ', 'pib' ); ?></strong>
35
+ <?php echo sprintf( '<a href="%s">%s</a>', add_query_arg( 'page', PIB_PLUGIN_SLUG, admin_url( 'admin.php' ) ), __( 'Go to "Pin It" Button Settings', 'pib' ) ); ?>
36
+ </p>
37
+ <?php endif; ?>
38
+ <p>
39
+ <label for="pib_url_of_webpage"><?php _e( 'URL of the web page to be pinned', 'pib' ); ?>:</label><br />
40
+ <input type="text" class="widefat" name="pib_url_of_webpage" id="pib_url_of_webpage" value="<?php echo esc_attr( $pib_url_of_webpage ); ?>" /><br/>
41
+ <span class="description"><?php _e( 'Defaults to current post/page URL if left blank.', 'pib' ); ?></span>
42
+ </p>
43
+ <p>
44
+ <label for="pib_url_of_img"><?php _e( 'URL of the image to be pinned', 'pib' ); ?>:</label><br />
45
+ <input type="text" class="widefat" name="pib_url_of_img" id="pib_url_of_img" value="<?php echo esc_attr( $pib_url_of_img ); ?>" /><br/>
46
+ <span class="description"><?php _e( 'Defaults to first image in post if left blank.', 'pib' ); ?></span>
47
+ </p>
48
+ <p>
49
+ <label for="pib_description"><?php _e( 'Description of the pin', 'pib' ); ?>:</label><br />
50
+ <input type="text" class="widefat" name="pib_description" id="pib_description" value="<?php echo esc_attr( $pib_description ); ?>" /><br/>
51
+ <span class="description"><?php _e( 'Defaults to post title if left blank.', 'pib' ); ?></span>
52
+ </p>
53
+ <p>
54
+ <input type="checkbox" name="pib_enable_post_sharing" id="pib_enable_post_sharing" <?php checked( empty( $pib_sharing_checked ) || ($pib_sharing_checked === false) ); ?> />
55
+ <label for="pib_enable_post_sharing"><?php _e( 'Show "Pin It" button ' . $pib_vars['post_meta_message'] . ' on this post/page', 'pib' ); ?></label>
56
+ </p>
57
+ <p class="description">
58
+ <?php _e( 'If checked displays the button ' . $pib_vars['post_meta_message'] . ' for this post (if Individual Posts selected) or this page (if Individual Pages selected) in the main "Pin It" button settings.', 'pib' ); ?>
59
+ </p>
60
+ <p class="description">
61
+ <?php _e( 'If unchecked the button ' . $pib_vars['post_meta_message'] . ' will always be hidden for this post/page.', 'pib' ); ?>
62
+ </p>
63
+
64
+ <?php
65
+ // Now using an action to easily add more post meta options
66
+ do_action( 'pib_post_meta_options' );
67
+ ?>
68
+
69
+ <input type="hidden" name="pib_sharing_status_hidden" value="1" />
views/public.php CHANGED
@@ -1,265 +1,300 @@
1
- <?php
2
-
3
- /**
4
- * Represents the view for the public-facing component of the plugin.
5
- *
6
- * @package PIB
7
- * @subpackage Views
8
- * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
- */
10
-
11
- // Exit if accessed directly.
12
- if ( ! defined( 'ABSPATH' ) ) {
13
- exit;
14
- }
15
-
16
-
17
- /**
18
- * Add Custom CSS.
19
- *
20
- * @since 2.0.0
21
- */
22
- function pib_add_custom_css() {
23
- global $pib_options;
24
-
25
- if( ! in_array( 'no_buttons', pib_render_button() ) ) {
26
- // Only add the custom CSS if it actually exists.
27
- if ( ! empty( $pib_options['custom_css'] ) ) {
28
- $custom_css = trim( $pib_options['custom_css'] );
29
-
30
- echo "\n" .
31
- '<style type="text/css">' . "\n" .
32
- $custom_css . "\n" . // Render custom CSS.
33
- '</style>' . "\n";
34
- }
35
- }
36
- }
37
- add_action( 'wp_head', 'pib_add_custom_css' );
38
-
39
-
40
- /**
41
- * Function for rendering "Pin It" button base html.
42
- * HTML comes from Pinterest Widget Builder 7/10/2013.
43
- * http://business.pinterest.com/widget-builder/#do_pin_it_button
44
- * Sample HTML from widget builder:
45
- * <a href="//www.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest" data-pin-do="buttonPin" data-pin-config="above">
46
- * <img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
47
- * </a>
48
- *
49
- * @since 2.0.0
50
- */
51
- function pib_button_base( $button_type, $post_url, $image_url, $description, $count_layout, $size, $color, $shape, $show_zero_count = null ) {
52
- global $pib_options;
53
- global $post;
54
- $postID = $post->ID;
55
-
56
- // Use updated backup button image URL from Pinterest.
57
- $btn_img_url = '//assets.pinterest.com/images/pidgets/pin_it_button.png';
58
-
59
- // Add "Pin It" title attribute.
60
- // Also add our own data attribute to track pin it button images.
61
- $inner_btn_html = '<img src="' . $btn_img_url . '" title="Pin It" data-pib-button="true" />';
62
-
63
- // Set data attribute for button style.
64
- if ( $button_type == 'image_selected' )
65
- $data_pin_do = 'buttonPin'; // image pre-selected
66
- else
67
- $data_pin_do = 'buttonBookmark'; // user selects image (default)
68
-
69
- // Set data attribute for count bubble style.
70
- if ( $count_layout == 'horizontal' )
71
- $data_pin_config = 'beside';
72
- elseif ( $count_layout == 'vertical' )
73
- $data_pin_config = 'above';
74
- else
75
- $data_pin_config = 'none';
76
-
77
- // Set post url to current post if still blank.
78
- if ( empty( $post_url ) )
79
- $post_url = get_permalink( $postID );
80
-
81
- // Set image url to first image if still blank.
82
- if ( empty( $image_url ) ) {
83
- // Get url of img and compare width and height.
84
- $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
85
-
86
- // Make sure the was an image match and if not set the image url to be blank
87
- if ( !( 0 == $output || false == $output ) )
88
- $image_url = $matches [1] [0];
89
- else
90
- $image_url = '';
91
- }
92
-
93
- // Set description to post title if still blank.
94
- if ( empty( $description ) )
95
- $description = get_post_field( 'post_title', $postID, 'raw' );
96
-
97
- $utm = '';
98
- $utm_meta = get_post_meta( $post->ID, 'pib_utm_meta', true );
99
-
100
- if( ! empty( $utm_meta ) ) {
101
- $utm = clean_and_encode_utm( $post_url, $utm_meta );
102
- } else if( ! empty( $pib_options['utm_string'] ) ) {
103
- $utm = clean_and_encode_utm( $post_url, $pib_options['utm_string'] );
104
- }
105
-
106
-
107
- // Link href always needs all the parameters in it for the count bubble to work.
108
- // Pinterest points out to use protocol-agnostic URL for popup.
109
-
110
-
111
-
112
- $link_href = '//www.pinterest.com/pin/create/button/' .
113
- '?url=' . rawurlencode( $post_url ) . $utm .
114
- '&media=' . rawurlencode( $image_url ) .
115
- '&description=' . rawurlencode( $description );
116
-
117
- // New options that were added to the widget builder on Pinterest
118
- // the size is different depending on the shape of the button, so first we determine the shape and then set the size
119
- if( $size == 'large' && $shape == 'circular' ) {
120
- $data_pin_size = 'data-pin-height="32" ';
121
- } else {
122
- $data_pin_size = ( $size == 'large' ? 'data-pin-height="28" ' : ' ' );
123
- }
124
-
125
- $data_pin_color = ( ! empty( $color ) ? 'data-pin-color="' . $color . '" ' : ' ' );
126
- $data_pin_shape = ( $shape == 'circular' ? 'data-pin-shape="round" ' : ' ' );
127
-
128
- // Use new data-pin-zero option to show count bubbles even on pages that have 0 pins
129
- // check if show_zero_count parameter is set and turn on the zero count if it is true
130
- if( $show_zero_count !== null ) {
131
- $display_zero = ( ( $show_zero_count == 'true' ) ? 'data-pin-zero="true" ' : ' ' );
132
- } else {
133
- // Check main settings option and set accordingly
134
- $display_zero = ( ! empty( $pib_options['show_zero_count'] ) ? 'data-pin-zero="true" ' : ' ' );
135
- }
136
-
137
- // Full link html with data attributes.
138
- // Add rel="nobox" to prevent lightbox popup.
139
- $link_html = '<a href="' . $link_href . '" ' .
140
- 'data-pin-do="' . $data_pin_do . '" ' .
141
- 'data-pin-config="' . $data_pin_config . '" ' .
142
- $data_pin_size .
143
- $data_pin_color .
144
- $display_zero .
145
- $data_pin_shape .
146
- 'rel="nobox">' .
147
- $inner_btn_html . '</a>';
148
-
149
- return $link_html;
150
- }
151
-
152
- /**
153
- * Button HTML to render for pages, posts, and excerpts.
154
- *
155
- * @since 2.0.0
156
- *
157
- */
158
- function pib_button_html( $image_url = '', $button_type = '' ) {
159
- global $pib_options;
160
- global $post;
161
- $postID = $post->ID;
162
-
163
- // Return nothing if sharing disabled on current post.
164
- if ( get_post_meta( $postID, 'pib_sharing_disabled', 1 ) )
165
- return '';
166
-
167
- // Set post url, image url and description from current post meta.
168
- // It'll leave them blank if there isn't any meta.
169
- $post_url = get_post_meta( $postID, 'pib_url_of_webpage', true );
170
- $description = get_post_meta( $postID, 'pib_description', true );
171
-
172
- if( get_post_meta( $postID, 'pib_url_of_img', true ) )
173
- $image_url = get_post_meta( $postID, 'pib_url_of_img', true );
174
-
175
- $count_layout = $pib_options['count_layout'];
176
-
177
- $size = ( ! empty( $pib_options['data_pin_size'] ) ? $pib_options['data_pin_size'] : '' );
178
- $color = ( ! empty( $pib_options['data_pin_color'] ) ? $pib_options['data_pin_color'] : '' );
179
- $shape = ( ! empty( $pib_options['data_pin_shape'] ) ? $pib_options['data_pin_shape'] : '' );
180
-
181
- if( empty( $button_type ) ) {
182
- $button_type = $pib_options['button_type'];
183
- }
184
-
185
- $base_btn = pib_button_base( $button_type, $post_url, $image_url, $description, $count_layout, $size, $color, $shape );
186
-
187
- // Don't wrap with div if using other sharing buttons or "remove div" is checked.
188
- if ( ! empty( $pib_options['remove_div'] ) )
189
- $html = $base_btn;
190
- else
191
- $html = '<div class="pin-it-btn-wrapper">' . $base_btn . '</div>'; // Surround with div tag
192
-
193
-
194
- $before_html = '';
195
- $after_html = '';
196
-
197
- $before_html = apply_filters( 'pib_button_before', $before_html );
198
- $html = apply_filters( 'pib_button_html', $html );
199
- $after_html = apply_filters( 'pib_button_after', $after_html );
200
-
201
-
202
- return $before_html . $html . $after_html;
203
- }
204
-
205
- /**
206
- * Render button HTML on pages with regular content.
207
- *
208
- * @since 2.0.0
209
- *
210
- */
211
- function pib_render_content( $content ) {
212
- global $pib_options;
213
- global $post;
214
-
215
- if( ! is_main_query() )
216
- return $content;
217
-
218
- //Determine if button displayed on current page from main admin settings
219
- if ( in_array( 'button', pib_render_button() ) ) {
220
- if ( ! empty( $pib_options['post_page_placement']['display_above_content'] ) ) {
221
- $content = pib_button_html() . $content;
222
- }
223
- if ( ! empty( $pib_options['post_page_placement']['display_below_content'] ) ) {
224
- $content .= pib_button_html();
225
- }
226
- }
227
-
228
- return $content;
229
- }
230
- add_filter( 'the_content', 'pib_render_content', 100 );
231
-
232
- /**
233
- * Render button HTML on pages with excerpts if option checked.
234
- *
235
- * @since 2.0.0
236
- *
237
- */
238
- function pib_render_content_excerpt( $content ) {
239
- global $pib_options;
240
- global $post;
241
-
242
- if( ! is_main_query() )
243
- return $content;
244
-
245
- if ( ! empty( $pib_options['post_page_placement']['display_on_post_excerpts'] ) ) {
246
- if (
247
- ( is_home() && ( ! empty( $pib_options['post_page_types']['display_home_page'] ) ) ) ||
248
- ( is_front_page() && ( ! empty( $pib_options['post_page_types']['display_front_page'] ) ) )
249
- ) {
250
- if ( ! empty( $pib_options['post_page_placement']['display_above_content'] ) ) {
251
- $content = pib_button_html() . $content;
252
- }
253
- if ( ! empty( $pib_options['post_page_placement']['display_below_content'] ) ) {
254
- $content .= pib_button_html();
255
- }
256
- }
257
-
258
- }
259
-
260
- return $content;
261
- }
262
- add_filter( 'the_excerpt', 'pib_render_content_excerpt', 100 );
263
-
264
-
265
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Represents the view for the public-facing component of the plugin.
5
+ *
6
+ * @package PIB
7
+ * @subpackage Views
8
+ * @author Phil Derksen <pderksen@gmail.com>, Nick Young <mycorpweb@gmail.com>
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+
17
+ /**
18
+ * Add Custom CSS.
19
+ *
20
+ * @since 2.0.0
21
+ */
22
+ function pib_add_custom_css() {
23
+ global $pib_options;
24
+
25
+ if( ! in_array( 'no_buttons', pib_render_button() ) ) {
26
+ // Only add the custom CSS if it actually exists.
27
+ if ( ! empty( $pib_options['custom_css'] ) ) {
28
+ $custom_css = trim( $pib_options['custom_css'] );
29
+
30
+ echo "\n" .
31
+ '<style type="text/css">' . "\n" .
32
+ $custom_css . "\n" . // Render custom CSS.
33
+ '</style>' . "\n";
34
+ }
35
+ }
36
+ }
37
+ add_action( 'wp_head', 'pib_add_custom_css' );
38
+
39
+
40
+ /**
41
+ * Function for rendering "Pin It" button base html.
42
+ * HTML comes from Pinterest Widget Builder 7/10/2013.
43
+ * http://business.pinterest.com/widget-builder/#do_pin_it_button
44
+ * Sample HTML from widget builder:
45
+ * <a href="//www.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest" data-pin-do="buttonPin" data-pin-config="above">
46
+ * <img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
47
+ * </a>
48
+ *
49
+ * @since 2.0.0
50
+ */
51
+ function pib_button_base( $button_type, $post_url, $image_url, $description, $count_layout, $size, $color, $shape, $show_zero_count = null ) {
52
+ global $pib_options;
53
+ global $post;
54
+ $postID = $post->ID;
55
+
56
+ // Use updated backup button image URL from Pinterest.
57
+ $btn_img_url = '//assets.pinterest.com/images/pidgets/pin_it_button.png';
58
+
59
+ // Add "Pin It" title attribute.
60
+ // Also add our own data attribute to track pin it button images.
61
+ $inner_btn_html = '<img src="' . $btn_img_url . '" title="Pin It" data-pib-button="true" />';
62
+
63
+ // Set data attribute for button style.
64
+ if ( $button_type == 'image_selected' ) {
65
+ $data_pin_do = 'buttonPin'; // image pre-selected
66
+ }
67
+ else {
68
+ $data_pin_do = 'buttonBookmark'; // user selects image (default)
69
+ }
70
+
71
+ // Set data attribute for count bubble style.
72
+ if ( $count_layout == 'horizontal' ) {
73
+ $data_pin_config = 'beside';
74
+ } elseif ( $count_layout == 'vertical' ) {
75
+ $data_pin_config = 'above';
76
+ } else {
77
+ $data_pin_config = 'none';
78
+ }
79
+
80
+ // Set post url to current post if still blank.
81
+ if ( empty( $post_url ) ) {
82
+ $post_url = get_permalink( $postID );
83
+ }
84
+
85
+ // Set image url to first image if still blank.
86
+ if ( empty( $image_url ) ) {
87
+ // Get url of img and compare width and height.
88
+ $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
89
+
90
+ // Make sure the was an image match and if not set the image url to be blank
91
+ if ( !( 0 == $output || false == $output ) )
92
+ $image_url = $matches [1] [0];
93
+ else
94
+ $image_url = '';
95
+ }
96
+
97
+ // Set description to post title if still blank.
98
+ if ( empty( $description ) ) {
99
+ $description = get_post_field( 'post_title', $postID, 'raw' );
100
+ }
101
+
102
+ // Show the character entities as their printable characters.
103
+ $description = html_entity_decode( $description, ENT_QUOTES );
104
+
105
+ $utm = '';
106
+ $utm_meta = get_post_meta( $post->ID, 'pib_utm_meta', true );
107
+
108
+ if( ! empty( $utm_meta ) ) {
109
+ $utm = clean_and_encode_utm( $post_url, $utm_meta );
110
+ } else if( ! empty( $pib_options['utm_string'] ) ) {
111
+ $utm = clean_and_encode_utm( $post_url, $pib_options['utm_string'] );
112
+ }
113
+
114
+ $dom = new simple_html_dom();
115
+
116
+ $dom->load( $post->post_content, true, false );
117
+
118
+ $img = '';
119
+ $has_full = false;
120
+
121
+ $img = $dom->find('img[src="' . $image_url . '"]');
122
+
123
+ foreach( $img as $i ) {
124
+ $imgParent = $i->parent();
125
+
126
+ if( $imgParent->tag == 'a' ) {
127
+ // We want to make sure the parent <a> tag is linking to an image so we get its filetype
128
+ $href = wp_check_filetype( $imgParent->href );
129
+
130
+ // Only show if the filetype being linked to comes back as any "image" MIME type
131
+ // Should work with NextGen galleries also.
132
+ if( strpos( $href['type'], 'image' ) !== false ) {
133
+ $has_full = true;
134
+ $img = $imgParent->href;
135
+ }
136
+ }
137
+ }
138
+
139
+ if( $has_full ) {
140
+ $image_url = $img;
141
+ }
142
+
143
+
144
+ // Link href always needs all the parameters in it for the count bubble to work.
145
+ // Pinterest points out to use protocol-agnostic URL for popup.
146
+
147
+ $link_href = '//www.pinterest.com/pin/create/button/' .
148
+ '?url=' . rawurlencode( $post_url ) . $utm .
149
+ '&media=' . rawurlencode( $image_url ) .
150
+ '&description=' . rawurlencode( $description );
151
+
152
+ // New options that were added to the widget builder on Pinterest
153
+ // the size is different depending on the shape of the button, so first we determine the shape and then set the size
154
+ if( $size == 'large' && $shape == 'circular' ) {
155
+ $data_pin_size = 'data-pin-height="32" ';
156
+ } else {
157
+ $data_pin_size = ( $size == 'large' ? 'data-pin-height="28" ' : ' ' );
158
+ }
159
+
160
+ $data_pin_color = ( ! empty( $color ) ? 'data-pin-color="' . $color . '" ' : ' ' );
161
+ $data_pin_shape = ( $shape == 'circular' ? 'data-pin-shape="round" ' : ' ' );
162
+
163
+ // Use new data-pin-zero option to show count bubbles even on pages that have 0 pins
164
+ // check if show_zero_count parameter is set and turn on the zero count if it is true
165
+ if( $show_zero_count !== null ) {
166
+ $display_zero = ( ( $show_zero_count == 'true' ) ? 'data-pin-zero="true" ' : ' ' );
167
+ } else {
168
+ // Check main settings option and set accordingly
169
+ $display_zero = ( ! empty( $pib_options['show_zero_count'] ) ? 'data-pin-zero="true" ' : ' ' );
170
+ }
171
+
172
+ // Full link html with data attributes.
173
+ // Add rel="nobox" to prevent lightbox popup.
174
+ $link_html = '<a href="' . $link_href . '" ' .
175
+ 'data-pin-do="' . $data_pin_do . '" ' .
176
+ 'data-pin-config="' . $data_pin_config . '" ' .
177
+ $data_pin_size .
178
+ $data_pin_color .
179
+ $display_zero .
180
+ $data_pin_shape .
181
+ 'rel="nobox">' .
182
+ $inner_btn_html . '</a>';
183
+
184
+ return $link_html;
185
+ }
186
+
187
+ /**
188
+ * Button HTML to render for pages, posts, and excerpts.
189
+ *
190
+ * @since 2.0.0
191
+ *
192
+ */
193
+ function pib_button_html( $image_url = '', $button_type = '' ) {
194
+ global $pib_options;
195
+ global $post;
196
+ $postID = $post->ID;
197
+
198
+ // Return nothing if sharing disabled on current post.
199
+ if ( get_post_meta( $postID, 'pib_sharing_disabled', 1 ) )
200
+ return '';
201
+
202
+ // Set post url, image url and description from current post meta.
203
+ // It'll leave them blank if there isn't any meta.
204
+ $post_url = get_post_meta( $postID, 'pib_url_of_webpage', true );
205
+ $description = get_post_meta( $postID, 'pib_description', true );
206
+
207
+ if( get_post_meta( $postID, 'pib_url_of_img', true ) )
208
+ $image_url = get_post_meta( $postID, 'pib_url_of_img', true );
209
+
210
+ $count_layout = $pib_options['count_layout'];
211
+
212
+ $size = ( ! empty( $pib_options['data_pin_size'] ) ? $pib_options['data_pin_size'] : '' );
213
+ $color = ( ! empty( $pib_options['data_pin_color'] ) ? $pib_options['data_pin_color'] : '' );
214
+ $shape = ( ! empty( $pib_options['data_pin_shape'] ) ? $pib_options['data_pin_shape'] : '' );
215
+
216
+ if( empty( $button_type ) ) {
217
+ $button_type = $pib_options['button_type'];
218
+ }
219
+
220
+ $base_btn = pib_button_base( $button_type, $post_url, $image_url, $description, $count_layout, $size, $color, $shape );
221
+
222
+ // Don't wrap with div if using other sharing buttons or "remove div" is checked.
223
+ if ( ! empty( $pib_options['remove_div'] ) )
224
+ $html = $base_btn;
225
+ else
226
+ $html = '<div class="pin-it-btn-wrapper">' . $base_btn . '</div>'; // Surround with div tag
227
+
228
+
229
+ $before_html = '';
230
+ $after_html = '';
231
+
232
+ $before_html = apply_filters( 'pib_button_before', $before_html );
233
+ $html = apply_filters( 'pib_button_html', $html );
234
+ $after_html = apply_filters( 'pib_button_after', $after_html );
235
+
236
+
237
+ return $before_html . $html . $after_html;
238
+ }
239
+
240
+ /**
241
+ * Render button HTML on pages with regular content.
242
+ *
243
+ * @since 2.0.0
244
+ *
245
+ */
246
+ function pib_render_content( $content ) {
247
+ global $pib_options;
248
+ global $post;
249
+
250
+ if( ! is_main_query() )
251
+ return $content;
252
+
253
+ //Determine if button displayed on current page from main admin settings
254
+ if ( in_array( 'button', pib_render_button() ) ) {
255
+ if ( ! empty( $pib_options['post_page_placement']['display_above_content'] ) ) {
256
+ $content = pib_button_html() . $content;
257
+ }
258
+ if ( ! empty( $pib_options['post_page_placement']['display_below_content'] ) ) {
259
+ $content .= pib_button_html();
260
+ }
261
+ }
262
+
263
+ return $content;
264
+ }
265
+ add_filter( 'the_content', 'pib_render_content', 100 );
266
+
267
+ /**
268
+ * Render button HTML on pages with excerpts if option checked.
269
+ *
270
+ * @since 2.0.0
271
+ *
272
+ */
273
+ function pib_render_content_excerpt( $content ) {
274
+ global $pib_options;
275
+ global $post;
276
+
277
+ if( ! is_main_query() )
278
+ return $content;
279
+
280
+ if ( ! empty( $pib_options['post_page_placement']['display_on_post_excerpts'] ) ) {
281
+ if (
282
+ ( is_home() && ( ! empty( $pib_options['post_page_types']['display_home_page'] ) ) ) ||
283
+ ( is_front_page() && ( ! empty( $pib_options['post_page_types']['display_front_page'] ) ) )
284
+ ) {
285
+ if ( ! empty( $pib_options['post_page_placement']['display_above_content'] ) ) {
286
+ $content = pib_button_html() . $content;
287
+ }
288
+ if ( ! empty( $pib_options['post_page_placement']['display_below_content'] ) ) {
289
+ $content .= pib_button_html();
290
+ }
291
+ }
292
+
293
+ }
294
+
295
+ return $content;
296
+ }
297
+ add_filter( 'the_excerpt', 'pib_render_content_excerpt', 100 );
298
+
299
+
300
+