Exemplo n.º 1
0
 function test_adding_node()
 {
     $n = new Navigation();
     $blog_node = (object) array('data' => 'Blog', 'attr' => (object) array('id' => 'blog', 'sort' => 0));
     /**
      * Add blog page.
      */
     $n->add($blog_node, 'index');
     /**
      * Should have second id now:
      *
      * index
      * - blog
      */
     $this->assertEquals($n->get_all_ids(), array('index', 'blog'));
     // Remove and re-add index
     $n->remove('index');
     $this->assertEquals($n->get_all_ids(), array());
     $n->add('index');
     $index_node = $n->node('index');
     $expected_index = (object) array('data' => 'Home', 'attr' => (object) array('id' => 'index', 'sort' => 0));
     /*
      * Should have index node with title 'Home' from the database.
      */
     $this->assertEquals($expected_index, $index_node);
 }
Exemplo n.º 2
0
<?php

/**
 * Displays a single section of the navigation as a
 * bulleted list, with `class="current"` added to
 * the current page's `<li>` element for custom styling.
 */
$n = new Navigation();
$section = $n->node($data['section']);
echo '<ul>';
foreach ($section->children as $item) {
    if ($item->attr->id == $page->id) {
        printf('<li class="current"><a href="/%s">%s</a></li>', $item->attr->id, $item->data);
    } else {
        printf('<li><a href="/%s">%s</a></li>', $item->attr->id, $item->data);
    }
}
echo '</ul>';
Exemplo n.º 3
0
<?php

/**
 * Updates the name of a page in the navigation. Called via a hook from
 * the page edit form.
 */
if (!$this->internal) {
    die('Must be called by another handler');
}
$n = new Navigation();
$node = $n->node($this->data['page']);
if ($node) {
    $node->data = !empty($this->data['menu_title']) ? $this->data['menu_title'] : $this->data['title'];
    if ($this->data['page'] != $this->data['id']) {
        // Update ID if renamed
        $node->attr->id = $this->data['id'];
    }
    $n->save();
    require_once 'apps/navigation/lib/Functions.php';
    navigation_clear_cache();
}