public
Description: Midgard Components Framework 3rd generation
Homepage: http://www.midgard-project.org
Clone URL: git://github.com/bergie/midcom.git
commit  2fcc41a60d75dfafbed4e763b9dbf545deae41cd
tree    00b9aac87bbc2a5a410eb7a934565fe8d5063626
parent  b0d820e66676171e50b55369b464e000b592d921
midcom / midcom_core / services / dispatcher / midgard2.php
100644 82 lines (71 sloc) 2.615 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* @package midcom_core
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
 
/**
* Midgard2 dispatcher for MidCOM 3
*
* Dispatches Midgard HTTP requests to components.
*
* @package midcom_core
*/
class midcom_core_services_dispatcher_midgard2 extends midcom_core_services_dispatcher_midgard implements midcom_core_services_dispatcher
{
    public function __construct()
    {
        if (!extension_loaded('midgard2'))
        {
            throw new Exception('Midgard 2.x is required for this MidCOM setup.');
        }
 
        foreach ($_MIDGARD_CONNECTION->request_config->argv as $argument)
        {
            if (substr($argument, 0, 1) == '?')
            {
                // FIXME: For some reason we get GET parameters into the argv string too, move them to get instead
                $gets = explode('&', substr($argument, 1));
                foreach ($gets as $get_string)
                {
                    $get_pair = explode('=', $get_string);
                    if (count($get_pair) != 2)
                    {
                        break;
                    }
                    $this->get[$get_pair[0]] = $get_pair[1];
                }
 
                break;
            }
            
            $this->argv[] = $argument;
        }
    }
    
    /**
* Pull data from currently loaded page into the context.
*/
    public function populate_environment_data()
    {
        $page_data = array();
 
        $prefix = "{$_MIDGARD_CONNECTION->request_config->host->prefix}/";
        foreach ($_MIDGARD_CONNECTION->request_config->pages as $page)
        {
            if ($page->id != $_MIDGARD_CONNECTION->request_config->host->root)
            {
                $prefix = "{$prefix}{$page->name}/";
            }
            $current_page = $page;
        }
        
        $page_data['guid'] = $current_page->guid;
        $page_data['title'] = $current_page->title;
        $page_data['content'] = $current_page->content;
 
        $_MIDCOM->context->component = $current_page->component;
        
        $_MIDCOM->context->page = $page_data;
        $_MIDCOM->context->prefix = $prefix;
        
        // Append styles from context
        $_MIDCOM->templating->append_style($_MIDGARD_CONNECTION->request_config->style->id);
        $_MIDCOM->templating->append_page($current_page->id);
        
        // Populate page to toolbar
        $this->populate_node_toolbar();
    }
}
?>