From 6a66282184dce6f7a1b28e58d35425570c73fbc9 Mon Sep 17 00:00:00 2001 From: Flabadab Date: Thu, 18 Apr 2013 16:36:45 +0300 Subject: [PATCH 01/11] Update MediaAccess.php Updated MediaAccess.php to use the Wordpress 3.5 Media Manager to upload. --- wp-content/wpalchemy/MediaAccess.php | 114 ++++++++++----------------- 1 file changed, 43 insertions(+), 71 deletions(-) diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 6748ad1..e256724 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -291,7 +291,7 @@ public function getButton(array $attr = array()) ### - return '' . $label . ''; + return ''; } /** @@ -314,8 +314,6 @@ public function init() ?> + Date: Wed, 28 Aug 2013 22:37:32 +0200 Subject: [PATCH 04/11] Added media-meta.php --- .../themes/mytheme/metaboxes/media-meta.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 wp-content/themes/mytheme/metaboxes/media-meta.php 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(); ?> +

+ +
From 5ffdf1f765eb4d46094f3480379f329294b695ec Mon Sep 17 00:00:00 2001 From: Flabadab Date: Wed, 28 Aug 2013 22:39:00 +0200 Subject: [PATCH 05/11] Added media-spec.php --- wp-content/themes/mytheme/metaboxes/media-spec.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 wp-content/themes/mytheme/metaboxes/media-spec.php 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 */ From cfa995a08bd0722f6a254c9a7865136dcc13820b Mon Sep 17 00:00:00 2001 From: Flabadab Date: Wed, 28 Aug 2013 22:40:06 +0200 Subject: [PATCH 06/11] Included media-spec.php --- wp-content/themes/mytheme/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 */ From 49627ecff7cac25b0b0acdcba268600cdcb30435 Mon Sep 17 00:00:00 2001 From: Flabadab Date: Sat, 21 Sep 2013 10:43:35 +0200 Subject: [PATCH 07/11] Update MediaAccess.php Fixed issue with posts with thumbnail support not setting featured image. --- wp-content/wpalchemy/MediaAccess.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 1656cfd..90357a2 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -87,11 +87,20 @@ public function __construct(array $a = array()) { $this->$n = $v; } - if(function_exists('wp_enqueue_media')) { - //call for new media manager + + // Get current post ID + + if ( isset( $_REQUEST['post'] ) ) { + $post = get_post( $_REQUEST['post'] ); + } + + // Check post type support for thumbnails, call wp_enqueue_media() scripts if thumbnails not supported. + + if(!post_type_supports( $post->post_type, 'thumbnail' ) && function_exists('wp_enqueue_media')) { wp_enqueue_script('jquery'); wp_enqueue_media(); } + if ( ! defined('WPALCHEMY_SEND_TO_EDITOR_ENABLED')) { add_action('admin_footer', array($this, 'init')); From fafc1fc7efee64c56ac6293a39a51862e24fae94 Mon Sep 17 00:00:00 2001 From: Flabadab Date: Sat, 26 Oct 2013 14:57:15 +0200 Subject: [PATCH 08/11] Update MediaAccess.php --- wp-content/wpalchemy/MediaAccess.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 90357a2..6bd3e97 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -97,9 +97,11 @@ public function __construct(array $a = array()) // Check post type support for thumbnails, call wp_enqueue_media() scripts if thumbnails not supported. if(!post_type_supports( $post->post_type, 'thumbnail' ) && function_exists('wp_enqueue_media')) { - wp_enqueue_script('jquery'); wp_enqueue_media(); } + if(!wp_script_is('jquery')){ + wp_enqueue_script('jquery'); + } if ( ! defined('WPALCHEMY_SEND_TO_EDITOR_ENABLED')) { From eb3f4cc9aedf0f2b8372332ba04465fd0151e4a8 Mon Sep 17 00:00:00 2001 From: Flabadab Date: Sat, 26 Oct 2013 15:38:36 +0200 Subject: [PATCH 09/11] Updated MetaBox.php and MediaAccess.php Applied MetaBox Strict Standards fix (https://gist.github.com/Pirenko/7022890/) Changed when jQuery enqueue check is made. --- wp-content/wpalchemy/MediaAccess.php | 15 +- wp-content/wpalchemy/MetaBox.php | 855 +++++++++++++-------------- 2 files changed, 424 insertions(+), 446 deletions(-) diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 6bd3e97..7ff0697 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -92,15 +92,14 @@ public function __construct(array $a = array()) if ( isset( $_REQUEST['post'] ) ) { $post = get_post( $_REQUEST['post'] ); - } // Check post type support for thumbnails, call wp_enqueue_media() scripts if thumbnails not supported. if(!post_type_supports( $post->post_type, 'thumbnail' ) && function_exists('wp_enqueue_media')) { - wp_enqueue_media(); - } - if(!wp_script_is('jquery')){ - wp_enqueue_script('jquery'); + if(!wp_script_is('jquery')){ + wp_enqueue_script('jquery'); + } + wp_enqueue_media(); } if ( ! defined('WPALCHEMY_SEND_TO_EDITOR_ENABLED')) @@ -109,6 +108,8 @@ public function __construct(array $a = array()) define('WPALCHEMY_SEND_TO_EDITOR_ENABLED', true); } + + } } /** @@ -323,7 +324,7 @@ public function getButton(array $attr = array()) $modal_update_href = esc_url( add_query_arg( array( '_wpnonce' => wp_create_nonce( 'media-access' ), ), - admin_url( 'upload.php' ) ) ); + admin_url( 'media-upload.php' ) ) ); ### @@ -411,4 +412,4 @@ public function init() } } -/* End of file */ +/* End of file */ \ No newline at end of file diff --git a/wp-content/wpalchemy/MetaBox.php b/wp-content/wpalchemy/MetaBox.php index 27bccdb..3a25989 100755 --- a/wp-content/wpalchemy/MetaBox.php +++ b/wp-content/wpalchemy/MetaBox.php @@ -1,21 +1,24 @@ 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 From 547a8a067e44de3d229cf301eb2cee55b7b8bb03 Mon Sep 17 00:00:00 2001 From: Flabadab Date: Sat, 7 Dec 2013 16:04:17 +0200 Subject: [PATCH 10/11] Update MediaAccess.php Moved media scripts from __construct() to init() to avoid Strict Standard errors and changed wp_enqueue_script('jquery') to wp_enqueue_script('custom-header'). --- wp-content/wpalchemy/MediaAccess.php | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/wp-content/wpalchemy/MediaAccess.php b/wp-content/wpalchemy/MediaAccess.php index 7ff0697..9eea214 100644 --- a/wp-content/wpalchemy/MediaAccess.php +++ b/wp-content/wpalchemy/MediaAccess.php @@ -88,20 +88,6 @@ public function __construct(array $a = array()) $this->$n = $v; } - // Get current post ID - - if ( isset( $_REQUEST['post'] ) ) { - $post = get_post( $_REQUEST['post'] ); - - // Check post type support for thumbnails, call wp_enqueue_media() scripts if thumbnails not supported. - - if(!post_type_supports( $post->post_type, 'thumbnail' ) && function_exists('wp_enqueue_media')) { - if(!wp_script_is('jquery')){ - wp_enqueue_script('jquery'); - } - wp_enqueue_media(); - } - if ( ! defined('WPALCHEMY_SEND_TO_EDITOR_ENABLED')) { add_action('admin_footer', array($this, 'init')); @@ -109,7 +95,6 @@ public function __construct(array $a = array()) define('WPALCHEMY_SEND_TO_EDITOR_ENABLED', true); } - } } /** @@ -342,12 +327,27 @@ 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 + + + // Get current post ID + + $post = get_post( $post_ID ); + + // Check post type support for thumbnails, call wp_enqueue_media() scripts if thumbnails not supported. + + if(!post_type_supports( $post->post_type, 'thumbnail' ) && function_exists('wp_enqueue_media')) { + if(!wp_script_is('custom-header')){ + wp_enqueue_script('custom-header'); + } + wp_enqueue_media(); + } + // include javascript for special functionality ?>