GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
Added functionality to get url of an any midgard_page
Tero Heikkinen (author)
Mon Aug 18 12:26:52 -0700 2008
commit  46c2416c2da0473324a820fa7832ef5f02c12e8f
tree    6dae04691fde7e4c4c9e804674fcc87767b795bb
parent  31350b1c1daccb5dbb6c01ae5fb9b363425b9e89
...
343
344
345
346
 
347
 
 
 
 
 
 
348
349
350
...
363
364
365
 
 
 
 
 
 
 
 
366
367
368
...
606
607
608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
610
...
343
344
345
 
346
347
348
349
350
351
352
353
354
355
356
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
0
@@ -343,8 +343,14 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
      * @param array $args associative arguments array
0
      * @return string url
0
      */
0
- public function generate_url($route_id, array $args)
0
+ public function generate_url($route_id, array $args, midgard_page $page = null)
0
     {
0
+ if ( !is_null($page))
0
+ {
0
+ $_MIDCOM->context->create();
0
+ $this->set_page($page);
0
+ $this->initialize($_MIDCOM->context->page->component);
0
+ }
0
         $route_definitions = $this->get_routes();
0
         if (!isset($route_definitions[$route_id]))
0
         {
0
@@ -363,6 +369,14 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
             throw new UnexpectedValueException("Missing arguments matching route '{$route_id}' of {$this->component_name}: " . implode(', ', $link_remaining_args));
0
         }
0
         
0
+ if ( !is_null($page))
0
+ {
0
+ $url = preg_replace('%/{2,}%', '/', $this->get_page_prefix() . $link);
0
+ $_MIDCOM->context->delete();
0
+ return $url;
0
+ }
0
+
0
+
0
         return preg_replace('%/{2,}%', '/', $_MIDCOM->context->prefix . $link);
0
     }
0
 
0
@@ -606,5 +620,60 @@ class midcom_core_services_dispatcher_midgard implements midcom_core_services_di
0
         // Unlike in route_matches falling through means match
0
         return true;
0
     }
0
+
0
+ public function set_page(midgard_page $page)
0
+ {
0
+ $_MIDCOM->context->page = $page;
0
+ }
0
+
0
+ private function get_page_prefix()
0
+ {
0
+ if (!$_MIDCOM->context->page)
0
+ {
0
+ throw new Exception("No page set for the manual dispatcher");
0
+ }
0
+
0
+ $prefix = "{$_MIDGARD['prefix']}/";
0
+ $host_mc = midgard_host::new_collector('id', $_MIDGARD['host']);
0
+ $host_mc->set_key_property('root');
0
+ $host_mc->execute();
0
+ $roots = $host_mc->list_keys();
0
+ if (!$roots)
0
+ {
0
+ throw new Exception("Failed to load root page data for host {$_MIDGARD['host']}");
0
+ }
0
+ $root_id = null;
0
+ foreach ($roots as $root => $array)
0
+ {
0
+ $root_id = $root;
0
+ break;
0
+ }
0
+
0
+ if ($_MIDCOM->context->page->id == $root_id)
0
+ {
0
+ return $prefix;
0
+ }
0
+
0
+ $page_path = '';
0
+ $page_id = $_MIDCOM->context->page->id;
0
+ while ( $page_id
0
+ && $page_id != $root_id)
0
+ {
0
+ $parent_mc = midgard_page::new_collector('id', $page_id);
0
+ $parent_mc->set_key_property('up');
0
+ $parent_mc->add_value_property('name');
0
+ $parent_mc->execute();
0
+ $parents = $parent_mc->list_keys();
0
+ foreach ($parents as $parent => $array)
0
+ {
0
+ $page_id = $parent;
0
+ $page_path = $parent_mc->get_subkey($parent, 'name') . "/{$page_path}";
0
+ }
0
+ }
0
+
0
+ return $prefix . $page_path;
0
+ }
0
+
0
+
0
 }
0
 ?>

Comments

    No one has commented yet.