Esempio n. 1
0
 private function get_page_prefix()
 {
     if (!$this->page) {
         throw new Exception("No page set for the manual dispatcher");
     }
     $prefix = "{$_MIDGARD['prefix']}/";
     $host_mc = midgard_host::new_collector('id', $_MIDGARD['host']);
     $host_mc->set_key_property('root');
     $host_mc->execute();
     $roots = $host_mc->list_keys();
     if (!$roots) {
         throw new Exception("Failed to load root page data for host {$_MIDGARD['host']}");
     }
     $root_id = null;
     foreach ($roots as $root => $array) {
         $root_id = $root;
         break;
     }
     if ($this->page->id == $root_id) {
         return $prefix;
     }
     $page_path = '';
     $page_id = $this->page->id;
     while ($page_id && $page_id != $root_id) {
         $parent_mc = midgard_page::new_collector('id', $page_id);
         $parent_mc->set_key_property('up');
         $parent_mc->add_value_property('name');
         $parent_mc->execute();
         $parents = $parent_mc->list_keys();
         foreach ($parents as $parent => $array) {
             $page_id = $parent;
             $page_path = $parent_mc->get_subkey($parent, 'name') . "/{$page_path}";
         }
     }
     return $prefix . $page_path;
 }
Esempio n. 2
0
 private function get_page_prefix()
 {
     $context = $this->midgardmvc->context;
     if (!$context->page) {
         throw new Exception("No page set for the manual dispatcher");
     }
     static $prefixes = array();
     if (isset($prefixes[$context->page->id])) {
         return $prefixes[$context->page->id];
     }
     $prefix = '/';
     $root_id = 0;
     if (isset($context->host)) {
         $host_mc = midgard_host::new_collector('id', $context->host->id);
         $host_mc->set_key_property('root');
         $host_mc->add_value_property('prefix');
         $host_mc->execute();
         $roots = $host_mc->list_keys();
         if (!$roots) {
             throw new Exception("Failed to load root page data for host {$context->host->id}");
         }
         $root_id = null;
         foreach ($roots as $root => $array) {
             $root_id = $root;
             $prefix = $host_mc->get_subkey($root, 'prefix') . '/';
             break;
         }
     }
     $root_id = $this->midgardmvc->context->root_page->id;
     if ($context->page->id == $root_id) {
         // We're requesting prefix for the root page
         $prefixes[$context->page->id] = $prefix;
         return $prefix;
     }
     $page_path = '';
     $page_id = $context->page->id;
     while ($page_id && $page_id != $root_id) {
         $parent_mc = midgardmvc_core_node::new_collector('id', $page_id);
         $parent_mc->set_key_property('up');
         $parent_mc->add_value_property('name');
         $parent_mc->execute();
         $parents = $parent_mc->list_keys();
         foreach ($parents as $parent => $array) {
             $page_id = $parent;
             $page_path = $parent_mc->get_subkey($parent, 'name') . "/{$page_path}";
         }
     }
     $prefixes[$context->page->id] = $prefix . $page_path;
     return $prefix . $page_path;
 }