jQuery Pin It Button for Images - Version 0.7

Version Description

  • Released 2012-12-18
  • Feature: Ability to show or hide the "Pin it" button on home page, single page, single post and categories (with archives)
  • Feature: Ability to disable the "Pin it" button on certain post or page, works only on single post/page view
  • Added security checks using Nonces
Download this release

Release Info

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

Code changes from version 0.5 to 0.7

Files changed (5) hide show
  1. css/admin.css +39 -3
  2. jquery-pin-it-button-for-images.php +253 -87
  3. js/admin.js +48 -0
  4. js/script.js +1 -1
  5. readme.txt +13 -2
css/admin.css CHANGED
@@ -22,7 +22,7 @@ table.form-table th {
22
  margin-top: 4px;
23
  }
24
 
25
- p.jpibfi-success-message, p.jpibfi-error-message {
26
  border: 1px solid;
27
  border-radius: 10px;
28
  margin: 10px 0px;
@@ -30,12 +30,48 @@ p.jpibfi-success-message, p.jpibfi-error-message {
30
  width: 55%;
31
  }
32
 
33
- p.jpibfi-success-message {
34
  color: #4F8A10;
35
  background-color: #DFF2BF;
36
  }
37
 
38
- p.jpibfi-error-message {
39
  color: #D8000C;
40
  background-color: #FFBABA;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  }
22
  margin-top: 4px;
23
  }
24
 
25
+ .jpibfi-success-message, .jpibfi-error-message {
26
  border: 1px solid;
27
  border-radius: 10px;
28
  margin: 10px 0px;
30
  width: 55%;
31
  }
32
 
33
+ .jpibfi-success-message {
34
  color: #4F8A10;
35
  background-color: #DFF2BF;
36
  }
37
 
38
+ .jpibfi-error-message {
39
  color: #D8000C;
40
  background-color: #FFBABA;
41
+ }
42
+
43
+ .error-border {
44
+ border: 1px solid #ff8387;
45
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
46
+ -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
47
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
48
+ }
49
+
50
+ .error-info {
51
+ border: 1px solid #eed3d7;;
52
+ -webkit-border-radius: 4px;
53
+ -moz-border-radius: 4px;
54
+ border-radius: 4px;
55
+ background-color: #f2dede;
56
+ color: #b94a48;
57
+ padding: 8px 14px;
58
+ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
59
+ float:left;
60
+ display:none;
61
+ margin-left: 5px;
62
+ max-width:45%;
63
+ }
64
+
65
+ .error-info :after,.description {
66
+ clear:both;
67
+ }
68
+
69
+
70
+ .left-element {
71
+ max-width:75%;
72
+ float:left;
73
+ }
74
+
75
+ label.chbox-label {
76
+ padding-left: 5px;
77
  }
jquery-pin-it-button-for-images.php CHANGED
@@ -1,28 +1,54 @@
1
  <?php
2
  /*
3
  Plugin Name: jQuery Pin It Button For Images
4
- Plugin URI: http://www.wordpress.org/
5
  Description: Highlights images on hover and adds a "Pin It" button over them for easy pinning.
6
  Author: Marcin Skrzypiec
7
- Version: 0.5
8
- Author URI: http://www.wordpress.org/
9
  */
10
 
11
  if (!empty($_SERVER['SCRIPT_FILENAME']) && 'jquery-pin-it-button-for-images.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Stop! Hammer time!'); //Plugin shouldn't be accessed directly
12
 
13
- define("JPIBFI_VERSION", "0.5");
14
 
15
  if (!class_exists("jQuery_Pin_It_Button_For_Images")) {
16
  class jQuery_Pin_It_Button_For_Images {
17
 
18
- var $admin_options_name = "jptbfi_options";
 
 
19
  var $description_option_values = array ( '1', '2', '3' );
20
 
21
  //Constructor
22
  function jQuery_Pin_It_Button_For_Images() {}
23
 
24
- //Returns an array of admin options, updates settings if necessary
25
- function get_admin_options() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  $admin_options = array(
27
  'image_selector' => 'div.jpibfi_container img',
28
  'disabled_classes' => 'nopin;wp-smiley',
@@ -31,7 +57,7 @@
31
  'compatibility_mode' => $this->description_option_values[0]
32
  );
33
 
34
- $dev_options = get_option( $this->admin_options_name );
35
  $changes_in_db = count( $admin_options ) != count ( $dev_options ); //if arrays aren't of the same length, changes in db needed
36
 
37
  //invalid values need to be corrected and saved in db
@@ -65,20 +91,76 @@
65
  } else {
66
  $changes_in_db = true;
67
  }
68
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  //if something changed in the database, we need to save it
70
  if ( $changes_in_db )
71
- update_option( $this->admin_options_name, $admin_options );
72
  return $admin_options;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  }
74
 
75
  //fire it when activating the plugin
76
  function init_plugin() {
77
- $this->get_admin_options();
 
78
  }
79
 
80
  //Adds all necessary scripts
81
  function add_plugin_scripts() {
 
 
 
82
  // Adding my custom js, dependent on jquery
83
  wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.js', __FILE__ ), array('jquery'), JPIBFI_VERSION, false );
84
  // Registering my custom style
@@ -87,67 +169,102 @@
87
  wp_enqueue_style( 'jquery-pin-it-button-style');
88
  }
89
 
90
- function add_admin_site_scripts() {
91
- wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
92
- wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
 
95
- function is_string_css_class_name($class_name) {
96
- return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/", $class_name );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
 
99
- function contains_css_class_names_or_empty($str) {
100
- if ( strlen ($str ) == 0 )
101
- return true;
102
-
103
- $names = explode( ";", $str );
104
- $only_css_class_names = true;
105
-
106
- foreach ( $names as $name ) {
107
- if ( false == $this->is_string_css_class_name( $name ) ) {
108
- $only_css_class_names = false;
109
- break;
110
- }
111
- }
112
- return $only_css_class_names;
113
  }
114
 
115
  //Prints out the admin page
116
  function print_admin_page() {
117
- $dev_options = $this->get_admin_options();
 
118
 
119
  if ( isset( $_POST['update_jQuery_Pin_It_Button_For_Images']) ) {
 
 
 
 
120
  $errors = array();
121
 
122
  if ( ! $this->contains_css_class_names_or_empty( $_POST['disabled_classes'] ) )
123
- array_push( $errors, "Disabled classes field not valid");
124
 
125
  if ( ! $this->contains_css_class_names_or_empty( $_POST['enabled_classes'] ) )
126
- array_push( $errors, "Enabled classes field not valid");
127
 
128
- if ( ! in_array( $_POST['description_option'], $this->description_option_values ) )
129
- array_push( $errors, "Description option field not valid");
 
 
 
 
 
 
 
 
 
130
 
131
- if ( 0 == count( $errors ) ) {
132
- $dev_options['image_selector'] = sanitize_text_field( $_POST['image_selector'] );
133
- $dev_options['compatibility_mode'] = $_POST['compatibility_mode'] == '1' ? '1' : '0';
134
- $dev_options['disabled_classes'] = $_POST['disabled_classes'];
135
- $dev_options['enabled_classes'] = $_POST['enabled_classes'];
136
- $dev_options['description_option'] = $_POST['description_option'];
137
- update_option( $this->admin_options_name, $dev_options );
138
  ?>
139
- <p class="jpibfi-success-message"><?php _e( "Settings Updated.", "jQuery_Pin_It_Button_For_Images" );?></p>
140
  <?php
141
- } else {
142
- foreach( $errors as $error ) {
143
- echo "<p class='jpibfi-error-message'>" . $error . "</p>";
144
- }
145
  }
146
  }
147
  ?>
148
  <div class="wrap">
149
  <h2>jQuery Pin It Button For Images</h2>
150
  <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
 
151
  <h3>Plugin settings</h3>
152
 
153
  <table class="settings-table">
@@ -156,20 +273,30 @@
156
  <th scope="row"><label for="image_selector">Image selector</label></th>
157
  <td>
158
  <input type="text" size="50" id="image_selector" name="image_selector" value="<?php echo esc_attr( $dev_options['image_selector'] );?>" />
159
- <p class="description">jQuery selector for all the images that should have the "Pin it" button. Set the value to <b>div.jpibfi_container img</b> if you want the "Pin it" button to appear only on images in content or <b>img</b> to appear on all images on site (including sidebar, header and footer). If you know a thing or two about jQuery, you might use your own selector. <a href="http://api.jquery.com/category/selectors/" target="_blank">Click here</a> to read about jQuery selectors.</p>
160
  </td>
161
  </tr>
162
  <tr>
163
  <th scope="row"><label for="disabled_classes">Disabled classes</label></th>
164
  <td>
165
- <textarea rows="3" cols="25" id="disabled_classes" name="disabled_classes"><?php echo esc_attr( $dev_options['disabled_classes'] );?></textarea>
 
 
 
 
 
166
  <p class="description">Pictures with these CSS classes won't show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.</p>
167
  </td>
168
  </tr>
169
  <tr>
170
  <th scope="row"><label for="enabled_classes">Enabled classes</label></th>
171
  <td>
172
- <textarea rows="3" cols="25" id="enabled_classes" name="enabled_classes"><?php echo $dev_options['enabled_classes'];?></textarea>
 
 
 
 
 
173
  <p class="description">Pictures with these CSS classes will show the "Pin it" button. Please separate multiple classes with semicolons. If this field is empty, images with any (besides disabled ones) classes will show the Pin It button.</p>
174
  </td>
175
  </tr>
@@ -185,16 +312,26 @@
185
  </td>
186
  </tr>
187
  <tr>
188
- <th scope="row"><label> IE7 Compatibility mode</label></th>
189
  <td>
190
- <input type="checkbox" id="compatibility_mode" name="compatibility_mode" <?php echo "1" == $dev_options['compatibility_mode'] ? "checked='checked'" : "";?>" value="1" /><label for="compatibility_mode"> Compatibility mode</label>
191
  <p class="description">Check this if you want the plugin to work properly on IE7. Without this it doesn't highlight images on IE7.</p>
192
  </td>
193
  </tr>
 
 
 
 
 
 
 
 
 
 
194
  <tr>
195
  <th scope="row"></th>
196
  <td>
197
- <input type="submit" style="padding:7px;float:right;" name="update_jQuery_Pin_It_Button_For_Images" value="<?php _e( 'Update Settings', 'jQuery_Pin_It_Button_For_Images' ) ?>" />
198
  </td>
199
  </tr>
200
  </tbody>
@@ -209,43 +346,69 @@
209
  add_action( 'admin_print_styles-' . $page, array($this, 'add_admin_site_scripts'));
210
  }
211
 
212
- function jptbfi_instance_action() {
213
- $dev_options = $this->get_admin_options();
214
- ?>
215
- <script type="text/javascript">
216
- jQuery(document).ready(function($) {
217
- $('.jpibfi').parent('div').addClass('jpibfi_container');
218
- $('<?php echo $dev_options['image_selector'];?>').pinit({disabled_classes:'<?php echo $dev_options['disabled_classes'];?>',
219
- description_option:'<?php echo $dev_options['description_option'];?>'<?php if ( $dev_options['enabled_classes'] ) echo ", enabled_classes:'".$dev_options['enabled_classes']."'";?>});
220
- });
221
- </script>
222
- <?php
223
  }
224
 
225
- function print_header_style_action() {
226
- $dev_options = $this->get_admin_options();
227
- ?>
228
- <style type="text/css">
229
- .pinit .pinit-overlay {
230
- <?php
231
- if ( $dev_options['compatibility_mode'] == '0' )
232
- echo 'background-color: rgba(255,255,255,0.5);';
233
- else
234
- echo "background: url('" . plugins_url('/images/point-five.png', __FILE__) . "') repeat;";
235
- ?>
236
- }</style>
237
- <?php
238
- }
239
 
240
- function print_hidden_field_script($content) {
241
- return "<input class='jpibfi' type='hidden' />" . $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
- function plugin_settings_filter($links) {
245
- $settings_link = '<a href="options-general.php?page=jquery-pin-it-button-for-images.php">Settings</a>';
246
- array_unshift( $links, $settings_link );
247
- return $links;
 
 
 
 
 
 
 
 
 
 
 
248
  }
 
249
  }
250
  } //End Class jQuery_Pin_It_Button_For_Images
251
 
@@ -255,12 +418,15 @@
255
 
256
  //Actions and Filters
257
  if ( isset($jptbfi_instance) ) {
 
 
258
  //Actions
259
  add_action( 'wp_enqueue_scripts', array( &$jptbfi_instance, 'add_plugin_scripts' ) );
260
- add_action( 'activate_jquery-pin-it-button-for-images/jquery-pin-it-button-for-images.php', array( &$jptbfi_instance, 'init_plugin' ) );
261
  add_action( 'admin_menu', array( &$jptbfi_instance, 'print_admin_page_action' ) );
262
- add_action( 'wp_footer', array( &$jptbfi_instance, 'jptbfi_instance_action' ) );
263
- add_action( 'wp_head', array( &$jptbfi_instance, 'print_header_style_action' ) );
 
 
264
 
265
  //Filters
266
  $plugin = plugin_basename( __FILE__ );
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.7
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'])) die ('Stop! Hammer time!'); //Plugin shouldn't be accessed directly
12
 
13
+ define("JPIBFI_VERSION", "0.7");
14
 
15
  if (!class_exists("jQuery_Pin_It_Button_For_Images")) {
16
  class jQuery_Pin_It_Button_For_Images {
17
 
18
+ var $admin_basic_options_name = "jptbfi_options";
19
+ var $admin_advanced_options_name = "jptbfi_advanced_options";
20
+ var $post_metadata_name = "jpibfi_meta";
21
  var $description_option_values = array ( '1', '2', '3' );
22
 
23
  //Constructor
24
  function jQuery_Pin_It_Button_For_Images() {}
25
 
26
+ //SETTINGS VALIDATION CODE
27
+
28
+ function is_string_css_class_name($class_name) {
29
+ return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/", $class_name );
30
+ }
31
+
32
+ function contains_css_class_names_or_empty($str) {
33
+ if ( strlen ($str ) == 0 )
34
+ return true;
35
+
36
+ $names = explode( ";", $str );
37
+ $only_css_class_names = true;
38
+
39
+ foreach ( $names as $name ) {
40
+ if ( false == $this->is_string_css_class_name( $name ) ) {
41
+ $only_css_class_names = false;
42
+ break;
43
+ }
44
+ }
45
+ return $only_css_class_names;
46
+ }
47
+
48
+ //END SETTINGS VALIDATION CODE
49
+
50
+ //Returns an array of basic admin options, updates settings if necessary
51
+ function get_basic_options() {
52
  $admin_options = array(
53
  'image_selector' => 'div.jpibfi_container img',
54
  'disabled_classes' => 'nopin;wp-smiley',
57
  'compatibility_mode' => $this->description_option_values[0]
58
  );
59
 
60
+ $dev_options = get_option( $this->admin_basic_options_name );
61
  $changes_in_db = count( $admin_options ) != count ( $dev_options ); //if arrays aren't of the same length, changes in db needed
62
 
63
  //invalid values need to be corrected and saved in db
91
  } else {
92
  $changes_in_db = true;
93
  }
94
+
95
+ //if something changed in the database, we need to save it
96
+ if ( $changes_in_db )
97
+ update_option( $this->admin_basic_options_name, $admin_options );
98
+
99
+ return $admin_options;
100
+ }//End function get_basic_options()
101
+
102
+ //Returns an array of advanced admin options, updates settings if necessary
103
+ function get_advanced_options() {
104
+ $admin_options = array(
105
+ 'on_home' => '1',
106
+ 'on_single' => '1',
107
+ 'on_page' => '1',
108
+ 'on_category' => '1'
109
+ );
110
+
111
+ $dev_options = get_option( $this->admin_advanced_options_name );
112
+ $changes_in_db = count( $admin_options ) != count ( $dev_options ); //if arrays aren't of the same length, changes in db needed
113
+
114
+ foreach ($admin_options as $setting_name => $setting_value) {
115
+ if ( array_key_exists( $setting_name, $dev_options ) )
116
+ $admin_options[$setting_name] = $dev_options[$setting_name];
117
+ }
118
+
119
  //if something changed in the database, we need to save it
120
  if ( $changes_in_db )
121
+ update_option( $this->admin_advanced_options_name, $admin_options );
122
  return $admin_options;
123
+ }//End function get_advanced_options()
124
+
125
+
126
+ function add_plugin_to_page() {
127
+ global $post;
128
+ $advanced_settings = $this->get_advanced_options();
129
+ if ( is_front_page() ) {
130
+ return $advanced_settings['on_home'] == "1";
131
+ } else if ( is_single() ) {
132
+ if ( $advanced_settings['on_single'] == "1" ) {
133
+ $post_meta = get_post_meta( $post->ID, $this->post_metadata_name, true );
134
+ if ( !empty($post_meta) && array_key_exists( 'jpibfi_disable_for_post', $post_meta ) && $post_meta['jpibfi_disable_for_post'] == '1')
135
+ return false;
136
+ return true;
137
+ }
138
+ return false;
139
+ } else if ( is_page() ) {
140
+ if ( $advanced_settings['on_page'] == "1" ) {
141
+ $post_meta = get_post_meta( $post->ID, $this->post_metadata_name, true );
142
+ if ( !empty($post_meta) && array_key_exists( 'jpibfi_disable_for_post', $post_meta ) && $post_meta['jpibfi_disable_for_post'] == '1')
143
+ return false;
144
+ return true;
145
+ }
146
+ return false;
147
+ } else if ( is_category() ) {
148
+ return $advanced_settings['on_category'] == "1";
149
+ }
150
+ return true;
151
  }
152
 
153
  //fire it when activating the plugin
154
  function init_plugin() {
155
+ $this->get_basic_options();
156
+ $this->get_advanced_options();
157
  }
158
 
159
  //Adds all necessary scripts
160
  function add_plugin_scripts() {
161
+ if ( !( $this->add_plugin_to_page() ) )
162
+ return;
163
+
164
  // Adding my custom js, dependent on jquery
165
  wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.js', __FILE__ ), array('jquery'), JPIBFI_VERSION, false );
166
  // Registering my custom style
169
  wp_enqueue_style( 'jquery-pin-it-button-style');
170
  }
171
 
172
+ function footer_action() {
173
+ if ( !( $this->add_plugin_to_page() ) )
174
+ return;
175
+
176
+ $dev_options = $this->get_basic_options();
177
+ ?>
178
+ <script type="text/javascript">
179
+ jQuery(document).ready(function($) {
180
+ $('.jpibfi').parent('div').addClass('jpibfi_container');
181
+ $('<?php echo $dev_options['image_selector'];?>').pinit({disabled_classes:'<?php echo $dev_options['disabled_classes'];?>',
182
+ description_option:'<?php echo $dev_options['description_option'];?>'<?php if ( $dev_options['enabled_classes'] ) echo ", enabled_classes:'".$dev_options['enabled_classes']."'";?>});
183
+ });
184
+ </script>
185
+ <?php
186
  }
187
 
188
+ function print_header_style_action() {
189
+ if ( !( $this->add_plugin_to_page() ) )
190
+ return;
191
+
192
+ $dev_options = $this->get_basic_options();
193
+ ?>
194
+ <style type="text/css">
195
+ .pinit .pinit-overlay {
196
+ <?php
197
+ if ( $dev_options['compatibility_mode'] == '0' )
198
+ echo 'background-color: rgba(255,255,255,0.5);';
199
+ else
200
+ echo "background: url('" . plugins_url('/images/point-five.png', __FILE__) . "') repeat;";
201
+ ?>
202
+ }</style>
203
+ <?php
204
  }
205
 
206
+ function print_hidden_field_script($content) {
207
+ if ( ! $this->add_plugin_to_page() )
208
+ return $content;
209
+ return "<input class='jpibfi' type='hidden' />" . $content;
210
+ }
211
+
212
+ //ADMIN PAGE CODE
213
+
214
+ //add admin scripts
215
+ function add_admin_site_scripts() {
216
+ wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION, 'all' );
217
+ wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
218
+ wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/admin.js', __FILE__ ), array('jquery'), JPIBFI_VERSION, false );
 
219
  }
220
 
221
  //Prints out the admin page
222
  function print_admin_page() {
223
+ $dev_options = $this->get_basic_options();
224
+ $advanced_dev_options = $this->get_advanced_options();
225
 
226
  if ( isset( $_POST['update_jQuery_Pin_It_Button_For_Images']) ) {
227
+ //security check
228
+ if ( !wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
229
+ die( 'Security alert');
230
+
231
  $errors = array();
232
 
233
  if ( ! $this->contains_css_class_names_or_empty( $_POST['disabled_classes'] ) )
234
+ $errors['disabled_classes'] = true;
235
 
236
  if ( ! $this->contains_css_class_names_or_empty( $_POST['enabled_classes'] ) )
237
+ $errors['enabled_classes'] = true;
238
 
239
+ //rewrite settings that came from the POST request
240
+ $dev_options['image_selector'] = sanitize_text_field( $_POST['image_selector'] );
241
+ $dev_options['compatibility_mode'] = $_POST['compatibility_mode'] == '1' ? '1' : '0';
242
+ $dev_options['disabled_classes'] = $_POST['disabled_classes'];
243
+ $dev_options['enabled_classes'] = $_POST['enabled_classes'];
244
+ $dev_options['description_option'] = $_POST['description_option'];
245
+
246
+ $advanced_dev_options['on_home'] = $_POST['on_home'] == '1' ? '1' : '0';
247
+ $advanced_dev_options['on_page'] = $_POST['on_page'] == '1' ? '1' : '0';
248
+ $advanced_dev_options['on_single'] = $_POST['on_single'] == '1' ? '1' : '0';
249
+ $advanced_dev_options['on_category'] = $_POST['on_category'] == '1' ? '1' : '0';
250
 
251
+ if ( 0 == count( $errors ) ) { //save only if there are no errors
252
+ update_option( $this->admin_basic_options_name, $dev_options );
253
+ update_option( $this->admin_advanced_options_name, $advanced_dev_options );
 
 
 
 
254
  ?>
255
+ <p class="jpibfi-success-message"><?php _e( "Settings Updated.", "jpibfi" );?></p>
256
  <?php
257
+ } else { //otherwise inform that there are some errors
258
+ ?>
259
+ <p class='jpibfi-error-message'><?php _e("Error. Settings not updated. Look for details below.", "jpibfi" ); ?></p>
260
+ <?php
261
  }
262
  }
263
  ?>
264
  <div class="wrap">
265
  <h2>jQuery Pin It Button For Images</h2>
266
  <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
267
+ <?php wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' ); ?>
268
  <h3>Plugin settings</h3>
269
 
270
  <table class="settings-table">
273
  <th scope="row"><label for="image_selector">Image selector</label></th>
274
  <td>
275
  <input type="text" size="50" id="image_selector" name="image_selector" value="<?php echo esc_attr( $dev_options['image_selector'] );?>" />
276
+ <p class="description">jQuery selector for all the images that should have the "Pin it" button. Set the value to <a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a> if you want the "Pin it" button to appear only on images in content or <a href="#" class="jpibfi_selector_option">img</a> to appear on all images on site (including sidebar, header and footer). If you know a thing or two about jQuery, you might use your own selector. <a href="http://api.jquery.com/category/selectors/" target="_blank">Click here</a> to read about jQuery selectors.</p>
277
  </td>
278
  </tr>
279
  <tr>
280
  <th scope="row"><label for="disabled_classes">Disabled classes</label></th>
281
  <td>
282
+ <div class="left-element">
283
+ <textarea rows="3" cols="25" id="disabled_classes" name="disabled_classes" <?php if ( !empty($errors) && array_key_exists( 'disabled_classes', $errors ) ) echo "class='error-border'"; ?>><?php echo esc_attr( $dev_options['disabled_classes'] );?></textarea>
284
+ </div>
285
+ <div id="disabled_classes_error" class="error-info" <?php if ( !empty($errors) && array_key_exists( 'disabled_classes', $errors ) ) echo "style='display:block;'"; ?>>
286
+ Error. Please change this setting and try submitting again.
287
+ </div>
288
  <p class="description">Pictures with these CSS classes won't show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.</p>
289
  </td>
290
  </tr>
291
  <tr>
292
  <th scope="row"><label for="enabled_classes">Enabled classes</label></th>
293
  <td>
294
+ <div class="left-element">
295
+ <textarea rows="3" cols="25" id="enabled_classes" name="enabled_classes" <?php if ( !empty($errors) && array_key_exists( 'enabled_classes', $errors ) ) echo "class='error-border'"; ?>><?php echo $dev_options['enabled_classes'];?></textarea>
296
+ </div>
297
+ <div id="enabled_classes_error" class="error-info" <?php if ( !empty($errors) && array_key_exists( 'enabled_classes', $errors ) ) echo "style='display:block;'"; ?>>
298
+ Error. Please change this setting and try submitting again.
299
+ </div>
300
  <p class="description">Pictures with these CSS classes will show the "Pin it" button. Please separate multiple classes with semicolons. If this field is empty, images with any (besides disabled ones) classes will show the Pin It button.</p>
301
  </td>
302
  </tr>
312
  </td>
313
  </tr>
314
  <tr>
315
+ <th scope="row"><label>IE7 Compatibility mode</label></th>
316
  <td>
317
+ <input type="checkbox" id="compatibility_mode" name="compatibility_mode" <?php echo "1" == $dev_options['compatibility_mode'] ? "checked='checked'" : "";?>" value="1" /><label class="chbox-label" for="compatibility_mode"> Compatibility mode</label>
318
  <p class="description">Check this if you want the plugin to work properly on IE7. Without this it doesn't highlight images on IE7.</p>
319
  </td>
320
  </tr>
321
+ <tr>
322
+ <th scope="row"><label>One which pages the "Pin it" button should be shown</label></th>
323
+ <td>
324
+ <input type="checkbox" id="on_home" 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/>
325
+ <input type="checkbox" id="on_page" 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/>
326
+ <input type="checkbox" id="on_single" 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/>
327
+ <input type="checkbox" id="on_category" 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>
328
+ <p class="description">Check on which pages you want the Pinterest button to show up.</p>
329
+ </td>
330
+ </tr>
331
  <tr>
332
  <th scope="row"></th>
333
  <td>
334
+ <input id="submit_form" type="submit" style="padding:7px;float:right;" name="update_jQuery_Pin_It_Button_For_Images" value="<?php _e( 'Update Settings', 'jQuery_Pin_It_Button_For_Images' ) ?>" />
335
  </td>
336
  </tr>
337
  </tbody>
346
  add_action( 'admin_print_styles-' . $page, array($this, 'add_admin_site_scripts'));
347
  }
348
 
349
+ function plugin_settings_filter($links) {
350
+ $settings_link = '<a href="options-general.php?page=jquery-pin-it-button-for-images.php">Settings</a>';
351
+ array_unshift( $links, $settings_link );
352
+ return $links;
 
 
 
 
 
 
 
353
  }
354
 
355
+ //END ADMIN PAGE CODE
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
+ //POST EDITOR CODE
358
+
359
+ function add_meta_box() {
360
+ //for posts
361
+ add_meta_box(
362
+ 'jpibfi_settings_id', // this is HTML id of the box on edit screen
363
+ 'jQuery Pin It Button for Images - Settings', // title of the box
364
+ array( $this, 'print_meta_box' ), // function to be called to display the checkboxes, see the function below
365
+ 'post', // on which edit screen the box should appear
366
+ 'side', // part of page where the box should appear
367
+ 'default' // priority of the box
368
+ );
369
+
370
+ //for pages
371
+ add_meta_box(
372
+ 'jpibfi_settings_id',
373
+ 'jQuery Pin It Button for Images - Settings',
374
+ array( $this, 'print_meta_box' ),
375
+ 'page',
376
+ 'side',
377
+ 'default'
378
+ );
379
+ }
380
+
381
+ // display the metabox
382
+ function print_meta_box( $post, $metabox ) {
383
+ wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' );
384
+
385
+ $post_meta = get_post_meta( $post->ID, $this->post_metadata_name, true );
386
+ if ( isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1' )
387
+ $checked_message = 'checked="checked"';
388
+ else
389
+ $checked_message = '';
390
+
391
+ echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"'
392
+ . $checked_message . ' /><label for="jpibfi_disable_for_post"> Disable "Pin it" button for this post (works only on single pages/posts)</label><br />';
393
  }
394
 
395
+ function save_meta_data($post_id) {
396
+ // check if this isn't an auto save
397
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
398
+ return;
399
+ // security check
400
+ if ( !wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
401
+ die( 'Security alert');
402
+
403
+ $post_meta = array( 'jpibfi_disable_for_post' => '0' );
404
+ // now store data in custom fields based on checkboxes selected
405
+ if ( isset( $_POST['jpibfi_disable_for_post'] ) && $_POST['jpibfi_disable_for_post'] == '1')
406
+ $post_meta['jpibfi_disable_for_post'] = '1';
407
+ else
408
+ $post_meta['jpibfi_disable_for_post'] = '0';
409
+ update_post_meta( $post_id, $this->post_metadata_name, $post_meta );
410
  }
411
+ //END POST EDITOR CODE
412
  }
413
  } //End Class jQuery_Pin_It_Button_For_Images
414
 
418
 
419
  //Actions and Filters
420
  if ( isset($jptbfi_instance) ) {
421
+ //Register
422
+ register_activation_hook(__FILE__, array( &$jptbfi_instance, 'init_plugin' ) );
423
  //Actions
424
  add_action( 'wp_enqueue_scripts', array( &$jptbfi_instance, 'add_plugin_scripts' ) );
 
425
  add_action( 'admin_menu', array( &$jptbfi_instance, 'print_admin_page_action' ) );
426
+ add_action( 'wp_footer', array( &$jptbfi_instance, 'footer_action' ) );
427
+ add_action( 'wp_head', array( &$jptbfi_instance, 'print_header_style_action' ) );
428
+ add_action( 'add_meta_boxes', array( &$jptbfi_instance, 'add_meta_box' ) );
429
+ add_action( 'save_post', array( &$jptbfi_instance, 'save_meta_data' ) );
430
 
431
  //Filters
432
  $plugin = plugin_basename( __FILE__ );
js/admin.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+
3
+ $('a.jpibfi_selector_option').click(function(e) {
4
+ $('#image_selector').val($(this).text());
5
+ e.preventDefault();
6
+ });
7
+
8
+ $('#submit_form').click(function(e){
9
+ var error = false;
10
+ var areas = ["#disabled_classes", "#enabled_classes"];
11
+
12
+ for (var i = 0; i < areas.length; i++) {
13
+ if ( !contains_css_class_names_or_empty( $(areas[i]).val() ) ) {
14
+ $(areas[i]).addClass('error-border');
15
+ $(areas[i] + "_error").show();
16
+ error = true;
17
+ }
18
+ else {
19
+ $(areas[i]).removeClass('error-border');
20
+ $(areas[i] + "_error").hide();
21
+ }
22
+ }
23
+
24
+ if (error)
25
+ e.preventDefault();
26
+ });
27
+
28
+ function is_string_css_class_name(class_name) {
29
+ var regExp = new RegExp("^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$");
30
+ return regExp.test(class_name);
31
+ }
32
+
33
+ function contains_css_class_names_or_empty(str) {
34
+ if ( str.length == 0 )
35
+ return true;
36
+
37
+ var names = str.split(";");
38
+ var only_css_class_names = true;
39
+
40
+ for (var i = 0; i < names.length; i++ ) {
41
+ if ( !is_string_css_class_name(names[i]) ) {
42
+ only_css_class_names = false;
43
+ break;
44
+ }
45
+ }
46
+ return only_css_class_names;
47
+ }
48
+ });
js/script.js CHANGED
@@ -20,7 +20,7 @@
20
 
21
  //Iterate over the current set of matched elements
22
  return this.each(function(i) {
23
- if (!(typeof allowed_classes === 'undefined')) {//variable exists
24
  var has_class = false;
25
  for(var c in allowed_classes){
26
  if($(this).hasClass(allowed_classes[c])){
20
 
21
  //Iterate over the current set of matched elements
22
  return this.each(function(i) {
23
+ if (!(typeof allowed_classes === 'undefined')) {//variable doesn't exist
24
  var has_class = false;
25
  for(var c in allowed_classes){
26
  if($(this).hasClass(allowed_classes[c])){
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.0.0
6
- Tested up to: 3.4.1
7
- Stable tag: 0.5
8
  License: GPLv2 or later
9
 
10
  Highlights images on hover and adds a Pinterest "Pin It" button over them for easy pinning.
@@ -17,6 +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
 
21
  Once you activate the plugin, it's ready to go with the typical settings - button appears on all images within the body of your posts/pages that aren't marked with "nopin" or "wp-smiley" classes.
22
 
@@ -60,6 +62,12 @@ Please report them in the plugin's support forum.
60
 
61
  == Changelog ==
62
 
 
 
 
 
 
 
63
  = 0.5 =
64
  * Released 2012-12-9
65
  * Feature: Pinterest window opens as a pop-up
@@ -70,5 +78,8 @@ Please report them in the plugin's support forum.
70
 
71
  == Upgrade Notice ==
72
 
 
 
 
73
  = 0.5 =
74
  First version of the plugin.
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.0.0
6
+ Tested up to: 3.5
7
+ Stable tag: 0.7
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
 
23
  Once you activate the plugin, it's ready to go with the typical settings - button appears on all images within the body of your posts/pages that aren't marked with "nopin" or "wp-smiley" classes.
24
 
62
 
63
  == Changelog ==
64
 
65
+ = 0.7 =
66
+ * Released 2012-12-18
67
+ * Feature: Ability to show or hide the "Pin it" button on home page, single page, single post and categories (with archives)
68
+ * Feature: Ability to disable the "Pin it" button on certain post or page, works only on single post/page view
69
+ * Added security checks using Nonces
70
+
71
  = 0.5 =
72
  * Released 2012-12-9
73
  * Feature: Pinterest window opens as a pop-up
78
 
79
  == Upgrade Notice ==
80
 
81
+ = 0.7 =
82
+ Additional features and some security enhancments
83
+
84
  = 0.5 =
85
  First version of the plugin.