jQuery Pin It Button for Images - Version 2.00

Version Description

  • Release 2016-10-02
  • Complete code rewrite
  • Added support for featured image
  • Plugin settings clean up
Download this release

Release Info

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

Code changes from version 1.60 to 2.00

Files changed (47) hide show
  1. css/admin-ad.css +26 -0
  2. css/admin.css +2 -43
  3. css/colorbox.css +0 -70
  4. css/images/border.png +0 -0
  5. css/images/controls.png +0 -0
  6. css/images/loading.gif +0 -0
  7. css/images/loading_background.png +0 -0
  8. css/images/overlay.png +0 -0
  9. includes/admin/class-jpibfi-admin-utilities.php +0 -50
  10. includes/admin/class-jpibfi-admin.php +110 -129
  11. includes/admin/class-jpibfi-advanced-options.php +0 -110
  12. includes/admin/class-jpibfi-import-export.php +0 -179
  13. includes/admin/class-jpibfi-lightbox-options.php +0 -121
  14. includes/admin/class-jpibfi-options.php +0 -26
  15. includes/admin/class-jpibfi-selection-options.php +0 -326
  16. includes/admin/class-jpibfi-visual-options.php +0 -429
  17. includes/admin/includes/class-jpibfi-ajax-result-builder.php +50 -0
  18. includes/admin/settings/class-jpibfi-import-export-settings.php +126 -0
  19. includes/admin/settings/class-jpibfi-selection-settings.php +133 -0
  20. includes/admin/settings/class-jpibfi-settings-base.php +121 -0
  21. includes/admin/settings/class-jpibfi-settings-validator.php +69 -0
  22. includes/admin/settings/class-jpibfi-visual-settings.php +167 -0
  23. includes/admin/settings/index.php +1 -0
  24. includes/admin/views/admin.php +0 -38
  25. includes/class-jpibfi-globals.php +0 -41
  26. includes/class-jpibfi.php +51 -0
  27. includes/consts/jpibfi-description-option.php +0 -11
  28. includes/includes/class-jpibfi-includes.php +21 -0
  29. includes/includes/class-jpibfi-option-converter.php +169 -0
  30. includes/{admin/views → includes}/index.php +0 -0
  31. includes/includes/options/class-jpibfi-options.php +24 -0
  32. includes/includes/options/class-jpibfi-selection-options.php +23 -0
  33. includes/includes/options/class-jpibfi-visual-options.php +48 -0
  34. includes/public/class-jpibfi-client-utilities.php +0 -110
  35. includes/public/class-jpibfi-client.php +191 -169
  36. jquery-pin-it-button-for-images.php +6 -67
  37. js/admin.js +0 -155
  38. js/jpibfi-ad.admin.js +10 -0
  39. js/jpibfi.admin.js +9 -0
  40. js/jpibfi.client.js +1 -0
  41. js/jpibfi.js +0 -1
  42. js/jquery.colorbox-min.js +0 -6
  43. js/upload-button-new.js +0 -38
  44. js/upload-button-old.js +0 -25
  45. languages/jquery-pin-it-button-for-images.pot +152 -257
  46. readme.txt +12 -3
  47. uninstall.php +2 -5
css/admin-ad.css ADDED
@@ -0,0 +1,26 @@
1
+ div.jpibfi-pro-notice {
2
+ overflow: hidden;
3
+ margin: 5px 0;
4
+ }
5
+
6
+ div.jpibfi-pro-notice p {
7
+ display:block;
8
+ float:left;
9
+ font-size: 1.3em;
10
+ font-weight: 600;
11
+ color: #23282d;
12
+ margin: 5px 0;
13
+ }
14
+
15
+ div.jpibfi-pro-notice a {
16
+ color: orange;
17
+ }
18
+
19
+ div.jpibfi-pro-notice span {
20
+ display:block;
21
+ float: right;
22
+ font-size: 1.6em;
23
+ padding: 2px 10px;
24
+ margin: 0.6em 0;
25
+ cursor: pointer;
26
+ }
css/admin.css CHANGED
@@ -1,46 +1,5 @@
1
- #custom_button_preview {
2
- text-indent: -9999px;
3
- display:block;
4
- }
5
-
6
- #show_button_error {
7
- background-color: white;
8
- border-left: 5px solid #dc3232;
9
- margin: 7px 0;
10
- padding: 5px 0 5px 12px;
11
- box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
12
- display: none;
13
- }
14
-
15
- .jpibfi-error-message {
16
- font-weight: bold;
17
- color: red;
18
- }
19
-
20
- .jpibfi-pro-notice {
21
- overflow: hidden;
22
- }
23
-
24
- .jpibfi-pro-notice p {
25
- display:block;
26
- float:left;
27
- font-size: 1.3em;
28
- font-weight: 600;
29
- color: #23282d;
30
- margin: 0.8em 0;
31
- }
32
-
33
- .jpibfi-pro-notice a {
34
- color: orange;
35
- }
36
-
37
- .jpibfi-pro-notice span {
38
- display:block;
39
- float: right;
40
- font-size: 1.6em;
41
- padding: 2px 10px;
42
- margin: 0.6em 0;
43
- cursor: pointer;
44
}
45
46
input[type="checkbox"] ~ label {
1
+ .frizzly-sortable li {
2
+ cursor: move;
3
}
4
5
input[type="checkbox"] ~ label {
css/colorbox.css DELETED
@@ -1,70 +0,0 @@
1
- /*
2
- Colorbox Core Style:
3
- The following CSS is consistent between example themes and should not be altered.
4
- */
5
- #colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden; -webkit-transform: translate3d(0,0,0);}
6
- #cboxWrapper {max-width:none;}
7
- #cboxOverlay{position:fixed; width:100%; height:100%;}
8
- #cboxMiddleLeft, #cboxBottomLeft{clear:left;}
9
- #cboxContent{position:relative;}
10
- #cboxLoadedContent{overflow:auto; -webkit-overflow-scrolling: touch;}
11
- #cboxTitle{margin:0;}
12
- #cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
13
- #cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
14
- .cboxPhoto{float:left; margin:auto; border:0; display:block; max-width:none; -ms-interpolation-mode:bicubic;}
15
- .cboxIframe{width:100%; height:100%; display:block; border:0; padding:0; margin:0;}
16
- #colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box; -moz-box-sizing:content-box; -webkit-box-sizing:content-box;}
17
-
18
- /*
19
- User Style:
20
- Change the following styles to modify the appearance of Colorbox. They are
21
- ordered & tabbed in a way that represents the nesting of the generated HTML.
22
- */
23
- #cboxOverlay{background:url(images/overlay.png) repeat 0 0;}
24
- #colorbox{outline:0;}
25
- #cboxTopLeft{width:21px; height:21px; background:url(images/controls.png) no-repeat -101px 0;}
26
- #cboxTopRight{width:21px; height:21px; background:url(images/controls.png) no-repeat -130px 0;}
27
- #cboxBottomLeft{width:21px; height:21px; background:url(images/controls.png) no-repeat -101px -29px;}
28
- #cboxBottomRight{width:21px; height:21px; background:url(images/controls.png) no-repeat -130px -29px;}
29
- #cboxMiddleLeft{width:21px; background:url(images/controls.png) left top repeat-y;}
30
- #cboxMiddleRight{width:21px; background:url(images/controls.png) right top repeat-y;}
31
- #cboxTopCenter{height:21px; background:url(images/border.png) 0 0 repeat-x;}
32
- #cboxBottomCenter{height:21px; background:url(images/border.png) 0 -29px repeat-x;}
33
- #cboxContent{background:#fff; overflow:hidden;}
34
- .cboxIframe{background:#fff;}
35
- #cboxError{padding:50px; border:1px solid #ccc;}
36
- #cboxLoadedContent{margin-bottom:28px;}
37
- #cboxTitle{position:absolute; bottom:4px; left:0; text-align:center; width:100%; color:#949494;}
38
- #cboxCurrent{position:absolute; bottom:4px; left:58px; color:#949494;}
39
- #cboxLoadingOverlay{background:url(images/loading_background.png) no-repeat center center;}
40
- #cboxLoadingGraphic{background:url(images/loading.gif) no-repeat center center;}
41
-
42
- /* these elements are buttons, and may need to have additional styles reset to avoid unwanted base styles */
43
- #cboxPrevious, #cboxNext, #cboxSlideshow, #cboxClose {border:0; padding:0; margin:0; overflow:visible; width:auto; background:none; }
44
-
45
- /* avoid outlines on :active (mouseclick), but preserve outlines on :focus (tabbed navigating) */
46
- #cboxPrevious:active, #cboxNext:active, #cboxSlideshow:active, #cboxClose:active {outline:0;}
47
-
48
- #cboxSlideshow{position:absolute; bottom:4px; right:30px; color:#0092ef;}
49
- #cboxPrevious{position:absolute; bottom:0; left:0; background:url(images/controls.png) no-repeat -75px 0; width:25px; height:25px; text-indent:-9999px;}
50
- #cboxPrevious:hover{background-position:-75px -25px;}
51
- #cboxNext{position:absolute; bottom:0; left:27px; background:url(images/controls.png) no-repeat -50px 0; width:25px; height:25px; text-indent:-9999px;}
52
- #cboxNext:hover{background-position:-50px -25px;}
53
- #cboxClose{position:absolute; bottom:0; right:0; background:url(images/controls.png) no-repeat -25px 0; width:25px; height:25px; text-indent:-9999px;}
54
- #cboxClose:hover{background-position:-25px -25px;}
55
-
56
- /*
57
- The following fixes a problem where IE7 and IE8 replace a PNG's alpha transparency with a black fill
58
- when an alpha filter (opacity change) is set on the element or ancestor element. This style is not applied to or needed in IE9.
59
- See: http://jacklmoore.com/notes/ie-transparency-problems/
60
- */
61
- .cboxIE #cboxTopLeft,
62
- .cboxIE #cboxTopCenter,
63
- .cboxIE #cboxTopRight,
64
- .cboxIE #cboxBottomLeft,
65
- .cboxIE #cboxBottomCenter,
66
- .cboxIE #cboxBottomRight,
67
- .cboxIE #cboxMiddleLeft,
68
- .cboxIE #cboxMiddleRight {
69
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);
70
- }
css/images/border.png DELETED
Binary file
css/images/controls.png DELETED
Binary file
css/images/loading.gif DELETED
Binary file
css/images/loading_background.png DELETED
Binary file
css/images/overlay.png DELETED
Binary file
includes/admin/class-jpibfi-admin-utilities.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- class JPIBFI_Admin_Utilities {
4
-
5
- /* Returns properly formatted description of a setting */
6
- public static function create_description( $desc ) {
7
- return '<p class="description">' . $desc . '</p>';
8
- }
9
-
10
- /* Returns error div if there are errors */
11
- public static function create_errors( $setting_name ) {
12
- $error = "";
13
-
14
- $errors_array = get_settings_errors( $setting_name );
15
-
16
- if ( count ( $errors_array ) > 0 ) {
17
- $error .= '<div class="jpibfi-error-message">';
18
- for( $i = 0; $i < count( $errors_array ); $i++ ){
19
- $error .= $errors_array[ $i ]['message'] . '</br>';
20
- }
21
- $error .= '</div>';
22
- }
23
-
24
- return $error;
25
- }
26
-
27
- /* Checks if value exists in array and if it is of certain value */
28
- public static function exists_and_equal_to( $array , $name, $expected_value = "1" ) {
29
- return isset( $array[ $name ] ) && $array[ $name ] == $expected_value;
30
- }
31
-
32
- /* Checks if given string contains class names separated by semicolons or is empty */
33
- public static function contains_css_class_names_or_empty( $str ) {
34
- if ( 0 == strlen( $str ) )
35
- return true;
36
-
37
- $names = explode( ';', $str );
38
- $only_class_names = true;
39
-
40
- for( $i = 0; $i < count( $names ) && $only_class_names; $i++ )
41
- $only_class_names = self::is_string_css_class_name( $names [ $i ] );
42
-
43
- return $only_class_names;
44
- }
45
-
46
- public static function is_string_css_class_name( $class_name ) {
47
- return 1 == preg_match( "/^-?[_a-zA-Z]+[_a-zA-Z0-9-]*#x2F;", $class_name );
48
- }
49
-
50
- }
includes/admin/class-jpibfi-admin.php CHANGED
@@ -2,28 +2,56 @@
2
3
class JPIBFI_Admin {
4
5
- protected static $instance = null;
6
7
private $admin_screen_hook = '';
8
9
- private function __construct() {
10
add_action( 'admin_menu', array( $this, 'print_admin_page_action') );
11
- add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
12
- add_action( 'save_post', array( $this, 'save_meta_data' ) );
13
- add_action( 'admin_enqueue_scripts', array($this, 'add_admin_site_scripts') );
14
- add_action( 'admin_notices', array( $this, 'show_admin_notice') );
15
add_filter( 'plugin_row_meta', array($this, 'plugin_meta_links'), 10, 2 );
16
add_action( 'wp_ajax_jpibfi_remove_pro_ad', array($this, 'remove_pro_ad') );
17
}
18
19
- public static function get_instance() {
20
- // If the single instance hasn't been set, set it now.
21
- if ( null == self::$instance ) {
22
- self::$instance = new self;
23
- }
24
25
- return self::$instance;
26
- }
27
28
public function print_admin_page_action() {
29
@@ -38,125 +66,88 @@ class JPIBFI_Admin {
38
);
39
}
40
41
- /* Adds admin scripts */
42
- public function add_admin_site_scripts($hook) {
43
-
44
- $hooks = array();
45
- $hooks[] = $this->admin_screen_hook;
46
- $hooks[] = 'plugins.php';
47
-
48
- if (!in_array($hook, $hooks))
49
- return;
50
-
51
- $is_plugins_php = $hook == 'plugins.php';
52
53
- wp_register_style( 'jquery-pin-it-button-admin-style', JPIBFI_Globals::get_plugin_url() . 'css/admin.css', array(), JPIBFI_Globals::get_file_version(), 'all' );
54
- wp_enqueue_style( 'jquery-pin-it-button-admin-style' );
55
56
- $settings = array();
57
$settings['version'] = 'lite';
58
- wp_enqueue_script( 'jquery-pin-it-button-admin-script', JPIBFI_Globals::get_plugin_url() . 'js/admin.js', array( 'jquery' ), JPIBFI_Globals::get_file_version(), false );
59
- wp_localize_script('jquery-pin-it-button-admin-script', 'jpibfiAdminSettings', $settings);
60
-
61
- if ($is_plugins_php)
62
- return;
63
64
if ( function_exists( "wp_enqueue_media") ) {
65
wp_enqueue_media();
66
- wp_enqueue_script( 'jpibfi-upload-new', JPIBFI_Globals::get_plugin_url() . 'js/upload-button-new.js', array(), JPIBFI_Globals::get_file_version(), false );
67
- } else {
68
- wp_enqueue_script( 'jpibfi-upload-old', JPIBFI_Globals::get_plugin_url() . 'js/upload-button-old.js', array('thickbox', 'media-upload' ), JPIBFI_Globals::get_file_version(), false );
69
}
70
- }
71
72
- /* Prints admin page */
73
- public function print_admin_page() {
74
75
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
76
- JPIBFI_Import_Export::get_instance()->handle_import();
77
}
78
79
- //dictionary of tab names associated with settings to render names
80
- $settings_tabs = array(
81
- 'selection_options' => array(
82
- 'settings_name' => 'jpibfi_selection_options',
83
- 'tab_label' => __( 'Selection', 'jquery-pin-it-button-for-images' ),
84
- ),
85
- 'visual_options' => array(
86
- 'settings_name' => 'jpibfi_visual_options',
87
- 'tab_label' => __( 'Visual', 'jquery-pin-it-button-for-images' ),
88
- ),
89
- 'advanced_options' => array(
90
- 'settings_name' => 'jpibfi_advanced_options',
91
- 'tab_label' => __('Advanced', 'jquery-pin-it-button-for-images' ),
92
- ),
93
- 'import_export' => array(
94
- 'settings_name' => 'jpibfi_import_export_options',
95
- 'tab_label' => __('Import/Export', 'jquery-pin-it-button-for-images')
96
- ),
97
- 'lightbox' => array(
98
- 'settings_name' => 'jpibfi_lightbox_options',
99
- 'tab_label' => __('Lightbox', 'jquery-pin-it-button-for-images')
100
- )
101
- );
102
-
103
- $settings_tabs = apply_filters( 'jpibfi_settings_tabs', $settings_tabs);
104
-
105
- include_once( 'views/admin.php' );
106
- //cumbersome, but needed for error management to work properly in WP 3.3
107
- delete_option( JPIBFI_Selection_Options::get_instance()->get_option_name() . '_errors' );
108
- delete_option( JPIBFI_Visual_Options::get_instance()->get_option_name() . '_errors' );
109
}
110
111
- /* Meta box for each post and page */
112
- public function add_meta_box() {
113
- /* TODO check if has permissions*/
114
- $post_types = array("post", "page");
115
- foreach($post_types as $pt){
116
- add_meta_box(
117
- 'jpibfi_settings_id',
118
- 'jQuery Pin It Button for Images - ' . __( 'Settings', 'jquery-pin-it-button-for-images' ),
119
- array( $this, 'print_meta_box' ),
120
- $pt,
121
- 'side',
122
- 'default'
123
- );
124
}
125
- }
126
-
127
- /* Displays the meta box */
128
- public function print_meta_box( $post, $metabox ) {
129
-
130
- wp_nonce_field( plugin_basename( __FILE__ ), 'jpibfi_nonce' );
131
-
132
- $post_meta = get_post_meta( $post->ID, 'jpibfi_meta', true );
133
- $checked = isset( $post_meta ) && isset( $post_meta['jpibfi_disable_for_post'] ) && $post_meta['jpibfi_disable_for_post'] == '1';
134
-
135
- echo '<input type="checkbox" id="jpibfi_disable_for_post" name="jpibfi_disable_for_post" value="1"' . checked( $checked, true, false ) . '>';
136
- echo '<label for="jpibfi_disable_for_post">' . __( 'Disable "Pin it" button for this post (works only on single pages/posts)', 'jquery-pin-it-button-for-images' ) . '</label><br />';
137
- }
138
-
139
- public function save_meta_data( $post_id ) {
140
-
141
- //check user's permissions and autosave
142
- if ( ! current_user_can( 'edit_post', $post_id ) || (defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE) )
143
- return;
144
-
145
- // security check = updating possible only using post edit form
146
- if ( !isset( $_POST['jpibfi_nonce'] ) || ! wp_verify_nonce( $_POST['jpibfi_nonce'], plugin_basename( __FILE__ ) ) )
147
- return;
148
-
149
- $post_meta = array( 'jpibfi_disable_for_post' => '0' );
150
- // now store data in custom fields based on checkboxes selected
151
- $post_meta['jpibfi_disable_for_post'] = isset( $_POST['jpibfi_disable_for_post'] ) && $_POST['jpibfi_disable_for_post'] == '1' ? '1' : '0';
152
153
- if ( $post_meta['jpibfi_disable_for_post'] == '1' )
154
- update_post_meta( $post_id, 'jpibfi_meta', $post_meta );
155
- else
156
- delete_post_meta( $post_id, 'jpibfi_meta' );
157
- }
158
159
- function show_admin_notice() {
160
global $hook_suffix;
161
$hooks = array();
162
$hooks[] = $this->admin_screen_hook;
@@ -176,14 +167,9 @@ class JPIBFI_Admin {
176
}
177
178
function plugin_meta_links( $links, $file ) {
179
- $basefile = JPIBFI_Globals::get_plugin_file();
180
- $plugin = plugin_basename($basefile);
181
- // create link
182
if ( $file == $plugin ) {
183
- return array_merge(
184
- $links,
185
- array( '<a href="http://mrsztuczkens.me/jpibfi-pro/">jQuery Pin It Button for Images Pro</a>' )
186
- );
187
}
188
return $links;
189
}
@@ -192,9 +178,4 @@ class JPIBFI_Admin {
192
delete_option('jpibfi_pro_ad');
193
wp_die();
194
}
195
-
196
-
197
-
198
- }
199
-
200
- add_action( 'plugins_loaded', array( 'JPIBFI_Admin', 'get_instance' ) );
2
3
class JPIBFI_Admin {
4
5
+ private $file;
6
+ private $version;
7
8
private $admin_screen_hook = '';
9
+ private $import_export_settings;
10
+ private $selection_settings;
11
+ private $visual_settings;
12
+
13
+ function __construct($file, $version) {
14
+ $this->file = $file;
15
+ $this->version = $version;
16
+
17
+ $this->load_dependencies();
18
+ $this->init_settings();
19
20
add_action( 'admin_menu', array( $this, 'print_admin_page_action') );
21
+ add_action( 'admin_enqueue_scripts', array($this, 'add_admin_scripts') );
22
+
23
+ $jpibfi_plugin = plugin_basename( $this->file );
24
+ add_filter( "plugin_action_links_$jpibfi_plugin", array( $this, 'add_settings_link' ) );
25
+ add_action( 'admin_notices', array( $this, 'show_lightbox_ad' ), 11 );
26
+ add_action( 'admin_notices', array( $this, 'show_pro_ad') );
27
add_filter( 'plugin_row_meta', array($this, 'plugin_meta_links'), 10, 2 );
28
add_action( 'wp_ajax_jpibfi_remove_pro_ad', array($this, 'remove_pro_ad') );
29
}
30
31
+ function add_settings_link( $links ) {
32
+ $settings_link = '<a href="options-general.php?page=jpibfi_settings">' . __( 'Settings', 'jquery-pin-it-button-for-images' ) . '</a>';
33
+ array_unshift( $links, $settings_link );
34
+ return $links;
35
+ }
36
37
+ private function load_dependencies(){
38
+ $deps = array(
39
+ 'includes/class-jpibfi-ajax-result-builder.php',
40
+ 'settings/class-jpibfi-settings-base.php',
41
+ 'settings/class-jpibfi-settings-validator.php',
42
+ 'settings/class-jpibfi-import-export-settings.php',
43
+ 'settings/class-jpibfi-selection-settings.php',
44
+ 'settings/class-jpibfi-visual-settings.php'
45
+ );
46
+ foreach ($deps as $dep)
47
+ require_once $dep;
48
+ }
49
+
50
+ private function init_settings(){
51
+ $this->import_export_settings = new JPIBFI_Import_Export_Settings();
52
+ $this->selection_settings = new JPIBFI_Selection_Settings();
53
+ $this->visual_settings = new JPIBFI_Visual_Settings();
54
+ }
55
56
public function print_admin_page_action() {
57
66
);
67
}
68
69
+ public function add_admin_scripts($hook) {
70
+ if ($this->admin_screen_hook === $hook) {
71
+ $this->add_settings_scripts();
72
+ }
73
74
+ if ('plugins.php' === $hook) {
75
+ $this->add_remove_ad_scripts();
76
+ }
77
+ }
78
79
+ private function add_settings_scripts() {
80
+ $plugin_dir_url = plugin_dir_url($this->file);
81
+
82
+ wp_enqueue_style( 'jquery-pin-it-button-admin-style', $plugin_dir_url . 'css/admin.css', array(), $this->version, 'all' );
83
+ wp_enqueue_style( 'jpibfi-ad', $plugin_dir_url . 'css/admin-ad.css', array(), $this->version, 'all' );
84
+
85
+ $slug = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'select';
86
+ $settings = array (
87
+ 'ajax' => apply_filters('jpibfi_settings_ajax', array (
88
+ 'url' => admin_url( 'admin-ajax.php' ),
89
+ 'tab' => $slug,
90
+ )),
91
+ 'tabs' => $this->get_sorted_tabs(),
92
+ 'currentTab' => $slug,
93
+ 'page' => 'jpibfi_settings',
94
+ 'settings' => apply_filters( 'jpibfi_settings_configuration_' . $slug, array()),
95
+ 'i18n' => array (
96
+ 'editor' => apply_filters( 'jpibfi_settings_i18n_' . $slug, array('submit' => __('Save Changes', 'jquery-pin-it-button-for-images'))),
97
+ 'status' => array (
98
+ 'pending' => __('Saving changes ...', 'jquery-pin-it-button-for-images'),
99
+ ),
100
+ ),
101
+ );
102
$settings['version'] = 'lite';
103
+ wp_enqueue_script( 'jpibfi', $plugin_dir_url . 'js/jpibfi.admin.js', array( 'jquery' ), $this->version, false );
104
+ wp_localize_script('jpibfi', 'jpibfi_settings', $settings);
105
106
if ( function_exists( "wp_enqueue_media") ) {
107
wp_enqueue_media();
108
}
109
+ }
110
111
+ private function get_sorted_tabs(){
112
+ $settings_tabs = apply_filters('jpibfi_settings_tabs', array());
113
114
+ /* order tabs by priority */
115
+ $priority = array();
116
+ foreach ($settings_tabs as $key => $tab){
117
+ $priority[$key] = $tab['priority'];
118
}
119
+ array_multisort($priority, SORT_ASC, $settings_tabs);
120
+ return $settings_tabs;
121
+ }
122
123
+ public function print_admin_page() {
124
+ ?>
125
+ <div ng-app="app" class="wrap">
126
+ <h2><?php _e( 'jQuery Pin It Button For Images Options', 'jquery-pin-it-button-for-images' ); ?></h2>
127
+ <div id="icon-plugins" class="icon32"></div>
128
+ <app settings-name="jpibfi_settings"></app>
129
+ </div>
130
+ <?php
131
}
132
133
+ public function show_lightbox_ad() {
134
+ global $hook_suffix;
135
+ if ( $hook_suffix === $this->admin_screen_hook ) {
136
+ ?>
137
+ <div class="updated jpibfi-pro-notice">
138
+ <p><?php echo sprintf(__('Lightbox feature has been transferred to another plugin. Click <a target="_blank" href="%s">here</a> to learn more.', 'jquery-pin-it-button-for-images'), 'http://bit.ly/2cXnS2D'); ?></p>
139
+ </div>
140
+ <?php
141
}
142
+ }
143
144
+ private function add_remove_ad_scripts() {
145
+ $plugin_dir_url = plugin_dir_url($this->file);
146
+ wp_enqueue_style( 'jpibfi-ad', $plugin_dir_url . 'css/admin-ad.css', array(), $this->version, 'all' );
147
+ wp_enqueue_script( 'jpibfi-ad', $plugin_dir_url . 'js/jpibfi-ad.admin.js', array( 'jquery' ), $this->version, false );
148
+ }
149
150
+ function show_pro_ad() {
151
global $hook_suffix;
152
$hooks = array();
153
$hooks[] = $this->admin_screen_hook;
167
}
168
169
function plugin_meta_links( $links, $file ) {
170
+ $plugin = plugin_basename($this->file);
171
if ( $file == $plugin ) {
172
+ return array_merge($links, array( '<a href="http://mrsztuczkens.me/jpibfi-pro/">jQuery Pin It Button for Images Pro</a>' ));
173
}
174
return $links;
175
}
178
delete_option('jpibfi_pro_ad');
179
wp_die();
180
}
181
+ }
includes/admin/class-jpibfi-advanced-options.php DELETED
@@ -1,110 +0,0 @@
1
- <?php
2
-
3
- class JPIBFI_Advanced_Options extends JPIBFI_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
- function get_default_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
- static function get_option_name(){
32
- return 'jpibfi_advanced_options';
33
- }
34
-
35
- /* Defines selection options section and adds all required fields */
36
- public function initialize_advanced_options() {
37
-
38
- // First, we register a section.
39
- add_settings_section(
40
- 'advanced_options_section',
41
- __( 'Advanced Settings', 'jquery-pin-it-button-for-images' ),
42
- array( $this, 'advanced_options_callback' ),
43
- 'jpibfi_advanced_options'
44
- );
45
-
46
- //lThen add all necessary fields to the section
47
- add_settings_field(
48
- 'debug',
49
- __( 'Debug', 'jquery-pin-it-button-for-images' ),
50
- array( $this, 'debug_callback' ),
51
- 'jpibfi_advanced_options',
52
- 'advanced_options_section',
53
- array(
54
- __( 'Use debug mode only if you are experiencing some issues with the plugin and you are reporting them to the developer of the plugin', 'jquery-pin-it-button-for-images' ),
55
- )
56
- );
57
-
58
- add_settings_field(
59
- 'container_selector',
60
- __( 'Container selector', 'jquery-pin-it-button-for-images' ),
61
- array( $this, 'container_selector_callback' ),
62
- 'jpibfi_advanced_options',
63
- 'advanced_options_section',
64
- array(
65
- __( '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.', 'jquery-pin-it-button-for-images' ),
66
- )
67
- );
68
-
69
- register_setting(
70
- 'jpibfi_advanced_options',
71
- 'jpibfi_advanced_options' //no sanitization needed for now
72
- );
73
- }
74
-
75
- public function advanced_options_callback() {
76
- echo '<p>' . __('Advanced settings', 'jquery-pin-it-button-for-images') . '</p>';
77
- }
78
-
79
- public function debug_callback( $args ){
80
- $options = $this->get_advanced_options();
81
- $debug = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'debug', '1' );
82
-
83
- echo '<input type="checkbox" id="debug" name="jpibfi_advanced_options[debug]" value="1" ' . checked( "1", $debug, false ) . '>';
84
- echo '<label for="debug">' . __( 'Enable debug mode', 'jquery-pin-it-button-for-images' ) . '</label>';
85
-
86
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
87
- }
88
-
89
- public function container_selector_callback( $args ) {
90
- $options = $this->get_advanced_options();
91
- $container_selector = esc_attr( $options[ 'container_selector' ] );
92
-
93
- echo '<input type="text" id="image_selector" name="jpibfi_advanced_options[container_selector]" value="' . $container_selector . '"/>';
94
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
95
- }
96
-
97
- private function get_advanced_options() {
98
- $jpibfi_adanced_options = JPIBFI_Advanced_Options::get_instance()->get_options();
99
-
100
- if ( null == $this->admin_advanced_options ) {
101
- //cumbersome, but works in WP 3.3
102
- $options = get_option( $this->get_option_name() . '_errors' );
103
- $this->admin_advanced_options = false == $options ? $jpibfi_adanced_options : $options;
104
- }
105
-
106
- return $this->admin_advanced_options;
107
- }
108
- }
109
-
110
- add_action( 'plugins_loaded', array( 'JPIBFI_Advanced_Options', 'get_instance' ) );
includes/admin/class-jpibfi-import-export.php DELETED
@@ -1,179 +0,0 @@
1
- <?php
2
-
3
- class JPIBFI_Import_Export {
4
-
5
- protected static $instance = null;
6
-
7
- public static function get_instance() {
8
- // If the single instance hasn't been set, set it now.
9
- if ( null == self::$instance ) {
10
- self::$instance = new self;
11
- }
12
- return self::$instance;
13
- }
14
-
15
- private function __construct(){
16
- add_filter( 'export_args', array( $this, 'export_args' ) );
17
- add_action( 'export_wp', array( $this, 'export_wp' ) );
18
- add_action( 'admin_init', array( $this, 'initialize' ) );
19
- }
20
-
21
- private function error_message( $message, $details = '' ) {
22
- echo '<div class="error notice is-dismissible"><p><strong>' . $message . '</strong>';
23
- if ( ! empty( $details ) ) {
24
- echo '<br />' . $details;
25
- }
26
- echo '</p></div>';
27
- return false;
28
- }
29
-
30
- private function success_message(){
31
- echo '<div class="updated notice is-dismissible"><p><strong>';
32
- _e('Import successful', 'jquery_pin_it_button_for_images');
33
- echo '</strong></p></div>';
34
- }
35
-
36
- /**
37
- * @param array $args The export args being filtered.
38
- * @return array The (possibly modified) export args.
39
- */
40
- public function export_args( $args ) {
41
- if ( ! empty( $_GET['content'] ) && 'jpibfi' == $_GET['content'] ) {
42
- return array( 'jpibfi' => true );
43
- }
44
- return $args;
45
- }
46
-
47
-
48
- /**
49
- * Export options as a JSON file if that's what the user wants to do.
50
- *
51
- * @param array $args The export arguments.
52
- * @return void
53
- */
54
- public function export_wp( $args ) {
55
- if (empty($args['jpibfi']))
56
- return;
57
-
58
- $filename = 'jpibfi_settings_' . date( 'Y-m-d' ) . '.json';
59
-
60
- header( 'Content-Description: File Transfer' );
61
- header( 'Content-Disposition: attachment; filename=' . $filename );
62
- header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ), true );
63
-
64
- $option_names = array();
65
- $option_names[] = JPIBFI_Selection_Options::get_option_name();
66
- $option_names[] = JPIBFI_Visual_Options::get_option_name();
67
- $option_names[] = JPIBFI_Advanced_Options::get_option_name();
68
-
69
- $export_options = array();
70
-
71
- foreach ( $option_names as $option_name ) {
72
-
73
- $option_value = get_option( $option_name );
74
- if ( $option_value !== false ) {
75
- $export_options[ $option_name ] = maybe_serialize( $option_value );
76
- }
77
- }
78
- $JSON_PRETTY_PRINT = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
79
- echo json_encode( array( 'options' => $export_options ), $JSON_PRETTY_PRINT );
80
- exit;
81
- }
82
-
83
- public function handle_import(){
84
- check_admin_referer( 'import-upload' );
85
- $file = wp_import_handle_upload();
86
-
87
- if ( isset( $file['error'] ) ) {
88
- return $this->error_message(
89
- __( 'Sorry, there has been an error.', 'jquery_pin_it_button_for_images' ),
90
- esc_html( $file['error'] )
91
- );
92
- }
93
-
94
- if ( ! isset( $file['file'], $file['id'] ) ) {
95
- return $this->error_message(
96
- __( 'Sorry, there has been an error.', 'jquery-pin-it-button-for-images' ),
97
- __( 'The file did not upload properly. Please try again.', 'jquery-pin-it-button-for-images' )
98
- );
99
- }
100
-
101
- if ( ! file_exists( $file['file'] ) ) {
102
- wp_import_cleanup( $file['id'] );
103
- return $this->error_message(
104
- __( 'Sorry, there has been an error.', 'jquery-pin-it-button-for-images' ),
105
- sprintf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'jquery-pin-it-button-for-images' ), esc_html( $file['file'] ) )
106
- );
107
- }
108
-
109
- if ( ! is_file( $file['file'] ) ) {
110
- wp_import_cleanup( $file['id'] );
111
- return $this->error_message(
112
- __( 'Sorry, there has been an error.', 'jquery-pin-it-button-for-images' ),
113
- __( 'The path is not a file, please try again.', 'jquery-pin-it-button-for-images' )
114
- );
115
- }
116
-
117
- $file_contents = file_get_contents( $file['file'] );
118
- $data = json_decode( $file_contents, true );
119
- wp_import_cleanup( $file['id']);
120
-
121
- $options_to_import = $data['options'];
122
- foreach ( (array)$options_to_import as $option_name => $option_value ) {
123
-
124
- $val= maybe_unserialize( $option_value );
125
- update_option( $option_name, $val );
126
- //var_dump($option_name, get_option($option_name), $val);
127
- }
128
- $this->success_message();
129
- }
130
-
131
- public function initialize(){
132
-
133
- add_settings_section(
134
- 'import_export_section',
135
- __( 'Import/Export Settings', 'jquery-pin-it-button-for-images' ),
136
- '__return_false',
137
- 'jpibfi_import_export_options'
138
- );
139
-
140
- add_settings_field(
141
- 'Export',
142
- __( 'Export', 'jquery-pin-it-button-for-images' ),
143
- array( $this, 'export_callback' ),
144
- 'jpibfi_import_export_options',
145
- 'import_export_section',
146
- array()
147
- );
148
-
149
- add_settings_field(
150
- 'Import',
151
- __( 'Import', 'jquery-pin-it-button-for-images' ),
152
- array( $this, 'import_callback' ),
153
- 'jpibfi_import_export_options',
154
- 'import_export_section',
155
- array()
156
- );
157
-
158
- register_setting(
159
- 'jpibfi_import_export_options',
160
- 'jpibfi_import_export_options'
161
- );
162
- }
163
-
164
- public function export_callback( $args ){
165
-
166
- echo '<a class="button button-primary" href="' . admin_url('export.php?download=true&content=jpibfi'). '">'
167
- .__('Download Export File', 'jquery-pin-it-button-for-images')
168
- .'</a>';
169
-
170
- }
171
-
172
- public function import_callback(){
173
- _e( 'Choose a JSON (.json) file to upload, then click Upload file and import.', 'jquery-pin-it-button-for-images' );
174
- wp_import_upload_form( 'options-general.php?page=jpibfi_settings&tab=import_export');
175
- }
176
- }
177
-
178
-
179
- add_action( 'plugins_loaded', array( 'JPIBFI_Import_Export', 'get_instance' ) );
includes/admin/class-jpibfi-lightbox-options.php DELETED
@@ -1,121 +0,0 @@
1
- <?php
2
-
3
- class JPIBFI_Lightbox_Options extends JPIBFI_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, 'init' ) );
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
- function get_default_options(){
23
- $defaults = array(
24
- 'enabled' => '0',
25
- 'description_option' => '1'
26
- );
27
-
28
- return apply_filters( 'jpibfi_default_lightbox_options', $defaults );
29
- }
30
-
31
- static function get_option_name(){
32
- return 'jpibfi_lightbox_options';
33
- }
34
-
35
- /* Defines selection options section and adds all required fields */
36
- public function init() {
37
-
38
- // First, we register a section.
39
- add_settings_section(
40
- 'lightbox_options_section',
41
- __( 'Lightbox Settings', 'jquery-pin-it-button-for-images' ),
42
- array( $this, 'section_name_callback' ),
43
- 'jpibfi_lightbox_options'
44
- );
45
-
46
- add_settings_field(
47
- 'enabled',
48
- __( 'Enabled', 'jquery-pin-it-button-for-images' ),
49
- array( $this, 'enabled_callback' ),
50
- 'jpibfi_lightbox_options',
51
- 'lightbox_options_section',
52
- array(
53
- __( 'Activate lightbox in posts', 'jquery-pin-it-button-for-images' )
54
- )
55
- );
56
-
57
- add_settings_field(
58
- 'description_option',
59
- __( 'Description source', 'jquery-pin-it-button-for-images' ),
60
- array( $this, 'description_option_callback' ),
61
- 'jpibfi_lightbox_options',
62
- 'lightbox_options_section',
63
- array(
64
- __( 'From where the lightbox description should be taken. Please note that "Image description" works properly only for images that were added to your Media Library.', 'jquery-pin-it-button-for-images' ),
65
- )
66
- );
67
-
68
- add_settings_field(
69
- 'footer',
70
- '',
71
- array( $this, 'footer_callback' ),
72
- 'jpibfi_lightbox_options',
73
- 'lightbox_options_section',
74
- array(
75
- __( 'Lightbox module uses Colorbox. Visit <a href="http://www.jacklmoore.com/colorbox/" target="_blank">this page</a> to learn more about Colorbox.', 'jquery-pin-it-button-for-images' ),
76
- )
77
- );
78
-
79
- register_setting(
80
- 'jpibfi_lightbox_options',
81
- 'jpibfi_lightbox_options'
82
- );
83
- }
84
-
85
- public function section_name_callback() {
86
- echo '<p>' . __('Lightbox settings', 'jquery-pin-it-button-for-images') . '</p>';
87
- }
88
-
89
- public function enabled_callback( $args ){
90
- $options = $this->get_options();
91
- $enabled = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'enabled', '1' );
92
-
93
- echo '<input type="checkbox" id="debug" name="jpibfi_lightbox_options[enabled]" value="1" ' . checked( "1", $enabled, false ) . '>';
94
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
95
- }
96
-
97
- public function description_option_callback( $args ) {
98
- $options = $this->get_options();
99
-
100
- $description_option = $options[ 'description_option' ];
101
- ?>
102
-
103
- <select id="description_option" name="jpibfi_lightbox_options[description_option]">
104
- <option value="1" <?php selected ( "1", $description_option ); ?>><?php _e( 'Page title', 'jquery-pin-it-button-for-images' ); ?></option>
105
- <option value="2" <?php selected ( "2", $description_option ); ?>><?php _e( 'Page description (excerpt)', 'jquery-pin-it-button-for-images' ); ?></option>
106
- <option value="3" <?php selected ( "3", $description_option ); ?>><?php _e( 'Image title or (if title not available) alt attribute', 'jquery-pin-it-button-for-images' ); ?></option>
107
- <option value="4" <?php selected ( "4", $description_option ); ?>><?php _e( 'Site title (Settings->General)', 'jquery-pin-it-button-for-images' ); ?></option>
108
- <option value="5" <?php selected ( "5", $description_option ); ?>><?php _e( 'Image description', 'jquery-pin-it-button-for-images' ); ?></option>
109
- <option value="6" <?php selected ( "6", $description_option ); ?>><?php _e( 'Image alt attribute', 'jquery-pin-it-button-for-images' ); ?></option>
110
- </select>
111
-
112
- <?php
113
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
114
- }
115
-
116
- public function footer_callback($args){
117
- echo '<span style="font-size: 18px">' . $args[0] . '</span>';
118
- }
119
- }
120
-
121
- add_action( 'plugins_loaded', array( 'JPIBFI_Lightbox_Options', 'get_instance' ) );
includes/admin/class-jpibfi-options.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- if (!class_exists('JPIBFI_Options')){
4
-
5
- abstract class JPIBFI_Options {
6
-
7
- protected static function get_option_name(){
8
- return '';
9
- }
10
-
11
- protected abstract function get_default_options();
12
-
13
- private function get_db_options(){
14
- $db_options = get_option($this->get_option_name());
15
- return $db_options;
16
- }
17
-
18
- public function get_options(){
19
- $db_options = $this->get_db_options();
20
- $db_options = $db_options != false ? $db_options : array();
21
- $defaults = $this->get_default_options();
22
- $merged = array_merge($defaults, $db_options);
23
- return $merged;
24
- }
25
- }
26
- }
includes/admin/class-jpibfi-selection-options.php DELETED
@@ -1,326 +0,0 @@
1
- <?php
2
-
3
- class JPIBFI_Selection_Options extends JPIBFI_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
- function get_default_options(){
23
- $defaults = array(
24
- 'image_selector' => '.jpibfi_container img',
25
- 'disabled_classes' => 'nopin;wp-smiley',
26
- 'enabled_classes' => '',
27
- 'min_image_height' => '0',
28
- 'min_image_width' => '0',
29
- 'show_on_home' => '1',
30
- 'show_on_single' => '1',
31
- 'show_on_page' => '1',
32
- 'show_on_category' => '1',
33
- 'show_on_blog' => '1'
34
- );
35
-
36
- return apply_filters('jpibfi_default_selection_options', $defaults);
37
- }
38
-
39
- static function get_option_name(){
40
- return 'jpibfi_selection_options';
41
- }
42
-
43
- private function get_checkbox_settings(){
44
- return array(
45
- 'show_on_home',
46
- 'show_on_single',
47
- 'show_on_page',
48
- 'show_on_category',
49
- 'show_on_blog'
50
- );
51
- }
52
-
53
- /*
54
- * Defines selection options section and adds all required fields
55
- */
56
- public function initialize_selection_options() {
57
-
58
- // First, we register a section.
59
- add_settings_section(
60
- 'selection_options_section', // ID used to identify this section and with which to register options
61
- __( 'Selection', 'jquery-pin-it-button-for-images' ), // Title to be displayed on the administration page
62
- array( $this, 'selection_options_callback' ), // Callback used to render the description of the section
63
- 'jpibfi_selection_options' // Page on which to add this section of options
64
- );
65
-
66
- //lThen add all necessary fields to the section
67
- add_settings_field(
68
- 'image_selector', // ID used to identify the field throughout the plugin
69
- __( 'Image selector', 'jquery-pin-it-button-for-images' ), // The label to the left of the option interface element
70
- array( $this, 'image_selector_callback'), // The name of the function responsible for rendering the option interface
71
- 'jpibfi_selection_options', // The page on which this option will be displayed
72
- 'selection_options_section', // The name of the section to which this field belongs
73
- array( // The array of arguments to pass to the callback. In this case, just a description.
74
- 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.', 'jquery-pin-it-button-for-images' ),
75
- '<a href="#" class="jpibfi_selector_option">.jpibfi_container img</a>',
76
- '<a href="#" class="jpibfi_selector_option">img</a>',
77
- '<a href="http://api.jquery.com/category/selectors/" target="_blank">',
78
- '</a>'
79
- )
80
- )
81
- );
82
-
83
- add_settings_field(
84
- 'disabled_classes',
85
- __( 'Disabled classes', 'jquery-pin-it-button-for-images' ),
86
- array( $this, 'disabled_classes_callback' ),
87
- 'jpibfi_selection_options',
88
- 'selection_options_section',
89
- array(
90
- __( 'Pictures with these CSS classes won\'t show the "Pin it" button. Please separate multiple classes with semicolons. Spaces are not accepted.', 'jquery-pin-it-button-for-images' ),
91
- )
92
- );
93
-
94
- add_settings_field(
95
- 'enabled_classes',
96
- __( 'Enabled classes', 'jquery-pin-it-button-for-images' ),
97
- array( $this, 'enabled_classes_callback' ),
98
- 'jpibfi_selection_options',
99
- 'selection_options_section',
100
- array(
101
- __( '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.', 'jquery-pin-it-button-for-images' ),
102
- )
103
- );
104
-
105
- add_settings_field(
106
- 'show_on_field',
107
- __( 'On which pages the "Pin it" button should be shown', 'jquery-pin-it-button-for-images' ),
108
- array( $this, 'show_on_field_callback' ),
109
- 'jpibfi_selection_options',
110
- 'selection_options_section',
111
- array(
112
- __( 'Check on which pages you want the Pinterest button to show up.', 'jquery-pin-it-button-for-images' ),
113
- )
114
- );
115
-
116
- add_settings_field(
117
- 'min_image',
118
- __( 'Minimum resolution that should trigger the "Pin it" button to show up', 'jquery-pin-it-button-for-images' ),
119
- array( $this, 'min_image_callback' ),
120
- 'jpibfi_selection_options',
121
- 'selection_options_section',
122
- array(
123
- __( '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.', 'jquery-pin-it-button-for-images' ),
124
- )
125
- );
126
-
127
- register_setting(
128
- 'jpibfi_selection_options',
129
- 'jpibfi_selection_options',
130
- array( $this, 'sanitize_selection_options' )
131
- );
132
- }
133
-
134
- public function selection_options_callback() {
135
- echo '<p>' . __('Which images can be pinned', 'jquery-pin-it-button-for-images') . '</p>';
136
- }
137
-
138
- public function image_selector_callback( $args ) {
139
-
140
- $options = $this->get_selection_options();
141
-
142
- $selector = esc_attr( $options['image_selector'] );
143
-
144
- echo '<input type="text" id="image_selector" name="jpibfi_selection_options[image_selector]" value="' . $selector . '"/>';
145
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
146
- }
147
-
148
- public function disabled_classes_callback( $args ){
149
-
150
- $options = $this->get_selection_options();
151
- $value = esc_attr( $options[ 'disabled_classes' ] );
152
- ?>
153
- <div id="jpibfi-disabled-classes">
154
- <input type="hidden" class="jpibfi-value" name="jpibfi_selection_options[disabled_classes]" value="<?php echo $value; ?>">
155
- <span class="jpibfi-empty"><?php echo JPIBFI_Admin_Utilities::create_description( __( 'No classes added.', 'jquery-pin-it-button-for-images' ) ); ?></span>
156
- <div class="jpibfi-classes-list tagchecklist"></div>
157
- <div>
158
- <label>
159
- <?php _e( 'Class name', 'jquery-pin-it-button-for-images' ); ?>
160
- <input class="jpibfi-class-name" type="text">
161
- </label>
162
- <button type="button" class="jpibfi-class-button button"><?php _e( 'Add', 'jquery-pin-it-button-for-images' ); ?></button>
163
- </div>
164
- </div>
165
-
166
- <?php
167
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
168
- echo JPIBFI_Admin_Utilities::create_errors( 'disabled_classes' );
169
- }
170
-
171
- public function enabled_classes_callback( $args ){
172
-
173
- $options = $this->get_selection_options();
174
- $value = esc_attr( $options[ 'enabled_classes' ] );
175
-
176
- ?>
177
- <div id="jpibfi-enabled-classes">
178
- <input type="hidden" class="jpibfi-value" name="jpibfi_selection_options[enabled_classes]" value="<?php echo $value; ?>">
179
- <span class="jpibfi-empty"><?php echo JPIBFI_Admin_Utilities::create_description( __( 'No classes added.', 'jquery-pin-it-button-for-images' ) ); ?></span>
180
- <div class="jpibfi-classes-list tagchecklist"></div>
181
- <div>
182
- <label>
183
- <?php _e( 'Class name', 'jquery-pin-it-button-for-images' ); ?>
184
- <input class="jpibfi-class-name" type="text">
185
- </label>
186
- <button type="button" class="jpibfi-class-button button"><?php _e( 'Add', 'jquery-pin-it-button-for-images' ); ?></button>
187
- </div>
188
- </div>
189
-
190
- <?php
191
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
192
- echo JPIBFI_Admin_Utilities::create_errors( 'enabled_classes' );
193
- }
194
-
195
- public function show_on_field_callback( $args ) {
196
- $options = $this->get_selection_options();
197
-
198
- $show_on_home = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_home', '1' );
199
- $show_on_page = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_page', '1' );
200
- $show_on_single = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_single', '1' );
201
- $show_on_category = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_category', '1' );
202
- $show_on_blog = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'show_on_blog', '1' );
203
- ?>
204
-
205
- <input type="checkbox" id="show_on_home" name="jpibfi_selection_options[show_on_home]" <?php checked( true, $show_on_home ); ?> value="1" />
206
- <label for="show_on_home"><?php _e( 'Home page', 'jquery-pin-it-button-for-images' ); ?></label><br/>
207
- <input type="checkbox" id="show_on_page" name="jpibfi_selection_options[show_on_page]" <?php checked( true, $show_on_page ); ?> value="1" />
208
- <label for="show_on_page"><?php _e( 'Pages', 'jquery-pin-it-button-for-images' ); ?></label><br />
209
- <input type="checkbox" id="show_on_single" name="jpibfi_selection_options[show_on_single]" <?php checked( true, $show_on_single ); ?> value="1" />
210
- <label for="show_on_single"><?php _e( 'Single posts', 'jquery-pin-it-button-for-images' ); ?></label><br />
211
- <input type="checkbox" id="show_on_category" name="jpibfi_selection_options[show_on_category]" <?php checked( true, $show_on_category ); ?> value="1" />
212
- <label for="show_on_category"><?php _e( 'Category and archive pages', 'jquery-pin-it-button-for-images' ); ?></label><br />
213
- <input type="checkbox" id="show_on_blog" name="jpibfi_selection_options[show_on_blog]" <?php checked( true, $show_on_blog ); ?> value="1" />
214
- <label for="show_on_blog"><?php _e( 'Blog pages', 'jquery-pin-it-button-for-images' ); ?></label>
215
-
216
- <?php
217
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
218
- }
219
-
220
- public function min_image_callback( $args ) {
221
- $options = $this->get_selection_options();
222
-
223
- $min_image_height = $options[ 'min_image_height' ];
224
- $min_image_width = $options[ 'min_image_width' ];
225
- ?>
226
-
227
- <p>
228
- <label for="min_image_height"><?php _e('Height', 'jquery-pin-it-button-for-images'); ?></label>
229
- <input type="number" min="0" step="1" id="min_image_height" name="jpibfi_selection_options[min_image_height]" value="<?php echo $min_image_height; ?>"
230
- class="small-text" /> px
231
- <?php echo JPIBFI_Admin_Utilities::create_errors( 'min_image_height' ); ?>
232
- </p>
233
-
234
- <p>
235
- <label for="min_image_width"><?php _e('Width', 'jquery-pin-it-button-for-images'); ?></label>
236
- <input type="number" min="0" step="1" id="min_image_width" name="jpibfi_selection_options[min_image_width]" value="<?php echo $min_image_width; ?>"
237
- class="small-text" /> px
238
- <?php echo JPIBFI_Admin_Utilities::create_errors( 'min_image_width' ); ?>
239
- </p>
240
-
241
- <?php
242
-
243
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
244
- }
245
-
246
- public function sanitize_selection_options( $input ) {
247
- $errors = false;
248
- $jpibfi_selection_options = $this->get_options();
249
-
250
- foreach( $input as $key => $value ) {
251
- switch($key) {
252
- case 'disabled_classes':
253
- case 'enabled_classes':
254
- if ( false == JPIBFI_Admin_Utilities::contains_css_class_names_or_empty( $input [ $key ] ) ) {
255
-
256
- $field = '';
257
- if ( 'disabled_classes' == $key )
258
- $field = __( 'Disabled classes', 'jquery-pin-it-button-for-images' );
259
- else if ( 'enabled_classes' == $key )
260
- $field = __( 'Enabled classes', 'jquery-pin-it-button-for-images' );
261
-
262
- $errors = true;
263
- add_settings_error(
264
- $key,
265
- esc_attr( 'settings_updated' ),
266
- $field . ' - ' . __('the given value doesn\'t meet the requirements. Please correct it and try again.', 'jquery-pin-it-button-for-images')
267
- );
268
- }
269
- break;
270
- case 'min_image_height':
271
- case 'min_image_width':
272
- if ( !is_numeric( $value ) || $value < 0 ) {
273
-
274
- $field = '';
275
- if ( 'min_image_height' == $key )
276
- $field = __( 'Minimum image height', 'jquery-pin-it-button-for-images' );
277
- else if ( 'min_image_width' == $key )
278
- $field = __( 'Minimum image width', 'jquery-pin-it-button-for-images' );
279
-
280
- $errors = true;
281
- add_settings_error(
282
- $key,
283
- esc_attr( 'settings_updated' ),
284
- $field . ' - ' . sprintf ( __('value must be a number greater or equal to %d.', 'jquery-pin-it-button-for-images'), '0' )
285
- );
286
- }
287
- break;
288
- }
289
-
290
- }
291
-
292
- $checkbox_settings = $this->get_checkbox_settings();
293
- foreach($checkbox_settings as $setting_name){
294
- if (false == array_key_exists( $setting_name, $input) ){
295
- $input[ $setting_name ] = '0';
296
- }
297
- }
298
-
299
-
300
- if ( $errors ) {
301
-
302
- update_option( $this->get_option_name() . '_errors', $input );
303
- return $jpibfi_selection_options;
304
-
305
- } else {
306
-
307
- delete_option( $this->get_option_name() . '_errors' );
308
- return $input;
309
-
310
- }
311
- }
312
-
313
- private function get_selection_options() {
314
- $jpibfi_selection_options = $this->get_options();
315
-
316
- if ( null == $this->admin_selection_options ) {
317
- //cumbersome, but works in WP 3.3
318
- $options = get_option( $this->get_option_name() . '_errors' );
319
- $this->admin_selection_options = false == $options ? $jpibfi_selection_options : $options;
320
- }
321
-
322
- return $this->admin_selection_options;
323
- }
324
- }
325
-
326
- add_action( 'plugins_loaded', array( 'JPIBFI_Selection_Options', 'get_instance' ) );
includes/admin/class-jpibfi-visual-options.php DELETED
@@ -1,429 +0,0 @@
1
- <?php
2
-
3
- class JPIBFI_Visual_Options extends JPIBFI_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
- return self::$instance;
19
- }
20
-
21
- private function get_visual_options() {
22
- $db_options = $this->get_options();
23
-
24
- if ( null == $this->admin_visual_options ) {
25
- //cumbersome, but works in WP 3.3
26
- $options = get_option( $this->get_option_name() . '_errors' );
27
- $this->admin_visual_options = false == $options ? $db_options : $options;
28
- }
29
-
30
- return $this->admin_visual_options;
31
- }
32
-
33
- function get_default_options(){
34
- $defaults = array(
35
- 'button_margin_bottom' => '20',
36
- 'button_margin_top' => '20',
37
- 'button_margin_right' => '20',
38
- 'button_margin_left' => '20',
39
- 'button_position' => '0',
40
- 'custom_image_url' => '',
41
- 'custom_image_height' => '0',
42
- 'custom_image_width' => '0',
43
- 'description_option' => '1',
44
- 'pinLinkedImages' => '0',
45
- 'pinLinkedImagesExtensions' => '',
46
- 'retina_friendly' => '0',
47
- 'show_button' => 'hover',
48
- 'transparency_value' => '0.5',
49
- 'use_custom_image' => '0',
50
- 'use_post_url' => '0'
51
- );
52
-
53
- return apply_filters( 'jpibfi_default_visual_options', $defaults );
54
- }
55
-
56
- static function get_option_name(){
57
- return 'jpibfi_visual_options';
58
- }
59
-
60
- function get_checkbox_settings() {
61
- return array(
62
- 'pinLinkedImages',
63
- 'use_post_url',
64
- 'retina_friendly',
65
- 'use_custom_image'
66
- );
67
- }
68
-
69
- /* Defines visual options section and defines all required fields */
70
- public function initialize_visual_options() {
71
-
72
- add_settings_section(
73
- 'visual_options_section', // ID used to identify this section and with which to register options
74
- __( 'Visual', 'jquery-pin-it-button-for-images' ), // Title to be displayed on the administration page
75
- array( $this, 'visual_options_callback' ), // Callback used to render the description of the section
76
- 'jpibfi_visual_options' // Page on which to add this section of options
77
- );
78
-
79
- add_settings_field(
80
- 'show_button',
81
- __( 'Show button', 'jquery-pin-it-button-for-images' ),
82
- array( $this, 'show_button_callback' ),
83
- 'jpibfi_visual_options',
84
- 'visual_options_section',
85
- array(
86
- __( 'When the "Pin it" button should be visible.', 'jquery-pin-it-button-for-images' ),
87
- )
88
- );
89
-
90
- add_settings_field(
91
- 'description_option',
92
- __( 'Description source', 'jquery-pin-it-button-for-images' ),
93
- array( $this, 'description_option_callback' ),
94
- 'jpibfi_visual_options',
95
- 'visual_options_section',
96
- array(
97
- __( '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.', 'jquery-pin-it-button-for-images' ),
98
- )
99
- );
100
-
101
- add_settings_field(
102
- 'use_post_url',
103
- __( 'Linked page', 'jquery-pin-it-button-for-images' ),
104
- array( $this, 'use_post_url_callback' ),
105
- 'jpibfi_visual_options',
106
- 'visual_options_section',
107
- array(
108
- __( '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.', 'jquery-pin-it-button-for-images' ),
109
- )
110
- );
111
-
112
- add_settings_field(
113
- 'pin_linked_images',
114
- __( 'Pin linked images', 'jquery-pin-it-button-for-images' ),
115
- array( $this, 'pin_linked_images_callback' ),
116
- 'jpibfi_visual_options',
117
- 'visual_options_section',
118
- array(
119
- )
120
- );
121
-
122
- add_settings_field(
123
- 'transparency_value',
124
- __( 'Transparency value', 'jquery-pin-it-button-for-images' ),
125
- array( $this, 'transparency_value_callback' ),
126
- 'jpibfi_visual_options',
127
- 'visual_options_section',
128
- array(
129
- __( 'This setting sets the transparency of the image.', 'jquery-pin-it-button-for-images' ),
130
- )
131
- );
132
-
133
- add_settings_field(
134
- 'custom_pin_it_button',
135
- __( 'Custom "Pin It" button', 'jquery-pin-it-button-for-images' ),
136
- array( $this, 'custom_pin_it_button_callback' ),
137
- 'jpibfi_visual_options',
138
- 'visual_options_section',
139
- array(
140
- __( '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.', 'jquery-pin-it-button-for-images' ),
141
- )
142
- );
143
-
144
- add_settings_field(
145
- 'pin_it_button_position',
146
- __( '"Pin it" button position', 'jquery-pin-it-button-for-images' ),
147
- array( $this, 'pin_it_button_position_callback' ),
148
- 'jpibfi_visual_options',
149
- 'visual_options_section',
150
- array(
151
- __( 'Where the "Pin it" button should appear on the image.', 'jquery-pin-it-button-for-images' ),
152
- )
153
- );
154
-
155
- add_settings_field(
156
- 'pin_it_button_margins',
157
- __( '"Pin it" button margins', 'jquery-pin-it-button-for-images' ),
158
- array( $this, 'pin_it_button_margins_callback' ),
159
- 'jpibfi_visual_options',
160
- 'visual_options_section',
161
- array(
162
- 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.', 'jquery-pin-it-button-for-images' ),
163
- __( 'Top left', 'jquery-pin-it-button-for-images' ),
164
- __( 'Bottom right', 'jquery-pin-it-button-for-images' ),
165
- __( 'Middle', 'jquery-pin-it-button-for-images' )
166
- ),
167
- )
168
- );
169
-
170
- add_settings_field(
171
- 'retina_friendly',
172
- __( 'Retina friendly', 'jquery-pin-it-button-for-images' ),
173
- array( $this, 'retina_friendly_callback' ),
174
- 'jpibfi_visual_options',
175
- 'visual_options_section',
176
- array(
177
- __( '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.', 'jquery-pin-it-button-for-images' ),
178
- )
179
- );
180
-
181
- register_setting(
182
- 'jpibfi_visual_options',
183
- 'jpibfi_visual_options',
184
- array( $this, 'sanitize_visual_options' )
185
- );
186
- }
187
-
188
- public function visual_options_callback() {
189
- echo '<p>' . __('How it should look like', 'jquery-pin-it-button-for-images') . '</p>';
190
- }
191
-
192
- public function show_button_callback($args){
193
- $options = $this->get_visual_options();
194
- $show_button = 'hover';
195
- ?>
196
- <select id="show_button" name="jpibfi_visual_options[show_button]">
197
- <option value="hover" <?php selected ( "hover", $show_button ); ?>><?php _e( 'On hover', 'jquery-pin-it-button-for-images' ); ?></option>
198
- <option value="always_touch" <?php selected ( "always_touch", $show_button ); ?>><?php _e( 'Always on touch devices', 'jquery-pin-it-button-for-images' ); ?></option>
199
- <option value="always" <?php selected ( "always", $show_button ); ?>><?php _e( 'Always', 'jquery-pin-it-button-for-images' ); ?></option>
200
- </select>
201
- <?php
202
- ?>
203
- <div id="show_button_error">
204
- <p><strong><?php echo sprintf(__('This feature is disabled in this version of the plugin. Consider buying <a target="_blank" href="%s">the PRO version</a>.', 'jquery-pin-it-button-for-images'), 'http://mrsztuczkens.me/jpibfi-pro/'); ?></strong></p>
205
- </div>
206
- <?php
207
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
208
- }
209
-
210
- public function description_option_callback( $args ) {
211
- $options = $this->get_visual_options();
212
-
213
- $description_option = $options[ 'description_option' ];
214
- ?>
215
-
216
- <select id="description_option" name="jpibfi_visual_options[description_option]">
217
- <option value="1" <?php selected ( "1", $description_option ); ?>><?php _e( 'Page title', 'jquery-pin-it-button-for-images' ); ?></option>
218
- <option value="2" <?php selected ( "2", $description_option ); ?>><?php _e( 'Page description (excerpt)', 'jquery-pin-it-button-for-images' ); ?></option>
219
- <option value="3" <?php selected ( "3", $description_option ); ?>><?php _e( 'Image title or (if title not available) alt attribute', 'jquery-pin-it-button-for-images' ); ?></option>
220
- <option value="4" <?php selected ( "4", $description_option ); ?>><?php _e( 'Site title (Settings->General)', 'jquery-pin-it-button-for-images' ); ?></option>
221
- <option value="5" <?php selected ( "5", $description_option ); ?>><?php _e( 'Image description', 'jquery-pin-it-button-for-images' ); ?></option>
222
- <option value="6" <?php selected ( "6", $description_option ); ?>><?php _e( 'Image alt attribute', 'jquery-pin-it-button-for-images' ); ?></option>
223
- </select>
224
-
225
- <?php
226
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
227
- }
228
-
229
- public function use_post_url_callback( $args ) {
230
-
231
- $options = $this->get_visual_options();
232
- $use_post_url = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'use_post_url', '1' );
233
-
234
- echo '<input type="checkbox" id="use_post_url" name="jpibfi_visual_options[use_post_url]" value="1" ' . checked( true, $use_post_url, false ) . '>';
235
- echo '<label for="use_post_url">' . __( 'Always link to individual post page', 'jquery-pin-it-button-for-images' ) . '</label>';
236
-
237
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
238
- }
239
-
240
- public function pin_linked_images_callback( $args){
241
- $options = $this->get_visual_options();
242
-
243
- $pin_linked_images = $options['pinLinkedImages']== '1';
244
- $pin_linked_images_extensions = $options['pinLinkedImagesExtensions'];
245
-
246
- echo '<input type="checkbox" id="pinLinkedImages" name="jpibfi_visual_options[pinLinkedImages]" value="1" ' . checked( true, $pin_linked_images, false ) . '>';
247
- echo '<label for="pinLinkedImages">' . __( 'Active', 'jquery-pin-it-button-for-images' ) . '</label>';
248
- echo JPIBFI_Admin_Utilities::create_description(__( 'When checked, pins full-sized images instead of thumbnails (works only if you link thumbnails to their full versions).', 'jquery-pin-it-button-for-images' ));
249
- echo '<p><label for="pinLinkedImagesExtensions">' . __( 'File extensions to use', 'jquery-pin-it-button-for-images' ) . '</label> ';
250
- echo '<input type="text" id="pinLinkedImagesExtensions" name="jpibfi_visual_options[pinLinkedImagesExtensions]" value="' . $pin_linked_images_extensions . '"></p>';
251
- echo JPIBFI_Admin_Utilities::create_description( __('Leaving this empty means files of any extension will be used (also those without any extension). If you want to use only files of specific extension(s), type those file extensions here (separated by commas).', 'jquery-pin-it-button-for-images') );
252
- }
253
-
254
- public function transparency_value_callback( $args ) {
255
- $options = $this->get_visual_options();
256
-
257
- $transparency_value = $options[ 'transparency_value' ];
258
-
259
- echo '<label for="transparency_value">' . sprintf ( __('Choose transparency (between %.02f and %.02f)', 'jquery-pin-it-button-for-images'), '0.00', '1.00' ) . '</label><br/>';
260
- echo '<input type="number" min="0" max="1" step="0.01" id="transparency_value" name="jpibfi_visual_options[transparency_value]"' .
261
- 'value="' . $transparency_value . '" class="small-text" >';
262
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
263
- echo JPIBFI_Admin_Utilities::create_errors( 'transparency_value' );
264
- }
265
-
266
- public function custom_pin_it_button_callback( $args ) {
267
- $options = $this->get_visual_options();
268
-
269
- $use_custom_image = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'use_custom_image', '1' );
270
- $custom_image_url = $options[ 'custom_image_url' ];
271
- $custom_image_height = $options[ 'custom_image_height' ];
272
- $custom_image_width = $options[ 'custom_image_width' ];
273
-
274
- ?>
275
- <p>
276
- <input type="checkbox" id="use_custom_image" name="jpibfi_visual_options[use_custom_image]" value="1" <?php checked( true, $use_custom_image ); ?> >
277
- <label class="chbox-label" for="use_custom_image"><?php _e( 'Use custom image', 'jquery-pin-it-button-for-images' ); ?></label>
278
- </p>
279
-
280
- <button id=upload-image><?php _e( 'Upload an image using media library','jquery-pin-it-button-for-images' ); ?></button><br />
281
-
282
- <p>
283
- <label for="custom_image_url"><?php _e( 'URL address of the image', 'jquery-pin-it-button-for-images' ); ?></label>
284
- <input type="url" id="custom_image_url" name="jpibfi_visual_options[custom_image_url]" value="<?php echo $custom_image_url; ?>">
285
- </p>
286
-
287
- <p>
288
- <label for="custom_image_height"><?php _e( 'Height', 'jquery-pin-it-button-for-images' ); ?></label>
289
- <input type="number" min="0" step="1" id="custom_image_height" name="jpibfi_visual_options[custom_image_height]" value="<?php echo $custom_image_height; ?>"
290
- class="small-text" /> px
291
- <?php echo JPIBFI_Admin_Utilities::create_errors( 'custom_image_height' ); ?>
292
- </p>
293
-
294
- <p>
295
- <label for="custom_image_width"><?php _e( 'Width', 'jquery-pin-it-button-for-images' ); ?></label>
296
- <input type="number" min="0" step="1" id="custom_image_width" name="jpibfi_visual_options[custom_image_width]" value="<?php echo $custom_image_width; ?>"
297
- class="small-text" /> px
298
- <?php echo JPIBFI_Admin_Utilities::create_errors( 'custom_image_width' ); ?>
299
- </p>
300
-
301
- <p>
302
- <b><?php _e( 'Custom Pin It button preview', 'jquery-pin-it-button-for-images' ); ?></b><br/>
303
- <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; ?>');">
304
- Preview
305
- </span><br/>
306
- <button id="refresh_custom_button_preview"><?php _e( 'Refresh preview', 'jquery-pin-it-button-for-images' ); ?></button>
307
- </p>
308
-
309
- <?php
310
-
311
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
312
- }
313
-
314
- public function pin_it_button_position_callback( $args ) {
315
- $options = $this->get_visual_options();
316
-
317
- $jpibfi_button_dropdown = array(
318
- __( 'Top left', 'jquery-pin-it-button-for-images' ),
319
- __( 'Top right', 'jquery-pin-it-button-for-images' ),
320
- __( 'Bottom left', 'jquery-pin-it-button-for-images' ),
321
- __( 'Bottom right', 'jquery-pin-it-button-for-images' ),
322
- __( 'Middle', 'jquery-pin-it-button-for-images' )
323
- );
324
-
325
- $button_position = $options[ 'button_position' ];
326
-
327
- ?>
328
-
329
- <select name="jpibfi_visual_options[button_position]" id="button_position">
330
- <?php for( $i = 0; $i < count( $jpibfi_button_dropdown ); $i++) { ?>
331
- <option value="<?php echo $i; ?>" <?php selected( $i, $button_position ); ?>><?php echo $jpibfi_button_dropdown[ $i ]; ?></option>
332
- <?php } ?>
333
- </select><br/>
334
-
335
- <?php
336
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
337
- }
338
-
339
- public function pin_it_button_margins_callback( $args ) {
340
- $options = $this->get_visual_options();
341
- ?>
342
- <label for="button_margin_top"><?php _e('Top', 'jquery-pin-it-button-for-images'); ?></label>
343
- <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/>
344
- <label for="button_margin_bottom"><?php _e('Bottom', 'jquery-pin-it-button-for-images'); ?></label>
345
- <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/>
346
- <label for="button_margin_left"><?php _e('Left', 'jquery-pin-it-button-for-images'); ?></label>
347
- <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/>
348
- <label for="button_margin_right"><?php _e('Right', 'jquery-pin-it-button-for-images'); ?></label>
349
- <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/>
350
-
351
- <?php
352
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
353
- }
354
-
355
- public function retina_friendly_callback( $args ) {
356
-
357
- $options = $this->get_visual_options();
358
- $retina_friendly = JPIBFI_Admin_Utilities::exists_and_equal_to( $options, 'retina_friendly', '1' );
359
-
360
- echo '<input type="checkbox" id="retina_friendly" name="jpibfi_visual_options[retina_friendly]" value="1" ' . checked( true, $retina_friendly, false ) . '>';
361
- echo '<label for="retina_friendly">' . __( 'Optimize for high pixel density displays', 'jquery-pin-it-button-for-images' ) . '</label>';
362
-
363
- echo JPIBFI_Admin_Utilities::create_description( $args[0] );
364
- }
365
-
366
- public function sanitize_visual_options( $input ) {
367
- $errors = false;
368
- $jpibfi_visual_options = $this->get_options();
369
-
370
- foreach( $input as $key => $value ) {
371
-
372
- switch($key) {
373
- case 'custom_image_height':
374
- case 'custom_image_width':
375
- $name = "";
376
- if ( 'custom_image_height' == $key )
377
- $name = __('Custom image height', 'jquery-pin-it-button-for-images' );
378
- else if ( 'custom_image_width' == $key )
379
- $name = __('Custom image width', 'jquery-pin-it-button-for-images' );
380
-
381
- if ( '' != $value && ( !is_numeric( $value ) || $value < 0 ) ) {
382
- $errors = true;
383
- add_settings_error(
384
- $key,
385
- esc_attr( 'settings_updated' ),
386
- $name . ' - ' . sprintf ( __('value must be a number greater or equal to %d.', 'jquery-pin-it-button-for-images'), '0' )
387
- );
388
- }
389
- break;
390
- case 'transparency_value':
391
- if ( !is_numeric( $input[ $key ] ) || ( $input[ $key ] < 0.0 ) || ( $input[ $key ] > 1.0 ) ) {
392
- $errors = true;
393
- add_settings_error(
394
- $key,
395
- esc_attr( 'settings_updated' ),
396
- sprintf( __('Transparency value must be a number between %.02d and %.02f.', 'jquery-pin-it-button-for-images'), '0.00', '1.00' )
397
- );
398
- }
399
- break;
400
- case 'pinLinkedImagesExtensions':
401
- $options[ $key ] = esc_attr( $value );
402
- break;
403
- }
404
- }
405
-
406
- $defaults = $this->get_default_options();
407
- $input['show_button'] = $defaults['show_button'];
408
-
409
- $checkbox_settings = $this->get_checkbox_settings();
410
- foreach($checkbox_settings as $setting_name){
411
- if (false == array_key_exists( $setting_name, $input) )
412
- $input[ $setting_name ] = '0';
413
- }
414
-
415
- if ( $errors ) {
416
-
417
- update_option( $this->get_option_name() . '_errors', $input );
418
- return $jpibfi_visual_options;
419
-
420
- } else {
421
-
422
- delete_option( $this->get_option_name() . '_errors' );
423
- return $input;
424
-
425
- }
426
- }
427
- }
428
-
429
- add_action( 'plugins_loaded', array( 'JPIBFI_Visual_Options', 'get_instance' ) );
includes/admin/includes/class-jpibfi-ajax-result-builder.php ADDED
@@ -0,0 +1,50 @@
1
+ <?php
2
+
3
+ class JPIBFI_Ajax_Result_Builder {
4
+
5
+ private $model;
6
+ private $status;
7
+ private $messages;
8
+
9
+ function __construct() {
10
+ $this->model = null;
11
+ $this->messages = array();
12
+ $this->status = 'OK';
13
+ }
14
+
15
+ function set_model($model) {
16
+ $this->model = $model;
17
+ return $this;
18
+ }
19
+
20
+ function set_error($error_msg, $error_msg_id = 'error') {
21
+ $arr = array();
22
+ $arr[$error_msg_id] = $error_msg;
23
+ return $this->set_errors($arr);
24
+ }
25
+
26
+ function set_errors($errors) {
27
+ $this->status = 'ERROR';
28
+ $this->messages = $errors;
29
+ return $this;
30
+ }
31
+
32
+ function set_message($msg, $msg_id = 'ok'){
33
+ $this->messages = array($msg_id => $msg);
34
+ return $this;
35
+ }
36
+
37
+ function build() {
38
+ $res = array(
39
+ 'status' => array(
40
+ 'status' => $this->status,
41
+ 'messages' => $this->messages
42
+ )
43
+ );
44
+
45
+ if ($this->model != null)
46
+ $res['model'] = $this->model;
47
+
48
+ return $res;
49
+ }
50
+ }
includes/admin/settings/class-jpibfi-import-export-settings.php ADDED
@@ -0,0 +1,126 @@
1
+ <?php
2
+
3
+ class JPIBFI_Import_Export_Settings extends JPIBFI_Settings_Tab {
4
+
5
+ private $ajax_import_action;
6
+
7
+ function __construct() {
8
+ parent::__construct();
9
+ $this->ajax_import_action = '_import';
10
+ add_filter( 'export_args', array( $this, 'export_args' ) );
11
+ add_action( 'export_wp', array( $this, 'export_wp' ) );
12
+ add_filter($this->ajax_custom_action . $this->ajax_import_action, array($this, 'ajax_import'));
13
+ }
14
+
15
+ function ajax_import() {
16
+ $result = new JPIBFI_Ajax_Result_Builder();
17
+ $file = wp_import_handle_upload();
18
+
19
+ if ( isset( $file['error'] ) ) {
20
+ return $result
21
+ ->set_error(esc_html( $file['error'] ))
22
+ ->build();
23
+ }
24
+
25
+ if ( ! isset( $file['file'], $file['id'] ) ) {
26
+ return $result
27
+ ->set_error(__( 'The file did not upload properly. Please try again.', 'jquery-pin-it-button-for-images' ))
28
+ ->build();
29
+ }
30
+
31
+ if ( ! file_exists( $file['file'] ) ) {
32
+ wp_import_cleanup( $file['id'] );
33
+ return $result
34
+ ->set_error(sprintf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'jquery-pin-it-button-for-images' ), esc_html( $file['file'] ) ))
35
+ ->build();
36
+ }
37
+
38
+ if ( ! is_file( $file['file'] ) ) {
39
+ wp_import_cleanup( $file['id'] );
40
+ return $result
41
+ ->set_error(__( 'The path is not a file, please try again.', 'jquery-pin-it-button-for-images' ))
42
+ ->build();
43
+ }
44
+
45
+ $file_contents = file_get_contents( $file['file'] );
46
+ $data = json_decode( $file_contents, true );
47
+ wp_import_cleanup( $file['id']);
48
+
49
+ $options_to_import = $data['options'];
50
+ foreach ( (array)$options_to_import as $option_name => $option_value ) {
51
+ $options_to_import[$option_name] = maybe_unserialize( $option_value );
52
+ }
53
+
54
+ $converter = new JPIBFI_Option_Converter();
55
+ $converter->save_and_convert_if_needed($options_to_import);
56
+
57
+ return $result
58
+ ->set_model($input)
59
+ ->set_message(__('Import Successful', 'jquery_pin_it_button_for_images'))
60
+ ->build();
61
+ }
62
+
63
+ function filter_settings_i18n($i18n) {
64
+ $i18n['export_title'] = __( 'Export', 'jquery-pin-it-button-for-images' );
65
+ $i18n['export_url'] = admin_url('export.php?download=true&content=jpibfi');
66
+ $i18n['export_button_text'] = __('Download Export File', 'jquery-pin-it-button-for-images');
67
+
68
+ $i18n['import_title'] = __( 'Import', 'jquery-pin-it-button-for-images' );
69
+ $i18n['import_button_text'] = __('Import Settings', 'jquery-pin-it-button-for-images');
70
+ $i18n['import_action_name'] = $this->ajax_import_action;
71
+ return $i18n;
72
+ }
73
+
74
+ function get_module_settings() {
75
+ return array (
76
+ 'slug' => 'import',
77
+ 'name' => __( 'Import/Export Settings', 'jquery-pin-it-button-for-images' ),
78
+ 'priority' => 10,
79
+ 'setting_name' => ''
80
+ );
81
+ }
82
+
83
+ /**
84
+ * @param array $args The export args being filtered.
85
+ * @return array The (possibly modified) export args.
86
+ */
87
+ public function export_args( $args ) {
88
+ if ( ! empty( $_GET['content'] ) && 'jpibfi' == $_GET['content'] ) {
89
+ return array( 'jpibfi' => true );
90
+ }
91
+ return $args;
92
+ }
93
+
94
+
95
+ /**
96
+ * Export options as a JSON file if that's what the user wants to do.
97
+ *
98
+ * @param array $args The export arguments.
99
+ * @return void
100
+ */
101
+ public function export_wp( $args ) {
102
+ if (empty($args['jpibfi']))
103
+ return;
104
+
105
+ $filename = 'jpibfi_settings_' . date( 'Y-m-d' ) . '.json';
106
+
107
+ header( 'Content-Description: File Transfer' );
108
+ header( 'Content-Disposition: attachment; filename=' . $filename );
109
+ header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ), true );
110
+
111
+ $option_names = apply_filters('jpibfi_option_names', array ('jpibfi_options_version'));
112
+
113
+ $export_options = array();
114
+
115
+ foreach ( $option_names as $option_name ) {
116
+
117
+ $option_value = get_option( $option_name );
118
+ if ( $option_value !== false ) {
119
+ $export_options[ $option_name ] = maybe_serialize( $option_value );
120
+ }
121
+ }
122
+ $JSON_PRETTY_PRINT = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
123
+ echo json_encode( array( 'options' => $export_options ), $JSON_PRETTY_PRINT );
124
+ exit;
125
+ }
126
+ }
includes/admin/settings/class-jpibfi-selection-settings.php ADDED
@@ -0,0 +1,133 @@
1
+ <?php
2