| 1 |
<?php |
| 2 |
/* Copyright 2011 Ungureanu Madalin (email : madalin@reflectionmedia.ro) |
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License as published by |
| 5 |
the Free Software Foundation; either version 2 of the License, or |
| 6 |
(at your option) any later version. |
| 7 |
This program is distributed in the hope that it will be useful, |
| 8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
GNU General Public License for more details. |
| 11 |
You should have received a copy of the GNU General Public License |
| 12 |
along with this program; if not, write to the Free Software |
| 13 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 14 |
*/ |
| 15 |
|
| 16 |
if( file_exists( dirname(__FILE__). '/wck-fep/wck-fep.php' ) ) |
| 17 |
require_once( 'wck-fep/wck-fep.php' ); |
| 18 |
|
| 19 |
if( file_exists( dirname(__FILE__). '/wck-static-metabox-api.php' ) ) |
| 20 |
require_once( 'wck-static-metabox-api.php' ); |
| 21 |
|
| 22 |
|
| 23 |
/* |
| 24 |
|
| 25 |
Usage Example 1: |
| 26 |
|
| 27 |
|
| 28 |
$fint = array( |
| 29 |
array( 'type' => 'text', 'title' => 'Title', 'description' => 'Description for this input' ), |
| 30 |
array( 'type' => 'textarea', 'title' => 'Description' ), |
| 31 |
array( 'type' => 'upload', 'title' => 'Image', 'description' => 'Upload a image' ), |
| 32 |
array( 'type' => 'select', 'title' => 'Select This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ), |
| 33 |
array( 'type' => 'checkbox', 'title' => 'Check This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ), |
| 34 |
array( 'type' => 'radio', 'title' => 'Radio This', 'options' => array( 'Radio 1', 'Radio 2', 'Radio 3' ) ), |
| 35 |
); |
| 36 |
|
| 37 |
$args = array( |
| 38 |
'metabox_id' => 'rm_slider_content', |
| 39 |
'metabox_title' => 'Slideshow Class', |
| 40 |
'post_type' => 'slideshows', |
| 41 |
'meta_name' => 'rmscontent', |
| 42 |
'meta_array' => $fint |
| 43 |
); |
| 44 |
|
| 45 |
new Wordpress_Creation_Kit_PB( $args ); |
| 46 |
|
| 47 |
|
| 48 |
On the frontend: |
| 49 |
|
| 50 |
$meta = get_post_meta( $post->ID, 'rmscontent', true ); |
| 51 |
|
| 52 |
*/ |
| 53 |
|
| 54 |
class Wordpress_Creation_Kit_PB{ |
| 55 |
|
| 56 |
private $defaults = array( |
| 57 |
'metabox_id' => '', |
| 58 |
'metabox_title' => 'Meta Box', |
| 59 |
'post_type' => 'post', |
| 60 |
'meta_name' => '', |
| 61 |
'meta_array' => array(), |
| 62 |
'page_template' => '', |
| 63 |
'post_id' => '', |
| 64 |
'single' => false, |
| 65 |
'unserialize_fields' => false, |
| 66 |
'sortable' => true, |
| 67 |
'context' => 'post_meta', |
| 68 |
'mb_context' => 'normal' |
| 69 |
); |
| 70 |
private $args; |
| 71 |
|
| 72 |
|
| 73 |
/* Constructor method for the class. */ |
| 74 |
function __construct( $args ) { |
| 75 |
|
| 76 |
/* Global that will hold all the arguments for all the custom boxes */ |
| 77 |
global $wck_objects; |
| 78 |
|
| 79 |
/* Merge the input arguments and the defaults. */ |
| 80 |
$this->args = wp_parse_args( $args, $this->defaults ); |
| 81 |
|
| 82 |
/* Add the settings for this box to the global object */ |
| 83 |
$wck_objects[$this->args['metabox_id']] = $this->args; |
| 84 |
|
| 85 |
/*print scripts*/ |
| 86 |
add_action('admin_enqueue_scripts', array( &$this, 'wck_print_scripts' )); |
| 87 |
/* add our own ajaxurl because we are going to use the wck script also in frontend and we want to avoid any conflicts */ |
| 88 |
add_action( 'admin_head', array( &$this, 'wck_print_ajax_url' ) ); |
| 89 |
|
| 90 |
// Set up the AJAX hooks |
| 91 |
add_action("wp_ajax_wck_add_meta".$this->args['meta_name'], array( &$this, 'wck_add_meta') ); |
| 92 |
add_action("wp_ajax_wck_update_meta".$this->args['meta_name'], array( &$this, 'wck_update_meta') ); |
| 93 |
add_action("wp_ajax_wck_show_update".$this->args['meta_name'], array( &$this, 'wck_show_update_form') ); |
| 94 |
add_action("wp_ajax_wck_refresh_list".$this->args['meta_name'], array( &$this, 'wck_refresh_list') ); |
| 95 |
add_action("wp_ajax_wck_refresh_entry".$this->args['meta_name'], array( &$this, 'wck_refresh_entry') ); |
| 96 |
add_action("wp_ajax_wck_add_form".$this->args['meta_name'], array( &$this, 'wck_add_form') ); |
| 97 |
add_action("wp_ajax_wck_remove_meta".$this->args['meta_name'], array( &$this, 'wck_remove_meta') ); |
| 98 |
add_action("wp_ajax_wck_reorder_meta".$this->args['meta_name'], array( &$this, 'wck_reorder_meta') ); |
| 99 |
|
| 100 |
/* modify Insert into post button */ |
| 101 |
add_action('admin_head-media-upload-popup', array( &$this, 'wck_media_upload_popup_head') ); |
| 102 |
|
| 103 |
/* custom functionality for upload video */ |
| 104 |
add_filter('media_send_to_editor', array( &$this, 'wck_media_send_to_editor' ), 15, 2 ); |
| 105 |
|
| 106 |
add_action('add_meta_boxes', array( &$this, 'wck_add_metabox') ); |
| 107 |
|
| 108 |
/* hook to add a side metabox with the Syncronize translation button */ |
| 109 |
add_action('add_meta_boxes', array( &$this, 'wck_add_sync_translation_metabox' ) ); |
| 110 |
|
| 111 |
/* ajax hook the syncronization function */ |
| 112 |
add_action("wp_ajax_wck_sync_translation", array( &$this, 'wck_sync_translation_ajax' ) ); |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
//add metabox using wordpress api |
| 118 |
|
| 119 |
function wck_add_metabox() { |
| 120 |
|
| 121 |
global $pb_wck_pages_hooknames; |
| 122 |
|
| 123 |
if( $this->args['context'] == 'post_meta' ){ |
| 124 |
if( $this->args['post_id'] == '' && $this->args['page_template'] == '' ){ |
| 125 |
add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $this->args['post_type'], $this->args['mb_context'], 'high', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); |
| 126 |
/* add class to meta box */ |
| 127 |
add_filter( "postbox_classes_".$this->args['post_type']."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) ); |
| 128 |
} |
| 129 |
else{ |
| 130 |
if( !empty( $_GET['post'] ) ) |
| 131 |
$post_id = $_GET['post']; |
| 132 |
else if( !empty( $_POST['post_ID'] ) ) |
| 133 |
$post_id = $_POST['post_ID']; |
| 134 |
else |
| 135 |
$post_id = ''; |
| 136 |
|
| 137 |
|
| 138 |
if( $this->args['post_id'] != '' && $this->args['page_template'] != '' ){ |
| 139 |
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE); |
| 140 |
if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] ) |
| 141 |
add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), 'page', $this->args['mb_context'], 'high', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) ); |
| 142 |
|
| 143 |
/* add class to meta box */ |
| 144 |
add_filter( "postbox_classes_page_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) ); |
| 145 |
} |
| 146 |
else{ |
| 147 |
|
| 148 |
if( $this->args['post_id'] != '' ){ |
| 149 |
if( $this->args['post_id'] == $post_id ){ |
| 150 |
$post_type = get_post_type( $post_id ); |
| 151 |
add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $post_type, $this->args['mb_context'], 'high', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) ); |
| 152 |
/* add class to meta box */ |
| 153 |
add_filter( "postbox_classes_".$post_type."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) ); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
if( $this->args['page_template'] != '' ){ |
| 158 |
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE); |
| 159 |
if ( $template_file == $this->args['page_template'] ){ |
| 160 |
add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), 'page', $this->args['mb_context'], 'high', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); |
| 161 |
/* add class to meta box */ |
| 162 |
add_filter( "postbox_classes_page_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) ); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
} |
| 169 |
} |
| 170 |
else if( $this->args['context'] == 'option' ){ |
| 171 |
add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $pb_wck_pages_hooknames[$this->args['post_type']], $this->args['mb_context'], 'high', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); |
| 172 |
/* add class to meta box */ |
| 173 |
add_filter( "postbox_classes_".$pb_wck_pages_hooknames[$this->args['post_type']]."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) ); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
/* Function used to add classes to the wck meta boxes */ |
| 178 |
function wck_add_metabox_classes( $classes ){ |
| 179 |
array_push($classes,'wck-post-box'); |
| 180 |
return $classes; |
| 181 |
} |
| 182 |
|
| 183 |
function wck_content($post, $metabox){ |
| 184 |
if( !empty( $post->ID ) ) |
| 185 |
$post_id = $post->ID; |
| 186 |
else |
| 187 |
$post_id = ''; |
| 188 |
|
| 189 |
//output the add form |
| 190 |
if( $this->args['single'] ){ |
| 191 |
|
| 192 |
if( $this->args['context'] == 'post_meta' ) |
| 193 |
$meta_val = get_post_meta( $post_id, $metabox['args']['meta_name'], true ); |
| 194 |
else if ( $this->args['context'] == 'option' ) |
| 195 |
$meta_val = get_option( $metabox['args']['meta_name'] ); |
| 196 |
|
| 197 |
if( empty( $meta_val ) ) |
| 198 |
self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post); |
| 199 |
} |
| 200 |
else |
| 201 |
self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post); |
| 202 |
|
| 203 |
//output the entries |
| 204 |
echo self::wck_output_meta_content($metabox['args']['meta_name'], $post_id, $metabox['args']['meta_array']); |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* The function used to create a form element |
| 209 |
* |
| 210 |
* @since 1.0.0 |
| 211 |
* |
| 212 |
* @param string $meta Meta name. |
| 213 |
* @param array $details Contains the details for the field. |
| 214 |
* @param string $value Contains input value; |
| 215 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.; |
| 216 |
* @param int $post_id The post ID; |
| 217 |
* @return string $element input element html string. |
| 218 |
*/ |
| 219 |
|
| 220 |
function wck_output_form_field( $meta, $details, $value = '', $context = '', $post_id = '' ){ |
| 221 |
$element = ''; |
| 222 |
|
| 223 |
if( $context == 'edit_form' ){ |
| 224 |
$edit_class = '.mb-table-container '; |
| 225 |
$var_prefix = 'edit'; |
| 226 |
} |
| 227 |
else if( $context == 'fep' ){ |
| 228 |
/* id prefix for frontend posting */ |
| 229 |
$frontend_prefix = 'fep-'; |
| 230 |
} |
| 231 |
else{ |
| 232 |
if( !empty( $details['default'] ) ) |
| 233 |
$value = apply_filters( "wck_default_value_{$meta}_". Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) , $details['default'] ); |
| 234 |
} |
| 235 |
|
| 236 |
$element .= '<label for="'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" class="field-label">'. apply_filters( "wck_label_{$meta}_". Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ), ucfirst($details['title']) ) .':'; |
| 237 |
if( !empty( $details['required'] ) && $details['required'] ) |
| 238 |
$element .= '<span class="required">*</span>'; |
| 239 |
$element .= '</label>'; |
| 240 |
|
| 241 |
$element .= '<div class="mb-right-column">'; |
| 242 |
|
| 243 |
/* |
| 244 |
include actual field type |
| 245 |
possible field types: text, textarea, select, checkbox, radio, upload, wysiwyg editor, datepicker, country select, user select, cpt select |
| 246 |
*/ |
| 247 |
|
| 248 |
if( function_exists( 'wck_nr_get_repeater_boxes' ) ){ |
| 249 |
$cfc_titles = wck_nr_get_repeater_boxes(); |
| 250 |
if( in_array( $details['type'], $cfc_titles ) ){ |
| 251 |
$details['type'] = 'nested repeater'; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
if( file_exists( dirname( __FILE__ ).'/fields/'.$details['type'].'.php' ) ){ |
| 257 |
require( dirname( __FILE__ ).'/fields/'.$details['type'].'.php' ); |
| 258 |
} |
| 259 |
|
| 260 |
if( !empty( $details['description'] ) ){ |
| 261 |
$element .= '<p class="description">'. $details['description'].'</p>'; |
| 262 |
} |
| 263 |
|
| 264 |
$element .= '</div><!-- .mb-right-column -->'; |
| 265 |
|
| 266 |
$element = apply_filters( "wck_output_form_field_{$meta}_" . Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ), $element ); |
| 267 |
|
| 268 |
return $element; |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
/** |
| 274 |
* The function used to create the form for adding records |
| 275 |
* |
| 276 |
* @since 1.0.0 |
| 277 |
* |
| 278 |
* @param array $fields Contains the desired inputs in the repeater field. Must be like: array('Key:type'). |
| 279 |
* Key is used for the name attribute of the field, label of the field and as the meta_key. |
| 280 |
* Supported types: input, textarea, upload |
| 281 |
* @param string $meta It is used in update_post_meta($id, $meta, $results);. Use '_' prefix if you don't want |
| 282 |
* the meta to apear in custom fields box. |
| 283 |
* @param object $post Post object |
| 284 |
*/ |
| 285 |
function create_add_form($fields, $meta, $post){ |
| 286 |
$nonce = wp_create_nonce( 'wck-add-meta' ); |
| 287 |
if( !empty( $post->ID ) ) |
| 288 |
$post_id = $post->ID; |
| 289 |
else |
| 290 |
$post_id = ''; |
| 291 |
|
| 292 |
?> |
| 293 |
<div id="<?php echo $meta ?>" style="padding:10px 0;" class="wck-add-form<?php if( $this->args['single'] ) echo ' single' ?>"> |
| 294 |
<ul class="mb-list-entry-fields"> |
| 295 |
<?php |
| 296 |
$element_id = 0; |
| 297 |
if( !empty( $fields ) ){ |
| 298 |
foreach( $fields as $details ){ |
| 299 |
|
| 300 |
do_action( "wck_before_add_form_{$meta}_element_{$element_id}" ); |
| 301 |
|
| 302 |
?> |
| 303 |
<li class="row-<?php echo esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) ?>"> |
| 304 |
<?php echo self::wck_output_form_field( $meta, $details, '', '', $post_id ); ?> |
| 305 |
</li> |
| 306 |
<?php |
| 307 |
|
| 308 |
do_action( "wck_after_add_form_{$meta}_element_{$element_id}" ); |
| 309 |
|
| 310 |
$element_id++; |
| 311 |
} |
| 312 |
} |
| 313 |
?> |
| 314 |
<li style="overflow:visible;" class="add-entry-button"> |
| 315 |
<a href="javascript:void(0)" class="button-primary" onclick="addMeta('<?php echo esc_js($meta); ?>', '<?php echo esc_js( $post_id ); ?>', '<?php echo esc_js($nonce); ?>')"><span><?php _e( apply_filters( 'wck_add_entry_button', 'Add Entry', $meta, $post ), 'wck' ); ?></span></a> |
| 316 |
</li> |
| 317 |
</ul> |
| 318 |
</div> |
| 319 |
<?php |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* The function used to display a form to update a reccord from meta |
| 324 |
* |
| 325 |
* @since 1.0.0 |
| 326 |
* |
| 327 |
* @param string $meta It is used in get_post_meta($id, $meta, $results);. Use '_' prefix if you don't want |
| 328 |
* the meta to apear in custom fields box. |
| 329 |
* @param int $id Post id |
| 330 |
* @param int $element_id The id of the reccord. The meta is stored as array(array()); |
| 331 |
*/ |
| 332 |
function mb_update_form($fields, $meta, $id, $element_id){ |
| 333 |
|
| 334 |
$update_nonce = wp_create_nonce( 'wck-update-entry' ); |
| 335 |
|
| 336 |
if( $this->args['context'] == 'post_meta' ) |
| 337 |
$results = get_post_meta($id, $meta, true); |
| 338 |
else if ( $this->args['context'] == 'option' ) |
| 339 |
$results = get_option( $meta ); |
| 340 |
|
| 341 |
/* Filter primary used for CFC/OPC fields in order to show/hide fields based on type */ |
| 342 |
$wck_update_container_css_class = " class='update_container_$meta'"; |
| 343 |
$wck_update_container_css_class = apply_filters("wck_update_container_class_{$meta}", $wck_update_container_css_class, $meta, $results, $element_id ); |
| 344 |
|
| 345 |
$form = ''; |
| 346 |
$form .= '<tr id="update_container_'.$meta.'_'.$element_id.'" ' . $wck_update_container_css_class . '><td colspan="4">'; |
| 347 |
|
| 348 |
if($results != null){ |
| 349 |
$i = 0; |
| 350 |
$form .= '<ul class="mb-list-entry-fields">'; |
| 351 |
|
| 352 |
if( !empty( $fields ) ){ |
| 353 |
foreach( $fields as $field ){ |
| 354 |
$details = $field; |
| 355 |
if( !empty( $results[$element_id][Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details )] ) ) |
| 356 |
$value = $results[$element_id][Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details )]; |
| 357 |
else |
| 358 |
$value = ''; |
| 359 |
|
| 360 |
$form = apply_filters( "wck_before_update_form_{$meta}_element_{$i}", $form, $element_id, $value ); |
| 361 |
|
| 362 |
$form .= '<li class="row-'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'">'; |
| 363 |
|
| 364 |
$form .= self::wck_output_form_field( $meta, $details, $value, 'edit_form', $id ); |
| 365 |
|
| 366 |
$form .= '</li>'; |
| 367 |
|
| 368 |
$form = apply_filters( "wck_after_update_form_{$meta}_element_{$i}", $form, $element_id, $value ); |
| 369 |
|
| 370 |
$i++; |
| 371 |
} |
| 372 |
} |
| 373 |
$form .= '<li style="overflow:visible;">'; |
| 374 |
$form .= '<a href="javascript:void(0)" class="button-primary" onclick=\'updateMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($update_nonce).'")\'><span>'. __( apply_filters( 'wck_save_changes_button', 'Save Changes', $meta ), 'wck' ) .'</span></a>'; |
| 375 |
$form .= '<a href="javascript:void(0)" class="button-secondary" style="margin-left:10px;" onclick=\'removeUpdateForm("'. esc_js( 'update_container_'.$meta.'_'.$element_id ). '" )\'><span>'. __( apply_filters( 'wck_cancel_button', 'Cancel', $meta ), 'wck' ) .'</span></a>'; |
| 376 |
$form .= '</li>'; |
| 377 |
|
| 378 |
$form .= '</ul>'; |
| 379 |
} |
| 380 |
$form .= '</td></tr>'; |
| 381 |
|
| 382 |
return $form; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
/** |
| 387 |
* The function used to output the content of a meta |
| 388 |
* |
| 389 |
* @since 1.0.0 |
| 390 |
* |
| 391 |
* @param string $meta It is used in get_post_meta($id, $meta, $results);. Use '_' prefix if you don't want |
| 392 |
* the meta to apear in custom fields box. |
| 393 |
* @param int $id Post id |
| 394 |
*/ |
| 395 |
function wck_output_meta_content($meta, $id, $fields, $box_args = '' ){ |
| 396 |
/* in fep $this->args is empty so we need it as a parameter */ |
| 397 |
if( !empty( $box_args ) ) |
| 398 |
$this->args = wp_parse_args( $box_args, $this->defaults ); |
| 399 |
|
| 400 |
|
| 401 |
if( $this->args['context'] == 'post_meta' || $this->args['context'] == '' ) |
| 402 |
$results = get_post_meta($id, $meta, true); |
| 403 |
else if ( $this->args['context'] == 'option' ) |
| 404 |
$results = get_option( $meta ); |
| 405 |
|
| 406 |
$list = ''; |
| 407 |
$list .= '<table id="container_'.esc_attr($meta).'" class="mb-table-container widefat'; |
| 408 |
|
| 409 |
if( $this->args['single'] ) $list .= ' single'; |
| 410 |
if( !$this->args['sortable'] ) $list .= ' not-sortable'; |
| 411 |
|
| 412 |
$list .= '" post="'.esc_attr($id).'">'; |
| 413 |
|
| 414 |
|
| 415 |
if($results != null){ |
| 416 |
$list .= apply_filters( 'wck_metabox_content_header_'.$meta , '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( 'Content', 'wck' ) .'</th><th class="wck-edit">'. __( 'Edit', 'wck' ) .'</th><th class="wck-delete">'. __( 'Delete', 'wck' ) .'</th></tr></thead>' ); |
| 417 |
$i=0; |
| 418 |
foreach ($results as $result){ |
| 419 |
|
| 420 |
$list .= self::wck_output_entry_content( $meta, $id, $fields, $results, $i ); |
| 421 |
|
| 422 |
$i++; |
| 423 |
} |
| 424 |
} |
| 425 |
$list .= apply_filters( 'wck_metabox_content_footer_'.$meta , '' ); |
| 426 |
$list .= '</table>'; |
| 427 |
|
| 428 |
$list = apply_filters('wck_metabox_content_'.$meta, $list, $id); |
| 429 |
return $list; |
| 430 |
} |
| 431 |
|
| 432 |
function wck_output_entry_content( $meta, $id, $fields, $results, $element_id ){ |
| 433 |
$edit_nonce = wp_create_nonce( 'wck-edit-entry' ); |
| 434 |
$delete_nonce = wp_create_nonce( 'wck-delete-entry' ); |
| 435 |
$entry_nr = $element_id +1; |
| 436 |
|
| 437 |
$wck_element_class = ''; |
| 438 |
$wck_element_class = apply_filters( "wck_element_class_{$meta}", $wck_element_class, $meta, $results, $element_id ); |
| 439 |
|
| 440 |
$list = ''; |
| 441 |
$list .= '<tr id="element_'.$element_id.'" ' . $wck_element_class . '>'; |
| 442 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-number">'. $entry_nr .'</td>'; |
| 443 |
$list .= '<td class="wck-content"><ul>' . "\r\n"; |
| 444 |
|
| 445 |
$j = 0; |
| 446 |
|
| 447 |
if( !empty( $fields ) ){ |
| 448 |
foreach( $fields as $field ){ |
| 449 |
$details = $field; |
| 450 |
|
| 451 |
if( !empty( $results[$element_id][Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details )] ) ) |
| 452 |
$value = $results[$element_id][Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details )]; |
| 453 |
else |
| 454 |
$value =''; |
| 455 |
|
| 456 |
/* filter display value */ |
| 457 |
$value = apply_filters( "wck_displayed_value_{$meta}_element_{$j}", $value ); |
| 458 |
|
| 459 |
/* display it differently based on field type*/ |
| 460 |
if( $details['type'] == 'upload' ){ |
| 461 |
$display_value = self::wck_get_entry_field_upload($value); |
| 462 |
} elseif ( $details['type'] == 'user select' ) { |
| 463 |
$display_value = self::wck_get_entry_field_user_select( $value ) . '</pre>'; |
| 464 |
} elseif ( $details['type'] == 'cpt select' ){ |
| 465 |
$display_value = self::wck_get_entry_field_cpt_select( $value ) . '</pre>'; |
| 466 |
} else { |
| 467 |
$display_value = '<pre>'.htmlspecialchars( $value ) . '</pre>'; |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
$list = apply_filters( "wck_before_listed_{$meta}_element_{$j}", $list, $element_id, $value ); |
| 472 |
/*check for nested repeater type and set it acordingly */ |
| 473 |
if( strpos( $details['type'], 'CFC-') === 0 ) |
| 474 |
$details['type'] = 'nested-repeater'; |
| 475 |
|
| 476 |
$list .= '<li class="row-'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" data-type="'.$details['type'].'"><strong>'.$details['title'].': </strong>'.$display_value.' </li>' . "\r\n"; |
| 477 |
|
| 478 |
$list = apply_filters( "wck_after_listed_{$meta}_element_{$j}", $list, $element_id, $value ); |
| 479 |
|
| 480 |
$j++; |
| 481 |
|
| 482 |
/* In CFC/OPC we need the field title. Find it out and output it if found */ |
| 483 |
if ($meta == 'wck_cfc_fields') { |
| 484 |
if( !empty( $results[$element_id][Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details )] ) ){ |
| 485 |
$field_title = $results[$element_id][Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details )]; |
| 486 |
if ($field_title == "Field Type") |
| 487 |
$cfc_field_type = $value; |
| 488 |
} |
| 489 |
} |
| 490 |
} |
| 491 |
} |
| 492 |
$list .= '</ul>'; |
| 493 |
|
| 494 |
/* check if we have nested repeaters */ |
| 495 |
if( function_exists( 'wck_nr_check_for_nested_repeaters' ) ){ |
| 496 |
if( wck_nr_check_for_nested_repeaters( $fields ) === true ){ |
| 497 |
$list .= wck_nr_handle_repeaters( $meta, $id, $fields, $results, $element_id ); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
$list .= '</td>'; |
| 502 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-edit"><a href="javascript:void(0)" class="button-secondary" onclick=\'showUpdateFormMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($edit_nonce).'")\' title="'. __( 'Edit this item', 'wck' ) .'">'. __( 'Edit', 'wck' ) .'</a></td>'; |
| 503 |
$list .= '<td style="text-align:center;vertical-align:middle;" class="wck-delete"><a href="javascript:void(0)" class="mbdelete" onclick=\'removeMeta("'.esc_js($meta).'", "'.esc_js($id).'", "'.esc_js($element_id).'", "'.esc_js($delete_nonce).'")\' title="'. __( 'Delete this item', 'wck' ) .'">'. __( 'Delete', 'wck' ) .'</a></td>'; |
| 504 |
|
| 505 |
$list .= "</tr> \r\n"; |
| 506 |
|
| 507 |
return $list; |
| 508 |
} |
| 509 |
|
| 510 |
/* function to generate output for upload field */ |
| 511 |
function wck_get_entry_field_upload($id){ |
| 512 |
if( !empty ( $id ) && is_numeric( $id ) ){ |
| 513 |
$file_src = wp_get_attachment_url($id); |
| 514 |
$thumbnail = wp_get_attachment_image( $id, array( 80, 60 ), true ); |
| 515 |
$file_name = get_the_title( $id ); |
| 516 |
|
| 517 |
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $id ), $matches ) ) |
| 518 |
$file_type = esc_html( strtoupper( $matches[1] ) ); |
| 519 |
else |
| 520 |
$file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $id ) ) ); |
| 521 |
|
| 522 |
return $display_value = '<div class="upload-field-details">'. $thumbnail .'<p><span class="file-name">'. $file_name .'</span><span class="file-type">'. $file_type . '</span></p></div>'; |
| 523 |
} else { |
| 524 |
return ''; |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
/* function to generate output for user select */ |
| 529 |
function wck_get_entry_field_user_select($id){ |
| 530 |
if( !empty ( $id ) && is_numeric( $id ) ){ |
| 531 |
$user = get_user_by( 'id', $id ); |
| 532 |
if ( $user ) |
| 533 |
return '<pre>'.htmlspecialchars( $user->display_name ); |
| 534 |
else |
| 535 |
return 'Error - User ID not found in database'; |
| 536 |
|
| 537 |
} else { |
| 538 |
return ''; |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
/* function to generate output for cpt select */ |
| 543 |
function wck_get_entry_field_cpt_select($id){ |
| 544 |
if( !empty ( $id ) && is_numeric( $id ) ){ |
| 545 |
$post = get_post( $id ); |
| 546 |
|
| 547 |
if ( $post != null ){ |
| 548 |
if ( $post->post_title == '' ) |
| 549 |
$post->post_title = 'No title. ID: ' . $id; |
| 550 |
|
| 551 |
return '<pre>'.htmlspecialchars( $post->post_title ); |
| 552 |
} |
| 553 |
else |
| 554 |
return 'Error - Post ID not found in database'; |
| 555 |
|
| 556 |
} else { |
| 557 |
return ''; |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
/* enque the js/css */ |
| 562 |
function wck_print_scripts($hook){ |
| 563 |
global $pb_wck_pages_hooknames; |
| 564 |
|
| 565 |
if( $this->args['context'] == 'post_meta' ) { |
| 566 |
if( 'post.php' == $hook || 'post-new.php' == $hook){ |
| 567 |
|
| 568 |
/* only add on profile builder custom post types */ |
| 569 |
if( !empty( $_GET['post'] ) ) |
| 570 |
$post_id = $_GET['post']; |
| 571 |
else if( !empty( $_POST['post_ID'] ) ) |
| 572 |
$post_id = $_POST['post_ID']; |
| 573 |
else |
| 574 |
$post_id = ''; |
| 575 |
if( !empty( $post_id ) ){ |
| 576 |
$current_post_type = get_post_type( $post_id ); |
| 577 |
if( strpos( $current_post_type, 'wppb-' ) === false ) |
| 578 |
return ''; |
| 579 |
} |
| 580 |
|
| 581 |
self::wck_enqueue(); |
| 582 |
} |
| 583 |
} |
| 584 |
elseif( $this->args['context'] == 'option' ){ |
| 585 |
if( $pb_wck_pages_hooknames[$this->args['post_type']] == $hook ){ |
| 586 |
self::wck_enqueue( 'options' ); |
| 587 |
} |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
/* our own ajaxurl */ |
| 592 |
function wck_print_ajax_url(){ |
| 593 |
echo '<script type="text/javascript">var wckAjaxurl = "'. admin_url('admin-ajax.php') .'";</script>'; |
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
/* Helper function for enqueueing scripts and styles */ |
| 598 |
private static function wck_enqueue( $context = '' ){ |
| 599 |
|
| 600 |
wp_enqueue_script( 'jquery-ui-draggable' ); |
| 601 |
wp_enqueue_script( 'jquery-ui-droppable' ); |
| 602 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 603 |
|
| 604 |
if( $context == 'options' ){ |
| 605 |
wp_enqueue_script( 'thickbox' ); |
| 606 |
wp_enqueue_style( 'thickbox' ); |
| 607 |
} |
| 608 |
|
| 609 |
wp_enqueue_script('wordpress-creation-kit', plugins_url('/wordpress-creation-kit.js', __FILE__), array('jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable' ) ); |
| 610 |
wp_register_style('wordpress-creation-kit-css', plugins_url('/wordpress-creation-kit.css', __FILE__)); |
| 611 |
wp_enqueue_style('wordpress-creation-kit-css'); |
| 612 |
|
| 613 |
// wysiwyg |
| 614 |
// wp_register_script( 'wck-tinymce', plugins_url( '/assets/js/tiny_mce/tiny_mce.js', __FILE__ ), array(), '1.0', true ); |
| 615 |
// wp_enqueue_script( 'wck-tinymce' ); |
| 616 |
// wp_register_script( 'wck-tinymce-init', plugins_url( '/assets/js/tiny_mce/wck_tiny_mce_init.js', __FILE__ ), array(), '1.0', true ); |
| 617 |
// wp_enqueue_script( 'wck-tinymce-init' ); |
| 618 |
|
| 619 |
//datepicker |
| 620 |
wp_enqueue_script('jquery-ui-datepicker'); |
| 621 |
wp_enqueue_style( 'jquery-style', plugins_url( '/assets/datepicker/datepicker.css', __FILE__ ) ); |
| 622 |
|
| 623 |
} |
| 624 |
|
| 625 |
/* Helper function for required fields */ |
| 626 |
function wck_test_required( $meta_array, $meta, $values, $id ){ |
| 627 |
$fields = $meta_array; |
| 628 |
$required_fields = array(); |
| 629 |
$required_fields_with_errors = array(); |
| 630 |
$required_message = ''; |
| 631 |
|
| 632 |
$errors = ''; |
| 633 |
|
| 634 |
if( !empty( $fields ) ){ |
| 635 |
foreach( $fields as $field ){ |
| 636 |
if( !empty( $field['required'] ) && $field['required'] ) |
| 637 |
$required_fields[Wordpress_Creation_Kit_PB::wck_generate_slug( $field['title'], $field )] = $field['title']; |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
if( !empty( $values ) ){ |
| 642 |
foreach( $values as $key => $value ){ |
| 643 |
if( array_key_exists( $key, $required_fields ) && apply_filters( "wck_required_test_{$meta}_{$key}", empty( $value ), $value, $id ) ){ |
| 644 |
$required_message .= apply_filters( "wck_required_message_{$meta}_{$key}", __( "Please enter a value for the required field ", "wck" ) . "$required_fields[$key] \n", $value ); |
| 645 |
$required_fields_with_errors[] = $key; |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
$required_message .= apply_filters( "wck_extra_message", "", $fields, $required_fields, $meta, $values, $id ); |
| 651 |
$required_fields_with_errors = apply_filters( "wck_required_fields_with_errors", $required_fields_with_errors, $fields, $required_fields, $meta, $value, $id ); |
| 652 |
|
| 653 |
if( $required_message != '' ){ |
| 654 |
$errors = array( 'error' => $required_message, 'errorfields' => $required_fields_with_errors ); |
| 655 |
} |
| 656 |
|
| 657 |
return $errors; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
/* ajax add a reccord to the meta */ |
| 662 |
function wck_add_meta(){ |
| 663 |
check_ajax_referer( "wck-add-meta" ); |
| 664 |
if( !empty( $_POST['meta'] ) ) |
| 665 |
$meta = $_POST['meta']; |
| 666 |
else |
| 667 |
$meta = ''; |
| 668 |
if( !empty( $_POST['id'] ) ) |
| 669 |
$id = absint($_POST['id']); |
| 670 |
else |
| 671 |
$id = ''; |
| 672 |
if( !empty( $_POST['values'] ) ) |
| 673 |
$values = $_POST['values']; |
| 674 |
else |
| 675 |
$values = array(); |
| 676 |
|
| 677 |
$values = apply_filters( "wck_add_meta_filter_values_{$meta}", $values ); |
| 678 |
|
| 679 |
/* check required fields */ |
| 680 |
$errors = self::wck_test_required( $this->args['meta_array'], $meta, $values, $id ); |
| 681 |
if( $errors != '' ){ |
| 682 |
header( 'Content-type: application/json' ); |
| 683 |
die( json_encode( $errors ) ); |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
if( $this->args['context'] == 'post_meta' ) |
| 688 |
$results = get_post_meta($id, $meta, true); |
| 689 |
else if ( $this->args['context'] == 'option' ) |
| 690 |
$results = get_option( $meta ); |
| 691 |
|
| 692 |
$results[] = $values; |
| 693 |
|
| 694 |
do_action( 'wck_before_add_meta', $meta, $id, $values ); |
| 695 |
|
| 696 |
if( $this->args['context'] == 'post_meta' ) |
| 697 |
update_post_meta($id, $meta, $results); |
| 698 |
else if ( $this->args['context'] == 'option' ) |
| 699 |
update_option( $meta, wp_unslash( $results ) ); |
| 700 |
|
| 701 |
/* if unserialize_fields is true add for each entry separate post meta for every element of the form */ |
| 702 |
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){ |
| 703 |
|
| 704 |
$meta_suffix = count( $results ); |
| 705 |
if( !empty( $values ) ){ |
| 706 |
foreach( $values as $name => $value ){ |
| 707 |
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value); |
| 708 |
} |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
exit; |
| 713 |
} |
| 714 |
|
| 715 |
/* ajax update a reccord in the meta */ |
| 716 |
function wck_update_meta(){ |
| 717 |
check_ajax_referer( "wck-update-entry" ); |
| 718 |
if( !empty( $_POST['meta'] ) ) |
| 719 |
$meta = $_POST['meta']; |
| 720 |
else |
| 721 |
$meta = ''; |
| 722 |
if( !empty( $_POST['id'] ) ) |
| 723 |
$id = absint($_POST['id']); |
| 724 |
else |
| 725 |
$id = ''; |
| 726 |
if( isset( $_POST['element_id'] ) ) |
| 727 |
$element_id = $_POST['element_id']; |
| 728 |
else |
| 729 |
$element_id = 0; |
| 730 |
if( !empty( $_POST['values'] ) ) |
| 731 |
$values = $_POST['values']; |
| 732 |
|
| 733 |
|
| 734 |
$values = apply_filters( "wck_update_meta_filter_values_{$meta}", $values, $element_id ); |
| 735 |
|
| 736 |
/* check required fields */ |
| 737 |
$errors = self::wck_test_required( $this->args['meta_array'], $meta, $values, $id ); |
| 738 |
if( $errors != '' ){ |
| 739 |
header( 'Content-type: application/json' ); |
| 740 |
die( json_encode( $errors ) ); |
| 741 |
} |
| 742 |
|
| 743 |
if( $this->args['context'] == 'post_meta' ) |
| 744 |
$results = get_post_meta($id, $meta, true); |
| 745 |
else if ( $this->args['context'] == 'option' ) |
| 746 |
$results = get_option( $meta ); |
| 747 |
|
| 748 |
$results[$element_id] = $values; |
| 749 |
|
| 750 |
do_action( 'wck_before_update_meta', $meta, $id, $values, $element_id ); |
| 751 |
|
| 752 |
if( $this->args['context'] == 'post_meta' ) |
| 753 |
update_post_meta($id, $meta, $results); |
| 754 |
else if ( $this->args['context'] == 'option' ) |
| 755 |
update_option( $meta, wp_unslash( $results ) ); |
| 756 |
|
| 757 |
/* if unserialize_fields is true update the coresponding post metas for every element of the form */ |
| 758 |
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){ |
| 759 |
|
| 760 |
$meta_suffix = $element_id + 1; |
| 761 |
if( !empty( $values ) ){ |
| 762 |
foreach( $values as $name => $value ){ |
| 763 |
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value); |
| 764 |
} |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
exit; |
| 769 |
} |
| 770 |
|
| 771 |
/* ajax to refresh the meta content */ |
| 772 |
function wck_refresh_list(){ |
| 773 |
if( isset( $_POST['meta'] ) ) |
| 774 |
$meta = $_POST['meta']; |
| 775 |
else |
| 776 |
$meta = ''; |
| 777 |
if( isset( $_POST['id'] ) ) |
| 778 |
$id = absint($_POST['id']); |
| 779 |
else |
| 780 |
$id = ''; |
| 781 |
echo self::wck_output_meta_content($meta, $id, $this->args['meta_array']); |
| 782 |
|
| 783 |
do_action( "wck_refresh_list_{$meta}", $id ); |
| 784 |
|
| 785 |
exit; |
| 786 |
} |
| 787 |
|
| 788 |
/* ajax to refresh an entry content */ |
| 789 |
function wck_refresh_entry(){ |
| 790 |
if( isset( $_POST['meta'] ) ) |
| 791 |
$meta = $_POST['meta']; |
| 792 |
else |
| 793 |
$meta = ''; |
| 794 |
if( isset( $_POST['id'] ) ) |
| 795 |
$id = absint( $_POST['id'] ); |
| 796 |
else |
| 797 |
$id = ''; |
| 798 |
if( isset( $_POST['element_id'] ) ) |
| 799 |
$element_id = $_POST['element_id']; |
| 800 |
else |
| 801 |
$element_id = ''; |
| 802 |
|
| 803 |
if( $this->args['context'] == 'post_meta' ) |
| 804 |
$results = get_post_meta($id, $meta, true); |
| 805 |
else if ( $this->args['context'] == 'option' ) |
| 806 |
$results = get_option( $meta ); |
| 807 |
|
| 808 |
echo self::wck_output_entry_content( $meta, $id, $this->args['meta_array'], $results, $element_id ); |
| 809 |
|
| 810 |
do_action( "wck_refresh_entry_{$meta}", $id ); |
| 811 |
|
| 812 |
exit; |
| 813 |
} |
| 814 |
|
| 815 |
/* ajax to add the form for single */ |
| 816 |
function wck_add_form(){ |
| 817 |
if( !empty( $_POST['meta'] ) ) |
| 818 |
$meta = $_POST['meta']; |
| 819 |
else |
| 820 |
$meta = ''; |
| 821 |
if( !empty( $_POST['id'] ) ) |
| 822 |
$id = absint( $_POST['id'] ); |
| 823 |
else |
| 824 |
$id = ''; |
| 825 |
$post = get_post($id); |
| 826 |
self::create_add_form($this->args['meta_array'], $meta, $post ); |
| 827 |
do_action( "wck_ajax_add_form_{$meta}", $id ); |
| 828 |
|
| 829 |
exit; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
/* ajax to show the update form */ |
| 834 |
function wck_show_update_form(){ |
| 835 |
check_ajax_referer( "wck-edit-entry" ); |
| 836 |
$meta = $_POST['meta']; |
| 837 |
$id = absint($_POST['id']); |
| 838 |
$element_id = $_POST['element_id']; |
| 839 |
|
| 840 |
echo self::mb_update_form($this->args['meta_array'], $meta, $id, $element_id); |
| 841 |
|
| 842 |
do_action( "wck_after_adding_form", $meta, $id, $element_id ); |
| 843 |
do_action( "wck_after_adding_form_{$meta}", $id, $element_id ); |
| 844 |
|
| 845 |
exit; |
| 846 |
} |
| 847 |
|
| 848 |
/* ajax to remove a reccord from the meta */ |
| 849 |
function wck_remove_meta(){ |
| 850 |
check_ajax_referer( "wck-delete-entry" ); |
| 851 |
if( !empty( $_POST['meta'] ) ) |
| 852 |
$meta = $_POST['meta']; |
| 853 |
else |
| 854 |
$meta = ''; |
| 855 |
if( !empty( $_POST['id'] ) ) |
| 856 |
$id = absint( $_POST['id'] ); |
| 857 |
else |
| 858 |
$id = ''; |
| 859 |
if( isset( $_POST['element_id'] ) ) |
| 860 |
$element_id = absint( $_POST['element_id'] ); |
| 861 |
else |
| 862 |
$element_id = ''; |
| 863 |
|
| 864 |
if( $this->args['context'] == 'post_meta' ) |
| 865 |
$results = get_post_meta($id, $meta, true); |
| 866 |
else if ( $this->args['context'] == 'option' ) |
| 867 |
$results = get_option( $meta ); |
| 868 |
|
| 869 |
$old_results = $results; |
| 870 |
unset($results[$element_id]); |
| 871 |
/* reset the keys for the array */ |
| 872 |
$results = array_values($results); |
| 873 |
|
| 874 |
do_action( 'wck_before_remove_meta', $meta, $id, $element_id ); |
| 875 |
|
| 876 |
if( $this->args['context'] == 'post_meta' ) |
| 877 |
update_post_meta($id, $meta, $results); |
| 878 |
else if ( $this->args['context'] == 'option' ) |
| 879 |
update_option( $meta, wp_unslash( $results ) ); |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
/* TODO: optimize so that it updates from the deleted element forward */ |
| 884 |
/* if unserialize_fields is true delete the coresponding post metas */ |
| 885 |
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){ |
| 886 |
|
| 887 |
$meta_suffix = 1; |
| 888 |
|
| 889 |
if( !empty( $results ) ){ |
| 890 |
foreach( $results as $result ){ |
| 891 |
foreach ( $result as $name => $value){ |
| 892 |
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value); |
| 893 |
} |
| 894 |
$meta_suffix++; |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
if( count( $results ) == 0 ) |
| 899 |
$results = $old_results; |
| 900 |
|
| 901 |
if( !empty( $results ) ){ |
| 902 |
foreach( $results as $result ){ |
| 903 |
foreach ( $result as $name => $value){ |
| 904 |
delete_post_meta( $id, $meta.'_'.$name.'_'.$meta_suffix ); |
| 905 |
} |
| 906 |
break; |
| 907 |
} |
| 908 |
} |
| 909 |
} |
| 910 |
|
| 911 |
exit; |
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
/* ajax to reorder records */ |
| 916 |
function wck_reorder_meta(){ |
| 917 |
if( !empty( $_POST['meta'] ) ) |
| 918 |
$meta = $_POST['meta']; |
| 919 |
else |
| 920 |
$meta = ''; |
| 921 |
if( !empty( $_POST['id'] ) ) |
| 922 |
$id = absint($_POST['id']); |
| 923 |
else |
| 924 |
$id = ''; |
| 925 |
if( !empty( $_POST['values'] ) ) |
| 926 |
$elements_id = $_POST['values']; |
| 927 |
else |
| 928 |
$elements_id = array(); |
| 929 |
|
| 930 |
do_action( 'wck_before_reorder_meta', $meta, $id, $elements_id ); |
| 931 |
|
| 932 |
if( $this->args['context'] == 'post_meta' ) |
| 933 |
$results = get_post_meta($id, $meta, true); |
| 934 |
else if ( $this->args['context'] == 'option' ) |
| 935 |
$results = get_option( $meta ); |
| 936 |
|
| 937 |
$new_results = array(); |
| 938 |
if( !empty( $elements_id ) ){ |
| 939 |
foreach($elements_id as $element_id){ |
| 940 |
$new_results[] = $results[$element_id]; |
| 941 |
} |
| 942 |
} |
| 943 |
|
| 944 |
$results = $new_results; |
| 945 |
|
| 946 |
if( $this->args['context'] == 'post_meta' ) |
| 947 |
update_post_meta($id, $meta, $results); |
| 948 |
else if ( $this->args['context'] == 'option' ) |
| 949 |
update_option( $meta, wp_unslash( $results ) ); |
| 950 |
|
| 951 |
|
| 952 |
/* if unserialize_fields is true reorder all the coresponding post metas */ |
| 953 |
if( $this->args['unserialize_fields'] && $this->args['context'] == 'post_meta' ){ |
| 954 |
|
| 955 |
$meta_suffix = 1; |
| 956 |
if( !empty( $new_results ) ){ |
| 957 |
foreach( $new_results as $result ){ |
| 958 |
foreach ( $result as $name => $value){ |
| 959 |
update_post_meta($id, $meta.'_'.$name.'_'.$meta_suffix, $value); |
| 960 |
} |
| 961 |
$meta_suffix++; |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
} |
| 966 |
|
| 967 |
exit; |
| 968 |
} |
| 969 |
|
| 970 |
/* modify Insert into post button */ |
| 971 |
function wck_media_upload_popup_head() |
| 972 |
{ |
| 973 |
if( isset( $_GET["meta_name"] ) ){ |
| 974 |
if( $this->args['meta_name'] == $_GET["meta_name"] ){ |
| 975 |
if( ( isset( $_GET["mb_type"] ) ) ){ |
| 976 |
?> |
| 977 |
<style type="text/css"> |
| 978 |
#media-upload-header #sidemenu li#tab-type_url, |
| 979 |
#media-upload-header #sidemenu li#tab-gallery { |
| 980 |
display: none; |
| 981 |
} |
| 982 |
|
| 983 |
#media-items tr.url, |
| 984 |
#media-items tr.align, |
| 985 |
#media-items tr.image_alt, |
| 986 |
#media-items tr.image-size, |
| 987 |
#media-items tr.post_excerpt, |
| 988 |
#media-items tr.post_content, |
| 989 |
#media-items tr.image_alt p, |
| 990 |
#media-items table thead input.button, |
| 991 |
#media-items table thead img.imgedit-wait-spin, |
| 992 |
#media-items tr.submit a.wp-post-thumbnail { |
| 993 |
display: none; |
| 994 |
} |
| 995 |
|
| 996 |
.media-item table thead img { |
| 997 |
border: #DFDFDF solid 1px; |
| 998 |
margin-right: 10px; |
| 999 |
} |
| 1000 |
|
| 1001 |
</style> |
| 1002 |
<script type="text/javascript"> |
| 1003 |
(function($){ |
| 1004 |
|
| 1005 |
$(document).ready(function(){ |
| 1006 |
|
| 1007 |
$('#media-items').bind('DOMNodeInserted',function(){ |
| 1008 |
$('input[value="Insert into Post"]').each(function(){ |
| 1009 |
$(this).attr('value','<?php _e("Select File")?>'); |
| 1010 |
}); |
| 1011 |
}).trigger('DOMNodeInserted'); |
| 1012 |
|
| 1013 |
$('form#filter').each(function(){ |
| 1014 |
|
| 1015 |
$(this).append('<input type="hidden" name="mb_type" value="<?php echo $_GET['mb_type']; ?>" />'); |
| 1016 |
$(this).append('<input type="hidden" name="mb_info_div" value="<?php echo $_GET['mb_info_div']; ?>" />'); |
| 1017 |
|
| 1018 |
}); |
| 1019 |
}); |
| 1020 |
|
| 1021 |
})(jQuery); |
| 1022 |
</script> |
| 1023 |
<?php |
| 1024 |
} |
| 1025 |
} |
| 1026 |
} |
| 1027 |
} |
| 1028 |
|
| 1029 |
/* custom functionality for upload button */ |
| 1030 |
|
| 1031 |
function wck_media_send_to_editor($html, $id) |
| 1032 |
{ |
| 1033 |
parse_str($_POST["_wp_http_referer"], $arr_postinfo); |
| 1034 |
|
| 1035 |
if(isset($arr_postinfo["mb_type"])) |
| 1036 |
{ |
| 1037 |
$file_src = wp_get_attachment_url($id); |
| 1038 |
$thumbnail = wp_get_attachment_image( $id, array( 80, 60 ), true ); |
| 1039 |
$file_name = get_the_title( $id ); |
| 1040 |
|
| 1041 |
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $id ), $matches ) ) |
| 1042 |
$file_type = esc_html( strtoupper( $matches[1] ) ); |
| 1043 |
else |
| 1044 |
$file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $id ) ) ); |
| 1045 |
|
| 1046 |
?> |
| 1047 |
<script type="text/javascript"> |
| 1048 |
|
| 1049 |
self.parent.window. <?php echo $arr_postinfo["mb_type"];?> .val('<?php echo $id; ?>'); |
| 1050 |
self.parent.window. <?php echo $arr_postinfo["mb_info_div"];?> .html('<?php echo $thumbnail ?><p><span class="file-name"><?php echo $file_name; ?></span><span class="file-type"><?php echo $file_type; ?></span><span class="wck-remove-upload"><?php _e( 'Remove', 'wck' )?></span></p>'); |
| 1051 |
|
| 1052 |
self.parent.tb_remove(); |
| 1053 |
|
| 1054 |
</script> |
| 1055 |
<?php |
| 1056 |
exit; |
| 1057 |
} |
| 1058 |
else |
| 1059 |
{ |
| 1060 |
return $html; |
| 1061 |
} |
| 1062 |
|
| 1063 |
} |
| 1064 |
|
| 1065 |
/* WPML Compatibility */ |
| 1066 |
|
| 1067 |
/** |
| 1068 |
* Function that ads the side metabox with the Syncronize translation button. |
| 1069 |
* The meta box is only added if the lang attribute is set and |
| 1070 |
* if any of the custom fields has the 'wckwpml' prefix. |
| 1071 |
*/ |
| 1072 |
function wck_add_sync_translation_metabox(){ |
| 1073 |
global $post; |
| 1074 |
|
| 1075 |
if( isset( $_GET['lang'] ) ){ |
| 1076 |
|
| 1077 |
$has_wck_with_unserialize_fields = false; |
| 1078 |
$custom_field_keys = get_post_custom_keys( $post->ID ); |
| 1079 |
if( !empty( $custom_field_keys ) ){ |
| 1080 |
foreach( $custom_field_keys as $custom_field_key ){ |
| 1081 |
$custom_field_key = explode( '_', $custom_field_key ); |
| 1082 |
if( $custom_field_key[0] == 'wckwpml' ){ |
| 1083 |
$has_wck_with_unserialize_fields = true; |
| 1084 |
break; |
| 1085 |
} |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
if($has_wck_with_unserialize_fields){ |
| 1090 |
add_meta_box( 'wck_sync_translation', __( 'Syncronize WCK', 'wck' ), array( &$this, 'wck_add_sync_box' ), $post->post_type, 'side', 'low' ); |
| 1091 |
} |
| 1092 |
|
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
/** |
| 1097 |
* Callback for the add_meta_box function that ads the "Syncronize WCK Translation" button. |
| 1098 |
*/ |
| 1099 |
function wck_add_sync_box(){ |
| 1100 |
global $post; |
| 1101 |
?> |
| 1102 |
<span id="wck_sync" class="button" onclick="wckSyncTranslation(<?php echo $post->ID; ?>)"><?php _e( 'Syncronize WCK Translation', 'wck' ) ?></span> |
| 1103 |
<?php |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
/** |
| 1109 |
* Function that recreates the serialized metas from the individual meta fields. |
| 1110 |
*/ |
| 1111 |
function wck_sync_translation_ajax(){ |
| 1112 |
if( !empty( $_POST['id'] ) ) |
| 1113 |
$post_id = $_POST['id']; |
| 1114 |
else |
| 1115 |
$post_id = ''; |
| 1116 |
|
| 1117 |
/* get all the custom fields keys for the post */ |
| 1118 |
$custom_field_keys = (array)get_post_custom_keys( $post_id ); |
| 1119 |
|
| 1120 |
/* initialize an array that will hold all the arrays for all the wck boxes */ |
| 1121 |
$wck_array = array(); |
| 1122 |
|
| 1123 |
/* go through all the custom fields and if it is a custom field created automaticaly for the translation add it to the $wck_array array*/ |
| 1124 |
if( !empty( $custom_field_keys ) ){ |
| 1125 |
foreach( $custom_field_keys as $cf ){ |
| 1126 |
|
| 1127 |
$cf_name_array = explode( '_', $cf ); |
| 1128 |
|
| 1129 |
/* a custom field added for the translation will have this form |
| 1130 |
'wckwpml_{meta name}_{field name}_{entry position}_{field position}' |
| 1131 |
*/ |
| 1132 |
if( count( $cf_name_array ) >= 5 ){ |
| 1133 |
|
| 1134 |
$cf_name = implode( '_', array_slice( $cf_name_array, 1, -3 ) ); |
| 1135 |
|
| 1136 |
if( $cf_name_array[0] == 'wckwpml' ){ |
| 1137 |
|
| 1138 |
$wck_key = $cf_name_array[ count($cf_name_array) -3 ]; |
| 1139 |
$wck_position = $cf_name_array[ count($cf_name_array) -2 ]; |
| 1140 |
$wck_field_position = $cf_name_array[ count($cf_name_array) -1 ]; |
| 1141 |
|
| 1142 |
/* "$wck_position - 1" is required because fields in wck by default start at 0 and the additional |
| 1143 |
translation fields start at 1 */ |
| 1144 |
$wck_array[$cf_name][$wck_position - 1][$wck_field_position][$wck_key] = get_post_meta($post_id,$cf,true); |
| 1145 |
|
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
if( !empty( $wck_array ) ){ |
| 1154 |
/* sort the array so that the entry order and fields order are synced */ |
| 1155 |
self::deep_ksort( $wck_array ); |
| 1156 |
|
| 1157 |
/* remove the field position level in the array because it was added just so we could keep the field |
| 1158 |
order in place */ |
| 1159 |
$wck_array = self::wck_reconstruct_array($wck_array); |
| 1160 |
|
| 1161 |
/* add the translated meta to the post */ |
| 1162 |
foreach( $wck_array as $wck_key => $wck_meta ){ |
| 1163 |
update_post_meta( $post_id, $wck_key, $wck_meta ); |
| 1164 |
} |
| 1165 |
echo('syncsuccess'); |
| 1166 |
} |
| 1167 |
|
| 1168 |
exit; |
| 1169 |
} |
| 1170 |
|
| 1171 |
/** |
| 1172 |
* Function that deep sorts a multy array by numeric key |
| 1173 |
*/ |
| 1174 |
function deep_ksort(&$arr) { |
| 1175 |
ksort($arr); |
| 1176 |
if( !empty( $arr ) ){ |
| 1177 |
foreach ($arr as &$a) { |
| 1178 |
if (is_array($a) && !empty($a)) { |
| 1179 |
self::deep_ksort($a); |
| 1180 |
} |
| 1181 |
} |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
/** |
| 1186 |
* Function that removes the field position level |
| 1187 |
*/ |
| 1188 |
function wck_reconstruct_array($wck_array){ |
| 1189 |
if( !empty( $wck_array ) ){ |
| 1190 |
foreach( $wck_array as $wck_array_key => $wck_meta ){ |
| 1191 |
if( !empty( $wck_meta ) ){ |
| 1192 |
foreach( $wck_meta as $wck_meta_key => $wck_entry ){ |
| 1193 |
if( !empty( $wck_entry ) ){ |
| 1194 |
foreach( $wck_entry as $wck_entry_key => $wck_field ){ |
| 1195 |
$wck_array[$wck_array_key][$wck_meta_key][key($wck_field)] = current($wck_field); |
| 1196 |
unset($wck_array[$wck_array_key][$wck_meta_key][$wck_entry_key]); |
| 1197 |
} |
| 1198 |
} |
| 1199 |
} |
| 1200 |
} |
| 1201 |
} |
| 1202 |
} |
| 1203 |
return $wck_array; |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
function wck_get_meta_boxes( $screen = null ){ |
| 1208 |
global $wp_meta_boxes, $wck_objects; |
| 1209 |
|
| 1210 |
if ( empty( $screen ) ) |
| 1211 |
$screen = get_current_screen(); |
| 1212 |
elseif ( is_string( $screen ) ) |
| 1213 |
$screen = convert_to_screen( $screen ); |
| 1214 |
|
| 1215 |
$page = $screen->id; |
| 1216 |
|
| 1217 |
$wck_meta_boxes = array(); |
| 1218 |
|
| 1219 |
if( !empty( $wck_objects ) && !empty( $wp_meta_boxes[$page]['normal']['low'] ) ){ |
| 1220 |
foreach( $wck_objects as $key => $wck_object ){ |
| 1221 |
if( array_key_exists( $key, $wp_meta_boxes[$page]['normal']['low'] ) ) |
| 1222 |
$wck_meta_boxes[] = $key; |
| 1223 |
} |
| 1224 |
} |
| 1225 |
|
| 1226 |
return $wck_meta_boxes; |
| 1227 |
} |
| 1228 |
|
| 1229 |
|
| 1230 |
/** |
| 1231 |
* The function used to generate slugs in WCK |
| 1232 |
* |
| 1233 |
* @since 1.1.1 |
| 1234 |
* |
| 1235 |
* @param string $string The input string from which we generate the slug |
| 1236 |
* @return string $slug The henerated slug |
| 1237 |
*/ |
| 1238 |
static function wck_generate_slug( $string, $details = array() ){ |
| 1239 |
if( !empty( $details['slug'] ) ) |
| 1240 |
$slug = $details['slug']; |
| 1241 |
else |
| 1242 |
$slug = rawurldecode( sanitize_title_with_dashes( remove_accents( $string ) ) ); |
| 1243 |
return $slug; |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
|
| 1248 |
/* |
| 1249 |
Helper class that creates admin menu pages ( both top level menu pages and submenu pages ) |
| 1250 |
Default Usage: |
| 1251 |
|
| 1252 |
$args = array( |
| 1253 |
'page_type' => 'menu_page', |
| 1254 |
'page_title' => '', |
| 1255 |
'menu_title' => '', |
| 1256 |
'capability' => '', |
| 1257 |
'menu_slug' => '', |
| 1258 |
'icon_url' => '', |
| 1259 |
'position' => '', |
| 1260 |
'parent_slug' => '' |
| 1261 |
); |
| 1262 |
|
| 1263 |
'page_type' (string) (required) The type of page you want to add. Possible values: 'menu_page', 'submenu_page' |
| 1264 |
'page_title' (string) (required) The text to be displayed in the title tags and header of |
| 1265 |
the page when the menu is selected |
| 1266 |
'menu_title' (string) (required) The on-screen name text for the menu |
| 1267 |
'capability' (string) (required) The capability required for this menu to be displayed to |
| 1268 |
the user. |
| 1269 |
'menu_slug' (string) (required) The slug name to refer to this menu by (should be unique |
| 1270 |
for this menu). |
| 1271 |
'icon_url' (string) (optional for 'page_type' => 'menu_page') The url to the icon to be used for this menu. |
| 1272 |
This parameter is optional. Icons should be fairly small, around 16 x 16 pixels |
| 1273 |
for best results. |
| 1274 |
'position' (integer) (optional for 'page_type' => 'menu_page') The position in the menu order this menu |
| 1275 |
should appear. |
| 1276 |
By default, if this parameter is omitted, the menu will appear at the bottom |
| 1277 |
of the menu structure. The higher the number, the lower its position in the menu. |
| 1278 |
WARNING: if 2 menu items use the same position attribute, one of the items may be |
| 1279 |
overwritten so that only one item displays! |
| 1280 |
'parent_slug' (string) (required for 'page_type' => 'submenu_page' ) The slug name for the parent menu |
| 1281 |
(or the file name of a standard WordPress admin page) For examples see http://codex.wordpress.org/Function_Reference/add_submenu_page $parent_slug parameter |
| 1282 |
'priority' (int) (optional) How important your function is. Alter this to make your function |
| 1283 |
be called before or after other functions. The default is 10, so (for example) setting it to 5 would make it run earlier and setting it to 12 would make it run later. |
| 1284 |
|
| 1285 |
public $hookname ( for required for 'page_type' => 'menu_page' ) string used internally to |
| 1286 |
track menu page callbacks for outputting the page inside the global $menu array |
| 1287 |
( for required for 'page_type' => 'submenu_page' ) The resulting page's hook_suffix, |
| 1288 |
or false if the user does not have the capability required. |
| 1289 |
*/ |
| 1290 |
|
| 1291 |
class WCK_Page_Creator_PB{ |
| 1292 |
|
| 1293 |
private $defaults = array( |
| 1294 |
'page_type' => 'menu_page', |
| 1295 |
'page_title' => '', |
| 1296 |
'menu_title' => '', |
| 1297 |
'capability' => '', |
| 1298 |
'menu_slug' => '', |
| 1299 |
'icon_url' => '', |
| 1300 |
'position' => '', |
| 1301 |
'parent_slug' => '', |
| 1302 |
'priority' => 10, |
| 1303 |
'network_page' => false |
| 1304 |
); |
| 1305 |
private $args; |
| 1306 |
public $hookname; |
| 1307 |
|
| 1308 |
|
| 1309 |
/* Constructor method for the class. */ |
| 1310 |
function __construct( $args ) { |
| 1311 |
|
| 1312 |
/* Global that will hold all the arguments for all the menu pages */ |
| 1313 |
global $wck_pages; |
| 1314 |
|
| 1315 |
/* Merge the input arguments and the defaults. */ |
| 1316 |
$this->args = wp_parse_args( $args, $this->defaults ); |
| 1317 |
|
| 1318 |
/* Add the settings for this page to the global object */ |
| 1319 |
$wck_pages[$this->args['page_title']] = $this->args; |
| 1320 |
|
| 1321 |
if( !$this->args['network_page'] ){ |
| 1322 |
/* Hook the page function to 'admin_menu'. */ |
| 1323 |
add_action( 'admin_menu', array( &$this, 'wck_page_init' ), $this->args['priority'] ); |
| 1324 |
} |
| 1325 |
else{ |
| 1326 |
/* Hook the page function to 'admin_menu'. */ |
| 1327 |
add_action( 'network_admin_menu', array( &$this, 'wck_page_init' ), $this->args['priority'] ); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
/** |
| 1332 |
* Function that creates the admin page |
| 1333 |
*/ |
| 1334 |
function wck_page_init(){ |
| 1335 |
global $pb_wck_pages_hooknames; |
| 1336 |
|
| 1337 |
/* Create the page using either add_menu_page or add_submenu_page functions depending on the 'page_type' parameter. */ |
| 1338 |
if( $this->args['page_type'] == 'menu_page' ){ |
| 1339 |
$this->hookname = add_menu_page( $this->args['page_title'], $this->args['menu_title'], $this->args['capability'], $this->args['menu_slug'], array( &$this, 'wck_page_template' ), $this->args['icon_url'], $this->args['position'] ); |
| 1340 |
|
| 1341 |
$pb_wck_pages_hooknames[$this->args['menu_slug']] = $this->hookname; |
| 1342 |
} |
| 1343 |
else if( $this->args['page_type'] == 'submenu_page' ){ |
| 1344 |
$this->hookname = add_submenu_page( $this->args['parent_slug'], $this->args['page_title'], $this->args['menu_title'], $this->args['capability'], $this->args['menu_slug'], array( &$this, 'wck_page_template' ) ); |
| 1345 |
|
| 1346 |
$pb_wck_pages_hooknames[$this->args['menu_slug']] = $this->hookname; |
| 1347 |
} |
| 1348 |
|
| 1349 |
do_action( 'WCK_Page_Creator_PB_after_init', $this->hookname ); |
| 1350 |
|
| 1351 |
/* Create a hook for adding meta boxes. */ |
| 1352 |
add_action( "load-{$this->hookname}", array( &$this, 'wck_settings_page_add_meta_boxes' ) ); |
| 1353 |
/* Load the JavaScript needed for the screen. */ |
| 1354 |
add_action( 'admin_enqueue_scripts', array( &$this, 'wck_page_enqueue_scripts' ) ); |
| 1355 |
add_action( "admin_head-{$this->hookname}", array( &$this, 'wck_page_load_scripts' ) ); |
| 1356 |
} |
| 1357 |
|
| 1358 |
/** |
| 1359 |
* Do action 'add_meta_boxes'. This hook isn't executed by default on a admin page so we have to add it. |
| 1360 |
*/ |
| 1361 |
function wck_settings_page_add_meta_boxes() { |
| 1362 |
do_action( 'add_meta_boxes', $this->hookname ); |
| 1363 |
} |
| 1364 |
|
| 1365 |
/** |
| 1366 |
* Loads the JavaScript files required for managing the meta boxes on the theme settings |
| 1367 |
* page, which allows users to arrange the boxes to their liking. |
| 1368 |
* |
| 1369 |
* @global string $bareskin_settings_page. The global setting page (returned by add_theme_page in function |
| 1370 |
* bareskin_settings_page_init ). |
| 1371 |
* @since 1.0.0 |
| 1372 |
* @param string $hook The current page being viewed. |
| 1373 |
*/ |
| 1374 |
function wck_page_enqueue_scripts( $hook ) { |
| 1375 |
if ( $hook == $this->hookname ) { |
| 1376 |
wp_enqueue_script( 'common' ); |
| 1377 |
wp_enqueue_script( 'wp-lists' ); |
| 1378 |
wp_enqueue_script( 'postbox' ); |
| 1379 |
} |
| 1380 |
} |
| 1381 |
|
| 1382 |
/** |
| 1383 |
* Loads the JavaScript required for toggling the meta boxes on the theme settings page. |
| 1384 |
* |
| 1385 |
* @global string $bareskin_settings_page. The global setting page (returned by add_theme_page in function |
| 1386 |
* bareskin_settings_page_init ). |
| 1387 |
* @since 1.0.0 |
| 1388 |
*/ |
| 1389 |
function wck_page_load_scripts() { |
| 1390 |
?> |
| 1391 |
<script type="text/javascript"> |
| 1392 |
//<![CDATA[ |
| 1393 |
jQuery(document).ready( function($) { |
| 1394 |
$('.if-js-closed').removeClass('if-js-closed').addClass('closed'); |
| 1395 |
postboxes.add_postbox_toggles( '<?php echo $this->hookname; ?>' ); |
| 1396 |
}); |
| 1397 |
//]]> |
| 1398 |
</script><?php |
| 1399 |
} |
| 1400 |
|
| 1401 |
/** |
| 1402 |
* Outputs default template for the page. It contains placeholders for metaboxes. It also |
| 1403 |
* provides two action hooks 'wck_before_meta_boxes' and 'wck_after_meta_boxes'. |
| 1404 |
*/ |
| 1405 |
function wck_page_template(){ |
| 1406 |
?> |
| 1407 |
<div class="wrap"> |
| 1408 |
|
| 1409 |
<?php if( !empty( $this->args['page_icon'] ) ): ?> |
| 1410 |
<div id="<?php echo $this->args['menu_slug'] ?>-icon" style="background: url('<?php echo $this->args['page_icon']; ?>') no-repeat;" class="icon32"> |
| 1411 |
<br/> |
| 1412 |
</div> |
| 1413 |
<?php endif; ?> |
| 1414 |
|
| 1415 |
<h2><?php echo $this->args['page_title'] ?></h2> |
| 1416 |
|
| 1417 |
<div id="poststuff"> |
| 1418 |
|
| 1419 |
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
| 1420 |
<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
| 1421 |
|
| 1422 |
<?php do_action( 'wck_before_meta_boxes', $this->hookname ); ?> |
| 1423 |
|
| 1424 |
<div class="metabox-holder"> |
| 1425 |
<div class="wck-post-body"> |
| 1426 |
<div class="post-box-container column-1 normal"> |
| 1427 |
<?php do_action( 'wck_before_column1_metabox_content', $this->hookname ); ?> |
| 1428 |
<?php do_meta_boxes( $this->hookname, 'normal', null ); ?> |
| 1429 |
<?php do_action( 'wck_after_column1_metabox_content', $this->hookname ); ?> |
| 1430 |
</div> |
| 1431 |
<div class="post-box-container column-3 advanced"> |
| 1432 |
<?php do_action( 'wck_before_column3_metabox_content', $this->hookname ); ?> |
| 1433 |
<?php do_meta_boxes( $this->hookname, 'advanced', null ); ?> |
| 1434 |
<?php do_action( 'wck_after_column3_metabox_content', $this->hookname ); ?> |
| 1435 |
</div> |
| 1436 |
</div> |
| 1437 |
<div class="post-box-container column-2 side"><?php do_meta_boxes( $this->hookname, 'side', null ); ?></div> |
| 1438 |
|
| 1439 |
</div> |
| 1440 |
|
| 1441 |
<?php do_action( 'wck_after_meta_boxes', $this->hookname ); ?> |
| 1442 |
|
| 1443 |
</div><!-- #poststuff --> |
| 1444 |
|
| 1445 |
</div><!-- .wrap --> |
| 1446 |
<?php |
| 1447 |
} |
| 1448 |
} |
| 1449 |
?> |