PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/plugins/breadcrumb-navxt/breadcrumb_navxt_admin.php

https://bitbucket.org/dkrzos/phc
PHP | 894 lines | 693 code | 1 blank | 200 comment | 69 complexity | 9915515b1944b47db3cf2c5e15d95f62 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. Plugin Name: Breadcrumb NavXT
  4. Plugin URI: http://mtekk.us/code/breadcrumb-navxt/
  5. Description: Adds a breadcrumb navigation showing the visitor&#39;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>.
  6. Version: 4.4.0
  7. Author: John Havlik
  8. Author URI: http://mtekk.us/
  9. License: GPL2
  10. TextDomain: breadcrumb-navxt
  11. DomainPath: /languages/
  12. */
  13. /* Copyright 2007-2013 John Havlik (email : mtekkmonkey@gmail.com)
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
  27. //Do a PHP version check, require 5.2 or newer
  28. if(version_compare(phpversion(), '5.2.0', '<'))
  29. {
  30. //Only purpose of this function is to echo out the PHP version error
  31. function bcn_phpold()
  32. {
  33. printf('<div class="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.2.0');
  34. }
  35. //If we are in the admin, let's print a warning then return
  36. if(is_admin())
  37. {
  38. add_action('admin_notices', 'bcn_phpold');
  39. }
  40. return;
  41. }
  42. if(!function_exists('mb_strlen'))
  43. {
  44. require_once(dirname(__FILE__) . '/includes/multibyte_supplicant.php');
  45. }
  46. //Include the breadcrumb class
  47. require_once(dirname(__FILE__) . '/breadcrumb_navxt_class.php');
  48. //Include the WP 2.8+ widget class
  49. require_once(dirname(__FILE__) . '/breadcrumb_navxt_widget.php');
  50. //Include admin base class
  51. if(!class_exists('mtekk_adminKit'))
  52. {
  53. require_once(dirname(__FILE__) . '/includes/mtekk_adminkit.php');
  54. }
  55. /**
  56. * The administrative interface class
  57. *
  58. */
  59. class bcn_admin extends mtekk_adminKit
  60. {
  61. protected $version = '4.4.0';
  62. protected $full_name = 'Breadcrumb NavXT Settings';
  63. protected $short_name = 'Breadcrumb NavXT';
  64. protected $access_level = 'manage_options';
  65. protected $identifier = 'breadcrumb-navxt';
  66. protected $unique_prefix = 'bcn';
  67. protected $plugin_basename = 'breadcrumb-navxt/breadcrumb_navxt_admin.php';
  68. protected $support_url = 'http://mtekk.us/archives/wordpress/plugins-wordpress/breadcrumb-navxt-';
  69. public $breadcrumb_trail;
  70. /**
  71. * Administrative interface class default constructor
  72. * @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object
  73. */
  74. function __construct(bcn_breadcrumb_trail $breadcrumb_trail)
  75. {
  76. $this->breadcrumb_trail = $breadcrumb_trail;
  77. //Grab defaults from the breadcrumb_trail object
  78. $this->opt = $this->breadcrumb_trail->opt;
  79. //We set the plugin basename here, could manually set it, but this is for demonstration purposes
  80. //$this->plugin_basename = plugin_basename(__FILE__);
  81. //Register the WordPress 2.8 Widget
  82. add_action('widgets_init', create_function('', 'return register_widget("'. $this->unique_prefix . '_widget");'));
  83. //We're going to make sure we load the parent's constructor
  84. parent::__construct();
  85. add_action('init', array($this, 'wp_init'));
  86. }
  87. /**
  88. * admin initialization callback function
  89. *
  90. * is bound to wpordpress action 'admin_init' on instantiation
  91. *
  92. * @since 3.2.0
  93. * @return void
  94. */
  95. function init()
  96. {
  97. //We're going to make sure we run the parent's version of this function as well
  98. parent::init();
  99. //We want to run late for using our breadcrumbs
  100. add_filter('tha_breadcrumb_navigation', array($this, 'tha_compat'), 99);
  101. }
  102. function wp_init()
  103. {
  104. add_filter('bcn_allowed_html', array($this, 'allowed_html'), 1, 1);
  105. }
  106. function allowed_html($tags)
  107. {
  108. $allowed_html = array(
  109. 'a' => array(
  110. 'href' => true,
  111. 'title' => true,
  112. 'class' => true,
  113. 'id' => true,
  114. 'media' => true,
  115. 'dir' => true,
  116. 'relList' => true,
  117. 'rel' => true,
  118. 'aria-hidden' => true,
  119. 'data-icon' => true,
  120. 'itemref' => true,
  121. 'itemid' => true,
  122. 'itemprop' => true,
  123. 'itemscope' => true,
  124. 'itemtype' => true
  125. ),
  126. 'img' => array(
  127. 'alt' => true,
  128. 'align' => true,
  129. 'height' => true,
  130. 'width' => true,
  131. 'src' => true,
  132. 'id' => true,
  133. 'class' => true,
  134. 'aria-hidden' => true,
  135. 'data-icon' => true,
  136. 'itemref' => true,
  137. 'itemid' => true,
  138. 'itemprop' => true,
  139. 'itemscope' => true,
  140. 'itemtype' => true
  141. ),
  142. 'span' => array(
  143. 'title' => true,
  144. 'class' => true,
  145. 'id' => true,
  146. 'dir' => true,
  147. 'align' => true,
  148. 'lang' => true,
  149. 'xml:lang' => true,
  150. 'aria-hidden' => true,
  151. 'data-icon' => true,
  152. 'itemref' => true,
  153. 'itemid' => true,
  154. 'itemprop' => true,
  155. 'itemscope' => true,
  156. 'itemtype' => true
  157. ),
  158. 'h1' => array(
  159. 'title' => true,
  160. 'class' => true,
  161. 'id' => true,
  162. 'dir' => true,
  163. 'align' => true,
  164. 'lang' => true,
  165. 'xml:lang' => true,
  166. 'aria-hidden' => true,
  167. 'data-icon' => true,
  168. 'itemref' => true,
  169. 'itemid' => true,
  170. 'itemprop' => true,
  171. 'itemscope' => true,
  172. 'itemtype' => true
  173. ),
  174. 'h2' => array(
  175. 'title' => true,
  176. 'class' => true,
  177. 'id' => true,
  178. 'dir' => true,
  179. 'align' => true,
  180. 'lang' => true,
  181. 'xml:lang' => true,
  182. 'aria-hidden' => true,
  183. 'data-icon' => true,
  184. 'itemref' => true,
  185. 'itemid' => true,
  186. 'itemprop' => true,
  187. 'itemscope' => true,
  188. 'itemtype' => true
  189. )
  190. );
  191. return $allowed_html; //$this->array_merge_recursive($tags, $allowed_html);
  192. }
  193. function wp_loaded()
  194. {
  195. //First make sure our defaults are safe
  196. $this->find_posttypes($this->opt);
  197. $this->find_taxonomies($this->opt);
  198. //Let others hook into our settings
  199. $this->opt = apply_filters($this->unique_prefix . '_settings_init', $this->opt);
  200. parent::wp_loaded();
  201. }
  202. /**
  203. * Makes sure the current user can manage options to proceed
  204. */
  205. function security()
  206. {
  207. //If the user can not manage options we will die on them
  208. if(!current_user_can($this->access_level))
  209. {
  210. wp_die(__('Insufficient privileges to proceed.', 'breadcrumb-navxt'));
  211. }
  212. }
  213. /**
  214. * Upgrades input options array, sets to $this->opt
  215. *
  216. * @param array $opts
  217. * @param string $version the version of the passed in options
  218. */
  219. function opts_upgrade($opts, $version)
  220. {
  221. global $wp_post_types;
  222. //If our version is not the same as in the db, time to update
  223. if(version_compare($version, $this->version, '<'))
  224. {
  225. //Upgrading to 3.8.1
  226. if(version_compare($version, '3.8.1', '<'))
  227. {
  228. $opts['post_page_root'] = get_option('page_on_front');
  229. $opts['post_post_root'] = get_option('page_for_posts');
  230. }
  231. //Upgrading to 4.0
  232. if(version_compare($version, '4.0.0', '<'))
  233. {
  234. //Only migrate if we haven't migrated yet
  235. if(isset($opts['current_item_linked']))
  236. {
  237. //Loop through the old options, migrate some of them
  238. foreach($opts as $option => $value)
  239. {
  240. //Handle all of our boolean options first, they're real easy, just add a 'b'
  241. if(strpos($option, 'display') > 0 || $option == 'current_item_linked')
  242. {
  243. $this->breadcrumb_trail->opt['b' . $option] = $value;
  244. }
  245. //Handle migration of anchor templates to the templates
  246. else if(strpos($option, 'anchor') > 0)
  247. {
  248. $parts = explode('_', $option);
  249. //Do excess slash removal sanitation
  250. $this->breadcrumb_trail->opt['H' . $parts[0] . '_template'] = $value . '%htitle%</a>';
  251. }
  252. //Handle our abs integers
  253. else if($option == 'max_title_length' || $option == 'post_post_root' || $option == 'post_page_root')
  254. {
  255. $this->breadcrumb_trail->opt['a' . $option] = $value;
  256. }
  257. //Now everything else, minus prefix and suffix
  258. else if(strpos($option, 'prefix') === false && strpos($option, 'suffix') === false)
  259. {
  260. $this->breadcrumb_trail->opt['S' . $option] = $value;
  261. }
  262. }
  263. }
  264. //Add in the new settings for CPTs introduced in 4.0
  265. foreach($wp_post_types as $post_type)
  266. {
  267. //We only want custom post types
  268. if(!$post_type->_builtin)
  269. {
  270. //Add in the archive_display option
  271. $this->breadcrumb_trail->opt['bpost_' . $post_type->name . '_archive_display'] = $post_type->has_archive;
  272. }
  273. }
  274. $opts = $this->breadcrumb_trail->opt;
  275. }
  276. if(version_compare($version, '4.0.1', '<'))
  277. {
  278. if(isset($opts['Hcurrent_item_template_no_anchor']))
  279. {
  280. unset($opts['Hcurrent_item_template_no_anchor']);
  281. }
  282. if(isset($opts['Hcurrent_item_template']))
  283. {
  284. unset($opts['Hcurrent_item_template']);
  285. }
  286. }
  287. //Upgrading to 4.3.0
  288. if(version_compare($version, '4.3.0', '<'))
  289. {
  290. //Removed home_title
  291. if(isset($opts['Shome_title']))
  292. {
  293. unset($opts['Shome_title']);
  294. }
  295. //Removed mainsite_title
  296. if(isset($opts['Smainsite_title']))
  297. {
  298. unset($opts['Smainsite_title']);
  299. }
  300. }
  301. //Add custom post types
  302. $this->find_posttypes($opts);
  303. //Add custom taxonomy types
  304. $this->find_taxonomies($opts);
  305. //Save the passed in opts to the object's option array
  306. $this->opt = $opts;
  307. }
  308. }
  309. /**
  310. * help action hook function
  311. *
  312. * @return string
  313. *
  314. */
  315. function help()
  316. {
  317. $screen = get_current_screen();
  318. //Exit early if the add_help_tab function doesn't exist
  319. if(!method_exists($screen, 'add_help_tab'))
  320. {
  321. return;
  322. }
  323. //Add contextual help on current screen
  324. if($screen->id == 'settings_page_' . $this->identifier)
  325. {
  326. $general_tab = '<p>' . __('Tips for the settings are located below select options.', 'breadcrumb-navxt') .
  327. '</p><h5>' . __('Resources', 'breadcrumb-navxt') . '</h5><ul><li>' .
  328. sprintf(__("%sTutorials and How Tos%s: There are several guides, tutorials, and how tos available on the author's website.", 'breadcrumb-navxt'),'<a title="' . __('Go to the Breadcrumb NavXT tag archive.', 'breadcrumb-navxt') . '" href="http://mtekk.us/archives/tag/breadcrumb-navxt">', '</a>') . '</li><li>' .
  329. sprintf(__('%sOnline Documentation%s: Check out the documentation for more indepth technical information.', 'breadcrumb-navxt'), '<a title="' . __('Go to the Breadcrumb NavXT online documentation', 'breadcrumb-navxt') . '" href="http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/">', '</a>') . '</li><li>' .
  330. sprintf(__('%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.', 'breadcrumb-navxt'),'<a title="' . __('Go to the Breadcrumb NavXT support post for your version.', 'breadcrumb-navxt') . '" href="http://mtekk.us/archives/wordpress/plugins-wordpress/breadcrumb-navxt-' . $this->version . '/#respond">', '</a>') . '</li></ul>' .
  331. '<h5>' . __('Giving Back', 'breadcrumb-navxt') . '</h5><ul><li>' .
  332. sprintf(__('%sDonate%s: Love Breadcrumb NavXT and want to help development? Consider buying the author a beer.', 'breadcrumb-navxt'),'<a title="' . __('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&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">', '</a>') . '</li><li>' .
  333. sprintf(__('%sTranslate%s: Is your language not available? Contact John Havlik to get translating.', 'breadcrumb-navxt'),'<a title="' . __('Go to the Breadcrumb NavXT translation project.', 'breadcrumb-navxt') . '" href="http://translate.mtekk.us/projects/breadcrumb-navxt">', '</a>') . '</li></ul>';
  334. $screen->add_help_tab(
  335. array(
  336. 'id' => $this->identifier . '-base',
  337. 'title' => __('General', 'breadcrumb-navxt'),
  338. 'content' => $general_tab
  339. ));
  340. $quickstart_tab = '<p>' . __('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') .
  341. '</p><h5>' . __('Breadcrumb trail with separators', 'breadcrumb-navxt') . '</h5><pre><code>&lt;div class="breadcrumbs"&gt;' . "
  342. &lt;?php if(function_exists('bcn_display'))
  343. {
  344. bcn_display();
  345. }?&gt;
  346. &lt;/div&gt;</code></pre>" .
  347. '<h5>' . __('Breadcrumb trail in list form', 'breadcrumb-navxt').'</h5><pre><code>&lt;ol class="breadcrumbs"&gt;'."
  348. &lt;?php if(function_exists('bcn_display_list'))
  349. {
  350. bcn_display_list();
  351. }?&gt;
  352. &lt;/ol&gt;</code></pre>";
  353. $screen->add_help_tab(
  354. array(
  355. 'id' => $this->identifier . '-quick-start',
  356. 'title' => __('Quick Start', 'breadcrumb-navxt'),
  357. 'content' => $quickstart_tab
  358. ));
  359. $styling_tab = '<p>' . __('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>' .
  360. '<pre><code>.breadcrumbs
  361. {
  362. font-size: 1.1em;
  363. color: #fff;
  364. margin: 30px 0 0 10px;
  365. position: relative;
  366. float: left;
  367. }</code></pre>';
  368. $screen->add_help_tab(
  369. array(
  370. 'id' => $this->identifier . '-styling',
  371. 'title' => __('Styling', 'breadcrumb-navxt'),
  372. 'content' => $styling_tab
  373. ));
  374. $screen->add_help_tab(
  375. array(
  376. 'id' => $this->identifier . '-import-export-reset',
  377. 'title' => __('Import/Export/Reset', 'breadcrumb-navxt'),
  378. 'content' => $this->import_form()
  379. ));
  380. }
  381. }
  382. /**
  383. * enqueue's the tab style sheet on the settings page
  384. */
  385. function admin_styles()
  386. {
  387. wp_enqueue_style('mtekk_adminkit_tabs');
  388. }
  389. /**
  390. * enqueue's the tab js and translation js on the settings page
  391. */
  392. function admin_scripts()
  393. {
  394. //Enqueue ui-tabs
  395. wp_enqueue_script('jquery-ui-tabs');
  396. //Enqueue the admin tabs javascript
  397. wp_enqueue_script('mtekk_adminkit_tabs');
  398. //Load the translations for the tabs
  399. wp_localize_script('mtekk_adminkit_tabs', 'objectL10n', array(
  400. 'mtad_uid' => 'bcn_admin',
  401. 'mtad_import' => __('Import', 'breadcrumb-navxt'),
  402. 'mtad_export' => __('Export', 'breadcrumb-navxt'),
  403. 'mtad_reset' => __('Reset', 'breadcrumb-navxt'),
  404. ));
  405. }
  406. /**
  407. * The administrative page for Breadcrumb NavXT
  408. */
  409. function admin_page()
  410. {
  411. global $wp_taxonomies, $wp_post_types;
  412. $this->security();
  413. //Let's call the parent version of the page, will handle our setting stuff
  414. parent::admin_page();
  415. ?>
  416. <div class="wrap"><div id="icon-options-general" class="icon32"></div><h2><?php _e('Breadcrumb NavXT Settings', 'breadcrumb-navxt'); ?></h2>
  417. <?php
  418. //We exit after the version check if there is an action the user needs to take before saving settings
  419. if(!$this->version_check(get_option($this->unique_prefix . '_version')))
  420. {
  421. return;
  422. }
  423. ?>
  424. <form action="<?php echo $this->admin_url(); ?>" method="post" id="bcn_admin-options">
  425. <?php settings_fields('bcn_options');?>
  426. <div id="hasadmintabs">
  427. <fieldset id="general" class="bcn_options">
  428. <h3 class="tab-title" title="<?php _e('A collection of settings most likely to be modified are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('General', 'breadcrumb-navxt'); ?></h3>
  429. <h3><?php _e('General', 'breadcrumb-navxt'); ?></h3>
  430. <table class="form-table">
  431. <?php
  432. $this->input_text(__('Breadcrumb Separator', 'breadcrumb-navxt'), 'hseparator', 'regular-text', false, __('Placed in between each breadcrumb.', 'breadcrumb-navxt'));
  433. ?>
  434. <tr valign="top">
  435. <th scope="row">
  436. <?php _e('Title Length', 'breadcrumb-navxt'); ?>
  437. </th>
  438. <td>
  439. <label>
  440. <input name="bcn_options[blimit_title]" type="checkbox" id="blimit_title" value="true" <?php checked(true, $this->opt['blimit_title']); ?> />
  441. <?php _e('Limit the length of the breadcrumb title.', 'breadcrumb-navxt'); ?>
  442. </label><br />
  443. <ul>
  444. <li>
  445. <label for="amax_title_length">
  446. <?php _e('Max Title Length: ','breadcrumb-navxt');?>
  447. <input type="number" name="bcn_options[amax_title_length]" id="amax_title_length" min="1" step="1" value="<?php echo esc_html($this->opt['amax_title_length'], ENT_COMPAT, 'UTF-8'); ?>" class="small-text" />
  448. </label>
  449. </li>
  450. </ul>
  451. </td>
  452. </tr>
  453. <?php
  454. do_action($this->unique_prefix . '_settings_general');
  455. ?>
  456. </table>
  457. <h3><?php _e('Current Item', 'breadcrumb-navxt'); ?></h3>
  458. <table class="form-table">
  459. <?php
  460. $this->input_check(__('Link Current Item', 'breadcrumb-navxt'), 'bcurrent_item_linked', __('Yes', 'breadcrumb-navxt'));
  461. $this->input_check(__('Paged Breadcrumb', 'breadcrumb-navxt'), 'bpaged_display', __('Include the paged breadcrumb in the breadcrumb trail.', 'breadcrumb-navxt'), false, __('Indicates that the user is on a page other than the first on paginated posts/pages.', 'breadcrumb-navxt'));
  462. $this->input_text(__('Paged Template', 'breadcrumb-navxt'), 'Hpaged_template', 'large-text', false, __('The template for paged breadcrumbs.', 'breadcrumb-navxt'));
  463. do_action($this->unique_prefix . '_settings_current_item');
  464. ?>
  465. </table>
  466. <h3><?php _e('Home Breadcrumb', 'breadcrumb-navxt'); ?></h3>
  467. <table class="form-table">
  468. <?php
  469. $this->input_check(__('Home Breadcrumb', 'breadcrumb-navxt'), 'bhome_display', __('Place the home breadcrumb in the trail.', 'breadcrumb-navxt'));
  470. $this->input_text(__('Home Template', 'breadcrumb-navxt'), 'Hhome_template', 'large-text', false, __('The template for the home breadcrumb.', 'breadcrumb-navxt'));
  471. $this->input_text(__('Home Template (Unlinked)', 'breadcrumb-navxt'), 'Hhome_template_no_anchor', 'large-text', false, __('The template for the home breadcrumb, used when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  472. do_action($this->unique_prefix . '_settings_home');
  473. ?>
  474. </table>
  475. <h3><?php _e('Blog Breadcrumb', 'breadcrumb-navxt'); ?></h3>
  476. <table class="form-table">
  477. <?php
  478. $this->input_check(__('Blog Breadcrumb', 'breadcrumb-navxt'), 'bblog_display', __('Place the blog breadcrumb in the trail.', 'breadcrumb-navxt'), (get_option('show_on_front') !== "page"));
  479. $this->input_text(__('Blog Template', 'breadcrumb-navxt'), 'Hblog_template', 'large-text', (get_option('show_on_front') !== "page"), __('The template for the blog breadcrumb, used only in static front page environments.', 'breadcrumb-navxt'));
  480. $this->input_text(__('Blog Template (Unlinked)', 'breadcrumb-navxt'), 'Hblog_template_no_anchor', 'large-text', (get_option('show_on_front') !== "page"), __('The template for the blog breadcrumb, used only in static front page environments and when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  481. do_action($this->unique_prefix . '_settings_blog');
  482. ?>
  483. </table>
  484. <h3><?php _e('Mainsite Breadcrumb', 'breadcrumb-navxt'); ?></h3>
  485. <table class="form-table">
  486. <?php
  487. $this->input_check(__('Main Site Breadcrumb', 'breadcrumb-navxt'), 'bmainsite_display', __('Place the main site home breadcrumb in the trail in an multisite setup.', 'breadcrumb-navxt'), !is_multisite());
  488. $this->input_text(__('Main Site Home Template', 'breadcrumb-navxt'), 'Hmainsite_template', 'large-text', !is_multisite(), __('The template for the main site home breadcrumb, used only in multisite environments.', 'breadcrumb-navxt'));
  489. $this->input_text(__('Main Site Home Template (Unlinked)', 'breadcrumb-navxt'), 'Hmainsite_template_no_anchor', 'large-text', !is_multisite(), __('The template for the main site home breadcrumb, used only in multisite environments and when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  490. do_action($this->unique_prefix . '_settings_mainsite');
  491. ?>
  492. </table>
  493. <?php do_action($this->unique_prefix . '_after_settings_tab_general'); ?>
  494. </fieldset>
  495. <fieldset id="post" class="bcn_options">
  496. <h3 class="tab-title" 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'); ?></h3>
  497. <h3><?php _e('Posts', 'breadcrumb-navxt'); ?></h3>
  498. <table class="form-table">
  499. <?php
  500. $this->input_text(__('Post Template', 'breadcrumb-navxt'), 'Hpost_post_template', 'large-text', false, __('The template for post breadcrumbs.', 'breadcrumb-navxt'));
  501. $this->input_text(__('Post Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_post_template_no_anchor', 'large-text', false, __('The template for post breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  502. $this->input_check(__('Post Hierarchy Display', 'breadcrumb-navxt'), 'bpost_post_taxonomy_display', __('Show the taxonomy leading to a post in the breadcrumb trail.', 'breadcrumb-navxt'));
  503. ?>
  504. <tr valign="top">
  505. <th scope="row">
  506. <?php _e('Post Hierarchy', 'breadcrumb-navxt'); ?>
  507. </th>
  508. <td>
  509. <?php
  510. $this->input_radio('Spost_post_taxonomy_type', 'category', __('Categories'));
  511. $this->input_radio('Spost_post_taxonomy_type', 'date', __('Dates'));
  512. $this->input_radio('Spost_post_taxonomy_type', 'post_tag', __('Tags'));
  513. //We use the value 'page' but really, this will follow the parent post hierarchy
  514. $this->input_radio('Spost_post_taxonomy_type', 'page', __('Post Parent'));
  515. //Loop through all of the taxonomies in the array
  516. foreach($wp_taxonomies as $taxonomy)
  517. {
  518. //Check for non-public taxonomies
  519. if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name))
  520. {
  521. continue;
  522. }
  523. //We only want custom taxonomies
  524. if(($taxonomy->object_type == 'post' || is_array($taxonomy->object_type) && in_array('post', $taxonomy->object_type)) && !$taxonomy->_builtin)
  525. {
  526. $this->input_radio('Spost_post_taxonomy_type', $taxonomy->name, mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'));
  527. }
  528. }
  529. ?>
  530. <p class="description"><?php _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'); ?></p>
  531. </td>
  532. </tr>
  533. </table>
  534. <h3><?php _e('Pages', 'breadcrumb-navxt'); ?></h3>
  535. <table class="form-table">
  536. <?php
  537. $this->input_text(__('Page Template', 'breadcrumb-navxt'), 'Hpost_page_template', 'large-text', false, __('The template for page breadcrumbs.', 'breadcrumb-navxt'));
  538. $this->input_text(__('Page Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_page_template_no_anchor', 'large-text', false, __('The template for page breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  539. $this->input_text(__('Attachment Template', 'breadcrumb-navxt'), 'Hpost_attachment_template', 'large-text', false, __('The template for attachment breadcrumbs.', 'breadcrumb-navxt'));
  540. $this->input_text(__('Attachment Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_attachment_template_no_anchor', 'large-text', false, __('The template for attachment breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  541. ?>
  542. </table>
  543. <?php
  544. //Loop through all of the post types in the array
  545. foreach($wp_post_types as $post_type)
  546. {
  547. //Check for non-public CPTs
  548. if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name))
  549. {
  550. continue;
  551. }
  552. //We only want custom post types
  553. if(!$post_type->_builtin)
  554. {
  555. $singular_name_lc = mb_strtolower($post_type->labels->singular_name, 'UTF-8');
  556. ?>
  557. <h3><?php echo $post_type->labels->singular_name; ?></h3>
  558. <table class="form-table">
  559. <?php
  560. $this->input_text(sprintf(__('%s Template', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'Hpost_' . $post_type->name . '_template', 'large-text', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $singular_name_lc));
  561. $this->input_text(sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'Hpost_' . $post_type->name . '_template_no_anchor', 'large-text', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $singular_name_lc));
  562. $optid = $this->get_valid_id('apost_' . $post_type->name . '_root');
  563. ?>
  564. <tr valign="top">
  565. <th scope="row">
  566. <label for="<?php echo $optid;?>"><?php printf(__('%s Root Page', 'breadcrumb-navxt'), $post_type->labels->singular_name);?></label>
  567. </th>
  568. <td>
  569. <?php wp_dropdown_pages(array('name' => $this->unique_prefix . '_options[apost_' . $post_type->name . '_root]', 'id' => $optid, 'echo' => 1, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => $this->opt['apost_' . $post_type->name . '_root']));?>
  570. </td>
  571. </tr>
  572. <?php
  573. $this->input_check(sprintf(__('%s Archive Display', 'breadcrumb-navxt'), $post_type->labels->singular_name), '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);
  574. $this->input_check(sprintf(__('%s Hierarchy Display', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_taxonomy_display', sprintf(__('Show the taxonomy leading to a %s in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc));
  575. ?>
  576. <tr valign="top">
  577. <th scope="row">
  578. <?php printf(__('%s Hierarchy', 'breadcrumb-navxt'), $post_type->labels->singular_name); ?>
  579. </th>
  580. <td>
  581. <?php
  582. //We use the value 'page' but really, this will follow the parent post hierarchy
  583. $this->input_radio('Spost_' . $post_type->name . '_taxonomy_type', 'page', __('Post Parent'));
  584. //Loop through all of the taxonomies in the array
  585. foreach($wp_taxonomies as $taxonomy)
  586. {
  587. //Check for non-public taxonomies
  588. if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name))
  589. {
  590. continue;
  591. }
  592. //We only want custom taxonomies
  593. if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type))
  594. {
  595. $this->input_radio('Spost_' . $post_type->name . '_taxonomy_type', $taxonomy->name, $taxonomy->labels->singular_name);
  596. }
  597. }
  598. ?>
  599. <p class="description">
  600. <?php
  601. if($post_type->hierarchical)
  602. {
  603. _e('The hierarchy which the breadcrumb trail will show.', 'breadcrumb-navxt');
  604. }
  605. else
  606. {
  607. _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');
  608. }
  609. ?>
  610. </p>
  611. </td>
  612. </tr>
  613. </table>
  614. <?php
  615. }
  616. }
  617. do_action($this->unique_prefix . '_after_settings_tab_post');
  618. ?>
  619. </fieldset>
  620. <fieldset id="tax" class="bcn_options alttab">
  621. <h3 class="tab-title" 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'); ?></h3>
  622. <h3><?php _e('Categories', 'breadcrumb-navxt'); ?></h3>
  623. <table class="form-table">
  624. <?php
  625. $this->input_text(__('Category Template', 'breadcrumb-navxt'), 'Hcategory_template', 'large-text', false, __('The template for category breadcrumbs.', 'breadcrumb-navxt'));
  626. $this->input_text(__('Category Template (Unlinked)', 'breadcrumb-navxt'), 'Hcategory_template_no_anchor', 'large-text', false, __('The template for category breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  627. ?>
  628. </table>
  629. <h3><?php _e('Tags', 'breadcrumb-navxt'); ?></h3>
  630. <table class="form-table">
  631. <?php
  632. $this->input_text(__('Tag Template', 'breadcrumb-navxt'), 'Hpost_tag_template', 'large-text', false, __('The template for tag breadcrumbs.', 'breadcrumb-navxt'));
  633. $this->input_text(__('Tag Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_tag_template_no_anchor', 'large-text', false, __('The template for tag breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  634. ?>
  635. </table>
  636. <h3><?php _e('Post Formats', 'breadcrumb-navxt'); ?></h3>
  637. <table class="form-table">
  638. <?php
  639. $this->input_text(__('Post Format Template', 'breadcrumb-navxt'), 'Hpost_format_template', 'large-text', false, __('The template for post format breadcrumbs.', 'breadcrumb-navxt'));
  640. $this->input_text(__('Post Format Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_format_template_no_anchor', 'large-text', false, __('The template for post_format breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  641. ?>
  642. </table>
  643. <?php
  644. //Loop through all of the taxonomies in the array
  645. foreach($wp_taxonomies as $taxonomy)
  646. {
  647. //Check for non-public taxonomies
  648. if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name))
  649. {
  650. continue;
  651. }
  652. //We only want custom taxonomies
  653. if(!$taxonomy->_builtin)
  654. {
  655. $label_lc = mb_strtolower($taxonomy->label, 'UTF-8');
  656. ?>
  657. <h3><?php echo mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'); ?></h3>
  658. <table class="form-table">
  659. <?php
  660. $this->input_text(sprintf(__('%s Template', 'breadcrumb-navxt'), $taxonomy->labels->singular_name), 'H' . $taxonomy->name . '_template', 'large-text', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $label_lc));
  661. $this->input_text(sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $taxonomy->labels->singular_name), 'H' . $taxonomy->name . '_template_no_anchor', 'large-text', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $label_lc));
  662. ?>
  663. </table>
  664. <?php
  665. }
  666. }
  667. do_action($this->unique_prefix . '_after_settings_tab_taxonomy'); ?>
  668. </fieldset>
  669. <fieldset id="miscellaneous" class="bcn_options">
  670. <h3 class="tab-title" 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'); ?></h3>
  671. <h3><?php _e('Author Archives', 'breadcrumb-navxt'); ?></h3>
  672. <table class="form-table">
  673. <?php
  674. $this->input_text(__('Author Template', 'breadcrumb-navxt'), 'Hauthor_template', 'large-text', false, __('The template for author breadcrumbs.', 'breadcrumb-navxt'));
  675. $this->input_text(__('Author Template (Unlinked)', 'breadcrumb-navxt'), 'Hauthor_template_no_anchor', 'large-text', false, __('The template for author breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  676. $this->input_select(__('Author Display Format', 'breadcrumb-navxt'), 'Sauthor_name', array("display_name", "nickname", "first_name", "last_name"), 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'));
  677. ?>
  678. </table>
  679. <h3><?php _e('Miscellaneous', 'breadcrumb-navxt'); ?></h3>
  680. <table class="form-table">
  681. <?php
  682. $this->input_text(__('Date Template', 'breadcrumb-navxt'), 'Hdate_template', 'large-text', false, __('The template for date breadcrumbs.', 'breadcrumb-navxt'));
  683. $this->input_text(__('Date Template (Unlinked)', 'breadcrumb-navxt'), 'Hdate_template_no_anchor', 'large-text', false, __('The template for date breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
  684. $this->input_text(__('Search Template', 'breadcrumb-navxt'), 'Hsearch_template', 'large-text', false, __('The anchor template for search breadcrumbs, used only when the search results span several pages.', 'breadcrumb-navxt'));
  685. $this->input_text(__('Search Template (Unlinked)', 'breadcrumb-navxt'), 'Hsearch_template_no_anchor', 'large-text', false, __('The anchor template for search breadcrumbs, used only when the search results span several pages and the breadcrumb is not linked.', 'breadcrumb-navxt'));
  686. $this->input_text(__('404 Title', 'breadcrumb-navxt'), 'S404_title', 'regular-text');
  687. $this->input_text(__('404 Template', 'breadcrumb-navxt'), 'H404_template', 'large-text', false, __('The template for 404 breadcrumbs.', 'breadcrumb-navxt'));
  688. ?>
  689. </table>
  690. <?php do_action($this->unique_prefix . '_after_settings_tab_miscellaneous'); ?>
  691. </fieldset>
  692. </div>
  693. <p class="submit"><input type="submit" class="button-primary" name="bcn_admin_options" value="<?php esc_attr_e('Save Changes') ?>" /></p>
  694. </form>
  695. <?php
  696. //Need to add a separate menu thing for this
  697. $this->import_form(); ?>
  698. </div>
  699. <?php
  700. }
  701. function opts_fix(&$opts)
  702. {
  703. if($opts['amax_title_length'] < 1)
  704. {
  705. $opts['amax_title_length'] = 1;
  706. }
  707. }
  708. function opts_update_prebk(&$opts)
  709. {
  710. //Add custom post types
  711. $this->find_posttypes($opts);
  712. //Add custom taxonomy types
  713. $this->find_taxonomies($opts);
  714. }
  715. /**
  716. * Places settings into $opts array, if missing, for the registered post types
  717. *
  718. * @param array $opts
  719. */
  720. function find_posttypes(&$opts)
  721. {
  722. global $wp_post_types, $wp_taxonomies;
  723. //Loop through all of the post types in the array
  724. foreach($wp_post_types as $post_type)
  725. {
  726. //Check for non-public CPTs
  727. if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name))
  728. {
  729. continue;
  730. }
  731. //We only want custom post types
  732. if(!$post_type->_builtin)
  733. {
  734. //If the post type does not have settings in the options array yet, we need to load some defaults
  735. if(!array_key_exists('Hpost_' . $post_type->name . '_template', $opts) || !$post_type->hierarchical && !array_key_exists('Spost_' . $post_type->name . '_taxonomy_type', $opts))
  736. {
  737. //Add the necessary option array members
  738. $opts['Hpost_' . $post_type->name . '_template'] = __('<a title="Go to %ftitle%." href="%link%">%htitle%</a>', 'breadcrumb-navxt');
  739. $opts['Hpost_' . $post_type->name . '_template_no_anchor'] = __('%htitle%', 'breadcrumb-navxt');
  740. $opts['bpost_' . $post_type->name . '_archive_display'] = $post_type->has_archive;
  741. //Do type dependent tasks
  742. if($post_type->hierarchical)
  743. {
  744. //Set post_root for hierarchical types
  745. $opts['apost_' . $post_type->name . '_root'] = get_option('page_on_front');
  746. //Default to displaying a 'taxonomy'
  747. $opts['bpost_' . $post_type->name . '_taxonomy_display'] = true;
  748. //The 'taxonomy' is the page/post hierarchy for hierarchical post types
  749. $opts['Spost_' . $post_type->name . '_taxonomy_type'] = 'page';
  750. }
  751. //If it is flat, we need a taxonomy selection
  752. else
  753. {
  754. //Set post_root for flat types
  755. $opts['apost_' . $post_type->name . '_root'] = get_option('page_for_posts');
  756. //Default to not displaying a taxonomy
  757. $opts['bpost_' . $post_type->name . '_taxonomy_display'] = false;
  758. //Loop through all of the possible taxonomies
  759. foreach($wp_taxonomies as $taxonomy)
  760. {
  761. //Check for non-public taxonomies
  762. if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name))
  763. {
  764. continue;
  765. }
  766. //Activate the first taxonomy valid for this post type and exit the loop
  767. if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type))
  768. {
  769. $opts['bpost_' . $post_type->name . '_taxonomy_display'] = true;
  770. $opts['Spost_' . $post_type->name . '_taxonomy_type'] = $taxonomy->name;
  771. break;
  772. }
  773. }
  774. }
  775. //If there are no valid taxonomies for this type, we default to not displaying taxonomies for this post type
  776. if(!isset($opts['Spost_' . $post_type->name . '_taxonomy_type']))
  777. {
  778. $opts['Spost_' . $post_type->name . '_taxonomy_type'] = 'page';
  779. }
  780. }
  781. }
  782. }
  783. }
  784. /**
  785. * Places settings into $opts array, if missing, for the registered taxonomies
  786. *
  787. * @param $opts
  788. */
  789. function find_taxonomies(&$opts)
  790. {
  791. global $wp_taxonomies;
  792. //We'll add our custom taxonomy stuff at this time
  793. foreach($wp_taxonomies as $taxonomy)
  794. {
  795. //Check for non-public taxonomies
  796. if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name))
  797. {
  798. continue;
  799. }
  800. //We only want custom taxonomies
  801. if(!$taxonomy->_builtin)
  802. {
  803. //If the taxonomy does not have settings in the options array yet, we need to load some defaults
  804. if(!array_key_exists('H' . $taxonomy->name . '_template', $opts))
  805. {
  806. //Add the necessary option array members
  807. $opts['H' . $taxonomy->name . '_template'] = __(sprintf('<a title="Go to the %%ftitle%% %s archives." href="%%link%%">%%htitle%%</a>', $taxonomy->labels->singular_name), 'breadcrumb-navxt');
  808. $opts['H' . $taxonomy->name . '_template_no_anchor'] = __(sprintf('%%htitle%%', $taxonomy->labels->singular_name), 'breadcrumb-navxt');
  809. }
  810. }
  811. }
  812. }
  813. /**
  814. * Hooks into the theme hook alliance tha_breadcrumb_navigation filter and replaces the trail
  815. * with one generated by Breadcrumb NavXT
  816. *
  817. * @param string $bradcrumb_trail The string breadcrumb trail that we will replace
  818. * @return string The Breadcrumb NavXT assembled breadcrumb trail
  819. */
  820. function tha_compat($breadcrumb_trail)
  821. {
  822. //Return our breadcrumb trail
  823. return $this->display(true);
  824. }
  825. /**
  826. * Outputs the breadcrumb trail
  827. *
  828. * @param bool $return Whether to return or echo the trail.
  829. * @param bool $linked Whether to allow hyperlinks in the trail or not.
  830. * @param bool $reverse Whether to reverse the output or not.
  831. */
  832. function display($return = false, $linked = true, $reverse = false)
  833. {
  834. //Grab the current settings from the db
  835. $this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $this->opt);
  836. //Generate the breadcrumb trail
  837. $this->breadcrumb_trail->fill();
  838. return $this->breadcrumb_trail->display($return, $linked, $reverse);
  839. }
  840. /**
  841. * Outputs the breadcrumb trail
  842. *
  843. * @since 3.2.0
  844. * @param bool $return Whether to return or echo the trail.
  845. * @param bool $linked Whether to allow hyperlinks in the trail or not.
  846. * @param bool $reverse Whether to reverse the output or not.
  847. */
  848. function display_list($return = false, $linked = true, $reverse = false)
  849. {
  850. //Grab the current settings from the db
  851. $this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $this->opt);
  852. //Generate the breadcrumb trail
  853. $this->breadcrumb_trail->fill();
  854. return $this->breadcrumb_trail->display_list($return, $linked, $reverse);
  855. }
  856. }
  857. //In the future there will be a hook for this so derivatives of bcn_breadcrumb_trail can use the admin
  858. $bcn_breadcrumb_trail = new bcn_breadcrumb_trail();
  859. //Let's make an instance of our object takes care of everything
  860. $bcn_admin = new bcn_admin($bcn_breadcrumb_trail);
  861. /**
  862. * A wrapper for the internal function in the class
  863. *
  864. * @param bool $return Whether to return or echo the trail. (optional)
  865. * @param bool $linked Whether to allow hyperlinks in the trail or not. (optional)
  866. * @param bool $reverse Whether to reverse the output or not. (optional)
  867. */
  868. function bcn_display($return = false, $linked = true, $reverse = false)
  869. {
  870. global $bcn_admin;
  871. if($bcn_admin !== null)
  872. {
  873. return $bcn_admin->display($return, $linked, $reverse);
  874. }
  875. }
  876. /**
  877. * A wrapper for the internal function in the class
  878. *
  879. * @param bool $return Whether to return or echo the trail. (optional)
  880. * @param bool $linked Whether to allow hyperlinks in the trail or not. (optional)
  881. * @param bool $reverse Whether to reverse the output or not. (optional)
  882. */
  883. function bcn_display_list($return = false, $linked = true, $reverse = false)
  884. {
  885. global $bcn_admin;
  886. if($bcn_admin !== null)
  887. {
  888. return $bcn_admin->display_list($return, $linked, $reverse);
  889. }
  890. }