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-]*$/", $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
- switch($key) {
802
- case 'disabled_classes':
803
- case 'enabled_classes':
804
- if ( false == jpibfi_contains_css_class_names_or_empty( $input [ $key ] ) ) {
805
-
806
- $field = '';
807
- if ( 'disabled_classes' == $key )
808
- $field = __( 'Disabled classes', 'jpibfi' );
809
- else if ( 'enabled_classes' == $key )
810
- $field = __( 'Enabled classes', 'jpibfi' );
811
-
812
- add_settings_error(
813
- $key,
814
- esc_attr( 'settings_updated' ),
815
- $field . ' - ' . __('the given value doesn\'t meet the requirements. Please correct it and try again.', 'jpibfi')
816
- );
817
- }
818
- break;
819
- case 'min_image_height':
820
- case 'min_image_width':
821
- if ( !is_numeric( $value ) || $value < 0 ) {
822
-
823
- $field = '';
824
- if ( 'min_image_height' == $key )
825
- $field = __( 'Minimum image height', 'jpibfi' );
826
- else if ( 'min_image_width' == $key )
827
- $field = __( 'Minimum image width', 'jpibfi' );
828
-
829
- add_settings_error(
830
- $key,
831
- esc_attr( 'settings_updated' ),
832
- $field . ' - ' . sprintf ( __('value must be a number greater or equal to %d.', 'jpibfi'), '0' )
833
- );
834
- }
835
- break;
836
  }
837
 
838
- }
839
-
840
- $errors = get_settings_errors();
841
-
842
- if ( count( $errors ) > 0 ) {
843
-
844
- update_option( JPIBFI_SELECTION_OPTIONS . '_errors', $input );
845
- return get_option( JPIBFI_SELECTION_OPTIONS );
846
-
847
- } else {
848
-
849
- delete_option( JPIBFI_SELECTION_OPTIONS . '_errors' );
850
- return $input;
851
-
852
- }
853
- }
854
-
855
- function jpibfi_get_selection_options() {
856
- return jpibfi_get_options( JPIBFI_SELECTION_OPTIONS );
857
- }
858
-
859
- /*
860
- *
861
- * VISUAL OPTIONS
862
- *
863
- */
864
-
865
- /*
866
- * Default values for visual options section
867
- */
868
- function jpibfi_default_visual_options() {
869
-
870
- $defaults = array(
871
- 'transparency_value' => '0.5',
872
- 'description_option' => '1',
873
- 'use_custom_image' => '0',
874
- 'custom_image_url' => '',
875
- 'custom_image_height' => '0',
876
- 'custom_image_width' => '0',
877
- 'use_post_url' => '0',
878
- 'button_position' => '0',
879
- 'mode' => 'static',
880
- 'button_margin_top' => '20',
881
- 'button_margin_right' => '20',
882
- 'button_margin_bottom'=> '20',
883
- 'button_margin_left' => '20',
884
- 'retina_friendly' => '0'
885
- );
886
-
887
- return apply_filters( 'jpibfi_default_visual_options', $defaults );
888
- }
889
-
890
- /*
891
- * Defines visual options section and defines all required fields
892
- */
893
- function jpibfi_initialize_visual_options() {
894
-
895
- // First, we register a section.
896
- add_settings_section(
897
- 'visual_options_section', // ID used to identify this section and with which to register options
898
- __( 'Visual', 'jpibfi' ), // Title to be displayed on the administration page
899
- 'jpibfi_visual_options_callback', // Callback used to render the description of the section
900
- 'jpibfi_visual_options' // Page on which to add this section of options
901
- );
902
-
903
- //Then add all necessary fields to the section
904
- add_settings_field(
905
- 'mode',
906
- __( 'Mode', 'jpibfi' ),
907
- 'jpibfi_mode_option_callback',
908
- 'jpibfi_visual_options',
909
- 'visual_options_section',
910
- array(
911
- __( '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' ),
912
- )
913
- );
914
-
915
- add_settings_field(
916
- 'description_option',
917
- __( 'Description source', 'jpibfi' ),
918
- 'jpibfi_description_option_callback',
919
- 'jpibfi_visual_options',
920
- 'visual_options_section',
921
- array(
922
- __( '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' ),
923
- )
924
- );
925
-
926
- add_settings_field(
927
- 'use_post_url',
928
- __( 'Linked page', 'jpibfi' ),
929
- 'jpibfi_use_post_url_callback',
930
- 'jpibfi_visual_options',
931
- 'visual_options_section',
932
- array(
933
- __( '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' ),
934
- )
935
- );
936
-
937
- add_settings_field(
938
- 'transparency_value',
939
- __( 'Transparency value', 'jpibfi' ),
940
- 'jpibfi_transparency_value_callback',
941
- 'jpibfi_visual_options',
942
- 'visual_options_section',
943
- array(
944
- __( 'This setting sets the transparency of the image.', 'jpibfi' ),
945
- )
946
- );
947
-
948
- add_settings_field(
949
- 'custom_pin_it_button',
950
- __( 'Custom "Pin It" button', 'jpibfi' ),
951
- 'jpibfi_custom_pin_it_button_callback',
952
- 'jpibfi_visual_options',
953
- 'visual_options_section',
954
- array(
955
- __( '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' ),
956
- )
957
- );
958
-
959
- add_settings_field(
960
- 'pin_it_button_position',
961
- __( '"Pin it" button position', 'jpibfi' ),
962
- 'jpibfi_pin_it_button_position_callback',
963
- 'jpibfi_visual_options',
964
- 'visual_options_section',
965
- array(
966
- __( 'Where the "Pin it" button should appear on the image.', 'jpibfi' ),
967
- )
968
- );
969
-
970
- add_settings_field(
971
- 'pin_it_button_margins',
972
- __( '"Pin it" button margins', 'jpibfi' ),
973
- 'jpibfi_pin_it_button_margins_callback',
974
- 'jpibfi_visual_options',
975
- 'visual_options_section',
976
- array(
977
- 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' ),
978
- __( 'Top left', 'jpibfi' ),
979
- __( 'Bottom right', 'jpibfi' ),
980
- __( 'Middle', 'jpibfi' )
981
- ),
982
- )
983
- );
984
-
985
- add_settings_field(
986
- 'retina_friendly',
987
- __( 'Retina friendly', 'jpibfi' ),
988
- 'jpibfi_retina_friendly_callback',
989
- 'jpibfi_visual_options',
990
- 'visual_options_section',
991
- array(
992
- __( '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' ),
993
- )
994
- );
995
-
996
- register_setting(
997
- 'jpibfi_visual_options',
998
- 'jpibfi_visual_options',
999
- 'jpibfi_sanitize_visual_options'
1000
- );
1001
-
1002
- }
1003
-
1004
- add_action( 'admin_init', 'jpibfi_initialize_visual_options' );
1005
-
1006
- function jpibfi_visual_options_callback() {
1007
- echo '<p>' . __('How it should look like', 'jpibfi') . '</p>';
1008
- }
1009
-
1010
- function jpibfi_mode_option_callback( $args ) {
1011
- $options = jpibfi_get_visual_options();
1012
- $mode = $options[ 'mode' ];
1013
-
1014
- ?>
1015
-
1016
- <select id="mode" name="jpibfi_visual_options[mode]">
1017
- <option value="static" <?php selected ( "static", $mode ); ?>><?php _e( 'Static', 'jpibfi' ); ?></option>
1018
- <option value="dynamic" <?php selected ( "dynamic", $mode ); ?>><?php _e( 'Dynamic', 'jpibfi' ); ?></option>
1019
- </select>
1020
-
1021
- <?php
1022
- echo jpibfi_create_description( $args[0] );
1023
- }
1024
-
1025
- function jpibfi_description_option_callback( $args ) {
1026
- $options = jpibfi_get_visual_options();
1027
-
1028
-
1029
- $description_option = $options[ 'description_option' ];
1030
- ?>
1031
-
1032
- <select id="description_option" name="jpibfi_visual_options[description_option]">
1033
- <option value="1" <?php selected ( "1", $description_option ); ?>><?php _e( 'Page title', 'jpibfi' ); ?></option>
1034
- <option value="2" <?php selected ( "2", $description_option ); ?>><?php _e( 'Page description', 'jpibfi' ); ?></option>
1035
- <option value="3" <?php selected ( "3", $description_option ); ?>><?php _e( 'Picture title or (if title not available) alt attribute', 'jpibfi' ); ?></option>
1036
- <option value="4" <?php selected ( "4", $description_option ); ?>><?php _e( 'Site title (Settings->General)', 'jpibfi' ); ?></option>
1037
- <option value="5" <?php selected ( "5", $description_option ); ?>><?php _e( 'Image description', 'jpibfi' ); ?></option>
1038
- </select>
1039
-
1040
- <?php
1041
- echo jpibfi_create_description( $args[0] );
1042
- }
1043
-
1044
- function jpibfi_use_post_url_callback( $args ) {
1045
-
1046
- $options = jpibfi_get_visual_options();
1047
- $use_post_url = jpibfi_exists_and_equal_to( $options, 'use_post_url', '1' );
1048
-
1049
- echo '<input type="checkbox" id="use_post_url" name="jpibfi_visual_options[use_post_url]" value="1" ' . checked( true, $use_post_url, false ) . '>';
1050
- echo '<label for="use_post_url">' . __( 'Always link to individual post page', 'jpibfi' ) . '</label>';
1051
-
1052
- echo jpibfi_create_description( $args[0] );
1053
- }
1054
-
1055
- function jpibfi_transparency_value_callback( $args ) {
1056
- $options = jpibfi_get_visual_options();
1057
-
1058
- $transparency_value = $options[ 'transparency_value' ];
1059
-
1060
- echo '<label for="transparency_value">' . sprintf ( __('Choose transparency (between %.02f and %.02f)', 'jpibfi'), '0.00', '1.00' ) . '</label><br/>';
1061
- echo '<input type="number" min="0" max="1" step="0.01" id="transparency_value" name="jpibfi_visual_options[transparency_value]"' .
1062
- 'value="' . $transparency_value . '" class="small-text" >';
1063
- echo jpibfi_create_description( $args[0] );
1064
- echo jpibfi_create_errors( 'transparency_value' );
1065
- }
1066
-
1067
- function jpibfi_custom_pin_it_button_callback( $args ) {
1068
- $options = jpibfi_get_visual_options();
1069
-
1070
- $use_custom_image = jpibfi_exists_and_equal_to( $options, 'use_custom_image', '1' );
1071
- $custom_image_url = $options[ 'custom_image_url' ];
1072
- $custom_image_height = $options[ 'custom_image_height' ];
1073
- $custom_image_width = $options[ 'custom_image_width' ];
1074
-
1075
- ?>
1076
- <p>
1077
- <input type="checkbox" id="use_custom_image" name="jpibfi_visual_options[use_custom_image]" value="1" <?php checked( true, $use_custom_image ); ?> >
1078
- <label class="chbox-label" for="use_custom_image"><?php _e( 'Use custom image', 'jpibfi' ); ?></label>
1079
- </p>
1080
-
1081
- <button id=upload-image><?php _e( 'Upload an image using media library','jpibfi' ); ?></button><br />
1082
-
1083
- <p>
1084
- <label for="custom_image_url"><?php _e( 'URL address of the image', 'jpibfi' ); ?></label>
1085
- <input type="url" id="custom_image_url" name="jpibfi_visual_options[custom_image_url]" value="<?php echo $custom_image_url; ?>">
1086
- </p>
1087
-
1088
- <p>
1089
- <label for="custom_image_height"><?php _e( 'Height', 'jpibfi' ); ?></label>
1090
- <input type="number" min="0" step="1" id="custom_image_height" name="jpibfi_visual_options[custom_image_height]" value="<?php echo $custom_image_height; ?>"
1091
- class="small-text" /> px
1092
- <?php echo jpibfi_create_errors( 'custom_image_height' ); ?>
1093
- </p>
1094
-
1095
- <p>
1096
- <label for="custom_image_width"><?php _e( 'Width', 'jpibfi' ); ?></label>
1097
- <input type="number" min="0" step="1" id="custom_image_width" name="jpibfi_visual_options[custom_image_width]" value="<?php echo $custom_image_width; ?>"
1098
- class="small-text" /> px
1099
- <?php echo jpibfi_create_errors( 'custom_image_width' ); ?>
1100
- </p>
1101
-
1102
- <p>
1103
- <b><?php _e( 'Custom Pin It button preview', 'jpibfi' ); ?></b><br/>
1104
- <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; ?>');">
1105
- Preview
1106
- </span><br/>
1107
- <button id="refresh_custom_button_preview"><?php _e( 'Refresh preview', 'jpibfi' ); ?></button>
1108
- </p>
1109
-
1110
- <?php
1111
-
1112
- echo jpibfi_create_description( $args[0] );
1113
- }
1114
-
1115
- function jpibfi_pin_it_button_position_callback( $args ) {
1116
- $options = jpibfi_get_visual_options();
1117
-
1118
- $jpibfi_button_dropdown = array(
1119
- __( 'Top left', 'jpibfi' ),
1120
- __( 'Top right', 'jpibfi' ),
1121
- __( 'Bottom left', 'jpibfi' ),
1122
- __( 'Bottom right', 'jpibfi' ),
1123
- __( 'Middle', 'jpibfi' )
1124
- );
1125
-
1126
- $button_position = $options[ 'button_position' ];
1127
-
1128
- ?>
1129
-
1130
- <select name="jpibfi_visual_options[button_position]" id="button_position">
1131
- <?php for( $i = 0; $i < count( $jpibfi_button_dropdown ); $i++) { ?>
1132
- <option value="<?php echo $i; ?>" <?php selected( $i, $button_position ); ?>><?php echo $jpibfi_button_dropdown[ $i ]; ?></option>
1133
- <?php } ?>
1134
- </select><br/>
1135
-
1136
- <?php
1137
- echo jpibfi_create_description( $args[0] );
1138
- }
1139
-
1140
- function jpibfi_pin_it_button_margins_callback( $args ) {
1141
- $options = jpibfi_get_visual_options();
1142
- ?>
1143
- <label for="button_margin_top"><?php _e('Top', 'jpibfi'); ?></label>
1144
- <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/>
1145
- <label for="button_margin_bottom"><?php _e('Bottom', 'jpibfi'); ?></label>
1146
- <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/>
1147
- <label for="button_margin_left"><?php _e('Left', 'jpibfi'); ?></label>
1148
- <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/>
1149
- <label for="button_margin_right"><?php _e('Right', 'jpibfi'); ?></label>
1150
- <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/>
1151
-
1152
- <?php
1153
- echo jpibfi_create_description( $args[0] );
1154
- }
1155
-
1156
- function jpibfi_retina_friendly_callback( $args ) {
1157
-
1158
- $options = jpibfi_get_visual_options();
1159
- $retina_friendly = jpibfi_exists_and_equal_to( $options, 'retina_friendly', '1' );
1160
-
1161
- echo '<input type="checkbox" id="retina_friendly" name="jpibfi_visual_options[retina_friendly]" value="1" ' . checked( true, $retina_friendly, false ) . '>';
1162
- echo '<label for="retina_friendly">' . __( 'Optimize for high pixel density displays', 'jpibfi' ) . '</label>';
1163
-
1164
- echo jpibfi_create_description( $args[0] );
1165
- }
1166
-
1167
- function jpibfi_sanitize_visual_options( $input ) {
1168
-
1169
- foreach( $input as $key => $value ) {
1170
-
1171
- switch($key) {
1172
- case 'transparency_value':
1173
- if ( !is_numeric( $input[ $key ] ) || ( $input[ $key ] < 0.0 ) || ( $input[ $key ] > 1.0 ) ) {
1174
-
1175
- add_settings_error(
1176
- $key,
1177
- esc_attr( 'settings_updated' ),
1178
- sprintf( __('Transparency value must be a number between %.02d and %.02f.', 'jpibfi'), '0.00', '1.00' )
1179
- );
1180
- }
1181
- break;
1182
- case 'custom_image_height':
1183
- case 'custom_image_width':
1184
- $name = "";
1185
- if ( 'custom_image_height' == $key )
1186
- $name = __('Custom image height', 'jpibfi' );
1187
- else if ( 'custom_image_width' == $key )
1188
- $name = __('Custom image width', 'jpibfi' );
1189
-
1190
- if ( '' != $value && ( !is_numeric( $value ) || $value < 0 ) ) {
1191
- add_settings_error(
1192
- $key,
1193
- esc_attr( 'settings_updated' ),
1194
- $name . ' - ' . sprintf ( __('value must be a number greater or equal to %d.', 'jpibfi'), '0' )
1195
- );
1196
- }
1197
- break;
1198
  }
1199
- }
1200
-
1201
- $errors = get_settings_errors();
1202
-
1203
- if ( count( $errors ) > 0 ) {
1204
-
1205
- update_option( JPIBFI_VISUAL_OPTIONS . '_errors', $input );
1206
- return get_option( JPIBFI_VISUAL_OPTIONS );
1207
-
1208
- } else {
1209
-
1210
- delete_option( JPIBFI_VISUAL_OPTIONS . '_errors' );
1211
- return $input;
1212
-
1213
- }
1214
- }
1215
-
1216
- function jpibfi_get_visual_options() {
1217
- return jpibfi_get_options( JPIBFI_VISUAL_OPTIONS );
1218
- }
1219
-
1220
- /*
1221
- *
1222
- * ADVANCED OPTIONS
1223
- *
1224
- */
1225
- function jpibfi_default_advanced_options() {
1226
- $defaults = array(
1227
- 'debug' => '0'
1228
- );
1229
-
1230
- return apply_filters( 'jpibfi_default_advanced_options', $defaults );
1231
- }
1232
-
1233
- /*
1234
- * Defines selection options section and adds all required fields
1235
- */
1236
- function jpibfi_initialize_advanced_options() {
1237
-
1238
- // First, we register a section.
1239
- add_settings_section(
1240
- 'advanced_options_section',
1241
- __( 'Advanced Settings', 'jpibfi' ),
1242
- 'jpibfi_advanced_options_callback',
1243
- 'jpibfi_advanced_options'
1244
- );
1245
-
1246
- //lThen add all necessary fields to the section
1247
- add_settings_field(
1248
- 'debug',
1249
- __( 'Debug', 'jpibfi' ),
1250
- 'jpibfi_debug_callback',
1251
- 'jpibfi_advanced_options',
1252
- 'advanced_options_section',
1253
- array(
1254
- __( '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' ),
1255
- )
1256
- );
1257
-
1258
- register_setting(
1259
- 'jpibfi_advanced_options',
1260
- 'jpibfi_advanced_options' //no sanitization needed for now
1261
- );
1262
- }
1263
-
1264
- add_action( 'admin_init', 'jpibfi_initialize_advanced_options' );
1265
-
1266
- function jpibfi_advanced_options_callback() {
1267
- echo '<p>' . __('Advanced settings', 'jpibfi') . '</p>';
1268
- }
1269
-
1270
- function jpibfi_get_advanced_options() {
1271
- return jpibfi_get_options( JPIBFI_ADVANCED_OPTIONS );
1272
- }
1273
-
1274
- function jpibfi_debug_callback( $args ){
1275
- $options = jpibfi_get_advanced_options();
1276
- $debug = jpibfi_exists_and_equal_to( $options, 'debug', '1' );
1277
-
1278
- echo '<input type="checkbox" id="debug" name="jpibfi_advanced_options[debug]" value="1" ' . checked( "1", $debug, false ) . '>';
1279
- echo '<label for="debug">' . __( 'Enable debug mode', 'jpibfi' ) . '</label>';
1280
-
1281
- echo jpibfi_create_description( $args[0] );
1282
- }
1283
-
1284
-
1285
- /*
1286
- *
1287
- * UTILITIES
1288
- *
1289
- */
1290
-
1291
- //function gets the id of the image by searching for class with wp-image- prefix, otherwise returns empty string
1292
- function jpibfi_get_post_id_from_image_classes( $class_attribute ) {
1293
- $classes = preg_split( '/\s+/', $class_attribute, -1, PREG_SPLIT_NO_EMPTY );
1294
- $prefix = 'wp-image-';
1295
-
1296
- for ($i = 0; $i < count( $classes ); $i++) {
1297
-
1298
- if ( $prefix === substr( $classes[ $i ], 0, strlen( $prefix ) ))
1299
- return str_replace( $prefix, '', $classes[ $i ] );
1300
-
1301
- }
1302
-
1303
- return '';
1304
- }
1305
 
1306
- /*
1307
- * Get description for a given image
1308
- */
1309
- function jpibfi_get_image_description( $id, $src ) {
1310
-
1311
- $error_result = jpibfi_get_image_description_error_array();
1312
-
1313
- $result = is_numeric( $id ) ? jpibfi_get_image_description_by_id( $id ) : $error_result;
1314
-
1315
- //if description based on id wasn't found
1316
- if ( $error_result[ 'result' ] === $result[ 'result' ] ) {
1317
- $id = jpibfi_fjarrett_get_attachment_id_by_url( $src );
1318
- $result = is_numeric ( $id ) ? jpibfi_get_image_description_by_id( $id ) : $error_result;
1319
- }
1320
-
1321
- return $result[ 'description' ];
1322
- }
1323
-
1324
- /*
1325
- * Function searches for image based on $id and returns an array based on results
1326
- */
1327
- function jpibfi_get_image_description_by_id( $id ){
1328
-
1329
- $attachment = get_post( $id );
1330
-
1331
- if ( null == $attachment ) {
1332
- $result = jpibfi_get_image_description_error_array();
1333
- } else {
1334
- $result = array(
1335
- 'description' => $attachment->post_content,
1336
- 'result' => '0'
1337
- );
1338
- }
1339
 
1340
- return $result;
1341
- }
1342
 
1343
- //returns error image description array
1344
- function jpibfi_get_image_description_error_array() {
1345
- return array(
1346
- 'description' => '',
1347
- 'result' => '1'
1348
- );
1349
- }
1350
 
1351
- /*
1352
- * Function returns properly formatted description of a setting
1353
- */
1354
- function jpibfi_create_description( $desc ) {
1355
- return '<p class="description">' . $desc . '</p>';
1356
- }
1357
 
1358
- function jpibfi_create_errors( $setting_name ) {
1359
- $error = "";
1360
 
1361
- $errors_array = get_settings_errors( $setting_name );
 
1362
 
1363
- if ( count ( $errors_array ) > 0 ) {
1364
- $error .= '<div class="jpibfi-error-message">';
1365
- for( $i = 0; $i < count( $errors_array ); $i++ ){
1366
- $error .= $errors_array[ $i ]['message'] . '</br>';
 
1367
  }
1368
- $error .= '</div>';
1369
- }
1370
 
1371
- return $error;
1372
- }
1373
 
1374
- /*
1375
- * writes or returns chosen text depending whether the given condition is true or false
1376
- */
1377
- function jpibfi_conditional( $condition, $true_value = "", $false_value = "", $echo = true) {
1378
- if ( $condition ) {
1379
- if ( $echo )
1380
- echo $true_value;
1381
- return $true_value;
1382
- }
1383
- if ( $echo )
1384
- echo $false_value;
1385
- return $false_value;
1386
- }
1387
 
1388
- function jpibfi_exists_and_equal_to( $array , $name, $expected_value = "1" ) {
1389
- return isset( $array[ $name ] ) && $array[ $name ] == $expected_value;
1390
- }
1391
-
1392
- /*
1393
- * If there are errors, let's return the array with 'unsaved' data
1394
- * 'Saved' settings otherwise
1395
- */
1396
- function jpibfi_get_options( $name ) {
1397
- //cumbersome, but works in WP 3.3
1398
- $options = get_option( $name . '_errors' );
1399
 
1400
- return false == $options ? get_option( $name ) : $options;
1401
- }
1402
-
1403
- /*
1404
- * Function makes sure that option has all needed fields by checking with defaults
1405
- */
1406
- function jpibfi_update_option_fields( $option, $default_option, $option_name ) {
1407
-
1408
- $new_option = array();
1409
-
1410
- if ( false == $option )
1411
- $option = array();
1412
 
1413
- foreach ($default_option as $key => $value ) {
1414
- if ( false == array_key_exists( $key, $option ) )
1415
- $new_option [ $key ] = $value;
1416
- else
1417
- $new_option [ $key ] = $option [ $key ];
1418
  }
1419
 
1420
- update_option( $option_name, $new_option );
1421
-
1422
- }
1423
-
1424
- function jpibfi_is_string_css_class_name( $class_name ) {
1425
- return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/", $class_name );
1426
- }
1427
 
1428
- //checks if given string contains class names separated by semicolons or is empty
1429
- function jpibfi_contains_css_class_names_or_empty( $str ) {
1430
- if ( 0 == strlen( $str ) )
1431
- return true;
1432
 
1433
- $names = explode( ';', $str );
1434
- $only_class_names = true;
1435
-
1436
- for( $i = 0; $i < count( $names ) && $only_class_names; $i++ )
1437
- $only_class_names = jpibfi_is_string_css_class_name( $names [ $i ] );
1438
-
1439
- return $only_class_names;
1440
  }
1441
 
1442
- /**
1443
- * Function copied from http://frankiejarrett.com/get-an-attachment-id-by-url-in-wordpress/
1444
- * Return an ID of an attachment by searching the database with the file URL.
1445
- *
1446
- * First checks to see if the $url is pointing to a file that exists in
1447
- * the wp-content directory. If so, then we search the database for a
1448
- * partial match consisting of the remaining path AFTER the wp-content
1449
- * directory. Finally, if a match is found the attachment ID will be
1450
- * returned.
1451
- *
1452
- * @return {int} $attachment
1453
- */
1454
- function jpibfi_fjarrett_get_attachment_id_by_url( $url ) {
1455
-
1456
- // Split the $url into two parts with the wp-content directory as the separator.
1457
- $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
1458
-
1459
- // Get the host of the current site and the host of the $url, ignoring www.
1460
- $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
1461
- $file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
1462
-
1463
- // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
1464
- if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) )
1465
- return;
1466
-
1467
- // Now we're going to quickly search the DB for any attachment GUID with a partial path match.
1468
- // Example: /uploads/2013/05/test-image.jpg
1469
- global $wpdb;
1470
-
1471
- $prefix = $wpdb->prefix;
1472
- $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $prefix . "posts WHERE guid RLIKE %s;", $parse_url[1] ) );
1473
-
1474
- // Returns null if no attachment is found.
1475
- return $attachment ? $attachment[0] : null;
1476
- }
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.30
8
  Author URI: http://mrsztuczkens.me/
9
  */
10
 
11
+ // If this file is called directly, abort.
12
+ if ( ! defined( 'WPINC' ) ) {
13
+ die;
14
  }
15
+ if ( ! class_exists( 'jQuery_Pin_It_Button_For_Images' ) ) :
16
 
17
+ /* Main JPIBFI Class */
18
+ final class jQuery_Pin_It_Button_For_Images {
19
+ /** Singleton *************************************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ private static $instance;
22
 
23
+ private function __construct() {
24
+ $this->setup_constants();
25
+ $this->includes();
26
+ $this->load_textdomain();
27
 
28
+ $jpibfi_plugin = plugin_basename( __FILE__ );
29
+ add_filter( "plugin_action_links_$jpibfi_plugin", array( $this, 'plugin_settings_filter' ) );
 
30
 
31
+ register_activation_hook( __FILE__, array( $this, 'update_plugin' ) );
32
+ add_action( 'plugins_loaded', array( $this, 'update_plugin' ) );
33
+ }
 
 
 
34
 
35
+ public static function instance() {
36
+ if ( null == self::$instance ) {
37
+ self::$instance = new self;
 
38
  }
39
+ return self::$instance;
40
  }
41
 
42
+ /**
43
+ * Setup plugin constants
44
+ */
45
+ private function setup_constants() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ /* VERSIONING */
48
+ //plugin version
49
+ if ( ! defined( 'JPIBFI_VERSION' ) )
50
+ define( 'JPIBFI_VERSION', '1.30' );
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ //used in versioning css and js files
53
+ if ( ! defined( 'JPIBFI_VERSION_MINOR' ) )
54
+ define( 'JPIBFI_VERSION_MINOR', 'a' );
55
 
56
+ /* OPTIONS IN DATABASE */
57
+ //metadata for each post
58
+ if ( ! defined( 'JPIBFI_METADATA' ) )
59
+ define( 'JPIBFI_METADATA', 'jpibfi_meta' );
60
 
61
+ //used in error handling
62
+ if ( ! defined( 'JPIBFI_UPDATE_OPTIONS' ) )
63
+ define( 'JPIBFI_UPDATE_OPTIONS', 'jpibfi_update_options' );
 
 
64
 
65
+ if ( ! defined( 'JPIBFI_SELECTION_OPTIONS' ) )
66
+ define( 'JPIBFI_SELECTION_OPTIONS', 'jpibfi_selection_options' );
 
 
 
 
 
 
 
67
 
68
+ if ( ! defined( 'JPIBFI_VISUAL_OPTIONS' ) )
69
+ define( 'JPIBFI_VISUAL_OPTIONS', 'jpibfi_visual_options' );
70
 
71
+ if ( ! defined( 'JPIBFI_ADVANCED_OPTIONS' ) )
72
+ define( 'JPIBFI_ADVANCED_OPTIONS', 'jpibfi_advanced_options' );
 
 
73
 
74
+ if ( ! defined( 'JPIBFI_VERSION_OPTION' ) )
75
+ define( 'JPIBFI_VERSION_OPTION', 'jpibfi_version' );
 
 
 
76
 
77
+ /* FOLDERS */
78
+ // Plugin Folder Path
79
+ if ( ! defined( 'JPIBFI_PLUGIN_DIR' ) )
80
+ define( 'JPIBFI_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
81
 
82
+ // Plugin Folder URL
83
+ if ( ! defined( 'JPIBFI_PLUGIN_URL' ) )
84
+ define( 'JPIBFI_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
85
 
86
+ // Plugin Root File
87
+ if ( ! defined( 'JPIBFI_PLUGIN_FILE' ) )
88
+ define( 'JPIBFI_PLUGIN_FILE', __FILE__ );
89
 
90
+ if ( ! defined( 'JPIBFI_STYLE_URL' ) )
91
+ define( 'JPIBFI_STYLE_URL', JPIBFI_PLUGIN_URL . 'css/' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
+ if ( ! defined( 'JPIBFI_SCRIPT_URL' ) )
94
+ define( 'JPIBFI_SCRIPT_URL', JPIBFI_PLUGIN_URL . 'js/' );
95
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
+ /**
98
+ * Include required files
99
+ */
100
+ private function includes() {
101
+ global $jpibfi_selection_options;
102
+ global $jpibfi_visual_options;
103
+ global $jpibfi_adanced_options;
104
+
105
+ $jpibfi_selection_options = get_option( JPIBFI_SELECTION_OPTIONS );
106
+ $jpibfi_visual_options = get_option( JPIBFI_VISUAL_OPTIONS );
107
+ $jpibfi_adanced_options = get_option( JPIBFI_ADVANCED_OPTIONS );
108
+
109
+ //require_once JPIBFI_PLUGIN_DIR . 'includes/login-register.php';
110
+
111
+ if ( is_admin() ) {
112
+ require_once JPIBFI_PLUGIN_DIR . 'includes/admin/class-jpibfi-admin-utilities.php';
113
+ require_once JPIBFI_PLUGIN_DIR . 'includes/admin/class-jpibfi-selection-options.php';
114
+ require_once JPIBFI_PLUGIN_DIR . 'includes/admin/class-jpibfi-advanced-options.php';
115
+ require_once JPIBFI_PLUGIN_DIR . 'includes/admin/class-jpibfi-visual-options.php';
116
+ require_once JPIBFI_PLUGIN_DIR . 'includes/admin/class-jpibfi-admin.php';
117
+ } else {
118
+ require_once JPIBFI_PLUGIN_DIR . 'includes/public/class-jpibfi-client-utilities.php';
119
+ require_once JPIBFI_PLUGIN_DIR . 'includes/public/class-jpibfi-client.php';
120
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
+ public function load_textdomain() {
124
+ load_plugin_textdomain( 'jpibfi', FALSE, dirname( plugin_basename( JPIBFI_PLUGIN_FILE ) ) . '/languages/' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
+ public function plugin_settings_filter( $links ) {
128
+ $settings_link = '<a href="options-general.php?page=jpibfi_settings">' . __( 'Settings', 'jpibfi' ) . '</a>';
129
+ array_unshift( $links, $settings_link );
130
+ return $links;
131
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
+ /* Function updates DB if it detects new version of the plugin */
134
+ public function update_plugin() {
135
 
136
+ $version = get_option( JPIBFI_VERSION_OPTION );
137
+ //if update is needed
138
+ if ( false == $version || (float)$version < (float)JPIBFI_VERSION || get_option( JPIBFI_UPDATE_OPTIONS ) ) {
 
 
 
 
139
 
140
+ $option = get_option( JPIBFI_VISUAL_OPTIONS );
141
+ self::update_option_fields( $option, JPIBFI_Visual_Options::default_visual_options(), JPIBFI_VISUAL_OPTIONS );
 
 
 
 
142
 
143
+ $option = get_option( JPIBFI_SELECTION_OPTIONS );
144
+ self::update_option_fields( $option, JPIBFI_Selection_Options::default_selection_options(), JPIBFI_SELECTION_OPTIONS );
145
 
146
+ $option = get_option( JPIBFI_ADVANCED_OPTIONS );
147
+ self::update_option_fields( $option, JPIBFI_ADVANCED_OPTIONS::default_advanced_options(), JPIBFI_ADVANCED_OPTIONS );
148
 
149
+ //update the version of the plugin stored in option
150
+ update_option( JPIBFI_VERSION_OPTION, JPIBFI_VERSION );
151
+ //update not needed anymore
152
+ update_option( JPIBFI_UPDATE_OPTIONS, false);
153
+ }
154
  }
 
 
155
 
156
+ /* Function makes sure that option has all needed fields by checking with defaults */
157
+ public static function update_option_fields( $option, $default_option, $option_name ) {
158
 
159
+ $new_option = array();
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
+ if ( false == $option )
162
+ $option = array();
 
 
 
 
 
 
 
 
 
163
 
164
+ foreach ($default_option as $key => $value ) {
165
+ if ( false == array_key_exists( $key, $option ) )
166
+ $new_option [ $key ] = $value;
167
+ else
168
+ $new_option [ $key ] = $option [ $key ];
169
+ }
 
 
 
 
 
 
170
 
171
+ update_option( $option_name, $new_option );
172
+ }
 
 
 
173
  }
174
 
175
+ endif; // End if class_exists check
 
 
 
 
 
 
176
 
 
 
 
 
177
 
178
+ function JPIBFI() {
179
+ return jQuery_Pin_It_Button_For_Images::instance();
 
 
 
 
 
180
  }
181
 
182
+ JPIBFI();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/script.js CHANGED
@@ -7,7 +7,7 @@
7
  var jpibfi_debug = false;
8
 
9
  /* SETTINGS */
10
- var settings = {};
11
  var pinButtonDimensions = {};
12
  var pinButtonMargins = {};
13
 
@@ -19,6 +19,9 @@
19
 
20
  var jpibfi = {};
21
 
 
 
 
22
  /* FUNCTIONS THAT CAN BE OVERRIDDEN */
23
  jpibfi.fn = {};
24
 
@@ -47,17 +50,17 @@
47
  jpibfi.prepareImages = function ( $elements ) {
48
  jpibfiLog( '>>Add Elements' );
49
  jpibfiLog( 'Elements: ' + $elements.length );
50
- jpibfiLog( 'Min width:' + settings.minImageWidth);
51
- jpibfiLog( 'Min height:' + settings.minImageHeight);
52
  var imageCount = 0;
53
  $elements.each(function () {
54
  var $image = $(this);
55
- if ( this.clientWidth < settings.minImageWidth || this.clientHeight < settings.minImageHeight ) {
56
  $image.removeAttr( 'data-jpibfi-indexer' );
57
  return;
58
  }
59
- if ( settings.mode == 'static' )
60
- jpibfiCreateAndShowOverlayDiv( $image, settings.buttonPosition );
61
 
62
  imageCount++;
63
  });
@@ -72,53 +75,46 @@
72
  /* INITIALIZE */
73
 
74
  jpibfi.init = function( jpibfi_options ) {
75
- settings = {
76
  pageUrl : document.URL,
77
  pageTitle : document.title,
78
  pageDescription : $('meta[name="description"]').attr('content') || "",
79
- siteTitle : jpibfi_options.site_title,
80
- disabledClasses : jpibfi_options.disabled_classes,
81
- enabledClasses : jpibfi_options.enabled_classes,
82
- descriptionOption : jpibfi_options.description_option,
83
- usePostUrl : jpibfi_options.use_post_url == "1",
84
- minImageHeight : jpibfi_options.min_image_height,
85
- minImageWidth : jpibfi_options.min_image_width,
86
- mode : jpibfi_options.mode,
87
- buttonPosition : jpibfi_options.button_position
88
  }
89
 
 
 
90
  pinButtonDimensions = {
91
- height: parseInt( jpibfi_options.pin_image_height ),
92
- width: parseInt( jpibfi_options.pin_image_width )
93
  }
94
 
95
  pinButtonMargins = {
96
- top: parseInt( jpibfi_options.button_margin_top ),
97
- right: parseInt( jpibfi_options.button_margin_right ),
98
- bottom: parseInt( jpibfi_options.button_margin_bottom ),
99
- left: parseInt( jpibfi_options.button_margin_left )
100
  }
101
 
102
  jpibfi_debug = '1' == jpibfi_options.debug;
103
 
104
- jpibfiLog( settings );
105
  jpibfiLog( pinButtonDimensions );
106
  jpibfiLog( pinButtonMargins );
107
 
108
- var $containers = $('.jpibfi').closest('div').addClass('jpibfi_container');
109
 
110
  jpibfiLog( 'Number of containers added: ' + $containers.length );
111
 
112
  //we need to prepare selectors
113
- notSelector = createSelectorFromList( settings.disabledClasses );
114
- filterSelector = createSelectorFromList( settings.enabledClasses ) || "*";
115
 
116
  jpibfiLog( 'Filter selector: ' + filterSelector );
117
  jpibfiLog( 'Not selector: ' + notSelector );
118
 
119
  //EVENT HANDLING - ADDING EVERY NEEDED EVENT
120
 
121
- if ( 'static' == settings.mode) {
122
 
123
  jpibfiLog( 'Adding static mode delegates');
124
 
@@ -129,7 +125,7 @@
129
  $('img[data-jpibfi-indexer="' + indexer + '"]').toggleClass( 'pinit-hover', hover );
130
  });
131
 
132
- } else if ( 'dynamic' == settings.mode ) {
133
 
134
  jpibfiLog( 'Adding dynamic mode delegates');
135
 
@@ -155,14 +151,14 @@
155
 
156
  if ( $button.length == 0 ) {
157
  //button doesn't exist so we need to create it
158
- var $button = jpibfiCreatePinitButton( indexer );
159
  var position = $image.offset();
160
  var imageDimensions = {
161
  width: $image.get(0).clientWidth,
162
  height: $image.get(0).clientHeight
163
  }
164
 
165
- switch( settings.buttonPosition ){
166
  case '0': //top-left
167
  position.left += pinButtonMargins.left;
168
  position.top += pinButtonMargins.top;
@@ -232,28 +228,29 @@
232
  var bookmarkDescription = "", descriptionForUrl = "", bookmarkUrl = "";
233
 
234
  //if usePostUrl feature is active, we need to get the data
235
- if ( settings.usePostUrl ) {
236
- var $inputWithData = $image.closest("div.jpibfi_container").find("input.jpibfi").first();
237
 
238
  if ( $inputWithData.length ) {
239
- descriptionForUrl = $inputWithData.data("jpibfi-description")
240
  bookmarkUrl = $inputWithData.data("jpibfi-url");
241
  }
242
  }
243
- bookmarkUrl = bookmarkUrl || settings.pageUrl;
244
 
245
- if ( settings.descriptionOption == 3 )
246
  bookmarkDescription = $image.attr('title') || $image.attr('alt');
247
- else if ( settings.descriptionOption == 2 )
248
- bookmarkDescription = descriptionForUrl || settings.pageDescription;
249
- else if ( settings.descriptionOption == 4 )
250
- bookmarkDescription = settings.siteTitle;
251
- else if ( settings.descriptionOption == 5 )
252
  bookmarkDescription = $image.data( 'jpibfi-description' );
253
 
254
- bookmarkDescription = bookmarkDescription || ( descriptionForUrl || settings.pageTitle );
255
 
256
- var imageUrl = 'http://pinterest.com/pin/create/bookmarklet/?is_video=' + encodeURIComponent('false') + "&url=" + encodeURIComponent( bookmarkUrl ) + "&media=" + encodeURIComponent( jpibfi.fn.getImageUrl( $image ) )
 
257
  + '&description=' + encodeURIComponent( bookmarkDescription );
258
 
259
  window.open(imageUrl, 'Pinterest', 'width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1');
@@ -353,7 +350,7 @@
353
  $(document).ready( function() {
354
  jpibfi.init( jpibfi_options );
355
 
356
- jpibfi.addImages( jpibfi_options.image_selector );
357
 
358
  $(window).load( function() {
359
  jpibfi.prepareImages( $('img[data-jpibfi-indexer]') );
7
  var jpibfi_debug = false;
8
 
9
  /* SETTINGS */
10
+
11
  var pinButtonDimensions = {};
12
  var pinButtonMargins = {};
13
 
19
 
20
  var jpibfi = {};
21
 
22
+ //here settings are stored
23
+ jpibfi.settings = {};
24
+
25
  /* FUNCTIONS THAT CAN BE OVERRIDDEN */
26
  jpibfi.fn = {};
27
 
50
  jpibfi.prepareImages = function ( $elements ) {
51
  jpibfiLog( '>>Add Elements' );
52
  jpibfiLog( 'Elements: ' + $elements.length );
53
+ jpibfiLog( 'Min width:' + jpibfi.settings.minImageWidth);
54
+ jpibfiLog( 'Min height:' + jpibfi.settings.minImageHeight);
55
  var imageCount = 0;
56
  $elements.each(function () {
57
  var $image = $(this);
58
+ if ( this.clientWidth < jpibfi.settings.minImageWidth || this.clientHeight < jpibfi.settings.minImageHeight ) {
59
  $image.removeAttr( 'data-jpibfi-indexer' );
60
  return;
61
  }
62
+ if ( jpibfi.settings.mode == 'static' )
63
+ jpibfiCreateAndShowOverlayDiv( $image, jpibfi.settings.buttonPosition );
64
 
65
  imageCount++;
66
  });
75
  /* INITIALIZE */
76
 
77
  jpibfi.init = function( jpibfi_options ) {
78
+ jpibfi.settings = {
79
  pageUrl : document.URL,
80
  pageTitle : document.title,
81
  pageDescription : $('meta[name="description"]').attr('content') || "",
 
 
 
 
 
 
 
 
 
82
  }
83
 
84
+ jpibfi.settings = $.extend(jpibfi.settings, jpibfi_options);
85
+
86
  pinButtonDimensions = {
87
+ height: parseInt( jpibfi_options.pinImageHeight ),
88
+ width: parseInt( jpibfi_options.pinImageWidth )
89
  }
90
 
91
  pinButtonMargins = {
92
+ top: parseInt( jpibfi_options.buttonMarginTop ),
93
+ right: parseInt( jpibfi_options.buttonMarginRight ),
94
+ bottom: parseInt( jpibfi_options.buttonMarginBottom ),
95
+ left: parseInt( jpibfi_options.buttonMarginLeft )
96
  }
97
 
98
  jpibfi_debug = '1' == jpibfi_options.debug;
99
 
100
+ jpibfiLog( jpibfi.settings );
101
  jpibfiLog( pinButtonDimensions );
102
  jpibfiLog( pinButtonMargins );
103
 
104
+ var $containers = $('.jpibfi').closest(jpibfi.settings.containerSelector).addClass('jpibfi_container');
105
 
106
  jpibfiLog( 'Number of containers added: ' + $containers.length );
107
 
108
  //we need to prepare selectors
109
+ notSelector = createSelectorFromList( jpibfi.settings.disabledClasses );
110
+ filterSelector = createSelectorFromList( jpibfi.settings.enabledClasses ) || "*";
111
 
112
  jpibfiLog( 'Filter selector: ' + filterSelector );
113
  jpibfiLog( 'Not selector: ' + notSelector );
114
 
115
  //EVENT HANDLING - ADDING EVERY NEEDED EVENT
116
 
117
+ if ( 'static' == jpibfi.settings.mode) {
118
 
119
  jpibfiLog( 'Adding static mode delegates');
120
 
125
  $('img[data-jpibfi-indexer="' + indexer + '"]').toggleClass( 'pinit-hover', hover );
126
  });
127
 
128
+ } else if ( 'dynamic' == jpibfi.settings.mode ) {
129
 
130
  jpibfiLog( 'Adding dynamic mode delegates');
131
 
151
 
152
  if ( $button.length == 0 ) {
153
  //button doesn't exist so we need to create it
154
+ $button = jpibfiCreatePinitButton( indexer );
155
  var position = $image.offset();
156
  var imageDimensions = {
157
  width: $image.get(0).clientWidth,
158
  height: $image.get(0).clientHeight
159
  }
160
 
161
+ switch( jpibfi.settings.buttonPosition ){
162
  case '0': //top-left
163
  position.left += pinButtonMargins.left;
164
  position.top += pinButtonMargins.top;
228
  var bookmarkDescription = "", descriptionForUrl = "", bookmarkUrl = "";
229
 
230
  //if usePostUrl feature is active, we need to get the data
231
+ if ( jpibfi.settings.usePostUrl ) {
232
+ var $inputWithData = $image.closest(".jpibfi_container").find("input.jpibfi").first();
233
 
234
  if ( $inputWithData.length ) {
235
+ descriptionForUrl = $inputWithData.data("jpibfi-description");
236
  bookmarkUrl = $inputWithData.data("jpibfi-url");
237
  }
238
  }
239
+ bookmarkUrl = bookmarkUrl || jpibfi.settings.pageUrl;
240
 
241
+ if ( jpibfi.settings.descriptionOption == 3 )
242
  bookmarkDescription = $image.attr('title') || $image.attr('alt');
243
+ else if ( jpibfi.settings.descriptionOption == 2 )
244
+ bookmarkDescription = descriptionForUrl || jpibfi.settings.pageDescription;
245
+ else if ( jpibfi.settings.descriptionOption == 4 )
246
+ bookmarkDescription = jpibfi.settings.siteTitle;
247
+ else if ( jpibfi.settings.descriptionOption == 5 )
248
  bookmarkDescription = $image.data( 'jpibfi-description' );
249
 
250
+ bookmarkDescription = bookmarkDescription || ( descriptionForUrl || jpibfi.settings.pageTitle );
251
 
252
+ var imageUrl = 'http://pinterest.com/pin/create/bookmarklet/?is_video=' + encodeURIComponent('false')
253
+ + "&url=" + encodeURIComponent( bookmarkUrl ) + "&media=" + encodeURIComponent( jpibfi.fn.getImageUrl( $image ) )
254
  + '&description=' + encodeURIComponent( bookmarkDescription );
255
 
256
  window.open(imageUrl, 'Pinterest', 'width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1');
350
  $(document).ready( function() {
351
  jpibfi.init( jpibfi_options );
352
 
353
+ jpibfi.addImages( jpibfi_options.imageSelector );
354
 
355
  $(window).load( function() {
356
  jpibfi.prepareImages( $('img[data-jpibfi-indexer]') );
js/script.min.js CHANGED
@@ -1 +1 @@
1
- (function(e){"use strict";window.jpibfi=function(){function f(t){var r=jQuery("<a/>",{href:"#","class":"pinit-button","data-jpibfi-indexer":t,text:"Pin It"});r.click(function(t){d("Pin In button clicked");var r=e(this).data("jpibfi-indexer");var i=e('img[data-jpibfi-indexer="'+r+'"]');var s="",o="",u="";if(n.usePostUrl){var f=i.closest("div.jpibfi_container").find("input.jpibfi").first();if(f.length){o=f.data("jpibfi-description");u=f.data("jpibfi-url")}}u=u||n.pageUrl;if(n.descriptionOption==3)s=i.attr("title")||i.attr("alt");else if(n.descriptionOption==2)s=o||n.pageDescription;else if(n.descriptionOption==4)s=n.siteTitle;else if(n.descriptionOption==5)s=i.data("jpibfi-description");s=s||o||n.pageTitle;var l="http://pinterest.com/pin/create/bookmarklet/?is_video="+encodeURIComponent("false")+"&url="+encodeURIComponent(u)+"&media="+encodeURIComponent(a.fn.getImageUrl(i))+"&description="+encodeURIComponent(s);window.open(l,"Pinterest","width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1");return false});return r}function l(e,t){var n=e.offset();var r=c(e,t);e.after(r);r.css({height:e.get(0).clientHeight+"px",width:e.get(0).clientWidth+"px"}).show().offset({left:n.left,top:n.top});return r}function c(e,t){var n=e.data("jpibfi-indexer");return jQuery("<div/>",{"class":"pinit-overlay","data-jpibfi-indexer":n,title:e.attr("title")||"",html:f(n).addClass(h(t))})}function h(e){switch(e){case"0":return"pinit-top-left";case"1":return"pinit-top-right";case"2":return"pinit-bottom-left";case"3":return"pinit-bottom-right";case"4":return"pinit-middle";default:return""}}function p(e){var t=e.split(";");var n="";for(var r=0;r<t.length;r++){if(t[r])n+="."+t[r]+","}if(n)n=n.substr(0,n.length-1);return n}function d(e){if(t&&console&&console.log){if("string"==typeof e||e instanceof String){console.log("jpibfi debug: "+e)}else if("object"==typeof e&&typeof JSON!=="undefined"&&typeof JSON.stringify==="function"){console.log("jpibfi debug: "+JSON.stringify(e,null,4))}else if("object"==typeof e){var n="";for(var r in e)n+=r+": "+e[r]+"\n";console.log("jpibfi debug: "+n)}}}var t=false;var n={};var r={};var i={};var s="";var o="*";var u=0;var a={};a.fn={};a.fn.getImageUrl=function(e){return e.data("media")||e.attr("src")};a.addImages=function(t){d(">>addImages");var n=e(t).not(s).not("[data-jpibfi-indexer]").filter(o);n.each(function(){e(this).attr("data-jpibfi-indexer",u);u++});d("Images caught by selectors: "+u);return n};a.prepareImages=function(t){d(">>Add Elements");d("Elements: "+t.length);d("Min width:"+n.minImageWidth);d("Min height:"+n.minImageHeight);var r=0;t.each(function(){var t=e(this);if(this.clientWidth<n.minImageWidth||this.clientHeight<n.minImageHeight){t.removeAttr("data-jpibfi-indexer");return}if(n.mode=="static")l(t,n.buttonPosition);r++});d("Images caught after filtering: "+r)};a.removeAllImages=function(){d("Remove Elements called");e("div.pinit-overlay").remove()};a.init=function(u){n={pageUrl:document.URL,pageTitle:document.title,pageDescription:e('meta[name="description"]').attr("content")||"",siteTitle:u.site_title,disabledClasses:u.disabled_classes,enabledClasses:u.enabled_classes,descriptionOption:u.description_option,usePostUrl:u.use_post_url=="1",minImageHeight:u.min_image_height,minImageWidth:u.min_image_width,mode:u.mode,buttonPosition:u.button_position};r={height:parseInt(u.pin_image_height),width:parseInt(u.pin_image_width)};i={top:parseInt(u.button_margin_top),right:parseInt(u.button_margin_right),bottom:parseInt(u.button_margin_bottom),left:parseInt(u.button_margin_left)};t="1"==u.debug;d(n);d(r);d(i);var a=e(".jpibfi").closest("div").addClass("jpibfi_container");d("Number of containers added: "+a.length);s=p(n.disabledClasses);o=p(n.enabledClasses)||"*";d("Filter selector: "+o);d("Not selector: "+s);if("static"==n.mode){d("Adding static mode delegates");e(document).delegate("div.pinit-overlay","hover",function(t){var n=t.type==="mouseenter";var r=e(this).data("jpibfi-indexer");e('.pinit-button[data-jpibfi-indexer="'+r+'"]').toggle(n);e('img[data-jpibfi-indexer="'+r+'"]').toggleClass("pinit-hover",n)})}else if("dynamic"==n.mode){d("Adding dynamic mode delegates");e(document).delegate("a.pinit-button","mouseenter",function(){var t=e(this);clearTimeout(t.data("jpibfi-timeoutId"))});e(document).delegate("a.pinit-button","mouseleave",function(){var t=e(this);var n=setTimeout(function(){t.remove();e('img[data-jpibfi-indexer="'+t.data("jpibfi-indexer")+'"]').removeClass("pinit-hover")},100);t.data("jpibfi-timeoutId",n)});e(document).delegate("img[data-jpibfi-indexer]","mouseenter",function(){var t=e(this);var s=t.data("jpibfi-indexer");var o=e('a.pinit-button[data-jpibfi-indexer="'+s+'"]');if(o.length==0){var o=f(s);var u=t.offset();var a={width:t.get(0).clientWidth,height:t.get(0).clientHeight};switch(n.buttonPosition){case"0":u.left+=i.left;u.top+=i.top;break;case"1":u.top+=i.top;u.left=u.left+a.width-i.right-r.width;break;case"2":u.left+=i.left;u.top=u.top+a.height-i.bottom-r.height;break;case"3":u.left=u.left+a.width-i.right-r.width;u.top=u.top+a.height-i.bottom-r.height;break;case"4":u.left=Math.round(u.left+a.width/2-r.width/2);u.top=Math.round(u.top+a.height/2-r.height/2);break}t.after(o);o.show().offset({left:u.left,top:u.top})}else{clearTimeout(o.data("jpibfi-timeoutId"))}t.addClass("pinit-hover")});e(document).delegate("img[data-jpibfi-indexer]","mouseleave",function(){var t=e(this).data("jpibfi-indexer");var n=e('a.pinit-button[data-jpibfi-indexer="'+t+'"]');var r=setTimeout(function(){n.remove();e('img[data-jpibfi-indexer="'+n.data("jpibfi-indexer")+'"]').removeClass("pinit-hover")},100);n.data("jpibfi-timeoutId",r)})}};return a;}()})(jQuery);(function(e){"use strict";e(document).ready(function(){jpibfi.init(jpibfi_options);jpibfi.addImages(jpibfi_options.image_selector);e(window).load(function(){jpibfi.prepareImages(e("img[data-jpibfi-indexer]"))});e(window).resize(function(){jpibfi.removeAllImages();jpibfi.prepareImages(e("img[data-jpibfi-indexer]"))})})})(jQuery)
1
+ (function(e){"use strict";window.jpibfi=function(){function a(t){var n=jQuery("<a/>",{href:"#","class":"pinit-button","data-jpibfi-indexer":t,text:"Pin It"});n.click(function(t){p("Pin In button clicked");var n=e(this).data("jpibfi-indexer");var r=e('img[data-jpibfi-indexer="'+n+'"]');var i="",s="",o="";if(u.settings.usePostUrl){var a=r.closest(".jpibfi_container").find("input.jpibfi").first();if(a.length){s=a.data("jpibfi-description");o=a.data("jpibfi-url")}}o=o||u.settings.pageUrl;if(u.settings.descriptionOption==3)i=r.attr("title")||r.attr("alt");else if(u.settings.descriptionOption==2)i=s||u.settings.pageDescription;else if(u.settings.descriptionOption==4)i=u.settings.siteTitle;else if(u.settings.descriptionOption==5)i=r.data("jpibfi-description");i=i||s||u.settings.pageTitle;var f="http://pinterest.com/pin/create/bookmarklet/?is_video="+encodeURIComponent("false")+"&url="+encodeURIComponent(o)+"&media="+encodeURIComponent(u.fn.getImageUrl(r))+"&description="+encodeURIComponent(i);window.open(f,"Pinterest","width=632,height=253,status=0,toolbar=0,menubar=0,location=1,scrollbars=1");return false});return n}function f(e,t){var n=e.offset();var r=l(e,t);e.after(r);r.css({height:e.get(0).clientHeight+"px",width:e.get(0).clientWidth+"px"}).show().offset({left:n.left,top:n.top});return r}function l(e,t){var n=e.data("jpibfi-indexer");return jQuery("<div/>",{"class":"pinit-overlay","data-jpibfi-indexer":n,title:e.attr("title")||"",html:a(n).addClass(c(t))})}function c(e){switch(e){case"0":return"pinit-top-left";case"1":return"pinit-top-right";case"2":return"pinit-bottom-left";case"3":return"pinit-bottom-right";case"4":return"pinit-middle";default:return""}}function h(e){var t=e.split(";");var n="";for(var r=0;r<t.length;r++){if(t[r])n+="."+t[r]+","}if(n)n=n.substr(0,n.length-1);return n}function p(e){if(t&&console&&console.log){if("string"==typeof e||e instanceof String){console.log("jpibfi debug: "+e)}else if("object"==typeof e&&typeof JSON!=="undefined"&&typeof JSON.stringify==="function"){console.log("jpibfi debug: "+JSON.stringify(e,null,4))}else if("object"==typeof e){var n="";for(var r in e)n+=r+": "+e[r]+"\n";console.log("jpibfi debug: "+n)}}}var t=false;var n={};var r={};var i="";var s="*";var o=0;var u={};u.settings={};u.fn={};u.fn.getImageUrl=function(e){return e.data("media")||e.attr("src")};u.addImages=function(t){p(">>addImages");var n=e(t).not(i).not("[data-jpibfi-indexer]").filter(s);n.each(function(){e(this).attr("data-jpibfi-indexer",o);o++});p("Images caught by selectors: "+o);return n};u.prepareImages=function(t){p(">>Add Elements");p("Elements: "+t.length);p("Min width:"+u.settings.minImageWidth);p("Min height:"+u.settings.minImageHeight);var n=0;t.each(function(){var t=e(this);if(this.clientWidth<u.settings.minImageWidth||this.clientHeight<u.settings.minImageHeight){t.removeAttr("data-jpibfi-indexer");return}if(u.settings.mode=="static")f(t,u.settings.buttonPosition);n++});p("Images caught after filtering: "+n)};u.removeAllImages=function(){p("Remove Elements called");e("div.pinit-overlay").remove()};u.init=function(o){u.settings={pageUrl:document.URL,pageTitle:document.title,pageDescription:e('meta[name="description"]').attr("content")||""};u.settings=e.extend(u.settings,o);n={height:parseInt(o.pinImageHeight),width:parseInt(o.pinImageWidth)};r={top:parseInt(o.buttonMarginTop),right:parseInt(o.buttonMarginRight),bottom:parseInt(o.buttonMarginBottom),left:parseInt(o.buttonMarginLeft)};t="1"==o.debug;p(u.settings);p(n);p(r);var f=e(".jpibfi").closest(u.settings.containerSelector).addClass("jpibfi_container");p("Number of containers added: "+f.length);i=h(u.settings.disabledClasses);s=h(u.settings.enabledClasses)||"*";p("Filter selector: "+s);p("Not selector: "+i);if("static"==u.settings.mode){p("Adding static mode delegates");e(document).delegate("div.pinit-overlay","hover",function(t){var n=t.type==="mouseenter";var r=e(this).data("jpibfi-indexer");e('.pinit-button[data-jpibfi-indexer="'+r+'"]').toggle(n);e('img[data-jpibfi-indexer="'+r+'"]').toggleClass("pinit-hover",n)})}else if("dynamic"==u.settings.mode){p("Adding dynamic mode delegates");e(document).delegate("a.pinit-button","mouseenter",function(){var t=e(this);clearTimeout(t.data("jpibfi-timeoutId"))});e(document).delegate("a.pinit-button","mouseleave",function(){var t=e(this);var n=setTimeout(function(){t.remove();e('img[data-jpibfi-indexer="'+t.data("jpibfi-indexer")+'"]').removeClass("pinit-hover")},100);t.data("jpibfi-timeoutId",n)});e(document).delegate("img[data-jpibfi-indexer]","mouseenter",function(){var t=e(this);var i=t.data("jpibfi-indexer");var s=e('a.pinit-button[data-jpibfi-indexer="'+i+'"]');if(s.length==0){s=a(i);var o=t.offset();var f={width:t.get(0).clientWidth,height:t.get(0).clientHeight};switch(u.settings.buttonPosition){case"0":o.left+=r.left;o.top+=r.top;break;case"1":o.top+=r.top;o.left=o.left+f.width-r.right-n.width;break;case"2":o.left+=r.left;o.top=o.top+f.height-r.bottom-n.height;break;case"3":o.left=o.left+f.width-r.right-n.width;o.top=o.top+f.height-r.bottom-n.height;break;case"4":o.left=Math.round(o.left+f.width/2-n.width/2);o.top=Math.round(o.top+f.height/2-n.height/2);break}t.after(s);s.show().offset({left:o.left,top:o.top})}else{clearTimeout(s.data("jpibfi-timeoutId"))}t.addClass("pinit-hover")});e(document).delegate("img[data-jpibfi-indexer]","mouseleave",function(){var t=e(this).data("jpibfi-indexer");var n=e('a.pinit-button[data-jpibfi-indexer="'+t+'"]');var r=setTimeout(function(){n.remove();e('img[data-jpibfi-indexer="'+n.data("jpibfi-indexer")+'"]').removeClass("pinit-hover")},100);n.data("jpibfi-timeoutId",r)})}};return u;}()})(jQuery);(function(e){"use strict";e(document).ready(function(){jpibfi.init(jpibfi_options);jpibfi.addImages(jpibfi_options.imageSelector);e(window).load(function(){jpibfi.prepareImages(e("img[data-jpibfi-indexer]"))});e(window).resize(function(){jpibfi.removeAllImages();jpibfi.prepareImages(e("img[data-jpibfi-indexer]"))})})})(jQuery)
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://bit.ly/Uw2mEP
4
  Tags: pinterest, pin it, button, image, images, pinit, social media, hover, click, photo, photos
5
  Requires at least: 3.3.0
6
  Tested up to: 3.6.1
7
- Stable tag: 1.21
8
  License: GPLv2 or later
9
 
10
  Highlights images on hover and adds a Pinterest "Pin It" button over them for easy pinning.
@@ -76,6 +76,11 @@ Please report them in the plugin's support forum on Wordpress.org.
76
 
77
  == Changelog ==
78
 
 
 
 
 
 
79
  = 1.21 =
80
  * Released 2014-02-22
81
  * Fixed one issue from the previous release
@@ -189,6 +194,9 @@ Please report them in the plugin's support forum on Wordpress.org.
189
 
190
  == Upgrade Notice ==
191
 
 
 
 
192
  = 1.21 =
193
  Fixed one issue from the previous release.
194
 
4
  Tags: pinterest, pin it, button, image, images, pinit, social media, hover, click, photo, photos
5
  Requires at least: 3.3.0
6
  Tested up to: 3.6.1
7
+ Stable tag: 1.30
8
  License: GPLv2 or later
9
 
10
  Highlights images on hover and adds a Pinterest "Pin It" button over them for easy pinning.
76
 
77
  == Changelog ==
78
 
79
+ = 1.30 =
80
+ * Release 2014-03-13
81
+ * PHP code redesign - plugin is much more extension friendly
82
+ * Deleted some of the compatibility-with-older-versions code
83
+
84
  = 1.21 =
85
  * Released 2014-02-22
86
  * Fixed one issue from the previous release
194
 
195
  == Upgrade Notice ==
196
 
197
+ = 1.30 =
198
+ PHP code redesign.
199
+
200
  = 1.21 =
201
  Fixed one issue from the previous release.
202
 
uninstall.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ //if uninstall not called from WordPress exit
5
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
6
+ exit();
7
+
8
+ //delete all added options
9
+ delete_option( 'jpibfi_selection_options' );
10
+ delete_option( 'jpibfi_visual_options' );
11
+ delete_option( 'jpibfi_advanced_options' );
12
+ delete_option( 'jpibfi_version' );
13
+
14
+ //delete added metadata from all posts
15
+ delete_post_meta_by_key( 'jpibfi_meta' );