jQuery Pin It Button for Images - Version 1.30

Version Description

  • Release 2014-03-13
  • PHP code redesign - plugin is much more extension friendly
  • Deleted some of the compatibility-with-older-versions code
Download this release

Release Info

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

Code changes from version 1.21 to 1.30

css/admin.css CHANGED
@@ -24,7 +24,7 @@ ul.jpibfi-classes-list {
24
25
ul.jpibfi-classes-list li {
26
float: left;
27
- margin-right: 0px;
28
padding: 0 20px 0 0;
29
}
30
@@ -34,14 +34,14 @@ ul.jpibfi-classes-list a {
34
background-color: #ffffff;
35
background-image: url('../images/delete.png');
36
background-repeat: no-repeat;
37
- background-position: 0px 0px;
38
width: 16px;
39
height: 16px;
40
cursor: pointer;
41
}
42
43
ul.jpibfi-classes-list a:hover {
44
- background-position: -16px 0px;
45
}
46
47
ul.jpibfi-classes-list span {
24
25
ul.jpibfi-classes-list li {
26
float: left;
27
+ margin-right: 0;
28
padding: 0 20px 0 0;
29
}
30
34
background-color: #ffffff;
35
background-image: url('../images/delete.png');
36
background-repeat: no-repeat;
37
+ background-position: 0 0;
38
width: 16px;
39
height: 16px;
40
cursor: pointer;
41
}
42
43
ul.jpibfi-classes-list a:hover {
44
+ background-position: -16px 0;
45
}
46
47
ul.jpibfi-classes-list span {
includes/admin/class-jpibfi-admin-utilities.php ADDED
@@ -0,0 +1,50 @@
1
+ <?php
2
+
3
+ class JPIBFI_Admin_Utilities {
4
+
5
+ /* Returns properly formatted description of a setting */
6
+ public static function create_description( $desc ) {
7
+ return '<p class="description">' . $desc . '</p>';
8
+ }
9
+
10
+ /* Returns error div if there are errors */
11
+ public static function create_errors( $setting_name ) {
12
+ $error = "";
13
+
14
+ $errors_array = get_settings_errors( $setting_name );
15
+
16
+ if ( count ( $errors_array ) > 0 ) {
17
+ $error .= '<div class="jpibfi-error-message">';
18
+ for( $i = 0; $i < count( $errors_array ); $i++ ){
19
+ $error .= $errors_array[ $i ]['message'] . '</br>';
20
+ }
21
+ $error .= '</div>';
22
+ }
23
+
24
+ return $error;
25
+ }
26
+
27
+ /* Checks if value exists in array and if it is of certain value */
28
+ public static function exists_and_equal_to( $array , $name, $expected_value = "1" ) {
29
+ return isset( $array[ $name ] ) && $array[ $name ] == $expected_value;
30
+ }
31
+
32
+ /* Checks if given string contains class names separated by semicolons or is empty */
33
+ public static function contains_css_class_names_or_empty( $str ) {
34
+ if ( 0 == strlen( $str ) )
35
+ return true;
36
+
37
+ $names = explode( ';', $str );
38
+ $only_class_names = true;
39
+
40
+ for( $i = 0; $i < count( $names ) && $only_class_names; $i++ )
41
+ $only_class_names = self::is_string_css_class_name( $names [ $i ] );
42
+
43
+ return $only_class_names;
44
+ }
45
+
46
+ public static function is_string_css_class_name( $class_name ) {
47
+ return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*#x2F;", $class_name );
48
+ }
49
+
50
+ }
includes/admin/class-jpibfi-admin.php ADDED
@@ -0,0 +1,146 @@
1
+ <?php
2
+
3
+ class JPIBFI_Admin {
4
+
5
+ protected static $instance = null;
6
+
7
+ private function __construct() {
8
+ add_action( 'admin_menu', array( $this, 'print_admin_page_action') );
9
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
10
+ add_action( 'save_post', array( $this, 'save_meta_data' ) );
11
+ }
12
+
13
+ public static function get_instance() {
14
+ // If the single instance hasn't been set, set it now.
15
+ if ( null == self::$instance ) {
16
+ self::$instance = new self;
17
+ }
18
+
19
+ return self::$instance;
20
+ }
21
+
22
+ public function print_admin_page_action() {
23
+ $page = add_submenu_page(
24
+ 'options-general.php',
25
+ 'jQuery Pin It Button For Images', // The value used to populate the browser's title bar when the menu page is active
26
+ 'jQuery Pin It Button For Images', // The text of the menu in the administrator's sidebar
27
+ 'administrator', // What roles are able to access the menu
28
+ 'jpibfi_settings', // The ID used to bind submenu items to this menu
29
+ array( $this, 'print_admin_page' ) // The callback function used to render this menu
30
+ );
31
+
32
+ add_action( 'admin_print_styles-' . $page, array( $this, 'add_admin_site_scripts') );
33
+ }
34
+
35
+ /* Adds admin scripts */
36
+ public function add_admin_site_scripts() {
37
+
38
+ wp_register_style( 'jquery-pin-it-button-admin-style', JPIBFI_STYLE_URL . 'admin.css', array(), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, 'all' );
39
+ wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
40
+
41
+ wp_enqueue_script( 'jquery-pin-it-button-admin-script', JPIBFI_SCRIPT_URL . 'admin.js', array( 'jquery' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
42
+
43
+ wp_register_script( 'angular', JPIBFI_SCRIPT_URL . 'angular.min.js' , '', '1.0.7', false );
44
+ wp_enqueue_script( 'jquery-pin-it-button-admin-angular-script', JPIBFI_SCRIPT_URL . 'admin-angular.js', array( 'angular' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
45
+
46
+ if ( function_exists( "wp_enqueue_media") ) {
47
+ wp_enqueue_media();
48
+ wp_enqueue_script( 'jpibfi-upload-new', JPIBFI_SCRIPT_URL . 'upload-button-new.js', array(), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
49
+ } else {
50
+ wp_enqueue_script( 'jpibfi-upload-old', JPIBFI_SCRIPT_URL . 'upload-button-old.js', array('thickbox', 'media-upload' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
51
+ }
52
+ }
53
+
54
+ /* Prints admin page */
55
+ public function print_admin_page() {
56
+
57
+ //dictionary of tab names associated with settings to render names
58
+ $settings_tabs = array(
59
+ 'selection_options' => array(
60
+ 'settings_name' => 'jpibfi_selection_options',
61
+ 'tab_label' => __( 'Selection', 'jpibfi' ),
62
+ 'support_link' => 'http://wordpress.org/support/plugin/jquery-pin-it-button-for-images',
63
+ 'review_link' => 'http://wordpress.org/support/view/plugin-reviews/jquery-pin-it-button-for-images'
64
+ ),
65
+ 'visual_options' => array(
66
+ 'settings_name' => 'jpibfi_visual_options',
67
+ 'tab_label' => __( 'Visual', 'jpibfi' ),
68
+ 'support_link' => 'http://wordpress.org/support/plugin/jquery-pin-it-button-for-images',
69
+ 'review_link' => 'http://wordpress.org/support/view/plugin-reviews/jquery-pin-it-button-for-images'
70
+ ),
71
+ 'advanced_options' => array(
72
+ 'settings_name' => 'jpibfi_advanced_options',
73
+ 'tab_label' => __('Advanced', 'jpibfi' ),
74
+ 'support_link' => 'http://wordpress.org/support/plugin/jquery-pin-it-button-for-images',
75
+ 'review_link' => 'http://wordpress.org/support/view/plugin-reviews/jquery-pin-it-button-for-images'
76
+ )
77
+ );
78
+
79
+ $settings_tabs = apply_filters( 'jpibfi_settings_tabs', $settings_tabs);
80
+
81
+ include_once( 'views/admin.php' );
82
+ //cumbersome, but needed for error management to work properly in WP 3.3
83
+ delete_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
84
+ delete_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
85
+ }
86
+
87
+ /* Meta box for each post and page */
88
+ public function add_meta_box() {
89
+ //for posts
90
+ add_meta_box(
91
+ 'jpibfi_settings_id', // this is HTML id of the box on edit screen
92
+ 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jpibfi' ), // title of the box
93
+ array( $this, 'print_meta_box' ), // function to be called to display the checkboxes, see the function below
94
+ 'post', // on which edit screen the box should appear
95
+ 'side', // part of page where the box should appear
96
+ 'default' // priority of the box
97
+ );
98
+
99
+ //for pages
100
+ add_meta_box(
101
+ 'jpibfi_settings_id',
102
+ 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jpibfi' ),
103
+ array( $this, 'print_meta_box' ),
104
+ 'page',
105
+ 'side',
106
+ 'default'
107
+ );
108
+ }
109
+
110
+ /* Displays the meta box */
111
+ public function print_meta_box( $post, $metabox ) {
112
+
113
+ wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' );
114
+
115
+ $post_meta = get_post_meta( $post->ID, JPIBFI_METADATA, true );
116
+ $checked = isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1';
117
+
118
+ echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"' . checked( $checked, true, false ) . '>';
119
+ echo '<label for="jpibfi_disable_for_post">' . __( 'Disable "Pin it" button for this post (works only on single pages/posts)', 'jpibfi' ) . '</label><br />';
120
+ }
121
+
122
+ public function save_meta_data( $post_id ) {
123
+
124
+ //check user's permissions
125
+ if ( ! current_user_can( 'edit_post', $post_id ) )
126
+ return;
127
+ // check if this isn't an auto save
128
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
129
+ return;
130
+ // security check = updating possible only using post edit form
131
+ if ( !isset( $_POST['jpibfi_nonce'] ) || ! wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
132
+ return;
133
+
134
+ $post_meta = array( 'jpibfi_disable_for_post' => '0' );
135
+ // now store data in custom fields based on checkboxes selected
136
+ $post_meta['jpibfi_disable_for_post'] =
137
+ isset( $_POST['jpibfi_disable_for_post'] ) && $_POST['jpibfi_disable_for_post'] == '1' ? '1' : '0';
138
+
139
+ if ( $post_meta['jpibfi_disable_for_post'] == '1' )
140
+ update_post_meta( $post_id, JPIBFI_METADATA, $post_meta );
141
+ else
142
+ delete_post_meta( $post_id, JPIBFI_METADATA );
143
+ }
144
+ }
145
+
146
+ add_action( 'plugins_loaded', array( 'JPIBFI_Admin', 'get_instance' ) );
includes/admin/class-jpibfi-advanced-options.php ADDED
@@ -0,0 +1,106 @@
1
+ <?php
2
+
3
+ class JPIBFI_Advanced_Options {
4
+
5
+ protected static $instance = null;
6
+
7
+ protected $admin_advanced_options = null;
8
+
9
+ private function __construct() {
10
+ add_action( 'admin_init', array( $this, 'initialize_advanced_options' ) );
11
+ }
12
+
13
+ public static function get_instance() {
14
+ // If the single instance hasn't been set, set it now.
15
+ if ( null == self::$instance ) {
16
+ self::$instance = new self;
17
+ }
18
+
19
+ return self::$instance;
20
+ }
21
+
22
+ public static function default_advanced_options() {
23
+ $defaults = array(
24
+ 'debug' => '0',
25
+ 'container_selector' => 'div'
26
+ );
27
+
28
+ return apply_filters( 'jpibfi_default_advanced_options', $defaults );
29
+ }
30
+
31
+ /* Defines selection options section and adds all required fields */
32
+ public function initialize_advanced_options() {
33
+
34
+ // First, we register a section.
35
+ add_settings_section(
36
+ 'advanced_options_section',
37
+ __( 'Advanced Settings', 'jpibfi' ),
38
+ array( $this, 'advanced_options_callback' ),
39
+ 'jpibfi_advanced_options'
40
+ );
41
+
42
+ //lThen add all necessary fields to the section
43
+ add_settings_field(
44
+ 'debug',
45
+ __( 'Debug', 'jpibfi' ),
46
+ array( $this, 'debug_callback' ),
47
+ 'jpibfi_advanced_options',
48
+ 'advanced_options_section',
49
+ array(
50
+ __( 'Use debug mode only if you are experiencing some issues with the plugin and you are reporting them to the developer of the plugin', 'jpibfi' ),
51
+ )
52
+ );
53
+
54
+ add_settings_field(
55
+ 'container_selector',
56
+ __( 'Container selector', 'jpibfi' ),
57
+ array( $this, 'container_selector_callback' ),
58
+ 'jpibfi_advanced_options',
59
+ 'advanced_options_section',
60
+ array(
61
+ __( 'This is the selector used to find the container that holds the entire single post. It looks for an element that is a parent of the content of the post. Usually it\'s a div or article element. This setting is important to making "Use post url" visual setting work properly.', 'jpibfi' ),
62
+ )
63
+ );
64
+
65
+ register_setting(
66
+ 'jpibfi_advanced_options',
67
+ 'jpibfi_advanced_options' //no sanitization needed for now
68
+ );
69
+ }
70
+
71
+ public function advanced_options_callback() {
72
+ echo '<p>' . __('Advanced settings', 'jpibfi') . '</p>';
73
+ }
74
+
75
+ public function debug_callback( $args ){
76
+ $options = $this->get_advanced_options();
77
+ $debug = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'debug', '1' );
78
+
79
+ echo '<input type="checkbox" id="debug" name="jpibfi_advanced_options[debug]" value="1" ' . checked( "1", $debug, false ) . '>';
80
+ echo '<label for="debug">' . __( 'Enable debug mode', 'jpibfi' ) . '</label>';
81
+
82
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
83
+ }
84
+
85
+ public function container_selector_callback( $args ) {
86
+ $options = $this->get_advanced_options();
87
+ $container_selector = esc_attr( $options[ 'container_selector' ] );
88
+
89
+ echo '<input type="text" id="image_selector" name="jpibfi_advanced_options[container_selector]" value="' . $container_selector . '"/>';
90
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
91
+ }
92
+
93
+ private function get_advanced_options() {
94
+ global $jpibfi_adanced_options;
95
+
96
+ if ( null == $this->admin_advanced_options ) {
97
+ //cumbersome, but works in WP 3.3
98
+ $options = get_option( JPIBFI_ADVANCED_OPTIONS . '_errors' );
99
+ $this->admin_advanced_options = false == $options ? $jpibfi_adanced_options : $options;
100
+ }
101
+
102
+ return $this->admin_advanced_options;
103
+ }
104
+ }
105
+
106
+ add_action( 'plugins_loaded', array( 'JPIBFI_Advanced_Options', 'get_instance' ) );
includes/admin/class-jpibfi-selection-options.php ADDED
@@ -0,0 +1,315 @@
1
+ <?php
2
+
3
+ class JPIBFI_Selection_Options {
4
+
5
+ protected static $instance = null;
6
+
7
+ protected $admin_selection_options = null;
8
+
9
+ private function __construct() {
10
+ add_action( 'admin_init', array( $this, 'initialize_selection_options' ) );
11
+ }
12
+
13
+ public static function get_instance() {
14
+ // If the single instance hasn't been set, set it now.
15
+ if ( null == self::$instance ) {
16
+ self::$instance = new self;
17
+ }
18
+
19
+ return self::$instance;
20
+ }
21
+
22
+ /* Default values for selection options section */
23
+ public static function default_selection_options() {
24
+ $defaults = array(
25
+ 'image_selector' => '.jpibfi_container img',
26
+ 'disabled_classes' => 'nopin;wp-smiley',
27
+ 'enabled_classes' => '',
28
+ 'min_image_height' => '0',
29
+ 'min_image_width' => '0',
30
+ 'show_on_home' => '1',
31
+ 'show_on_single' => '1',
32
+ 'show_on_page' => '1',
33
+ 'show_on_category' => '1',
34
+ 'show_on_blog' => '1'
35
+ );
36
+
37
+ return apply_filters('jpibfi_default_selection_options', $defaults);
38
+ }
39
+
40
+ /*
41
+ * Defines selection options section and adds all required fields
42
+ */
43
+ public function initialize_selection_options() {
44
+
45
+ // First, we register a section.
46
+ add_settings_section(
47
+ 'selection_options_section', // ID used to identify this section and with which to register options
48
+ __( 'Selection', 'jpibfi' ), // Title to be displayed on the administration page
49
+ array( $this, 'selection_options_callback' ), // Callback used to render the description of the section
50
+ 'jpibfi_selection_options' // Page on which to add this section of options
51
+ );
52
+
53
+ //lThen add all necessary fields to the section
54
+ add_settings_field(
55
+ 'image_selector', // ID used to identify the field throughout the plugin
56
+ __( 'Image selector', 'jpibfi' ), // The label to the left of the option interface element
57
+ array( $this, 'image_selector_callback'), // The name of the function responsible for rendering the option interface
58
+ 'jpibfi_selection_options', // The page on which this option will be displayed
59
+ 'selection_options_section', // The name of the section to which this field belongs
60
+ array( // The array of arguments to pass to the callback. In this case, just a description.
61
+ sprintf ( __( 'jQuery selector for all the images that should have the "Pin it" button. Set the value to %s if you want the "Pin it" button to appear only on images in content or %s 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. %sClick here%s to read about jQuery selectors.', 'jpibfi' ),
62
+ '<a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a>',
63
+ '<a href="#" class="jpibfi_selector_option">img</a>',
64
+ '<a href="http://api.jquery.com/category/selectors/" target="_blank">',
65
+ '</a>'
66
+ )
67
+ )
68
+ );
69
+
70
+ add_settings_field(
71
+ 'disabled_classes',
72
+ __( 'Disabled classes', 'jpibfi' ),
73
+ array( $this, 'disabled_classes_callback' ),
74
+ 'jpibfi_selection_options',
75
+ 'selection_options_section',
76
+ array(
77
+ __( 'Pictures with these CSS classes won\'t show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.', 'jpibfi' ),
78
+ )
79
+ );
80
+
81
+ add_settings_field(
82
+ 'enabled_classes',
83
+ __( 'Enabled classes', 'jpibfi' ),
84
+ array( $this, 'enabled_classes_callback' ),
85
+ 'jpibfi_selection_options',
86
+ 'selection_options_section',
87
+ array(
88
+ __( 'Only 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.', 'jpibfi' ),
89
+ )
90
+ );
91
+
92
+ add_settings_field(
93
+ 'show_on_field',
94
+ __( 'On which pages the "Pin it" button should be shown', 'jpibfi' ),
95
+ array( $this, 'show_on_field_callback' ),
96
+ 'jpibfi_selection_options',
97
+ 'selection_options_section',
98
+ array(
99
+ __( 'Check on which pages you want the Pinterest button to show up.', 'jpibfi' ),
100
+ )
101
+ );
102
+
103
+ add_settings_field(
104
+ 'min_image',
105
+ __( 'Minimum resolution that should trigger the "Pin it" button to show up', 'jpibfi' ),
106
+ array( $this, 'min_image_callback' ),
107
+ 'jpibfi_selection_options',
108
+ 'selection_options_section',
109
+ array(
110
+ __( 'If you\'d like the "Pin it" button to not show up on small images (e.g. social media icons), just set the appropriate values above. The default values cause the "Pin it" button to show on every eligible image.', 'jpibfi' ),
111
+ )
112
+ );
113
+
114
+ register_setting(
115
+ 'jpibfi_selection_options',
116
+ 'jpibfi_selection_options',
117
+ array( $this, 'sanitize_selection_options' )
118
+ );
119
+ }
120
+
121
+ public function selection_options_callback() {
122
+ echo '<p>' . __('Which images can be pinned', 'jpibfi') . '</p>';
123
+ }
124
+
125
+ public function image_selector_callback( $args ) {
126
+
127
+ $options = $this->get_selection_options();
128
+
129
+ $selector = esc_attr( $options['image_selector'] );
130
+
131
+ echo '<input type="text" id="image_selector" name="jpibfi_selection_options[image_selector]" value="' . $selector . '"/>';
132
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
133
+ }
134
+
135
+ public function disabled_classes_callback( $args ){
136
+
137
+ $options = $this->get_selection_options();
138
+ $value = esc_attr( $options[ 'disabled_classes' ] );
139
+
140
+ ?>
141
+ <input type="hidden" name="jpibfi_selection_options[disabled_classes]" value="{{ disabledClassesFormatted }}" ng-init="initDisabledClasses('<?php echo $value; ?>')">
142
+ <span ng-hide="disabledClasses.length > 0">
143
+ <?php echo JPIBFI_Admin_Utilities::create_description( __( 'No classes added.', 'jpibfi' ) ); ?>
144
+ </span>
145
+ <ul class="jpibfi-classes-list" ng-hide="disabledClasses.length == 0">
146
+ <li ng-repeat="class in disabledClasses">
147
+ <a ng-click="deleteDisabledClass(class)">X</a><span>{{ class }}</span>
148
+ </li>
149
+ </ul>
150
+ <div>
151
+ <div>
152
+ <label for="disabledClass" ><?php _e( 'Class name', 'jpibfi' ); ?></label>
153
+ <input id="disabledClass" type="text" ng-model="disabledClass">
154
+ <button type="button" ng-click="addDisabledClass(disabledClass)"><?php _e( 'Add to list', 'jpibfi' ); ?></button>
155
+ </div>
156
+ </div>
157
+
158
+ <?php
159
+
160
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
161
+ echo JPIBFI_Admin_Utilities::create_errors( 'disabled_classes' );
162
+ }
163
+
164
+ public function enabled_classes_callback( $args ){
165
+
166
+ $options = $this->get_selection_options();
167
+ $value = esc_attr( $options[ 'enabled_classes' ] );
168
+
169
+ ?>
170
+ <input type="hidden" name="jpibfi_selection_options[enabled_classes]" value="{{ enabledClassesFormatted }}" ng-init="initEnabledClasses('<?php echo $value; ?>')">
171
+ <span ng-hide="enabledClasses.length > 0">
172
+ <?php echo JPIBFI_Admin_Utilities::create_description( __( 'No classes added.', 'jpibfi' ) ); ?>
173
+ </span>
174
+ <ul class="jpibfi-classes-list" ng-hide="enabledClasses.length == 0">
175
+ <li ng-repeat="class in enabledClasses">
176
+ <a ng-click="deleteEnabledClass(class)">X</a><span>{{ class }}</span>
177
+ </li>
178
+ </ul>
179
+ <div>
180
+ <div>
181
+ <label for="enabledClass" ><?php _e( 'Class name', 'jpibfi' ); ?></label>
182
+ <input id="enabledClass" type="text" ng-model="enabledClass">
183
+ <button type="button" ng-click="addEnabledClass(enabledClass)"><?php _e( 'Add to list', 'jpibfi' ); ?></button>
184
+ </div>
185
+ </div>
186
+
187
+ <?php
188
+
189
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
190
+ echo JPIBFI_Admin_Utilities::create_errors( 'enabled_classes' );
191
+ }
192
+
193
+ public function show_on_field_callback( $args ) {
194
+ $options = $this->get_selection_options();
195
+
196
+ $show_on_home = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_home', '1' );
197
+ $show_on_page = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_page', '1' );
198
+ $show_on_single = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_single', '1' );
199
+ $show_on_category = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_category', '1' );
200
+ $show_on_blog = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_blog', '1' );
201
+ ?>
202
+
203
+ <input type="checkbox" id="show_on_home" name="jpibfi_selection_options[show_on_home]" <?php checked( true, $show_on_home ); ?> value="1" />
204
+ <label for="show_on_home"><?php _e( 'Home page', 'jpibfi' ); ?></label><br/>
205
+ <input type="checkbox" id="show_on_page" name="jpibfi_selection_options[show_on_page]" <?php checked( true, $show_on_page ); ?> value="1" />
206
+ <label for="show_on_page"><?php _e( 'Pages', 'jpibfi' ); ?></label><br />
207
+ <input type="checkbox" id="show_on_single" name="jpibfi_selection_options[show_on_single]" <?php checked( true, $show_on_single ); ?> value="1" />
208
+ <label for="show_on_single"><?php _e( 'Single posts', 'jpibfi' ); ?></label><br />
209
+ <input type="checkbox" id="show_on_category" name="jpibfi_selection_options[show_on_category]" <?php checked( true, $show_on_category ); ?> value="1" />
210
+ <label for="show_on_category"><?php _e( 'Category and archive pages', 'jpibfi' ); ?></label><br />
211
+ <input type="checkbox" id="show_on_blog" name="jpibfi_selection_options[show_on_blog]" <?php checked( true, $show_on_blog ); ?> value="1" />
212
+ <label for="show_on_blog"><?php _e( 'Blog pages', 'jpibfi' ); ?></label>
213
+
214
+ <?php
215
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
216
+ }
217
+
218
+ public function min_image_callback( $args ) {
219
+ $options = $this->get_selection_options();
220
+
221
+ $min_image_height = $options[ 'min_image_height' ];
222
+ $min_image_width = $options[ 'min_image_width' ];
223
+ ?>
224
+
225
+ <p>
226
+ <label for="min_image_height"><?php _e('Height', 'jpibfi'); ?></label>
227
+ <input type="number" min="0" step="1" id="min_image_height" name="jpibfi_selection_options[min_image_height]" value="<?php echo $min_image_height; ?>"
228
+ class="small-text" /> px
229
+ <?php echo JPIBFI_Admin_Utilities::create_errors( 'min_image_height' ); ?>
230
+ </p>
231
+
232
+ <p>
233
+ <label for="min_image_width"><?php _e('Width', 'jpibfi'); ?></label>
234
+ <input type="number" min="0" step="1" id="min_image_width" name="jpibfi_selection_options[min_image_width]" value="<?php echo $min_image_width; ?>"
235
+ class="small-text" /> px
236
+ <?php echo JPIBFI_Admin_Utilities::create_errors( 'min_image_width' ); ?>
237
+ </p>
238
+
239
+ <?php
240
+
241
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
242
+ }
243
+
244
+ public function sanitize_selection_options( $input ) {
245
+ global $jpibfi_selection_options;
246
+
247
+ foreach( $input as $key => $value ) {
248
+ switch($key) {
249
+ case 'disabled_classes':
250
+ case 'enabled_classes':
251
+ if ( false == JPIBFI_Admin_Utilities::contains_css_class_names_or_empty( $input [ $key ] ) ) {
252
+
253
+ $field = '';
254
+ if ( 'disabled_classes' == $key )
255
+ $field = __( 'Disabled classes', 'jpibfi' );
256
+ else if ( 'enabled_classes' == $key )
257
+ $field = __( 'Enabled classes', 'jpibfi' );
258
+
259
+ add_settings_error(
260
+ $key,
261
+ esc_attr( 'settings_updated' ),
262
+ $field . ' - ' . __('the given value doesn\'t meet the requirements. Please correct it and try again.', 'jpibfi')
263
+ );
264
+ }
265
+ break;
266
+ case 'min_image_height':
267
+ case 'min_image_width':
268
+ if ( !is_numeric( $value ) || $value < 0 ) {
269
+
270
+ $field = '';
271
+ if ( 'min_image_height' == $key )
272
+ $field = __( 'Minimum image height', 'jpibfi' );
273
+ else if ( 'min_image_width' == $key )
274
+ $field = __( 'Minimum image width', 'jpibfi' );
275
+
276
+ add_settings_error(
277
+ $key,
278
+ esc_attr( 'settings_updated' ),
279
+ $field . ' - ' . sprintf ( __('value must be a number greater or equal to %d.', 'jpibfi'), '0' )
280
+ );
281
+ }
282
+ break;
283
+ }
284
+
285
+ }
286
+
287
+ $errors = get_settings_errors();
288
+
289
+ if ( count( $errors ) > 0 ) {
290
+
291
+ update_option( JPIBFI_SELECTION_OPTIONS . '_errors', $input );
292
+ return $jpibfi_selection_options;
293
+
294
+ } else {
295
+
296
+ delete_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
297
+ return $input;
298
+
299
+ }
300
+ }
301
+
302
+ private function get_selection_options() {
303
+ global $jpibfi_selection_options;
304
+
305
+ if ( null == $this->admin_selection_options ) {
306
+ //cumbersome, but works in WP 3.3
307
+ $options = get_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
308
+ $this->admin_selection_options = false == $options ? $jpibfi_selection_options : $options;
309
+ }
310
+
311
+ return $this->admin_selection_options;
312
+ }
313
+ }
314
+
315
+ add_action( 'plugins_loaded', array( 'JPIBFI_Selection_Options', 'get_instance' ) );
includes/admin/class-jpibfi-visual-options.php ADDED
@@ -0,0 +1,381 @@
1
+ <?php
2
+
3
+ class JPIBFI_Visual_Options {
4
+ protected static $instance = null;
5
+
6
+ protected $admin_visual_options = null;
7
+
8
+ private function __construct() {
9
+ add_action( 'admin_init', array( $this, 'initialize_visual_options' ) );
10
+
11
+ }
12
+
13
+ public static function get_instance() {
14
+ // If the single instance hasn't been set, set it now.
15
+ if ( null == self::$instance ) {
16
+ self::$instance = new self;
17
+ }
18
+
19
+ return self::$instance;
20
+ }
21
+
22
+ private function get_visual_options() {
23
+ global $jpibfi_visual_options;
24
+
25
+ if ( null == $this->admin_visual_options ) {
26
+ //cumbersome, but works in WP 3.3
27
+ $options = get_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
28
+ $this->admin_visual_options = false == $options ? $jpibfi_visual_options : $options;
29
+ }
30
+
31
+ return $this->admin_visual_options;
32
+ }
33
+
34
+ /* Default values for visual options section */
35
+ public static function default_visual_options() {
36
+
37
+ $defaults = array(
38
+ 'transparency_value' => '0.5',
39
+ 'description_option' => '1',
40
+ 'use_custom_image' => '0',
41
+ 'custom_image_url' => '',
42
+ 'custom_image_height' => '0',
43
+ 'custom_image_width' => '0',
44
+ 'use_post_url' => '0',
45
+ 'button_position' => '0',
46
+ 'mode' => 'static',
47
+ 'button_margin_top' => '20',
48
+ 'button_margin_right' => '20',
49
+ 'button_margin_bottom'=> '20',
50
+ 'button_margin_left' => '20',
51
+ 'retina_friendly' => '0'
52
+ );
53
+
54
+ return apply_filters( 'jpibfi_default_visual_options', $defaults );
55
+ }
56
+
57
+ /* Defines visual options section and defines all required fields */
58
+ public function initialize_visual_options() {
59
+
60
+ // First, we register a section.
61
+ add_settings_section(
62
+ 'visual_options_section', // ID used to identify this section and with which to register options
63
+ __( 'Visual', 'jpibfi' ), // Title to be displayed on the administration page
64
+ array( $this, 'visual_options_callback' ), // Callback used to render the description of the section
65
+ 'jpibfi_visual_options' // Page on which to add this section of options
66
+ );
67
+
68
+ //Then add all necessary fields to the section
69
+ add_settings_field(
70
+ 'mode',
71
+ __( 'Mode', 'jpibfi' ),
72
+ array( $this, 'mode_option_callback' ),
73
+ 'jpibfi_visual_options',
74
+ 'visual_options_section',
75
+ array(
76
+ __( 'Static mode adds a layer on the top of the image that restricts image download, but works on websites that protect images download. Dynamic mode doesn\'t add that layer and allows image download. If you\'re experiencing issues with static mode, try using dynamic mode.', 'jpibfi' ),
77
+ )
78
+ );
79
+
80
+ add_settings_field(
81
+ 'description_option',
82
+ __( 'Description source', 'jpibfi' ),
83
+ array( $this, 'description_option_callback' ),
84
+ 'jpibfi_visual_options',
85
+ 'visual_options_section',
86
+ array(
87
+ __( 'From where the Pinterest message should be taken. Please note that "Image description" works properly only for images that were added to your Media Library.', 'jpibfi' ),
88
+ )
89
+ );
90
+
91
+ add_settings_field(
92
+ 'use_post_url',
93
+ __( 'Linked page', 'jpibfi' ),
94
+ array( $this, 'use_post_url_callback' ),
95
+ 'jpibfi_visual_options',
96
+ 'visual_options_section',
97
+ array(
98
+ __( 'When checked, the link on Pinterest will always point to the individual page with the image and title of this individual page will be used if you\'ve selected Title as the description source, even when the image was pinned on an archive page, category page or homepage. If false, the link will point to the URL the user is currently on.', 'jpibfi' ),
99
+ )
100
+ );
101
+
102
+ add_settings_field(
103
+ 'transparency_value',
104
+ __( 'Transparency value', 'jpibfi' ),
105
+ array( $this, 'transparency_value_callback' ),
106
+ 'jpibfi_visual_options',
107
+ 'visual_options_section',
108
+ array(
109
+ __( 'This setting sets the transparency of the image.', 'jpibfi' ),
110
+ )
111
+ );
112
+
113
+ add_settings_field(
114
+ 'custom_pin_it_button',
115
+ __( 'Custom "Pin It" button', 'jpibfi' ),
116
+ array( $this, 'custom_pin_it_button_callback' ),
117
+ 'jpibfi_visual_options',
118
+ 'visual_options_section',
119
+ array(
120
+ __( 'Check the <b>Use custom image</b> checkbox, specify image\'s URL, height and width to use your own Pinterest button design. You can just upload an image using Wordpress media library if you wish.', 'jpibfi' ),
121
+ )
122
+ );
123
+
124
+ add_settings_field(
125
+ 'pin_it_button_position',
126
+ __( '"Pin it" button position', 'jpibfi' ),
127
+ array( $this, 'pin_it_button_position_callback' ),
128
+ 'jpibfi_visual_options',
129
+ 'visual_options_section',
130
+ array(
131
+ __( 'Where the "Pin it" button should appear on the image.', 'jpibfi' ),
132
+ )
133
+ );
134
+
135
+ add_settings_field(
136
+ 'pin_it_button_margins',
137
+ __( '"Pin it" button margins', 'jpibfi' ),
138
+ array( $this, 'pin_it_button_margins_callback' ),
139
+ 'jpibfi_visual_options',
140
+ 'visual_options_section',
141
+ array(
142
+ sprintf( __( 'Margins are used to adjust the position of the "Pin it" button, but not all margins are used on all button positions. Here is an example. If you\'re using the "%s" position, the button\'s position will be affected only by top and left margins. Bottom and right margins affect "%s" position, etc. The "%s" position does not use any margins at all.', 'jpibfi' ),
143
+ __( 'Top left', 'jpibfi' ),
144
+ __( 'Bottom right', 'jpibfi' ),
145
+ __( 'Middle', 'jpibfi' )
146
+ ),
147
+ )
148
+ );
149
+
150
+ add_settings_field(
151
+ 'retina_friendly',
152
+ __( 'Retina friendly', 'jpibfi' ),
153
+ array( $this, 'retina_friendly_callback' ),
154
+ 'jpibfi_visual_options',
155
+ 'visual_options_section',
156
+ array(
157
+ __( 'Please note that checking this option will result in rendering the "Pin it" button half of its normal size (if you use a 80x60 image, the button will be 40x30). When uploading a custom "Pin it" button (the default one is too small), please make sure both width and height are even numbers (i.e. divisible by two) when using this option.', 'jpibfi' ),
158
+ )
159
+ );
160
+
161
+ register_setting(
162
+ 'jpibfi_visual_options',
163
+ 'jpibfi_visual_options',
164
+ array( $this, 'sanitize_visual_options' )
165
+ );
166
+
167
+ }
168
+
169
+ public function visual_options_callback() {
170
+ echo '<p>' . __('How it should look like', 'jpibfi') . '</p>';
171
+ }
172
+
173
+ public function mode_option_callback( $args ) {
174
+ $options = $this->get_visual_options();
175
+ $mode = $options[ 'mode' ];
176
+
177
+ ?>
178
+
179
+ <select id="mode" name="jpibfi_visual_options[mode]">
180
+ <option value="static" <?php selected ( "static", $mode ); ?>><?php _e( 'Static', 'jpibfi' ); ?></option>
181
+ <option value="dynamic" <?php selected ( "dynamic", $mode ); ?>><?php _e( 'Dynamic', 'jpibfi' ); ?></option>
182
+ </select>
183
+
184
+ <?php
185
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
186
+ }
187
+
188
+ public function description_option_callback( $args ) {
189
+ $options = $this->get_visual_options();
190
+
191
+
192
+ $description_option = $options[ 'description_option' ];
193
+ ?>
194
+
195
+ <select id="description_option" name="jpibfi_visual_options[description_option]">
196
+ <option value="1" <?php selected ( "1", $description_option ); ?>><?php _e( 'Page title', 'jpibfi' ); ?></option>
197
+ <option value="2" <?php selected ( "2", $description_option ); ?>><?php _e( 'Page description', 'jpibfi' ); ?></option>
198
+ <option value="3" <?php selected ( "3", $description_option ); ?>><?php _e( 'Picture title or (if title not available) alt attribute', 'jpibfi' ); ?></option>
199
+ <option value="4" <?php selected ( "4", $description_option ); ?>><?php _e( 'Site title (Settings->General)', 'jpibfi' ); ?></option>
200
+ <option value="5" <?php selected ( "5", $description_option ); ?>><?php _e( 'Image description', 'jpibfi' ); ?></option>
201
+ </select>
202
+
203
+ <?php
204
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
205
+ }
206
+
207
+ public function use_post_url_callback( $args ) {
208
+
209
+ $options = $this->get_visual_options();
210
+ $use_post_url = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'use_post_url', '1' );
211
+
212
+ echo '<input type="checkbox" id="use_post_url" name="jpibfi_visual_options[use_post_url]" value="1" ' . checked( true, $use_post_url, false ) . '>';
213
+ echo '<label for="use_post_url">' . __( 'Always link to individual post page', 'jpibfi' ) . '</label>';
214
+
215
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
216
+ }
217
+
218
+ public function transparency_value_callback( $args ) {
219
+ $options = $this->get_visual_options();
220
+
221
+ $transparency_value = $options[ 'transparency_value' ];
222
+
223
+ echo '<label for="transparency_value">' . sprintf ( __('Choose transparency (between %.02f and %.02f)', 'jpibfi'), '0.00', '1.00' ) . '</label><br/>';
224
+ echo '<input type="number" min="0" max="1" step="0.01" id="transparency_value" name="jpibfi_visual_options[transparency_value]"' .
225
+ 'value="' . $transparency_value . '" class="small-text" >';
226
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
227
+ echo JPIBFI_Admin_Utilities::create_errors( 'transparency_value' );
228
+ }
229
+
230
+ public function custom_pin_it_button_callback( $args ) {
231
+ $options = $this->get_visual_options();
232
+
233
+ $use_custom_image = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'use_custom_image', '1' );
234
+ $custom_image_url = $options[ 'custom_image_url' ];
235
+ $custom_image_height = $options[ 'custom_image_height' ];
236
+ $custom_image_width = $options[ 'custom_image_width' ];
237
+
238
+ ?>
239
+ <p>
240
+ <input type="checkbox" id="use_custom_image" name="jpibfi_visual_options[use_custom_image]" value="1" <?php checked( true, $use_custom_image ); ?> >
241
+ <label class="chbox-label" for="use_custom_image"><?php _e( 'Use custom image', 'jpibfi' ); ?></label>
242
+ </p>
243
+
244
+ <button id=upload-image><?php _e( 'Upload an image using media library','jpibfi' ); ?></button><br />
245
+
246
+ <p>
247
+ <label for="custom_image_url"><?php _e( 'URL address of the image', 'jpibfi' ); ?></label>
248
+ <input type="url" id="custom_image_url" name="jpibfi_visual_options[custom_image_url]" value="<?php echo $custom_image_url; ?>">
249
+ </p>
250
+
251
+ <p>
252
+ <label for="custom_image_height"><?php _e( 'Height', 'jpibfi' ); ?></label>
253
+ <input type="number" min="0" step="1" id="custom_image_height" name="jpibfi_visual_options[custom_image_height]" value="<?php echo $custom_image_height; ?>"
254
+ class="small-text" /> px
255
+ <?php echo JPIBFI_Admin_Utilities::create_errors( 'custom_image_height' ); ?>
256
+ </p>
257
+
258
+ <p>
259
+ <label for="custom_image_width"><?php _e( 'Width', 'jpibfi' ); ?></label>
260
+ <input type="number" min="0" step="1" id="custom_image_width" name="jpibfi_visual_options[custom_image_width]" value="<?php echo $custom_image_width; ?>"
261
+ class="small-text" /> px
262
+ <?php echo JPIBFI_Admin_Utilities::create_errors( 'custom_image_width' ); ?>
263
+ </p>
264
+
265
+ <p>
266
+ <b><?php _e( 'Custom Pin It button preview', 'jpibfi' ); ?></b><br/>
267
+ <span id="custom_button_preview" style="width: <?php echo $custom_image_width; ?>px; height: <?php echo $custom_image_height; ?>px; background-image: url('<?php echo $custom_image_url; ?>');">
268
+ Preview
269
+ </span><br/>
270
+ <button id="refresh_custom_button_preview"><?php _e( 'Refresh preview', 'jpibfi' ); ?></button>
271
+ </p>
272
+
273
+ <?php
274
+
275
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
276
+ }
277
+
278
+ public function pin_it_button_position_callback( $args ) {
279
+ $options = $this->get_visual_options();
280
+
281
+ $jpibfi_button_dropdown = array(
282
+ __( 'Top left', 'jpibfi' ),
283
+ __( 'Top right', 'jpibfi' ),
284
+ __( 'Bottom left', 'jpibfi' ),
285
+ __( 'Bottom right', 'jpibfi' ),
286
+ __( 'Middle', 'jpibfi' )
287
+ );
288
+
289
+ $button_position = $options[ 'button_position' ];
290
+
291
+ ?>
292
+
293
+ <select name="jpibfi_visual_options[button_position]" id="button_position">
294
+ <?php for( $i = 0; $i < count( $jpibfi_button_dropdown ); $i++) { ?>
295
+ <option value="<?php echo $i; ?>" <?php selected( $i, $button_position ); ?>><?php echo $jpibfi_button_dropdown[ $i ]; ?></option>
296
+ <?php } ?>
297
+ </select><br/>
298
+
299
+ <?php
300
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
301
+ }
302
+
303
+ public function pin_it_button_margins_callback( $args ) {
304
+ $options = $this->get_visual_options();
305
+ ?>
306
+ <label for="button_margin_top"><?php _e('Top', 'jpibfi'); ?></label>
307
+ <input type="number" min="-1000" max="1000" step="1" id="button_margin_top" name="jpibfi_visual_options[button_margin_top]" value="<?php echo $options[ 'button_margin_top' ]; ?>" class="small-text" >px<br/>
308
+ <label for="button_margin_bottom"><?php _e('Bottom', 'jpibfi'); ?></label>
309
+ <input type="number" min="-1000" max="1000" step="1" id="button_margin_bottom" name="jpibfi_visual_options[button_margin_bottom]" value="<?php echo $options[ 'button_margin_bottom' ]; ?>" class="small-text" >px<br/>
310
+ <label for="button_margin_left"><?php _e('Left', 'jpibfi'); ?></label>
311
+ <input type="number" min="-1000" max="1000" step="1" id="button_margin_left" name="jpibfi_visual_options[button_margin_left]" value="<?php echo $options[ 'button_margin_left' ]; ?>" class="small-text" >px<br/>
312
+ <label for="button_margin_right"><?php _e('Right', 'jpibfi'); ?></label>
313
+ <input type="number" min="-1000" max="1000" step="1" id="button_margin_right" name="jpibfi_visual_options[button_margin_right]" value="<?php echo $options[ 'button_margin_right' ]; ?>" class="small-text" >px<br/>
314
+
315
+ <?php
316
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
317
+ }
318
+
319
+ public function retina_friendly_callback( $args ) {
320
+
321
+ $options = $this->get_visual_options();
322
+ $retina_friendly = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'retina_friendly', '1' );
323
+
324
+ echo '<input type="checkbox" id="retina_friendly" name="jpibfi_visual_options[retina_friendly]" value="1" ' . checked( true, $retina_friendly, false ) . '>';
325
+ echo '<label for="retina_friendly">' . __( 'Optimize for high pixel density displays', 'jpibfi' ) . '</label>';
326
+
327
+ echo JPIBFI_Admin_Utilities::create_description( $args[0] );
328
+ }
329
+
330
+ public function sanitize_visual_options( $input ) {
331
+ global $jpibfi_visual_options;
332
+
333
+ foreach( $input as $key => $value ) {
334
+
335
+ switch($key) {
336
+ case 'transparency_value':
337
+ if ( !is_numeric( $input[ $key ] ) || ( $input[ $key ] < 0.0 ) || ( $input[ $key ] > 1.0 ) ) {
338
+
339
+ add_settings_error(
340
+ $key,
341
+ esc_attr( 'settings_updated' ),
342
+ sprintf( __('Transparency value must be a number between %.02d and %.02f.', 'jpibfi'), '0.00', '1.00' )
343
+ );
344
+ }
345
+ break;
346
+ case 'custom_image_height':
347
+ case 'custom_image_width':
348
+ $name = "";
349
+ if ( 'custom_image_height' == $key )
350
+ $name = __('Custom image height', 'jpibfi' );
351
+ else if ( 'custom_image_width' == $key )
352
+ $name = __('Custom image width', 'jpibfi' );
353
+
354
+ if ( '' != $value && ( !is_numeric( $value ) || $value < 0 ) ) {
355
+ add_settings_error(
356
+ $key,
357
+ esc_attr( 'settings_updated' ),
358
+ $name . ' - ' . sprintf ( __('value must be a number greater or equal to %d.', 'jpibfi'), '0' )
359
+ );
360
+ }
361
+ break;
362
+ }
363
+ }
364
+
365
+ $errors = get_settings_errors();
366
+
367
+ if ( count( $errors ) > 0 ) {
368
+
369
+ update_option( JPIBFI_VISUAL_OPTIONS . '_errors', $input );
370
+ return $jpibfi_visual_options;
371
+
372
+ } else {
373
+
374
+ delete_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
375
+ return $input;
376
+
377
+ }
378
+ }
379
+ }
380
+
381
+ add_action( 'plugins_loaded', array( 'JPIBFI_Visual_Options', 'get_instance' ) );
includes/admin/index.php ADDED
@@ -0,0 +1 @@
1
+ <?php //Silence is golden
includes/admin/views/admin.php ADDED
@@ -0,0 +1,42 @@
1
+ <?php
2
+
3
+ ?>
4
+ <div class="wrap">
5
+
6
+ <h2><?php _e( 'jQuery Pin It Button For Images Options', 'jpibfi' ); ?></h2>
7
+ <?php
8
+ $tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'selection_options';
9
+ $tab_found = false;
10
+ foreach( $settings_tabs as $tab_name => $tab_settings)
11
+ $tab_found = $tab_found || ( $tab_name == $tab );
12
+
13
+ $tab = false == $tab_found ? 'selection_options' : $tab;
14
+ $current_settings = $settings_tabs[ $tab ];
15
+ //TODO dokończyć pętlę
16
+ ?>
17
+ <div id="icon-plugins" class="icon32"></div>
18
+ <h2 class="nav-tab-wrapper">
19
+ <?php foreach( $settings_tabs as $tab_name => $settings) { ?>
20
+ <a href="?page=jpibfi_settings&tab=<?php echo $tab_name; ?>" class="nav-tab <?php echo $tab_name == $tab ? 'nav-tab-active' : ''; ?>"><?php echo $settings['tab_label']; ?></a>
21
+ <?php } ?>
22
+ </h2>
23
+
24
+ <p>
25
+ <a href="http://mrsztuczkens.me/jquery-pin-it-button-for-images-customization/" class="button" target="_blank" rel="nofollow"><b><?php _e( 'Plugin Customization', 'jpibfi' ); ?></b></a>
26
+ <a href="http://mrsztuczkens.me/jquery-pin-it-button-for-images-extensions/" class="button" target="_blank" rel="nofollow"><b><?php _e( 'Plugin Extensions', 'jpibfi' ); ?></b></a>
27
+ <a href="http://bit.ly/Uw2mEP" class="button" target="_blank" rel="nofollow"><b><?php _e( 'Donate', 'jpibfi' ); ?></b></a>
28
+ <a href="<?php echo $current_settings['support_link']; ?>" class="button" target="_blank" rel="nofollow"><b><?php _e( 'Support forum', 'jpibfi' ); ?></b></a>
29
+ <a href="<?php echo $current_settings['review_link']; ?>" class="button" target="_blank" rel="nofollow"><b><?php _e( 'Leave a review', 'jpibfi' ); ?></b></a>
30
+ </p>
31
+ <form method="post" action="options.php" ng-app="jpibfiApp" ng-controller="jpibfiController">
32
+ <?php
33
+
34
+ settings_fields( $current_settings[ 'settings_name'] );
35
+ do_settings_sections( $current_settings[ 'settings_name'] );
36
+ submit_button();
37
+ ?>
38
+ </form>
39
+ <p>
40
+ The Silk Icon Set is provided by Mark James and is availble from <a href="http://famfamfam.com/lab/icons/silk/">FamFamFam</a> under the <a href="http://creativecommons.org/licenses/by/2.5/">Creative Commons Attribution 2.5 License</a>.
41
+ </p>
42
+ </div>
includes/admin/views/index.php ADDED
@@ -0,0 +1 @@
1
+ <?php //Silence is golden
includes/public/class-jpibfi-client-utilities.php ADDED
@@ -0,0 +1,110 @@
1
+ <?php
2
+
3
+ class JPIBFI_Client_Utilities {
4
+
5
+ //function gets the id of the image by searching for class with wp-image- prefix, otherwise returns empty string
6
+ public static function get_post_id_from_image_classes( $class_attribute ) {
7
+ $classes = preg_split( '/\s+/', $class_attribute, -1, PREG_SPLIT_NO_EMPTY );
8
+ $prefix = 'wp-image-';
9
+
10
+ for ($i = 0; $i < count( $classes ); $i++) {
11
+
12
+ if ( $prefix === substr( $classes[ $i ], 0, strlen( $prefix ) ))
13
+ return str_replace( $prefix, '', $classes[ $i ] );
14
+ }
15
+
16
+ return '';
17
+ }
18
+
19
+ /* Get description for a given image */
20
+ public static function get_image_description( $id, $src ) {
21
+
22
+ $result = is_numeric( $id ) ? self::get_image_description_by_id( $id ) : '';
23
+
24
+ //if description based on id wasn't found
25
+ if ( '' === $result ) {
26
+ $id = self::fjarrett_get_attachment_id_by_url( $src );
27
+ $result = is_numeric ( $id ) ? self::get_image_description_by_id( $id ) : '';
28
+ }
29
+
30
+ return $result;
31
+ }
32
+
33
+ /* Function searches for image based on $id and returns its description */
34
+ static function get_image_description_by_id( $id ){
35
+
36
+ $attachment = get_post( $id );
37
+ return null == $attachment ? '' : $attachment->post_content;
38
+ }
39
+
40
+ /**
41
+ * Function copied from http://frankiejarrett.com/get-an-attachment-id-by-url-in-wordpress/
42
+ * Return an ID of an attachment by searching the database with the file URL.
43
+ *
44
+ * First checks to see if the $url is pointing to a file that exists in
45
+ * the wp-content directory. If so, then we search the database for a
46
+ * partial match consisting of the remaining path AFTER the wp-content
47
+ * directory. Finally, if a match is found the attachment ID will be
48
+ * returned.
49
+ *
50
+ * @return {int} $attachment
51
+ */
52
+ static function fjarrett_get_attachment_id_by_url( $url ) {
53
+
54
+ // Split the $url into two parts with the wp-content directory as the separator.
55
+ $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
56
+
57
+ // Get the host of the current site and the host of the $url, ignoring www.
58
+ $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
59
+ $file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
60
+
61
+ // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
62
+ if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) )
63
+ return;
64
+
65
+ // Now we're going to quickly search the DB for any attachment GUID with a partial path match.
66
+ // Example: /uploads/2013/05/test-image.jpg
67
+ global $wpdb;
68
+
69
+ $prefix = $wpdb->prefix;
70
+ $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $prefix . "posts WHERE guid RLIKE %s;", $parse_url[1] ) );
71
+
72
+ // Returns null if no attachment is found.
73
+ return $attachment ? $attachment[0] : null;
74
+ }
75
+
76
+ /* True if plugin should be added to the current post/page */
77
+ public static function add_jpibfi() {
78
+ global $post;
79
+ global $jpibfi_selection_options;
80
+
81
+ if ( is_front_page() )
82
+ return isset( $jpibfi_selection_options['show_on_home'] ) && $jpibfi_selection_options['show_on_home'] == "1";
83
+ else if ( is_single() )
84
+ return isset( $jpibfi_selection_options['show_on_single'] ) && $jpibfi_selection_options['show_on_single'] == "1" ? self::add_plugin_to_post( $post->ID ) : false;
85
+ else if ( is_page() )
86
+ return isset( $jpibfi_selection_options['show_on_page'] ) && $jpibfi_selection_options['show_on_page'] == "1" ? self::add_plugin_to_post( $post->ID ) : false;
87
+ else if ( is_category() || is_archive() || is_search() )
88
+ return isset( $jpibfi_selection_options['show_on_category'] ) && $jpibfi_selection_options['show_on_category'] == "1";
89
+ else if ( self::is_blog_page() )
90
+ return isset( $jpibfi_selection_options['show_on_blog'] ) && $jpibfi_selection_options['show_on_blog'] == "1";
91
+ return true;
92
+ }
93
+
94
+ /* Checks if the plugin wasn't deactivated in the given post/page */
95
+ private static function add_plugin_to_post( $post_id ) {
96
+ $post_meta = get_post_meta( $post_id, JPIBFI_METADATA, true );
97
+ return empty( $post_meta )
98
+ || false == array_key_exists( 'jpibfi_disable_for_post', $post_meta )
99
+ || '1' != $post_meta['jpibfi_disable_for_post'];
100
+ }
101
+
102
+ /* function copied from https://gist.github.com/wesbos/1189639 */
103
+ private static function is_blog_page() {
104
+ global $post;
105
+
106
+ $post_type = get_post_type( $post );
107
+
108
+ return ( ( is_home() || is_archive() || is_single() ) && ( $post_type == 'post' ) );
109
+ }
110
+ }
includes/public/class-jpibfi-client.php ADDED
@@ -0,0 +1,222 @@
1
+ <?php
2
+
3
+ class JPIBFI_Client {
4
+
5
+ protected static $instance = null;
6
+
7
+ private function __construct() {
8
+ $this->setup_constants();
9
+ add_action( 'wp_enqueue_scripts', array( $this, 'add_plugin_scripts' ) );
10
+ add_action( 'wp_enqueue_scripts', array( $this, 'add_plugin_styles' ) );
11
+ add_action( 'wp_head', array( $this, 'print_header_style' ) );
12
+ add_filter( "the_content", array( $this, 'prepare_the_content' ) );
13
+ add_filter( "the_excerpt", array( $this, 'prepare_the_content' ) );
14
+ }
15
+
16
+ public static function get_instance() {
17
+ // If the single instance hasn't been set, set it now.
18
+ if ( null == self::$instance ) {
19
+ self::$instance = new self;
20
+ }
21
+
22
+ return self::$instance;
23
+ }
24
+
25
+ private function setup_constants() {
26
+ if ( ! defined( 'JPIBFI_IMAGE_WIDTH' ) )
27
+ define( 'JPIBFI_IMAGE_WIDTH', 65 );
28
+
29
+ if ( ! defined( 'JPIBFI_IMAGE_HEIGHT' ) )
30
+ define( 'JPIBFI_IMAGE_HEIGHT', 41 );
31
+ }
32
+
33
+ //Adds all necessary styles
34
+ public function add_plugin_styles() {
35
+ if ( ! ( JPIBFI_Client_Utilities::add_jpibfi() ) )
36
+ return;
37
+
38
+ wp_register_style( 'jquery-pin-it-button-style', JPIBFI_STYLE_URL . 'style.css', array(), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, 'all' );
39
+ wp_enqueue_style( 'jquery-pin-it-button-style' );
40
+ }
41
+
42
+ //Adds all necessary scripts
43
+ public function add_plugin_scripts() {
44
+ global $jpibfi_selection_options;
45
+ global $jpibfi_visual_options;
46
+ global $jpibfi_adanced_options;
47
+
48
+ if ( ! ( JPIBFI_Client_Utilities::add_jpibfi() ) )
49
+ return;
50
+ //TODO minify
51
+ wp_enqueue_script( 'jquery-pin-it-button-script', JPIBFI_SCRIPT_URL . 'script.min.js', array( 'jquery' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
52
+
53
+ $use_custom_image = isset( $jpibfi_visual_options[ 'use_custom_image' ] ) && $jpibfi_visual_options[ 'use_custom_image' ] == "1";
54
+
55
+ $parameters_array = array(
56
+ 'imageSelector' => $jpibfi_selection_options['image_selector'],
57
+ 'disabledClasses' => $jpibfi_selection_options['disabled_classes'],
58
+ 'enabledClasses' => $jpibfi_selection_options['enabled_classes'],
59
+ 'descriptionOption' => $jpibfi_visual_options['description_option'],
60
+ 'usePostUrl' => isset ( $jpibfi_visual_options['use_post_url'] ) ? $jpibfi_visual_options['use_post_url'] : '0',
61
+ 'minImageHeight' => $jpibfi_selection_options['min_image_height'],
62
+ 'minImageWidth' => $jpibfi_selection_options['min_image_width'],
63
+ 'siteTitle' => get_bloginfo( 'name', 'display' ),
64
+ 'mode' => $jpibfi_visual_options[ 'mode' ],
65
+ 'buttonPosition' => $jpibfi_visual_options[ 'button_position' ],
66
+ 'debug' => isset( $jpibfi_adanced_options[ 'debug'] ) ? $jpibfi_adanced_options[ 'debug'] : '0',
67
+ 'containerSelector' => $jpibfi_adanced_options[ 'container_selector'],
68
+ 'pinImageHeight' => $use_custom_image ? $jpibfi_visual_options['custom_image_height'] : JPIBFI_IMAGE_HEIGHT,
69
+ 'pinImageWidth' => $use_custom_image ? $jpibfi_visual_options['custom_image_width'] : JPIBFI_IMAGE_WIDTH,
70
+ 'buttonMarginTop' => $jpibfi_visual_options[ 'button_margin_top' ],
71
+ 'buttonMarginBottom' => $jpibfi_visual_options[ 'button_margin_bottom' ],
72
+ 'buttonMarginLeft'=> $jpibfi_visual_options[ 'button_margin_left' ],
73
+ 'buttonMarginRight' => $jpibfi_visual_options[ 'button_margin_right' ]
74
+ );
75
+
76
+ wp_localize_script( 'jquery-pin-it-button-script', 'jpibfi_options', apply_filters( 'jpibfi_javascript_parameters', $parameters_array ) );
77
+ }
78
+
79
+ public function print_header_style() {
80
+ global $jpibfi_visual_options;
81
+
82
+ if ( ! ( JPIBFI_Client_Utilities::add_jpibfi() ) )
83
+ return;
84
+
85
+ $use_custom_image = isset( $jpibfi_visual_options[ 'use_custom_image' ] ) && $jpibfi_visual_options[ 'use_custom_image' ] == "1";
86
+
87
+ $width = $use_custom_image ? $jpibfi_visual_options['custom_image_width'] : JPIBFI_IMAGE_WIDTH;
88
+ $height = $use_custom_image ? $jpibfi_visual_options['custom_image_height'] : JPIBFI_IMAGE_HEIGHT;
89
+
90
+ if ( isset( $jpibfi_visual_options[ 'retina_friendly' ] ) && $jpibfi_visual_options[ 'retina_friendly' ] == '1' ){
91
+ $width = floor( $width / 2 );
92
+ $height = floor ( $height / 2 );
93
+ }
94
+
95
+ $url = $use_custom_image ? $jpibfi_visual_options['custom_image_url'] : JPIBFI_PLUGIN_URL . 'images/pinit-button.png';
96
+
97
+ ?>
98
+ <!--[if lt IE 9]>
99
+ <style type="text/css">
100
+ .pinit-overlay {
101
+ background-image: url( '<?php echo JPIBFI_PLUGIN_URL . 'images/transparency_0.png'; ?>' ) !important;
102
+ }
103
+ </style>
104
+ <![endif]-->
105
+
106
+ <style type="text/css">
107
+ a.pinit-button {
108
+ width: <?php echo $width; ?>px !important;
109
+ height: <?php echo $height; ?>px !important;
110
+ background: transparent url('<?php echo $url; ?>') no-repeat 0 0 !important;
111
+ background-size: <?php echo $width; ?>px <?php echo $height; ?>px !important
112
+ }
113
+
114
+ a.pinit-button.pinit-top-left {
115
+ <?php printf('margin: %dpx 0 0 %dpx', $jpibfi_visual_options['button_margin_top'], $jpibfi_visual_options['button_margin_left']); ?>
116
+ }
117
+
118
+ a.pinit-button.pinit-top-right {
119
+ <?php printf('margin: %dpx %dpx 0 0', $jpibfi_visual_options['button_margin_top'], $jpibfi_visual_options['button_margin_right']); ?>
120
+ }
121
+
122
+ a.pinit-button.pinit-bottom-left {
123
+ <?php printf('margin: 0 0 %dpx %dpx', $jpibfi_visual_options['button_margin_bottom'], $jpibfi_visual_options['button_margin_left']); ?>
124
+ }
125
+
126
+ a.pinit-button.pinit-bottom-right {
127
+ <?php printf('margin: 0 %dpx %dpx 0', $jpibfi_visual_options['button_margin_right'], $jpibfi_visual_options['button_margin_bottom']); ?>
128
+ }
129
+
130
+ img.pinit-hover {
131
+ opacity: <?php echo (1 - $jpibfi_visual_options['transparency_value']); ?> !important;
132
+ filter:alpha(opacity=<?php echo (1 - $jpibfi_visual_options['transparency_value']) * 100; ?>) !important; /* For IE8 and earlier */
133
+ }
134
+ </style>
135
+ <?php
136
+ }
137
+
138
+ /*
139
+ * Adds a hidden field with url and and description of the pin that's used when user uses "Link to individual page"
140
+ * Thanks go to brocheafoin, who added most of the code that handles creating description
141
+ */
142
+ public function prepare_the_content( $content ) {
143
+ if ( ! JPIBFI_Client_Utilities::add_jpibfi() )
144
+ return $content;
145
+
146
+ global $post;
147
+ global $jpibfi_visual_options;
148
+
149
+ $add_attributes = false == is_singular() && isset( $jpibfi_visual_options[ 'use_post_url' ] ) && '1' == $jpibfi_visual_options[ 'use_post_url' ];
150
+
151
+ $attributes_html = '';
152
+
153
+ //if we need to add additional attributes to handle use_post_url setting
154
+ if ( $add_attributes ){
155
+ //if page description should be used as pin description and an excerpt for the post exists
156
+ if ( has_excerpt( $post->ID ) && 2 == $jpibfi_visual_options[ 'description_option' ] )
157
+ $description = wp_kses( $post->post_excerpt, array() );
158
+ else
159
+ $description = get_the_title($post->ID);
160
+
161
+ $attributes_html .= 'data-jpibfi-url="' . get_permalink( $post->ID ) . '" ' ;
162
+ $attributes_html .= 'data-jpibfi-description ="' . esc_attr( $description ) . '" ';
163
+ }
164
+
165
+ $input_html = '<input class="jpibfi" type="hidden" ' . $attributes_html . '>';
166
+ $content = $input_html . $content;
167
+
168
+ $add_image_descriptions = '5' == $jpibfi_visual_options[ 'description_option' ];
169
+
170
+ //if we need to add data-jpibfi-description to each image
171
+ if ( $add_image_descriptions ){
172
+ $content = $this->add_description_attribute_to_images( $content );
173
+ }
174
+
175
+ return $content;
176
+ }
177
+
178
+ /* PRIVATE METHODS */
179
+
180
+ /*
181
+ * Adds data-jpibfi-description attribute to each image that is added through media library. The value is the "Description" of the image from media library.
182
+ * This piece of code uses a lot of code from the Photo Protect http://wordpress.org/plugins/photo-protect/ plugin
183
+ */
184
+ private function add_description_attribute_to_images( $content ) {
185
+
186
+ $imgPattern = '/<img[^>]*>/i';
187
+ $attrPattern = '/ ([\w]+)[ ]*=[ ]*([\"\'])(.*?)\2/i';
188
+
189
+ preg_match_all($imgPattern, $content, $images, PREG_SET_ORDER);
190
+
191
+ foreach ($images as $img) {
192
+
193
+ preg_match_all($attrPattern, $img[0], $attributes, PREG_SET_ORDER);
194
+
195
+ $newImg = '<img';
196
+ $src = '';
197
+ $id = '';
198
+
199
+ foreach ($attributes as $att) {
200
+ $full = $att[0];
201
+ $name = $att[1];
202
+ $value = $att[3];
203
+
204
+ $newImg .= $full;
205
+
206
+ if ('class' == $name ) {
207
+ $id = JPIBFI_Client_Utilities::get_post_id_from_image_classes( $value );
208
+ } else if ( 'src' == $name ) {
209
+ $src = $value;
210
+ }
211
+ }
212
+
213
+ $description = JPIBFI_Client_Utilities::get_image_description( $id, $src );
214
+ $newImg .= ' data-jpibfi-description="' . esc_attr( $description ) . '" />';
215
+ $content = str_replace($img[0], $newImg, $content);
216
+ }
217
+
218
+ return $content;
219
+ }
220
+ }
221
+
222
+ add_action( 'plugins_loaded', array( 'JPIBFI_Client', 'get_instance' ) );
includes/public/index.php ADDED
@@ -0,0 +1 @@
1
+ <?php //Silence is golden
jquery-pin-it-button-for-images.php CHANGED
@@ -4,1473 +4,179 @@ Plugin Name: jQuery Pin It Button For Images
4
Plugin URI: http://mrsztuczkens.me/jpibfi/
5
Description: Highlights images on hover and adds a "Pin It" button over them for easy pinning.
6
Author: Marcin Skrzypiec
7
- Version: 1.21
8
Author URI: http://mrsztuczkens.me/
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
- /*
17
- *
18
- * CONSTANTS
19
- *
20
- */
21
- define( "JPIBFI_VERSION", "1.21" );
22
- define( "JPIBFI_VERSION_MINOR", "a" );
23
- define( "JPIBFI_METADATA", "jpibfi_meta" );
24
- define( "JPIBFI_UPDATE_OPTIONS", "jpibfi_update_options");
25
- define( "JPIBFI_SELECTION_OPTIONS", "jpibfi_selection_options" );
26
- define( "JPIBFI_VISUAL_OPTIONS", "jpibfi_visual_options" );
27
- define( "JPIBFI_ADVANCED_OPTIONS", "jpibfi_advanced_options" );
28
- define( "JPIBFI_VERSION_OPTION", "jpibfi_version");
29
-
30
- //DEFAULT PIN BUTTON IMAGE
31
- define( "JPIBFI_IMAGE_URL", plugins_url( '/images/pinit-button.png', __FILE__ ) );
32
- define( "JPIBFI_IMAGE_WIDTH", 65 );
33
- define( "JPIBFI_IMAGE_HEIGHT", 41 );
34
-
35
- /*
36
- *
37
- * FRONT END STUFF
38
- *
39
- */
40
-
41
- /*
42
- * Checks if the plugin wasn't deactivated in the given post/page
43
- */
44
- function jpibfi_add_plugin_to_post( $post_id ) {
45
- $post_meta = get_post_meta( $post_id, JPIBFI_METADATA, true );
46
- return empty( $post_meta )
47
- || false == array_key_exists( 'jpibfi_disable_for_post', $post_meta )
48
- || '1' != $post_meta['jpibfi_disable_for_post'];
49
- }
50
-
51
- /*
52
- * function copied from https://gist.github.com/wesbos/1189639
53
- */
54
- function jpibfi_is_blog_page() {
55
- global $post;
56
-
57
- $post_type = get_post_type( $post );
58
-
59
- return ( ( is_home() || is_archive() || is_single() ) && ( $post_type == 'post' ) );
60
- }
61
-
62
- /*
63
- * True if plugin should be added to the current post/page
64
- */
65
- function jpibfi_add_plugin() {
66
-
67
- global $post;
68
- $options = get_option( JPIBFI_SELECTION_OPTIONS );
69
-
70
- if ( is_front_page() )
71
- return isset( $options['show_on_home'] ) && $options['show_on_home'] == "1";
72
- else if ( is_single() )
73
- return isset( $options['show_on_single'] ) && $options['show_on_single'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
74
- else if ( is_page() )
75
- return isset( $options['show_on_page'] ) && $options['show_on_page'] == "1" ? jpibfi_add_plugin_to_post( $post->ID ) : false;
76
- else if ( is_category() || is_archive() || is_search() )
77
- return isset( $options['show_on_category'] ) && $options['show_on_category'] == "1";
78
- else if ( jpibfi_is_blog_page() )
79
- return isset( $options['show_on_blog'] ) && $options['show_on_blog'] == "1";
80
- return true;
81
- }
82
-
83
- //Adds all necessary scripts
84
- function jpibfi_add_plugin_scripts() {
85
- if ( ! ( jpibfi_add_plugin() ) )
86
- return;
87
-
88
- wp_register_style( 'jquery-pin-it-button-style', plugins_url( '/css/style.css', __FILE__ ), array(), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, 'all' );
89
- wp_enqueue_style( 'jquery-pin-it-button-style' );
90
- wp_enqueue_script( 'jquery-pin-it-button-script', plugins_url( '/js/script.min.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
91
-
92
- $visual_options = get_option( JPIBFI_VISUAL_OPTIONS );
93
- $selection_options = get_option( JPIBFI_SELECTION_OPTIONS );
94
- $advanced_options = get_option( JPIBFI_ADVANCED_OPTIONS );
95
- $use_custom_image = isset( $visual_options[ 'use_custom_image' ] ) && $visual_options[ 'use_custom_image' ] == "1";
96
-
97
- $parameters_array = array(
98
- 'image_selector' => $selection_options['image_selector'],
99
- 'disabled_classes' => $selection_options['disabled_classes'],
100
- 'enabled_classes' => $selection_options['enabled_classes'],
101
- 'description_option'=> $visual_options['description_option'],
102
- 'use_post_url' => isset ( $visual_options['use_post_url'] ) ? $visual_options['use_post_url'] : '0',
103
- 'min_image_height' => $selection_options['min_image_height'],
104
- 'min_image_width' => $selection_options['min_image_width'],
105
- 'site_title' => get_bloginfo( 'name', 'display' ),
106
- 'mode' => $visual_options[ 'mode' ],
107
- 'button_position' => $visual_options[ 'button_position' ],
108
- 'debug' => isset( $advanced_options[ 'debug'] ) ? $advanced_options[ 'debug'] : '0',
109
- 'pin_image_height' => $use_custom_image ? $visual_options['custom_image_height'] : JPIBFI_IMAGE_HEIGHT,
110
- 'pin_image_width' => $use_custom_image ? $visual_options['custom_image_width'] : JPIBFI_IMAGE_WIDTH,
111
- 'button_margin_top' => $visual_options[ 'button_margin_top' ],
112
- 'button_margin_bottom' => $visual_options[ 'button_margin_bottom' ],
113
- 'button_margin_left'=> $visual_options[ 'button_margin_left' ],
114
- 'button_margin_right' => $visual_options[ 'button_margin_right' ]
115
- );
116
-
117
- wp_localize_script( 'jquery-pin-it-button-script', 'jpibfi_options',
118
- apply_filters('jpibfi_javascript_parameters',$parameters_array, $selection_options, $visual_options, $advanced_options ) );
119
- }
120
-
121
- add_action( 'wp_enqueue_scripts', 'jpibfi_add_plugin_scripts' );
122
-
123
- function jpibfi_print_header_style_action() {
124
- if ( ! ( jpibfi_add_plugin() ) )
125
- return;
126
-
127
- $options = get_option( JPIBFI_VISUAL_OPTIONS );
128
-
129
- $use_custom_image = isset( $options[ 'use_custom_image' ] ) && $options[ 'use_custom_image' ] == "1";
130
-
131
- $width = $use_custom_image ? $options['custom_image_width'] : JPIBFI_IMAGE_WIDTH;
132
- $height = $use_custom_image ? $options['custom_image_height'] : JPIBFI_IMAGE_HEIGHT;
133
-
134
- if ( isset( $options[ 'retina_friendly' ] ) && $options[ 'retina_friendly' ] == '1' ){
135
- $width = floor( $width / 2 );
136
- $height = floor ( $height / 2 );
137
- }
138
-
139
- $url = $use_custom_image ? $options['custom_image_url'] : JPIBFI_IMAGE_URL;
140
-
141
- ?>
142
- <!--[if lt IE 9]>
143
- <style type="text/css">
144
- .pinit-overlay {
145
- background-image: url( '<?php echo plugins_url( '/images/transparency_0.png', __FILE__ ); ?>' ) !important;
146
- }
147
- </style>
148
- <![endif]-->
149
-
150
- <style type="text/css">
151
- a.pinit-button {
152
- width: <?php echo $width; ?>px !important;
153
- height: <?php echo $height; ?>px !important;
154
- background: transparent url('<?php echo $url; ?>') no-repeat 0 0 !important;
155
- background-size: <?php echo $width; ?>px <?php echo $height; ?>px !important
156
- }
157
-
158
- a.pinit-button.pinit-top-left {
159
- margin: <?php echo $options['button_margin_top']; ?>px 0 0 <?php echo $options['button_margin_left']; ?>px;
160
- }
161
-
162
- a.pinit-button.pinit-top-right {
163
- margin: <?php echo $options['button_margin_top']; ?>px <?php echo $options['button_margin_right']; ?>px 0 0;
164
- }
165
-
166
- a.pinit-button.pinit-bottom-left {
167
- margin: 0 0 <?php echo $options['button_margin_bottom']; ?>px <?php echo $options['button_margin_left']; ?>px;
168
- }
169
-
170
- a.pinit-button.pinit-bottom-right {
171
- margin: 0 <?php echo $options['button_margin_right']; ?>px <?php echo $options['button_margin_bottom']; ?>px 0;
172
- }
173
-
174
- img.pinit-hover {
175
- opacity: <?php echo (1 - $options['transparency_value']); ?> !important;
176
- filter:alpha(opacity=<?php echo (1 - $options['transparency_value']) * 100; ?>) !important; /* For IE8 and earlier */
177
- }
178
- </style>
179
- <?php
180
- }
181
-
182
- add_action( 'wp_head', 'jpibfi_print_header_style_action' );
183
-
184
- /*
185
- * Adds data-jpibfi-description attribute to each image that is added through media library. The value is the "Description" of the image from media library.
186
- * This piece of code uses a lot of code from the Photo Protect http://wordpress.org/plugins/photo-protect/ plugin
187
- */
188
- function jpibfi_add_description_attribute_to_images( $content ) {
189
-
190
- $imgPattern = '/<img[^>]*>/i';
191
- $attrPattern = '/ ([\w]+)[ ]*=[ ]*([\"\'])(.*?)\2/i';
192
-
193
- preg_match_all($imgPattern, $content, $images, PREG_SET_ORDER);
194
195
- foreach ($images as $img) {
196
197
- preg_match_all($attrPattern, $img[0], $attributes, PREG_SET_ORDER);
198
199
- $newImg = '<img';
200
- $src = '';
201
- $id = '';
202
203
- foreach ($attributes as $att) {
204
- $full = $att[0];
205
- $name = $att[1];
206
- $value = $att[3];
207
-
208
- $newImg .= $full;
209
210
- if ('class' == $name ) {
211
- $id = jpibfi_get_post_id_from_image_classes( $value );
212
- } else if ( 'src' == $name ) {
213
- $src = $value;
214
}
215
}
216
217
- $description = jpibfi_get_image_description( $id, $src );
218
- $newImg .= ' data-jpibfi-description="' . esc_attr( $description ) . '" />';
219
- $content = str_replace($img[0], $newImg, $content);
220
- }
221
-
222
- return $content;
223
- }
224
-
225
- /*
226
- * Adds a hidden field with url and and description of the pin that's used when user uses "Link to individual page"
227
- * Thanks go to brocheafoin, who added most of the code that handles creating description
228
- */
229
- function jpibfi_prepare_the_content( $content ) {
230
- if ( ! jpibfi_add_plugin() )
231
- return $content;
232
- global $post;
233
-
234
- $options = get_option( JPIBFI_VISUAL_OPTIONS );
235
-
236
- $add_attributes = false == is_singular() && isset( $options[ 'use_post_url' ] ) && '1' == $options[ 'use_post_url' ];
237
-
238
- $attributes_html = '';
239
-
240
- //if we need to add additional attributes to handle use_post_url setting
241
- if ( $add_attributes ){
242
- //if page description should be used as pin description and an excerpt for the post exists
243
- if ( has_excerpt( $post->ID ) && 2 == $options[ 'description_option' ] )
244
- $description = wp_kses( $post->post_excerpt, array() );
245
- else
246
- $description = get_the_title($post->ID);
247
-
248
- $attributes_html .= 'data-jpibfi-url="' . get_permalink( $post->ID ) . '" ' ;
249
- $attributes_html .= 'data-jpibfi-description ="' . esc_attr( $description ) . '" ';
250
- }
251
-
252
- $input_html = '<input class="jpibfi" type="hidden" ' . $attributes_html . '>';
253
- $content = $input_html . $content;
254
-
255
- $add_image_descriptions = '5' == $options[ 'description_option' ];
256
-
257
- //if we need to add data-jpibfi-description to each image
258
- if ( $add_image_descriptions ){
259
- $content = jpibfi_add_description_attribute_to_images( $content );
260
- }
261
-
262
- return $content;
263
- }
264
-
265
- add_filter( "the_content", 'jpibfi_prepare_the_content' );
266
- add_filter( "the_excerpt", 'jpibfi_prepare_the_content' );
267
-
268
- /*
269
- *
270
- * POST EDITOR CODE
271
- *
272
- */
273
-
274
- function jpibfi_add_meta_box() {
275
- //for posts
276
- add_meta_box(
277
- 'jpibfi_settings_id', // this is HTML id of the box on edit screen
278
- 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jpibfi' ), // title of the box
279
- 'jpibfi_print_meta_box', // function to be called to display the checkboxes, see the function below
280
- 'post', // on which edit screen the box should appear
281
- 'side', // part of page where the box should appear
282
- 'default' // priority of the box
283
- );
284
285
- //for pages
286
- add_meta_box(
287
- 'jpibfi_settings_id',
288
- 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jpibfi' ),
289
- 'jpibfi_print_meta_box',
290
- 'page',
291
- 'side',
292
- 'default'
293
- );
294
- }
295
-
296
- add_action( 'add_meta_boxes', 'jpibfi_add_meta_box' );
297
-
298
- // display the metabox
299
- function jpibfi_print_meta_box( $post, $metabox ) {
300
301
- wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' );
302
303
- $post_meta = get_post_meta( $post->ID, JPIBFI_METADATA, true );
304
- $checked = isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1';
305
306
- echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"' . checked( $checked, true, false ) . '>';
307
- echo '<label for="jpibfi_disable_for_post">' . __( 'Disable "Pin it" button for this post (works only on single pages/posts)', 'jpibfi' ) . '</label><br />';
308
- }
309
-
310
- function jpibfi_save_meta_data( $post_id ) {
311
312
- //check user's permissions
313
- if ( ! current_user_can( 'edit_post', $post_id ) )
314
- return;
315
- // check if this isn't an auto save
316
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
317
- return;
318
- // security check = updating possible only using post edit form
319
- if ( !isset( $_POST['jpibfi_nonce'] ) || ! wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
320
- return;
321
322
323
- $post_meta = array( 'jpibfi_disable_for_post' => '0' );
324
- // now store data in custom fields based on checkboxes selected
325
- $post_meta['jpibfi_disable_for_post'] =
326
- isset( $_POST['jpibfi_disable_for_post'] ) && $_POST['jpibfi_disable_for_post'] == '1' ? '1' : '0';
327
328
- if ( $post_meta['jpibfi_disable_for_post'] == '1' )
329
- update_post_meta( $post_id, JPIBFI_METADATA, $post_meta );
330
- else
331
- delete_post_meta( $post_id, JPIBFI_METADATA );
332
- }
333
334
- add_action( 'save_post', 'jpibfi_save_meta_data' );
335
336
- //END POST EDITOR CODE
337
338
- //Delete everything the plugin added into DB
339
- function jpibfi_uninstall_plugin() {
340
341
- //delete all added options
342
- delete_option( JPIBFI_SELECTION_OPTIONS );
343
- delete_option( JPIBFI_VISUAL_OPTIONS );
344
- delete_option( JPIBFI_ADVANCED_OPTIONS );
345
- delete_option( JPIBFI_VERSION_OPTION );
346
-
347
- //delete added metadata from all posts
348
- delete_post_meta_by_key( JPIBFI_METADATA );
349
- }
350
-
351
- register_uninstall_hook( __FILE__, 'jpibfi_uninstall_plugin' );
352
-
353
- /*
354
- *
355
- * ADMIN SETTINGS
356
- *
357
- */
358
-
359
- function jpibfi_load_plugin_textdomain() {
360
-
361
- load_plugin_textdomain( 'jpibfi', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
362
- }
363
-
364
- add_action( 'plugins_loaded', 'jpibfi_load_plugin_textdomain' );
365
-
366
- /*
367
- * Function updates DB if it detects new version of the plugin
368
- */
369
- function jpibfi_update_plugin() {
370
371
- $version = get_option( JPIBFI_VERSION_OPTION );
372
-
373
- //if the plugin isn't installed at all or the version is below 1.00
374
- if ( false == $version ) {
375
- //rewrite old settings (if they exist) to new settings
376
- jpibfi_convert_settings();
377
-
378
- //if new settings are still absent (plugin wasn't installed previously), we need to add them
379
- if( false == get_option( JPIBFI_VISUAL_OPTIONS ) )
380
- add_option( JPIBFI_VISUAL_OPTIONS, jpibfi_default_visual_options() );
381
-
382
- if( false == get_option( JPIBFI_SELECTION_OPTIONS ) )
383
- add_option( JPIBFI_SELECTION_OPTIONS, jpibfi_default_selection_options() );
384
-
385
- if( false == get_option( JPIBFI_ADVANCED_OPTIONS ) )
386
- add_option( JPIBFI_ADVANCED_OPTIONS, jpibfi_default_advanced_options() );
387
-
388
- } else if ( (float)$version < (float)JPIBFI_VERSION || get_option( JPIBFI_UPDATE_OPTIONS ) ) { //if the plugins version is older than current, we need to update options with new defaults
389
-
390
- $option = get_option( JPIBFI_VISUAL_OPTIONS );
391
- $option['button_position'] = '5' == $option['button_position'] ? '0' : $option['button_position'];
392
- jpibfi_update_option_fields( $option, jpibfi_default_visual_options(), JPIBFI_VISUAL_OPTIONS );
393
-
394
- $option = get_option( JPIBFI_SELECTION_OPTIONS );
395
- jpibfi_update_option_fields( $option, jpibfi_default_selection_options(), JPIBFI_SELECTION_OPTIONS );
396
-
397
- $option = get_option( JPIBFI_ADVANCED_OPTIONS );
398
- jpibfi_update_option_fields( $option, jpibfi_default_advanced_options(), JPIBFI_ADVANCED_OPTIONS );
399
- }
400
-
401
- //update the version of the plugin stored in option
402
- update_option( JPIBFI_VERSION_OPTION, JPIBFI_VERSION );
403
- }
404
-
405
- register_activation_hook( __FILE__, 'jpibfi_update_plugin' );
406
- add_action( 'plugins_loaded', 'jpibfi_update_plugin' );
407
-
408
- /*
409
- * This function converts old settings from versions earlier than 1.00 (if there are any) format to new settings format (changed names of options, etc)
410
- */
411
- function jpibfi_convert_settings() {
412
- //get all old options
413
- $basic_option = get_option( "jptbfi_options" );
414
- $advanced_options = get_option( 'jptbfi_advanced_options' );
415
-
416
- //if options don't exist, there's nothing to convert so the function ends
417
- if ( false == $basic_option || false == $advanced_options )
418
- return;
419
-
420
- //rewrite them to new options
421
- $default_selection_options = jpibfi_default_selection_options();
422
-
423
- $selection_options = array();
424
- $selection_options[ 'image_selector' ] = isset ( $basic_option[ 'image_selector' ] ) ? $basic_option[ 'image_selector' ] : $default_selection_options[ 'image_selector' ];
425
- $selection_options[ 'disabled_classes' ] = isset ( $basic_option[ 'disabled_classes' ] ) ? $basic_option[ 'disabled_classes' ] : $default_selection_options[ 'disabled_classes' ];
426
- $selection_options[ 'enabled_classes' ] = isset ( $basic_option[ 'enabled_classes' ] ) ? $basic_option[ 'enabled_classes' ] : $default_selection_options[ 'enabled_classes' ];
427
- $selection_options[ 'min_image_height' ] = isset ( $basic_option[ 'min_image_height' ] ) ? $basic_option[ 'min_image_height' ] : $default_selection_options[ 'min_image_height' ];
428
- $selection_options[ 'min_image_width' ] = isset ( $basic_option[ 'min_image_width' ] ) ? $basic_option[ 'min_image_width' ] : $default_selection_options[ 'min_image_width' ];
429
-
430
- $selection_options[ 'show_on_home' ] = isset ( $advanced_options[ 'on_home' ] ) && '1' == $advanced_options[ 'on_home' ] ? '1' : '0';
431
- $selection_options[ 'show_on_single' ] = isset ( $advanced_options[ 'on_single' ] ) && '1' == $advanced_options[ 'on_single' ] ? '1' : '0';
432
- $selection_options[ 'show_on_page' ] = isset ( $advanced_options[ 'on_page' ] ) && '1' == $advanced_options[ 'on_page' ] ? '1' : '0';
433
- $selection_options[ 'show_on_category' ] = isset ( $advanced_options[ 'on_category' ] )&& '1' == $advanced_options[ 'on_category' ] ? '1' : '0';
434
- $selection_options[ 'show_on_blog' ] = isset ( $advanced_options[ 'on_blog' ] ) && '1' == $advanced_options[ 'on_blog' ] ? '1' : '0';
435
-
436
- update_option( JPIBFI_SELECTION_OPTIONS, $selection_options );
437
- //just in case any new fields are added to the option in the future
438
- jpibfi_update_option_fields( $selection_options, jpibfi_default_selection_options(), JPIBFI_SELECTION_OPTIONS );
439
-
440
- //visual options
441
- $default_visual_options = jpibfi_default_visual_options();
442
-
443
- $visual_options = array();
444
- $visual_options[ 'description_option' ] = isset ( $basic_option[ 'description_option' ] ) ? $basic_option[ 'description_option' ] : $default_visual_options[ 'description_option' ];
445
- $visual_options[ 'transparency_value' ] = isset ( $basic_option[ 'transparency_value' ] ) ? $basic_option[ 'transparency_value' ] : $default_visual_options[ 'transparency_value' ];
446
- $visual_options[ 'use_custom_image' ] = isset ( $basic_option[ 'use_custom_image' ] ) && '1' == $basic_option[ 'use_custom_image' ] ? '1' : '0';
447
- $visual_options[ 'custom_image_url' ] = isset ( $basic_option[ 'custom_image_url' ] ) ? $basic_option[ 'custom_image_url' ] : $default_visual_options[ 'custom_image_url' ];
448
- $visual_options[ 'custom_image_height' ] = isset ( $basic_option[ 'custom_image_height' ] ) ? $basic_option[ 'custom_image_height' ] : $default_visual_options[ 'custom_image_height' ];
449
- $visual_options[ 'custom_image_width' ] = isset ( $basic_option[ 'custom_image_width' ] ) ? $basic_option[ 'custom_image_width' ] : $default_visual_options[ 'custom_image_width' ];
450
- $visual_options[ 'use_post_url' ] = isset ( $basic_option[ 'use_post_url' ] ) && '1' == $basic_option[ 'use_post_url' ] ? '1' : '0';
451
- $visual_options[ 'button_position' ] = isset ( $basic_option[ 'button_position' ] )
452
- ? ( '5' == $basic_option[ 'button_position' ] ? '0' : $basic_option[ 'button_position' ] )
453
- : $default_visual_options[ 'button_position' ];
454
-
455
- update_option( JPIBFI_VISUAL_OPTIONS, $visual_options );
456
- //just in case any new fields are added to the option in the future
457
- jpibfi_update_option_fields( $visual_options, jpibfi_default_visual_options(), JPIBFI_VISUAL_OPTIONS );
458
-
459
- //delete all old options
460
- delete_option( "jptbfi_options" );
461
- delete_option( 'jptbfi_advanced_options' );
462
- delete_option( 'jpibfi_button_custom_css' );
463
- }
464
-
465
- function jpibfi_print_admin_page_action() {
466
- $page = add_submenu_page(
467
- 'options-general.php',
468
- 'jQuery Pin It Button For Images', // The value used to populate the browser's title bar when the menu page is active
469
- 'jQuery Pin It Button For Images', // The text of the menu in the administrator's sidebar
470
- 'administrator', // What roles are able to access the menu
471
- 'jpibfi_settings', // The ID used to bind submenu items to this menu
472
- 'jpibfi_print_admin_page' // The callback function used to render this menu
473
- );
474
-
475
- add_action( 'admin_print_styles-' . $page, 'jpibfi_add_admin_site_scripts' );
476
- }
477
-
478
- add_action( 'admin_menu', 'jpibfi_print_admin_page_action' );
479
-
480
- /*
481
- * adds admin scripts
482
- */
483
- function jpibfi_add_admin_site_scripts() {
484
-
485
- wp_register_style( 'jquery-pin-it-button-admin-style', plugins_url( '/css/admin.css', __FILE__ ), array(), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, 'all' );
486
- wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
487
-
488
- wp_enqueue_script( 'jquery-pin-it-button-admin-script', plugins_url( '/js/admin.js', __FILE__ ), array( 'jquery' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
489
-
490
- wp_register_script( 'angular', plugins_url( '/js/angular.min.js', __FILE__ ) , '', '1.0.7', false );
491
- wp_enqueue_script( 'jquery-pin-it-button-admin-angular-script', plugins_url( '/js/admin-angular.js', __FILE__ ), array( 'angular' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
492
-
493
- if ( function_exists( "wp_enqueue_media") ) {
494
- wp_enqueue_media();
495
- wp_enqueue_script( 'jpibfi-upload-new', plugins_url( '/js/upload-button-new.js', __FILE__ ), array(), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
496
- } else {
497
- wp_enqueue_script( 'jpibfi-upload-old', plugins_url( '/js/upload-button-old.js', __FILE__ ), array('thickbox', 'media-upload' ), JPIBFI_VERSION . JPIBFI_VERSION_MINOR, false );
498
- }
499
- }
500
-
501
-
502
- function jpibfi_plugin_settings_filter( $links ) {
503
- $settings_link = '<a href="options-general.php?page=jpibfi_settings">' . __( 'Settings', 'jpibfi' ) . '</a>';
504
- array_unshift( $links, $settings_link );
505
- return $links;
506
- }
507
-
508
- $jpibfi_plugin = plugin_basename( __FILE__ );
509
- add_filter( "plugin_action_links_$jpibfi_plugin", 'jpibfi_plugin_settings_filter' );
510
-
511
- function jpibfi_print_admin_page() {
512
- ?>
513
- <!-- Create a header in the default WordPress 'wrap' container -->
514
- <div class="wrap">
515
-
516
- <h2><?php _e( 'jQuery Pin It Button For Images Options', 'jpibfi' ); ?></h2>
517
-
518
- <?php
519
- $tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'selection_options';
520
- if ( 'selection_options' != $tab && 'visual_options' != $tab && 'advanced_options' != $tab )
521
- $tab = 'selection_options';
522
- ?>
523
- <div id="icon-plugins" class="icon32"></div>
524
- <h2 class="nav-tab-wrapper">
525
- <a href="?page=jpibfi_settings&tab=selection_options" class="nav-tab <?php echo 'selection_options' == $tab ? 'nav-tab-active' : ''; ?>"><?php _e( 'Selection Settings', 'jpibfi' ); ?></a>
526
- <a href="?page=jpibfi_settings&tab=visual_options" class="nav-tab <?php echo 'visual_options' == $tab ? 'nav-tab-active' : ''; ?>"><?php _e( 'Visual Settings', 'jpibfi' ); ?></a>
527
- <a href="?page=jpibfi_settings&tab=advanced_options" class="nav-tab <?php echo 'advanced_options' == $tab ? 'nav-tab-active' : ''; ?>"><?php _e( 'Advanced Settings', 'jpibfi' ); ?></a>
528
- </h2>
529
-
530
- <p>
531
- <?php
532
- printf( '<a href="http://mrsztuczkens.me/jquery-pin-it-button-for-images-customization/" class="button" target="_blank" rel="nofollow"><b>' . __( 'Plugin Customization', 'jpibfi' ) . '</b></a>' );
533
- printf( '<a href="http://bit.ly/Uw2mEP" class="button" target="_blank" rel="nofollow"><b>' . __( 'Donate', 'jpibfi' ) . '</b></a>' );
534
- printf( '<a href="http://wordpress.org/support/plugin/jquery-pin-it-button-for-images" class="button" target="_blank" rel="nofollow"><b>' . __( 'Support forum', 'jpibfi' ) . '</b></a>' );
535
- printf( '<a href="http://wordpress.org/support/view/plugin-reviews/jquery-pin-it-button-for-images" class="button" target="_blank" rel="nofollow"><b>'. __( 'Leave a review', 'jpibfi' ) . '</b></a>' );
536
- ?>
537
- </p>
538
- <form method="post" action="options.php" ng-app="jpibfiApp" ng-controller="jpibfiController">
539
- <?php
540
541
- if ( 'selection_options' == $tab ) {
542
- settings_fields( 'jpibfi_selection_options' );
543
- do_settings_sections( 'jpibfi_selection_options' );
544
- } else if ( 'visual_options' == $tab) {
545
- settings_fields( 'jpibfi_visual_options' );
546
- do_settings_sections( 'jpibfi_visual_options' );
547
- } else if ( 'advanced_options' == $tab) {
548
- settings_fields( 'jpibfi_advanced_options' );
549
- do_settings_sections( 'jpibfi_advanced_options' );
550
}
551
-
552
- submit_button();
553
- ?>
554
- </form>
555
- <p>
556
- The Silk Icon Set is provided by Mark James and is availble from <a href="http://famfamfam.com/lab/icons/silk/">FamFamFam</a> under the <a href="http://creativecommons.org/licenses/by/2.5/">Creative Commons Attribution 2.5 License</a>.
557
- </p>
558
- </div>
559
- <?php
560
-
561
- //cumbersome, but needed for error management to work properly in WP 3.3
562
- delete_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
563
- delete_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
564
- }
565
-
566
- /*
567
- *
568
- * SELECTION OPTIONS
569
- *
570
- */
571
-
572
- /*
573
- * Default values for selection options section
574
- */
575
- function jpibfi_default_selection_options() {
576
- $defaults = array(
577
- 'image_selector' => 'div.jpibfi_container img',
578
- 'disabled_classes' => 'nopin;wp-smiley',
579
- 'enabled_classes' => '',
580
- 'min_image_height' => '0',
581
- 'min_image_width' => '0',
582
- 'show_on_home' => '1',
583
- 'show_on_single' => '1',
584
- 'show_on_page' => '1',
585
- 'show_on_category' => '1',
586
- 'show_on_blog' => '1'
587
- );
588
-
589
- return apply_filters('jpibfi_default_selection_options', $defaults);
590
- }
591
-
592
- /*
593
- * Defines selection options section and adds all required fields
594
- */
595
- function jpibfi_initialize_selection_options() {
596
-
597
- // First, we register a section.
598
- add_settings_section(
599
- 'selection_options_section', // ID used to identify this section and with which to register options
600
- __( 'Selection', 'jpibfi' ), // Title to be displayed on the administration page
601
- 'jpibfi_selection_options_callback', // Callback used to render the description of the section
602
- 'jpibfi_selection_options' // Page on which to add this section of options
603
- );
604
-
605
- //lThen add all necessary fields to the section
606
- add_settings_field(
607
- 'image_selector', // ID used to identify the field throughout the plugin
608
- __( 'Image selector', 'jpibfi' ), // The label to the left of the option interface element
609
- 'jpibfi_image_selector_callback', // The name of the function responsible for rendering the option interface
610
- 'jpibfi_selection_options', // The page on which this option will be displayed
611
- 'selection_options_section', // The name of the section to which this field belongs
612
- array( // The array of arguments to pass to the callback. In this case, just a description.
613
- sprintf ( __( 'jQuery selector for all the images that should have the "Pin it" button. Set the value to %s if you want the "Pin it" button to appear only on images in content or %s 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. %sClick here%s to read about jQuery selectors.', 'jpibfi' ),
614
- '<a href="#" class="jpibfi_selector_option">div.jpibfi_container img</a>',
615
- '<a href="#" class="jpibfi_selector_option">img</a>',
616
- '<a href="http://api.jquery.com/category/selectors/" target="_blank">',
617
- '</a>'
618
- )
619
- )
620
- );
621
-
622
- add_settings_field(
623
- 'disabled_classes',
624
- __( 'Disabled classes', 'jpibfi' ),
625
- 'jpibfi_disabled_classes_callback',
626
- 'jpibfi_selection_options',
627
- 'selection_options_section',
628
- array(
629
- __( 'Pictures with these CSS classes won\'t show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.', 'jpibfi' ),
630
- )
631
- );
632
-
633
- add_settings_field(
634
- 'enabled_classes',
635
- __( 'Enabled classes', 'jpibfi' ),
636
- 'jpibfi_enabled_classes_callback',
637
- 'jpibfi_selection_options',
638
- 'selection_options_section',
639
- array(
640
- __( 'Only 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.', 'jpibfi' ),
641
- )
642
- );
643
-
644
- add_settings_field(
645
- 'show_on_field',
646
- __( 'On which pages the "Pin it" button should be shown', 'jpibfi' ),
647
- 'jpibfi_show_on_field_callback',
648
- 'jpibfi_selection_options',
649
- 'selection_options_section',
650
- array(
651
- __( 'Check on which pages you want the Pinterest button to show up.', 'jpibfi' ),
652
- )
653
- );
654
-
655
- add_settings_field(
656
- 'min_image',
657
- __( 'Minimum resolution that should trigger the "Pin it" button to show up', 'jpibfi' ),
658
- 'jpibfi_min_image_callback',
659
- 'jpibfi_selection_options',
660
- 'selection_options_section',
661
- array(
662
- __( 'If you\'d like the "Pin it" button to not show up on small images (e.g. social media icons), just set the appropriate values above. The default values cause the "Pin it" button to show on every eligible image.', 'jpibfi' ),
663
- )
664
- );
665
-
666
- register_setting(
667
- 'jpibfi_selection_options',
668
- 'jpibfi_selection_options',
669
- 'jpibfi_sanitize_selection_options'
670
- );
671
- }
672
-
673
- add_action( 'admin_init', 'jpibfi_initialize_selection_options' );
674
-
675
- function jpibfi_selection_options_callback() {
676
- echo '<p>' . __('Which images can be pinned', 'jpibfi') . '</p>';
677
- }
678
-
679
- function jpibfi_image_selector_callback( $args ) {
680
-
681
- $options = jpibfi_get_selection_options();
682
-
683
- $selector = esc_attr( $options['image_selector'] );
684
-
685
- echo '<input type="text" id="image_selector" name="jpibfi_selection_options[image_selector]" value="' . $selector . '"/>';
686
- echo jpibfi_create_description( $args[0] );
687
- }
688
-
689
- function jpibfi_disabled_classes_callback( $args ){
690
-
691
- $options = jpibfi_get_selection_options();
692
- $value = esc_attr( $options[ 'disabled_classes' ] );
693
-
694
- ?>
695
- <input type="hidden" name="jpibfi_selection_options[disabled_classes]" value="{{ disabledClassesFormatted }}" ng-init="initDisabledClasses('<?php echo $value; ?>')">
696
- <span ng-hide="disabledClasses.length > 0">
697
- <?php echo jpibfi_create_description( __( 'No classes added.', 'jpibfi' ) ); ?>
698
- </span>
699
- <ul class="jpibfi-classes-list" ng-hide="disabledClasses.length == 0">
700
- <li ng-repeat="class in disabledClasses">
701
- <a ng-click="deleteDisabledClass(class)">X</a><span>{{ class }}</span>
702
- </li>
703
- </ul>
704
- <div>
705
- <div>
706
- <label for="disabledClass" ><?php _e( 'Class name', 'jpibfi' ); ?></label>
707
- <input id="disabledClass" type="text" ng-model="disabledClass">
708
- <button type="button" ng-click="addDisabledClass(disabledClass)"><?php _e( 'Add to list', 'jpibfi' ); ?></button>
709
- </div>
710
- </div>
711
-
712
- <?php
713
-
714
- echo jpibfi_create_description( $args[0] );
715
- echo jpibfi_create_errors( 'disabled_classes' );
716
- }
717
-
718
- function jpibfi_enabled_classes_callback( $args ){
719
-
720
- $options = jpibfi_get_selection_options();
721
- $value = esc_attr( $options[ 'enabled_classes' ] );
722
-
723
- ?>
724
- <input type="hidden" name="jpibfi_selection_options[enabled_classes]" value="{{ enabledClassesFormatted }}" ng-init="initEnabledClasses('<?php echo $value; ?>')">
725
- <span ng-hide="enabledClasses.length > 0">
726
- <?php echo jpibfi_create_description( __( 'No classes added.', 'jpibfi' ) ); ?>
727
- </span>
728
- <ul class="jpibfi-classes-list" ng-hide="enabledClasses.length == 0">
729
- <li ng-repeat="class in enabledClasses">
730
- <a ng-click="deleteEnabledClass(class)">X</a><span>{{ class }}</span>
731
- </li>
732
- </ul>
733
- <div>
734
- <div>
735
- <label for="enabledClass" ><?php _e( 'Class name', 'jpibfi' ); ?></label>
736
- <input id="enabledClass" type="text" ng-model="enabledClass">
737
- <button type="button" ng-click="addEnabledClass(enabledClass)"><?php _e( 'Add to list', 'jpibfi' ); ?></button>
738
- </div>
739
- </div>
740
-
741
- <?php
742
-
743
- echo jpibfi_create_description( $args[0] );
744
- echo jpibfi_create_errors( 'enabled_classes' );
745
- }
746
-
747
- function jpibfi_show_on_field_callback( $args ) {
748
- $options = jpibfi_get_selection_options();
749
-
750
- $show_on_home = jpibfi_exists_and_equal_to( $options, 'show_on_home', '1' );
751
- $show_on_page = jpibfi_exists_and_equal_to( $options, 'show_on_page', '1' );
752
- $show_on_single = jpibfi_exists_and_equal_to( $options, 'show_on_single', '1' );
753
- $show_on_category = jpibfi_exists_and_equal_to( $options, 'show_on_category', '1' );
754
- $show_on_blog = jpibfi_exists_and_equal_to( $options, 'show_on_blog', '1' );
755
- ?>
756
-
757
- <input type="checkbox" id="show_on_home" name="jpibfi_selection_options[show_on_home]" <?php checked( true, $show_on_home ); ?> value="1" />
758
- <label for="show_on_home"><?php _e( 'Home page', 'jpibfi' ); ?></label><br/>
759
- <input type="checkbox" id="show_on_page" name="jpibfi_selection_options[show_on_page]" <?php checked( true, $show_on_page ); ?> value="1" />
760
- <label for="show_on_page"><?php _e( 'Pages', 'jpibfi' ); ?></label><br />
761
- <input type="checkbox" id="show_on_single" name="jpibfi_selection_options[show_on_single]" <?php checked( true, $show_on_single ); ?> value="1" />
762
- <label for="show_on_single"><?php _e( 'Single posts', 'jpibfi' ); ?></label><br />
763
- <input type="checkbox" id="show_on_category" name="jpibfi_selection_options[show_on_category]" <?php checked( true, $show_on_category ); ?> value="1" />
764
- <label for="show_on_category"><?php _e( 'Category and archive pages', 'jpibfi' ); ?></label><br />
765
- <input type="checkbox" id="show_on_blog" name="jpibfi_selection_options[show_on_blog]" <?php checked( true, $show_on_blog ); ?> value="1" />
766
- <label for="show_on_blog"><?php _e( 'Blog pages', 'jpibfi' ); ?></label>
767
-
768
- <?php
769
- echo jpibfi_create_description( $args[0] );
770
- }
771
-
772
- function jpibfi_min_image_callback( $args ) {
773
- $options = jpibfi_get_selection_options();
774
-
775
- $min_image_height = $options[ 'min_image_height' ];
776
- $min_image_width = $options[ 'min_image_width' ];
777
- ?>
778
-
779
- <p>
780
- <label for="min_image_height"><?php _e('Height', 'jpibfi'); ?></label>
781
- <input type="number" min="0" step="1" id="min_image_height" name="jpibfi_selection_options[min_image_height]" value="<?php echo $min_image_height; ?>"
782
- class="small-text" /> px
783
- <?php echo jpibfi_create_errors( 'min_image_height' ); ?>
784
- </p>
785
-
786
- <p>
787
- <label for="min_image_width"><?php _e('Width', 'jpibfi'); ?></label>
788
- <input type="number" min="0" step="1" id="min_image_width" name="jpibfi_selection_options[min_image_width]" value="<?php echo $min_image_width; ?>"
789
- class="small-text" /> px
790
- <?php echo jpibfi_create_errors( 'min_image_width' ); ?>
791
- </p>
792
-
793
- <?php
794
-
795
- echo jpibfi_create_description( $args[0] );
796
- }
797
-
798
- function jpibfi_sanitize_selection_options( $input ) {
799
-
800
- foreach( $input as $key => $value ) {
801