jQuery Pin It Button for Images - Version 0.9.1

Version Description

  • Released 2013-02-12
  • Bug fixed: resizing images when their dimensions are larger than the container they're in
  • Bug fixed: plugin not working when jQuery added multiple times
  • Bug fixed: wrong image url when images are lazy-loaded
Download this release

Release Info

Developer mrsztuczkens
Plugin Icon wp plugin jQuery Pin It Button for Images
Version 0.9.1
Comparing to
See all releases

Code changes from version 0.9 to 0.9.1

jpibfi-admin.php CHANGED
@@ -1,164 +1,260 @@
1
  <?php
2
- if (!empty($_SERVER['SCRIPT_FILENAME']) && 'jquery-pin-it-button-for-images.php' == basename($_SERVER['SCRIPT_FILENAME']))
3
- die ('Stop! Hammer time!'); //settings file shouldn't be accessed directly
4
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  <div class="wrap">
7
- <h2>jQuery Pin It Button For Images</h2>
8
-
9
- <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
10
- <?php wp_nonce_field("jpibfi_admin_settings", 'jpibfi_nonce'); ?>
11
- <h3>Plugin settings</h3>
12
-
13
- <table class="settings-table">
14
- <tbody>
15
- <tr>
16
- <th scope="row"><label for="image_selector">Image selector</label></th>
17
- <td>
18
- <input type="text" id="image_selector" name="image_selector"
19
- value="<?php echo esc_attr($dev_options['image_selector']);?>"/>
20
-
21
- <p class="description">jQuery selector for all the images that should have the "Pin it" button. Set
22
- the value to <a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a> if you want
23
- the "Pin it" button to appear only on images in content or <a href="#" class="jpibfi_selector_option">img</a>
24
- to appear on all images on site (including sidebar, header and footer). If you know a thing or
25
- two about jQuery, you might use your own selector. <a href="http://api.jquery.com/category/selectors/" target="_blank">Click here</a> to read
26
- about jQuery selectors.</p>
27
- </td>
28
- </tr>
29
- <tr>
30
- <th scope="row"><label for="disabled_classes">Disabled classes</label></th>
31
- <td>
32
- <div class="left-element">
33
- <textarea id="disabled_classes"
34
- name="disabled_classes" <?php $this->print_error_class( $errors, 'disabled_classes'); ?>><?php echo esc_attr($dev_options['disabled_classes']);?></textarea>
35
- </div>
36
- <?php $this->print_error_div("disabled_classes_error", $errors, "disabled_classes",
37
- "Error. Please change this setting and try submitting again."); ?>
38
-
39
- <p class="description">Pictures with these CSS classes won't show the "Pin it" button. Please
40
- separate multiple classes with semicolons. Spaces are not accepted.</p>
41
- </td>
42
- </tr>
43
- <tr>
44
- <th scope="row"><label for="enabled_classes">Enabled classes</label></th>
45
- <td>
46
- <div class="left-element">
47
- <textarea id="enabled_classes"
48
- name="enabled_classes" <?php $this->print_error_class( $errors, 'enabled_classes'); ?>><?php echo $dev_options['enabled_classes'];?></textarea>
49
- </div>
50
- <?php $this->print_error_div("enabled_classes_error", $errors, "enabled_classes",
51
- "Error. Please change this setting and try submitting again."); ?>
52
-
53
- <p class="description">Pictures with these CSS classes will show the "Pin it" button. Please
54
- separate multiple classes with semicolons. If this field is empty, images with any (besides
55
- disabled ones) classes will show the Pin It button.</p>
56
- </td>
57
- </tr>
58
- <tr>
59
- <th scope="row"><label for="description_option">Description source</label></th>
60
- <td>
61
- <select id="description_option" name="description_option">
62
- <option value="1" <?php if ("1" == $dev_options['description_option']) echo "selected='selected'"; ?>>
63
- Page title
64
- </option>
65
- <option value="2" <?php if ("2" == $dev_options['description_option']) echo "selected='selected'"; ?>>
66
- Page description
67
- </option>
68
- <option value="3" <?php if ("3" == $dev_options['description_option']) echo "selected='selected'"; ?>>
69
- Picture title or alt attributes
70
- </option>
71
- </select>
72
-
73
- <p class="description">From where the Pinterest message should be taken.</p>
74
- </td>
75
- </tr>
76
- <tr>
77
- <th scope="row"><label for="compatibility_mode">Transparency</label></th>
78
- <td>
79
- <select name="compatibility_mode" id="compatibility_mode">
80
- <option value="0" <?php echo "0" == $dev_options['compatibility_mode'] ? "selected='selected'" : "";?>>
81
- Standard mode
82
- </option>
83
- <option value="1" <?php echo "1" == $dev_options['compatibility_mode'] ? "selected='selected'" : "";?>>
84
- IE7 Compatibility mode
85
- </option>
86
- </select>
87
-
88
- <p id="standard_mode_transparency" <?php echo "1" == $dev_options['compatibility_mode'] ? "style='display:none'" : "";?>>
89
- <label for="standard_transparency">Choose transparency (between 0.00 and 1.00)</label><br/>
90
- <input type="text" id="standard_transparency" name="standard_transparency"
91
- value="<?php echo $dev_options['transparency_value'];?>" <?php $this->print_error_class( $errors, 'transparency_value'); ?>/>
92
-
93
- <?php $this->print_error_div("standard_transparency_error", $errors, "transparency_value",
94
- "The number is not valid. Please change the value and try submitting again."); ?>
95
-
96
- </p>
97
- <p id="compatibility_mode_transparency" <?php echo "0" == $dev_options['compatibility_mode'] ? "style='display:none'" : "";?>>
98
- <label for="compatibility_transparency">Choose transparency</label><br/>
99
- <select name="compatibility_transparency" id="compatibility_transparency">
100
- <?php for ($i = 0; $i <= 1; $i += 0.1): ?>
101
- <option value="<?php echo $i;?>" <?php if (round($i, 1) == round($dev_options['transparency_value'], 1)) echo "selected='selected'"; ?>>
102
- <?php echo $i;?>
103
- </option>
104
- <?php endfor; ?>
105
- </select>
106
- </p>
107
- <p class="description">If you want the plugin to work properly on IE7, meaning the image will become
108
- transparent on hover, you need to use IE7 Compatibility mode.</p>
109
- </td>
110
- </tr>
111
- <tr>
112
- <th scope="row"><label>Use custom Pinterest button</label></th>
113
- <td>
114
- <input type="checkbox" id="use_custom_image" name="use_custom_image" value="1" <?php echo "1" == $dev_options["use_custom_image"] ? "checked='checked'" : "" ?> />
115
- <label class="chbox-label" for="use_custom_image">Use custom image</label><br/>
116
-
117
- <p><label for="custom_image_url">URL address of the image</label><br/>
118
- <input type="text" id="custom_image_url" name="custom_image_url" value="<?php echo $dev_options["custom_image_url"]; ?>" />
119
- </p>
120
-
121
- <div class="left-element" style="clear:both;"><label for="custom_image_height">Height of the image (in pixels)</label><br/>
122
- <input type="text" id="custom_image_height" name="custom_image_height" value="<?php echo $dev_options["custom_image_height"]; ?>"
123
- <?php $this->print_error_class( $errors, 'custom_image_height'); ?> />
124
- </div>
125
- <?php $this->print_error_div("custom_image_height_error", $errors, "custom_image_height",
126
- "Must be either blank or a number"); ?>
127
-
128
- <div class="left-element" style="clear:both;"><label for="custom_image_width">Width of the image (in pixels)</label><br/>
129
- <input type="text" id="custom_image_width" name="custom_image_width" value="<?php echo $dev_options["custom_image_width"]; ?>"
130
- <?php $this->print_error_class( $errors, 'custom_image_width'); ?> />
131
- </div>
132
- <?php $this->print_error_div("custom_image_width_error", $errors, "custom_image_width",
133
- "Must be either blank or a number"); ?>
134
-
135
- <p class="description">Check the <b>Use custom image</b> checkbox, specify image's URL, height and width to use your own Pinterest button design.</p>
136
- </td>
137
- </tr>
138
- <tr>
139
- <th scope="row"><label>On which pages the "Pin it" button should be shown</label></th>
140
- <td>
141
- <input type="checkbox" id="on_home"
142
- name="on_home" <?php echo "1" == $advanced_dev_options['on_home'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_home"> Home page</label><br/>
143
- <input type="checkbox" id="on_page"
144
- name="on_page" <?php echo "1" == $advanced_dev_options['on_page'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_page"> Pages</label><br/>
145
- <input type="checkbox" id="on_single"
146
- name="on_single" <?php echo "1" == $advanced_dev_options['on_single'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_single"> Single posts</label><br/>
147
- <input type="checkbox" id="on_category"
148
- name="on_category" <?php echo "1" == $advanced_dev_options['on_category'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_category"> Category pages</label>
149
-
150
- <p class="description">Check on which pages you want the Pinterest button to show up.</p>
151
- </td>
152
- </tr>
153
- <tr>
154
- <th scope="row"></th>
155
- <td>
156
- <input id="submit_form" type="submit" style="padding:7px; float:right;"
157
- name="update_jQuery_Pin_It_Button_For_Images"
158
- value="<?php _e('Update Settings', 'jQuery_Pin_It_Button_For_Images') ?>"/>
159
- </td>
160
- </tr>
161
- </tbody>
162
- </table>
163
- </form>
164
- </div>
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ if ( ! function_exists( 'add_action' ) ) {
3
+ echo "Hi there! I'm just a plugin, not much I can do when called directly.";
4
+ exit;
5
+ }
6
+
7
+ require_once( "jpibfi-validation.php" );
8
+
9
+ //HTML HELPERS
10
+
11
+ function jpibfi_print_error_class( $error_array, $field_name ) {
12
+ if ( ! empty( $error_array ) && array_key_exists( $field_name, $error_array ) )
13
+ echo "class='error-border'";
14
+ }
15
+
16
+ function jpibfi_print_error_div( $div_id, $error_array, $field_name, $message ) {
17
+ $display_message = "";
18
+ if ( ! empty( $error_array ) && array_key_exists( $field_name, $error_array ) )
19
+ $display_message = "style='display:block;'";
20
+ printf( '<div id="%s" class="error-info" %s>%s</div>', $div_id, $display_message, $message );
21
+ }
22
+
23
+ //END HTML HELPERS
24
+
25
+ //Prints out the admin page
26
+ function jpibfi_print_admin_page() {
27
+ global $jpibfi_admin_basic_options_name;
28
+ global $jpibfi_admin_advanced_options_name;
29
+
30
+ $dev_options = jpibfi_get_basic_options();
31
+ $advanced_dev_options = jpibfi_get_advanced_options();
32
+
33
+ $errors = array();
34
+
35
+ if ( isset( $_POST['update_jQuery_Pin_It_Button_For_Images'] ) ) {
36
+ //security check
37
+ if ( ! wp_verify_nonce( $_POST['jpibfi_nonce'], 'jpibfi_admin_settings' ) )
38
+ die( 'Security alert' );
39
+
40
+
41
+
42
+ if ( ! jpibfi_contains_css_class_names_or_empty( $_POST['disabled_classes'] ) )
43
+ $errors['disabled_classes'] = true;
44
+
45
+ if ( ! jpibfi_contains_css_class_names_or_empty( $_POST['enabled_classes'] ) )
46
+ $errors['enabled_classes'] = true;
47
+
48
+ if ( ! jpibfi_is_numeric_or_empty( $_POST['custom_image_height'] ) )
49
+ $errors['custom_image_height'] = true;
50
+
51
+ if ( ! jpibfi_is_numeric_or_empty( $_POST['custom_image_width'] ) )
52
+ $errors['custom_image_width'] = true;
53
+
54
+ //rewrite settings that came from the POST request
55
+ $dev_options['image_selector'] = sanitize_text_field( $_POST['image_selector'] );
56
+ $dev_options['compatibility_mode'] = $_POST['compatibility_mode'] == '1' ? '1' : '0';
57
+ $dev_options['transparency_value'] =
58
+ $dev_options['compatibility_mode'] == '0' ? $_POST['standard_transparency'] : $_POST['compatibility_transparency'];
59
+ $dev_options['disabled_classes'] = $_POST['disabled_classes'];
60
+ $dev_options['enabled_classes'] = $_POST['enabled_classes'];
61
+ $dev_options['description_option'] = $_POST['description_option'];
62
+
63
+ $dev_options['use_custom_image'] = $_POST['use_custom_image'] == "1" ? "1" : "0";
64
+ $dev_options['custom_image_url'] = $_POST['custom_image_url'];
65
+ $dev_options['custom_image_height'] = $_POST['custom_image_height'];
66
+ $dev_options['custom_image_width'] = $_POST['custom_image_width'];
67
+
68
 
69
+ if ( $dev_options['compatibility_mode'] == '0' )
70
+ if ( ! is_numeric( $dev_options['transparency_value'] ) || ( $dev_options['transparency_value'] < 0.0 ) || ( $dev_options['transparency_value'] > 1.0 ) )
71
+ $errors['transparency_value'] = true;
72
+
73
+ $advanced_dev_options['on_home'] = $_POST['on_home'] == '1' ? '1' : '0';
74
+ $advanced_dev_options['on_page'] = $_POST['on_page'] == '1' ? '1' : '0';
75
+ $advanced_dev_options['on_single'] = $_POST['on_single'] == '1' ? '1' : '0';
76
+ $advanced_dev_options['on_category'] = $_POST['on_category'] == '1' ? '1' : '0';
77
+
78
+ if ( 0 == count( $errors ) ) { //save only if there are no errors
79
+ update_option( $jpibfi_admin_basic_options_name, $dev_options );
80
+ update_option( $jpibfi_admin_advanced_options_name, $advanced_dev_options );
81
+ ?>
82
+ <p class="jpibfi-success-message"><?php _e( "Settings Updated.", "jpibfi" );?></p>
83
+ <?php
84
+ }
85
+ else { //otherwise inform that there are some errors
86
+ ?>
87
+ <p class='jpibfi-error-message'><?php _e( "Error. Settings not updated. Look for details below.", "jpibfi" ); ?></p>
88
+ <?php
89
+ }
90
+ }
91
+ ?>
92
  <div class="wrap">
93
+ <h2>jQuery Pin It Button For Images</h2>
94
+
95
+ <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
96
+ <?php wp_nonce_field( "jpibfi_admin_settings", 'jpibfi_nonce' ); ?>
97
+ <h3>Plugin settings</h3>
98
+
99
+ <table class="settings-table">
100
+ <tbody>
101
+ <tr>
102
+ <th scope="row"><label for="image_selector">Image selector</label></th>
103
+ <td>
104
+ <input type="text" id="image_selector" name="image_selector"
105
+ value="<?php echo esc_attr( $dev_options['image_selector'] );?>" />
106
+
107
+ <p class="description">jQuery selector for all the images that should have the "Pin it" button. Set
108
+ the value to <a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a> if you want
109
+ the "Pin it" button to appear only on images in content or
110
+ <a href="#" class="jpibfi_selector_option">img</a>
111
+ to appear on all images on site (including sidebar, header and footer). If you know a thing or
112
+ two about jQuery, you might use your own selector.
113
+ <a href="http://api.jquery.com/category/selectors/" target="_blank">Click here</a> to read
114
+ about jQuery selectors.</p>
115
+ </td>
116
+ </tr>
117
+ <tr>
118
+ <th scope="row"><label for="disabled_classes">Disabled classes</label></th>
119
+ <td>
120
+ <div class="left-element">
121
+ <textarea id="disabled_classes"
122
+ name="disabled_classes" <?php jpibfi_print_error_class( $errors, 'disabled_classes' ); ?>><?php echo esc_attr( $dev_options['disabled_classes'] );?></textarea>
123
+ </div>
124
+ <?php jpibfi_print_error_div( "disabled_classes_error", $errors, "disabled_classes",
125
+ "Error. Please change this setting and try submitting again." ); ?>
126
+
127
+ <p class="description">Pictures with these CSS classes won't show the "Pin it" button. Please
128
+ separate multiple classes with semicolons. Spaces are not accepted.</p>
129
+ </td>
130
+ </tr>
131
+ <tr>
132
+ <th scope="row"><label for="enabled_classes">Enabled classes</label></th>
133
+ <td>
134
+ <div class="left-element">
135
+ <textarea id="enabled_classes"
136
+ name="enabled_classes" <?php jpibfi_print_error_class( $errors, 'enabled_classes' ); ?>><?php echo $dev_options['enabled_classes'];?></textarea>
137
+ </div>
138
+ <?php jpibfi_print_error_div( "enabled_classes_error", $errors, "enabled_classes",
139
+ "Error. Please change this setting and try submitting again." ); ?>
140
+
141
+ <p class="description">Pictures with these CSS classes will show the "Pin it" button. Please
142
+ separate multiple classes with semicolons. If this field is empty, images with any (besides
143
+ disabled ones) classes will show the Pin It button.</p>
144
+ </td>
145
+ </tr>
146
+ <tr>
147
+ <th scope="row"><label for="description_option">Description source</label></th>
148
+ <td>
149
+ <select id="description_option" name="description_option">
150
+ <option value="1" <?php if ( "1" == $dev_options['description_option'] ) echo "selected='selected'"; ?>>
151
+ Page title
152
+ </option>
153
+ <option value="2" <?php if ( "2" == $dev_options['description_option'] ) echo "selected='selected'"; ?>>
154
+ Page description
155
+ </option>
156
+ <option value="3" <?php if ( "3" == $dev_options['description_option'] ) echo "selected='selected'"; ?>>
157
+ Picture title or alt attributes
158
+ </option>
159
+ </select>
160
+
161
+ <p class="description">From where the Pinterest message should be taken.</p>
162
+ </td>
163
+ </tr>
164
+ <tr>
165
+ <th scope="row"><label for="compatibility_mode">Transparency</label></th>
166
+ <td>
167
+ <select name="compatibility_mode" id="compatibility_mode">
168
+ <option value="0" <?php echo "0" == $dev_options['compatibility_mode'] ? "selected='selected'" : "";?>>
169
+ Standard mode
170
+ </option>
171
+ <option value="1" <?php echo "1" == $dev_options['compatibility_mode'] ? "selected='selected'" : "";?>>
172
+ IE7 Compatibility mode
173
+ </option>
174
+ </select>
175
+
176
+ <p id="standard_mode_transparency" <?php echo "1" == $dev_options['compatibility_mode'] ? "style='display:none'" : "";?>>
177
+ <label for="standard_transparency">Choose transparency (between 0.00 and 1.00)</label><br />
178
+ <input type="text" id="standard_transparency" name="standard_transparency"
179
+ value="<?php echo $dev_options['transparency_value'];?>" <?php jpibfi_print_error_class( $errors, 'transparency_value' ); ?>/>
180
+
181
+ <?php jpibfi_print_error_div( "standard_transparency_error", $errors, "transparency_value",
182
+ "The number is not valid. Please change the value and try submitting again." ); ?>
183
+
184
+ </p>
185
+
186
+ <p id="compatibility_mode_transparency" <?php echo "0" == $dev_options['compatibility_mode'] ? "style='display:none'" : "";?>>
187
+ <label for="compatibility_transparency">Choose transparency</label><br />
188
+ <select name="compatibility_transparency" id="compatibility_transparency">
189
+ <?php for ( $i = 0; $i <= 1; $i += 0.1 ): ?>
190
+ <option value="<?php echo $i;?>" <?php if ( round( $i, 1 ) == round( $dev_options['transparency_value'], 1 ) ) echo "selected='selected'"; ?>>
191
+ <?php echo $i;?>
192
+ </option>
193
+ <?php endfor; ?>
194
+ </select>
195
+ </p>
196
+ <p class="description">If you want the plugin to work properly on IE7, meaning the image will become
197
+ transparent on hover, you need to use IE7 Compatibility mode.</p>
198
+ </td>
199
+ </tr>
200
+ <tr>
201
+ <th scope="row"><label>Use custom Pinterest button</label></th>
202
+ <td>
203
+ <input type="checkbox" id="use_custom_image" name="use_custom_image" value="1" <?php echo "1" == $dev_options["use_custom_image"] ? "checked='checked'" : "" ?> />
204
+ <label class="chbox-label" for="use_custom_image">Use custom image</label><br />
205
+
206
+ <p><label for="custom_image_url">URL address of the image</label><br />
207
+ <input type="text" id="custom_image_url" name="custom_image_url" value="<?php echo $dev_options["custom_image_url"]; ?>" />
208
+ </p>
209
+
210
+ <div class="left-element" style="clear:both;">
211
+ <label for="custom_image_height">Height of the image (in pixels)</label><br />
212
+ <input type="text" id="custom_image_height" name="custom_image_height" value="<?php echo $dev_options["custom_image_height"]; ?>"
213
+ <?php jpibfi_print_error_class( $errors, 'custom_image_height' ); ?> />
214
+ </div>
215
+ <?php jpibfi_print_error_div( "custom_image_height_error", $errors, "custom_image_height",
216
+ "Must be either blank or a number" ); ?>
217
+
218
+ <div class="left-element" style="clear:both;">
219
+ <label for="custom_image_width">Width of the image (in pixels)</label><br />
220
+ <input type="text" id="custom_image_width" name="custom_image_width" value="<?php echo $dev_options["custom_image_width"]; ?>"
221
+ <?php jpibfi_print_error_class( $errors, 'custom_image_width' ); ?> />
222
+ </div>
223
+ <?php jpibfi_print_error_div( "custom_image_width_error", $errors, "custom_image_width",
224
+ "Must be either blank or a number" ); ?>
225
+
226
+ <p class="description">Check the
227
+ <b>Use custom image</b> checkbox, specify image's URL, height and width to use your own Pinterest button design.
228
+ </p>
229
+ </td>
230
+ </tr>
231
+ <tr>
232
+ <th scope="row"><label>On which pages the "Pin it" button should be shown</label></th>
233
+ <td>
234
+ <input type="checkbox" id="on_home"
235
+ name="on_home" <?php echo "1" == $advanced_dev_options['on_home'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_home"> Home page</label><br />
236
+ <input type="checkbox" id="on_page"
237
+ name="on_page" <?php echo "1" == $advanced_dev_options['on_page'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_page"> Pages</label><br />
238
+ <input type="checkbox" id="on_single"
239
+ name="on_single" <?php echo "1" == $advanced_dev_options['on_single'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_single"> Single posts</label><br />
240
+ <input type="checkbox" id="on_category"
241
+ name="on_category" <?php echo "1" == $advanced_dev_options['on_category'] ? "checked='checked'" : "";?> value="1" /><label class="chbox-label" for="on_category"> Category pages</label>
242
+
243
+ <p class="description">Check on which pages you want the Pinterest button to show up.</p>
244
+ </td>
245
+ </tr>
246
+ <tr>
247
+ <th scope="row"></th>
248
+ <td>
249
+ <input id="submit_form" type="submit" style="padding:7px; float:right;"
250
+ name="update_jQuery_Pin_It_Button_For_Images"
251
+ value="<?php _e( 'Update Settings', 'jQuery_Pin_It_Button_For_Images' ) ?>" />
252
+ </td>
253
+ </tr>
254
+ </tbody>
255
+ </table>
256
+ </form>
257
+ </div>
258
+ <?php
259
+ }
260
+ ?>
jpibfi-validation.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! function_exists( 'add_action' ) ) {
4
+ echo "Hi there! I'm just a plugin, not much I can do when called directly.";
5
+ exit;
6
+ }
7
+
8
+ function jpibfi_is_string_css_class_name( $class_name ) {
9
+ return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/", $class_name );
10
+ }
11
+
12
+ function jpibfi_contains_css_class_names_or_empty( $str ) {
13
+ if ( strlen( $str ) == 0 )
14
+ return true;
15
+
16
+ $names = explode( ";", $str );
17
+ $only_css_class_names = true;
18
+
19
+ foreach ( $names as $name ) {
20
+ if ( false == jpibfi_is_string_css_class_name( $name ) ) {
21
+ $only_css_class_names = false;
22
+ break;
23
+ }
24
+ }
25
+ return $only_css_class_names;
26
+ }
27
+
28
+ function jpibfi_is_numeric_or_empty( $str ) {
29
+ return ( is_numeric( $str ) || "" === $str );
30
+ }
jquery-pin-it-button-for-images.php CHANGED
@@ -1,449 +1,361 @@
1
  <?php
2
- /*
3
- Plugin Name: jQuery Pin It Button For Images
4
- Plugin URI: http://wordpress.org/extend/plugins/jquery-pin-it-button-for-images/
5
- Description: Highlights images on hover and adds a "Pin It" button over them for easy pinning.
6
- Author: Marcin Skrzypiec
7
- Version: 0.9
8
- Author URI: http://profiles.wordpress.org/mrsztuczkens
9
- */
10
-
11
- if (!empty($_SERVER['SCRIPT_FILENAME']) && 'jquery-pin-it-button-for-images.php' == basename($_SERVER['SCRIPT_FILENAME']))
12
- die ('Stop! Hammer time!'); //Plugin shouldn't be accessed directly
13
-
14
- define("JPIBFI_VERSION", "0.9");
15
-
16
- if (!class_exists("jQuery_Pin_It_Button_For_Images")) {
17
- class jQuery_Pin_It_Button_For_Images {
18
-
19
- public static $admin_basic_options_name = "jptbfi_options";
20
- public static $admin_advanced_options_name = "jptbfi_advanced_options";
21
- public static $post_metadata_name = "jpibfi_meta";
22
- var $description_option_values = array ( '1', '2', '3' );
23
-
24
- //Constructor
25
- function jQuery_Pin_It_Button_For_Images() {}
26
-
27
- //SETTINGS VALIDATION CODE
28
-
29
- function is_string_css_class_name($class_name) {
30
- return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/", $class_name );
31
- }
32
-
33
- function contains_css_class_names_or_empty($str) {
34
- if ( strlen ($str ) == 0 )
35
- return true;
36
-
37
- $names = explode( ";", $str );
38
- $only_css_class_names = true;
39
-
40
- foreach ( $names as $name ) {
41
- if ( false == $this->is_string_css_class_name( $name ) ) {
42
- $only_css_class_names = false;
43
- break;
44
- }
45
- }
46
- return $only_css_class_names;
47
- }
48
 
49
- function is_numeric_or_empty($str) {
50
- return ( is_numeric($str) || "" === $str );
51
- }
52
-
53
- //END SETTINGS VALIDATION CODE
54
-
55
- //HELPERS
56
-
57
- function print_error_class($error_array, $field_name) {
58
- if ( !empty( $error_array ) && array_key_exists( $field_name, $error_array ) )
59
- echo "class='error-border'";
60
- }
61
-
62
- function print_error_div($div_id, $error_array, $field_name, $message) {
63
- $display_message = "";
64
- if ( !empty($error_array) && array_key_exists($field_name, $error_array) )
65
- $display_message = "style='display:block;'";
66
- printf('<div id="%s" class="error-info" %s>%s</div>', $div_id, $display_message, $message);
67
- }
68
-
69
- //END HELPERS
70
-
71
- //Returns an array of basic admin options, updates settings if necessary
72
- function get_basic_options() {
73
- $admin_options = array(
74
- 'image_selector' => 'div.jpibfi_container img',
75
- 'disabled_classes' => 'nopin;wp-smiley',
76
- 'description_option' => $this->description_option_values[0],
77
- 'enabled_classes' => '',
78
- 'compatibility_mode' => '0',
79
- 'transparency_value' => '0.5',
80
- 'use_custom_image' => '0',
81
- 'custom_image_url' => '',
82
- 'custom_image_height'=> '',
83
- 'custom_image_width' => ''
84
- );
85
-
86
- $dev_options = get_option( self::$admin_basic_options_name );
87
-
88
- $changes_in_db = count( $admin_options ) != count ( $dev_options ); //if arrays aren't of the same length, changes in db needed
89
-
90
- //invalid values need to be corrected and saved in db
91
- if ( ! empty( $dev_options ) ) {
92
- foreach ( $dev_options as $key => $option ) {
93
- switch ($key) {
94
- case "image_selector": //no constraints
95
- case "custom_image_url":
96
- $admin_options[$key] = $option;
97
- break;
98
- case "disabled_classes": //contains list of css classes or is empty
99
- case "enabled_classes":
100
- if ( $this->contains_css_class_names_or_empty( $option ) )
101
- $admin_options[$key] = $option;
102
- else
103
- $changes_in_db = true;
104
- break;
105
- case "description_option":
106
- if ( in_array( $option, $this->description_option_values ) )
107
- $admin_options[$key] = $option;
108
- else
109
- $changes_in_db = true;
110
- break;
111
- case "compatibility_mode": //0 or 1 values
112
- case "use_custom_image":
113
- if ( strcmp( $option, '0') != 0 && strcmp( $option, '1') != 0 ) //invalid value in database
114
- $changes_in_db = true;
115
- else
116
- $admin_options[$key] = $option;
117
- break;
118
- case "transparency_value": //between 0 and 1
119
- if ( !is_numeric( $option ) || ( $option < 0 ) || ( $option > 1 ) )
120
- $changes_in_db = true;
121
- else
122
- $admin_options[$key] = $option;
123
- break;
124
- case "custom_image_width": //numeric value or empty
125
- case "custom_image_height":
126
- if ( $this->is_numeric_or_empty( $option ) )
127
- $admin_options[$key] = $option;
128
- else
129
- $changes_in_db = true;
130
- break;
131
- }
132
- }
133
- } else {
134
- $changes_in_db = true;
135
- }
136
-
137
- //if something changed in the database, we need to save it
138
- if ( $changes_in_db )
139
- update_option( self::$admin_basic_options_name, $admin_options );
140
-
141
- return $admin_options;
142
- }//End function get_basic_options()
143
-
144
- //Returns an array of advanced admin options, updates settings if necessary
145
- function get_advanced_options() {
146
- $admin_options = array(
147
- 'on_home' => '1',
148
- 'on_single' => '1',
149
- 'on_page' => '1',
150
- 'on_category' => '1'
151
- );
152
-
153
- $dev_options = get_option( self::$admin_advanced_options_name );
154
- $changes_in_db = count( $admin_options ) != count ( $dev_options ); //if arrays aren't of the same length, changes in db needed
155
-
156
- foreach ( $admin_options as $setting_name => $setting_value ) {
157
- if ( array_key_exists( $setting_name, $dev_options ) )
158
- $admin_options[$setting_name] = $dev_options[$setting_name];
159
- }
160
-
161
- //if something changed in the database, we need to save it
162
- if ( $changes_in_db )
163
- update_option( self::$admin_advanced_options_name, $admin_options );
164
- return $admin_options;
165
- }
166
 
167
- //returns false if plugin shouldn't be added to certain post based on metadata, otherwise true
168
- function add_plugin_to_post( $post_id ){
169
- $post_meta = get_post_meta( $post_id, self::$post_metadata_name, true );
170
- if ( !empty($post_meta) && array_key_exists( 'jpibfi_disable_for_post', $post_meta ) && $post_meta['jpibfi_disable_for_post'] == '1')
171
- return false;
172
- return true;
173
- }
174
-
175
- //Returns true if plugin should be added to a certain page
176
- function add_plugin() {
177
- global $post;
178
- $advanced_settings = $this->get_advanced_options();
179
-
180
- if ( is_front_page() )
181
- return $advanced_settings['on_home'] == "1";
182
- else if ( is_single() )
183
- return $advanced_settings['on_single'] == "1" ? $this->add_plugin_to_post( $post->ID ) : false;
184
- else if ( is_page() )
185
- return $advanced_settings['on_page'] == "1" ? $this->add_plugin_to_post( $post->ID ) : false;
186
- else if ( is_category() )
187
- return $advanced_settings['on_category'] == "1";
188
- return true;
189
- }
190
 
191
- //fire it when activating the plugin - add all necessary db entries
192
- function init_plugin() {
193
- $this->get_basic_options();
194
- $this->get_advanced_options();
195
- }
196
-
197
- //Adds all necessary scripts
198
- function add_plugin_scripts() {
199
- if ( !( $this->add_plugin() ) )
200
- return;
201
-
202
- // Adding my custom js, dependent on jquery
203
- wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.min.js', __FILE__ ), array('jquery'), JPIBFI_VERSION, false );
204
- // Registering my custom style
205
- wp_register_style( 'jquery-pin-it-button-style', plugins_url( '/css/style.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
206
- //Enqueue the style
207
- wp_enqueue_style( 'jquery-pin-it-button-style');
208
- }
209
-
210
- function footer_action() {
211
- if ( !( $this->add_plugin() ) )
212
- return;
213
-
214
- $dev_options = $this->get_basic_options();
215
- $enabled_classes = $dev_options['enabled_classes'] ? ", enabled_classes:'" . $dev_options['enabled_classes'] . "'" : "";
216
-
217
- ?>
218
- <script type="text/javascript">
219
- jQuery(document).ready(function($) {
220
- $('.jpibfi').parent('div').addClass('jpibfi_container');
221
- $('<?php echo $dev_options['image_selector'];?>').pinit({disabled_classes:'<?php echo $dev_options['disabled_classes'];?>',
222
- description_option:'<?php echo $dev_options['description_option'];?>'<?php echo $enabled_classes;?>});
223
- });
224
- </script>
225
- <?php
226
- }
227
-
228
- function print_header_style_action() {
229
- if ( !( $this->add_plugin() ) )
230
- return;
231
-
232
- $dev_options = $this->get_basic_options();
233
-
234
- if ( $dev_options['compatibility_mode'] == '0' )
235
- $css = 'background-color: rgba(255, 255, 255, ' . $dev_options['transparency_value']. ');';
236
- else
237
- $css = "background: url('" .
238
- plugins_url( '/images/transparency/'.
239
- str_replace( '.','_', $dev_options['transparency_value'] ) . '.png', __FILE__) . "') repeat;";
240
-
241
- if ( $dev_options['use_custom_image'] == "1" ) {
242
- $width = $dev_options['custom_image_width'];
243
- $height = $dev_options['custom_image_height'];
244
- $url = $dev_options['custom_image_url'];
245
- } else {
246
- $width = 65;
247
- $height = 41;
248
- $url = plugins_url( '/images/pinit-button.png', __FILE__);
249
- }
250
-
251
- ?>
252
- <style type="text/css">
253
- .pinit .pinit-overlay { <?php echo $css; ?> }
254
- .pinit .pinit-overlay a {
255
- <?php printf('width:%spx; height:%spx; background:transparent url("%s") no-repeat 0 0;',
256
- $width, $height, $url); ?>
257
- }
258
- </style>
259
- <?php
260
- }
261
-
262
- function print_hidden_field_script($content) {
263
- if ( ! $this->add_plugin() )
264
- return $content;
265
- return "<input class='jpibfi' type='hidden' />" . $content;
266
- }
267
-
268
- //ADMIN PAGE CODE
269
-
270
- //add admin scripts
271
- function add_admin_site_scripts() {
272
- wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
273
- wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
274
- wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/admin.js', __FILE__ ), array('jquery'), JPIBFI_VERSION, false );
275
- }
276
-
277
- //Prints out the admin page
278
- function print_admin_page() {
279
- $dev_options = $this->get_basic_options();
280
- $advanced_dev_options = $this->get_advanced_options();
281
-
282
- if ( isset( $_POST['update_jQuery_Pin_It_Button_For_Images']) ) {
283
- //security check
284
- if ( !wp_verify_nonce( $_POST['jpibfi_nonce'], 'jpibfi_admin_settings' ) )
285
- die( 'Security alert');
286
-
287
- $errors = array();
288
-
289
- if ( ! $this->contains_css_class_names_or_empty( $_POST['disabled_classes'] ) )
290
- $errors['disabled_classes'] = true;
291
-
292
- if ( ! $this->contains_css_class_names_or_empty( $_POST['enabled_classes'] ) )
293
- $errors['enabled_classes'] = true;
294
-
295
- if ( !$this->is_numeric_or_empty( $_POST['custom_image_height'] ) )
296
- $errors['custom_image_height'] = true;
297
-
298
- if ( !$this->is_numeric_or_empty( $_POST['custom_image_width'] ) )
299
- $errors['custom_image_width'] = true;
300
-
301
- //rewrite settings that came from the POST request
302
- $dev_options['image_selector'] = sanitize_text_field( $_POST['image_selector'] );
303
- $dev_options['compatibility_mode'] = $_POST['compatibility_mode'] == '1' ? '1' : '0';
304
- $dev_options['transparency_value'] =
305
- $dev_options['compatibility_mode'] =='0' ? $_POST['standard_transparency'] : $_POST['compatibility_transparency'];
306
- $dev_options['disabled_classes'] = $_POST['disabled_classes'];
307
- $dev_options['enabled_classes'] = $_POST['enabled_classes'];
308
- $dev_options['description_option'] = $_POST['description_option'];
309
-
310
- $dev_options['use_custom_image'] = $_POST['use_custom_image'] == "1" ? "1" : "0";
311
- $dev_options['custom_image_url'] = $_POST['custom_image_url'];
312
- $dev_options['custom_image_height'] = $_POST['custom_image_height'];
313
- $dev_options['custom_image_width'] = $_POST['custom_image_width'];
314
-
315
-
316
- if ($dev_options['compatibility_mode'] =='0')
317
- if ( !is_numeric( $dev_options['transparency_value'] ) || ( $dev_options['transparency_value'] < 0.0 ) || ( $dev_options['transparency_value'] > 1.0 ) )
318
- $errors['transparency_value'] = true;
319
-
320
- $advanced_dev_options['on_home'] = $_POST['on_home'] == '1' ? '1' : '0';
321
- $advanced_dev_options['on_page'] = $_POST['on_page'] == '1' ? '1' : '0';
322
- $advanced_dev_options['on_single'] = $_POST['on_single'] == '1' ? '1' : '0';
323
- $advanced_dev_options['on_category'] = $_POST['on_category'] == '1' ? '1' : '0';
324
-
325
- if ( 0 == count( $errors ) ) { //save only if there are no errors
326
- update_option( self::$admin_basic_options_name, $dev_options );
327
- update_option( self::$admin_advanced_options_name, $advanced_dev_options );
328
- ?>
329
- <p class="jpibfi-success-message"><?php _e( "Settings Updated.", "jpibfi" );?></p>
330
- <?php
331
- } else { //otherwise inform that there are some errors
332
- ?>
333
- <p class='jpibfi-error-message'><?php _e("Error. Settings not updated. Look for details below.", "jpibfi" ); ?></p>
334
- <?php
335
- }
336
- }
337
- include_once("jpibfi-admin.php");
338
- }//End function print_admin_page()
339
-
340
- function print_admin_page_action() {
341
- $page = add_options_page( 'jQuery Pin It Button For Images', 'jQuery Pin It Button For Images', 9, basename( __FILE__ ), array( $this, 'print_admin_page' ) );
342
- add_action( 'admin_print_styles-' . $page, array($this, 'add_admin_site_scripts' ) );
343
- }
344
-
345
- function plugin_settings_filter($links) {
346
- $settings_link = '<a href="options-general.php?page=jquery-pin-it-button-for-images.php">Settings</a>';
347
- array_unshift( $links, $settings_link );
348
- return $links;
349
- }
350
-
351
- //END ADMIN PAGE CODE
352
-
353
- //POST EDITOR CODE
354
-
355
- function add_meta_box() {
356
- //for posts
357
- add_meta_box(
358
- 'jpibfi_settings_id', // this is HTML id of the box on edit screen
359
- 'jQuery Pin It Button for Images - Settings', // title of the box
360
- array( $this, 'print_meta_box' ), // function to be called to display the checkboxes, see the function below
361
- 'post', // on which edit screen the box should appear
362
- 'side', // part of page where the box should appear
363
- 'default' // priority of the box
364
- );
365
-
366
- //for pages
367
- add_meta_box(
368
- 'jpibfi_settings_id',
369
- 'jQuery Pin It Button for Images - Settings',
370
- array( $this, 'print_meta_box' ),
371
- 'page',
372
- 'side',
373
- 'default'
374
- );
375
- }
376
 
377
- // display the metabox
378
- function print_meta_box( $post, $metabox ) {
379
- wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' );
380
-
381
- $post_meta = get_post_meta( $post->ID, self::$post_metadata_name, true );
382
- if ( isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1' )
383
- $checked_message = 'checked="checked"';
384
- else
385
- $checked_message = '';
386
-
387
- echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"'
388
- . $checked_message . ' /><label for="jpibfi_disable_for_post"> Disable "Pin it" button for this post (works only on single pages/posts)</label><br />';
389
- }
390
-
391
- function save_meta_data($post_id) {
392
- // check if this isn't an auto save
393
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
394
- return;
395
- // security check = updating possible only using post edit form
396
- if ( !wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
397
- return;
398
- //check user's permissions
399
- if ( !current_user_can( 'edit_post', $post_id ) )
400
- return;
401
-
402
- $post_meta = array( 'jpibfi_disable_for_post' => '0' );
403
- // now store data in custom fields based on checkboxes selected
404
- $post_meta['jpibfi_disable_for_post'] =
405
- isset( $_POST['jpibfi_disable_for_post'] ) && $_POST['jpibfi_disable_for_post'] == '1' ? '1' : '0';
406
-
407
- if ($post_meta['jpibfi_disable_for_post'] == '1')
408
- update_post_meta( $post_id, self::$post_metadata_name, $post_meta );
409
- else
410
- delete_post_meta( $post_id, self::$post_metadata_name );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  }
412
- //END POST EDITOR CODE
413
  }
414
- } //End Class jQuery_Pin_It_Button_For_Images
415
-
416
- if ( class_exists("jQuery_Pin_It_Button_For_Images") )
417
- $jptbfi_instance = new jQuery_Pin_It_Button_For_Images();
418
-
419
- //fire it when the plugin is deleted
420
- function jpibfi_uninstall_plugin() {
421
-
422
- //delete all added options
423
- delete_option(jQuery_Pin_It_Button_For_Images::$admin_basic_options_name);
424
- delete_option(jQuery_Pin_It_Button_For_Images::$admin_advanced_options_name);
425
-
426
- //delete added metadata from all posts
427
- delete_post_meta_by_key(jQuery_Pin_It_Button_For_Images::$post_metadata_name);
428
- }
429
-
430
- //Actions and Filters
431
- if ( isset($jptbfi_instance) ) {
432
- //Register
433
- register_activation_hook( __FILE__, array( &$jptbfi_instance, 'init_plugin' ) );
434
- register_uninstall_hook( __FILE__, 'jpibfi_uninstall_plugin' );
435
- //Actions
436
- add_action( 'wp_enqueue_scripts', array( &$jptbfi_instance, 'add_plugin_scripts' ) );
437
- add_action( 'admin_menu', array( &$jptbfi_instance, 'print_admin_page_action' ) );
438
- add_action( 'wp_footer', array( &$jptbfi_instance, 'footer_action' ) );
439
- add_action( 'wp_head', array( &$jptbfi_instance, 'print_header_style_action' ) );
440
- add_action( 'add_meta_boxes', array( &$jptbfi_instance, 'add_meta_box' ) );
441
- add_action( 'save_post', array( &$jptbfi_instance, 'save_meta_data' ) );
442
-
443
- //Filters
444
- $plugin = plugin_basename( __FILE__ );
445
- add_filter( "plugin_action_links_$plugin", array( &$jptbfi_instance, 'plugin_settings_filter' ) );
446
- add_filter( "the_content", array( &$jptbfi_instance, 'print_hidden_field_script' ) );
447
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
 
449
  ?>
1
  <?php
2
+ /*
3
+ Plugin Name: jQuery Pin It Button For Images
4
+ Plugin URI: http://wordpress.org/extend/plugins/jquery-pin-it-button-for-images/
5
+ Description: Highlights images on hover and adds a "Pin It" button over them for easy pinning.
6
+ Author: Marcin Skrzypiec
7
+ Version: 0.9.1
8
+ Author URI: http://profiles.wordpress.org/mrsztuczkens
9
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ if ( ! function_exists( 'add_action' ) ) {
12
+ echo "Hi there! I'm just a plugin, not much I can do when called directly.";
13
+ exit;
14
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ define( "JPIBFI_VERSION", "0.9.1" );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ require_once( "jpibfi-validation.php" );
19
+ require_once( "jpibfi-admin.php" );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ $jpbfi_description_option_values = array( '1', '2', '3' );
22
+ $jpibfi_admin_basic_options_name = "jptbfi_options";
23
+ $jpibfi_admin_advanced_options_name = "jptbfi_advanced_options";
24
+ $jpibfi_post_metadata_name = "jpibfi_meta";
25
+
26
+
27
+ //Returns an array of basic admin options, updates settings if necessary
28
+ function jpibfi_get_basic_options() {
29
+ global $jpibfi_admin_basic_options_name, $jpbfi_description_option_values;
30
+
31
+ $admin_options = array(
32
+ 'image_selector' => 'div.jpibfi_container img',
33
+ 'disabled_classes' => 'nopin;wp-smiley',
34
+ 'description_option' => $jpbfi_description_option_values[0],
35
+ 'enabled_classes' => '',
36
+ 'compatibility_mode' => '0',
37
+ 'transparency_value' => '0.5',
38
+ 'use_custom_image' => '0',
39
+ 'custom_image_url' => '',
40
+ 'custom_image_height' => '',
41
+ 'custom_image_width' => ''
42
+ );
43
+
44
+ $dev_options = get_option( $jpibfi_admin_basic_options_name );
45
+
46
+ $changes_in_db = count( $admin_options ) != count( $dev_options ); //if arrays aren't of the same length, changes in db needed
47
+
48
+ //invalid values need to be corrected and saved in db
49
+ if ( ! empty( $dev_options ) ) {
50
+ foreach ( $dev_options as $key => $option ) {
51
+ switch ( $key ) {
52
+ case "image_selector": //no constraints
53
+ case "custom_image_url":
54
+ $admin_options[$key] = $option;
55
+ break;
56
+ case "disabled_classes": //contains list of css classes or is empty
57
+ case "enabled_classes":
58
+ if ( jpibfi_contains_css_class_names_or_empty( $option ) )
59
+ $admin_options[$key] = $option;
60
+ else
61
+ $changes_in_db = true;
62
+ break;
63
+ case "description_option":
64
+ if ( in_array( $option, $jpbfi_description_option_values ) )
65
+ $admin_options[$key] = $option;
66
+ else
67
+ $changes_in_db = true;
68
+ break;
69
+ case "compatibility_mode": //0 or 1 values
70
+ case "use_custom_image":
71
+ if ( strcmp( $option, '0' ) != 0 && strcmp( $option, '1' ) != 0 ) //invalid value in database
72
+ $changes_in_db = true;
73
+ else
74
+ $admin_options[$key] = $option;
75
+ break;
76
+ case "transparency_value": //between 0 and 1
77
+ if ( ! is_numeric( $option ) || ( $option < 0 ) || ( $option > 1 ) )
78
+ $changes_in_db = true;
79
+ else
80
+ $admin_options[$key] = $option;
81
+ break;
82
+ case "custom_image_width": //numeric value or empty
83
+ case "custom_image_height":
84
+ if ( jpibfi_is_numeric_or_empty( $option ) )
85
+ $admin_options[$key] = $option;
86
+ else
87
+ $changes_in_db = true;
88
+ break;
89
  }
 
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
+ else {
93
+ $changes_in_db = true;
94
+ }
95
+
96
+ //if something changed in the database, we need to save it
97
+ if ( $changes_in_db )
98
+ update_option( $jpibfi_admin_basic_options_name, $admin_options );
99
+
100
+ return $admin_options;
101
+ }
102
+
103
+ //End function jpibfi_get_basic_options()
104
+
105
+ //Returns an array of advanced admin options, updates settings if necessary
106
+ function jpibfi_get_advanced_options() {
107
+ global $jpibfi_admin_advanced_options_name;
108
+
109
+ $admin_options = array(
110
+ 'on_home' => '1',
111
+ 'on_single' => '1',
112
+ 'on_page' => '1',
113
+ 'on_category' => '1'
114
+ );
115
+
116
+ $dev_options = get_option( $jpibfi_admin_advanced_options_name );
117
+ $changes_in_db = count( $admin_options ) != count( $dev_options ); //if arrays aren't of the same length, changes in db needed
118
+
119
+ foreach ( $admin_options as $setting_name => $setting_value ) {
120
+ if ( array_key_exists( $setting_name, $dev_options ) )
121
+ $admin_options[$setting_name] = $dev_options[$setting_name];
122
+ }
123
+
124
+ //if something changed in the database, we need to save it
125
+ if ( $changes_in_db )
126
+ update_option( $jpibfi_admin_advanced_options_name, $admin_options );
127
+ return $admin_options;
128
+ }
129
+ //
130
+
131
+
132
+ //returns false if plugin shouldn't be added to certain post based on metadata, otherwise true
133
+ function jpibfi_add_plugin_to_post( $post_id ) {
134
+ global $jpibfi_post_metadata_name;
135
+ $post_meta = get_post_meta( $post_id, $jpibfi_post_metadata_name, true );
136
+ if ( ! empty( $post_meta ) && array_key_exists( 'jpibfi_disable_for_post', $post_meta ) && $post_meta['jpibfi_disable_for_post'] == '1' )
137
+ return false;
138
+ return true;
139
+ }
140
+
141
+ //Returns true if plugin should be added to a certain page
142
+ function jpibfi_add_plugin() {
143
+ global $post;
144
+ $advanced_settings = jpibfi_get_advanced_options();
145
+
146
+ if ( is_front_page() )
147
+ return $advanced_settings['on_home'] == "1";
148
+ else if ( is_single() )
149
+ return $advanced_settings['on_single'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
150
+ else if ( is_page() )
151
+ return $advanced_settings['on_page'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
152
+ else if ( is_category() )
153
+ return $advanced_settings['on_category'] == "1";
154
+ return true;
155
+ }
156
+
157
+ //fire it when activating the plugin - add all necessary db entries
158
+ function jpibfi_init_plugin() {
159
+ jpibfi_get_basic_options();
160
+ jpibfi_get_advanced_options();
161
+ }
162
+
163
+ //Adds all necessary scripts
164
+ function jpibfi_add_plugin_scripts() {
165
+ if ( ! ( jpibfi_add_plugin() ) )
166
+ return;
167
+ // Adding my custom js, dependent on jquery
168
+ wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.min.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
169
+ // Registering my custom style
170
+ wp_register_style( 'jquery-pin-it-button-style', plugins_url( '/css/style.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
171
+ //Enqueue the style
172
+ wp_enqueue_style( 'jquery-pin-it-button-style' );
173
+ }
174
+
175
+ function jpibfi_footer_action() {
176
+ if ( !jpibfi_add_plugin() )
177
+ return;
178
+
179
+ $dev_options = jpibfi_get_basic_options();
180
+ $enabled_classes = $dev_options['enabled_classes'] ? ", enabled_classes:'" . $dev_options['enabled_classes'] . "'" : "";
181
+
182
+ ?>
183
+ <script type="text/javascript">
184
+ jQuery(document).ready(function ($) {
185
+ $('.jpibfi').parent('div').addClass('jpibfi_container');
186
+ jpibfi_pinit({
187
+ image_selector:'<?php echo $dev_options['image_selector'];?>',
188
+ disabled_classes:'<?php echo $dev_options['disabled_classes'];?>',
189
+ description_option:'<?php echo $dev_options['description_option'];?>'
190
+ <?php echo $enabled_classes;?>
191
+ });
192
+ });
193
+ </script>
194
+ <?php
195
+ }
196
+
197
+ function jpibfi_print_header_style_action() {
198
+ if ( ! ( jpibfi_add_plugin() ) )
199
+ return;
200
+
201
+ $dev_options = jpibfi_get_basic_options();
202
+
203
+ if ( $dev_options['compatibility_mode'] == '0' )
204
+ $css = 'background-color: rgba(255, 255, 255, ' . $dev_options['transparency_value'] . ');';
205
+ else
206
+ $css = "background: url('" .
207
+ plugins_url( '/images/transparency/' .
208
+ str_replace( '.', '_', $dev_options['transparency_value'] ) . '.png', __FILE__ ) . "') repeat;";
209
+
210
+ if ( $dev_options['use_custom_image'] == "1" ) {
211
+ $width = $dev_options['custom_image_width'];
212
+ $height = $dev_options['custom_image_height'];
213
+ $url = $dev_options['custom_image_url'];
214
+ }
215
+ else {
216
+ $width = 65;
217
+ $height = 41;
218
+ $url = plugins_url( '/images/pinit-button.png', __FILE__ );
219
+ }
220
+
221
+ ?>
222
+ <style type="text/css">
223
+ .pinit .pinit-overlay { <?php echo $css; ?> }
224
+
225
+ .pinit .pinit-overlay a {
226
+ <?php printf( 'width:%spx; height:%spx; background:transparent url("%s") no-repeat 0 0;',
227
+ $width, $height, $url ); ?>
228
+ }
229
+ </style>
230
+ <?php
231
+ }
232
+
233
+ function jpibfi_print_hidden_field_script( $content ) {
234
+ if ( ! jpibfi_add_plugin() )
235
+ return $content;
236
+ return "<input class='jpibfi' type='hidden' />" . $content;
237
+ }
238
+
239
+ //ADMIN PAGE CODE
240
+
241
+ //add admin scripts
242
+ function jpibfi_add_admin_site_scripts() {
243
+ wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
244
+ wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
245
+ wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/admin.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION, false );
246
+ }
247
+
248
+
249
+
250
+
251
+ //End function print_admin_page()
252
+
253
+ function jpibfi_print_admin_page_action() {
254
+ $page = add_options_page( 'jQuery Pin It Button For Images', 'jQuery Pin It Button For Images', 9, basename( __FILE__ ), 'jpibfi_print_admin_page' );
255
+ add_action( 'admin_print_styles-' . $page, 'jpibfi_add_admin_site_scripts' );
256
+ }
257
+
258
+ function jpibfi_plugin_settings_filter( $links ) {
259
+ $settings_link = '<a href="options-general.php?page=jquery-pin-it-button-for-images.php">Settings</a>';
260
+ array_unshift( $links, $settings_link );
261
+ return $links;
262
+ }
263
+
264
+ //END ADMIN PAGE CODE
265
+
266
+ //POST EDITOR CODE
267
+
268
+ function jpibfi_add_meta_box() {
269
+ //for posts
270
+ add_meta_box(
271
+ 'jpibfi_settings_id', // this is HTML id of the box on edit screen
272
+ 'jQuery Pin It Button for Images - Settings', // title of the box
273
+ 'jpibfi_print_meta_box', // function to be called to display the checkboxes, see the function below
274
+ 'post', // on which edit screen the box should appear
275
+ 'side', // part of page where the box should appear
276
+ 'default' // priority of the box
277
+ );
278
+
279
+ //for pages
280
+ add_meta_box(
281
+ 'jpibfi_settings_id',
282
+ 'jQuery Pin It Button for Images - Settings',
283
+ 'jpibfi_print_meta_box',
284
+ 'page',
285
+ 'side',
286
+ 'default'
287
+ );
288
+ }
289
+
290
+ // display the metabox
291
+ function jpibfi_print_meta_box( $post, $metabox ) {
292
+ global $jpibfi_post_metadata_name;
293
+
294
+ wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' );
295
+
296
+ $post_meta = get_post_meta( $post->ID, $jpibfi_post_metadata_name, true );
297
+ if ( isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1' )
298
+ $checked_message = 'checked="checked"';
299
+ else
300
+ $checked_message = '';
301
+
302
+ echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"'
303
+ . $checked_message . ' /><label for="jpibfi_disable_for_post"> Disable "Pin it" button for this post (works only on single pages/posts)</label><br />';
304
+ }
305
+
306
+ function jpibfi_save_meta_data( $post_id ) {
307
+ global $jpibfi_post_metadata_name;
308
+
309
+ // check if this isn't an auto save
310
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
311
+ return;
312
+ // security check = updating possible only using post edit form
313
+ if ( ! wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
314
+ return;
315
+ //check user's permissions
316
+ if ( ! current_user_can( 'edit_post', $post_id ) )
317
+ return;
318
+
319
+ $post_meta = array( 'jpibfi_disable_for_post' => '0' );
320
+ // now store data in custom fields based on checkboxes selected
321
+ $post_meta['jpibfi_disable_for_post'] =
322
+ isset( $_POST['jpibfi_disable_for_post'] ) && $_POST['jpibfi_disable_for_post'] == '1' ? '1' : '0';
323
+
324
+ if ( $post_meta['jpibfi_disable_for_post'] == '1' )
325
+ update_post_meta( $post_id, $jpibfi_post_metadata_name, $post_meta );
326
+ else
327
+ delete_post_meta( $post_id, $jpibfi_post_metadata_name );
328
+ }
329
+
330
+ //END POST EDITOR CODE
331
+
332
+ //fire it when the plugin is deleted
333
+ function jpibfi_uninstall_plugin() {
334
+ global $jpibfi_admin_basic_options_name, $jpibfi_admin_advanced_options_name, $jpibfi_post_metadata_name;
335
+
336
+ //delete all added options
337
+ delete_option( $jpibfi_admin_basic_options_name );
338
+ delete_option( $jpibfi_admin_advanced_options_name );
339
+
340
+ //delete added metadata from all posts
341
+ delete_post_meta_by_key( $jpibfi_post_metadata_name );
342
+ }
343
+
344
+ //Actions and Filters
345
+
346
+ register_activation_hook( __FILE__, 'jpibfi_init_plugin' );
347
+ register_uninstall_hook( __FILE__, 'jpibfi_uninstall_plugin' );
348
+ //Actions
349
+ add_action( 'wp_enqueue_scripts', 'jpibfi_add_plugin_scripts' );
350
+ add_action( 'admin_menu', 'jpibfi_print_admin_page_action' );
351
+ add_action( 'wp_footer', 'jpibfi_footer_action' );
352
+ add_action( 'wp_head', 'jpibfi_print_header_style_action' );
353
+ add_action( 'add_meta_boxes', 'jpibfi_add_meta_box' );
354
+ add_action( 'save_post', 'jpibfi_save_meta_data' );
355
+
356
+ //Filters
357
+ $plugin = plugin_basename( __FILE__ );
358
+ add_filter( "plugin_action_links_$plugin", 'jpibfi_plugin_settings_filter' );
359
+ add_filter( "the_content", 'jpibfi_print_hidden_field_script' );
360
 
361
  ?>
js/script.js CHANGED
@@ -1,107 +1,107 @@
1
- (function($){
2
- //Attach this new method to jQuery
3
- $.fn.extend({
4
-
5
- pinit: function(options) {
6
-
7
- var defaults = {
8
- pageURL: document.URL,
9
- pageTitle: document.title,
10
- pageDescription: $('meta[name="description"]').attr('content')
11
- }
12
-
13
- var o = $.extend(defaults, options);
14
- var discriminator_classes = o.disabled_classes.split(';');
15
-
16
- if (!(typeof o.enabled_classes === 'undefined')) //variable exists
17
- var allowed_classes = o.enabled_classes.split(';');
18
-
19
- window.onload = function(){
20
-
21
- var wpclasses = ['alignnone', 'alignright', 'alignleft'];
22
-
23
- $("img[data-indexer]").each(function(){
24
- var image = $(this),
25
- pi_media = image.data('media') ? image.data('media') : image[0].src,
26
- pi_url = o.pageURL;
27
-
28
- //Pin message depending on settings
29
- var pi_desc;
30
- if (o.description_option == 3)
31
- pi_desc = image.attr('title') ? image.attr('title') : image.attr('alt');
32
- else if (o.description_option == 2)
33
- pi_desc = o.pageDescription;
34
- !pi_desc && (pi_desc = o.pageTitle);
35
-
36
- var indexer = image.attr("data-indexer");
37
- var bookmark = 'http://pinterest.com/pin/create/bookmarklet/?media=' + encodeURI(pi_media) + '&url=' + encodeURI(pi_url) + '&is_video=' + encodeURI('false') + '&description=' + encodeURI(pi_desc);
38
-
39
- image.wrap('<span class="pinit" data-indexer="' + indexer + '"/>');
40
- image.after('<span class="pinit-overlay" data-indexer= "' + indexer + '"><a class="pinit-button" href="' + bookmark + '">Pin It</a></span>');
41
-
42
- $('span.pinit-overlay[data-indexer="' + indexer + '"]')
43
- .css({
44
- height: image.innerHeight() + 'px',
45
- width: image.innerWidth() + 'px',
46
- 'margin-right': image.css('margin-right'),
47
- 'margin-left': image.css('margin-left'),
48
- 'margin-top': image.css('margin-top'),
49
- 'margin-bottom': image.css('margin-bottom')
50
- });
51
-
52
- for(var i in wpclasses)
53
- image.hasClass(wpclasses[i]) && $('span.pinit[data-indexer="' + indexer +'"]').addClass(wpclasses[i]);
54
-
55
- if (image.hasClass('aligncenter')){
56
- $('span.pinit[data-indexer="' + indexer +'"]')
57
- .addClass('aligncenter')
58
- .css('clear', 'both');
59
- $('span.pinit-overlay[data-indexer="' + indexer + '"]')
60
- .css({
61
- "margin-left":"auto",
62
- "margin-right": "auto",
63
- left: 0,
64
- right: 0
65
- })
66
- }
67
-
68
- $('.pinit .pinit-button').on('click', function () {
69
- window.open($(this).attr('href'), 'Pinterest', 'width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1');
70
- return false;
71
- });
72
-
73
- $('.pinit').mouseenter(function () {
74
- $(this).children('.pinit-overlay').fadeIn(200);
75
- }).mouseleave(function () {
76
- $(this).children('.pinit-overlay').fadeOut(200);
77
- });
78
- })
79
- };
80
-
81
- //loop over every selected image
82
- return this.each(function(i) {
83
- var e = $(this);
84
- //check if the image has a discriminator class, if has, then return
85
- for(var c in discriminator_classes){
86
- if(e.hasClass(discriminator_classes[c]))
87
- return;
88
- }
89
-
90
- if (!(typeof allowed_classes === 'undefined')) {//variable doesn't exist
91
- var has_class = false;
92
- for(var c in allowed_classes){
93
- if(e.hasClass(allowed_classes[c])){
94
- has_class = true;
95
- break;
96
- }
97
- }
98
- if (!has_class)
99
- return;
100
  }
101
-
102
- //to identify the image when loaded
103
- e.attr('data-indexer', i);
104
- });
105
- }
106
- });
107
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function jpibfi_pinit(options) {
2
+ var $ = jQuery;
3
+
4
+ var defaults = {
5
+ pageURL : document.URL,
6
+ pageTitle : document.title,
7
+ pageDescription: $('meta[name="description"]').attr('content')
8
+ }
9
+
10
+ var o = $.extend(defaults, options);
11
+ var discriminator_classes = o.disabled_classes.split(';');
12
+
13
+ if (!(typeof o.enabled_classes === 'undefined')) //variable exists
14
+ var allowed_classes = o.enabled_classes.split(';');
15
+
16
+ $(o.image_selector).each(function (i) {
17
+ var e = $(this);
18
+ //check if the image has a discriminator class, if has, then return
19
+ for (var c in discriminator_classes) {
20
+ if (e.hasClass(discriminator_classes[c]))
21
+ return;
22
+ }
23
+
24
+ if (!(typeof allowed_classes === 'undefined')) {//variable doesn't exist
25
+ var has_class = false;
26
+ for (var c in allowed_classes) {
27
+ if (e.hasClass(allowed_classes[c])) {
28
+ has_class = true;
29
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
+ }
32
+ if (!has_class)
33
+ return;
34
+ }
35
+
36
+ //to identify the image when loaded
37
+ e.attr('data-indexer', i);
38
+ });
39
+
40
+ window.onload = function () {
41
+
42
+ var wpclasses = ['alignnone', 'alignright', 'alignleft'];
43
+
44
+ $("img[data-indexer]").each(function () {
45
+ var image = $(this),
46
+ pi_url = o.pageURL;
47
+
48
+ //Pin message depending on settings
49
+ var pi_desc;
50
+ if (o.description_option == 3)
51
+ pi_desc = image.attr('title') ? image.attr('title') : image.attr('alt');
52
+ else if (o.description_option == 2)
53
+ pi_desc = o.pageDescription;
54
+ !pi_desc && (pi_desc = o.pageTitle);
55
+
56
+ var indexer = image.attr("data-indexer"),
57
+ bookmark = 'http://pinterest.com/pin/create/bookmarklet/?url=' + encodeURI(pi_url) + '&is_video=' + encodeURI('false') + '&description=' + encodeURI(pi_desc),
58
+ height = this.clientHeight,
59
+ width = this.clientWidth;
60
+
61
+ image.wrap('<div class="pinit" data-indexer="' + indexer + '"/>');
62
+ image.after('<span class="pinit-overlay" data-indexer= "' + indexer + '"><a class="pinit-button" href="' + bookmark + '" data-indexer= "' + indexer + '">Pin It</a></span>');
63
+ image.attr('height', height + 'px').attr('width', width + 'px');
64
+
65
+ $('span.pinit-overlay[data-indexer="' + indexer + '"]')
66
+ .css({
67
+ height :height + 'px',
68
+ width :width + 'px',
69
+ 'margin-right' :image.css('margin-right'),
70
+ 'margin-left' :image.css('margin-left'),
71
+ 'margin-top' :image.css('margin-top'),
72
+ 'margin-bottom':image.css('margin-bottom')
73
+ });
74
+
75
+ for (var i in wpclasses)
76
+ image.hasClass(wpclasses[i]) && $('span.pinit[data-indexer="' + indexer + '"]').addClass(wpclasses[i]);
77
+
78
+ if (image.hasClass('aligncenter')) {
79
+ $('.pinit[data-indexer="' + indexer + '"]')
80
+ .addClass('aligncenter')
81
+ .css('clear', 'both');
82
+ $('span.pinit-overlay[data-indexer="' + indexer + '"]')
83
+ .css({
84
+ "margin-left" :"auto",
85
+ "margin-right":"auto",
86
+ left :0,
87
+ right :0
88
+ })
89
+ }
90
+
91
+ $('.pinit .pinit-button').on('click', function () {
92
+ var index = $(this).attr("data-indexer");
93
+ var image = $('img[data-indexer="' + index+ '"]');
94
+ var url = $(this).attr('href') + "&media=" + encodeURI ( image.data('media') ? image.data('media') : image[0].src );
95
+ window.open(url, 'Pinterest', 'width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1');
96
+ return false;
97
+ });
98
+
99
+ $('.pinit').mouseenter(function () {
100
+ $(this).children('.pinit-overlay').fadeIn(200);
101
+ }).mouseleave(function () {
102
+ $(this).children('.pinit-overlay').fadeOut(200);
103
+ });
104
+ })
105
+ };
106
+ }
107
+
js/script.min.js CHANGED
@@ -1 +1 @@
1
- (function(e){e.fn.extend({pinit:function(t){var n={pageURL:document.URL,pageTitle:document.title,pageDescription:e('meta[name="description"]').attr("content")};var r=e.extend(n,t);var i=r.disabled_classes.split(";");if(!(typeof r.enabled_classes==="undefined"))var s=r.enabled_classes.split(";");window.onload=function(){var t=["alignnone","alignright","alignleft"];e("img[data-indexer]").each(function(){var n=e(this),i=n.data("media")?n.data("media"):n[0].src,s=r.pageURL;var u;if(r.description_option==3)u=n.attr("title")?n.attr("title"):n.attr("alt");else if(r.description_option==2)u=r.pageDescription;!u&&(u=r.pageTitle);var a=n.attr("data-indexer");var f="http://pinterest.com/pin/create/bookmarklet/?media="+encodeURI(i)+"&url="+encodeURI(s)+"&is_video="+encodeURI("false")+"&description="+encodeURI(u);n.wrap('<span class="pinit" data-indexer="'+a+'"/>');n.after('<span class="pinit-overlay" data-indexer= "'+a+'"><a class="pinit-button" href="'+f+'">Pin It</a></span>');e('span.pinit-overlay[data-indexer="'+a+'"]').css({height:n.innerHeight()+"px",width:n.innerWidth()+"px","margin-right":n.css("margin-right"),"margin-left":n.css("margin-left"),"margin-top":n.css("margin-top"),"margin-bottom":n.css("margin-bottom")});for(var l in t)n.hasClass(t[l])&&e('span.pinit[data-indexer="'+a+'"]').addClass(t[l]);if(n.hasClass("aligncenter")){e('span.pinit[data-indexer="'+a+'"]').addClass("aligncenter").css("clear","both");e('span.pinit-overlay[data-indexer="'+a+'"]').css({"margin-left":"auto","margin-right":"auto",left:0,right:0})}e(".pinit .pinit-button").on("click",function(){window.open(e(this).attr("href"),"Pinterest","width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1");return false});e(".pinit").mouseenter(function(){e(this).children(".pinit-overlay").fadeIn(200)}).mouseleave(function(){e(this).children(".pinit-overlay").fadeOut(200)})})};return this.each(function(t){var n=e(this);for(var r in i){if(n.hasClass(i[r]))return}if(!(typeof s==="undefined")){var o=false;for(var r in s){if(n.hasClass(s[r])){o=true;break}}if(!o)return}n.attr("data-indexer",t)})}})})(jQuery)
1
+ function jpibfi_pinit(e){var t=jQuery;var n={pageURL:document.URL,pageTitle:document.title,pageDescription:t('meta[name="description"]').attr("content")};var r=t.extend(n,e);var i=r.disabled_classes.split(";");if(!(typeof r.enabled_classes==="undefined"))var s=r.enabled_classes.split(";");t(r.image_selector).each(function(e){var n=t(this);for(var r in i){if(n.hasClass(i[r]))return}if(!(typeof s==="undefined")){var o=false;for(var r in s){if(n.hasClass(s[r])){o=true;break}}if(!o)return}n.attr("data-indexer",e)});window.onload=function(){var e=["alignnone","alignright","alignleft"];t("img[data-indexer]").each(function(){var n=t(this),i=r.pageURL;var s;if(r.description_option==3)s=n.attr("title")?n.attr("title"):n.attr("alt");else if(r.description_option==2)s=r.pageDescription;!s&&(s=r.pageTitle);var u=n.attr("data-indexer"),a="http://pinterest.com/pin/create/bookmarklet/?url="+encodeURI(i)+"&is_video="+encodeURI("false")+"&description="+encodeURI(s),f=this.clientHeight,l=this.clientWidth;n.wrap('<div class="pinit" data-indexer="'+u+'"/>');n.after('<span class="pinit-overlay" data-indexer= "'+u+'"><a class="pinit-button" href="'+a+'" data-indexer= "'+u+'">Pin It</a></span>');n.attr("height",f+"px").attr("width",l+"px");t('span.pinit-overlay[data-indexer="'+u+'"]').css({height:f+"px",width:l+"px","margin-right":n.css("margin-right"),"margin-left":n.css("margin-left"),"margin-top":n.css("margin-top"),"margin-bottom":n.css("margin-bottom")});for(var c in e)n.hasClass(e[c])&&t('span.pinit[data-indexer="'+u+'"]').addClass(e[c]);if(n.hasClass("aligncenter")){t('.pinit[data-indexer="'+u+'"]').addClass("aligncenter").css("clear","both");t('span.pinit-overlay[data-indexer="'+u+'"]').css({"margin-left":"auto","margin-right":"auto",left:0,right:0})}t(".pinit .pinit-button").on("click",function(){var e=t(this).attr("data-indexer");var n=t('img[data-indexer="'+e+'"]');var r=t(this).attr("href")+"&media="+encodeURI(n.data("media")?n.data("media"):n[0].src);window.open(r,"Pinterest","width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1");return false});t(".pinit").mouseenter(function(){t(this).children(".pinit-overlay").fadeIn(200)}).mouseleave(function(){t(this).children(".pinit-overlay").fadeOut(200)})})}}
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mrsztuczkens
3
  Donate link: http://bit.ly/Uw2mEP
4
  Tags: pinterest, pin it, button, image, images, pinit, social media, hover, click, photo, photos
5
  Requires at least: 3.3.0
6
- Tested up to: 3.5
7
- Stable tag: 0.9
8
  License: GPLv2 or later
9
 
10
  Highlights images on hover and adds a Pinterest "Pin It" button over them for easy pinning.
@@ -17,8 +17,8 @@ The plugin allows you to:
17
  * choose from where the description should be taken (possible options: page title, page description and alt/title tags from the image)
18
  * choose which pictures shouldn't show the "Pin it" button (using classes)
19
  * choose which pictures should show the "Pin it" button (all images, post images, images with certain class(es))
20
- * choose if you want to show the "Pin it" button on home page, single posts, single pages or category pages
21
- * disable showing the button on certain posts and pages (works only on single posts and single pages)
22
  * choose transparency level depending on your needs
23
  * use your own Pinterest button design
24
 
@@ -69,6 +69,12 @@ Please report them in the plugin's support forum on Wordpress.org.
69
 
70
  == Changelog ==
71
 
 
 
 
 
 
 
72
  = 0.9 =
73
  * Released 2013-01-28
74
  * Feature: Ability to use custom Pinterest button design
@@ -98,6 +104,9 @@ Please report them in the plugin's support forum on Wordpress.org.
98
 
99
  == Upgrade Notice ==
100
 
 
 
 
101
  = 0.9 =
102
  New feature: using custom Pinterest button design
103
 
3
  Donate link: http://bit.ly/Uw2mEP
4
  Tags: pinterest, pin it, button, image, images, pinit, social media, hover, click, photo, photos
5
  Requires at least: 3.3.0
6
+ Tested up to: 3.5.1
7
+ Stable tag: 0.9.1
8
  License: GPLv2 or later
9
 
10
  Highlights images on hover and adds a Pinterest "Pin It" button over them for easy pinning.
17
  * choose from where the description should be taken (possible options: page title, page description and alt/title tags from the image)
18
  * choose which pictures shouldn't show the "Pin it" button (using classes)
19
  * choose which pictures should show the "Pin it" button (all images, post images, images with certain class(es))
20
+ * choose if you want to show the "Pin it" button on home page, single posts, single pages or category pages
21
+ * disable showing the button on certain posts and pages (works only on single posts and single pages)
22
  * choose transparency level depending on your needs
23
  * use your own Pinterest button design
24
 
69
 
70
  == Changelog ==
71
 
72
+ = 0.9.1 =
73
+ * Released 2013-02-12
74
+ * Bug fixed: resizing images when their dimensions are larger than the container they're in
75
+ * Bug fixed: plugin not working when jQuery added multiple times
76
+ * Bug fixed: wrong image url when images are lazy-loaded
77
+
78
  = 0.9 =
79
  * Released 2013-01-28
80
  * Feature: Ability to use custom Pinterest button design
104
 
105
  == Upgrade Notice ==
106
 
107
+ = 0.9.1 =
108
+ Few bugs reported by users got fixed.
109
+
110
  = 0.9 =
111
  New feature: using custom Pinterest button design
112