コード例 #1
0
ファイル: test-library.php プロジェクト: iamapioneer/sdas
 /**
  *	Covers bu_navigation_supported_post_types()
  */
 public function test_bu_navigation_supported_post_types()
 {
     // Post Types without Link pages + test
     $exp_post_types = array("page" => "page", "test" => "test");
     $post_types = bu_navigation_supported_post_types();
     $this->assertEquals($exp_post_types, $post_types);
     // Add "Link" to expected post types
     $exp_post_types["bu_link"] = "bu_link";
     $post_types = bu_navigation_supported_post_types(true);
     $this->assertEquals($exp_post_types, $post_types);
 }
コード例 #2
0
 /**
  * Display the content navigation widget
  *
  * @param array $args widget args
  * @param array $instance widget instance args
  */
 function widget($args, $instance)
 {
     global $post;
     // Only display navigation widget for supported post types
     if (!in_array($post->post_type, bu_navigation_supported_post_types())) {
         return;
     }
     extract($args);
     $title = '';
     // Set widget title
     if ($instance['navigation_title'] == 'static' && !empty($instance['navigation_title_text'])) {
         $title = apply_filters('widget_title', $instance['navigation_title_text']);
         // Wrap with anchor tag if URL is present
         if (!empty($instance['navigation_title_url'])) {
             $title = sprintf('<a class="content_nav_header" href="%s">%s</a>', $instance['navigation_title_url'], $title);
         }
     } else {
         if ($instance['navigation_title'] == 'section') {
             // Use navigation label of top level post for current section
             $title = $this->section_title($args, $instance);
         }
     }
     // Prepare arguments to bu_navigation_list_pages
     $list_args = array('page_id' => $post->ID, 'title_li' => '', 'echo' => 0, 'container_id' => BU_WIDGET_PAGES_LIST_ID, 'post_types' => $post->post_type);
     // Set list arguments based on navigation style
     if (array_key_exists('navigation_style', $instance)) {
         $list_args['style'] = $instance['navigation_style'];
         if ($instance['navigation_style'] == 'section') {
             $list_args['navigate_in_section'] = 1;
             if (is_404()) {
                 return '';
             }
         } else {
             if ($instance['navigation_style'] == 'adaptive') {
                 add_action('bu_navigation_widget_before_list', 'bu_navigation_widget_adaptive_before_list');
             }
         }
     } else {
         error_log("No nav label widget style set!");
     }
     do_action('bu_navigation_widget_before_list');
     // Fetch markup and display
     $out = bu_navigation_list_pages(apply_filters('widget_bu_pages_args', $list_args));
     if (!empty($out)) {
         printf('%s<div id="contentnav">', $before_widget);
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         printf('%s</div>', $out);
         echo $after_widget;
     }
 }
コード例 #3
0
ファイル: library.php プロジェクト: iamapioneer/sdas
/**
 * Displays a select box containing page parents, used to filter page list by parent
 *
 * Relocated from the navigation plugin (bu-filter-pages.php) to remove dependency on plugin.
 *
 * @return boolean TRUE if the box was displayed, FALSE otherwise.
 */
function bu_filter_pages_parent_dropdown($pages_by_parent, $default = 0, $parent = 0, $level = 0)
{
    $post_types = bu_navigation_supported_post_types();
    if (is_array($pages_by_parent) && array_key_exists($parent, $pages_by_parent) && count($pages_by_parent) > 0) {
        foreach ($pages_by_parent[$parent] as $p) {
            if (!in_array($p->post_type, $post_types)) {
                continue;
            }
            // only show valid post types
            if (!array_key_exists($p->ID, $pages_by_parent)) {
                continue;
            }
            // don't show pages with no children
            $padding = str_repeat('&nbsp;', $level * 3);
            $selected = $p->ID == $default ? 'selected="selected"' : '';
            printf("\n\t<option value=\"%d\" %s>%s%s</option>\r", $p->ID, $selected, $padding, esc_html($p->post_title));
            bu_filter_pages_parent_dropdown($pages_by_parent, $default, $p->ID, $level + 1);
        }
        return TRUE;
    }
    return FALSE;
}