PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/class-switcher-content.php

https://github.com/humanmade/babble
PHP | 551 lines | 388 code | 38 blank | 125 comment | 92 complexity | c24bea8dc08db48a16f51c84a08f2a09 MD5 | raw file
  1. <?php
  2. /**
  3. * Class for providing the switch/create links for the current
  4. * content items. Works in the admin or public areas of the site.
  5. *
  6. * Used by the admin bar class, for example.
  7. *
  8. * @package Babble
  9. * @since 0.2
  10. */
  11. class Babble_Switcher_Menu {
  12. /**
  13. * The translations for the current content item.
  14. *
  15. * @var array
  16. **/
  17. protected $translations;
  18. /**
  19. * A multi-dimensional array of the links for the current
  20. * translation structure.
  21. *
  22. * @var array
  23. **/
  24. protected $links;
  25. /**
  26. * The WP Screen object
  27. *
  28. * @var object
  29. **/
  30. protected $screen;
  31. // PUBLIC METHODS
  32. // ==============
  33. /**
  34. * Returns an array of links to the other objects
  35. * in this translation group. Each element in the array
  36. * looks like:
  37. * array (
  38. *
  39. * )
  40. *
  41. * @param string $id_prefix A prefix to the ID for each item
  42. * @return array An array of link info for the objects in this current translation group.
  43. **/
  44. public function get_switcher_links( $id_prefix ) {
  45. $this->populate_links();
  46. return $this->links;
  47. }
  48. // PRIVATE/PROTECTED METHODS
  49. // =========================
  50. /**
  51. * undocumented function
  52. *
  53. * @return void
  54. **/
  55. protected function populate_links() {
  56. if ( is_array( $this->links ) && ! empty( $this->links ) )
  57. return; // Already done
  58. $this->links = array();
  59. // @FIXME: Not sure this is the best way to specify languages
  60. $alt_langs = bbl_get_active_langs();
  61. $this->screen = is_admin() ? get_current_screen() : false;
  62. // Create a handy flag for whether we're editing a post or listing posts
  63. $editing_post = false;
  64. $listing_posts = false;
  65. if ( is_admin() ) {
  66. $editing_post = ( is_admin() && 'post' == $this->screen->base && isset( $_GET[ 'post' ] ) );
  67. $listing_posts = ( is_admin() && 'edit' == $this->screen->base && ! isset( $_GET[ 'post' ] ) );
  68. }
  69. // Create a handy flag for whether we're editing a term or listing terms
  70. $editing_term = false;
  71. $listing_terms = false;
  72. if ( is_admin() ) {
  73. $editing_term = ( is_admin() && 'edit-tags' == $this->screen->base && isset( $_GET[ 'tag_ID' ] ) );
  74. $listing_terms = ( is_admin() && 'edit-tags' == $this->screen->base && ! isset( $_GET[ 'tag_ID' ] ) );
  75. }
  76. if ( is_singular() || is_single() || $editing_post ) {
  77. $this->translations = bbl_get_post_translations( get_the_ID() );
  78. $this->jobs = bbl_get_post_jobs( get_the_ID() );
  79. } else if ( 'page' == get_option( 'show_on_front' ) && is_home() ) {
  80. $this->translations = bbl_get_post_translations( get_option( 'page_for_posts' ) );
  81. $this->jobs = bbl_get_post_jobs( get_option( 'page_for_posts' ) );
  82. } else if ( ( !is_admin() and ( is_tax() || is_category() ) ) || $editing_term ) {
  83. if ( isset( $_REQUEST[ 'tag_ID' ] ) )
  84. $term = get_term( (int) @ $_REQUEST[ 'tag_ID' ], $this->screen->taxonomy );
  85. else
  86. $term = get_queried_object();
  87. $this->translations = bbl_get_term_translations( $term->term_id, $term->taxonomy );
  88. $this->jobs = bbl_get_term_jobs( $term->term_id, $term->taxonomy );
  89. }
  90. foreach ( $alt_langs as $i => & $alt_lang ) {
  91. // @TODO: Convert to a switch statement, convert all the vars to a single property on the class
  92. if ( is_admin() ) {
  93. if ( $editing_post ) { // Admin: Editing post link
  94. $this->add_admin_post_link( $alt_lang );
  95. } else if ( $editing_term ) { // Admin: Editing term link
  96. $this->add_admin_term_link( $alt_lang );
  97. } else if ( $listing_posts ) { // Admin: Listing posts link
  98. $this->add_admin_list_posts_link( $alt_lang );
  99. } else if ( $listing_terms ) { // Admin: Listing terms link
  100. $this->add_admin_list_terms_link( $alt_lang );
  101. } else { // Admin: Generic link link
  102. $this->add_admin_generic_link( $alt_lang );
  103. }
  104. continue;
  105. }
  106. if (
  107. is_singular() || is_single() ||
  108. ( 'page' == get_option( 'show_on_front' ) && is_home() )
  109. ) { // Single posts, pages, blog homepage
  110. $this->add_post_link( $alt_lang );
  111. continue;
  112. }
  113. // Don't add a switcher link if the language is not public and
  114. // the user cannot edit any posts (as a rough guide to whether
  115. // they are more than just a subscriber).
  116. // @TODO this cap check should move into each add_*_link() method:
  117. if ( ! bbl_is_public_lang( $alt_lang->code ) && ! current_user_can( 'edit_posts' ) )
  118. continue;
  119. if ( is_front_page() ) { // Language homepage
  120. // is_front_page works for language homepages, phew
  121. $this->add_front_page_link( $alt_lang );
  122. } else if ( is_post_type_archive() ) { // Post type archives
  123. $this->add_post_type_archive_link( $alt_lang );
  124. } else if ( is_tax() || is_category() ) { // Category or taxonomy archive
  125. $this->add_taxonomy_archive_link( $alt_lang );
  126. } else { // 404's, amongst other things
  127. $this->add_arbitrary_link( $alt_lang );
  128. }
  129. }
  130. // Make up the class attribute on all links
  131. foreach ( $this->links as $lang_code => & $link ){
  132. $link[ 'class' ] = implode( ' ', $link[ 'classes' ] );
  133. $link[ 'active' ] = $lang_code == bbl_get_current_lang_code();
  134. }
  135. }
  136. /**
  137. * Add an admin link to the same page, but with the language switch GET
  138. * parameter set.
  139. *
  140. * @param object $lang A Babble language object for this link
  141. * @return void
  142. **/
  143. protected function add_admin_generic_link( $lang ) {
  144. $classes = array();
  145. $href = add_query_arg( array( 'lang' => $lang->code ) );
  146. $href = apply_filters( 'bbl_switch_admin_generic_link', $href, $lang );
  147. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  148. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  149. $classes[] = 'bbl-admin';
  150. $classes[] = 'bbl-admin-generic';
  151. $classes[] = 'bbl-lang';
  152. if ( $lang->code == bbl_get_current_lang_code() )
  153. $classes[] = 'bbl-active';
  154. // Preventing errors on initial plugin load - before settings saved the first time
  155. if ( empty( $lang->display_name ) ) {
  156. $lang->display_name = '';
  157. }
  158. $this->links[ $lang->code ] = array(
  159. 'classes' => $classes,
  160. 'href' => $href,
  161. 'id' => $lang->url_prefix,
  162. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  163. 'title' => $title,
  164. 'lang' => $lang,
  165. );
  166. }
  167. /**
  168. * Add an admin term link to the parent link provided (by reference).
  169. *
  170. * @param object $lang A Babble language object for this link
  171. * @return void
  172. **/
  173. protected function add_admin_term_link( $lang ) {
  174. $classes = array();
  175. if ( isset( $this->translations[ $lang->code ]->term_id ) ) { // Translation exists
  176. $args = array(
  177. 'lang' => $lang->code,
  178. 'taxonomy' => $this->translations[ $lang->code ]->taxonomy,
  179. 'tag_ID' => $this->translations[ $lang->code ]->term_id
  180. );
  181. $href = add_query_arg( $args );
  182. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  183. $classes[] = 'bbl-existing-edit';
  184. $classes[] = 'bbl-existing-edit-term';
  185. } else if ( isset( $this->jobs[ $lang->code ]->ID ) ) { // Translation job exists
  186. $href = get_edit_post_link( $this->jobs[ $lang->code ]->ID, 'url' );
  187. $title = sprintf( _x( '%s: %s', 'Translation job status and language (example: In Progress: French)', 'babble' ), get_post_status_object( $this->jobs[ $lang->code ]->post_status )->label, $lang->display_name );
  188. $classes[] = 'bbl-job-edit';
  189. $classes[] = 'bbl-job-edit-term';
  190. } else { // Translation does not exist
  191. $default_term = (int) $_GET[ 'tag_ID' ];
  192. $href = bbl_get_new_term_translation_url( $default_term, $lang->code, $this->screen->taxonomy );
  193. $title = sprintf( __( 'Create for %s', 'babble' ), $lang->display_name );
  194. $classes[] = 'bbl-add';
  195. $classes[] = 'bbl-add-term';
  196. }
  197. $href = apply_filters( 'bbl_switch_admin_term_link', $href, $lang, $this->translations );
  198. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  199. $classes[] = 'bbl-admin';
  200. $classes[] = 'bbl-admin-taxonomy';
  201. $classes[] = 'bbl-admin-edit-term';
  202. $classes[] = 'bbl-lang';
  203. if ( $lang->code == bbl_get_current_lang_code() )
  204. $classes[] = 'bbl-active';
  205. $this->links[ $lang->code ] = array(
  206. 'classes' => $classes,
  207. 'href' => $href,
  208. 'id' => $lang->url_prefix,
  209. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  210. 'title' => $title,
  211. 'lang' => $lang,
  212. );
  213. }
  214. /**
  215. * Add an admin list terms screen link to the parent link provided (by reference).
  216. *
  217. * @param object $lang A Babble language object for this link
  218. * @return void
  219. **/
  220. protected function add_admin_list_terms_link( $lang ) {
  221. $classes = array();
  222. $args = array(
  223. 'lang' => $lang->code,
  224. 'taxonomy' => bbl_get_taxonomy_in_lang( $this->screen->taxonomy, $lang->code ),
  225. );
  226. $href = add_query_arg( $args );
  227. $href = apply_filters( 'bbl_switch_admin_list_terms_link', $href, $lang );
  228. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  229. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  230. $classes[] = 'bbl-admin';
  231. $classes[] = 'bbl-admin-taxonomy';
  232. $classes[] = 'bbl-admin-list-terms';
  233. $classes[] = 'bbl-lang';
  234. if ( $lang->code == bbl_get_current_lang_code() )
  235. $classes[] = 'bbl-active';
  236. $this->links[ $lang->code ] = array(
  237. 'classes' => $classes,
  238. 'href' => $href,
  239. 'id' => $lang->url_prefix,
  240. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  241. 'title' => $title,
  242. 'lang' => $lang,
  243. );
  244. }
  245. /**
  246. * Add an admin post link to the parent link provided (by reference)
  247. *
  248. * @param object $lang A Babble language object for this link
  249. * @return void
  250. **/
  251. protected function add_admin_post_link( $lang ) {
  252. $classes = array();
  253. if ( isset( $this->translations[ $lang->code ]->ID ) ) { // Translation exists
  254. $href = add_query_arg( array( 'lang' => $lang->code, 'post' => $this->translations[ $lang->code ]->ID ) );
  255. $href = remove_query_arg( 'message', $href );
  256. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  257. $classes[] = 'bbl-existing-edit';
  258. $classes[] = 'bbl-existing-edit-post';
  259. } else if ( isset( $this->jobs[ $lang->code ]->ID ) ) { // Translation job exists
  260. $href = add_query_arg( array( 'lang' => $lang->code, 'post' => $this->jobs[ $lang->code ]->ID ) );
  261. $href = remove_query_arg( 'message', $href );
  262. $title = sprintf( _x( '%s: %s', 'Translation job status and language (example: In Progress: French)', 'babble' ), get_post_status_object( $this->jobs[ $lang->code ]->post_status )->label, $lang->display_name );
  263. $classes[] = 'bbl-job-edit';
  264. $classes[] = 'bbl-job-edit-post';
  265. } else { // Translation does not exist
  266. if ( isset( $this->translations[ bbl_get_default_lang_code() ] ) ) {
  267. $default_post = $this->translations[ bbl_get_default_lang_code() ];
  268. $href = bbl_get_new_post_translation_url( $default_post, $lang->code );
  269. $title = sprintf( __( 'Create for %s', 'babble' ), $lang->display_name );
  270. $classes[] = 'bbl-add';
  271. $classes[] = 'bbl-add-post';
  272. } else {
  273. return; // Don't create the switcher menu items yet
  274. }
  275. }
  276. $href = apply_filters( 'bbl_switch_admin_post_link', $href, $lang, $this->translations );
  277. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  278. $classes[] = 'bbl-admin';
  279. $classes[] = 'bbl-admin-edit-post';
  280. $classes[] = 'bbl-admin-post-type';
  281. $classes[] = 'bbl-lang';
  282. $classes[] = 'bbl-post';
  283. if ( $lang->code == bbl_get_current_lang_code() )
  284. $classes[] = 'bbl-active';
  285. $this->links[ $lang->code ] = array(
  286. 'classes' => $classes,
  287. 'href' => $href,
  288. 'id' => $lang->url_prefix,
  289. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  290. 'title' => $title,
  291. 'lang' => $lang,
  292. );
  293. }
  294. /**
  295. * Add an admin list posts screen link to the parent link provided (by reference).
  296. *
  297. * @param object $lang A Babble language object for this link
  298. * @return void
  299. **/
  300. protected function add_admin_list_posts_link( $lang ) {
  301. $classes = array();
  302. $args = array(
  303. 'lang' => $lang->code,
  304. 'post_type' => bbl_get_post_type_in_lang( $this->screen->post_type, $lang->code ),
  305. );
  306. $href = add_query_arg( $args );
  307. $href = apply_filters( 'bbl_switch_admin_list_posts_link', $href, $lang );
  308. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  309. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  310. $classes[] = 'bbl-admin';
  311. $classes[] = 'bbl-admin-edit-post';
  312. $classes[] = 'bbl-admin-post-type';
  313. $classes[] = 'bbl-lang';
  314. if ( $lang->code == bbl_get_current_lang_code() )
  315. $classes[] = 'bbl-active';
  316. $this->links[ $lang->code ] = array(
  317. 'classes' => $classes,
  318. 'href' => $href,
  319. 'id' => $lang->url_prefix,
  320. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  321. 'title' => $title,
  322. 'lang' => $lang,
  323. );
  324. }
  325. /**
  326. * Add a post link to the parent link provided (by reference)
  327. *
  328. * @param object $lang A Babble language object for this link
  329. * @return void
  330. **/
  331. protected function add_post_link( $lang ) {
  332. $classes = array();
  333. if ( isset( $this->translations[ $lang->code ] ) ) { // Translation exists
  334. // Don't add this link if the user cannot edit THIS post and
  335. // the language is not public.
  336. if (
  337. ! bbl_is_public_lang( $lang->code ) &&
  338. ! current_user_can( 'edit_post', $this->translations[ $lang->code ]->ID )
  339. ) {
  340. return;
  341. }
  342. bbl_switch_to_lang( $lang->code );
  343. $href = get_permalink( $this->translations[ $lang->code ]->ID );
  344. bbl_restore_lang();
  345. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  346. $classes[] = 'bbl-existing';
  347. $classes[] = 'bbl-existing-post';
  348. } else if ( current_user_can( 'edit_post', $this->translations[ bbl_get_default_lang_code() ]->ID ) ) {
  349. // Generate a URL to create the translation
  350. $default_post = $this->translations[ bbl_get_default_lang_code() ];
  351. $href = bbl_get_new_post_translation_url( $default_post, $lang->code );
  352. $title = sprintf( __( 'Create for %s', 'babble' ), $lang->display_name );
  353. $classes[] = 'bbl-add';
  354. $classes[] = 'bbl-add-post';
  355. } else {
  356. // Don't show links to non-public languages
  357. if ( ! bbl_is_public_lang( $lang->code ) )
  358. return;
  359. // Show a blank link for unavailable translations
  360. $href = false;
  361. $title = sprintf( __( 'This content is unavailable in %s', 'babble' ), $lang->display_name );
  362. $classes[] = 'bbl-unavailable';
  363. }
  364. $href = apply_filters( 'bbl_switch_post_link', $href, $lang, $this->translations );
  365. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  366. $classes[] = 'bbl-lang';
  367. $classes[] = 'bbl-post';
  368. if ( $lang->code == bbl_get_current_lang_code() )
  369. $classes[] = 'bbl-active';
  370. $this->links[ $lang->code ] = array(
  371. 'classes' => $classes,
  372. 'href' => $href,
  373. 'id' => $lang->url_prefix,
  374. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  375. 'title' => $title,
  376. 'lang' => $lang,
  377. );
  378. }
  379. /**
  380. * Add a link to a language specific front page.
  381. *
  382. * @TODO: Is this any different from a regular post link?
  383. *
  384. * @param object $lang A Babble language object for this link
  385. * @return void
  386. **/
  387. protected function add_front_page_link( $lang ) {
  388. global $bbl_locale;
  389. $classes = array();
  390. remove_filter( 'home_url', array( $bbl_locale, 'home_url'), null, 2 );
  391. $href = home_url( "$lang->url_prefix/" );
  392. add_filter( 'home_url', array( $bbl_locale, 'home_url'), null, 2 );
  393. $href = apply_filters( 'bbl_switch_front_page_link', $href, $lang );
  394. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  395. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  396. $classes[] = 'bbl-existing';
  397. $classes[] = 'bbl-front-page';
  398. $classes[] = 'bbl-lang';
  399. if ( $lang->code == bbl_get_current_lang_code() )
  400. $classes[] = 'bbl-active';
  401. $this->links[ $lang->code ] = array(
  402. 'classes' => $classes,
  403. 'id' => $lang->url_prefix,
  404. 'href' => $href,
  405. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  406. 'title' => $title,
  407. 'lang' => $lang,
  408. );
  409. }
  410. /**
  411. * Add a link to a post_type archive.
  412. *
  413. * @param object $lang A Babble language object for this link
  414. * @return void
  415. **/
  416. protected function add_post_type_archive_link( $lang ) {
  417. $classes = array();
  418. bbl_switch_to_lang( $lang->code );
  419. $href = get_post_type_archive_link( get_query_var( 'post_type' ) );
  420. bbl_restore_lang();
  421. $href = apply_filters( 'bbl_switch_post_type_archive_link', $href, $lang );
  422. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  423. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  424. $classes[] = 'bbl-existing';
  425. $classes[] = 'bbl-post-type-archive';
  426. $classes[] = 'bbl-lang';
  427. if ( $lang->code == bbl_get_current_lang_code() )
  428. $classes[] = 'bbl-active';
  429. $this->links[ $lang->code ] = array(
  430. 'classes' => $classes,
  431. 'id' => $lang->url_prefix,
  432. 'href' => $href,
  433. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  434. 'title' => $title,
  435. 'lang' => $lang,
  436. );
  437. }
  438. /**
  439. * Add a link to a taxonomy archive.
  440. *
  441. * @param object $lang A Babble language object for this link
  442. * @return void
  443. **/
  444. protected function add_taxonomy_archive_link( $lang ) {
  445. $classes = array();
  446. $queried_object = get_queried_object();
  447. if ( ! bbl_is_translated_taxonomy( $queried_object->taxonomy ) ) {
  448. $this->add_arbitrary_link( $lang );
  449. return;
  450. } elseif ( isset( $this->translations[ $lang->code ]->term_id ) ) { // Translation exists
  451. bbl_switch_to_lang( $lang->code );
  452. $href = get_term_link( $this->translations[ $lang->code ], bbl_get_base_taxonomy( $queried_object->taxonomy ) );
  453. bbl_restore_lang();
  454. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  455. $classes[] = 'bbl-existing';
  456. $classes[] = 'bbl-existing-term';
  457. } else { // Translation does not exist
  458. // Generate a URL to create the translation
  459. $default_term = $this->translations[ bbl_get_default_lang_code() ];
  460. $href = bbl_get_new_term_translation_url( $default_term->term_id, $lang->code, $default_term->taxonomy );
  461. $title = sprintf( __( 'Create for %s', 'babble' ), $lang->display_name );
  462. $classes[] = 'bbl-add';
  463. $classes[] = 'bbl-add-term';
  464. }
  465. $href = apply_filters( 'bbl_switch_taxonomy_archive_link', $href, $lang, $this->translations );
  466. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  467. $classes[] = 'bbl-lang';
  468. $classes[] = 'bbl-term';
  469. if ( $lang == bbl_get_current_lang_code() )
  470. $classes[] = 'bbl-active';
  471. $this->links[ $lang->code ] = array(
  472. 'classes' => $classes,
  473. 'href' => $href,
  474. 'id' => $lang->url_prefix,
  475. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  476. 'title' => $title,
  477. 'lang' => $lang,
  478. );
  479. }
  480. /**
  481. * Add a link to an arbitrary link, e.g. 404, within the site.
  482. *
  483. * @param object $lang A Babble language object for this link
  484. * @return void
  485. **/
  486. protected function add_arbitrary_link( $lang ) {
  487. $classes = array();
  488. if ( ! preg_match( '|^/[^/]+/(.*)?|', $_SERVER[ 'REQUEST_URI' ], $matches ) )
  489. return;
  490. bbl_switch_to_lang( $lang->code );
  491. $href = home_url( $matches[ 1 ] );
  492. bbl_restore_lang();
  493. $href = apply_filters( 'bbl_switch_arbitrary_link', $href, $lang );
  494. $title = sprintf( __( 'Switch to %s', 'babble' ), $lang->display_name );
  495. $classes[] = 'bbl-existing';
  496. $classes[] = 'bbl-existing-term';
  497. $classes[] = "bbl-lang-$lang->code bbl-lang-$lang->url_prefix";
  498. $classes[] = 'bbl-lang';
  499. $classes[] = 'bbl-term';
  500. if ( $lang == bbl_get_current_lang_code() )
  501. $classes[] = 'bbl-active';
  502. $this->links[ $lang->code ] = array(
  503. 'classes' => $classes,
  504. 'href' => $href,
  505. 'id' => $lang->url_prefix,
  506. 'meta' => array( 'class' => strtolower( join( ' ', array_unique( $classes ) ) ) ),
  507. 'title' => $title,
  508. 'lang' => $lang,
  509. );
  510. }
  511. }
  512. global $bbl_switcher_menu;
  513. $bbl_switcher_menu = new Babble_Switcher_Menu();