| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Displays a language list |
| 5 |
* |
| 6 |
* @since 1.2 |
| 7 |
*/ |
| 8 |
class PLL_Walker_List extends Walker { |
| 9 |
public $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); |
| 10 |
|
| 11 |
/** |
| 12 |
* Outputs one element |
| 13 |
* |
| 14 |
* @since 1.2 |
| 15 |
* |
| 16 |
* @param string $output Passed by reference. Used to append additional content. |
| 17 |
* @param object $element The data object. |
| 18 |
* @param int $depth Depth of the item. |
| 19 |
* @param array $args An array of additional arguments. |
| 20 |
* @param int $current_object_id ID of the current item. |
| 21 |
*/ |
| 22 |
public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { |
| 23 |
$output .= sprintf( |
| 24 |
'%6$s<li class="%1$s"><a lang="%2$s" hreflang="%2$s" href="%3$s">%4$s%5$s</a></li>%7$s', |
| 25 |
esc_attr( implode( ' ', $element->classes ) ), |
| 26 |
esc_attr( $element->locale ), |
| 27 |
esc_url( $element->url ), |
| 28 |
$element->flag, |
| 29 |
$args['show_flags'] ? sprintf( '<span style="margin-%1$s:0.3em;">%2$s</span>', is_rtl() ? 'right' : 'left', esc_html( $element->name ) ) : esc_html( $element->name ), |
| 30 |
'discard' === $args['item_spacing'] ? '' : "\t", |
| 31 |
'discard' === $args['item_spacing'] ? '' : "\n" |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Overrides Walker::display_element as it expects an object with a parent property |
| 37 |
* |
| 38 |
* @since 1.2 |
| 39 |
* |
| 40 |
* @param object $element Data object. |
| 41 |
* @param array $children_elements List of elements to continue traversing. |
| 42 |
* @param int $max_depth Max depth to traverse. |
| 43 |
* @param int $depth Depth of current element. |
| 44 |
* @param array $args An array of arguments. |
| 45 |
* @param string $output Passed by reference. Used to append additional content. |
| 46 |
*/ |
| 47 |
public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { |
| 48 |
$element = (object) $element; // Make sure we have an object |
| 49 |
$element->parent = $element->id = 0; // Don't care about this |
| 50 |
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Overrides Walker:walk to set depth argument |
| 55 |
* |
| 56 |
* @since 1.2 |
| 57 |
* |
| 58 |
* @param array $elements elements to display |
| 59 |
* @param array $args |
| 60 |
* @return string |
| 61 |
*/ |
| 62 |
public function walk( $elements, $args = array() ) { |
| 63 |
return parent::walk( $elements, -1, $args ); |
| 64 |
} |
| 65 |
} |
| 66 |
|