From bbdb9d960339d67b558348eb80721784761b0c68 Mon Sep 17 00:00:00 2001 From: Jared Atchison Date: Wed, 25 May 2011 18:59:33 -0700 Subject: [PATCH] fixed line 407 not using CMB_META_BOX_URL --- init.php | 825 +++++++++++++++++++++++++++---------------------------- 1 file changed, 412 insertions(+), 413 deletions(-) diff --git a/init.php b/init.php index 844996a..897079d 100644 --- a/init.php +++ b/init.php @@ -1,413 +1,412 @@ -_meta_box = $meta_box; - - $upload = false; - foreach ( $meta_box['fields'] as $field ) { - if ( $field['type'] == 'file' || $field['type'] == 'file_list' ) { - $upload = true; - break; - } - } - - $current_page = substr(strrchr($_SERVER['PHP_SELF'], '/'), 1, -4); - - if ( $upload && ( $current_page == 'page' || $current_page == 'page-new' || $current_page == 'post' || $current_page == 'post-new' ) ) { - add_action('admin_head', array(&$this, 'add_post_enctype')); - } - - add_action( 'admin_menu', array(&$this, 'add') ); - add_action( 'save_post', array(&$this, 'save') ); - } - - function add_post_enctype() { - echo ' - '; - } - - /// Add metaboxes - function add() { - $this->_meta_box['context'] = empty($this->_meta_box['context']) ? 'normal' : $this->_meta_box['context']; - $this->_meta_box['priority'] = empty($this->_meta_box['priority']) ? 'high' : $this->_meta_box['priority']; - foreach ($this->_meta_box['pages'] as $page) { - add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']); - } - } - - // Show fields - function show() { - global $post; - - // Use nonce for verification - echo ''; - echo ''; - - foreach ( $this->_meta_box['fields'] as $field ) { - // Set up blank values for empty ones - if ( !isset($field['desc']) ) $field['desc'] = ''; - if ( !isset($field['std']) ) $field['std'] = ''; - - $meta = get_post_meta( $post->ID, $field['id'], 'multicheck' != $field['type'] /* If multicheck this can be multiple values */ ); - - echo ''; - - if ( $field['type'] == "title" ) { - echo ''; - } - echo '',''; - } - echo '
'; - } else { - if( $this->_meta_box['show_names'] == true ) { - echo ''; - } - - switch ( $field['type'] ) { - case 'text': - echo '', - '

', $field['desc'], '

'; - break; - case 'text_small': - echo '', $field['desc'], ''; - break; - case 'text_medium': - echo '', $field['desc'], ''; - break; - case 'text_date': - echo '', $field['desc'], ''; - break; - case 'text_money': - echo '$ ', $field['desc'], ''; - break; - case 'textarea': - echo '', - '

', $field['desc'], '

'; - break; - case 'textarea_small': - echo '', - '

', $field['desc'], '

'; - break; - case 'select': - echo ''; - echo '

', $field['desc'], '

'; - break; - case 'radio_inline': - echo '
'; - foreach ($field['options'] as $option) { - echo '
', $option['name'], '
'; - } - echo '
'; - echo '

', $field['desc'], '

'; - break; - case 'radio': - foreach ($field['options'] as $option) { - echo '

', $option['name'].'

'; - } - echo '

', $field['desc'], '

'; - break; - case 'checkbox': - echo ''; - echo '', $field['desc'], ''; - break; - case 'multicheck': - echo '
    '; - foreach ( $field['options'] as $value => $name ) { - // Append `[]` to the name to get multiple values - // Use in_array() to check whether the current option should be checked - echo '
  • '; - } - echo '
'; - echo '', $field['desc'], ''; - break; - case 'title': - echo '
', $field['name'], '
'; - echo '

', $field['desc'], '

'; - break; - case 'wysiwyg': - echo '
'; - echo '
'; - echo '
'; - echo '

', $field['desc'], '

'; - break; -/* - case 'wysiwyg': - echo ''; - echo '

', $field['desc'], '

'; - break; -*/ - case 'file_list': - echo ''; - echo ''; - echo '

', $field['desc'], '

'; - $args = array( - 'post_type' => 'attachment', - 'numberposts' => null, - 'post_status' => null, - 'post_parent' => $post->ID - ); - $attachments = get_posts($args); - if ($attachments) { - echo '
    '; - foreach ($attachments as $attachment) { - echo '
  • '.wp_get_attachment_link($attachment->ID, 'thumbnail', 0, 0, 'Download'); - echo ''; - echo apply_filters('the_title', ' '.$attachment->post_title); - echo '
  • '; - } - echo '
'; - } - break; - case 'file': - echo ''; - echo ''; - echo '

', $field['desc'], '

'; - echo '
'; - if ( $meta != '' ) { - $check_image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $meta ); - if ( $check_image ) { - echo '
'; - echo ''; - echo 'Remove Image'; - echo '
'; - } else { - $parts = explode( "/", $meta ); - for( $i = 0; $i < sizeof( $parts ); ++$i ) { - $title = $parts[$i]; - } - echo 'File: ', $title, '    (Download / Remove)'; - } - } - echo '
'; - break; - } - echo '
'; - } - - // Save data from metabox - function save( $post_id) { - // verify nonce - if ( ! isset( $_POST['wp_meta_box_nonce'] ) || !wp_verify_nonce($_POST['wp_meta_box_nonce'], basename(__FILE__))) { - return $post_id; - } - - // check autosave - if ( defined('DOING_AUTOSAVE' ) && DOING_AUTOSAVE) { - return $post_id; - } - - // check permissions - if ( 'page' == $_POST['post_type'] ) { - if ( !current_user_can( 'edit_page', $post_id ) ) { - return $post_id; - } - } elseif ( !current_user_can( 'edit_post', $post_id ) ) { - return $post_id; - } - - foreach ( $this->_meta_box['fields'] as $field ) { - $name = $field['id']; - $old = get_post_meta( $post_id, $name, 'multicheck' != $field['type'] /* If multicheck this can be multiple values */ ); - $new = isset( $_POST[$field['id']] ) ? $_POST[$field['id']] : null; - - if ( $field['type'] == 'wysiwyg' ) { - $new = wpautop($new); - } - - if ( ($field['type'] == 'textarea') || ($field['type'] == 'textarea_small') ) { - $new = htmlspecialchars($new); - } - - // validate meta value - if ( isset($field['validate_func']) ) { - $ok = call_user_func(array('cmb_Meta_Box_Validate', $field['validate_func']), $new); - if ( $ok === false ) { // pass away when meta value is invalid - continue; - } - } elseif ( 'multicheck' == $field['type'] ) { - // Do the saving in two steps: first get everything we don't have yet - // Then get everything we should not have anymore - if ( empty( $new ) ) { - $new = array(); - } - $aNewToAdd = array_diff( $new, $old ); - $aOldToDelete = array_diff( $old, $new ); - foreach ( $aNewToAdd as $newToAdd ) { - add_post_meta( $post_id, $name, $newToAdd, false ); - } - foreach ( $aOldToDelete as $oldToDelete ) { - delete_post_meta( $post_id, $name, $oldToDelete ); - } - } elseif ($new && $new != $old) { - update_post_meta($post_id, $name, $new); - } elseif ('' == $new && $old && $field['type'] != 'file') { - delete_post_meta($post_id, $name, $old); - } - } - } -} - - -/** - * Adding scripts and styles - */ - -function cmb_scripts( $hook ) { - if ( $hook == 'post.php' OR $hook == 'post-new.php' OR $hook == 'page-new.php' OR $hook == 'page.php' ) { - wp_register_script( 'cmb-scripts', CMB_META_BOX_URL.'jquery.cmbScripts.js', array('jquery','media-upload','thickbox')); - wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'jquery-ui-core' ); // Make sure and use elements form the 1.7.3 UI - not 1.8.9 - wp_enqueue_script( 'media-upload' ); - wp_enqueue_script( 'thickbox' ); - wp_enqueue_script( 'cmb-scripts' ); - wp_enqueue_style( 'thickbox' ); - wp_enqueue_style( 'jquery-custom-ui' ); - add_action( 'admin_head', 'cmb_styles_inline' ); - } -} -add_action( 'admin_enqueue_scripts', 'cmb_scripts',10,1 ); - -function editor_admin_init() { - wp_enqueue_script('word-count'); - wp_enqueue_script('post'); - wp_enqueue_script('editor'); -} - -function editor_admin_head() { - wp_tiny_mce(); -} - - -add_action('admin_init', 'editor_admin_init'); -add_action('admin_head', 'editor_admin_head'); - -function cmb_editor_footer_scripts() { ?> - - '; - // For some reason this script doesn't like to register - ?> - - _meta_box = $meta_box; + + $upload = false; + foreach ( $meta_box['fields'] as $field ) { + if ( $field['type'] == 'file' || $field['type'] == 'file_list' ) { + $upload = true; + break; + } + } + + $current_page = substr(strrchr($_SERVER['PHP_SELF'], '/'), 1, -4); + + if ( $upload && ( $current_page == 'page' || $current_page == 'page-new' || $current_page == 'post' || $current_page == 'post-new' ) ) { + add_action('admin_head', array(&$this, 'add_post_enctype')); + } + + add_action( 'admin_menu', array(&$this, 'add') ); + add_action( 'save_post', array(&$this, 'save') ); + } + + function add_post_enctype() { + echo ' + '; + } + + /// Add metaboxes + function add() { + $this->_meta_box['context'] = empty($this->_meta_box['context']) ? 'normal' : $this->_meta_box['context']; + $this->_meta_box['priority'] = empty($this->_meta_box['priority']) ? 'high' : $this->_meta_box['priority']; + foreach ($this->_meta_box['pages'] as $page) { + add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']); + } + } + + // Show fields + function show() { + global $post; + + // Use nonce for verification + echo ''; + echo ''; + + foreach ( $this->_meta_box['fields'] as $field ) { + // Set up blank values for empty ones + if ( !isset($field['desc']) ) $field['desc'] = ''; + if ( !isset($field['std']) ) $field['std'] = ''; + + $meta = get_post_meta( $post->ID, $field['id'], 'multicheck' != $field['type'] /* If multicheck this can be multiple values */ ); + + echo ''; + + if ( $field['type'] == "title" ) { + echo ''; + } + echo '',''; + } + echo '
'; + } else { + if( $this->_meta_box['show_names'] == true ) { + echo ''; + } + + switch ( $field['type'] ) { + case 'text': + echo '', + '

', $field['desc'], '

'; + break; + case 'text_small': + echo '', $field['desc'], ''; + break; + case 'text_medium': + echo '', $field['desc'], ''; + break; + case 'text_date': + echo '', $field['desc'], ''; + break; + case 'text_money': + echo '$ ', $field['desc'], ''; + break; + case 'textarea': + echo '', + '

', $field['desc'], '

'; + break; + case 'textarea_small': + echo '', + '

', $field['desc'], '

'; + break; + case 'select': + echo ''; + echo '

', $field['desc'], '

'; + break; + case 'radio_inline': + echo '
'; + foreach ($field['options'] as $option) { + echo '
', $option['name'], '
'; + } + echo '
'; + echo '

', $field['desc'], '

'; + break; + case 'radio': + foreach ($field['options'] as $option) { + echo '

', $option['name'].'

'; + } + echo '

', $field['desc'], '

'; + break; + case 'checkbox': + echo ''; + echo '', $field['desc'], ''; + break; + case 'multicheck': + echo '
    '; + foreach ( $field['options'] as $value => $name ) { + // Append `[]` to the name to get multiple values + // Use in_array() to check whether the current option should be checked + echo '
  • '; + } + echo '
'; + echo '', $field['desc'], ''; + break; + case 'title': + echo '
', $field['name'], '
'; + echo '

', $field['desc'], '

'; + break; + case 'wysiwyg': + echo '
'; + echo '
'; + echo '
'; + echo '

', $field['desc'], '

'; + break; +/* + case 'wysiwyg': + echo ''; + echo '

', $field['desc'], '

'; + break; +*/ + case 'file_list': + echo ''; + echo ''; + echo '

', $field['desc'], '

'; + $args = array( + 'post_type' => 'attachment', + 'numberposts' => null, + 'post_status' => null, + 'post_parent' => $post->ID + ); + $attachments = get_posts($args); + if ($attachments) { + echo '
    '; + foreach ($attachments as $attachment) { + echo '
  • '.wp_get_attachment_link($attachment->ID, 'thumbnail', 0, 0, 'Download'); + echo ''; + echo apply_filters('the_title', ' '.$attachment->post_title); + echo '
  • '; + } + echo '
'; + } + break; + case 'file': + echo ''; + echo ''; + echo '

', $field['desc'], '

'; + echo '
'; + if ( $meta != '' ) { + $check_image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $meta ); + if ( $check_image ) { + echo '
'; + echo ''; + echo 'Remove Image'; + echo '
'; + } else { + $parts = explode( "/", $meta ); + for( $i = 0; $i < sizeof( $parts ); ++$i ) { + $title = $parts[$i]; + } + echo 'File: ', $title, '    (Download / Remove)'; + } + } + echo '
'; + break; + } + echo '
'; + } + + // Save data from metabox + function save( $post_id) { + // verify nonce + if ( ! isset( $_POST['wp_meta_box_nonce'] ) || !wp_verify_nonce($_POST['wp_meta_box_nonce'], basename(__FILE__))) { + return $post_id; + } + + // check autosave + if ( defined('DOING_AUTOSAVE' ) && DOING_AUTOSAVE) { + return $post_id; + } + + // check permissions + if ( 'page' == $_POST['post_type'] ) { + if ( !current_user_can( 'edit_page', $post_id ) ) { + return $post_id; + } + } elseif ( !current_user_can( 'edit_post', $post_id ) ) { + return $post_id; + } + + foreach ( $this->_meta_box['fields'] as $field ) { + $name = $field['id']; + $old = get_post_meta( $post_id, $name, 'multicheck' != $field['type'] /* If multicheck this can be multiple values */ ); + $new = isset( $_POST[$field['id']] ) ? $_POST[$field['id']] : null; + + if ( $field['type'] == 'wysiwyg' ) { + $new = wpautop($new); + } + + if ( ($field['type'] == 'textarea') || ($field['type'] == 'textarea_small') ) { + $new = htmlspecialchars($new); + } + + // validate meta value + if ( isset($field['validate_func']) ) { + $ok = call_user_func(array('cmb_Meta_Box_Validate', $field['validate_func']), $new); + if ( $ok === false ) { // pass away when meta value is invalid + continue; + } + } elseif ( 'multicheck' == $field['type'] ) { + // Do the saving in two steps: first get everything we don't have yet + // Then get everything we should not have anymore + if ( empty( $new ) ) { + $new = array(); + } + $aNewToAdd = array_diff( $new, $old ); + $aOldToDelete = array_diff( $old, $new ); + foreach ( $aNewToAdd as $newToAdd ) { + add_post_meta( $post_id, $name, $newToAdd, false ); + } + foreach ( $aOldToDelete as $oldToDelete ) { + delete_post_meta( $post_id, $name, $oldToDelete ); + } + } elseif ($new && $new != $old) { + update_post_meta($post_id, $name, $new); + } elseif ('' == $new && $old && $field['type'] != 'file') { + delete_post_meta($post_id, $name, $old); + } + } + } +} + + +/** + * Adding scripts and styles + */ + +function cmb_scripts( $hook ) { + if ( $hook == 'post.php' OR $hook == 'post-new.php' OR $hook == 'page-new.php' OR $hook == 'page.php' ) { + wp_register_script( 'cmb-scripts', CMB_META_BOX_URL.'jquery.cmbScripts.js', array('jquery','media-upload','thickbox')); + wp_enqueue_script( 'jquery' ); + wp_enqueue_script( 'jquery-ui-core' ); // Make sure and use elements form the 1.7.3 UI - not 1.8.9 + wp_enqueue_script( 'media-upload' ); + wp_enqueue_script( 'thickbox' ); + wp_enqueue_script( 'cmb-scripts' ); + wp_enqueue_style( 'thickbox' ); + wp_enqueue_style( 'jquery-custom-ui' ); + add_action( 'admin_head', 'cmb_styles_inline' ); + } +} +add_action( 'admin_enqueue_scripts', 'cmb_scripts',10,1 ); + +function editor_admin_init() { + wp_enqueue_script('word-count'); + wp_enqueue_script('post'); + wp_enqueue_script('editor'); +} + +function editor_admin_head() { + wp_tiny_mce(); +} + + +add_action('admin_init', 'editor_admin_init'); +add_action('admin_head', 'editor_admin_head'); + +function cmb_editor_footer_scripts() { ?> + + '; + // For some reason this script doesn't like to register + ?> + +