~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/ecosystem/uwa-server-original/server/lib/Exposition/Compiler/Frame.php

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright Netvibes 2006-2009.
 
4
 * This file is part of Exposition PHP Lib.
 
5
 * 
 
6
 * Exposition PHP Lib is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * Exposition PHP Lib is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with Exposition PHP Lib.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
 
 
21
require_once 'Compiler.php';
 
22
 
 
23
/**
 
24
 * Frame Compiler to render a UWA widget within an iframe.
 
25
 */
 
26
class Compiler_Frame extends Compiler
 
27
{
 
28
    /**
 
29
     * Javascript UWA environment.
 
30
     *
 
31
     * @var string
 
32
     */
 
33
    protected $_environment = 'Frame';
 
34
 
 
35
    /**
 
36
     * Stylesheet.
 
37
     *
 
38
     * @var string
 
39
     */
 
40
    protected $_stylesheet = 'uwa-iframe.css';
 
41
    
 
42
    /**
 
43
     * Main rendering function.
 
44
     *
 
45
     * @return string
 
46
     */
 
47
    public function render()
 
48
    {
 
49
        $l = array();
 
50
 
 
51
        $l[] = '<?xml version="1.0" encoding="utf-8"?>';
 
52
        $l[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' .
 
53
            ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
 
54
        $l[] = '<html xmlns="http://www.w3.org/1999/xhtml">';
 
55
        $l[] = '<head>';
 
56
        $l[] = '<title>' . $this->_widget->getTitle() . '</title>';
 
57
        $l[] = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
 
58
        foreach ($this->getStylesheets() as $stylesheet) {
 
59
            $l[] = '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '"/>';
 
60
        }
 
61
        $l[] = '</head>';
 
62
 
 
63
        $className = 'moduleIframe';
 
64
        if (isset($this->options['chromeColor'])) {
 
65
            $className .= ' ' .  $this->options['chromeColor'] . '-module';
 
66
        }  
 
67
        $l[] = '<body class="' . $className . '">';
 
68
 
 
69
        $l[] = $this->getHtmlBody();
 
70
 
 
71
        $l[] = '</body>';
 
72
        $l[] = '</html>';
 
73
 
 
74
        return implode("\n", $l);
 
75
    }
 
76
    
 
77
    public function getHtmlBody()
 
78
    {
 
79
        $l = array();
 
80
 
 
81
        if (isset($this->options['displayHeader']) && $this->options['displayHeader'] == '1') {
 
82
            $l[] = $this->_getHtmlHeader();
 
83
        }
 
84
 
 
85
        $l[] = '<div class="moduleContent" id="moduleContent">';
 
86
        $l[] = $this->_widget->getBody();
 
87
        $l[] = '</div>';
 
88
 
 
89
        if (isset($this->options['displayStatus']) && $this->options['displayStatus'] == '1') {
 
90
            $l[] = $this->_getHtmlStatus();
 
91
        }
 
92
 
 
93
        $l[] = $this->_getJavascriptConstants();
 
94
 
 
95
        foreach ($this->_getJavascripts() as $script) {
 
96
            $l[] = '<script type="text/javascript" src="' . $script . '"></script>';
 
97
        }
 
98
 
 
99
        $l[] = '<script type="text/javascript">';
 
100
        $l[] = $this->_getFrameScript();
 
101
        $l[] = '</script>';
 
102
 
 
103
        return implode("\n", $l);
 
104
    }
 
105
 
 
106
    public function getStylesheets()
 
107
    {
 
108
        return $this->_getStylesheets();
 
109
    }
 
110
 
 
111
    private function _getFrameScript()
 
112
    {
 
113
        $l = array();
 
114
 
 
115
        $proxies = array(
 
116
            'ajax' => Zend_Registry::get('proxyEndpoint') . '/ajax',
 
117
            'feed' => Zend_Registry::get('proxyEndpoint') . '/feed'
 
118
        );
 
119
 
 
120
        $l[] = sprintf('UWA.proxies = %s;', Zend_Json::encode($proxies));
 
121
 
 
122
        if (isset($this->options['properties'])) {
 
123
            foreach ($this->options['properties'] as $key => $value) {
 
124
                if (isset($value)) {
 
125
                    $l[] = sprintf("widget.%s = %s;", $key, Zend_Json::encode($value));
 
126
                }
 
127
            }
 
128
        }
 
129
 
 
130
        if (isset($this->options['data']) && count($this->options['data'])) {
 
131
            $l[] = sprintf("UWA.extend(widget.data, %s);", Zend_Json::encode($this->options['data']));
 
132
        }
 
133
 
 
134
        $script = $this->_widget->getScript();
 
135
        if (!empty($script)) {
 
136
            if (isset($this->options['uwaId'])) {
 
137
                $l[] = sprintf("UWA.Scripts['%s'](widget);", $this->options['uwaId']);
 
138
            } else {
 
139
                $l[] = "UWA.script(widget);";
 
140
            }
 
141
        }
 
142
 
 
143
        if (isset($this->options['ifproxyUrl'])) {
 
144
            $l[] = sprintf("Environment.ifproxyUrl = %s;", Zend_Json::encode($this->options['ifproxyUrl']));
 
145
        }
 
146
 
 
147
        $l[] = "Environment.launchModule();";
 
148
 
 
149
        return implode("\n", $l);
 
150
    }
 
151
 
 
152
}