Gestionnaire de fichiers - Editer - /home/wwgoat/public_html/blog/breadcrumb-navxt.tar
Arrière
class.bcn_admin.php 0000644 00000110554 14720660717 0010313 0 ustar 00 <?php /* Copyright 2015-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); //Do a PHP version check, require 5.6.0 or newer if(version_compare(phpversion(), '5.6.0', '<')) { //Only purpose of this function is to echo out the PHP version error function bcn_phpold() { printf('<div class="notice notice-error"><p>' . __('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.6.0'); } //If we are in the admin, let's print a warning then return if(is_admin()) { add_action('admin_notices', 'bcn_phpold'); } return; } //Include admin base class if(!class_exists('\mtekk\adminKit\adminKit')) { require_once(dirname(__FILE__) . '/includes/adminKit/class-mtekk_adminkit.php'); } use mtekk\adminKit\{adminKit, form, message, setting}; /** * The administrative interface class * */ class bcn_admin extends adminKit { const version = '7.3.1'; protected $full_name = 'Breadcrumb NavXT Settings'; protected $short_name = 'Breadcrumb NavXT'; protected $access_level = 'bcn_manage_options'; protected $identifier = 'breadcrumb-navxt'; protected $unique_prefix = 'bcn'; protected $plugin_basename = null; protected $support_url = 'https://wordpress.org/support/plugin/breadcrumb-navxt/'; /** * Administrative interface class default constructor * * @param array $opts The breadcrumb trail object's settings array * @param string $basename The basename of the plugin * @param array $settings The array of settings objects */ function __construct(array &$opts, $basename, array &$settings) { $this->plugin_basename = $basename; $this->full_name = esc_html__('Breadcrumb NavXT Settings', 'breadcrumb-navxt'); $this->settings =& $settings; $this->opt =& $opts; //We're going to make sure we load the parent's constructor parent::__construct(); } function is_network_admin() { return false; } /** * Loads opts array values into the local settings array * * @param array $opts The opts array */ function setting_merge($opts) { $unknown = array(); foreach($opts as $key => $value) { if(isset($this->settings[$key]) && $this->settings[$key] instanceof setting\setting) { $this->settings[$key]->set_value($this->settings[$key]->validate($value)); } else if(isset($this->settings[$key]) && is_array($this->settings[$key]) && is_array($value)) { foreach($value as $subkey => $subvalue) { if(isset($this->settings[$key][$subkey]) && $this->settings[$key][$subkey]instanceof setting\setting) { $this->settings[$key][$subkey]->set_value($this->settings[$key][$subkey]->validate($subvalue)); } } } else { $unknown[] = $key; } } //Add a message if we found some unknown settings while merging if(count($unknown) > 0) { $this->messages[] = new message( sprintf(__('Found %u unknown legacy settings: %s','breadcrumb-navxt'), count($unknown), implode(', ', $unknown)), 'warning', true, 'bcn_unkonwn_legacy_settings'); } } /** * admin initialization callback function * * is bound to wordpress action 'admin_init' on instantiation * * @since 3.2.0 * @return void */ function init() { //We're going to make sure we run the parent's version of this function as well parent::init(); $this->setting_merge($this->opt); } /** * Upgrades input options array, sets to $this->opt * * @param array $opts * @param string $version the version of the passed in options */ function opts_upgrade($opts, $version) { //If our version is not the same as in the db, time to update if(version_compare($version, $this::version, '<')) { require_once(dirname(__FILE__) . '/options_upgrade.php'); bcn_options_upgrade_handler($opts, $version, $this->opt); } //Merge in the defaults $this->opt = adminKit::parse_args($opts, adminKit::settings_to_opts($this->settings)); } /** * Fills in the help tab contents * * @param WP_Screen $screen The screen to add the help tab items to */ function help_contents(\WP_Screen &$screen) { $general_tab = '<p>' . esc_html__('Tips for the settings are located below select options.', 'breadcrumb-navxt') . '</p><h5>' . esc_html__('Resources', 'breadcrumb-navxt') . '</h5><ul><li>' . '<a title="' . esc_attr__('Go to the Breadcrumb NavXT tag archive.', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/tag/breadcrumb-navxt">' . esc_html__('Tutorials and How Tos', 'breadcrumb-navxt') . '</a>: ' . esc_html__("There are several guides, tutorials, and how tos available on the author's website.", 'breadcrumb-navxt') . '</li><li>' . '<a title="' . esc_attr__('Go to the Breadcrumb NavXT online documentation', 'breadcrumb-navxt') . '" href="https://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/">' . esc_html__('Online Documentation', 'breadcrumb-navxt') . '</a>: '. esc_html__('Check out the documentation for more indepth technical information.', 'breadcrumb-navxt') . '</li><li>' . '<a title="' . esc_attr__('Go to the Breadcrumb NavXT support post for your version.', 'breadcrumb-navxt') . '" href="https://wordpress.org/support/plugin/breadcrumb-navxt/">' . esc_html__('Report a Bug', 'breadcrumb-navxt') . '</a>: ' . esc_html__('If you think you have found a bug, please include your WordPress version and details on how to reproduce the bug.', 'breadcrumb-navxt') . '</li></ul>' . '<h5>' . esc_html__('Giving Back', 'breadcrumb-navxt') . '</h5><ul><li>' . '<a title="' . esc_attr__('Go to PayPal to give a donation to Breadcrumb NavXT.', 'breadcrumb-navxt') . '" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=FD5XEU783BR8U&lc=US&item_name=Breadcrumb%20NavXT%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">' . esc_html__('Donate', 'breadcrumb-navxt') . '</a>: ' . esc_html__('Love Breadcrumb NavXT and want to help development? Consider buying the author a beer.', 'breadcrumb-navxt') . '</li><li>' . '<a title="' . esc_attr__('Go to the Breadcrumb NavXT translation project.', 'breadcrumb-navxt') . '" href="https://translate.wordpress.org/projects/wp-plugins/breadcrumb-navxt">' . esc_html__('Translate', 'breadcrumb-navxt') . '</a>: ' . esc_html__('Is your language not available? Visit the Breadcrumb NavXT translation project on WordPress.org to start translating.', 'breadcrumb-navxt') . '</li></ul>'; $screen->add_help_tab( array( 'id' => $this->identifier . '-base', 'title' => __('General', 'breadcrumb-navxt'), 'content' => $general_tab )); $quickstart_tab = '<p>' . esc_html__('For the settings on this page to take effect, you must either use the included Breadcrumb NavXT widget, or place either of the code sections below into your theme.', 'breadcrumb-navxt') . '</p><h5>' . esc_html__('Breadcrumb trail with separators', 'breadcrumb-navxt') . '</h5><pre><code><div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">' . " <?php if(function_exists('bcn_display')) { bcn_display(); }?> </div></code></pre>" . '<h5>' . esc_html__('Breadcrumb trail in list form', 'breadcrumb-navxt').'</h5><pre><code><ol class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">'." <?php if(function_exists('bcn_display_list')) { bcn_display_list(); }?> </ol></code></pre>"; $screen->add_help_tab( array( 'id' => $this->identifier . '-quick-start', 'title' => __('Quick Start', 'breadcrumb-navxt'), 'content' => $quickstart_tab )); $styling_tab = '<p>' . esc_html__('Using the code from the Quick Start section above, the following CSS can be used as base for styling your breadcrumb trail.', 'breadcrumb-navxt') . '</p>' . '<pre><code>.breadcrumbs { font-size: 1.1em; color: #fff; margin: 30px 0 0 10px; position: relative; float: left; }</code></pre>'; $screen->add_help_tab( array( 'id' => $this->identifier . '-styling', 'title' => __('Styling', 'breadcrumb-navxt'), 'content' => $styling_tab )); $screen->add_help_tab( array( 'id' => $this->identifier . '-import-export-reset', 'title' => __('Import/Export/Reset', 'breadcrumb-navxt'), 'content' => $this->import_form() )); } /** * enqueue's the tab style sheet on the settings page */ function admin_styles() { wp_enqueue_style('mtekk_adminkit_tabs'); } /** * enqueue's the tab js and translation js on the settings page */ function admin_scripts() { //Enqueue ui-tabs wp_enqueue_script('jquery-ui-tabs'); //Enqueue the admin tabs javascript wp_enqueue_script('mtekk_adminkit_tabs'); //Load the translations for the tabs wp_localize_script('mtekk_adminkit_tabs', 'objectL10n', array( 'mtad_uid' => 'bcn_admin', 'mtad_import' => __('Import', 'breadcrumb-navxt'), 'mtad_export' => __('Export', 'breadcrumb-navxt'), 'mtad_reset' => __('Reset', 'breadcrumb-navxt'), )); //Enqueue the admin enable/disable groups javascript wp_enqueue_script('mtekk_adminkit_engroups'); } /** * A message function that checks for the BCN_SETTINGS_* define statement */ function multisite_settings_warn() { if(is_multisite()) { if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL) { } else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK) { $this->messages[] = new message(esc_html__('Warning: Your network settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nsiteoveride'); } else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL) { $this->messages[] = new message(esc_html__('Warning: Your network settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_isitemayoveride'); } else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK) { $this->messages[] = new message(esc_html__('Warning: Your network settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nsitemayoveride'); } //Fall through if no settings mode was set else { $this->messages[] = new message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nosetting'); } } } /** * A message function that checks for deprecated settings that are set and warns the user */ function deprecated_settings_warn() { //We're deprecating the limit title length setting, let the user know the new method of accomplishing this if(isset($this->settings['blimit_title']) && $this->settings['blimit_title']->get_value()) { $this->messages[] = new message( sprintf( esc_html__('Error: The deprecated setting "Title Length" (see Miscellaneous > Deprecated) has no effect in this version Breadcrumb NavXT. Please %1$suse CSS instead%2$s.', 'breadcrumb-navxt'), '<a title="' . __('Go to the guide on trimming breadcrumb title lengths with CSS', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/guides/trimming-breadcrumb-title-lengths-with-css/">', '</a>'), 'error'); } foreach($this->settings as $key => $setting) { if($key[0] == "H" && substr_count($key, '_template') >= 1) { $deprecated_tags = array(); $replacement_tags = array(); //Deprecated ftitle check if(substr_count($setting->get_value(), '%ftitle%') >= 1) { $deprecated_tags[] = '%ftitle%'; $replacement_tags[] = '%title%'; } //Deprecated fhtitle check if(substr_count($setting->get_value(), '%fhtitle%') >= 1) { $deprecated_tags[] = '%fhtitle%'; $replacement_tags[] = '%htitle%'; } if(count($deprecated_tags) > 0) { $setting_link = sprintf('<a href="#%1$s">%2$s</a>', $key, $setting->get_title()); $this->messages[] = new message( sprintf( esc_html__('Error: The deprecated template tag %1$s found in setting %3$s. Please use %2$s instead.', 'breadcrumb-navxt'), implode(' and ', $deprecated_tags), implode(' and ', $replacement_tags), $setting_link), 'error'); } } } } /** * A message function that checks for post types added after the settings defaults were established */ function unknown_custom_types_warn() { foreach($GLOBALS['wp_post_types'] as $post_type) { if(!($post_type instanceof WP_Post_Type)) { $this->messages[] = new message( sprintf( esc_html__('Error: WP_Post_Types global contains non WP_Post_Type object. Debug information: %1$s', 'breadcrumb-navxt'), var_export($post_type, true)), 'error', true, 'badtypeWP_Post_Types'); continue; } //If we haven't seen this post type before, warn the user if(!isset($this->settings['Hpost_' . $post_type->name . '_template'])) { $this->messages[] = new message( sprintf( esc_html__('Warning: The post type %1$s (%2$s) was registered after the Breadcrumb NavXT default settings. It will not show up in the settings.', 'breadcrumb-navxt'), $post_type->labels->singular_name, $post_type->name), 'warning', true, $post_type->name); } } foreach($GLOBALS['wp_taxonomies'] as $taxonomy) { if(!($taxonomy instanceof WP_Taxonomy)) { //If we haven't seen this taxonomy before, warn the user $this->messages[] = new message( sprintf( esc_html__('Error: WP_Taxonomies global contains non WP_Taxonomy object. Debug information: %1$s', 'breadcrumb-navxt'), var_export($taxonomy, true)), 'error', true, 'badtypeWP_Taxonomies'); continue; } if(!isset($this->settings['Htax_' . $taxonomy->name . '_template'])) { //If we haven't seen this taxonomy before, warn the user $this->messages[] = new message( sprintf( esc_html__('Warning: The taxonomy %1$s (%2$s) was registered after the Breadcrumb NavXT default settings. It will not show up in the settings.', 'breadcrumb-navxt'), $taxonomy->label, $taxonomy->name), 'warning', true, $taxonomy->name); } } } /** * Function checks the current site to see if the blog options should be disabled * * @return boool Whether or not the blog options should be disabled */ function maybe_disable_blog_options() { return (get_option('show_on_front') !== 'page' || get_option('page_for_posts') < 1); } /** * Function checks the current site to see if the mainsite options should be disabled * * @return bool Whether or not the mainsite options should be disabled */ function maybe_disable_mainsite_options() { return !is_multisite(); } /** * The administrative page for Breadcrumb NavXT */ function admin_page() { global $wp_taxonomies, $wp_post_types; $this->security(); //Do a check on deprecated settings $this->deprecated_settings_warn(); //Do a check for unknown CPTs and Taxnomies $this->unknown_custom_types_warn(); //Do a check for multisite settings mode $this->multisite_settings_warn(); do_action($this->unique_prefix . '_settings_pre_messages', $this->settings); //Display our messages $this->messages(); //Grab the network options, if multisite $network_opts = array(); $local_opts = array(); $overriden = array(); $overriden_style = array(); if(is_multisite() && !$this->is_network_admin()) { $network_opts = get_site_option('bcn_options'); $local_opts = get_option('bcn_options'); } foreach($this->settings as $key => $setting) { if(isset($network_opts[$key]) && ((defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK) || (defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK))) { $overriden[$key] = ' ' . __('Value has been set via network wide setting.', 'breadcrumb-navxt'); $overriden_style[$key] = ' disabled'; } else { $overriden[$key] = ''; $overriden_style[$key] = ''; } } ?> <div class="wrap"><h1><?php echo $this->full_name; ?></h1> <?php //We exit after the version check if there is an action the user needs to take before saving settings if(!$this->version_check($this->get_option($this->unique_prefix . '_version'))) { return; } ?> <form action="<?php echo $this->admin_url(); ?>" method="post" id="bcn_admin-options"> <?php settings_fields('bcn_options');?> <div id="hasadmintabs"> <fieldset id="general" class="bcn_options"> <legend class="screen-reader-text" data-title="<?php _e( 'A collection of settings most likely to be modified are located under this tab.', 'breadcrumb-navxt' );?>"><?php _e( 'General', 'breadcrumb-navxt' ); ?></legend> <h2><?php _e('General', 'breadcrumb-navxt'); ?></h2> <table class="form-table"> <?php $this->form->textbox($this->settings['hseparator'], '2', false, __('Placed in between each breadcrumb.', 'breadcrumb-navxt') . $overriden['hseparator'], $overriden_style['hseparator']); do_action($this->unique_prefix . '_settings_general', $this->settings); ?> </table> <h2><?php _e('Current Item', 'breadcrumb-navxt'); ?></h2> <table class="form-table adminkit-enset-top"> <?php $this->form->input_check( $this->settings['bcurrent_item_linked'], __('Yes', 'breadcrumb-navxt'), false, $overriden['bcurrent_item_linked'], $overriden_style['bcurrent_item_linked']); $this->form->input_check( $this->settings['bpaged_display'], __('Place the page number breadcrumb in the trail.', 'breadcrumb-navxt'), false, __('Indicates that the user is on a page other than the first of a paginated archive or post.', 'breadcrumb-navxt') . $overriden['bpaged_display'], 'adminkit-enset-ctrl adminkit-enset' . $overriden_style['bpaged_display']); $this->form->textbox( $this->settings['Hpaged_template'], '4', false, __('The template for paged breadcrumbs.', 'breadcrumb-navxt') . $overriden['Hpaged_template'], 'adminkit-enset' . $overriden_style['Hpaged_template']); do_action($this->unique_prefix . '_settings_current_item', $this->settings); ?> </table> <h2><?php _e('Home Breadcrumb', 'breadcrumb-navxt'); ?></h2> <table class="form-table adminkit-enset-top"> <?php $this->form->input_check( $this->settings['bhome_display'], __('Place the home breadcrumb in the trail.', 'breadcrumb-navxt'), false, $overriden['bhome_display'], 'adminkit-enset-ctrl adminkit-enset' . $overriden_style['bhome_display']); $this->form->textbox( $this->settings['Hhome_template'], '6', false, __('The template for the home breadcrumb.', 'breadcrumb-navxt') . $overriden['Hhome_template'], 'adminkit-enset' . $overriden_style['Hhome_template']); $this->form->textbox( $this->settings['Hhome_template_no_anchor'], '4', false, __('The template for the home breadcrumb, used when the breadcrumb is not linked.', 'breadcrumb-navxt') . $overriden['Hhome_template_no_anchor'], 'adminkit-enset' . $overriden_style['Hhome_template_no_anchor']); do_action($this->unique_prefix . '_settings_home', $this->settings); ?> </table> <h2><?php _e('Blog Breadcrumb', 'breadcrumb-navxt'); ?></h2> <table class="form-table adminkit-enset-top"> <?php $this->form->input_check( $this->settings['bblog_display'], __('Place the blog breadcrumb in the trail.', 'breadcrumb-navxt'), $this->maybe_disable_blog_options(), $overriden['bblog_display'], 'adminkit-enset-ctrl adminkit-enset' . $overriden_style['bblog_display']); do_action($this->unique_prefix . '_settings_blog', $this->settings); ?> </table> <h2><?php _e('Mainsite Breadcrumb', 'breadcrumb-navxt'); ?></h2> <table class="form-table adminkit-enset-top"> <?php $this->form->input_check( $this->settings['bmainsite_display'], __('Place the main site home breadcrumb in the trail in an multisite setup.', 'breadcrumb-navxt'), $this->maybe_disable_mainsite_options(), $overriden['bmainsite_display'], 'adminkit-enset-ctrl adminkit-enset' . $overriden_style['bmainsite_display']); $this->form->textbox( $this->settings['Hmainsite_template'], '6', $this->maybe_disable_mainsite_options(), __('The template for the main site home breadcrumb, used only in multisite environments.', 'breadcrumb-navxt') . $overriden['Hmainsite_template'], 'adminkit-enset' . $overriden_style['Hmainsite_template']); $this->form->textbox( $this->settings['Hmainsite_template_no_anchor'], '4', $this->maybe_disable_mainsite_options(), __('The template for the main site home breadcrumb, used only in multisite environments and when the breadcrumb is not linked.', 'breadcrumb-navxt') . $overriden['Hmainsite_template_no_anchor'], 'adminkit-enset' . $overriden_style['Hmainsite_template_no_anchor']); do_action($this->unique_prefix . '_settings_mainsite', $this->settings); ?> </table> <?php do_action($this->unique_prefix . '_after_settings_tab_general', $this->settings); ?> </fieldset> <fieldset id="post" class="bcn_options"> <legend class="screen-reader-text" data-title="<?php _e( 'The settings for all post types (Posts, Pages, and Custom Post Types) are located under this tab.', 'breadcrumb-navxt' );?>"><?php _e( 'Post Types', 'breadcrumb-navxt' ); ?></legend> <?php //Loop through all of the post types in the array foreach($wp_post_types as $post_type) { //Check for bad post type objects, for non-public CPTs, and if the CPT wasn't known when defaults were generated if(!($post_type instanceof WP_Post_Type) || !apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name) || !isset($this->settings['Hpost_' . $post_type->name . '_template'])) { continue; } $singular_name_lc = mb_strtolower($post_type->labels->singular_name, 'UTF-8'); ?> <h2><?php echo $post_type->labels->singular_name; ?></h2> <table class="form-table adminkit-enset-top"> <?php $this->form->textbox( $this->settings['Hpost_' . $post_type->name . '_template'], '6', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $singular_name_lc) . $overriden['Hpost_' . $post_type->name . '_template'], $overriden_style['Hpost_' . $post_type->name . '_template']); $this->form->textbox( $this->settings['Hpost_' . $post_type->name . '_template_no_anchor'], '4', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $singular_name_lc) . $overriden['Hpost_' . $post_type->name . '_template_no_anchor'], $overriden_style['Hpost_' . $post_type->name . '_template_no_anchor']); if(!in_array($post_type->name, array('page', 'post'))) { $optid = form::get_valid_id('apost_' . $post_type->name . '_root'); ?> <tr valign="top"> <th scope="row"> <label for="<?php echo $optid;?>"><?php printf(esc_html__('%s Root Page', 'breadcrumb-navxt'), $post_type->labels->singular_name);?></label> </th> <td> <?php wp_dropdown_pages( array('name' => $this->unique_prefix . '_options[apost_' . $post_type->name . '_root]', 'id' => $optid, 'echo' => 1, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => $this->settings['apost_' . $post_type->name . '_root']->get_value(), 'class' => $overriden_style['apost_' . $post_type->name . '_root'])); if(isset($overriden['apost_' . $post_type->name . '_root']) && $overriden['apost_' . $post_type->name . '_root'] !== '') { printf('<p class="description">%s</p>', $overriden['apost_' . $post_type->name . '_root']); } ?> </td> </tr> <?php $this->form->input_check( $this->settings['bpost_' . $post_type->name . '_archive_display'], sprintf(__('Show the breadcrumb for the %s post type archives in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc), !$post_type->has_archive, $overriden['bpost_' . $post_type->name . '_archive_display'], $overriden_style['bpost_' . $post_type->name . '_archive_display']); } if(in_array($post_type->name, array('page'))) { $this->form->input_hidden($this->settings['bpost_' . $post_type->name . '_hierarchy_display']); $this->form->input_hidden($this->settings['bpost_' . $post_type->name . '_hierarchy_parent_first']); $this->form->input_hidden($this->settings['bpost_' . $post_type->name . '_taxonomy_referer']); } else { $this->form->input_check( $this->settings['bpost_' . $post_type->name . '_hierarchy_display'], sprintf(__('Show the hierarchy (specified below) leading to a %s in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc), false, $overriden['bpost_' . $post_type->name . '_hierarchy_display'], 'adminkit-enset-ctrl adminkit-enset' . $overriden_style['bpost_' . $post_type->name . '_hierarchy_display']); $this->form->input_check( $this->settings['bpost_' . $post_type->name . '_hierarchy_parent_first'], sprintf(__('Use the parent of the %s as the primary hierarchy, falling back to the hierarchy selected below when the parent hierarchy is exhausted.', 'breadcrumb-navxt'), $singular_name_lc), false, $overriden['bpost_' . $post_type->name . '_hierarchy_parent_first'], 'adminkit-enset' . $overriden_style['bpost_' . $post_type->name . '_hierarchy_parent_first']); $this->form->input_check( $this->settings['bpost_' . $post_type->name . '_taxonomy_referer'], __('Allow the referring page to influence the taxonomy selected for the hierarchy.', 'breadcrumb-navxt'), false, $overriden['bpost_' . $post_type->name . '_taxonomy_referer'], 'adminkit-enset' . $overriden_style['bpost_' . $post_type->name . '_taxonomy_referer']); ?> <tr valign="top"> <th scope="row"> <?php printf(__('%s Hierarchy', 'breadcrumb-navxt'), $post_type->labels->singular_name); ?> </th> <td> <?php //We use the value 'page' but really, this will follow the parent post hierarchy $this->form->input_radio($this->settings['Epost_' . $post_type->name . '_hierarchy_type'], 'BCN_POST_PARENT', __('Post Parent', 'breadcrumb-navxt'), false, 'adminkit-enset' . $overriden_style['Epost_' . $post_type->name . '_hierarchy_type']); $this->form->input_radio($this->settings['Epost_' . $post_type->name . '_hierarchy_type'], 'BCN_DATE', __('Dates', 'breadcrumb-navxt'), false, 'adminkit-enset' . $overriden_style['Epost_' . $post_type->name . '_hierarchy_type']); //Loop through all of the taxonomies in the array foreach($wp_taxonomies as $taxonomy) { //Check for non-public taxonomies if(!($taxonomy instanceof WP_Taxonomy) || !apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, $post_type->name)) { continue; } //We only want custom taxonomies if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type)) { $this->form->input_radio($this->settings['Epost_' . $post_type->name . '_hierarchy_type'], $taxonomy->name, $taxonomy->labels->singular_name, false, 'adminkit-enset' . $overriden_style['Epost_' . $post_type->name . '_hierarchy_type']); } } ?> <p class="description"> <?php if($post_type->hierarchical) { esc_html_e('The hierarchy which the breadcrumb trail will show.', 'breadcrumb-navxt'); } else { esc_html_e('The hierarchy which the breadcrumb trail will show. Note that the "Post Parent" option may require an additional plugin to behave as expected since this is a non-hierarchical post type.', 'breadcrumb-navxt'); } echo $overriden['Epost_' . $post_type->name . '_hierarchy_type']; ?> </p> </td> </tr> <?php } ?> </table> <?php } do_action($this->unique_prefix . '_after_settings_tab_post', $this->settings); ?> </fieldset> <fieldset id="tax" class="bcn_options alttab"> <legend class="screen-reader-text" data-title="<?php _e( 'The settings for all taxonomies (including Categories, Tags, and custom taxonomies) are located under this tab.', 'breadcrumb-navxt' );?>"><?php _e( 'Taxonomies', 'breadcrumb-navxt' ); ?></legend> <?php //Loop through all of the taxonomies in the array foreach($wp_taxonomies as $taxonomy) { //Check for non-public taxonomies and if the taxonomy wasn't known when defaults were generated if(!($taxonomy instanceof WP_Taxonomy) || !apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, null) || !isset($this->settings['Htax_' . $taxonomy->name . '_template'])) { continue; } $label_lc = mb_strtolower($taxonomy->label, 'UTF-8'); ?> <h2><?php echo mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'); ?></h2> <table class="form-table"> <?php $this->form->textbox( $this->settings['Htax_' . $taxonomy->name . '_template'], '6', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt') . $overriden['Htax_' . $taxonomy->name . '_template'], $label_lc), $overriden_style['Htax_' . $taxonomy->name . '_template']); $this->form->textbox( $this->settings['Htax_' . $taxonomy->name . '_template_no_anchor'], '4', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt') . $overriden['Htax_' . $taxonomy->name . '_template_no_anchor'], $label_lc), $overriden_style['Htax_' . $taxonomy->name . '_template_no_anchor']); ?> </table> <?php } do_action($this->unique_prefix . '_after_settings_tab_taxonomy', $this->settings); ?> </fieldset> <fieldset id="miscellaneous" class="bcn_options"> <legend class="screen-reader-text" data-title="<?php _e( 'The settings for author and date archives, searches, and 404 pages are located under this tab.', 'breadcrumb-navxt' );?>"><?php _e( 'Miscellaneous', 'breadcrumb-navxt' ); ?></legend> <h2><?php _e('Author Archives', 'breadcrumb-navxt'); ?></h2> <table class="form-table"> <?php $this->form->textbox( $this->settings['Hauthor_template'], '6', false, __('The template for author breadcrumbs.', 'breadcrumb-navxt') . $overriden['Hauthor_template'], $overriden_style['Hauthor_template']); $this->form->textbox( $this->settings['Hauthor_template_no_anchor'], '4', false, __('The template for author breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt') . $overriden['Hauthor_template_no_anchor'], $overriden_style['Hauthor_template_no_anchor']); $this->form->input_select( $this->settings['Eauthor_name'], $this->settings['Eauthor_name']->get_allowed_vals(), false, __('display_name uses the name specified in "Display name publicly as" under the user profile the others correspond to options in the user profile.', 'breadcrumb-navxt') . $overriden['Eauthor_name'], $overriden_style['Eauthor_name']); $optid = form::get_valid_id('aauthor_root'); ?> <tr valign="top"> <th scope="row"> <label for="<?php echo $optid;?>"><?php esc_html_e('Author Root Page', 'breadcrumb-navxt');?></label> </th> <td> <?php wp_dropdown_pages(array( 'name' => $this->unique_prefix . '_options[aauthor_root]', 'id' => $optid, 'echo' => 1, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => $this->settings['aauthor_root']->get_value(), 'class' => $overriden_style['aauthor_root'] )); if(isset($overriden['aauthor_root']) && $overriden['aauthor_root'] !== '') { printf('<p class="description">%s</p>', $overriden['aauthor_root']); } ?> </td> </tr> </table> <h2><?php _e('Miscellaneous', 'breadcrumb-navxt'); ?></h2> <table class="form-table"> <?php $this->form->textbox( $this->settings['Hdate_template'], '6', false, __('The template for date breadcrumbs.', 'breadcrumb-navxt') . $overriden['Hdate_template'], $overriden_style['Hdate_template']); $this->form->textbox( $this->settings['Hdate_template_no_anchor'], '4', false, __('The template for date breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt') . $overriden['Hdate_template_no_anchor'], $overriden_style['Hdate_template_no_anchor']); $this->form->textbox( $this->settings['Hsearch_template'], '6', false, __('The anchor template for search breadcrumbs, used only when the search results span several pages.', 'breadcrumb-navxt') . $overriden['Hsearch_template'], $overriden_style['Hsearch_template']); $this->form->textbox( $this->settings['Hsearch_template_no_anchor'], '4', false, __('The anchor template for search breadcrumbs, used only when the search results span several pages and the breadcrumb is not linked.', 'breadcrumb-navxt') . $overriden['Hsearch_template_no_anchor'], $overriden_style['Hsearch_template_no_anchor']); $this->form->input_text( $this->settings['S404_title'], 'regular-text' . $overriden_style['S404_title'], false, $overriden['S404_title']); $this->form->textbox( $this->settings['H404_template'], '4', false, __('The template for 404 breadcrumbs.', 'breadcrumb-navxt') . $overriden['H404_template'], $overriden_style['H404_template']); ?> </table> <h2><?php _e('Deprecated', 'breadcrumb-navxt'); ?></h2> <table class="form-table"> <tr valign="top"> <th scope="row"> <?php esc_html_e('Title Length', 'breadcrumb-navxt'); ?> </th> <td> <label> <input name="bcn_options[blimit_title]" type="checkbox" id="blimit_title" value="true" class="disabled" <?php checked(true, $this->settings['blimit_title']->get_value()); ?> /> <?php printf(esc_html__('Limit the length of the breadcrumb title. (Deprecated, %suse CSS instead%s)', 'breadcrumb-navxt'), '<a title="' . esc_attr__('Go to the guide on trimming breadcrumb title lengths with CSS', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/guides/trimming-breadcrumb-title-lengths-with-css/">', '</a>');?> </label><br /> <ul> <li> <label for="amax_title_length"> <?php esc_html_e('Max Title Length: ','breadcrumb-navxt');?> <input type="number" name="bcn_options[amax_title_length]" id="amax_title_length" min="1" step="1" value="<?php echo esc_html($this->settings['amax_title_length']->get_value(), ENT_COMPAT, 'UTF-8'); ?>" class="small-text disabled" /> </label> </li> </ul> </td> </tr> </table> <?php do_action($this->unique_prefix . '_after_settings_tab_miscellaneous', $this->settings); ?> </fieldset> <?php do_action($this->unique_prefix . '_after_settings_tabs', $this->settings); ?> </div> <p class="submit"><input type="submit" class="button-primary" name="bcn_admin_options" value="<?php esc_attr_e('Save Changes') ?>" /></p> </form> </div> <?php } } includes/block_direct_access.php 0000644 00000002034 14720660717 0013041 0 ustar 00 <?php /* Copyright 2015-2020 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //If this file is included directly (e.g. WordPress isn't running), return 404 if(!defined('ABSPATH')) { //First catches the Apache users header("HTTP/1.0 404 Not Found"); //This should catch FastCGI users header("Status: 404 Not Found"); die(); } includes/multibyte_supplicant.php 0000644 00000006343 14720660717 0013363 0 ustar 00 <?php /* A small library that adds in fallbacks for some of the PHP multibyte string functions. Mainly inteneded to be used with Breadcrumb NavXT Copyright 2009-2020 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/block_direct_access.php'); if(!function_exists('mb_strlen')) { /** * Fallback for mb_strlen for users without multibyte support * * @param string $string the string to determine the lenght of * @return int the number of characters in the string */ function mb_strlen($string) { return strlen($string); } } if(!function_exists('mb_strpos')) { /** * Fallback for mb_strpos for users without multibyte support * * @param string $haystack the string to search within * @param string $needle the string to search for * @return mixed position of the first instances of needle, or false if needle not found */ function mb_strpos($haystack, $needle, $offset = 0) { return strpos($haystack, $needle, $offset); } } if(!function_exists('mb_substr')) { /** * Fallback for mb_substr for users without multibyte support * * @param string $string the input string * @param int $start the start * @param int length the length of the substring * @return string the substring of specified length */ function mb_substr($string, $start, $length = 'a') { //This happens to be the easiest way to preserve the behavior of substr if($length = 'a') { return substr($string, $start); } else { return substr($string, $start, $length); } } } if(!function_exists('mb_strtolower')) { /** * Fallback for mb_strtolower for users without multibyte support * * @param string $str the string to change to lowercase * @param string $encoding the encoding of the string * @return string the lowercase string */ function mb_strtolower($str, $encoding = 'UTF-8') { return strtolower($str); } } //We need this constant to be defined, otherwise things will break if(!defined('MB_CASE_TITLE')) { define('MB_CASE_TITLE', '1'); } if(!function_exists('mb_convert_case')) { /** * A very hacky fallback for mb_convert_case for users without multibyte support * * @param string $str the string to change the case on * @param int $mode the mode of case convert to use * @param string $encoding the encoding of the string * @return string the case converted string */ function mb_convert_case($str, $mode = MB_CASE_TITLE, $encoding = 'UTF-8') { //Only implementing MB_CASE_TITLE if($mode = MB_CASE_TITLE) { return ucwords($str); } return $str; } } includes/blocks/build/breadcrumb-trail/index.js 0000644 00000005411 14720660717 0015625 0 ustar 00 (()=>{"use strict";var e={n:r=>{var a=r&&r.__esModule?()=>r.default:()=>r;return e.d(a,{a}),a},d:(r,a)=>{for(var t in a)e.o(a,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:a[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};const r=window.wp.blocks,a=window.React,t=(window.wp.data,window.wp.i18n),n=window.wp.components,l=window.wp.serverSideRender;var o=e.n(l);const c=window.wp.blockEditor,b=JSON.parse('{"u2":"bcn/breadcrumb-trail"}'),d=(0,a.createElement)("svg",{viewbox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",focusable:"false"},(0,a.createElement)("path",{d:"M0.6 7.2C0.4 7.2 0.4 7.2 0.4 7.4V16.9C0.4 17.1 0.4 17.1 0.6 17.1H10.9C11.1 17.1 11.1 17.1 11.3 16.9L16 12.1 11.3 7.4C11.1 7.2 11.1 7.2 10.9 7.2ZM15 7.2 19.9 12.1 15 17.1H18.7C18.9 17.1 18.9 17.1 19.1 16.9L23.8 12.1 19.1 7.4C18.9 7.2 18.9 7.2 18.7 7.2Z"}));(0,r.registerBlockType)(b.u2,{icon:d,edit:function({attributes:e,setAttributes:r}){const l=e=>a=>r({[e]:a});return(0,a.createElement)("div",{...(0,c.useBlockProps)()},(0,a.createElement)(c.InspectorControls,null,(0,a.createElement)(n.PanelBody,{title:(0,t.__)("Breadcrumb Trail Settings","breadcrumb-navxt")},(0,a.createElement)("p",{className:"description"},(0,t.__)("Adjust the breadcrumb trail.","breadcrumb-navxt")),(0,a.createElement)(n.TextControl,{label:(0,t.__)("Tesxt to show before the trail","breadcrumb-navxt"),value:e.pretext,onChange:l("pretext")}),(0,a.createElement)(n.SelectControl,{label:(0,t.__)("Output trail format","breadcrumb-navxt"),value:e.format,options:[{value:"list",label:(0,t.__)("Ordered list elements","breadcrumb-navxt")},{value:"breadcrumblist_rdfa",label:(0,t.__)("Schema.org BreadcrumbList (RDFa)","breadcrumb-navxt")},{value:"breadcrumblist_rdfa_wai_aria",label:(0,t.__)("Schema.org BreadcrumbList (RDFa) with WAI-ARIA","breadcrumb-navxt")},{value:"breadcrumblist_microdata",label:(0,t.__)("Schema.org BreadcrumbList (microdata)","breadcrumb-navxt")},{value:"plain",label:(0,t.__)("Plane (no Schema.org BreadcrumbList)","breadcrumb-navxt")}],onChange:l("format")}),(0,a.createElement)(n.ToggleControl,{label:(0,t.__)("Link the breadcrumbs","breadcrumb-navxt"),checked:!!e.link,onChange:l("link")}),(0,a.createElement)(n.ToggleControl,{label:(0,t.__)("Reverse the order of the trail","breadcrumb-navxt"),checked:!!e.reverseOrder,onChange:l("reverseOrder")}),(0,a.createElement)(n.ToggleControl,{label:(0,t.__)("Hide the breadcrumb trail on the front page","breadcrumb-navxt"),checked:!!e.hideonHome,onChange:l("hideonHome")}),(0,a.createElement)(n.ToggleControl,{label:(0,t.__)("Ignore the breadcrumb cache","breadcrumb-navxt"),checked:!!e.ignoreCache,onChange:l("ignoreCache")}))),(0,a.createElement)(n.Disabled,null,(0,a.createElement)(o(),{block:"bcn/breadcrumb-trail",attributes:{...e},urlQueryArgs:""})))}})})(); includes/blocks/build/breadcrumb-trail/index.asset.php 0000644 00000000273 14720660717 0017117 0 ustar 00 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '093b1bc0838bc818fe10'); includes/blocks/build/breadcrumb-trail/block.json 0000644 00000003600 14720660717 0016143 0 ustar 00 { "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "bcn/breadcrumb-trail", "title": "Breadcrumb Trail", "category": "theme", "description": "Displays a breadcrumb trail", "keywords": [ "breadcrumbs", "navigation", "breadcrumb trail" ], "version": "2.0.0", "textdomain": "breadcrumb-navxt", "attributes": { "pretext": { "type": "string", "default": "" }, "format": { "type": "string", "enum": [ "list", "breadcrumblist_rdfa", "breadcrumblist_rdfa_wai_aria", "breadcrumblist_microdata", "plain" ], "default": "breadcrumblist_rdfa" }, "link": { "type": "boolean", "default": true }, "reverseOrder": { "type": "boolean", "default": false }, "hideonHome": { "type": "boolean", "default": false }, "ignoreCache": { "type": "boolean", "default": true }, "className": { "type": "string", "default": "" }, "textColor": { "type": "string", "default": "" }, "backgroundColor": { "type": "string", "default": "" }, "align": { "type": "string", "default": "" }, "typography": { "type": "string", "default": "" }, "fontSize": { "type": "string", "default": "" }, "style": { "type": "object", "default": {} } }, "usesContext": [ "groupId" ], "selectors": { "root": ".wp-block-breadcrumb-trail" }, "supports": { "align": true, "color": { "text": true, "link": true, "background": true }, "typography": { "fontSize": true }, "html": false }, "example": { "attributes": { "pretext": "You are here:" } }, "editorScript": "file:./index.js", "render": "file:./render.php" } includes/blocks/build/breadcrumb-trail/render.php 0000644 00000005563 14720660717 0016160 0 ustar 00 <?php /** * All of the parameters passed to the function where this file is being required are accessible in this scope: * * @param array $attributes The array of attributes for this block. * @param string $content Rendered block output. ie. <InnerBlocks.Content />. * @param WP_Block $block The instance of the WP_Block class that represents the block being rendered. * * @package breadcrumb-navxt */ if($attributes['hideonHome'] === true && is_front_page() && (!is_paged() && $GLOBALS['breadcrumb_navxt']->show_paged())) { return; } //Handle previews if(isset($_REQUEST['post_id'])) { $post_id = $_REQUEST['post_id']; $preview_post = get_post($post_id); if($attributes['format'] === 'list') { $template = "<li%3\$s>%1\$s</li>\n"; $outer_template = "<ul>%1\$s</ul>\n"; } else { $template = '%1$s%2$s'; $outer_template = '%1$s'; } $trail_string = $GLOBALS['breadcrumb_navxt']->_display_post($preview_post, true, $attributes['link'], $attributes['reverseOrder'], $attributes['ignoreCache'], $template, $outer_template); } else if($attributes['format'] === 'list') { $trail_string = bcn_display_list(true, $attributes['link'], $attributes['reverseOrder'], $attributes['ignoreCache']); } else { $trail_string = bcn_display(true, $attributes['link'], $attributes['reverseOrder'], $attributes['ignoreCache']); } if($attributes['format'] === 'list') { ?> <span><?php echo wp_kses_post($attributes['pretext']);?></span> <ol <?php echo wp_kses_data( get_block_wrapper_attributes( array('class' => 'breadcrumbs') ) );?>> <?php echo $trail_string; ?> </ol> <?php } else if($attributes['format'] === 'breadcrumblist_rdfa_wai_aria') { ?> <nav <?php echo wp_kses_data( get_block_wrapper_attributes( array( 'class' => 'breadcrumbs', 'aria-label' => 'Breadcrumb', 'vocab' => 'https://schema.org/', 'typeof' => 'BreadcrumbList' ) ) );?>> <span><?php echo wp_kses_post($attributes['pretext']);?></span> <?php echo $trail_string;?> </nav> <?php } else { if($attributes['format'] === 'breadcrumblist_rdfa') { ?> <div <?php echo wp_kses_data( get_block_wrapper_attributes( array( 'class' => 'breadcrumbs', 'vocab' => 'https://schema.org/', 'typeof' => 'BreadcrumbList' ) ) );?>> <span><?php echo wp_kses_post($attributes['pretext']);?></span> <?php echo $trail_string;?> </div> <?php } else if($attributes['format'] === 'breadcrumblist_microdata') { ?> <div itemscope <?php echo wp_kses_data( get_block_wrapper_attributes( array( 'class' => 'breadcrumbs', 'itemtype' => 'https://schema.org/BreadcrumbList' ) ) );?>> <span><?php echo wp_kses_post($attributes['pretext']);?></span> <?php echo $trail_string; ?> </div> <?php } else { ?> <div <?php echo wp_kses_data( get_block_wrapper_attributes( array( 'class' => 'breadcrumbs' ) ) );?>> <span><?php echo wp_kses_post($attributes['pretext']);?></span> <?php echo $trail_string; ?> </div> <?php } } includes/adminKit/class-mtekk_adminkit.php 0000644 00000147737 14720660717 0014756 0 ustar 00 <?php /* Copyright 2015-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit; use mtekk\adminKit\setting\setting; require_once( __DIR__ . '/../block_direct_access.php'); //Include message class if(!class_exists('message')) { require_once(__DIR__ . '/class-mtekk_adminkit_message.php'); } if(version_compare(phpversion(), '8.0.0', '<')) { //Include setting class if(!class_exists('setting\setting_bool')) { require_once(__DIR__ . '/setting/php7/class-mtekk_adminkit_setting_bool.php'); } //Include setting class if(!class_exists('setting\setting_float')) { require_once(__DIR__ . '/setting/php7/class-mtekk_adminkit_setting_float.php'); } //Include setting class if(!class_exists('setting\setting_int')) { require_once(__DIR__ . '/setting/php7/class-mtekk_adminkit_setting_int.php'); } } else { //Include setting class if(!class_exists('setting\setting_bool')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_bool.php'); } //Include setting class if(!class_exists('setting\setting_float')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_float.php'); } //Include setting class if(!class_exists('setting\setting_int')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_int.php'); } } //Include setting class if(!class_exists('setting\setting_absint')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_absint.php'); } //Include setting class if(!class_exists('setting\setting_enum')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_enum.php'); } //Include setting class if(!class_exists('settingsetting_\html')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_html.php'); } //Include setting class if(!class_exists('setting\setting_string')) { require_once(__DIR__ . '/setting/class-mtekk_adminkit_setting_string.php'); } //Include from class if(!class_exists('form')) { require_once(__DIR__ . '/class-mtekk_adminkit_form.php'); } abstract class adminKit { const version = '3.1.1'; protected $full_name; protected $short_name; protected $plugin_basename; protected $access_level = 'manage_options'; protected $identifier; protected $unique_prefix; protected $opt = array(); protected $messages; protected $message; protected $support_url; protected $allowed_html; protected $settings = array(); protected $form; function __construct() { $this->message = array(); $this->messages = array(); //Admin Init Hook add_action('admin_init', array($this, 'init')); //WordPress Admin interface hook add_action('admin_menu', array($this, 'add_page')); //Installation Script hook add_action('activate_' . $this->plugin_basename, array($this, 'install')); //Initilizes l10n domain $this->local(); add_action('wp_loaded', array($this, 'wp_loaded')); $this->form = new form($this->unique_prefix); //Register Help Output //add_action('add_screen_help_and_options', array($this, 'help')); } function wp_loaded() { //Filter our allowed html tags $this->allowed_html = apply_filters($this->unique_prefix . '_allowed_html', wp_kses_allowed_html('post')); } /** * Returns the internal mtekk_admin_class version */ function get_admin_class_version() { return adminKit::version; } /** * Checks if the administrator has the access capability, and adds it if they don't */ function add_cap() { $role = get_role('administrator'); if($role instanceof \WP_Role && !$role->has_cap($this->access_level)) { $role->add_cap($this->access_level); } } /** * Return the URL of the settings page for the plugin */ function admin_url() { return admin_url('options-general.php?page=' . $this->identifier); } /** * A wrapper for nonced_anchor returns a nonced anchor for admin pages * * @param string $mode The nonce "mode", a unique string at the end of the standardized nonce identifier * @param string $title (optional) The text to use in the title portion of the anchor * @param string $text (optional) The text that will be surrounded by the anchor tags * @return string the assembled anchor */ function admin_anchor($mode, $title = '', $text = '') { return $this->nonced_anchor($this->admin_url(), 'admin_' . $mode, 'true', $title, $text); } /** * Returns a properly formed nonced anchor to the specified URI * * @param string $uri The URI that the anchor should be for * @param string $mode The nonce "mode", a unique string at the end of the standardized nonce identifier * @param mixed $value (optional) The value to place in the query string * @param string $title (optional) The text to use in the title portion of the anchor * @param string $text (optional) The text that will be surrounded by the anchor tags * @param string $anchor_extras (optional) This text is placed within the opening anchor tag, good for adding id, classe, rel field * @return string the assembled anchor */ function nonced_anchor($uri, $mode, $value = 'true', $title = '', $text = '', $anchor_extras = '') { //Assemble our url, nonce and all $url = wp_nonce_url(add_query_arg($this->unique_prefix . '_' . $mode, $value, $uri), $this->unique_prefix . '_' . $mode); //Return a valid anchor return ' <a title="' . esc_attr($title) . '" href="' . $url . '" '. $anchor_extras . '>' . esc_html($text) . '</a>'; } /** * Abstracts the check_admin_referer so that all the end user has to supply is the mode * * @param string $mode The specific nonce "mode" (see nonced_anchor) that is being checked */ function check_nonce($mode) { check_admin_referer($this->unique_prefix . '_' . $mode); } /** * Makes sure the current user can manage options to proceed */ function security() { //If the user can not manage options we will die on them if(!current_user_can($this->access_level)) { wp_die(__('Insufficient privileges to proceed.', $this->identifier)); } } function init() { $this->add_cap(); //Admin Options reset hook if(isset($_POST[$this->unique_prefix . '_admin_reset'])) { //Run the reset function on init if reset form has been submitted $this->opts_reset(); } //Admin Settings export hook else if(isset($_POST[$this->unique_prefix . '_admin_settings_export'])) { //Run the export function on init if export form has been submitted $this->settings_export(); } //Admin Settings import hook else if(isset($_POST[$this->unique_prefix . '_admin_settings_import']) && isset($_FILES[$this->unique_prefix . '_admin_import_file']) && !empty($_FILES[$this->unique_prefix . '_admin_import_file']['name'])) { //Run the import function on init if import form has been submitted $this->settings_import(); } //Admin Options rollback hook else if(isset($_GET[$this->unique_prefix . '_admin_undo'])) { //Run the rollback function on init if undo button has been pressed $this->opts_undo(); } //Admin Options upgrade hook else if(isset($_GET[$this->unique_prefix . '_admin_upgrade'])) { //Run the upgrade function on init if upgrade button has been pressed $this->opts_upgrade_wrapper(); } //Admin Options fix hook else if(isset($_GET[$this->unique_prefix . '_admin_fix'])) { //Run the options fix function on init if fix button has been pressed $this->opts_upgrade_wrapper(); } //Admin Options update hook else if(isset($_POST[$this->unique_prefix . '_admin_options'])) { //Temporarily add update function on init if form has been submitted $this->opts_update(); } //Add in the nice "settings" link to the plugins page add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) { $suffix = ''; } else { $suffix = '.min'; } //Register JS for more permanently dismissing messages wp_register_script('mtekk_adminkit_messages', plugins_url('/mtekk_adminkit_messages' . $suffix . '.js', dirname(__FILE__) . '/assets/mtekk_adminkit_messages' . $suffix . '.js'), array('jquery'), self::version, true); //Register JS for enable/disable settings groups wp_register_script('mtekk_adminkit_engroups', plugins_url('/mtekk_adminkit_engroups' . $suffix . '.js', dirname(__FILE__) . '/assets/mtekk_adminkit_engroups' . $suffix . '.js'), array('jquery'), self::version, true); //Register JS for tabs wp_register_script('mtekk_adminkit_tabs', plugins_url('/mtekk_adminkit_tabs' . $suffix . '.js', dirname(__FILE__) . '/assets/mtekk_adminkit_tabs' . $suffix . '.js'), array('jquery-ui-tabs'), self::version, true); //Register CSS for tabs wp_register_style('mtekk_adminkit_tabs', plugins_url('/mtekk_adminkit_tabs' . $suffix . '.css', dirname(__FILE__) . '/assets/mtekk_adminkit_tabs' . $suffix . '.css')); //Register options register_setting($this->unique_prefix . '_options', $this->unique_prefix . '_options', ''); //Synchronize up our settings with the database as we're done modifying them now $this->opt = $this::parse_args($this->get_option($this->unique_prefix . '_options'), $this->opt); add_action('wp_ajax_mtekk_admin_message_dismiss', array($this, 'dismiss_message')); } /** * Adds the adminpage the menu and the nice little settings link * TODO: make this more generic for easier extension */ function add_page() { //Add the submenu page to "settings" menu $hookname = add_submenu_page('options-general.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page')); // check capability of user to manage options (access control) if(current_user_can($this->access_level)) { //Register admin_head-$hookname callback add_action('admin_head-' . $hookname, array($this, 'admin_head')); //Register admin_print_styles-$hookname callback add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles')); //Register admin_print_scripts-$hookname callback add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts')); //Register Help Output add_action('load-' . $hookname, array($this, 'help')); } } /** * Initilizes localization textdomain for translations (if applicable) * * Will conditionally load the textdomain for translations. This is here for * plugins that span multiple files and have localization in more than one file * * @return void */ function local() { global $l10n; // the global and the check might become obsolete in // further wordpress versions // @see https://core.trac.wordpress.org/ticket/10527 if(!isset($l10n[$this->identifier])) { load_plugin_textdomain($this->identifier, false, $this->identifier . '/languages'); } } /** * Places in a link to the settings page in the plugins listing entry * * @param array $links An array of links that are output in the listing * @param string $file The file that is currently in processing * @return array Array of links that are output in the listing. */ function filter_plugin_actions($links, $file) { //Make sure we are adding only for the current plugin if($file == $this->plugin_basename) { //Add our link to the end of the array to better integrate into the WP 2.8 plugins page $links[] = '<a href="' . $this->admin_url() . '">' . esc_html__('Settings') . '</a>'; } return $links; } /** * Checks to see if the plugin has been fully installed * * @return bool whether or not the plugin has been installed */ function is_installed() { $opts = $this->get_option($this->unique_prefix . '_options'); return is_array($opts); } /** * This sets up and upgrades the database settings, runs on every activation * * FIXME: seems there is a lot of very similar code in opts_upgrade_wrapper */ function install() { //Call our little security function $this->security(); //Try retrieving the options from the database $opts = $this->get_option($this->unique_prefix . '_options'); //If there are no settings, copy over the default settings if(!is_array($opts)) { //Add the options, we only store differences from defaults now, so start with blank array $this->add_option($this->unique_prefix . '_options', array()); $this->add_option($this->unique_prefix . '_options_bk', array(), '', false); //Add the version, no need to autoload the db version $this->update_option($this->unique_prefix . '_version', $this::version, false); } else { //Retrieve the database version $db_version = $this->get_option($this->unique_prefix . '_version'); if($this::version !== $db_version) { //Run the settings update script $this->opts_upgrade($opts, $db_version); //Always have to update the version $this->update_option($this->unique_prefix . '_version', $this::version, false); //Store the options $this->update_option($this->unique_prefix . '_options', $this->opt, true); } } } /** * This removes database settings upon deletion of the plugin from WordPress */ function uninstall() { //Remove the option array setting $this->delete_option($this->unique_prefix . '_options'); //Remove the option backup array setting $this->delete_option($this->unique_prefix . '_options_bk'); //Remove the version setting $this->delete_option($this->unique_prefix . '_version'); } /** * Compares the supplided version with the internal version, places an upgrade warning if there is a missmatch * TODO: change this to being auto called in admin_init action */ function version_check($version) { //If we didn't get a version, setup if($version === false) { //Add the version, no need to autoload the db version $this->add_option($this->unique_prefix . '_version', $this::version, '', 'no'); } //Do a quick version check if($version && version_compare($version, $this::version, '<') && is_array($this->opt)) { //Throw an error since the DB version is out of date $this->messages[] = new message(esc_html__('Your settings are for an older version of this plugin and need to be migrated.', $this->identifier) . $this->admin_anchor('upgrade', __('Migrate the settings now.', $this->identifier), __('Migrate now.', $this->identifier)), 'warning'); //Output any messages that there may be $this->messages(); return false; } //Do a quick version check else if($version && version_compare($version, $this::version, '>') && is_array($this->opt)) { //Let the user know that their settings are for a newer version $this->messages[] = new message(esc_html__('Your settings are for a newer version of this plugin.', $this->identifier) . $this->admin_anchor('upgrade', __('Migrate the settings now.', $this->identifier), __('Attempt back migration now.', $this->identifier)), 'warning'); //Output any messages that there may be $this->messages(); return true; } else if(!is_array($this->settings)) { //Throw an error since it appears the options were never registered $this->messages[] = new message(esc_html__('Your plugin install is incomplete.', $this->identifier) . $this->admin_anchor('upgrade', __('Load default settings now.', $this->identifier), __('Complete now.', $this->identifier)), 'error'); //Output any messages that there may be $this->messages(); return false; } else if(!$this->settings_validate($this->settings)) { //Throw an error since it appears the options contain invalid data $this->messages[] = new message(esc_html__('One or more of your plugin settings are invalid.', $this->identifier) . $this->admin_anchor('fix', __('Attempt to fix settings now.', $this->identifier), __('Fix now.', $this->identifier)), 'error'); //Output any messages that there may be $this->messages(); return false; } return true; } /** * Run through all of the settings, check if the value matches the validated value * * @param array $settings The settings array * @return boolean */ function settings_validate(array &$settings) { foreach($settings as $setting) { if(is_array($setting)) { if(!$this->settings_validate($setting)) { return false; } } else if($setting instanceof setting && $setting->get_value() !== $setting->validate($setting->get_value())) { return false; } } return true; } /** * Synchronizes the backup options entry with the current options entry */ function opts_backup() { //Set the backup options in the DB to the current options $this->update_option($this->unique_prefix . '_options_bk', $this->get_option($this->unique_prefix . '_options'), false); } /** * The new, simpler settings update loop, handles the new settings array and replaces the old opts_update_loop * * @param array $settings * @param array $input * @param bool $bool_ignore_missing */ protected function settings_update_loop(&$settings, $input, $bool_ignore_missing = false) { foreach($settings as $key => $setting) { if(is_array($setting)) { if(isset($input[$key])) { $this->settings_update_loop($settings[$key], $input[$key]); } } else if($setting instanceof setting) { $setting->maybe_update_from_form_input($input, $bool_ignore_missing); } } } /** * A better version of parse_args, will recrusivly follow arrays * * @param mixed $args The arguments to be parsed * @param mixed $defaults (optional) The default values to validate against * @return mixed */ static function parse_args($args, $defaults = '') { if(is_object($args)) { $r = get_object_vars($args); } else if(is_array($args)) { $r =& $args; } else { wp_parse_str($args, $r); } if(is_array($defaults)) { return adminKit::array_merge_recursive($defaults, $r); } return $r; } /** * An alternate version of array_merge_recursive, less flexible * still recursive, ~2x faster than the more flexible version * * @param array $arg1 first array * @param array $arg2 second array to merge into $arg1 * @return array */ static function array_merge_recursive($arg1, $arg2) { foreach($arg2 as $key => $value) { if(array_key_exists($key, $arg1) && is_array($value)) { $arg1[$key] = adminKit::array_merge_recursive($arg1[$key], $value); } else { $arg1[$key] = $value; } } return $arg1; } /** * Extracts settings values to form opts array, for old options compatibility * * @param array $settings The settings array * @return array */ static function settings_to_opts($settings) { $opts = array(); foreach ($settings as $key => $setting) { if(is_array($setting)) { $opts[$key] = adminKit::settings_to_opts($setting); } else if($setting instanceof setting) { $opts[$key] = $setting->get_value(); } } return $opts; } /** * Loop through the settings and applying opts values if found * * @param array $opts The opts array */ function load_opts_into_settings($opts) { foreach($opts as $key => $value) { if(isset($this->settings[$key]) && $this->settings[$key] instanceof setting) { $this->settings[$key]->set_value($this->settings[$key]->validate($value)); } else if(isset($this->settings[$key]) && is_array($this->settings[$key]) && is_array($value)) { foreach($value as $subkey => $subvalue) { if(isset($this->settings[$key][$subkey]) && $this->settings[$key][$subkey]instanceof setting) { $this->settings[$key][$subkey]->set_value($this->settings[$key][$subkey]->validate($subvalue)); } } } } } /** * Compares two settings by name and value to see if they are equal * * @param \mtekk\adminKit\setting\setting $a * @param \mtekk\adminKit\setting\setting $b * @return number */ function setting_equal_check($a, $b) { if(is_array($a) || is_array($b)) { foreach($a as $key=>$value) { if($value instanceof setting && isset($b[$key]) && $b[$key] instanceof setting) { return $this->setting_equal_check($value, $b[$key]); } else { return -1; } } return -1; } if($a instanceof setting && $b instanceof setting) { if($a->get_name() === $b->get_name() && $a->get_value() === $b->get_value()) { return 0; } else if($a->get_name() === $b->get_name() && $a->get_value() > $b->get_value()) { return 1; } } return -1; } static function setting_cloner($setting) { if(is_array($setting)) { return array_map('mtekk\adminKit\adminKit::setting_cloner', $setting); } if($setting instanceof setting) { return clone $setting; } } /** * Generates array of the new non-default settings based off of form input * * @param array $input The form input array of setting values * @param bool $bool_ignore_missing Tell maybe_update_from_form_input to not treat missing bool setting entries as setting to false * @return array The diff array of adminkit settings */ private function get_settings_diff($input, $bool_ignore_missing = false) { //Backup default settings //Must clone the defaults since PHP normally shallow copies $default_settings = array_map('mtekk\adminKit\adminKit::setting_cloner', $this->settings); //Run the update loop $this->settings_update_loop($this->settings, $input, $bool_ignore_missing); //Calculate diff $new_settings = apply_filters($this->unique_prefix . '_opts_update_to_save', array_udiff_assoc($this->settings, $default_settings, array($this, 'setting_equal_check'))); //Return the new settings return $new_settings; } /** * Updates the database settings from the webform * * The general flow of data is: * 1) Establish default values * 2) Merge in updates from webform * 3) Compute difference between defaults and results of #3 * 4) Save to database the difference generated in #4 */ function opts_update() { //Do some security related thigns as we are not using the normal WP settings API $this->security(); //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_options-options'); //Update local options from database $this->opt = adminKit::parse_args($this->get_option($this->unique_prefix . '_options'), $this->opt); $this->opt = apply_filters($this->unique_prefix . '_opts_update_prebk', $this->opt); //Update our backup options $this->update_option($this->unique_prefix . '_options_bk', $this->opt, false); $opt_prev = $this->opt; //Grab our incomming array (the data is dirty) $input = $_POST[$this->unique_prefix . '_options']; //Run through the loop and get the diff from detauls $new_settings = $this->get_settings_diff($input); //FIXME: Eventually we'll save the object array, but not today //Convert to opts array for saving $this->opt = adminKit::settings_to_opts($new_settings); //Commit the option changes $updated = $this->update_option($this->unique_prefix . '_options', $this->opt, true); //Check if known settings match attempted save if($updated && count(array_diff_key($input, $this->settings)) == 0) { //Let the user know everything went ok $this->messages[] = new message(esc_html__('Settings successfully saved.', $this->identifier) . $this->admin_anchor('undo', __('Undo the options save.', $this->identifier), __('Undo', $this->identifier)), 'success'); } else if(!$updated && count(array_diff_key($opt_prev, $this->settings)) == 0) { $this->messages[] = new message(esc_html__('Settings did not change, nothing to save.', $this->identifier), 'info'); } else if(!$updated) { $this->messages[] = new message(esc_html__('Settings were not saved.', $this->identifier), 'error'); } else { //Let the user know the following were not saved $this->messages[] = new message(esc_html__('Some settings were not saved.', $this->identifier) . $this->admin_anchor('undo', __('Undo the options save.', $this->identifier), __('Undo', $this->identifier)), 'warning'); $temp = esc_html__('The following settings were not saved:', $this->identifier); foreach(array_diff_key($input, $this->settings) as $setting => $value) { $temp .= '<br />' . $setting; } $this->messages[] = new message($temp . '<br />' . sprintf(esc_html__('Please include this message in your %sbug report%s.', $this->identifier), '<a title="' . sprintf(esc_attr__('Go to the %s support forum.', $this->identifier), $this->short_name) . '" href="' . $this->support_url . '">', '</a>'), 'info'); } add_action('admin_notices', array($this, 'messages')); } /** * Retrieves the settings from database and exports as JSON */ function settings_export() { //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_import_export'); //Must clone the defaults since PHP normally shallow copies $default_settings = array_map('mtekk\adminKit\adminKit::setting_cloner', $this->settings); //Get the database options, and load //FIXME: This changes once we save settings to the db instead of opts $this->load_opts_into_settings($this->get_option($this->unique_prefix . '_options')); //Get the unique settings $export_settings = apply_filters($this->unique_prefix . '_settings_to_export', array_udiff_assoc($this->settings, $default_settings, array($this, 'setting_equal_check'))); //Change our headder to application/json for direct save header('Cache-Control: public'); //The next two will cause good browsers to download instead of displaying the file header('Content-Description: File Transfer'); header('Content-disposition: attachemnt; filename=' . $this->unique_prefix . '_settings.json'); header('Content-Type: application/json'); //JSON encode our settings array $output = json_encode( (object)array( 'plugin' => $this->short_name, 'version' => $this::version, 'settings' => $export_settings) , JSON_UNESCAPED_SLASHES, 32); //Let the browser know how long the file is header('Content-Length: ' . strlen($output)); // binary length //Output the file echo $output; //Prevent WordPress from continuing on die(); } /** * Imports JSON settings into database */ function settings_import() { //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_import_export'); //Set the backup options in the DB to the current options $this->opts_backup(); //Load the user uploaded file, handle failure gracefully if(is_uploaded_file($_FILES[$this->unique_prefix . '_admin_import_file']['tmp_name'])) { //Grab the json settings from the temp file, treat as associative array so we can just throw the settings subfield at the update loop $settings_upload = json_decode(file_get_contents($_FILES[$this->unique_prefix . '_admin_import_file']['tmp_name']), true); //Only continue if we have a JSON object that is for this plugin (the the WP rest_is_object() function is handy here as the REST API passes JSON) if(rest_is_object($settings_upload) && isset($settings_upload['plugin']) && $settings_upload['plugin'] === $this->short_name) { //Act as if the JSON file was just a bunch of POST entries for a settings save //Run through the loop and get the diff from detauls $new_settings = $this->get_settings_diff($settings_upload['settings'], true); //FIXME: Eventually we'll save the object array, but not today //Convert to opts array for saving $this->opt = adminKit::settings_to_opts($new_settings); //Run opts through update script //Make sure we safely import and upgrade settings if needed $this->opts_upgrade($this->opt, $settings_upload['version']); //Commit the option changes $updated = $this->update_option($this->unique_prefix . '_options', $this->opt, true); //Check if known settings match attempted save if($updated && count(array_diff_key($settings_upload['settings'], $this->settings)) == 0) { //Let the user know everything went ok $this->messages[] = new message(esc_html__('Settings successfully imported from the uploaded file.', $this->identifier) . $this->admin_anchor('undo', __('Undo the options import.', $this->identifier), __('Undo', $this->identifier)), 'success'); } else { $this->messages[] = new message(esc_html__('No settings were imported. Settings from uploaded file matched existing settings.', $this->identifier), 'info'); } //Output any messages that there may be add_action('admin_notices', array($this, 'messages')); //And return as we're successful return; } //If it wasn't JSON, try XML else { return $this->opts_import(); } } //Throw an error since we could not load the file for various reasons $this->messages[] = new message(esc_html__('Importing settings from file failed.', $this->identifier), 'error'); } /** * Exports a XML options document */ function opts_export() { //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_import_export'); //Update our internal settings $this->opt = $this->get_option($this->unique_prefix . '_options'); //Create a DOM document $dom = new \DOMDocument('1.0', 'UTF-8'); //Adds in newlines and tabs to the output $dom->formatOutput = true; //We're not using a DTD therefore we need to specify it as a standalone document $dom->xmlStandalone = true; //Add an element called options $node = $dom->createElement('options'); $parnode = $dom->appendChild($node); //Add a child element named plugin $node = $dom->createElement('plugin'); $plugnode = $parnode->appendChild($node); //Add some attributes that identify the plugin and version for the options export $plugnode->setAttribute('name', $this->short_name); $plugnode->setAttribute('version', $this::version); //Change our headder to text/xml for direct save header('Cache-Control: public'); //The next two will cause good browsers to download instead of displaying the file header('Content-Description: File Transfer'); header('Content-disposition: attachemnt; filename=' . $this->unique_prefix . '_settings.xml'); header('Content-Type: text/xml'); //Loop through the options array foreach($this->opt as $key=>$option) { if(is_array($option)) { continue; } //Add a option tag under the options tag, store the option value $node = $dom->createElement('option', htmlentities($option, ENT_COMPAT | ENT_XML1, 'UTF-8')); $newnode = $plugnode->appendChild($node); //Change the tag's name to that of the stored option $newnode->setAttribute('name', $key); } //Prepair the XML for output $output = $dom->saveXML(); //Let the browser know how long the file is header('Content-Length: ' . strlen($output)); // binary length //Output the file echo $output; //Prevent WordPress from continuing on die(); } /** * Imports a XML options document */ function opts_import() { //Our quick and dirty error supressor $error_handler = function($errno, $errstr, $eerfile, $errline, $errcontext) { return true; }; //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_import_export'); //Set the backup options in the DB to the current options $this->opts_backup(); //Create a DOM document $dom = new \DOMDocument('1.0', 'UTF-8'); //We want to catch errors ourselves set_error_handler($error_handler); //Load the user uploaded file, handle failure gracefully if(is_uploaded_file($_FILES[$this->unique_prefix . '_admin_import_file']['tmp_name']) && $dom->load($_FILES[$this->unique_prefix . '_admin_import_file']['tmp_name'])) { $opts_temp = array(); $version = ''; //Have to use an xpath query otherwise we run into problems $xpath = new \DOMXPath($dom); $option_sets = $xpath->query('plugin'); //Loop through all of the xpath query results foreach($option_sets as $options) { //We only want to import options for only this plugin if($options->getAttribute('name') === $this->short_name) { //Grab the file version $version = $options->getAttribute('version'); //Loop around all of the options foreach($options->getelementsByTagName('option') as $child) { //Place the option into the option array, DOMDocument decodes html entities for us $opts_temp[$child->getAttribute('name')] = $child->nodeValue; } } } //Make sure we safely import and upgrade settings if needed $this->opts_upgrade($opts_temp, $version); //Commit the loaded options to the database $this->update_option($this->unique_prefix . '_options', $this->opt, true); //Everything was successful, let the user know $this->messages[] = new message(esc_html__('Settings successfully imported from the uploaded file.', $this->identifier) . $this->admin_anchor('undo', __('Undo the options import.', $this->identifier), __('Undo', $this->identifier)), 'success'); } else { //Throw an error since we could not load the file for various reasons $this->messages[] = new message(esc_html__('Importing settings from file failed.', $this->identifier), 'error'); } //Reset to the default error handler after we're done restore_error_handler(); //Output any messages that there may be add_action('admin_notices', array($this, 'messages')); } /** * Resets the database settings array to the default set in opt */ function opts_reset() { //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_import_export'); //Set the backup options in the DB to the current options $this->opts_backup(); //Load in the hard coded default option values $this->update_option($this->unique_prefix . '_options', array(), true); //Reset successful, let the user know $this->messages[] = new message(esc_html__('Settings successfully reset to the default values.', $this->identifier) . $this->admin_anchor('undo', __('Undo the options reset.', $this->identifier), __('Undo', $this->identifier)), 'success'); add_action('admin_notices', array($this, 'messages')); } /** * Undos the last settings save/reset/import */ function opts_undo() { //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_undo'); //Set the options array to the current options $opt = $this->get_option($this->unique_prefix . '_options'); //Set the options in the DB to the backup options $this->update_option($this->unique_prefix . '_options', $this->get_option($this->unique_prefix . '_options_bk'), true); //Set the backup options to the undone options $this->update_option($this->unique_prefix . '_options_bk', $opt, false); //Send the success/undo message $this->messages[] = new message(esc_html__('Settings successfully undid the last operation.', $this->identifier) . $this->admin_anchor('undo', __('Undo the last undo operation.', $this->identifier), __('Undo', $this->identifier)), 'success'); add_action('admin_notices', array($this, 'messages')); } /** * Upgrades input options array, sets to $this->opt, designed to be overwritten * * @param array $opts * @param string $version the version of the passed in options */ function opts_upgrade($opts, $version) { //We don't support using newer versioned option files in older releases if(version_compare($this::version, $version, '>=')) { $this->opt = $opts; } } /** * Forces a database settings upgrade * * FIXME: seems there is a lot of very similar code in install */ function opts_upgrade_wrapper() { //Do a nonce check, prevent malicious link/form problems check_admin_referer($this->unique_prefix . '_admin_upgrade'); //Grab the database options $opts = $this->get_option($this->unique_prefix . '_options'); if(is_array($opts)) { //Feed the just read options into the upgrade function $this->opts_upgrade($opts, $this->get_option($this->unique_prefix . '_version')); //Always have to update the version $this->update_option($this->unique_prefix . '_version', $this::version, false); //Store the options $this->update_option($this->unique_prefix . '_options', $this->opt, true); //Send the success message $this->messages[] = new message(esc_html__('Settings successfully migrated.', $this->identifier), 'success'); } else { //Run the install script $this->install(); //Send the success message $this->messages[] = new message(esc_html__('Default settings successfully installed.', $this->identifier), 'success'); } add_action('admin_notices', array($this, 'messages')); } /** * help action hook function * * @return string * */ function help() { $screen = get_current_screen(); //Exit early if the add_help_tab function doesn't exist if(!method_exists($screen, 'add_help_tab')) { return; } //Add contextual help on current screen if($screen->id == 'settings_page_' . $this->identifier) { $this->help_contents($screen); } } function help_contents(\WP_Screen &$screen) { } function dismiss_message() { //Grab the submitted UID $uid = esc_attr($_POST['uid']); //Create a dummy message, with the discovered UID $message = new message('', '', true, $uid); //Dismiss the message $message->dismiss(); wp_die(); } /** * Prints to screen all of the messages stored in the message member variable */ function messages() { foreach($this->messages as $message) { $message->render(); } //Old deprecated messages if(is_array($this->message) && count($this->message)) { _deprecated_function( __FUNCTION__, '2.0.0', __('adminKit::message is deprecated, use new adminkit_messages instead.', $this->identifier) ); //Loop through our message classes foreach($this->message as $key => $class) { //Loop through the messages in the current class foreach($class as $message) { printf('<div class="%s"><p>%s</p></div>', esc_attr($key), $message); } } $this->message = array(); } $this->messages = array(); } /** * Function prototype to prevent errors */ function admin_styles() { } /** * Function prototype to prevent errors */ function admin_scripts() { } /** * Function prototype to prevent errors */ function admin_head() { } /** * Function prototype to prevent errors */ function admin_page() { } /** * Function prototype to prevent errors */ protected function _get_help_text() { } /** * Returns a valid xHTML element ID * * @param object $option * * @deprecated 7.0.0 */ static public function get_valid_id($option) { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::get_valid_id'); if(is_numeric($option[0])) { return 'p' . $option; } else { return $option; } } function import_form() { $form = '<div id="mtekk_admin_import_export_relocate">'; $form .= sprintf('<form action="%s" method="post" enctype="multipart/form-data" id="%s_admin_upload">', esc_attr($this->admin_url()), esc_attr($this->unique_prefix)); $form .= wp_nonce_field($this->unique_prefix . '_admin_import_export', '_wpnonce', true, false); $form .= sprintf('<fieldset id="import_export" class="%s_options">', esc_attr($this->unique_prefix)); $form .= '<legend class="screen-reader-text">' . esc_html__( 'Import settings', $this->identifier ) . '</legend>'; $form .= '<p>' . esc_html__('Import settings from a JSON or XML file, export the current settings to a JSON file, or reset to the default settings.', $this->identifier) . '</p>'; $form .= '<table class="form-table"><tr valign="top"><th scope="row">'; $form .= sprintf('<label for="%s_admin_import_file">', esc_attr($this->unique_prefix)); $form .= esc_html__('Settings File', $this->identifier); $form .= '</label></th><td>'; $form .= sprintf('<input type="file" name="%1$s_admin_import_file" id="%1$s_admin_import_file" size="32" /><p class="description">', esc_attr($this->unique_prefix)); $form .= esc_html__('Select a JSON or XML settings file to upload and import settings from.', $this->identifier); $form .= '</p></td></tr></table><p class="submit">'; $form .= sprintf('<input type="submit" class="button" name="%1$s_admin_settings_import" value="%2$s"/>', $this->unique_prefix, esc_attr__('Import', $this->identifier)); $form .= sprintf('<input type="submit" class="button" name="%1$s_admin_settings_export" value="%2$s"/>', $this->unique_prefix, esc_attr__('Export', $this->identifier)); $form .= sprintf('<input type="submit" class="button" name="%1$s_admin_reset" value="%2$s"/>', $this->unique_prefix, esc_attr__('Reset', $this->identifier)); $form .= '</p></fieldset></form></div>'; return $form; } /** * This will output a well formed hidden option * * @param string $option * * @deprecated 7.0.0 */ function input_hidden($option) { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::input_hidden'); $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; printf('<input type="hidden" name="%1$s" id="%2$s" value="%3$s" />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option])); } /** * This will output a well formed option label * * @param string $opt_id * @param string $label * * @deprecated 7.0.0 */ function label($opt_id, $label) { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::label'); printf('<label for="%1$s">%2$s</label>', esc_attr($opt_id), $label); } /** * This will output a well formed table row for a text input * * @param string $label * @param string $option * @param string $class (optional) * @param bool $disable (optional) * @param string $description (optional) * * @deprecated 7.0.0 */ function input_text($label, $option, $class = 'regular-text', $disable = false, $description = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::input_text'); $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $label);?> </th> <td> <?php printf('<input type="text" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false));?> <?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?> </td> </tr> <?php } /** * This will output a well formed table row for a HTML5 number input * * @param string $label * @param string $option * @param string $class (optional) * @param bool $disable (optional) * @param string $description (optional) * @param int|string $min (optional) * @param int|string $max (optional) * @param int|string $step (optional) * * @deprecated 7.0.0 */ function input_number($label, $option, $class = 'small-text', $disable = false, $description = '', $min = '', $max = '', $step = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::input_number'); $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; $extras = ''; if($min !== '') { $extras .= 'min="' . esc_attr($min) . '" '; } if($max !== '') { $extras .= 'max="' . esc_attr($max) . '" '; } if($step !== '') { $extras .= 'step="' . esc_attr($step) . '" '; } if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $label);?> </th> <td> <?php printf('<input type="number" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %6$s%5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false), $extras);?> <?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?> </td> </tr> <?php } /** * This will output a well formed textbox * * @param string $label * @param string $option * @param string $rows (optional) * @param bool $disable (optional) * @param string $description (optional) * * @deprecated 7.0.0 */ function textbox($label, $option, $height = '3', $disable = false, $description = '', $class = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::textbox'); $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; $class .= ' large-text'; if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $label);?> </th> <td> <?php printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($this->opt[$option]), esc_attr($class), disabled($disable, true, false), esc_attr($height));?> <?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?> </td> </tr> <?php } /** * This will output a well formed tiny mce ready textbox * * @param string $label * @param string $option * @param string $rows (optional) * @param bool $disable (optional) * @param string $description (optional) * * @deprecated 7.0.0 */ function tinymce($label, $option, $height = '3', $disable = false, $description = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::tinymce'); $opt_id = adminKit::get_valid_id($option); $class = 'mtekk_mce'; if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $label);?> </th> <td> <?php printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($this->opt[$option]), esc_attr($class), disabled($disable, true, false), esc_attr($height));?> <?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?> </td> </tr> <?php } /** * This will output a well formed table row for a checkbox input * * @param string $label * @param string $option * @param string $instruction * @param bool $disable (optional) * @param string $description (optional) * @param string $class (optional) * * @deprecated 7.0.0 */ function input_check($label, $option, $instruction, $disable = false, $description = '', $class = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::input_check'); $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <tr valign="top"> <th scope="row"> <?php echo esc_html( $label ); ?> </th> <td> <label for="<?php echo esc_attr( $opt_id ); ?>"> <?php printf('<input type="checkbox" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false), checked($this->opt[$option], true, false));?> <?php echo $instruction; ?> </label><br /> <?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?> </td> </tr> <?php } /** * This will output a singular radio type form input field * * @param string $option * @param string $value * @param string $instruction * @param object $disable (optional) * @param string $class (optional) * * @deprecated 7.0.0 */ function input_radio($option, $value, $instruction, $disable = false, $class = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::input_radio'); $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; $class .= ' togx'; if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <label> <?php printf('<input type="radio" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($value), esc_attr($class), disabled($disable, true, false), checked($value, $this->opt[$option], false));?> <?php echo $instruction; ?> </label><br/> <?php } /** * This will output a well formed table row for a select input * * @param string $label * @param string $option * @param array $values * @param bool $disable (optional) * @param string $description (optional) * @param array $titles (optional) The array of titiles for the options, if they should be different from the values * @param string $class (optional) Extra class to apply to the elements * * @deprecated 7.0.0 */ function input_select($label, $option, $values, $disable = false, $description = '', $titles = false, $class = '') { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::input_select'); //If we don't have titles passed in, we'll use option names as values if(!$titles) { $titles = $values; } $opt_id = adminKit::get_valid_id($option); $opt_name = $this->unique_prefix . '_options[' . $option . ']'; if($disable) { $this->input_hidden($option); $class .= ' disabled'; }?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $label);?> </th> <td> <?php printf('<select name="%1$s" id="%2$s" class="%4$s" %5$s>%3$s</select><br />', esc_attr($opt_name), esc_attr($opt_id), $this->select_options($option, $titles, $values), esc_attr($class), disabled($disable, true, false));?> <?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?> </td> </tr> <?php } /** * Displays wordpress options as <seclect> * * @param string $optionname name of wordpress options store * @param array $options array of names of options that can be selected * @param array $values array of the values of the options that can be selected * @param array $exclude(optional) array of names in $options array to be excluded * * @return string The assembled HTML for the select options * * @deprecated 7.0.0 */ function select_options($optionname, $options, $values, $exclude = array()) { _deprecated_function( __FUNCTION__, '7.0', '\mtekk\adminKit\form::select_options'); $options_html = ''; $value = $this->opt[$optionname]; //Now do the rest foreach($options as $key => $option) { if(!in_array($option, $exclude)) { $options_html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($values[$key]), selected($value, $values[$key], false), $option); } } return $options_html; } /** * A local pass through for get_option so that we can hook in and pick the correct method if needed * * @param string $option The name of the option to retrieve * @return mixed The value of the option */ function get_option($option) { return get_option($option); } /** * A local pass through for update_option so that we can hook in and pick the correct method if needed * * @param string $option The name of the option to update * @param mixed $newvalue The new value to set the option to */ function update_option($option, $newvalue, $autoload = null) { return update_option($option, $newvalue, $autoload); } /** * A local pass through for add_option so that we can hook in and pick the correct method if needed * * @param string $option The name of the option to update * @param mixed $value The new value to set the option to * @param null $deprecated Deprecated parameter * @param string $autoload Whether or not to autoload the option, it's a string because WP is special */ function add_option($option, $value = '', $deprecated = '', $autoload = 'yes') { return add_option($option, $value, null, $autoload); } /** * A local pass through for delete_option so that we can hook in and pick the correct method if needed * * @param string $option The name of the option to delete */ function delete_option($option) { return delete_option($option); } } includes/adminKit/class-mtekk_adminkit_message.php 0000644 00000006557 14720660717 0016454 0 ustar 00 <?php /* Copyright 2015-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit; require_once( __DIR__ . '/../block_direct_access.php'); class message { const version = '1.0.0'; protected $type = ''; protected $contents = ''; protected $dismissed = false; protected $dismissible = false; protected $uid; /** * Default constructor function * * @param string $contents The string to display in the message * @param string $type The message type, 'error', 'warning', 'success', or 'info' * @param bool $dismissible Whether or not the message is dismissable * @param string $uid The message unique ID, only necessary if the message is dismissable */ public function __construct($contents, $type = 'info', $dismissible = false, $uid = '') { $uid = sanitize_html_class($uid); //If the message is dismissable, the UID better not be null/empty if($dismissible === true && $uid === '') { //Let the user know they're doing it wrong _doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('$uid must not be null if message is dismissible', 'mtekk_adminKit'), '1.0.0'); //Treat the message as non-dismissible $dismissible = false; } $this->contents = $contents; $this->type = $type; $this->dismissible = $dismissible; $this->uid = $uid; if($this->dismissible) { $this->dismissed = $this->was_dismissed(); } } /** * Attempts to retrieve the dismissal transient for this message * * @return bool Whether or not the message has been dismissed */ public function was_dismissed() { $this->dismissed = get_transient($this->uid); return $this->dismissed; } /** * Dismisses the message, preventing it from being rendered */ public function dismiss() { if($this->dismissible && isset($_POST['uid']) && esc_attr($_POST['uid']) === $this->uid) { check_ajax_referer($this->uid . '_dismiss', 'nonce'); $this->dismissed = true; //If the message was dismissed, update the transient for 30 days $result = set_transient($this->uid, $this->dismissed, 2592000); } } /** * Function that prints out the message if not already dismissed */ public function render() { if($this->dismissible) { //Don't render dismissed messages if($this->was_dismissed()) { return; } wp_enqueue_script('mtekk_adminkit_messages'); printf('<div class="notice notice-%1$s is-dismissible"><p>%2$s</p><meta property="uid" content="%3$s"><meta property="nonce" content="%4$s"></div>', esc_attr($this->type), $this->contents, esc_attr($this->uid), wp_create_nonce($this->uid . '_dismiss')); } else { printf('<div class="notice notice-%1$s"><p>%2$s</p></div>', esc_attr($this->type), $this->contents); } } } includes/adminKit/setting/class-mtekk_adminkit_setting_float.php 0000644 00000003502 14720660717 0021332 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_float extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, float $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { return (float) $new_value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting_base::jsonSerialize() */ public function jsonSerialize(): float { return $this->value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'f' . $this->get_name(); } } includes/adminKit/setting/class-mtekk_adminkit_setting_html.php 0000644 00000003662 14720660717 0021200 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('\mtekk\adminKit\setting\setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_html extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, string $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { if(!$this->allow_empty && $new_value === '') { return $this->value; } return wp_kses(stripslashes($new_value), apply_filters('mtekk_adminkit_allowed_html', wp_kses_allowed_html('post'))); } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { if($this->allow_empty) { $type = 'h'; } else { $type = 'H'; } return $type . $this->get_name(); } } includes/adminKit/setting/php7/class-mtekk_adminkit_setting_float.php 0000644 00000003240 14720660717 0022207 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../../block_direct_access.php'); //Include setting base class if(!class_exists('setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_float extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, float $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { return (float) $new_value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'f' . $this->get_name(); } } includes/adminKit/setting/php7/class-mtekk_adminkit_setting_bool.php 0000644 00000004257 14720660717 0022046 0 ustar 00 <?php /* Copyright 2020-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../../block_direct_access.php'); //Include setting base class if(!class_exists('setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_bool extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, bool $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { return (bool) $new_value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'b' . $this->get_name(); } /** * * {@inheritDoc} * @see mtekk_adminKit_setting::updateFromFormInput() */ public function maybe_update_from_form_input($input, $bool_ignore_missing = false) { if(isset($input[$this->get_opt_name()]) && ($input[$this->get_opt_name()] === true || $input[$this->get_opt_name()] === '1')) { $newval = true; } else { //If the value wasn't set, but we are to ignore missing inputs if($bool_ignore_missing) { return; } $newval = false; } $this->set_value($this->validate($newval)); } } includes/adminKit/setting/php7/class-mtekk_adminkit_setting_int.php 0000644 00000003232 14720660717 0021675 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../../block_direct_access.php'); //Include setting base class if(!class_exists('setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_int extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, int $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { return (int) $new_value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'i' . $this->get_name(); } } includes/adminKit/setting/php7/class-mtekk_adminkit_setting_base.php 0000644 00000004262 14720660717 0022021 0 ustar 00 <?php /* Copyright 2020-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../../block_direct_access.php'); //Include setting interface if(!interface_exists('setting')) { require_once( __DIR__ . '/../interface-mtekk_adminkit_setting.php'); } abstract class setting_base implements setting,\JsonSerializable { const version = '1.0.0'; protected $name = ''; protected $value = ''; protected $title = ''; protected $allow_empty = false; protected $deprecated = false; public function is_deprecated() { return $this->deprecated; } public function set_deprecated($deprecated) { $this->deprecated = $deprecated; } public function get_value() { return $this->value; } public function set_value($new_value) { $this->value = $new_value; } public function get_title() { return $this->title; } public function get_name() { return $this->name; } public function get_allow_empty() { return $this->allow_empty; } public function set_allow_empty($allow_empty) { $this->allow_empty = $allow_empty; } public function jsonSerialize() { return $this->value; } /** * Basic updateFromFormInput method * * {@inheritDoc} * @see mtekk\adminKit\setting::maybe_update_from_form_input() */ public function maybe_update_from_form_input($input, $bool_ignore_missing = false) { if(isset($input[$this->get_opt_name()])) { $this->set_value($this->validate($input[$this->get_opt_name()])); } } } includes/adminKit/setting/interface-mtekk_adminkit_setting.php 0000644 00000003510 14720660717 0020777 0 ustar 00 <?php /* Copyright 2020-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); interface setting { /** * Validation method * * @param unknown $new_value new setting value to validate * @return the validated version of the setting (may be old/current value if new value was invalid) */ public function validate($new_value); public function is_deprecated(); public function set_deprecated($deprecated); public function get_value(); public function set_value($new_value); public function get_title(); public function get_name(); public function get_allow_empty(); public function set_allow_empty($allow_empty); /** * @return string The 'option' name for this setting, a combination of the type and name */ public function get_opt_name(); /** * Update from form values method * * @param array $input Array of new values from well formatted form POST request */ public function maybe_update_from_form_input($input, $bool_ignore_missing = false); //public function render(); //This is a future item we'll add, maybe } includes/adminKit/setting/class-mtekk_adminkit_setting_bool.php 0000644 00000004520 14720660717 0021161 0 ustar 00 <?php /* Copyright 2020-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_bool extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, bool $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { return (bool) $new_value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting_base::jsonSerialize() */ public function jsonSerialize(): bool { return $this->value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'b' . $this->get_name(); } /** * * {@inheritDoc} * @see mtekk_adminKit_setting::updateFromFormInput() */ public function maybe_update_from_form_input($input, $bool_ignore_missing = false) { if(isset($input[$this->get_opt_name()]) && ($input[$this->get_opt_name()] === true || $input[$this->get_opt_name()] === '1')) { $newval = true; } else { //If the value wasn't set, but we are to ignore missing inputs if($bool_ignore_missing) { return; } $newval = false; } $this->set_value($this->validate($newval)); } } includes/adminKit/setting/class-mtekk_adminkit_setting_enum.php 0000644 00000004612 14720660717 0021174 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('\mtekk\adminKit\setting\setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_enum extends setting_base { protected $allowed_vals = array(); /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, string $value, string $title, $allow_empty = false, $deprecated = false, $allowed_vals = array()) { $this->name = $name; $this->value = $value; $this->title = $title; $this->deprecated = $deprecated; $this->allow_empty = $allow_empty; $this->allowed_vals= $allowed_vals; } /** * Validates the new value against the allowed values for this setting * * {@inheritDoc} * @see mtekk_adminKit_setting::validate() */ public function validate($new_value) { if(in_array($new_value, $this->allowed_vals)) { return $new_value; } else { return $this->value; } } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'E' . $this->get_name(); } /** * Setter for the allowed values array * * @param array $allowed_vals Array of allowed values */ public function set_allowed_vals(array $allowed_vals) { $this->allowed_vals = $allowed_vals; } /** * Getter of the allowed values array * * @return array Allowed values used in validation of the setting */ public function get_allowed_vals() { return $this->allowed_vals; } } includes/adminKit/setting/class-mtekk_adminkit_setting_string.php 0000644 00000003532 14720660717 0021536 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('\mtekk\adminKit\setting\setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_string extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, string $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { if(!$this->allow_empty && $new_value === '') { return $this->value; } return esc_html($new_value); } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { if($this->allow_empty) { $type = 's'; } else { $type = 'S'; } return $type . $this->get_name(); } } includes/adminKit/setting/class-mtekk_adminkit_setting_int.php 0000644 00000003472 14720660717 0021025 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('setting_base')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_base.php'); } class setting_int extends setting_base { /** * Default constructor function * * @param string $title The display title of the setting */ public function __construct(string $name, int $value, string $title, $allow_empty = false, $deprecated = false) { $this->name = $name; $this->value = $value; $this->title = $title; $this->allow_empty = $allow_empty; $this->deprecated = $deprecated; } /** * */ public function validate($new_value) { return (int) $new_value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting_base::jsonSerialize() */ public function jsonSerialize(): int { return $this->value; } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'i' . $this->get_name(); } } includes/adminKit/setting/class-mtekk_adminkit_setting_absint.php 0000644 00000002477 14720660717 0021517 0 ustar 00 <?php /* Copyright 2020-2021 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting base class if(!class_exists('\mtekk\adminKit\setting\setting_int')) { require_once( __DIR__ . '/class-mtekk_adminkit_setting_int.php'); } class setting_absint extends setting_int { /** * */ public function validate($new_value) { return absint($new_value); } /** * * {@inheritDoc} * @see \mtekk\adminKit\setting\setting::get_opt_name() */ public function get_opt_name() { return 'a' . $this->get_name(); } } includes/adminKit/setting/class-mtekk_adminkit_setting_base.php 0000644 00000004263 14720660717 0021144 0 ustar 00 <?php /* Copyright 2020-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit\setting; require_once( __DIR__ . '/../../block_direct_access.php'); //Include setting interface if(!interface_exists('setting')) { require_once( __DIR__ . '/interface-mtekk_adminkit_setting.php'); } abstract class setting_base implements setting,\JsonSerializable { const version = '1.0.0'; protected $name = ''; protected $value = ''; protected $title = ''; protected $allow_empty = false; protected $deprecated = false; public function is_deprecated() { return $this->deprecated; } public function set_deprecated($deprecated) { $this->deprecated = $deprecated; } public function get_value() { return $this->value; } public function set_value($new_value) { $this->value = $new_value; } public function get_title() { return $this->title; } public function get_name() { return $this->name; } public function get_allow_empty() { return $this->allow_empty; } public function set_allow_empty($allow_empty) { $this->allow_empty = $allow_empty; } public function jsonSerialize(): mixed { return $this->value; } /** * Basic updateFromFormInput method * * {@inheritDoc} * @see mtekk\adminKit\setting::maybe_update_from_form_input() */ public function maybe_update_from_form_input($input, $bool_ignore_missing = false) { if(isset($input[$this->get_opt_name()])) { $this->set_value($this->validate($input[$this->get_opt_name()])); } } } includes/adminKit/assets/mtekk_adminkit_messages.js 0000644 00000000541 14720660717 0016646 0 ustar 00 jQuery(function() { jQuery("div.notice button.notice-dismiss").click(function (event){ data = { 'action': 'mtekk_admin_message_dismiss', 'uid': jQuery(this).parent().children("meta[property='uid']").attr("content"), 'nonce': jQuery(this).parent().children("meta[property='nonce']").attr("content") }; jQuery.post(ajaxurl, data); }); }); includes/adminKit/assets/mtekk_adminkit_tabs.js 0000644 00000002531 14720660717 0015771 0 ustar 00 jQuery(function() { mtekk_admin_tabulator_init(); }); /** * Tabulator Bootup */ function mtekk_admin_tabulator_init(){ if(!jQuery("#hasadmintabs").length) return; /* init markup for tabs */ jQuery('#hasadmintabs').prepend('<ul class="nav-tab-wrapper"><\/ul>'); jQuery('#hasadmintabs > fieldset').each(function(i){ id = jQuery(this).attr('id'); cssc = jQuery(this).attr('class'); title = jQuery(this).find('legend').data('title'); caption = jQuery(this).find('legend').text(); jQuery('#hasadmintabs > ul').append('<li><a href="#'+id+'" class="nav-tab '+cssc+'" title="'+title+'"><span>'+caption+"<\/span><\/a><\/li>"); }); var form = jQuery('#'+objectL10n.mtad_uid+'-options'); /* init the tabs plugin */ var tabs = jQuery("#hasadmintabs").tabs({ beforeActivate: function(event, ui){ form.find('input').each(function(){ if(!this.checkValidity()){ form.find(':submit').click(); event.preventDefault(); } }); /* Update form action for reload on tab traversal*/ var action = form.attr("action").split('#', 1) + '#' + ui.newPanel[0].id; form.get(0).setAttribute("action", action); }, create: function(event, ui){ /* Update form action for reload of current tab on page load */ var action = form.attr("action").split('#', 1) + '#' + ui.panel[0].id; form.get(0).setAttribute("action", action); } }); } includes/adminKit/assets/mtekk_adminkit_engroups.js 0000644 00000002255 14720660717 0016705 0 ustar 00 jQuery(function() { jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_group); jQuery("input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_set); }); function mtekk_admin_enable_group(){ var setting = this; jQuery(this).parents(".adminkit-engroup").find("input, textarea").each(function(){ if(this != setting){ if(jQuery(setting).prop("checked")){ jQuery(this).prop("disabled", false); jQuery(this).removeClass("disabled"); } else{ jQuery(this).prop("disabled", true); jQuery(this).addClass("disabled"); } } }); } function mtekk_admin_enable_set(){ var setting = this; jQuery(this).parents(".adminkit-enset-top").find("input.adminkit-enset, textarea.adminkit-enset").each(function(){ if(this != setting){ if(jQuery(setting).prop("checked")){ jQuery(this).prop("disabled", false); jQuery(this).removeClass("disabled"); } else{ jQuery(this).prop("disabled", true); jQuery(this).addClass("disabled"); } } }); } jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_group); jQuery("input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_set); includes/adminKit/assets/mtekk_adminkit_tabs.css 0000644 00000002400 14720660717 0016140 0 ustar 00 #hasadmintabs ul.ui-tabs-nav{float: left; width: 100%; border-bottom:1px solid #ccc; font-size:12px; height:27px; list-style-image:none; list-style-position:outside; list-style-type:none; margin:14px 0 0; overflow:visible;padding:0 0 0 6px;} #hasadmintabs ul.ui-tabs-nav li{display:block; float:left; line-height:200%; list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; position:relative; text-align:center; white-space:nowrap; width:auto;} #hasadmintabs ul.ui-tabs-nav li a{border-bottom:1px solid #ccc; display:block; color:#464646; float:left; line-height:25px; padding:1px 13px 0; position:relative; text-decoration:none;margin:0 4px 0 0;} #hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a{background:none;border:1px solid #ccc; border-bottom-color:#f1f1f1; height: 25px; color:#464646; font-weight:normal; padding:1px 13px 0;color:#000;} #hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a:hover, #hasadmintabs ul.ui-tabs-nav a:hover{outline-color:-moz-use-text-color; outline-style:none; outline-width:medium;} #hasadmintabs ul.ui-tabs-nav li a:focus, #hasadmintabs ul.ui-tabs-nav li a:active{outline: none;} #hasadmintabs ul.ui-tabs-nav span{font-size: 12px; font-weight: bolder;} #screen-options-wrap p.submit {margin:0; padding:0;} includes/adminKit/assets/mtekk_adminkit_messages.min.js 0000644 00000000541 14720660717 0017430 0 ustar 00 jQuery(function() { jQuery("div.notice button.notice-dismiss").click(function (event){ data = { 'action': 'mtekk_admin_message_dismiss', 'uid': jQuery(this).parent().children("meta[property='uid']").attr("content"), 'nonce': jQuery(this).parent().children("meta[property='nonce']").attr("content") }; jQuery.post(ajaxurl, data); }); }); includes/adminKit/assets/mtekk_adminkit_tabs.min.js 0000644 00000001665 14720660717 0016562 0 ustar 00 function mtekk_admin_tabulator_init(){if(jQuery("#hasadmintabs").length){jQuery("#hasadmintabs").prepend('<ul class="nav-tab-wrapper"></ul>'),jQuery("#hasadmintabs > fieldset").each(function(t){id=jQuery(this).attr("id"),cssc=jQuery(this).attr("class"),title=jQuery(this).find("legend").data("title"),caption=jQuery(this).find("legend").text(),jQuery("#hasadmintabs > ul").append('<li><a href="#'+id+'" class="nav-tab '+cssc+'" title="'+title+'"><span>'+caption+"</span></a></li>")});var e=jQuery("#"+objectL10n.mtad_uid+"-options");jQuery("#hasadmintabs").tabs({beforeActivate:function(t,a){e.find("input").each(function(){this.checkValidity()||(e.find(":submit").click(),t.preventDefault())});var i=e.attr("action").split("#",1)+"#"+a.newPanel[0].id;e.get(0).setAttribute("action",i)},create:function(t,a){var i=e.attr("action").split("#",1)+"#"+a.panel[0].id;e.get(0).setAttribute("action",i)}})}}jQuery(function(){mtekk_admin_tabulator_init()}); includes/adminKit/assets/mtekk_adminkit_tabs.min.css 0000644 00000002276 14720660717 0016735 0 ustar 00 #hasadmintabs ul.ui-tabs-nav{float:left;width:100%;border-bottom:1px solid #ccc;font-size:12px;height:27px;list-style-image:none;list-style-position:outside;list-style-type:none;margin:14px 0 0;overflow:visible;padding:0 0 0 6px}#hasadmintabs ul.ui-tabs-nav li{display:block;float:left;line-height:200%;list-style-image:none;list-style-position:outside;list-style-type:none;margin:0;padding:0;position:relative;text-align:center;white-space:nowrap;width:auto}#hasadmintabs ul.ui-tabs-nav li a{border-bottom:1px solid #ccc;display:block;color:#464646;float:left;line-height:25px;padding:1px 13px 0;position:relative;text-decoration:none;margin:0 4px 0 0}#hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a{background:0;border:1px solid #ccc;border-bottom-color:#f1f1f1;height:25px;color:#464646;font-weight:normal;padding:1px 13px 0;color:#000}#hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a:hover,#hasadmintabs ul.ui-tabs-nav a:hover{outline-color:-moz-use-text-color;outline-style:none;outline-width:medium}#hasadmintabs ul.ui-tabs-nav li a:focus,#hasadmintabs ul.ui-tabs-nav li a:active{outline:0}#hasadmintabs ul.ui-tabs-nav span{font-size:12px;font-weight:bolder}#screen-options-wrap p.submit{margin:0;padding:0} includes/adminKit/assets/mtekk_adminkit_engroups.min.js 0000644 00000002012 14720660717 0017456 0 ustar 00 jQuery(function(){jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_group);jQuery("input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_set)});function mtekk_admin_enable_group(){var a=this;jQuery(this).parents(".adminkit-engroup").find("input, textarea").each(function(){if(this!=a){if(jQuery(a).prop("checked")){jQuery(this).prop("disabled",false);jQuery(this).removeClass("disabled")}else{jQuery(this).prop("disabled",true);jQuery(this).addClass("disabled")}}})}function mtekk_admin_enable_set(){var a=this;jQuery(this).parents(".adminkit-enset-top").find("input.adminkit-enset, textarea.adminkit-enset").each(function(){if(this!=a){if(jQuery(a).prop("checked")){jQuery(this).prop("disabled",false);jQuery(this).removeClass("disabled")}else{jQuery(this).prop("disabled",true);jQuery(this).addClass("disabled")}}})}jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_group);jQuery("input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_set); includes/adminKit/class-mtekk_adminkit_uninstaller.php 0000644 00000004144 14720660717 0017356 0 ustar 00 <?php /* Copyright 2015-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once( __DIR__ . '/../block_direct_access.php'); /** * Breadcrumb NavXT abstract plugin uninstaller class * * @author Tom Klingenberg */ abstract class mtekk_adminKit_uninstaller { protected $unique_prefix = ''; protected $plugin_basename = null; protected $_uninstall_result = false; /** * get plugin path * * @return string full path to plugin file */ protected function _get_plugin_path() { return sprintf('%s/%s', dirname(dirname(__DIR__)), $this->plugin_basename); } /** * constructor * * @param array $options class options * plugin => */ public function __construct() { $this->_uninstall_result = $this->uninstall(); } /** * Result Getter * * @return bool wether or not uninstall did run successfull. */ public function get_result() { return $this->_uninstall_result; } public function is_installed() { return ((get_option($this->unique_prefix . '_options') !== false) && (get_option($this->unique_prefix . '_options_bk') !== false) && (get_option($this->unique_prefix . '_version') !== false) && (get_site_option($this->unique_prefix . '_options') !== false) && (get_site_option($this->unique_prefix . '_options_bk') !== false) && (get_site_option($this->unique_prefix . '_version') !== false)); } } /// class bcn_uninstaller_abstract includes/adminKit/class-mtekk_adminkit_form.php 0000644 00000026314 14720660717 0015764 0 ustar 00 <?php /* Copyright 2015-2023 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ namespace mtekk\adminKit; use mtekk\adminKit\setting\setting as setting; require_once( __DIR__ . '/../block_direct_access.php'); //Include setting interface if(!interface_exists('\mtekk\adminKit\setting\setting')) { require_once( __DIR__ . '/interface-mtekk_adminkit_setting.php'); } class form { const version = '1.0.0'; protected $unique_prefix; /** * Default constructor function * * @param string $unique_prefix */ public function __construct($unique_prefix) { $this->unique_prefix = $unique_prefix; } /** * Returns a valid xHTML element ID * * @param object $option */ static public function get_valid_id($option) { if(is_numeric($option[0])) { return 'p' . $option; } else { return $option; } } /** * This will output a well formed hidden option * * @param string $option */ public function input_hidden(setting $option) { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']'; printf('<input type="hidden" name="%1$s" id="%2$s" value="%3$s" />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($option->get_value())); } /** * This will output a well formed option label * * @param string $opt_id * @param string $label */ public function label($opt_id, $label) { printf('<label for="%1$s">%2$s</label>', esc_attr($opt_id), $label); } /** * This will output a well formed table row for a text input * * @param setting $option * @param string $class (optional) * @param bool $disable (optional) * @param string $description (optional) * * FIXME: Parameter list non-consistant with others */ public function input_text(setting $option, $class = 'regular-text', $disable = false, $description = '') { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']';?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $option->get_title());?> </th> <td> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<input type="text" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($option->get_value()), esc_attr($class), disabled($disable, true, false)); if($description !== '') { printf('<p class="description">%s</p>', $description); }?> </td> </tr> <?php } /** * This will output a well formed table row for a HTML5 number input * * @param setting $option * @param string $class (optional) * @param bool $disable (optional) * @param string $description (optional) * @param int|string $min (optional) * @param int|string $max (optional) * @param int|string $step (optional) * * FIXME: Parameter list non-consistant with others */ public function input_number(setting $option, $class = 'small-text', $disable = false, $description = '', $min = '', $max = '', $step = '') { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']'; $extras = ''; if($min !== '') { $extras .= 'min="' . esc_attr($min) . '" '; } if($max !== '') { $extras .= 'max="' . esc_attr($max) . '" '; } if($step !== '') { $extras .= 'step="' . esc_attr($step) . '" '; }?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $option->get_title());?> </th> <td> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<input type="number" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %6$s%5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($option->get_value()), esc_attr($class), disabled($disable, true, false), $extras); if($description !== '') { printf('<p class="description">%s</p>', $description); }?> </td> </tr> <?php } /** * This will output a well formed textbox * * @param setting $option * @param string $rows (optional) * @param bool $disable (optional) * @param string $description (optional) */ public function textbox(setting $option, $height = '3', $disable = false, $description = '', $class = '') { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']'; $class .= ' large-text';?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $option->get_title());?> </th> <td> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($option->get_value()), esc_attr($class), disabled($disable, true, false), esc_attr($height)); if($description !== '') { printf('<p class="description">%s</p>', $description); }?> </td> </tr> <?php } /** * This will output a well formed tiny mce ready textbox * * @param setting $option * @param string $rows (optional) * @param bool $disable (optional) * @param string $description (optional) */ public function tinymce(setting $option, $height = '3', $disable = false, $description = '') { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']'; $class = 'mtekk_mce';?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $option->get_title());?> </th> <td> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($option->get_value()), esc_attr($class), disabled($disable, true, false), esc_attr($height)); if($description !== '') { printf('<p class="description">%s</p>', $description); }?> </td> </tr> <?php } /** * This will output a well formed table row for a checkbox input * * @param setting $option * @param string $instruction * @param bool $disable (optional) * @param string $description (optional) * @param string $class (optional) */ public function input_check(setting $option, $instruction, $disable = false, $description = '', $class = '') { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']';?> <tr valign="top"> <th scope="row"> <?php echo esc_html($option->get_title()); ?> </th> <td> <label for="<?php echo esc_attr( $opt_id ); ?>"> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<input type="checkbox" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), 1, esc_attr($class), disabled($disable, true, false), checked($option->get_value(), true, false)); echo $instruction;?> </label><br /> <?php if($description !== '') { printf('<p class="description">%s</p>', $description); }?> </td> </tr> <?php } /** * This will output a singular radio type form input field * * @param setting $option * @param string $value * @param string $instruction * @param object $disable (optional) * @param string $class (optional) */ public function input_radio(setting $option, $value, $instruction, $disable = false, $class = '') { $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']'; $class .= ' togx';?> <label> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<input type="radio" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($value), esc_attr($class), disabled($disable, true, false), checked($value, $option->get_value(), false)); echo $instruction; ?> </label><br/> <?php } /** * This will output a well formed table row for a select input * * @param setting $option * @param array $values * @param bool $disable (optional) * @param string $description (optional) * @param array $titles (optional) The array of titiles for the options, if they should be different from the values * @param string $class (optional) Extra class to apply to the elements */ public function input_select(setting $option, $values, $disable = false, $description = '', $titles = false, $class = '') { //If we don't have titles passed in, we'll use option names as values if(!$titles) { $titles = $values; } $opt_id = form::get_valid_id($option->get_name()); $opt_name = $this->unique_prefix . '_options[' . $option->get_opt_name(). ']';?> <tr valign="top"> <th scope="row"> <?php $this->label($opt_id, $option->get_title());?> </th> <td> <?php if($disable) { $this->input_hidden($option); $class .= ' disabled'; } printf('<select name="%1$s" id="%2$s" class="%4$s" %5$s>%3$s</select><br />', esc_attr($opt_name), esc_attr($opt_id), $this->select_options($option->get_value(), $titles, $values), esc_attr($class), disabled($disable, true, false)); if($description !== '') { printf('<p class="description">%s</p>', $description); }?> </td> </tr> <?php } /** * Generates <seclect> block based off of passed in options array * * @param string $current_value current value of option * @param array $options array of names of options that can be selected * @param array $values array of the values of the options that can be selected * @param array $exclude(optional) array of names in $options array to be excluded * * @return string The assembled HTML for the select options */ public function select_options($current_value, $options, $values, $exclude = array()) { $options_html = ''; //Now do the rest foreach($options as $key => $option) { if(!in_array($option, $exclude)) { $options_html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($values[$key]), selected($current_value, $values[$key], false), $option); } } return $options_html; } } breadcrumb-navxt.php 0000644 00000074743 14720660717 0010552 0 ustar 00 <?php /* Plugin Name: Breadcrumb NavXT Plugin URI: http://mtekk.us/code/breadcrumb-navxt/ Description: Adds a breadcrumb navigation showing the visitor's path to their current location. For details on how to use this plugin visit <a href="http://mtekk.us/code/breadcrumb-navxt/">Breadcrumb NavXT</a>. Version: 7.3.1 Author: John Havlik Author URI: http://mtekk.us/ License: GPL2 Text Domain: breadcrumb-navxt Domain Path: /languages */ /* Copyright 2007-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //Do a PHP version check, require 5.6 or newer if(version_compare(phpversion(), '5.6.0', '<')) { //Only purpose of this function is to echo out the PHP version error function bcn_phpold() { printf('<div class="notice notice-error"><p>' . esc_html__('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.6.0'); } //If we are in the admin, let's print a warning then return if(is_admin()) { add_action('admin_notices', 'bcn_phpold'); } return; } require_once(dirname(__FILE__) . '/includes/multibyte_supplicant.php'); //Include admin base class if(!class_exists('\mtekk\adminKit\adminKit')) { require_once(dirname(__FILE__) . '/includes/adminKit/class-mtekk_adminkit.php'); } //Include the breadcrumb class require_once(dirname(__FILE__) . '/class.bcn_breadcrumb.php'); //Include the breadcrumb trail class require_once(dirname(__FILE__) . '/class.bcn_breadcrumb_trail.php'); if(class_exists('WP_Widget')) { //Include the WP 2.8+ widget class require_once(dirname(__FILE__) . '/class.bcn_widget.php'); } use mtekk\adminKit\adminKit as adminKit; use mtekk\adminKit\setting; $breadcrumb_navxt = null; //TODO change to extends \mtekk\plugKit class breadcrumb_navxt { const version = '7.3.1'; protected $name = 'Breadcrumb NavXT'; protected $identifier = 'breadcrumb-navxt'; protected $unique_prefix = 'bcn'; protected $plugin_basename = null; protected $opt = null; protected $settings = array(); protected $breadcrumb_trail = null; protected $admin = null; protected $rest_controller = null; /** * Constructor for a new breadcrumb_navxt object * * @param bcn_breadcrumb_trail $breadcrumb_trail An instance of a bcn_breadcrumb_trail object to use for everything */ public function __construct(bcn_breadcrumb_trail $breadcrumb_trail) { //We get our breadcrumb trail object from our constructor $this->breadcrumb_trail = $breadcrumb_trail; //We set the plugin basename here $this->plugin_basename = plugin_basename(__FILE__); //We need to add in the defaults for CPTs and custom taxonomies after all other plugins are loaded add_action('wp_loaded', array($this, 'wp_loaded'), 15); add_action('rest_api_init', array($this, 'rest_api_init'), 10); //Run much later than everyone else to give other plugins a chance to hook into the filters and actions in this add_action('init', array($this, 'init'), 9000); //Register the WordPress 2.8 Widget add_action('widgets_init', array($this, 'register_widget')); //Load our network admin if in the network dashboard (yes is_network_admin() doesn't exist) if(defined('WP_NETWORK_ADMIN') && WP_NETWORK_ADMIN) { require_once(dirname(__FILE__) . '/class.bcn_network_admin.php'); //Instantiate our new admin object $this->admin = new bcn_network_admin($this->breadcrumb_trail->opt, $this->plugin_basename, $this->settings); } //Load our main admin if in the dashboard, but only if we're not in the network dashboard (prevents goofy bugs) else if(is_admin() || defined('WP_UNINSTALL_PLUGIN')) { require_once(dirname(__FILE__) . '/class.bcn_admin.php'); //Instantiate our new admin object $this->admin = new bcn_admin($this->breadcrumb_trail->opt, $this->plugin_basename, $this->settings); } } public function init() { add_filter('bcn_allowed_html', array($this, 'allowed_html'), 1, 1); add_filter('mtekk_adminkit_allowed_html', array($this, 'adminkit_allowed_html'), 1, 1); //We want to run late for using our breadcrumbs add_filter('tha_breadcrumb_navigation', array($this, 'tha_compat'), 99); //Only include the REST API if enabled if(!defined('BCN_DISABLE_REST_API') || !BCN_DISABLE_REST_API) { require_once(dirname(__FILE__) . '/class.bcn_rest_controller.php'); $this->rest_controller = new bcn_rest_controller($this->breadcrumb_trail, $this->unique_prefix); } breadcrumb_navxt::setup_setting_defaults($this->settings); if(!is_admin() || (!isset($_POST[$this->unique_prefix . '_admin_reset']) && !isset($_POST[$this->unique_prefix . '_admin_options']))) { $this->get_settings(); //This breaks the reset options script, so only do it if we're not trying to reset the settings } //Register Guternberg Block $this->register_block(); } public function rest_api_init() { add_filter('bcn_register_rest_endpoint', array($this, 'api_enable_for_block'), 10, 4); } public function register_widget() { return register_widget($this->unique_prefix . '_widget'); } /** * Handles registering the Breadcrumb Trail Gutenberg block */ public function register_block() { if(function_exists('register_block_type')) { register_block_type( dirname(__FILE__) . '/includes/blocks/build/breadcrumb-trail'); } } public function api_enable_for_block($register_rest_endpoint, $endpoint, $version, $methods) { //Enable if the current user can edit posts if(current_user_can('edit_posts') && $endpoint === 'post') { return true; } return $register_rest_endpoint; } public function adminkit_allowed_html($tags) { //Hoop through normal allowed_html filters return apply_filters('bcn_allowed_html', $tags); } public function allowed_html($tags) { $allowed_html = array( 'a' => array( 'href' => true, 'title' => true, 'class' => true, 'id' => true, 'media' => true, 'dir' => true, 'relList' => true, 'rel' => true, 'aria-hidden' => true, 'data-icon' => true, 'itemref' => true, 'itemid' => true, 'itemprop' => true, 'itemscope' => true, 'itemtype' => true, 'xmlns:v' => true, 'typeof' => true, 'property' => true, 'vocab' => true, 'translate' => true, 'lang' => true, 'bcn-aria-current' => true ), 'img' => array( 'alt' => true, 'align' => true, 'height' => true, 'width' => true, 'src' => true, 'srcset' => true, 'sizes' => true, 'id' => true, 'class' => true, 'aria-hidden' => true, 'data-icon' => true, 'itemref' => true, 'itemid' => true, 'itemprop' => true, 'itemscope' => true, 'itemtype' => true, 'xmlns:v' => true, 'typeof' => true, 'property' => true, 'vocab' => true, 'lang' => true ), 'span' => array( 'title' => true, 'class' => true, 'id' => true, 'dir' => true, 'align' => true, 'lang' => true, 'xml:lang' => true, 'aria-hidden' => true, 'data-icon' => true, 'itemref' => true, 'itemid' => true, 'itemprop' => true, 'itemscope' => true, 'itemtype' => true, 'xmlns:v' => true, 'typeof' => true, 'property' => true, 'vocab' => true, 'translate' => true, 'lang' => true ), 'h1' => array( 'title' => true, 'class' => true, 'id' => true, 'dir' => true, 'align' => true, 'lang' => true, 'xml:lang' => true, 'aria-hidden' => true, 'data-icon' => true, 'itemref' => true, 'itemid' => true, 'itemprop' => true, 'itemscope' => true, 'itemtype' => true, 'xmlns:v' => true, 'typeof' => true, 'property' => true, 'vocab' => true, 'translate' => true, 'lang' => true ), 'h2' => array( 'title' => true, 'class' => true, 'id' => true, 'dir' => true, 'align' => true, 'lang' => true, 'xml:lang' => true, 'aria-hidden' => true, 'data-icon' => true, 'itemref' => true, 'itemid' => true, 'itemprop' => true, 'itemscope' => true, 'itemtype' => true, 'xmlns:v' => true, 'typeof' => true, 'property' => true, 'vocab' => true, 'translate' => true, 'lang' => true ), 'meta' => array( 'content' => true, 'property' => true, 'vocab' => true, 'itemprop' => true ) ); if(!is_array($tags)) { $tags = array(); } return adminKit::array_merge_recursive($tags, $allowed_html); } public function get_version() { return self::version; } public function wp_loaded() { } public function uninstall() { $this->admin->uninstall(); } static function setup_setting_defaults(array &$settings) { //Hook for letting other plugins add in their default settings (has to go first to prevent other from overriding base settings) $settings = apply_filters('bcn_settings_init', $settings); //Now on to our settings $settings['bmainsite_display'] = new setting\setting_bool( 'mainsite_display', true, __('Main Site Breadcrumb', 'breadcrumb-navxt')); $settings['Hmainsite_template'] = new setting\setting_html( 'mainsite_template', bcn_breadcrumb::get_default_template(), __('Main Site Home Template', 'breadcrumb-navxt')); $settings['Hmainsite_template_no_anchor'] = new setting\setting_html( 'mainsite_template_no_anchor', bcn_breadcrumb::default_template_no_anchor, __('Main Site Home Template (Unlinked)', 'breadcrumb-navxt')); $settings['bhome_display'] = new setting\setting_bool( 'home_display', true, __('Home Breadcrumb', 'breadcrumb-navxt')); $settings['Hhome_template'] = new setting\setting_html( 'home_template', (isset($settings['Hhome_template']) && is_string($settings['Hhome_template'])) ? $settings['Hhome_template'] : bcn_breadcrumb::get_default_template(), __('Home Template', 'breadcrumb-navxt')); $settings['Hhome_template_no_anchor'] = new setting\setting_html( 'home_template_no_anchor', (isset($settings['Hhome_template_no_anchor']) && is_string($settings['Hhome_template_no_anchor'])) ? $settings['Hhome_template_no_anchor'] : bcn_breadcrumb::default_template_no_anchor, __('Home Template (Unlinked)', 'breadcrumb-navxt')); $settings['bblog_display'] = new setting\setting_bool( 'blog_display', true, __('Blog Breadcrumb', 'breadcrumb-navxt')); $settings['hseparator'] = new setting\setting_html( 'separator', (isset($settings['hseparator']) && is_string($settings['hseparator'])) ? $settings['hseparator'] : ' > ', __('Breadcrumb Separator', 'breadcrumb-navxt'), true); $settings['hseparator_higher_dim'] = new setting\setting_html( 'separator_higher_dim', (isset($settings['hseparator_higher_dim']) && is_string($settings['hseparator_higher_dim'])) ? $settings['hseparator_higher_dim'] : ', ', __('Breadcrumb Separator (Higher Dimension)', 'breadcrumb-navxt'), true); $settings['bcurrent_item_linked'] = new setting\setting_bool( 'current_item_linked', false, __('Link Current Item', 'breadcrumb-navxt')); $settings['Hpaged_template'] = new setting\setting_html( 'paged_template', sprintf('<span class="%%type%%">%1$s</span>', esc_attr__('Page %htitle%', 'breadcrumb-navxt')), _x('Paged Template', 'Paged as in when on an archive or post that is split into multiple pages', 'breadcrumb-navxt')); $settings['bpaged_display'] = new setting\setting_bool( 'paged_display', false, _x('Paged Breadcrumb', 'Paged as in when on an archive or post that is split into multiple pages', 'breadcrumb-navxt')); //Post types foreach($GLOBALS['wp_post_types'] as $post_type) { //If we somehow end up with the WP_Post_Types array having a non-WP_Post_Type object, we should skip it if(!($post_type instanceof WP_Post_Type)) { continue; } $settings['Hpost_' . $post_type->name . '_template'] = new setting\setting_html( 'post_' . $post_type->name . '_template', bcn_breadcrumb::get_default_template(), sprintf(__('%s Template', 'breadcrumb-navxt'), $post_type->labels->singular_name)); $settings['Hpost_' . $post_type->name . '_template_no_anchor'] = new setting\setting_html( 'post_' . $post_type->name . '_template_no_anchor', bcn_breadcrumb::default_template_no_anchor, sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $post_type->labels->singular_name)); //Root default depends on post type if($post_type->name === 'page') { $default_root = absint(get_option('page_on_front')); } else if($post_type->name === 'post') { $default_root = absint(get_option('page_for_posts')); } else { $default_root = 0; } $settings['apost_' . $post_type->name . '_root'] = new setting\setting_absint( 'post_' . $post_type->name . '_root', $default_root, sprintf(__('%s Root Page', 'breadcrumb-navxt'), $post_type->labels->singular_name)); //Archive display default depends on post type if($post_type->has_archive == true || is_string($post_type->has_archive)) { $default_archive_display = true; } else { $default_archive_display = false; } $settings['bpost_' . $post_type->name . '_archive_display'] = new setting\setting_bool( 'post_' . $post_type->name . '_archive_display', $default_archive_display, sprintf(__('%s Archive Display', 'breadcrumb-navxt'), $post_type->labels->singular_name)); $settings['bpost_' . $post_type->name . '_taxonomy_referer'] = new setting\setting_bool( 'post_' . $post_type->name . '_taxonomy_referer', false, sprintf(__('%s Hierarchy Referer Influence', 'breadcrumb-navxt'), $post_type->labels->singular_name)); //Hierarchy use parent first depends on post type if(in_array($post_type->name, array('page', 'post'))) { $default_parent_first = false; } else if($post_type->name === 'attachment') { $default_parent_first = true; } else { $default_parent_first = apply_filters('bcn_default_hierarchy_parent_first', false, $post_type->name); } $settings['bpost_' . $post_type->name . '_hierarchy_parent_first'] = new setting\setting_bool( 'post_' . $post_type->name . '_hierarchy_parent_first', $default_parent_first, sprintf(__('%s Hierarchy Use Parent First', 'breadcrumb-navxt'), $post_type->labels->singular_name)); //Hierarchy depends on post type if($post_type->name === 'page') { $hierarchy_type_allowed_values = array('BCN_POST_PARENT'); $hierarchy_type_default = 'BCN_POST_PARENT'; $default_hierarchy_display = true; } else { $hierarchy_type_allowed_values = array('BCN_POST_PARENT', 'BCN_DATE'); $hierarchy_type_default = 'BCN_POST_PARENT'; $default_hierarchy_display = false; //Loop through all of the possible taxonomies foreach($GLOBALS['wp_taxonomies'] as $taxonomy) { //Check for non-public taxonomies if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, $post_type->name)) { continue; } //Add valid taxonomies to list if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type)) { $hierarchy_type_allowed_values[] = $taxonomy->name; $default_hierarchy_display = true; //Only change from default on first valid taxonomy, if not a hierarchcial post type if($hierarchy_type_default === 'BCN_POST_PARENT') { $hierarchy_type_default = $taxonomy->name; } } } //For hierarchical post types and attachments, override whatever we may have done in the taxonomy finding if($post_type->hierarchical === true || $post_type->name === 'attachment') { $default_hierarchy_display = true; $hierarchy_type_default = 'BCN_POST_PARENT'; } } $settings['bpost_' . $post_type->name . '_hierarchy_display'] = new setting\setting_bool( 'post_' . $post_type->name . '_hierarchy_display', $default_hierarchy_display, sprintf(__('%s Hierarchy Display', 'breadcrumb-navxt'), $post_type->labels->singular_name)); $settings['Epost_' . $post_type->name . '_hierarchy_type'] = new setting\setting_enum( 'post_' . $post_type->name . '_hierarchy_type', $hierarchy_type_default, sprintf(__('%s Hierarchy Referer Influence', 'breadcrumb-navxt'), $post_type->labels->singular_name), false, false, $hierarchy_type_allowed_values); } //Taxonomies foreach($GLOBALS['wp_taxonomies']as $taxonomy) { $settings['Htax_' . $taxonomy->name. '_template'] = new setting\setting_html( 'tax_' . $taxonomy->name. '_template', __(sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %%title%% %s archives." href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', $taxonomy->labels->singular_name), 'breadcrumb-navxt'), sprintf(__('%s Template', 'breadcrumb-navxt'), $taxonomy->labels->singular_name)); $settings['Htax_' . $taxonomy->name. '_template_no_anchor'] = new setting\setting_html( 'tax_' . $taxonomy->name. '_template_no_anchor', bcn_breadcrumb::default_template_no_anchor, sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $taxonomy->labels->singular_name)); } //Miscellaneous $settings['H404_template'] = new setting\setting_html( '404_template', bcn_breadcrumb::get_default_template(), __('404 Template', 'breadcrumb-navxt')); $settings['S404_title'] = new setting\setting_string( '404_title', __('404', 'breadcrumb-navxt'), __('404 Title', 'breadcrumb-navxt')); $settings['Hsearch_template'] = new setting\setting_html( 'search_template', sprintf('<span property="itemListElement" typeof="ListItem"><span property="name">%1$s</span><meta property="position" content="%%position%%"></span>', sprintf(esc_attr__('Search results for '%1$s'', 'breadcrumb-navxt'), sprintf('<a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current>%%htitle%%</a>', esc_attr__('Go to the first page of search results for %title%.', 'breadcrumb-navxt')))), __('Search Template', 'breadcrumb-navxt')); $settings['Hsearch_template_no_anchor'] = new setting\setting_html( 'search_template_no_anchor', sprintf('<span class="%%type%%">%1$s</span>', sprintf(esc_attr__('Search results for '%1$s'', 'breadcrumb-navxt'), '%htitle%')), __('Search Template (Unlinked)', 'breadcrumb-navxt')); $settings['Hdate_template'] = new setting\setting_html( 'date_template', sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', esc_attr__('Go to the %title% archives.', 'breadcrumb-navxt')), __('Date Template', 'breadcrumb-navxt')); $settings['Hdate_template_no_anchor'] = new setting\setting_html( 'date_template_no_anchor', bcn_breadcrumb::default_template_no_anchor, __('Date Template (Unlinked)', 'breadcrumb-navxt')); $settings['Hauthor_template'] = new setting\setting_html( 'author_template', sprintf('<span property="itemListElement" typeof="ListItem"><span property="name">%1$s</span><meta property="position" content="%%position%%"></span>', sprintf(esc_attr__('Articles by: %1$s', 'breadcrumb-navxt'), sprintf('<a title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current>%%htitle%%</a>', esc_attr__('Go to the first page of posts by %title%.', 'breadcrumb-navxt')))), __('Author Template', 'breadcrumb-navxt')); $settings['Hauthor_template_no_anchor'] = new setting\setting_html( 'author_template_no_anchor', sprintf('<span class="%%type%%">%1$s</span>', sprintf(esc_attr__('Articles by: %1$s', 'breadcrumb-navxt'), '%htitle%')), __('Author Template (Unlinked)', 'breadcrumb-navxt')); $settings['aauthor_root'] = new setting\setting_absint( 'author_root', 0, __('Author Root Page', 'breadcrumb-navxt')); $settings['Eauthor_name'] = new setting\setting_enum( 'author_name', 'display_name', __('Author Display Format', 'breadcrumb-navxt'), false, false, array('display_name', 'nickname', 'first_name', 'last_name')); /** * Here are some deprecated settings */ $settings['blimit_title'] = new setting\setting_bool( 'limit_title', false, __('Limit Title Length', 'breadcrumb-navxt'), false, true); $settings['amax_title_length'] = new setting\setting_absint( 'max_title_length', 30, __('Maximum Title Length', 'breadcrumb-navxt'), false, true); } /** * Sets up the extended options for any CPTs, taxonomies or extensions * * @param array $opt The options array, passed by reference * @deprecated 7.0 */ static public function setup_options(&$opt) { //Do nothing by default, deprecated and keeping just for compatibility } /** * Hooks into the theme hook alliance tha_breadcrumb_navigation filter and replaces the trail * with one generated by Breadcrumb NavXT * * @param string $bradcrumb_trail The string breadcrumb trail that we will replace * @return string The Breadcrumb NavXT assembled breadcrumb trail */ public function tha_compat($breadcrumb_trail) { //Return our breadcrumb trail return $this->display(true); } public function show_paged() { return $this->settings['bpaged_display']->get_value(); } public function _display_post($post, $return = false, $linked = true, $reverse = false, $force = false, $template = '%1$s%2$s', $outer_template = '%1$s') { if($post instanceof WP_Post) { //If we're being forced to fill the trail, clear it before calling fill if($force) { $this->breadcrumb_trail->breadcrumbs = array(); } //Generate the breadcrumb trail $this->breadcrumb_trail->fill_REST($post); $trail_string = $this->breadcrumb_trail->display($linked, $reverse, $template); if($return) { return $trail_string; } else { //Helps track issues, please don't remove it $credits = "<!-- Breadcrumb NavXT " . $this::version . " -->\n"; echo $credits . $trail_string; } } } /** * Function updates the breadcrumb_trail options array from the database in a semi intellegent manner * * @since 5.0.0 */ private function get_settings() { //Convert our settings to opts $opts = adminKit::settings_to_opts($this->settings); //Run setup_options for compatibilty reasons breadcrumb_navxt::setup_options($opts); //TODO: Unit tests needed to ensure the expected behavior exists //Grab the current settings for the current local site from the db $this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $opts); //If we're in multisite mode, look at the three BCN_SETTINGS globals if(is_multisite()) { $multisite_opts = wp_parse_args(get_site_option('bcn_options'), $opts); if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK) { //Grab the current network wide settings $this->breadcrumb_trail->opt = $multisite_opts; } else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL) { //Grab the current local site settings and merge into network site settings + defaults $this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $multisite_opts); } else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK) { //Grab the current network site settings and merge into local site settings + defaults $this->breadcrumb_trail->opt = wp_parse_args(get_site_option('bcn_options'), $this->breadcrumb_trail->opt); } } //Currently only support using post_parent for the page hierarchy $this->breadcrumb_trail->opt['bpost_page_hierarchy_display'] = true; $this->breadcrumb_trail->opt['bpost_page_hierarchy_parent_first'] = true; $this->breadcrumb_trail->opt['Epost_page_hierarchy_type'] = 'BCN_POST_PARENT'; $this->breadcrumb_trail->opt['apost_page_root'] = get_option('page_on_front'); //This one isn't needed as it is performed in bcn_breadcrumb_trail::fill(), it's here for completeness only $this->breadcrumb_trail->opt['apost_post_root'] = get_option('page_for_posts'); } /** * Outputs the breadcrumb trail * * @param bool $return Whether to return or echo the trail. * @param bool $linked Whether to allow hyperlinks in the trail or not. * @param bool $reverse Whether to reverse the output or not. * @param bool $force Whether or not to force the fill function to run. * @param string $template The template to use for the string output. * @param string $outer_template The template to place an entire dimension of the trail into for all dimensions higher than 1. * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ public function display($return = false, $linked = true, $reverse = false, $force = false, $template = '%1$s%2$s', $outer_template = '%1$s') { //If we're being forced to fill the trail, clear it before calling fill if($force) { $this->breadcrumb_trail->breadcrumbs = array(); } //Generate the breadcrumb trail $this->breadcrumb_trail->fill($force); $trail_string = $this->breadcrumb_trail->display($linked, $reverse, $template, $outer_template); if($return) { return $trail_string; } else { //Helps track issues, please don't remove it $credits = "<!-- Breadcrumb NavXT " . $this::version . " -->\n"; echo $credits . $trail_string; } } /** * Outputs the breadcrumb trail with each element encapsulated with li tags * * @deprecated 6.0.0 No longer needed, superceeded by $template parameter in display * * @param bool $return Whether to return or echo the trail. * @param bool $linked Whether to allow hyperlinks in the trail or not. * @param bool $reverse Whether to reverse the output or not. * @param bool $force Whether or not to force the fill function to run. * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ public function display_list($return = false, $linked = true, $reverse = false, $force = false) { _deprecated_function( __FUNCTION__, '6.0', 'breadcrumb_navxt::display'); return $this->display($return, $linked, $reverse, $force, "<li%3\$s>%1\$s</li>\n"); } /** * Outputs the breadcrumb trail in Schema.org BreadcrumbList compatible JSON-LD * * @param bool $return Whether to return or echo the trail. * @param bool $reverse Whether to reverse the output or not. * @param bool $force Whether or not to force the fill function to run. * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ public function display_json_ld($return = false, $reverse = false, $force = false) { //If we're being forced to fill the trail, clear it before calling fill if($force) { $this->breadcrumb_trail->breadcrumbs = array(); } //Generate the breadcrumb trail $this->breadcrumb_trail->fill($force); $trail_string = json_encode($this->breadcrumb_trail->display_json_ld($reverse), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); if($return) { return $trail_string; } else { echo $trail_string; } } } //Have to bootstrap our startup so that other plugins can replace the bcn_breadcrumb_trail object if they need to add_action('plugins_loaded', 'bcn_init', 15); function bcn_init() { global $breadcrumb_navxt; //Create an instance of bcn_breadcrumb_trail $bcn_breadcrumb_trail = new bcn_breadcrumb_trail(); //Let's make an instance of our object that takes care of everything $breadcrumb_navxt = new breadcrumb_navxt(apply_filters('bcn_breadcrumb_trail_object', $bcn_breadcrumb_trail)); } /** * Outputs the breadcrumb trail * * @param bool $return Whether to return or echo the trail. (optional) * @param bool $linked Whether to allow hyperlinks in the trail or not. (optional) * @param bool $reverse Whether to reverse the output or not. (optional) * @param bool $force Whether or not to force the fill function to run. (optional) * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ function bcn_display($return = false, $linked = true, $reverse = false, $force = false) { global $breadcrumb_navxt; if($breadcrumb_navxt !== null) { return $breadcrumb_navxt->display($return, $linked, $reverse, $force); } } /** * Outputs the breadcrumb trail with each element encapsulated with li tags * * @param bool $return Whether to return or echo the trail. (optional) * @param bool $linked Whether to allow hyperlinks in the trail or not. (optional) * @param bool $reverse Whether to reverse the output or not. (optional) * @param bool $force Whether or not to force the fill function to run. (optional) * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ function bcn_display_list($return = false, $linked = true, $reverse = false, $force = false) { global $breadcrumb_navxt; if($breadcrumb_navxt !== null) { return $breadcrumb_navxt->display($return, $linked, $reverse, $force, "<li%3\$s>%1\$s</li>\n", "<ul>%1\$s</ul>\n"); } } /** * Outputs the breadcrumb trail in Schema.org BreadcrumbList compatible JSON-LD * * @param bool $return Whether to return or echo the trail. (optional) * @param bool $reverse Whether to reverse the output or not. (optional) * @param bool $force Whether or not to force the fill function to run. (optional) * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ function bcn_display_json_ld($return = false, $reverse = false, $force = false) { global $breadcrumb_navxt; if($breadcrumb_navxt !== null) { return $breadcrumb_navxt->display_json_ld($return, $reverse, $force); } } class.bcn_rest_controller.php 0000644 00000022016 14720660717 0012436 0 ustar 00 <?php /* Copyright 2015-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); //Do a PHP version check, require 5.3 or newer if(version_compare(phpversion(), '5.3.0', '<')) { //Only purpose of this function is to echo out the PHP version error function bcn_phpold() { printf('<div class="notice notice-error"><p>' . __('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0'); } //If we are in the admin, let's print a warning then return if(is_admin()) { add_action('admin_notices', 'bcn_phpold'); } return; } class bcn_rest_controller { const version = '1'; protected $unique_prefix = 'bcn'; protected $breadcrumb_trail = null; protected $methods = array('GET', 'OPTIONS'); /** * Default constructor * * @param bcn_breadcrumb_trail $breadcrumb_trail An instance of a bcn_breadcrumb_trail object to use for everything * @param string $unique_prefix The unique prefix to use for the API endpoint */ public function __construct(bcn_breadcrumb_trail $breadcrumb_trail, $unique_prefix) { $this->breadcrumb_trail = $breadcrumb_trail; $this->unique_prefix = $unique_prefix; add_action('rest_api_init', array($this, 'register_routes')); } /** * A quick wrapper for register_rest_route to add our inclusion filter * * @param string $endpoint The endpoint name passed into the bcn_register_rest_endpoint filter * @param string $namespace The first URL segment after core prefix. Should be unique * @param string $route The base URL for route being added * @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for * multiple methods. Default empty array. * @param bool $override Optional. If the route already exists, should we override it? * @return boolean True on success, false on error. */ protected function register_rest_route($endpoint, $namespace, $route, $args = array(), $override = false) { if(apply_filters('bcn_register_rest_endpoint', false, $endpoint, $this::version, $this->methods)) { return register_rest_route($namespace, $route, $args, $override); } return false; } public function register_routes() { $this->register_rest_route('post', $this->unique_prefix . '/v' . $this::version, '/post/(?P<id>[\d]+)', array( 'args' => array( 'id' => array( 'description' => __('The ID of the post (any type) to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'), 'type' => 'integer', 'required' => true, 'validate_callback' => array($this, 'validate_id') ) ), 'methods' => $this->methods, 'callback' => array($this, 'display_rest_post'), 'permission_callback' => array($this, 'display_rest_post_permissions_check') ), false ); $this->register_rest_route('term', $this->unique_prefix . '/v' . $this::version, '/term/(?P<taxonomy>[\w-]+)/(?P<id>[\d]+)', array( 'args' => array( 'id' => array( 'description' => __('The ID of the term to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'), 'type' => 'integer', 'required' => true, 'validate_callback' => array($this, 'validate_id') ), 'taxonomy' => array( 'description' => __('The taxonomy of the term to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'), 'type' => 'string', 'required' => true, 'validate_callback' => array($this, 'validate_taxonomy') ) ), 'methods' => $this->methods, 'callback' => array($this, 'display_rest_term'), 'permission_callback' => '__return_true' ), false ); $this->register_rest_route('author', $this->unique_prefix . '/v' . $this::version, '/author/(?P<id>\d+)', array( 'args' => array( 'id' => array( 'description' => __('The ID of the author to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'), 'type' => 'integer', 'required' => true, 'validate_callback' => array($this, 'validate_id') ) ), 'methods' => $this->methods, 'callback' => array($this, 'display_rest_author'), 'permission_callback' => '__return_true' ), false ); } /** * Checks to see if the request ID looks like it could be an ID (numeric and greater than 0) * * @param mixed $param The parameter to validate * @param WP_REST_Request $request REST API request data * @param string $key The paramter key * @return bool Whether or not the ID is valid (or atleast looks valid) */ public function validate_id($param, $request, $key) { return is_numeric($param) && absint($param) > 0; } /** * Checks to see if the request taxonomy is a valid taxonomy * * @param mixed $param The parameter to validate * @param WP_REST_Request $request REST API request data * @param string $key The paramter key * @return bool Whether or not the ID is valid (or atleast looks valid) */ public function validate_taxonomy($param, $request, $key) { return taxonomy_exists(esc_attr($param)); } /** * Check permissions for the post * * @param WP_REST_Request $request The request to check the permissions on * @return bool | WP_Error Whether or not the user can view the requested post */ public function display_rest_post_permissions_check(WP_REST_Request $request) { $post = get_post(absint($request->get_param('id'))); if($post === null) { return true; } return $this->check_post_read_permission($post); } /** * Check to ensure the current user can read the post (and subsequently view its breadcrumb trail) * * @param WP_Post $post The post to check if the current user can view the breadcrumb trail for * @return bool Whether or not the post should be readable */ public function check_post_read_permission($post) { if(!($post instanceof WP_Post)) { return false; } $post_type = get_post_type_object($post->post_type); if(empty($post_type) || empty($post_type->show_in_rest)) { return false; } if($post->post_status === 'publish' || current_user_can($post_type->cap->read_post, $post->ID)) { return true; } $post_status_obj = get_post_status_object($post->post_status); if($post_status_obj && $post_status_obj->public) { return true; } if($post->post_status === 'inherit' && $post->post_parent > 0) { $parent = get_post($post->post_parent); if($parent) { return $this->check_post_read_permission($parent); } } if($post->post_status === 'inherit') { return true; } return false; } /** * Breadcrumb trail handler for REST requests for post breadcrumb trails * * @param WP_REST_Request $request REST API request data * @return STD_Object Basic object data of the Schema.org Breadcrumb List compatible breadcrumb trail */ public function display_rest_post(WP_REST_Request $request) { $post = get_post(absint($request->get_param('id'))); if($post instanceof WP_Post) { $this->breadcrumb_trail->breadcrumbs = array(); //Generate the breadcrumb trail $this->breadcrumb_trail->fill_REST($post); return $this->breadcrumb_trail->display_json_ld(false); } } /** * Breadcrumb trail handler for REST requests for term breadcrumb trails * * @param WP_REST_Request $request REST API request data * @return STD_Object Basic object data of the Schema.org Breadcrumb List compatible breadcrumb trail */ public function display_rest_term(WP_REST_Request $request) { $term = get_term(absint($request->get_param('id')), esc_attr($request->get_param('taxonomy'))); if($term instanceof WP_Term) { $this->breadcrumb_trail->breadcrumbs = array(); //Generate the breadcrumb trail $this->breadcrumb_trail->fill_REST($term); return $this->breadcrumb_trail->display_json_ld(false); } } /** * Breadcrumb trail handler for REST requests for term breadcrumb trails * * @param WP_REST_Request $request REST API request data * @return STD_Object Basic object data of the Schema.org Breadcrumb List compatible breadcrumb trail */ public function display_rest_author(WP_REST_Request $request) { $user = get_user_by('ID', absint($request->get_param('id')), esc_attr($request->get_param('taxonomy'))); if($user instanceof WP_User) { $this->breadcrumb_trail->breadcrumbs = array(); //Generate the breadcrumb trail $this->breadcrumb_trail->fill_REST($user); return $this->breadcrumb_trail->display_json_ld(false); } } } languages/breadcrumb-navxt.pot 0000644 00000070104 14720660717 0012516 0 ustar 00 # Copyright (C) 2016 Breadcrumb NavXT # This file is distributed under the same license as the Breadcrumb NavXT package. msgid "" msgstr "" "Project-Id-Version: Breadcrumb NavXT 5.5.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/breadcrumb-navxt\n" "POT-Creation-Date: 2016-08-13 19:01:09+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" #: breadcrumb-navxt.php:35 class.bcn_admin.php:25 #: class.bcn_network_admin.php:25 msgid "" "Your PHP version is too old, please upgrade to a newer version. Your version " "is %1$s, Breadcrumb NavXT requires %2$s" msgstr "" #: class.bcn_admin.php:64 msgid "Breadcrumb NavXT Settings" msgstr "" #: class.bcn_admin.php:295 class.bcn_network_admin.php:366 msgid "Tips for the settings are located below select options." msgstr "" #: class.bcn_admin.php:296 class.bcn_network_admin.php:367 msgid "Resources" msgstr "" #: class.bcn_admin.php:297 class.bcn_network_admin.php:368 msgid "" "%sTutorials and How Tos%s: There are several guides, tutorials, and how tos " "available on the author's website." msgstr "" #: class.bcn_admin.php:297 class.bcn_network_admin.php:368 msgid "Go to the Breadcrumb NavXT tag archive." msgstr "" #: class.bcn_admin.php:298 class.bcn_network_admin.php:369 msgid "" "%sOnline Documentation%s: Check out the documentation for more indepth " "technical information." msgstr "" #: class.bcn_admin.php:298 class.bcn_network_admin.php:369 msgid "Go to the Breadcrumb NavXT online documentation" msgstr "" #: class.bcn_admin.php:299 class.bcn_network_admin.php:370 msgid "" "%sReport a Bug%s: If you think you have found a bug, please include your " "WordPress version and details on how to reproduce the bug." msgstr "" #: class.bcn_admin.php:299 class.bcn_network_admin.php:370 msgid "Go to the Breadcrumb NavXT support post for your version." msgstr "" #: class.bcn_admin.php:300 class.bcn_network_admin.php:371 msgid "Giving Back" msgstr "" #: class.bcn_admin.php:301 class.bcn_network_admin.php:372 msgid "" "%sDonate%s: Love Breadcrumb NavXT and want to help development? Consider " "buying the author a beer." msgstr "" #: class.bcn_admin.php:301 class.bcn_network_admin.php:372 msgid "Go to PayPal to give a donation to Breadcrumb NavXT." msgstr "" #: class.bcn_admin.php:302 class.bcn_network_admin.php:373 msgid "" "%sTranslate%s: Is your language not available? Visit the Breadcrumb NavXT " "translation project on WordPress.org to start translating." msgstr "" #: class.bcn_admin.php:302 class.bcn_network_admin.php:373 msgid "Go to the Breadcrumb NavXT translation project." msgstr "" #: class.bcn_admin.php:307 class.bcn_admin.php:446 class.bcn_admin.php:447 #: class.bcn_network_admin.php:378 class.bcn_network_admin.php:518 #: class.bcn_network_admin.php:519 msgid "General" msgstr "" #: class.bcn_admin.php:310 class.bcn_network_admin.php:381 msgid "" "For the settings on this page to take effect, you must either use the " "included Breadcrumb NavXT widget, or place either of the code sections below " "into your theme." msgstr "" #: class.bcn_admin.php:311 class.bcn_network_admin.php:382 msgid "Breadcrumb trail with separators" msgstr "" #: class.bcn_admin.php:317 class.bcn_network_admin.php:388 msgid "Breadcrumb trail in list form" msgstr "" #: class.bcn_admin.php:326 class.bcn_network_admin.php:397 msgid "Quick Start" msgstr "" #: class.bcn_admin.php:329 class.bcn_network_admin.php:400 msgid "" "Using the code from the Quick Start section above, the following CSS can be " "used as base for styling your breadcrumb trail." msgstr "" #: class.bcn_admin.php:341 class.bcn_network_admin.php:412 msgid "Styling" msgstr "" #: class.bcn_admin.php:347 class.bcn_network_admin.php:418 msgid "Import/Export/Reset" msgstr "" #: class.bcn_admin.php:371 class.bcn_network_admin.php:442 #: includes/class.mtekk_adminkit.php:841 msgid "Import" msgstr "" #: class.bcn_admin.php:372 class.bcn_network_admin.php:443 #: includes/class.mtekk_adminkit.php:842 msgid "Export" msgstr "" #: class.bcn_admin.php:373 class.bcn_network_admin.php:444 #: includes/class.mtekk_adminkit.php:843 msgid "Reset" msgstr "" #: class.bcn_admin.php:391 msgid "" "Warning: Your network settings will override any settings set in this page." msgstr "" #: class.bcn_admin.php:395 class.bcn_admin.php:399 msgid "" "Warning: Your network settings may override any settings set in this page." msgstr "" #: class.bcn_admin.php:404 class.bcn_network_admin.php:475 msgid "" "Warning: No BCN_SETTINGS_* define statement found, defaulting to " "BCN_SETTINGS_USE_LOCAL." msgstr "" #: class.bcn_admin.php:416 class.bcn_network_admin.php:488 msgid "" "Warning: Your are using a deprecated setting \"Title Length\" (see " "Miscellaneous > Deprecated), please %1$suse CSS instead%2$s." msgstr "" #: class.bcn_admin.php:416 class.bcn_admin.php:704 #: class.bcn_network_admin.php:488 class.bcn_network_admin.php:776 msgid "Go to the guide on trimming breadcrumb title lengths with CSS" msgstr "" #: class.bcn_admin.php:446 class.bcn_network_admin.php:518 msgid "" "A collection of settings most likely to be modified are located under this " "tab." msgstr "" #: class.bcn_admin.php:450 class.bcn_network_admin.php:522 msgid "Breadcrumb Separator" msgstr "" #: class.bcn_admin.php:450 class.bcn_network_admin.php:522 msgid "Placed in between each breadcrumb." msgstr "" #: class.bcn_admin.php:454 class.bcn_network_admin.php:526 msgid "Current Item" msgstr "" #: class.bcn_admin.php:457 class.bcn_network_admin.php:529 msgid "Link Current Item" msgstr "" #: class.bcn_admin.php:457 class.bcn_network_admin.php:529 msgid "Yes" msgstr "" #: class.bcn_admin.php:458 class.bcn_network_admin.php:530 msgctxt "" "Paged as in when on an archive or post that is split into multiple pages" msgid "Paged Breadcrumb" msgstr "" #: class.bcn_admin.php:458 class.bcn_network_admin.php:530 msgid "Place the page number breadcrumb in the trail." msgstr "" #: class.bcn_admin.php:458 class.bcn_network_admin.php:530 msgid "" "Indicates that the user is on a page other than the first of a paginated " "archive or post." msgstr "" #: class.bcn_admin.php:459 class.bcn_network_admin.php:531 msgctxt "" "Paged as in when on an archive or post that is split into multiple pages" msgid "Paged Template" msgstr "" #: class.bcn_admin.php:459 class.bcn_network_admin.php:531 msgid "The template for paged breadcrumbs." msgstr "" #: class.bcn_admin.php:463 class.bcn_admin.php:466 #: class.bcn_network_admin.php:535 class.bcn_network_admin.php:538 msgid "Home Breadcrumb" msgstr "" #: class.bcn_admin.php:466 class.bcn_network_admin.php:538 msgid "Place the home breadcrumb in the trail." msgstr "" #: class.bcn_admin.php:467 class.bcn_network_admin.php:539 msgid "Home Template" msgstr "" #: class.bcn_admin.php:467 class.bcn_network_admin.php:539 msgid "The template for the home breadcrumb." msgstr "" #: class.bcn_admin.php:468 class.bcn_network_admin.php:540 msgid "Home Template (Unlinked)" msgstr "" #: class.bcn_admin.php:468 class.bcn_network_admin.php:540 msgid "" "The template for the home breadcrumb, used when the breadcrumb is not linked." msgstr "" #: class.bcn_admin.php:472 class.bcn_admin.php:475 #: class.bcn_network_admin.php:544 class.bcn_network_admin.php:547 msgid "Blog Breadcrumb" msgstr "" #: class.bcn_admin.php:475 class.bcn_network_admin.php:547 msgid "Place the blog breadcrumb in the trail." msgstr "" #: class.bcn_admin.php:476 class.bcn_network_admin.php:548 msgid "Blog Template" msgstr "" #: class.bcn_admin.php:476 class.bcn_network_admin.php:548 msgid "" "The template for the blog breadcrumb, used only in static front page " "environments." msgstr "" #: class.bcn_admin.php:477 class.bcn_network_admin.php:549 msgid "Blog Template (Unlinked)" msgstr "" #: class.bcn_admin.php:477 class.bcn_network_admin.php:549 msgid "" "The template for the blog breadcrumb, used only in static front page " "environments and when the breadcrumb is not linked." msgstr "" #: class.bcn_admin.php:481 class.bcn_network_admin.php:553 msgid "Mainsite Breadcrumb" msgstr "" #: class.bcn_admin.php:484 class.bcn_network_admin.php:556 msgid "Main Site Breadcrumb" msgstr "" #: class.bcn_admin.php:484 class.bcn_network_admin.php:556 msgid "Place the main site home breadcrumb in the trail in an multisite setup." msgstr "" #: class.bcn_admin.php:485 class.bcn_network_admin.php:557 msgid "Main Site Home Template" msgstr "" #: class.bcn_admin.php:485 class.bcn_network_admin.php:557 msgid "" "The template for the main site home breadcrumb, used only in multisite " "environments." msgstr "" #: class.bcn_admin.php:486 class.bcn_network_admin.php:558 msgid "Main Site Home Template (Unlinked)" msgstr "" #: class.bcn_admin.php:486 class.bcn_network_admin.php:558 msgid "" "The template for the main site home breadcrumb, used only in multisite " "environments and when the breadcrumb is not linked." msgstr "" #: class.bcn_admin.php:493 class.bcn_network_admin.php:565 msgid "" "The settings for all post types (Posts, Pages, and Custom Post Types) are " "located under this tab." msgstr "" #: class.bcn_admin.php:493 class.bcn_network_admin.php:565 msgid "Post Types" msgstr "" #: class.bcn_admin.php:494 class.bcn_network_admin.php:566 msgid "Posts" msgstr "" #: class.bcn_admin.php:497 class.bcn_network_admin.php:569 msgid "Post Template" msgstr "" #: class.bcn_admin.php:497 class.bcn_network_admin.php:569 msgid "The template for post breadcrumbs." msgstr "" #: class.bcn_admin.php:498 class.bcn_network_admin.php:570 msgid "Post Template (Unlinked)" msgstr "" #: class.bcn_admin.php:498 class.bcn_network_admin.php:570 msgid "" "The template for post breadcrumbs, used only when the breadcrumb is not " "linked." msgstr "" #: class.bcn_admin.php:499 class.bcn_network_admin.php:571 msgid "Post Hierarchy Display" msgstr "" #: class.bcn_admin.php:499 class.bcn_network_admin.php:571 msgid "" "Show the hierarchy (specified below) leading to a post in the breadcrumb " "trail." msgstr "" #: class.bcn_admin.php:500 class.bcn_network_admin.php:572 msgid "Post Hierarchy Referer Influence" msgstr "" #: class.bcn_admin.php:500 class.bcn_admin.php:578 #: class.bcn_network_admin.php:572 class.bcn_network_admin.php:650 msgid "" "Allow the refereing page to influence the taxonomy selected for the " "hierarchy." msgstr "" #: class.bcn_admin.php:504 class.bcn_network_admin.php:576 msgid "Post Hierarchy" msgstr "" #: class.bcn_admin.php:508 class.bcn_admin.php:627 #: class.bcn_network_admin.php:580 class.bcn_network_admin.php:699 msgid "Categories" msgstr "" #: class.bcn_admin.php:509 class.bcn_admin.php:588 #: class.bcn_network_admin.php:581 class.bcn_network_admin.php:660 msgid "Dates" msgstr "" #: class.bcn_admin.php:510 class.bcn_admin.php:634 #: class.bcn_network_admin.php:582 class.bcn_network_admin.php:706 msgid "Tags" msgstr "" #: class.bcn_admin.php:512 class.bcn_admin.php:587 #: class.bcn_network_admin.php:584 class.bcn_network_admin.php:659 msgid "Post Parent" msgstr "" #: class.bcn_admin.php:528 class.bcn_admin.php:612 #: class.bcn_network_admin.php:600 class.bcn_network_admin.php:684 msgid "" "The hierarchy which the breadcrumb trail will show. Note that the \"Post " "Parent\" option may require an additional plugin to behave as expected since " "this is a non-hierarchical post type." msgstr "" #: class.bcn_admin.php:532 class.bcn_network_admin.php:604 msgid "Pages" msgstr "" #: class.bcn_admin.php:535 class.bcn_network_admin.php:607 msgid "Page Template" msgstr "" #: class.bcn_admin.php:535 class.bcn_network_admin.php:607 msgid "The template for page breadcrumbs." msgstr "" #: class.bcn_admin.php:536 class.bcn_network_admin.php:608 msgid "Page Template (Unlinked)" msgstr "" #: class.bcn_admin.php:536 class.bcn_network_admin.php:608 msgid "" "The template for page breadcrumbs, used only when the breadcrumb is not " "linked." msgstr "" #: class.bcn_admin.php:539 class.bcn_network_admin.php:611 msgid "Attachments" msgstr "" #: class.bcn_admin.php:542 class.bcn_network_admin.php:614 msgid "Attachment Template" msgstr "" #: class.bcn_admin.php:542 class.bcn_network_admin.php:614 msgid "The template for attachment breadcrumbs." msgstr "" #: class.bcn_admin.php:543 class.bcn_network_admin.php:615 msgid "Attachment Template (Unlinked)" msgstr "" #: class.bcn_admin.php:543 class.bcn_network_admin.php:615 msgid "" "The template for attachment breadcrumbs, used only when the breadcrumb is " "not linked." msgstr "" #: class.bcn_admin.php:563 class.bcn_admin.php:665 #: class.bcn_network_admin.php:635 class.bcn_network_admin.php:737 msgid "%s Template" msgstr "" #: class.bcn_admin.php:563 class.bcn_admin.php:665 #: class.bcn_network_admin.php:635 class.bcn_network_admin.php:737 msgid "The template for %s breadcrumbs." msgstr "" #: class.bcn_admin.php:564 class.bcn_admin.php:666 #: class.bcn_network_admin.php:636 class.bcn_network_admin.php:738 msgid "%s Template (Unlinked)" msgstr "" #: class.bcn_admin.php:564 class.bcn_admin.php:666 #: class.bcn_network_admin.php:636 class.bcn_network_admin.php:738 msgid "" "The template for %s breadcrumbs, used only when the breadcrumb is not linked." msgstr "" #: class.bcn_admin.php:569 class.bcn_network_admin.php:641 msgid "%s Root Page" msgstr "" #: class.bcn_admin.php:572 class.bcn_network_admin.php:644 msgid "— Select —" msgstr "" #: class.bcn_admin.php:576 class.bcn_network_admin.php:648 msgid "%s Archive Display" msgstr "" #: class.bcn_admin.php:576 class.bcn_network_admin.php:648 msgid "" "Show the breadcrumb for the %s post type archives in the breadcrumb trail." msgstr "" #: class.bcn_admin.php:577 class.bcn_network_admin.php:649 msgid "%s Hierarchy Display" msgstr "" #: class.bcn_admin.php:577 class.bcn_network_admin.php:649 msgid "" "Show the hierarchy (specified below) leading to a %s in the breadcrumb trail." msgstr "" #: class.bcn_admin.php:578 class.bcn_network_admin.php:650 msgid "%s Hierarchy Referer Influence" msgstr "" #: class.bcn_admin.php:582 class.bcn_network_admin.php:654 msgid "%s Hierarchy" msgstr "" #: class.bcn_admin.php:608 class.bcn_network_admin.php:680 msgid "The hierarchy which the breadcrumb trail will show." msgstr "" #: class.bcn_admin.php:626 class.bcn_network_admin.php:698 msgid "" "The settings for all taxonomies (including Categories, Tags, and custom " "taxonomies) are located under this tab." msgstr "" #: class.bcn_admin.php:626 class.bcn_network_admin.php:698 msgid "Taxonomies" msgstr "" #: class.bcn_admin.php:630 class.bcn_network_admin.php:702 msgid "Category Template" msgstr "" #: class.bcn_admin.php:630 class.bcn_network_admin.php:702 msgid "The template for category breadcrumbs." msgstr "" #: class.bcn_admin.php:631 class.bcn_network_admin.php:703 msgid "Category Template (Unlinked)" msgstr "" #: class.bcn_admin.php:631 class.bcn_network_admin.php:703 msgid "" "The template for category breadcrumbs, used only when the breadcrumb is not " "linked." msgstr "" #: class.bcn_admin.php:637 class.bcn_network_admin.php:709 msgid "Tag Template" msgstr "" #: class.bcn_admin.php:637 class.bcn_network_admin.php:709 msgid "The template for tag breadcrumbs." msgstr "" #: class.bcn_admin.php:638 class.bcn_network_admin.php:710 msgid "Tag Template (Unlinked)" msgstr "" #: class.bcn_admin.php:638 class.bcn_network_admin.php:710 msgid "" "The template for tag breadcrumbs, used only when the breadcrumb is not " "linked." msgstr "" #: class.bcn_admin.php:641 class.bcn_network_admin.php:713 msgid "Post Formats" msgstr "" #: class.bcn_admin.php:644 class.bcn_network_admin.php:716 msgid "Post Format Template" msgstr "" #: class.bcn_admin.php:644 class.bcn_network_admin.php:716 msgid "The template for post format breadcrumbs." msgstr "" #: class.bcn_admin.php:645 class.bcn_network_admin.php:717 msgid "Post Format Template (Unlinked)" msgstr "" #: class.bcn_admin.php:645 class.bcn_network_admin.php:717 msgid "" "The template for post_format breadcrumbs, used only when the breadcrumb is " "not linked." msgstr "" #: class.bcn_admin.php:675 class.bcn_network_admin.php:747 msgid "" "The settings for author and date archives, searches, and 404 pages are " "located under this tab." msgstr "" #: class.bcn_admin.php:675 class.bcn_admin.php:684 #: class.bcn_network_admin.php:747 class.bcn_network_admin.php:756 msgid "Miscellaneous" msgstr "" #: class.bcn_admin.php:676 class.bcn_network_admin.php:748 msgid "Author Archives" msgstr "" #: class.bcn_admin.php:679 class.bcn_network_admin.php:751 msgid "Author Template" msgstr "" #: class.bcn_admin.php:679 class.bcn_network_admin.php:751 msgid "The template for author breadcrumbs." msgstr "" #: class.bcn_admin.php:680 class.bcn_network_admin.php:752 msgid "Author Template (Unlinked)" msgstr "" #: class.bcn_admin.php:680 class.bcn_network_admin.php:752 msgid "" "The template for author breadcrumbs, used only when the breadcrumb is not " "linked." msgstr "" #: class.bcn_admin.php:681 class.bcn_network_admin.php:753 msgid "Author Display Format" msgstr "" #: class.bcn_admin.php:681 class.bcn_network_admin.php:753 msgid "" "display_name uses the name specified in \"Display name publicly as\" under " "the user profile the others correspond to options in the user profile." msgstr "" #: class.bcn_admin.php:687 class.bcn_network_admin.php:759 msgid "Date Template" msgstr "" #: class.bcn_admin.php:687 class.bcn_network_admin.php:759 msgid "The template for date breadcrumbs." msgstr "" #: class.bcn_admin.php:688 class.bcn_network_admin.php:760 msgid "Date Template (Unlinked)" msgstr "" #: class.bcn_admin.php:688 class.bcn_network_admin.php:760 msgid "" "The template for date breadcrumbs, used only when the breadcrumb is not " "linked." msgstr "" #: class.bcn_admin.php:689 class.bcn_network_admin.php:761 msgid "Search Template" msgstr "" #: class.bcn_admin.php:689 class.bcn_network_admin.php:761 msgid "" "The anchor template for search breadcrumbs, used only when the search " "results span several pages." msgstr "" #: class.bcn_admin.php:690 class.bcn_network_admin.php:762 msgid "Search Template (Unlinked)" msgstr "" #: class.bcn_admin.php:690 class.bcn_network_admin.php:762 msgid "" "The anchor template for search breadcrumbs, used only when the search " "results span several pages and the breadcrumb is not linked." msgstr "" #: class.bcn_admin.php:691 class.bcn_network_admin.php:763 msgid "404 Title" msgstr "" #: class.bcn_admin.php:692 class.bcn_network_admin.php:764 msgid "404 Template" msgstr "" #: class.bcn_admin.php:692 class.bcn_network_admin.php:764 msgid "The template for 404 breadcrumbs." msgstr "" #: class.bcn_admin.php:695 class.bcn_network_admin.php:767 msgid "Deprecated" msgstr "" #: class.bcn_admin.php:699 class.bcn_network_admin.php:771 msgid "Title Length" msgstr "" #: class.bcn_admin.php:704 class.bcn_network_admin.php:776 msgid "" "Limit the length of the breadcrumb title. (Deprecated, %suse CSS instead%s)" msgstr "" #: class.bcn_admin.php:709 class.bcn_network_admin.php:781 msgid "Max Title Length: " msgstr "" #: class.bcn_admin.php:721 class.bcn_network_admin.php:793 msgid "Save Changes" msgstr "" #: class.bcn_breadcrumb.php:91 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><a property=\"item\" " "typeof=\"WebPage\" title=\"Go to %title%.\" href=\"%link%\" class=\"%type%" "\"><span property=\"name\">%htitle%</span></a><meta property=\"position\" " "content=\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:77 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><span property=\"name" "\">Page %htitle%</span><meta property=\"position\" content=\"%position%\"></" "span>" msgstr "" #: class.bcn_breadcrumb_trail.php:102 msgid "404" msgstr "" #: class.bcn_breadcrumb_trail.php:105 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><span property=\"name" "\">Search results for '<a property=\"item\" typeof=\"WebPage\" title=" "\"Go to the first page of search results for %title%.\" href=\"%link%\" " "class=\"%type%\">%htitle%</a>'</span><meta property=\"position\" content=" "\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:107 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><span property=\"name" "\">Search results for '%htitle%'</span><meta property=\"position\" " "content=\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:110 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><a property=\"item\" " "typeof=\"WebPage\" title=\"Go to the %title% tag archives.\" href=\"%link%\" " "class=\"%type%\"><span property=\"name\">%htitle%</span></a><meta property=" "\"position\" content=\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:115 class.bcn_breadcrumb_trail.php:131 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><a property=\"item\" " "typeof=\"WebPage\" title=\"Go to the %title% archives.\" href=\"%link%\" " "class=\"%type%\"><span property=\"name\">%htitle%</span></a><meta property=" "\"position\" content=\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:120 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><span property=\"name" "\">Articles by: <a title=\"Go to the first page of posts by %title%.\" href=" "\"%link%\" class=\"%type%\">%htitle%</a>" msgstr "" #: class.bcn_breadcrumb_trail.php:122 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><span property=\"name" "\">Articles by: %htitle%</span><meta property=\"position\" content=" "\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:127 msgid "" "<span property=\"itemListElement\" typeof=\"ListItem\"><a property=\"item\" " "typeof=\"WebPage\" title=\"Go to the %title% category archives.\" href=" "\"%link%\" class=\"%type%\"><span property=\"name\">%htitle%</span></a><meta " "property=\"position\" content=\"%position%\"></span>" msgstr "" #: class.bcn_breadcrumb_trail.php:465 msgid "$post global is not of type WP_Post" msgstr "" #: class.bcn_breadcrumb_trail.php:563 msgctxt "day archive breadcrumb date format" msgid "d" msgstr "" #: class.bcn_breadcrumb_trail.php:583 msgctxt "month archive breadcrumb date format" msgid "F" msgstr "" #: class.bcn_breadcrumb_trail.php:600 msgctxt "year archive breadcrumb date format" msgid "Y" msgstr "" #: class.bcn_network_admin.php:63 msgid "Breadcrumb NavXT Network Settings" msgstr "" #: class.bcn_network_admin.php:458 class.bcn_network_admin.php:476 msgid "" "Warning: Individual site settings will override any settings set in this " "page." msgstr "" #: class.bcn_network_admin.php:466 class.bcn_network_admin.php:470 msgid "" "Warning: Individual site settings may override any settings set in this page." msgstr "" #: class.bcn_widget.php:32 msgid "Adds a breadcrumb trail to your sidebar" msgstr "" #: class.bcn_widget.php:99 msgid "Title:" msgstr "" #: class.bcn_widget.php:103 msgid "Text to show before the trail:" msgstr "" #: class.bcn_widget.php:107 msgid "Output trail as:" msgstr "" #: class.bcn_widget.php:109 msgid "List" msgstr "" #: class.bcn_widget.php:110 msgid "Google (RDFa) Breadcrumbs" msgstr "" #: class.bcn_widget.php:111 msgid "Plain" msgstr "" #: class.bcn_widget.php:117 msgid "Link the breadcrumbs" msgstr "" #: class.bcn_widget.php:119 msgid "Reverse the order of the trail" msgstr "" #: class.bcn_widget.php:121 msgid "Hide the trail on the front page" msgstr "" #: includes/class.mtekk_adminkit.php:113 msgid "Insufficient privileges to proceed." msgstr "" #: includes/class.mtekk_adminkit.php:236 msgid "Settings" msgstr "" #: includes/class.mtekk_adminkit.php:312 msgid "" "Your settings are for an older version of this plugin and need to be " "migrated." msgstr "" #: includes/class.mtekk_adminkit.php:312 includes/class.mtekk_adminkit.php:321 msgid "Migrate the settings now." msgstr "" #: includes/class.mtekk_adminkit.php:312 msgid "Migrate now." msgstr "" #: includes/class.mtekk_adminkit.php:321 msgid "Your settings are for a newer version of this plugin." msgstr "" #: includes/class.mtekk_adminkit.php:321 msgid "Attempt back migration now." msgstr "" #: includes/class.mtekk_adminkit.php:329 msgid "Your plugin install is incomplete." msgstr "" #: includes/class.mtekk_adminkit.php:329 msgid "Load default settings now." msgstr "" #: includes/class.mtekk_adminkit.php:329 msgid "Complete now." msgstr "" #: includes/class.mtekk_adminkit.php:337 msgid "One or more of your plugin settings are invalid." msgstr "" #: includes/class.mtekk_adminkit.php:337 msgid "Attempt to fix settings now." msgstr "" #: includes/class.mtekk_adminkit.php:337 msgid "Fix now." msgstr "" #: includes/class.mtekk_adminkit.php:536 msgid "Settings successfully saved." msgstr "" #: includes/class.mtekk_adminkit.php:536 includes/class.mtekk_adminkit.php:549 msgid "Undo the options save." msgstr "" #: includes/class.mtekk_adminkit.php:536 includes/class.mtekk_adminkit.php:549 #: includes/class.mtekk_adminkit.php:654 includes/class.mtekk_adminkit.php:678 #: includes/class.mtekk_adminkit.php:695 msgid "Undo" msgstr "" #: includes/class.mtekk_adminkit.php:540 msgid "Settings did not change, nothing to save." msgstr "" #: includes/class.mtekk_adminkit.php:544 msgid "Settings were not saved." msgstr "" #: includes/class.mtekk_adminkit.php:549 msgid "Some settings were not saved." msgstr "" #: includes/class.mtekk_adminkit.php:550 msgid "The following settings were not saved:" msgstr "" #: includes/class.mtekk_adminkit.php:555 msgid "Please include this message in your %sbug report%s." msgstr "" #: includes/class.mtekk_adminkit.php:555 msgid "Go to the %s support post for your version." msgstr "" #: includes/class.mtekk_adminkit.php:654 msgid "Settings successfully imported from the uploaded file." msgstr "" #: includes/class.mtekk_adminkit.php:654 msgid "Undo the options import." msgstr "" #: includes/class.mtekk_adminkit.php:659 msgid "Importing settings from file failed." msgstr "" #: includes/class.mtekk_adminkit.php:678 msgid "Settings successfully reset to the default values." msgstr "" #: includes/class.mtekk_adminkit.php:678 msgid "Undo the options reset." msgstr "" #: includes/class.mtekk_adminkit.php:695 msgid "Settings successfully undid the last operation." msgstr "" #: includes/class.mtekk_adminkit.php:695 msgid "Undo the last undo operation." msgstr "" #: includes/class.mtekk_adminkit.php:730 msgid "Settings successfully migrated." msgstr "" #: includes/class.mtekk_adminkit.php:737 msgid "Default settings successfully installed." msgstr "" #: includes/class.mtekk_adminkit.php:833 msgid "" "Import settings from a XML file, export the current settings to a XML file, " "or reset to the default settings." msgstr "" #: includes/class.mtekk_adminkit.php:836 msgid "Settings File" msgstr "" #: includes/class.mtekk_adminkit.php:839 msgid "Select a XML settings file to upload and import settings from." msgstr "" #. Plugin Name of the plugin/theme msgid "Breadcrumb NavXT" msgstr "" #. Plugin URI of the plugin/theme msgid "http://mtekk.us/code/breadcrumb-navxt/" msgstr "" #. Description of the plugin/theme msgid "" "Adds a breadcrumb navigation showing the visitor's path to their current " "location. For details on how to use this plugin visit <a href=\"http://mtekk." "us/code/breadcrumb-navxt/\">Breadcrumb NavXT</a>." msgstr "" #. Author of the plugin/theme msgid "John Havlik" msgstr "" #. Author URI of the plugin/theme msgid "http://mtekk.us/" msgstr "" readme.txt 0000644 00000036772 14720660717 0006573 0 ustar 00 === Breadcrumb NavXT === Contributors: mtekk, hakre Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=FD5XEU783BR8U&lc=US&item_name=Breadcrumb%20NavXT%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted Tags: breadcrumb, breadcrumbs, trail, navigation, block Requires at least: 5.8 Tested up to: 6.5 Stable tag: 7.3.1 Requires PHP: 7.0 License: GPLv2 or later Adds breadcrumb navigation showing the visitor's path to their current location. == Description == Breadcrumb NavXT, the successor to the popular WordPress plugin Breadcrumb Navigation XT, was written from the ground up to be better than its ancestor. This plugin generates locational breadcrumb trails for your WordPress powered blog or website. These breadcrumb trails are highly customizable to suit the needs of just about any website running WordPress. The Administrative interface makes setting options easy, while a direct class access is available for theme developers and more adventurous users. = PHP Requirements = Breadcrumb NavXT 7.0 and newer require PHP7.0 Breadcrumb NavXT 5.2 and newer require PHP5.3 Breadcrumb NavXT 5.1.1 and older require PHP5.2 = Features (non-exhaustive) = * RDFa format Schema.org BreadcrumbList compatible breadcrumb generation. * Extensive breadcrumb customization control via a settings page with appropriate default values for most use cases. * Network admin settings page for managing breadcrumb settings for all subsites with [configurable global priority](http://mtekk.us/archives/guides/controlling-breadcrumb-navxt-settings-from-the-network-settings-page/ "Go to the article on configuring the network settings priority."). * Built in WordPress Widget. * Extensible via OOP and provided [actions](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/2/#action_reference "Go to the Breadcrumb NavXT Documentation's action reference.") and [filters](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/2/#filter_reference "Go to the Breadcrumb NavXT Documentation's filter reference."). * WPML compatible (enhanced compatibility with WPML extensions plugin). * Polylang compatible (enhanced compatibility with Polylang extensions plugin). * bbPress compatible (enhanced compatibility with bbPress extensions plugin). * BuddyPress compatible (enhanced compatibility with BuddyPress extensions plugin). = Translations = Breadcrumb NavXT now supports WordPress.org language packs. Want to translate Breadcrumb NavXT? Visit [Breadcrumb NavXT's WordPress.org translation project](https://translate.wordpress.org/projects/wp-plugins/breadcrumb-navxt/). == Installation == Breadcrumb NavXT can be installed from within WordPress’ administration panel. After installing and activating the plugin, to get breadcrumb trails to display either use the included widget, or call the breadcrumb trail in your theme (or child theme). See the [Calling the Breadcrumb Trail](http://mtekk.us/archives/guides/calling-the-breadcrumb-trail "Read more on calling the breadcrumb trail") article for more information on calling the breadcrumb trail. To customize the breadcrumb trail you may edit the default values for the options in the administrative interface. This is located in your administration panel under Settings > Breadcrumb NavXT. Please visit [Breadcrumb NavXT's Documentation](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/ "Go to Breadcrumb NavXT's Documentation.") page for more information. == Screenshots == 1. This screenshot shows 5 different examples of breadcrumbs generated by Breadcrumb NavXT 2. A screenshot of the General tab of the settings page 3. A screenshot of the Post Types tab of the settings page 4. A screenshot of the Taxonomies tab of the settings page 5. A screenshot of the Miscellaneous tab of the settings page 6. A screenshot of the Settings Import/Export/Reset form under the Help menu == Changelog == = 7.3.1 = Release date: June, 27th 2024 * Bug fix: Fixed issue where $force parameter wasn’t passed into `bcn_breadcrumb_trail::fill()` within `bcn_display*()` functions. * Bug fix: Fixed improper textdomain existing within `adminKit`. * Bug fix: Fixed issue with `$force` parameter where when it is not set the homepage breadcrumb would use the wrong template when calling the breadcrumb trail within the loop. = 7.3.0 = Release date: February, 9th 2024 * Behavior change: `bcn_display_json_ld()` now returns unescaped Unicode characters. * Behavior change: `$force` parameter in `bcn_display*()` functions is now passed to `bcn_breadcrumb_trail::fill()` allowing generation of trails within the loop for the current loop item instead of the parent page/resource. * New feature: Breadcrumb Trail block rewritten to have feature parity with Breadcrumb NavXT Widget. * New feature: Breadcrumb Trail block supports basic styling within block editor. * Bug fix: Fixed error where $outer_template argument was dropped within `breadcrumb_navxt::display()`. * Bug fix: Fixed issue where boolean settings were not exported/imported properly. * Bug fix: Fixed cause of PHP error in `bcn_breadcrumb_trail::maybe_add_post_type_arg()` when 3rd party code breaks the WP API. * Bug fix: Added check for proper queried object type for author archives. = 7.2.0 = Release date: February, 9th 2023 * Behavior change: Settings reset sets option entry to blank array, consistent with the change to only storing non-default values in the database. * New feature: Added `bcn_display_separator` filter. * New feature: Add per setting indication if Network wide settings are overriding the local setting. * Bug fix: Improved compatibility with PHP8.1. * Bug fix: Fixed PHP errors caused by unexpected entries in WP Post Types array. * Bug fix: Settings help menu now shows up in the network settings page. * Bug fix: Fixed cause of "file not found" error on the import/export/reset form in the network settings page. = 7.1.0 = Release date: July, 17th 2022 * Behavior change: BCN_SETTINGS_FAVOR_* constant behavior changed to take advantage of settings changes in 7.0. * Behavior change: Settings page now warns if it detected CPTs that were added too late. * New feature: Added bcn_before_loop filter which runs at the top of bcn_breadcrumb_trail::display_loop(). * New feature: Added JSON formatted settings import and export (successor to the old XML settings import/export format). * Bug fix: Fixed PHP error caused by term archives that don’t know the active term. * Bug fix: Fixed PHP error caused by introduction of namespacing in the legacy XML settings importer and exporter. * Bug fix: Explicitly set option autoload values, avoiding inappropriate default autoload values being used. = 7.0.2 = Release date: January, 4th 2022 * Behavior change: Allow value of `Hhome_template`, `Hhome_template_unlinked`, `hseparator`, and `hseparator_higher_dim` to be overridden via `bcn_settings_init`. * Bug fix: Fixed cause of “Sorry, you are not allowed to access this page.” message when attempting to visit the settings page. = 7.0.1 = Release date: December, 27th 2021 * Behavior change: Moved `bcn_settings_init` filter to before establishing default setting values. This filter is no longer capable of changing the default values of settings. * Behavior change: Moved setup of defaults to 9000 priority, intending to cover the majority of plugins that add CPTs. * Bug fix: Fixed compatibility issues with PHP5.6. * Bug fix: Fixed PHP error caused by some return value of page_ settings. * Bug fix: Fixed PHP error caused by non settings settings in array passed into `adminKit::settings_to_opts`. * Bug fix: Fixed issue with `bcn_allowed_html` not covering admin interface elements (mapped `bcn_allowed_html` to `mtekk_adminkit_allowed_html`). = 7.0.0 = Release date: December, 17th 2021 * Behavior change: Within the `bcn_breadcrumb_trail` object instead of passing term id and taxonomy, a WP_Term object is passed instead. * Behavior change: Attachments now use parent post type for post type argument. * New feature: Moved to adminKit 3.0 * New feature: Core `bcn_breadcrumb_trail object` now supports multi dimensional trails. * New feature: Added `bcn_opts_update_to_save` filter. * Bug fix: Fixed parameter order issue in REST controller that resulted in PHP Deprecated message in PHP8. * Bug fix: Updated REST controller endpoint registration for better WordPress 5.5+ compatibility. * Bug fix: Fixed compatibility issue with Widget settings not saving properly in WordPress 5.8. * Bug fix: Fixed issue with the position count parameter within bcn_display when outputting a trail in reverse order. = 6.6.0 = Release date: October, 31st 2020 * Behavior change: Moved to using the post type of the parent post for the type archive rather than that of the current item. * Bug fix: Fixed error thrown when a site does not have an `administrator` role. = 6.5.0 = Release date: June, 12th 2020 * Behavior change: Moved to using the taxonomy of the term rather than passed in taxonomy in various functions. As a consequence, this allows `bcn_pick_post_term` to override the taxonomy selection. * Behavior change: Default template for unlinked breadcrumbs now includes breadcrumbList markup. * New feature: Added new filter `bcn_breadcrumb_linked`. * New feature: Introduced new WordPress capability: `bnc_manage_options`. * Bug fix: Fixed XML settings exporter so that it no longer creates malformed files that cannot be imported when settings contain special HTML entities. = 6.4.0 = Release date: December, 31st 2019 * Behavior change: Attachment post type settings moved to Media, additional post type options made available. * Behavior change: Privately published parent posts are now, by default, skipped over in breadcrumb trails. * Behavior change: On single post breadcrumb trails, the hierarchical term code path is now used in cases where only a single term from a non-hierarchical taxonomy is present for the current post. * New feature: Allow `%link%` tag in unlinked breadcrumb templates. * New feature: Added `bcn_show_post_private` filter. * New feature: Added `bcn_show_type_term_archive` filter. = 6.3.0 = Release date: May, 3rd 2019 * New feature: Added Gutenberg block for displaying breadcrumb trails. * New feature: Added `bcn_display_attribute_array` filter. * New feature: Added `bcn-aria-current` template tag to facilitate WAI-ARIA Breadcrumb support. * Bug Fix: Updated settings page to follow WP core standards for header structure. * Bug Fix: Updated checkbox in adminKit to eliminate multiple labels to follow WCAG 2.0. * Bug Fix: Fixed PHP error in circumstances of `bcn_breadcrumb_trail::fill()` falling back on treating an unknown item as a taxonomy. = 6.2.1 = Release date: October, 26th 2018 * Behavior change: Added `span` element wrapping the breadcrumb title in the default unlinked breadcrumb template. * Bug fix: Fixed issue that caused PHP warnings and “the following settings were not saved” messages for hierarchical CPTs. = 6.2.0 = Release date: September, 24th 2018 * Behavior change: Cleaned up translations for default templates, simplifying and clarifying the translatable content. * Behavior change: Default unlinked breadcrumb templates no longer contain Schema.org BreadcrumbList markup. * Behavior change: Breadcrumb NavXT REST API endpoints are no longer enabled by default. * New feature: Added `bcn_register_rest_endpoint` filter. * New feature: Added `bcn_breadcrumb_assembled_json_ld_array` filter. * New feature: Added support for following the post parent hierarchy first then falling back to a secondary hierarchy. * Bug fix: Fixed issue where on loading the settings page immediately after migrating settings causes PHP warnings on CPT and custom taxonomy settings. * Bug fix: Fixed issue that caused the settings reset option under the help drop down to not work. = 6.1.0 = Release date: June, 1st 2018 * Behavior change: Links to generate support requests migrated to the WordPress.org forums. * New feature: Added support for Schema.org BreadcrumbList (microdata format) in the included widget. * New feature: Added new Root Page support for author archives. * New feature: Added REST API endpoint for posts, terms, and author archives. * Bug fix: Corrected label for the Schema.org BreadcrumbList (RDFa format) option in the included widget. * Bug fix: Fixed issue where a PHP warning would be thrown due to `get_term()` returning something other than an instance of `WP_Term`. = 6.0.4 = Release date: January, 26th 2018 * Behavior change: Added auto migration of post type hierarchy settings to `bcn_display*()` functions. * Bug fix: Fixed issue where a PHP notice would be generated on the page for posts when the blog breadcrumb display option is set to false. * Bug fix: Fixed issue where a PHP notice would be generated on archive pages where attachments were included in the `wp_query` results. = 6.0.3 = Release date: January, 1st 2018 * Bug fix: Fixed issue where an improper breadcrumb would be generated in the trail for pages under some circumstances. * Bug fix: Fixed issue where the post and page roots were not updating to track user changes in Settings > Reading. = 6.0.2 = Release date: December, 30th 2017 * Behavior change: Added warning alerting that `bcn_breadcrumb::type` must be an array. * Bug fix: Changed Breadcrumb Separator and Paged Template from an input field to a textbox to reduce confusion caused by HTML entities. * Bug fix: Fixed issue where the parents of a page may not show up in the breadcrumb trail. * Bug fix: Fixed issue where the `$reverse` parameter for `bcn_display` and `bcn_display_list` did not work properly. * Bug fix: Fixed issue where the `bcn_display_list` function did not include the `li` elements. = 6.0.1 = Release date: December, 28th 2017 * Behavior change: Removed unused Blog Template and Blog Template (Unlinked) from settings page. * Bug fix: Fixed issue where changes to the hierarchy type for any post type would not save. * Bug fix: Fixed issue where the blog display setting was ignored. = 6.0.0 = Release date: December, 26th 2017 * Behavior change: `bcn_breadcrumb_trail::display_list()` deprecated in favor of using the `$template` parameter in `bcn_breadcrumb_trail::display()`. * Behavior change: `bcn_breadcrumb_trail::do_attachment()` deprecated in favor of calling `bcn_breadcrumb_trail::do_post()`. * Behavior change: `bcn_breadcrumb_trail::do_front_page()` deprecated in favor of calling `bcn_breadcrumb_trail::do_home()`. * Behavior change: `bcn_li_attributes` filter was deprecated in favor of `bcn_display_attributes`. * Behavior change: `bcn_breadcrumb_trail::do_archive_by_date()` deprecated in favor of calling bcn_breadcrumb_trail::do_day()`, `bcn_breadcrumb_trail::do_month()`, and/or `bcn_breadcrumb_trail::do_year()`. * Behavior change: `bcn_breadcrumb_trail::find_type()` deprecated and removed from bcn_breadcrumb_trail. * Behavior change: Breadcrumb for 404 error pages changed to be a child of the front page. * New feature: Added support for various HTML tags in the widget's pretext field. * New feature: Added `bcn_default_hierarchy_display` filter. * New feature: Added `bcn_default_hierarchy_type` filter. * New feature: Added `$posttype_name` as the third parameter to `bcn_show_tax_private`. * Bug fix: Fixed UI/UX issue in the settings screen where enabling/disabling settings groups for the Home, Blog, and Mainsite breadcrumb settings did not work. * Bug fix: Fixed UI/UX issue in the settings screen where not including the paged breadcrumb still allowed the paged breadcrumb template to be edited. * Bug fix: Removed use of `create_function` in registering the widget as it was deprecated in PHP 7.2. == Upgrade Notice == = 7.1.0 = This version requires PHP7.0 or newer. This version introduces a new JSON settings import/export feature. class.bcn_breadcrumb_trail.php 0000644 00000157651 14720660717 0012535 0 ustar 00 <?php /* Copyright 2015-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); //The trail class class bcn_breadcrumb_trail { //Our member variables const version = '7.3.1'; //An array of breadcrumbs public $breadcrumbs = array(); public $trail = array(); //The options public $opt; //Default constructor public function __construct() { //@see https://core.trac.wordpress.org/ticket/10527 if(!is_textdomain_loaded('breadcrumb-navxt')) { load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages'); } $this->trail = &$this->breadcrumbs; //Initilize with default option values $this->opt = array( //Should the mainsite be shown 'bmainsite_display' => true, //The breadcrumb template for the main site 'Hmainsite_template' => bcn_breadcrumb::get_default_template(), //The breadcrumb template for the main site, used when an anchor is not needed 'Hmainsite_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //Should the home page be shown 'bhome_display' => true, //The breadcrumb template for the home page 'Hhome_template' => bcn_breadcrumb::get_default_template(), //The breadcrumb template for the home page, used when an anchor is not needed 'Hhome_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //Should the blog page be shown globally 'bblog_display' => true, //Separator that is placed between each item in the breadcrumb trial, but not placed before //the first and not after the last breadcrumb 'hseparator' => ' > ', //Separator that is placed between each item in the breadcrumb trial on the 2nd and higher dimensions, but not placed before //the first and not after the last breadcrumb 'hseparator_higher_dim' => ', ', //Whether or not we should trim the breadcrumb titles 'blimit_title' => false, //The maximum title length 'amax_title_length' => 20, //Current item options 'bcurrent_item_linked' => false, //Static page options //Should the trail include the hierarchy of the page 'bpost_page_hierarchy_display' => true, //Should the post parent be followed first for this type, then fallback to the hierarchy type 'bpost_page_hierarchy_parent_first' => false, //What hierarchy should be shown leading to the page 'Epost_page_hierarchy_type' => 'BCN_POST_PARENT', //The anchor template for page breadcrumbs 'Hpost_page_template' => bcn_breadcrumb::get_default_template(), //The anchor template for page breadcrumbs, used when an anchor is not needed 'Hpost_page_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //Just a link to the page on front property 'apost_page_root' => get_option('page_on_front'), //Paged options //The template for paged breadcrumb 'Hpaged_template' => sprintf('<span class="%%type%%">%1$s</span>', esc_attr__('Page %htitle%', 'breadcrumb-navxt')), //Should we try filling out paged information 'bpaged_display' => false, //The post options previously singleblogpost //The breadcrumb template for post breadcrumbs 'Hpost_post_template' => bcn_breadcrumb::get_default_template(), //The breadcrumb template for post breadcrumbs, used when an anchor is not needed 'Hpost_post_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //Just a link for the page for posts 'apost_post_root' => get_option('page_for_posts'), //Should the trail include the hierarchy of the post 'bpost_post_hierarchy_display' => true, //Should the post parent be followed first for this type, then fallback to the hierarchy type 'bpost_post_hierarchy_parent_first' => false, //Should the trail reflect the referer taxonomy or not 'bpost_post_taxonomy_referer' => false, //What hierarchy should be shown leading to the post, tag or category 'Epost_post_hierarchy_type' => 'category', //Attachment settings 'bpost_attachment_archive_display' => false, 'bpost_attachment_hierarchy_display' => true, //Should the post parent be followed first for this type, then fallback to the hierarchy type 'bpost_attachment_hierarchy_parent_first' => true, //Should the trail reflect the referer taxonomy or not 'bpost_attachment_taxonomy_referer' => false, //What hierarchy should be shown leading to the attachment 'Epost_attachment_hierarchy_type' => 'BCN_POST_PARENT', //Give an invlaid page ID for the attachement root 'apost_attachment_root' => 0, //The breadcrumb template for attachment breadcrumbs 'Hpost_attachment_template' => bcn_breadcrumb::get_default_template(), //The breadcrumb template for attachment breadcrumbs, used when an anchor is not needed 'Hpost_attachment_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //404 page settings //The template for 404 breadcrumbs 'H404_template' => bcn_breadcrumb::default_template_no_anchor, //The text to be shown in the breadcrumb for a 404 page 'S404_title' => __('404', 'breadcrumb-navxt'), //Search page options //The breadcrumb template for search breadcrumbs 'Hsearch_template' => sprintf('<span property="itemListElement" typeof="ListItem"><span property="name">%1$s</span><meta property="position" content="%%position%%"></span>', sprintf(esc_attr__('Search results for '%1$s'', 'breadcrumb-navxt'), sprintf('<a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current>%%htitle%%</a>', esc_attr__('Go to the first page of search results for %title%.', 'breadcrumb-navxt')))), //The breadcrumb template for search breadcrumbs, used when an anchor is not necessary 'Hsearch_template_no_anchor' => sprintf('<span class="%%type%%">%1$s</span>', sprintf(esc_attr__('Search results for '%1$s'', 'breadcrumb-navxt'), '%htitle%')), //Tag related stuff //The breadcrumb template for tag breadcrumbs 'Htax_post_tag_template' => sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', esc_attr__('Go to the %title% tag archives.', 'breadcrumb-navxt')), //The breadcrumb template for tag breadcrumbs, used when an anchor is not necessary 'Htax_post_tag_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //Post format related stuff //The breadcrumb template for post format breadcrumbs, used when an anchor is not necessary 'Htax_post_format_template' => sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', esc_attr__('Go to the %title% archives.', 'breadcrumb-navxt')), //The breadcrumb template for post format breadcrumbs 'Htax_post_format_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //Author page stuff //The anchor template for author breadcrumbs 'Hauthor_template' => sprintf('<span property="itemListElement" typeof="ListItem"><span property="name">%1$s</span><meta property="position" content="%%position%%"></span>', sprintf(esc_attr__('Articles by: %1$s', 'breadcrumb-navxt'), sprintf('<a title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current>%%htitle%%</a>', esc_attr__('Go to the first page of posts by %title%.', 'breadcrumb-navxt')))), //The anchor template for author breadcrumbs, used when anchors are not needed 'Hauthor_template_no_anchor' => sprintf('<span class="%%type%%">%1$s</span>', sprintf(esc_attr__('Articles by: %1$s', 'breadcrumb-navxt'), '%htitle%')), //Which of the various WordPress display types should the author breadcrumb display 'Eauthor_name' => 'display_name', //Give an invlaid page ID for the author root 'aauthor_root' => 0, //Category stuff //The breadcrumb template for category breadcrumbs 'Htax_category_template' => sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', esc_attr__('Go to the %title% category archives.', 'breadcrumb-navxt')), //The breadcrumb template for category breadcrumbs, used when anchors are not needed 'Htax_category_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, //The breadcrumb template for date breadcrumbs 'Hdate_template' => sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', esc_attr__('Go to the %title% archives.', 'breadcrumb-navxt')), //The breadcrumb template for date breadcrumbs, used when anchors are not needed 'Hdate_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor ); } /** * Adds a breadcrumb to the breadcrumb trail * * @param bcn_breadcrumb $object Breadcrumb to add to the trail * * @return pointer to the just added Breadcrumb */ public function &add(bcn_breadcrumb $object) { $this->breadcrumbs[] = $object; //Return the just added object return $this->breadcrumbs[count($this->breadcrumbs) - 1]; } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for a search page * * @param string $search_query The search query that was performed * @param bool $is_paged Whether or not the current resource is on a page other than page 1 */ protected function do_search($search_query, $is_paged = false) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add( new bcn_breadcrumb( $search_query, $this->opt['Hsearch_template_no_anchor'], array('search', 'current-item'), get_search_link($search_query))); //If we're paged, or allowing the current item to be linked, let's link to the first page if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display'])) { //Since we are paged and are linking the root breadcrumb, time to change to the regular template $breadcrumb->set_template($this->opt['Hsearch_template']); $breadcrumb->set_linked(true); } } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for an author page * * @param string $author_data The author to generate the breadcrumb for * @param bool $is_paged Whether or not the current resource is on a page other than page 1 */ protected function do_author($author_data, $is_paged = false) { //Setup array of valid author_name values $valid_author_name = array('display_name', 'nickname', 'first_name', 'last_name'); //Make sure user picks only safe values if(in_array($this->opt['Eauthor_name'], $valid_author_name)) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( get_the_author_meta($this->opt['Eauthor_name'], $author_data->ID), $this->opt['Hauthor_template_no_anchor'], array('author', 'current-item'), get_author_posts_url($author_data->ID), $author_data->ID)); //If we're paged, or allowing the current item to be linked, let's link to the first page if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display'])) { //Set the template to our one containing an anchor $breadcrumb->set_template($this->opt['Hauthor_template']); $breadcrumb->set_linked(true); } } } /** * Determines the taxonomy name represented by the specified query var * * @param string $query_var The query var to attempt to find the corresponding taxonomy * * @return string|bool Either the name of the taxonomy corresponding to the query_var or false if no taxonomy exists for the specified query_var */ protected function query_var_to_taxonomy($query_var) { global $wp_taxonomies; foreach($wp_taxonomies as $taxonomy) { if($taxonomy->query_var === $query_var) { return $taxonomy->name; } } return false; } /** * Determines the referer taxonomy * * @return string|bool Either the name of the taxonomy to use or false if a referer taxonomy wasn't found */ protected function determine_taxonomy() { global $wp; //Backup the server request variable $bk_req = $_SERVER['REQUEST_URI']; //Now set the request URL to the referrer URL //Could just chain the [1] selection, but that's not PHP5.3 compatible $url_split = explode(home_url(), esc_url(wp_get_referer())); if(isset($url_split[1])) { $_SERVER['REQUEST_URI'] = $url_split[1]; } else { return false; } //Create our own new instance of WP, and have it parse our faux request $bcn_wp = new WP(); //Copy over the current global wp object's query_vars since CPTs and taxonomies are added directly to the global $wp $bcn_wp->public_query_vars = $wp->public_query_vars; $bcn_wp->parse_request(); $_SERVER['REQUEST_URI'] = $bk_req; if(is_array($bcn_wp->query_vars)) { foreach($bcn_wp->query_vars as $query_var => $value) { if($taxonomy = $this->query_var_to_taxonomy($query_var)) { return $taxonomy; } } } return false; } /** * This function selects the term that should be used for a post's hierarchy * * @param int $id The ID of the post to find the term for * @param string $type The post type of the post to figure out the taxonomy for * @param string $taxonomy The taxonomy to use * * @return WP_Term|bool The term object to use for the post hierarchy or false if no suitable term was found */ protected function pick_post_term($id, $type, $taxonomy) { //Fill a temporary object with the terms $bcn_object = get_the_terms($id, $taxonomy); $potential_parent = 0; //Make sure we have an non-empty array if(is_array($bcn_object)) { //Now try to find the deepest term of those that we know of $bcn_use_term = key($bcn_object); foreach($bcn_object as $key => $object) { //Can't use the next($bcn_object) trick since order is unknown if($object->parent > 0 && ($potential_parent === 0 || $object->parent === $potential_parent)) { $bcn_use_term = $key; $potential_parent = $object->term_id; } } return $bcn_object[$bcn_use_term]; } return false; } /** * A Breadcrumb Trail Filling Function * * This function fills breadcrumbs for any post taxonomy * * @param int $id The id of the post to figure out the taxonomy for * @param string $type The post type of the post to figure out the taxonomy for * @param int $parent (optional) The id of the parent of the current post, used if hiearchal posts will be the "taxonomy" for the current post */ protected function post_hierarchy($id, $type, $parent = null) { //Check to see if breadcrumbs for the hierarchy of the post needs to be generated if($this->opt['bpost_' . $type . '_hierarchy_display']) { //Check if we have a date 'taxonomy' request if($this->opt['Epost_' . $type . '_hierarchy_type'] === 'BCN_DATE') { $post = get_post($id); $this->do_day($post, $type, false, false); $this->do_month($post, $type, false, false); $this->do_year($post, $type, false, false); } //Handle the use of hierarchical posts as the 'taxonomy' else if($this->opt['Epost_' . $type . '_hierarchy_type'] === 'BCN_POST_PARENT') { if($parent == null) { //We have to grab the post to find its parent, can't use $post for this one $parent = get_post($id); //TODO should we check that we have a WP_Post object here? $parent = $parent->post_parent; } //Grab the frontpage, we'll need it shortly $frontpage = get_option('page_on_front'); //If there is a parent page let's find it if($parent > 0 && $id != $parent && $frontpage != $parent) { $parent = $this->post_parents($parent, $frontpage); } } else { $taxonomy = $this->opt['Epost_' . $type . '_hierarchy_type']; //Possibly let the referer influence the taxonomy used if($this->opt['bpost_' . $type . '_taxonomy_referer'] && $referrer_taxonomy = $this->determine_taxonomy()) { //See if there were any terms, if so, we can use the referrer influenced taxonomy $terms = get_the_terms($id, $referrer_taxonomy); if(is_array($terms)) { $taxonomy = $referrer_taxonomy; } } //Handle all hierarchical taxonomies, including categories if(is_taxonomy_hierarchical($taxonomy)) { //Filter the results of post_pick_term $term = apply_filters('bcn_pick_post_term', $this->pick_post_term($id, $type, $taxonomy), $id, $type, $taxonomy); //Only do something if we found a term if($term instanceof WP_Term) { //Fill out the term hiearchy $parent = $this->term_parents($term, $type); } } //Handle the rest of the taxonomies, including tags else { $this->post_terms($id, $taxonomy); } } } //If we never got a good parent for the type_archive, make it now if(!($parent instanceof WP_Post)) { $parent = get_post($id); } //Finish off with trying to find the type archive $this->maybe_do_archive_by_post_type($parent->post_type); } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for the terms of a post * * @param int $id The id of the post to find the terms for * @param string $taxonomy The name of the taxonomy that the term belongs to * * TODO Need to implement this cleaner */ protected function post_terms($id, $taxonomy) { //Apply a filter to the terms for the post referred to by ID $bcn_terms = apply_filters('bcn_post_terms', get_the_terms($id, $taxonomy), $taxonomy, $id); //Only process if we have terms if(is_array($bcn_terms)) { //For single terms, treat as if they are hierarchical if(count($bcn_terms) === 1 && $bcn_terms[0] instanceof WP_Term) { return $this->term_parents($bcn_terms[0], get_post_type($id)); } $title = ''; $is_first = true; //Loop through all of the term results foreach($bcn_terms as $term) { //Everything but the first term needs a comma separator if($is_first == false) { $title .= ', '; } //This is a bit hackish, but it compiles the term anchor and appends it to the current breadcrumb title $title .= str_replace( array('%title%', '%link%', '%htitle%', '%type%'), array($term->name, $this->maybe_add_post_type_arg(get_term_link($term), null, $term->taxonomy), $term->name, $term->taxonomy), $this->opt['Htax_' . $term->taxonomy . '_template']); $is_first = false; } //Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb($title, '%htitle%', array('taxonomy', $taxonomy))); } } /** * A Breadcrumb Trail Filling Function * * This recursive functions fills the trail with breadcrumbs for parent terms * * @param WP_Term $term The term object to generate breadcrumbs for * @param string|null $type The post type string to use for determining whether or not to add the post type argument * * @return WP_Term|WP_Error The term we stopped at */ protected function term_parents($term, $type = null) { if($term instanceof WP_Term) { //Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( $term->name, $this->opt['Htax_' . $term->taxonomy . '_template'], array('taxonomy', $term->taxonomy), $this->maybe_add_post_type_arg(get_term_link($term), $type, $term->taxonomy), $term->term_id, true)); //Make sure the id is valid, and that we won't end up spinning in a loop if($term->parent && $term->parent != $term->term_id) { //Figure out the rest of the term hiearchy via recursion $ret_term = $this->term_parents(get_term($term->parent, $term->taxonomy), $type); //May end up with WP_Error, don't update the term if that's the case if($ret_term instanceof WP_Term) { $term = $ret_term; } } } return $term; } /** * A Breadcrumb Trail Filling Function * * This recursive functions fills the trail with breadcrumbs for parent posts/pages * * @param int $id The id of the parent page * @param int $frontpage The id of the front page * * @return WP_Post The parent we stopped at */ protected function post_parents($id, $frontpage) { //Use WordPress API, though a bit heavier than the old method, this will ensure compatibility with other plug-ins $parent = get_post($id); //Only add the breadcrumb if it is non-private or we allow private posts in the breadcrumb trail if(apply_filters('bcn_show_post_private', get_post_status($parent) !== 'private', $parent->ID)) { //Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( get_the_title($id), $this->opt['Hpost_' . $parent->post_type . '_template'], array('post', 'post-' . $parent->post_type), get_permalink($id), $id, true)); } //Make sure the id is valid, and that we won't end up spinning in a loop if($parent->post_parent > 0 && $id != $parent->post_parent && $frontpage != $parent->post_parent) { //If valid, recursively call this function $parent = $this->post_parents($parent->post_parent, $frontpage); } return $parent; } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for posts * * @param WP_Post $post Instance of WP_Post object to create a breadcrumb for * @param bool $force_link Whether or not to force this breadcrumb to be linked * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_post($post, $force_link = false, $is_paged = false, $is_current_item = true) { //If we did not get a WP_Post object, warn developer and return early if(!($post instanceof WP_Post)) { _doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('$post global is not of type WP_Post', 'breadcrumb-navxt'), '5.1.1'); return; } //If this is the current item or if we're allowing private posts in the trail add a breadcrumb if($is_current_item || apply_filters('bcn_show_post_private', get_post_status($post) !== 'private', $post->ID)) { //Place the breadcrumb in the trail, uses the bcn_breadcrumb constructor to set the title, template, and type $breadcrumb = $this->add(new bcn_breadcrumb( get_the_title($post), $this->opt['Hpost_' . $post->post_type . '_template_no_anchor'], array('post', 'post-' . $post->post_type), get_permalink($post), $post->ID)); if($is_current_item) { $breadcrumb->add_type('current-item'); } //Under a couple of circumstances we will want to link this breadcrumb if($force_link || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { //Change the template over to the normal, linked one $breadcrumb->set_template($this->opt['Hpost_' . $post->post_type . '_template']); //Add the link $breadcrumb->set_linked(true); } } //Done with the current item, now on to the parents $frontpage = get_option('page_on_front'); //If we are to follow the hierarchy first (with hierarchy type backup), run through the post again if($this->opt['bpost_' . $post->post_type. '_hierarchy_parent_first'] && $post->post_parent > 0 && $post->ID != $post->post_parent && $frontpage != $post->post_parent) { //Get the parent's information $parent = get_post($post->post_parent); //Take care of the parent's breadcrumb $this->do_post($parent, true, false, false); } //Otherwise we need the follow the hiearchy tree else { //Handle the post's hiearchy $this->post_hierarchy($post->ID, $post->post_type, $post->post_parent); } } /** * A Breadcrumb Trail Filling Function * * This function fills a breadcrumb for any taxonomy archive, was previously two separate functions * * @param WP_Term $term The term object to generate the breadcrumb for * @param bool $is_paged Whether or not the current resource is on a page other than page 1 */ protected function do_archive_by_term($term, $is_paged = false) { if(!($term instanceof WP_Term)) { _doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('$term global is not of type WP_Term', 'breadcrumb-navxt'), '7.0.3'); return; } //Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( $term->name, $this->opt['Htax_' . $term->taxonomy . '_template_no_anchor'], array('archive', 'taxonomy', $term->taxonomy, 'current-item'), $this->maybe_add_post_type_arg(get_term_link($term), null, $term->taxonomy), $term->term_id)); //If we're paged, let's link to the first page if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display'])) { $breadcrumb->set_template($this->opt['Htax_' . $term->taxonomy . '_template']); //Figure out the anchor for current category $breadcrumb->set_linked(true); } //Get parents of current term if($term->parent) { $this->term_parents(get_term($term->parent, $term->taxonomy)); } } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for day date archives * * @param WP_Post $post Instance of WP_Post object to create a breadcrumb for * @param string $type The name of the CPT to generate the archive breadcrumb for * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_day($post, $type, $is_paged = false, $is_current_item = true) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( get_the_time(_x('d', 'day archive breadcrumb date format', 'breadcrumb-navxt'), $post), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-day'), $this->maybe_add_post_type_arg(get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')), $type))); //If this is a day archive, add current-item type if($is_current_item) { $breadcrumb->add_type('current-item'); } //If we're paged, let's link to the first page if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { //We're linking, so set the linked template $breadcrumb->set_template($this->opt['Hdate_template']); //Deal with the anchor $breadcrumb->set_linked(true); } } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for month date archives * * @param WP_Post $post Instance of WP_Post object to create a breadcrumb for * @param string $type The name of the CPT to generate the archive breadcrumb for * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_month($post, $type, $is_paged = false, $is_current_item = true) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( get_the_time(_x('F', 'month archive breadcrumb date format', 'breadcrumb-navxt'), $post), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-month'), $this->maybe_add_post_type_arg(get_month_link(get_the_time('Y'), get_the_time('m')), $type))); //If this is a month archive, add current-item type if($is_current_item) { $breadcrumb->add_type('current-item'); } //If we're paged, or not in the archive by month let's link to the first archive by month page if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { //We're linking, so set the linked template $breadcrumb->set_template($this->opt['Hdate_template']); //Deal with the anchor $breadcrumb->set_linked(true); } } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for year date archives * * @param WP_Post $post Instance of WP_Post object to create a breadcrumb for * @param string $type The name of the CPT to generate the archive breadcrumb for * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_year($post, $type, $is_paged = false, $is_current_item = true) { //Place the year breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( get_the_time(_x('Y', 'year archive breadcrumb date format', 'breadcrumb-navxt'), $post), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-year'), $this->maybe_add_post_type_arg(get_year_link(get_the_time('Y')), $type))); //If this is a year archive, add current-item type if($is_current_item) { $breadcrumb->add_type('current-item'); } //If we're paged, or not in the archive by year let's link to the first archive by year page if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { //We're linking, so set the linked template $breadcrumb->set_template($this->opt['Hdate_template']); $breadcrumb->set_linked(true); } } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for the front page * * @param bool $force_link Whether or not to force this breadcrumb to be linked * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_home($force_link = false, $is_paged = false, $is_current_item = true) { global $current_site; //Exit early if we're not displaying the home breadcrumb if(!$this->opt['bhome_display']) { return; } //Get the site name $site_name = get_option('blogname'); //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb($site_name, $this->opt['Hhome_template_no_anchor'], array('home'), get_home_url())); if($is_current_item) { $breadcrumb->add_type('current-item'); } //Under a couple of circumstances we will want to link this breadcrumb if($force_link || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { $breadcrumb->set_template($this->opt['Hhome_template']); $breadcrumb->set_linked(true); } //If we have a multi site and are not on the main site we may need to add a breadcrumb for the main site if($this->opt['bmainsite_display'] && !is_main_site()) { //Get the site name $site_name = get_site_option('site_name'); //Place the main site breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb($site_name, $this->opt['Hmainsite_template'], array('main-home'), get_home_url($current_site->blog_id), null, true)); } } /** * A modified version of WordPress' function of the same name * * @param object $object the post or taxonomy object used to attempt to find the title * * @return string the title */ protected function post_type_archive_title($object) { if(isset($object->labels->name)) { //Core filter use here is ok for time being //TODO: Recheck validitiy prior to each release return apply_filters('post_type_archive_title', $object->labels->name, $object->name); } } /** * Determines if a post type is a built in type or not * * @param string $post_type the name of the post type * * @return bool */ protected function is_builtin($post_type) { $type = get_post_type_object($post_type); //If we get a null, that means either then type wasn't found, or we had 'any' as a type, treat as builtin if($type === null) { return true; } else { return $type->_builtin; } } /** * Determines if the current location is a for a root page or not * * @param string $post_type the name of the post type * @return bool * * TODO: Remove dependancies to current state (state should be passed in) */ protected function treat_as_root_page($post_type) { return (is_home() || (is_post_type_archive() && !$this->opt['bpost_' . $post_type . '_archive_display'])); } /** * Determines if a post type has archives enabled or not * * @param string $post_type the name of the post type * * @return bool */ protected function has_archive($post_type) { $type = get_post_type_object($post_type); //TODO need a check on this for WP_Error? return $type->has_archive; } /** * Retrieves the query var for 'post_type', sets default to post, and escapes * * @param string $default[optional] The default value to return if nothing was found/set or if post_type was an array * * @return string The post type string found in the post_type query var */ protected function get_type_string_query_var($default = 'post') { $type_str = get_query_var('post_type', $default); if($type_str === '' || is_array($type_str)) { //If we didn't get a type, or it was an array, try the the first post $post = get_post(); if($post instanceof WP_Post) { $type_str = $post->post_type; } else { $type_str = $default; } } return esc_attr($type_str); } /** * Retrieves the query var for 'post_type', and returns whether or not it is an array * * @return bool Whether or not the post_type query var is an array */ protected function is_type_query_var_array() { return is_array(get_query_var('post_type')); } /** * Adds the post type argument to the URL iff the passed in type is not post * * @param string $url The URL to possibly add the post_type argument to * @param string $type[optional] The type to possibly add to the URL * @param string $taxonomy[optional] If we're dealing with a taxonomy term, the taxonomy of that term * * @return string The possibly modified URL */ protected function maybe_add_post_type_arg($url, $type = null, $taxonomy = null) { global $wp_taxonomies; //Rather than default to post, we should try to find the type if($type == null) { $type = $this->get_type_string_query_var(); } $add_query_arg = false; //Add a query arg if we are not on the default post type for the archive in question and the post type is not post if($type !== 'post' && !($taxonomy && isset($wp_taxonomies[$taxonomy]->object_type[0]) && $type === $wp_taxonomies[$taxonomy]->object_type[0])) { $add_query_arg = true; } //Filter the add_query_arg logic, only add the query arg if necessary if(apply_filters('bcn_add_post_type_arg', $add_query_arg, $type, $taxonomy)) { $url = add_query_arg(array('post_type' => $type), $url); } return $url; } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for a post type archive (WP 3.1 feature) * @param string type_str The name of the CPT to generate the archive breadcrumb for * @param bool $force_link Whether or not to force this breadcrumb to be linked * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_archive_by_post_type($type_str, $force_link = false, $is_paged = false, $is_current_item = true) { //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( $this->post_type_archive_title(get_post_type_object($type_str)), $this->opt['Hpost_' . $type_str . '_template_no_anchor'], array('archive', 'post-' . $type_str . '-archive'), get_post_type_archive_link($type_str))); if($is_current_item) { $breadcrumb->add_type('current-item'); } //Under a couple of circumstances we will want to link this breadcrumb if($force_link || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { //Change the template over to the normal, linked one $breadcrumb->set_template($this->opt['Hpost_' . $type_str. '_template']); //Add the link $breadcrumb->set_linked(true); } } /** * A wrapper function for do_archive_by_post_type which checks to ensure generating the post type archive is appropriate * * @param string $type_str The type string for the post type archive */ protected function maybe_do_archive_by_post_type($type_str) { //If this is a custom post type with a post type archive, add it if(!$this->is_builtin($type_str) && $this->opt['bpost_' . $type_str . '_archive_display'] && $this->has_archive($type_str)) { //Going farther down the rabbit hole here $this->do_archive_by_post_type($type_str, true, false, false); } } /** * A Breadcrumb Trail Filling Function * * Deals with the post type archive and taxonomy archives * * @param WP_Post|WP_Taxonomy $type The post or taxonomy to generate the archive breadcrumb for * @param string $type_str The type string for the archive */ protected function type_archive($type, $type_str = false) { //Not at taxonomy, and didn't get a type string, see if we can get the info from the query var if(!isset($type->taxonomy) && $type_str === false) //TODO could probably check the class type here { $type_str = $this->get_type_string_query_var(); } //Have a taxonomy, try to figure the type out from that else if(isset($type->taxonomy) && isset($GLOBALS['wp_taxonomies'][$type->taxonomy]->object_type[0]) && !$this->is_type_query_var_array() && apply_filters('bcn_show_type_term_archive', true, $type->taxonomy)) { $type_str = apply_filters('bcn_type_archive_post_type', $this->get_type_string_query_var($GLOBALS['wp_taxonomies'][$type->taxonomy]->object_type[0])); } $this->maybe_do_archive_by_post_type($type_str); return $type_str; } /** * A Breadcrumb Trail Filling Function * * Handles only the root page stuff for post types, including the "page for posts" * * @param string $type_str The type string variable * @param int $root_id The ID for the post type root * @param bool $is_paged Whether or not the current resource is on a page other than page 1 * @param bool $is_current_item Whether or not the breadcrumb being generated is the current item */ protected function do_root($type_str, $root_id, $is_paged = false, $is_current_item = true) { //Nothing to do for the page post type, exit early if($type_str === 'page') { return; } $frontpage_id = get_option('page_on_front'); //Retrieve the post for the root_id as we will need it eventually $bcn_post = get_post($root_id); //We'll have to check if this ID is valid, e.g. user has specified a posts page if($bcn_post instanceof WP_Post && $root_id > 0 && $root_id != $frontpage_id) { //Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, we get a pointer to it in return $breadcrumb = $this->add(new bcn_breadcrumb( get_the_title($root_id), $this->opt['Hpost_' . $type_str . '_template_no_anchor'], array($type_str . '-root', 'post', 'post-' . $type_str), get_permalink($root_id), $root_id)); //If we are at home, or any root page archive then we need to add the current item type if($is_current_item) { $breadcrumb->add_type('current-item'); } //If we're not on the current item we need to setup the anchor if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display'])) { $breadcrumb->set_template($this->opt['Hpost_' . $type_str . '_template']); $breadcrumb->set_linked(true); } //Done with the "root", now on to the parents //If there is a parent post let's find it if($bcn_post->post_parent > 0 && $bcn_post->ID != $bcn_post->post_parent && $frontpage_id != $bcn_post->post_parent) { $this->post_parents($bcn_post->post_parent, $frontpage_id); } } } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for 404 pages. */ protected function do_404() { //Place the breadcrumb in the trail, uses the bcn_breadcrumb constructor to set the title, prefix, and suffix $this->breadcrumbs[] = new bcn_breadcrumb($this->opt['S404_title'], $this->opt['H404_template'], array('404', 'current-item')); } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for paged pages * * @param int $page_number The page number to create a breadcrumb for */ protected function do_paged($page_number) { //Place the breadcrumb in the trail, uses the bcn_breadcrumb constructor to set the title, prefix, and suffix $this->breadcrumbs[] = new bcn_breadcrumb((string) $page_number, $this->opt['Hpaged_template'], array('paged')); } /** * Breadcrumb Trail Filling Function * * @param bool $force Whether or not to force the fill function to run in the loop. * * This functions fills the breadcrumb trail. */ public function fill($force = false) { global $wpdb, $wp_query, $wp, $wp_taxonomies; //Check to see if the trail is already populated if(count($this->breadcrumbs) > 0) { //Exit early since we have breadcrumbs in the trail return null; } if($this->opt['bblog_display']) { $this->opt['apost_post_root'] = get_option('page_for_posts'); } else { $this->opt['apost_post_root'] = false; } //Do any actions if necessary, we past through the current object instance to keep life simple do_action('bcn_before_fill', $this); $type = $wp_query->get_queried_object(); //Do specific opperations for the various page types //Check if this isn't the first of a multi paged item if($this->opt['bpaged_display'] && (is_paged() || is_singular() && get_query_var('page') > 1)) { //Need to switch between paged and page for archives and singular (posts) if(get_query_var('paged') > 0) { //Can use simple type hinting here to int since we already checked for greater than 0 $page_number = (int) abs(get_query_var('paged')); } else { $page_number = (int) abs(get_query_var('page')); } $this->do_paged($page_number); } //For the front page, as it may also validate as a page, do it first if(is_front_page() && !$force) { //Must have two seperate branches so that we don't evaluate it as a page if($this->opt['bhome_display']) { $this->do_home(false, is_paged()); } } //For posts else if(is_singular() || ($force && in_the_loop())) { //Could use the $post global, but we can't really trust it $type = get_post(); $this->do_post($type, false, (get_query_var('page') > 1)); //If this is an attachment then we need to change the queried object to the parent post if(is_attachment()) { $type = get_post($type->post_parent); //TODO check for WP_Error? } if($type instanceof WP_Post) { $this->do_root($type->post_type, $this->opt['apost_' . $type->post_type . '_root'], is_paged(), false); } } //For searches else if(is_search()) { $this->do_search(get_search_query(), is_paged()); } //For author pages else if(is_author() && $type instanceof WP_User) { $this->do_author($type, is_paged()); $this->do_root('post', $this->opt['aauthor_root'], is_paged(), false); } //For archives else if(is_archive()) { //We need the type for later, so save it $type_str = get_query_var('post_type'); //May be an array, if so, rewind the iterator and grab first item if(is_array($type_str)) { $type_str = reset($type_str); } //For date based archives if(is_date()) { $type_str = $this->get_type_string_query_var(); //First deal with the day breadcrumb if(is_day()) { $this->do_day(get_post(), $type_str, is_paged(), true); } //Now deal with the month breadcrumb if(is_month() || is_day()) { $this->do_month(get_post(), $type_str, is_paged(), is_month()); } $this->do_year(get_post(), $type_str, is_paged(), is_year()); $this->maybe_do_archive_by_post_type($type_str); } //If we have a post type archive, and it does not have a root page generate the archive else if(is_post_type_archive() && !isset($type->taxonomy) && (!is_numeric($this->opt['apost_' . $type_str . '_root']) || $this->opt['bpost_' . $type_str . '_archive_display'])) { $this->do_archive_by_post_type($this->get_type_string_query_var(), false, is_paged(), true); } //For taxonomy based archives else if((is_category() || is_tag() || is_tax()) && $type instanceof WP_Term) { $this->do_archive_by_term($type, is_paged()); $type_str = $this->type_archive($type); } else { $this->type_archive($type); } //Occasionally, we may end up with garbage for the type string, if so, skip the root if(isset($this->opt['apost_' . $type_str . '_root'])) { $this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str)); } } //For 404 pages else if(is_404()) { $this->do_404(); } else { //If it looks, walks, and quacks like a taxonomy, treat is as one if(isset($type->taxonomy)) { $this->do_archive_by_term($type, is_paged()); $type_str = $this->type_archive($type); } //Otherwise, it's likely the blog page else if($this->opt['bblog_display'] || is_home()) { $type_str = 'post'; } if(isset($type_str) && isset($this->opt['apost_' . $type_str . '_root'])) { $this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str)); } } //We always do the home link last, unless on the frontpage if(!is_front_page()) { $this->do_home(true, false, false); } //Do any actions if necessary, we past through the current object instance to keep life simple do_action('bcn_after_fill', $this); } public function fill_REST($item) { if($item instanceof WP_Error || $item === null) { return; } //Handle Posts if($item instanceof WP_Post) { $this->do_post($item, false); $this->do_root($item->post_type, $this->opt['apost_' . $item->post_type . '_root'], false, false); } //Handle Terms else if($item instanceof WP_Term) { $this->do_archive_by_term($item); $type_str = $this->type_archive($item); $this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str)); } //Handle Author Archives else if($item instanceof WP_User) { $this->do_author($item); $this->do_root('post', $this->opt['aauthor_root'], false, false); } $this->do_home(true, false, false); } /** * This function will either set the order of the trail to reverse key * order, or make sure it is forward key ordered. * * @param bool $reverse[optional] Whether to reverse the trail or not. */ protected function order($reverse = false) { if($reverse) { //Since there may be multiple calls our trail may be in a non-standard order ksort($this->breadcrumbs); } else { //For normal opperation we must reverse the array by key krsort($this->breadcrumbs); } } /** * This functions outputs or returns the breadcrumb trail in string form. * * @param bool $linked[optional] Whether to allow hyperlinks in the trail or not. * @param bool $reverse[optional] Whether to reverse the output or not. * @param string $template The template to use for the string output. * @param string $outer_template The template to place an entire dimension of the trail into for all dimensions higher than 1. * * @return void Void if Option to print out breadcrumb trail was chosen. * @return string String-Data of breadcrumb trail. */ public function display($linked = true, $reverse = false, $template = '%1$s%2$s', $outer_template = '<span>%1$s</span>%2$s') { //Set trail order based on reverse flag $this->order($reverse); //The main compiling loop $trail_str = $this->display_loop($this->breadcrumbs, $linked, $reverse, $template, $outer_template, $this->opt['hseparator']); return $trail_str; } /** * This function assembles the breadcrumbs in the breadcrumb trail in accordance with the passed in template * * @param array $breadcrumbs Array containing bcn_breadcrumb objects to render * @param bool $linked Whether to allow hyperlinks in the trail or not. * @param bool $reverse Whether to reverse the output or not. * @param string $template The template to use for the string output of each breadcrumb. Also known as the inner template. * @param string $outer_template The template to place an entire dimension of the trail into for all dimensions higher than 1. * @param string $separator The separator to use at this level of the breadcrumb trail * @param int $depth The iteration depth * * @return string Compiled string version of breadcrumb trail ready for display. */ protected function display_loop($breadcrumbs, $linked, $reverse, $template, $outer_template, $separator, $depth = 1) { $position = 1; $breadcrumbs = apply_filters('bcn_before_loop', $breadcrumbs); $last_position = count($breadcrumbs); if($reverse) { $position = $last_position; } //Initilize the string which will hold the assembled trail $trail_str = ''; foreach($breadcrumbs as $key => $breadcrumb) { //Blank the separator if we are dealing with what is the last breadcrumb in the assembled trail if((!$reverse && ($position >= $last_position)) || ($reverse && $position == 1)) { $separator = ''; } if(is_array($breadcrumb)) { $trail_str .= sprintf($outer_template, $this->display_loop($breadcrumb, $linked, $reverse, $template, $outer_template, $this->opt['hseparator_higher_dim'], $depth + 1), $separator); } else if($breadcrumb instanceof bcn_breadcrumb) { $types = $breadcrumb->get_types(); array_walk($types, 'sanitize_html_class'); $attrib_array = array('class' => $types); $attribs = ''; //Allow others to hook into the attribute array $attrib_array = apply_filters('bcn_display_attribute_array', $attrib_array, $breadcrumb->get_types(), $breadcrumb->get_id()); //Stringify the array foreach($attrib_array as $attrib => $value) { $attribs .= sprintf(' %1$s="%2$s"', esc_attr($attrib), esc_attr(implode(' ', $value))); } //Filter li_attributes adding attributes to the li element //TODO: Remove the bcn_li_attributes filter $attribs = apply_filters_deprecated('bcn_li_attributes', array($attribs, $breadcrumb->get_types(), $breadcrumb->get_id()), '6.0.0', 'bcn_display_attributes'); //TODO: Deprecate this filter in favor of just using bcn_display_attributes_array $attribs = apply_filters('bcn_display_attributes', $attribs, $breadcrumb->get_types(), $breadcrumb->get_id()); $separator = apply_filters('bcn_display_separator', $separator, $position, $last_position, $depth); //Assemble the breadcrumb $trail_str .= sprintf($template, $breadcrumb->assemble($linked, $position, ($key === 0)), $separator, $attribs); } if($reverse) { $position--; } else { $position++; } } return $trail_str; } /** * This functions outputs or returns the breadcrumb trail in Schema.org BreadcrumbList compliant JSON-LD * * @param bool $reverse[optional] Whether to reverse the output or not. * * @return void Void if option to print out breadcrumb trail was chosen. * @return object basic object version of the breadcrumb trail ready for json_encode. */ public function display_json_ld($reverse = false) { //Set trail order based on reverse flag $this->order($reverse); $trail_str = (object)array( '@context' => 'http://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $this->json_ld_loop($reverse)); return $trail_str; } /** * This function assembles all of the breadcrumbs into an object ready for json_encode * * @param bool $reverse[optional] Whether to reverse the output or not. * @return array The array of breadcrumbs prepared for JSON-LD */ protected function json_ld_loop($reverse = false) { $position = 1; if($reverse) { $position = count($this->breadcrumbs); } $breadcrumbs = array(); //Loop around our breadcrumbs, call the JSON-LD assembler foreach($this->breadcrumbs as $breadcrumb) { $breadcrumbs[] = $breadcrumb->assemble_json_ld($position); if($reverse) { $position--; } else { $position++; } } return $breadcrumbs; } /** * Deprecated functions, don't use these */ /** * This returns the internal version * * @deprecated 5.2.0 No longer needed, superceeded bcn_breadcrumb_trail::version * * @return string internal version of the Breadcrumb trail */ public function get_version() { _deprecated_function( __FUNCTION__, '5.2', 'bcn_breadcrumb_trail::version' ); return self::version; } /** * A Breadcrumb Trail Filling Function * * @deprecated 6.0.0 No longer needed, superceeded by do_post * * This functions fills a breadcrumb for an attachment page. */ protected function do_attachment() { _deprecated_function( __FUNCTION__, '6.0', 'bcn_breadcrumb_trail::do_post'); $this->do_post(get_post()); } /** * A Breadcrumb Trail Filling Function * * This functions fills a breadcrumb for a date archive. * * @param string $type The type to restrict the date archives to * * @deprecated 6.0.0 No longer needed, superceeded by do_day, do_month, and/or do_year */ protected function do_archive_by_date($type) { _deprecated_function( __FUNCTION__, '6.0', 'bcn_breadcrumb_trail::do_day, bcn_breadcrumb_trail::do_month, and/or bcn_breadcrumb_trail::do_year'); //First deal with the day breadcrumb if(is_day() || is_single()) { $this->do_day(get_post(), $type, is_paged(), is_day()); } //Now deal with the month breadcrumb if(is_month() || is_day() || is_single()) { $this->do_month(get_post(), $type, is_paged(), is_month()); } $this->do_year(get_post(), $type, is_paged(), is_year()); } /** * This functions outputs or returns the breadcrumb trail in list form. * * @deprecated 6.0.0 No longer needed, superceeded by $template parameter in display * * @param bool $linked[optional] Whether to allow hyperlinks in the trail or not. * @param bool $reverse[optional] Whether to reverse the output or not. * * @return void Void if option to print out breadcrumb trail was chosen. * @return string String version of the breadcrumb trail. */ public function display_list($linked = true, $reverse = false) { _deprecated_function( __FUNCTION__, '6.0', 'bcn_breadcrumb_trail::display'); return $this->display($linked, $reverse, "<li%3\$s>%1\$s</li>\n"); } } options_upgrade.php 0000644 00000020545 14720660717 0010477 0 ustar 00 <?php /* Copyright 2015-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); //Do a PHP version check, require 5.3 or newer if(version_compare(phpversion(), '5.3.0', '<')) { //Only purpose of this function is to echo out the PHP version error function bcn_phpold() { printf('<div class="notice notice-error"><p>' . __('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0'); } //If we are in the admin, let's print a warning then return if(is_admin()) { add_action('admin_notices', 'bcn_phpold'); } return; } //FIXME: this seems to be all sorts of garbage that needs fixing function bcn_options_upgrade_handler(&$opts, $version, $defaults) { //Upgrading to 3.8.1 if(version_compare($version, '3.8.1', '<')) { $opts['post_page_root'] = get_option('page_on_front'); $opts['post_post_root'] = get_option('page_for_posts'); } //Upgrading to 4.0 if(version_compare($version, '4.0.0', '<')) { //Only migrate if we haven't migrated yet if(isset($opts['current_item_linked'])) { //Loop through the old options, migrate some of them foreach($opts as $option => $value) { //Handle all of our boolean options first, they're real easy, just add a 'b' if(strpos($option, 'display') > 0 || $option == 'current_item_linked') { $defaults['b' . $option] = $value; } //Handle migration of anchor templates to the templates else if(strpos($option, 'anchor') > 0) { $parts = explode('_', $option); //Do excess slash removal sanitation $defaults['H' . $parts[0] . '_template'] = $value . '%htitle%</a>'; } //Handle our abs integers else if($option == 'max_title_length' || $option == 'post_post_root' || $option == 'post_page_root') { $opts['a' . $option] = $value; } //Now everything else, minus prefix and suffix else if(strpos($option, 'prefix') === false && strpos($option, 'suffix') === false) { $defaults['S' . $option] = $value; } } } //Add in the new settings for CPTs introduced in 4.0 foreach($GLOBALS['wp_post_types'] as $post_type) { //We only want custom post types if(!$post_type->_builtin) { //Add in the archive_display option $defaults['bpost_' . $post_type->name . '_archive_display'] = $post_type->has_archive; } } $opts = $defaults; } if(version_compare($version, '4.0.1', '<')) { if(isset($opts['Hcurrent_item_template_no_anchor'])) { unset($opts['Hcurrent_item_template_no_anchor']); } if(isset($opts['Hcurrent_item_template'])) { unset($opts['Hcurrent_item_template']); } } //Upgrading to 4.3.0 if(version_compare($version, '4.3.0', '<')) { //Removed home_title if(isset($opts['Shome_title'])) { unset($opts['Shome_title']); } //Removed mainsite_title if(isset($opts['Smainsite_title'])) { unset($opts['Smainsite_title']); } } //Upgrading to 5.1.0 if(version_compare($version, '5.1.0', '<')) { foreach($GLOBALS['wp_taxonomies'] as $taxonomy) { //If we have the old options style for it, update if($taxonomy->name !== 'post_format' && isset($opts['H' . $taxonomy->name . '_template'])) { //Migrate to the new setting name $opts['Htax_' . $taxonomy->name . '_template'] = $opts['H' . $taxonomy->name . '_template']; $opts['Htax_' . $taxonomy->name . '_template_no_anchor'] = $opts['H' . $taxonomy->name . '_template_no_anchor']; //Clean up old settings unset($opts['H' . $taxonomy->name . '_template']); unset($opts['H' . $taxonomy->name . '_template_no_anchor']); } } } //Upgrading to 5.4.0 if(version_compare($version, '5.4.0', '<')) { //Migrate users to schema.org breadcrumbs for author and search if still on the defaults for posts if($opts['Hpost_post_template'] === bcn_breadcrumb::get_default_template() && $opts['Hpost_post_template_no_anchor'] === bcn_breadcrumb::default_template_no_anchor) { if($opts['Hpaged_template'] === 'Page %htitle%') { $opts['Hpaged_template'] = $defaults['Hpaged_template']; } if($opts['Hsearch_template'] === 'Search results for '<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'' || $opts['Hsearch_template'] === 'Search results for '<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'') { $opts['Hsearch_template'] = $defaults['Hsearch_template']; } if($opts['Hsearch_template_no_anchor'] === 'Search results for '%htitle%'' || $opts['Hsearch_template_no_anchor'] === 'Search results for '%htitle%'') { $opts['Hsearch_template_no_anchor'] = $defaults['Hsearch_template_no_anchor']; } if($opts['Hauthor_template'] === 'Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>') { $opts['Hauthor_template'] = $defaults['Hauthor_template']; } if($opts['Hauthor_template_no_anchor'] === 'Articles by: %htitle%') { $opts['Hauthor_template_no_anchor'] = $defaults['Hauthor_template_no_anchor']; } } } //Upgrading to 5.5.0 if(version_compare($version, '5.5.0', '<')) { //Translate the old 'page' taxonomy type to BCN_POST_PARENT if($defaults['Spost_post_taxonomy_type'] === 'page') { $opts['Spost_post_taxonomy_type'] = 'BCN_POST_PARENT'; } if(!isset($defaults['Spost_post_taxonomy_referer'])) { $opts['bpost_post_taxonomy_referer'] = false; } //Loop through all of the post types in the array foreach($GLOBALS['wp_post_types'] as $post_type) { //Check for non-public CPTs if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name)) { continue; } //We only want custom post types if(!$post_type->_builtin) { //Translate the old 'page' taxonomy type to BCN_POST_PARENT if($opts['Spost_' . $post_type->name . '_taxonomy_type'] === 'page') { $opts['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_POST_PARENT'; } //Translate the old 'date' taxonomy type to BCN_DATE if($opts['Spost_' . $post_type->name . '_taxonomy_type'] === 'date') { $opts['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_DATE'; } if(!isset($opts['Spost_' . $post_type->name . '_taxonomy_referer'])) { $opts['bpost_' . $post_type->name . '_taxonomy_referer'] = false; } } } } //Upgrading to 6.0.0 if(version_compare($version, '6.0.0', '<')) { //Loop through all of the post types in the array foreach($GLOBALS['wp_post_types'] as $post_type) { if(isset($opts['Spost_' . $post_type->name . '_taxonomy_type'])) { $opts['Spost_' . $post_type->name . '_hierarchy_type'] = $opts['Spost_' . $post_type->name . '_taxonomy_type']; unset($opts['Spost_' . $post_type->name . '_taxonomy_type']); } if(isset($opts['Spost_' . $post_type->name . '_taxonomy_display'])) { $opts['Spost_' . $post_type->name . '_hierarchy_display'] = $opts['Spost_' . $post_type->name . '_taxonomy_display']; unset($opts['Spost_' . $post_type->name . '_taxonomy_display']); } } } if(version_compare($version, '7.0.0', '<')) { //Loop through all of the post types in the array foreach($GLOBALS['wp_post_types'] as $post_type) { if(isset($opts['Spost_' . $post_type->name . '_hierarchy_type'])) { $opts['Epost_' . $post_type->name . '_hierarchy_type'] = $opts['Spost_' . $post_type->name . '_hierarchy_type']; unset($opts['Spost_' . $post_type->name . '_hierarchy_type']); } } if(isset($opts['Sauthor_name'])) { $opts['Eauthor_name'] = $opts['Sauthor_name']; unset($opts['Sauthor_name']); } } } class.bcn_breadcrumb.php 0000644 00000024051 14720660717 0011325 0 ustar 00 <?php /* Copyright 2007-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); //The breadcrumb class class bcn_breadcrumb { //Our member variables const version = '7.3.1'; //The main text that will be shown protected $title; //The breadcrumb's template, used durring assembly protected $template; //The breadcrumb's no anchor template, used durring assembly when there won't be an anchor protected $template_no_anchor; //Boolean, is this element linked protected $linked = false; //The link the breadcrumb leads to, null if $linked == false protected $url; //The corresponding resource ID protected $id = null; private $_title = null; //The type of this breadcrumb protected $type; const default_template_no_anchor = '<span property="itemListElement" typeof="ListItem"><span property="name" class="%type%">%htitle%</span><meta property="url" content="%link%"><meta property="position" content="%position%"></span>'; /** * The enhanced default constructor, ends up setting all parameters via the set_ functions * * @param string $title (optional) The title of the breadcrumb * @param string $template (optional) The html template for the breadcrumb * @param string $type (optional) The breadcrumb type * @param string $url (optional) The url the breadcrumb links to * @param bool $linked (optional) Whether or not the breadcrumb uses the linked or unlinked template */ public function __construct($title = '', $template = '', array $type = array(), $url = '', $id = null, $linked = false) { //The breadcrumb type $this->type = $type; //Set the resource id $this->set_id($id); //Set the title $this->set_title($title); //Set the default anchorless templates value $this->template_no_anchor = bcn_breadcrumb::default_template_no_anchor; //If we didn't get a good template, use a default template if($template == null) { $this->set_template(bcn_breadcrumb::get_default_template()); } //If something was passed in template wise, update the appropriate internal template else { if($linked) { $this->set_template($template); } else { $this->template_no_anchor = $this->run_template_kses(apply_filters('bcn_breadcrumb_template_no_anchor', $template, $this->type, $this->id)); $this->set_template(bcn_breadcrumb::get_default_template()); } } $this->set_url($url); $this->set_linked($linked); } /** * Function to return the translated default template * * @return string The default breadcrumb template */ static public function get_default_template() { return sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="%1$s" href="%%link%%" class="%%type%%" bcn-aria-current><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', esc_attr__('Go to %title%.','breadcrumb-navxt')); } /** * Function to set the protected title member * * @param string $title The title of the breadcrumb */ public function set_title($title) { //Set the title $this->title = apply_filters('bcn_breadcrumb_title', $title, $this->type, $this->id); $this->_title = $this->title; } /** * Function to get the protected title member * * @return $this->title */ public function get_title() { //Return the title return $this->title; } /** * Function to set the internal URL variable * * @param string $url the URL to link to */ public function set_url($url) { $url = trim($url); $this->url = apply_filters('bcn_breadcrumb_url', $url, $this->type, $this->id); } /** * Function to get the internal URL variable * * @return string the URL that the breadcrumb links to */ public function get_url() { return $this->url; } /** * Function to set the internal breadcrumb linked status * * @param bool $linked whether or not the breadcrumb uses the linked or unlinked template */ public function set_linked($linked) { $this->linked = apply_filters('bcn_breadcrumb_linked', $linked, $this->type, $this->id); } /** * Function to check if this breadcrumb will be linked * * @return boolean whether or not this breadcrumb is linked */ public function is_linked() { return $this->linked; } /** * A wrapper for wp_kses which handles getting the allowed html * * @param string $template_str The tempalte string to run through kses * @return string The template string post cleaning */ protected function run_template_kses($template_str) { return wp_kses($template_str, apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'))); } /** * Function to set the internal breadcrumb template * * @param string $template the template to use durring assebly */ public function set_template($template) { //Assign the breadcrumb template $this->template = $this->run_template_kses(apply_filters('bcn_breadcrumb_template', $template, $this->type, $this->id)); } /** * Function to set the internal breadcrumb ID * * @param int $id the id of the resource this breadcrumb represents */ public function set_id($id) { $this->id = $id; } /** * Function to get the internal breadcrumb ID * * @return int the id of the resource this breadcrumb represents */ public function get_id() { return $this->id; } /** * Append a type entry to the type array * * @param string $type the type to append */ public function add_type($type) { $this->type[] = $type; } /** * Return the type array * * @return array The type array */ public function get_types() { return $this->type; } /** * This function will intelligently trim the title to the value passed in through $max_length. This function is deprecated, do not call. * * @param int $max_length of the title. * @deprecated since 5.2.0 */ public function title_trim($max_length) { _deprecated_function(__FUNCTION__, '5.2.0'); //To preserve HTML entities, must decode before splitting $this->title = html_entity_decode($this->title, ENT_COMPAT, 'UTF-8'); $title_length = mb_strlen($this->title); //Make sure that we are not making it longer with that ellipse if($title_length > $max_length && ($title_length + 2) > $max_length) { //Trim the title $this->title = mb_substr($this->title, 0, $max_length - 1); //Make sure we can split, but we want to limmit to cutting at max an additional 25% if(mb_strpos($this->title, ' ', .75 * $max_length) > 0) { //Don't split mid word while(mb_substr($this->title,-1) != ' ') { $this->title = mb_substr($this->title, 0, -1); } } //Remove the whitespace at the end and add the hellip $this->title = rtrim($this->title) . html_entity_decode('…', ENT_COMPAT, 'UTF-8'); } //Return to the encoded version of all HTML entities (keep standards complance) $this->title = force_balance_tags(htmlentities($this->title, ENT_COMPAT, 'UTF-8')); } /** * Assembles the parts of the breadcrumb into a html string * * @param bool $linked Allow the output to contain anchors? * @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail) * @param bool $is_current_item Whether or not this breadcrumb represents the current item * * @return string The compiled breadcrumb string */ public function assemble($linked, $position, $is_current_item = false) { if($is_current_item) { $aria_current_str = 'aria-current="page"'; } else { $aria_current_str = ''; } //Build our replacements array $replacements = array( '%title%' => esc_attr(strip_tags($this->title)), '%link%' => esc_url($this->url), '%htitle%' => $this->title, '%type%' => apply_filters('bcn_breadcrumb_types', $this->type, $this->id), '%ftitle%' => esc_attr(strip_tags($this->_title)), '%fhtitle%' => $this->_title, '%position%' => $position, 'bcn-aria-current' => $aria_current_str ); //The type may be an array, implode it if that is the case if(is_array($replacements['%type%'])) { array_walk($replacements['%type%'], 'sanitize_html_class'); $replacements['%type%'] = esc_attr(implode(' ', $replacements['%type%'])); } else { _doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('bcn_breadcrumb::type must be an array', 'breadcrumb-navxt'), '6.0.2'); } $replacements = apply_filters('bcn_template_tags', $replacements, $this->type, $this->id); //If we are linked we'll need to use the normal template if($this->linked && $linked) { //Return the assembled breadcrumb string return str_replace(array_keys($replacements), $replacements, $this->template); } //Otherwise we use the no anchor template else { //Return the assembled breadcrumb string return str_replace(array_keys($replacements), $replacements, $this->template_no_anchor); } } /** * Assembles the parts of the breadcrumb into a JSON-LD ready object-array * * @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail) * * @return array(object) The prepared array object ready to pass into json_encode */ public function assemble_json_ld($position) { return (object) apply_filters('bcn_breadcrumb_assembled_json_ld_array', array( '@type' => 'ListItem', 'position' => $position, 'item' => (object)array( '@id' => esc_url($this->url), 'name' => esc_attr($this->title)) ), $this->type, $this->id); } } class.bcn_network_admin.php 0000644 00000016461 14720660717 0012066 0 ustar 00 <?php /* Copyright 2015-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); //Include admin base class if(!class_exists('bcn_admin')) { require_once(dirname(__FILE__) . '/class.bcn_admin.php'); } use mtekk\adminKit\{adminKit, form, message, setting}; /** * The administrative interface class * */ class bcn_network_admin extends bcn_admin { const version = '7.3.1'; protected $full_name = 'Breadcrumb NavXT Network Settings'; protected $access_level = 'manage_network_options'; /** * Administrative interface class default constructor * @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object * @param string $basename The basename of the plugin */ function __construct(array &$opts, $basename, array &$settings) { //We're going to make sure we load the parent's constructor parent::__construct($opts, $basename, $settings); //Change to the proper name $this->full_name = __('Breadcrumb NavXT Network Settings', 'breadcrumb-navxt'); //Remove the hook added by the parent as we don't want this classes settings page everywhere remove_action('admin_menu', array($this, 'add_page')); //Replace with the network_admin hook add_action('network_admin_menu', array($this, 'add_page')); } function is_network_admin() { return true; } /** * admin initialization callback function * * is bound to wordpress action 'admin_init' on instantiation * * @since 3.2.0 * @return void */ function init() { //We're going to make sure we run the parent's version of this function as well parent::init(); } function wp_loaded() { parent::wp_loaded(); } /** * Return the URL of the settings page for the plugin */ function admin_url() { return admin_url('network/settings.php?page=' . $this->identifier); } /** * Adds the adminpage the menu and the nice little settings link */ function add_page() { //Add the submenu page to "settings" menu $hookname = add_submenu_page('settings.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page')); // check capability of user to manage options (access control) if(current_user_can($this->access_level)) { //Register admin_head-$hookname callback add_action('admin_head-' . $hookname, array($this, 'admin_head')); //Register admin_print_styles-$hookname callback add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles')); //Register admin_print_scripts-$hookname callback add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts')); //Register Help Output add_action('load-' . $hookname, array($this, 'help')); } } /** * help action hook function * * @return string * */ function help() { $screen = get_current_screen(); //Exit early if the add_help_tab function doesn't exist if(!method_exists($screen, 'add_help_tab')) { return; } //Add contextual help on current screen if($screen->id == 'settings_page_' . $this->identifier . '-network') { $this->help_contents($screen); } } /** * Have to hook into get_option and replace with network wide alternate * * @param string $option The name of the option to retrieve * @return mixed The value of the option */ function get_option($option) { return get_site_option($option); } /** * Have to hook into update_option and replace with network wide alternate * * @param string $option The name of the option to update * @param mixed $newvalue The new value to set the option to * */ function update_option($option, $newvalue, $autoload = null) { return update_site_option($option, $newvalue); } /** * Have to hook into add_option and replace with network wide alternate * * @param string $option The name of the option to update * @param mixed $value The new value to set the option to * @param null $deprecated Deprecated parameter * @param string $autoload Whether or not to autoload the option, it's a string because WP is special * */ function add_option($option, $value = '', $deprecated = '', $autoload = 'yes') { return add_site_option($option, $value); } /** * Have to hook into delete_option and replace with network wide alternate * * @param string $option The name of the option to delete */ function delete_option($option) { return delete_site_option($option); } /** * A message function that checks for the BCN_SETTINGS_* define statement */ function multisite_settings_warn() { if(is_multisite()) { if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL) { $this->messages[] = new message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride'); } else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK) { } else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL) { $this->messages[] = new message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isitemayoveride'); } else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK) { $this->messages[] = new message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nsmayoveride'); } //Fall through if no settings mode was set else { $this->messages[] = new message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nosetting'); $this->messages[] = new message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride'); } } } /** * A message function that checks for deprecated settings that are set and warns the user */ function deprecated_settings_warn() { parent::deprecated_settings_warn(); } /** * Function checks the current site to see if the blog options should be disabled * * @return boool Whether or not the blog options should be disabled */ function maybe_disable_blog_options() { return false; } /** * Function checks the current site to see if the mainsite options should be disabled * * @return bool Whether or not the mainsite options should be disabled */ function maybe_disable_mainsite_options() { return false; } } class.bcn_widget.php 0000644 00000021457 14720660717 0010511 0 ustar 00 <?php /* Copyright 2015-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); class bcn_widget extends WP_Widget { const version = '7.3.1'; protected $allowed_html = array(); protected $defaults = array('title' => '', 'pretext' => '', 'type' => 'microdata', 'linked' => true, 'reverse' => false, 'front' => false, 'force' => false); //Default constructor function __construct() { //Filter allowed_html array to allow others to add acceptable tags $this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post')); //@see https://core.trac.wordpress.org/ticket/10527 if(!is_textdomain_loaded('breadcrumb-navxt')) { load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages'); } $ops = array('classname' => 'widget_breadcrumb_navxt', 'description' => __('Adds a breadcrumb trail to your sidebar', 'breadcrumb-navxt')); parent::__construct('bcn_widget', 'Breadcrumb NavXT', $ops); } function widget($args, $instance) { //Make sure we grab defaults in the case of out of date instance settings being sent $instance = wp_parse_args((array) $instance, $this->defaults); $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $instance['pretext'] = apply_filters('widget_text', $instance['pretext'], $instance); $instance['pretext'] = apply_filters('bcn_widget_pretext', $instance['pretext'], $instance); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); //A bit of a hack but we need the DB settings to know if we should exit early $opt = get_option('bcn_options'); //If we are on the front page and don't display on the front, return early if($instance['front'] && is_front_page() && !(is_paged() && $opt['bpaged_display'])) { return; } //Manditory before widget junk echo $args['before_widget']; if(!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } //We'll want to switch between the two breadcrumb output types if($instance['type'] === 'list') { //Display the list output breadcrumb echo wp_kses($instance['pretext'], $this->allowed_html) . '<ol class="breadcrumb_trail breadcrumbs">'; bcn_display_list(false, $instance['linked'], $instance['reverse'], $instance['force']); echo '</ol>'; } else if($instance['type'] === 'microdata' || $instance['type'] === 'breadcrumblist_rdfa') { echo '<div class="breadcrumbs" vocab="https://schema.org/" typeof="BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html); //Display the regular output breadcrumb bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']); echo '</div>'; } else if($instance['type'] === 'breadcrumblist_microdata') { echo '<div class="breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html); //Display the regular output breadcrumb bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']); echo '</div>'; } else if($instance['type'] === 'plain') { //Display the pretext echo wp_kses($instance['pretext'], $this->allowed_html); //Display the regular output breadcrumb bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']); } else if($instance['type'] === 'microdata_wai_aria') { echo '<nav aria-label="Breadcrumb" class="breadcrumbs" vocab="https://schema.org/" typeof="BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html); //Display the regular output breadcrumb bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']); echo '</nav>'; } else { //If we recieved a type that is not of the built in displays, it must be relegated to an extension plugin do_action('bcn_widget_display_trail', $instance); } //Manditory after widget junk echo $args['after_widget']; } function update($new_instance, $old_instance) { //Filter out anything that could be invalid $old_instance['title'] = strip_tags($new_instance['title']); $old_instance['pretext'] = wp_kses($new_instance['pretext'], $this->allowed_html); $old_instance['type'] = strip_tags($new_instance['type']); //Have to check more than if it is set as it appears this must effectively run twice since WordPress 5.8 $old_instance['linked'] = isset($new_instance['linked']) && $new_instance['linked'] !== false; $old_instance['reverse'] = isset($new_instance['reverse']) && $new_instance['reverse'] !== false; $old_instance['front'] = isset($new_instance['front']) && $new_instance['front'] !== false; $old_instance['force'] = isset($new_instance['force']) && $new_instance['force'] !== false; return $old_instance; } function form($instance) { $instance = wp_parse_args((array) $instance, $this->defaults); ?> <p> <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"> <?php _e('Title:', 'breadcrumb-navxt'); ?></label> <input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>" id="<?php echo esc_attr($this->get_field_id('title')); ?>" value="<?php echo esc_attr($instance['title']);?>" /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('pretext')); ?>"> <?php _e('Text to show before the trail:', 'breadcrumb-navxt'); ?></label> <input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('pretext')); ?>" id="<?php echo esc_attr($this->get_field_id('pretext')); ?>" value="<?php echo esc_attr($instance['pretext']);?>" /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('type')); ?>"> <?php _e('Output trail as:', 'breadcrumb-navxt'); ?></label> <select name="<?php echo esc_attr($this->get_field_name('type')); ?>" id="<?php echo esc_attr($this->get_field_id('type')); ?>"> <option value="list" <?php selected('list', $instance['type']);?>><?php _e('List', 'breadcrumb-navxt'); ?></option> <option value="microdata" <?php selected('microdata', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (RDFa)', 'breadcrumb-navxt'); ?></option> <option value="microdata_wai_aria" <?php selected('microdata_wai_aria', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (RDFa) with WAI-ARIA', 'breadcrumb-navxt'); ?></option> <option value="breadcrumblist_microdata" <?php selected('breadcrumblist_microdata', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (microdata)', 'breadcrumb-navxt'); ?></option> <option value="plain" <?php selected('plain', $instance['type']);?>><?php _e('Plain', 'breadcrumb-navxt'); ?></option> <?php do_action('bcn_widget_display_types', $instance);?> </select> </p> <p> <input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('linked')); ?>" id="<?php echo esc_attr($this->get_field_id('linked')); ?>"<?php checked(true, $instance['linked']);?> /> <label for="<?php echo esc_attr($this->get_field_id('linked')); ?>"> <?php _e('Link the breadcrumbs', 'breadcrumb-navxt'); ?></label><br /> <input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('reverse')); ?>" id="<?php echo esc_attr($this->get_field_id('reverse')); ?>"<?php checked(true, $instance['reverse']);?> /> <label for="<?php echo esc_attr($this->get_field_id('reverse')); ?>"> <?php _e('Reverse the order of the trail', 'breadcrumb-navxt'); ?></label><br /> <input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('front')); ?>" id="<?php echo esc_attr($this->get_field_id('front')); ?>"<?php checked(true, $instance['front']);?> /> <label for="<?php echo esc_attr($this->get_field_id('front')); ?>"> <?php _e('Hide the trail on the front page', 'breadcrumb-navxt'); ?></label><br /> <input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('force')); ?>" id="<?php echo esc_attr($this->get_field_id('force')); ?>"<?php checked(true, $instance['force']);?> /> <label for="<?php echo esc_attr($this->get_field_id('force')); ?>"> <?php _e('Ignore breadcrumb cache', 'breadcrumb-navxt'); ?></label><br /> </p> <?php } } uninstall.php 0000644 00000007174 14720660717 0007311 0 ustar 00 <?php /** * Breadcrumb NavXT - uninstall script * * uninstall script based on WordPress Uninstall Plugin API * * * Because bcn_admin->uninstall() does not work with WPMU, * an uninstaller class has been written, that encapsulates * the uninstall logic and calls bcn_admin->uninstall() * when applicable. * * @see http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Uninstall_Plugin_API * @see http://trac.mu.wordpress.org/ticket/967 * * this uninstall.php file was executed multiple times because * breadcrumb navxt (until 3.3) constsisted of two plugins: * * 1.) breadcrumb_navxt_class.php / Core * 2.) breadcrumb_navxt_admin.php / Adminstration Interface * * @author Tom Klingenberg */ /* Copyright 2010-2024 John Havlik (email : john.havlik@mtekk.us) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //Ensure the uninstall.php file was only called by WordPress and not directly if(!defined('WP_UNINSTALL_PLUGIN')) { //First catches the Apache users header("HTTP/1.0 404 Not Found"); //This should catch FastCGI users header("Status: 404 Not Found"); die(); } require_once(dirname(__FILE__) . '/includes/adminKit/class-mtekk_adminkit_uninstaller.php'); /** * Breadcrumb NavXT uninstaller class * * @author Tom Klingenberg */ class bcn_uninstaller extends mtekk_adminKit_uninstaller { protected $unique_prefix = 'bcn'; protected $plugin_basename = null; public function __construct() { $this->plugin_basename = plugin_basename('/breadcrumb-navxt.php'); parent::__construct(); } /** * Options uninstallation function for legacy */ private function uninstall_legacy() { delete_option($this->unique_prefix . '_options'); delete_option($this->unique_prefix . '_options_bk'); delete_option($this->unique_prefix . '_version'); delete_site_option($this->unique_prefix . '_options'); delete_site_option($this->unique_prefix . '_options_bk'); delete_site_option($this->unique_prefix . '_version'); } /** * uninstall breadcrumb navxt admin plugin * * @return bool */ private function uninstall_options() { if(version_compare(phpversion(), '5.3.0', '<')) { return $this->uninstall_legacy(); } //Grab our global breadcrumb_navxt object global $breadcrumb_navxt; //Load dependencies if applicable if(!class_exists('breadcrumb_navxt')) { require_once($this->_get_plugin_path()); } //Initalize $breadcrumb_navxt so we can use it $bcn_breadcrumb_trail = new bcn_breadcrumb_trail(); //Let's make an instance of our object takes care of everything $breadcrumb_navxt = new breadcrumb_navxt($bcn_breadcrumb_trail); //Uninstall return $breadcrumb_navxt->uninstall(); } /** * uninstall method * * @return bool wether or not uninstall did run successfull. */ public function uninstall() { //Only bother to do things if we have something in the database if($this->is_installed()) { return $this->uninstall_options(); } } } /// class bcn_uninstaller /* * main */ new bcn_uninstaller();
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Génération de la page: 0.03 |
proxy
|
phpinfo
|
Réglages