Initial commit

This commit is contained in:
Felix Förtsch
2020-10-20 14:39:50 +02:00
commit 648ded8896
1225 changed files with 216511 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Audio.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Audio' ) ) :
/**
* Information on the standard WP [audio] shortcode.
*/
class Debug_Bar_Shortcode_Info_Audio extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Whether the shortcode is self-closing or not.
*
* @var bool|null $self_closing
*/
public $self_closing = true;
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = 'http://codex.wordpress.org/Audio_Shortcode';
/**
* Constructor - set some properties which need to be translated.
*/
public function __construct() {
$this->name = __( 'Audio Media', 'debug-bar-shortcodes' );
$this->description = __( 'The Audio feature allows you to embed audio files and play them back. This was added as of WordPress 3.6.', 'debug-bar-shortcodes' );
/* translators: %s = file format. */
$string = __( 'Source of %s fallback file', 'debug-bar-shortcodes' );
$this->parameters['optional'] = array(
'src' => __( 'The source of your audio file. If not included it will auto-populate with the first audio file attached to the post.', 'debug-bar-shortcodes' ),
'mp3' => sprintf( $string, 'mp3' ),
'm4a' => sprintf( $string, 'm4a' ),
'ogg' => sprintf( $string, 'ogg' ),
'wav' => sprintf( $string, 'wav' ),
'wma' => sprintf( $string, 'wma' ),
'loop' => __( 'Allows for the looping of media. Defaults to "off".', 'debug-bar-shortcodes' ),
'autoplay' => __( 'Causes the media to automatically play as soon as the media file is ready. Defaults to "off".', 'debug-bar-shortcodes' ),
'preload' => __( 'Specifies if and how the audio should be loaded when the page loads. Defaults to "none".', 'debug-bar-shortcodes' ),
);
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,56 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Caption.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Caption' ) ) :
/**
* Information on the standard WP [caption] shortcode.
*/
class Debug_Bar_Shortcode_Info_Caption extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Whether the shortcode is self-closing or not.
*
* @var bool|null $self_closing
*/
public $self_closing = false;
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = 'http://codex.wordpress.org/Caption_Shortcode';
/**
* Constructor - set some properties which need to be translated.
*/
public function __construct() {
$this->name = __( 'Wrap captions around content', 'debug-bar-shortcodes' );
$this->description = __( 'The Caption feature allows you to wrap captions around content. This is primarily used with individual images.', 'debug-bar-shortcodes' );
$this->parameters['required'] = array(
'caption' => __( 'The actual text of your caption.', 'debug-bar-shortcodes' ),
'width' => __( 'How wide the caption should be in pixels.', 'debug-bar-shortcodes' ),
);
$this->parameters['optional'] = array(
'id' => __( 'A unique HTML ID that you can change to use within your CSS.', 'debug-bar-shortcodes' ),
'align' => __( 'The alignment of the caption within the post. Valid values are: alignnone (default), aligncenter, alignright, and alignleft.', 'debug-bar-shortcodes' ),
);
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,73 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Defaults.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Defaults' ) ) :
/**
* Shortcode Info defaults.
*/
class Debug_Bar_Shortcode_Info_Defaults {
/**
* Friendly name for the shortcode.
*
* @var string $name
*/
public $name = '';
/**
* Longer description of what the shortcode is for.
*
* @var string $description
*/
public $description = '';
/**
* Whether the shortcode is self-closing or not.
* - `true` if of form: [shortcode],
* - `false` if of form: [shortcode]...[/shortcode]
* Defaults to `null` (=unknown)
*
* @var bool|null $self_closing
*/
public $self_closing;
/**
* Parameters which can be passed to the shortcode.
*
* Array format:
* - [required] => array Required parameters.
* Array format:
* - key = name of the parameter.
* - value = description of the parameter.
* - [optional] => array Optional parameters.
* Follows same format as for required parameters.
*
* @var array $parameters
*/
public $parameters = array(
'required' => array(),
'optional' => array(),
);
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = '';
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,54 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Embed.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Embed' ) ) :
/**
* Information on the standard WP [embed] shortcode.
*/
class Debug_Bar_Shortcode_Info_Embed extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Whether the shortcode is self-closing or not.
*
* @var bool|null $self_closing
*/
public $self_closing = false;
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = 'http://codex.wordpress.org/Embed_Shortcode';
/**
* Constructor - set some properties which need to be translated.
*/
public function __construct() {
$this->name = __( 'Embed videos, images, and other content', 'debug-bar-shortcodes' );
$this->description = __( 'You can opt to wrap a URL in the [embed] shortcode. It will accomplish the same effect as having it on a line of it\'s own, but does not require the "Auto-embeds" setting to be enabled. It also allows you to set a maximum (but not fixed) width and height.If WordPress fails to embed your URL you will get a hyperlink to the URL.', 'debug-bar-shortcodes' );
/* translators: %s = height/weight. */
$string = __( 'Maximum %s for the embedded object.', 'debug-bar-shortcodes' );
$this->parameters['optional'] = array(
'height' => sprintf( $string, __( 'height', 'debug-bar-shortcodes' ) ),
'width' => sprintf( $string, __( 'width', 'debug-bar-shortcodes' ) ),
);
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,316 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info From File.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_From_File' ) ) :
/**
* Information on a shortcode based on documentation found for the function the
* shortcode points to.
*/
class Debug_Bar_Shortcode_Info_From_File extends Debug_Bar_Shortcode_Info_Reflection {
/**
* Constructor - set the properties.
*
* @param string $shortcode The shortcode for which to retrieve info.
*/
public function __construct( $shortcode = '' ) {
parent::__construct( $shortcode );
$this->set_info_properties();
}
/**
* Enrich shortcode information.
*
* If a Reflection object can be obtained for the function/method the shortcode points to,
* use the documentation of that function to enrich the available information.
*/
private function set_info_properties() {
if ( $this->reflection_object instanceof ReflectionFunctionAbstract ) {
$this->description = nl2br( $this->strip_comment_markers( $this->reflection_object->getDocComment() ) );
$this->self_closing = true;
if ( $this->reflection_object->getNumberOfRequiredParameters() > 1 ) {
$this->self_closing = false;
}
$this->info_url = $this->get_plugin_url_from_file( $this->reflection_object->getFileName() );
}
}
/**
* Strip all comment markings and extra whitespace from a comment string.
*
* Strips for each line of the comment:
* - '/*[*]', '//', '#', '*' from the beginning of a line.
* - '*\/' from the end of a line.
* - spaces and tabs from the beginning of a line.
* - carriage returns (\r) from the end of a line.
* - merges any combination of spaces and tabs into one space.
*
* @param string $comment The comment string to examine.
*
* @return string
*/
private function strip_comment_markers( $comment ) {
static $search = array(
'`(^[\s]*(/\*+[\s]*(?:\*[ \t]*)?)|[\s]*(\*+/)[\s]*$|^[\s]*(\*+[ \t]*)|^[\s]*(/{2,})[\s]*|^[\s]*(#+)[\s]*)`m',
'`^([ \t]+)`m',
'`(\r)+[\n]?$`m',
'`([ \t\r]{2,})`',
);
static $replace = array(
'',
'',
'',
' ',
);
// Parse out all the line endings and comment delimiters.
$comment = trim( preg_replace( $search, $replace, trim( $comment ) ) );
return $comment;
}
/**
* Get the URL where you can find more information about the shortcode.
*
* Inspired by Shortcode reference, heavily adjusted to work more accurately.
* Source: https://wordpress.org/plugins/shortcode-reference/
*
* @param string $path_to_file Path to file containing the callback function.
*
* @return string URL.
*/
protected function get_plugin_url_from_file( $path_to_file ) {
/* Make sure the paths use the same slashing to make them comparable. */
$path_to_file = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $path_to_file );
$wp_abs_path = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, ABSPATH );
$wp_includes_path = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, ABSPATH . WPINC ) . DIRECTORY_SEPARATOR;
$wp_plugins_path = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, WP_PLUGIN_DIR ) . DIRECTORY_SEPARATOR;
$wp_mu_plugins_path = str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, WPMU_PLUGIN_DIR ) . DIRECTORY_SEPARATOR;
/* Check what type of file this is. */
if ( false !== strpos( $path_to_file, $wp_includes_path ) ) {
// WP native.
return 'http://codex.wordpress.org/index.php?title=Special:Search&search=' . urlencode( $this->shortcode ) . '_Shortcode';
}
$is_plugin = strpos( $path_to_file, $wp_plugins_path );
$is_mu_plugin = strpos( $path_to_file, $wp_mu_plugins_path );
$plugin_data = array();
$plugin_basename = '';
/* Is this a plugin in the normal plugin directory ? */
if ( false !== $is_plugin ) {
// Plugin in the plugins directory.
$relative_path = substr( $path_to_file, ( $is_plugin + strlen( $wp_plugins_path ) ) );
if ( function_exists( 'get_plugins' ) && false !== strpos( $relative_path, DIRECTORY_SEPARATOR ) ) {
// Subdirectory plugin.
$folder = substr( $relative_path, 0, strpos( $relative_path, DIRECTORY_SEPARATOR ) );
$folder = DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR;
$plugins = get_plugins( $folder );
/*
We'd expect only one file in the directory to have plugin data, otherwise we have
a problem as we won't know which file is the parent of the one containing the shortcode.
*/
if ( is_array( $plugins ) && 1 === count( $plugins ) ) {
// Only one item, but we don't know the key, use foreach to set the variables we need.
foreach ( $plugins as $plugin_basename => $plugin_data ) {
break;
}
}
/*
So in the case of several plugins within a directory - check if the file containing
the shortcode callback is one of the plugin main files. If so, accept.
Otherwise, ignore altogether.
*/
else {
$found = false;
foreach ( $plugins as $plugin_basename => $plugin_data ) {
if ( false !== strpos( $relative_path, DIRECTORY_SEPARATOR . $plugin_basename ) ) {
$found = true;
break;
}
}
if ( false === $found ) {
unset( $plugin_basename, $plugin_data );
}
unset( $found );
}
unset( $plugins, $folder );
}
elseif ( function_exists( 'get_plugin_data' ) ) {
// File directly in the plugins dir, just get straight plugin_data.
$plugin_basename = $relative_path;
$plugin_data = get_plugin_data( $path_to_file, false, false );
}
unset( $relative_path );
}
/* Is this a plugin in the mu plugin directory ? (`get_plugin_data()` only available on admin side.) */
elseif ( function_exists( 'get_plugin_data' ) && false !== $is_mu_plugin ) {
$relative_path = substr( $path_to_file, ( $is_mu_plugin + strlen( $wp_mu_plugins_path ) ) );
if ( false !== strpos( $relative_path, DIRECTORY_SEPARATOR ) ) {
// Subdirectory file, presume the mu-dir plugin bootstrap file is called directory-name.php.
$relative_path = substr( $relative_path, 0, strpos( $relative_path, DIRECTORY_SEPARATOR ) ) . '.php';
}
$plugin_basename = $relative_path;
$plugin_data = get_plugin_data( $wp_mu_plugins_path . $relative_path, false, false );
unset( $relative_path );
}
/* Let's see if we've got some results. */
if ( is_array( $plugin_data ) && ! empty( $plugin_data ) ) {
if ( isset( $plugin_data['PluginURI'] ) && trim( $plugin_data['PluginURI'] ) !== '' ) {
return trim( $plugin_data['PluginURI'] );
}
elseif ( isset( $plugin_data['AuthorURI'] ) && trim( $plugin_data['AuthorURI'] ) !== '' ) {
return trim( $plugin_data['AuthorURI'] );
}
}
/* Not exited yet ? Ok, then we didn't have either or the info items, let's try another way. */
if ( '' !== $plugin_basename ) {
$uri = $this->wp_repo_exists( $plugin_basename );
if ( false !== $uri ) {
return $uri;
}
else {
return 'http://www.google.com/search?q=Wordpress+' . urlencode( '"' . $plugin_basename . '"' ) . '+shortcode+' . urlencode( '"' . $this->shortcode . '"' );
}
}
/*
If all else fails, Google is your friend, but let's try not to reveal our server path.
*/
$is_wp = strpos( $path_to_file, $wp_abs_path );
if ( false !== $is_wp ) {
$sort_of_safe_path = substr( $path_to_file, ( $is_wp + strlen( $wp_abs_path ) ) );
return 'http://www.google.com/search?q=Wordpress+' . urlencode( '"' . $sort_of_safe_path . '"' ) . '+shortcode+' . urlencode( '"' . $this->shortcode . '"' );
}
return 'http://www.google.com/search?q=Wordpress+shortcode+' . urlencode( '"' . $this->shortcode . '"' );
}
/**
* Try to check if a wp plugin repository exists for a given plugin.
*
* @todo check WP for alternative way to do this, i.e. using flexible http_base class or something
* which will auto switch depending on call methods available.
*
* @param string $plugin_basename Plugin basename in the format dir/file.php.
*
* @return string|false URL or false if unsuccessful.
*/
private function wp_repo_exists( $plugin_basename ) {
if ( ! extension_loaded( 'curl' ) || '' === $plugin_basename ) {
// May be check using another method ? Nah, google is good enough.
return false;
}
/* Set up curl. */
$curl = curl_init();
// Issue a HEAD request.
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HEADER, true );
curl_setopt( $curl, CURLOPT_NOBODY, true );
// Follow any redirects.
$open_basedir = ini_get( 'open_basedir' );
if ( false === $this->ini_get_bool( 'safe_mode' ) && ( ( ! isset( $open_basedir ) || empty( $open_basedir ) ) || 'none' === $open_basedir ) ) {
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_MAXREDIRS, 5 );
}
unset( $open_basedir );
// Bypass servers which refuse curl.
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
// Set a time-out.
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
/* Figure out what the repo should be called. */
if ( strpos( $plugin_basename, DIRECTORY_SEPARATOR ) ) {
$plugin_basename = substr( $plugin_basename, 0, strpos( $plugin_basename, DIRECTORY_SEPARATOR ) );
}
if ( strpos( $plugin_basename, '.php' ) ) {
$plugin_basename = substr( $plugin_basename, 0, strpos( $plugin_basename, '.php' ) );
}
/* Check if it exists. */
if ( '' !== $plugin_basename ) {
$plugin_uri = 'https://wordpress.org/plugins/' . urlencode( $plugin_basename );
/* Get the http headers for the given url. */
curl_setopt( $curl, CURLOPT_URL, $plugin_uri );
$header = curl_exec( $curl );
/* If we didn't get an error, interpret the headers. */
if ( ( false !== $header && ! empty( $header ) ) && ( 0 === curl_errno( $curl ) ) ) {
/* Get the http status. */
$statuscode = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
if ( false === $statuscode && preg_match( '/^HTTP\/1\.[01] (\d\d\d)/', $header, $matches ) ) {
$statuscode = (int) $matches[1];
}
/* No http error response, so presume valid uri. */
if ( 400 > $statuscode ) {
curl_close( $curl );
return $plugin_uri;
}
}
}
curl_close( $curl );
return false;
}
/* ************** HELPER METHODS ************** */
/**
* Test a boolean PHP ini value.
*
* @since 3.0
*
* @param string $ini_key Key of the value you want to get.
*
* @return bool
*/
private function ini_get_bool( $ini_key ) {
$value = ini_get( $ini_key );
switch ( strtolower( $value ) ) {
case 'on':
case 'yes':
case 'true':
return 'assert.active' !== $ini_key;
default:
return (bool) (int) $value;
}
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,60 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Gallery.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Gallery' ) ) :
/**
* Information on the standard WP [gallery] shortcode.
*/
class Debug_Bar_Shortcode_Info_Gallery extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Whether the shortcode is self-closing or not.
*
* @var bool|null $self_closing
*/
public $self_closing = true;
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = 'http://codex.wordpress.org/Gallery_Shortcode';
/**
* Constructor - set some properties which need to be translated.
*/
public function __construct() {
$this->name = __( 'Image Gallery', 'debug-bar-shortcodes' );
$this->description = __( 'The Gallery feature allows you to add one or more image galleries to your posts and pages.', 'debug-bar-shortcodes' );
$this->parameters['optional'] = array(
'orderby' => __( 'Specify how to sort the display thumbnails. The default is "menu_order".', 'debug-bar-shortcodes' ),
'order' => __( 'Specify the sort order used to display thumbnails. ASC or DESC.', 'debug-bar-shortcodes' ),
'columns' => __( 'Specify the number of columns. The gallery will include a break tag at the end of each row, and calculate the column width as appropriate. The default value is 3. If columns is set to 0, no row breaks will be included.', 'debug-bar-shortcodes' ),
'id' => __( 'Specify the post ID. The gallery will display images which are attached to that post. The default behavior, if no ID is specified, is to display images attached to the current post.', 'debug-bar-shortcodes' ),
'size' => __( 'specify the image size to use for the thumbnail display. Valid values include "thumbnail", "medium", "large", "full". The default value is "thumbnail".', 'debug-bar-shortcodes' ),
'itemtag' => __( 'The name of the XHTML tag used to enclose each item in the gallery. The default is "dl".', 'debug-bar-shortcodes' ),
'icontag' => __( 'The name of the XHTML tag used to enclose each thumbnail icon in the gallery. The default is "dt".', 'debug-bar-shortcodes' ),
'captiontag' => __( 'The name of the XHTML tag used to enclose each caption. The default is "dd".', 'debug-bar-shortcodes' ),
'link' => __( 'You can set it to "file" so each image will link to the image file. The default value links to the attachment\'s permalink.', 'debug-bar-shortcodes' ),
'include' => __( 'Comma separated attachment IDs to show only the images from these attachments. ', 'debug-bar-shortcodes' ),
'exclude' => __( 'Comma separated attachment IDs excludes the images from these attachments. Please note that include and exclude cannot be used together.', 'debug-bar-shortcodes' ),
);
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,117 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info LHR.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_LHR' ) ) :
/**
* Information on a shortcode provided in the lhr shortcode plugin format.
*
* @see [LHR-Shortcode list](https://wordpress.org/plugins/lrh-shortcode-list/)
*/
class Debug_Bar_Shortcode_Info_LHR extends Debug_Bar_Shortcode_Info_Defaults {
/**
* LHR Defaults
*
* @var array $lhr_defaults
*/
private $lhr_defaults = array();
/**
* Info array as retrieved by running the LHR `sim_{$shortcode}` filter.
*
* This info is in the LHR format and has not been validated.
*
* @var array $lhr_info
*/
private $lhr_info;
/**
* Constructor - set the properties based on the lhr shortcode filter.
*
* @param string $shortcode The shortcode for which to retrieve info.
*/
public function __construct( $shortcode = '' ) {
$this->lhr_defaults = array(
'scTag' => $shortcode,
'scName' => $shortcode,
'scDesc' => __( 'No information available', 'debug-bar-shortcodes' ),
'scSelfCls' => 'u', // Unknown.
'scReqP' => array(),
'scOptP' => array(),
);
$this->lhr_info = apply_filters( 'sim_' . $shortcode, $this->lhr_defaults );
$this->set_name();
$this->set_description();
$this->set_self_closing();
$this->set_parameters( 'scReqP', 'required' );
$this->set_parameters( 'scOptP', 'optional' );
}
/**
* Set the name property if the LHR filter provided us with usable information.
*/
private function set_name() {
$this->set_string_property( 'scName', 'name' );
}
/**
* Set the description property if the LHR filter provided us with usable information.
*/
private function set_description() {
$this->set_string_property( 'scDesc', 'description' );
}
/**
* Set the self_closing property if the LHR filter provided us with usable information.
*/
private function set_self_closing() {
if ( is_bool( $this->lhr_info['scSelfCls'] ) ) {
$this->self_closing = $this->lhr_info['scSelfCls'];
}
}
/**
* Set the parameter property if the LHR filter provided us with usable information.
*
* @param string $lhr_key The array key for the LHR array.
* @param string $type The parameter type.
*/
private function set_parameters( $lhr_key, $type ) {
if ( is_array( $this->lhr_info[ $lhr_key ] ) && ! empty( $this->lhr_info[ $lhr_key ] ) ) {
$this->parameters[ $type ] = $this->lhr_info[ $lhr_key ];
}
}
/**
* Test and set a string property.
*
* @param string $key The array key for the LHR array.
* @param string $property The name of the property to set.
*/
private function set_string_property( $key, $property ) {
if ( is_string( $this->lhr_info[ $key ] ) && $this->lhr_info[ $key ] !== $this->lhr_defaults[ $key ] ) {
$this->{$property} = $this->lhr_info[ $key ];
}
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,60 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Playlist.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Playlist' ) ) :
/**
* Information on the standard WP [playlist] shortcode.
*/
class Debug_Bar_Shortcode_Info_Playlist extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Whether the shortcode is self-closing or not.
*
* @var bool|null $self_closing
*/
public $self_closing = true;
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = 'http://codex.wordpress.org/Playlist_Shortcode';
/**
* Constructor - set some properties which need to be translated.
*/
public function __construct() {
$this->name = __( 'Media Playlist', 'debug-bar-shortcodes' );
$this->description = __( 'The playlist shortcode implements the functionality of displaying a collection of WordPress audio or video files in a post using a simple Shortcode.', 'debug-bar-shortcodes' );
$this->parameters['optional'] = array(
'type' => __( 'Type of playlist to display. Accepts "audio" or "video". Defaults to "audio".', 'debug-bar-shortcodes' ),
'order' => __( 'Designates ascending or descending order of items in the playlist. Accepts "ASC", "DESC". Defaults to "ASC".', 'debug-bar-shortcodes' ),
'orderby' => __( 'Any column, or columns, to sort the playlist by. Accepts "rand" to play the list in random order. Defaults to "menu_order ID". If `$ids` are passed, this defaults to the order of the $ids array (\'post__in\').', 'debug-bar-shortcodes' ),
'id' => __( 'If an explicit `$ids` array is not present, this parameter will determine which attachments are used for the playlist. Defaults to the current post ID.', 'debug-bar-shortcodes' ),
'ids' => __( 'Create a playlist out of these explicit attachment IDs. If empty, a playlist will be created from all `$type` attachments of `$id`.', 'debug-bar-shortcodes' ),
'exclude' => __( 'List of specific attachment IDs to exclude from the playlist.', 'debug-bar-shortcodes' ),
'style' => __( 'Playlist style to use. Accepts "light" or "dark". Defaults to "light".', 'debug-bar-shortcodes' ),
'tracklist' => __( 'Whether to show or hide the playlist. Defaults to (bool) true.', 'debug-bar-shortcodes' ),
'tracknumbers' => __( 'Whether to show or hide the numbers next to entries in the playlist. Defaults to (bool) true.', 'debug-bar-shortcodes' ),
'images' => __( 'Show or hide the video or audio thumbnail (Featured Image/post thumbnail). Defaults to (bool) true.', 'debug-bar-shortcodes' ),
'artists' => __( 'Whether to show or hide artist name in the playlist. Defaults to (bool) true.', 'debug-bar-shortcodes' ),
);
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,93 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Reflection.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Reflection' ) ) :
/**
* Retrieve information on a shortcode using Reflection.
*
* Utility class. Not meant to be called directly, but meant to be extended.
*/
class Debug_Bar_Shortcode_Info_Reflection extends Debug_Bar_Shortcode_Info_Defaults {
/**
* The current shortcode.
*
* @var string $shortcode
*/
protected $shortcode = '';
/**
* Reflection object for the function being called for the current shortcode.
*
* @var object $reflection_object
*/
protected $reflection_object;
/**
* Constructor - set the properties.
*
* @param string $shortcode The shortcode for which to retrieve info.
*/
public function __construct( $shortcode = '' ) {
if ( ! empty( $shortcode ) && is_string( $shortcode ) ) {
$this->shortcode = $shortcode;
}
$this->set_reflection_object();
}
/**
* Retrieve a Reflection object for the file a shortcode is in.
*
* @uses $this->shortcode
* @uses $this->reflection_object
*/
private function set_reflection_object() {
$shortcodes = $GLOBALS['shortcode_tags'];
if ( empty( $this->shortcode ) || ! isset( $shortcodes[ $this->shortcode ] ) ) {
// Not a registered shortcode.
return;
}
$callback = $shortcodes[ $this->shortcode ];
if ( ! is_string( $callback ) && ( ! is_array( $callback ) || ( is_array( $callback ) && ( ! is_string( $callback[0] ) && ! is_object( $callback[0] ) ) ) ) && ( ! is_object( $callback ) || ( is_object( $callback ) && ! Debug_Bar_Shortcodes_Render::is_closure( $callback ) ) ) ) {
// Not a valid callback.
return;
}
/* Set up reflection. */
if ( ( is_string( $callback ) && false === strpos( $callback, '::' ) ) || ( is_object( $callback ) && Debug_Bar_Shortcodes_Render::is_closure( $callback ) ) ) {
$this->reflection_object = new ReflectionFunction( $callback );
}
elseif ( is_string( $callback ) && false !== strpos( $callback, '::' ) ) {
$this->reflection_object = new ReflectionMethod( $callback );
}
elseif ( is_array( $callback ) ) {
$this->reflection_object = new ReflectionMethod( $callback[0], $callback[1] );
}
if ( isset( $this->reflection_object ) && false === $this->reflection_object->isUserDefined() ) {
// Not a user defined callback, i.e. native PHP, nothing to find out about it (shouldn't ever happen).
$this->reflection_object = null;
}
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,143 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Shortcake.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Shortcake' ) ) :
/**
* Information on a shortcode based on what's available through the Shortcake UI registration.
*
* @see [Shortcake](https://wordpress.org/plugins/shortcode-ui/)
* @see https://github.com/wp-shortcake/Shortcake/
*
* @todo Potentially provide support for shortcake ui registrations from other plugins even
* when shortcake itself is not available. I.e. run their hooks to obtain the info.
*
* Current implementation based on Shortcake 0.6.2.
*/
class Debug_Bar_Shortcode_Info_Shortcake extends Debug_Bar_Shortcode_Info_From_File {
/**
* Shortcode as registered in Shortcake.
*
* @var array
*/
private $shortcake;
/**
* Constructor - set the properties.
*
* @param string $shortcode The shortcode for which to retrieve info.
*/
public function __construct( $shortcode = '' ) {
$shortcake = shortcode_ui_get_register_shortcode( $shortcode );
if ( ! isset( $shortcake ) ) {
return;
}
$this->shortcake = $shortcake;
Debug_Bar_Shortcode_Info_Reflection::__construct( $shortcode ); // Skip parent, do grandparent.
$this->set_name();
$this->set_description();
$this->set_self_closing();
$this->set_parameters();
$this->set_info_url();
}
/**
* Set the name property if Shortcake provided us with usable information.
*/
private function set_name() {
if ( ! empty( $this->shortcake['label'] ) && ( is_string( $this->shortcake['label'] ) && $this->shortcake['label'] !== $this->shortcode ) ) {
$this->name = $this->shortcake['label'];
}
}
/**
* Set the description property if Shortcake provided us with usable information.
*
* @internal Description field support does not exist yet within Shortcake.
* @see https://github.com/wp-shortcake/Shortcake/issues/386
*/
private function set_description() {
if ( ! empty( $this->shortcake['description'] ) && is_string( $this->shortcake['description'] ) ) {
$this->description = $this->shortcake['description'];
}
}
/**
* Set the self_closing property if Shortcake provided us with usable information.
*/
private function set_self_closing() {
if ( ! empty( $this->shortcake['inner_content'] ) && is_array( $this->shortcake['inner_content'] ) ) {
$this->self_closing = false;
}
else {
$this->self_closing = true;
}
}
/**
* Set the parameter property if Shortcake provided us with usable information.
*/
private function set_parameters() {
if ( ! empty( $this->shortcake['attrs'] ) && is_array( $this->shortcake['attrs'] ) ) {
foreach ( $this->shortcake['attrs'] as $attr_array ) {
if ( ! isset( $attr_array['attr'] ) ) {
continue;
}
$text = '';
foreach ( array( 'label', 'description' ) as $key ) {
if ( ! empty( $attr_array[ $key ] ) && is_string( $attr_array[ $key ] ) ) {
$text .= $attr_array[ $key ] . '. ';
}
}
unset( $key );
// Does not exist yet - issue https://github.com/wp-shortcake/Shortcake/issues/132 .
if ( isset( $attr_array['required'] ) && true === $attr_array['required'] ) {
$this->parameters['required'][ $attr_array['attr'] ] = $text;
}
else {
$this->parameters['optional'][ $attr_array['attr'] ] = $text;
}
}
}
}
/**
* Set the info URL.
*
* @internal Maybe move this to an ajax call once Shortcake is used more as is expensive.
*/
private function set_info_url() {
if ( $this->reflection_object instanceof ReflectionFunctionAbstract ) {
$this->info_url = $this->get_plugin_url_from_file( $this->reflection_object->getFileName() );
}
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,125 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Validator.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Validator' ) ) :
/**
* Retrieve information on a shortcode using Reflection.
*
* Utility class. Not meant to be called directly, but meant to be extended.
*/
class Debug_Bar_Shortcode_Info_Validator extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Unvalidated shortcode info.
*
* @var object $dirty
*/
private $dirty;
/**
* Validate the shortcode info before using it to make sure that it's still in a usable form.
*
* @param object|array $info Shortcode info.
*/
public function __construct( $info ) {
if ( is_object( $info ) ) {
$this->dirty = $info;
}
elseif ( is_array( $info ) && ! empty( $info ) ) {
$this->dirty = (object) $info;
}
else {
// No valid input received, will effectively return the default properties.
return;
}
$this->validate_name();
$this->validate_description();
$this->validate_self_closing();
$this->validate_parameters();
$this->validate_info_url();
unset( $this->dirty );
}
/**
* Validate a shortcode name.
*/
private function validate_name() {
if ( isset( $this->dirty->name ) && is_string( $this->dirty->name ) && '' !== trim( $this->dirty->name ) ) {
$this->name = sanitize_text_field( trim( $this->dirty->name ) );
}
}
/**
* Validate a shortcode description.
*/
private function validate_description() {
if ( isset( $this->dirty->description ) && is_string( $this->dirty->description ) && '' !== trim( $this->dirty->description ) ) {
$this->description = wp_kses( trim( $this->dirty->description ), array( 'br' => array() ) );
}
}
/**
* Validate the self_closing information.
*/
private function validate_self_closing() {
if ( isset( $this->dirty->self_closing ) ) {
// Work around flacky behaviour of PHP for the FILTER_NULL_ON_FAILURE flag.
if ( is_bool( $this->dirty->self_closing ) ) {
$this->self_closing = $this->dirty->self_closing;
}
elseif ( function_exists( 'filter_var' ) ) {
$this->self_closing = filter_var( $this->dirty->self_closing, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
}
}
}
/**
* Validate the shortcode parameters information.
*/
private function validate_parameters() {
if ( ! empty( $this->dirty->parameters ) && is_array( $this->dirty->parameters ) ) {
foreach ( $this->parameters as $k => $v ) {
if ( ! empty( $this->dirty->parameters[ $k ] ) && is_array( $this->dirty->parameters[ $k ] ) ) {
foreach ( $this->dirty->parameters[ $k ] as $attr => $explanation ) {
if ( ( ( is_string( $attr ) && '' !== trim( $attr ) ) || ( is_int( $attr ) && $attr >= 0 ) ) && ( is_string( $explanation ) && '' !== trim( $explanation ) ) ) {
$this->parameters[ $k ][ sanitize_key( trim( $attr ) ) ] = sanitize_text_field( trim( $explanation ) );
}
}
unset( $attr, $explanation );
}
}
unset( $k, $v );
}
}
/**
* Validate the shortcode info URL.
*/
private function validate_info_url() {
if ( ( isset( $this->dirty->info_url ) && is_string( $this->dirty->info_url ) && preg_match( '`http(s?)://(.+)`i', $this->dirty->info_url ) ) ) {
$this->info_url = esc_url_raw( trim( $this->dirty->info_url ) );
}
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,71 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info Video.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_Video' ) ) :
/**
* Information on the standard WP [video] shortcode.
*/
class Debug_Bar_Shortcode_Info_Video extends Debug_Bar_Shortcode_Info_Defaults {
/**
* Whether the shortcode is self-closing or not.
*
* @var bool|null $self_closing
*/
public $self_closing = true;
/**
* Info URL.
*
* @var string $info_url
*/
public $info_url = 'http://codex.wordpress.org/Video_Shortcode';
/**
* Constructor - set some properties which need to be translated.
*/
public function __construct() {
$this->name = __( 'Video Media', 'debug-bar-shortcodes' );
$this->description = __( 'The Video feature allows you to embed video files and play them back. This was added as of WordPress 3.6.', 'debug-bar-shortcodes' );
/* translators: %s = height/weight. */
$string = __( 'Defines %s of the media. Value is automatically detected on file upload.', 'debug-bar-shortcodes' );
$this->parameters['required'] = array(
'height' => sprintf( $string, __( 'height', 'debug-bar-shortcodes' ) ),
'width' => sprintf( $string, __( 'width', 'debug-bar-shortcodes' ) ),
);
/* translators: %s = file extension. */
$string = __( 'Source of %s fallback file.', 'debug-bar-shortcodes' );
$this->parameters['optional'] = array(
'src' => __( 'The source of your video file. If not included it will auto-populate with the first video file attached to the post.', 'debug-bar-shortcodes' ),
'mp4' => sprintf( $string, 'mp4' ),
'm4v' => sprintf( $string, 'm4v' ),
'webm' => sprintf( $string, 'webm' ),
'ogv' => sprintf( $string, 'ogv' ),
'wmv' => sprintf( $string, 'wmv' ),
'flv' => sprintf( $string, 'flv' ),
'poster' => __( 'Defines image to show as placeholder before the media plays. Defaults to "none".', 'debug-bar-shortcodes' ),
'loop' => __( 'Allows for the looping of media. Defaults to "off"', 'debug-bar-shortcodes' ),
'autoplay' => __( 'Causes the media to automatically play as soon as the media file is ready. Defaults to "off".', 'debug-bar-shortcodes' ),
'preload' => __( 'Specifies if and how the video should be loaded when the page loads. Defaults to "metadata".', 'debug-bar-shortcodes' ),
);
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,23 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info WP Caption.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info_WP_Caption' ) ) :
/**
* Information on the standard WP [wp_caption] shortcode.
*/
class Debug_Bar_Shortcode_Info_WP_Caption extends Debug_Bar_Shortcode_Info_Caption {
}
endif; // End of if class_exists.

View File

@@ -0,0 +1,274 @@
<?php
/**
* Debug Bar Shortcodes - Debug Bar Shortcode Info.
*
* @package WordPress\Plugins\Debug Bar Shortcodes
* @subpackage WordPress\Plugins\Debug Bar Shortcodes\Shortcode Info
* @author Juliette Reinders Folmer <wpplugins_nospam@adviesenzo.nl>
* @link https://github.com/jrfnl/Debug-Bar-Shortcodes
* @since 2.0
*
* @copyright 2013-2016 Juliette Reinders Folmer
* @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License, version 2 or higher
*/
if ( ! class_exists( 'Debug_Bar_Shortcode_Info' ) ) :
/**
* Retrieve shortcode info.
*/
class Debug_Bar_Shortcode_Info {
/**
* The shortcode this object applies to.
*
* @var string $shortcode
*/
protected $shortcode = '';
/**
* Defaults.
*
* @var \Debug_Bar_Shortcode_Info_Defaults $defaults
*/
protected $defaults;
/**
* Shortcode info object.
*
* Can be of type Debug_Bar_Shortcode_Info_Defaults (or one of it's children), but doesn't have to be.
*
* @var object $info
*/
protected $info;
/**
* The names of the shortcodes which are included with WP by default.
*
* @var array $wp_shortcodes
*/
protected $wp_shortcodes = array(
'audio',
'video',
'caption',
'wp_caption',
'gallery',
'embed',
'playlist',
);
/**
* Try and enrich the shortcode with additional information.
*
* @param string $shortcode Current shortcode.
* @param bool $use_reflection Whether or not to get additional information from the function documentation.
* Defaults to false.
*/
public function __construct( $shortcode, $use_reflection = false ) {
$this->defaults = new Debug_Bar_Shortcode_Info_Defaults();
$this->info = $this->defaults;
// Bail out if we didn't receive a valid shortcode.
if ( empty( $shortcode ) || ! is_string( $shortcode ) ) {
return;
}
$this->shortcode = $shortcode;
// Low priority to allow override by better data.
add_filter( 'db_shortcodes_info_' . $this->shortcode, array( $this, 'lhr_shortcode_info' ), 8 );
add_filter( 'db_shortcodes_info_' . $this->shortcode, array( $this, 'shortcake_shortcode_info' ), 9 );
add_filter( 'db_shortcodes_info_' . $this->shortcode, array( $this, 'wp_shortcode_info' ), 10 );
if ( true === $use_reflection && true === $this->is_registered() ) {
add_filter( 'db_shortcodes_info_' . $this->shortcode, array( $this, 'shortcode_info_from_documentation' ), 12 );
}
/*
* Casts objects to array before passing them into the filter for backwards compatibility
* with the original (pre-2.0) documentation.
*
* @todo document filters
*/
$info = (object) apply_filters( 'db_shortcodes_info', $this->defaults, $this->shortcode, (array) $this->defaults );
$info = (object) apply_filters( 'db_shortcodes_info_' . $this->shortcode, $info, (array) $info );
// Make sure that the information is usable.
$this->info = new Debug_Bar_Shortcode_Info_Validator( $info );
}
/**
* Get the info object for this shortcode.
*
* @return \Debug_Bar_Shortcode_Info_Defaults
*/
public function get_info_object() {
return $this->info;
}
/**
* Check whether the shortcode has details beyond the defaults.
*
* @return bool True if it has, false otherwise.
*/
public function has_details() {
return ( (array) $this->info !== (array) $this->defaults );
}
/**
* Check whether the shortcode has been registered in WP.
*
* @return bool True if registered, false otherwise.
*/
public function is_registered() {
return ( ! empty( $this->shortcode ) && isset( $GLOBALS['shortcode_tags'][ $this->shortcode ] ) );
}
/* ************** METHODS TO RETRIEVE SHORTCODE INFO ************** */
/**
* Get potentially provided info for a shortcode in the lhr shortcode plugin format.
*
* @param object $info Shortcode info.
*
* @return object Updated shortcode info.
*/
public function lhr_shortcode_info( $info ) {
// If the current shortcode is native to WP Core, don't use the lhr info as the info
// in this plugin is better.
if ( in_array( $this->shortcode, $this->wp_shortcodes, true ) || false === has_filter( 'sim_' . $this->shortcode ) ) {
return $info;
}
$additional = new Debug_Bar_Shortcode_Info_LHR( $this->shortcode );
return $this->merge_info_objects( $additional, $info );
}
/**
* Get potentially provided info for a shortcode based on the Shortcake UI registration.
*
* @param object $info Shortcode info.
*
* @return object Updated shortcode info.
*/
public function shortcake_shortcode_info( $info ) {
// Bail out if Shortcake is not available.
if ( ! function_exists( 'shortcode_ui_get_register_shortcode' ) ) {
return $info;
}
$additional = new Debug_Bar_Shortcode_Info_Shortcake( $this->shortcode );
return $this->merge_info_objects( $additional, $info );
}
/**
* Enrich the information for the standard WP shortcodes.
*
* @param object $info Shortcode info.
*
* @return object Updated shortcode info.
*/
public function wp_shortcode_info( $info ) {
// Return early if not a WP Core native shortcode.
if ( ! in_array( $this->shortcode, $this->wp_shortcodes, true ) ) {
return $info;
}
$class = 'Debug_Bar_Shortcode_Info_' . $this->shortcode;
$additional = new $class;
return $this->merge_info_objects( $additional, $info );
}
/**
* Conditionally retrieve additional info about a shortcode based on the function/method documentation.
*
* @param object $info Shortcode info.
*
* @return object Updated shortcode info.
*/
public function shortcode_info_from_documentation( $info ) {
$additional = new Debug_Bar_Shortcode_Info_From_File( $this->shortcode );
return $this->merge_info_objects( $additional, $info );
}
/* ************** HELPER METHODS ************** */
/**
* Merge two info objects into one making sure that the old values are not overruled by 'empties'.
*
* The received value *could* be an array if someone still uses the old filter logic.
*
* @param object|array $new The new values.
* @param object|array $old The old values.
*
* @return object
*/
public function merge_info_objects( $new, $old ) {
// Filter out the empties, but preserve the value for self_closing (which could be false).
$new_filtered = array_filter( (array) $new );
$new_filtered['self_closing'] = isset( $new->self_closing ) ? $new->self_closing : null;
return (object) $this->array_merge_recursive_distinct( (array) $old, $new_filtered );
}
/**
* Recursively merge a variable number of arrays, using the left array as base,
* giving priority to the right array.
*
* Difference with native array_merge_recursive():
* `array_merge_recursive()` converts values with duplicate keys to arrays rather than
* overwriting the value in the first array with the duplicate value in the second array.
*
* `array_merge_recursive_distinct()` does not change the data types of the values in the arrays.
* Matching keys' values in the second array overwrite those in the first array, as is the
* case with array_merge.
*
* Freely based on information found on http://www.php.net/manual/en/function.array-merge-recursive.php.
*
* @params array $arrays 2 or more arrays to merge.
*
* @return array
*/
private function array_merge_recursive_distinct() {
$arrays = func_get_args();
if ( count( $arrays ) < 2 ) {
if ( empty( $arrays ) ) {
return array();
}
else {
return $arrays[0];
}
}
$merged = array_shift( $arrays );
foreach ( $arrays as $array ) {
foreach ( $array as $key => $value ) {
if ( is_array( $value ) && ( isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) ) {
$merged[ $key ] = self::array_merge_recursive_distinct( $merged[ $key ], $value );
}
else {
$merged[ $key ] = $value;
}
}
unset( $key, $value );
}
return $merged;
}
} // End of class.
endif; // End of if class_exists.

View File

@@ -0,0 +1,2 @@
<?php
// Nothing to see here.