diff --git a/wp-content/themes/mytheme/functions.php b/wp-content/themes/mytheme/functions.php index 4238ffc..f9b1981 100644 --- a/wp-content/themes/mytheme/functions.php +++ b/wp-content/themes/mytheme/functions.php @@ -12,4 +12,6 @@ include_once 'metaboxes/select-spec.php'; -/* eof */ \ No newline at end of file +include_once 'metaboxes/media-spec.php'; + +/* eof */ diff --git a/wp-content/themes/mytheme/metaboxes/media-meta.php b/wp-content/themes/mytheme/metaboxes/media-meta.php new file mode 100644 index 0000000..ebc843e --- /dev/null +++ b/wp-content/themes/mytheme/metaboxes/media-meta.php @@ -0,0 +1,20 @@ + +
+ + the_field('imgurl'); ?> + setGroupName('nn')->setInsertButtonLabel('Add File to Text Box')->setButtonLabel('Upload File'); ?> + +

+ getField(array('name' => $mb->get_the_name(), 'value' => $mb->get_the_value())); ?> + getButton(); ?> +

+ + the_field('imgurl2'); ?> + setGroupName('nn2')->setButtonLabel('Add Image From Library')->setInsertButtonLabel('Insert This')->setTab('gallery'); ?> + +

+ getField(array('name' => $mb->get_the_name(), 'value' => $mb->get_the_value())); ?> + getButton(); ?> +

+ +
diff --git a/wp-content/themes/mytheme/metaboxes/media-spec.php b/wp-content/themes/mytheme/metaboxes/media-spec.php new file mode 100644 index 0000000..fc62c7b --- /dev/null +++ b/wp-content/themes/mytheme/metaboxes/media-spec.php @@ -0,0 +1,13 @@ + '_custom_meta', + 'title' => 'My Custom Media Meta', + 'types' => array('book'), + 'template' => get_stylesheet_directory() . '/metaboxes/media-meta.php', +)); + +/* eof */ diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 6748ad1..49a461e 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -43,6 +43,17 @@ class WPAlchemy_MediaAccess */ public $insert_button_label = null; + /** + * User defined label for the "Add Media" button, this + * can be set once or per field and button pair. + * + * @since 0.1 + * @access public + * @var string optional + * @see setInsertButtonLabel() + */ + public $button_label = null; + /** * Used to track the current groupname for pairing a field and button. * @@ -76,13 +87,14 @@ public function __construct(array $a = array()) { $this->$n = $v; } - + if ( ! defined('WPALCHEMY_SEND_TO_EDITOR_ENABLED')) { add_action('admin_footer', array($this, 'init')); define('WPALCHEMY_SEND_TO_EDITOR_ENABLED', true); } + } /** @@ -113,6 +125,13 @@ public function setInsertButtonLabel($label = 'Insert') return $this; } + + public function setButtonLabel($button = 'Add Media') + { + $this->button_label = $button; + + return $this; + } public function setTab($name) { @@ -201,7 +220,14 @@ public function getButtonLink($tab = null) $tab = ! empty($tab) ? $tab : 'library' ; - return 'media-upload.php?post_id=' . $post_ID . '&tab=' . $tab . '&TB_iframe=1'; + $update_href = esc_url( add_query_arg( array( + 'post_id' => $post_ID, + 'tab' => $tab, + 'TB_iframe' => 1, + '_wpnonce' => wp_create_nonce('shiba_gallery_options'), + ), admin_url('upload.php') ) ); + + return $update_href; } /** @@ -219,7 +245,7 @@ public function getButtonClass($groupname = null) { $groupname = isset($groupname) ? $groupname : $this->groupname ; - return $this->button_class_name . '-' . $groupname . ' thickbox'; + return $this->button_class_name . '-' . $groupname . ' '; } /** @@ -257,14 +283,13 @@ public function getButton(array $attr = array()) $attr_default = array ( - 'label' => 'Add Media', - 'href' => $this->getButtonLink($tab), + 'label' => $this->button_label, 'class' => $this->getButtonClass($groupname) . ' button', ); if (isset($this->insert_button_label)) { - $attr_default['class'] .= " {label:'" . $this->insert_button_label . "'}"; + $attr_default['data-update'] = $this->insert_button_label; } ### @@ -288,10 +313,13 @@ public function getButton(array $attr = array()) { array_push($elem_attr, $n . '="' . $v . '"'); } + + $link = $this->getButtonLink(); - ### - return '' . $label . ''; + ### + //return ''; + return ''.$label.''; } /** @@ -304,111 +332,89 @@ public function getButton(array $attr = array()) */ public function init() { + global $post_ID; $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; $file = basename(parse_url($uri, PHP_URL_PATH)); - if ($uri AND in_array($file, array('post.php', 'post-new.php'))) { - // include javascript for special functionality - ?> +lock_on_top) $this->lock = WPALCHEMY_LOCK_TOP; elseif ($this->lock_on_bottom) $this->lock = WPALCHEMY_LOCK_BOTTOM; @@ -510,9 +513,7 @@ function WPAlchemy_MetaBox($arr) } /** - * Used to correct double serialized data during post/page export/import, - * additionally will try to fix corrupted serialized data by recalculating - * string length values + * Used to correct double serialized data during post/page export/import * * @since 1.3.16 * @access private @@ -521,29 +522,8 @@ function _import($post_id, $key, $value) { if (WPALCHEMY_MODE_ARRAY == $this->mode AND $key == $this->id) { - // using $wp_import to get access to the raw postmeta data prior to it getting passed - // through "maybe_unserialize()" in "plugins/wordpress-importer/wordpress-importer.php" - // the "import_post_meta" action is called after "maybe_unserialize()" - - global $wp_import; - - foreach ( $wp_import->posts as $post ) - { - if ( $post_id == $post['post_id'] ) - { - foreach( $post['postmeta'] as $meta ) - { - if ( $key == $meta['key'] ) - { - // try to fix corrupted serialized data, specifically "\r\n" being converted to "\n" during wordpress XML export (WXR) - // "maybe_unserialize()" fixes a wordpress bug which double serializes already serialized data during export/import - $value = maybe_unserialize( preg_replace( '!s:(\d+):"(.*?)";!es', "'s:'.strlen('$2').':\"$2\";'", stripslashes( $meta['value'] ) ) ); - - update_post_meta( $post_id, $key, $value ); - } - } - } - } + // maybe_unserialize fixes a wordpress bug which double serializes already serialized data during export/import + update_post_meta($post_id, $key, maybe_unserialize(stripslashes($value))); } } @@ -557,7 +537,7 @@ function _import($post_id, $key, $value) function _init() { // must be creating or editing a post or page - if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return; + if ( !prk_alc_is_post() AND !prk_alc_is_page()) return; if ( ! empty($this->output_filter)) { @@ -971,147 +951,14 @@ function do_action($tag, $arg = '') $args[0] = $this->_get_action_tag($tag); return call_user_func_array('do_action', $args); } - - /** - * Used to check if creating a new post or editing one - * - * @static - * @since 1.3.7 - * @access private - * @return bool - * @see _is_page() - */ - function _is_post() - { - if ('post' == WPAlchemy_MetaBox::_is_post_or_page()) - { - return TRUE; - } - - return FALSE; - } - - /** - * Used to check if creating a new page or editing one - * - * @static - * @since 1.3.7 - * @access private - * @return bool - * @see _is_post() - */ - function _is_page() - { - if ('page' == WPAlchemy_MetaBox::_is_post_or_page()) - { - return TRUE; - } - - return FALSE; - } - - /** - * Used to check if creating or editing a post or page - * - * @static - * @since 1.3.8 - * @access private - * @return string "post" or "page" - * @see _is_post(), _is_page() - */ - function _is_post_or_page() - { - $post_type = WPAlchemy_MetaBox::_get_current_post_type(); - - if (isset($post_type)) - { - if ('page' == $post_type) - { - return 'page'; - } - else - { - return 'post'; - } - } - - return NULL; - } - - /** - * Used to check for the current post type, works when creating or editing a - * new post, page or custom post type. - * - * @static - * @since 1.4.6 - * @return string [custom_post_type], page or post - */ - function _get_current_post_type() - { - $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; - - if ( isset( $uri ) ) - { - $uri_parts = parse_url($uri); - - $file = basename($uri_parts['path']); - - if ($uri AND in_array($file, array('post.php', 'post-new.php'))) - { - $post_id = WPAlchemy_MetaBox::_get_post_id(); - - $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL ; - - $post_type = $post_id ? get_post_type($post_id) : $post_type ; - - if (isset($post_type)) - { - return $post_type; - } - else - { - // because of the 'post.php' and 'post-new.php' checks above, we can default to 'post' - return 'post'; - } - } - } - - return NULL; - } - - /** - * Used to get the current post id. - * - * @static - * @since 1.4.8 - * @return int post ID - */ - function _get_post_id() - { - global $post; - - $p_post_id = isset($_POST['post_ID']) ? $_POST['post_ID'] : null ; - - $g_post_id = isset($_GET['post']) ? $_GET['post'] : null ; - - $post_id = $g_post_id ? $g_post_id : $p_post_id ; - - $post_id = isset($post->ID) ? $post->ID : $post_id ; - - if (isset($post_id)) - { - return (integer) $post_id; - } - - return null; - } + /** * @since 1.0 */ function can_output() { - $post_id = WPAlchemy_MetaBox::_get_post_id(); + $post_id = prk_alc_get_post_id(); if (!empty($this->exclude_template) OR !empty($this->include_template)) { @@ -1321,7 +1168,7 @@ function can_output() } } - $post_type = WPAlchemy_MetaBox::_get_current_post_type(); + $post_type = prk_alc_get_current_post_type(); if (isset($post_type) AND ! in_array($post_type, $this->types)) { @@ -1337,288 +1184,97 @@ function can_output() return $can_output; } + /** - * Used to insert global STYLE or SCRIPT tags into the head, called on - * WordPress admin_footer action. + * Gets the meta data for a meta box + * + * @since 1.0 + * @access public + * @param int $post_id optional post ID for which to retrieve the meta data + * @return array + * @see _meta + */ + function the_meta($post_id = NULL) + { + return $this->_meta($post_id); + } + + /** + * Gets the meta data for a meta box + * + * Internal method calls will typically bypass the data retrieval and will + * immediately return the current meta data * - * @static * @since 1.3 * @access private - * @see _global_foot() + * @param int $post_id optional post ID for which to retrieve the meta data + * @param bool $internal optional boolean if internally calling + * @return array + * @see the_meta() */ - function _global_head() + function _meta($post_id = NULL, $internal = FALSE) { - // must be creating or editing a post or page - if ( ! WPAlchemy_MetaBox::_is_post() AND ! WPAlchemy_MetaBox::_is_page()) return; - - // todo: you're assuming people will want to use this exact functionality - // consider giving a developer access to change this via hooks/callbacks - - // include javascript for special functionality - ?> - - - - _meta($post_id); - } - - /** - * Gets the meta data for a meta box - * - * Internal method calls will typically bypass the data retrieval and will - * immediately return the current meta data - * - * @since 1.3 - * @access private - * @param int $post_id optional post ID for which to retrieve the meta data - * @param bool $internal optional boolean if internally calling - * @return array - * @see the_meta() - */ - function _meta($post_id = NULL, $internal = FALSE) - { - if ( ! is_numeric($post_id)) - { - if ($internal AND $this->current_post_id) - { - $post_id = $this->current_post_id; - } - else - { - global $post; - - $post_id = $post->ID; - } - } - - // this allows multiple internal calls to _meta() without having to fetch data everytime - if ($internal AND !empty($this->meta) AND $this->current_post_id == $post_id) return $this->meta; - - $this->current_post_id = $post_id; - - // WPALCHEMY_MODE_ARRAY - - $meta = get_post_meta($post_id, $this->id, TRUE); - - // WPALCHEMY_MODE_EXTRACT - - $fields = get_post_meta($post_id, $this->id . '_fields', TRUE); - - if ( ! empty($fields) AND is_array($fields)) - { - $meta = array(); - - foreach ($fields as $field) - { - $field_noprefix = preg_replace('/^' . $this->prefix . '/i', '', $field); - $meta[$field_noprefix] = get_post_meta($post_id, $field, TRUE); - } - } - - $this->meta = $meta; - - return $this->meta; - } - - // user can also use the_ID(), php functions are case-insensitive - /** - * @since 1.0 - * @access public - */ - function the_id() - { - echo $this->get_the_id(); - } - - /** - * @since 1.0 - * @access public - */ - function get_the_id() - { - return $this->id; - } + /** + * @since 1.0 + * @access public + */ + function get_the_id() + { + return $this->id; + } /** * @since 1.0 @@ -2370,4 +2026,325 @@ function clean(&$arr) } } + +/** + * Used to insert global STYLE or SCRIPT tags into the head, called on + * WordPress admin_footer action. + * + * @static + * @since 1.3 + * @access private + * @see prk_alc_global_foot() + */ + function prk_alc_global_head() + { + // must be creating or editing a post or page + if ( !prk_alc_is_post() AND ! prk_alc_is_page()) return; + + // todo: you're assuming people will want to use this exact functionality + // consider giving a developer access to change this via hooks/callbacks + + // include javascript for special functionality + ?> + + + + ID) ? $post->ID : $post_id ; + + if (isset($post_id)) + { + return (integer) $post_id; + } + + return null; + } + +/** + * Used to check for the current post type, works when creating or editing a + * new post, page or custom post type. + * + * @static + * @since 1.4.6 + * @return string [custom_post_type], page or post + */ + function prk_alc_get_current_post_type() + { + $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; + + if ( isset( $uri ) ) + { + $uri_parts = parse_url($uri); + + $file = basename($uri_parts['path']); + + if ($uri AND in_array($file, array('post.php', 'post-new.php'))) + { + $post_id = prk_alc_get_post_id(); + + $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL ; + + $post_type = $post_id ? get_post_type($post_id) : $post_type ; + + if (isset($post_type)) + { + return $post_type; + } + else + { + // because of the 'post.php' and 'post-new.php' checks above, we can default to 'post' + return 'post'; + } + } + } + + return NULL; + } + + /** + * Used to check if creating or editing a post or page + * + * @static + * @since 1.3.8 + * @access private + * @return string "post" or "page" + * @see prk_alc_is_post(), prk_alc_is_page() + */ + function prk_alc_is_post_or_page() + { + $post_type = prk_alc_get_current_post_type(); + + if (isset($post_type)) + { + if ('page' == $post_type) + { + return 'page'; + } + else + { + return 'post'; + } + } + + return NULL; + } + + /** + * Used to check if creating a new post or editing one + * + * @static + * @since 1.3.7 + * @access private + * @return bool + * @see prk_alc_is_page() + */ + function prk_alc_is_post() + { + if ('post' == prk_alc_is_post_or_page()) + { + return TRUE; + } + + return FALSE; + } + + /** + * Used to check if creating a new page or editing one + * + * @static + * @since 1.3.7 + * @access private + * @return bool + * @see prk_alc_is_post() + */ + function prk_alc_is_page() + { + if ('page' == prk_alc_is_post_or_page()) + { + return TRUE; + } + + return FALSE; + } + /* eof */ \ No newline at end of file