Post Duplicator - Version 2.2

Version Description

  • Updated metaboxer code.
Download this release

Release Info

Developer metaphorcreations
Plugin Icon 128x128 Post Duplicator
Version 2.2
Comparing to
See all releases

Code changes from version 2.0 to 2.2

assets/js/pd-admin.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready( function() {
2
+
3
+ /**
4
+ * Duplicate post listener.
5
+ *
6
+ * Creates an ajax request that creates a new post,
7
+ * duplicating all the data and custom meta.
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ jQuery( '.m4c-duplicate-post' ).click( function( e ) {
12
+
13
+ e.preventDefault();
14
+
15
+ // Create the data to pass
16
+ var data = {
17
+ action: 'm4c_duplicate_post',
18
+ original_id: jQuery(this).attr('href'),
19
+ security: jQuery(this).attr('rel')
20
+ };
21
+
22
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
23
+ jQuery.post( ajaxurl, data, function( response ) {
24
+
25
+ // Reload the page
26
+ location.reload();
27
+ });
28
+ });
29
+ });
includes/ajax.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'wp_ajax_m4c_duplicate_post', 'm4c_duplicate_post' );
4
+ /**
5
+ * Thehe jQuery ajax call to create a new post.
6
+ * Duplicates all the data including custom meta.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ function m4c_duplicate_post() {
11
+
12
+ // Get access to the database
13
+ global $wpdb;
14
+
15
+ // Check the nonce
16
+ check_ajax_referer( 'm4c_ajax_file_nonce', 'security' );
17
+
18
+ // Get variables
19
+ $original_id = $_POST['original_id'];
20
+
21
+ // Get the post as an array
22
+ $duplicate = get_post( $original_id, 'ARRAY_A' );
23
+
24
+ $settings = get_mtphr_post_duplicator_settings();
25
+
26
+ // Modify some of the elements
27
+ $duplicate['post_title'] = $duplicate['post_title'].' Copy';
28
+
29
+ // Set the status
30
+ if( $settings['status'] != 'same' ) {
31
+ $duplicate['post_status'] = $settings['status'];
32
+ }
33
+
34
+ // Set the post date
35
+ $timestamp = ( $settings['timestamp'] == 'duplicate' ) ? strtotime($duplicate['post_date']) : current_time('timestamp',0);
36
+ if( $settings['time_offset'] ) {
37
+ $offset = intval($settings['time_offset_seconds']+$settings['time_offset_minutes']*60+$settings['time_offset_hours']*3600+$settings['time_offset_days']*86400);
38
+ if( $settings['time_offset_direction'] == 'newer' ) {
39
+ $timestamp = intval($timestamp+$offset);
40
+ } else {
41
+ $timestamp = intval($timestamp-$offset);
42
+ }
43
+ }
44
+ $duplicate['post_date'] = date('Y-m-d H:i:s', $timestamp);
45
+
46
+ // Remove some of the keys
47
+ unset( $duplicate['ID'] );
48
+ unset( $duplicate['guid'] );
49
+ unset( $duplicate['comment_count'] );
50
+
51
+ // Insert the post into the database
52
+ $duplicate_id = wp_insert_post( $duplicate );
53
+
54
+ // Duplicate all the taxonomies/terms
55
+ $taxonomies = get_object_taxonomies( $duplicate['post_type'] );
56
+ foreach( $taxonomies as $taxonomy ) {
57
+ $terms = wp_get_post_terms( $original_id, $taxonomy, array('fields' => 'names') );
58
+ wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
59
+ }
60
+
61
+ // Duplicate all the custom fields
62
+ $custom_fields = get_post_custom( $original_id );
63
+ foreach ( $custom_fields as $key => $value ) {
64
+ add_post_meta( $duplicate_id, $key, maybe_unserialize($value[0]) );
65
+ }
66
+
67
+ echo 'Duplicate Post Created!';
68
+
69
+ die(); // this is required to return a proper result
70
+ }
includes/edit.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_filter( 'post_row_actions', 'mtphr_post_duplicator_action_row', 10, 2 );
4
+ add_filter( 'page_row_actions', 'mtphr_post_duplicator_action_row', 10, 2 );
5
+ /**
6
+ * Add a duplicate post link.
7
+ *
8
+ * @since 1.0.0
9
+ */
10
+ function mtphr_post_duplicator_action_row( $actions, $post ){
11
+
12
+ // Get the post type object
13
+ $post_type = get_post_type_object( $post->post_type );
14
+
15
+ // Create a nonce & add an action
16
+ $nonce = wp_create_nonce( 'm4c_ajax_file_nonce' );
17
+ $actions['duplicate_post'] = '<a class="m4c-duplicate-post" rel="'.$nonce.'" href="'.$post->ID.'">Duplicate '.$post_type->labels->singular_name.'</a>';
18
+
19
+ return $actions;
20
+ }
21
+
includes/functions.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Return a value from the options table if it exists,
5
+ * or return a default value
6
+ *
7
+ * @since 2.0
8
+ */
9
+ function get_mtphr_post_duplicator_settings() {
10
+
11
+ // Get the options
12
+ $settings = get_option('mtphr_post_duplicator_settings', array());
13
+
14
+ $defaults = array(
15
+ 'status' => 'same',
16
+ 'timestamp' => 'duplicate',
17
+ 'time_offset' => false,
18
+ 'time_offset_days' => 0,
19
+ 'time_offset_hours' => 0,
20
+ 'time_offset_minutes' => 0,
21
+ 'time_offset_seconds' => 0,
22
+ 'time_offset_direction' => 'newer'
23
+ );
24
+
25
+ // Filter the settings
26
+ $settings = apply_filters( 'mtphr_post_duplicator_settings', $settings );
27
+
28
+ // Return the settings
29
+ return wp_parse_args( $settings, $defaults );
30
+ }
includes/scripts.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Load Metaboxer
4
+ if( !function_exists('metaboxer_container') ) {
5
+
6
+ add_action( 'admin_enqueue_scripts', 'mtphr_post_duplicator_metaboxer_scripts' );
7
+ /**
8
+ * Load the metaboxer scripts
9
+ *
10
+ * @since 1.0
11
+ */
12
+ function mtphr_post_duplicator_metaboxer_scripts() {
13
+
14
+ // Load the style sheet
15
+ wp_register_style( 'mtphr-post-duplicator-metaboxer', MTPHR_POST_DUPLICATOR_URL.'/metaboxer/metaboxer.css', false, MTPHR_POST_DUPLICATOR_VERSION );
16
+ wp_enqueue_style( 'mtphr-post-duplicator-metaboxer' );
17
+
18
+ // Load the jQuery
19
+ wp_register_script( 'mtphr-post-duplicator-metaboxer', MTPHR_POST_DUPLICATOR_URL.'/metaboxer/metaboxer.js', array('jquery'), MTPHR_POST_DUPLICATOR_VERSION, true );
20
+ wp_enqueue_script( 'mtphr-post-duplicator-metaboxer' );
21
+ }
22
+ }
23
+
24
+
25
+
26
+
27
+ add_action( 'admin_enqueue_scripts', 'm4c_duplicate_post_scripts' );
28
+ /**
29
+ * Add the necessary jquery.
30
+ *
31
+ * @since 1.0.0
32
+ */
33
+ function m4c_duplicate_post_scripts( $hook_suffix ) {
34
+ if( $hook_suffix == 'edit.php' ) {
35
+ wp_enqueue_script( 'mtphr-post-duplicator', MTPHR_POST_DUPLICATOR_URL.'/assets/js/pd-admin.js', array('jquery'), MTPHR_POST_DUPLICATOR_VERSION );
36
+ }
37
+ }
includes/settings.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'admin_menu', 'mtphr_post_duplicator_settings_page' );
4
+ /**
5
+ * Add a menu page to display options
6
+ *
7
+ * @since 2.0
8
+ */
9
+ function mtphr_post_duplicator_settings_page() {
10
+
11
+ add_management_page(
12
+ 'Post Duplicator', // The value used to populate the browser's title bar when the menu page is active
13
+ 'Post Duplicator', // The label of this submenu item displayed in the menu
14
+ 'administrator', // What roles are able to access this submenu item
15
+ 'mtphr_post_duplicator_settings_menu', // The ID used to represent this submenu item
16
+ 'mtphr_post_duplicator_settings_display' // The callback function used to render the options for this submenu item
17
+ );
18
+ }
19
+
20
+
21
+
22
+
23
+ add_action( 'admin_init', 'mtphr_post_duplicator_initialize_settings' );
24
+ /**
25
+ * Initializes the options page.
26
+ *
27
+ * @since 2.2
28
+ */
29
+ function mtphr_post_duplicator_initialize_settings() {
30
+
31
+ $settings['status'] = array(
32
+ 'title' => __( 'Post Status', 'post-duplicator' ),
33
+ 'type' => 'select',
34
+ 'options' => array(
35
+ 'same' => __('Same as original', 'post-duplicator'),
36
+ 'draft' => __('Draft', 'post-duplicator'),
37
+ 'publish' => __('Published', 'post-duplicator'),
38
+ 'pending' => __('Pending', 'post-duplicator')
39
+ ),
40
+ 'default' => 'same'
41
+ );
42
+
43
+ $settings['timestamp'] = array(
44
+ 'title' => __( 'Post Date', 'post-duplicator' ),
45
+ 'type' => 'radio',
46
+ 'options' => array(
47
+ 'duplicate' => __('Duplicate Timestamp', 'post-duplicator'),
48
+ 'current' => __('Current Time', 'post-duplicator')
49
+ ),
50
+ 'display' => 'inline',
51
+ 'default' => 'duplicate'
52
+ );
53
+
54
+ $settings['time_offset'] = array(
55
+ 'title' => __( 'Offset Date', 'post-duplicator' ),
56
+ 'type' => 'checkbox',
57
+ 'append' => array(
58
+ 'time_offset_days' => array(
59
+ 'type' => 'text',
60
+ 'size' => 2,
61
+ 'after' => __(' days', 'post-duplicator'),
62
+ 'text_align' => 'right',
63
+ 'default' => 0
64
+ ),
65
+ 'time_offset_hours' => array(
66
+ 'type' => 'text',
67
+ 'size' => 2,
68
+ 'after' => __(' hours', 'post-duplicator'),
69
+ 'text_align' => 'right',
70
+ 'default' => 0
71
+ ),
72
+ 'time_offset_minutes' => array(
73
+ 'type' => 'text',
74
+ 'size' => 2,
75
+ 'after' => __(' minutes', 'post-duplicator'),
76
+ 'text_align' => 'right',
77
+ 'default' => 0
78
+ ),
79
+ 'time_offset_seconds' => array(
80
+ 'type' => 'text',
81
+ 'size' => 2,
82
+ 'after' => __(' seconds', 'post-duplicator'),
83
+ 'text_align' => 'right',
84
+ 'default' => 0
85
+ ),
86
+ 'time_offset_direction' => array(
87
+ 'type' => 'select',
88
+ 'options' => array(
89
+ 'newer' => __('newer', 'post-duplicator'),
90
+ 'older' => __('older', 'post-duplicator')
91
+ ),
92
+ 'default' => 'newer'
93
+ )
94
+ )
95
+ );
96
+
97
+ if( false == get_option('mtphr_post_duplicator_settings') ) {
98
+ add_option( 'mtphr_post_duplicator_settings' );
99
+ }
100
+
101
+ /* Register the style options */
102
+ add_settings_section(
103
+ 'mtphr_post_duplicator_settings_section', // ID used to identify this section and with which to register options
104
+ '', // Title to be displayed on the administration page
105
+ 'mtphr_post_duplicator_settings_callback', // Callback used to render the description of the section
106
+ 'mtphr_post_duplicator_settings' // Page on which to add this section of options
107
+ );
108
+
109
+ $settings = apply_filters( 'mtphr_post_duplicator_settings', $settings );
110
+
111
+ if( is_array($settings) ) {
112
+ foreach( $settings as $id => $setting ) {
113
+ $setting['option'] = 'mtphr_post_duplicator_settings';
114
+ $setting['option_id'] = $id;
115
+ $setting['id'] = 'mtphr_post_duplicator_settings['.$id.']';
116
+ add_settings_field( $setting['id'], $setting['title'], 'mtphr_post_duplicator_field_display', 'mtphr_post_duplicator_settings', 'mtphr_post_duplicator_settings_section', $setting);
117
+ }
118
+ }
119
+
120
+ // Register the fields with WordPress
121
+ register_setting( 'mtphr_post_duplicator_settings', 'mtphr_post_duplicator_settings' );
122
+ }
123
+
124
+
125
+
126
+
127
+ /**
128
+ * Renders a simple page to display for the theme menu defined above.
129
+ *
130
+ * @since 2.0
131
+ */
132
+ function mtphr_post_duplicator_settings_display() {
133
+ ?>
134
+ <div class="wrap">
135
+
136
+ <h2><?php _e( 'Post Duplicator Settings', 'post-duplicator' ); ?></h2>
137
+ <?php settings_errors(); ?>
138
+
139
+ <form method="post" action="options.php">
140
+ <?php
141
+ settings_fields( 'mtphr_post_duplicator_settings' );
142
+ do_settings_sections( 'mtphr_post_duplicator_settings' );
143
+ submit_button();
144
+ ?>
145
+ </form>
146
+
147
+ </div><!-- /.wrap -->
148
+ <?php
149
+ }
150
+
151
+
152
+
153
+
154
+ /**
155
+ * The callback function for the settings sections.
156
+ *
157
+ * @since 2.0
158
+ */
159
+ function mtphr_post_duplicator_settings_callback() {
160
+ echo '<h4>Customize the settings for duplicated posts.</h4>';
161
+ }
162
+
163
+
164
+
165
+
166
+ /**
167
+ * The custom field callback.
168
+ *
169
+ * @since 1.0
170
+ */
171
+ function mtphr_post_duplicator_field_display( $args ) {
172
+
173
+ // First, we read the options collection
174
+ if( isset($args['option']) ) {
175
+ $options = get_option( $args['option'] );
176
+ $value = isset( $options[$args['option_id']] ) ? $options[$args['option_id']] : '';
177
+ } else {
178
+ $value = get_option( $args['id'] );
179
+ }
180
+ if( $value == '' && isset($args['default']) ) {
181
+ $value = $args['default'];
182
+ }
183
+ if( isset($args['type']) ) {
184
+
185
+ echo '<div class="mtphr-post-duplicator-metaboxer-field mtphr-post-duplicator-metaboxer-'.$args['type'].'">';
186
+
187
+ // Call the function to display the field
188
+ if ( function_exists('mtphr_post_duplicator_metaboxer_'.$args['type']) ) {
189
+ call_user_func( 'mtphr_post_duplicator_metaboxer_'.$args['type'], $args, $value );
190
+ }
191
+
192
+ echo '<div>';
193
+ }
194
+
195
+ // Add a descriptions
196
+ if( isset($args['description']) ) {
197
+ echo '<span class="description"><small>'.$args['description'].'</small></span>';
198
+ }
199
+ }
200
+
201
+
languages/post-duplicator-en_US.mo ADDED
Binary file
languages/post-duplicator-en_US.po ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Post Duplicator v2.2\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: 2013-02-07 20:29:35+0000\n"
7
+ "Last-Translator: admin <joe@metaphorcreations.com>\n"
8
+ "Language-Team: \n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
+ "X-Generator: CSL v1.x\n"
14
+ "X-Poedit-Language: English\n"
15
+ "X-Poedit-Country: UNITED STATES\n"
16
+ "X-Poedit-SourceCharset: utf-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
18
+ "X-Poedit-Basepath: \n"
19
+ "X-Poedit-Bookmarks: \n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Textdomain-Support: yes"
22
+
23
+ #: includes/settings.php:32
24
+ #@ post-duplicator
25
+ msgid "Post Status"
26
+ msgstr ""
27
+
28
+ #: includes/settings.php:35
29
+ #@ post-duplicator
30
+ msgid "Same as original"
31
+ msgstr ""
32
+
33
+ #: includes/settings.php:36
34
+ #@ post-duplicator
35
+ msgid "Draft"
36
+ msgstr ""
37
+
38
+ #: includes/settings.php:37
39
+ #@ post-duplicator
40
+ msgid "Published"
41
+ msgstr ""
42
+
43
+ #: includes/settings.php:38
44
+ #@ post-duplicator
45
+ msgid "Pending"
46
+ msgstr ""
47
+
48
+ #: includes/settings.php:44
49
+ #@ post-duplicator
50
+ msgid "Post Date"
51
+ msgstr ""
52
+
53
+ #: includes/settings.php:47
54
+ #@ post-duplicator
55
+ msgid "Duplicate Timestamp"
56
+ msgstr ""
57
+
58
+ #: includes/settings.php:48
59
+ #@ post-duplicator
60
+ msgid "Current Time"
61
+ msgstr ""
62
+
63
+ #: includes/settings.php:55
64
+ #@ post-duplicator
65
+ msgid "Offset Date"
66
+ msgstr ""
67
+
68
+ #: includes/settings.php:61
69
+ #@ post-duplicator
70
+ msgid " days"
71
+ msgstr ""
72
+
73
+ #: includes/settings.php:68
74
+ #@ post-duplicator
75
+ msgid " hours"
76
+ msgstr ""
77
+
78
+ #: includes/settings.php:75
79
+ #@ post-duplicator
80
+ msgid " minutes"
81
+ msgstr ""
82
+
83
+ #: includes/settings.php:82
84
+ #@ post-duplicator
85
+ msgid " seconds"
86
+ msgstr ""
87
+
88
+ #: includes/settings.php:89
89
+ #@ post-duplicator
90
+ msgid "newer"
91
+ msgstr ""
92
+
93
+ #: includes/settings.php:90
94
+ #@ post-duplicator
95
+ msgid "older"
96
+ msgstr ""
97
+
98
+ #: includes/settings.php:136
99
+ #@ post-duplicator
100
+ msgid "Post Duplicator Settings"
101
+ msgstr ""
102
+
103
+ #: metaboxer/metaboxer.php:943
104
+ #@ post-duplicator
105
+ msgid "Select Code"
106
+ msgstr ""
107
+
m4c-postduplicator.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Post Duplicator
4
  Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
5
- Version: 2.0
6
  Author: Metaphor Creations
7
  Author URI: http://www.metaphorcreations.com
8
  License: GPL2
@@ -30,9 +30,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
 
31
  /**Define Widget Constants */
32
  if ( WP_DEBUG ) {
33
- define ( 'MTPHR_POST_DUPLICATOR_VERSION', '2.0-'.time() );
34
  } else {
35
- define ( 'MTPHR_POST_DUPLICATOR_VERSION', '2.0' );
36
  }
37
  define ( 'MTPHR_POST_DUPLICATOR_DIR', plugin_dir_path(__FILE__) );
38
  define ( 'MTPHR_POST_DUPLICATOR_URL', plugins_url().'/post-duplicator' );
@@ -40,6 +40,19 @@ define ( 'MTPHR_POST_DUPLICATOR_URL', plugins_url().'/post-duplicator' );
40
 
41
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  /**
44
  * Include files.
45
  *
@@ -48,11 +61,8 @@ define ( 'MTPHR_POST_DUPLICATOR_URL', plugins_url().'/post-duplicator' );
48
  if ( is_admin() ) {
49
 
50
  // Load Metaboxer
51
- if( !function_exists('metaboxer_container') ) {
52
- require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer.php' );
53
- require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer-class.php' );
54
- }
55
-
56
  require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/scripts.php' );
57
  require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/ajax.php' );
58
  require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/edit.php' );
2
  /*
3
  Plugin Name: Post Duplicator
4
  Description: Creates functionality to duplicate any and all post types, including taxonomies & custom fields
5
+ Version: 2.2
6
  Author: Metaphor Creations
7
  Author URI: http://www.metaphorcreations.com
8
  License: GPL2
30
 
31
  /**Define Widget Constants */
32
  if ( WP_DEBUG ) {
33
+ define ( 'MTPHR_POST_DUPLICATOR_VERSION', '2.2-'.time() );
34
  } else {
35
+ define ( 'MTPHR_POST_DUPLICATOR_VERSION', '2.2' );
36
  }
37
  define ( 'MTPHR_POST_DUPLICATOR_DIR', plugin_dir_path(__FILE__) );
38
  define ( 'MTPHR_POST_DUPLICATOR_URL', plugins_url().'/post-duplicator' );
40
 
41
 
42
 
43
+ add_action( 'plugins_loaded', 'mtphr_post_duplicator_localization' );
44
+ /**
45
+ * Setup localization
46
+ *
47
+ * @since 2.1.2
48
+ */
49
+ function mtphr_post_duplicator_localization() {
50
+ load_plugin_textdomain( 'post-duplicator', false, MTPHR_POST_DUPLICATOR_DIR.'/languages/' );
51
+ }
52
+
53
+
54
+
55
+
56
  /**
57
  * Include files.
58
  *
61
  if ( is_admin() ) {
62
 
63
  // Load Metaboxer
64
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer.php' );
65
+ require_once( MTPHR_POST_DUPLICATOR_DIR.'metaboxer/metaboxer-class.php' );
 
 
 
66
  require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/scripts.php' );
67
  require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/ajax.php' );
68
  require_once( MTPHR_POST_DUPLICATOR_DIR.'includes/edit.php' );
metaboxer/images/attachment-audio.png ADDED
Binary file
metaboxer/images/attachment-delete.png ADDED
Binary file
metaboxer/images/attachment-image.png ADDED
Binary file
metaboxer/images/attachment-preview.png ADDED
Binary file
metaboxer/images/attachment-settings.png ADDED
Binary file
metaboxer/images/attachment-video.png ADDED
Binary file
metaboxer/images/attachment-vimeo.png ADDED
Binary file
metaboxer/images/attachment-youtube.png ADDED
Binary file
metaboxer/metaboxer-class.php ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This is where the metabox magic happens.
4
+ *
5
+ * @package Ditty News Ticker
6
+ * @author Metaphor Creations
7
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
8
+ * @link http://www.metaphorcreations.com/plugins/metatools
9
+ **/
10
+
11
+ /* Version 1.1 - 10/18/2012 */
12
+
13
+
14
+
15
+
16
+ /**
17
+ * Create the metabox class
18
+ *
19
+ * @since 1.0.0
20
+ */
21
+ if( !class_exists('MTPHR_POST_DUPLICATOR_MetaBoxer') ) {
22
+
23
+ class MTPHR_POST_DUPLICATOR_MetaBoxer {
24
+
25
+ public function __construct( $meta_box ) {
26
+
27
+ if ( !is_admin() ) return;
28
+
29
+ // Save the meta box data
30
+ $this->mb = $meta_box;
31
+ $this->mb_fields = &$this->mb['fields'];
32
+
33
+ add_action( 'add_meta_boxes', array(&$this, 'mtphr_post_duplicator_metaboxer_add') );
34
+ add_action( 'save_post', array(&$this, 'mtphr_post_duplicator_metaboxer_save') );
35
+ }
36
+
37
+
38
+
39
+
40
+ /**
41
+ * Create the metaboxes
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ public function mtphr_post_duplicator_metaboxer_add() {
46
+
47
+ foreach ( $this->mb['page'] as $page ) {
48
+ add_meta_box( $this->mb['id'], $this->mb['title'], array(&$this, 'mtphr_post_duplicator_metaboxer_render_content'), $page, $this->mb['context'], $this->mb['priority'] );
49
+ }
50
+ }
51
+
52
+
53
+
54
+
55
+ /**
56
+ * Render the metabox content
57
+ *
58
+ * @since 1.0.0
59
+ */
60
+ public function mtphr_post_duplicator_metaboxer_render_content() {
61
+ ?>
62
+ <table style="width:100%;" class="mtphr-post-duplicator-metaboxer-admin-fields wrap">
63
+ <?php
64
+ foreach( $this->mb_fields as $field ) {
65
+
66
+ if ( isset( $field['id'] ) ) {
67
+ // Create a nonce field
68
+ echo'<input type="hidden" name="'.$field['id'].'_noncename" id="'.$field['id'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
69
+ }
70
+
71
+ // Output the field
72
+ mtphr_post_duplicator_metaboxer_container( $field, $this->mb['context'] );
73
+ }
74
+ ?>
75
+ </table>
76
+ <?php
77
+ }
78
+
79
+
80
+
81
+
82
+ /**
83
+ * Save the field values
84
+ *
85
+ * @since 1.0.0
86
+ */
87
+ public function mtphr_post_duplicator_metaboxer_save( $post_id ) {
88
+
89
+ global $post;
90
+
91
+ foreach( $this->mb_fields as $field ) {
92
+
93
+ if ( isset($field['id']) ) {
94
+
95
+ if ( isset($_POST[$field['id'].'_noncename']) ) {
96
+
97
+ // Verify the nonce and return if false
98
+ if ( !wp_verify_nonce($_POST[$field['id'].'_noncename'], plugin_basename(__FILE__)) ) {
99
+ return $post_id;
100
+ }
101
+
102
+ // Make sure the user can edit pages & posts
103
+ if ( 'page' == $_POST['post_type'] ) {
104
+ if ( !current_user_can('edit_page', $post_id) ) {
105
+ return $post_id;
106
+ }
107
+ } else {
108
+ if ( !current_user_can('edit_post', $post_id) ) {
109
+ return $post_id;
110
+ }
111
+ }
112
+
113
+ // Store the user data or set as empty string
114
+ $data = ( isset($_POST[$field['id']]) ) ? $_POST[$field['id']] : '';
115
+
116
+ // Update the meta
117
+ mtphr_post_duplicator_metaboxer_update_meta( $post_id, $field['id'], $field['type'], $data );
118
+
119
+ // Save appended fields
120
+ mtphr_post_duplicator_metaboxer_save_appended( $post_id, $field );
121
+
122
+ // Save row fields
123
+ mtphr_post_duplicator_metaboxer_save_rows( $post_id, $field );
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Save the row field values
132
+ *
133
+ * @since 1.0.0
134
+ */
135
+ function mtphr_post_duplicator_metaboxer_save_rows( $post_id, $field ) {
136
+
137
+ if( isset($field['rows']) ) {
138
+
139
+ foreach( $field['rows'] as $id => $row ) {
140
+
141
+ $row_id = $row['id'];
142
+
143
+ // Store the user data or set as empty string
144
+ $data = ( isset($_POST[$row_id]) ) ? $_POST[$row_id] : '';
145
+
146
+ // Update the meta
147
+ mtphr_post_duplicator_metaboxer_update_meta( $post_id, $row_id, $row['type'], $data );
148
+
149
+ // Save appended fields
150
+ mtphr_post_duplicator_metaboxer_save_appended( $post_id, $row );
151
+ }
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Save the appended field values
157
+ *
158
+ * @since 1.0.0
159
+ */
160
+ function mtphr_post_duplicator_metaboxer_save_appended( $post_id, $field ) {
161
+
162
+ if( isset($field['append']) ) {
163
+
164
+ foreach( $field['append'] as $id => $append ) {
165
+
166
+ // Store the user data or set as empty string
167
+ $data = ( isset($_POST[$id]) ) ? $_POST[$id] : '';
168
+
169
+ // Update the meta
170
+ mtphr_post_duplicator_metaboxer_update_meta( $post_id, $id, $append['type'], $data );
171
+ }
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Update the meta
177
+ *
178
+ * @since 1.0.0
179
+ */
180
+ function mtphr_post_duplicator_metaboxer_update_meta( $post_id, $id, $type, $data ) {
181
+
182
+ // Update the post meta
183
+ update_post_meta( $post_id, $id, $data );
184
+ }
185
+
186
+ }
metaboxer/metaboxer.css ADDED
@@ -0,0 +1,524 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Table of Contents
2
+
3
+ * Media Uploader
4
+ * General
5
+ * Fields
6
+ * Labels
7
+ * Content
8
+
9
+ * File
10
+ * Lists
11
+ * Sorts
12
+ * Code
13
+ * Radio
14
+ * Checkbox
15
+ * WYSIWYG
16
+ * Farbtastic
17
+ * jQuery Slider
18
+ * Pattern Select
19
+ * Image Select
20
+ * Attachments
21
+ * Single Image
22
+ * Clearfix
23
+ * Custom
24
+
25
+ */
26
+
27
+ /* General
28
+ ------------------------------------------------------------ */
29
+
30
+ .mtphr-post-duplicator-metaboxer-admin-fields {
31
+ padding-top: 10px;
32
+ }
33
+ .mtphr-post-duplicator-metaboxer-loading-gif {
34
+ opacity: 0;
35
+ }
36
+ .mtphr-post-duplicator-metaboxer-appended {
37
+ display: inline;
38
+ margin-left: 10px;
39
+ }
40
+
41
+
42
+ /* Fields
43
+ ------------------------------------------------------------ */
44
+
45
+ .mtphr-post-duplicator-metaboxer-field {
46
+ margin-bottom: 20px;
47
+ }
48
+ #side-info-column .mtphr-post-duplicator-metaboxer-field {
49
+ margin-bottom: 10px;
50
+ }
51
+ .mtphr-post-duplicator-metaboxer-field:last-child {
52
+ margin-bottom: 20px;
53
+ }
54
+
55
+ /* Labels
56
+ ------------------------------------------------------------ */
57
+
58
+ .mtphr-post-duplicator-metaboxer-label {
59
+ vertical-align: top;
60
+ width: 20%;
61
+ overflow: hidden;
62
+ padding-bottom: 20px;
63
+ padding-right: 20px;
64
+ }
65
+ .mtphr-post-duplicator-metaboxer-label label {
66
+ display: block;
67
+ font-weight: bold;
68
+ font-size: 12px;
69
+ }
70
+ .mtphr-post-duplicator-metaboxer-label small {
71
+ font-size: 10px;
72
+ font-style: italic;
73
+ }
74
+ #side-sortables .mtphr-post-duplicator-metaboxer-label {
75
+ width: auto;
76
+ margin: 0;
77
+ padding: 0;
78
+ }
79
+
80
+ /* Content
81
+ ------------------------------------------------------------ */
82
+ .mtphr-post-duplicator-metaboxer-field-content {
83
+ width: 80%;
84
+ vertical-align: top;
85
+ padding-bottom: 20px;
86
+ }
87
+ .mtphr-post-duplicator-metaboxer-field-content-full {
88
+ width: 100%;
89
+ }
90
+ .vertical .mtphr-post-duplicator-metaboxer-field-content,
91
+ #side-sortables .vertical .mtphr-post-duplicator-metaboxer-field-content {
92
+ float: none;
93
+ width: auto;
94
+ }
95
+
96
+ /* File
97
+ ------------------------------------------------------------ */
98
+
99
+ .wp-core-ui .mtphr-post-duplicator-metaboxer-file-upload {
100
+ display: none;
101
+ }
102
+ .mtphr-post-duplicator-metaboxer-file-table {
103
+ width: 100%;
104
+ }
105
+ .mtphr-post-duplicator-metaboxer-file-display a {
106
+ display: block;
107
+ margin: 0;
108
+ padding: 10px;
109
+ background: #FEFEFE;
110
+ border: 1px solid #EEE;
111
+ white-space: normal;
112
+ text-decoration: none;
113
+
114
+ -webkit-border-radius: 5px;
115
+ -moz-border-radius: 5px;
116
+ border-radius: 5px;
117
+ }
118
+ .mtphr-post-duplicator-metaboxer-file-display img {
119
+ display: block;
120
+ float: left;
121
+ margin-right: 10px;
122
+ }
123
+ .mtphr-post-duplicator-metaboxer-file-display span {
124
+ text-decoration: none;
125
+ }
126
+ .mtphr-post-duplicator-metaboxer-file-delete {
127
+ width: 16px;
128
+ padding-top: 4px !important;
129
+ }
130
+ .mtphr-post-duplicator-metaboxer-file-delete a {
131
+ display: block;
132
+ text-indent: -9999px;
133
+ width: 16px;
134
+ height: 16px;
135
+ background: url(images/minus-circle.png) no-repeat top;
136
+ }
137
+ .mtphr-post-duplicator-metaboxer-file-delete a:hover {
138
+ background-position: 0 -16px;
139
+ }
140
+
141
+ /* List Item
142
+ ------------------------------------------------------------ */
143
+
144
+ .mtphr-post-duplicator-metaboxer-list > table {
145
+ width: 100%;
146
+ }
147
+ .mtphr-post-duplicator-metaboxer-list th,
148
+ .mtphr-post-duplicator-metaboxer-list td {
149
+ text-align: left;
150
+ vertical-align: top;
151
+ padding: 0 3px;
152
+ }
153
+ .mtphr-post-duplicator-metaboxer-list input[type="text"],
154
+ .mtphr-post-duplicator-metaboxer-list input[type="number"],
155
+ .mtphr-post-duplicator-metaboxer-list input[type="email"],
156
+ .mtphr-post-duplicator-metaboxer-list input[type="password"],
157
+ .mtphr-post-duplicator-metaboxer-list textarea {
158
+ width: 100%;
159
+ }
160
+ .mtphr-post-duplicator-metaboxer-list-item-handle,
161
+ .mtphr-post-duplicator-metaboxer-list-item-add,
162
+ .mtphr-post-duplicator-metaboxer-list-item-delete {
163
+ width: 16px;
164
+ padding-top: 4px !important;
165
+ }
166
+ .mtphr-post-duplicator-metaboxer-list-item-handle span,
167
+ .mtphr-post-duplicator-metaboxer-list-item-add a,
168
+ .mtphr-post-duplicator-metaboxer-list-item-delete a {
169
+ display: block;
170
+ text-indent: -9999px;
171
+ width: 16px;
172
+ height: 16px;
173
+ }
174
+ .mtphr-post-duplicator-metaboxer-list-item-handle span {
175
+ background: url(images/arrow-resize-090.png) no-repeat top;
176
+ }
177
+ .mtphr-post-duplicator-metaboxer-list-item-add a {
178
+ background: url(images/plus-circle.png) no-repeat top;
179
+ }
180
+ .mtphr-post-duplicator-metaboxer-list-item-delete a {
181
+ background: url(images/minus-circle.png) no-repeat top;
182
+ }
183
+ .mtphr-post-duplicator-metaboxer-list-item-handle span:hover,
184
+ .mtphr-post-duplicator-metaboxer-list-item-add a:hover,
185
+ .mtphr-post-duplicator-metaboxer-list-item-delete a:hover {
186
+ background-position: 0 -16px;
187
+ }
188
+
189
+ /* Sorts
190
+ ------------------------------------------------------------ */
191
+
192
+ .mtphr-post-duplicator-metaboxer-sort td {
193
+ padding: 6px 3px;
194
+ border-bottom: 1px dashed #CCC;
195
+ }
196
+ .mtphr-post-duplicator-metaboxer-sort td.mtphr-post-duplicator-metaboxer-sort-name {
197
+ font-weight: bold;
198
+ padding-right: 10px;
199
+ }
200
+ .mtphr-post-duplicator-metaboxer-sort td.mtphr-post-duplicator-metaboxer-sort-item-handle {
201
+ width: 16px;
202
+ padding-top: 2px !important;
203
+ border: none;
204
+ }
205
+ .mtphr-post-duplicator-metaboxer-sort-item-handle span {
206
+ display: block;
207
+ text-indent: -9999px;
208
+ width: 16px;
209
+ height: 16px;
210
+ background: url(images/arrow-resize-090.png) no-repeat top;
211
+ }
212
+ .mtphr-post-duplicator-metaboxer-sort-item-handle span:hover {
213
+ background-position: 0 -16px;
214
+ }
215
+
216
+ /* Code
217
+ ------------------------------------------------------------ */
218
+
219
+ .mtphr-post-duplicator-metaboxer-code pre {
220
+ margin: 0 0 5px 0;
221
+ padding: 10px;
222
+ background: #FFF;
223
+ border: 1px solid #EEE;
224
+ white-space: normal;
225
+
226
+ -webkit-border-radius: 5px;
227
+ -moz-border-radius: 5px;
228
+ border-radius: 5px;
229
+ }
230
+ .mtphr-post-duplicator-metaboxer-code pre p {
231
+ margin: 0;
232
+ }
233
+
234
+ /* Radio
235
+ ------------------------------------------------------------ */
236
+
237
+ .mtphr-post-duplicator-metaboxer-radio input {
238
+ margin-top: 0;
239
+ margin-right: 1px;
240
+ }
241
+
242
+ /* Checkbox
243
+ ------------------------------------------------------------ */
244
+
245
+ .mtphr-post-duplicator-metaboxer-checkbox input {
246
+ margin-top: 0;
247
+ margin-right: 1px;
248
+ }
249
+
250
+ /* Textarea
251
+ ------------------------------------------------------------ */
252
+
253
+ .mtphr-post-duplicator-metaboxer-textarea textarea {
254
+ width: 96%;
255
+ }
256
+
257
+ /* WYSIWYG
258
+ ------------------------------------------------------------ */
259
+
260
+ .mtphr-post-duplicator-metaboxer-wysiwyg {
261
+ max-width: 800px;
262
+ }
263
+ .mtphr-post-duplicator-metaboxer-wysiwyg .mceIframeContainer {
264
+ background: #FFF;
265
+ }
266
+
267
+ /* Farbtastic
268
+ ------------------------------------------------------------ */
269
+
270
+ .farbtastic_cp {
271
+ float: left;
272
+ display: none;
273
+ }
274
+
275
+ /* jQuery Slider
276
+ ------------------------------------------------------------ */
277
+
278
+ .slider-value {
279
+ display: inline;
280
+ font-weight: bold;
281
+ line-height: 12px;
282
+ color: #3D759B;
283
+ border: none !important;
284
+ margin: 0 0 0 5px;
285
+ padding: 0;
286
+ }
287
+
288
+ /* Pattern Select
289
+ ------------------------------------------------------------ */
290
+
291
+ .mtphr-post-duplicator-metaboxer-pattern_select select {
292
+ margin-bottom: 5px;
293
+ }
294
+ .mtphr-post-duplicator-metaboxer-pattern-selection {
295
+ width: 200px;
296
+ height: 100px;
297
+ background-repeat: repeat;
298
+ }
299
+
300
+ /* Image Select
301
+ ------------------------------------------------------------ */
302
+
303
+ .mtphr-post-duplicator-metaboxer-image-select {
304
+ margin-bottom: 10px;
305
+ }
306
+ a.mtphr-post-duplicator-metaboxer-image-select-link {
307
+ display: block;
308
+ float: left;
309
+ margin: 0 10px 10px 0;
310
+ text-decoration: none;
311
+ }
312
+ a.mtphr-post-duplicator-metaboxer-image-select-link small {
313
+ display: block;
314
+ text-align: center;
315
+ font-weight: bold;
316
+ color: #333;
317
+ }
318
+ a.mtphr-post-duplicator-metaboxer-image-select-link img {
319
+ opacity: .5;
320
+ -webkit-transition: opacity .2s linear;
321
+ -moz-transition: opacity .2s linear;
322
+ -o-transition: opacity .2s linear;
323
+ -ms-transition: opacity .2s linear;
324
+ transition: opacity .2s linear;
325
+ }
326
+ a.mtphr-post-duplicator-metaboxer-image-select-link.selected img {
327
+ opacity: 1;
328
+ }
329
+
330
+
331
+ /* Attachments
332
+ ------------------------------------------------------------ */
333
+
334
+ .mtphr-post-duplicator-metaboxer-attachment-container {
335
+ margin: 0;
336
+ padding: 0;
337
+ }
338
+ .mtphr-post-duplicator-metaboxer-attachment-buttons {
339
+ margin-bottom: 10px;
340
+ }
341
+ .mtphr-post-duplicator-metaboxer-attachment-links {
342
+ opacity: 0;
343
+ -webkit-transition: opacity .2s linear;
344
+ -moz-transition: opacity .2s linear;
345
+ -o-transition: opacity .2s linear;
346
+ -ms-transition: opacity .2s linear;
347
+ transition: opacity .2s linear;
348
+ }
349
+ .mtphr-post-duplicator-metaboxer-gallery-attachment:hover .mtphr-post-duplicator-metaboxer-attachment-links,
350
+ .mtphr-post-duplicator-metaboxer-single-attachment:hover .mtphr-post-duplicator-metaboxer-attachment-links {
351
+ opacity: 1;
352
+ }
353
+ .mtphr-post-duplicator-metaboxer-attachment-preview,
354
+ .mtphr-post-duplicator-metaboxer-attachment-settings,
355
+ .mtphr-post-duplicator-metaboxer-attachment-delete {
356
+ display: inline-block;
357
+ opacity: .5;
358
+ -webkit-transition: opacity .2s linear;
359
+ -moz-transition: opacity .2s linear;
360
+ -o-transition: opacity .2s linear;
361
+ -ms-transition: opacity .2s linear;
362
+ transition: opacity .2s linear;
363
+ }
364
+ .mtphr-post-duplicator-metaboxer-attachment-preview:hover,
365
+ .mtphr-post-duplicator-metaboxer-attachment-settings:hover,
366
+ .mtphr-post-duplicator-metaboxer-attachment-delete:hover {
367
+ opacity: 1;
368
+ }
369
+ .mtphr-post-duplicator-metaboxer-attachment-preview {
370
+ position: absolute;
371
+ top: 10px;
372
+ left: 10px;
373
+ width: 17px;
374
+ height: 17px;
375
+ background: url(images/attachment-preview.png);
376
+ }
377
+ .mtphr-post-duplicator-metaboxer-attachment-settings {
378
+ position: absolute;
379
+ top: 10px;
380
+ right: 10px;
381
+ width: 17px;
382
+ height: 17px;
383
+ background: url(images/attachment-settings.png);
384
+ }
385
+ .mtphr-post-duplicator-metaboxer-attachment-delete {
386
+ position: absolute;
387
+ bottom: 10px;
388
+ right: 10px;
389
+ width: 14px;
390
+ height: 14px;
391
+ background: url(images/attachment-delete.png);
392
+ }
393
+ .mtphr-post-duplicator-metaboxer-attachment-mime-type {
394
+ position: absolute;
395
+ bottom: 10px;
396
+ left: 10px;
397
+ }
398
+ .mtphr-post-duplicator-metaboxer-attachment-mime-type-vimeo {
399
+ width: 20px;
400
+ height: 20px;
401
+ background: url(images/attachment-vimeo.png);
402
+ }
403
+ .mtphr-post-duplicator-metaboxer-attachment-mime-type-youtube {
404
+ width: 20px;
405
+ height: 23px;
406
+ background: url(images/attachment-youtube.png);
407
+ }
408
+ .mtphr-post-duplicator-metaboxer-attachment-mime-type-audio {
409
+ width: 20px;
410
+ height: 20px;
411
+ background: url(images/attachment-audio.png);
412
+ }
413
+ .mtphr-post-duplicator-metaboxer-attachment-mime-type-video {
414
+ width: 20px;
415
+ height: 20px;
416
+ background: url(images/attachment-video.png);
417
+ }
418
+ .mtphr-post-duplicator-metaboxer-attachment-mime-type-image {
419
+ width: 20px;
420
+ height: 20px;
421
+ background: url(images/attachment-image.png);
422
+ }
423
+ .mtphr-post-duplicator-metaboxer-gallery-attachment-container {
424
+ width:100%;
425
+ margin: 0;
426
+ }
427
+ .mtphr-post-duplicator-metaboxer-gallery-attachment {
428
+ position: relative;
429
+ float: left;
430
+ width: 120px;
431
+ height: 120px;
432
+
433
+ margin: 0 10px 10px 0;
434
+
435
+ -webkit-border-radius: 5px;
436
+ -moz-border-radius: 5px;
437
+ border-radius: 5px;
438
+
439
+ -moz-box-shadow: 2px 0 0px #000, inset 0 0 3px #DDD;
440
+ -webkit-box-shadow: 2px 0 0px #000, inset 0 0 3px #DDD;
441
+ box-shadow: 0 0 1px #000;
442
+
443
+ opacity: 1;
444
+ -webkit-transition: opacity .2s linear;
445
+ -moz-transition: opacity .2s linear;
446
+ -o-transition: opacity .2s linear;
447
+ -ms-transition: opacity .2s linear;
448
+ transition: opacity .2s linear;
449
+ }
450
+ .mtphr-post-duplicator-metaboxer-gallery-attachment:active {
451
+ opacity: .5;
452
+ }
453
+ .mtphr-post-duplicator-metaboxer-gallery-attachment-bg {
454
+ width: 120px;
455
+ height: 120px;
456
+ background-position: center center;
457
+ background-size: auto 120px;
458
+ -webkit-border-radius: 5px;
459
+ -moz-border-radius: 5px;
460
+ border-radius: 5px;
461
+ }
462
+ .mtphr-post-duplicator-metaboxer-gallery-attachment-bg-youtube {
463
+ background-size: auto 160px;
464
+ }
465
+ .mtphr-post-duplicator-metaboxer-gallery-attachment img {
466
+ -webkit-border-radius: 5px;
467
+ -moz-border-radius: 5px;
468
+ border-radius: 5px;
469
+ }
470
+ .mtphr-post-duplicator-metaboxer-gallery-attachment:active .mtphr-post-duplicator-metaboxer-attachment-links {
471
+ opacity: 0;
472
+ }
473
+ .attachment-mtphr-post-duplicator-metaboxer-gallery-thumb {
474
+ cursor: move;
475
+ -webkit-border-radius: 5px;
476
+ -moz-border-radius: 5px;
477
+ border-radius: 5px;
478
+ }
479
+
480
+ /* Single Image
481
+ ------------------------------------------------------------ */
482
+
483
+ .mtphr-post-duplicator-metaboxer-single-attachment {
484
+ float: left;
485
+ position: relative;
486
+ margin: 0;
487
+ padding: 0;
488
+ }
489
+ .mtphr-post-duplicator-metaboxer-single-attachment img {
490
+ max-width: 90%;
491
+ height: auto;
492
+ padding: 20px;
493
+ margin: 0;
494
+
495
+ -webkit-border-radius: 5px;
496
+ -moz-border-radius: 5px;
497
+ border-radius: 5px;
498
+
499
+ -moz-box-shadow: 2px 0 0px #000, inset 0 0 3px #DDD;
500
+ -webkit-box-shadow: 2px 0 0px #000, inset 0 0 3px #DDD;
501
+ box-shadow: 0 0 1px #000;
502
+ }
503
+
504
+ /* Clearfix
505
+ ------------------------------------------------------------ */
506
+
507
+ .clearfix {
508
+ *zoom: 1;
509
+ }
510
+ .clearfix:before,
511
+ .clearfix:after {
512
+ display: table;
513
+ content: "";
514
+ }
515
+ .clearfix:after {
516
+ clear: both;
517
+ }
518
+
519
+ /* Custom
520
+ ------------------------------------------------------------ */
521
+
522
+ #mtphr_post_duplicator_global_settings .mtphr-post-duplicator-metaboxer-field-content {
523
+ padding-bottom: 0;
524
+ }
metaboxer/metaboxer.js ADDED
@@ -0,0 +1,383 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Table of Contents
2
+
3
+ * File
4
+ * Lists
5
+ * Code
6
+ * Metabox toggle
7
+
8
+ */
9
+
10
+
11
+
12
+
13
+ jQuery(document).ready( function($) {
14
+
15
+
16
+
17
+
18
+ /**
19
+ * Add file functionality.
20
+ *
21
+ * @since 1.0.0
22
+ */
23
+ if( $('.mtphr-post-duplicator-metaboxer-file').length > 0 ) {
24
+ mtphr_post_duplicator_metaboxer_files();
25
+ }
26
+ function mtphr_post_duplicator_metaboxer_files() {
27
+
28
+ // Loop through all files to initialize
29
+ $('.mtphr-post-duplicator-metaboxer-file').each( function(index) {
30
+
31
+ // If there currently isn't a value, show the upload button
32
+ if( $(this).find('.mtphr-post-duplicator-metaboxer-file-value').val() == '' ) {
33
+ $(this).find('.mtphr-post-duplicator-metaboxer-file-upload').css('display','inline-block');
34
+ }
35
+ });
36
+
37
+ // Custom media upload functionality
38
+ $('.mtphr-post-duplicator-metaboxer-file-upload').click(function() {
39
+
40
+ // Save the container
41
+ var $container = $(this).parent('.mtphr-post-duplicator-metaboxer-field-content');
42
+
43
+ var send_attachment_bkp = wp.media.editor.send.attachment;
44
+
45
+ wp.media.editor.send.attachment = function( props, attachment ) {
46
+
47
+ // Set the field value
48
+ $container.find('.mtphr-post-duplicator-metaboxer-file-value').val(attachment.id);
49
+
50
+ // Create the display
51
+ var data = {
52
+ action: 'mtphr_post_duplicator_metaboxer_ajax_file_display',
53
+ id: attachment.id,
54
+ type: attachment.type,
55
+ url: attachment.url,
56
+ title: attachment.title,
57
+ caption: attachment.caption,
58
+ description: attachment.description,
59
+ security: mtphr_post_duplicator_metaboxer_vars.security
60
+ };
61
+
62
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
63
+ jQuery.post( ajaxurl, data, function( response ) {
64
+
65
+ // Append the new data
66
+ $container.append( response );
67
+
68
+ // Hide the upload button
69
+ $container.find('.mtphr-post-duplicator-metaboxer-file-upload').hide();
70
+ });
71
+
72
+ wp.media.editor.send.attachment = send_attachment_bkp;
73
+ }
74
+
75
+ wp.media.editor.open();
76
+
77
+ return false;
78
+ });
79
+
80
+ $('.mtphr-post-duplicator-metaboxer-file-delete').live('click',function() {
81
+
82
+ // Save the container
83
+ var $container = $(this).parents('.mtphr-post-duplicator-metaboxer-field-content');
84
+
85
+ // Remove the field value
86
+ $container.find('.mtphr-post-duplicator-metaboxer-file-value').val('');
87
+
88
+ // Remove the current display
89
+ $container.find('.mtphr-post-duplicator-metaboxer-file-table').remove();
90
+
91
+ // Disply the upload button
92
+ $container.find('.mtphr-post-duplicator-metaboxer-file-upload').css('display','inline-block');
93
+ });
94
+ }
95
+
96
+
97
+
98
+
99
+ /**
100
+ * Add list functionality.
101
+ *
102
+ * @since 1.0.0
103
+ */
104
+ if( $('.mtphr-post-duplicator-metaboxer-list').length > 0 ) {
105
+ mtphr_post_duplicator_metaboxer_lists();
106
+ }
107
+ function mtphr_post_duplicator_metaboxer_lists() {
108
+
109
+ // Loop through all lists to initialize
110
+ $('.mtphr-post-duplicator-metaboxer-list').each( function(index) {
111
+
112
+ // Set the field order
113
+ mtphr_post_duplicator_metaboxer_lists_set_order( $(this) );
114
+
115
+ // Add sorting to the items
116
+ $(this).sortable( {
117
+ handle: '.mtphr-post-duplicator-metaboxer-list-item-handle',
118
+ items: '.mtphr-post-duplicator-metaboxer-list-item',
119
+ axis: 'y',
120
+ helper: function(e, tr) {
121
+ var $originals = tr.children();
122
+ var $helper = tr.clone();
123
+ $helper.children().each(function(index) {
124
+ // Set helper cell sizes to match the original sizes
125
+ $(this).width($originals.eq(index).width())
126
+ });
127
+ return $helper;
128
+ },
129
+ update: function( event, ui ) {
130
+
131
+ // Set the field order
132
+ mtphr_post_duplicator_metaboxer_lists_set_order( $(this) );
133
+ }
134
+ });
135
+ });
136
+
137
+ // Set the list item order
138
+ function mtphr_post_duplicator_metaboxer_lists_set_order( $list ) {
139
+
140
+ // Set the order of the items
141
+ $list.find('.mtphr-post-duplicator-metaboxer-list-item').each( function(i) {
142
+
143
+ $(this).find('.mtphr-post-duplicator-metaboxer-list-structure-item').each( function(e) {
144
+
145
+ var base = $(this).attr('base');
146
+ var field = $(this).attr('field');
147
+ $(this).find('input,textarea,select').attr('name', base+'['+i+']['+field+']');
148
+ });
149
+ });
150
+
151
+ // Hide the delete if only one element
152
+ if( $list.find('.mtphr-post-duplicator-metaboxer-list-item').length == 1 ) {
153
+
154
+ $list.find('.mtphr-post-duplicator-metaboxer-list-item-handle,.mtphr-post-duplicator-metaboxer-list-item-delete').hide();
155
+ }
156
+ }
157
+
158
+ // Add item click
159
+ $('.mtphr-post-duplicator-metaboxer-list-item-add').children('a').click( function(e) {
160
+ e.preventDefault();
161
+
162
+ // Create a new item with blank content
163
+ var $parent = $(this).parents('.mtphr-post-duplicator-metaboxer-list-item');
164
+ var $new = $parent.clone(true).hide();
165
+ $new.find('input,textarea,select').removeAttr('value').removeAttr('checked').removeAttr('selected');
166
+ $parent.after($new);
167
+ $new.fadeIn();
168
+
169
+ // Set the field order
170
+ mtphr_post_duplicator_metaboxer_lists_set_order( $(this).parents('.mtphr-post-duplicator-metaboxer-list') );
171
+
172
+ // Show the handles
173
+ $(this).parents('.mtphr-post-duplicator-metaboxer-list').find('.mtphr-post-duplicator-metaboxer-list-item-handle,.mtphr-post-duplicator-metaboxer-list-item-delete').show();
174
+
175
+ // Set the focus to the new input
176
+ var inputs = $new.find('input,textarea,select');
177
+ $(inputs[0]).focus();
178
+ });
179
+
180
+ // Delete item click
181
+ $('.mtphr-post-duplicator-metaboxer-list-item-delete').children('a').click( function(e) {
182
+ e.preventDefault();
183
+
184
+ // Fade out the item
185
+ $(this).parents('.mtphr-post-duplicator-metaboxer-list-item').fadeOut( function() {
186
+
187
+ // Get the list
188
+ var $list = $(this).parents('.mtphr-post-duplicator-metaboxer-list');
189
+
190
+ // Remove the item
191
+ $(this).remove();
192
+
193
+ // Set the field order
194
+ mtphr_post_duplicator_metaboxer_lists_set_order( $list );
195
+ });
196
+ });
197
+ }
198
+
199
+
200
+
201
+
202
+ /**
203
+ * Add list functionality.
204
+ *
205
+ * @since 1.0.0
206
+ */
207
+ if( $('.mtphr-post-duplicator-metaboxer-sort').length > 0 ) {
208
+ mtphr_post_duplicator_metaboxer_sorts();
209
+ }
210
+ function mtphr_post_duplicator_metaboxer_sorts() {
211
+
212
+ // Loop through all sorts to initialize
213
+ $('.mtphr-post-duplicator-metaboxer-sort').each( function(index) {
214
+
215
+ // Set the field order
216
+ //mtphr_post_duplicator_metaboxer_sorts_set_order( $(this) );
217
+
218
+ // Add sorting to the items
219
+ $(this).sortable( {
220
+ handle: '.mtphr-post-duplicator-metaboxer-sort-item-handle',
221
+ items: '.mtphr-post-duplicator-metaboxer-sort-item',
222
+ axis: 'y',
223
+ helper: function(e, tr) {
224
+ var $originals = tr.children();
225
+ var $helper = tr.clone();
226
+ $helper.children().each(function(index) {
227
+ // Set helper cell sizes to match the original sizes
228
+ $(this).width($originals.eq(index).width())
229
+ });
230
+ return $helper;
231
+ },
232
+ update: function( event, ui ) {
233
+
234
+ // Set the field order
235
+ //mtphr_post_duplicator_metaboxer_sorts_set_order( $(this) );
236
+ }
237
+ });
238
+ });
239
+
240
+ // Set the list item order
241
+ /*
242
+ function mtphr_post_duplicator_metaboxer_sorts_set_order( $sort ) {
243
+
244
+ // Set the order of the items
245
+ $list.find('.mtphr-post-duplicator-metaboxer-list-item').each( function(i) {
246
+
247
+ $(this).find('.mtphr-post-duplicator-metaboxer-list-structure-item').each( function(e) {
248
+
249
+ var base = $(this).attr('base');
250
+ var field = $(this).attr('field');
251
+ $(this).find('input,textarea,select').attr('name', base+'['+i+']['+field+']');
252
+ });
253
+ });
254
+
255
+ // Hide the delete if only one element
256
+ if( $list.find('.mtphr-post-duplicator-metaboxer-list-item').length == 1 ) {
257
+
258
+ $list.find('.mtphr-post-duplicator-metaboxer-list-item-handle,.mtphr-post-duplicator-metaboxer-list-item-delete').hide();
259
+ }
260
+ }
261
+ */
262
+ }
263
+
264
+
265
+
266
+
267
+ /**
268
+ * Add code functionality.
269
+ *
270
+ * @since 1.0.0
271
+ */
272
+ if( $('.mtphr-post-duplicator-metaboxer-code').length > 0 ) {
273
+ mtphr_post_duplicator_metaboxer_codes();
274
+ }
275
+ function mtphr_post_duplicator_metaboxer_codes() {
276
+
277
+ // Select the code on button click
278
+ $('.mtphr-post-duplicator-metaboxer-code-select').click( function(e) {
279
+ e.preventDefault();
280
+
281
+ var $pre = $(this).parents('.mtphr-post-duplicator-metaboxer-code').find('pre');
282
+ var refNode = $pre[0];
283
+ if ( jQuery.browser.msie ) {
284
+ var range = document.body.createTextRange();
285
+ range.moveToElementText( refNode );
286
+ range.select();
287
+ } else if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
288
+ var selection = window.getSelection();
289
+ var range = document.createRange();
290
+ range.selectNodeContents( refNode );
291
+ selection.removeAllRanges();
292
+ selection.addRange( range );
293
+ } else if ( jQuery.browser.safari || jQuery.browser.chrome ) {
294
+ var selection = window.getSelection();
295
+ selection.setBaseAndExtent( refNode, 0, refNode, 1 );
296
+ }
297
+ });
298
+ }
299
+
300
+
301
+
302
+
303
+ /**
304
+ * Add metabox toggle functionality.
305
+ *
306
+ * @since 1.0.0
307
+ */
308
+ if( $('.mtphr-post-duplicator-metaboxer-field-metabox_toggle').length > 0 ) {
309
+ mtphr_post_duplicator_metaboxer_metabox_toggles();
310
+ }
311
+ function mtphr_post_duplicator_metaboxer_metabox_toggles() {
312
+
313
+ $('.mtphr-post-duplicator-metaboxer-field-metabox_toggle').each( function(index) {
314
+
315
+ // Create an array to store all the toggled metaboxes
316
+ var metaboxes = Array();
317
+ $(this).find('.mtphr-post-duplicator-metaboxer-metabox-toggle').each( function(index) {
318
+
319
+ // Get the metaboxes and merge into the main array
320
+ var m = $(this).attr('metaboxes').split(',');
321
+ $.merge( metaboxes, m );
322
+ });
323
+ var total_metaboxes = metaboxes.length;
324
+
325
+ // Hide the toggled metaboxes
326
+ mtphr_post_duplicator_metaboxer_metabox_hide();
327
+
328
+ // Display the current metaboxes
329
+ if( $(this).find('.mtphr-post-duplicator-metaboxer-metabox-toggle.button-primary').length > 0 ) {
330
+ $init_button = $(this).find('.mtphr-post-duplicator-metaboxer-metabox-toggle.button-primary');
331
+ } else {
332
+ $init_button = $(this).find('.mtphr-post-duplicator-metaboxer-metabox-toggle:first');
333
+ $init_button.addClass('button-primary');
334
+ }
335
+ mtphr_post_duplicator_metaboxer_metabox_show( $init_button );
336
+
337
+ // Hide the toggled metaboxes
338
+ function mtphr_post_duplicator_metaboxer_metabox_hide() {
339
+ for( var i=0; i<total_metaboxes; i++ ) {
340
+ $('#'+metaboxes[i]).hide();
341
+ $('input[name="'+metaboxes[i]+'-hide"]').removeAttr('checked');
342
+ }
343
+ }
344
+
345
+ // Show the selected metaboxes
346
+ function mtphr_post_duplicator_metaboxer_metabox_show( $button ) {
347
+
348
+ // Get and display the selected metaboxes
349
+ var m = $button.attr('metaboxes').split(',');
350
+ var t = m.length;
351
+
352
+ // Show all the toggled metaboxes
353
+ for( var i=0; i<t; i++ ) {
354
+ $('#'+m[i]).show();
355
+ $('input[name="'+m[i]+'-hide"]').attr('checked', 'checked');
356
+ }
357
+
358
+ // Store the new value
359
+ $button.siblings('input').val($button.attr('href'));
360
+ }
361
+
362
+ // Select the code on button click
363
+ $(this).find('.mtphr-post-duplicator-metaboxer-metabox-toggle').click( function(e) {
364
+ e.preventDefault();
365
+
366
+ // Hide all the toggled metaboxes
367
+ mtphr_post_duplicator_metaboxer_metabox_hide();
368
+
369
+ // Show the selected metaboxes
370
+ mtphr_post_duplicator_metaboxer_metabox_show( $(this) );
371
+
372
+ // Set the button classes
373
+ $(this).siblings('.mtphr-post-duplicator-metaboxer-metabox-toggle').removeClass('button-primary');
374
+ $(this).addClass('button-primary');
375
+ });
376
+ });
377
+ }
378
+
379
+
380
+
381
+
382
+
383
+ });
metaboxer/metaboxer.php ADDED
@@ -0,0 +1,946 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Put all the Metaboxer admin function here fields here
4
+ *
5
+ * @package Ditty News Ticker
6
+ * @author Metaphor Creations
7
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
8
+ * @link http://www.metaphorcreations.com/plugins/metatools
9
+ * @version 1.0.0
10
+ */
11
+
12
+
13
+
14
+ /**
15
+ * Create a field container and switch.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ function mtphr_post_duplicator_metaboxer_container( $field, $context ) {
20
+
21
+ global $post;
22
+
23
+ $default = isset( $field['default'] ) ? $field['default'] : '';
24
+ $value = ( get_post_meta( $post->ID, $field['id'], true ) != '' ) ? get_post_meta( $post->ID, $field['id'], true ) : $default;
25
+ $display = isset( $field['display'] ) ? $field['display'] : '';
26
+ ?>
27
+ <tr class="mtphr-post-duplicator-metaboxer-field mtphr-post-duplicator-metaboxer-field-<?php echo $field['type']; ?> mtphr-post-duplicator-metaboxer<?php echo $field['id']; ?><?php if( isset($field['class']) ) { echo ' '.$field['class']; } ?> clearfix">
28
+
29
+ <?php
30
+ $content_class = 'mtphr-post-duplicator-metaboxer-field-content mtphr-post-duplicator-metaboxer-field-content-full mtphr-post-duplicator-metaboxer-'.$field['type'].' clearfix';
31
+ $content_span = ' colspan="2"';
32
+ $label = false;
33
+
34
+ if ( isset($field['name']) || isset($field['description']) ) {
35
+
36
+ $content_class = 'mtphr-post-duplicator-metaboxer-field-content mtphr-post-duplicator-metaboxer-'.$field['type'].' clearfix';
37
+ $content_span = '';
38
+ $label = true;
39
+ ?>
40
+
41
+ <?php if( $context == 'side' || $display == 'vertical' ) { ?><td><table><tr><?php } ?>
42
+
43
+ <td class="mtphr-post-duplicator-metaboxer-label">
44
+ <?php if( isset($field['name']) ) { ?><label for="<?php echo $field['id']; ?>"><?php echo $field['name']; ?></label><?php } ?>
45
+ <?php if( isset($field['description']) ) { ?><small><?php echo $field['description']; ?></small><?php } ?>
46
+ </td>
47
+
48
+ <?php if( $context == 'side' || $display == 'vertical' ) { echo '</tr>'; } ?>
49
+
50
+ <?php
51
+ }
52
+ ?>
53
+
54
+ <?php if( $label ) { if( $context == 'side' || $display == 'vertical' ) { echo '<tr>'; } } ?>
55
+
56
+ <td<?php echo $content_span; ?> class="<?php echo $content_class; ?>" id="<?php echo $post->ID; ?>">
57
+ <?php
58
+ // Call the function to display the field
59
+ if ( function_exists('mtphr_post_duplicator_metaboxer_'.$field['type']) ) {
60
+ call_user_func( 'mtphr_post_duplicator_metaboxer_'.$field['type'], $field, $value );
61
+ }
62
+ ?>
63
+ </td>
64
+
65
+ <?php if( $label ) { if( $context == 'side' || $display == 'vertical' ) { echo '</tr></table></td>'; } } ?>
66
+
67
+ </tr>
68
+ <?php
69
+ }
70
+
71
+
72
+
73
+ /**
74
+ * Add custom image sizes.
75
+ *
76
+ * @since 1.0.0
77
+ */
78
+ if ( function_exists( 'add_image_size' ) ) {
79
+
80
+ // Create custom image sizes
81
+ add_image_size( 'metaboxer-gallery-thumb', 120, 120, true );
82
+ }
83
+
84
+
85
+
86
+
87
+ add_action( 'wp_ajax_mtphr_post_duplicator_metaboxer_insert_attachment', 'mtphr_post_duplicator_metaboxer_insert_attachment' );
88
+ /**
89
+ * Ajax function used to insert a single attachment
90
+ *
91
+ * @since 1.0.0
92
+ */
93
+ function mtphr_post_duplicator_metaboxer_insert_attachment() {
94
+
95
+ // Get access to the database
96
+ global $wpdb;
97
+
98
+ // Check the nonce
99
+ check_ajax_referer( 'mtphr_post_duplicator_metaboxer_ajax_file_nonce', 'security' );
100
+
101
+ // Get variables
102
+ $file_id = $_POST['file_ids'];
103
+ $file_type = isset( $_POST['file_type'] ) ? $_POST['file_type'] : '';
104
+ $file_size = isset( $_POST['file_size'] ) ? $_POST['file_size'] : '';
105
+
106
+ $output = '<li class="mtphr-post-duplicator-metaboxer-single-attachment" id="'.$file_id.'">'.wp_get_attachment_image( $file_id, ( $file_size != '' ) ? $file_size : 'thumbnail' );;
107
+ $output .= '<div class="mtphr-post-duplicator-metaboxer-attachment-links">';
108
+ //$output .= '<a href="'.$file_id.'" class="mtphr-post-duplicator-metaboxer-attachment-preview"></a>';
109
+ $output .= '<a href="'.$file_id.'" class="mtphr-post-duplicator-metaboxer-attachment-settings"></a>';
110
+ $output .= '<a href="'.$file_id.'" class="mtphr-post-duplicator-metaboxer-attachment-delete"></a>';
111
+ $output .= '</div><li>';
112
+
113
+ echo $output;
114
+
115
+ die(); // this is required to return a proper result
116
+ }
117
+
118
+
119
+
120
+
121
+ add_action( 'wp_ajax_mtphr_post_duplicator_metaboxer_insert_attachments', 'mtphr_post_duplicator_metaboxer_insert_attachments' );
122
+ /**
123
+ * Ajax function used to insert multiple attachments
124
+ *
125
+ * @since 1.0.0
126
+ */
127
+ function mtphr_post_duplicator_metaboxer_insert_attachments() {
128
+
129
+ // Get access to the database
130
+ global $wpdb;
131
+
132
+ // Check the nonce
133
+ check_ajax_referer( 'mtphr_post_duplicator_metaboxer_ajax_file_nonce', 'security' );
134
+
135
+ // Get variables
136
+ $file_ids = $_POST['file_ids'];
137
+
138
+ // Create an array of ids
139
+ $files = explode( ',', $file_ids );
140
+
141
+ // Create the new files
142
+ foreach ( $files as $id ) {
143
+ echo mtphr_post_duplicator_metaboxer_thumb( $id, false );
144
+ }
145
+
146
+ die(); // this is required to return a proper result
147
+ }
148
+
149
+
150
+
151
+
152
+ add_action( 'wp_ajax_mtphr_post_duplicator_metaboxer_delete_attachments', 'mtphr_post_duplicator_metaboxer_delete_attachments' );
153
+ /**
154
+ * Ajax function used to delete attachments
155
+ *
156
+ * @since 1.0.0
157
+ */
158
+ function mtphr_post_duplicator_metaboxer_delete_attachments() {
159
+
160
+ // Get access to the database
161
+ global $wpdb;
162
+
163
+ // Check the nonce
164
+ check_ajax_referer( 'mtphr_post_duplicator_metaboxer_ajax_file_nonce', 'security' );
165
+
166
+ // Get variables
167
+ $file_ids = $_POST['file_ids'];
168
+
169
+ // Create an array of ids
170
+ $files = explode( ',', $file_ids );
171
+
172
+ // Delete the attachments
173
+ foreach ( $files as $id ) {
174
+ wp_delete_attachment( $id );
175
+ }
176
+
177
+ die(); // this is required to return a proper result
178
+ }
179
+
180
+
181
+ /**
182
+ * Append fields
183
+ *
184
+ * @since 1.0.0
185
+ */
186
+ function mtphr_post_duplicator_metaboxer_append_field( $field ) {
187
+
188
+ // Add appended fields
189
+ if( isset($field['append']) ) {
190
+
191
+ $fields = $field['append'];
192
+ $settings = ( isset($field['option'] ) ) ? $field['option'] : false;
193
+
194
+ if( is_array($fields) ) {
195
+
196
+ foreach( $fields as $id => $field ) {
197
+
198
+ // Get the value
199
+ if( $settings) {
200
+ $options = get_option( $settings );
201
+ $value = isset( $options[$id] ) ? $options[$id] : get_option( $id );
202
+ } else {
203
+ global $post;
204
+ $value = get_post_meta( $post->ID, $id, true );
205
+ }
206
+
207
+ // Set the default if no value
208
+ if( $value == '' && isset($field['default']) ) {
209
+ $value = $field['default'];
210
+ }
211
+
212
+ if( isset($field['type']) ) {
213
+
214
+ if( $settings ) {
215
+ $field['id'] = $settings.'['.$id.']';
216
+ $field['option'] = $settings;
217
+ } else {
218
+ $field['id'] = $id;
219
+ }
220
+
221
+ // Call the function to display the field
222
+ if ( function_exists('mtphr_post_duplicator_metaboxer_'.$field['type']) ) {
223
+ echo '<div class="mtphr-post-duplicator-metaboxer-appended mtphr-post-duplicator-metaboxer'.$field['id'].'">';
224
+ call_user_func( 'mtphr_post_duplicator_metaboxer_'.$field['type'], $field, $value );
225
+ echo '</div>';
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+
233
+
234
+
235
+ /* Table of Contents
236
+
237
+ * text
238
+ * number
239
+ * textarea
240
+ * wysiwyg
241
+ * checkbox
242
+ * radio
243
+ * farbtastic
244
+ * image
245
+ * select
246
+ * image_select
247
+ * list
248
+ * sort
249
+ * html
250
+ * metabox toggle
251
+ * file
252
+ * gallery
253
+ * code
254
+
255
+ */
256
+
257
+ /**
258
+ * Renders an text field.
259
+ *
260
+ * @since 1.0.0
261
+ */
262
+ function mtphr_post_duplicator_metaboxer_text( $field, $value='' ) {
263
+ $size = ( isset($field['size']) ) ? $field['size'] : 40;
264
+ $before = ( isset($field['before']) ) ? '<span>'.$field['before'].' </span>' : '';
265
+ $after = ( isset($field['after']) ) ? '<span> '.$field['after'].'</span>' : '';
266
+ $text_align = ( isset($field['text_align']) ) ? ' style="text-align:'.$field['text_align'].'"' : '' ;
267
+ $output = $before.'<input name="'.$field['id'].'" id="'.$field['id'].'" type="text" value="'.$value.'" size="'.$size.'"'.$text_align.'>'.$after;
268
+ echo $output;
269
+
270
+ // Add appended fields
271
+ mtphr_post_duplicator_metaboxer_append_field($field);
272
+ }
273
+
274
+ /**
275
+ * Renders an number field.
276
+ *
277
+ * @since 1.0.0
278
+ */
279
+ function mtphr_post_duplicator_metaboxer_number( $field, $value='' ) {
280
+ $style = ( isset($field['style']) ) ? ' style="'.$field['style'].'"' : '';
281
+ $before = ( isset($field['before']) ) ? '<span>'.$field['before'].' </span>' : '';
282
+ $after = ( isset($field['after']) ) ? '<span> '.$field['after'].'</span>' : '';
283
+ $output = $before.'<input name="'.$field['id'].'" id="'.$field['id'].'" type="number" value="'.$value.'" class="small-text"'.$style.'>'.$after;
284
+ echo $output;
285
+
286
+ // Add appended fields
287
+ mtphr_post_duplicator_metaboxer_append_field($field);
288
+ }
289
+
290
+ /**
291
+ * Renders a textarea custom field.
292
+ *
293
+ * @since 1.0.0
294
+ */
295
+ function mtphr_post_duplicator_metaboxer_textarea( $field, $value='' ) {
296
+ $rows = ( isset($field['rows']) ) ? $field['rows'] : 5;
297
+ $cols = ( isset($field['cols']) ) ? $field['cols'] : 40;
298
+ $output = '<textarea name="'.$field['id'].'" id="'.$field['id'].'" rows="'.$rows.'" cols="'.$cols.'">'.$value.'</textarea>';
299
+ echo $output;
300
+
301
+ // Add appended fields
302
+ mtphr_post_duplicator_metaboxer_append_field($field);
303
+ }
304
+
305
+ /**
306
+ * Renders a wysiwyg field.
307
+ *
308
+ * @since 1.0.0
309
+ */
310
+ function mtphr_post_duplicator_metaboxer_wysiwyg( $field, $value='' ) {
311
+ $settings = array();
312
+ $settings['media_buttons'] = true;
313
+ $settings['textarea_rows'] = ( isset($field['rows']) ) ? $field['rows'] : 12;
314
+ wp_editor( $value, $field['id'], $settings );
315
+
316
+ // Add appended fields
317
+ mtphr_post_duplicator_metaboxer_append_field($field);
318
+ }
319
+
320
+ /**
321
+ * Renders a checkbox custom field.
322
+ *
323
+ * @since 1.0.0
324
+ */
325
+ function mtphr_post_duplicator_metaboxer_checkbox( $field, $value='' ) {
326
+
327
+ $output = '';
328
+ $before = ( isset($field['before']) ) ? '<span>'.$field['before'].' </span>' : '';
329
+ $after = ( isset($field['after']) ) ? '<span> '.$field['after'].'</span>' : '';
330
+
331
+ if( isset($field['options']) ) {
332
+
333
+ $break = '<br/>';
334
+ if ( isset($field['display']) ) {
335
+ if( $field['display'] == 'inline' ) {
336
+ $break = '&nbsp;&nbsp;&nbsp;&nbsp;';
337
+ }
338
+ }
339
+ foreach( $field['options'] as $i => $option ) {
340
+ $checked = ( isset($value[$i]) ) ? 'checked="checked"' : '';
341
+ $output .= '<label><input name="'.$field['id'].'['.$i.']" id="'.$field['id'].'['.$i.']" type="checkbox" value="1" '.$checked.' /> '.$option.'</label>'.$break;
342
+ }
343
+
344
+ } else {
345
+
346
+ $checked = ( $value == 1 ) ? 'checked="checked"' : '';
347
+ $output .= '<label><input name="'.$field['id'].'" id="'.$field['id'].'" type="checkbox" value="1" '.$checked.' />';
348
+ if( isset($field['label']) ) {
349
+ $output .= ' '.$field['label'];
350
+ }
351
+ $output .= '</label>';
352
+ }
353
+
354
+ echo $before.$output.$after;
355
+
356
+ // Add appended fields
357
+ mtphr_post_duplicator_metaboxer_append_field($field);
358
+ }
359
+
360
+ /**
361
+ * Renders a radio custom field.
362
+ *
363
+ * @since 1.0.0
364
+ */
365
+ function mtphr_post_duplicator_metaboxer_radio( $field, $value='' ) {
366
+
367
+ if( isset($field['options']) ) {
368
+
369
+ $output = '';
370
+ $break = '<br/>';
371
+ if ( isset($field['display']) ) {
372
+ if( $field['display'] == 'inline' ) {
373
+ $break = '&nbsp;&nbsp;&nbsp;&nbsp;';
374
+ }
375
+ }
376
+ foreach( $field['options'] as $i => $option ) {
377
+ $checked = ( $value == $i ) ? 'checked="checked"' : '';
378
+ $output .= '<label><input name="'.$field['id'].'" id="'.$field['id'].'" type="radio" value="'.$i.'" '.$checked.' /> '.$option.'</label>'.$break;
379
+ }
380
+ }
381
+
382
+ echo $output;
383
+
384
+ // Add appended fields
385
+ mtphr_post_duplicator_metaboxer_append_field($field);
386
+ }
387
+
388
+ /**
389
+ * Renders a farbtastic custom field.
390
+ *
391
+ * @since 1.0.0
392
+ */
393
+ function mtphr_post_duplicator_metaboxer_farbtastic( $field, $value='' ) {
394
+ $output = '<div class="farbtastic_cp" id="'.$field['id'].'_cp"></div>';
395
+ $output .= '<input name="'.$field['id'].'" id="'.$field['id'].'" type="text" value="'.$value.'" />';
396
+ $output .= '<a href="#" class="farbtastic-pick button">Pick Color</a>';
397
+ echo $output;
398
+
399
+ // Add appended fields
400
+ mtphr_post_duplicator_metaboxer_append_field($field);
401
+ }
402
+
403
+ /**
404
+ * Renders an image field.
405
+ *
406
+ * @since 1.0.0
407
+ */
408
+ function mtphr_post_duplicator_metaboxer_image( $field, $value=false ) {
409
+ $button = isset( $field['button'] ) ? $field['button'] : 'Upload Image';
410
+ $size = isset( $field['size'] ) ? $field['size'] : 'thumbnail';
411
+
412
+ $value = ( $value ) ? $value : false;
413
+
414
+ $output = '<div class="mtphr-post-duplicator-metaboxer-attachment-buttons"><a href="#" class="button mtphr-post-duplicator-metaboxer-upload-button">'.$button.'</a></div>';
415
+ $output .= '<input class="mtphr-post-duplicator-metaboxer-attachment-limit" type="hidden" value="1" />';
416
+ $output .= '<input class="mtphr-post-duplicator-metaboxer-attachment-size" type="hidden" value="'.$size.'" />';
417
+ $output .= '<div class="mtphr-post-duplicator-metaboxer-input-container" id="'.$field['id'].'"></div>';
418
+ $output .= '<ul id="'.wp_create_nonce( 'mtphr_post_duplicator_metaboxer_ajax_file_nonce' ).'" class="mtphr-post-duplicator-metaboxer-attachment-container clearfix">';
419
+ if( $value ) {
420
+ if( get_post($value[0]) ) {
421
+ $output .= '<li id="'.$value[0].'" class="mtphr-post-duplicator-metaboxer-single-attachment">'.wp_get_attachment_image( $value[0], isset( $field['size'] ) ? $field['size'] : 'thumbnail' );
422
+ $output .= '<div class="mtphr-post-duplicator-metaboxer-attachment-links">';
423
+ //$output .= '<a href="'.$value[0].'" class="mtphr-post-duplicator-metaboxer-attachment-preview"></a>';
424
+ $output .= '<a href="'.$value[0].'" class="mtphr-post-duplicator-metaboxer-attachment-settings"></a>';
425
+ $output .= '<a href="'.$value[0].'" class="mtphr-post-duplicator-metaboxer-attachment-delete"></a>';
426
+ $output .= '</div>';
427
+ $output .= '</li>';
428
+ }
429
+ }
430
+ $output .= '</ul>';
431
+ echo $output;
432
+
433
+ // Add appended fields
434
+ mtphr_post_duplicator_metaboxer_append_field($field);
435
+ }
436
+
437
+ /**
438
+ * Renders a select field.
439
+ *
440
+ * @since 1.0.0
441
+ */
442
+ function mtphr_post_duplicator_metaboxer_select( $field, $value='' ) {
443
+
444
+ $before = ( isset($field['before']) ) ? '<span>'.$field['before'].' </span>' : '';
445
+ $after = ( isset($field['after']) ) ? '<span> '.$field['after'].'</span>' : '';
446
+
447
+ $output = $before.'<select name="'.$field['id'].'" id="'.$field['id'].'">';
448
+
449
+ if( $field['options'] ) {
450
+
451
+ $key_val = isset( $field['key_val'] ) ? true : false;
452
+
453
+ foreach ( $field['options'] as $key => $option ) {
454
+ if( is_numeric($key) && !$key_val ) {
455
+ $name = ( is_array( $option ) ) ? $option['name'] : $option;
456
+ $val = ( is_array( $option ) ) ? $option['value'] : $option;
457
+ } else {
458
+ $name = $option;
459
+ $val = $key;
460
+ }
461
+ $selected = ( $val == $value ) ? 'selected="selected"' : '';
462
+ $output .= '<option value="'.$val.'" '.$selected.'>'.stripslashes( $name ).'</option>';
463
+ }
464
+ }
465
+ $output .= '</select>'.$after;
466
+
467
+ echo $output;
468
+
469
+ // Add appended fields
470
+ mtphr_post_duplicator_metaboxer_append_field($field);
471
+ }
472
+
473
+ /**
474
+ * Renders an image select
475
+ *
476
+ * @since 1.0.0
477
+ */
478
+ function mtphr_post_duplicator_metaboxer_image_select( $field, $value='' ) {
479
+ $output = '<input type="hidden" id="'.$field['id'].'" name="'.$field['id'].'" value="'.$value.'" />';
480
+ foreach ( $field['options'] as $option ) {
481
+ $selected = ( $value == $option['value'] ) ? 'selected' : '';
482
+ $output .= '<a class="mtphr-post-duplicator-metaboxer-image-select-link '.$selected.'" href="'.$option['value'].'"><img src="'.$option['path'].'" /><small>'.$option['label'].'</small></a>';
483
+ }
484
+ echo $output;
485
+
486
+ // Add appended fields
487
+ mtphr_post_duplicator_metaboxer_append_field($field);
488
+ }
489
+
490
+ /**
491
+ * Renders a list.
492
+ *
493
+ * @since 1.0.0
494
+ */
495
+ function mtphr_post_duplicator_metaboxer_list( $field, $value='' ) {
496
+
497
+ $output = '<table>';
498
+
499
+ $headers = false;
500
+ $header_str = '';
501
+ foreach( $field['structure'] as $id => $str ) {
502
+
503
+ $header_str .= '<th>';
504
+ if( isset($str['header']) ) {
505
+ $headers = true;
506
+ $header_str .= $str['header'];
507
+ }
508
+ $header_str .= '</th>';
509
+ }
510
+ if( $headers ) {
511
+ $output .= '<tr><td class="mtphr-post-duplicator-metaboxer-list-item-handle"></td>'.$header_str.'</tr>';
512
+ }
513
+
514
+ $buttons = '<td class="mtphr-post-duplicator-metaboxer-list-item-delete"><a href="#">Delete</a></td><td class="mtphr-post-duplicator-metaboxer-list-item-add"><a href="#">Add</a></td>';
515
+ if( is_array($value) ) {
516
+ foreach( $value as $i=>$v ) {
517
+ $structure = mtphr_post_duplicator_metaboxer_list_structure( $i, $field, $v );
518
+ $output .= '<tr class="mtphr-post-duplicator-metaboxer-list-item"><td class="mtphr-post-duplicator-metaboxer-list-item-handle"><span></span></td>'.$structure.$buttons.'</tr>';
519
+ }
520
+ }
521
+
522
+ // If nothing is being output make sure one field is showing
523
+ if( $value == '' ) {
524
+ $structure = mtphr_post_duplicator_metaboxer_list_structure( 0, $field );
525
+ $output .= '<tr class="mtphr-post-duplicator-metaboxer-list-item"><td class="mtphr-post-duplicator-metaboxer-list-item-handle"><span></span></td>'.$structure.$buttons.'</tr>';
526
+ }
527
+
528
+ $output .= '</table>';
529
+
530
+ echo $output;
531
+
532
+ // Add appended fields
533
+ mtphr_post_duplicator_metaboxer_append_field($field);
534
+ }
535
+
536
+ /**
537
+ * Add the list structure
538
+ *
539
+ * @since 1.0.0
540
+ */
541
+ function mtphr_post_duplicator_metaboxer_list_structure( $pos, $fields, $m_value='' ) {
542
+
543
+ $main_id = $fields['id'];
544
+
545
+ // Add appended fields
546
+ if( isset($fields['structure']) ) {
547
+
548
+ $fields = $fields['structure'];
549
+ $settings = ( isset($fields['option'] ) ) ? $fields['option'] : false;
550
+
551
+ if( is_array($fields) ) {
552
+
553
+ ob_start();
554
+
555
+ foreach( $fields as $id => $field ) {
556
+
557
+ // Get the value
558
+ $value = isset($m_value[$id]) ? $m_value[$id] : '';
559
+
560
+ // Get the width
561
+ $width = isset($field['width']) ? ' style="width:'.$field['width'].'"' : '';
562
+
563
+ if( isset($field['type']) ) {
564
+
565
+ $field['id'] = $main_id.'['.$pos.']['.$id.']';
566
+
567
+ // Call the function to display the field
568
+ if ( function_exists('mtphr_post_duplicator_metaboxer_'.$field['type']) ) {
569
+
570
+ echo '<td'.$width.' class="mtphr-post-duplicator-metaboxer-list-structure-item mtphr-post-duplicator-metaboxer'.$main_id.'-'.$id.'" base="'.$main_id.'" field="'.$id.'">';
571
+ call_user_func( 'mtphr_post_duplicator_metaboxer_'.$field['type'], $field, $value );
572
+ echo '</td>';
573
+ }
574
+ }
575
+ }
576
+
577
+ return ob_get_clean();
578
+ }
579
+ }
580
+ }
581
+
582
+ /**
583
+ * Renders a sort.
584
+ *
585
+ * @since 1.0.0
586
+ */
587
+ function mtphr_post_duplicator_metaboxer_sort( $field, $value='' ) {
588
+
589
+ global $post;
590
+
591
+ $rows = array();
592
+ if( is_array($value) ) {
593
+ foreach( $value as $id ) {
594
+ $rows[$id] = $field['rows'][$id];
595
+ }
596
+ } else {
597
+ $rows = $field['rows'];
598
+ }
599
+
600
+ $output = '<table>';
601
+
602
+ foreach( $rows as $id => $data ) {
603
+
604
+ $output .= '<tr class="mtphr-post-duplicator-metaboxer-sort-item"><td class="mtphr-post-duplicator-metaboxer-sort-item-handle"><span></span></td>';
605
+ if( isset($data['name']) ) {
606
+ $output .= '<td class="mtphr-post-duplicator-metaboxer-sort-name">'.$data['name'].'</td>';
607
+ }
608
+ $output .= '<td><input name="'.$field['id'].'[]" id="'.$field['id'].'[]" type="hidden" value="'.$id.'">';
609
+
610
+ // Find the value
611
+ $data_value = get_post_meta( $post->ID, $data['id'], true );
612
+ if( $data_value == '' && isset($data['default']) ) {
613
+ $data_value = $data['default'];
614
+ }
615
+
616
+ ob_start();
617
+ // Call the function to display the field
618
+ if ( function_exists('mtphr_post_duplicator_metaboxer_'.$data['type']) ) {
619
+ call_user_func( 'mtphr_post_duplicator_metaboxer_'.$data['type'], $data, $data_value );
620
+ }
621
+ $output .= ob_get_clean();
622
+
623
+ $output .= '</td>';
624
+
625
+ $output .= '</tr>';
626
+ }
627
+
628
+ $output .= '</table>';
629
+
630
+ echo $output;
631
+
632
+ // Add appended fields
633
+ mtphr_post_duplicator_metaboxer_append_field($field);
634
+ }
635
+
636
+ /**
637
+ * Renders an html field.
638
+ *
639
+ * @since 1.0.0
640
+ */
641
+ function mtphr_post_duplicator_metaboxer_html( $field, $value='' ) {
642
+
643
+ // Echo the html
644
+ echo $value;
645
+
646
+ // Add appended fields
647
+ mtphr_post_duplicator_metaboxer_append_field($field);
648
+ }
649
+
650
+ /**
651
+ * Renders a metabox toggle.
652
+ *
653
+ * @since 1.0.0
654
+ */
655
+ function mtphr_post_duplicator_metaboxer_metabox_toggle( $field, $value='' ) {
656
+
657
+ if( isset($field['options']) ) {
658
+
659
+ $output = '';
660
+ $output .= '<input type="hidden" id="'.$field['id'].'" name="'.$field['id'].'" value="'.$value.'" />';
661
+
662
+ foreach( $field['options'] as $i => $option ) {
663
+
664
+ $button = $option['button'];
665
+ $metaboxes = $option['metaboxes'];
666
+ $metabox_list = join( ',', $metaboxes );
667
+
668
+ // Create a button
669
+ $selected = ( $value == $i ) ? ' button-primary' : '';
670
+ $output .= '<a href="'.$i.'" metaboxes="'.$metabox_list.'" class="mtphr-post-duplicator-metaboxer-metabox-toggle button'.$selected.'">'.$button.'</a>&nbsp;';
671
+ }
672
+
673
+ echo $output;
674
+ }
675
+
676
+ // Add appended fields
677
+ mtphr_post_duplicator_metaboxer_append_field($field);
678
+ }
679
+
680
+
681
+
682
+
683
+ /**
684
+ * Redners a file attachment
685
+ *
686
+ * @since 1.0.0
687
+ */
688
+ function mtphr_post_duplicator_metaboxer_file( $field, $value='' ) {
689
+
690
+ // Check if there's actually a file
691
+ $file = false;
692
+ if( $value != '' ) {
693
+ $file = get_post( $value );
694
+ }
695
+
696
+ // If there isn't a file reset the value
697
+ if( !$file ) {
698
+ $value = '';
699
+ }
700
+ ?>
701
+
702
+ <input class="mtphr-post-duplicator-metaboxer-file-value" type="hidden" id="<?php echo $field['id']; ?>" name="<?php echo $field['id']; ?>" value="<?php echo $value; ?>" />
703
+
704
+ <?php
705
+ echo isset( $field['button'] ) ? '<a href="#" class="button mtphr-post-duplicator-metaboxer-file-upload">'.$field['button'].'</a>' : '<a href="#" class="button custom-media-upload">Insert File</a>';
706
+
707
+ if( $file ) {
708
+
709
+ $type = explode( '/', $file->post_mime_type );
710
+
711
+ // Display the file
712
+ echo mtphr_post_duplicator_metaboxer_file_display( $file->ID, $type[0], $file->guid, $file->post_title, $file -> post_excerpt, $file->post_content );
713
+ }
714
+
715
+ // Add appended fields
716
+ mtphr_post_duplicator_metaboxer_append_field($field);
717
+ }
718
+
719
+ add_action( 'wp_ajax_mtphr_post_duplicator_metaboxer_ajax_file_display', 'mtphr_post_duplicator_metaboxer_ajax_file_display' );
720
+ /**
721
+ * Ajax function used to delete attachments
722
+ *
723
+ * @since 1.0.0
724
+ */
725
+ function mtphr_post_duplicator_metaboxer_ajax_file_display() {
726
+
727
+ // Get access to the database
728
+ global $wpdb;
729
+
730
+ // Check the nonce
731
+ check_ajax_referer( 'mtphr_dnt', 'security' );
732
+
733
+ // Get variables
734
+ $id = $_POST['id'];
735
+ $type = $_POST['type'];
736
+ $url = $_POST['url'];
737
+ $title = $_POST['title'];
738
+ $caption = $_POST['caption'];
739
+ $description = $_POST['description'];
740
+
741
+ // Display the file
742
+ mtphr_post_duplicator_metaboxer_file_display( $id, $type, $url, $title, $caption, $description );
743
+
744
+ die(); // this is required to return a proper result
745
+ }
746
+
747
+ // Display the file
748
+ function mtphr_post_duplicator_metaboxer_file_display( $id, $type, $url, $title, $caption, $description ) {
749
+
750
+ $src = '';
751
+ switch( $type ) {
752
+
753
+ case 'image':
754
+ $att = wp_get_attachment_image_src( $id, 'thumbnail' );
755
+ $src = $att[0];
756
+ break;
757
+
758
+ case 'application':
759
+ $att = wp_get_attachment_image_src( $id, 'thumbnail', true );
760
+ $src = $att[0];
761
+ break;
762
+ }
763
+ ?>
764
+ <table class="mtphr-post-duplicator-metaboxer-file-table">
765
+ <tr>
766
+ <td class="mtphr-post-duplicator-metaboxer-file-display">
767
+ <a href="<?php echo $url; ?>" target="_blank" class="clearfix">
768
+ <img class="custom_media_image" src="<?php echo $src; ?>" />
769
+ <span class="mtphr-post-duplicator-metaboxer-file-title"><strong>Title:</strong> <?php echo $title; ?></span><br/>
770
+ <?php if( $caption != '' ) { ?>
771
+ <span class="mtphr-post-duplicator-metaboxer-file-caption"><strong>Caption:</strong> <?php echo $caption; ?></span><br/>
772
+ <?php }
773
+ if( $description != '' ) { ?>
774
+ <span class="mtphr-post-duplicator-metaboxer-file-description"><strong>Description:</strong> <?php echo $description; ?></span>
775
+ <?php } ?>
776
+ </a>
777
+ </td>
778
+ <td class="mtphr-post-duplicator-metaboxer-file-delete">
779
+ <a href="#"></a>
780
+ </td>
781
+ </tr>
782
+ </table>
783
+ <?php
784
+ }
785
+
786
+
787
+
788
+
789
+ /**
790
+ * Render a gallery attachment
791
+ *
792
+ * @since 1.0.0
793
+ */
794
+ function mtphr_post_duplicator_metaboxer_gallery( $field, $value='' ) {
795
+
796
+ /* Create the buttons */
797
+ $button = isset( $field['button'] ) ? $field['button'] : 'Insert Media';
798
+
799
+ $output = '<div class="mtphr-post-duplicator-metaboxer-attachment-buttons"><a href="#" class="button mtphr-post-duplicator-metaboxer-upload-button">'.$button.'</a></div>';
800
+
801
+ /* If there is a file limit */
802
+ if ( isset( $field['limit'] ) ) {
803
+ $output .= '<input class="mtphr-post-duplicator-metaboxer-attachment-limit" type="hidden" value="'.$field['limit'].'" />';
804
+ }
805
+ $output .= '<div class="mtphr-post-duplicator-metaboxer-input-container" id="'.$field['id'].'"></div>';
806
+ $output .= '<ul id="'.wp_create_nonce( 'mtphr_post_duplicator_metaboxer_ajax_file_nonce' ).'" class="mtphr-post-duplicator-metaboxer-gallery-attachment-container mtphr-post-duplicator-metaboxer-attachment-container clearfix">';
807
+
808
+ /* Loop through the existing attachments */
809
+ if( $value != '' ){
810
+ foreach( $value as $id ) {
811
+ $output .= mtphr_post_duplicator_metaboxer_thumb( $id );
812
+ }
813
+ }
814
+ $output .= '</ul>';
815
+ echo $output;
816
+
817
+ // Add appended fields
818
+ mtphr_post_duplicator_metaboxer_append_field($field);
819
+ }
820
+
821
+ /**
822
+ * Create the gallery thumbnail containers.
823
+ *
824
+ * @since 1.0.0
825
+ */
826
+ function mtphr_post_duplicator_metaboxer_thumb( $id, $preview=true ) {
827
+
828
+ $html = '';
829
+ $attachment = get_post( $id );
830
+ $nonce = wp_create_nonce( 'mtphr_post_duplicator_metaboxer_ajax_file_nonce' );
831
+
832
+ if ( $attachment ) {
833
+
834
+ $mime = $attachment->post_mime_type;
835
+
836
+ $html = '<li id="'.$id.'" class="mtphr-post-duplicator-metaboxer-gallery-attachment mtphr-post-duplicator-metaboxer-sort-container clearfix">';
837
+
838
+ switch ( $mime ) {
839
+
840
+ case 'image/jpeg':
841
+ $thumb = wp_get_attachment_image_src( $id, 'metaboxer-gallery-thumb' );
842
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-image" style="background-image:url('.$thumb[0].');"></div>';
843
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-image"></div>';
844
+ break;
845
+
846
+ case 'image/png':
847
+ $thumb = wp_get_attachment_image_src( $id, 'metaboxer-gallery-thumb' );
848
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-image" style="background-image:url('.$thumb[0].');"></div>';
849
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-image"></div>';
850
+ break;
851
+
852
+ case 'application/pdf':
853
+ $thumb = wp_get_attachment_image_src( $id, false, true );
854
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-pdf" style="background-image:url('.$thumb[0].');"></div>';
855
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-pdf"></div>';
856
+ break;
857
+
858
+ case 'application/zip':
859
+ $thumb = wp_get_attachment_image_src( $id, false, true );
860
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-zip" style="background-image:url('.$thumb[0].');"></div>';
861
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-zip"></div>';
862
+ break;
863
+
864
+ case 'audio/mpeg':
865
+ $image_id = get_post_meta( $id, '_attachment_poster_image', true );
866
+ $default = ( !$image_id || $image_id=='none' ) ? true : false;
867
+ $thumb = ( $default ) ? wp_get_attachment_image_src( $id, false, true ) : wp_get_attachment_image_src( $image_id, 'metaboxer-gallery-thumb' );
868
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-audio" style="background-image:url('.$thumb[0].');"></div>';
869
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-audio"></div>';
870
+ break;
871
+
872
+ case 'video/mp4':
873
+ $image_id = get_post_meta( $id, '_attachment_poster_image', true );
874
+ $default = ( !$image_id || $image_id=='none' ) ? true : false;
875
+ $thumb = ( $default ) ? wp_get_attachment_image_src( $id, false, true ) : wp_get_attachment_image_src( $image_id, 'metaboxer-gallery-thumb' );
876
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-video" style="background-image:url('.$thumb[0].');"></div>';
877
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-video"></div>';
878
+ break;
879
+
880
+ case 'video/m4v':
881
+ $image_id = get_post_meta( $id, '_attachment_poster_image', true );
882
+ $default = ( !$image_id || $image_id=='none' ) ? true : false;
883
+ $thumb = ( $default ) ? wp_get_attachment_image_src( $id, false, true ) : wp_get_attachment_image_src( $image_id, 'metaboxer-gallery-thumb' );
884
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-video" style="background-image:url('.$thumb[0].');"></div>';
885
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-video"></div>';
886
+ break;
887
+
888
+ case 'vimeo':
889
+ $thumb = get_post_meta( $id, '_video_thumb_large', true );
890
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-vimeo" style="background-image:url('.$thumb.');"></div>';
891
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-vimeo"></div>';
892
+ break;
893
+
894
+ case 'youtube':
895
+ $thumb = get_post_meta( $id, '_video_thumb_large', true );
896
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-gallery-attachment-bg mtphr-post-duplicator-metaboxer-gallery-attachment-bg-youtube" style="background-image:url('.$thumb.');"></div>';
897
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-mime-type mtphr-post-duplicator-metaboxer-attachment-mime-type-youtube"></div>';
898
+ break;
899
+
900
+ default:
901
+ // Call the function to display the custom field
902
+ call_user_func( 'mtphr_post_duplicator_metaboxer_'.str_replace('%/%','_',$mime).'_thumb', $id, $nonce );
903
+ $html .= $mime;
904
+ break;
905
+ }
906
+
907
+ $html .= '<div class="mtphr-post-duplicator-metaboxer-attachment-links">';
908
+ //$html .= '<a href="'.$id.'" rel="attachment_preview" class="mtphr-post-duplicator-metaboxer-attachment-preview"></a>';
909
+ $html .= '<a href="'.$id.'" class="mtphr-post-duplicator-metaboxer-attachment-settings"></a>';
910
+ $html .= '<a href="'.$id.'" class="mtphr-post-duplicator-metaboxer-attachment-delete"></a>';
911
+ $html .= '</div>';
912
+
913
+ $html .= '</li>';
914
+ }
915
+
916
+ return $html;
917
+ }
918
+
919
+
920
+
921
+
922
+ /**
923
+ * Renders the code fields.
924
+ *
925
+ * @since 1.0.0
926
+ */
927
+ function mtphr_post_duplicator_metaboxer_code( $field, $value='' ) {
928
+
929
+ global $post;
930
+
931
+ // Display the shortcode code
932
+ if( $field['id'] == '_mtphr_post_duplicator_shortcode' ) {
933
+
934
+ echo '<pre><p>[ditty_news_ticker id="'.$post->ID.'"]</p></pre>';
935
+
936
+ // Display the function code
937
+ } elseif( $field['id'] == '_mtphr_post_duplicator_function' ) {
938
+
939
+ echo '<pre><p>ditty_news_ticker('.$post->ID.');</p></pre>';
940
+ }
941
+
942
+ // Display a "Select All" button
943
+ $button = isset($field['button']) ? $field['button'] : __('Select Code', 'post-duplicator');
944
+ echo '<a href="#" class="button mtphr-post-duplicator-metaboxer-code-select">'.$button.'</a>';
945
+ }
946
+
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: metaphorcreations
3
  Tags: posts, post, duplicate, duplication
4
  Requires at least: 3.0
5
- Tested up to: 3.4.
6
  Stable tag: /trunk/
7
  License: GPL2
8
 
@@ -41,6 +41,9 @@ Check out the 'Installation' tab.
41
 
42
  == Changelog ==
43
 
 
 
 
44
  = 2.0 =
45
  * Added a settings page to set 'post status' and 'date' of duplicated posts.
46
 
@@ -49,6 +52,9 @@ Check out the 'Installation' tab.
49
 
50
  == Upgrade Notice ==
51
 
 
 
 
52
  = 2.0 =
53
  Upgrade Post Duplicator to add 'post status' and 'date' options to your duplicated posts.
54
 
2
  Contributors: metaphorcreations
3
  Tags: posts, post, duplicate, duplication
4
  Requires at least: 3.0
5
+ Tested up to: 3.5.1
6
  Stable tag: /trunk/
7
  License: GPL2
8
 
41
 
42
  == Changelog ==
43
 
44
+ = 2.2 =
45
+ * Updated metaboxer code.
46
+
47
  = 2.0 =
48
  * Added a settings page to set 'post status' and 'date' of duplicated posts.
49
 
52
 
53
  == Upgrade Notice ==
54
 
55
+ = 2.2 =
56
+ Code updates.
57
+
58
  = 2.0 =
59
  Upgrade Post Duplicator to add 'post status' and 'date' options to your duplicated posts.
60
 
screenshot-2.png ADDED
Binary file