breadcrumb_navxt

The Breadcrumb NavXT breadcrumb navxt class.

Defined (1)

The class is defined in the following location(s).

/breadcrumb-navxt.php  
  1. class breadcrumb_navxt 
  2. const version = '5.5.2'; 
  3. protected $name = 'Breadcrumb NavXT'; 
  4. protected $identifier = 'breadcrumb-navxt'; 
  5. protected $unique_prefix = 'bcn'; 
  6. protected $plugin_basename = null; 
  7. protected $opt = null; 
  8. protected $breadcrumb_trail = null; 
  9. protected $admin = null; 
  10. /** 
  11. * Constructor for a new breadcrumb_navxt object 
  12. *  
  13. * @param bcn_breadcrumb_trail $breadcrumb_trail An instance of a bcn_breadcrumb_trail object to use for everything 
  14. */ 
  15. public function __construct(bcn_breadcrumb_trail $breadcrumb_trail) 
  16. //We get our breadcrumb trail object from our constructor 
  17. $this->breadcrumb_trail = $breadcrumb_trail; 
  18. //Grab defaults from the breadcrumb_trail object 
  19. $this->opt = $this->breadcrumb_trail->opt; 
  20. //We set the plugin basename here 
  21. $this->plugin_basename = plugin_basename(__FILE__); 
  22. //We need to add in the defaults for CPTs and custom taxonomies after all other plugins are loaded 
  23. add_action('wp_loaded', array($this, 'wp_loaded'), 15); 
  24. add_action('init', array($this, 'init')); 
  25. //Register the WordPress 2.8 Widget 
  26. add_action('widgets_init', create_function('', 'return register_widget("'. $this->unique_prefix . '_widget");')); 
  27. //Load our network admin if in the network dashboard (yes is_network_admin() doesn't exist) 
  28. if(defined('WP_NETWORK_ADMIN') && WP_NETWORK_ADMIN) 
  29. require_once(dirname(__FILE__) . '/class.bcn_network_admin.php'); 
  30. //Instantiate our new admin object 
  31. $this->admin = new bcn_network_admin($this->breadcrumb_trail, $this->plugin_basename); 
  32. //Load our main admin if in the dashboard, but only if we're not in the network dashboard (prevents goofy bugs) 
  33. else if(is_admin()) 
  34. require_once(dirname(__FILE__) . '/class.bcn_admin.php'); 
  35. //Instantiate our new admin object 
  36. $this->admin = new bcn_admin($this->breadcrumb_trail, $this->plugin_basename); 
  37. public function init() 
  38. add_filter('bcn_allowed_html', array($this, 'allowed_html'), 1, 1); 
  39. //We want to run late for using our breadcrumbs 
  40. add_filter('tha_breadcrumb_navigation', array($this, 'tha_compat'), 99); 
  41. public function allowed_html($tags) 
  42. $allowed_html = array( 
  43. 'a' => array( 
  44. 'href' => true,  
  45. 'title' => true,  
  46. 'class' => true,  
  47. 'id' => true,  
  48. 'media' => true,  
  49. 'dir' => true,  
  50. 'relList' => true,  
  51. 'rel' => true,  
  52. 'aria-hidden' => true,  
  53. 'data-icon' => true,  
  54. 'itemref' => true,  
  55. 'itemid' => true,  
  56. 'itemprop' => true,  
  57. 'itemscope' => true,  
  58. 'itemtype' => true,  
  59. 'xmlns:v' => true,  
  60. 'typeof' => true,  
  61. 'property' => true,  
  62. 'vocab' => true,  
  63. 'translate' => true,  
  64. 'lang' => true 
  65. ),  
  66. 'img' => array( 
  67. 'alt' => true,  
  68. 'align' => true,  
  69. 'height' => true,  
  70. 'width' => true,  
  71. 'src' => true,  
  72. 'srcset' => true,  
  73. 'sizes' => true,  
  74. 'id' => true,  
  75. 'class' => true,  
  76. 'aria-hidden' => true,  
  77. 'data-icon' => true,  
  78. 'itemref' => true,  
  79. 'itemid' => true,  
  80. 'itemprop' => true,  
  81. 'itemscope' => true,  
  82. 'itemtype' => true,  
  83. 'xmlns:v' => true,  
  84. 'typeof' => true,  
  85. 'property' => true,  
  86. 'vocab' => true,  
  87. 'lang' => true 
  88. ),  
  89. 'span' => array( 
  90. 'title' => true,  
  91. 'class' => true,  
  92. 'id' => true,  
  93. 'dir' => true,  
  94. 'align' => true,  
  95. 'lang' => true,  
  96. 'xml:lang' => true,  
  97. 'aria-hidden' => true,  
  98. 'data-icon' => true,  
  99. 'itemref' => true,  
  100. 'itemid' => true,  
  101. 'itemprop' => true,  
  102. 'itemscope' => true,  
  103. 'itemtype' => true,  
  104. 'xmlns:v' => true,  
  105. 'typeof' => true,  
  106. 'property' => true,  
  107. 'vocab' => true,  
  108. 'translate' => true,  
  109. 'lang' => true 
  110. ),  
  111. 'h1' => array( 
  112. 'title' => true,  
  113. 'class' => true,  
  114. 'id' => true,  
  115. 'dir' => true,  
  116. 'align' => true,  
  117. 'lang' => true,  
  118. 'xml:lang' => true,  
  119. 'aria-hidden' => true,  
  120. 'data-icon' => true,  
  121. 'itemref' => true,  
  122. 'itemid' => true,  
  123. 'itemprop' => true,  
  124. 'itemscope' => true,  
  125. 'itemtype' => true,  
  126. 'xmlns:v' => true,  
  127. 'typeof' => true,  
  128. 'property' => true,  
  129. 'vocab' => true,  
  130. 'translate' => true,  
  131. 'lang' => true 
  132. ),  
  133. 'h2' => array( 
  134. 'title' => true,  
  135. 'class' => true,  
  136. 'id' => true,  
  137. 'dir' => true,  
  138. 'align' => true,  
  139. 'lang' => true,  
  140. 'xml:lang' => true,  
  141. 'aria-hidden' => true,  
  142. 'data-icon' => true,  
  143. 'itemref' => true,  
  144. 'itemid' => true,  
  145. 'itemprop' => true,  
  146. 'itemscope' => true,  
  147. 'itemtype' => true,  
  148. 'xmlns:v' => true,  
  149. 'typeof' => true,  
  150. 'property' => true,  
  151. 'vocab' => true,  
  152. 'translate' => true,  
  153. 'lang' => true 
  154. ),  
  155. 'meta' => array( 
  156. 'content' => true,  
  157. 'property' => true,  
  158. 'vocab' => true,  
  159. 'itemprop' => true 
  160. ); 
  161. return mtekk_adminKit::array_merge_recursive($tags, $allowed_html); 
  162. public function get_version() 
  163. return self::version; 
  164. public function wp_loaded() 
  165. breadcrumb_navxt::setup_options($this->opt); 
  166. public function uninstall() 
  167. $this->admin->uninstall(); 
  168. /** 
  169. * Sets up the extended options for any CPTs, taxonomies or extensions 
  170. *  
  171. * @param array $opt The options array, passed by reference 
  172. */ 
  173. static public function setup_options(&$opt) 
  174. //Add custom post types 
  175. breadcrumb_navxt::find_posttypes($opt); 
  176. //Add custom taxonomy types 
  177. breadcrumb_navxt::find_taxonomies($opt); 
  178. //Let others hook into our settings 
  179. $opt = apply_filters('bcn_settings_init', $opt); 
  180. /** 
  181. * Places settings into $opts array, if missing, for the registered post types 
  182. *  
  183. * @param array $opts 
  184. */ 
  185. static function find_posttypes(&$opts) 
  186. global $wp_post_types, $wp_taxonomies; 
  187. //Loop through all of the post types in the array 
  188. foreach($wp_post_types as $post_type) 
  189. //We only want custom post types 
  190. if(!$post_type->_builtin) 
  191. if(!isset($opts['bpost_' . $post_type->name . '_taxonomy_referer'])) 
  192. //Default to not letting the refering page influence the referer 
  193. $opts['bpost_' . $post_type->name . '_taxonomy_referer'] = false; 
  194. //If the post type does not have settings in the options array yet, we need to load some defaults 
  195. if(!isset($opts['Hpost_' . $post_type->name . '_template']) || !$post_type->hierarchical && !isset($opts['Spost_' . $post_type->name . '_taxonomy_type'])) 
  196. //Add the necessary option array members 
  197. $opts['Hpost_' . $post_type->name . '_template'] = bcn_breadcrumb::get_default_template(); 
  198. $opts['Hpost_' . $post_type->name . '_template_no_anchor'] = bcn_breadcrumb::default_template_no_anchor; 
  199. if($post_type->has_archive == true || is_string($post_type->has_archive)) 
  200. $opts['bpost_' . $post_type->name . '_archive_display'] = true; 
  201. else 
  202. $opts['bpost_' . $post_type->name . '_archive_display'] = false;  
  203. //Default to not showing a post_root 
  204. $opts['apost_' . $post_type->name . '_root'] = 0; 
  205. //Default to not displaying a taxonomy 
  206. $opts['bpost_' . $post_type->name . '_taxonomy_display'] = false; 
  207. //Loop through all of the possible taxonomies 
  208. foreach($wp_taxonomies as $taxonomy) 
  209. //Check for non-public taxonomies 
  210. if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name)) 
  211. continue; 
  212. //Activate the first taxonomy valid for this post type and exit the loop 
  213. if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type)) 
  214. $opts['bpost_' . $post_type->name . '_taxonomy_display'] = true; 
  215. $opts['Spost_' . $post_type->name . '_taxonomy_type'] = $taxonomy->name; 
  216. break; 
  217. //If there are no valid taxonomies for this type, we default to not displaying taxonomies for this post type 
  218. if(!isset($opts['Spost_' . $post_type->name . '_taxonomy_type'])) 
  219. $opts['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_DATE'; 
  220. /** 
  221. * Places settings into $opts array, if missing, for the registered taxonomies 
  222. *  
  223. * @param $opts 
  224. */ 
  225. static function find_taxonomies(&$opts) 
  226. global $wp_taxonomies; 
  227. //We'll add our custom taxonomy stuff at this time 
  228. foreach($wp_taxonomies as $taxonomy) 
  229. //We only want custom taxonomies 
  230. if(!$taxonomy->_builtin) 
  231. //If the taxonomy does not have settings in the options array yet, we need to load some defaults 
  232. if(!isset($opts['Htax_' . $taxonomy->name . '_template'])) 
  233. //Add the necessary option array members 
  234. $opts['Htax_' . $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%%"><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', $taxonomy->labels->singular_name), 'breadcrumb-navxt'); 
  235. $opts['Htax_' . $taxonomy->name . '_template_no_anchor'] = __(sprintf('<span property="itemListElement" typeof="ListItem"><span property="name">%%htitle%%</span><meta property="position" content="%%position%%"></span>', $taxonomy->labels->singular_name), 'breadcrumb-navxt'); 
  236. /** 
  237. * Hooks into the theme hook alliance tha_breadcrumb_navigation filter and replaces the trail 
  238. * with one generated by Breadcrumb NavXT 
  239. *  
  240. * @param string $bradcrumb_trail The string breadcrumb trail that we will replace 
  241. * @return string The Breadcrumb NavXT assembled breadcrumb trail 
  242. */ 
  243. public function tha_compat($breadcrumb_trail) 
  244. //Return our breadcrumb trail 
  245. return $this->display(true); 
  246. /** 
  247. * Function updates the breadcrumb_trail options array from the database in a semi intellegent manner 
  248. *  
  249. * @since 5.0.0 
  250. */ 
  251. private function get_settings() 
  252. //Grab the current settings for the current local site from the db 
  253. $this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $this->opt); 
  254. //If we're in multisite mode, look at the three BCN_SETTINGS globals 
  255. if(is_multisite()) 
  256. if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK) 
  257. //Grab the current network wide settings 
  258. $this->breadcrumb_trail->opt = wp_parse_args(get_site_option('bcn_options'), $this->opt); 
  259. else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL) 
  260. //Grab the current settings for the current local site from the db 
  261. $this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $this->breadcrumb_trail->opt); 
  262. else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK) 
  263. //Grab the current settings from the db 
  264. $this->breadcrumb_trail->opt = wp_parse_args(get_site_option('bcn_options'), get_option('bcn_options')); 
  265. /** 
  266. * Outputs the breadcrumb trail 
  267. *  
  268. * @param bool $return Whether to return or echo the trail. 
  269. * @param bool $linked Whether to allow hyperlinks in the trail or not. 
  270. * @param bool $reverse Whether to reverse the output or not. 
  271. */ 
  272. public function display($return = false, $linked = true, $reverse = false) 
  273. $this->get_settings(); 
  274. //Generate the breadcrumb trail 
  275. $this->breadcrumb_trail->fill(); 
  276. return $this->breadcrumb_trail->display($return, $linked, $reverse); 
  277. /** 
  278. * Outputs the breadcrumb trail with each element encapsulated with li tags 
  279. *  
  280. * @since 3.2.0 
  281. * @param bool $return Whether to return or echo the trail. 
  282. * @param bool $linked Whether to allow hyperlinks in the trail or not. 
  283. * @param bool $reverse Whether to reverse the output or not. 
  284. */ 
  285. public function display_list($return = false, $linked = true, $reverse = false) 
  286. $this->get_settings(); 
  287. //Generate the breadcrumb trail 
  288. $this->breadcrumb_trail->fill(); 
  289. return $this->breadcrumb_trail->display_list($return, $linked, $reverse);