Social Media Share Buttons | MashShare - Version 3.5.2

Version Description

  • Fix: Warning A non-numeric value encountered
Download this release

Release Info

Developer ReneHermi
Plugin Icon 128x128 Social Media Share Buttons | MashShare
Version 3.5.2
Comparing to
See all releases

Code changes from version 3.5.1 to 3.5.2

includes/admin/meta-box/inc/fields/custom-html.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
-
3
- /**
4
- * Custom HTML field class.
5
- */
6
- class MASHSB_RWMB_Custom_Html_Field extends MASHSB_RWMB_Field {
7
-
8
- /**
9
- * Get field HTML
10
- *
11
- * @param mixed $meta
12
- * @param array $field
13
- *
14
- * @return string
15
- */
16
- static function html( $meta, $field ) {
17
- global $post;
18
- $html = !empty( $field['std'] ) ? $field['std'] : '';
19
- if( !empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
20
- $html = call_user_func_array( $field['callback'], array($meta, $field) );
21
- }
22
- //return $html;
23
- //return get_permalink( $post->ID );
24
- return self::get_fb_debugger_url($post);
25
- }
26
-
27
- /**
28
- * Link to the open graph debugger to check if open graph tags are valid
29
- *
30
- * @global array $post
31
- * @return string
32
- */
33
- static function get_fb_debugger_url($post) {
34
- //var_dump( $post );
35
- if( isset( $post ) && $post->post_status == "publish" ) {
36
- $url = get_permalink( $post->ID );
37
- return '<a href="https://developers.facebook.com/tools/debug/og/object?q=' . $url . '" target="_blank" rel="noopener"> Validate Open Graph data </a>';
38
- } else {
39
- return '';
40
- }
41
- }
42
-
43
- }
1
+ <?php
2
+
3
+ /**
4
+ * Custom HTML field class.
5
+ */
6
+ class MASHSB_RWMB_Custom_Html_Field extends MASHSB_RWMB_Field {
7
+
8
+ /**
9
+ * Get field HTML
10
+ *
11
+ * @param mixed $meta
12
+ * @param array $field
13
+ *
14
+ * @return string
15
+ */
16
+ static function html( $meta, $field ) {
17
+ global $post;
18
+ $html = !empty( $field['std'] ) ? $field['std'] : '';
19
+ if( !empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
20
+ $html = call_user_func_array( $field['callback'], array($meta, $field) );
21
+ }
22
+ //return $html;
23
+ //return get_permalink( $post->ID );
24
+ return self::get_fb_debugger_url($post);
25
+ }
26
+
27
+ /**
28
+ * Link to the open graph debugger to check if open graph tags are valid
29
+ *
30
+ * @global array $post
31
+ * @return string
32
+ */
33
+ static function get_fb_debugger_url($post) {
34
+ //var_dump( $post );
35
+ if( isset( $post ) && $post->post_status == "publish" ) {
36
+ $url = get_permalink( $post->ID );
37
+ return '<a href="https://developers.facebook.com/tools/debug/og/object?q=' . $url . '" target="_blank" rel="noopener"> Validate Open Graph data </a>';
38
+ } else {
39
+ return '';
40
+ }
41
+ }
42
+
43
+ }
includes/admin/meta-box/inc/fields/file.php CHANGED
@@ -1,367 +1,367 @@
1
- <?php
2
- /**
3
- * File field class which uses HTML <input type="file"> to upload file.
4
- */
5
- class MASHSB_RWMB_File_Field extends MASHSB_RWMB_Field
6
- {
7
- /**
8
- * Enqueue scripts and styles
9
- */
10
- static function admin_enqueue_scripts()
11
- {
12
- wp_enqueue_style( 'mashsb-rwmb-file', MASHSB_RWMB_CSS_URL . 'file.css', array(), MASHSB_RWMB_VER );
13
- wp_enqueue_script( 'mashsb-rwmb-file', MASHSB_RWMB_JS_URL . 'file.js', array( 'jquery' ), MASHSB_RWMB_VER, true );
14
- wp_localize_script( 'mashsb-rwmb-file', 'rwmbFile', array(
15
- 'maxFileUploadsSingle' => __( 'You may only upload maximum %d file', 'meta-box' ),
16
- 'maxFileUploadsPlural' => __( 'You may only upload maximum %d files', 'meta-box' ),
17
- ) );
18
- }
19
-
20
- /**
21
- * Add custom actions
22
- */
23
- static function add_actions()
24
- {
25
- // Add data encoding type for file uploading
26
- add_action( 'post_edit_form_tag', array( __CLASS__, 'post_edit_form_tag' ) );
27
-
28
- // Delete file via Ajax
29
- add_action( 'wp_ajax_rwmb_delete_file', array( __CLASS__, 'wp_ajax_delete_file' ) );
30
-
31
- // Allow reordering files
32
- add_action( 'wp_ajax_rwmb_reorder_files', array( __CLASS__, 'wp_ajax_reorder_files' ) );
33
- }
34
-
35
- /**
36
- * Ajax callback for reordering images
37
- */
38
- static function wp_ajax_reorder_files()
39
- {
40
- $post_id = (int) filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );
41
- $field_id = (string) filter_input( INPUT_POST, 'field_id' );
42
- $order = (string) filter_input( INPUT_POST, 'order' );
43
-
44
- check_ajax_referer( "mashsb-rwmb-reorder-files_{$field_id}" );
45
- parse_str( $order, $items );
46
- delete_post_meta( $post_id, $field_id );
47
- foreach ( $items['item'] as $item )
48
- {
49
- add_post_meta( $post_id, $field_id, $item, false );
50
- }
51
- wp_send_json_success();
52
- }
53
-
54
- /**
55
- * Add data encoding type for file uploading
56
- *
57
- * @return void
58
- */
59
- static function post_edit_form_tag()
60
- {
61
- echo ' enctype="multipart/form-data"';
62
- }
63
-
64
- /**
65
- * Ajax callback for deleting files.
66
- * Modified from a function used by "Verve Meta Boxes" plugin
67
- * @link http://goo.gl/LzYSq
68
- */
69
- static function wp_ajax_delete_file()
70
- {
71
- $post_id = (int) filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );
72
- $field_id = (string) filter_input( INPUT_POST, 'field_id' );
73
- $attachment_id = (int) filter_input( INPUT_POST, 'attachment_id', FILTER_SANITIZE_NUMBER_INT );
74
- $force_delete = (int) filter_input( INPUT_POST, 'force_delete', FILTER_SANITIZE_NUMBER_INT );
75
-
76
- check_ajax_referer( "mashsb-rwmb-delete-file_{$field_id}" );
77
- delete_post_meta( $post_id, $field_id, $attachment_id );
78
- $success = $force_delete ? wp_delete_attachment( $attachment_id ) : true;
79
-
80
- if ( $success )
81
- wp_send_json_success();
82
- else
83
- wp_send_json_error( __( 'Error: Cannot delete file', 'meta-box' ) );
84
- }
85
-
86
- /**
87
- * Get field HTML
88
- *
89
- * @param mixed $meta
90
- * @param array $field
91
- *
92
- * @return string
93
- */
94
- static function html( $meta, $field )
95
- {
96
- $i18n_title = apply_filters( 'rwmb_file_upload_string', _x( 'Upload Files', 'file upload', 'meta-box' ), $field );
97
- $i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'meta-box' ), $field );
98
-
99
- // Uploaded files
100
- $html = self::get_uploaded_files( $meta, $field );
101
- $new_file_classes = array( 'new-files' );
102
- if ( ! empty( $field['max_file_uploads'] ) && count( $meta ) >= (int) $field['max_file_uploads'] )
103
- $new_file_classes[] = 'hidden';
104
-
105
- // Show form upload
106
- $html .= sprintf(
107
- '<div class="%s">
108
- <h4>%s</h4>
109
- <div class="file-input"><input type="file" name="%s[]" /></div>
110
- <a class="mashsb-rwmb-add-file" href="#"><strong>%s</strong></a>
111
- </div>',
112
- implode( ' ', $new_file_classes ),
113
- $i18n_title,
114
- $field['id'],
115
- $i18n_more
116
- );
117
-
118
- return $html;
119
- }
120
-
121
- static function get_uploaded_files( $files, $field )
122
- {
123
- $reorder_nonce = wp_create_nonce( "mashsb-rwmb-reorder-files_{$field['id']}" );
124
- $delete_nonce = wp_create_nonce( "mashsb-rwmb-delete-file_{$field['id']}" );
125
-
126
- $classes = array( 'mashsb-rwmb-file', 'mashsb-rwmb-uploaded' );
127
- if ( count( $files ) <= 0 )
128
- $classes[] = 'hidden';
129
- $list = '<ul class="%s" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s" data-mime_type="%s">';
130
- $html = sprintf(
131
- $list,
132
- implode( ' ', $classes ),
133
- $field['id'],
134
- $delete_nonce,
135
- $reorder_nonce,
136
- $field['force_delete'] ? 1 : 0,
137
- $field['max_file_uploads'],
138
- $field['mime_type']
139
- );
140
-
141
- foreach ( (array) $files as $attachment_id )
142
- {
143
- $html .= self::file_html( $attachment_id );
144
- }
145
-
146
- $html .= '</ul>';
147
-
148
- return $html;
149
- }
150
-
151
- static function file_html( $attachment_id )
152
- {
153
- $i18n_delete = apply_filters( 'rwmb_file_delete_string', _x( 'Delete', 'file upload', 'meta-box' ) );
154
- $i18n_edit = apply_filters( 'rwmb_file_edit_string', _x( 'Edit', 'file upload', 'meta-box' ) );
155
- $item = '
156
- <li id="item_%s">
157
- <div class="mashsb-rwmb-icon">%s</div>
158
- <div class="mashsb-rwmb-info">
159
- <a href="%s" target="_blank" rel="noopener">%s</a>
160
- <p>%s</p>
161
- <a title="%s" href="%s" target="_blank">%s</a> |
162
- <a title="%s" class="mashsb-rwmb-delete-file" href="#" data-attachment_id="%s">%s</a>
163
- </div>
164
- </li>';
165
-
166
- $mime_type = get_post_mime_type( $attachment_id );
167
-
168
- return sprintf(
169
- $item,
170
- $attachment_id,
171
- wp_get_attachment_image( $attachment_id, array( 60, 60 ), true ),
172
- wp_get_attachment_url( $attachment_id ),
173
- get_the_title( $attachment_id ),
174
- $mime_type,
175
- $i18n_edit,
176
- get_edit_post_link( $attachment_id ),
177
- $i18n_edit,
178
- $i18n_delete,
179
- $attachment_id,
180
- $i18n_delete
181
- );
182
- }
183
-
184
- /**
185
- * Get meta values to save
186
- *
187
- * @param mixed $new
188
- * @param mixed $old
189
- * @param int $post_id
190
- * @param array $field
191
- *
192
- * @return array|mixed
193
- */
194
- static function value( $new, $old, $post_id, $field )
195
- {
196
- $name = $field['id'];
197
- if ( empty( $_FILES[$name] ) )
198
- return $new;
199
-
200
- $new = array();
201
- $files = self::fix_file_array( $_FILES[$name] );
202
-
203
- foreach ( $files as $file_item )
204
- {
205
- $file = wp_handle_upload( $file_item, array( 'test_form' => false ) );
206
-
207
- if ( ! isset( $file['file'] ) )
208
- continue;
209
-
210
- $file_name = $file['file'];
211
-
212
- $attachment = array(
213
- 'post_mime_type' => $file['type'],
214
- 'guid' => $file['url'],
215
- 'post_parent' => $post_id,
216
- 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_name ) ),
217
- 'post_content' => '',
218
- );
219
- $id = wp_insert_attachment( $attachment, $file_name, $post_id );
220
-
221
- if ( ! is_wp_error( $id ) )
222
- {
223
- wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file_name ) );
224
-
225
- // Save file ID in meta field
226
- $new[] = $id;
227
- }
228
- }
229
-
230
- return array_unique( array_merge( $old, $new ) );
231
- }
232
-
233
- /**
234
- * Fixes the odd indexing of multiple file uploads from the format:
235
- * $_FILES['field']['key']['index']
236
- * To the more standard and appropriate:
237
- * $_FILES['field']['index']['key']
238
- *
239
- * @param array $files
240
- *
241
- * @return array
242
- */
243
- static function fix_file_array( $files )
244
- {
245
- $output = array();
246
- foreach ( $files as $key => $list )
247
- {
248
- foreach ( $list as $index => $value )
249
- {
250
- $output[$index][$key] = $value;
251
- }
252
- }
253
-
254
- return $output;
255
- }
256
-
257
- /**
258
- * Normalize parameters for field
259
- *
260
- * @param array $field
261
- *
262
- * @return array
263
- */
264
- static function normalize( $field )
265
- {
266
- $field = parent::normalize( $field );
267
- $field = wp_parse_args( $field, array(
268
- 'std' => array(),
269
- 'force_delete' => false,
270
- 'max_file_uploads' => 0,
271
- 'mime_type' => '',
272
- ) );
273
- $field['multiple'] = true;
274
-
275
- return $field;
276
- }
277
-
278
- /**
279
- * Get the field value
280
- * The difference between this function and 'meta' function is 'meta' function always returns the escaped value
281
- * of the field saved in the database, while this function returns more meaningful value of the field
282
- *
283
- * @param array $field Field parameters
284
- * @param array $args Not used for this field
285
- * @param int|null $post_id Post ID. null for current post. Optional.
286
- *
287
- * @return mixed Full info of uploaded files
288
- */
289
- static function get_value( $field, $args = array(), $post_id = null )
290
- {
291
- if ( ! $post_id )
292
- $post_id = get_the_ID();
293
-
294
- /**
295
- * Get raw meta value in the database, no escape
296
- * Very similar to self::meta() function
297
- */
298
- $file_ids = get_post_meta( $post_id, $field['id'], false );
299
-
300
- // For each file, get full file info
301
- $value = array();
302
- foreach ( (array) $file_ids as $file_id )
303
- {
304
- if ( $file_info = call_user_func( array( MASHSB_RW_Meta_Box::get_class_name( $field ), 'file_info' ), $file_id, $args ) )
305
- {
306
- $value[$file_id] = $file_info;
307
- }
308
- }
309
-
310
- return $value;
311
- }
312
-
313
- /**
314
- * Output the field value
315
- * Display unordered list of files
316
- *
317
- * @param array $field Field parameters
318
- * @param array $args Additional arguments. Not used for these fields.
319
- * @param int|null $post_id Post ID. null for current post. Optional.
320
- *
321
- * @return mixed Field value
322
- */
323
- static function the_value( $field, $args = array(), $post_id = null )
324
- {
325
- $value = self::get_value( $field, $args, $post_id );
326
- if ( ! $value )
327
- return '';
328
-
329
- $output = '<ul>';
330
- foreach ( $value as $file_id => $file_info )
331
- {
332
- $output .= sprintf(
333
- '<li><a href="%s" target="_blank">%s</a></li>',
334
- wp_get_attachment_url( $file_id ),
335
- get_the_title( $file_id )
336
- );
337
- }
338
- $output .= '</ul>';
339
-
340
- return $output;
341
- }
342
-
343
- /**
344
- * Get uploaded file information
345
- *
346
- * @param int $file_id Attachment file ID (post ID). Required.
347
- * @param array $args Array of arguments (for size).
348
- *
349
- * @return array|bool False if file not found. Array of (id, name, path, url) on success
350
- */
351
- static function file_info( $file_id, $args = array() )
352
- {
353
- $path = get_attached_file( $file_id );
354
- if ( ! $path )
355
- {
356
- return false;
357
- }
358
-
359
- return array(
360
- 'ID' => $file_id,
361
- 'name' => basename( $path ),
362
- 'path' => $path,
363
- 'url' => wp_get_attachment_url( $file_id ),
364
- 'title' => get_the_title( $file_id ),
365
- );
366
- }
367
- }
1
+ <?php
2
+ /**
3
+ * File field class which uses HTML <input type="file"> to upload file.
4
+ */
5
+ class MASHSB_RWMB_File_Field extends MASHSB_RWMB_Field
6
+ {
7
+ /**
8
+ * Enqueue scripts and styles
9
+ */
10
+ static function admin_enqueue_scripts()
11
+ {
12
+ wp_enqueue_style( 'mashsb-rwmb-file', MASHSB_RWMB_CSS_URL . 'file.css', array(), MASHSB_RWMB_VER );
13
+ wp_enqueue_script( 'mashsb-rwmb-file', MASHSB_RWMB_JS_URL . 'file.js', array( 'jquery' ), MASHSB_RWMB_VER, true );
14
+ wp_localize_script( 'mashsb-rwmb-file', 'rwmbFile', array(
15
+ 'maxFileUploadsSingle' => __( 'You may only upload maximum %d file', 'meta-box' ),
16
+ 'maxFileUploadsPlural' => __( 'You may only upload maximum %d files', 'meta-box' ),
17
+ ) );
18
+ }
19
+
20
+ /**
21
+ * Add custom actions
22
+ */
23
+ static function add_actions()
24
+ {
25
+ // Add data encoding type for file uploading
26
+ add_action( 'post_edit_form_tag', array( __CLASS__, 'post_edit_form_tag' ) );
27
+
28
+ // Delete file via Ajax
29
+ add_action( 'wp_ajax_rwmb_delete_file', array( __CLASS__, 'wp_ajax_delete_file' ) );
30
+
31
+ // Allow reordering files
32
+ add_action( 'wp_ajax_rwmb_reorder_files', array( __CLASS__, 'wp_ajax_reorder_files' ) );
33
+ }
34
+
35
+ /**
36
+ * Ajax callback for reordering images
37
+ */
38
+ static function wp_ajax_reorder_files()
39
+ {
40
+ $post_id = (int) filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );
41
+ $field_id = (string) filter_input( INPUT_POST, 'field_id' );
42
+ $order = (string) filter_input( INPUT_POST, 'order' );
43
+
44
+ check_ajax_referer( "mashsb-rwmb-reorder-files_{$field_id}" );
45
+ parse_str( $order, $items );
46
+ delete_post_meta( $post_id, $field_id );
47
+ foreach ( $items['item'] as $item )
48
+ {
49
+ add_post_meta( $post_id, $field_id, $item, false );
50
+ }
51
+ wp_send_json_success();
52
+ }
53
+
54
+ /**
55
+ * Add data encoding type for file uploading
56
+ *
57
+ * @return void
58
+ */
59
+ static function post_edit_form_tag()
60
+ {
61
+ echo ' enctype="multipart/form-data"';
62
+ }
63
+
64
+ /**
65
+ * Ajax callback for deleting files.
66
+ * Modified from a function used by "Verve Meta Boxes" plugin
67
+ * @link http://goo.gl/LzYSq
68
+ */
69
+ static function wp_ajax_delete_file()
70
+ {
71
+ $post_id = (int) filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );
72
+ $field_id = (string) filter_input( INPUT_POST, 'field_id' );
73
+ $attachment_id = (int) filter_input( INPUT_POST, 'attachment_id', FILTER_SANITIZE_NUMBER_INT );
74
+ $force_delete = (int) filter_input( INPUT_POST, 'force_delete', FILTER_SANITIZE_NUMBER_INT );
75
+
76
+ check_ajax_referer( "mashsb-rwmb-delete-file_{$field_id}" );
77
+ delete_post_meta( $post_id, $field_id, $attachment_id );
78
+ $success = $force_delete ? wp_delete_attachment( $attachment_id ) : true;
79
+
80
+ if ( $success )
81
+ wp_send_json_success();
82
+ else
83
+ wp_send_json_error( __( 'Error: Cannot delete file', 'meta-box' ) );
84
+ }
85
+
86
+ /**
87
+ * Get field HTML
88
+ *
89
+ * @param mixed $meta
90
+ * @param array $field
91
+ *
92
+ * @return string
93
+ */
94
+ static function html( $meta, $field )
95
+ {
96
+ $i18n_title = apply_filters( 'rwmb_file_upload_string', _x( 'Upload Files', 'file upload', 'meta-box' ), $field );
97
+ $i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'meta-box' ), $field );
98
+
99
+ // Uploaded files
100
+ $html = self::get_uploaded_files( $meta, $field );
101
+ $new_file_classes = array( 'new-files' );
102
+ if ( ! empty( $field['max_file_uploads'] ) && count( $meta ) >= (int) $field['max_file_uploads'] )
103
+ $new_file_classes[] = 'hidden';
104
+
105
+ // Show form upload
106
+ $html .= sprintf(
107
+ '<div class="%s">
108
+ <h4>%s</h4>
109
+ <div class="file-input"><input type="file" name="%s[]" /></div>
110
+ <a class="mashsb-rwmb-add-file" href="#"><strong>%s</strong></a>
111
+ </div>',
112
+ implode( ' ', $new_file_classes ),
113
+ $i18n_title,
114
+ $field['id'],
115
+ $i18n_more
116
+ );
117
+
118
+ return $html;
119
+ }
120
+
121
+ static function get_uploaded_files( $files, $field )
122
+ {
123
+ $reorder_nonce = wp_create_nonce( "mashsb-rwmb-reorder-files_{$field['id']}" );
124
+ $delete_nonce = wp_create_nonce( "mashsb-rwmb-delete-file_{$field['id']}" );
125
+
126
+ $classes = array( 'mashsb-rwmb-file', 'mashsb-rwmb-uploaded' );
127
+ if ( count( $files ) <= 0 )
128
+ $classes[] = 'hidden';
129
+ $list = '<ul class="%s" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s" data-mime_type="%s">';
130
+ $html = sprintf(
131
+ $list,
132
+ implode( ' ', $classes ),
133
+ $field['id'],
134
+ $delete_nonce,
135
+ $reorder_nonce,
136
+ $field['force_delete'] ? 1 : 0,
137
+ $field['max_file_uploads'],
138
+ $field['mime_type']
139
+ );
140
+
141
+ foreach ( (array) $files as $attachment_id )
142
+ {
143
+ $html .= self::file_html( $attachment_id );
144
+ }
145
+
146
+ $html .= '</ul>';
147
+
148
+ return $html;
149
+ }
150
+
151
+ static function file_html( $attachment_id )
152
+ {
153
+ $i18n_delete = apply_filters( 'rwmb_file_delete_string', _x( 'Delete', 'file upload', 'meta-box' ) );
154
+ $i18n_edit = apply_filters( 'rwmb_file_edit_string', _x( 'Edit', 'file upload', 'meta-box' ) );
155
+ $item = '
156
+ <li id="item_%s">
157
+ <div class="mashsb-rwmb-icon">%s</div>
158
+ <div class="mashsb-rwmb-info">
159
+ <a href="%s" target="_blank" rel="noopener">%s</a>
160
+ <p>%s</p>
161
+ <a title="%s" href="%s" target="_blank">%s</a> |
162
+ <a title="%s" class="mashsb-rwmb-delete-file" href="#" data-attachment_id="%s">%s</a>
163
+ </div>
164
+ </li>';
165
+
166
+ $mime_type = get_post_mime_type( $attachment_id );
167
+
168
+ return sprintf(
169
+ $item,
170
+ $attachment_id,
171
+ wp_get_attachment_image( $attachment_id, array( 60, 60 ), true ),
172
+ wp_get_attachment_url( $attachment_id ),
173
+ get_the_title( $attachment_id ),
174
+ $mime_type,
175
+ $i18n_edit,
176
+ get_edit_post_link( $attachment_id ),
177
+ $i18n_edit,
178
+ $i18n_delete,
179
+ $attachment_id,
180
+ $i18n_delete
181
+ );
182
+ }
183
+
184
+ /**
185
+ * Get meta values to save
186
+ *
187
+ * @param mixed $new
188
+ * @param mixed $old
189
+ * @param int $post_id
190
+ * @param array $field
191
+ *
192
+ * @return array|mixed
193
+ */
194
+ static function value( $new, $old, $post_id, $field )
195
+ {
196
+ $name = $field['id'];
197
+ if ( empty( $_FILES[$name] ) )
198
+ return $new;
199
+
200
+ $new = array();
201
+ $files = self::fix_file_array( $_FILES[$name] );
202
+
203
+ foreach ( $files as $file_item )
204
+ {
205
+ $file = wp_handle_upload( $file_item, array( 'test_form' => false ) );
206
+
207
+ if ( ! isset( $file['file'] ) )
208
+ continue;
209
+
210
+ $file_name = $file['file'];
211
+
212
+ $attachment = array(
213
+ 'post_mime_type' => $file['type'],
214
+ 'guid' => $file['url'],
215
+ 'post_parent' => $post_id,
216
+ 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $file_name ) ),
217
+ 'post_content' => '',
218
+ );
219
+ $id = wp_insert_attachment( $attachment, $file_name, $post_id );
220
+
221
+ if ( ! is_wp_error( $id ) )
222
+ {
223
+ wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file_name ) );
224
+
225
+ // Save file ID in meta field
226
+ $new[] = $id;
227
+ }
228
+ }
229
+
230
+ return array_unique( array_merge( $old, $new ) );
231
+ }
232
+
233
+ /**
234
+ * Fixes the odd indexing of multiple file uploads from the format:
235
+ * $_FILES['field']['key']['index']
236
+ * To the more standard and appropriate:
237
+ * $_FILES['field']['index']['key']
238
+ *
239
+ * @param array $files
240
+ *
241
+ * @return array
242
+ */
243
+ static function fix_file_array( $files )
244
+ {
245
+ $output = array();
246
+ foreach ( $files as $key => $list )
247
+ {
248
+ foreach ( $list as $index => $value )
249
+ {
250
+ $output[$index][$key] = $value;
251
+ }
252
+ }
253
+
254
+ return $output;
255
+ }
256
+
257
+ /**
258
+ * Normalize parameters for field
259
+ *
260
+ * @param array $field
261
+ *
262
+ * @return array
263
+ */
264
+ static function normalize( $field )
265
+ {
266
+ $field = parent::normalize( $field );
267
+ $field = wp_parse_args( $field, array(
268
+ 'std' => array(),
269
+ 'force_delete' => false,
270
+ 'max_file_uploads' => 0,
271
+ 'mime_type' => '',
272
+ ) );
273
+ $field['multiple'] = true;
274
+
275
+ return $field;
276
+ }
277
+
278
+ /**
279
+ * Get the field value
280
+ * The difference between this function and 'meta' function is 'meta' function always returns the escaped value
281
+ * of the field saved in the database, while this function returns more meaningful value of the field
282
+ *
283
+ * @param array $field Field parameters
284
+ * @param array $args Not used for this field
285
+ * @param int|null $post_id Post ID. null for current post. Optional.
286
+ *
287
+ * @return mixed Full info of uploaded files
288
+ */
289
+ static function get_value( $field, $args = array(), $post_id = null )
290
+ {
291
+ if ( ! $post_id )
292
+ $post_id = get_the_ID();
293
+
294
+ /**
295
+ * Get raw meta value in the database, no escape
296
+ * Very similar to self::meta() function
297
+ */
298
+ $file_ids = get_post_meta( $post_id, $field['id'], false );
299
+
300
+ // For each file, get full file info
301
+ $value = array();
302
+ foreach ( (array) $file_ids as $file_id )
303
+ {
304
+ if ( $file_info = call_user_func( array( MASHSB_RW_Meta_Box::get_class_name( $field ), 'file_info' ), $file_id, $args ) )
305
+ {
306
+ $value[$file_id] = $file_info;
307
+ }
308
+ }
309
+
310
+ return $value;
311
+ }
312
+
313
+ /**
314
+ * Output the field value
315
+ * Display unordered list of files
316
+ *
317
+ * @param array $field Field parameters
318
+ * @param array $args Additional arguments. Not used for these fields.
319
+ * @param int|null $post_id Post ID. null for current post. Optional.
320
+ *
321
+ * @return mixed Field value
322
+ */
323
+ static function the_value( $field, $args = array(), $post_id = null )
324
+ {
325
+ $value = self::get_value( $field, $args, $post_id );
326
+ if ( ! $value )
327
+ return '';
328
+
329
+ $output = '<ul>';
330
+ foreach ( $value as $file_id => $file_info )
331
+ {
332
+ $output .= sprintf(
333
+ '<li><a href="%s" target="_blank">%s</a></li>',
334
+ wp_get_attachment_url( $file_id ),
335
+ get_the_title( $file_id )
336
+ );
337
+ }
338
+ $output .= '</ul>';
339
+
340
+ return $output;
341
+ }
342
+
343
+ /**
344
+ * Get uploaded file information
345
+ *
346
+ * @param int $file_id Attachment file ID (post ID). Required.
347
+ * @param array $args Array of arguments (for size).
348
+ *
349
+ * @return array|bool False if file not found. Array of (id, name, path, url) on success
350
+ */
351
+ static function file_info( $file_id, $args = array() )
352
+ {
353
+ $path = get_attached_file( $file_id );
354
+ if ( ! $path )
355
+ {
356
+ return false;
357
+ }
358
+
359
+ return array(
360
+ 'ID' => $file_id,
361
+ 'name' => basename( $path ),
362
+ 'path' => $path,
363
+ 'url' => wp_get_attachment_url( $file_id ),
364
+ 'title' => get_the_title( $file_id ),
365
+ );
366
+ }
367
+ }
includes/admin/meta-box/inc/fields/force-creation.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
-
3
- /**
4
- * Custom HTML field class.
5
- */
6
- class MASHSB_RWMB_Force_Creation_Field extends MASHSB_RWMB_Field {
7
-
8
- /**
9
- * Get field HTML
10
- *
11
- * @param mixed $meta
12
- * @param array $field
13
- *
14
- * @return string
15
- */
16
- static function html( $meta, $field ) {
17
- global $post;
18
- $html = !empty( $field['std'] ) ? $field['std'] : '';
19
- if( !empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
20
- $html = call_user_func_array( $field['callback'], array($meta, $field) );
21
- }
22
- return self::get_force_refresh_url($post, $field);
23
- }
24
-
25
- /**
26
- * Link to the open graph debugger to check if open graph tags are valid
27
- *
28
- * @global array $post
29
- * @return string
30
- */
31
- static function get_force_refresh_url($post, $field) {
32
- //var_dump( $post );
33
- if( isset( $post ) && $post->post_status == "publish" ) {
34
- $url = get_permalink( $post->ID );
35
- return '<a href="' . $url . '?mashsb-refresh" target="_blank" rel="noopener" class="button-small"> Get Shares & Shortlinks </a>' . $field['helper'];
36
- } else {
37
- return '';
38
- }
39
- }
40
-
41
- }
1
+ <?php
2
+
3
+ /**
4
+ * Custom HTML field class.
5
+ */
6
+ class MASHSB_RWMB_Force_Creation_Field extends MASHSB_RWMB_Field {
7
+
8
+ /**
9
+ * Get field HTML
10
+ *
11
+ * @param mixed $meta
12
+ * @param array $field
13
+ *
14
+ * @return string
15
+ */
16
+ static function html( $meta, $field ) {
17
+ global $post;
18
+ $html = !empty( $field['std'] ) ? $field['std'] : '';
19
+ if( !empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
20
+ $html = call_user_func_array( $field['callback'], array($meta, $field) );
21
+ }
22
+ return self::get_force_refresh_url($post, $field);
23
+ }
24
+
25
+ /**
26
+ * Link to the open graph debugger to check if open graph tags are valid
27
+ *
28
+ * @global array $post
29
+ * @return string
30
+ */
31
+ static function get_force_refresh_url($post, $field) {
32
+ //var_dump( $post );
33
+ if( isset( $post ) && $post->post_status == "publish" ) {
34
+ $url = get_permalink( $post->ID );
35
+ return '<a href="' . $url . '?mashsb-refresh" target="_blank" rel="noopener" class="button-small"> Get Shares & Shortlinks </a>' . $field['helper'];
36
+ } else {
37
+ return '';
38
+ }
39
+ }
40
+
41
+ }
includes/admin/meta-box/inc/fields/image.php CHANGED
@@ -1,234 +1,234 @@
1
- <?php
2
-
3
- /**
4
- * Image field class which uses <input type="file"> to upload.
5
- */
6
- class MASHSB_RWMB_Image_Field extends MASHSB_RWMB_File_Field
7
- {
8
- /**
9
- * Enqueue scripts and styles.
10
- */
11
- static function admin_enqueue_scripts()
12
- {
13
- // Enqueue same scripts and styles as for file field
14
- parent::admin_enqueue_scripts();
15
-
16
- wp_enqueue_style( 'mashsb-rwmb-image', MASHSB_RWMB_CSS_URL . 'image.css', array(), MASHSB_RWMB_VER );
17
- wp_enqueue_script( 'mashsb-rwmb-image', MASHSB_RWMB_JS_URL . 'image.js', array( 'jquery-ui-sortable' ), MASHSB_RWMB_VER, true );
18
- }
19
-
20
- /**
21
- * Add custom actions.
22
- */
23
- static function add_actions()
24
- {
25
- // Do same actions as file field
26
- parent::add_actions();
27
-
28
- // Reorder images via Ajax
29
- add_action( 'wp_ajax_rwmb_reorder_images', array( __CLASS__, 'wp_ajax_reorder_images' ) );
30
- }
31
-
32
- /**
33
- * Ajax callback for reordering images.
34
- */
35
- static function wp_ajax_reorder_images()
36
- {
37
- $post_id = (int) filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );
38
- $field_id = (string) filter_input( INPUT_POST, 'field_id' );
39
- $order = (string) filter_input( INPUT_POST, 'order' );
40
-
41
- check_ajax_referer( "mashsb-rwmb-reorder-images_{$field_id}" );
42
- parse_str( $order, $items );
43
- delete_post_meta( $post_id, $field_id );
44
- foreach ( $items['item'] as $item )
45
- {
46
- add_post_meta( $post_id, $field_id, $item, false );
47
- }
48
- wp_send_json_success();
49
- }
50
-
51
- /**
52
- * Get field HTML
53
- *
54
- * @param mixed $meta
55
- * @param array $field
56
- *
57
- * @return string
58
- */
59
- static function html( $meta, $field )
60
- {
61
- $i18n_title = apply_filters( 'rwmb_image_upload_string', _x( 'Upload Images', 'image upload', 'meta-box' ), $field );
62
- $i18n_more = apply_filters( 'rwmb_image_add_string', _x( '+ Add new image', 'image upload', 'meta-box' ), $field );
63
-
64
- // Uploaded images
65
- $html = self::get_uploaded_images( $meta, $field );
66
-
67
- // Show form upload
68
- $html .= sprintf(
69
- '<h4>%s</h4>
70
- <div class="new-files">
71
- <div class="file-input"><input type="file" name="%s[]" /></div>
72
- <a class="mashsb-rwmb-add-file" href="#"><strong>%s</strong></a>
73
- </div>',
74
- $i18n_title,
75
- $field['id'],
76
- $i18n_more
77
- );
78
-
79
- return $html;
80
- }
81
-
82
- /**
83
- * Get HTML markup for uploaded images
84
- *
85
- * @param array $images
86
- * @param array $field
87
- *
88
- * @return string
89
- */
90
- static function get_uploaded_images( $images, $field )
91
- {
92
- $reorder_nonce = wp_create_nonce( "mashsb-rwmb-reorder-images_{$field['id']}" );
93
- $delete_nonce = wp_create_nonce( "mashsb-rwmb-delete-file_{$field['id']}" );
94
- $classes = array( 'mashsb-rwmb-images', 'mashsb-rwmb-uploaded' );
95
- if ( count( $images ) <= 0 )
96
- $classes[] = 'hidden';
97
- $list = '<ul class="%s" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s">';
98
- $html = sprintf(
99
- $list,
100
- implode( ' ', $classes ),
101
- $field['id'],
102
- $delete_nonce,
103
- $reorder_nonce,
104
- $field['force_delete'] ? 1 : 0,
105
- $field['max_file_uploads']
106
- );
107
-
108
- foreach ( $images as $image )
109
- {
110
- $html .= self::img_html( $image );
111
- }
112
- $html .= '</ul>';
113
- return $html;
114
- }
115
-
116
- /**
117
- * Get HTML markup for ONE uploaded image
118
- *
119
- * @param int $image Image ID
120
- * @return string
121
- */
122
- static function img_html( $image )
123
- {
124
- $i18n_delete = apply_filters( 'rwmb_image_delete_string', _x( 'Delete', 'image upload', 'meta-box' ) );
125
- $i18n_edit = apply_filters( 'rwmb_image_edit_string', _x( 'Edit', 'image upload', 'meta-box' ) );
126
- $item = '
127
- <li id="item_%s">
128
- <img src="%s" />
129
- <div class="mashsb-rwmb-image-bar">
130
- <a title="%s" class="mashsb-rwmb-edit-file" href="%s" target="_blank" rel="noopener">%s</a> |
131
- <a title="%s" class="mashsb-rwmb-delete-file" href="#" data-attachment_id="%s">&times;</a>
132
- </div>
133
- </li>
134
- ';
135
-
136
- $src = wp_get_attachment_image_src( $image, 'thumbnail' );
137
- $src = $src[0];
138
- $link = get_edit_post_link( $image );
139
-
140
- return sprintf(
141
- $item,
142
- $image,
143
- $src,
144
- $i18n_edit, $link, $i18n_edit,
145
- $i18n_delete, $image
146
- );
147
- }
148
-
149
- /**
150
- * Output the field value
151
- * Display unordered list of images with option for size and link to full size
152
- *
153
- * @param array $field Field parameters
154
- * @param array $args Additional arguments. Not used for these fields.
155
- * @param int|null $post_id Post ID. null for current post. Optional.
156
- *
157
- * @return mixed Field value
158
- */
159
- static function the_value( $field, $args = array(), $post_id = null )
160
- {
161
- $value = self::get_value( $field, $args, $post_id );
162
- if ( ! $value )
163
- return '';
164
-
165
- $output = '<ul>';
166
- foreach ( $value as $file_info )
167
- {
168
- $img = sprintf(
169
- '<img src="%s" alt="%s" title="%s">',
170
- esc_url( $file_info['url'] ),
171
- esc_attr( $file_info['alt'] ),
172
- esc_attr( $file_info['title'] )
173
- );
174
-
175
- // Link thumbnail to full size image?
176
- if ( isset( $args['link'] ) && $args['link'] )
177
- {
178
- $img = sprintf(
179
- '<a href="%s" title="%s">%s</a>',
180
- esc_url( $file_info['full_url'] ),
181
- esc_attr( $file_info['title'] ),
182
- $img
183
- );
184
- }
185
-
186
- $output .= "<li>$img</li>";
187
- }
188
- $output .= '</ul>';
189
-
190
- return $output;
191
- }
192
-
193
- /**
194
- * Get uploaded file information
195
- *
196
- * @param int $file_id Attachment image ID (post ID). Required.
197
- * @param array $args Array of arguments (for size).
198
- *
199
- * @return array|bool False if file not found. Array of image info on success
200
- */
201
- static function file_info( $file_id, $args = array() )
202
- {
203
- $args = wp_parse_args( $args, array(
204
- 'size' => 'thumbnail',
205
- ) );
206
-
207
- $img_src = wp_get_attachment_image_src( $file_id, $args['size'] );
208
- if ( ! $img_src )
209
- {
210
- return false;
211
- }
212
-
213
- $attachment = get_post( $file_id );
214
- $path = get_attached_file( $file_id );
215
- $info = array(
216
- 'ID' => $file_id,
217
- 'name' => basename( $path ),
218
- 'path' => $path,
219
- 'url' => $img_src[0],
220
- 'width' => $img_src[1],
221
- 'height' => $img_src[2],
222
- 'full_url' => wp_get_attachment_url( $file_id ),
223
- 'title' => $attachment->post_title,
224
- 'caption' => $attachment->post_excerpt,
225
- 'description' => $attachment->post_content,
226
- 'alt' => get_post_meta( $file_id, '_wp_attachment_image_alt', true ),
227
- );
228
- if ( function_exists( 'wp_get_attachment_image_srcset' ) )
229
- {
230
- $info['srcset'] = wp_get_attachment_image_srcset( $file_id );
231
- }
232
- return $info;
233
- }
234
- }
1
+ <?php
2
+
3
+ /**
4
+ * Image field class which uses <input type="file"> to upload.
5
+ */
6
+ class MASHSB_RWMB_Image_Field extends MASHSB_RWMB_File_Field
7
+ {
8
+ /**
9
+ * Enqueue scripts and styles.
10
+ */
11
+ static function admin_enqueue_scripts()
12
+ {
13
+ // Enqueue same scripts and styles as for file field
14
+ parent::admin_enqueue_scripts();
15
+
16
+ wp_enqueue_style( 'mashsb-rwmb-image', MASHSB_RWMB_CSS_URL . 'image.css', array(), MASHSB_RWMB_VER );
17
+ wp_enqueue_script( 'mashsb-rwmb-image', MASHSB_RWMB_JS_URL . 'image.js', array( 'jquery-ui-sortable' ), MASHSB_RWMB_VER, true );
18
+ }
19
+
20
+ /**
21
+ * Add custom actions.
22
+ */
23
+ static function add_actions()
24
+ {
25
+ // Do same actions as file field
26
+ parent::add_actions();
27
+
28
+ // Reorder images via Ajax
29
+ add_action( 'wp_ajax_rwmb_reorder_images', array( __CLASS__, 'wp_ajax_reorder_images' ) );
30
+ }
31
+
32
+ /**
33
+ * Ajax callback for reordering images.
34
+ */
35
+ static function wp_ajax_reorder_images()
36
+ {
37
+ $post_id = (int) filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT );
38
+ $field_id = (string) filter_input( INPUT_POST, 'field_id' );
39
+ $order = (string) filter_input( INPUT_POST, 'order' );
40
+
41
+ check_ajax_referer( "mashsb-rwmb-reorder-images_{$field_id}" );
42
+ parse_str( $order, $items );
43
+ delete_post_meta( $post_id, $field_id );
44
+ foreach ( $items['item'] as $item )
45
+ {
46
+ add_post_meta( $post_id, $field_id, $item, false );
47
+ }
48
+ wp_send_json_success();
49
+ }
50
+
51
+ /**
52
+ * Get field HTML
53
+ *
54
+ * @param mixed $meta
55
+ * @param array $field
56
+ *
57
+ * @return string
58
+ */
59
+ static function html( $meta, $field )
60
+ {
61
+ $i18n_title = apply_filters( 'rwmb_image_upload_string', _x( 'Upload Images', 'image upload', 'meta-box' ), $field );
62
+ $i18n_more = apply_filters( 'rwmb_image_add_string', _x( '+ Add new image', 'image upload', 'meta-box' ), $field );
63
+
64
+ // Uploaded images
65
+ $html = self::get_uploaded_images( $meta, $field );
66
+
67
+ // Show form upload
68
+ $html .= sprintf(
69
+ '<h4>%s</h4>
70
+ <div class="new-files">
71
+ <div class="file-input"><input type="file" name="%s[]" /></div>
72
+ <a class="mashsb-rwmb-add-file" href="#"><strong>%s</strong></a>
73
+ </div>',
74
+ $i18n_title,
75
+ $field['id'],
76
+ $i18n_more
77
+ );
78
+
79
+ return $html;
80
+ }
81
+
82
+ /**
83
+ * Get HTML markup for uploaded images
84
+ *
85
+ * @param array $images
86
+ * @param array $field
87
+ *
88
+ * @return string
89
+ */
90
+ static function get_uploaded_images( $images, $field )
91
+ {
92
+ $reorder_nonce = wp_create_nonce( "mashsb-rwmb-reorder-images_{$field['id']}" );
93
+ $delete_nonce = wp_create_nonce( "mashsb-rwmb-delete-file_{$field['id']}" );
94
+ $classes = array( 'mashsb-rwmb-images', 'mashsb-rwmb-uploaded' );
95
+ if ( count( $images ) <= 0 )
96
+ $classes[] = 'hidden';
97
+ $list = '<ul class="%s" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s">';
98
+ $html = sprintf(
99
+ $list,
100
+ implode( ' ', $classes ),
101
+ $field['id'],
102
+ $delete_nonce,
103
+ $reorder_nonce,
104
+ $field['force_delete'] ? 1 : 0,
105
+ $field['max_file_uploads']
106
+ );
107
+
108
+ foreach ( $images as $image )
109
+ {
110
+ $html .= self::img_html( $image );
111
+ }
112
+ $html .= '</ul>';
113
+ return $html;
114
+ }
115
+
116
+ /**
117
+ * Get HTML markup for ONE uploaded image
118
+ *
119
+ * @param int $image Image ID
120
+ * @return string
121
+ */
122
+ static function img_html( $image )
123
+ {
124
+ $i18n_delete = apply_filters( 'rwmb_image_delete_string', _x( 'Delete', 'image upload', 'meta-box' ) );
125
+ $i18n_edit = apply_filters( 'rwmb_image_edit_string', _x( 'Edit', 'image upload', 'meta-box' ) );
126
+ $item = '
127
+ <li id="item_%s">
128
+ <img src="%s" />
129
+ <div class="mashsb-rwmb-image-bar">
130
+ <a title="%s" class="mashsb-rwmb-edit-file" href="%s" target="_blank" rel="noopener">%s</a> |
131
+ <a title="%s" class="mashsb-rwmb-delete-file" href="#" data-attachment_id="%s">&times;</a>
132
+ </div>
133
+ </li>
134
+ ';
135
+
136
+ $src = wp_get_attachment_image_src( $image, 'thumbnail' );
137
+ $src = $src[0];
138
+ $link = get_edit_post_link( $image );
139
+
140
+ return sprintf(
141
+ $item,
142
+ $image,
143
+ $src,
144
+ $i18n_edit, $link, $i18n_edit,
145
+ $i18n_delete, $image
146
+ );
147
+ }
148
+
149
+ /**
150
+ * Output the field value
151
+ * Display unordered list of images with option for size and link to full size
152
+ *
153
+ * @param array $field Field parameters
154
+ * @param array $args Additional arguments. Not used for these fields.
155
+ * @param int|null $post_id Post ID. null for current post. Optional.
156
+ *
157
+ * @return mixed Field value
158
+ */
159
+ static function the_value( $field, $args = array(), $post_id = null )
160
+ {
161
+ $value = self::get_value( $field, $args, $post_id );
162
+ if ( ! $value )
163
+ return '';
164
+
165
+ $output = '<ul>';
166
+ foreach ( $value as $file_info )
167
+ {
168
+ $img = sprintf(
169
+ '<img src="%s" alt="%s" title="%s">',
170
+ esc_url( $file_info['url'] ),
171
+ esc_attr( $file_info['alt'] ),
172
+ esc_attr( $file_info['title'] )
173
+ );
174
+
175
+ // Link thumbnail to full size image?
176
+ if ( isset( $args['link'] ) && $args['link'] )
177
+ {
178
+ $img = sprintf(
179
+ '<a href="%s" title="%s">%s</a>',
180
+ esc_url( $file_info['full_url'] ),
181
+ esc_attr( $file_info['title'] ),
182
+ $img
183
+ );
184
+ }
185
+
186
+ $output .= "<li>$img</li>";
187
+ }
188
+ $output .= '</ul>';
189
+
190
+ return $output;
191
+ }
192
+
193
+ /**
194
+ * Get uploaded file information
195
+ *
196
+ * @param int $file_id Attachment image ID (post ID). Required.
197
+ * @param array $args Array of arguments (for size).
198
+ *
199
+ * @return array|bool False if file not found. Array of image info on success
200
+ */
201
+ static function file_info( $file_id, $args = array() )
202
+ {
203
+ $args = wp_parse_args( $args, array(
204
+ 'size' => 'thumbnail',
205
+ ) );
206
+
207
+ $img_src = wp_get_attachment_image_src( $file_id, $args['size'] );
208
+ if ( ! $img_src )
209
+ {
210
+ return false;
211
+ }
212
+
213
+ $attachment = get_post( $file_id );
214
+ $path = get_attached_file( $file_id );
215
+ $info = array(
216
+ 'ID' => $file_id,
217
+ 'name' => basename( $path ),
218
+ 'path' => $path,
219
+ 'url' => $img_src[0],
220
+ 'width' => $img_src[1],
221
+ 'height' => $img_src[2],
222
+ 'full_url' => wp_get_attachment_url( $file_id ),
223
+ 'title' => $attachment->post_title,
224
+ 'caption' => $attachment->post_excerpt,
225
+ 'description' => $attachment->post_content,
226
+ 'alt' => get_post_meta( $file_id, '_wp_attachment_image_alt', true ),
227
+ );
228
+ if ( function_exists( 'wp_get_attachment_image_srcset' ) )
229
+ {
230
+ $info['srcset'] = wp_get_attachment_image_srcset( $file_id );
231
+ }
232
+ return $info;
233
+ }
234
+ }
includes/admin/meta-box/inc/fields/validate-og.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
-
3
- /**
4
- * Custom HTML field class.
5
- */
6
- class MASHSB_RWMB_Validate_Og_Field extends MASHSB_RWMB_Field {
7
-
8
- /**
9
- * Get field HTML
10
- *
11
- * @param mixed $meta
12
- * @param array $field
13
- *
14
- * @return string
15
- */
16
- static function html( $meta, $field ) {
17
- global $post;
18
- $html = !empty( $field['std'] ) ? $field['std'] : '';
19
- if( !empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
20
- $html = call_user_func_array( $field['callback'], array($meta, $field) );
21
- }
22
- //return $html;
23
- //return get_permalink( $post->ID );
24
- return self::get_fb_debugger_url($post, $field);
25
- }
26
-
27
- /**
28
- * Link to the open graph debugger to check if open graph tags are valid
29
- *
30
- * @global array $post
31
- * @return string
32
- */
33
- static function get_fb_debugger_url($post, $field) {
34
- //var_dump( $post );
35
- if( isset( $post ) && $post->post_status == "publish" ) {
36
- $url = get_permalink( $post->ID );
37
- return '<a href="https://developers.facebook.com/tools/debug/og/object?q=' . $url . '" target="_blank" rel="noopener" class="button-small"> Validate Open Graph data </a>' . $field['helper'];
38
- } else {
39
- return '';
40
- }
41
- }
42
-
43
- }
1
+ <?php
2
+
3
+ /**
4
+ * Custom HTML field class.
5
+ */
6
+ class MASHSB_RWMB_Validate_Og_Field extends MASHSB_RWMB_Field {
7
+
8
+ /**
9
+ * Get field HTML
10
+ *
11
+ * @param mixed $meta
12
+ * @param array $field
13
+ *
14
+ * @return string
15
+ */
16
+ static function html( $meta, $field ) {
17
+ global $post;
18
+ $html = !empty( $field['std'] ) ? $field['std'] : '';
19
+ if( !empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
20
+ $html = call_user_func_array( $field['callback'], array($meta, $field) );
21
+ }
22
+ //return $html;
23
+ //return get_permalink( $post->ID );
24
+ return self::get_fb_debugger_url($post, $field);
25
+ }
26
+
27
+ /**
28
+ * Link to the open graph debugger to check if open graph tags are valid
29
+ *
30
+ * @global array $post
31
+ * @return string
32
+ */
33
+ static function get_fb_debugger_url($post, $field) {
34
+ //var_dump( $post );
35
+ if( isset( $post ) && $post->post_status == "publish" ) {
36
+ $url = get_permalink( $post->ID );
37
+ return '<a href="https://developers.facebook.com/tools/debug/og/object?q=' . $url . '" target="_blank" rel="noopener" class="button-small"> Validate Open Graph data </a>' . $field['helper'];
38
+ } else {
39
+ return '';
40
+ }
41
+ }
42
+
43
+ }
includes/scripts.php CHANGED
@@ -71,7 +71,7 @@ function mashsb_load_scripts( $hook ) {
71
  $refresh = mashsb_is_cache_refresh() ? 1 : 0;
72
 
73
  wp_localize_script( 'mashsb', 'mashsb', array(
74
- 'shares' => isset($post->ID) ? mashsb_get_total_shares_post_meta($post->ID) + getFakecount() : false,
75
  'round_shares' => isset( $mashsb_options['mashsharer_round'] ),
76
  /* Do not animate shares on blog posts. The share count would be wrong there and performance bad */
77
  'animate_shares' => isset( $mashsb_options['animate_shares'] ) && is_singular() ? 1 : 0,
71
  $refresh = mashsb_is_cache_refresh() ? 1 : 0;
72
 
73
  wp_localize_script( 'mashsb', 'mashsb', array(
74
+ 'shares' => isset($post->ID) ? mashsb_get_total_shares_post_meta($post->ID) + (int)getFakecount() : false,
75
  'round_shares' => isset( $mashsb_options['mashsharer_round'] ),
76
  /* Do not animate shares on blog posts. The share count would be wrong there and performance bad */
77
  'animate_shares' => isset( $mashsb_options['animate_shares'] ) && is_singular() ? 1 : 0,
includes/sharecount-functions.php CHANGED
@@ -46,7 +46,7 @@ function mashsb_set_fb_sharecount() {
46
  update_post_meta( $postId, 'mashsb_jsonshares', json_encode($cacheJsonShares) );
47
 
48
  $newTotalShares = mashsb_get_total_shares($postId);
49
- if ($newTotalShares > $cacheTotalShares){
50
  update_post_meta( $postId, 'mashsb_shares', $newTotalShares );
51
  }
52
  wp_die( json_encode( $cacheJsonShares ) );
@@ -161,7 +161,7 @@ function mashsb_get_total_shares_post_meta($postId = false){
161
 
162
  $result = get_post_meta( $postId, 'mashsb_shares', true );
163
 
164
- return $result;
165
  }
166
 
167
  /**
46
  update_post_meta( $postId, 'mashsb_jsonshares', json_encode($cacheJsonShares) );
47
 
48
  $newTotalShares = mashsb_get_total_shares($postId);
49
+ if ($newTotalShares > $cacheTotalShares && is_numeric($newTotalShares) ){
50
  update_post_meta( $postId, 'mashsb_shares', $newTotalShares );
51
  }
52
  wp_die( json_encode( $cacheJsonShares ) );
161
 
162
  $result = get_post_meta( $postId, 'mashsb_shares', true );
163
 
164
+ return (int)$result;
165
  }
166
 
167
  /**
includes/template-functions.php CHANGED
@@ -240,7 +240,7 @@ function getSharedcount( $url ) {
240
  * API share count is greater than real fresh requested share count ->
241
  */
242
 
243
- if( $mashsbShareCounts->total >= $mashsbStoredShareCount ) {
244
  update_post_meta( $post->ID, 'mashsb_shares', $mashsbShareCounts->total );
245
  update_post_meta( $post->ID, 'mashsb_jsonshares', json_encode( $mashsbShareCounts ) );
246
  MASHSB()->logger->info( "Refresh Cache: Update database with share count: " . $mashsbShareCounts->total );
@@ -1102,7 +1102,7 @@ function getFakecount() {
1102
  $fakecount = isset($mashsb_options['fake_count']) && is_numeric ($mashsb_options['fake_count']) ?
1103
  round( $mashsb_options['fake_count'] * mashsb_get_fake_factor(), 0 ) : 0;
1104
 
1105
- return $fakecount;
1106
 
1107
  }
1108
 
240
  * API share count is greater than real fresh requested share count ->
241
  */
242
 
243
+ if( is_numeric($mashsbShareCounts->total) && $mashsbShareCounts->total >= $mashsbStoredShareCount ) {
244
  update_post_meta( $post->ID, 'mashsb_shares', $mashsbShareCounts->total );
245
  update_post_meta( $post->ID, 'mashsb_jsonshares', json_encode( $mashsbShareCounts ) );
246
  MASHSB()->logger->info( "Refresh Cache: Update database with share count: " . $mashsbShareCounts->total );
1102
  $fakecount = isset($mashsb_options['fake_count']) && is_numeric ($mashsb_options['fake_count']) ?
1103
  round( $mashsb_options['fake_count'] * mashsb_get_fake_factor(), 0 ) : 0;
1104
 
1105
+ return (int)$fakecount;
1106
 
1107
  }
1108
 
mashshare.php CHANGED
@@ -6,7 +6,7 @@
6
  * Description: Mashshare is a Share functionality inspired by the the great website Mashable for Facebook and Twitter. More networks available.
7
  * Author: René Hermenau
8
  * Author URI: https://www.mashshare.net
9
- * Version: 3.5.1
10
  * Text Domain: mashsb
11
  * Domain Path: /languages
12
  * Credits: Thanks go to Pippin Williamson and the edd team. When we started with Mashshare we decided to use the EDD code base and
@@ -37,7 +37,7 @@ if( !defined( 'ABSPATH' ) )
37
 
38
  // Plugin version
39
  if( !defined( 'MASHSB_VERSION' ) ) {
40
- define( 'MASHSB_VERSION', '3.5.1' );
41
  }
42
 
43
  // Debug mode
6
  * Description: Mashshare is a Share functionality inspired by the the great website Mashable for Facebook and Twitter. More networks available.
7
  * Author: René Hermenau
8
  * Author URI: https://www.mashshare.net
9
+ * Version: 3.5.2
10
  * Text Domain: mashsb
11
  * Domain Path: /languages
12
  * Credits: Thanks go to Pippin Williamson and the edd team. When we started with Mashshare we decided to use the EDD code base and
37
 
38
  // Plugin version
39
  if( !defined( 'MASHSB_VERSION' ) ) {
40
+ define( 'MASHSB_VERSION', '3.5.2' );
41
  }
42
 
43
  // Debug mode
readme.txt CHANGED
@@ -9,7 +9,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Tags: Share buttons, Social Sharing, social media, Facebook, Twitter, Subscribe, Traffic posts, pages, widget, social share buttons, analytics, email, dsgvo
10
  Requires at least: 3.6+
11
  Tested up to: 4.9
12
- Stable tag: 3.5.1
13
 
14
  Social Media Share Buttons for Twitter, Facebook and other social networks. Highly customizable Social Media ecosystem
15
 
@@ -249,6 +249,9 @@ Read here more about this: http://docs.mashshare.net/article/10-facebook-is-show
249
 
250
  == Changelog ==
251
 
 
 
 
252
  = 3.5.1 =
253
  * Fix: Fake shares not added after latest update
254
  * Fix: Do not collect shares if page is previewed. Fixes an issue where shares from a post are collected from the main page, resulting in wrong share counts
@@ -321,5 +324,5 @@ https://www.mashshare.net/changelog/
321
 
322
  == Upgrade Notice ==
323
 
324
- = 3.4.8 =
325
- 3.4.8 * New shortcode options. Preparations for new MashShare count queue processing. Compatible up to WordPress 4.9.2
9
  Tags: Share buttons, Social Sharing, social media, Facebook, Twitter, Subscribe, Traffic posts, pages, widget, social share buttons, analytics, email, dsgvo
10
  Requires at least: 3.6+
11
  Tested up to: 4.9
12
+ Stable tag: 3.5.2
13
 
14
  Social Media Share Buttons for Twitter, Facebook and other social networks. Highly customizable Social Media ecosystem
15
 
249
 
250
  == Changelog ==
251
 
252
+ = 3.5.2 =
253
+ * Fix: Warning A non-numeric value encountered
254
+
255
  = 3.5.1 =
256
  * Fix: Fake shares not added after latest update
257
  * Fix: Do not collect shares if page is previewed. Fixes an issue where shares from a post are collected from the main page, resulting in wrong share counts
324
 
325
  == Upgrade Notice ==
326
 
327
+ = 3.5.2 =
328
+ 3.5.2 * Fix minor issues. Compatible up to WordPress 4.9.5